adac  2.0.0.0
adac.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  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef ADAC_H
35 #define ADAC_H
36 
37 #include "drv_digital_out.h"
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define ADAC_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
55 
61 #define ADAC_RETVAL uint8_t
62 
63 #define ADAC_OK 0x00
64 #define ADAC_INIT_ERROR 0xFF
65 
71 #define ADAC_I2C_SLAVE_ADDR 0X10
72 #define ADAC_SOFT_RESET_CMD 0x0DAC
73 #define ADAC_NO_OP 0X00
74 #define ADAC_ADC_SEQUENCE 0X02
75 #define ADAC_GP_CONTROL 0X03
76 #define ADAC_ADC_CONFIG 0X04
77 #define ADAC_DAC_CONFIG 0X05
78 #define ADAC_PULL_DOWN 0X06
79 #define ADAC_LDAC_MODE 0X07
80 #define ADAC_GPIO_WR_CONFIG 0X08
81 #define ADAC_GPIO_WR_DATA 0X09
82 #define ADAC_GPIO_RD_CONFIG 0X0A
83 #define ADAC_POWER_REF_CTRL 0X0B
84 #define ADAC_OPEN_DRAIN_CFG 0X0C
85 #define ADAC_THREE_STATE 0X0D
86 #define ADAC_SOFT_RESET 0X0F
87 
93 #define ADAC_CONFIG_MOD 0X00
94 #define ADAC_DAC_WRITE 0X10
95 #define ADAC_ADC_READ 0X40
96 #define ADAC_DAC_READ 0X50
97 #define ADAC_GPIO_READ 0X60
98 #define ADAC_REG_READ 0X70
99 
105 #define ADAC_VREF_ON 0X02
106 #define ADAC_SEQUENCE_ON 0X02
107 
113 #define ADAC_IO0 0X01
114 #define ADAC_IO1 0X02
115 #define ADAC_IO2 0X04
116 #define ADAC_IO3 0X08
117 #define ADAC_IO4 0X10
118 #define ADAC_IO5 0X20
119 #define ADAC_IO6 0X40
120 #define ADAC_IO7 0X80
121 
127 #define ADAC_PB_PIN0 0X00
128 #define ADAC_PB_PIN1 0X01
129 #define ADAC_PB_PIN2 0X02
130 #define ADAC_PB_PIN3 0X03
131 #define ADAC_PB_PIN4 0X04
132 #define ADAC_PB_PIN5 0X05
133 #define ADAC_PB_PIN6 0X06
134 #define ADAC_PB_PIN7 0X07
135 
141 #define ADAC_PB_DAC0 0X10
142 #define ADAC_PB_DAC1 0X11
143 #define ADAC_PB_DAC2 0X12
144 #define ADAC_PB_DAC3 0X13
145 #define ADAC_PB_DAC4 0X14
146 #define ADAC_PB_DAC5 0X15
147 #define ADAC_PB_DAC6 0X16
148 #define ADAC_PB_DAC7 0X17
149 
155 #define ADAC_DAC_RANGE_SEL 0X0010
156 #define ADAC_ADC_RANGE_SEL 0X0020
157 #define ADAC_WRITE_ALL_DACS 0X0040
158 #define ADAC_LOCK_CONFIG 0X0080
159 #define ADAC_ADC_BUFF_ENABLE 0X0100
160 #define ADAC_ADC_BUFF_PRE_CHAR 0X0200
161 
167 #define ADAC_PD_CHAN_0 0X0001
168 #define ADAC_PD_CHAN_1 0X0002
169 #define ADAC_PD_CHAN_2 0X0004
170 #define ADAC_PD_CHAN_3 0X0008
171 #define ADAC_PD_CHAN_4 0X0010
172 #define ADAC_PD_CHAN_5 0X0020
173 #define ADAC_PD_CHAN_6 0X0040
174 #define ADAC_PD_CHAN_7 0x0080
175 #define ADAC_REF_BUFF_POW_UP 0x0200
176 #define ADAC_PD_ALL 0x0400
177  // End group macro
180 // --------------------------------------------------------------- PUBLIC TYPES
189 typedef struct
190 {
191  // Output pins
192 
193  digital_out_t rst;
194 
195  // Modules
196 
197  i2c_master_t i2c;
198 
199  // ctx variable
200 
201  uint8_t slave_address;
202 
203 } adac_t;
204 
208 typedef struct
209 {
210  // Communication gpio pins
211 
212  pin_name_t scl;
213  pin_name_t sda;
214 
215  // Additional gpio pins
216 
217  pin_name_t rst;
218 
219  // static variable
220 
221  uint32_t i2c_speed;
222  uint8_t i2c_address;
223 
224 } adac_cfg_t;
225  // End types group
227 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
228 
234 #ifdef __cplusplus
235 extern "C"{
236 #endif
237 
247 
256 
267 void adac_generic_write ( adac_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
268 
280 void adac_generic_read ( adac_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
281 
290 
299 void adac_software_reset ( adac_t *ctx, uint16_t cmd );
300 
309 void adac_power_down_settings ( adac_t *ctx, uint16_t settings );
310 
319 void adac_general_purpose_settings ( adac_t *ctx, uint16_t settings );
320 
328 uint16_t adac_read_config( adac_t *ctx );
329 
338 void adac_write_gpio ( adac_t *ctx, uint8_t w_data );
339 
347 uint8_t adac_read_gpio ( adac_t *ctx );
348 
357 uint16_t adac_read_dac ( adac_t *ctx, uint8_t *chan );
358 
367 uint16_t adac_read_adc( adac_t *ctx, uint8_t *chan );
368 
378 void adac_write_dac_data ( adac_t *ctx, uint8_t chan, uint16_t w_data );
379 
390 void adac_write_dac ( adac_t *ctx, uint8_t chan, uint8_t msb, uint8_t lsb );
391 
402 void adac_set_configuration ( adac_t *ctx, uint8_t ptr, uint8_t msb, uint8_t lsb );
403 
413 uint16_t adac_read_data ( adac_t *ctx, uint8_t addr );
414 
424 void adac_write_data ( adac_t *ctx, uint8_t addr, uint16_t w_data );
425 
426 #ifdef __cplusplus
427 }
428 #endif
429 #endif // _ADAC_H_
430  // End public_function group
433 
434 // ------------------------------------------------------------------------- END
adac_software_reset
void adac_software_reset(adac_t *ctx, uint16_t cmd)
Software reset function.
adac_generic_write
void adac_generic_write(adac_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
adac_write_dac_data
void adac_write_dac_data(adac_t *ctx, uint8_t chan, uint16_t w_data)
Write DAC data function.
adac_hardware_reset
void adac_hardware_reset(adac_t *ctx)
Hardware reset function.
adac_t
Click ctx object definition.
Definition: adac.h:190
adac_write_dac
void adac_write_dac(adac_t *ctx, uint8_t chan, uint8_t msb, uint8_t lsb)
Write DAC function.
ADAC_RETVAL
#define ADAC_RETVAL
Definition: adac.h:61
adac_set_configuration
void adac_set_configuration(adac_t *ctx, uint8_t ptr, uint8_t msb, uint8_t lsb)
Set configuration function.
adac_init
ADAC_RETVAL adac_init(adac_t *ctx, adac_cfg_t *cfg)
Initialization function.
adac_cfg_t::i2c_address
uint8_t i2c_address
Definition: adac.h:222
adac_write_gpio
void adac_write_gpio(adac_t *ctx, uint8_t w_data)
Write GPIO function.
adac_t::i2c
i2c_master_t i2c
Definition: adac.h:197
adac_read_config
uint16_t adac_read_config(adac_t *ctx)
Read configuration function.
adac_cfg_setup
void adac_cfg_setup(adac_cfg_t *cfg)
Config Object Initialization function.
adac_cfg_t::scl
pin_name_t scl
Definition: adac.h:212
adac_cfg_t
Click configuration structure definition.
Definition: adac.h:209
adac_cfg_t::sda
pin_name_t sda
Definition: adac.h:213
adac_read_adc
uint16_t adac_read_adc(adac_t *ctx, uint8_t *chan)
Read ADC function.
adac_general_purpose_settings
void adac_general_purpose_settings(adac_t *ctx, uint16_t settings)
General purpose function.
adac_read_dac
uint16_t adac_read_dac(adac_t *ctx, uint8_t *chan)
Read DAC function.
adac_t::slave_address
uint8_t slave_address
Definition: adac.h:201
adac_write_data
void adac_write_data(adac_t *ctx, uint8_t addr, uint16_t w_data)
Write data function.
adac_read_data
uint16_t adac_read_data(adac_t *ctx, uint8_t addr)
Read data function.
adac_read_gpio
uint8_t adac_read_gpio(adac_t *ctx)
Read GPIO function.
adac_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: adac.h:221
adac_cfg_t::rst
pin_name_t rst
Definition: adac.h:217
adac_t::rst
digital_out_t rst
Definition: adac.h:193
adac_power_down_settings
void adac_power_down_settings(adac_t *ctx, uint16_t settings)
Power down function.
adac_generic_read
void adac_generic_read(adac_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.