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
27#include <sensors/Sensor.h>
28
29#include "ND015XData.h"
30
31namespace Boardcore
32{
33
34class ND015A : public Sensor<ND015XData>
35{
36public:
37 static const char MODEL_NAME[];
38
39 enum class IOWatchdogEnable : uint8_t
40 {
41 DISABLED = 0x00,
42 ENABLED = 0x01,
43 };
44
45 enum class BWLimitFilter : uint8_t
46 {
47 BWL_1 = 0x00, // 1.0 Hz
48 BWL_2 = 0x01, // 2.0 Hz
49 BWL_5 = 0x02, // 5.0 Hz
50 BWL_10 = 0x03, // 10 Hz
51 BWL_20 = 0x04, // 20 Hz
52 BWL_50 = 0x05, // 50 Hz
53 BWL_100 = 0x06, // 100 Hz
54 BWL_200 = 0x07, // 200 Hz
55 };
56
57 enum class NotchEnable : uint8_t
58 {
59 DISABLED = 0x00,
60 ENABLED = 0x01,
61 };
62
69
77 ND015A(SPIBusInterface& bus, miosix::GpioPin cs, SPIBusConfig spiConfig,
80 NotchEnable ntc = NotchEnable::ENABLED, uint8_t odr = 0x1C);
81
87 bool init() override;
88
94 bool selfTest() override;
95
105 void setOutputDataRate(uint8_t odr);
106
113
120
127
138 bool checkModelMatch();
139
140protected:
141 ND015XData sampleImpl() override;
142
143private:
144 SPISlave slave;
145
151 struct
152 {
153 uint8_t fsr : 3; // full scale range, value cannot be changed
154 IOWatchdogEnable iow : 1; // IO watchdog enable
155 BWLimitFilter bwl : 3; // bandwidth limit filter
156 NotchEnable ntc : 1; // notch filter enable
157 uint8_t odr : 8; // output data rate
158 } sensorSettings;
159
160 static_assert(sizeof(sensorSettings) == 2,
161 "sensorSettings size is not 2 bytes");
162
163 struct ND015ADataExtended
164 {
165 uint16_t pressure;
166 uint16_t temperature;
167 char model[8];
168 uint8_t serial[4];
169 uint8_t build[6];
170 };
171
172 PrintLogger logger = Logging::getLogger("nd015a");
173};
174
175} // namespace Boardcore
176
static PrintLogger getLogger(const string &name)
bool init() override
Initializes the sensor.
Definition ND015A.cpp:58
void setBWLimitFilter(BWLimitFilter bwl)
Sets the bandwidth limit filter for the sensor.
Definition ND015A.cpp:125
bool checkModelMatch()
Checks if the sensor model matches the expected model.
Definition ND015A.cpp:72
void setNotch(NotchEnable ntc)
Enables or disables the notch filter.
Definition ND015A.cpp:136
NotchEnable ntc
Definition ND015A.h:156
bool selfTest() override
Not implemented.
Definition ND015A.cpp:70
static const char MODEL_NAME[]
Definition ND015A.h:37
static SPIBusConfig getDefaultSPIConfig()
Constructs the default config for the SPI bus.
Definition ND015A.cpp:35
IOWatchdogEnable iow
Definition ND015A.h:154
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:147
void setIOWatchdog(IOWatchdogEnable iow)
function to enable the IO watchdog
Definition ND015A.cpp:114
BWLimitFilter bwl
Definition ND015A.h:155
void setOutputDataRate(uint8_t odr)
function to set the output data rate
Definition ND015A.cpp:103
ND015A(SPIBusInterface &bus, miosix::GpioPin cs, SPIBusConfig spiConfig, IOWatchdogEnable iow=IOWatchdogEnable::DISABLED, BWLimitFilter bwl=BWLimitFilter::BWL_200, NotchEnable ntc=NotchEnable::ENABLED, uint8_t odr=0x1C)
Constructor for the ND015A sensor.
Definition ND015A.cpp:51
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.