32 : spi(spiBus, cs, cfg), odr(odr), bdu(bdu), fs(fs), initialized(false)
71 "Failed init. Cause: INVALID_WHOAMI. Expected Value: "
72 "{:X}. Actual Value: {:X}\n",
83 uint8_t ctrlReg1 = 0b0000'0000;
93 uint8_t ctrlReg1OnChip =
96 initialized = (ctrlReg1 == ctrlReg1OnChip);
101 "Control Register 1 After init: {:X}, expected "
103 ctrlReg1OnChip, ctrlReg1);
112 uint8_t ctrlReg4 = 0b0000'0000;
120 uint8_t ctrlReg4OnChip =
123 initialized = (ctrlReg4 == ctrlReg4OnChip);
128 "Control Register 1 After init: {:X}, expected "
130 ctrlReg4OnChip, ctrlReg4);
166 uint8_t status = buff[0];
167 uint16_t regX = buff[2] << 8 | buff[1];
168 uint16_t regY = buff[4] << 8 | buff[3];
169 uint16_t regZ = buff[6] << 8 | buff[5];
174 LOG_ERR(logger,
"No new data available.");
181 int16_t xInt =
static_cast<int16_t
>(regX);
182 float xFloat =
static_cast<float>(xInt >> 4);
183 x = xFloat * sensitivity;
185 int16_t yInt =
static_cast<int16_t
>(regY);
186 float yFloat =
static_cast<float>(yInt >> 4);
187 y = yFloat * sensitivity;
189 int16_t zInt =
static_cast<int16_t
>(regZ);
190 float zFloat =
static_cast<float>(zInt >> 4);
191 z = zFloat * sensitivity;
#define LOG_ERR(logger,...)
static SPIBusConfig getDefaultSPIConfig()
H3LIS331DL(SPIBusInterface &spiBus, miosix::GpioPin cs, H3LIS331DLDefs::OutputDataRate odr, H3LIS331DLDefs::BlockDataUpdate bdu, H3LIS331DLDefs::FullScaleRange fs)
Creates an instance of an H3LIS331DL sensor.
H3LIS331DLData sampleImpl() override
Samples data from the register.
bool init()
Initializes the H3LIS331DL.
bool selfTest()
This method does nothing as no self test is implemented in the sensor.
Interface for low level access of a SPI bus as a master.
Provides high-level access to the SPI Bus for a single transaction.
constexpr float SENSITIVITY_VALUES[]
Constants for the sensitivity values based on the Full Scale Range.
FullScaleRange
Constants for the FullScale Range.
BlockDataUpdate
Constants for Block Data Update.
constexpr uint8_t CTRL_REG1_ZEN
constexpr uint8_t CTRL_REG1_XEN
constexpr uint8_t AUTOINC_ADDR
make the driver automatically increase the register address when reading multiple bytes with SPI.
const uint8_t WHO_AM_I_ID
constexpr uint8_t CTRL_REG1_YEN
@ STATUS_REG_XYZDR
Data Ready on All Axis.
OutputDataRate
Constants for Output Data Rate configuration.
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.
SPI Bus configuration for a specific slave.
SPI::ClockDivider clockDivider
< Peripheral clock division