adac3  2.0.0.0
adac3.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef ADAC3_H
29 #define ADAC3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define ADAC3_CONTROL_AOUT_ENABLE 0x40
60 #define ADAC3_CONTROL_AIN_SINGLE_ENDED 0x00
61 #define ADAC3_CONTROL_AIN_3_DIFFERENTIAL 0x10
62 #define ADAC3_CONTROL_AIN_MIXED 0x20
63 #define ADAC3_CONTROL_AIN_2_DIFFERENTIAL 0x30
64 #define ADAC3_CONTROL_AUTO_INCREMENT 0x04
65 #define ADAC3_CONTROL_AD_CH0 0x00
66 #define ADAC3_CONTROL_AD_CH1 0x01
67 #define ADAC3_CONTROL_AD_CH2 0x02
68 #define ADAC3_CONTROL_AD_CH3 0x03
69 
74 #define ADAC3_VREF_2048mV 2048.0
75 #define ADAC3_VREF_4096mV 4096.0
76 #define ADAC3_RESOLUTION 0xFF
77 
83 #define ADAC3_DEVICE_ADDRESS_A2A1A0_000 0x48
84 #define ADAC3_DEVICE_ADDRESS_A2A1A0_001 0x49
85 #define ADAC3_DEVICE_ADDRESS_A2A1A0_010 0x4A
86 #define ADAC3_DEVICE_ADDRESS_A2A1A0_011 0x4B
87 #define ADAC3_DEVICE_ADDRESS_A2A1A0_100 0x4C
88 #define ADAC3_DEVICE_ADDRESS_A2A1A0_101 0x4D
89 #define ADAC3_DEVICE_ADDRESS_A2A1A0_110 0x4E
90 #define ADAC3_DEVICE_ADDRESS_A2A1A0_111 0x4F
91  // adac3_set
93 
108 #define ADAC3_MAP_MIKROBUS( cfg, mikrobus ) \
109  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
110  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
111  // adac3_map // adac3
114 
119 typedef struct
120 {
121  // Modules
122  i2c_master_t i2c;
124  // I2C slave address
125  uint8_t slave_address;
127  uint8_t control;
128  uint8_t dac;
130 } adac3_t;
131 
136 typedef struct
137 {
138  pin_name_t scl;
139  pin_name_t sda;
141  uint32_t i2c_speed;
142  uint8_t i2c_address;
144 } adac3_cfg_t;
145 
150 typedef enum
151 {
152  ADAC3_OK = 0,
153  ADAC3_ERROR = -1
154 
156 
173 
187 err_t adac3_init ( adac3_t *ctx, adac3_cfg_t *cfg );
188 
201 err_t adac3_default_cfg ( adac3_t *ctx );
202 
214 err_t adac3_write_control ( adac3_t *ctx, uint8_t control );
215 
227 err_t adac3_write_dac ( adac3_t *ctx, uint8_t dac );
228 
240 err_t adac3_read_adc ( adac3_t *ctx, uint8_t *adc );
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 #endif // ADAC3_H
246  // adac3
248 
249 // ------------------------------------------------------------------------ END
adac3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: adac3.h:141
adac3_cfg_t::sda
pin_name_t sda
Definition: adac3.h:139
adac3_t::i2c
i2c_master_t i2c
Definition: adac3.h:122
adac3_cfg_setup
void adac3_cfg_setup(adac3_cfg_t *cfg)
ADAC 3 configuration object setup function.
adac3_t::slave_address
uint8_t slave_address
Definition: adac3.h:125
adac3_cfg_t::scl
pin_name_t scl
Definition: adac3.h:138
adac3_return_value_t
adac3_return_value_t
ADAC 3 Click return value data.
Definition: adac3.h:151
adac3_t
ADAC 3 Click context object.
Definition: adac3.h:120
adac3_read_adc
err_t adac3_read_adc(adac3_t *ctx, uint8_t *adc)
ADAC 3 read adc function.
ADAC3_ERROR
@ ADAC3_ERROR
Definition: adac3.h:153
adac3_init
err_t adac3_init(adac3_t *ctx, adac3_cfg_t *cfg)
ADAC 3 initialization function.
adac3_write_dac
err_t adac3_write_dac(adac3_t *ctx, uint8_t dac)
ADAC 3 write dac function.
ADAC3_OK
@ ADAC3_OK
Definition: adac3.h:152
adac3_cfg_t
ADAC 3 Click configuration object.
Definition: adac3.h:137
adac3_write_control
err_t adac3_write_control(adac3_t *ctx, uint8_t control)
ADAC 3 write control function.
adac3_default_cfg
err_t adac3_default_cfg(adac3_t *ctx)
ADAC 3 default configuration function.
adac3_cfg_t::i2c_address
uint8_t i2c_address
Definition: adac3.h:142
adac3_t::dac
uint8_t dac
Definition: adac3.h:128
adac3_t::control
uint8_t control
Definition: adac3.h:127