dac7  2.0.0.0
dac7.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 DAC7_H
36 #define DAC7_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_spi_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define DAC7_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
63  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
64  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
65  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
66 
72 #define DAC7_RETVAL uint8_t
73 #define DAC7_RETVAL_T uint8_t
74 
75 #define DAC7_OK 0x00
76 #define DAC7_INIT_ERROR 0xFF
77 
78 #define DAC7_ERROR 0x00
79 #define DAC7_SUCCESS 0x01
80 
86 #define DAC7_COMMAND_WRITE_INPUT_REGISTER 0x00
87 #define DAC7_COMMAND_UPDATE_DAC_REGISTER 0x08
88 #define DAC7_COMMAND_WRITE_INPUT_REGISTER_UPDATE_ALL 0x10
89 #define DAC7_COMMAND_WRITE_UPDATE_CHANNEL 0x18
90 #define DAC7_COMMAND_POWER_UPDOWN 0x20
91 #define DAC7_COMMAND_RESET 0x28
92 #define DAC7_COMMAND_SET_LDAC 0x30
93 #define DAC7_COMMAND_REFERENCE_ONOFF 0x38
94 
101 #define DAC7_ADDRESS_CHANNEL_A 0x00
102 #define DAC7_ADDRESS_CHANNEL_B 0x01
103 #define DAC7_ADDRESS_CHANNEL_C 0x02
104 #define DAC7_ADDRESS_CHANNEL_D 0x03
105 #define DAC7_ADDRESS_CHANNEL_ALL 0x07
106 
112 #define DAC7_SELECT_CHANNEL_A 0x01
113 #define DAC7_SELECT_CHANNEL_B 0x02
114 #define DAC7_SELECT_CHANNEL_C 0x04
115 #define DAC7_SELECT_CHANNEL_D 0x08
116 #define DAC7_SELECT_CHANNEL_ALL 0x0F
117 
123 #define DAC7_SET_MODE_INPUT 0x00
124 #define DAC7_SET_MODE_INPUT_DAC 0x18
125 #define DAC7_SET_MODE_INPUT_DAC_ALL 0x10
126 
132 #define DAC7_PWR_MODE_NORMAL 0x00
133 #define DAC7_PWR_MODE_POWERDOWN_1K 0x10
134 #define DAC7_PWR_MODE_POWERDOWN_100K 0x20
135 #define DAC7_PWR_MODE_TRISTATE 0x30
136 
142 #define DAC7_PWR_ON_DISABLE 0x00
143 #define DAC7_PWR_ON_ENABLE 0x01
144 
150 #define DAC7_SW_RST_COMMAND 0x01
151 
157 #define DAC7_DONT_CARE_COMMAND 0x00
158 
164 #define DAC7_MASK_BIT_COMMAND 0x38
165 #define DAC7_MASK_BIT_ADDRESS 0x07
166 #define DAC7_MASK_BIT_POWERMODE 0x30
167 #define DAC7_MASK_BIT_SEL_CHANNEL 0x0F
168 #define DAC7_MASK_BIT_0 0x01
169 #define DAC7_MASK_BIT_LBS 0x00FF
170 
176 #define DAC7_VREF_4096mV 0x1000
177 #define DAC7_VREF_5000mV 0x13BA
178  // End group macro
181 
182 // --------------------------------------------------------------- PUBLIC TYPES
191 typedef struct
192 {
193  // Modules
194  spi_master_t spi;
195  pin_name_t chip_select;
196 
197 } dac7_t;
198 
202 typedef struct
203 {
204  // Communication gpio pins
205 
206  pin_name_t miso;
207  pin_name_t mosi;
208  pin_name_t sck;
209  pin_name_t cs;
210 
211  // static variable
212 
213  uint32_t spi_speed;
214  spi_master_mode_t spi_mode;
215  spi_master_chip_select_polarity_t cs_polarity;
216 
217 } dac7_cfg_t;
218  // End types group
220 
221 // ------------------------------------------------------------------ CONSTANTS // End constants group
229 
230 // ------------------------------------------------------------------ VARIABLES // End variable group
238 
239 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
244 #ifdef __cplusplus
245 extern "C"{
246 #endif
247 
257 
267 
279 void dac7_write_data ( dac7_t *ctx, uint8_t def_cmd, uint8_t addr_cmd, uint16_t write_data );
280 
301 DAC7_RETVAL_T dac7_set_channel ( dac7_t *ctx, uint8_t set_cmd, uint8_t addr_ch, uint16_t write_data );
302 
323 DAC7_RETVAL_T dac7_set_ch_voltage ( dac7_t *ctx, uint8_t addr_ch, uint16_t vol_val, uint16_t v_ref_mv );
324 
344 DAC7_RETVAL_T dac7_update_channel ( dac7_t *ctx, uint8_t addr_ch, uint16_t ch_data );
345 
365 DAC7_RETVAL_T dac7_set_power ( dac7_t *ctx, uint8_t pwr_en, uint8_t sel_ch );
366 
385 
404 DAC7_RETVAL_T dac7_set_ldac ( dac7_t *ctx, uint8_t sel_ch );
405 
424 DAC7_RETVAL_T dac7_set_internal_reference ( dac7_t *ctx, uint8_t int_ref_en );
425 
426 #ifdef __cplusplus
427 }
428 #endif
429 #endif // _DAC7_H_
430  // End public_function group
433 
434 // ------------------------------------------------------------------------- END
dac7_cfg_t::miso
pin_name_t miso
Definition: dac7.h:206
dac7_t
Click ctx object definition.
Definition: dac7.h:192
dac7_write_data
void dac7_write_data(dac7_t *ctx, uint8_t def_cmd, uint8_t addr_cmd, uint16_t write_data)
Generic write data function.
dac7_sw_reset
DAC7_RETVAL_T dac7_sw_reset(dac7_t *ctx)
Software reset function.
dac7_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac7.h:213
dac7_cfg_t
Click configuration structure definition.
Definition: dac7.h:203
dac7_set_ldac
DAC7_RETVAL_T dac7_set_ldac(dac7_t *ctx, uint8_t sel_ch)
Set LDAC setup function.
dac7_t::chip_select
pin_name_t chip_select
Definition: dac7.h:195
dac7_cfg_t::sck
pin_name_t sck
Definition: dac7.h:208
dac7_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac7.h:215
dac7_set_ch_voltage
DAC7_RETVAL_T dac7_set_ch_voltage(dac7_t *ctx, uint8_t addr_ch, uint16_t vol_val, uint16_t v_ref_mv)
Set the voltage values of the specified channel function.
dac7_set_channel
DAC7_RETVAL_T dac7_set_channel(dac7_t *ctx, uint8_t set_cmd, uint8_t addr_ch, uint16_t write_data)
Set the values of the specified channel function.
dac7_init
DAC7_RETVAL dac7_init(dac7_t *ctx, dac7_cfg_t *cfg)
Initialization function.
dac7_update_channel
DAC7_RETVAL_T dac7_update_channel(dac7_t *ctx, uint8_t addr_ch, uint16_t ch_data)
Update channel function.
DAC7_RETVAL_T
#define DAC7_RETVAL_T
Definition: dac7.h:73
dac7_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac7.h:214
dac7_cfg_setup
void dac7_cfg_setup(dac7_cfg_t *cfg)
Config Object Initialization function.
dac7_set_power
DAC7_RETVAL_T dac7_set_power(dac7_t *ctx, uint8_t pwr_en, uint8_t sel_ch)
Set power mode function.
dac7_cfg_t::mosi
pin_name_t mosi
Definition: dac7.h:207
dac7_set_internal_reference
DAC7_RETVAL_T dac7_set_internal_reference(dac7_t *ctx, uint8_t int_ref_en)
Set internal reference function.
DAC7_RETVAL
#define DAC7_RETVAL
Definition: dac7.h:72
dac7_cfg_t::cs
pin_name_t cs
Definition: dac7.h:209
dac7_t::spi
spi_master_t spi
Definition: dac7.h:194