Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

include: [sensor-device.yaml, i2c-device.yaml]

compatible: "analog,adau1860"
compatible: "adi,adau1860"

properties:
enable-gpios:
Expand Down
20 changes: 20 additions & 0 deletions include/sensor_sink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef SENSOR_SINK_H
#define SENSOR_SINK_H

#include "openearable_common.h"
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

int sensor_sink_put(const struct sensor_msg *msg);

int sensor_sink_write_sd(const void *const *data_blocks, const size_t *lengths,
size_t block_count);

#ifdef __cplusplus
}
#endif

#endif
6 changes: 3 additions & 3 deletions src/ParseInfo/DefaultSensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
// ============= Microphones =============

#define MICRO_CHANNEL_COUNT 2
SensorComponent microComponenents[MICRO_CHANNEL_COUNT] = {
SensorComponent microComponents[MICRO_CHANNEL_COUNT] = {
{ .name = "INNER", .unit = "ADC", .parseType = PARSE_TYPE_UINT16 },
{ .name = "Outer", .unit = "ADC", .parseType = PARSE_TYPE_UINT16 },
{ .name = "OUTER", .unit = "ADC", .parseType = PARSE_TYPE_UINT16 },
};

#define MICRO_GROUP_COUNT 1
SensorComponentGroup microGroups[MICRO_GROUP_COUNT] = {
{ .name = "MICROPHONE", .componentCount = MICRO_CHANNEL_COUNT, .components = microComponenents },
{ .name = "MICROPHONE", .componentCount = MICRO_CHANNEL_COUNT, .components = microComponents },
};

// ============= IMU =============
Expand Down
2 changes: 1 addition & 1 deletion src/ParseInfo/ParseType.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum ParseType {
PARSE_TYPE_DOUBLE,
};

const int parseTypeSizes[] = {
static const int parseTypeSizes[] = {
1, // PARSE_TYPE_INT8
1, // PARSE_TYPE_UINT8

Expand Down
Empty file removed src/SensorManager/ANCDamping.cpp
Empty file.
Empty file removed src/SensorManager/ANCDamping.h
Empty file.
83 changes: 37 additions & 46 deletions src/SensorManager/BMA580/BMA580_Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
*
*/
#include <stdint.h>
// #include <stdlib.h>
// #include <stdio.h>

#include "bma5.h"
#include "BMA580_Sensor.h"
Expand Down Expand Up @@ -63,7 +61,7 @@ BMA5_INTF_RET_TYPE bma5_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t l
int ret;
BMA580_dev_inf * dev_info = (BMA580_dev_inf *) intf_ptr;

dev_info->i2c_dev->aquire();
dev_info->i2c_dev->acquire();

ret = i2c_burst_read(dev_info->i2c_dev->master, dev_info->addr, reg_addr, reg_data, len);
if (ret) LOG_WRN("I2C read failed: %d\n", ret);
Expand All @@ -79,7 +77,7 @@ BMA5_INTF_RET_TYPE bma5_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uin
{
BMA580_dev_inf * dev_info = (BMA580_dev_inf *) intf_ptr;

dev_info->i2c_dev->aquire();
dev_info->i2c_dev->acquire();

int ret = i2c_burst_write(dev_info->i2c_dev->master, dev_info->addr, reg_addr, reg_data, len);
if (ret) LOG_WRN("I2C write failed: %d", ret);
Expand Down Expand Up @@ -236,7 +234,10 @@ int8_t BMA580::get_accel_and_int_settings(struct bma5_dev *dev)
}

/*!
* @brief This internal API gets FIFO configurations.
* @brief This internal API sets FIFO configurations and verifies the readback
* matches what we asked for. The chip silently clamps fifo_size when the
* feature engine is enabled (datasheet section 4.6.1.5), so a missing log here
* is the only way to notice that condition without a logic analyzer.
*/
int8_t BMA580::get_fifo_conf(const struct bma5_fifo_conf *fifo_conf, struct bma5_dev *dev)
{
Expand All @@ -252,13 +253,18 @@ int8_t BMA580::get_fifo_conf(const struct bma5_fifo_conf *fifo_conf, struct bma5
rslt = bma5_get_fifo_conf(&read_fifo_conf, dev);
bma5_check_rslt("bma5_get_fifo_conf", rslt);

/* Verify that the chip accepted the size we asked for. */
if (read_fifo_conf.fifo_size != fifo_conf->fifo_size) {
LOG_ERR("FIFO size mismatch: requested 0x%02X, readback 0x%02X "
"(feature engine likely still enabled)",
fifo_conf->fifo_size, read_fifo_conf.fifo_size);
}

return rslt;
}

int BMA580::init(int odr, int fifo_watermark_level) {
int8_t rslt;
struct bma580_int_map int_map, get_int_map;
//struct bma5_fifo_conf fifo_conf;

/* Assign context parameter selection */
enum bma5_context context = BMA5_HEARABLE;
Expand All @@ -276,19 +282,20 @@ int BMA580::init(int odr, int fifo_watermark_level) {
bma5_check_rslt("bma580_init", rslt);
LOG_DBG("Chip ID :0x%X", dev.chip_id);

/* Map generic interrupts to hardware interrupt pin of the sensor */
rslt = bma580_get_int_map(&int_map, &dev);
bma5_check_rslt("bma580_get_int_map", rslt);

/* Set FIFO full interrupt to INT2 */
//int_map.fifo_full_int_map = BMA580_FIFO_FULL_INT_MAP_INT2;
int_map.fifo_wm_int_map = BMA580_FIFO_WM_INT_MAP_INT1;

rslt = bma580_set_int_map(&int_map, &dev);
bma5_check_rslt("bma580_set_int_map", rslt);

rslt = bma580_get_int_map(&get_int_map, &dev);
bma5_check_rslt("bma580_get_int_map", rslt);
/* Disable the feature engine. The BMA580 powers up with feat_eng enabled
* (FEAT_ENG_CONF reset value = 0x01), and feat_eng shares its 1024-byte
* RAM with the FIFO. While feat_eng is enabled the FIFO is capped at
* 512 bytes and any write of fifo_size = 0x03 (1024 B) is silently
* clamped to 0x02 (512 B) — verified empirically via the readback log
* in get_fifo_conf(). We don't use any feature-engine features
* (VAD, tap, generic interrupts, FOC, self-wakeup), so disabling it is
* safe and gives the FIFO its full 1024 bytes. */
rslt = bma5_set_feat_eng_conf(BMA5_FEAT_ENG_CTRL_DISABLE, &dev);
bma5_check_rslt("bma5_set_feat_eng_conf", rslt);

/* INT1/INT2 hardware interrupt pins are unused — FIFO is drained by a
* timer-based poll in BoneConduction::update_sensor, so we don't map
* the watermark or full interrupts to any pin. */

rslt = get_accel_and_int_settings(&dev);
bma5_check_rslt("get_accel_and_int_settings", rslt);
Expand All @@ -297,17 +304,14 @@ int BMA580::init(int odr, int fifo_watermark_level) {
rslt = bma5_get_fifo_conf(&fifo_conf, &dev);
bma5_check_rslt("bma5_get_fifo_conf", rslt);

rslt = bma5_get_fifo_conf(&fifo_conf, &dev);
bma5_check_rslt("bma5_get_fifo_conf", rslt);

fifo_conf.fifo_cfg = BMA5_FIFO_CFG_ENABLE;
fifo_conf.fifo_acc_x = BMA5_FIFO_ACC_X_ENABLE;
fifo_conf.fifo_acc_y = BMA5_FIFO_ACC_Y_ENABLE;
fifo_conf.fifo_acc_z = BMA5_FIFO_ACC_Z_ENABLE;
fifo_conf.fifo_compression = BMA5_FIFO_COMPRESSION_ACC_16BIT;
fifo_conf.fifo_sensor_time = BMA5_FIFO_SENSOR_TIME_OFF;
fifo_conf.fifo_size = BMA5_FIFO_SIZE_MAX_512_BYTES;
fifo_conf.fifo_stop_on_full = BMA5_ENABLE; //BMA5_ENABLE
fifo_conf.fifo_size = BMA5_FIFO_SIZE_MAX_1024_BYTES;
fifo_conf.fifo_stop_on_full = BMA5_DISABLE;

rslt = get_fifo_conf(&fifo_conf, &dev);
bma5_check_rslt("get_fifo_conf", rslt);
Expand Down Expand Up @@ -335,32 +339,19 @@ int BMA580::stop() {

int BMA580::read(bma5_sens_fifo_axes_data_16_bit *fifo_accel_data) {
int8_t rslt = BMA5_OK;
uint8_t n_status = 1;
struct bma580_int_status_types int_status = { 0 };

fifoframe.fifo_avail_frames = 0;

int_status.int_src = BMA580_INT_STATUS_INT1;

/* Get fifo full interrupt 2 status */
rslt = bma580_get_int_status(&int_status, n_status, &dev);
bma5_check_rslt("bma580_get_int_status", rslt);
/* Read whatever is in the FIFO — don't wait for watermark interrupt.
* When using a timer-based read at the FIFO fill rate, the watermark
* may not have triggered yet due to clock drift between the nRF5340
* and BMA580. Reading unconditionally avoids this race. */
rslt = bma5_read_fifo_data(&fifoframe, &fifo_conf, &dev);
bma5_check_rslt("bma5_read_fifo_data", rslt);

if (int_status.int_status.fifo_wm_int_status & BMA5_ENABLE)
if (rslt == BMA5_OK && fifoframe.fifo_avail_len > 0)
{
/* Read FIFO data */
rslt = bma5_read_fifo_data(&fifoframe, &fifo_conf, &dev);
bma5_check_rslt("bma5_read_fifo_data", rslt);

/* Set fifo full interrupt 2 status */
rslt = bma580_set_int_status(&int_status, n_status, &dev);
bma5_check_rslt("bma580_get_int_status\n", rslt);

if (rslt == BMA5_OK)
{
/* Parse the FIFO data to extract accelerometer and sensortime data from the FIFO buffer */
(void)bma5_extract_acc_sens_time_16_bit(fifo_accel_data, &fifoframe, &fifo_conf, &dev);
}
(void)bma5_extract_acc_sens_time_16_bit(fifo_accel_data, &fifoframe, &fifo_conf, &dev);
}

return fifoframe.fifo_avail_frames;
Expand Down
3 changes: 1 addition & 2 deletions src/SensorManager/BMA580/BMA580_Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@

#include <stdio.h>
#include "bma5.h"
//#include "Wire.h"
#include <TWIM.h>

/******************************************************************************/
/*! Macro definition */

/*! FIFO raw data buffer size */
#define BMA580_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(520)
#define BMA580_FIFO_RAW_DATA_BUFFER_SIZE UINT16_C(1032)

/*! Number of accel frames to be extracted from FIFO
* Calculation:
Expand Down
94 changes: 20 additions & 74 deletions src/SensorManager/BMP388/Adafruit_BMP3XX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Adafruit_BMP3XX::Adafruit_BMP3XX(void) {
}

bool Adafruit_BMP3XX::detect(int address) {
dev_inf.i2c_dev->aquire();
dev_inf.i2c_dev->acquire();
uint8_t dummy = 0;
int ret = i2c_write(dev_inf.i2c_dev->master, &dummy, 0, address);
dev_inf.i2c_dev->release();
Expand Down Expand Up @@ -140,16 +140,24 @@ bool Adafruit_BMP3XX::_init(void) {
printk("P9 = %i\n", the_sensor.calib_data.reg_calib_data.par_p9);
printk("P10 = %i\n", the_sensor.calib_data.reg_calib_data.par_p10);
printk("P11 = %i\n", the_sensor.calib_data.reg_calib_data.par_p11);
// printk("T lin = %i\n", the_sensor.calib_data.reg_calib_data.t_lin);
#endif

setTemperatureOversampling(BMP3_NO_OVERSAMPLING);
setPressureOversampling(BMP3_NO_OVERSAMPLING);
setIIRFilterCoeff(BMP3_IIR_FILTER_DISABLE);
setOutputDataRate(BMP3_ODR_25_HZ);

// don't do anything till we request a reading
the_sensor.settings.op_mode = BMP3_MODE_FORCED;
the_sensor.settings.temp_en = BMP3_ENABLE;
the_sensor.settings.press_en = BMP3_ENABLE;
uint16_t settings_sel = BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_EN | BMP3_SEL_ODR;
int8_t settings_rslt = bmp3_set_sensor_settings(settings_sel, &the_sensor);
if (settings_rslt != BMP3_OK)
return false;

the_sensor.settings.op_mode = BMP3_MODE_NORMAL;
settings_rslt = bmp3_set_op_mode(&the_sensor);
if (settings_rslt != BMP3_OK)
return false;

return true;
}
Expand Down Expand Up @@ -218,86 +226,24 @@ float Adafruit_BMP3XX::readAltitude(float seaLevel) {
*/
/**************************************************************************/
bool Adafruit_BMP3XX::performReading(void) {
//g_i2c_dev = i2c_dev;
//g_spi_dev = spi_dev;
int8_t rslt;
/* Used to select the settings user needs to change */
uint16_t settings_sel = 0;
/* Variable used to select the sensor component */
uint8_t sensor_comp = 0;

/* Select the pressure and temperature sensor to be enabled */
the_sensor.settings.temp_en = BMP3_ENABLE;
settings_sel |= BMP3_SEL_TEMP_EN;
sensor_comp |= BMP3_TEMP;
if (_tempOSEnabled) {
settings_sel |= BMP3_SEL_TEMP_OS;
}

the_sensor.settings.press_en = BMP3_ENABLE;
settings_sel |= BMP3_SEL_PRESS_EN;
sensor_comp |= BMP3_PRESS;
if (_presOSEnabled) {
settings_sel |= BMP3_SEL_PRESS_OS;
}

if (_filterEnabled) {
settings_sel |= BMP3_SEL_IIR_FILTER;
}

if (_ODREnabled) {
settings_sel |= BMP3_SEL_ODR;
}

// set interrupt to data ready
// settings_sel |= BMP3_DRDY_EN_SEL | BMP3_LEVEL_SEL | BMP3_LATCH_SEL;

/* Set the desired sensor configuration */
#ifdef BMP3XX_DEBUG
printk("Setting sensor settings\n");
#endif
rslt = bmp3_set_sensor_settings(settings_sel, &the_sensor);

if (rslt != BMP3_OK)
return false;

/* Set the power mode */
the_sensor.settings.op_mode = BMP3_MODE_FORCED;
#ifdef BMP3XX_DEBUG
printk("Setting power mode\n");
#endif
rslt = bmp3_set_op_mode(&the_sensor);
if (rslt != BMP3_OK)
return false;

/* Variable used to store the compensated data */
struct bmp3_data data;

/* Temperature and Pressure data are read and stored in the bmp3_data instance
*/
#ifdef BMP3XX_DEBUG
printk("Getting sensor data\n");
#endif
rslt = bmp3_get_sensor_data(sensor_comp, &data, &the_sensor);
rslt = bmp3_get_sensor_data(BMP3_TEMP | BMP3_PRESS, &data, &the_sensor);
if (rslt != BMP3_OK)
return false;

/*
#ifdef BMP3XX_DEBUG
Serial.println(F("Analyzing sensor data"));
#endif
rslt = analyze_sensor_data(&data);
if (rslt != BMP3_OK)
return false;
*/

/* Save the temperature and pressure data */
temperature = data.temperature;
pressure = data.pressure;

return true;
}

bool Adafruit_BMP3XX::sleep(void) {
the_sensor.settings.op_mode = BMP3_MODE_SLEEP;
return bmp3_set_op_mode(&the_sensor) == BMP3_OK;
}

/**************************************************************************/
/*!
@brief Setter for Temperature oversampling
Expand Down Expand Up @@ -403,7 +349,7 @@ int8_t i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len,

BMP3XX_dev_inf * dev_info = (BMP3XX_dev_inf *) intf_ptr;

dev_info->i2c_dev->aquire();
dev_info->i2c_dev->acquire();

int ret = i2c_burst_read(dev_info->i2c_dev->master, dev_info->addr, reg_addr, reg_data, len);
if (ret) LOG_WRN("I2C read failed: %d\n", ret);
Expand All @@ -422,7 +368,7 @@ int8_t i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len,
void *intf_ptr) {
BMP3XX_dev_inf * dev_info = (BMP3XX_dev_inf *) intf_ptr;

dev_info->i2c_dev->aquire();
dev_info->i2c_dev->acquire();

int ret = i2c_burst_write(dev_info->i2c_dev->master, dev_info->addr, reg_addr, reg_data, len);
if (ret) LOG_WRN("I2C write failed: %d", ret);
Expand Down
Loading
Loading