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 
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_digital_in.h"
54 #include "drv_spi_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
67 #define DAC6_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
72 
78 #define DAC6_RETVAL uint8_t
79 
80 #define DAC6_OK 0x00
81 #define DAC6_INIT_ERROR 0xFF
82 
88 #define DAC6_CHANNEL_A 0x00
89 #define DAC6_CHANNEL_B 0x01
90 #define DAC6_CHANNEL_C 0x02
91 #define DAC6_CHANNEL_D 0x03
92 
98 #define DAC6_WRITE_SPEC_UPDATE_NO 0x00
99 #define DAC6_WRITE_SPEC_UPDATE_OUTPUT 0x01
100 #define DAC6_WRITE_ALL_AND_UPDATE 0x02
101 #define DAC6_POWER_DOWN_OUTPUTS 0x03
102 
108 #define DAC6_V_REF_2048 2048
109 
115 #define DAC6_OUTPUT_SHORT_CIRC_CURR 0x03FF
116  // End group macro
118 // --------------------------------------------------------------- PUBLIC TYPES
127 typedef struct
128 {
129  // Output pins
130 
131  digital_out_t cs;
132 
133  // Modules
134 
135  spi_master_t spi;
136  pin_name_t chip_select;
137 
138  // Variables
139  uint8_t chan;
140  uint8_t op_mod;
141  uint16_t v_ref;
142  uint16_t set_out;
143 
144 } dac6_t;
145 
149 typedef struct
150 {
151  // Communication gpio pins
152 
153  pin_name_t miso;
154  pin_name_t mosi;
155  pin_name_t sck;
156  pin_name_t cs;
157 
158  // static variable
159 
160  uint32_t spi_speed;
161  spi_master_mode_t spi_mode;
162  spi_master_chip_select_polarity_t cs_polarity;
163 
164 } dac6_cfg_t;
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
173 #ifdef __cplusplus
174 extern "C"{
175 #endif
176 
186 
196 
208 void dac6_generic_transfer ( dac6_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
209 
218 void dac6_write_data ( dac6_t *ctx, uint16_t wr_data );
219 
241 float dac6_set_output ( dac6_t *ctx );
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 #endif // _DAC6_H_
247  // End public_function group
250 
251 // ------------------------------------------------------------------------- END
dac6_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac6.h:160
dac6_cfg_t
Click configuration structure definition.
Definition: dac6.h:150
dac6_t::v_ref
uint16_t v_ref
Definition: dac6.h:141
dac6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac6.h:161
dac6_cfg_t::sck
pin_name_t sck
Definition: dac6.h:155
dac6_t
Click ctx object definition.
Definition: dac6.h:128
dac6_cfg_t::cs
pin_name_t cs
Definition: dac6.h:156
dac6_t::chip_select
pin_name_t chip_select
Definition: dac6.h:136
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:153
DAC6_RETVAL
#define DAC6_RETVAL
Definition: dac6.h:78
dac6_t::chan
uint8_t chan
Definition: dac6.h:139
dac6_t::spi
spi_master_t spi
Definition: dac6.h:135
dac6_cfg_t::mosi
pin_name_t mosi
Definition: dac6.h:154
dac6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac6.h:162
dac6_t::op_mod
uint8_t op_mod
Definition: dac6.h:140
dac6_t::cs
digital_out_t cs
Definition: dac6.h:131
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:142