Skyward boardcore
Loading...
Searching...
No Matches
ND030D.h
Go to the documentation of this file.
1/* Copyright (c) 2025 Skyward Experimental Rocketry
2 * Author: Pietro Bortolus
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
26#include <drivers/dma/DMA.h>
28#include <sensors/Sensor.h>
29
30#include "ND030XData.h"
31
32namespace Boardcore
33{
34
35class ND030D : public Sensor<ND030XData>
36{
37public:
38 static const char MODEL_NAME[];
39
44 enum class FullScaleRange : uint8_t
45 {
46 FS_5 = 0x02, // 5.0 psi
47 FS_10 = 0x03, // 10.0 psi
48 FS_15 = 0x04, // 15.0 psi
49 FS_20 = 0x05, // 20.0 psi
50 FS_25 = 0x06, // 25.0 psi
51 FS_30 = 0x07, // 30.0 psi
52 };
53
61
62 enum class IOWatchdogEnable : uint8_t
63 {
64 DISABLED = 0x00,
65 ENABLED = 0x01,
66 };
67
68 enum class BWLimitFilter : uint8_t
69 {
70 BWL_1 = 0x00, // 1.0 Hz
71 BWL_2 = 0x01, // 2.0 Hz
72 BWL_5 = 0x02, // 5.0 Hz
73 BWL_10 = 0x03, // 10 Hz
74 BWL_20 = 0x04, // 20 Hz
75 BWL_50 = 0x05, // 50 Hz
76 BWL_100 = 0x06, // 100 Hz
77 BWL_200 = 0x07, // 200 Hz
78 };
79
80 enum class NotchEnable : uint8_t
81 {
82 DISABLED = 0x00,
83 ENABLED = 0x01,
84 };
85
92
103 ND030D(SPIBusInterface& bus, miosix::GpioPin cs, SPIBusConfig spiConfig,
104 DMAStreamGuard* streamRx, DMAStreamGuard* streamTx,
105 std::chrono::nanoseconds timeoutDma,
109 NotchEnable ntc = NotchEnable::ENABLED, uint8_t odr = 0x1C);
110
118 ND030D(SPIBusInterface& bus, miosix::GpioPin cs, SPIBusConfig spiConfig,
122 NotchEnable ntc = NotchEnable::ENABLED, uint8_t odr = 0x1C);
123
129 bool init() override;
130
136 bool selfTest() override;
137
147 void setOutputDataRate(uint8_t odr);
148
155
162
169
176
187 bool checkModelMatch();
188
196 void setOffset(float offset);
197
205 void updateOffset(float offset);
206
212 float getOffset();
213
214protected:
215 ND030XData sampleImpl() override;
216
217private:
218 SPISlave slave;
219 float range;
220 DMAStreamGuard* const streamRx;
221 DMAStreamGuard* const streamTx;
222 const std::chrono::nanoseconds timeoutDma;
223 float pressureOffset = 0;
224
233 struct
234 {
235 uint8_t odr : 8; // output data rate
236 FullScaleRange fsr : 3; // full scale range
237 IOWatchdogEnable iow : 1; // IO watchdog enable
238 BWLimitFilter bwl : 3; // bandwidth limit filter
239 NotchEnable ntc : 1; // notch filter enable
240 } sensorSettings;
241
242 static_assert(sizeof(sensorSettings) == 2,
243 "sensorSettings size is not 2 bytes");
244
245 struct ND030DDataExtended
246 {
247 uint16_t pressure;
248 uint16_t temperature;
249 char model[8];
250 uint8_t serial[4];
251 uint8_t build[6];
252 };
253
254 PrintLogger logger = Logging::getLogger("nd030d");
255};
256
257} // namespace Boardcore
Simple RAII class to handle DMA streams.
Definition DMA.h:557
static PrintLogger getLogger(const string &name)
bool selfTest() override
Not implemented.
Definition ND030D.cpp:91
ND030XData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
Definition ND030D.cpp:206
void setIOWatchdog(IOWatchdogEnable iow)
Enables or disables the IO watchdog.
Definition ND030D.cpp:169
BWLimitFilter bwl
Definition ND030D.h:238
static SPIBusConfig getDefaultSPIConfig()
Constructs the default config for the SPI bus.
Definition ND030D.cpp:37
static float rangeToPressure(FullScaleRange fsr)
Converts the FullScale value to its corresponding range.
Definition ND030D.cpp:148
void setFullScaleRange(FullScaleRange fsr)
Sets the full-scale range for the sensor.
Definition ND030D.cpp:135
void setOutputDataRate(uint8_t odr)
function to set the output data rate
Definition ND030D.cpp:124
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.
Definition ND030D.cpp:202
void setNotch(NotchEnable ntc)
Enables or disables the notch filter.
Definition ND030D.cpp:191
void setBWLimitFilter(BWLimitFilter bwl)
Sets the bandwidth limit filter for the sensor.
Definition ND030D.cpp:180
IOWatchdogEnable iow
Definition ND030D.h:237
NotchEnable ntc
Definition ND030D.h:239
FullScaleRange fsr
Definition ND030D.h:236
float getOffset()
Get the current offset of this sensor. The offset is stored as a int16_t and can be both postive or n...
Definition ND030D.cpp:204
static const char MODEL_NAME[]
Definition ND030D.h:38
bool checkModelMatch()
Checks if the sensor model matches the expected model.
Definition ND030D.cpp:93
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...
Definition ND030D.cpp:203
bool init() override
Initializes the sensor.
Definition ND030D.cpp:73
Interface for low level access of a SPI bus as a master.
Base sensor class with has to be extended by any sensor driver.
Definition Sensor.h:91
Driver for the VN100S IMU.
SPI Bus configuration for a specific slave.
Contains information about a single SPI slave device.