dac2  2.0.0.0
dac2.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  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef DAC2_H
35 #define DAC2_H
36 
37 #include "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_out.h"
48 #include "drv_digital_in.h"
49 #include "drv_spi_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
62 #define DAC2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
64  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
65  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
66  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.clr = MIKROBUS( mikrobus, MIKROBUS_RST );
68 
74 #define DAC2_RETVAL uint8_t
75 
76 #define DAC2_OK 0x00
77 #define DAC2_INIT_ERROR 0xFF
78  // End group macro
81 
82 // --------------------------------------------------------------- PUBLIC TYPES
91 typedef struct
92 {
93  // Output pins
94 
95  digital_out_t clr;
96  digital_out_t cs;
97 
98  // Modules
99 
100  spi_master_t spi;
101  pin_name_t chip_select;
102 
103 } dac2_t;
104 
108 typedef struct
109 {
110  // Communication gpio pins
111 
112  pin_name_t miso;
113  pin_name_t mosi;
114  pin_name_t sck;
115  pin_name_t cs;
116 
117  // Additional gpio pins
118 
119  pin_name_t clr;
120 
121  // static variable
122 
123  uint32_t spi_speed;
124  spi_master_mode_t spi_mode;
125  spi_master_chip_select_polarity_t cs_polarity;
126 
127 } dac2_cfg_t;
128  // End types group
130 
131 // ------------------------------------------------------------------ CONSTANTS // End constants group
139 
140 // ------------------------------------------------------------------ VARIABLES // End variable group
148 
149 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
150 
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
168 
178 
191 (
192  dac2_t *ctx,
193  uint8_t *wr_buf,
194  uint16_t wr_len,
195  uint8_t *rd_buf,
196  uint16_t rd_len
197 );
198 
206 void dac2_default_cfg ( dac2_t *ctx );
207 
217 
228 void dac2_write_output_voltage_procentage ( dac2_t *ctx, uint8_t value_pct );
229 
240 void dac2_write_output_voltage_data ( dac2_t *ctx, uint16_t value_data );
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 #endif // _DAC2_H_
246  // End public_function group
249 
250 // ------------------------------------------------------------------------- END
dac2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac2.h:124
dac2_t::cs
digital_out_t cs
Definition: dac2.h:96
dac2_cfg_t::clr
pin_name_t clr
Definition: dac2.h:119
dac2_cfg_t
Click configuration structure definition.
Definition: dac2.h:109
dac2_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac2.h:123
dac2_t::chip_select
pin_name_t chip_select
Definition: dac2.h:101
dac2_t
Click ctx object definition.
Definition: dac2.h:92
dac2_write_output_voltage_procentage
void dac2_write_output_voltage_procentage(dac2_t *ctx, uint8_t value_pct)
Procentage generic write function.
dac2_init
DAC2_RETVAL dac2_init(dac2_t *ctx, dac2_cfg_t *cfg)
Initialization function.
dac2_t::clr
digital_out_t clr
Definition: dac2.h:95
dac2_write_output_voltage_data
void dac2_write_output_voltage_data(dac2_t *ctx, uint16_t value_data)
Data generic write function.
dac2_default_cfg
void dac2_default_cfg(dac2_t *ctx)
Click Default Configuration function.
DAC2_RETVAL
#define DAC2_RETVAL
Definition: dac2.h:74
dac2_generic_transfer
void dac2_generic_transfer(dac2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
dac2_cfg_t::sck
pin_name_t sck
Definition: dac2.h:114
dac2_t::spi
spi_master_t spi
Definition: dac2.h:100
dac2_cfg_t::mosi
pin_name_t mosi
Definition: dac2.h:113
dac2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac2.h:125
dac2_clr_dac_2_reg
void dac2_clr_dac_2_reg(dac2_t *ctx)
Asynchronous Clear Input function.
dac2_cfg_t::cs
pin_name_t cs
Definition: dac2.h:115
dac2_cfg_t::miso
pin_name_t miso
Definition: dac2.h:112
dac2_cfg_setup
void dac2_cfg_setup(dac2_cfg_t *cfg)
Config Object Initialization function.