dac9 2.0.0.0
dac9.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef DAC9_H
29#define DAC9_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define DAC9_REG_NOOP 0x00
76#define DAC9_REG_DEVID 0x01
77#define DAC9_REG_SYNC 0x02
78#define DAC9_REG_CONFIG 0x03
79#define DAC9_REG_GAIN 0x04
80#define DAC9_REG_TRIGGER 0x05
81#define DAC9_REG_STATUS 0x07
82#define DAC9_REG_DAC 0x08
83
84 // dac9_reg
85
100#define DAC9_SYNC_DISABLE 0x0000
101#define DAC9_SYNC_ENABLE 0x0001
102
103#define DAC9_CONFIG_REF_PWDWN_ENABLE 0x0000
104#define DAC9_CONFIG_REF_PWDWN_DISABLE 0x0100
105#define DAC9_CONFIG_REF_PWDWN_BIT_MASK 0x0100
106#define DAC9_CONFIG_DAC_PWDWN_DISABLE 0x0000
107#define DAC9_CONFIG_DAC_PWDWN_ENABLE 0x0001
108#define DAC9_CONFIG_DAC_PWDWN_BIT_MASK 0x0001
109
110#define DAC9_GAIN_REF_DIV_DISABLE 0x0000
111#define DAC9_GAIN_REF_DIV_2 0x0100
112#define DAC9_GAIN_REF_DIV_BIT_MASK 0x0100
113#define DAC9_GAIN_BUFF_GAIN_1 0x0000
114#define DAC9_GAIN_BUFF_GAIN_2 0x0001
115#define DAC9_GAIN_BUFF_GAIN_BIT_MASK 0x0001
116
117#define DAC9_TRIGGER_LDAC 0x0010
118#define DAC9_TRIGGER_SOFT_RESET 0x000A
119
120#define DAC9_STATUS_REF_ALARM_BIT_MASK 0x0001
121
127#define DAC9_I2C_ADR_AGND 0x48
128#define DAC9_I2C_ADR_VDD 0x49
129#define DAC9_I2C_ADR_SDA 0x4A
130#define DAC9_I2C_ADR_SCL 0x4B
131
140#define DAC9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
141#define DAC9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
142
143 // dac9_set
144
159#define DAC9_MAP_MIKROBUS( cfg, mikrobus ) \
160 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
161 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
162 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
163 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
164 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
165 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
166
167 // dac9_map
168 // dac9
169
180
185typedef err_t ( *dac9_master_io_t )( struct dac9_s*, uint8_t, uint8_t*, uint8_t );
204
209typedef struct
210{
211 pin_name_t scl;
212 pin_name_t sda;
213 pin_name_t miso;
214 pin_name_t mosi;
215 pin_name_t sck;
216 pin_name_t cs;
218 uint32_t i2c_speed;
219 uint8_t i2c_address;
221 uint32_t spi_speed;
222 spi_master_mode_t spi_mode;
223 spi_master_chip_select_polarity_t cs_polarity;
227} dac9_cfg_t;
228
233typedef enum
234{
236 DAC9_ERROR = -1
237
239
256
272
287err_t dac9_init ( dac9_t *ctx, dac9_cfg_t *cfg );
288
304err_t dac9_generic_write ( dac9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
305
321err_t dac9_generic_read ( dac9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
322
334err_t dac9_enable_sync ( dac9_t *ctx, uint8_t en_sync );
335
348err_t dac9_set_config ( dac9_t *ctx, uint16_t en_ref_pwdwn, uint16_t en_dac_pwdwn );
349
362err_t dac9_set_gain ( dac9_t *ctx, uint16_t en_ref_div, uint16_t en_buff_gain );
363
373
382
393uint8_t dac9_get_ref_alarm ( dac9_t *ctx );
394
407err_t dac9_set_vout ( dac9_t *ctx, uint16_t vout_mv );
408
409#ifdef __cplusplus
410}
411#endif
412#endif // DAC9_H
413
414 // dac9
415
416// ------------------------------------------------------------------------ END
struct dac9_s dac9_t
DAC 9 Click context object.
dac9_drv_t
DAC 9 Click driver selector.
Definition dac9.h:175
@ DAC9_DRV_SEL_SPI
Definition dac9.h:176
@ DAC9_DRV_SEL_I2C
Definition dac9.h:177
dac9_return_value_t
DAC 9 Click return value data.
Definition dac9.h:234
@ DAC9_OK
Definition dac9.h:235
@ DAC9_ERROR
Definition dac9.h:236
err_t(* dac9_master_io_t)(struct dac9_s *, uint8_t, uint8_t *, uint8_t)
DAC 9 Click driver interface.
Definition dac9.h:185
void dac9_soft_reset(dac9_t *ctx)
Set reset function.
err_t dac9_generic_read(dac9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
DAC 9 data reading function.
err_t dac9_generic_write(dac9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
DAC 9 data writing function.
void dac9_drv_interface_selection(dac9_cfg_t *cfg, dac9_drv_t drv_sel)
DAC 9 driver interface setup function.
void dac9_cfg_setup(dac9_cfg_t *cfg)
DAC 9 configuration object setup function.
err_t dac9_set_config(dac9_t *ctx, uint16_t en_ref_pwdwn, uint16_t en_dac_pwdwn)
Set config function.
uint8_t dac9_get_ref_alarm(dac9_t *ctx)
Get ref alarm function.
void dac9_set_synchronously_load(dac9_t *ctx)
Set synchronously load function.
err_t dac9_set_vout(dac9_t *ctx, uint16_t vout_mv)
Set Vout function.
err_t dac9_init(dac9_t *ctx, dac9_cfg_t *cfg)
DAC 9 initialization function.
err_t dac9_enable_sync(dac9_t *ctx, uint8_t en_sync)
Enable synchronous function.
err_t dac9_set_gain(dac9_t *ctx, uint16_t en_ref_div, uint16_t en_buff_gain)
Set gain function.
This file contains SPI specific macros, functions, etc.
DAC 9 Click configuration object.
Definition dac9.h:210
dac9_drv_t drv_sel
Definition dac9.h:225
uint32_t i2c_speed
Definition dac9.h:218
spi_master_chip_select_polarity_t cs_polarity
Definition dac9.h:223
pin_name_t sck
Definition dac9.h:215
spi_master_mode_t spi_mode
Definition dac9.h:222
pin_name_t mosi
Definition dac9.h:214
uint32_t spi_speed
Definition dac9.h:221
pin_name_t scl
Definition dac9.h:211
pin_name_t miso
Definition dac9.h:213
pin_name_t sda
Definition dac9.h:212
pin_name_t cs
Definition dac9.h:216
uint8_t i2c_address
Definition dac9.h:219
DAC 9 Click context object.
Definition dac9.h:192
spi_master_t spi
Definition dac9.h:194
dac9_drv_t drv_sel
Definition dac9.h:198
dac9_master_io_t write_f
Definition dac9.h:200
i2c_master_t i2c
Definition dac9.h:193
uint8_t slave_address
Definition dac9.h:196
pin_name_t chip_select
Definition dac9.h:197
dac9_master_io_t read_f
Definition dac9.h:201