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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_i2c_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
65#define DAC5_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
69 cfg.lda = MIKROBUS( mikrobus, MIKROBUS_PWM )
76#define DAC5_RETVAL uint8_t
77
78#define DAC5_OK 0x00
79#define DAC5_INIT_ERROR 0xFF
80#define DAC5_ERROR 0
81#define DAC5_SUCCESS 1
88#define DAC5_SLAVE_ADDRESS_BROADCAST 0x47
89#define DAC5_SLAVE_ADDRESS_GND 0x48
90#define DAC5_SLAVE_ADDRESS_VCC 0x49
91#define DAC5_SLAVE_ADDRESS_SDA 0x4A
92#define DAC5_SLAVE_ADDRESS_SCL 0x4B
99#define DAC5_VREF_3300MV 3300
100#define DAC5_VREF_5000MV 5000
101#define DAC5_VREF_2048MV 2048
102#define DAC5_VREF_1024MV 1024
109#define DAC5_REG_CONFIG 0x01
110#define DAC5_REG_STATUS_TRIGGER 0x02
111#define DAC5_REG_BRDCAST 0x03
112#define DAC5_REG_DAC_A_DATA 0x08
113#define DAC5_REG_DAC_B_DATA 0x09
114#define DAC5_REG_DAC_C_DATA 0x0A
115#define DAC5_REG_DAC_D_DATA 0x0B
116#define DAC5_REG_DAC_E_DATA 0x0C
117#define DAC5_REG_DAC_F_DATA 0x0D
118#define DAC5_REG_DAC_G_DATA 0x0E
119#define DAC5_REG_DAC_H_DATA 0x0F
126#define DAC5_CONFIG_DEFAULT 0x00FF
127#define DAC5_CONFIG_GLOBAL_ENABLED 0x0000
128#define DAC5_CONFIG_GLOBAL_DISABLED 0x0100
129#define DAC5_CONFIG_A_ENABLED 0x0000
130#define DAC5_CONFIG_A_DISABLED 0x0001
131#define DAC5_CONFIG_B_ENABLED 0x0000
132#define DAC5_CONFIG_B_DISABLED 0x0002
133#define DAC5_CONFIG_C_ENABLED 0x0000
134#define DAC5_CONFIG_C_DISABLED 0x0004
135#define DAC5_CONFIG_D_ENABLED 0x0000
136#define DAC5_CONFIG_D_DISABLED 0x0008
137#define DAC5_CONFIG_E_ENABLED 0x0000
138#define DAC5_CONFIG_E_DISABLED 0x0010
139#define DAC5_CONFIG_F_ENABLED 0x0000
140#define DAC5_CONFIG_F_DISABLED 0x0020
141#define DAC5_CONFIG_G_ENABLED 0x0000
142#define DAC5_CONFIG_G_DISABLED 0x0040
143#define DAC5_CONFIG_H_ENABLED 0x0000
144#define DAC5_CONFIG_H_DISABLED 0x0080
151#define DAC5_DEVICE_ID 0x0300
152#define DAC5_SOFTWARE_RESET 0x000A
159#define DAC5_MIN_DATA 0x0000
160#define DAC5_MAX_DATA 0x0FFF
167#define DAC5_ERROR 0
168#define DAC5_SUCCESS 1
175#define DAC5_SYNCHRONOUS 1
176#define DAC5_ASYNCHRONOUS 0
179 // End group macro
180// --------------------------------------------------------------- PUBLIC TYPES
189typedef struct
190{
191 // Output pins
192
193 digital_out_t rst;
194 digital_out_t lda;
195
196 // Modules
197
198 i2c_master_t i2c;
199
200 // ctx variable
201
203 uint16_t vref;
204
205} dac5_t;
206
210typedef struct
211{
212 // Communication gpio pins
213
214 pin_name_t scl;
215 pin_name_t sda;
216
217 // Additional gpio pins
218
219 pin_name_t rst;
220 pin_name_t lda;
221
222 // static variable
223
224 uint32_t i2c_speed;
225 uint8_t i2c_address;
226
227} dac5_cfg_t;
228
229 // End types group
230
231// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
232
238#ifdef __cplusplus
239extern "C"{
240#endif
241
251
261
271void dac5_generic_write ( dac5_t *ctx, uint8_t reg, uint16_t data_buf );
272
283uint16_t dac5_generic_read ( dac5_t *ctx, uint8_t reg );
284
293void dac5_config ( dac5_t *ctx, uint16_t config_data );
294
304uint16_t dac5_get_device_id ( dac5_t *ctx );
305
314
322void dac5_clear ( dac5_t *ctx );
323
334uint8_t dac5_set_ldac_pin ( dac5_t *ctx, uint8_t status );
335
349uint8_t dac5_send_data ( dac5_t *ctx, uint8_t data_reg, uint16_t data_buf );
350
351#ifdef __cplusplus
352}
353#endif
354#endif // _DAC5_H_
355
356 // End public_function group
358
359// ------------------------------------------------------------------------- END
#define DAC5_RETVAL
Definition dac5.h:76
void dac5_cfg_setup(dac5_cfg_t *cfg)
Config Object Initialization function.
uint16_t dac5_generic_read(dac5_t *ctx, uint8_t reg)
Generic read function.
DAC5_RETVAL dac5_init(dac5_t *ctx, dac5_cfg_t *cfg)
Initialization function.
uint8_t dac5_set_ldac_pin(dac5_t *ctx, uint8_t status)
Function for setting LDAC pin status.
void dac5_clear(dac5_t *ctx)
Function for clearing sent data.
uint16_t dac5_get_device_id(dac5_t *ctx)
Function for reading device id.
uint8_t dac5_send_data(dac5_t *ctx, uint8_t data_reg, uint16_t data_buf)
Function for sending data to one output.
void dac5_software_reset(dac5_t *ctx)
Function for software reset.
void dac5_config(dac5_t *ctx, uint16_t config_data)
Function for configurating click.
void dac5_generic_write(dac5_t *ctx, uint8_t reg, uint16_t data_buf)
Generic write function.
Click configuration structure definition.
Definition dac5.h:211
uint32_t i2c_speed
Definition dac5.h:224
pin_name_t lda
Definition dac5.h:220
pin_name_t scl
Definition dac5.h:214
pin_name_t sda
Definition dac5.h:215
pin_name_t rst
Definition dac5.h:219
uint8_t i2c_address
Definition dac5.h:225
Click ctx object definition.
Definition dac5.h:190
digital_out_t lda
Definition dac5.h:194
uint16_t vref
Definition dac5.h:203
i2c_master_t i2c
Definition dac5.h:198
digital_out_t rst
Definition dac5.h:193
uint8_t slave_address
Definition dac5.h:202