pot3 2.0.0.0
pot3.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 POT3_H
36#define POT3_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
57// -------------------------------------------------------------- PUBLIC MACROS
67#define POT3_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 ); \
72 cfg.vo = MIKROBUS( mikrobus, MIKROBUS_AN )
79#define POT3_RETVAL uint8_t
80
81#define POT3_OK 0x00
82#define POT3_INIT_ERROR 0xFF
89#define POT3_VREF_2V 0
90#define POT3_VREF_3V3 1
91 // End group VREF_value
92
93
94 // End group macro
95// --------------------------------------------------------------- PUBLIC TYPES
104typedef struct
105{
106 digital_out_t cs;
107
108 // Input pins
109
110 digital_in_t vo;
111
112 // Modules
113
114 spi_master_t spi;
115 pin_name_t chip_select;
116
117} pot3_t;
118
122typedef struct
123{
124 // Communication gpio pins
125
126 pin_name_t miso;
127 pin_name_t mosi;
128 pin_name_t sck;
129 pin_name_t cs;
130
131 // Additional gpio pins
132
133 pin_name_t vo;
134
135 // static variable
136
137 uint32_t spi_speed;
138 uint8_t spi_mode;
139 spi_master_chip_select_polarity_t cs_polarity;
140
141} pot3_cfg_t;
142
143 // End types group
144// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
145
150#ifdef __cplusplus
151extern "C"{
152#endif
153
163
172
182uint16_t pot3_read_adc ( pot3_t* ctx );
183
194uint16_t pot3_read_avg_adc ( pot3_t* ctx, uint16_t n_samples );
195
208uint16_t pot3_get_vout ( pot3_t* ctx, uint8_t vref_sel, uint16_t n_samples );
209
210#ifdef __cplusplus
211}
212#endif
213#endif // _POT3_H_
214
215 // End public_function group
217
218// ------------------------------------------------------------------------- END
#define POT3_RETVAL
Definition pot3.h:79
uint16_t pot3_get_vout(pot3_t *ctx, uint8_t vref_sel, uint16_t n_samples)
ADC Averaged Read function.
uint16_t pot3_read_adc(pot3_t *ctx)
ADC Read function
uint16_t pot3_read_avg_adc(pot3_t *ctx, uint16_t n_samples)
ADC Averaged Read function.
POT3_RETVAL pot3_init(pot3_t *ctx, pot3_cfg_t *cfg)
Initialization function.
void pot3_cfg_setup(pot3_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition pot3.h:123
uint8_t spi_mode
Definition pot3.h:138
spi_master_chip_select_polarity_t cs_polarity
Definition pot3.h:139
pin_name_t sck
Definition pot3.h:128
pin_name_t mosi
Definition pot3.h:127
uint32_t spi_speed
Definition pot3.h:137
pin_name_t vo
Definition pot3.h:133
pin_name_t miso
Definition pot3.h:126
pin_name_t cs
Definition pot3.h:129
Click ctx object definition.
Definition pot3.h:105
digital_out_t cs
Definition pot3.h:106
digital_in_t vo
Definition pot3.h:110
spi_master_t spi
Definition pot3.h:114
pin_name_t chip_select
Definition pot3.h:115