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 
41 #ifdef PREINIT_SUPPORTED
42 #include "preinit.h"
43 #endif
44 
45 #ifdef MikroCCoreVersion
46  #if MikroCCoreVersion >= 1
47  #include "delays.h"
48  #endif
49 #endif
50 
51 #include "drv_digital_out.h"
52 #include "drv_digital_in.h"
53 #include "drv_spi_master.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
66 #define DAC2_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
68  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
69  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
70  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.clr = MIKROBUS( mikrobus, MIKROBUS_RST );
72 
78 #define DAC2_RETVAL uint8_t
79 
80 #define DAC2_OK 0x00
81 #define DAC2_INIT_ERROR 0xFF
82  // End group macro
85 
86 // --------------------------------------------------------------- PUBLIC TYPES
95 typedef struct
96 {
97  // Output pins
98 
99  digital_out_t clr;
100  digital_out_t cs;
101 
102  // Modules
103 
104  spi_master_t spi;
105  pin_name_t chip_select;
106 
107 } dac2_t;
108 
112 typedef struct
113 {
114  // Communication gpio pins
115 
116  pin_name_t miso;
117  pin_name_t mosi;
118  pin_name_t sck;
119  pin_name_t cs;
120 
121  // Additional gpio pins
122 
123  pin_name_t clr;
124 
125  // static variable
126 
127  uint32_t spi_speed;
128  spi_master_mode_t spi_mode;
129  spi_master_chip_select_polarity_t cs_polarity;
130 
131 } dac2_cfg_t;
132  // End types group
134 
135 // ------------------------------------------------------------------ CONSTANTS // End constants group
143 
144 // ------------------------------------------------------------------ VARIABLES // End variable group
152 
153 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154 
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
172 
182 
195 (
196  dac2_t *ctx,
197  uint8_t *wr_buf,
198  uint16_t wr_len,
199  uint8_t *rd_buf,
200  uint16_t rd_len
201 );
202 
210 void dac2_default_cfg ( dac2_t *ctx );
211 
221 
232 void dac2_write_output_voltage_procentage ( dac2_t *ctx, uint8_t value_pct );
233 
244 void dac2_write_output_voltage_data ( dac2_t *ctx, uint16_t value_data );
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 #endif // _DAC2_H_
250  // End public_function group
253 
254 // ------------------------------------------------------------------------- END
dac2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac2.h:128
dac2_t::cs
digital_out_t cs
Definition: dac2.h:100
dac2_cfg_t::clr
pin_name_t clr
Definition: dac2.h:123
dac2_cfg_t
Click configuration structure definition.
Definition: dac2.h:113
dac2_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac2.h:127
dac2_t::chip_select
pin_name_t chip_select
Definition: dac2.h:105
dac2_t
Click ctx object definition.
Definition: dac2.h:96
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:99
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:78
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:118
dac2_t::spi
spi_master_t spi
Definition: dac2.h:104
dac2_cfg_t::mosi
pin_name_t mosi
Definition: dac2.h:117
dac2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac2.h:129
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:119
dac2_cfg_t::miso
pin_name_t miso
Definition: dac2.h:116
dac2_cfg_setup
void dac2_cfg_setup(dac2_cfg_t *cfg)
Config Object Initialization function.