dac17  2.1.0.0
dac17.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 DAC17_H
29 #define DAC17_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_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define DAC17_CMD_WRITE_BUFER 0x00
75 #define DAC17_CMD_WRITE_BUFER_AND_LOAD 0x10
76 #define DAC17_CMD_WRITE_BUFER_AND_LOAD_ALL 0x20
77 #define DAC17_CMD_WRITE_LOAD_BUFF 0x30
78  // dac17_reg
80 
95 #define DAC17_SELECTED_CH_A 0x00
96 #define DAC17_SELECTED_CH_B 0x01
97 #define DAC17_SELECTED_CH_C 0x02
98 #define DAC17_SELECTED_CH_D 0x03
99 #define DAC17_SELECTED_CH_E 0x04
100 #define DAC17_SELECTED_CH_F 0x05
101 #define DAC17_SELECTED_CH_G 0x06
102 #define DAC17_SELECTED_CH_H 0x07
103 
108 #define DAC17_LOAD_CH_AB 0x00
109 #define DAC17_LOAD_CH_ABCD 0x01
110 #define DAC17_LOAD_CH_ABCDEF 0x02
111 #define DAC17_LOAD_CH_ALL 0x03
112 
117 #define DAC17_LOAD_AND_WRITE_CH_AB 0x04
118 #define DAC17_LOAD_AND_WRITE_CH_ABCD 0x05
119 #define DAC17_LOAD_AND_WRITE_CH_ABCDEF 0x06
120 #define DAC17_LOAD_AND_WRITE_CH_ALL 0x07
121 
126 #define DAC17_PIN_STATE_LOW 0x00
127 #define DAC17_PIN_STATE_HIGH 0x01
128 
133 #define DAC17_12BIT_VALUE 0x0FFFu
134 
143 #define DAC17_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
144 #define DAC17_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
145  // dac17_set
147 
162 #define DAC17_MAP_MIKROBUS( cfg, mikrobus ) \
163  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
164  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
165  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
166  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
167  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
168  cfg.pd = MIKROBUS( mikrobus, MIKROBUS_PWM )
169  // dac17_map // dac17
172 
177 typedef struct
178 {
179  // Output pins
180  digital_out_t rst;
181  digital_out_t pd;
183  // Modules
184  spi_master_t spi;
186  pin_name_t chip_select;
188 } dac17_t;
189 
194 typedef struct
195 {
196  // Communication gpio pins
197  pin_name_t miso;
198  pin_name_t mosi;
199  pin_name_t sck;
200  pin_name_t cs;
202  // Additional gpio pins
203  pin_name_t rst;
204  pin_name_t pd;
206  // static variable
207  uint32_t spi_speed;
208  spi_master_mode_t spi_mode;
209  spi_master_chip_select_polarity_t cs_polarity;
211 } dac17_cfg_t;
212 
217 typedef enum
218 {
219  DAC17_OK = 0,
220  DAC17_ERROR = -1
221 
223 
240 
254 err_t dac17_init ( dac17_t *ctx, dac17_cfg_t *cfg );
255 
268 err_t dac17_default_cfg ( dac17_t *ctx );
269 
284 err_t dac17_generic_write ( dac17_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
285 
296 void dac17_set_rst_pin ( dac17_t *ctx, uint8_t pin_state );
297 
308 void dac17_set_pd_pin ( dac17_t *ctx, uint8_t pin_state );
309 
319 void dac17_hw_reset ( dac17_t *ctx );
320 
335 err_t dac17_send_command ( dac17_t *ctx, uint8_t command, uint8_t ch_sel, uint16_t data_in );
336 
350 err_t dac17_set_dac_output ( dac17_t *ctx, uint8_t ch_sel, uint16_t dac_data );
351 
364 err_t dac17_set_all_dac_output ( dac17_t *ctx, uint16_t dac_data );
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 #endif // DAC17_H
370  // dac17
372 
373 // ------------------------------------------------------------------------ END
dac17_cfg_t
DAC 17 Click configuration object.
Definition: dac17.h:195
dac17_set_pd_pin
void dac17_set_pd_pin(dac17_t *ctx, uint8_t pin_state)
DAC 17 set PD pin function.
dac17_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac17.h:208
dac17_generic_write
err_t dac17_generic_write(dac17_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
DAC 17 data writing function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
dac17_set_rst_pin
void dac17_set_rst_pin(dac17_t *ctx, uint8_t pin_state)
DAC 17 set RST pin function.
dac17_cfg_t::mosi
pin_name_t mosi
Definition: dac17.h:198
dac17_hw_reset
void dac17_hw_reset(dac17_t *ctx)
DAC 17 hardware reset function.
DAC17_ERROR
@ DAC17_ERROR
Definition: dac17.h:220
dac17_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac17.h:207
DAC17_OK
@ DAC17_OK
Definition: dac17.h:219
dac17_send_command
err_t dac17_send_command(dac17_t *ctx, uint8_t command, uint8_t ch_sel, uint16_t data_in)
DAC 17 send command function.
dac17_cfg_t::rst
pin_name_t rst
Definition: dac17.h:203
dac17_return_value_t
dac17_return_value_t
DAC 17 Click return value data.
Definition: dac17.h:218
dac17_cfg_t::cs
pin_name_t cs
Definition: dac17.h:200
dac17_t::pd
digital_out_t pd
Definition: dac17.h:181
dac17_cfg_t::sck
pin_name_t sck
Definition: dac17.h:199
dac17_t::rst
digital_out_t rst
Definition: dac17.h:180
dac17_cfg_t::pd
pin_name_t pd
Definition: dac17.h:204
dac17_cfg_setup
void dac17_cfg_setup(dac17_cfg_t *cfg)
DAC 17 configuration object setup function.
dac17_init
err_t dac17_init(dac17_t *ctx, dac17_cfg_t *cfg)
DAC 17 initialization function.
dac17_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac17.h:209
dac17_t
DAC 17 Click context object.
Definition: dac17.h:178
dac17_set_all_dac_output
err_t dac17_set_all_dac_output(dac17_t *ctx, uint16_t dac_data)
DAC 17 set output level of all channels function.
dac17_set_dac_output
err_t dac17_set_dac_output(dac17_t *ctx, uint8_t ch_sel, uint16_t dac_data)
DAC 17 set output level the selected channel function.
dac17_t::chip_select
pin_name_t chip_select
Definition: dac17.h:186
dac17_default_cfg
err_t dac17_default_cfg(dac17_t *ctx)
DAC 17 default configuration function.
dac17_cfg_t::miso
pin_name_t miso
Definition: dac17.h:197
dac17_t::spi
spi_master_t spi
Definition: dac17.h:184