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
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 ADC5_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 ADC5_RETVAL uint8_t
79
80#define ADC5_OK 0x00
81#define ADC5_INIT_ERROR 0xFF
88#define ADC5_VREF 3300
89#define ADC5_RESOLUTION 4096
92 // End group macro
93// --------------------------------------------------------------- PUBLIC TYPES
102typedef struct
103{
104 digital_out_t cs;
105
106 // Modules
107
108 spi_master_t spi;
109 pin_name_t chip_select;
110
111} adc5_t;
112
116typedef struct
117{
118 // Communication gpio pins
119
120 pin_name_t miso;
121 pin_name_t mosi;
122 pin_name_t sck;
123 pin_name_t cs;
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} adc5_cfg_t;
132
133 // End types group
134// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
135
140#ifdef __cplusplus
141extern "C"{
142#endif
143
153
163
171uint16_t adc5_get_voltage ( adc5_t *ctx );
172
180uint16_t adc5_get_data ( adc5_t *ctx );
181
182#ifdef __cplusplus
183}
184#endif
185#endif // _ADC5_H_
186
187 // End public_function group
189
190// ------------------------------------------------------------------------- END
#define ADC5_RETVAL
Definition adc5.h:78
uint16_t adc5_get_voltage(adc5_t *ctx)
Get voltage function.
uint16_t adc5_get_data(adc5_t *ctx)
Get data function.
void adc5_cfg_setup(adc5_cfg_t *cfg)
Config Object Initialization function.
ADC5_RETVAL adc5_init(adc5_t *ctx, adc5_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition adc5.h:117
spi_master_chip_select_polarity_t cs_polarity
Definition adc5.h:129
pin_name_t sck
Definition adc5.h:122
spi_master_mode_t spi_mode
Definition adc5.h:128
pin_name_t mosi
Definition adc5.h:121
uint32_t spi_speed
Definition adc5.h:127
pin_name_t miso
Definition adc5.h:120
pin_name_t cs
Definition adc5.h:123
Click ctx object definition.
Definition adc5.h:103
digital_out_t cs
Definition adc5.h:104
spi_master_t spi
Definition adc5.h:108
pin_name_t chip_select
Definition adc5.h:109