Skyward boardcore
Loading...
Searching...
No Matches
LIS331HH.h
Go to the documentation of this file.
1/* Copyright (c) 2022 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 <sensors/Sensor.h>
27
28#include "LIS331HHData.h"
29
30namespace Boardcore
31{
32
33class LIS331HH : public Sensor<LIS331HHData>
34{
35public:
36 enum OutputDataRate : uint8_t
37 {
38 ODR_50 = 0x00,
39 ODR_100 = 0x08,
40 ODR_400 = 0x10,
41 ODR_1000 = 0x18,
42 };
43
44 enum FullScaleRange : uint8_t
45 {
46 FS_6 = 0x00,
47 FS_12 = 0x10,
48 FS_24 = 0x30,
49 };
50
51 LIS331HH(SPIBusInterface& bus, miosix::GpioPin cs, SPIBusConfig spiConfig);
52
53 bool init() override;
54
55 bool selfTest() override;
56
58
60
61protected:
62 LIS331HHData sampleImpl() override;
63
64private:
65 SPISlave slave;
66 float sensitivity = 6.0 / 32767.0;
67
68 enum Register : uint8_t
69 {
70 CTRL_REG1 = 0x20,
71 CTRL_REG2 = 0x21,
72 CTRL_REG3 = 0x22,
73 CTRL_REG4 = 0x23,
74 CTRL_REG5 = 0x24,
75 HP_FILTER_RESET = 0x25,
76 REFERENCE = 0x26,
77 STATUS_REG = 0x27,
78 OUT_X_L = 0x28,
79 OUT_X_H = 0x29,
80 OUT_Y_L = 0x2a,
81 OUT_Y_H = 0x2b,
82 OUT_Z_L = 0x2c,
83 OUT_Z_H = 0x2d,
84 INT1_CFG = 0x30,
85 INT1_SOURCE = 0x31,
86 INT1_THS = 0x32,
87 INT1_DURATION = 0x33,
88 INT2_CFG = 0x34,
89 INT2_SOURCE = 0x35,
90 INT2_THS = 0x36,
91 INT2_DURATION = 0x37,
92 };
93
94 enum PowerMode : uint8_t
95 {
96 POWER_DOWN = 0x00,
97 NORMAL_MODE = 0x20,
98 LOW_POWER_0_5 = 0x40,
99 LOW_POWER_1 = 0x60,
100 LOW_POWER_2 = 0x80,
101 LOW_POWER_5 = 0xA0,
102 LOW_POWER_10 = 0xC0,
103 };
104
105 enum RegisterMask : uint8_t
106 {
107 CTRL_REG1_PM = 0xE0,
108 CTRL_REG1_DR = 0x18,
109 CTRL_REG1_Z_EN = 0x04,
110 CTRL_REG1_Y_EN = 0x02,
111 CTRL_REG1_X_EN = 0x01,
112
113 CTRL_REG4_FS = 0x30,
114 CTRL_REG4_ST_SIGN = 0x08,
115 CTRL_REG4_ST = 0x02,
116 };
117};
118
119} // namespace Boardcore
LIS331HHData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
Definition LIS331HH.cpp:73
bool init() override
Initialize the sensor.
Definition LIS331HH.cpp:36
LIS331HH(SPIBusInterface &bus, miosix::GpioPin cs, SPIBusConfig spiConfig)
Definition LIS331HH.cpp:30
void setFullScaleRange(FullScaleRange fs)
Definition LIS331HH.cpp:57
void setOutputDataRate(OutputDataRate odr)
Definition LIS331HH.cpp:48
bool selfTest() override
Check if the sensor is working.
Definition LIS331HH.cpp:46
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.