pot5  2.1.0.0
pot5.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 POT5_H
29 #define POT5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_analog_in.h"
38 #include "drv_i2c_master.h"
39 
60 #define POT5_PERCENTS 100
61 #define POT5_ROUND_TO_NEAREST_INT 0.5
62 
67 #define POT5_ADC_RESOLUTION 0x0FFF
68 #define POT5_VREF_3V3 3.3
69 #define POT5_VREF_5V 5.0
70 
76 #define POT5_SET_DEV_ADDR 0x4D
77  // pot5_set
79 
94 #define POT5_MAP_MIKROBUS( cfg, mikrobus ) \
95  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
96  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
97  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
98  // pot5_map // pot5
101 
106 typedef enum
107 {
112 
117 typedef struct
118 {
119  analog_in_t adc;
120  i2c_master_t i2c;
122  uint8_t slave_address;
123  pin_name_t chip_select;
124  float vref;
127 } pot5_t;
128 
133 typedef struct
134 {
135  pin_name_t an;
136  pin_name_t scl;
137  pin_name_t sda;
139  analog_in_resolution_t resolution;
140  float vref;
142  uint32_t i2c_speed;
143  uint8_t i2c_address;
147 } pot5_cfg_t;
148 
153 typedef enum
154 {
155  POT5_OK = 0,
156  POT5_ERROR = -1
157 
159 
176 
192 
206 err_t pot5_init ( pot5_t *ctx, pot5_cfg_t *cfg );
207 
219 err_t pot5_read_raw_adc ( pot5_t *ctx, uint16_t *raw_adc );
220 
232 err_t pot5_read_voltage ( pot5_t *ctx, float *voltage );
233 
245 err_t pot5_set_vref ( pot5_t *ctx, float vref );
246 
255 uint8_t pot5_convert_voltage_to_percents ( pot5_t *ctx, float voltage );
256 
257 #ifdef __cplusplus
258 }
259 #endif
260 #endif // POT5_H
261  // pot5
263 
264 // ------------------------------------------------------------------------ END
pot5_cfg_setup
void pot5_cfg_setup(pot5_cfg_t *cfg)
POT 5 configuration object setup function.
pot5_t::slave_address
uint8_t slave_address
Definition: pot5.h:122
pot5_init
err_t pot5_init(pot5_t *ctx, pot5_cfg_t *cfg)
POT 5 initialization function.
pot5_cfg_t::drv_sel
pot5_drv_t drv_sel
Definition: pot5.h:145
POT5_OK
@ POT5_OK
Definition: pot5.h:155
pot5_t::vref
float vref
Definition: pot5.h:124
pot5_read_raw_adc
err_t pot5_read_raw_adc(pot5_t *ctx, uint16_t *raw_adc)
POT 5 read raw ADC value function.
pot5_cfg_t::i2c_address
uint8_t i2c_address
Definition: pot5.h:143
POT5_DRV_SEL_ADC
@ POT5_DRV_SEL_ADC
Definition: pot5.h:108
pot5_t::drv_sel
pot5_drv_t drv_sel
Definition: pot5.h:125
pot5_convert_voltage_to_percents
uint8_t pot5_convert_voltage_to_percents(pot5_t *ctx, float voltage)
POT 5 convert voltage to percents function.
POT5_DRV_SEL_I2C
@ POT5_DRV_SEL_I2C
Definition: pot5.h:109
pot5_cfg_t
POT 5 Click configuration object.
Definition: pot5.h:134
pot5_cfg_t::resolution
analog_in_resolution_t resolution
Definition: pot5.h:139
pot5_cfg_t::scl
pin_name_t scl
Definition: pot5.h:136
POT5_ERROR
@ POT5_ERROR
Definition: pot5.h:156
pot5_t
POT 5 Click context object.
Definition: pot5.h:118
pot5_cfg_t::sda
pin_name_t sda
Definition: pot5.h:137
pot5_t::i2c
i2c_master_t i2c
Definition: pot5.h:120
pot5_t::adc
analog_in_t adc
Definition: pot5.h:119
pot5_t::chip_select
pin_name_t chip_select
Definition: pot5.h:123
pot5_cfg_t::vref
float vref
Definition: pot5.h:140
pot5_return_value_t
pot5_return_value_t
POT 5 Click return value data.
Definition: pot5.h:154
pot5_read_voltage
err_t pot5_read_voltage(pot5_t *ctx, float *voltage)
POT 5 read voltage level function.
pot5_cfg_t::an
pin_name_t an
Definition: pot5.h:135
pot5_drv_interface_selection
void pot5_drv_interface_selection(pot5_cfg_t *cfg, pot5_drv_t drv_sel)
POT 5 driver interface setup function.
pot5_set_vref
err_t pot5_set_vref(pot5_t *ctx, float vref)
POT 5 set vref function.
pot5_drv_t
pot5_drv_t
POT 5 Click driver selector.
Definition: pot5.h:107
pot5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: pot5.h:142