dac3  2.0.0.0
dac3.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  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DAC3_H
36 #define DAC3_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define DAC3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define DAC3_RETVAL uint8_t
72 
73 #define DAC3_OK 0x00
74 #define DAC3_INIT_ERROR 0xFF
75 
81 #define DAC3_RESET 0x06
82 #define DAC3_WAKE_UP 0x09
83 #define DAC3_VOLATILE_MEM 0x40
84 #define DAC3_VOLATILE_ALL_MEM 0x60
85 #define DAC3_VOLATILE_CONF 0x80
86  // End group macro
89 // --------------------------------------------------------------- PUBLIC TYPES
98 typedef enum
99 {
101  VDD = 0,
106 
107 } dac3_vrl_t;
108 
112 typedef enum
113 {
121  PD_500
122 
124 
128 typedef enum
129 {
133  GAIN_2x
134 
136 
140 typedef struct
141 {
145 
146 } dac3_conf_t;
147 
151 typedef struct
152 {
153  // Modules
154 
155  i2c_master_t i2c;
156 
157  // ctx variable
158 
160  uint8_t slave_address;
161 
162 } dac3_t;
163 
167 typedef struct
168 {
169  // Communication gpio pins
170 
171  pin_name_t scl;
172  pin_name_t sda;
173 
174  // static variable
175 
177  uint32_t i2c_speed;
178  uint8_t i2c_address;
179 
180 } dac3_cfg_t;
181  // End types group
183 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
184 
190 #ifdef __cplusplus
191 extern "C"{
192 #endif
193 
203 
212 
221 void dac3_set_out_voltage ( dac3_t *ctx, uint16_t output );
222 
231 void dac3_send_command ( dac3_t *ctx, uint8_t cmd );
232 
242 void dac3_write_all_mem ( dac3_t *ctx, uint16_t value );
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 #endif // _DAC3_H_
248  // End public_function group
251 
252 // ------------------------------------------------------------------------- END
DAC3_RETVAL
#define DAC3_RETVAL
Definition: dac3.h:71
dac3_t::i2c
i2c_master_t i2c
Definition: dac3.h:155
dac3_send_command
void dac3_send_command(dac3_t *ctx, uint8_t cmd)
Send command function.
VREF_BUFFERED
@ VREF_BUFFERED
Definition: dac3.h:105
dac3_cfg_t
Click configuration structure definition.
Definition: dac3.h:168
dac3_set_out_voltage
void dac3_set_out_voltage(dac3_t *ctx, uint16_t output)
Set output voltage function.
VREF_UNBUFFERED
@ VREF_UNBUFFERED
Definition: dac3.h:103
GAIN_2x
@ GAIN_2x
Definition: dac3.h:133
dac3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dac3.h:177
dac3_write_all_mem
void dac3_write_all_mem(dac3_t *ctx, uint16_t value)
Send command function.
dac3_conf_t::power
dac3_pd_t power
Definition: dac3.h:143
dac3_cfg_t::sda
pin_name_t sda
Definition: dac3.h:172
PD_1
@ PD_1
Definition: dac3.h:117
dac3_conf_t::vrl
dac3_vrl_t vrl
Definition: dac3.h:142
VDD
@ VDD
Definition: dac3.h:101
dac3_gain_t
dac3_gain_t
Gain configuration enumeration.
Definition: dac3.h:129
dac3_t
Click ctx object definition.
Definition: dac3.h:152
PD_100
@ PD_100
Definition: dac3.h:119
dac3_conf_t
DAC configuration object.
Definition: dac3.h:141
dac3_pd_t
dac3_pd_t
Power configuration enumeration.
Definition: dac3.h:113
dac3_init
DAC3_RETVAL dac3_init(dac3_t *ctx, dac3_cfg_t *cfg)
Initialization function.
dac3_cfg_t::scl
pin_name_t scl
Definition: dac3.h:171
dac3_cfg_setup
void dac3_cfg_setup(dac3_cfg_t *cfg)
Config Object Initialization function.
dac3_conf_t::gain
dac3_gain_t gain
Definition: dac3.h:144
GAIN_1x
@ GAIN_1x
Definition: dac3.h:131
dac3_vrl_t
dac3_vrl_t
VRL configuration enumeration.
Definition: dac3.h:99
dac3_cfg_t::i2c_address
uint8_t i2c_address
Definition: dac3.h:178
NORMAL
@ NORMAL
Definition: dac3.h:115
dac3_t::dac_cfg
dac3_conf_t dac_cfg
Definition: dac3.h:159
PD_500
@ PD_500
Definition: dac3.h:121
dac3_t::slave_address
uint8_t slave_address
Definition: dac3.h:160
dac3_cfg_t::dac_cfg
dac3_conf_t dac_cfg
Definition: dac3.h:176