Skyward boardcore
Loading...
Searching...
No Matches
LPS331AP.h
Go to the documentation of this file.
1/* Copyright (c) 2023 Skyward Experimental Rocketry
2 * Author: 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 "LPS331APData.h"
30
31namespace Boardcore
32{
33
34class LPS331AP : public Sensor<LPS331APData>
35{
36public:
37 enum class ODR : uint8_t
38 {
39 ODR_1HZ = 0x01,
40 ODR_7Hz = 0x05,
41 ODR_12_5Hz = 0x06,
42 ODR_25Hz = 0x07,
43 };
44
45 explicit LPS331AP(I2C& bus, ODR odr = ODR::ODR_25Hz);
46
47 bool init() override;
48
49 bool selfTest() override;
50
51protected:
52 LPS331APData sampleImpl() override;
53
54private:
55 bool checkWhoAmI();
56
57 static constexpr uint8_t WHO_AM_I_VAL = 0x58;
58
59 enum Registers : uint8_t
60 {
61 REG_WHO_AM_I = 0x8f,
62 REG_RES_CONF = 0x10,
63 REG_CTRL_REG1 = 0x20,
64 REG_PRESS_XLSB = 0x28,
65 };
66
67 I2C& bus;
68 I2CDriver::I2CSlaveConfig slaveConfig{0x5c, I2CDriver::Addressing::BIT7,
70
71 ODR odr;
72
73 PrintLogger logger = Logging::getLogger("lps331ap");
74};
75
76} // namespace Boardcore
High level driver for the I2C peripherals.
Definition I2C.h:40
LPS331APData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
Definition LPS331AP.cpp:62
bool init() override
Initialize the sensor.
Definition LPS331AP.cpp:33
bool selfTest() override
Check if the sensor is working.
Definition LPS331AP.cpp:60
static PrintLogger getLogger(const string &name)
Base sensor class with has to be extended by any sensor driver.
Definition Sensor.h:91
Driver for the VN100S IMU.