pot  2.0.0.0
pot.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 
34 #ifndef POT_H
35 #define POT_H
36 
37 #include "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_out.h"
48 #include "drv_digital_in.h"
49 #include "drv_analog_in.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define POT_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
63  // End group macro
66 // --------------------------------------------------------------- PUBLIC TYPES
75 typedef struct
76 {
77  analog_in_t adc;
79 } pot_t;
80 
84 typedef struct
85 {
86  pin_name_t an;
88  analog_in_resolution_t resolution;
89  float vref;
91 } pot_cfg_t;
92 
97 typedef enum
98 {
99  POT_OK = 0,
100  POT_ERROR = -1
101 
103  // End types group
105 
106 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
107 
113 #ifdef __cplusplus
114 extern "C"{
115 #endif
116 
126 void pot_cfg_setup ( pot_cfg_t *cfg );
127 
141 err_t pot_init ( pot_t *ctx, pot_cfg_t *cfg );
142 
154 err_t pot_read_an_pin_value ( pot_t *ctx, uint16_t *data_out );
155 
169 err_t pot_read_an_pin_voltage ( pot_t *ctx, float *data_out );
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 #endif // _POT_H_
175  // End public_function group
178 
179 // ------------------------------------------------------------------------ END
pot_read_an_pin_value
err_t pot_read_an_pin_value(pot_t *ctx, uint16_t *data_out)
POT read AN pin value function.
pot_cfg_setup
void pot_cfg_setup(pot_cfg_t *cfg)
POT configuration object setup function.
pot_cfg_t::an
pin_name_t an
Definition: pot.h:86
POT_OK
@ POT_OK
Definition: pot.h:99
pot_cfg_t
Click configuration structure definition.
Definition: pot.h:85
pot_cfg_t::resolution
analog_in_resolution_t resolution
Definition: pot.h:88
pot_return_value_t
pot_return_value_t
POT Click return value data.
Definition: pot.h:98
pot_t::adc
analog_in_t adc
Definition: pot.h:77
pot_init
err_t pot_init(pot_t *ctx, pot_cfg_t *cfg)
POT initialization function.
pot_t
Click ctx object definition.
Definition: pot.h:76
pot_cfg_t::vref
float vref
Definition: pot.h:89
pot_read_an_pin_voltage
err_t pot_read_an_pin_voltage(pot_t *ctx, float *data_out)
POT read AN pin voltage level function.
POT_ERROR
@ POT_ERROR
Definition: pot.h:100