18#include <libtock-sync/services/alarm.h>
19#include <libtock/peripherals/i2c_master.h>
20#include <libtock/tock.h>
22#include "../proto/sensor.h"
25static const double voltage_calibration_m = -0.00039326;
26static const double voltage_calibration_b = 4.92916378e-05;
27static const double current_calibration_m = -1.18693164e-10;
28static const double current_calibration_b = 4.14518594e-05;
30static const uint8_t addr = 0x40;
32static uint8_t addrls = addr << 1;
127 int ret = RETURNCODE_SUCCESS;
131 ret = i2c_master_write_sync(addrls, write_buf, 1);
132 if (ret != RETURNCODE_SUCCESS) {
137 libtocksync_alarm_delay_ms(1);
143 int ret = RETURNCODE_SUCCESS;
145 ret = i2c_master_write_sync(addrls, (uint8_t*)i2c_data,
sizeof(i2c_data));
146 if (ret != RETURNCODE_SUCCESS) {
180 *voltage = (voltage_calibration_m * (double)raw) + voltage_calibration_b;
215 *current = (current_calibration_m * (double)raw) + current_calibration_b;
232 int ret = RETURNCODE_SUCCESS;
234 uint8_t rx_data[3] = {0x00, 0x00, 0x00};
240 ret = i2c_master_write_sync(addrls, buf, 1);
241 if (ret != RETURNCODE_SUCCESS) {
246 libtocksync_alarm_delay_ms(100);
254 ret = i2c_master_write_sync(addrls, buf, 1);
255 if (ret != RETURNCODE_SUCCESS) {
260 ret = i2c_master_read_sync(addrls, rx_data, 3);
261 if (ret != RETURNCODE_SUCCESS) {
268 *meas = ((int32_t)rx_data[0] << 16) | ((int32_t)rx_data[1] << 8) |
269 ((int32_t)rx_data[2]);
271 if (*meas & 0x800000) {
void power_on(void)
GPIO port for adc data ready line.
void power_off(void)
Turn off power to analog circuit.
int measure(uint32_t *meas)
Measure from the adc.
int configure(const ConfigReg reg_data)
This function reconfigures the ADS1219 based on the parameter reg_data.
This file contains all the function prototypes for the ads.c file.
int ads1219_current(double *current)
This function reads the current ADC ampere value.
uint8_t ads1219_sensor_voltage(uint8_t *data, Metadata meta, uint32_t idx)
Sensor measure functions.
int ads1219_reset(void)
This function starts up the ADS1219.
int ads1219_voltage_raw(uint32_t *voltage)
uint8_t ads1219_sensor_current(uint8_t *data, Metadata meta, uint32_t idx)
int ads1219_voltage(double *voltage)
This function reads the current ADC voltage value.
int ads1219_current_raw(uint32_t *current)
SensorStatus EncodeDoubleMeasurement(Metadata meta, double value, SensorType type, uint8_t *buffer, size_t *size)
Encodes a double sensor measurement into a buffer.
enum _SensorStatus SensorStatus
struct ConfigReg::@0 bits