mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-13 08:33:49 +01:00
Merge pull request #21731 from baptleduc/rename-ads101x-driver
drivers: rename ads101x driver to ads1x1x
This commit is contained in:
commit
c5cb0c216b
80
dist/tools/doccheck/exclude_simple
vendored
80
dist/tools/doccheck/exclude_simple
vendored
@ -104,46 +104,46 @@ warning: Member ADI_SET (macro definition) of file cc26xx_cc13xx.h is not docume
|
||||
warning: Member ADPS9960_PARAM_ADDR (macro definition) of file board.h is not documented.
|
||||
warning: Member ADPS9960_PARAM_I2C (macro definition) of file board.h is not documented.
|
||||
warning: Member ADPS9960_PARAM_PIN_INT (macro definition) of file board.h is not documented.
|
||||
warning: Member ADS101X_AIN0_DIFFM_AIN1 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_AIN0_DIFFM_AIN3 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_AIN0_SINGM (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_AIN1_DIFFM_AIN3 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_AIN1_SINGM (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_AIN2_DIFFM_AIN3 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_AIN2_SINGM (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_AIN3_SINGM (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_ALERT_PARAMS (macro definition) of file ads101x_params.h is not documented.
|
||||
warning: Member ADS101X_CONF_ADDR (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_CONF_COMP_DIS (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_CONF_COMP_MODE_WIND (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_CONF_OS_CONV (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_CONV_RES_ADDR (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_DATAR_128 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_DATAR_1600 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_DATAR_2400 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_DATAR_250 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_DATAR_3300 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_DATAR_490 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_DATAR_920 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_DATAR_MASK (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_HIGH_LIMIT_ADDR (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_LOW_LIMIT_ADDR (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_MUX_MASK (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_PARAM_ADDR (macro definition) of file ads101x_params.h is not documented.
|
||||
warning: Member ADS101X_PARAM_ALERT_PIN (macro definition) of file ads101x_params.h is not documented.
|
||||
warning: Member ADS101X_PARAM_HIGH_LIMIT (macro definition) of file ads101x_params.h is not documented.
|
||||
warning: Member ADS101X_PARAM_I2C (macro definition) of file ads101x_params.h is not documented.
|
||||
warning: Member ADS101X_PARAM_LOW_LIMIT (macro definition) of file ads101x_params.h is not documented.
|
||||
warning: Member ADS101X_PARAM_MUX_GAIN (macro definition) of file ads101x_params.h is not documented.
|
||||
warning: Member ADS101X_PARAMS (macro definition) of file ads101x_params.h is not documented.
|
||||
warning: Member ADS101X_PGA_FSR_0V256 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_PGA_FSR_0V512 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_PGA_FSR_1V024 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_PGA_FSR_2V048 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_PGA_FSR_4V096 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_PGA_FSR_6V144 (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_PGA_MASK (macro definition) of file ads101x_regs.h is not documented.
|
||||
warning: Member ADS101X_SAUL_INFO (macro definition) of file ads101x_params.h is not documented.
|
||||
warning: Member ADS1X1X_AIN0_DIFFM_AIN1 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_AIN0_DIFFM_AIN3 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_AIN0_SINGM (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_AIN1_DIFFM_AIN3 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_AIN1_SINGM (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_AIN2_DIFFM_AIN3 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_AIN2_SINGM (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_AIN3_SINGM (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_ALERT_PARAMS (macro definition) of file ads1x1x_params.h is not documented.
|
||||
warning: Member ADS1X1X_CONF_ADDR (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_CONF_COMP_DIS (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_CONF_COMP_MODE_WIND (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_CONF_OS_CONV (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_CONV_RES_ADDR (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_DATAR_128 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_DATAR_1600 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_DATAR_2400 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_DATAR_250 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_DATAR_3300 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_DATAR_490 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_DATAR_920 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_DATAR_MASK (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_HIGH_LIMIT_ADDR (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_LOW_LIMIT_ADDR (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_MUX_MASK (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_PARAM_ADDR (macro definition) of file ads1x1x_params.h is not documented.
|
||||
warning: Member ADS1X1X_PARAM_ALERT_PIN (macro definition) of file ads1x1x_params.h is not documented.
|
||||
warning: Member ADS1X1X_PARAM_HIGH_LIMIT (macro definition) of file ads1x1x_params.h is not documented.
|
||||
warning: Member ADS1X1X_PARAM_I2C (macro definition) of file ads1x1x_params.h is not documented.
|
||||
warning: Member ADS1X1X_PARAM_LOW_LIMIT (macro definition) of file ads1x1x_params.h is not documented.
|
||||
warning: Member ADS1X1X_PARAM_MUX_GAIN (macro definition) of file ads1x1x_params.h is not documented.
|
||||
warning: Member ADS1X1X_PARAMS (macro definition) of file ads1x1x_params.h is not documented.
|
||||
warning: Member ADS1X1X_PGA_FSR_0V256 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_PGA_FSR_0V512 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_PGA_FSR_1V024 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_PGA_FSR_2V048 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_PGA_FSR_4V096 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_PGA_FSR_6V144 (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_PGA_MASK (macro definition) of file ads1x1x_internal.h is not documented.
|
||||
warning: Member ADS1X1X_SAUL_INFO (macro definition) of file ads1x1x_params.h is not documented.
|
||||
warning: Member ADT7310_CONF_CT_POL_MASK (macro definition) of group drivers_adt7310 is not documented.
|
||||
warning: Member ADT7310_CONF_CT_POL_SHIFT (macro definition) of group drivers_adt7310 is not documented.
|
||||
warning: Member ADT7310_CONF_CT_POL(x) (macro definition) of group drivers_adt7310 is not documented.
|
||||
|
||||
@ -29,7 +29,7 @@ rsource "periph_common/Kconfig"
|
||||
endmenu # Peripherals drivers
|
||||
|
||||
menu "Sensor Device Drivers"
|
||||
rsource "ads101x/Kconfig"
|
||||
rsource "ads1x1x/Kconfig"
|
||||
rsource "bmx055/Kconfig"
|
||||
rsource "fxos8700/Kconfig"
|
||||
rsource "gp2y10xx/Kconfig"
|
||||
|
||||
@ -5,7 +5,11 @@ ifneq (,$(filter adc%1c,$(USEMODULE)))
|
||||
endif
|
||||
|
||||
ifneq (,$(filter ads101%,$(USEMODULE)))
|
||||
USEMODULE += ads101x
|
||||
$(error "Module ads101x got renamed to ads1x1x.")
|
||||
endif
|
||||
|
||||
ifneq (,$(filter ads1x1%,$(USEMODULE)))
|
||||
USEMODULE += ads1x1x
|
||||
endif
|
||||
|
||||
ifneq (,$(filter apds99%,$(USEMODULE)))
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
USEMODULE_INCLUDES_ads101x := $(LAST_MAKEFILEDIR)/include
|
||||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_ads101x)
|
||||
@ -1,218 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 OTA keys S.A.
|
||||
* 2018 Acutam Automation, LLC
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_ads101x
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief ADS101x/111x ADC device driver
|
||||
*
|
||||
* @author Vincent Dupont <vincent@otakeys.com>
|
||||
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "assert.h"
|
||||
#include "periph/i2c.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "ztimer.h"
|
||||
|
||||
#include "ads101x.h"
|
||||
#include "ads101x_params.h"
|
||||
#include "ads101x_regs.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
#ifndef ADS101X_READ_DELAY_MS
|
||||
#define ADS101X_READ_DELAY_MS 8 /* ompatible with 128SPS */
|
||||
#endif
|
||||
|
||||
#define DEV (dev->params.i2c)
|
||||
#define ADDR (dev->params.addr)
|
||||
|
||||
static int _ads101x_init_test(i2c_t i2c, uint8_t addr);
|
||||
|
||||
int ads101x_init(ads101x_t *dev, const ads101x_params_t *params)
|
||||
{
|
||||
assert(dev && params);
|
||||
|
||||
dev->params = *params;
|
||||
|
||||
return _ads101x_init_test(DEV, ADDR);
|
||||
}
|
||||
|
||||
int ads101x_alert_init(ads101x_alert_t *dev,
|
||||
const ads101x_alert_params_t *params)
|
||||
{
|
||||
assert(dev && params);
|
||||
|
||||
dev->params = *params;
|
||||
dev->cb = NULL;
|
||||
dev->arg = NULL;
|
||||
|
||||
/* Set up alerts */
|
||||
ads101x_set_alert_parameters(dev, dev->params.low_limit,
|
||||
dev->params.high_limit);
|
||||
|
||||
return _ads101x_init_test(DEV, ADDR);
|
||||
}
|
||||
|
||||
static int _ads101x_init_test(i2c_t i2c, uint8_t addr)
|
||||
{
|
||||
uint8_t regs[2];
|
||||
|
||||
i2c_acquire(i2c);
|
||||
|
||||
/* Register read test */
|
||||
if (i2c_read_regs(i2c, addr, ADS101X_CONF_ADDR, ®s, 2, 0x0) < 0) {
|
||||
DEBUG("[ads101x] init - error: unable to read reg %x\n",
|
||||
ADS101X_CONF_ADDR);
|
||||
i2c_release(i2c);
|
||||
return ADS101X_NODEV;
|
||||
}
|
||||
|
||||
regs[1] = (regs[1] & ~ADS101X_DATAR_MASK) | ADS101X_DATAR_3300;
|
||||
|
||||
/* Register write test */
|
||||
if (i2c_write_regs(i2c, addr, ADS101X_CONF_ADDR, ®s, 2, 0x0) < 0) {
|
||||
DEBUG("[ads101x] init - error: unable to write reg %x\n",
|
||||
ADS101X_CONF_ADDR);
|
||||
i2c_release(i2c);
|
||||
return ADS101X_NODEV;
|
||||
}
|
||||
|
||||
i2c_read_regs(i2c, addr, ADS101X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
i2c_release(i2c);
|
||||
|
||||
/* Write should have actually written the register */
|
||||
if ((regs[1] & ADS101X_DATAR_MASK) != ADS101X_DATAR_3300) {
|
||||
DEBUG("[ads101x] init - error: unable to set reg (reg=%x)\n", regs[1]);
|
||||
return ADS101X_NODEV;
|
||||
}
|
||||
|
||||
return ADS101X_OK;
|
||||
}
|
||||
|
||||
int ads101x_set_mux_gain(const ads101x_t *dev, uint8_t mux_gain)
|
||||
{
|
||||
uint8_t regs[2];
|
||||
|
||||
i2c_acquire(DEV);
|
||||
|
||||
i2c_read_regs(DEV, ADDR, ADS101X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Zero mux and gain */
|
||||
regs[0] &= ~ADS101X_MUX_MASK;
|
||||
regs[0] &= ~ADS101X_PGA_MASK;
|
||||
|
||||
/* Write mux and gain */
|
||||
regs[0] |= mux_gain;
|
||||
|
||||
i2c_write_regs(DEV, ADDR, ADS101X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
i2c_release(DEV);
|
||||
|
||||
return ADS101X_OK;
|
||||
}
|
||||
|
||||
int ads101x_read_raw(const ads101x_t *dev, int16_t *raw)
|
||||
{
|
||||
uint8_t regs[2];
|
||||
|
||||
i2c_acquire(DEV);
|
||||
|
||||
/* Read control register */
|
||||
i2c_read_regs(DEV, ADDR, ADS101X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Tell the ADC to acquire a single-shot sample */
|
||||
regs[0] |= ADS101X_CONF_OS_CONV;
|
||||
i2c_write_regs(DEV, ADDR, ADS101X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Wait for the sample to be acquired */
|
||||
ztimer_sleep(ZTIMER_MSEC, ADS101X_READ_DELAY_MS);
|
||||
|
||||
/* Read the sample */
|
||||
if (i2c_read_regs(DEV, ADDR, ADS101X_CONV_RES_ADDR, ®s, 2, 0x0) < 0) {
|
||||
i2c_release(DEV);
|
||||
return ADS101X_NODATA;
|
||||
}
|
||||
|
||||
i2c_release(DEV);
|
||||
|
||||
/* If all okay, change raw value */
|
||||
*raw = (int16_t)(regs[0] << 8) | (int16_t)(regs[1]);
|
||||
|
||||
return ADS101X_OK;
|
||||
}
|
||||
|
||||
int ads101x_enable_alert(ads101x_alert_t *dev,
|
||||
ads101x_alert_cb_t cb, void *arg)
|
||||
{
|
||||
uint8_t regs[2];
|
||||
|
||||
if (!gpio_is_valid(dev->params.alert_pin)) {
|
||||
return ADS101X_OK;
|
||||
}
|
||||
|
||||
/* Read control register */
|
||||
i2c_acquire(DEV);
|
||||
i2c_read_regs(DEV, ADDR, ADS101X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Enable alert comparator */
|
||||
regs[1] &= ~ADS101X_CONF_COMP_DIS;
|
||||
i2c_write_regs(DEV, ADDR, ADS101X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
i2c_release(DEV);
|
||||
|
||||
/* Enable interrupt */
|
||||
dev->arg = arg;
|
||||
dev->cb = cb;
|
||||
gpio_init_int(dev->params.alert_pin, GPIO_IN, GPIO_FALLING, cb, arg);
|
||||
|
||||
return ADS101X_OK;
|
||||
}
|
||||
|
||||
int ads101x_set_alert_parameters(const ads101x_alert_t *dev,
|
||||
int16_t low_limit, int16_t high_limit)
|
||||
{
|
||||
uint8_t regs[2];
|
||||
|
||||
i2c_acquire(DEV);
|
||||
|
||||
/* Set up low_limit */
|
||||
regs[0] = (uint8_t)(low_limit >> 8);
|
||||
regs[1] = (uint8_t)low_limit;
|
||||
i2c_write_regs(DEV, ADDR, ADS101X_LOW_LIMIT_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Set up high_limit */
|
||||
regs[0] = (uint8_t)(high_limit >> 8);
|
||||
regs[1] = (uint8_t)high_limit;
|
||||
i2c_write_regs(DEV, ADDR, ADS101X_HIGH_LIMIT_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Read control register */
|
||||
i2c_read_regs(DEV, ADDR, ADS101X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Set up window mode */
|
||||
if (low_limit != 0) {
|
||||
/* Enable window mode */
|
||||
regs[1] |= ADS101X_CONF_COMP_MODE_WIND;
|
||||
}
|
||||
else {
|
||||
/* Disable window mode */
|
||||
regs[1] &= ~ADS101X_CONF_COMP_MODE_WIND;
|
||||
}
|
||||
i2c_write_regs(DEV, ADDR, ADS101X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
i2c_release(DEV);
|
||||
|
||||
return ADS101X_OK;
|
||||
}
|
||||
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 OTA keys S.A.
|
||||
* 2018 Acutam Automation, LLC
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @ingroup drivers_ads101x
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Default configuration for ADS101x/111x devices
|
||||
*
|
||||
* @author Vincent Dupont <vincent@otakeys.com>
|
||||
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "saul_reg.h"
|
||||
#include "ads101x.h"
|
||||
#include "ads101x_regs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name Set default configuration parameters for the ADS101x/111x driver
|
||||
* @{
|
||||
*/
|
||||
#ifndef ADS101X_PARAM_I2C
|
||||
#define ADS101X_PARAM_I2C (I2C_DEV(0))
|
||||
#endif
|
||||
#ifndef ADS101X_PARAM_ADDR
|
||||
#define ADS101X_PARAM_ADDR (CONFIG_ADS101X_I2C_ADDRESS)
|
||||
#endif
|
||||
#ifndef ADS101X_PARAM_MUX_GAIN
|
||||
#define ADS101X_PARAM_MUX_GAIN (ADS101X_AIN0_DIFFM_AIN1 \
|
||||
| ADS101X_PGA_FSR_2V048)
|
||||
#endif
|
||||
#ifndef ADS101X_PARAM_ALERT_PIN
|
||||
#define ADS101X_PARAM_ALERT_PIN (GPIO_UNDEF)
|
||||
#endif
|
||||
#ifndef ADS101X_PARAM_LOW_LIMIT
|
||||
#define ADS101X_PARAM_LOW_LIMIT (10000U)
|
||||
#endif
|
||||
#ifndef ADS101X_PARAM_HIGH_LIMIT
|
||||
#define ADS101X_PARAM_HIGH_LIMIT (20000U)
|
||||
#endif
|
||||
|
||||
#ifndef ADS101X_PARAMS
|
||||
#define ADS101X_PARAMS { .i2c = ADS101X_PARAM_I2C, \
|
||||
.addr = ADS101X_PARAM_ADDR, \
|
||||
.mux_gain = ADS101X_PARAM_MUX_GAIN }
|
||||
#endif
|
||||
|
||||
#ifndef ADS101X_ALERT_PARAMS
|
||||
#define ADS101X_ALERT_PARAMS { .i2c = ADS101X_PARAM_I2C, \
|
||||
.addr = ADS101X_PARAM_ADDR, \
|
||||
.alert_pin = ADS101X_PARAM_ALERT_PIN, \
|
||||
.low_limit = ADS101X_PARAM_LOW_LIMIT, \
|
||||
.high_limit = ADS101X_PARAM_HIGH_LIMIT }
|
||||
#endif
|
||||
#ifndef ADS101X_SAUL_INFO
|
||||
#define ADS101X_SAUL_INFO { .name = "ads101x" }
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief ADS101X/111x defaults if not defined for a board or application
|
||||
*/
|
||||
static const ads101x_params_t ads101x_params[] =
|
||||
{
|
||||
ADS101X_PARAMS
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief ADS101X/111x alert defaults if not defined for a board or application
|
||||
*/
|
||||
static const ads101x_alert_params_t ads101x_alert_params[] =
|
||||
{
|
||||
ADS101X_ALERT_PARAMS
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Additional meta information to keep in the SAUL registry
|
||||
*/
|
||||
static const saul_reg_info_t ads101x_saul_info[] =
|
||||
{
|
||||
ADS101X_SAUL_INFO
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 OTA keys S.A.
|
||||
* 2018 Acutam Automation, LLC
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @ingroup drivers_ads101x
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Register definition for ADS101x/111x devices
|
||||
*
|
||||
* @author Vincent Dupont <vincent@otakeys.com>
|
||||
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name ADS101x/111x register addresses
|
||||
* @{
|
||||
*/
|
||||
#define ADS101X_CONV_RES_ADDR (0)
|
||||
#define ADS101X_CONF_ADDR (1)
|
||||
#define ADS101X_LOW_LIMIT_ADDR (2)
|
||||
#define ADS101X_HIGH_LIMIT_ADDR (3)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name ADS101x/111x Config flags
|
||||
*
|
||||
* Comparator flags have no effect on ADS1013 and ADS1113.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define ADS101X_CONF_OS_CONV (1 << 7)
|
||||
#define ADS101X_CONF_COMP_MODE_WIND (1 << 4)
|
||||
#define ADS101X_CONF_COMP_DIS ((1 << 1) | (1 << 0))
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name ADS101x/111x mux settings
|
||||
*
|
||||
* Supports both single mode and differential.
|
||||
* This has no effect on ADS1013-4 and ADS1113-4.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define ADS101X_MUX_MASK ((1 << 6) | (1 << 5) | (1 << 4))
|
||||
#define ADS101X_AIN0_DIFFM_AIN1 ((0 << 6) | (0 << 5) | (0 << 4))
|
||||
#define ADS101X_AIN0_DIFFM_AIN3 ((0 << 6) | (0 << 5) | (1 << 4))
|
||||
#define ADS101X_AIN1_DIFFM_AIN3 ((0 << 6) | (1 << 5) | (0 << 4))
|
||||
#define ADS101X_AIN2_DIFFM_AIN3 ((0 << 6) | (1 << 5) | (1 << 4))
|
||||
#define ADS101X_AIN0_SINGM ((1 << 6) | (0 << 5) | (0 << 4))
|
||||
#define ADS101X_AIN1_SINGM ((1 << 6) | (0 << 5) | (1 << 4))
|
||||
#define ADS101X_AIN2_SINGM ((1 << 6) | (1 << 5) | (0 << 4))
|
||||
#define ADS101X_AIN3_SINGM ((1 << 6) | (1 << 5) | (1 << 4))
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name ADS101x/111x programmable gain
|
||||
*
|
||||
* Sets the full-scale range (max voltage value).
|
||||
* This has no effect on ADS1013 and ADS1113 (both use 2.048V FSR).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define ADS101X_PGA_MASK ((1 << 3) | (1 << 2) | (1 << 1))
|
||||
#define ADS101X_PGA_FSR_6V144 ((0 << 3) | (0 << 2) | (0 << 1))
|
||||
#define ADS101X_PGA_FSR_4V096 ((0 << 3) | (0 << 2) | (1 << 1))
|
||||
#define ADS101X_PGA_FSR_2V048 ((0 << 3) | (1 << 2) | (0 << 1))
|
||||
#define ADS101X_PGA_FSR_1V024 ((0 << 3) | (1 << 2) | (1 << 1))
|
||||
#define ADS101X_PGA_FSR_0V512 ((1 << 3) | (0 << 2) | (0 << 1))
|
||||
#define ADS101X_PGA_FSR_0V256 ((1 << 3) | (0 << 2) | (1 << 1))
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name ADS101x/111x data rate settings
|
||||
*
|
||||
* Determines how quickly samples are taken (even on one-shot mode)
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define ADS101X_DATAR_MASK ((1 << 7) | (1 << 6) | (1 << 5))
|
||||
#define ADS101X_DATAR_128 ((0 << 7) | (0 << 6) | (0 << 5))
|
||||
#define ADS101X_DATAR_250 ((0 << 7) | (0 << 6) | (1 << 5))
|
||||
#define ADS101X_DATAR_490 ((0 << 7) | (1 << 6) | (0 << 5))
|
||||
#define ADS101X_DATAR_920 ((0 << 7) | (1 << 6) | (1 << 5))
|
||||
#define ADS101X_DATAR_1600 ((1 << 7) | (0 << 6) | (0 << 5))
|
||||
#define ADS101X_DATAR_2400 ((1 << 7) | (0 << 6) | (1 << 5))
|
||||
#define ADS101X_DATAR_3300 ((1 << 7) | (1 << 6) | (0 << 5))
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
@ -5,16 +5,16 @@
|
||||
# directory for more details.
|
||||
#
|
||||
|
||||
menu "ADS101X driver"
|
||||
depends on USEMODULE_ADS101X
|
||||
menu "ADS1X1X driver"
|
||||
depends on USEMODULE_ADS1X1X
|
||||
|
||||
config ADS101X_I2C_ADDRESS
|
||||
config ADS1X1X_I2C_ADDRESS
|
||||
hex "Default I2C address"
|
||||
range 0x48 0x51
|
||||
default 0x48
|
||||
help
|
||||
ADS101X allows for upto 4 devices on Single Bus. The value depends on
|
||||
ADS1X1X allows for upto 4 devices on Single Bus. The value depends on
|
||||
the state of ADDR Pin. Default value (0x48) corresponds to ADDR pin tied
|
||||
to GND. For more information refer I2C Address Selection in Datasheet.
|
||||
|
||||
endmenu # ADS101X driver
|
||||
endmenu # ADS1X1X driver
|
||||
2
drivers/ads1x1x/Makefile.include
Normal file
2
drivers/ads1x1x/Makefile.include
Normal file
@ -0,0 +1,2 @@
|
||||
USEMODULE_INCLUDES_ads1x1x := $(LAST_MAKEFILEDIR)/include
|
||||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_ads1x1x)
|
||||
218
drivers/ads1x1x/ads1x1x.c
Normal file
218
drivers/ads1x1x/ads1x1x.c
Normal file
@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright (C) 2017 OTA keys S.A.
|
||||
* 2018 Acutam Automation, LLC
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_ads1x1x
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief ADS101x/111x ADC device driver
|
||||
*
|
||||
* @author Vincent Dupont <vincent@otakeys.com>
|
||||
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "assert.h"
|
||||
#include "periph/i2c.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "ztimer.h"
|
||||
|
||||
#include "ads1x1x.h"
|
||||
#include "ads1x1x_params.h"
|
||||
#include "ads1x1x_internal.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
#ifndef ADS1X1X_READ_DELAY_MS
|
||||
#define ADS1X1X_READ_DELAY_MS 8 /* ompatible with 128SPS */
|
||||
#endif
|
||||
|
||||
#define DEV (dev->params.i2c)
|
||||
#define ADDR (dev->params.addr)
|
||||
|
||||
static int _ads1x1x_init_test(i2c_t i2c, uint8_t addr);
|
||||
|
||||
int ads1x1x_init(ads1x1x_t *dev, const ads1x1x_params_t *params)
|
||||
{
|
||||
assert(dev && params);
|
||||
|
||||
dev->params = *params;
|
||||
|
||||
return _ads1x1x_init_test(DEV, ADDR);
|
||||
}
|
||||
|
||||
int ads1x1x_alert_init(ads1x1x_alert_t *dev,
|
||||
const ads1x1x_alert_params_t *params)
|
||||
{
|
||||
assert(dev && params);
|
||||
|
||||
dev->params = *params;
|
||||
dev->cb = NULL;
|
||||
dev->arg = NULL;
|
||||
|
||||
/* Set up alerts */
|
||||
ads1x1x_set_alert_parameters(dev, dev->params.low_limit,
|
||||
dev->params.high_limit);
|
||||
|
||||
return _ads1x1x_init_test(DEV, ADDR);
|
||||
}
|
||||
|
||||
static int _ads1x1x_init_test(i2c_t i2c, uint8_t addr)
|
||||
{
|
||||
uint8_t regs[2];
|
||||
|
||||
i2c_acquire(i2c);
|
||||
|
||||
/* Register read test */
|
||||
if (i2c_read_regs(i2c, addr, ADS1X1X_CONF_ADDR, ®s, 2, 0x0) < 0) {
|
||||
DEBUG("[ads1x1x] init - error: unable to read reg %x\n",
|
||||
ADS1X1X_CONF_ADDR);
|
||||
i2c_release(i2c);
|
||||
return ADS1X1X_NODEV;
|
||||
}
|
||||
|
||||
regs[1] = (regs[1] & ~ADS1X1X_DATAR_MASK) | ADS1X1X_DATAR_3300;
|
||||
|
||||
/* Register write test */
|
||||
if (i2c_write_regs(i2c, addr, ADS1X1X_CONF_ADDR, ®s, 2, 0x0) < 0) {
|
||||
DEBUG("[ads1x1x] init - error: unable to write reg %x\n",
|
||||
ADS1X1X_CONF_ADDR);
|
||||
i2c_release(i2c);
|
||||
return ADS1X1X_NODEV;
|
||||
}
|
||||
|
||||
i2c_read_regs(i2c, addr, ADS1X1X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
i2c_release(i2c);
|
||||
|
||||
/* Write should have actually written the register */
|
||||
if ((regs[1] & ADS1X1X_DATAR_MASK) != ADS1X1X_DATAR_3300) {
|
||||
DEBUG("[ads1x1x] init - error: unable to set reg (reg=%x)\n", regs[1]);
|
||||
return ADS1X1X_NODEV;
|
||||
}
|
||||
|
||||
return ADS1X1X_OK;
|
||||
}
|
||||
|
||||
int ads1x1x_set_mux_gain(const ads1x1x_t *dev, uint8_t mux_gain)
|
||||
{
|
||||
uint8_t regs[2];
|
||||
|
||||
i2c_acquire(DEV);
|
||||
|
||||
i2c_read_regs(DEV, ADDR, ADS1X1X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Zero mux and gain */
|
||||
regs[0] &= ~ADS1X1X_MUX_MASK;
|
||||
regs[0] &= ~ADS1X1X_PGA_MASK;
|
||||
|
||||
/* Write mux and gain */
|
||||
regs[0] |= mux_gain;
|
||||
|
||||
i2c_write_regs(DEV, ADDR, ADS1X1X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
i2c_release(DEV);
|
||||
|
||||
return ADS1X1X_OK;
|
||||
}
|
||||
|
||||
int ads1x1x_read_raw(const ads1x1x_t *dev, int16_t *raw)
|
||||
{
|
||||
uint8_t regs[2];
|
||||
|
||||
i2c_acquire(DEV);
|
||||
|
||||
/* Read control register */
|
||||
i2c_read_regs(DEV, ADDR, ADS1X1X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Tell the ADC to acquire a single-shot sample */
|
||||
regs[0] |= ADS1X1X_CONF_OS_CONV;
|
||||
i2c_write_regs(DEV, ADDR, ADS1X1X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Wait for the sample to be acquired */
|
||||
ztimer_sleep(ZTIMER_MSEC, ADS1X1X_READ_DELAY_MS);
|
||||
|
||||
/* Read the sample */
|
||||
if (i2c_read_regs(DEV, ADDR, ADS1X1X_CONV_RES_ADDR, ®s, 2, 0x0) < 0) {
|
||||
i2c_release(DEV);
|
||||
return ADS1X1X_NODATA;
|
||||
}
|
||||
|
||||
i2c_release(DEV);
|
||||
|
||||
/* If all okay, change raw value */
|
||||
*raw = (int16_t)(regs[0] << 8) | (int16_t)(regs[1]);
|
||||
|
||||
return ADS1X1X_OK;
|
||||
}
|
||||
|
||||
int ads1x1x_enable_alert(ads1x1x_alert_t *dev,
|
||||
ads1x1x_alert_cb_t cb, void *arg)
|
||||
{
|
||||
uint8_t regs[2];
|
||||
|
||||
if (!gpio_is_valid(dev->params.alert_pin)) {
|
||||
return ADS1X1X_OK;
|
||||
}
|
||||
|
||||
/* Read control register */
|
||||
i2c_acquire(DEV);
|
||||
i2c_read_regs(DEV, ADDR, ADS1X1X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Enable alert comparator */
|
||||
regs[1] &= ~ADS1X1X_CONF_COMP_DIS;
|
||||
i2c_write_regs(DEV, ADDR, ADS1X1X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
i2c_release(DEV);
|
||||
|
||||
/* Enable interrupt */
|
||||
dev->arg = arg;
|
||||
dev->cb = cb;
|
||||
gpio_init_int(dev->params.alert_pin, GPIO_IN, GPIO_FALLING, cb, arg);
|
||||
|
||||
return ADS1X1X_OK;
|
||||
}
|
||||
|
||||
int ads1x1x_set_alert_parameters(const ads1x1x_alert_t *dev,
|
||||
int16_t low_limit, int16_t high_limit)
|
||||
{
|
||||
uint8_t regs[2];
|
||||
|
||||
i2c_acquire(DEV);
|
||||
|
||||
/* Set up low_limit */
|
||||
regs[0] = (uint8_t)(low_limit >> 8);
|
||||
regs[1] = (uint8_t)low_limit;
|
||||
i2c_write_regs(DEV, ADDR, ADS1X1X_LOW_LIMIT_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Set up high_limit */
|
||||
regs[0] = (uint8_t)(high_limit >> 8);
|
||||
regs[1] = (uint8_t)high_limit;
|
||||
i2c_write_regs(DEV, ADDR, ADS1X1X_HIGH_LIMIT_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Read control register */
|
||||
i2c_read_regs(DEV, ADDR, ADS1X1X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
/* Set up window mode */
|
||||
if (low_limit != 0) {
|
||||
/* Enable window mode */
|
||||
regs[1] |= ADS1X1X_CONF_COMP_MODE_WIND;
|
||||
}
|
||||
else {
|
||||
/* Disable window mode */
|
||||
regs[1] &= ~ADS1X1X_CONF_COMP_MODE_WIND;
|
||||
}
|
||||
i2c_write_regs(DEV, ADDR, ADS1X1X_CONF_ADDR, ®s, 2, 0x0);
|
||||
|
||||
i2c_release(DEV);
|
||||
|
||||
return ADS1X1X_OK;
|
||||
}
|
||||
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_ads101x
|
||||
* @ingroup drivers_ads1x1x
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
@ -24,8 +24,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "saul.h"
|
||||
#include "ads101x.h"
|
||||
#include "ads101x_regs.h"
|
||||
#include "ads1x1x.h"
|
||||
#include "ads1x1x_internal.h"
|
||||
|
||||
/* LSB conversion to power of 10
|
||||
* (5/8) * 2^16 = 40960 */
|
||||
@ -33,20 +33,20 @@
|
||||
|
||||
static int read_adc(const void *dev, phydat_t *res)
|
||||
{
|
||||
const ads101x_t *mydev = dev;
|
||||
const ads1x1x_t *mydev = dev;
|
||||
|
||||
/* Change the mux channel */
|
||||
ads101x_set_mux_gain(mydev, mydev->params.mux_gain);
|
||||
ads1x1x_set_mux_gain(mydev, mydev->params.mux_gain);
|
||||
|
||||
/* Read raw value */
|
||||
if (ads101x_read_raw(mydev, res->val) < 0) {
|
||||
if (ads1x1x_read_raw(mydev, res->val) < 0) {
|
||||
return ECANCELED;
|
||||
}
|
||||
|
||||
/* Special case for 2.048V */
|
||||
/* (this is the fixed FSR of ADS1013 and ADS1113) */
|
||||
if ((mydev->params.mux_gain & ADS101X_PGA_MASK)
|
||||
== ADS101X_PGA_FSR_2V048) {
|
||||
if ((mydev->params.mux_gain & ADS1X1X_PGA_MASK)
|
||||
== ADS1X1X_PGA_FSR_2V048) {
|
||||
|
||||
/* LSB == 62.5uV to LSB == 100uV */
|
||||
*(res->val) = (int16_t)((CONV_TO_B10 * (int32_t)*(res->val)) >> 16);
|
||||
@ -64,7 +64,7 @@ static int read_adc(const void *dev, phydat_t *res)
|
||||
return 1;
|
||||
}
|
||||
|
||||
const saul_driver_t ads101x_saul_driver = {
|
||||
const saul_driver_t ads1x1x_saul_driver = {
|
||||
.read = read_adc,
|
||||
.write = saul_write_notsup,
|
||||
.type = SAUL_SENSE_ANALOG,
|
||||
106
drivers/ads1x1x/include/ads1x1x_internal.h
Normal file
106
drivers/ads1x1x/include/ads1x1x_internal.h
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2017 OTA keys S.A.
|
||||
* 2018 Acutam Automation, LLC
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @ingroup drivers_ads1x1x
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Register definition for ADS1X1X/111x devices
|
||||
*
|
||||
* @author Vincent Dupont <vincent@otakeys.com>
|
||||
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name ADS101X/111x register addresses
|
||||
* @{
|
||||
*/
|
||||
#define ADS1X1X_CONV_RES_ADDR (0)
|
||||
#define ADS1X1X_CONF_ADDR (1)
|
||||
#define ADS1X1X_LOW_LIMIT_ADDR (2)
|
||||
#define ADS1X1X_HIGH_LIMIT_ADDR (3)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name ADS101X/111x Config flags
|
||||
*
|
||||
* Comparator flags have no effect on ADS1013 and ADS1113.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define ADS1X1X_CONF_OS_CONV (1 << 7)
|
||||
#define ADS1X1X_CONF_COMP_MODE_WIND (1 << 4)
|
||||
#define ADS1X1X_CONF_COMP_DIS ((1 << 1) | (1 << 0))
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name ADS101X/111x mux settings
|
||||
*
|
||||
* Supports both single mode and differential.
|
||||
* This has no effect on ADS1013-4 and ADS1113-4.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define ADS1X1X_MUX_MASK ((1 << 6) | (1 << 5) | (1 << 4))
|
||||
#define ADS1X1X_AIN0_DIFFM_AIN1 ((0 << 6) | (0 << 5) | (0 << 4))
|
||||
#define ADS1X1X_AIN0_DIFFM_AIN3 ((0 << 6) | (0 << 5) | (1 << 4))
|
||||
#define ADS1X1X_AIN1_DIFFM_AIN3 ((0 << 6) | (1 << 5) | (0 << 4))
|
||||
#define ADS1X1X_AIN2_DIFFM_AIN3 ((0 << 6) | (1 << 5) | (1 << 4))
|
||||
#define ADS1X1X_AIN0_SINGM ((1 << 6) | (0 << 5) | (0 << 4))
|
||||
#define ADS1X1X_AIN1_SINGM ((1 << 6) | (0 << 5) | (1 << 4))
|
||||
#define ADS1X1X_AIN2_SINGM ((1 << 6) | (1 << 5) | (0 << 4))
|
||||
#define ADS1X1X_AIN3_SINGM ((1 << 6) | (1 << 5) | (1 << 4))
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name ADS101X/111x programmable gain
|
||||
*
|
||||
* Sets the full-scale range (max voltage value).
|
||||
* This has no effect on ADS1013 and ADS1113 (both use 2.048V FSR).
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define ADS1X1X_PGA_MASK ((1 << 3) | (1 << 2) | (1 << 1))
|
||||
#define ADS1X1X_PGA_FSR_6V144 ((0 << 3) | (0 << 2) | (0 << 1))
|
||||
#define ADS1X1X_PGA_FSR_4V096 ((0 << 3) | (0 << 2) | (1 << 1))
|
||||
#define ADS1X1X_PGA_FSR_2V048 ((0 << 3) | (1 << 2) | (0 << 1))
|
||||
#define ADS1X1X_PGA_FSR_1V024 ((0 << 3) | (1 << 2) | (1 << 1))
|
||||
#define ADS1X1X_PGA_FSR_0V512 ((1 << 3) | (0 << 2) | (0 << 1))
|
||||
#define ADS1X1X_PGA_FSR_0V256 ((1 << 3) | (0 << 2) | (1 << 1))
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name ADS101X/111x data rate settings
|
||||
*
|
||||
* Determines how quickly samples are taken (even on one-shot mode)
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define ADS1X1X_DATAR_MASK ((1 << 7) | (1 << 6) | (1 << 5))
|
||||
#define ADS1X1X_DATAR_128 ((0 << 7) | (0 << 6) | (0 << 5))
|
||||
#define ADS1X1X_DATAR_250 ((0 << 7) | (0 << 6) | (1 << 5))
|
||||
#define ADS1X1X_DATAR_490 ((0 << 7) | (1 << 6) | (0 << 5))
|
||||
#define ADS1X1X_DATAR_920 ((0 << 7) | (1 << 6) | (1 << 5))
|
||||
#define ADS1X1X_DATAR_1600 ((1 << 7) | (0 << 6) | (0 << 5))
|
||||
#define ADS1X1X_DATAR_2400 ((1 << 7) | (0 << 6) | (1 << 5))
|
||||
#define ADS1X1X_DATAR_3300 ((1 << 7) | (1 << 6) | (0 << 5))
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
102
drivers/ads1x1x/include/ads1x1x_params.h
Normal file
102
drivers/ads1x1x/include/ads1x1x_params.h
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2017 OTA keys S.A.
|
||||
* 2018 Acutam Automation, LLC
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @ingroup drivers_ads1x1x
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Default configuration for ADS101x/111x devices
|
||||
*
|
||||
* @author Vincent Dupont <vincent@otakeys.com>
|
||||
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "saul_reg.h"
|
||||
#include "ads1x1x.h"
|
||||
#include "ads1x1x_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name Set default configuration parameters for the ADS101x/111x driver
|
||||
* @{
|
||||
*/
|
||||
#ifndef ADS1X1X_PARAM_I2C
|
||||
#define ADS1X1X_PARAM_I2C (I2C_DEV(0))
|
||||
#endif
|
||||
#ifndef ADS1X1X_PARAM_ADDR
|
||||
#define ADS1X1X_PARAM_ADDR (CONFIG_ADS1X1X_I2C_ADDRESS)
|
||||
#endif
|
||||
#ifndef ADS1X1X_PARAM_MUX_GAIN
|
||||
#define ADS1X1X_PARAM_MUX_GAIN (ADS1X1X_AIN0_DIFFM_AIN1 \
|
||||
| ADS1X1X_PGA_FSR_2V048)
|
||||
#endif
|
||||
#ifndef ADS1X1X_PARAM_ALERT_PIN
|
||||
#define ADS1X1X_PARAM_ALERT_PIN (GPIO_UNDEF)
|
||||
#endif
|
||||
#ifndef ADS1X1X_PARAM_LOW_LIMIT
|
||||
#define ADS1X1X_PARAM_LOW_LIMIT (10000U)
|
||||
#endif
|
||||
#ifndef ADS1X1X_PARAM_HIGH_LIMIT
|
||||
#define ADS1X1X_PARAM_HIGH_LIMIT (20000U)
|
||||
#endif
|
||||
|
||||
#ifndef ADS1X1X_PARAMS
|
||||
#define ADS1X1X_PARAMS { .i2c = ADS1X1X_PARAM_I2C, \
|
||||
.addr = ADS1X1X_PARAM_ADDR, \
|
||||
.mux_gain = ADS1X1X_PARAM_MUX_GAIN }
|
||||
#endif
|
||||
|
||||
#ifndef ADS1X1X_ALERT_PARAMS
|
||||
#define ADS1X1X_ALERT_PARAMS { .i2c = ADS1X1X_PARAM_I2C, \
|
||||
.addr = ADS1X1X_PARAM_ADDR, \
|
||||
.alert_pin = ADS1X1X_PARAM_ALERT_PIN, \
|
||||
.low_limit = ADS1X1X_PARAM_LOW_LIMIT, \
|
||||
.high_limit = ADS1X1X_PARAM_HIGH_LIMIT }
|
||||
#endif
|
||||
#ifndef ADS1X1X_SAUL_INFO
|
||||
#define ADS1X1X_SAUL_INFO { .name = "ads1x1x" }
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief ADS101X/111x defaults if not defined for a board or application
|
||||
*/
|
||||
static const ads1x1x_params_t ads1x1x_params[] =
|
||||
{
|
||||
ADS1X1X_PARAMS
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief ADS101X/111x alert defaults if not defined for a board or application
|
||||
*/
|
||||
static const ads1x1x_alert_params_t ads1x1x_alert_params[] =
|
||||
{
|
||||
ADS1X1X_ALERT_PARAMS
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Additional meta information to keep in the SAUL registry
|
||||
*/
|
||||
static const saul_reg_info_t ads1x1x_saul_info[] =
|
||||
{
|
||||
ADS1X1X_SAUL_INFO
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
@ -10,7 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @defgroup drivers_ads101x ADS101x/111x ADC device driver
|
||||
* @defgroup drivers_ads1x1x ADS101x/111x ADC device driver
|
||||
* @ingroup drivers_sensors
|
||||
* @ingroup drivers_saul
|
||||
* @brief I2C Analog-to-Digital Converter device driver
|
||||
@ -38,7 +38,7 @@ extern "C" {
|
||||
#include "periph/gpio.h"
|
||||
|
||||
/**
|
||||
* @defgroup drivers_ads101x_config ADS101 driver compile configuration
|
||||
* @defgroup drivers_ads1x1x_config ADS101 driver compile configuration
|
||||
* @ingroup config_drivers_sensors
|
||||
* @{
|
||||
*/
|
||||
@ -48,8 +48,8 @@ extern "C" {
|
||||
*
|
||||
* Address pin tied to: GND (0x48), Vcc (0x49), SDA (0x50), SCL (0x51)
|
||||
*/
|
||||
#ifndef CONFIG_ADS101X_I2C_ADDRESS
|
||||
#define CONFIG_ADS101X_I2C_ADDRESS (0x48)
|
||||
#ifndef CONFIG_ADS1X1X_I2C_ADDRESS
|
||||
#define CONFIG_ADS1X1X_I2C_ADDRESS (0x48)
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
@ -57,52 +57,52 @@ extern "C" {
|
||||
* @brief Named return values
|
||||
*/
|
||||
enum {
|
||||
ADS101X_OK = 0, /**< everything was fine */
|
||||
ADS101X_NOI2C = -1, /**< I2C communication failed */
|
||||
ADS101X_NODEV = -2, /**< no ADS101X device found on the bus */
|
||||
ADS101X_NODATA = -3 /**< no data available */
|
||||
ADS1X1X_OK = 0, /**< everything was fine */
|
||||
ADS1X1X_NOI2C = -1, /**< I2C communication failed */
|
||||
ADS1X1X_NODEV = -2, /**< no ADS1X1X device found on the bus */
|
||||
ADS1X1X_NODATA = -3 /**< no data available */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief ADS101x/111x params
|
||||
*/
|
||||
typedef struct ads101x_params {
|
||||
typedef struct ads1x1x_params {
|
||||
i2c_t i2c; /**< i2c device */
|
||||
uint8_t addr; /**< i2c address */
|
||||
uint8_t mux_gain; /**< Mux and gain boolean settings */
|
||||
} ads101x_params_t;
|
||||
} ads1x1x_params_t;
|
||||
|
||||
/**
|
||||
* @brief ADS101x/111x alert params
|
||||
*/
|
||||
typedef struct ads101x_alert_params {
|
||||
typedef struct ads1x1x_alert_params {
|
||||
i2c_t i2c; /**< i2c device */
|
||||
uint8_t addr; /**< i2c address */
|
||||
gpio_t alert_pin; /**< alert pin (GPIO_UNDEF if not connected) */
|
||||
int16_t low_limit; /**< alert low value */
|
||||
int16_t high_limit; /**< alert high value */
|
||||
} ads101x_alert_params_t;
|
||||
} ads1x1x_alert_params_t;
|
||||
|
||||
/**
|
||||
* @brief ADS101x/111x device descriptor
|
||||
*/
|
||||
typedef struct ads101x {
|
||||
ads101x_params_t params; /**< device driver configuration */
|
||||
} ads101x_t;
|
||||
typedef struct ads1x1x {
|
||||
ads1x1x_params_t params; /**< device driver configuration */
|
||||
} ads1x1x_t;
|
||||
|
||||
/**
|
||||
* @brief ADS101x/111x alert callback
|
||||
*/
|
||||
typedef void (*ads101x_alert_cb_t)(void *);
|
||||
typedef void (*ads1x1x_alert_cb_t)(void *);
|
||||
|
||||
/**
|
||||
* @brief ADS101x/111x alert device descriptor
|
||||
*/
|
||||
typedef struct ads101x_alert {
|
||||
ads101x_alert_params_t params; /**< device driver configuration */
|
||||
ads101x_alert_cb_t cb; /**< alert callback */
|
||||
typedef struct ads1x1x_alert {
|
||||
ads1x1x_alert_params_t params; /**< device driver configuration */
|
||||
ads1x1x_alert_cb_t cb; /**< alert callback */
|
||||
void *arg; /**< alert callback param */
|
||||
} ads101x_alert_t;
|
||||
} ads1x1x_alert_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize an ADS101x/111x ADC device (ADC only)
|
||||
@ -112,7 +112,7 @@ typedef struct ads101x_alert {
|
||||
*
|
||||
* @return zero on successful initialization, non zero on error
|
||||
*/
|
||||
int ads101x_init(ads101x_t *dev, const ads101x_params_t *params);
|
||||
int ads1x1x_init(ads1x1x_t *dev, const ads1x1x_params_t *params);
|
||||
|
||||
/**
|
||||
* @brief Initialize an ADS101x/111x alert device
|
||||
@ -122,8 +122,8 @@ int ads101x_init(ads101x_t *dev, const ads101x_params_t *params);
|
||||
*
|
||||
* @return zero on successful initialization, non zero on error
|
||||
*/
|
||||
int ads101x_alert_init(ads101x_alert_t *dev,
|
||||
const ads101x_alert_params_t *params);
|
||||
int ads1x1x_alert_init(ads1x1x_alert_t *dev,
|
||||
const ads1x1x_alert_params_t *params);
|
||||
|
||||
/**
|
||||
* @brief Set mux and gain
|
||||
@ -136,7 +136,7 @@ int ads101x_alert_init(ads101x_alert_t *dev,
|
||||
*
|
||||
* @return zero on successful read, non zero on error
|
||||
*/
|
||||
int ads101x_set_mux_gain(const ads101x_t *dev, uint8_t mux_gain);
|
||||
int ads1x1x_set_mux_gain(const ads1x1x_t *dev, uint8_t mux_gain);
|
||||
|
||||
/**
|
||||
* @brief Read a raw ADC value
|
||||
@ -146,7 +146,7 @@ int ads101x_set_mux_gain(const ads101x_t *dev, uint8_t mux_gain);
|
||||
*
|
||||
* @return zero on successful read, non zero on error
|
||||
*/
|
||||
int ads101x_read_raw(const ads101x_t *dev, int16_t *raw);
|
||||
int ads1x1x_read_raw(const ads1x1x_t *dev, int16_t *raw);
|
||||
|
||||
/**
|
||||
* @brief Enable alert interrupt
|
||||
@ -159,8 +159,8 @@ int ads101x_read_raw(const ads101x_t *dev, int16_t *raw);
|
||||
*
|
||||
* @return zero on success, non zero on error
|
||||
*/
|
||||
int ads101x_enable_alert(ads101x_alert_t *dev,
|
||||
ads101x_alert_cb_t cb, void *arg);
|
||||
int ads1x1x_enable_alert(ads1x1x_alert_t *dev,
|
||||
ads1x1x_alert_cb_t cb, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Set the alert parameters
|
||||
@ -173,7 +173,7 @@ int ads101x_enable_alert(ads101x_alert_t *dev,
|
||||
*
|
||||
* @return zero on success, non zero on error
|
||||
*/
|
||||
int ads101x_set_alert_parameters(const ads101x_alert_t *dev,
|
||||
int ads1x1x_set_alert_parameters(const ads1x1x_alert_t *dev,
|
||||
int16_t low_limit, int16_t high_limit);
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -25,48 +25,49 @@
|
||||
#include "log.h"
|
||||
|
||||
#include "saul_reg.h"
|
||||
#include "ads101x.h"
|
||||
#include "ads101x_params.h"
|
||||
#include "ads1x1x.h"
|
||||
#include "ads1x1x_params.h"
|
||||
#include "container.h"
|
||||
|
||||
/**
|
||||
* @brief Define the number of configured sensors
|
||||
*/
|
||||
#define ADS101X_NUM ARRAY_SIZE(ads101x_params)
|
||||
#define ADS1X1X_NUM ARRAY_SIZE(ads1x1x_params)
|
||||
|
||||
/**
|
||||
* @brief Allocate memory for the device descriptors
|
||||
*/
|
||||
static ads101x_t ads101x_devs[ADS101X_NUM];
|
||||
static ads1x1x_t ads1x1x_devs[ADS1X1X_NUM];
|
||||
|
||||
/**
|
||||
* @brief Memory for the SAUL registry entries
|
||||
*/
|
||||
static saul_reg_t saul_entries[ADS101X_NUM];
|
||||
static saul_reg_t saul_entries[ADS1X1X_NUM];
|
||||
|
||||
/**
|
||||
* @brief Define the number of saul info
|
||||
*/
|
||||
#define ADS101X_INFO_NUM ARRAY_SIZE(ads101x_saul_info)
|
||||
#define ADS1X1X_INFO_NUM ARRAY_SIZE(ads1x1x_saul_info)
|
||||
|
||||
/**
|
||||
* @brief Reference the driver struct
|
||||
*/
|
||||
extern saul_driver_t ads101x_saul_driver;
|
||||
extern saul_driver_t ads1x1x_saul_driver;
|
||||
|
||||
void auto_init_ads101x(void)
|
||||
void auto_init_ads1x1x(void)
|
||||
{
|
||||
assert(ADS101X_INFO_NUM == ADS101X_NUM);
|
||||
assert(ADS1X1X_INFO_NUM == ADS1X1X_NUM);
|
||||
|
||||
for (unsigned i = 0; i < ADS101X_NUM; i++) {
|
||||
LOG_DEBUG("[auto_init_saul] initializing ads101x #%d\n", i);
|
||||
if (ads101x_init(&ads101x_devs[i], &ads101x_params[i]) < 0) {
|
||||
LOG_ERROR("[auto_init_saul] error initializing ads101x #%d\n", i);
|
||||
for (unsigned i = 0; i < ADS1X1X_NUM; i++) {
|
||||
LOG_DEBUG("[auto_init_saul] initializing ads1x1x #%d\n", i);
|
||||
if (ads1x1x_init(&ads1x1x_devs[i], &ads1x1x_params[i]) < 0) {
|
||||
LOG_ERROR("[auto_init_saul] error initializing ads1x1x #%d\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
saul_entries[i].dev = &(ads101x_devs[i]);
|
||||
saul_entries[i].name = ads101x_saul_info[i].name;
|
||||
saul_entries[i].driver = &ads101x_saul_driver;
|
||||
saul_entries[i].dev = &(ads1x1x_devs[i]);
|
||||
saul_entries[i].name = ads1x1x_saul_info[i].name;
|
||||
saul_entries[i].driver = &ads1x1x_saul_driver;
|
||||
saul_reg_add(&(saul_entries[i]));
|
||||
}
|
||||
}
|
||||
@ -63,9 +63,9 @@ void saul_init_devs(void)
|
||||
extern void auto_init_adcxx1c(void);
|
||||
auto_init_adcxx1c();
|
||||
}
|
||||
if (IS_USED(MODULE_ADS101X)) {
|
||||
extern void auto_init_ads101x(void);
|
||||
auto_init_ads101x();
|
||||
if (IS_USED(MODULE_ADS1X1X)) {
|
||||
extern void auto_init_ads1x1x(void);
|
||||
auto_init_ads1x1x();
|
||||
}
|
||||
if (IS_USED(MODULE_ADXL345)) {
|
||||
extern void auto_init_adxl345(void);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
include ../Makefile.drivers_common
|
||||
|
||||
USEMODULE += ads101x
|
||||
USEMODULE += ads1x1x
|
||||
USEMODULE += ztimer
|
||||
USEMODULE += ztimer_msec
|
||||
|
||||
@ -19,14 +19,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ztimer.h"
|
||||
#include "ads101x.h"
|
||||
#include "ads101x_params.h"
|
||||
#include "ads101x_regs.h"
|
||||
#include "ads1x1x.h"
|
||||
#include "ads1x1x_params.h"
|
||||
#include "ads1x1x_internal.h"
|
||||
|
||||
#define SLEEP_MSEC 100
|
||||
|
||||
static ads101x_t dev;
|
||||
static ads101x_alert_t alert_dev;
|
||||
static ads1x1x_t dev;
|
||||
static ads1x1x_alert_t alert_dev;
|
||||
|
||||
static void alert_cb(void *arg)
|
||||
{
|
||||
@ -38,11 +38,11 @@ int main(void)
|
||||
{
|
||||
int16_t data;
|
||||
|
||||
puts("ADS101X analog to digital driver test application\n");
|
||||
puts("ADS1X1X analog to digital driver test application\n");
|
||||
printf("Initializing ADS101x analog to digital at I2C_DEV(%i)... ",
|
||||
ads101x_params->i2c);
|
||||
ads1x1x_params->i2c);
|
||||
|
||||
if (ads101x_init(&dev, ads101x_params) == ADS101X_OK) {
|
||||
if (ads1x1x_init(&dev, ads1x1x_params) == ADS1X1X_OK) {
|
||||
puts("[OK]");
|
||||
}
|
||||
else {
|
||||
@ -50,10 +50,10 @@ int main(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Initializing ADS101x alert at I2C_DEV(%i)... ",
|
||||
ads101x_alert_params->i2c);
|
||||
printf("Initializing ADS1X1X alert at I2C_DEV(%i)... ",
|
||||
ads1x1x_alert_params->i2c);
|
||||
|
||||
if (ads101x_alert_init(&alert_dev, ads101x_alert_params) == ADS101X_OK) {
|
||||
if (ads1x1x_alert_init(&alert_dev, ads1x1x_alert_params) == ADS1X1X_OK) {
|
||||
puts("[OK]");
|
||||
}
|
||||
else {
|
||||
@ -62,7 +62,7 @@ int main(void)
|
||||
}
|
||||
|
||||
printf("Enabling alert interrupt: ");
|
||||
if (ads101x_enable_alert(&alert_dev, alert_cb, NULL) == ADS101X_OK) {
|
||||
if (ads1x1x_enable_alert(&alert_dev, alert_cb, NULL) == ADS1X1X_OK) {
|
||||
puts("[OK]");
|
||||
}
|
||||
else {
|
||||
@ -72,8 +72,8 @@ int main(void)
|
||||
|
||||
while (1) {
|
||||
printf("Raw analog read. CH0: ");
|
||||
ads101x_set_mux_gain(&dev, ADS101X_AIN0_SINGM | ADS101X_PGA_FSR_2V048);
|
||||
if (ads101x_read_raw(&dev, &data) == ADS101X_OK) {
|
||||
ads1x1x_set_mux_gain(&dev, ADS1X1X_AIN0_SINGM | ADS1X1X_PGA_FSR_2V048);
|
||||
if (ads1x1x_read_raw(&dev, &data) == ADS1X1X_OK) {
|
||||
printf("%d", data);
|
||||
}
|
||||
else {
|
||||
@ -82,8 +82,8 @@ int main(void)
|
||||
}
|
||||
|
||||
printf(" CH1: ");
|
||||
ads101x_set_mux_gain(&dev, ADS101X_AIN1_SINGM | ADS101X_PGA_FSR_2V048);
|
||||
if (ads101x_read_raw(&dev, &data) == ADS101X_OK) {
|
||||
ads1x1x_set_mux_gain(&dev, ADS1X1X_AIN1_SINGM | ADS1X1X_PGA_FSR_2V048);
|
||||
if (ads1x1x_read_raw(&dev, &data) == ADS1X1X_OK) {
|
||||
printf("%d", data);
|
||||
}
|
||||
else {
|
||||
@ -92,8 +92,8 @@ int main(void)
|
||||
}
|
||||
|
||||
printf(" CH2: ");
|
||||
ads101x_set_mux_gain(&dev, ADS101X_AIN2_SINGM | ADS101X_PGA_FSR_2V048);
|
||||
if (ads101x_read_raw(&dev, &data) == ADS101X_OK) {
|
||||
ads1x1x_set_mux_gain(&dev, ADS1X1X_AIN2_SINGM | ADS1X1X_PGA_FSR_2V048);
|
||||
if (ads1x1x_read_raw(&dev, &data) == ADS1X1X_OK) {
|
||||
printf("%d", data);
|
||||
}
|
||||
else {
|
||||
@ -102,8 +102,8 @@ int main(void)
|
||||
}
|
||||
|
||||
printf(" CH3: ");
|
||||
ads101x_set_mux_gain(&dev, ADS101X_AIN3_SINGM | ADS101X_PGA_FSR_2V048);
|
||||
if (ads101x_read_raw(&dev, &data) == ADS101X_OK) {
|
||||
ads1x1x_set_mux_gain(&dev, ADS1X1X_AIN3_SINGM | ADS1X1X_PGA_FSR_2V048);
|
||||
if (ads1x1x_read_raw(&dev, &data) == ADS1X1X_OK) {
|
||||
printf("%d", data);
|
||||
}
|
||||
else {
|
||||
Loading…
x
Reference in New Issue
Block a user