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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define DAC3_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
61 #define DAC3_RETVAL uint8_t
62 
63 #define DAC3_OK 0x00
64 #define DAC3_INIT_ERROR 0xFF
65 
71 #define DAC3_RESET 0x06
72 #define DAC3_WAKE_UP 0x09
73 #define DAC3_VOLATILE_MEM 0x40
74 #define DAC3_VOLATILE_ALL_MEM 0x60
75 #define DAC3_VOLATILE_CONF 0x80
76  // End group macro
79 // --------------------------------------------------------------- PUBLIC TYPES
88 typedef enum
89 {
91  VDD = 0,
96 
97 } dac3_vrl_t;
98 
102 typedef enum
103 {
112 
113 } dac3_pd_t;
114 
118 typedef enum
119 {
124 
125 } dac3_gain_t;
126 
130 typedef struct
131 {
135 
136 } dac3_conf_t;
137 
141 typedef struct
142 {
143  // Modules
144 
145  i2c_master_t i2c;
146 
147  // ctx variable
148 
150  uint8_t slave_address;
151 
152 } dac3_t;
153 
157 typedef struct
158 {
159  // Communication gpio pins
160 
161  pin_name_t scl;
162  pin_name_t sda;
163 
164  // static variable
165 
167  uint32_t i2c_speed;
168  uint8_t i2c_address;
169 
170 } dac3_cfg_t;
171  // End types group
173 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
174 
180 #ifdef __cplusplus
181 extern "C"{
182 #endif
183 
192 void dac3_cfg_setup ( dac3_cfg_t *cfg );
193 
201 DAC3_RETVAL dac3_init ( dac3_t *ctx, dac3_cfg_t *cfg );
202 
211 void dac3_set_out_voltage ( dac3_t *ctx, uint16_t output );
212 
221 void dac3_send_command ( dac3_t *ctx, uint8_t cmd );
222 
232 void dac3_write_all_mem ( dac3_t *ctx, uint16_t value );
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 #endif // _DAC3_H_
238  // End public_function group
241 
242 // ------------------------------------------------------------------------- END
DAC3_RETVAL
#define DAC3_RETVAL
Definition: dac3.h:61
dac3_t::i2c
i2c_master_t i2c
Definition: dac3.h:145
dac3_send_command
void dac3_send_command(dac3_t *ctx, uint8_t cmd)
Send command function.
VREF_BUFFERED
Definition: dac3.h:95
dac3_cfg_t
Click configuration structure definition.
Definition: dac3.h:157
dac3_set_out_voltage
void dac3_set_out_voltage(dac3_t *ctx, uint16_t output)
Set output voltage function.
VREF_UNBUFFERED
Definition: dac3.h:93
GAIN_2x
Definition: dac3.h:123
dac3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dac3.h:167
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:133
dac3_cfg_t::sda
pin_name_t sda
Definition: dac3.h:162
PD_1
Definition: dac3.h:107
dac3_conf_t::vrl
dac3_vrl_t vrl
Definition: dac3.h:132
VDD
Definition: dac3.h:91
dac3_gain_t
dac3_gain_t
Gain configuration enumeration.
Definition: dac3.h:118
dac3_t
Click ctx object definition.
Definition: dac3.h:141
PD_100
Definition: dac3.h:109
dac3_conf_t
DAC configuration object.
Definition: dac3.h:130
dac3_pd_t
dac3_pd_t
Power configuration enumeration.
Definition: dac3.h:102
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:161
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:134
GAIN_1x
Definition: dac3.h:121
dac3_vrl_t
dac3_vrl_t
VRL configuration enumeration.
Definition: dac3.h:88
dac3_cfg_t::i2c_address
uint8_t i2c_address
Definition: dac3.h:168
NORMAL
Definition: dac3.h:105
dac3_t::dac_cfg
dac3_conf_t dac_cfg
Definition: dac3.h:149
PD_500
Definition: dac3.h:111
dac3_t::slave_address
uint8_t slave_address
Definition: dac3.h:150
dac3_cfg_t::dac_cfg
dac3_conf_t dac_cfg
Definition: dac3.h:166