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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_spi_master.h"
49 #include "spi_specifics.h"
50 
71 #define DAC9_REG_NOOP 0x00
72 #define DAC9_REG_DEVID 0x01
73 #define DAC9_REG_SYNC 0x02
74 #define DAC9_REG_CONFIG 0x03
75 #define DAC9_REG_GAIN 0x04
76 #define DAC9_REG_TRIGGER 0x05
77 #define DAC9_REG_STATUS 0x07
78 #define DAC9_REG_DAC 0x08
79  // dac9_reg
81 
96 #define DAC9_SYNC_DISABLE 0x0000
97 #define DAC9_SYNC_ENABLE 0x0001
98 
99 #define DAC9_CONFIG_REF_PWDWN_ENABLE 0x0000
100 #define DAC9_CONFIG_REF_PWDWN_DISABLE 0x0100
101 #define DAC9_CONFIG_REF_PWDWN_BIT_MASK 0x0100
102 #define DAC9_CONFIG_DAC_PWDWN_DISABLE 0x0000
103 #define DAC9_CONFIG_DAC_PWDWN_ENABLE 0x0001
104 #define DAC9_CONFIG_DAC_PWDWN_BIT_MASK 0x0001
105 
106 #define DAC9_GAIN_REF_DIV_DISABLE 0x0000
107 #define DAC9_GAIN_REF_DIV_2 0x0100
108 #define DAC9_GAIN_REF_DIV_BIT_MASK 0x0100
109 #define DAC9_GAIN_BUFF_GAIN_1 0x0000
110 #define DAC9_GAIN_BUFF_GAIN_2 0x0001
111 #define DAC9_GAIN_BUFF_GAIN_BIT_MASK 0x0001
112 
113 #define DAC9_TRIGGER_LDAC 0x0010
114 #define DAC9_TRIGGER_SOFT_RESET 0x000A
115 
116 #define DAC9_STATUS_REF_ALARM_BIT_MASK 0x0001
117 
123 #define DAC9_I2C_ADR_AGND 0x48
124 #define DAC9_I2C_ADR_VDD 0x49
125 #define DAC9_I2C_ADR_SDA 0x4A
126 #define DAC9_I2C_ADR_SCL 0x4B
127 
136 #define DAC9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
137 #define DAC9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
138  // dac9_set
140 
155 #define DAC9_MAP_MIKROBUS( cfg, mikrobus ) \
156  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
157  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
158  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
159  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
160  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
161  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
162  // dac9_map // dac9
165 
170 typedef enum
171 {
176 
181 typedef err_t ( *dac9_master_io_t )( struct dac9_s*, uint8_t, uint8_t*, uint8_t );
187 typedef struct dac9_s
188 {
189  i2c_master_t i2c;
190  spi_master_t spi;
192  uint8_t slave_address;
193  pin_name_t chip_select;
200 
205 typedef struct
206 {
207  pin_name_t scl;
208  pin_name_t sda;
209  pin_name_t miso;
210  pin_name_t mosi;
211  pin_name_t sck;
212  pin_name_t cs;
214  uint32_t i2c_speed;
215  uint8_t i2c_address;
217  uint32_t spi_speed;
218  spi_master_mode_t spi_mode;
219  spi_master_chip_select_polarity_t cs_polarity;
223 } dac9_cfg_t;
224 
229 typedef enum
230 {
231  DAC9_OK = 0,
232  DAC9_ERROR = -1
233 
235 
252 
268 
283 err_t dac9_init ( dac9_t *ctx, dac9_cfg_t *cfg );
284 
300 err_t dac9_generic_write ( dac9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
301 
317 err_t dac9_generic_read ( dac9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
318 
330 err_t dac9_enable_sync ( dac9_t *ctx, uint8_t en_sync );
331 
344 err_t dac9_set_config ( dac9_t *ctx, uint16_t en_ref_pwdwn, uint16_t en_dac_pwdwn );
345 
358 err_t dac9_set_gain ( dac9_t *ctx, uint16_t en_ref_div, uint16_t en_buff_gain );
359 
369 
377 void dac9_soft_reset ( dac9_t *ctx );
378 
389 uint8_t dac9_get_ref_alarm ( dac9_t *ctx );
390 
403 err_t dac9_set_vout ( dac9_t *ctx, uint16_t vout_mv );
404 
405 #ifdef __cplusplus
406 }
407 #endif
408 #endif // DAC9_H
409  // dac9
411 
412 // ------------------------------------------------------------------------ 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:207
dac9_s::chip_select
pin_name_t chip_select
Definition: dac9.h:193
DAC9_OK
@ DAC9_OK
Definition: dac9.h:231
dac9_drv_t
dac9_drv_t
DAC 9 Click driver selector.
Definition: dac9.h:171
dac9_cfg_t
DAC 9 Click configuration object.
Definition: dac9.h:206
dac9_init
err_t dac9_init(dac9_t *ctx, dac9_cfg_t *cfg)
DAC 9 initialization function.
DAC9_ERROR
@ DAC9_ERROR
Definition: dac9.h:232
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:196
spi_specifics.h
This file contains SPI specific macros, functions, etc.
DAC9_DRV_SEL_I2C
@ DAC9_DRV_SEL_I2C
Definition: dac9.h:173
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:217
dac9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac9.h:219
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:194
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:172
dac9_s::i2c
i2c_master_t i2c
Definition: dac9.h:189
dac9_cfg_t::i2c_address
uint8_t i2c_address
Definition: dac9.h:215
dac9_cfg_t::miso
pin_name_t miso
Definition: dac9.h:209
dac9_s::slave_address
uint8_t slave_address
Definition: dac9.h:192
dac9_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac9.h:218
dac9_s
DAC 9 Click context object.
Definition: dac9.h:188
dac9_cfg_t::cs
pin_name_t cs
Definition: dac9.h:212
dac9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dac9.h:214
dac9_cfg_t::sda
pin_name_t sda
Definition: dac9.h:208
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:181
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:210
dac9_s::read_f
dac9_master_io_t read_f
Definition: dac9.h:197
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:221
dac9_return_value_t
dac9_return_value_t
DAC 9 Click return value data.
Definition: dac9.h:230
dac9_cfg_t::sck
pin_name_t sck
Definition: dac9.h:211
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:190