26#include <interfaces/endianness.h>
32 SINGLE_SHOT_MODE, FSR_2_048, MUX_AIN0_AIN1, 0, 0,
33 VALID_OPERATION, PULL_UP_EN, ADC_MODE, DR_128};
43 : spiSlave(spiSlave_), baseConfig(config_), busyWait(busyWait_),
44 tempDivider(tempDivider_)
50 channelsConfig[i].
word = 0;
78 channelsConfig[mux].
bits.mode = baseConfig.
bits.mode;
79 channelsConfig[mux].
bits.pga = pga;
80 channelsConfig[mux].
bits.mux = mux;
81 channelsConfig[mux].
bits.singleShot = 1;
83 channelsConfig[mux].
bits.pullUp = baseConfig.
bits.pullUp;
85 channelsConfig[mux].
bits.rate = rate;
96 channelsConfig[i].word = 0;
137 return CONV_TIME[channelsConfig[channel].
bits.rate];
145 bool prevConfigCheck = configCheck;
159 configCheck = prevConfigCheck;
175 int8_t i = findNextEnabledChannel(lastConfigIndex + 1);
181 lastConfig.
word = channelsConfig[i].
word;
188 return values[lastConfigIndex];
191void ADS1118::readChannel(int8_t nextChannel, int8_t prevChannel)
193 uint32_t writeData, transferData;
200 writeData = channelsConfig[nextChannel].
word;
210 transferData = writeData;
212 SPITransaction transaction(spiSlave);
213 transaction.transfer((uint8_t*)&transferData, configCheck ? 4 : 2);
218 if (configCheck && writeData)
221 if ((channelsConfig[nextChannel].word & CONFIG_MASK) !=
222 (transferData >> 16 & CONFIG_MASK))
235 int16_t rawValue = swapBytes16(transferData);
241 if (prevChannel != 8)
244 rawValue * PGA_LSB_SIZE[channelsConfig[prevChannel].
bits.pga] /
258void ADS1118::readChannel(int8_t channel)
281int8_t ADS1118::findNextEnabledChannel(int8_t startChannel)
283 int8_t& channel = startChannel;
285 for (
auto i = 0; i < 2; i++)
299 if (channel ==
TEMP_CHANNEL && sampleCounter % tempDivider != 0)
TemperatureData getTemperature()
Returns the last temperature value.
TemperatureData readTemperatureAndWait()
Reads on the fly the temperature.
int getConversionTime(int8_t channel)
Returns the conversion time in us for the specified channel.
ADS1118Data getVoltage(ADS1118Mux mux)
Returns the last read voltage value for the specified channel.
static constexpr int8_t NUM_OF_CHANNELS
void enableConfigCheck()
Enables the configuration check after it's writing to the device.
ADS1118(SPIBusInterface &bus, miosix::GpioPin cs, ADS1118Config config_, SPIBusConfig spiConfig=getDefaultSPIConfig())
Construct a new ADS1118 object specifying spi bus, spi config and cs pin as well as device configurat...
void disableConfigCheck()
Disables the configuration check after it's writing to the device.
void enablePullUpResistor()
@ PULL_UP_DIS
Pullup resistor disabled on DOUT pin.
@ PULL_UP_EN
Pullup resistor enabled on DOUT pin (default)
ADS1118Data sampleImpl() override
Reads the previously configured channel while writing the next enabled configuration.
void disablePullUpResistor()
static constexpr uint8_t VALID_OPERATION
Indicates a valid configuration.
bool selfTest() override
Writes the temperature configuration and check if it is read back correctly.
void enableInput(ADS1118Mux mux)
Enables the sapling of a specific mux configuration with the main configuration specified in the cons...
void disableInput(ADS1118Mux mux)
static const ADS1118Config ADS1118_DEFAULT_CONFIG
Default configuration.
bool init() override
Initialize the configuration.
ADS1118Data readInputAndWait(ADS1118Mux mux)
Reads on the fly the specified input.
@ ADC_MODE
ADC mode (default)
void disableTemperature()
static SPIBusConfig getDefaultSPIConfig()
static constexpr int8_t TEMP_CHANNEL
Temperature channel number.
static constexpr int8_t INVALID_CHANNEL
Interface for low level access of a SPI bus as a master.
@ MODE_1
CPOL = 1, CPHA = 0 -> Clock high when idle, sample on first edge.
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.
uint64_t voltageTimestamp
SPI Bus configuration for a specific slave.
SPI::ClockDivider clockDivider
< Peripheral clock division
Contains information about a single SPI slave device.
Structure of configuration word.
struct Boardcore::ADS1118::ADS1118Config::@0 bits
Includes all the configuration bits.
uint16_t word
Representation in word (16-bits) format.