dac8 2.0.0.0
dac8.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 DAC8_H
36#define DAC8_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_digital_in.h"
54#include "drv_i2c_master.h"
55#include "drv_spi_master.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define DAC8_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
72 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
73 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
74 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
75 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
76 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
83#define DAC8_MASTER_I2C 0
84#define DAC8_MASTER_SPI 1
91#define DAC8_RETVAL uint8_t
92
93#define DAC8_OK 0x00
94#define DAC8_INIT_ERROR 0xFF
101#define DAC8_I2C_SLAVE_ADDR 0x48
108#define DAC8_REG_NOOP 0x00
109#define DAC8_REG_DEVID 0x01
110#define DAC8_REG_SYNC 0x02
111#define DAC8_REG_CONFIG 0x03
112#define DAC8_REG_GAIN 0x04
113#define DAC8_REG_TRIGGER 0x05
114#define DAC8_REG_STATUS 0x07
115#define DAC8_REG_DAC 0x08
122#define DAC8_SYNC_DISABLE 0x0000
123#define DAC8_SYNC_ENABLE 0x0001
130#define DAC8_CONFIG_REF_PWDWN_ENABLE 0x0000
131#define DAC8_CONFIG_REF_PWDWN_DISABLE 0x0001
132#define DAC8_CONFIG_REF_PWDWN_BIT_MASK 0x0001
133#define DAC8_CONFIG_DAC_PWDWN_DISABLE 0x0000
134#define DAC8_CONFIG_DAC_PWDWN_ENABLE 0x0001
135#define DAC8_CONFIG_DAC_PWDWN_BIT_MASK 0x0001
142#define DAC8_GAIN_REF_DIV_DISABLE 0x0000
143#define DAC8_GAIN_REF_DIV_2 0x0001
144#define DAC8_GAIN_REF_DIV_BIT_MASK 0x0001
145#define DAC8_GAIN_BUFF_GAIN_1 0x0000
146#define DAC8_GAIN_BUFF_GAIN_2 0x0001
147#define DAC8_GAIN_BUFF_GAIN_BIT_MASK 0x0001
154#define DAC8_TRIGGER_LDAC 0x0010
155#define DAC8_TRIGGER_SOFT_RESET 0x000A
162#define DAC8_STATUS_REF_ALARM_BIT_MASK 0x0001
163
164#define DAC8_ERROR 0x00
165#define DAC8_SUCCESS 0x01
172#define DAC8_ADDR_DEFAULT 0x00
173#define DAC8_ADDR_BIT_MASK 0x03
174
175#define DAC8_CTRL_UPD_AN_OUT_SINGLE_CH_STORE 0x00
176#define DAC8_CTRL_UPD_AN_OUT_SINGLE_CH_UPDATE 0x01
177#define DAC8_CTRL_UPD_AN_OUT_SIMULTANEOUS_UPDATE 0x02
178#define DAC8_CTRL_UPD_AN_OUT_BROADCAST_UPDATE 0x03
179#define DAC8_CTRL_UPD_AN_OUT_BIT_MASK 0x03
180
181#define DAC8_DAC_SEL_CH_A 0x00
182#define DAC8_DAC_SEL_CH_B 0x01
183#define DAC8_DAC_SEL_CH_C 0x02
184#define DAC8_DAC_SEL_CH_D 0x03
185#define DAC8_DAC_SEL_ALL_CH_BROADCAST 0x30
186#define DAC8_DAC_SEL_CH_BIT_MASK 0x03
187
188#define DAC8_PWR_MODE_POWER_UP 0x00
189#define DAC8_PWR_MODE_POWER_DOWN_OUT_HIGH_IMPEDANCE 0x09
190#define DAC8_PWR_MODE_POWER_DOWN_OUT_TYP_1K_TO_GND 0x0B
191#define DAC8_PWR_MODE_POWER_DOWN_OUT_TYP_100K_TO_GND 0x0D
192#define DAC8_PWR_MODE_POWER_DOWN_OUT_HIGH_IMPEDANCES 0x0F
193#define DAC8_PWR_UP_MODE_BIT_MASK 0x01
194#define DAC8_PWR_DOWN_MODE_BIT_MASK 0x0E
195
196#define DAC8_24_BIT_BIT_MASK 0x00FFFFFF
197
198#define DAC8_DAC_OUT_DATA_MIN 0x0000
199#define DAC8_DAC_OUT_DATA_MAX 0x0FFF
200
201#define DAC8_LDAC_LOW 0x00
202#define DAC8_LDAC_HIGH 0x01
203
204#define DAC8_DAC8554_ENABLE 0x00
205#define DAC8_DAC8554_DISABLE 0x01
207 // End group macro
208// --------------------------------------------------------------- PUBLIC TYPES
217typedef uint8_t dac8_select_t;
218
222typedef void ( *dac8_master_io_t )( struct dac8_s*, uint8_t, uint8_t*, uint8_t );
223
227typedef struct dac8_s
228{
229 // Modules
230
231 i2c_master_t i2c;
232 spi_master_t spi;
233
234 // Output pins
235
236 digital_out_t cs;
237 digital_out_t pwm;
238 digital_out_t rst;
239
240 // ctx variable
241
243 pin_name_t chip_select;
247
249
253typedef struct
254{
255 // Communication gpio pins
256
257 pin_name_t scl;
258 pin_name_t sda;
259 pin_name_t miso;
260 pin_name_t mosi;
261 pin_name_t sck;
262 pin_name_t cs;
263
264 // Additional gpio pins
265
266 pin_name_t pwm;
267 pin_name_t rst;
268
269 // static variable
270
271 uint32_t i2c_speed;
272 uint8_t i2c_address;
273
274 uint32_t spi_speed;
275 spi_master_mode_t spi_mode;
276 spi_master_chip_select_polarity_t cs_polarity;
277
279
280} dac8_cfg_t;
281
282typedef struct
283{
284 uint8_t addr;
286 uint8_t dac_sel;
287 uint8_t pwr_mode;
288 uint16_t dac_val;
289}
291
292 // End types group
293// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
299#ifdef __cplusplus
300extern "C"{
301#endif
302
313
322DAC8_RETVAL dac8_init ( dac8_t *ctx, dac8_cfg_t *cfg, uint8_t master_mode );
323
334void dac8_generic_write ( dac8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
335
346void dac8_generic_read ( dac8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
347
368DAC8_RETVAL dac8_enable_sync ( dac8_t *ctx, uint8_t en_sync );
369
395DAC8_RETVAL dac8_set_config ( dac8_t *ctx, uint16_t en_ref_pwdwn, uint16_t en_dac_pwdwn );
396
423DAC8_RETVAL dac8_set_gain ( dac8_t *ctx, uint16_t en_ref_div, uint16_t en_buff_gain );
424
435
446
463uint8_t dac8_get_ref_alarm ( dac8_t *ctx );
464
482DAC8_RETVAL dac8_set_vref ( dac8_t *ctx, uint16_t vref_mv );
483
499void dac8_device_enable ( dac8_t *ctx, uint8_t en_sel );
500
515void dac8_set_ldac ( dac8_t *ctx, uint8_t ldac_sel );
516
527void dac8_load_dac ( dac8_t *ctx );
528
540void dac8_generic_spi_write ( dac8_t *ctx, uint32_t tx_data );
541
553
554#ifdef __cplusplus
555}
556#endif
557#endif // _DAC8_H_
558
559 // End public_function group
561
562// ------------------------------------------------------------------------- END
#define DAC8_RETVAL
Definition dac8.h:91
void dac8_soft_reset(dac8_t *ctx)
Set reset function.
void dac8_cfg_setup(dac8_cfg_t *cfg)
Config Object Initialization function.
uint8_t dac8_get_ref_alarm(dac8_t *ctx)
Get ref alarm function.
DAC8_RETVAL dac8_set_vref(dac8_t *ctx, uint16_t vref_mv)
Set vref function.
DAC8_RETVAL dac8_set_gain(dac8_t *ctx, uint16_t en_ref_div, uint16_t en_buff_gain)
Set gain function.
DAC8_RETVAL dac8_enable_sync(dac8_t *ctx, uint8_t en_sync)
Enable synchronous function.
void dac8_set_synchronously_load(dac8_t *ctx)
Set synchronously load function.
void dac8_generic_read(dac8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void dac8_device_config(dac8_t *ctx, dac8_cfg_data_t cfg_data)
Set device config function.
void dac8_load_dac(dac8_t *ctx)
Load DAC function.
DAC8_RETVAL dac8_set_config(dac8_t *ctx, uint16_t en_ref_pwdwn, uint16_t en_dac_pwdwn)
Set config function.
void dac8_generic_write(dac8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void dac8_set_ldac(dac8_t *ctx, uint8_t ldac_sel)
Set LDAC function.
void dac8_generic_spi_write(dac8_t *ctx, uint32_t tx_data)
Generic SPI write function.
DAC8_RETVAL dac8_init(dac8_t *ctx, dac8_cfg_t *cfg, uint8_t master_mode)
Initialization function.
void dac8_device_enable(dac8_t *ctx, uint8_t en_sel)
Device enable function.
uint8_t dac8_select_t
Communication type.
Definition dac8.h:217
struct dac8_s dac8_t
Click ctx object definition.
void(* dac8_master_io_t)(struct dac8_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition dac8.h:222
Definition dac8.h:283
uint8_t dac_sel
Definition dac8.h:286
uint8_t ctrl_upd_an_out
Definition dac8.h:285
uint16_t dac_val
Definition dac8.h:288
uint8_t pwr_mode
Definition dac8.h:287
uint8_t addr
Definition dac8.h:284
Click configuration structure definition.
Definition dac8.h:254
dac8_select_t sel
Definition dac8.h:278
uint32_t i2c_speed
Definition dac8.h:271
spi_master_chip_select_polarity_t cs_polarity
Definition dac8.h:276
pin_name_t sck
Definition dac8.h:261
spi_master_mode_t spi_mode
Definition dac8.h:275
pin_name_t mosi
Definition dac8.h:260
uint32_t spi_speed
Definition dac8.h:274
pin_name_t scl
Definition dac8.h:257
pin_name_t pwm
Definition dac8.h:266
pin_name_t miso
Definition dac8.h:259
pin_name_t sda
Definition dac8.h:258
pin_name_t rst
Definition dac8.h:267
pin_name_t cs
Definition dac8.h:262
uint8_t i2c_address
Definition dac8.h:272
Click ctx object definition.
Definition dac8.h:228
digital_out_t cs
Definition dac8.h:236
dac8_master_io_t write_f
Definition dac8.h:244
spi_master_t spi
Definition dac8.h:232
dac8_master_io_t read_f
Definition dac8.h:245
dac8_select_t master_sel
Definition dac8.h:246
digital_out_t pwm
Definition dac8.h:237
i2c_master_t i2c
Definition dac8.h:231
digital_out_t rst
Definition dac8.h:238
uint8_t slave_address
Definition dac8.h:242
pin_name_t chip_select
Definition dac8.h:243