eive-obsw/mission/devices/devicedefinitions/GyroL3GD20Definitions.h

141 lines
4.8 KiB
C
Raw Normal View History

2020-12-22 13:41:01 +01:00
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_
2021-03-07 14:06:29 +01:00
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
2020-12-23 20:17:39 +01:00
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
2020-12-22 13:44:32 +01:00
#include <cstdint>
2020-12-22 13:41:01 +01:00
namespace L3GD20H {
2021-03-07 14:06:29 +01:00
/* Actual size is 15 but we round up a bit */
static constexpr size_t MAX_BUFFER_SIZE = 16;
2020-12-22 13:44:32 +01:00
static constexpr uint8_t READ_MASK = 0b1000'0000;
static constexpr uint8_t AUTO_INCREMENT_MASK = 0b0100'0000;
static constexpr uint8_t WHO_AM_I_REG = 0b0000'1111;
static constexpr uint8_t WHO_AM_I_VAL = 0b1101'0111;
2020-12-23 20:17:39 +01:00
/*------------------------------------------------------------------------*/
2020-12-29 01:15:35 +01:00
/* Control registers */
2020-12-23 20:17:39 +01:00
/*------------------------------------------------------------------------*/
2020-12-22 13:44:32 +01:00
static constexpr uint8_t CTRL_REG_1 = 0b0010'0000;
static constexpr uint8_t CTRL_REG_2 = 0b0010'0001;
static constexpr uint8_t CTRL_REG_3 = 0b0010'0010;
static constexpr uint8_t CTRL_REG_4 = 0b0010'0011;
static constexpr uint8_t CTRL_REG_5 = 0b0010'0100;
2021-03-07 12:53:10 +01:00
/* Register 1 */
2020-12-23 20:17:39 +01:00
static constexpr uint8_t SET_DR_1 = 1 << 7;
static constexpr uint8_t SET_DR_0 = 1 << 6;
static constexpr uint8_t SET_BW_1 = 1 << 5;
static constexpr uint8_t SET_BW_0 = 1 << 4;
static constexpr uint8_t SET_POWER_NORMAL_MODE = 1 << 3;
static constexpr uint8_t SET_Z_ENABLE = 1 << 2;
static constexpr uint8_t SET_X_ENABLE = 1 << 1;
static constexpr uint8_t SET_Y_ENABLE = 1;
static constexpr uint8_t CTRL_REG_1_VAL = SET_POWER_NORMAL_MODE | SET_Z_ENABLE |
SET_Y_ENABLE | SET_X_ENABLE;
2021-03-07 12:53:10 +01:00
/* Register 2 */
2020-12-23 20:17:39 +01:00
static constexpr uint8_t EXTERNAL_EDGE_ENB = 1 << 7;
static constexpr uint8_t LEVEL_SENSITIVE_TRIGGER = 1 << 6;
static constexpr uint8_t SET_HPM_1 = 1 << 5;
static constexpr uint8_t SET_HPM_0 = 1 << 4;
static constexpr uint8_t SET_HPCF_3 = 1 << 3;
static constexpr uint8_t SET_HPCF_2 = 1 << 2;
static constexpr uint8_t SET_HPCF_1 = 1 << 1;
static constexpr uint8_t SET_HPCF_0 = 1;
static constexpr uint8_t CTRL_REG_2_VAL = 0b0000'0000;
2021-03-07 12:53:10 +01:00
/* Register 3 */
2020-12-23 20:17:39 +01:00
static constexpr uint8_t CTRL_REG_3_VAL = 0b0000'0000;
2021-03-07 12:53:10 +01:00
/* Register 4 */
2020-12-23 20:17:39 +01:00
static constexpr uint8_t SET_BNU = 1 << 7;
static constexpr uint8_t SET_BLE = 1 << 6;
static constexpr uint8_t SET_FS_1 = 1 << 5;
static constexpr uint8_t SET_FS_0 = 1 << 4;
static constexpr uint8_t SET_IMP_ENB = 1 << 3;
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_SPI_IF_SELECT = 1;
2021-03-07 12:53:10 +01:00
/* Enable big endian data format */
static constexpr uint8_t CTRL_REG_4_VAL = SET_BLE;
2020-12-23 20:17:39 +01:00
2021-03-07 12:53:10 +01:00
/* Register 5 */
2020-12-23 20:17:39 +01:00
static constexpr uint8_t SET_REBOOT_MEM = 1 << 7;
static constexpr uint8_t SET_FIFO_ENB = 1 << 6;
static constexpr uint8_t CTRL_REG_5_VAL = 0b0000'0000;
2021-03-07 12:53:10 +01:00
/* Possible range values in degrees per second (DPS). */
2020-12-23 20:17:39 +01:00
static constexpr uint16_t RANGE_DPS_00 = 245;
static constexpr uint16_t RANGE_DPS_01 = 500;
static constexpr uint16_t RANGE_DPS_11 = 2000;
static constexpr uint8_t READ_START = CTRL_REG_1;
static constexpr size_t READ_LEN = 14;
2021-03-07 12:53:10 +01:00
/* Indexing */
2020-12-23 20:17:39 +01:00
static constexpr uint8_t REFERENCE_IDX = 6;
static constexpr uint8_t TEMPERATURE_IDX = 7;
static constexpr uint8_t STATUS_IDX = 8;
2021-03-07 12:53:10 +01:00
static constexpr uint8_t OUT_X_H = 9;
static constexpr uint8_t OUT_X_L = 10;
static constexpr uint8_t OUT_Y_H = 11;
static constexpr uint8_t OUT_Y_L = 12;
static constexpr uint8_t OUT_Z_H = 13;
static constexpr uint8_t OUT_Z_L = 14;
2020-12-23 20:17:39 +01:00
/*------------------------------------------------------------------------*/
2020-12-29 01:15:35 +01:00
/* Device Handler specific */
2020-12-23 20:17:39 +01:00
/*------------------------------------------------------------------------*/
static constexpr DeviceCommandId_t READ_REGS = 0;
static constexpr DeviceCommandId_t CONFIGURE_CTRL_REGS = 1;
static constexpr DeviceCommandId_t READ_CTRL_REGS = 2;
static constexpr uint32_t GYRO_DATASET_ID = READ_REGS;
enum GyroPoolIds: lp_id_t {
ANG_VELOC_X,
ANG_VELOC_Y,
ANG_VELOC_Z,
TEMPERATURE
};
2021-03-07 14:06:29 +01:00
}
2020-12-23 20:17:39 +01:00
class GyroPrimaryDataset: public StaticLocalDataSet<3 * sizeof(float)> {
public:
2021-03-07 14:06:29 +01:00
/** Constructor for data users like controllers */
GyroPrimaryDataset(object_id_t mgmId):
StaticLocalDataSet(sid_t(mgmId, L3GD20H::GYRO_DATASET_ID)) {
setAllVariablesReadOnly();
}
2020-12-23 20:17:39 +01:00
2021-03-07 14:06:29 +01:00
/* Angular velocities in degrees per second (DPS) */
2020-12-23 20:17:39 +01:00
lp_var_t<float> angVelocX = lp_var_t<float>(sid.objectId,
2021-03-07 14:06:29 +01:00
L3GD20H::ANG_VELOC_X, this);
2020-12-23 20:17:39 +01:00
lp_var_t<float> angVelocY = lp_var_t<float>(sid.objectId,
2021-03-07 14:06:29 +01:00
L3GD20H::ANG_VELOC_Y, this);
2020-12-23 20:17:39 +01:00
lp_var_t<float> angVelocZ = lp_var_t<float>(sid.objectId,
2021-03-07 14:06:29 +01:00
L3GD20H::ANG_VELOC_Z, this);
2020-12-23 20:17:39 +01:00
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId,
2021-03-07 14:06:29 +01:00
L3GD20H::TEMPERATURE, this);
private:
2020-12-22 13:41:01 +01:00
2021-03-07 14:06:29 +01:00
friend class GyroHandlerL3GD20H;
/** Constructor for the data creator */
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner):
StaticLocalDataSet(hkOwner, L3GD20H::GYRO_DATASET_ID) {}
};
2020-12-22 13:41:01 +01:00
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_ */