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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define ADAC3_CONTROL_AOUT_ENABLE 0x40
74 #define ADAC3_CONTROL_AIN_SINGLE_ENDED 0x00
75 #define ADAC3_CONTROL_AIN_3_DIFFERENTIAL 0x10
76 #define ADAC3_CONTROL_AIN_MIXED 0x20
77 #define ADAC3_CONTROL_AIN_2_DIFFERENTIAL 0x30
78 #define ADAC3_CONTROL_AUTO_INCREMENT 0x04
79 #define ADAC3_CONTROL_AD_CH0 0x00
80 #define ADAC3_CONTROL_AD_CH1 0x01
81 #define ADAC3_CONTROL_AD_CH2 0x02
82 #define ADAC3_CONTROL_AD_CH3 0x03
83 
88 #define ADAC3_VREF_2048mV 2048.0
89 #define ADAC3_VREF_4096mV 4096.0
90 #define ADAC3_RESOLUTION 0xFF
91 
97 #define ADAC3_DEVICE_ADDRESS_A2A1A0_000 0x48
98 #define ADAC3_DEVICE_ADDRESS_A2A1A0_001 0x49
99 #define ADAC3_DEVICE_ADDRESS_A2A1A0_010 0x4A
100 #define ADAC3_DEVICE_ADDRESS_A2A1A0_011 0x4B
101 #define ADAC3_DEVICE_ADDRESS_A2A1A0_100 0x4C
102 #define ADAC3_DEVICE_ADDRESS_A2A1A0_101 0x4D
103 #define ADAC3_DEVICE_ADDRESS_A2A1A0_110 0x4E
104 #define ADAC3_DEVICE_ADDRESS_A2A1A0_111 0x4F
105  // adac3_set
107 
122 #define ADAC3_MAP_MIKROBUS( cfg, mikrobus ) \
123  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
124  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
125  // adac3_map // adac3
128 
133 typedef struct
134 {
135  // Modules
136  i2c_master_t i2c;
138  // I2C slave address
139  uint8_t slave_address;
141  uint8_t control;
142  uint8_t dac;
144 } adac3_t;
145 
150 typedef struct
151 {
152  pin_name_t scl;
153  pin_name_t sda;
155  uint32_t i2c_speed;
156  uint8_t i2c_address;
158 } adac3_cfg_t;
159 
164 typedef enum
165 {
166  ADAC3_OK = 0,
167  ADAC3_ERROR = -1
168 
170 
187 
201 err_t adac3_init ( adac3_t *ctx, adac3_cfg_t *cfg );
202 
215 err_t adac3_default_cfg ( adac3_t *ctx );
216 
228 err_t adac3_write_control ( adac3_t *ctx, uint8_t control );
229 
241 err_t adac3_write_dac ( adac3_t *ctx, uint8_t dac );
242 
254 err_t adac3_read_adc ( adac3_t *ctx, uint8_t *adc );
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 #endif // ADAC3_H
260  // adac3
262 
263 // ------------------------------------------------------------------------ END
adac3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: adac3.h:155
adac3_cfg_t::sda
pin_name_t sda
Definition: adac3.h:153
adac3_t::i2c
i2c_master_t i2c
Definition: adac3.h:136
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:139
adac3_cfg_t::scl
pin_name_t scl
Definition: adac3.h:152
adac3_return_value_t
adac3_return_value_t
ADAC 3 Click return value data.
Definition: adac3.h:165
adac3_t
ADAC 3 Click context object.
Definition: adac3.h:134
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:167
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:166
adac3_cfg_t
ADAC 3 Click configuration object.
Definition: adac3.h:151
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:156
adac3_t::dac
uint8_t dac
Definition: adac3.h:142
adac3_t::control
uint8_t control
Definition: adac3.h:141