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 "drv_digital_out.h"
38 #include "drv_digital_in.h"
39 #include "drv_spi_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
52 #define DAC2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
54  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
55  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
56  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.clr = MIKROBUS( mikrobus, MIKROBUS_RST );
58 
64 #define DAC2_RETVAL uint8_t
65 
66 #define DAC2_OK 0x00
67 #define DAC2_INIT_ERROR 0xFF
68  // End group macro
71 
72 // --------------------------------------------------------------- PUBLIC TYPES
81 typedef struct
82 {
83  // Output pins
84 
85  digital_out_t clr;
86  digital_out_t cs;
87 
88  // Modules
89 
90  spi_master_t spi;
91  pin_name_t chip_select;
92 
93 } dac2_t;
94 
98 typedef struct
99 {
100  // Communication gpio pins
101 
102  pin_name_t miso;
103  pin_name_t mosi;
104  pin_name_t sck;
105  pin_name_t cs;
106 
107  // Additional gpio pins
108 
109  pin_name_t clr;
110 
111  // static variable
112 
113  uint32_t spi_speed;
114  spi_master_mode_t spi_mode;
115  spi_master_chip_select_polarity_t cs_polarity;
116 
117 } dac2_cfg_t;
118  // End types group
120 
121 // ------------------------------------------------------------------ CONSTANTS // End constants group
129 
130 // ------------------------------------------------------------------ VARIABLES // End variable group
138 
139 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
140 
145 #ifdef __cplusplus
146 extern "C"{
147 #endif
148 
157 void dac2_cfg_setup ( dac2_cfg_t *cfg );
158 
167 DAC2_RETVAL dac2_init ( dac2_t *ctx, dac2_cfg_t *cfg );
168 
181 (
182  dac2_t *ctx,
183  uint8_t *wr_buf,
184  uint16_t wr_len,
185  uint8_t *rd_buf,
186  uint16_t rd_len
187 );
188 
196 void dac2_default_cfg ( dac2_t *ctx );
197 
206 void dac2_clr_dac_2_reg ( dac2_t *ctx );
207 
218 void dac2_write_output_voltage_procentage ( dac2_t *ctx, uint8_t value_pct );
219 
230 void dac2_write_output_voltage_data ( dac2_t *ctx, uint16_t value_data );
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 #endif // _DAC2_H_
236  // End public_function group
239 
240 // ------------------------------------------------------------------------- END
dac2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac2.h:114
dac2_t::cs
digital_out_t cs
Definition: dac2.h:86
dac2_cfg_t::clr
pin_name_t clr
Definition: dac2.h:109
dac2_cfg_t
Click configuration structure definition.
Definition: dac2.h:98
dac2_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac2.h:113
dac2_t::chip_select
pin_name_t chip_select
Definition: dac2.h:91
dac2_t
Click ctx object definition.
Definition: dac2.h:81
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:85
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:64
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:104
dac2_t::spi
spi_master_t spi
Definition: dac2.h:90
dac2_cfg_t::mosi
pin_name_t mosi
Definition: dac2.h:103
dac2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac2.h:115
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:105
dac2_cfg_t::miso
pin_name_t miso
Definition: dac2.h:102
dac2_cfg_setup
void dac2_cfg_setup(dac2_cfg_t *cfg)
Config Object Initialization function.