dac5  2.0.0.0
dac5.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 DAC5_H
36 #define DAC5_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_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define DAC5_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
65  cfg.lda = MIKROBUS( mikrobus, MIKROBUS_PWM )
66 
72 #define DAC5_RETVAL uint8_t
73 
74 #define DAC5_OK 0x00
75 #define DAC5_INIT_ERROR 0xFF
76 #define DAC5_ERROR 0
77 #define DAC5_SUCCESS 1
78 
84 #define DAC5_SLAVE_ADDRESS_BROADCAST 0x47
85 #define DAC5_SLAVE_ADDRESS_GND 0x48
86 #define DAC5_SLAVE_ADDRESS_VCC 0x49
87 #define DAC5_SLAVE_ADDRESS_SDA 0x4A
88 #define DAC5_SLAVE_ADDRESS_SCL 0x4B
89 
95 #define DAC5_VREF_3300MV 3300
96 #define DAC5_VREF_5000MV 5000
97 #define DAC5_VREF_2048MV 2048
98 #define DAC5_VREF_1024MV 1024
99 
105 #define DAC5_REG_CONFIG 0x01
106 #define DAC5_REG_STATUS_TRIGGER 0x02
107 #define DAC5_REG_BRDCAST 0x03
108 #define DAC5_REG_DAC_A_DATA 0x08
109 #define DAC5_REG_DAC_B_DATA 0x09
110 #define DAC5_REG_DAC_C_DATA 0x0A
111 #define DAC5_REG_DAC_D_DATA 0x0B
112 #define DAC5_REG_DAC_E_DATA 0x0C
113 #define DAC5_REG_DAC_F_DATA 0x0D
114 #define DAC5_REG_DAC_G_DATA 0x0E
115 #define DAC5_REG_DAC_H_DATA 0x0F
116 
122 #define DAC5_CONFIG_DEFAULT 0x00FF
123 #define DAC5_CONFIG_GLOBAL_ENABLED 0x0000
124 #define DAC5_CONFIG_GLOBAL_DISABLED 0x0100
125 #define DAC5_CONFIG_A_ENABLED 0x0000
126 #define DAC5_CONFIG_A_DISABLED 0x0001
127 #define DAC5_CONFIG_B_ENABLED 0x0000
128 #define DAC5_CONFIG_B_DISABLED 0x0002
129 #define DAC5_CONFIG_C_ENABLED 0x0000
130 #define DAC5_CONFIG_C_DISABLED 0x0004
131 #define DAC5_CONFIG_D_ENABLED 0x0000
132 #define DAC5_CONFIG_D_DISABLED 0x0008
133 #define DAC5_CONFIG_E_ENABLED 0x0000
134 #define DAC5_CONFIG_E_DISABLED 0x0010
135 #define DAC5_CONFIG_F_ENABLED 0x0000
136 #define DAC5_CONFIG_F_DISABLED 0x0020
137 #define DAC5_CONFIG_G_ENABLED 0x0000
138 #define DAC5_CONFIG_G_DISABLED 0x0040
139 #define DAC5_CONFIG_H_ENABLED 0x0000
140 #define DAC5_CONFIG_H_DISABLED 0x0080
141 
147 #define DAC5_DEVICE_ID 0x0300
148 #define DAC5_SOFTWARE_RESET 0x000A
149 
155 #define DAC5_MIN_DATA 0x0000
156 #define DAC5_MAX_DATA 0x0FFF
157 
163 #define DAC5_ERROR 0
164 #define DAC5_SUCCESS 1
165 
171 #define DAC5_SYNCHRONOUS 1
172 #define DAC5_ASYNCHRONOUS 0
173  // End group macro
176 // --------------------------------------------------------------- PUBLIC TYPES
185 typedef struct
186 {
187  // Output pins
188 
189  digital_out_t rst;
190  digital_out_t lda;
191 
192  // Modules
193 
194  i2c_master_t i2c;
195 
196  // ctx variable
197 
198  uint8_t slave_address;
199  uint16_t vref;
200 
201 } dac5_t;
202 
206 typedef struct
207 {
208  // Communication gpio pins
209 
210  pin_name_t scl;
211  pin_name_t sda;
212 
213  // Additional gpio pins
214 
215  pin_name_t rst;
216  pin_name_t lda;
217 
218  // static variable
219 
220  uint32_t i2c_speed;
221  uint8_t i2c_address;
222 
223 } dac5_cfg_t;
224  // End types group
226 
227 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
228 
234 #ifdef __cplusplus
235 extern "C"{
236 #endif
237 
247 
257 
267 void dac5_generic_write ( dac5_t *ctx, uint8_t reg, uint16_t data_buf );
268 
279 uint16_t dac5_generic_read ( dac5_t *ctx, uint8_t reg );
280 
289 void dac5_config ( dac5_t *ctx, uint16_t config_data );
290 
300 uint16_t dac5_get_device_id ( dac5_t *ctx );
301 
310 
318 void dac5_clear ( dac5_t *ctx );
319 
330 uint8_t dac5_set_ldac_pin ( dac5_t *ctx, uint8_t status );
331 
345 uint8_t dac5_send_data ( dac5_t *ctx, uint8_t data_reg, uint16_t data_buf );
346 
347 #ifdef __cplusplus
348 }
349 #endif
350 #endif // _DAC5_H_
351  // End public_function group
354 
355 // ------------------------------------------------------------------------- END
dac5_generic_read
uint16_t dac5_generic_read(dac5_t *ctx, uint8_t reg)
Generic read function.
dac5_cfg_t
Click configuration structure definition.
Definition: dac5.h:207
dac5_cfg_t::scl
pin_name_t scl
Definition: dac5.h:210
dac5_t
Click ctx object definition.
Definition: dac5.h:186
dac5_cfg_setup
void dac5_cfg_setup(dac5_cfg_t *cfg)
Config Object Initialization function.
dac5_t::slave_address
uint8_t slave_address
Definition: dac5.h:198
dac5_software_reset
void dac5_software_reset(dac5_t *ctx)
Function for software reset.
dac5_set_ldac_pin
uint8_t dac5_set_ldac_pin(dac5_t *ctx, uint8_t status)
Function for setting LDAC pin status.
dac5_cfg_t::lda
pin_name_t lda
Definition: dac5.h:216
dac5_send_data
uint8_t dac5_send_data(dac5_t *ctx, uint8_t data_reg, uint16_t data_buf)
Function for sending data to one output.
dac5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dac5.h:220
dac5_generic_write
void dac5_generic_write(dac5_t *ctx, uint8_t reg, uint16_t data_buf)
Generic write function.
dac5_t::rst
digital_out_t rst
Definition: dac5.h:189
dac5_init
DAC5_RETVAL dac5_init(dac5_t *ctx, dac5_cfg_t *cfg)
Initialization function.
dac5_cfg_t::i2c_address
uint8_t i2c_address
Definition: dac5.h:221
dac5_t::lda
digital_out_t lda
Definition: dac5.h:190
DAC5_RETVAL
#define DAC5_RETVAL
Definition: dac5.h:72
dac5_cfg_t::rst
pin_name_t rst
Definition: dac5.h:215
dac5_cfg_t::sda
pin_name_t sda
Definition: dac5.h:211
dac5_get_device_id
uint16_t dac5_get_device_id(dac5_t *ctx)
Function for reading device id.
dac5_t::i2c
i2c_master_t i2c
Definition: dac5.h:194
dac5_clear
void dac5_clear(dac5_t *ctx)
Function for clearing sent data.
dac5_config
void dac5_config(dac5_t *ctx, uint16_t config_data)
Function for configurating click.
dac5_t::vref
uint16_t vref
Definition: dac5.h:199