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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define POT3_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  cfg.vo = MIKROBUS( mikrobus, MIKROBUS_AN )
59 
65 #define POT3_RETVAL uint8_t
66 
67 #define POT3_OK 0x00
68 #define POT3_INIT_ERROR 0xFF
69 
75 #define POT3_VREF_2V 0
76 #define POT3_VREF_3V3 1
77  // End group VREF_value
78 
79  // End group macro
81 // --------------------------------------------------------------- PUBLIC TYPES
90 typedef struct
91 {
92  digital_out_t cs;
93 
94  // Input pins
95 
96  digital_in_t vo;
97 
98  // Modules
99 
100  spi_master_t spi;
101  pin_name_t chip_select;
102 
103 } pot3_t;
104 
108 typedef struct
109 {
110  // Communication gpio pins
111 
112  pin_name_t miso;
113  pin_name_t mosi;
114  pin_name_t sck;
115  pin_name_t cs;
116 
117  // Additional gpio pins
118 
119  pin_name_t vo;
120 
121  // static variable
122 
123  uint32_t spi_speed;
124  uint8_t spi_mode;
125  spi_master_chip_select_polarity_t cs_polarity;
126 
127 } pot3_cfg_t;
128  // End types group
130 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
131 
136 #ifdef __cplusplus
137 extern "C"{
138 #endif
139 
149 
158 
168 uint16_t pot3_read_adc ( pot3_t* ctx );
169 
180 uint16_t pot3_read_avg_adc ( pot3_t* ctx, uint16_t n_samples );
181 
194 uint16_t pot3_get_vout ( pot3_t* ctx, uint8_t vref_sel, uint16_t n_samples );
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 #endif // _POT3_H_
200  // End public_function group
203 
204 // ------------------------------------------------------------------------- END
pot3_get_vout
uint16_t pot3_get_vout(pot3_t *ctx, uint8_t vref_sel, uint16_t n_samples)
ADC Averaged Read function.
pot3_init
POT3_RETVAL pot3_init(pot3_t *ctx, pot3_cfg_t *cfg)
Initialization function.
pot3_cfg_setup
void pot3_cfg_setup(pot3_cfg_t *cfg)
Config Object Initialization function.
pot3_cfg_t::mosi
pin_name_t mosi
Definition: pot3.h:113
pot3_t::vo
digital_in_t vo
Definition: pot3.h:96
pot3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: pot3.h:125
pot3_cfg_t::sck
pin_name_t sck
Definition: pot3.h:114
pot3_cfg_t
Click configuration structure definition.
Definition: pot3.h:109
pot3_t::spi
spi_master_t spi
Definition: pot3.h:100
pot3_cfg_t::miso
pin_name_t miso
Definition: pot3.h:112
pot3_cfg_t::spi_speed
uint32_t spi_speed
Definition: pot3.h:123
pot3_read_avg_adc
uint16_t pot3_read_avg_adc(pot3_t *ctx, uint16_t n_samples)
ADC Averaged Read function.
pot3_read_adc
uint16_t pot3_read_adc(pot3_t *ctx)
ADC Read function
pot3_t::cs
digital_out_t cs
Definition: pot3.h:92
pot3_t
Click ctx object definition.
Definition: pot3.h:91
pot3_t::chip_select
pin_name_t chip_select
Definition: pot3.h:101
pot3_cfg_t::cs
pin_name_t cs
Definition: pot3.h:115
pot3_cfg_t::vo
pin_name_t vo
Definition: pot3.h:119
pot3_cfg_t::spi_mode
uint8_t spi_mode
Definition: pot3.h:124
POT3_RETVAL
#define POT3_RETVAL
Definition: pot3.h:65