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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_spi_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
65#define DAC7_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
67 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
68 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
69 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
76#define DAC7_RETVAL uint8_t
77#define DAC7_RETVAL_T uint8_t
78
79#define DAC7_OK 0x00
80#define DAC7_INIT_ERROR 0xFF
81
82#define DAC7_ERROR 0x00
83#define DAC7_SUCCESS 0x01
90#define DAC7_COMMAND_WRITE_INPUT_REGISTER 0x00
91#define DAC7_COMMAND_UPDATE_DAC_REGISTER 0x08
92#define DAC7_COMMAND_WRITE_INPUT_REGISTER_UPDATE_ALL 0x10
93#define DAC7_COMMAND_WRITE_UPDATE_CHANNEL 0x18
94#define DAC7_COMMAND_POWER_UPDOWN 0x20
95#define DAC7_COMMAND_RESET 0x28
96#define DAC7_COMMAND_SET_LDAC 0x30
97#define DAC7_COMMAND_REFERENCE_ONOFF 0x38
98
105#define DAC7_ADDRESS_CHANNEL_A 0x00
106#define DAC7_ADDRESS_CHANNEL_B 0x01
107#define DAC7_ADDRESS_CHANNEL_C 0x02
108#define DAC7_ADDRESS_CHANNEL_D 0x03
109#define DAC7_ADDRESS_CHANNEL_ALL 0x07
116#define DAC7_SELECT_CHANNEL_A 0x01
117#define DAC7_SELECT_CHANNEL_B 0x02
118#define DAC7_SELECT_CHANNEL_C 0x04
119#define DAC7_SELECT_CHANNEL_D 0x08
120#define DAC7_SELECT_CHANNEL_ALL 0x0F
127#define DAC7_SET_MODE_INPUT 0x00
128#define DAC7_SET_MODE_INPUT_DAC 0x18
129#define DAC7_SET_MODE_INPUT_DAC_ALL 0x10
136#define DAC7_PWR_MODE_NORMAL 0x00
137#define DAC7_PWR_MODE_POWERDOWN_1K 0x10
138#define DAC7_PWR_MODE_POWERDOWN_100K 0x20
139#define DAC7_PWR_MODE_TRISTATE 0x30
146#define DAC7_PWR_ON_DISABLE 0x00
147#define DAC7_PWR_ON_ENABLE 0x01
154#define DAC7_SW_RST_COMMAND 0x01
161#define DAC7_DONT_CARE_COMMAND 0x00
168#define DAC7_MASK_BIT_COMMAND 0x38
169#define DAC7_MASK_BIT_ADDRESS 0x07
170#define DAC7_MASK_BIT_POWERMODE 0x30
171#define DAC7_MASK_BIT_SEL_CHANNEL 0x0F
172#define DAC7_MASK_BIT_0 0x01
173#define DAC7_MASK_BIT_LBS 0x00FF
180#define DAC7_VREF_4096mV 0x1000
181#define DAC7_VREF_5000mV 0x13BA
184 // End group macro
185
186// --------------------------------------------------------------- PUBLIC TYPES
195typedef struct
196{
197 // Modules
198 spi_master_t spi;
199 pin_name_t chip_select;
200
201} dac7_t;
202
206typedef struct
207{
208 // Communication gpio pins
209
210 pin_name_t miso;
211 pin_name_t mosi;
212 pin_name_t sck;
213 pin_name_t cs;
214
215 // static variable
216
217 uint32_t spi_speed;
218 spi_master_mode_t spi_mode;
219 spi_master_chip_select_polarity_t cs_polarity;
220
221} dac7_cfg_t;
222
223 // End types group
224
225// ------------------------------------------------------------------ CONSTANTS
232 // End constants group
233
234// ------------------------------------------------------------------ VARIABLES
241 // End variable group
242
243// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
248#ifdef __cplusplus
249extern "C"{
250#endif
251
261
271
283void dac7_write_data ( dac7_t *ctx, uint8_t def_cmd, uint8_t addr_cmd, uint16_t write_data );
284
305DAC7_RETVAL_T dac7_set_channel ( dac7_t *ctx, uint8_t set_cmd, uint8_t addr_ch, uint16_t write_data );
306
327DAC7_RETVAL_T dac7_set_ch_voltage ( dac7_t *ctx, uint8_t addr_ch, uint16_t vol_val, uint16_t v_ref_mv );
328
348DAC7_RETVAL_T dac7_update_channel ( dac7_t *ctx, uint8_t addr_ch, uint16_t ch_data );
349
369DAC7_RETVAL_T dac7_set_power ( dac7_t *ctx, uint8_t pwr_en, uint8_t sel_ch );
370
389
408DAC7_RETVAL_T dac7_set_ldac ( dac7_t *ctx, uint8_t sel_ch );
409
429
430#ifdef __cplusplus
431}
432#endif
433#endif // _DAC7_H_
434
435 // End public_function group
437
438// ------------------------------------------------------------------------- END
#define DAC7_RETVAL
Definition dac7.h:76
#define DAC7_RETVAL_T
Definition dac7.h:77
DAC7_RETVAL_T dac7_set_ldac(dac7_t *ctx, uint8_t sel_ch)
Set LDAC setup function.
DAC7_RETVAL_T dac7_set_power(dac7_t *ctx, uint8_t pwr_en, uint8_t sel_ch)
Set power mode function.
void dac7_cfg_setup(dac7_cfg_t *cfg)
Config Object Initialization function.
DAC7_RETVAL_T dac7_update_channel(dac7_t *ctx, uint8_t addr_ch, uint16_t ch_data)
Update channel function.
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.
void dac7_write_data(dac7_t *ctx, uint8_t def_cmd, uint8_t addr_cmd, uint16_t write_data)
Generic write data function.
DAC7_RETVAL dac7_init(dac7_t *ctx, dac7_cfg_t *cfg)
Initialization function.
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_RETVAL_T dac7_set_internal_reference(dac7_t *ctx, uint8_t int_ref_en)
Set internal reference function.
DAC7_RETVAL_T dac7_sw_reset(dac7_t *ctx)
Software reset function.
Click configuration structure definition.
Definition dac7.h:207
spi_master_chip_select_polarity_t cs_polarity
Definition dac7.h:219
pin_name_t sck
Definition dac7.h:212
spi_master_mode_t spi_mode
Definition dac7.h:218
pin_name_t mosi
Definition dac7.h:211
uint32_t spi_speed
Definition dac7.h:217
pin_name_t miso
Definition dac7.h:210
pin_name_t cs
Definition dac7.h:213
Click ctx object definition.
Definition dac7.h:196
spi_master_t spi
Definition dac7.h:198
pin_name_t chip_select
Definition dac7.h:199