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 
23 #ifndef ADCXX1C_H
24 #define ADCXX1C_H
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include "periph/i2c.h"
31 #include "periph/gpio.h"
32 
36 #ifndef ADCXX1C_I2C_ADDRESS
37 #define ADCXX1C_I2C_ADDRESS (0x54)
38 #endif
39 
43 enum {
47 };
48 
52 #if defined(MODULE_ADC081C)
53 #define ADCXX1C_RES_DEFAULT ADCXX1C_RES_8BITS
54 #elif defined(MODULE_ADC101C)
55 #define ADCXX1C_RES_DEFAULT ADCXX1C_RES_10BITS
56 #elif defined(MODULE_ADC121C)
57 #define ADCXX1C_RES_DEFAULT ADCXX1C_RES_12BITS
58 #else
59 #define ADCXX1C_RES_DEFAULT (-1)
60 #error "ADCXX1C: Failed to select resolution: unknown ADCXX1C device variant!"
61 #endif
62 
66 enum {
75 };
76 
80 enum {
81  ADCXX1C_OK = 0,
85 };
86 
90 typedef struct adcxx1c_params {
92  uint8_t addr;
93  uint8_t bits;
94  uint8_t cycle;
95  gpio_t alert_pin;
96  int16_t low_limit;
97  int16_t high_limit;
98  int16_t hysteresis;
100 
104 typedef void (*adcxx1c_cb_t)(void *);
105 
109 typedef struct adcxx1c {
112  void *arg;
113 } adcxx1c_t;
114 
123 int adcxx1c_init(adcxx1c_t *dev, const adcxx1c_params_t *params);
124 
133 int adcxx1c_read_raw(const adcxx1c_t *dev, int16_t *raw);
134 
144 int adcxx1c_enable_alert(adcxx1c_t *dev, adcxx1c_cb_t cb, void *arg);
145 
156 int adcxx1c_set_alert_parameters(const adcxx1c_t *dev, int16_t low_limit,
157  int16_t high_limit, int16_t hysteresis);
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif /* ADCXX1C_H */
164 
Conversion cycle = Tconvert x 2048.
Definition: adcxx1c.h:74
10 bits resolution (ADC101C family)
Definition: adcxx1c.h:45
gpio_t alert_pin
alert pin (GPIO_UNDEF if not connected)
Definition: adcxx1c.h:95
uint8_t cycle
conversion interval
Definition: adcxx1c.h:94
Low-level GPIO peripheral driver interface definitions.
no ADCXX1C device found on the bus
Definition: adcxx1c.h:83
int16_t low_limit
alert low value
Definition: adcxx1c.h:96
int adcxx1c_init(adcxx1c_t *dev, const adcxx1c_params_t *params)
Initialize an ADCxx1C ADC device.
Conversion cycle = Tconvert x 32.
Definition: adcxx1c.h:68
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:108
struct adcxx1c adcxx1c_t
ADCxx1C device descriptor.
int adcxx1c_set_alert_parameters(const adcxx1c_t *dev, int16_t low_limit, int16_t high_limit, int16_t hysteresis)
Set the alert parameters.
uint8_t addr
i2c address
Definition: adcxx1c.h:92
Conversion cycle = Tconvert x 1024.
Definition: adcxx1c.h:73
Conversion cycle = Tconvert x 512.
Definition: adcxx1c.h:72
Conversion cycle = Tconvert x 256.
Definition: adcxx1c.h:71
I2C communication failed.
Definition: adcxx1c.h:82
8 bits resolution (ADC081C family)
Definition: adcxx1c.h:44
12 bits resolution (ADC121C family)
Definition: adcxx1c.h:46
void(* adcxx1c_cb_t)(void *)
ADCxx1C alert callback.
Definition: adcxx1c.h:104
void * arg
alert callback param
Definition: adcxx1c.h:112
int16_t hysteresis
alert hysteresis
Definition: adcxx1c.h:98
uint8_t bits
resolution
Definition: adcxx1c.h:93
adcxx1c_cb_t cb
alert callback
Definition: adcxx1c.h:111
Conversion cycle = Tconvert x 64.
Definition: adcxx1c.h:69
ADCxx1C params.
Definition: adcxx1c.h:90
int16_t high_limit
alert high value
Definition: adcxx1c.h:97
ADCxx1C device descriptor.
Definition: adcxx1c.h:109
No cycle conversion.
Definition: adcxx1c.h:67
adcxx1c_params_t params
device driver configuration
Definition: adcxx1c.h:110
int adcxx1c_read_raw(const adcxx1c_t *dev, int16_t *raw)
Read a raw ADC value.
int adcxx1c_enable_alert(adcxx1c_t *dev, adcxx1c_cb_t cb, void *arg)
Enable alert interrupt.
struct adcxx1c_params adcxx1c_params_t
ADCxx1C params.
i2c_t i2c
i2c device
Definition: adcxx1c.h:91
no data available
Definition: adcxx1c.h:84
everything was fine
Definition: adcxx1c.h:81
Conversion cycle = Tconvert x 128.
Definition: adcxx1c.h:70
Low-level I2C peripheral driver interface definition.