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 "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_out.h"
48 #include "drv_digital_in.h"
49 #include "drv_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define ADAC_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
65 
71 #define ADAC_RETVAL uint8_t
72 
73 #define ADAC_OK 0x00
74 #define ADAC_INIT_ERROR 0xFF
75 
81 #define ADAC_I2C_SLAVE_ADDR 0X10
82 #define ADAC_SOFT_RESET_CMD 0x0DAC
83 #define ADAC_NO_OP 0X00
84 #define ADAC_ADC_SEQUENCE 0X02
85 #define ADAC_GP_CONTROL 0X03
86 #define ADAC_ADC_CONFIG 0X04
87 #define ADAC_DAC_CONFIG 0X05
88 #define ADAC_PULL_DOWN 0X06
89 #define ADAC_LDAC_MODE 0X07
90 #define ADAC_GPIO_WR_CONFIG 0X08
91 #define ADAC_GPIO_WR_DATA 0X09
92 #define ADAC_GPIO_RD_CONFIG 0X0A
93 #define ADAC_POWER_REF_CTRL 0X0B
94 #define ADAC_OPEN_DRAIN_CFG 0X0C
95 #define ADAC_THREE_STATE 0X0D
96 #define ADAC_SOFT_RESET 0X0F
97 
103 #define ADAC_CONFIG_MOD 0X00
104 #define ADAC_DAC_WRITE 0X10
105 #define ADAC_ADC_READ 0X40
106 #define ADAC_DAC_READ 0X50
107 #define ADAC_GPIO_READ 0X60
108 #define ADAC_REG_READ 0X70
109 
115 #define ADAC_VREF_ON 0X02
116 #define ADAC_SEQUENCE_ON 0X02
117 
123 #define ADAC_IO0 0X01
124 #define ADAC_IO1 0X02
125 #define ADAC_IO2 0X04
126 #define ADAC_IO3 0X08
127 #define ADAC_IO4 0X10
128 #define ADAC_IO5 0X20
129 #define ADAC_IO6 0X40
130 #define ADAC_IO7 0X80
131 
137 #define ADAC_PB_PIN0 0X00
138 #define ADAC_PB_PIN1 0X01
139 #define ADAC_PB_PIN2 0X02
140 #define ADAC_PB_PIN3 0X03
141 #define ADAC_PB_PIN4 0X04
142 #define ADAC_PB_PIN5 0X05
143 #define ADAC_PB_PIN6 0X06
144 #define ADAC_PB_PIN7 0X07
145 
151 #define ADAC_PB_DAC0 0X10
152 #define ADAC_PB_DAC1 0X11
153 #define ADAC_PB_DAC2 0X12
154 #define ADAC_PB_DAC3 0X13
155 #define ADAC_PB_DAC4 0X14
156 #define ADAC_PB_DAC5 0X15
157 #define ADAC_PB_DAC6 0X16
158 #define ADAC_PB_DAC7 0X17
159 
165 #define ADAC_DAC_RANGE_SEL 0X0010
166 #define ADAC_ADC_RANGE_SEL 0X0020
167 #define ADAC_WRITE_ALL_DACS 0X0040
168 #define ADAC_LOCK_CONFIG 0X0080
169 #define ADAC_ADC_BUFF_ENABLE 0X0100
170 #define ADAC_ADC_BUFF_PRE_CHAR 0X0200
171 
177 #define ADAC_PD_CHAN_0 0X0001
178 #define ADAC_PD_CHAN_1 0X0002
179 #define ADAC_PD_CHAN_2 0X0004
180 #define ADAC_PD_CHAN_3 0X0008
181 #define ADAC_PD_CHAN_4 0X0010
182 #define ADAC_PD_CHAN_5 0X0020
183 #define ADAC_PD_CHAN_6 0X0040
184 #define ADAC_PD_CHAN_7 0x0080
185 #define ADAC_REF_BUFF_POW_UP 0x0200
186 #define ADAC_PD_ALL 0x0400
187  // End group macro
190 // --------------------------------------------------------------- PUBLIC TYPES
199 typedef struct
200 {
201  // Output pins
202 
203  digital_out_t rst;
204 
205  // Modules
206 
207  i2c_master_t i2c;
208 
209  // ctx variable
210 
211  uint8_t slave_address;
212 
213 } adac_t;
214 
218 typedef struct
219 {
220  // Communication gpio pins
221 
222  pin_name_t scl;
223  pin_name_t sda;
224 
225  // Additional gpio pins
226 
227  pin_name_t rst;
228 
229  // static variable
230 
231  uint32_t i2c_speed;
232  uint8_t i2c_address;
233 
234 } adac_cfg_t;
235  // End types group
237 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
238 
244 #ifdef __cplusplus
245 extern "C"{
246 #endif
247 
257 
266 
277 void adac_generic_write ( adac_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
278 
290 void adac_generic_read ( adac_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
291 
300 
309 void adac_software_reset ( adac_t *ctx, uint16_t cmd );
310 
319 void adac_power_down_settings ( adac_t *ctx, uint16_t settings );
320 
329 void adac_general_purpose_settings ( adac_t *ctx, uint16_t settings );
330 
338 uint16_t adac_read_config( adac_t *ctx );
339 
348 void adac_write_gpio ( adac_t *ctx, uint8_t w_data );
349 
357 uint8_t adac_read_gpio ( adac_t *ctx );
358 
367 uint16_t adac_read_dac ( adac_t *ctx, uint8_t *chan );
368 
377 uint16_t adac_read_adc( adac_t *ctx, uint8_t *chan );
378 
388 void adac_write_dac_data ( adac_t *ctx, uint8_t chan, uint16_t w_data );
389 
400 void adac_write_dac ( adac_t *ctx, uint8_t chan, uint8_t msb, uint8_t lsb );
401 
412 void adac_set_configuration ( adac_t *ctx, uint8_t ptr, uint8_t msb, uint8_t lsb );
413 
423 uint16_t adac_read_data ( adac_t *ctx, uint8_t addr );
424 
434 void adac_write_data ( adac_t *ctx, uint8_t addr, uint16_t w_data );
435 
436 #ifdef __cplusplus
437 }
438 #endif
439 #endif // _ADAC_H_
440  // End public_function group
443 
444 // ------------------------------------------------------------------------- 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:200
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:71
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:232
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:207
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:222
adac_cfg_t
Click configuration structure definition.
Definition: adac.h:219
adac_cfg_t::sda
pin_name_t sda
Definition: adac.h:223
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:211
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:231
adac_cfg_t::rst
pin_name_t rst
Definition: adac.h:227
adac_t::rst
digital_out_t rst
Definition: adac.h:203
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.