dac4 2.0.0.0
dac4.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef DAC4_H
36#define DAC4_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define DAC4_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.lda = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
70 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define DAC4_OK 0
78#define DAC4_ERROR -1
81#define DAC4_DEVICE_ADDRESS 0x60
82
87#define DAC4_CHANNEL_A 0
88#define DAC4_CHANNEL_B 1
89#define DAC4_CHANNEL_C 2
90#define DAC4_CHANNEL_D 3
97#define DAC4_UPDATE 0
98#define DAC4_DONT_UPDATE 1
105#define DAC4_VREF_EXTERNAL 0
106#define DAC4_VREF_INTERNAL 1
113#define DAC4_MODE_NORMAL 0
114#define DAC4_MODE_1kOhm 1
115#define DAC4_MODE_100kOhm 2
116#define DAC4_MODE_500kOhm 3
123#define DAC4_GAIN_x1 0
124#define DAC4_GAIN_x2 1
127 // End group macro
128// --------------------------------------------------------------- PUBLIC TYPES
134typedef struct
135{
136 uint8_t rdy_bit;
137 uint8_t por_bit;
139 uint8_t udac_bit;
141 uint8_t power_mode;
142 uint8_t gain_value;
144
146
155
156typedef struct
157{
158 uint8_t channel_a;
159 uint8_t channel_b;
160 uint8_t channel_c;
161 uint8_t channel_d;
162
164
165typedef struct
166{
167 uint8_t channel_a;
168 uint8_t channel_b;
169 uint8_t channel_c;
170 uint8_t channel_d;
171
173
174typedef struct
175{
176 uint8_t channel_a;
177 uint8_t channel_b;
178 uint8_t channel_c;
179 uint8_t channel_d;
180
182
186typedef struct
187{
188 // Output pins
189
190 digital_out_t lda;
191
192 // Input pins
193
194 digital_in_t rdy;
195
196 // Modules
197
198 i2c_master_t i2c;
199
200 // ctx variable
201
203
204} dac4_t;
205
209typedef struct
210{
211 // Communication gpio pins
212
213 pin_name_t scl;
214 pin_name_t sda;
215
216 // Additional gpio pins
217
218 pin_name_t lda;
219 pin_name_t rdy;
220
221 // static variable
222
223 uint32_t i2c_speed;
224 uint8_t i2c_address;
225
226} dac4_cfg_t;
227
228 // End types group
229// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
230
236#ifdef __cplusplus
237extern "C"{
238#endif
239
249
258err_t dac4_init ( dac4_t *ctx, dac4_cfg_t *cfg );
259
269void dac4_generic_write ( dac4_t *ctx, uint8_t *data_buf, uint8_t len );
270
280void dac4_generic_read ( dac4_t *ctx, uint8_t *data_buf, uint8_t len );
281
292uint8_t dac4_int_get ( dac4_t *ctx );
293
302void dac4_pwm_set ( dac4_t *ctx, uint8_t pin_state );
303
313void dac4_i2c_get ( dac4_t *ctx, uint8_t *get_buffer, uint16_t n_bytes );
314
324void dac4_i2c_set ( dac4_t *ctx, uint8_t *set_buffer, uint16_t n_bytes );
325
337
349
361
382uint8_t dac4_fast_write ( dac4_t *ctx, dac4_channel_t *channels );
404uint8_t dac4_multi_write ( dac4_t *ctx, dac4_channel_setting_t *channel_buffer, uint8_t n_channels );
405
427uint8_t dac4_sequential_write ( dac4_t *ctx, uint8_t starting_channel, dac4_channel_setting_t *channel_buffer );
428
450
466
482
498
517uint8_t dac4_data_report ( dac4_t *ctx, dac4_channel_setting_t *channel_buffer );
518
519
520#ifdef __cplusplus
521}
522#endif
523#endif // _DAC4_H_
524
525 // End public_function group
527
528// ------------------------------------------------------------------------- END
err_t dac4_init(dac4_t *ctx, dac4_cfg_t *cfg)
Initialization function.
uint8_t dac4_general_call_wake_up(dac4_t *ctx)
Executing wake up command.
void dac4_i2c_set(dac4_t *ctx, uint8_t *set_buffer, uint16_t n_bytes)
Setting data via I2C.
uint8_t dac4_fast_write(dac4_t *ctx, dac4_channel_t *channels)
Executing fast write command.
void dac4_i2c_get(dac4_t *ctx, uint8_t *get_buffer, uint16_t n_bytes)
Getting data via I2C.
uint8_t dac4_multi_write(dac4_t *ctx, dac4_channel_setting_t *channel_buffer, uint8_t n_channels)
Executing multi-write command.
uint8_t dac4_single_write(dac4_t *ctx, dac4_channel_setting_t *channel_x)
Executing single write command.
uint8_t dac4_general_call_software_update(dac4_t *ctx)
Executing software update command.
uint8_t dac4_voltage_reference_set(dac4_t *ctx, dac4_v_ref_channels_t *vref)
Setting channel voltage reference values.
void dac4_cfg_setup(dac4_cfg_t *cfg)
Config Object Initialization function.
uint8_t dac4_data_report(dac4_t *ctx, dac4_channel_setting_t *channel_buffer)
void dac4_generic_read(dac4_t *ctx, uint8_t *data_buf, uint8_t len)
Generic read function.
void dac4_pwm_set(dac4_t *ctx, uint8_t pin_state)
Setting PWM pin state.
uint8_t dac4_sequential_write(dac4_t *ctx, uint8_t starting_channel, dac4_channel_setting_t *channel_buffer)
Executing sequential write command.
uint8_t dac4_power_mode_set(dac4_t *ctx, dac4_pm_channels_t *pm)
Setting channel power modes.
uint8_t dac4_int_get(dac4_t *ctx)
Getting INT pin state.
uint8_t dac4_general_call_reset(dac4_t *ctx)
Executing reset command.
void dac4_generic_write(dac4_t *ctx, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t dac4_gain_set(dac4_t *ctx, dac4_gain_channels_t *gain)
Writing channel gain values.
Click configuration structure definition.
Definition dac4.h:210
uint32_t i2c_speed
Definition dac4.h:223
pin_name_t lda
Definition dac4.h:218
pin_name_t scl
Definition dac4.h:213
pin_name_t rdy
Definition dac4.h:219
pin_name_t sda
Definition dac4.h:214
uint8_t i2c_address
Definition dac4.h:224
Definition dac4.h:135
uint8_t channel_select
Definition dac4.h:138
uint8_t power_mode
Definition dac4.h:141
uint8_t udac_bit
Definition dac4.h:139
uint8_t por_bit
Definition dac4.h:137
uint8_t voltage_reference
Definition dac4.h:140
uint16_t dac_input_data
Definition dac4.h:143
uint8_t gain_value
Definition dac4.h:142
uint8_t rdy_bit
Definition dac4.h:136
Definition dac4.h:148
dac4_channel_setting_t channel_b
Definition dac4.h:150
dac4_channel_setting_t channel_c
Definition dac4.h:151
dac4_channel_setting_t channel_d
Definition dac4.h:152
dac4_channel_setting_t channel_a
Definition dac4.h:149
Definition dac4.h:175
uint8_t channel_c
Definition dac4.h:178
uint8_t channel_b
Definition dac4.h:177
uint8_t channel_a
Definition dac4.h:176
uint8_t channel_d
Definition dac4.h:179
Definition dac4.h:166
uint8_t channel_c
Definition dac4.h:169
uint8_t channel_b
Definition dac4.h:168
uint8_t channel_a
Definition dac4.h:167
uint8_t channel_d
Definition dac4.h:170
Click ctx object definition.
Definition dac4.h:187
digital_out_t lda
Definition dac4.h:190
i2c_master_t i2c
Definition dac4.h:198
uint8_t slave_address
Definition dac4.h:202
digital_in_t rdy
Definition dac4.h:194
Definition dac4.h:157
uint8_t channel_c
Definition dac4.h:160
uint8_t channel_b
Definition dac4.h:159
uint8_t channel_a
Definition dac4.h:158
uint8_t channel_d
Definition dac4.h:161