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 
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  // 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  // 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  // dac9_map // dac9
169 
174 typedef enum
175 {
180 
185 typedef err_t ( *dac9_master_io_t )( struct dac9_s*, uint8_t, uint8_t*, uint8_t );
191 typedef struct dac9_s
192 {
193  i2c_master_t i2c;
194  spi_master_t spi;
196  uint8_t slave_address;
197  pin_name_t chip_select;
204 
209 typedef 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 
233 typedef enum
234 {
235  DAC9_OK = 0,
236  DAC9_ERROR = -1
237 
239 
256 
272 
287 err_t dac9_init ( dac9_t *ctx, dac9_cfg_t *cfg );
288 
304 err_t dac9_generic_write ( dac9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
305 
321 err_t dac9_generic_read ( dac9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
322 
334 err_t dac9_enable_sync ( dac9_t *ctx, uint8_t en_sync );
335 
348 err_t dac9_set_config ( dac9_t *ctx, uint16_t en_ref_pwdwn, uint16_t en_dac_pwdwn );
349 
362 err_t dac9_set_gain ( dac9_t *ctx, uint16_t en_ref_div, uint16_t en_buff_gain );
363 
373 
381 void dac9_soft_reset ( dac9_t *ctx );
382 
393 uint8_t dac9_get_ref_alarm ( dac9_t *ctx );
394 
407 err_t dac9_set_vout ( dac9_t *ctx, uint16_t vout_mv );
408 
409 #ifdef __cplusplus
410 }
411 #endif
412 #endif // DAC9_H
413  // dac9
415 
416 // ------------------------------------------------------------------------ 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:211
dac9_s::chip_select
pin_name_t chip_select
Definition: dac9.h:197
DAC9_OK
@ DAC9_OK
Definition: dac9.h:235
dac9_drv_t
dac9_drv_t
DAC 9 Click driver selector.
Definition: dac9.h:175
dac9_cfg_t
DAC 9 Click configuration object.
Definition: dac9.h:210
dac9_init
err_t dac9_init(dac9_t *ctx, dac9_cfg_t *cfg)
DAC 9 initialization function.
DAC9_ERROR
@ DAC9_ERROR
Definition: dac9.h:236
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:200
spi_specifics.h
This file contains SPI specific macros, functions, etc.
DAC9_DRV_SEL_I2C
@ DAC9_DRV_SEL_I2C
Definition: dac9.h:177
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:221
dac9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac9.h:223
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:198
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:176
dac9_s::i2c
i2c_master_t i2c
Definition: dac9.h:193
dac9_cfg_t::i2c_address
uint8_t i2c_address
Definition: dac9.h:219
dac9_cfg_t::miso
pin_name_t miso
Definition: dac9.h:213
dac9_s::slave_address
uint8_t slave_address
Definition: dac9.h:196
dac9_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac9.h:222
dac9_s
DAC 9 Click context object.
Definition: dac9.h:192
dac9_cfg_t::cs
pin_name_t cs
Definition: dac9.h:216
dac9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dac9.h:218
dac9_cfg_t::sda
pin_name_t sda
Definition: dac9.h:212
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:185
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:214
dac9_s::read_f
dac9_master_io_t read_f
Definition: dac9.h:201
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:225
dac9_return_value_t
dac9_return_value_t
DAC 9 Click return value data.
Definition: dac9.h:234
dac9_cfg_t::sck
pin_name_t sck
Definition: dac9.h:215
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:194