Skyward boardcore
Loading...
Searching...
No Matches
ND015D.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
27#include <sensors/Sensor.h>
28
29#include "ND015XData.h"
30
31namespace Boardcore
32{
33
34class ND015D : public Sensor<ND015XData>
35{
36public:
37 static const char MODEL_NAME[];
38
43 enum class FullScaleRange : uint8_t
44 {
45 FS_1 = 0x02, // 1.0 psi
46 FS_2 = 0x03, // 2.0 psi
47 FS_4 = 0x04, // 4.0 psi
48 FS_5 = 0x05, // 5.0 psi
49 FS_10 = 0x06, // 10.0 psi
50 FS_15 = 0x07, // 15.0 psi
51 };
52
60
61 enum class IOWatchdogEnable : uint8_t
62 {
63 DISABLED = 0x00,
64 ENABLED = 0x01,
65 };
66
67 enum class BWLimitFilter : uint8_t
68 {
69 BWL_1 = 0x00, // 1.0 Hz
70 BWL_2 = 0x01, // 2.0 Hz
71 BWL_5 = 0x02, // 5.0 Hz
72 BWL_10 = 0x03, // 10 Hz
73 BWL_20 = 0x04, // 20 Hz
74 BWL_50 = 0x05, // 50 Hz
75 BWL_100 = 0x06, // 100 Hz
76 BWL_200 = 0x07, // 200 Hz
77 };
78
79 enum class NotchEnable : uint8_t
80 {
81 DISABLED = 0x00,
82 ENABLED = 0x01,
83 };
84
91
100 ND015D(SPIBusInterface& bus, miosix::GpioPin cs, SPIBusConfig spiConfig,
104 NotchEnable ntc = NotchEnable::ENABLED, uint8_t odr = 0x1C);
105
111 bool init() override;
112
118 bool selfTest() override;
119
129 void setOutputDataRate(uint8_t odr);
130
137
144
151
158
169 bool checkModelMatch();
170
171protected:
172 ND015XData sampleImpl() override;
173
174private:
175 SPISlave slave;
176 float range;
177
183 struct
184 {
185 FullScaleRange fsr : 3; // full scale range
186 IOWatchdogEnable iow : 1; // IO watchdog enable
187 BWLimitFilter bwl : 3; // bandwidth limit filter
188 NotchEnable ntc : 1; // notch filter enable
189 uint8_t odr : 8; // output data rate
190 } sensorSettings;
191
192 static_assert(sizeof(sensorSettings) == 2,
193 "sensorSettings size is not 2 bytes");
194
195 struct ND015DDataExtended
196 {
197 uint16_t pressure;
198 uint16_t temperature;
199 char model[8];
200 uint8_t serial[4];
201 uint8_t build[6];
202 };
203
204 PrintLogger logger = Logging::getLogger("nd015d");
205};
206
207} // namespace Boardcore
208
static PrintLogger getLogger(const string &name)
void setIOWatchdog(IOWatchdogEnable iow)
Enables or disables the IO watchdog.
Definition ND015D.cpp:149
void setFullScaleRange(FullScaleRange fsr)
Sets the full-scale range for the sensor.
Definition ND015D.cpp:115
BWLimitFilter bwl
Definition ND015D.h:187
bool init() override
Initializes the sensor.
Definition ND015D.cpp:59
FullScaleRange fsr
Definition ND015D.h:185
void setBWLimitFilter(BWLimitFilter bwl)
Sets the bandwidth limit filter for the sensor.
Definition ND015D.cpp:160
void setNotch(NotchEnable ntc)
Enables or disables the notch filter.
Definition ND015D.cpp:171
static SPIBusConfig getDefaultSPIConfig()
Constructs the default config for the SPI bus.
Definition ND015D.cpp:35
static float rangeToPressure(FullScaleRange fsr)
Converts the FullScale value to its corresponding range.
Definition ND015D.cpp:128
IOWatchdogEnable iow
Definition ND015D.h:186
NotchEnable ntc
Definition ND015D.h:188
static const char MODEL_NAME[]
Definition ND015D.h:37
bool checkModelMatch()
Checks if the sensor model matches the expected model.
Definition ND015D.cpp:73
void setOutputDataRate(uint8_t odr)
function to set the output data rate
Definition ND015D.cpp:104
ND015XData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
Definition ND015D.cpp:182
ND015D(SPIBusInterface &bus, miosix::GpioPin cs, SPIBusConfig spiConfig, 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.
Definition ND015D.cpp:51
bool selfTest() override
Not implemented.
Definition ND015D.cpp:71
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
This file includes all the types the logdecoder script will decode.
SPI Bus configuration for a specific slave.
Contains information about a single SPI slave device.