Loading...
Searching...
No Matches
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
30extern "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
46enum {
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
69enum {
78};
79
83enum {
87 ADCXX1C_NODATA = -3
88};
89
93enum {
96};
97
101typedef 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
115typedef void (*adcxx1c_cb_t)(void *);
116
125
134int adcxx1c_init(adcxx1c_t *dev, const adcxx1c_params_t *params);
135
144int adcxx1c_read_raw(const adcxx1c_t *dev, int16_t *raw);
145
156
167int adcxx1c_set_alert_parameters(const adcxx1c_t *dev, int16_t low_limit,
168 int16_t high_limit, int16_t hysteresis);
169
179
180#ifdef __cplusplus
181}
182#endif
183
184#endif /* ADCXX1C_H */
Low-level GPIO peripheral driver interface definitions.
int adcxx1c_get_and_clear_alert(const adcxx1c_t *dev)
Get alert source and clear it.
void(* adcxx1c_cb_t)(void *)
ADCxx1C alert callback.
Definition adcxx1c.h:115
int adcxx1c_set_alert_parameters(const adcxx1c_t *dev, int16_t low_limit, int16_t high_limit, int16_t hysteresis)
Set the alert parameters.
struct adcxx1c adcxx1c_t
ADCxx1C device descriptor.
int adcxx1c_init(adcxx1c_t *dev, const adcxx1c_params_t *params)
Initialize an ADCxx1C ADC device.
struct adcxx1c_params adcxx1c_params_t
ADCxx1C params.
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.
@ ADCXX1C_CYCLE_2048
Conversion cycle = Tconvert x 2048.
Definition adcxx1c.h:77
@ ADCXX1C_CYCLE_512
Conversion cycle = Tconvert x 512.
Definition adcxx1c.h:75
@ ADCXX1C_CYCLE_128
Conversion cycle = Tconvert x 128.
Definition adcxx1c.h:73
@ ADCXX1C_CYCLE_DISABLED
No cycle conversion.
Definition adcxx1c.h:70
@ ADCXX1C_CYCLE_256
Conversion cycle = Tconvert x 256.
Definition adcxx1c.h:74
@ ADCXX1C_CYCLE_64
Conversion cycle = Tconvert x 64.
Definition adcxx1c.h:72
@ ADCXX1C_CYCLE_32
Conversion cycle = Tconvert x 32.
Definition adcxx1c.h:71
@ ADCXX1C_CYCLE_1024
Conversion cycle = Tconvert x 1024.
Definition adcxx1c.h:76
@ ADCXX1C_RES_8BITS
8 bits resolution (ADC081C family)
Definition adcxx1c.h:47
@ ADCXX1C_RES_12BITS
12 bits resolution (ADC121C family)
Definition adcxx1c.h:49
@ ADCXX1C_RES_10BITS
10 bits resolution (ADC101C family)
Definition adcxx1c.h:48
@ ADCXX1C_ALERT_OVER_RANGE
Measured voltage exceeded Vhigh.
Definition adcxx1c.h:95
@ ADCXX1C_ALERT_UNDER_RANGE
Measured voltage fell below Vlow.
Definition adcxx1c.h:94
@ ADCXX1C_NODATA
no data available
Definition adcxx1c.h:87
@ ADCXX1C_NOI2C
I2C communication failed.
Definition adcxx1c.h:85
@ ADCXX1C_NODEV
no ADCXX1C device found on the bus
Definition adcxx1c.h:86
@ ADCXX1C_OK
everything was fine
Definition adcxx1c.h:84
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:151
Low-level I2C peripheral driver interface definition.
ADCxx1C params.
Definition adcxx1c.h:101
uint8_t bits
resolution
Definition adcxx1c.h:104
gpio_t alert_pin
alert pin (GPIO_UNDEF if not connected)
Definition adcxx1c.h:106
int16_t hysteresis
alert hysteresis
Definition adcxx1c.h:109
int16_t low_limit
alert low value
Definition adcxx1c.h:107
i2c_t i2c
i2c device
Definition adcxx1c.h:102
uint8_t cycle
conversion interval
Definition adcxx1c.h:105
int16_t high_limit
alert high value
Definition adcxx1c.h:108
uint8_t addr
i2c address
Definition adcxx1c.h:103
ADCxx1C device descriptor.
Definition adcxx1c.h:120
adcxx1c_cb_t cb
alert callback
Definition adcxx1c.h:122
void * arg
alert callback param
Definition adcxx1c.h:123
adcxx1c_params_t params
device driver configuration
Definition adcxx1c.h:121