digivref 2.0.0.0
digivref.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 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef DIGIVREF_H
36#define DIGIVREF_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define DIGIVREF_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
78#define DIGIVREF_RETVAL uint8_t
79
80#define DIGIVREF_OK 0x00
81#define DIGIVREF_INIT_ERROR 0xFF
88#define DIGIVREF_REF_VOLTAGE_4096mV 0xF0
89#define DIGIVREF_REF_VOLTAGE_3072mV 0xF2
90#define DIGIVREF_REF_VOLTAGE_2048mV 0xF4
91#define DIGIVREF_REF_VOLTAGE_1024mV 0xF6
94 // End group macro
95// --------------------------------------------------------------- PUBLIC TYPES
104typedef struct
105{
106 // Output pins
107
108 digital_out_t cs;
109
110 // Modules
111
112 spi_master_t spi;
113 pin_name_t chip_select;
114
115} digivref_t;
116
120typedef struct
121{
122 // Communication gpio pins
123
124 pin_name_t miso;
125 pin_name_t mosi;
126 pin_name_t sck;
127 pin_name_t cs;
128
129 // static variable
130
131 uint32_t spi_speed;
132 spi_master_mode_t spi_mode;
133 spi_master_chip_select_polarity_t cs_polarity;
134
136
137 // End types group
138// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
139
144#ifdef __cplusplus
145extern "C"{
146#endif
147
157
167
179void digivref_generic_transfer ( digivref_t *ctx, uint8_t *wr_buf,
180 uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
181
190void digivref_set_output_voltage ( digivref_t *ctx, uint8_t v_ref );
191
192#ifdef __cplusplus
193}
194#endif
195#endif // _DIGIVREF_H_
196
197 // End public_function group
199
200// ------------------------------------------------------------------------- END
#define DIGIVREF_RETVAL
Definition digivref.h:78
DIGIVREF_RETVAL digivref_init(digivref_t *ctx, digivref_cfg_t *cfg)
Initialization function.
void digivref_generic_transfer(digivref_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void digivref_cfg_setup(digivref_cfg_t *cfg)
Config Object Initialization function.
void digivref_set_output_voltage(digivref_t *ctx, uint8_t v_ref)
Function for set reference output voltage.
Click configuration structure definition.
Definition digivref.h:121
spi_master_chip_select_polarity_t cs_polarity
Definition digivref.h:133
pin_name_t sck
Definition digivref.h:126
spi_master_mode_t spi_mode
Definition digivref.h:132
pin_name_t mosi
Definition digivref.h:125
uint32_t spi_speed
Definition digivref.h:131
pin_name_t miso
Definition digivref.h:124
pin_name_t cs
Definition digivref.h:127
Click ctx object definition.
Definition digivref.h:105
digital_out_t cs
Definition digivref.h:108
spi_master_t spi
Definition digivref.h:112
pin_name_t chip_select
Definition digivref.h:113