Skyward boardcore
Loading...
Searching...
No Matches
MS5803.h
Go to the documentation of this file.
1/* Copyright (c) 2015-2021 Skyward Experimental Rocketry
2 * Authors: Davide Benini, Matteo Piazzolla, Alain Carlucci, Alberto Nidasio
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 "MS5803Data.h"
30
31namespace Boardcore
32{
33
34class MS5803 : public Sensor<MS5803Data>
35{
36public:
43
44 enum MS5803Registers : uint8_t
45 {
46 REG_RESET = 0x1E,
47
48 // Conversion commands for pressure and output data resolution
49 REG_CONVERT_D1_256 = 0x40, // Conversion time: 0.48-0.54-0.60ms
50 REG_CONVERT_D1_512 = 0x42, // Conversion time: 0.95-1.06-1.17ms
51 REG_CONVERT_D1_1024 = 0x44, // Conversion time: 1.88-2.08-2.28ms
52 REG_CONVERT_D1_2048 = 0x46, // Conversion time: 3.72-4.13-4-54ms
53 REG_CONVERT_D1_4096 = 0x48, // Conversion time: 7.40-8.22-9.04ms
54
55 // Conversion commands for temperature and output data resolution
56 REG_CONVERT_D2_256 = 0x50, // Conversion time: 0.48-0.54-0.60ms
57 REG_CONVERT_D2_512 = 0x52, // Conversion time: 0.95-1.06-1.17ms
58 REG_CONVERT_D2_1024 = 0x54, // Conversion time: 1.88-2.08-2.28ms
59 REG_CONVERT_D2_2048 = 0x56, // Conversion time: 3.72-4.13-4-54ms
60 REG_CONVERT_D2_4096 = 0x58, // Conversion time: 7.40-8.22-9.04ms
61
62 // Read command for adc output
64
71 };
72
73 static constexpr uint8_t TIMEOUT = 5;
74
75 MS5803(SPIBusInterface& spiBus, miosix::GpioPin cs,
76 SPIBusConfig spiConfig = {}, uint16_t temperatureDivider = 1);
77
78 bool init() override;
79
80 bool selfTest() override;
81
82protected:
95 MS5803Data sampleImpl() override;
96
97private:
98 MS5803Data updateData();
99
100 SPISlave spiSlave;
101
102 MS5803CalibrationData calibrationData;
103 uint16_t temperatureDivider;
104
105 uint8_t deviceState = STATE_INIT;
106 uint32_t rawTemperature = 0;
107 uint32_t rawPressure = 0;
108 uint64_t lastTemperatureTimestamp = 0;
109 uint16_t tempCounter = 0;
110
111 PrintLogger logger = Logging::getLogger("ms5803");
112};
113
114} // namespace Boardcore
static PrintLogger getLogger(const string &name)
MS5803(SPIBusInterface &spiBus, miosix::GpioPin cs, SPIBusConfig spiConfig={}, uint16_t temperatureDivider=1)
Definition MS5803.cpp:31
bool init() override
Initialize the sensor.
Definition MS5803.cpp:39
static constexpr uint8_t TIMEOUT
Definition MS5803.h:73
@ REG_PROM_TEMPSENS_MASK
Definition MS5803.h:70
MS5803Data sampleImpl() override
Definition MS5803.cpp:63
bool selfTest() override
Check if the sensor is working.
Definition MS5803.cpp:61
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.
MS5803 calibration data. See page 13 of datasheet for more details.
Definition MS5803Data.h:34
SPI Bus configuration for a specific slave.
Contains information about a single SPI slave device.