dac11 2.0.0.0
dac11.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 DAC11_H
29#define DAC11_H
30
31#ifdef __cplusplus
32extern "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_spi_master.h"
52#include "spi_specifics.h"
53
74#define DAC11_CMD_CHANNEL_A 0x00
75#define DAC11_CMD_CHANNEL_B 0x01
76#define DAC11_CMD_CHANNEL_C 0x02
77#define DAC11_CMD_CHANNEL_D 0x03
78#define DAC11_CMD_CHANNEL_E 0x04
79#define DAC11_CMD_CHANNEL_F 0x05
80#define DAC11_CMD_CHANNEL_G 0x06
81#define DAC11_CMD_CHANNEL_H 0x07
82#define DAC11_CMD_WRM 0x08
83#define DAC11_CMD_WTM 0x09
84#define DAC11_CMD_UPDATE_SELECT 0x0A
85#define DAC11_CMD_CHANNEL_A_WRITE 0x0B
86#define DAC11_CMD_BROADCAST 0x0C
87#define DAC11_CMD_PD_HIGH_Z 0x0D
88#define DAC11_CMD_PD_100KOHM 0x0E
89#define DAC11_CMD_PD_2p5KOHM 0x0F
90
91 // dac11_reg
92
107#define DAC11_SELECT_CHANNEL_A 0x01
108#define DAC11_SELECT_CHANNEL_B 0x02
109#define DAC11_SELECT_CHANNEL_C 0x04
110#define DAC11_SELECT_CHANNEL_D 0x08
111#define DAC11_SELECT_CHANNEL_E 0x10
112#define DAC11_SELECT_CHANNEL_F 0x20
113#define DAC11_SELECT_CHANNEL_G 0x40
114#define DAC11_SELECT_CHANNEL_H 0x80
115#define DAC11_SELECT_ALL_CHANNELS 0xFF
116
121#define DAC11_MIN_DAC_VALUE 0x0000
122#define DAC11_MAX_DAC_VALUE 0x0FFF
123
128#define DAC11_VREF_3V3 3.3
129#define DAC11_VREF_5V 5
130
139#define DAC11_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
140#define DAC11_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
141
142 // dac11_set
143
158#define DAC11_MAP_MIKROBUS( cfg, mikrobus ) \
159 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
160 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
161 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
162 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
163
164 // dac11_map
165 // dac11
166
171typedef struct
172{
173 // Modules
174 spi_master_t spi;
176 pin_name_t chip_select;
178} dac11_t;
179
184typedef struct
185{
186 // Communication gpio pins
187 pin_name_t miso;
188 pin_name_t mosi;
189 pin_name_t sck;
190 pin_name_t cs;
192 // static variable
193 uint32_t spi_speed;
194 spi_master_mode_t spi_mode;
195 spi_master_chip_select_polarity_t cs_polarity;
198
203typedef enum
204{
206 DAC11_ERROR = -1
207
209
226
241err_t dac11_init ( dac11_t *ctx, dac11_cfg_t *cfg );
242
257
271err_t dac11_generic_write ( dac11_t *ctx, uint16_t *data_in, uint8_t len );
272
286err_t dac11_write_control_reg( dac11_t *ctx, uint8_t cmd, uint16_t data_in );
287
300err_t dac11_set_all_ch_value( dac11_t *ctx, uint16_t dac_value );
301
316err_t dac11_set_all_ch_voltage( dac11_t *ctx, float vref, float voltage );
317
331err_t dac11_set_specific_ch_value( dac11_t *ctx, uint8_t channel, uint16_t dac_value );
332
348err_t dac11_set_specific_ch_voltage( dac11_t *ctx, uint8_t channel, float vref, float voltage );
349
350#ifdef __cplusplus
351}
352#endif
353#endif // DAC11_H
354
355 // dac11
356
357// ------------------------------------------------------------------------ END
dac11_return_value_t
DAC 11 Click return value data.
Definition dac11.h:204
@ DAC11_ERROR
Definition dac11.h:206
@ DAC11_OK
Definition dac11.h:205
err_t dac11_set_all_ch_voltage(dac11_t *ctx, float vref, float voltage)
DAC 11 set all channels voltage function.
void dac11_cfg_setup(dac11_cfg_t *cfg)
DAC 11 configuration object setup function.
err_t dac11_default_cfg(dac11_t *ctx)
DAC 11 default configuration function.
err_t dac11_generic_write(dac11_t *ctx, uint16_t *data_in, uint8_t len)
DAC 11 generic write function.
err_t dac11_set_all_ch_value(dac11_t *ctx, uint16_t dac_value)
DAC 11 set all channels value function.
err_t dac11_init(dac11_t *ctx, dac11_cfg_t *cfg)
DAC 11 initialization function.
err_t dac11_set_specific_ch_value(dac11_t *ctx, uint8_t channel, uint16_t dac_value)
DAC 11 set specific channels value function.
err_t dac11_set_specific_ch_voltage(dac11_t *ctx, uint8_t channel, float vref, float voltage)
DAC 11 set specific channels voltage function.
err_t dac11_write_control_reg(dac11_t *ctx, uint8_t cmd, uint16_t data_in)
DAC 11 write control register function.
This file contains SPI specific macros, functions, etc.
DAC 11 Click configuration object.
Definition dac11.h:185
spi_master_chip_select_polarity_t cs_polarity
Definition dac11.h:195
pin_name_t sck
Definition dac11.h:189
spi_master_mode_t spi_mode
Definition dac11.h:194
pin_name_t mosi
Definition dac11.h:188
uint32_t spi_speed
Definition dac11.h:193
pin_name_t miso
Definition dac11.h:187
pin_name_t cs
Definition dac11.h:190
DAC 11 Click context object.
Definition dac11.h:172
spi_master_t spi
Definition dac11.h:174
pin_name_t chip_select
Definition dac11.h:176