pot4  2.1.0.0
pot4.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef POT4_H
29 #define POT4_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_analog_in.h"
48 #include "drv_i2c_master.h"
49 
70 #define POT4_PERCENTS 100
71 #define POT4_ROUND_TO_NEAREST_INT 0.5
72 
77 #define POT4_ADC_RESOLUTION 0x0FFF
78 #define POT4_VREF_3V3 3.3
79 #define POT4_VREF_5V 5.0
80 
86 #define POT4_SET_DEV_ADDR 0x4D
87  // pot4_set
89 
104 #define POT4_MAP_MIKROBUS( cfg, mikrobus ) \
105  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
106  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
107  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
108  cfg.sw = MIKROBUS( mikrobus, MIKROBUS_INT )
109  // pot4_map // pot4
112 
117 typedef enum
118 {
123 
128 typedef struct
129 {
130  digital_in_t sw;
132  analog_in_t adc;
133  i2c_master_t i2c;
135  uint8_t slave_address;
136  pin_name_t chip_select;
137  float vref;
140 } pot4_t;
141 
146 typedef struct
147 {
148  pin_name_t an;
149  pin_name_t scl;
150  pin_name_t sda;
151  pin_name_t sw;
153  analog_in_resolution_t resolution;
154  float vref;
156  uint32_t i2c_speed;
157  uint8_t i2c_address;
161 } pot4_cfg_t;
162 
167 typedef enum
168 {
169  POT4_OK = 0,
170  POT4_ERROR = -1
171 
173 
190 
206 
220 err_t pot4_init ( pot4_t *ctx, pot4_cfg_t *cfg );
221 
233 err_t pot4_read_raw_adc ( pot4_t *ctx, uint16_t *raw_adc );
234 
246 err_t pot4_read_voltage ( pot4_t *ctx, float *voltage );
247 
259 err_t pot4_set_vref ( pot4_t *ctx, float vref );
260 
269 uint8_t pot4_get_switch_pin ( pot4_t *ctx );
270 
279 uint8_t pot4_convert_voltage_to_percents ( pot4_t *ctx, float voltage );
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 #endif // POT4_H
285  // pot4
287 
288 // ------------------------------------------------------------------------ END
pot4_read_voltage
err_t pot4_read_voltage(pot4_t *ctx, float *voltage)
POT 4 read voltage level function.
POT4_ERROR
@ POT4_ERROR
Definition: pot4.h:170
pot4_cfg_t::resolution
analog_in_resolution_t resolution
Definition: pot4.h:153
pot4_cfg_t::vref
float vref
Definition: pot4.h:154
pot4_get_switch_pin
uint8_t pot4_get_switch_pin(pot4_t *ctx)
POT 4 get switch pin function.
pot4_t::i2c
i2c_master_t i2c
Definition: pot4.h:133
pot4_cfg_t::an
pin_name_t an
Definition: pot4.h:148
pot4_cfg_setup
void pot4_cfg_setup(pot4_cfg_t *cfg)
POT 4 configuration object setup function.
pot4_init
err_t pot4_init(pot4_t *ctx, pot4_cfg_t *cfg)
POT 4 initialization function.
pot4_t::chip_select
pin_name_t chip_select
Definition: pot4.h:136
pot4_cfg_t::scl
pin_name_t scl
Definition: pot4.h:149
pot4_t::adc
analog_in_t adc
Definition: pot4.h:132
POT4_DRV_SEL_ADC
@ POT4_DRV_SEL_ADC
Definition: pot4.h:119
pot4_cfg_t::sw
pin_name_t sw
Definition: pot4.h:151
pot4_cfg_t::drv_sel
pot4_drv_t drv_sel
Definition: pot4.h:159
pot4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: pot4.h:156
pot4_t::drv_sel
pot4_drv_t drv_sel
Definition: pot4.h:138
pot4_read_raw_adc
err_t pot4_read_raw_adc(pot4_t *ctx, uint16_t *raw_adc)
POT 4 read raw ADC value function.
pot4_t::slave_address
uint8_t slave_address
Definition: pot4.h:135
pot4_cfg_t
POT 4 Click configuration object.
Definition: pot4.h:147
pot4_set_vref
err_t pot4_set_vref(pot4_t *ctx, float vref)
POT 4 set vref function.
pot4_drv_t
pot4_drv_t
POT 4 Click driver selector.
Definition: pot4.h:118
pot4_drv_interface_selection
void pot4_drv_interface_selection(pot4_cfg_t *cfg, pot4_drv_t drv_sel)
POT 4 driver interface setup function.
pot4_t
POT 4 Click context object.
Definition: pot4.h:129
pot4_cfg_t::sda
pin_name_t sda
Definition: pot4.h:150
pot4_return_value_t
pot4_return_value_t
POT 4 Click return value data.
Definition: pot4.h:168
pot4_cfg_t::i2c_address
uint8_t i2c_address
Definition: pot4.h:157
pot4_convert_voltage_to_percents
uint8_t pot4_convert_voltage_to_percents(pot4_t *ctx, float voltage)
POT 4 convert voltage to percents function.
pot4_t::vref
float vref
Definition: pot4.h:137
pot4_t::sw
digital_in_t sw
Definition: pot4.h:130
POT4_OK
@ POT4_OK
Definition: pot4.h:169
POT4_DRV_SEL_I2C
@ POT4_DRV_SEL_I2C
Definition: pot4.h:120