adc5  2.0.0.0
adc5.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 ADC5_H
36 #define ADC5_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define ADC5_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
74 #define ADC5_RETVAL uint8_t
75 
76 #define ADC5_OK 0x00
77 #define ADC5_INIT_ERROR 0xFF
78 
84 #define ADC5_VREF 3300
85 #define ADC5_RESOLUTION 4096
86  // End group macro
89 // --------------------------------------------------------------- PUBLIC TYPES
98 typedef struct
99 {
100  digital_out_t cs;
101 
102  // Modules
103 
104  spi_master_t spi;
105  pin_name_t chip_select;
106 
107 } adc5_t;
108 
112 typedef 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  // static variable
122 
123  uint32_t spi_speed;
124  spi_master_mode_t spi_mode;
125  spi_master_chip_select_polarity_t cs_polarity;
126 
127 } adc5_cfg_t;
128  // End types group
130 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
131 
136 #ifdef __cplusplus
137 extern "C"{
138 #endif
139 
149 
159 
167 uint16_t adc5_get_voltage ( adc5_t *ctx );
168 
176 uint16_t adc5_get_data ( adc5_t *ctx );
177 
178 #ifdef __cplusplus
179 }
180 #endif
181 #endif // _ADC5_H_
182  // End public_function group
185 
186 // ------------------------------------------------------------------------- END
adc5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: adc5.h:125
adc5_t::chip_select
pin_name_t chip_select
Definition: adc5.h:105
adc5_t::spi
spi_master_t spi
Definition: adc5.h:104
adc5_get_voltage
uint16_t adc5_get_voltage(adc5_t *ctx)
Get voltage function.
adc5_cfg_t::mosi
pin_name_t mosi
Definition: adc5.h:117
adc5_get_data
uint16_t adc5_get_data(adc5_t *ctx)
Get data function.
adc5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: adc5.h:124
adc5_t::cs
digital_out_t cs
Definition: adc5.h:100
adc5_cfg_t::spi_speed
uint32_t spi_speed
Definition: adc5.h:123
adc5_cfg_setup
void adc5_cfg_setup(adc5_cfg_t *cfg)
Config Object Initialization function.
adc5_t
Click ctx object definition.
Definition: adc5.h:99
adc5_cfg_t::miso
pin_name_t miso
Definition: adc5.h:116
ADC5_RETVAL
#define ADC5_RETVAL
Definition: adc5.h:74
adc5_cfg_t
Click configuration structure definition.
Definition: adc5.h:113
adc5_cfg_t::cs
pin_name_t cs
Definition: adc5.h:119
adc5_init
ADC5_RETVAL adc5_init(adc5_t *ctx, adc5_cfg_t *cfg)
Initialization function.
adc5_cfg_t::sck
pin_name_t sck
Definition: adc5.h:118