Skyward boardcore
Loading...
Searching...
No Matches
VN100Spi.h
Go to the documentation of this file.
1/* Copyright (c) 2024 Skyward Experimental Rocketry
2 * Author: Fabrizio Monti
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
43#include <sensors/Sensor.h>
44
45#include "VN100SpiData.h"
46#include "VN100SpiDefs.h"
47
48namespace Boardcore
49{
50
54class VN100Spi : public Sensor<VN100SpiData>
55{
56public:
67 VN100Spi(SPIBus& bus, miosix::GpioPin csPin, SPIBusConfig busConfiguration,
68 uint16_t syncOutSkipFactor);
69
73 bool init() override;
74
80 bool selfTest() override;
81
86
91
92protected:
96 VN100SpiData sampleImpl() override;
97
98private:
104 bool checkModelNumber();
105
111 void sendDummyPacket();
112
118 bool setInterrupt();
119
128 bool getSample(VN100SpiData& data);
129
140 VN100SpiDefs::VNErrors readRegister(const uint8_t regId,
141 uint8_t* payloadBuf,
142 const uint32_t payloadSize);
143
153 VN100SpiDefs::VNErrors writeRegister(const uint8_t regId,
154 const uint8_t* payloadBuf,
155 const uint32_t payloadSize);
156
157 bool isInit = false;
158
159 SPISlave spiSlave;
160
166 const uint16_t syncOutSkipFactor = 0;
167
168 PrintLogger logger = Logging::getLogger("vn100-spi");
169};
170
171} // namespace Boardcore
static PrintLogger getLogger(const string &name)
Driver for STM32 low level SPI peripheral.
Definition SPIBus.h:61
Base sensor class with has to be extended by any sensor driver.
Definition Sensor.h:91
Driver class for VN100 Spi IMU.
Definition VN100Spi.h:55
bool selfTest() override
Performs self test for the sensor.
Definition VN100Spi.cpp:164
VN100Spi(SPIBus &bus, miosix::GpioPin csPin, SPIBusConfig busConfiguration, uint16_t syncOutSkipFactor)
VN100 constructor.
Definition VN100Spi.cpp:32
PressureData getPressure()
Retrieve pressure data from the sensor [kPa].
Definition VN100Spi.cpp:248
VN100SpiData sampleImpl() override
Gather data from the sensor.
Definition VN100Spi.cpp:166
bool init() override
Initialize the sensor.
Definition VN100Spi.cpp:39
TemperatureData getTemperature()
Retrieve temperature data from the sensor [°C].
Definition VN100Spi.cpp:222
VNErrors
Error codes of the sensor.
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.
Data type class for VN100 Spi.