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
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 POT4_PERCENTS 100
75#define POT4_ROUND_TO_NEAREST_INT 0.5
76
81#define POT4_ADC_RESOLUTION 0x0FFF
82#define POT4_VREF_3V3 3.3
83#define POT4_VREF_5V 5.0
84
90#define POT4_SET_DEV_ADDR 0x4D
91
92 // pot4_set
93
108#define POT4_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 cfg.sw = MIKROBUS( mikrobus, MIKROBUS_INT )
113
114 // pot4_map
115 // pot4
116
127
132typedef struct
133{
134 digital_in_t sw;
136 analog_in_t adc;
137 i2c_master_t i2c;
140 pin_name_t chip_select;
141 float vref;
144} pot4_t;
145
150typedef struct
151{
152 pin_name_t an;
153 pin_name_t scl;
154 pin_name_t sda;
155 pin_name_t sw;
157 analog_in_resolution_t resolution;
158 float vref;
160 uint32_t i2c_speed;
161 uint8_t i2c_address;
165} pot4_cfg_t;
166
171typedef enum
172{
174 POT4_ERROR = -1
175
177
194
210
224err_t pot4_init ( pot4_t *ctx, pot4_cfg_t *cfg );
225
237err_t pot4_read_raw_adc ( pot4_t *ctx, uint16_t *raw_adc );
238
250err_t pot4_read_voltage ( pot4_t *ctx, float *voltage );
251
263err_t pot4_set_vref ( pot4_t *ctx, float vref );
264
274
283uint8_t pot4_convert_voltage_to_percents ( pot4_t *ctx, float voltage );
284
285#ifdef __cplusplus
286}
287#endif
288#endif // POT4_H
289
290 // pot4
291
292// ------------------------------------------------------------------------ END
err_t pot4_read_raw_adc(pot4_t *ctx, uint16_t *raw_adc)
POT 4 read raw ADC value function.
uint8_t pot4_get_switch_pin(pot4_t *ctx)
POT 4 get switch pin function.
void pot4_drv_interface_selection(pot4_cfg_t *cfg, pot4_drv_t drv_sel)
POT 4 driver interface setup function.
err_t pot4_read_voltage(pot4_t *ctx, float *voltage)
POT 4 read voltage level function.
err_t pot4_init(pot4_t *ctx, pot4_cfg_t *cfg)
POT 4 initialization function.
void pot4_cfg_setup(pot4_cfg_t *cfg)
POT 4 configuration object setup function.
err_t pot4_set_vref(pot4_t *ctx, float vref)
POT 4 set vref function.
uint8_t pot4_convert_voltage_to_percents(pot4_t *ctx, float voltage)
POT 4 convert voltage to percents function.
pot4_drv_t
POT 4 Click driver selector.
Definition pot4.h:122
@ POT4_DRV_SEL_I2C
Definition pot4.h:124
@ POT4_DRV_SEL_ADC
Definition pot4.h:123
pot4_return_value_t
POT 4 Click return value data.
Definition pot4.h:172
@ POT4_OK
Definition pot4.h:173
@ POT4_ERROR
Definition pot4.h:174
POT 4 Click configuration object.
Definition pot4.h:151
pot4_drv_t drv_sel
Definition pot4.h:163
analog_in_resolution_t resolution
Definition pot4.h:157
float vref
Definition pot4.h:158
uint32_t i2c_speed
Definition pot4.h:160
pin_name_t scl
Definition pot4.h:153
pin_name_t sw
Definition pot4.h:155
pin_name_t sda
Definition pot4.h:154
pin_name_t an
Definition pot4.h:152
uint8_t i2c_address
Definition pot4.h:161
POT 4 Click context object.
Definition pot4.h:133
pot4_drv_t drv_sel
Definition pot4.h:142
float vref
Definition pot4.h:141
digital_in_t sw
Definition pot4.h:134
i2c_master_t i2c
Definition pot4.h:137
uint8_t slave_address
Definition pot4.h:139
pin_name_t chip_select
Definition pot4.h:140
analog_in_t adc
Definition pot4.h:136