Skyward boardcore
Loading...
Searching...
No Matches
MS5803I2C.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
26#include <drivers/i2c/I2C.h>
27#include <sensors/Sensor.h>
28
29#include "MS5803Data.h"
30
31namespace Boardcore
32{
33
34class MS5803I2C : 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 explicit MS5803I2C(I2C& bus, uint16_t temperatureDivider = 1);
76
77 bool init() override;
78
79 bool selfTest() override;
80
81protected:
94 MS5803Data sampleImpl() override;
95
96private:
97 MS5803Data updateData();
98
99 uint16_t readReg(uint8_t reg);
100
101 I2C& bus;
104
105 MS5803CalibrationData calibrationData;
106 uint16_t temperatureDivider;
107
108 uint8_t deviceState = STATE_INIT;
109 uint32_t rawTemperature = 0;
110 uint32_t rawPressure = 0;
111 uint64_t lastTemperatureTimestamp = 0;
112 uint16_t tempCounter = 0;
113
114 PrintLogger logger = Logging::getLogger("ms5803");
115};
116
117} // namespace Boardcore
High level driver for the I2C peripherals.
Definition I2C.h:40
static PrintLogger getLogger(const string &name)
static constexpr uint8_t TIMEOUT
Definition MS5803I2C.h:73
bool init() override
Initialize the sensor.
Definition MS5803I2C.cpp:36
bool selfTest() override
Check if the sensor is working.
Definition MS5803I2C.cpp:55
MS5803I2C(I2C &bus, uint16_t temperatureDivider=1)
Definition MS5803I2C.cpp:31
MS5803Data sampleImpl() override
Definition MS5803I2C.cpp:57
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.
Configuration struct for a slave device. This will be used for configuring the bus in order to commun...
Definition I2CDriver.h:104
MS5803 calibration data. See page 13 of datasheet for more details.
Definition MS5803Data.h:34