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
41#ifdef PREINIT_SUPPORTED
42#include "preinit.h"
43#endif
44
45#ifdef MikroCCoreVersion
46 #if MikroCCoreVersion >= 1
47 #include "delays.h"
48 #endif
49#endif
50
51#include "drv_digital_out.h"
52#include "drv_digital_in.h"
53#include "drv_i2c_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
65#define ADAC_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
75#define ADAC_RETVAL uint8_t
76
77#define ADAC_OK 0x00
78#define ADAC_INIT_ERROR 0xFF
85#define ADAC_I2C_SLAVE_ADDR 0X10
86#define ADAC_SOFT_RESET_CMD 0x0DAC
87#define ADAC_NO_OP 0X00
88#define ADAC_ADC_SEQUENCE 0X02
89#define ADAC_GP_CONTROL 0X03
90#define ADAC_ADC_CONFIG 0X04
91#define ADAC_DAC_CONFIG 0X05
92#define ADAC_PULL_DOWN 0X06
93#define ADAC_LDAC_MODE 0X07
94#define ADAC_GPIO_WR_CONFIG 0X08
95#define ADAC_GPIO_WR_DATA 0X09
96#define ADAC_GPIO_RD_CONFIG 0X0A
97#define ADAC_POWER_REF_CTRL 0X0B
98#define ADAC_OPEN_DRAIN_CFG 0X0C
99#define ADAC_THREE_STATE 0X0D
100#define ADAC_SOFT_RESET 0X0F
107#define ADAC_CONFIG_MOD 0X00
108#define ADAC_DAC_WRITE 0X10
109#define ADAC_ADC_READ 0X40
110#define ADAC_DAC_READ 0X50
111#define ADAC_GPIO_READ 0X60
112#define ADAC_REG_READ 0X70
119#define ADAC_VREF_ON 0X02
120#define ADAC_SEQUENCE_ON 0X02
127#define ADAC_IO0 0X01
128#define ADAC_IO1 0X02
129#define ADAC_IO2 0X04
130#define ADAC_IO3 0X08
131#define ADAC_IO4 0X10
132#define ADAC_IO5 0X20
133#define ADAC_IO6 0X40
134#define ADAC_IO7 0X80
141#define ADAC_PB_PIN0 0X00
142#define ADAC_PB_PIN1 0X01
143#define ADAC_PB_PIN2 0X02
144#define ADAC_PB_PIN3 0X03
145#define ADAC_PB_PIN4 0X04
146#define ADAC_PB_PIN5 0X05
147#define ADAC_PB_PIN6 0X06
148#define ADAC_PB_PIN7 0X07
155#define ADAC_PB_DAC0 0X10
156#define ADAC_PB_DAC1 0X11
157#define ADAC_PB_DAC2 0X12
158#define ADAC_PB_DAC3 0X13
159#define ADAC_PB_DAC4 0X14
160#define ADAC_PB_DAC5 0X15
161#define ADAC_PB_DAC6 0X16
162#define ADAC_PB_DAC7 0X17
169#define ADAC_DAC_RANGE_SEL 0X0010
170#define ADAC_ADC_RANGE_SEL 0X0020
171#define ADAC_WRITE_ALL_DACS 0X0040
172#define ADAC_LOCK_CONFIG 0X0080
173#define ADAC_ADC_BUFF_ENABLE 0X0100
174#define ADAC_ADC_BUFF_PRE_CHAR 0X0200
181#define ADAC_PD_CHAN_0 0X0001
182#define ADAC_PD_CHAN_1 0X0002
183#define ADAC_PD_CHAN_2 0X0004
184#define ADAC_PD_CHAN_3 0X0008
185#define ADAC_PD_CHAN_4 0X0010
186#define ADAC_PD_CHAN_5 0X0020
187#define ADAC_PD_CHAN_6 0X0040
188#define ADAC_PD_CHAN_7 0x0080
189#define ADAC_REF_BUFF_POW_UP 0x0200
190#define ADAC_PD_ALL 0x0400
193 // End group macro
194// --------------------------------------------------------------- PUBLIC TYPES
203typedef struct
204{
205 // Output pins
206
207 digital_out_t rst;
208
209 // Modules
210
211 i2c_master_t i2c;
212
213 // ctx variable
214
216
217} adac_t;
218
222typedef struct
223{
224 // Communication gpio pins
225
226 pin_name_t scl;
227 pin_name_t sda;
228
229 // Additional gpio pins
230
231 pin_name_t rst;
232
233 // static variable
234
235 uint32_t i2c_speed;
236 uint8_t i2c_address;
237
238} adac_cfg_t;
239
240 // End types group
241// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
242
248#ifdef __cplusplus
249extern "C"{
250#endif
251
261
270
281void adac_generic_write ( adac_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
282
294void adac_generic_read ( adac_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
295
304
313void adac_software_reset ( adac_t *ctx, uint16_t cmd );
314
323void adac_power_down_settings ( adac_t *ctx, uint16_t settings );
324
333void adac_general_purpose_settings ( adac_t *ctx, uint16_t settings );
334
342uint16_t adac_read_config( adac_t *ctx );
343
352void adac_write_gpio ( adac_t *ctx, uint8_t w_data );
353
361uint8_t adac_read_gpio ( adac_t *ctx );
362
371uint16_t adac_read_dac ( adac_t *ctx, uint8_t *chan );
372
381uint16_t adac_read_adc( adac_t *ctx, uint8_t *chan );
382
392void adac_write_dac_data ( adac_t *ctx, uint8_t chan, uint16_t w_data );
393
404void adac_write_dac ( adac_t *ctx, uint8_t chan, uint8_t msb, uint8_t lsb );
405
416void adac_set_configuration ( adac_t *ctx, uint8_t ptr, uint8_t msb, uint8_t lsb );
417
427uint16_t adac_read_data ( adac_t *ctx, uint8_t addr );
428
438void adac_write_data ( adac_t *ctx, uint8_t addr, uint16_t w_data );
439
440#ifdef __cplusplus
441}
442#endif
443#endif // _ADAC_H_
444
445 // End public_function group
447
448// ------------------------------------------------------------------------- END
#define ADAC_RETVAL
Definition adac.h:75
void adac_power_down_settings(adac_t *ctx, uint16_t settings)
Power down function.
ADAC_RETVAL adac_init(adac_t *ctx, adac_cfg_t *cfg)
Initialization function.
uint16_t adac_read_dac(adac_t *ctx, uint8_t *chan)
Read DAC function.
void adac_cfg_setup(adac_cfg_t *cfg)
Config Object Initialization function.
void adac_hardware_reset(adac_t *ctx)
Hardware reset function.
void adac_write_dac_data(adac_t *ctx, uint8_t chan, uint16_t w_data)
Write DAC data function.
void adac_general_purpose_settings(adac_t *ctx, uint16_t settings)
General purpose function.
void adac_set_configuration(adac_t *ctx, uint8_t ptr, uint8_t msb, uint8_t lsb)
Set configuration function.
void adac_software_reset(adac_t *ctx, uint16_t cmd)
Software reset function.
void adac_generic_write(adac_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint16_t adac_read_config(adac_t *ctx)
Read configuration function.
void adac_generic_read(adac_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void adac_write_dac(adac_t *ctx, uint8_t chan, uint8_t msb, uint8_t lsb)
Write DAC function.
void adac_write_data(adac_t *ctx, uint8_t addr, uint16_t w_data)
Write data function.
uint8_t adac_read_gpio(adac_t *ctx)
Read GPIO function.
uint16_t adac_read_adc(adac_t *ctx, uint8_t *chan)
Read ADC function.
uint16_t adac_read_data(adac_t *ctx, uint8_t addr)
Read data function.
void adac_write_gpio(adac_t *ctx, uint8_t w_data)
Write GPIO function.
Click configuration structure definition.
Definition adac.h:223
uint32_t i2c_speed
Definition adac.h:235
pin_name_t scl
Definition adac.h:226
pin_name_t sda
Definition adac.h:227
pin_name_t rst
Definition adac.h:231
uint8_t i2c_address
Definition adac.h:236
Click ctx object definition.
Definition adac.h:204
i2c_master_t i2c
Definition adac.h:211
digital_out_t rst
Definition adac.h:207
uint8_t slave_address
Definition adac.h:215