44 spiConfig.csSetupTimeUs = 50;
58 : slave(bus, cs, spiConfig), range(rangeToPressure(fsr)),
59 streamRx(streamRx), streamTx(streamTx), timeoutDma(timeout),
60 sensorSettings{odr, fsr, iow, bwl, ntc}
67 : slave(bus, cs, spiConfig), range(rangeToPressure(fsr)), streamRx(nullptr),
68 streamTx(nullptr), timeoutDma(
std::chrono::nanoseconds::zero()),
69 sensorSettings{odr, fsr, iow, bwl, ntc}
79 memcpy(&spiDataOut, &sensorSettings,
sizeof(spiDataOut));
86 miosix::Thread::sleep(4);
95 ND015DDataExtended extendedData{};
96 uint8_t* data =
reinterpret_cast<uint8_t*
>(&extendedData);
99 memcpy(&extendedData, &sensorSettings,
sizeof(sensorSettings));
102 spi.
transfer(data,
sizeof(extendedData));
112 std::string(extendedData.model,
sizeof(extendedData.model));
114 std::replace(model.begin(), model.end(),
'\0',
'.');
117 "Sensor model mismatch: received {}, expected {} (. = \\0)",
126 sensorSettings.odr =
odr;
131 memcpy(&spiDataOut, &sensorSettings,
sizeof(spiDataOut));
137 sensorSettings.fsr =
fsr;
144 memcpy(&spiDataOut, &sensorSettings,
sizeof(spiDataOut));
171 sensorSettings.iow =
iow;
176 memcpy(&spiDataOut, &sensorSettings,
sizeof(spiDataOut));
182 sensorSettings.bwl =
bwl;
187 memcpy(&spiDataOut, &sensorSettings,
sizeof(spiDataOut));
193 sensorSettings.ntc =
ntc;
198 memcpy(&spiDataOut, &sensorSettings,
sizeof(spiDataOut));
210 uint16_t spiDataIn = 0;
212 memcpy(&spiDataOut, &sensorSettings,
sizeof(spiDataOut));
214 if (streamRx !=
nullptr && streamTx !=
nullptr)
218 spiDataIn = spi.
transfer16(spiDataOut, timeoutDma);
226 float normalizedPressure =
227 std::bit_cast<int16_t>(spiDataIn) / (0.9f * powf(2, 15));
230 normalizedPressure * range * Constants::PSI_TO_PASCAL + pressureOffset;
#define LOG_ERR(logger,...)
Simple RAII class to handle DMA streams.
void setIOWatchdog(IOWatchdogEnable iow)
Enables or disables the IO watchdog.
void setFullScaleRange(FullScaleRange fsr)
Sets the full-scale range for the sensor.
void setOffset(float offset)
Set the offset of this sensor. The offset is stored as a int16_t and can be both postive or negative.
bool init() override
Initializes the sensor.
ND015D(SPIBusInterface &bus, miosix::GpioPin cs, SPIBusConfig spiConfig, DMAStreamGuard *streamRx, DMAStreamGuard *streamTx, std::chrono::nanoseconds timeoutDma, FullScaleRange fsr=FullScaleRange::FS_2, IOWatchdogEnable iow=IOWatchdogEnable::DISABLED, BWLimitFilter bwl=BWLimitFilter::BWL_200, NotchEnable ntc=NotchEnable::ENABLED, uint8_t odr=0x1C)
Constructor for the ND015D sensor.
void setBWLimitFilter(BWLimitFilter bwl)
Sets the bandwidth limit filter for the sensor.
void setNotch(NotchEnable ntc)
Enables or disables the notch filter.
float getOffset()
Get the current offset of this sensor. The offset is stored as a int16_t and can be both postive or n...
void updateOffset(float offset)
Modify the offset of this sensor. The offset is stored as a int16_t and can be both postive or negati...
static SPIBusConfig getDefaultSPIConfig()
Constructs the default config for the SPI bus.
static float rangeToPressure(FullScaleRange fsr)
Converts the FullScale value to its corresponding range.
static const char MODEL_NAME[]
bool checkModelMatch()
Checks if the sensor model matches the expected model.
void setOutputDataRate(uint8_t odr)
function to set the output data rate
ND015XData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
bool selfTest() override
Not implemented.
Interface for low level access of a SPI bus as a master.
Provides high-level access to the SPI Bus for a single spi transaction with dma.
uint16_t transfer16(uint16_t data, std::chrono::nanoseconds timeout=std::chrono::nanoseconds::zero())
Full duplex transmission of 16 bits on the bus.
Provides high-level access to the SPI Bus for a single transaction.
uint16_t transfer16(uint16_t data)
Full duplex transmission of one half word on the bus.
uint8_t transfer(uint8_t data)
Full duplex transmission of one byte on the bus.
@ MODE_1
CPOL = 1, CPHA = 0 -> Clock high when idle, sample on first edge.
uint64_t getTimestamp()
Returns the current timer value in microseconds.
Driver for the VN100S IMU.
uint64_t pressureTimestamp
SPI Bus configuration for a specific slave.
SPI::Mode mode
MSBit or LSBit first.