Skyward boardcore
Loading...
Searching...
No Matches
ND015A.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 "ND015XData.h"
31
32namespace Boardcore
33{
34
35class ND015A : public Sensor<ND015XData>
36{
37public:
38 static const char MODEL_NAME[];
39 static const int FULLSCALE = 15;
40
41 enum class IOWatchdogEnable : uint8_t
42 {
43 DISABLED = 0x00,
44 ENABLED = 0x01,
45 };
46
47 enum class BWLimitFilter : uint8_t
48 {
49 BWL_1 = 0x00, // 1.0 Hz
50 BWL_2 = 0x01, // 2.0 Hz
51 BWL_5 = 0x02, // 5.0 Hz
52 BWL_10 = 0x03, // 10 Hz
53 BWL_20 = 0x04, // 20 Hz
54 BWL_50 = 0x05, // 50 Hz
55 BWL_100 = 0x06, // 100 Hz
56 BWL_200 = 0x07, // 200 Hz
57 };
58
59 enum class NotchEnable : uint8_t
60 {
61 DISABLED = 0x00,
62 ENABLED = 0x01,
63 };
64
71
82 ND015A(SPIBusInterface& bus, miosix::GpioPin cs, SPIBusConfig spiConfig,
83 DMAStreamGuard* streamRx, DMAStreamGuard* streamTx,
84 std::chrono::nanoseconds timeoutDma,
87 NotchEnable ntc = NotchEnable::ENABLED, uint8_t odr = 0x1C);
88
96 ND015A(SPIBusInterface& bus, miosix::GpioPin cs, SPIBusConfig spiConfig,
99 NotchEnable ntc = NotchEnable::ENABLED, uint8_t odr = 0x1C);
100
106 bool init() override;
107
113 bool selfTest() override;
114
124 void setOutputDataRate(uint8_t odr);
125
132
139
146
157 bool checkModelMatch();
158
166 void setOffset(float offset);
167
175 void updateOffset(float offset);
176
182 float getOffset();
183
184protected:
185 ND015XData sampleImpl() override;
186
187private:
188 SPISlave slave;
189 DMAStreamGuard* const streamRx;
190 DMAStreamGuard* const streamTx;
191 const std::chrono::nanoseconds timeoutDma;
192 float pressureOffset = 0;
193
202 struct
203 {
204 uint8_t odr : 8; // output data rate
205 uint8_t fsr : 3; // full scale range, value cannot be changed
206 IOWatchdogEnable iow : 1; // IO watchdog enable
207 BWLimitFilter bwl : 3; // bandwidth limit filter
208 NotchEnable ntc : 1; // notch filter enable
209 } sensorSettings;
210
211 static_assert(sizeof(sensorSettings) == 2,
212 "sensorSettings size is not 2 bytes");
213
214 struct ND015ADataExtended
215 {
216 uint16_t pressure;
217 uint16_t temperature;
218 char model[8];
219 uint8_t serial[4];
220 uint8_t build[6];
221 };
222
223 PrintLogger logger = Logging::getLogger("nd015a");
224};
225
226} // namespace Boardcore
Simple RAII class to handle DMA streams.
Definition DMA.h:557
static PrintLogger getLogger(const string &name)
bool init() override
Initializes the sensor.
Definition ND015A.cpp:70
void setBWLimitFilter(BWLimitFilter bwl)
Sets the bandwidth limit filter for the sensor.
Definition ND015A.cpp:143
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 ND015A.cpp:166
bool checkModelMatch()
Checks if the sensor model matches the expected model.
Definition ND015A.cpp:90
void setNotch(NotchEnable ntc)
Enables or disables the notch filter.
Definition ND015A.cpp:154
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 ND015A.cpp:165
NotchEnable ntc
Definition ND015A.h:208
bool selfTest() override
Not implemented.
Definition ND015A.cpp:88
static const char MODEL_NAME[]
Definition ND015A.h:38
static const int FULLSCALE
Definition ND015A.h:39
static SPIBusConfig getDefaultSPIConfig()
Constructs the default config for the SPI bus.
Definition ND015A.cpp:36
IOWatchdogEnable iow
Definition ND015A.h:206
ND015XData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
Definition ND015A.cpp:169
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 ND015A.cpp:167
void setIOWatchdog(IOWatchdogEnable iow)
function to enable the IO watchdog
Definition ND015A.cpp:132
BWLimitFilter bwl
Definition ND015A.h:207
void setOutputDataRate(uint8_t odr)
function to set the output data rate
Definition ND015A.cpp:121
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.