9#include <freertos/FreeRTOS.h>
10#include <freertos/task.h>
19static constexpr uint8_t MAX_CHANNELS = 8;
29 std::array<float, MAX_CHANNELS>
rms{};
30 std::array<float, MAX_CHANNELS>
mean{};
39 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
40 spi::CLOCK_PHASE_TRAILING, spi::DATA_RATE_8MHZ> {
42 void setup()
override;
74 bool transfer_frame_(uint16_t command, uint16_t data, uint16_t *response, int32_t *samples);
93 portMUX_TYPE
lock_ = portMUX_INITIALIZER_UNLOCKED;
Helper for FreeRTOS static task management.
TI ADS131M02/04/08 simultaneous-sampling 24-bit delta-sigma ADC (https://www.ti.com/lit/ds/symlink/ad...
void drain_fifo_()
Reads both FIFO slots back to back, as the datasheet requires after a gap in reading.
const LogString * configure_()
Resets (if a reset pin is set) and configures the device. Returns nullptr on success,...
uint32_t last_device_resets_
void dump_config() override
void set_gain(uint8_t channel, uint8_t gain_code)
std::atomic< uint32_t > device_resets_
void check_rate_(uint32_t elapsed_ms, uint32_t frames)
Averages the sample rate over several health checks and warns when conversions are being lost.
void set_window_ms(uint32_t window_ms)
InternalGPIOPin * reset_pin_
static void task_entry(void *arg)
uint32_t get_window_ms() const
uint8_t * frame_buf_
DMA-capable, allocated once in setup()
uint32_t rate_elapsed_ms_
void invalidate_snapshot_()
Marks the snapshot as invalid (sequence 0) until a full window has been sampled again.
void set_osr_code(uint8_t code)
bool transfer_frame_(uint16_t command, uint16_t data, uint16_t *response, int32_t *samples)
Clocks one full frame. Returns false on an output CRC mismatch. response receives the first word.
std::atomic< uint8_t > healthy_
size_t frame_bytes_() const
ADS131M0xPowerMode power_mode_
InternalGPIOPin * drdy_pin_
void set_sample_rate(float sample_rate)
size_t transfer_bytes_
Frame length, padded where the DMA requires it.
uint32_t last_crc_errors_
uint32_t rate_start_frames_
float get_full_scale(uint8_t channel) const
Input full scale of a channel in volts (the input range is +/- this value).
std::atomic< uint32_t > crc_errors_
void set_reset_pin(InternalGPIOPin *pin)
bool write_register_(uint8_t address, uint16_t value)
static void drdy_isr(ADS131M0x *self)
void set_drdy_pin(InternalGPIOPin *pin)
void set_power_mode(ADS131M0xPowerMode power_mode)
std::atomic< uint8_t > configured_
Snapshot get_snapshot()
Copy of the latest completed window; sequence is 0 until the first window after (re)configuration.
std::array< uint8_t, MAX_CHANNELS > gain_codes_
void set_num_channels(uint8_t num_channels)
uint32_t window_sequence_
bool read_register_(uint8_t address, uint16_t *value)
bool is_healthy() const
True while the device is configured and delivers samples at the expected rate.
uint32_t last_health_check_
std::atomic< uint32_t > frames_
The SPIDevice is what components using the SPI will create.
@ ADS131M0X_POWER_MODE_VERY_LOW_POWER
@ ADS131M0X_POWER_MODE_HIGH_RESOLUTION
@ ADS131M0X_POWER_MODE_LOW_POWER
Result of one measurement window, in volts at the ADC input.
uint32_t sequence
Incremented with every completed window; 0 = no valid data.
std::array< float, MAX_CHANNELS > mean
Mean (DC) value.
std::array< float, MAX_CHANNELS > rms
RMS of the AC component (DC offset removed)
uint32_t timestamp_ms
millis() at the end of the window