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 
41 #ifdef PREINIT_SUPPORTED
42 #include "preinit.h"
43 #endif
44 
45 #ifdef MikroCCoreVersion
46  #if MikroCCoreVersion >= 1
47  #include "delays.h"
48  #endif
49 #endif
50 
51 #include "drv_digital_out.h"
52 #include "drv_digital_in.h"
53 #include "drv_analog_in.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define POT_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
67  // End group macro
70 // --------------------------------------------------------------- PUBLIC TYPES
79 typedef struct
80 {
81  analog_in_t adc;
83 } pot_t;
84 
88 typedef struct
89 {
90  pin_name_t an;
92  analog_in_resolution_t resolution;
93  float vref;
95 } pot_cfg_t;
96 
101 typedef enum
102 {
103  POT_OK = 0,
104  POT_ERROR = -1
105 
107  // End types group
109 
110 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
111 
117 #ifdef __cplusplus
118 extern "C"{
119 #endif
120 
130 void pot_cfg_setup ( pot_cfg_t *cfg );
131 
145 err_t pot_init ( pot_t *ctx, pot_cfg_t *cfg );
146 
158 err_t pot_read_an_pin_value ( pot_t *ctx, uint16_t *data_out );
159 
173 err_t pot_read_an_pin_voltage ( pot_t *ctx, float *data_out );
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 #endif // _POT_H_
179  // End public_function group
182 
183 // ------------------------------------------------------------------------ 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:90
POT_OK
@ POT_OK
Definition: pot.h:103
pot_cfg_t
Click configuration structure definition.
Definition: pot.h:89
pot_cfg_t::resolution
analog_in_resolution_t resolution
Definition: pot.h:92
pot_return_value_t
pot_return_value_t
POT Click return value data.
Definition: pot.h:102
pot_t::adc
analog_in_t adc
Definition: pot.h:81
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:80
pot_cfg_t::vref
float vref
Definition: pot.h:93
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:104