dac  2.0.0.0
dac.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 DAC_H
35 #define DAC_H
36 
37 #include "drv_digital_out.h"
38 #include "drv_spi_master.h"
39 
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
52 #define DAC_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 
63 #define DAC_RETVAL uint8_t
64 
65 #define DAC_OK 0x00
66 #define DAC_INIT_ERROR 0xFF
67 
73 #define DAC_APPLY_SETTINGS 0x30
74 
75 #define DAC_4_BIT_DATA 0x0F
76 #define DAC_8_BIT_DATA 0xFF
77 #define DAC_PERCENTAGE 100
78 #define DAC_ONE_STEP_VAL 819
79 #define DAC_CLAC_VAL 20
80 #define DAC_CALIB_VAL_1 220
81 #define DAC_CALIB_VAL_2 273
82 #define DAC_RESOLUTION 4096
83 #define DAC_STEP_VALUE 1000
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
96 typedef struct
97 {
98  digital_out_t cs;
99 
100  // Modules
101 
102  spi_master_t spi;
103  pin_name_t chip_select;
104 
105 } dac_t;
106 
110 typedef struct
111 {
112  // Communication gpio pins
113 
114  pin_name_t miso;
115  pin_name_t mosi;
116  pin_name_t sck;
117  pin_name_t cs;
118 
119  // static variable
120 
121  uint32_t spi_speed;
122  spi_master_mode_t spi_mode;
123  spi_master_chip_select_polarity_t cs_polarity;
124 
125 } dac_cfg_t;
126  // End types group
128 // ------------------------------------------------------------------ CONSTANTS // End constants group
137 // ------------------------------------------------------------------ VARIABLES // End variable group
145 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
146 
151 #ifdef __cplusplus
152 extern "C"{
153 #endif
154 
164 void dac_cfg_setup ( dac_cfg_t *cfg );
165 
174 DAC_RETVAL dac_init ( dac_t *ctx, dac_cfg_t *cfg );
175 
184 void dac_set_voltage ( dac_t *ctx, uint16_t v_out );
185 
195 void dac_set_voltage_pct ( dac_t *ctx, uint8_t v_out_pct );
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 #endif // _DAC_H_
201  // End public_function group
204 
205 // ------------------------------------------------------------------------- END
dac_cfg_t::spi_speed
uint32_t spi_speed
Definition: dac.h:121
dac_cfg_t::cs
pin_name_t cs
Definition: dac.h:117
dac_t
Click ctx object definition.
Definition: dac.h:96
DAC_RETVAL
#define DAC_RETVAL
Definition: dac.h:63
dac_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dac.h:123
dac_cfg_t
Click configuration structure definition.
Definition: dac.h:110
dac_cfg_t::sck
pin_name_t sck
Definition: dac.h:116
dac_cfg_setup
void dac_cfg_setup(dac_cfg_t *cfg)
Config Object Initialization function.
dac_cfg_t::mosi
pin_name_t mosi
Definition: dac.h:115
dac_init
DAC_RETVAL dac_init(dac_t *ctx, dac_cfg_t *cfg)
Initialization function.
dac_t::cs
digital_out_t cs
Definition: dac.h:98
dac_cfg_t::miso
pin_name_t miso
Definition: dac.h:114
dac_t::chip_select
pin_name_t chip_select
Definition: dac.h:103
dac_set_voltage_pct
void dac_set_voltage_pct(dac_t *ctx, uint8_t v_out_pct)
Function write procentage value.
dac_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dac.h:122
dac_t::spi
spi_master_t spi
Definition: dac.h:102
dac_set_voltage
void dac_set_voltage(dac_t *ctx, uint16_t v_out)
Set voltage function.