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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define ADC5_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 ADC5_RETVAL uint8_t
65 
66 #define ADC5_OK 0x00
67 #define ADC5_INIT_ERROR 0xFF
68 
74 #define ADC5_VREF 3300
75 #define ADC5_RESOLUTION 4096
76  // End group macro
79 // --------------------------------------------------------------- PUBLIC TYPES
88 typedef struct
89 {
90  digital_out_t cs;
91 
92  // Modules
93 
94  spi_master_t spi;
95  pin_name_t chip_select;
96 
97 } adc5_t;
98 
102 typedef struct
103 {
104  // Communication gpio pins
105 
106  pin_name_t miso;
107  pin_name_t mosi;
108  pin_name_t sck;
109  pin_name_t cs;
110 
111  // static variable
112 
113  uint32_t spi_speed;
114  spi_master_mode_t spi_mode;
115  spi_master_chip_select_polarity_t cs_polarity;
116 
117 } adc5_cfg_t;
118  // End types group
120 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
121 
126 #ifdef __cplusplus
127 extern "C"{
128 #endif
129 
138 void adc5_cfg_setup ( adc5_cfg_t *cfg );
139 
148 ADC5_RETVAL adc5_init ( adc5_t *ctx, adc5_cfg_t *cfg );
149 
157 uint16_t adc5_get_voltage ( adc5_t *ctx );
158 
166 uint16_t adc5_get_data ( adc5_t *ctx );
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 #endif // _ADC5_H_
172  // End public_function group
175 
176 // ------------------------------------------------------------------------- END
digital_out_t cs
Definition: adc5.h:90
pin_name_t sck
Definition: adc5.h:108
ADC5_RETVAL adc5_init(adc5_t *ctx, adc5_cfg_t *cfg)
Initialization function.
pin_name_t mosi
Definition: adc5.h:107
void adc5_cfg_setup(adc5_cfg_t *cfg)
Config Object Initialization function.
pin_name_t cs
Definition: adc5.h:109
spi_master_mode_t spi_mode
Definition: adc5.h:114
uint16_t adc5_get_data(adc5_t *ctx)
Get data function.
Click configuration structure definition.
Definition: adc5.h:102
spi_master_t spi
Definition: adc5.h:94
Click ctx object definition.
Definition: adc5.h:88
pin_name_t miso
Definition: adc5.h:106
spi_master_chip_select_polarity_t cs_polarity
Definition: adc5.h:115
uint32_t spi_speed
Definition: adc5.h:113
#define ADC5_RETVAL
Definition: adc5.h:64
pin_name_t chip_select
Definition: adc5.h:95
uint16_t adc5_get_voltage(adc5_t *ctx)
Get voltage function.