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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define DIGIVREF_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 DIGIVREF_RETVAL uint8_t
65 
66 #define DIGIVREF_OK 0x00
67 #define DIGIVREF_INIT_ERROR 0xFF
68 
74 #define DIGIVREF_REF_VOLTAGE_4096mV 0xF0
75 #define DIGIVREF_REF_VOLTAGE_3072mV 0xF2
76 #define DIGIVREF_REF_VOLTAGE_2048mV 0xF4
77 #define DIGIVREF_REF_VOLTAGE_1024mV 0xF6
78  // End group macro
81 // --------------------------------------------------------------- PUBLIC TYPES
90 typedef struct
91 {
92  // Output pins
93 
94  digital_out_t cs;
95 
96  // Modules
97 
98  spi_master_t spi;
99  pin_name_t chip_select;
100 
101 } digivref_t;
102 
106 typedef struct
107 {
108  // Communication gpio pins
109 
110  pin_name_t miso;
111  pin_name_t mosi;
112  pin_name_t sck;
113  pin_name_t cs;
114 
115  // static variable
116 
117  uint32_t spi_speed;
118  spi_master_mode_t spi_mode;
119  spi_master_chip_select_polarity_t cs_polarity;
120 
122  // End types group
124 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
125 
130 #ifdef __cplusplus
131 extern "C"{
132 #endif
133 
143 
153 
165 void digivref_generic_transfer ( digivref_t *ctx, uint8_t *wr_buf,
166  uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
167 
176 void digivref_set_output_voltage ( digivref_t *ctx, uint8_t v_ref );
177 
178 #ifdef __cplusplus
179 }
180 #endif
181 #endif // _DIGIVREF_H_
182  // End public_function group
185 
186 // ------------------------------------------------------------------------- END
digivref_cfg_t::sck
pin_name_t sck
Definition: digivref.h:112
digivref_cfg_setup
void digivref_cfg_setup(digivref_cfg_t *cfg)
Config Object Initialization function.
digivref_generic_transfer
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.
digivref_cfg_t::miso
pin_name_t miso
Definition: digivref.h:110
digivref_cfg_t::spi_speed
uint32_t spi_speed
Definition: digivref.h:117
digivref_cfg_t::cs
pin_name_t cs
Definition: digivref.h:113
digivref_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digivref.h:119
digivref_t::spi
spi_master_t spi
Definition: digivref.h:98
digivref_cfg_t
Click configuration structure definition.
Definition: digivref.h:107
digivref_t::cs
digital_out_t cs
Definition: digivref.h:94
digivref_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: digivref.h:118
digivref_t::chip_select
pin_name_t chip_select
Definition: digivref.h:99
digivref_set_output_voltage
void digivref_set_output_voltage(digivref_t *ctx, uint8_t v_ref)
Function for set reference output voltage.
digivref_init
DIGIVREF_RETVAL digivref_init(digivref_t *ctx, digivref_cfg_t *cfg)
Initialization function.
digivref_cfg_t::mosi
pin_name_t mosi
Definition: digivref.h:111
DIGIVREF_RETVAL
#define DIGIVREF_RETVAL
Definition: digivref.h:64
digivref_t
Click ctx object definition.
Definition: digivref.h:91