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 )
63#define DAC_RETVAL uint8_t
64
65#define DAC_OK 0x00
66#define DAC_INIT_ERROR 0xFF
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 // End group macro
87// --------------------------------------------------------------- PUBLIC TYPES
96typedef 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
110typedef 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
152extern "C"{
153#endif
154
165
175
184void dac_set_voltage ( dac_t *ctx, uint16_t v_out );
185
195void 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
#define DAC_RETVAL
Definition: dac.h:63
DAC_RETVAL dac_init(dac_t *ctx, dac_cfg_t *cfg)
Initialization function.
void dac_cfg_setup(dac_cfg_t *cfg)
Config Object Initialization function.
void dac_set_voltage_pct(dac_t *ctx, uint8_t v_out_pct)
Function write procentage value.
void dac_set_voltage(dac_t *ctx, uint16_t v_out)
Set voltage function.
Click configuration structure definition.
Definition: dac.h:111
spi_master_chip_select_polarity_t cs_polarity
Definition: dac.h:123
pin_name_t sck
Definition: dac.h:116
spi_master_mode_t spi_mode
Definition: dac.h:122
pin_name_t mosi
Definition: dac.h:115
uint32_t spi_speed
Definition: dac.h:121
pin_name_t miso
Definition: dac.h:114
pin_name_t cs
Definition: dac.h:117
Click ctx object definition.
Definition: dac.h:97
digital_out_t cs
Definition: dac.h:98
spi_master_t spi
Definition: dac.h:102
pin_name_t chip_select
Definition: dac.h:103