using big endian now for gyro

This commit is contained in:
Robin Müller 2021-03-07 12:53:10 +01:00
parent a581ce8bd6
commit b1dc0122b7
3 changed files with 31 additions and 30 deletions

View File

@ -1,15 +1,15 @@
#include <mission/devices/GyroL3GD20Handler.h> #include <mission/devices/GyroL3GD20Handler.h>
#include <fsfw/datapool/PoolReadGuard.h> #include <fsfw/datapool/PoolReadGuard.h>
GyroHandler::GyroHandler(object_id_t objectId, object_id_t deviceCommunication, GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
CookieIF *comCookie): CookieIF *comCookie):
DeviceHandlerBase(objectId, deviceCommunication, comCookie), DeviceHandlerBase(objectId, deviceCommunication, comCookie),
dataset(this) { dataset(this) {
} }
GyroHandler::~GyroHandler() {} GyroHandlerL3GD20H::~GyroHandlerL3GD20H() {}
void GyroHandler::doStartUp() { void GyroHandlerL3GD20H::doStartUp() {
if(internalState == InternalState::STATE_NONE) { if(internalState == InternalState::STATE_NONE) {
internalState = InternalState::STATE_CONFIGURE; internalState = InternalState::STATE_CONFIGURE;
} }
@ -22,11 +22,11 @@ void GyroHandler::doStartUp() {
} }
} }
void GyroHandler::doShutDown() { void GyroHandlerL3GD20H::doShutDown() {
setMode(_MODE_POWER_DOWN); setMode(_MODE_POWER_DOWN);
} }
ReturnValue_t GyroHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) { ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
switch(internalState) { switch(internalState) {
case(InternalState::STATE_NONE): case(InternalState::STATE_NONE):
case(InternalState::STATE_NORMAL): { case(InternalState::STATE_NORMAL): {
@ -52,12 +52,12 @@ ReturnValue_t GyroHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t GyroHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) { ReturnValue_t GyroHandlerL3GD20H::buildNormalDeviceCommand(DeviceCommandId_t *id) {
*id = L3GD20H::READ_REGS; *id = L3GD20H::READ_REGS;
return buildCommandFromCommand(*id, nullptr, 0); return buildCommandFromCommand(*id, nullptr, 0);
} }
ReturnValue_t GyroHandler::buildCommandFromCommand( ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t *commandData, DeviceCommandId_t deviceCommand, const uint8_t *commandData,
size_t commandDataLen) { size_t commandDataLen) {
switch(deviceCommand) { switch(deviceCommand) {
@ -120,7 +120,7 @@ ReturnValue_t GyroHandler::buildCommandFromCommand(
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t GyroHandler::scanForReply(const uint8_t *start, size_t len, ReturnValue_t GyroHandlerL3GD20H::scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) { DeviceCommandId_t *foundId, size_t *foundLen) {
// SPI, ID will always be the one of the last sent command. // SPI, ID will always be the one of the last sent command.
*foundId = this->getPendingCommand(); *foundId = this->getPendingCommand();
@ -133,7 +133,7 @@ ReturnValue_t GyroHandler::scanForReply(const uint8_t *start, size_t len,
return DeviceHandlerIF::INVALID_DATA; return DeviceHandlerIF::INVALID_DATA;
} }
ReturnValue_t GyroHandler::interpretDeviceReply(DeviceCommandId_t id, ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) { const uint8_t *packet) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
switch(id) { switch(id) {
@ -189,11 +189,11 @@ ReturnValue_t GyroHandler::interpretDeviceReply(DeviceCommandId_t id,
} }
uint32_t GyroHandler::getTransitionDelayMs(Mode_t from, Mode_t to) { uint32_t GyroHandlerL3GD20H::getTransitionDelayMs(Mode_t from, Mode_t to) {
return 20000; return 20000;
} }
ReturnValue_t GyroHandler::initializeLocalDataPool( ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_X, localDataPoolMap.emplace(L3GD20H::ANG_VELOC_X,
new PoolEntry<float>({0.0})); new PoolEntry<float>({0.0}));
@ -206,12 +206,12 @@ ReturnValue_t GyroHandler::initializeLocalDataPool(
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void GyroHandler::fillCommandAndReplyMap() { void GyroHandlerL3GD20H::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(L3GD20H::READ_REGS, 1, &dataset); insertInCommandAndReplyMap(L3GD20H::READ_REGS, 1, &dataset);
insertInCommandAndReplyMap(L3GD20H::CONFIGURE_CTRL_REGS, 1); insertInCommandAndReplyMap(L3GD20H::CONFIGURE_CTRL_REGS, 1);
insertInCommandAndReplyMap(L3GD20H::READ_CTRL_REGS, 1); insertInCommandAndReplyMap(L3GD20H::READ_CTRL_REGS, 1);
} }
void GyroHandler::modeChanged() { void GyroHandlerL3GD20H::modeChanged() {
internalState = InternalState::STATE_NONE; internalState = InternalState::STATE_NONE;
} }

View File

@ -11,11 +11,11 @@
* Advanced documentation: * Advanced documentation:
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/L3GD20H_Gyro * https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/L3GD20H_Gyro
*/ */
class GyroHandler: public DeviceHandlerBase { class GyroHandlerL3GD20H: public DeviceHandlerBase {
public: public:
GyroHandler(object_id_t objectId, object_id_t deviceCommunication, GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
CookieIF* comCookie); CookieIF* comCookie);
virtual ~GyroHandler(); virtual ~GyroHandlerL3GD20H();
protected: protected:

View File

@ -22,7 +22,7 @@ static constexpr uint8_t CTRL_REG_3 = 0b0010'0010;
static constexpr uint8_t CTRL_REG_4 = 0b0010'0011; static constexpr uint8_t CTRL_REG_4 = 0b0010'0011;
static constexpr uint8_t CTRL_REG_5 = 0b0010'0100; static constexpr uint8_t CTRL_REG_5 = 0b0010'0100;
// Register 1 /* Register 1 */
static constexpr uint8_t SET_DR_1 = 1 << 7; static constexpr uint8_t SET_DR_1 = 1 << 7;
static constexpr uint8_t SET_DR_0 = 1 << 6; static constexpr uint8_t SET_DR_0 = 1 << 6;
static constexpr uint8_t SET_BW_1 = 1 << 5; static constexpr uint8_t SET_BW_1 = 1 << 5;
@ -35,7 +35,7 @@ static constexpr uint8_t SET_Y_ENABLE = 1;
static constexpr uint8_t CTRL_REG_1_VAL = SET_POWER_NORMAL_MODE | SET_Z_ENABLE | static constexpr uint8_t CTRL_REG_1_VAL = SET_POWER_NORMAL_MODE | SET_Z_ENABLE |
SET_Y_ENABLE | SET_X_ENABLE; SET_Y_ENABLE | SET_X_ENABLE;
// Register 2 /* Register 2 */
static constexpr uint8_t EXTERNAL_EDGE_ENB = 1 << 7; static constexpr uint8_t EXTERNAL_EDGE_ENB = 1 << 7;
static constexpr uint8_t LEVEL_SENSITIVE_TRIGGER = 1 << 6; static constexpr uint8_t LEVEL_SENSITIVE_TRIGGER = 1 << 6;
static constexpr uint8_t SET_HPM_1 = 1 << 5; static constexpr uint8_t SET_HPM_1 = 1 << 5;
@ -47,10 +47,10 @@ static constexpr uint8_t SET_HPCF_0 = 1;
static constexpr uint8_t CTRL_REG_2_VAL = 0b0000'0000; static constexpr uint8_t CTRL_REG_2_VAL = 0b0000'0000;
// Register 3 /* Register 3 */
static constexpr uint8_t CTRL_REG_3_VAL = 0b0000'0000; static constexpr uint8_t CTRL_REG_3_VAL = 0b0000'0000;
// Register 4 /* Register 4 */
static constexpr uint8_t SET_BNU = 1 << 7; static constexpr uint8_t SET_BNU = 1 << 7;
static constexpr uint8_t SET_BLE = 1 << 6; static constexpr uint8_t SET_BLE = 1 << 6;
static constexpr uint8_t SET_FS_1 = 1 << 5; static constexpr uint8_t SET_FS_1 = 1 << 5;
@ -60,15 +60,16 @@ static constexpr uint8_t SET_SELF_TEST_ENB_1 = 1 << 2;
static constexpr uint8_t SET_SELF_TEST_ENB_0 = 1 << 1; static constexpr uint8_t SET_SELF_TEST_ENB_0 = 1 << 1;
static constexpr uint8_t SET_SPI_IF_SELECT = 1; static constexpr uint8_t SET_SPI_IF_SELECT = 1;
static constexpr uint8_t CTRL_REG_4_VAL = 0b0000'0000; /* Enable big endian data format */
static constexpr uint8_t CTRL_REG_4_VAL = SET_BLE;
// Register 5 /* Register 5 */
static constexpr uint8_t SET_REBOOT_MEM = 1 << 7; static constexpr uint8_t SET_REBOOT_MEM = 1 << 7;
static constexpr uint8_t SET_FIFO_ENB = 1 << 6; static constexpr uint8_t SET_FIFO_ENB = 1 << 6;
static constexpr uint8_t CTRL_REG_5_VAL = 0b0000'0000; static constexpr uint8_t CTRL_REG_5_VAL = 0b0000'0000;
// In degrees per second (DPS) for now. /* Possible range values in degrees per second (DPS). */
static constexpr uint16_t RANGE_DPS_00 = 245; static constexpr uint16_t RANGE_DPS_00 = 245;
static constexpr uint16_t RANGE_DPS_01 = 500; static constexpr uint16_t RANGE_DPS_01 = 500;
static constexpr uint16_t RANGE_DPS_11 = 2000; static constexpr uint16_t RANGE_DPS_11 = 2000;
@ -76,16 +77,16 @@ static constexpr uint16_t RANGE_DPS_11 = 2000;
static constexpr uint8_t READ_START = CTRL_REG_1; static constexpr uint8_t READ_START = CTRL_REG_1;
static constexpr size_t READ_LEN = 14; static constexpr size_t READ_LEN = 14;
// Indexing /* Indexing */
static constexpr uint8_t REFERENCE_IDX = 6; static constexpr uint8_t REFERENCE_IDX = 6;
static constexpr uint8_t TEMPERATURE_IDX = 7; static constexpr uint8_t TEMPERATURE_IDX = 7;
static constexpr uint8_t STATUS_IDX = 8; static constexpr uint8_t STATUS_IDX = 8;
static constexpr uint8_t OUT_X_L = 9; static constexpr uint8_t OUT_X_H = 9;
static constexpr uint8_t OUT_X_H = 10; static constexpr uint8_t OUT_X_L = 10;
static constexpr uint8_t OUT_Y_L = 11; static constexpr uint8_t OUT_Y_H = 11;
static constexpr uint8_t OUT_Y_H = 12; static constexpr uint8_t OUT_Y_L = 12;
static constexpr uint8_t OUT_Z_L = 13; static constexpr uint8_t OUT_Z_H = 13;
static constexpr uint8_t OUT_Z_H = 14; static constexpr uint8_t OUT_Z_L = 14;
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/* Device Handler specific */ /* Device Handler specific */