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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_spi_master.h"
39 #include "spi_specifics.h"
40 
61 #define DAC9_REG_NOOP 0x00
62 #define DAC9_REG_DEVID 0x01
63 #define DAC9_REG_SYNC 0x02
64 #define DAC9_REG_CONFIG 0x03
65 #define DAC9_REG_GAIN 0x04
66 #define DAC9_REG_TRIGGER 0x05
67 #define DAC9_REG_STATUS 0x07
68 #define DAC9_REG_DAC 0x08
69  // dac9_reg
71 
86 #define DAC9_SYNC_DISABLE 0x0000
87 #define DAC9_SYNC_ENABLE 0x0001
88 
89 #define DAC9_CONFIG_REF_PWDWN_ENABLE 0x0000
90 #define DAC9_CONFIG_REF_PWDWN_DISABLE 0x0100
91 #define DAC9_CONFIG_REF_PWDWN_BIT_MASK 0x0100
92 #define DAC9_CONFIG_DAC_PWDWN_DISABLE 0x0000
93 #define DAC9_CONFIG_DAC_PWDWN_ENABLE 0x0001
94 #define DAC9_CONFIG_DAC_PWDWN_BIT_MASK 0x0001
95 
96 #define DAC9_GAIN_REF_DIV_DISABLE 0x0000
97 #define DAC9_GAIN_REF_DIV_2 0x0100
98 #define DAC9_GAIN_REF_DIV_BIT_MASK 0x0100
99 #define DAC9_GAIN_BUFF_GAIN_1 0x0000
100 #define DAC9_GAIN_BUFF_GAIN_2 0x0001
101 #define DAC9_GAIN_BUFF_GAIN_BIT_MASK 0x0001
102 
103 #define DAC9_TRIGGER_LDAC 0x0010
104 #define DAC9_TRIGGER_SOFT_RESET 0x000A
105 
106 #define DAC9_STATUS_REF_ALARM_BIT_MASK 0x0001
107 
113 #define DAC9_I2C_ADR_AGND 0x48
114 #define DAC9_I2C_ADR_VDD 0x49
115 #define DAC9_I2C_ADR_SDA 0x4A
116 #define DAC9_I2C_ADR_SCL 0x4B
117 
126 #define DAC9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
127 #define DAC9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
128  // dac9_set
130 
145 #define DAC9_MAP_MIKROBUS( cfg, mikrobus ) \
146  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
147  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
148  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
149  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
150  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
151  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
152  // dac9_map // dac9
155 
160 typedef enum
161 {
166 
171 typedef err_t ( *dac9_master_io_t )( struct dac9_s*, uint8_t, uint8_t*, uint8_t );
177 typedef struct dac9_s
178 {
179  i2c_master_t i2c;
180  spi_master_t spi;
182  uint8_t slave_address;
183  pin_name_t chip_select;
190 
195 typedef struct
196 {
197  pin_name_t scl;
198  pin_name_t sda;
199  pin_name_t miso;
200  pin_name_t mosi;
201  pin_name_t sck;
202  pin_name_t cs;
204  uint32_t i2c_speed;
205  uint8_t i2c_address;
207  uint32_t spi_speed;
208  spi_master_mode_t spi_mode;
209  spi_master_chip_select_polarity_t cs_polarity;
213 } dac9_cfg_t;
214 
219 typedef enum
220 {
221  DAC9_OK = 0,
222  DAC9_ERROR = -1
223 
225 
242 
258 
273 err_t dac9_init ( dac9_t *ctx, dac9_cfg_t *cfg );
274 
290 err_t dac9_generic_write ( dac9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
291 
307 err_t dac9_generic_read ( dac9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
308 
320 err_t dac9_enable_sync ( dac9_t *ctx, uint8_t en_sync );
321 
334 err_t dac9_set_config ( dac9_t *ctx, uint16_t en_ref_pwdwn, uint16_t en_dac_pwdwn );
335 
348 err_t dac9_set_gain ( dac9_t *ctx, uint16_t en_ref_div, uint16_t en_buff_gain );
349 
359 
367 void dac9_soft_reset ( dac9_t *ctx );
368 
379 uint8_t dac9_get_ref_alarm ( dac9_t *ctx );
380 
393 err_t dac9_set_vout ( dac9_t *ctx, uint16_t vout_mv );
394 
395 #ifdef __cplusplus
396 }
397 #endif
398 #endif // DAC9_H
399  // dac9
401 
402 // ------------------------------------------------------------------------ END
dac9_set_vout
err_t dac9_set_vout(dac9_t *ctx, uint16_t vout_mv)
Set Vout function.
dac9_cfg_setup
void dac9_cfg_setup(dac9_cfg_t *cfg)
DAC 9 configuration object setup function.
dac9_cfg_t::scl
pin_name_t scl
Definition: dac9.h:197
dac9_s::chip_select
pin_name_t chip_select
Definition: dac9.h:183
DAC9_OK
@ DAC9_OK
Definition: dac9.h:221
dac9_drv_t
dac9_drv_t
DAC 9 Click driver selector.
Definition: dac9.h:161
dac9_cfg_t
DAC 9 Click configuration object.
Definition: dac9.h:196
dac9_init
err_t dac9_init(dac9_t *ctx, dac9_cfg_t *cfg)
DAC 9 initialization function.
DAC9_ERROR
@ DAC9_ERROR
Definition: dac9.h:222
dac9_set_synchronously_load
void dac9_set_synchronously_load(dac9_t *ctx)
Set synchronously load function.
dac9_enable_sync
err_t dac9_enable_sync(dac9_t *ctx, uint8_t en_sync)
Enable synchronous function.
dac9_set_gain
err_t dac9_set_gain(dac9_t *ctx, uint16_t en_ref_div, uint16_t en_buff_gain)
Set gain function.
dac9_s::write_f
dac9_master_io_t write_f
Definition: dac9.h:186
spi_specifics.h
This file contains SPI specific macros, functions, etc.
DAC9_DRV_SEL_I2C
@ DAC9_DRV_SEL_I2C
Definition: dac9.h:163
dac9_soft_reset
void dac9_soft_reset(dac9_t *ctx)
Set reset function.
dac9_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac9.h:207
dac9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac9.h:209
dac9_set_config
err_t dac9_set_config(dac9_t *ctx, uint16_t en_ref_pwdwn, uint16_t en_dac_pwdwn)
Set config function.
dac9_s::drv_sel
dac9_drv_t drv_sel
Definition: dac9.h:184
dac9_get_ref_alarm
uint8_t dac9_get_ref_alarm(dac9_t *ctx)
Get ref alarm function.
DAC9_DRV_SEL_SPI
@ DAC9_DRV_SEL_SPI
Definition: dac9.h:162
dac9_s::i2c
i2c_master_t i2c
Definition: dac9.h:179
dac9_cfg_t::i2c_address
uint8_t i2c_address
Definition: dac9.h:205
dac9_cfg_t::miso
pin_name_t miso
Definition: dac9.h:199
dac9_s::slave_address
uint8_t slave_address
Definition: dac9.h:182
dac9_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac9.h:208
dac9_s
DAC 9 Click context object.
Definition: dac9.h:178
dac9_cfg_t::cs
pin_name_t cs
Definition: dac9.h:202
dac9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dac9.h:204
dac9_cfg_t::sda
pin_name_t sda
Definition: dac9.h:198
dac9_master_io_t
err_t(* dac9_master_io_t)(struct dac9_s *, uint8_t, uint8_t *, uint8_t)
DAC 9 Click driver interface.
Definition: dac9.h:171
dac9_generic_read
err_t dac9_generic_read(dac9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
DAC 9 data reading function.
dac9_cfg_t::mosi
pin_name_t mosi
Definition: dac9.h:200
dac9_s::read_f
dac9_master_io_t read_f
Definition: dac9.h:187
dac9_drv_interface_selection
void dac9_drv_interface_selection(dac9_cfg_t *cfg, dac9_drv_t drv_sel)
DAC 9 driver interface setup function.
dac9_cfg_t::drv_sel
dac9_drv_t drv_sel
Definition: dac9.h:211
dac9_return_value_t
dac9_return_value_t
DAC 9 Click return value data.
Definition: dac9.h:220
dac9_cfg_t::sck
pin_name_t sck
Definition: dac9.h:201
dac9_generic_write
err_t dac9_generic_write(dac9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
DAC 9 data writing function.
dac9_t
struct dac9_s dac9_t
DAC 9 Click context object.
dac9_s::spi
spi_master_t spi
Definition: dac9.h:180