dac6  2.0.0.0
dac6.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 DAC6_H
36 #define DAC6_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_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define DAC6_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
74 #define DAC6_RETVAL uint8_t
75 
76 #define DAC6_OK 0x00
77 #define DAC6_INIT_ERROR 0xFF
78 
84 #define DAC6_CHANNEL_A 0x00
85 #define DAC6_CHANNEL_B 0x01
86 #define DAC6_CHANNEL_C 0x02
87 #define DAC6_CHANNEL_D 0x03
88 
94 #define DAC6_WRITE_SPEC_UPDATE_NO 0x00
95 #define DAC6_WRITE_SPEC_UPDATE_OUTPUT 0x01
96 #define DAC6_WRITE_ALL_AND_UPDATE 0x02
97 #define DAC6_POWER_DOWN_OUTPUTS 0x03
98 
104 #define DAC6_V_REF_2048 2048
105 
111 #define DAC6_OUTPUT_SHORT_CIRC_CURR 0x03FF
112  // End group macro
114 // --------------------------------------------------------------- PUBLIC TYPES
123 typedef struct
124 {
125  // Output pins
126 
127  digital_out_t cs;
128 
129  // Modules
130 
131  spi_master_t spi;
132  pin_name_t chip_select;
133 
134  // Variables
135  uint8_t chan;
136  uint8_t op_mod;
137  uint16_t v_ref;
138  uint16_t set_out;
139 
140 } dac6_t;
141 
145 typedef struct
146 {
147  // Communication gpio pins
148 
149  pin_name_t miso;
150  pin_name_t mosi;
151  pin_name_t sck;
152  pin_name_t cs;
153 
154  // static variable
155 
156  uint32_t spi_speed;
157  spi_master_mode_t spi_mode;
158  spi_master_chip_select_polarity_t cs_polarity;
159 
160 } dac6_cfg_t;
161  // End types group
163 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
164 
169 #ifdef __cplusplus
170 extern "C"{
171 #endif
172 
182 
192 
204 void dac6_generic_transfer ( dac6_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
205 
214 void dac6_write_data ( dac6_t *ctx, uint16_t wr_data );
215 
237 float dac6_set_output ( dac6_t *ctx );
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 #endif // _DAC6_H_
243  // End public_function group
246 
247 // ------------------------------------------------------------------------- END
dac6_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac6.h:156
dac6_cfg_t
Click configuration structure definition.
Definition: dac6.h:146
dac6_t::v_ref
uint16_t v_ref
Definition: dac6.h:137
dac6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac6.h:157
dac6_cfg_t::sck
pin_name_t sck
Definition: dac6.h:151
dac6_t
Click ctx object definition.
Definition: dac6.h:124
dac6_cfg_t::cs
pin_name_t cs
Definition: dac6.h:152
dac6_t::chip_select
pin_name_t chip_select
Definition: dac6.h:132
dac6_write_data
void dac6_write_data(dac6_t *ctx, uint16_t wr_data)
Generic write function.
dac6_init
DAC6_RETVAL dac6_init(dac6_t *ctx, dac6_cfg_t *cfg)
Initialization function.
dac6_generic_transfer
void dac6_generic_transfer(dac6_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
dac6_cfg_t::miso
pin_name_t miso
Definition: dac6.h:149
DAC6_RETVAL
#define DAC6_RETVAL
Definition: dac6.h:74
dac6_t::chan
uint8_t chan
Definition: dac6.h:135
dac6_t::spi
spi_master_t spi
Definition: dac6.h:131
dac6_cfg_t::mosi
pin_name_t mosi
Definition: dac6.h:150
dac6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac6.h:158
dac6_t::op_mod
uint8_t op_mod
Definition: dac6.h:136
dac6_t::cs
digital_out_t cs
Definition: dac6.h:127
dac6_cfg_setup
void dac6_cfg_setup(dac6_cfg_t *cfg)
Config Object Initialization function.
dac6_set_output
float dac6_set_output(dac6_t *ctx)
Set DAC output function.
dac6_t::set_out
uint16_t set_out
Definition: dac6.h:138