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 typedef struct adcxx1c_params {
95  uint8_t addr;
96  uint8_t bits;
97  uint8_t cycle;
98  gpio_t alert_pin;
99  int16_t low_limit;
100  int16_t high_limit;
101  int16_t hysteresis;
103 
107 typedef void (*adcxx1c_cb_t)(void *);
108 
112 typedef struct adcxx1c {
115  void *arg;
116 } adcxx1c_t;
117 
126 int adcxx1c_init(adcxx1c_t *dev, const adcxx1c_params_t *params);
127 
136 int adcxx1c_read_raw(const adcxx1c_t *dev, int16_t *raw);
137 
147 int adcxx1c_enable_alert(adcxx1c_t *dev, adcxx1c_cb_t cb, void *arg);
148 
159 int adcxx1c_set_alert_parameters(const adcxx1c_t *dev, int16_t low_limit,
160  int16_t high_limit, int16_t hysteresis);
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif /* ADCXX1C_H */
167 
everything was fine
Definition: adcxx1c.h:84
void(* adcxx1c_cb_t)(void *)
ADCxx1C alert callback.
Definition: adcxx1c.h:107
struct adcxx1c adcxx1c_t
ADCxx1C device descriptor.
gpio_t alert_pin
alert pin (GPIO_UNDEF if not connected)
Definition: adcxx1c.h:98
uint8_t cycle
conversion interval
Definition: adcxx1c.h:97
Low-level GPIO peripheral driver interface definitions.
int16_t low_limit
alert low value
Definition: adcxx1c.h:99
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:157
uint8_t addr
i2c address
Definition: adcxx1c.h:95
int adcxx1c_set_alert_parameters(const adcxx1c_t *dev, int16_t low_limit, int16_t high_limit, int16_t hysteresis)
Set the alert parameters.
no ADCXX1C device found on the bus
Definition: adcxx1c.h:86
Conversion cycle = Tconvert x 1024.
Definition: adcxx1c.h:76
int adcxx1c_enable_alert(adcxx1c_t *dev, adcxx1c_cb_t cb, void *arg)
Enable alert interrupt.
10 bits resolution (ADC101C family)
Definition: adcxx1c.h:48
Conversion cycle = Tconvert x 128.
Definition: adcxx1c.h:73
Conversion cycle = Tconvert x 64.
Definition: adcxx1c.h:72
no data available
Definition: adcxx1c.h:87
void * arg
alert callback param
Definition: adcxx1c.h:115
int adcxx1c_init(adcxx1c_t *dev, const adcxx1c_params_t *params)
Initialize an ADCxx1C ADC device.
int16_t hysteresis
alert hysteresis
Definition: adcxx1c.h:101
No cycle conversion.
Definition: adcxx1c.h:70
Conversion cycle = Tconvert x 32.
Definition: adcxx1c.h:71
uint8_t bits
resolution
Definition: adcxx1c.h:96
adcxx1c_cb_t cb
alert callback
Definition: adcxx1c.h:114
ADCxx1C params.
Definition: adcxx1c.h:93
int16_t high_limit
alert high value
Definition: adcxx1c.h:100
Conversion cycle = Tconvert x 2048.
Definition: adcxx1c.h:77
ADCxx1C device descriptor.
Definition: adcxx1c.h:112
8 bits resolution (ADC081C family)
Definition: adcxx1c.h:47
Conversion cycle = Tconvert x 256.
Definition: adcxx1c.h:74
I2C communication failed.
Definition: adcxx1c.h:85
struct adcxx1c_params adcxx1c_params_t
ADCxx1C params.
int adcxx1c_read_raw(const adcxx1c_t *dev, int16_t *raw)
Read a raw ADC value.
adcxx1c_params_t params
device driver configuration
Definition: adcxx1c.h:113
Conversion cycle = Tconvert x 512.
Definition: adcxx1c.h:75
12 bits resolution (ADC121C family)
Definition: adcxx1c.h:49
i2c_t i2c
i2c device
Definition: adcxx1c.h:94
Low-level I2C peripheral driver interface definition.