adcxx1c.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 OTA keys S.A.
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
26 #ifndef ADCXX1C_H
27 #define ADCXX1C_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include "periph/i2c.h"
34 #include "periph/gpio.h"
35 
39 #ifndef ADCXX1C_I2C_ADDRESS
40 #define ADCXX1C_I2C_ADDRESS (0x54)
41 #endif
42 
46 enum {
50 };
51 
55 #if defined(MODULE_ADC081C)
56 #define ADCXX1C_RES_DEFAULT ADCXX1C_RES_8BITS
57 #elif defined(MODULE_ADC101C)
58 #define ADCXX1C_RES_DEFAULT ADCXX1C_RES_10BITS
59 #elif defined(MODULE_ADC121C)
60 #define ADCXX1C_RES_DEFAULT ADCXX1C_RES_12BITS
61 #else
62 #define ADCXX1C_RES_DEFAULT (-1)
63 #error "ADCXX1C: Failed to select resolution: unknown ADCXX1C device variant!"
64 #endif
65 
69 enum {
78 };
79 
83 enum {
84  ADCXX1C_OK = 0,
88 };
89 
93 enum {
96 };
97 
101 typedef struct adcxx1c_params {
103  uint8_t addr;
104  uint8_t bits;
105  uint8_t cycle;
106  gpio_t alert_pin;
107  int16_t low_limit;
108  int16_t high_limit;
109  int16_t hysteresis;
111 
115 typedef void (*adcxx1c_cb_t)(void *);
116 
120 typedef struct adcxx1c {
123  void *arg;
124 } adcxx1c_t;
125 
134 int adcxx1c_init(adcxx1c_t *dev, const adcxx1c_params_t *params);
135 
144 int adcxx1c_read_raw(const adcxx1c_t *dev, int16_t *raw);
145 
155 int adcxx1c_enable_alert(adcxx1c_t *dev, adcxx1c_cb_t cb, void *arg);
156 
167 int adcxx1c_set_alert_parameters(const adcxx1c_t *dev, int16_t low_limit,
168  int16_t high_limit, int16_t hysteresis);
169 
178 int adcxx1c_get_and_clear_alert(const adcxx1c_t *dev);
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 #endif /* ADCXX1C_H */
185 
adcxx1c_t
struct adcxx1c adcxx1c_t
ADCxx1C device descriptor.
adcxx1c_params::high_limit
int16_t high_limit
alert high value
Definition: adcxx1c.h:108
adcxx1c_params::bits
uint8_t bits
resolution
Definition: adcxx1c.h:104
ADCXX1C_CYCLE_128
@ ADCXX1C_CYCLE_128
Conversion cycle = Tconvert x 128.
Definition: adcxx1c.h:73
ADCXX1C_NODATA
@ ADCXX1C_NODATA
no data available
Definition: adcxx1c.h:87
adcxx1c_params
ADCxx1C params.
Definition: adcxx1c.h:101
ADCXX1C_ALERT_UNDER_RANGE
@ ADCXX1C_ALERT_UNDER_RANGE
Measured voltage fell below Vlow.
Definition: adcxx1c.h:94
ADCXX1C_RES_10BITS
@ ADCXX1C_RES_10BITS
10 bits resolution (ADC101C family)
Definition: adcxx1c.h:48
ADCXX1C_CYCLE_256
@ ADCXX1C_CYCLE_256
Conversion cycle = Tconvert x 256.
Definition: adcxx1c.h:74
ADCXX1C_CYCLE_1024
@ ADCXX1C_CYCLE_1024
Conversion cycle = Tconvert x 1024.
Definition: adcxx1c.h:76
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
adcxx1c_get_and_clear_alert
int adcxx1c_get_and_clear_alert(const adcxx1c_t *dev)
Get alert source and clear it.
adcxx1c_cb_t
void(* adcxx1c_cb_t)(void *)
ADCxx1C alert callback.
Definition: adcxx1c.h:115
adcxx1c::params
adcxx1c_params_t params
device driver configuration
Definition: adcxx1c.h:121
ADCXX1C_NOI2C
@ ADCXX1C_NOI2C
I2C communication failed.
Definition: adcxx1c.h:85
ADCXX1C_ALERT_OVER_RANGE
@ ADCXX1C_ALERT_OVER_RANGE
Measured voltage exceeded Vhigh.
Definition: adcxx1c.h:95
ADCXX1C_RES_8BITS
@ ADCXX1C_RES_8BITS
8 bits resolution (ADC081C family)
Definition: adcxx1c.h:47
ADCXX1C_CYCLE_DISABLED
@ ADCXX1C_CYCLE_DISABLED
No cycle conversion.
Definition: adcxx1c.h:70
ADCXX1C_RES_12BITS
@ ADCXX1C_RES_12BITS
12 bits resolution (ADC121C family)
Definition: adcxx1c.h:49
ADCXX1C_OK
@ ADCXX1C_OK
everything was fine
Definition: adcxx1c.h:84
adcxx1c_params::i2c
i2c_t i2c
i2c device
Definition: adcxx1c.h:102
adcxx1c_init
int adcxx1c_init(adcxx1c_t *dev, const adcxx1c_params_t *params)
Initialize an ADCxx1C ADC device.
adcxx1c_params::alert_pin
gpio_t alert_pin
alert pin (GPIO_UNDEF if not connected)
Definition: adcxx1c.h:106
adcxx1c_params_t
struct adcxx1c_params adcxx1c_params_t
ADCxx1C params.
ADCXX1C_CYCLE_512
@ ADCXX1C_CYCLE_512
Conversion cycle = Tconvert x 512.
Definition: adcxx1c.h:75
adcxx1c_params::low_limit
int16_t low_limit
alert low value
Definition: adcxx1c.h:107
adcxx1c_read_raw
int adcxx1c_read_raw(const adcxx1c_t *dev, int16_t *raw)
Read a raw ADC value.
adcxx1c_params::cycle
uint8_t cycle
conversion interval
Definition: adcxx1c.h:105
adcxx1c::cb
adcxx1c_cb_t cb
alert callback
Definition: adcxx1c.h:122
gpio.h
Low-level GPIO peripheral driver interface definitions.
adcxx1c_params::addr
uint8_t addr
i2c address
Definition: adcxx1c.h:103
adcxx1c_enable_alert
int adcxx1c_enable_alert(adcxx1c_t *dev, adcxx1c_cb_t cb, void *arg)
Enable alert interrupt.
adcxx1c::arg
void * arg
alert callback param
Definition: adcxx1c.h:123
ADCXX1C_CYCLE_2048
@ ADCXX1C_CYCLE_2048
Conversion cycle = Tconvert x 2048.
Definition: adcxx1c.h:77
ADCXX1C_CYCLE_32
@ ADCXX1C_CYCLE_32
Conversion cycle = Tconvert x 32.
Definition: adcxx1c.h:71
i2c.h
Low-level I2C peripheral driver interface definition.
adcxx1c
ADCxx1C device descriptor.
Definition: adcxx1c.h:120
adcxx1c_set_alert_parameters
int adcxx1c_set_alert_parameters(const adcxx1c_t *dev, int16_t low_limit, int16_t high_limit, int16_t hysteresis)
Set the alert parameters.
ADCXX1C_NODEV
@ ADCXX1C_NODEV
no ADCXX1C device found on the bus
Definition: adcxx1c.h:86
ADCXX1C_CYCLE_64
@ ADCXX1C_CYCLE_64
Conversion cycle = Tconvert x 64.
Definition: adcxx1c.h:72
adcxx1c_params::hysteresis
int16_t hysteresis
alert hysteresis
Definition: adcxx1c.h:109