2021-05-31 20:40:16 +02:00
|
|
|
#ifndef FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
|
|
|
|
#define FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
|
|
|
|
|
|
|
|
#include "stm32h7xx_hal.h"
|
|
|
|
#include "stm32h7xx_hal_spi.h"
|
|
|
|
|
2021-06-03 21:53:52 +02:00
|
|
|
#include "../spi/spiDefinitions.h"
|
2021-05-31 20:40:16 +02:00
|
|
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
|
|
|
|
2021-06-03 14:00:50 +02:00
|
|
|
#include <cstdint>
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
enum class TransferStates {
|
|
|
|
IDLE,
|
|
|
|
WAIT,
|
|
|
|
SUCCESS,
|
|
|
|
FAILURE
|
|
|
|
};
|
|
|
|
|
2021-05-31 20:40:16 +02:00
|
|
|
class GyroL3GD20H {
|
|
|
|
public:
|
2021-06-03 21:53:52 +02:00
|
|
|
GyroL3GD20H(SPI_HandleTypeDef* spiHandle, spi::TransferModes transferMode);
|
2021-05-31 20:40:16 +02:00
|
|
|
|
2021-06-03 14:00:50 +02:00
|
|
|
ReturnValue_t initialize();
|
2021-05-31 20:40:16 +02:00
|
|
|
ReturnValue_t performOperation();
|
2021-06-03 14:00:50 +02:00
|
|
|
|
2021-05-31 20:40:16 +02:00
|
|
|
private:
|
2021-06-03 14:00:50 +02:00
|
|
|
|
2021-06-03 22:07:59 +02:00
|
|
|
const uint8_t WHO_AM_I_REG = 0b00001111;
|
|
|
|
const uint8_t STM_READ_MASK = 0b10000000;
|
2021-06-04 14:41:02 +02:00
|
|
|
const uint8_t STM_AUTO_INCREMENT_MASK = 0b01000000;
|
2021-06-03 22:07:59 +02:00
|
|
|
const uint8_t EXPECTED_WHO_AM_I_VAL = 0b11010111;
|
2021-06-04 14:41:02 +02:00
|
|
|
const uint8_t CTRL_REG_1 = 0b00100000;
|
|
|
|
const uint32_t L3G_RANGE = 245;
|
2021-06-03 22:07:59 +02:00
|
|
|
|
2021-05-31 20:40:16 +02:00
|
|
|
SPI_HandleTypeDef* spiHandle;
|
2021-06-04 12:58:30 +02:00
|
|
|
|
2021-06-04 15:50:02 +02:00
|
|
|
static spi::TransferModes transferMode;
|
2021-06-04 14:41:02 +02:00
|
|
|
static constexpr size_t recvBufferSize = 32 * 10;
|
2021-06-03 14:00:50 +02:00
|
|
|
static std::array<uint8_t, recvBufferSize> rxBuffer;
|
2021-06-04 12:58:30 +02:00
|
|
|
static constexpr size_t txBufferSize = 32;
|
|
|
|
static std::array<uint8_t, txBufferSize> txBuffer;
|
2021-06-03 22:07:59 +02:00
|
|
|
|
2021-06-04 14:41:02 +02:00
|
|
|
ReturnValue_t handleDmaTransferInit();
|
2021-06-04 15:50:02 +02:00
|
|
|
ReturnValue_t handlePollingTransferInit();
|
|
|
|
ReturnValue_t handleInterruptTransferInit();
|
|
|
|
|
2021-06-04 14:41:02 +02:00
|
|
|
ReturnValue_t handleDmaSensorRead();
|
|
|
|
HAL_StatusTypeDef performDmaTransfer(size_t sendSize);
|
2021-06-04 15:50:02 +02:00
|
|
|
ReturnValue_t handlePollingSensorRead();
|
|
|
|
ReturnValue_t handleInterruptSensorRead();
|
2021-06-04 14:41:02 +02:00
|
|
|
|
2021-06-05 13:29:43 +02:00
|
|
|
static void spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
|
|
|
|
static void spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args);
|
|
|
|
|
2021-06-04 15:50:02 +02:00
|
|
|
void prepareConfigRegs(uint8_t* configRegs);
|
|
|
|
void handleSensorReadout();
|
2021-05-31 20:40:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_ */
|