Skip to content
Snippets Groups Projects
Commit 1a47bc10 authored by Alberto Nidasio's avatar Alberto Nidasio
Browse files

[LIS331HH] Added basic sensor driver

parent b59fb331
Branches
Tags
No related merge requests found
......@@ -46,13 +46,13 @@ add_executable(mxgui-helloworld src/entrypoints/examples/mxgui-helloworld.cpp)
sbs_target(mxgui-helloworld stm32f429zi_stm32f4discovery)
add_executable(kernel-testsuite src/entrypoints/kernel-testsuite.cpp)
sbs_target(kernel-testsuite stm32f429zi_stm32f4discovery)
sbs_target(kernel-testsuite stm32f205rc_skyward_ciuti)
add_executable(runcam-settings src/entrypoints/runcam-settings.cpp)
sbs_target(runcam-settings stm32f407vg_stm32f4discovery)
add_executable(sdcard-benchmark src/entrypoints/sdcard-benchmark.cpp)
sbs_target(sdcard-benchmark stm32f429zi_skyward_death_stack_x)
sbs_target(sdcard-benchmark stm32f205rc_skyward_ciuti)
#-----------------------------------------------------------------------------#
# Tests #
......
......@@ -80,6 +80,7 @@ foreach(OPT_BOARD ${BOARDS})
${SBS_BASE}/src/shared/sensors/BMX160/BMX160WithCorrection.cpp
${SBS_BASE}/src/shared/sensors/HX711/HX711.cpp
${SBS_BASE}/src/shared/sensors/LIS3MDL/LIS3MDL.cpp
${SBS_BASE}/src/shared/sensors/LIS331HH/LIS331HH.cpp
${SBS_BASE}/src/shared/sensors/calibration/SensorDataExtra.cpp
${SBS_BASE}/src/shared/sensors/MAX6675/MAX6675.cpp
${SBS_BASE}/src/shared/sensors/MAX31855/MAX31855.cpp
......
......@@ -27,7 +27,11 @@
namespace Boardcore
{
#ifndef _ARCH_CORTEXM3_STM32F2
static const unsigned int STACK_MIN_FOR_SKYWARD = 16 * 1024;
#else
static const unsigned int STACK_MIN_FOR_SKYWARD = 1024;
#endif
inline unsigned int skywardStack(unsigned int stack)
{
......
/* Copyright (c) 2022 Skyward Experimental Rocketry
* Author: Alberto Nidasio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "LIS331HH.h"
#include <drivers/timer/TimestampTimer.h>
namespace Boardcore
{
LIS331HH::LIS331HH(SPIBusInterface& bus, miosix::GpioPin cs,
SPIBusConfig spiConfig)
: slave(bus, cs, spiConfig)
{
}
bool LIS331HH::init()
{
SPITransaction spi(slave);
spi.writeRegister(CTRL_REG1, 0x20);
printf("CTRL_REG1: %X\n", spi.readRegister(CTRL_REG1));
return true;
}
bool LIS331HH::selfTest() { return true; }
LIS331HHData LIS331HH::sampleImpl()
{
uint16_t val;
LIS331HHData data;
data.accelerationTimestamp = TimestampTimer::getTimestamp();
SPITransaction spi(slave);
val = spi.readRegister(OUT_X_L);
val |= spi.readRegister(OUT_X_H) << 8;
data.accelerationX = 6.0 / 65536.0 * val;
printf("%X\t", val);
val = spi.readRegister(OUT_Y_L);
val |= spi.readRegister(OUT_Y_H) << 8;
data.accelerationX = 6.0 / 65536.0 * val;
printf("%X\t", val);
val = spi.readRegister(OUT_Z_L);
val |= spi.readRegister(OUT_Z_H) << 8;
data.accelerationX = 6.0 / 65536.0 * val;
printf("%X\t", val);
return data;
}
} // namespace Boardcore
\ No newline at end of file
/* Copyright (c) 2022 Skyward Experimental Rocketry
* Author: Alberto Nidasio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include <drivers/spi/SPIDriver.h>
#include <sensors/Sensor.h>
#include "LIS331HHData.h"
namespace Boardcore
{
class LIS331HH : public Sensor<LIS331HHData>
{
public:
LIS331HH(SPIBusInterface& bus, miosix::GpioPin cs, SPIBusConfig spiConfig);
bool init() override;
bool selfTest() override;
private:
LIS331HHData sampleImpl() override;
SPISlave slave;
enum Registers : uint8_t
{
CTRL_REG1 = 0x20,
CTRL_REG2 = 0x21,
CTRL_REG3 = 0x22,
CTRL_REG4 = 0x23,
CTRL_REG5 = 0x24,
HP_FILTER_RESET = 0x25,
REFERENCE = 0x26,
STATUS_REG = 0x27,
OUT_X_L = 0x28,
OUT_X_H = 0x29,
OUT_Y_L = 0x2a,
OUT_Y_H = 0x2b,
OUT_Z_L = 0x2c,
OUT_Z_H = 0x2d,
INT1_CFG = 0x30,
INT1_SOURCE = 0x31,
INT1_THS = 0x32,
INT1_DURATION = 0x33,
INT2_CFG = 0x34,
INT2_SOURCE = 0x35,
INT2_THS = 0x36,
INT2_DURATION = 0x37,
};
};
} // namespace Boardcore
\ No newline at end of file
/* Copyright (c) 2022 Skyward Experimental Rocketry
* Author: Alberto Nidasio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include <sensors/SensorData.h>
namespace Boardcore
{
struct LIS331HHData : public AccelerometerData
{
static std::string header()
{
return "accelerationTimestamp,accelerationX,accelerationY,"
"accelerationZ,temp_"
"timestamp,"
"temp\n";
}
void print(std::ostream& os) const
{
os << accelerationTimestamp << "," << accelerationX << ","
<< accelerationY << "," << accelerationZ << "\n";
}
};
} // namespace Boardcore
......@@ -318,9 +318,10 @@ public:
private:
/**
* @brief Read new data from the accelerometer.
* Acceleretions are returned in g.
*
* @return boolean value indicating whether the operation succeded or not
* Accelerations are returned in g.
*
* @return boolean value indicating whether the operation succeeded or not
*/
LIS3DSHData sampleImpl() override
{
......@@ -346,9 +347,9 @@ private:
}
/**
* @brief Read accelrometer data.
* @brief Read accelerometer data.
*
* @return the read accelrometer sample
* @return the read accelerometer sample
*/
AccelerometerData readAccelData()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment