dac  2.0.0.0
dac.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DAC_H
36 #define DAC_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_spi_master.h"
40 
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define DAC_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
58 
64 #define DAC_RETVAL uint8_t
65 
66 #define DAC_OK 0x00
67 #define DAC_INIT_ERROR 0xFF
68 
74 #define DAC_APPLY_SETTINGS 0x30
75 
76 #define DAC_4_BIT_DATA 0x0F
77 #define DAC_8_BIT_DATA 0xFF
78 #define DAC_PERCENTAGE 100
79 #define DAC_ONE_STEP_VAL 819
80 #define DAC_CLAC_VAL 20
81 #define DAC_CALIB_VAL_1 220
82 #define DAC_CALIB_VAL_2 273
83 #define DAC_RESOLUTION 4096
84 #define DAC_STEP_VALUE 1000
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99  // Modules
100 
101  spi_master_t spi;
102 
103 } dac_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  // static variable
118 
119  hal_spi_speed_t spi_speed;
120  hal_spi_mode_t spi_mode;
121 
122 } dac_cfg_t;
123  // End types group
125 // ------------------------------------------------------------------ CONSTANTS // End constants group
134 // ------------------------------------------------------------------ VARIABLES // End variable group
142 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
161 void dac_cfg_setup ( dac_cfg_t *cfg );
162 
171 DAC_RETVAL dac_init ( dac_t *ctx, dac_cfg_t *cfg );
172 
181 void dac_set_voltage ( dac_t *ctx, uint16_t v_out );
182 
192 void dac_set_voltage_pct ( dac_t *ctx, uint8_t v_out_pct );
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 #endif // _DAC_H_
198  // End public_function group
201 
202 // ------------------------------------------------------------------------- END
dac_cfg_t::cs
pin_name_t cs
Definition: dac.h:115
dac_t
Click ctx object definition.
Definition: dac.h:97
DAC_RETVAL
#define DAC_RETVAL
Definition: dac.h:64
dac_cfg_t
Click configuration structure definition.
Definition: dac.h:108
dac_cfg_t::sck
pin_name_t sck
Definition: dac.h:114
dac_cfg_t::spi_mode
hal_spi_mode_t spi_mode
Definition: dac.h:120
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:113
dac_init
DAC_RETVAL dac_init(dac_t *ctx, dac_cfg_t *cfg)
Initialization function.
dac_cfg_t::miso
pin_name_t miso
Definition: dac.h:112
dac_set_voltage_pct
void dac_set_voltage_pct(dac_t *ctx, uint8_t v_out_pct)
Function write procentage value.
dac_t::spi
spi_master_t spi
Definition: dac.h:101
dac_cfg_t::spi_speed
hal_spi_speed_t spi_speed
Definition: dac.h:119
dac_set_voltage
void dac_set_voltage(dac_t *ctx, uint16_t v_out)
Set voltage function.