2020-10-01 02:06:39 +02:00
|
|
|
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERLIS3DEFINITIONS_H_
|
|
|
|
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERLIS3DEFINITIONS_H_
|
|
|
|
|
2020-12-03 12:57:44 +01:00
|
|
|
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
|
|
|
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
|
|
|
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
2020-10-01 02:06:39 +02:00
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
namespace MGMLIS3MDL {
|
|
|
|
|
|
|
|
enum set {
|
|
|
|
ON, OFF
|
|
|
|
};
|
|
|
|
enum opMode {
|
|
|
|
LOW, MEDIUM, HIGH, ULTRA
|
|
|
|
};
|
|
|
|
|
2021-03-07 14:06:29 +01:00
|
|
|
/* Actually 15, we just round up a bit */
|
|
|
|
static constexpr size_t MAX_BUFFER_SIZE = 16;
|
|
|
|
|
2020-12-03 12:57:44 +01:00
|
|
|
static constexpr uint8_t GAUSS_TO_MICROTESLA_FACTOR = 100;
|
|
|
|
|
2021-06-24 18:05:41 +02:00
|
|
|
static const DeviceCommandId_t READ_CONFIG_AND_DATA = 0x00;
|
|
|
|
static const DeviceCommandId_t SETUP_MGM = 0x01;
|
2020-12-03 12:57:44 +01:00
|
|
|
static const DeviceCommandId_t READ_TEMPERATURE = 0x02;
|
|
|
|
static const DeviceCommandId_t IDENTIFY_DEVICE = 0x03;
|
|
|
|
static const DeviceCommandId_t TEMP_SENSOR_ENABLE = 0x04;
|
|
|
|
static const DeviceCommandId_t ACCURACY_OP_MODE_SET = 0x05;
|
2020-10-01 02:06:39 +02:00
|
|
|
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Number of all control registers */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t NR_OF_CTRL_REGISTERS = 5;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Number of registers in the MGM */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t NR_OF_REGISTERS = 19;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Total number of adresses for all registers */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t TOTAL_NR_OF_ADRESSES = 52;
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t NR_OF_DATA_AND_CFG_REGISTERS = 14;
|
|
|
|
static const uint8_t TEMPERATURE_REPLY_LEN = 3;
|
|
|
|
static const uint8_t SETUP_REPLY_LEN = 6;
|
2020-10-01 02:06:39 +02:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
/* Register adresses */
|
|
|
|
/*------------------------------------------------------------------------*/
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress returns identifier of device with default 0b00111101 */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t IDENTIFY_DEVICE_REG_ADDR = 0b00001111;
|
|
|
|
static const uint8_t DEVICE_ID = 0b00111101; // Identifier for Device
|
|
|
|
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access register 1 */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t CTRL_REG1 = 0b00100000;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access register 2 */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t CTRL_REG2 = 0b00100001;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access register 3 */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t CTRL_REG3 = 0b00100010;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access register 4 */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t CTRL_REG4 = 0b00100011;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access register 5 */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t CTRL_REG5 = 0b00100100;
|
|
|
|
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access status register */
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t STATUS_REG_IDX = 8;
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t STATUS_REG = 0b00100111;
|
|
|
|
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access low byte of x-axis */
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t X_LOWBYTE_IDX = 9;
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t X_LOWBYTE = 0b00101000;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access high byte of x-axis */
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t X_HIGHBYTE_IDX = 10;
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t X_HIGHBYTE = 0b00101001;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access low byte of y-axis */
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t Y_LOWBYTE_IDX = 11;
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t Y_LOWBYTE = 0b00101010;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access high byte of y-axis */
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t Y_HIGHBYTE_IDX = 12;
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t Y_HIGHBYTE = 0b00101011;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access low byte of z-axis */
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t Z_LOWBYTE_IDX = 13;
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t Z_LOWBYTE = 0b00101100;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access high byte of z-axis */
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t Z_HIGHBYTE_IDX = 14;
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t Z_HIGHBYTE = 0b00101101;
|
|
|
|
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access low byte of temperature sensor */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t TEMP_LOWBYTE = 0b00101110;
|
2021-02-24 11:24:31 +01:00
|
|
|
/* Register adress to access high byte of temperature sensor */
|
2020-10-01 02:06:39 +02:00
|
|
|
static const uint8_t TEMP_HIGHBYTE = 0b00101111;
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
2020-12-03 12:57:44 +01:00
|
|
|
/* Initialize Setup Register set bits */
|
2020-10-01 02:06:39 +02:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
/* General transfer bits */
|
|
|
|
// Read=1 / Write=0 Bit
|
|
|
|
static const uint8_t RW_BIT = 7;
|
|
|
|
// Continous Read/Write Bit, increment adress
|
|
|
|
static const uint8_t MS_BIT = 6;
|
|
|
|
|
|
|
|
/* CTRL_REG1 bits */
|
|
|
|
static const uint8_t ST = 0; // Self test enable bit, enabled = 1
|
|
|
|
// Enable rates higher than 80 Hz enabled = 1
|
|
|
|
static const uint8_t FAST_ODR = 1;
|
|
|
|
static const uint8_t DO0 = 2; // Output data rate bit 2
|
|
|
|
static const uint8_t DO1 = 3; // Output data rate bit 3
|
|
|
|
static const uint8_t DO2 = 4; // Output data rate bit 4
|
|
|
|
static const uint8_t OM0 = 5; // XY operating mode bit 5
|
|
|
|
static const uint8_t OM1 = 6; // XY operating mode bit 6
|
|
|
|
static const uint8_t TEMP_EN = 7; // Temperature sensor enable enabled = 1
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t CTRL_REG1_DEFAULT = (1 << TEMP_EN) | (1 << OM1) |
|
|
|
|
(1 << DO0) | (1 << DO1) | (1 << DO2);
|
2020-10-01 02:06:39 +02:00
|
|
|
|
|
|
|
/* CTRL_REG2 bits */
|
|
|
|
//reset configuration registers and user registers
|
|
|
|
static const uint8_t SOFT_RST = 2;
|
|
|
|
static const uint8_t REBOOT = 3; //reboot memory content
|
|
|
|
static const uint8_t FSO = 5; //full-scale selection bit 5
|
|
|
|
static const uint8_t FS1 = 6; //full-scale selection bit 6
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t CTRL_REG2_DEFAULT = 0;
|
2020-10-01 02:06:39 +02:00
|
|
|
|
|
|
|
/* CTRL_REG3 bits */
|
|
|
|
static const uint8_t MD0 = 0; //Operating mode bit 0
|
|
|
|
static const uint8_t MD1 = 1; //Operating mode bit 1
|
|
|
|
//SPI serial interface mode selection enabled = 3-wire-mode
|
|
|
|
static const uint8_t SIM = 2;
|
|
|
|
static const uint8_t LP = 5; //low-power mode
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t CTRL_REG3_DEFAULT = 0;
|
2020-10-01 02:06:39 +02:00
|
|
|
|
|
|
|
/* CTRL_REG4 bits */
|
|
|
|
//big/little endian data selection enabled = MSb at lower adress
|
|
|
|
static const uint8_t BLE = 1;
|
|
|
|
static const uint8_t OMZ0 = 2; //Z operating mode bit 2
|
|
|
|
static const uint8_t OMZ1 = 3; //Z operating mode bit 3
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t CTRL_REG4_DEFAULT = (1 << OMZ1);
|
2020-10-01 02:06:39 +02:00
|
|
|
|
|
|
|
/* CTRL_REG5 bits */
|
|
|
|
static const uint8_t BDU = 6; //Block data update
|
|
|
|
static const uint8_t FAST_READ = 7; //Fast read enabled = 1
|
2020-12-03 12:57:44 +01:00
|
|
|
static const uint8_t CTRL_REG5_DEFAULT = 0;
|
|
|
|
|
2020-12-14 22:50:15 +01:00
|
|
|
static const uint32_t MGM_DATA_SET_ID = READ_CONFIG_AND_DATA;
|
2020-12-03 12:57:44 +01:00
|
|
|
|
|
|
|
enum MgmPoolIds: lp_id_t {
|
|
|
|
FIELD_STRENGTH_X,
|
|
|
|
FIELD_STRENGTH_Y,
|
|
|
|
FIELD_STRENGTH_Z,
|
|
|
|
TEMPERATURE_CELCIUS
|
|
|
|
};
|
|
|
|
|
2021-05-25 15:45:48 +02:00
|
|
|
class MgmPrimaryDataset: public StaticLocalDataSet<5> {
|
2020-12-03 12:57:44 +01:00
|
|
|
public:
|
|
|
|
MgmPrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
|
|
|
StaticLocalDataSet(hkOwner, MGM_DATA_SET_ID) {}
|
|
|
|
|
|
|
|
MgmPrimaryDataset(object_id_t mgmId):
|
|
|
|
StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
|
|
|
|
|
2020-12-14 22:50:15 +01:00
|
|
|
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId,
|
2020-12-03 12:57:44 +01:00
|
|
|
FIELD_STRENGTH_X, this);
|
2020-12-14 22:50:15 +01:00
|
|
|
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId,
|
2020-12-03 12:57:44 +01:00
|
|
|
FIELD_STRENGTH_Y, this);
|
2020-12-14 22:50:15 +01:00
|
|
|
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId,
|
2020-12-03 12:57:44 +01:00
|
|
|
FIELD_STRENGTH_Z, this);
|
|
|
|
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId,
|
|
|
|
TEMPERATURE_CELCIUS, this);
|
|
|
|
};
|
2020-10-01 02:06:39 +02:00
|
|
|
|
2020-12-03 12:57:44 +01:00
|
|
|
}
|
2020-10-01 02:06:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERLIS3DEFINITIONS_H_ */
|