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 );
78#define DAC2_RETVAL uint8_t
79
80#define DAC2_OK 0x00
81#define DAC2_INIT_ERROR 0xFF
84 // End group macro
85
86// --------------------------------------------------------------- PUBLIC TYPES
95typedef 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
112typedef 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
133 // End types group
134
135// ------------------------------------------------------------------ CONSTANTS
142 // End constants group
143
144// ------------------------------------------------------------------ VARIABLES
151 // End variable group
152
153// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154
159#ifdef __cplusplus
160extern "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
211
221
232void dac2_write_output_voltage_procentage ( dac2_t *ctx, uint8_t value_pct );
233
244void dac2_write_output_voltage_data ( dac2_t *ctx, uint16_t value_data );
245
246#ifdef __cplusplus
247}
248#endif
249#endif // _DAC2_H_
250
251 // End public_function group
253
254// ------------------------------------------------------------------------- END
#define DAC2_RETVAL
Definition dac2.h:78
void dac2_write_output_voltage_procentage(dac2_t *ctx, uint8_t value_pct)
Procentage generic write function.
void dac2_clr_dac_2_reg(dac2_t *ctx)
Asynchronous Clear Input function.
void dac2_default_cfg(dac2_t *ctx)
Click Default Configuration function.
void dac2_write_output_voltage_data(dac2_t *ctx, uint16_t value_data)
Data generic write function.
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.
void dac2_cfg_setup(dac2_cfg_t *cfg)
Config Object Initialization function.
DAC2_RETVAL dac2_init(dac2_t *ctx, dac2_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition dac2.h:113
pin_name_t clr
Definition dac2.h:123
spi_master_chip_select_polarity_t cs_polarity
Definition dac2.h:129
pin_name_t sck
Definition dac2.h:118
spi_master_mode_t spi_mode
Definition dac2.h:128
pin_name_t mosi
Definition dac2.h:117
uint32_t spi_speed
Definition dac2.h:127
pin_name_t miso
Definition dac2.h:116
pin_name_t cs
Definition dac2.h:119
Click ctx object definition.
Definition dac2.h:96
digital_out_t cs
Definition dac2.h:100
spi_master_t spi
Definition dac2.h:104
digital_out_t clr
Definition dac2.h:99
pin_name_t chip_select
Definition dac2.h:105