eive-obsw/linux/boardtest/SpiTestClass.h

77 lines
2.4 KiB
C
Raw Normal View History

2021-03-04 18:29:28 +01:00
#ifndef LINUX_BOARDTEST_SPITESTCLASS_H_
#define LINUX_BOARDTEST_SPITESTCLASS_H_
#include <linux/gpio/GpioIF.h>
#include <linux/spi/SpiCookie.h>
#include <test/testtasks/TestTask.h>
#include <vector>
class SpiTestClass: public TestTask {
public:
enum TestModes {
NONE,
MGM_LIS3MDL,
MGM_RM3100,
GYRO_L3GD20H,
};
TestModes testMode;
SpiTestClass(object_id_t objectId, GpioIF* gpioIF);
ReturnValue_t performOneShotAction() override;
ReturnValue_t performPeriodicAction() override;
private:
GpioIF* gpioIF;
std::array<uint8_t, 128> recvBuffer;
std::array<uint8_t, 128> sendBuffer;
2021-03-06 20:21:23 +01:00
struct spi_ioc_transfer spiTransferStruct = {};
2021-03-04 18:29:28 +01:00
void performRm3100Test(uint8_t mgmId);
void performLis3MdlTest(uint8_t lis3Id);
2021-03-07 12:50:41 +01:00
void performL3gTest(uint8_t l3gId);
2021-03-04 18:29:28 +01:00
/* ACS board specific code which pulls all GPIOs high */
void acsInit();
/* ACS board specific variables */
uint8_t mgm0Lis3ChipSelect = 0;
uint8_t mgm1Rm3100ChipSelect = 1;
uint8_t gyro0AdisChipSelect = 5;
uint8_t gyro1L3gd20ChipSelect = 6;
uint8_t gyro2L3gd20ChipSelect = 4;
uint8_t mgm2Lis3mdlChipSelect = 17;
uint8_t mgm3Rm3100ChipSelect = 27;
static constexpr uint8_t STM_READ_MASK = 0b1000'0000;
2021-03-06 18:12:50 +01:00
static constexpr uint8_t RM3100_READ_MASK = STM_READ_MASK;
2021-02-23 18:01:28 +01:00
static constexpr uint8_t STM_AUTO_INCR_MASK = 0b0100'0000;
2021-03-07 14:06:29 +01:00
void setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed);
2021-03-07 12:50:41 +01:00
2021-02-23 18:01:28 +01:00
void writeStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t value,
bool autoIncrement);
2021-03-07 12:50:41 +01:00
void writeMultipleStmRegisters(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t* values,
size_t len);
void writeMultipleRegisters(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t *values,
size_t len);
void writeRegister(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t value);
2021-03-06 18:12:50 +01:00
uint8_t readRm3100Register(int fd, gpioId_t chipSelect, uint8_t reg);
2021-02-23 18:01:28 +01:00
uint8_t readStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, bool autoIncrement);
2021-03-07 12:50:41 +01:00
uint8_t readRegister(int fd, gpioId_t chipSelect, uint8_t reg);
void readMultipleStmRegisters(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t *reply,
size_t len);
void readMultipleRegisters(int fd, gpioId_t chipSelect, uint8_t reg,
uint8_t* reply, size_t len);
2021-03-04 18:29:28 +01:00
};
#endif /* LINUX_BOARDTEST_SPITESTCLASS_H_ */