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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define DAC6_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
58 
64 #define DAC6_RETVAL uint8_t
65 
66 #define DAC6_OK 0x00
67 #define DAC6_INIT_ERROR 0xFF
68 
74 #define DAC6_CHANNEL_A 0x00
75 #define DAC6_CHANNEL_B 0x01
76 #define DAC6_CHANNEL_C 0x02
77 #define DAC6_CHANNEL_D 0x03
78 
84 #define DAC6_WRITE_SPEC_UPDATE_NO 0x00
85 #define DAC6_WRITE_SPEC_UPDATE_OUTPUT 0x01
86 #define DAC6_WRITE_ALL_AND_UPDATE 0x02
87 #define DAC6_POWER_DOWN_OUTPUTS 0x03
88 
94 #define DAC6_V_REF_2048 2048
95 
101 #define DAC6_OUTPUT_SHORT_CIRC_CURR 0x03FF
102  // End group macro
104 // --------------------------------------------------------------- PUBLIC TYPES
113 typedef struct
114 {
115  // Output pins
116 
117  digital_out_t cs;
118 
119  // Modules
120 
121  spi_master_t spi;
122  pin_name_t chip_select;
123 
124  // Variables
125  uint8_t chan;
126  uint8_t op_mod;
127  uint16_t v_ref;
128  uint16_t set_out;
129 
130 } dac6_t;
131 
135 typedef struct
136 {
137  // Communication gpio pins
138 
139  pin_name_t miso;
140  pin_name_t mosi;
141  pin_name_t sck;
142  pin_name_t cs;
143 
144  // static variable
145 
146  uint32_t spi_speed;
147  spi_master_mode_t spi_mode;
148  spi_master_chip_select_polarity_t cs_polarity;
149 
150 } dac6_cfg_t;
151  // End types group
153 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154 
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
172 
182 
194 void dac6_generic_transfer ( dac6_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
195 
204 void dac6_write_data ( dac6_t *ctx, uint16_t wr_data );
205 
227 float dac6_set_output ( dac6_t *ctx );
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 #endif // _DAC6_H_
233  // End public_function group
236 
237 // ------------------------------------------------------------------------- END
dac6_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac6.h:146
dac6_cfg_t
Click configuration structure definition.
Definition: dac6.h:136
dac6_t::v_ref
uint16_t v_ref
Definition: dac6.h:127
dac6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac6.h:147
dac6_cfg_t::sck
pin_name_t sck
Definition: dac6.h:141
dac6_t
Click ctx object definition.
Definition: dac6.h:114
dac6_cfg_t::cs
pin_name_t cs
Definition: dac6.h:142
dac6_t::chip_select
pin_name_t chip_select
Definition: dac6.h:122
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:139
DAC6_RETVAL
#define DAC6_RETVAL
Definition: dac6.h:64
dac6_t::chan
uint8_t chan
Definition: dac6.h:125
dac6_t::spi
spi_master_t spi
Definition: dac6.h:121
dac6_cfg_t::mosi
pin_name_t mosi
Definition: dac6.h:140
dac6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac6.h:148
dac6_t::op_mod
uint8_t op_mod
Definition: dac6.h:126
dac6_t::cs
digital_out_t cs
Definition: dac6.h:117
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:128