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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define ADAC3_CONTROL_AOUT_ENABLE 0x40
70 #define ADAC3_CONTROL_AIN_SINGLE_ENDED 0x00
71 #define ADAC3_CONTROL_AIN_3_DIFFERENTIAL 0x10
72 #define ADAC3_CONTROL_AIN_MIXED 0x20
73 #define ADAC3_CONTROL_AIN_2_DIFFERENTIAL 0x30
74 #define ADAC3_CONTROL_AUTO_INCREMENT 0x04
75 #define ADAC3_CONTROL_AD_CH0 0x00
76 #define ADAC3_CONTROL_AD_CH1 0x01
77 #define ADAC3_CONTROL_AD_CH2 0x02
78 #define ADAC3_CONTROL_AD_CH3 0x03
79 
84 #define ADAC3_VREF_2048mV 2048.0
85 #define ADAC3_VREF_4096mV 4096.0
86 #define ADAC3_RESOLUTION 0xFF
87 
93 #define ADAC3_DEVICE_ADDRESS_A2A1A0_000 0x48
94 #define ADAC3_DEVICE_ADDRESS_A2A1A0_001 0x49
95 #define ADAC3_DEVICE_ADDRESS_A2A1A0_010 0x4A
96 #define ADAC3_DEVICE_ADDRESS_A2A1A0_011 0x4B
97 #define ADAC3_DEVICE_ADDRESS_A2A1A0_100 0x4C
98 #define ADAC3_DEVICE_ADDRESS_A2A1A0_101 0x4D
99 #define ADAC3_DEVICE_ADDRESS_A2A1A0_110 0x4E
100 #define ADAC3_DEVICE_ADDRESS_A2A1A0_111 0x4F
101  // adac3_set
103 
118 #define ADAC3_MAP_MIKROBUS( cfg, mikrobus ) \
119  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
120  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
121  // adac3_map // adac3
124 
129 typedef struct
130 {
131  // Modules
132  i2c_master_t i2c;
134  // I2C slave address
135  uint8_t slave_address;
137  uint8_t control;
138  uint8_t dac;
140 } adac3_t;
141 
146 typedef struct
147 {
148  pin_name_t scl;
149  pin_name_t sda;
151  uint32_t i2c_speed;
152  uint8_t i2c_address;
154 } adac3_cfg_t;
155 
160 typedef enum
161 {
162  ADAC3_OK = 0,
163  ADAC3_ERROR = -1
164 
166 
183 
197 err_t adac3_init ( adac3_t *ctx, adac3_cfg_t *cfg );
198 
211 err_t adac3_default_cfg ( adac3_t *ctx );
212 
224 err_t adac3_write_control ( adac3_t *ctx, uint8_t control );
225 
237 err_t adac3_write_dac ( adac3_t *ctx, uint8_t dac );
238 
250 err_t adac3_read_adc ( adac3_t *ctx, uint8_t *adc );
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif // ADAC3_H
256  // adac3
258 
259 // ------------------------------------------------------------------------ END
adac3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: adac3.h:151
adac3_cfg_t::sda
pin_name_t sda
Definition: adac3.h:149
adac3_t::i2c
i2c_master_t i2c
Definition: adac3.h:132
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:135
adac3_cfg_t::scl
pin_name_t scl
Definition: adac3.h:148
adac3_return_value_t
adac3_return_value_t
ADAC 3 Click return value data.
Definition: adac3.h:161
adac3_t
ADAC 3 Click context object.
Definition: adac3.h:130
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:163
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:162
adac3_cfg_t
ADAC 3 Click configuration object.
Definition: adac3.h:147
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:152
adac3_t::dac
uint8_t dac
Definition: adac3.h:138
adac3_t::control
uint8_t control
Definition: adac3.h:137