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
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_analog_in.h"
52#include "drv_i2c_master.h"
53
74#define POT5_PERCENTS 100
75#define POT5_ROUND_TO_NEAREST_INT 0.5
76
81#define POT5_ADC_RESOLUTION 0x0FFF
82#define POT5_VREF_3V3 3.3
83#define POT5_VREF_5V 5.0
84
90#define POT5_SET_DEV_ADDR 0x4D
91
92 // pot5_set
93
108#define POT5_MAP_MIKROBUS( cfg, mikrobus ) \
109 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
110 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
111 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
112
113 // pot5_map
114 // pot5
115
126
131typedef struct
132{
133 analog_in_t adc;
134 i2c_master_t i2c;
137 pin_name_t chip_select;
138 float vref;
141} pot5_t;
142
147typedef struct
148{
149 pin_name_t an;
150 pin_name_t scl;
151 pin_name_t sda;
153 analog_in_resolution_t resolution;
154 float vref;
156 uint32_t i2c_speed;
157 uint8_t i2c_address;
161} pot5_cfg_t;
162
167typedef enum
168{
170 POT5_ERROR = -1
171
173
190
206
220err_t pot5_init ( pot5_t *ctx, pot5_cfg_t *cfg );
221
233err_t pot5_read_raw_adc ( pot5_t *ctx, uint16_t *raw_adc );
234
246err_t pot5_read_voltage ( pot5_t *ctx, float *voltage );
247
259err_t pot5_set_vref ( pot5_t *ctx, float vref );
260
269uint8_t pot5_convert_voltage_to_percents ( pot5_t *ctx, float voltage );
270
271#ifdef __cplusplus
272}
273#endif
274#endif // POT5_H
275
276 // pot5
277
278// ------------------------------------------------------------------------ END
err_t pot5_init(pot5_t *ctx, pot5_cfg_t *cfg)
POT 5 initialization function.
void pot5_drv_interface_selection(pot5_cfg_t *cfg, pot5_drv_t drv_sel)
POT 5 driver interface setup function.
err_t pot5_set_vref(pot5_t *ctx, float vref)
POT 5 set vref function.
void pot5_cfg_setup(pot5_cfg_t *cfg)
POT 5 configuration object setup function.
uint8_t pot5_convert_voltage_to_percents(pot5_t *ctx, float voltage)
POT 5 convert voltage to percents function.
err_t pot5_read_voltage(pot5_t *ctx, float *voltage)
POT 5 read voltage level function.
err_t pot5_read_raw_adc(pot5_t *ctx, uint16_t *raw_adc)
POT 5 read raw ADC value function.
pot5_return_value_t
POT 5 Click return value data.
Definition pot5.h:168
@ POT5_ERROR
Definition pot5.h:170
@ POT5_OK
Definition pot5.h:169
pot5_drv_t
POT 5 Click driver selector.
Definition pot5.h:121
@ POT5_DRV_SEL_ADC
Definition pot5.h:122
@ POT5_DRV_SEL_I2C
Definition pot5.h:123
POT 5 Click configuration object.
Definition pot5.h:148
pot5_drv_t drv_sel
Definition pot5.h:159
analog_in_resolution_t resolution
Definition pot5.h:153
float vref
Definition pot5.h:154
uint32_t i2c_speed
Definition pot5.h:156
pin_name_t scl
Definition pot5.h:150
pin_name_t sda
Definition pot5.h:151
pin_name_t an
Definition pot5.h:149
uint8_t i2c_address
Definition pot5.h:157
POT 5 Click context object.
Definition pot5.h:132
pot5_drv_t drv_sel
Definition pot5.h:139
float vref
Definition pot5.h:138
i2c_master_t i2c
Definition pot5.h:134
uint8_t slave_address
Definition pot5.h:136
pin_name_t chip_select
Definition pot5.h:137
analog_in_t adc
Definition pot5.h:133