gpio bugfix
This commit is contained in:
@ -1,8 +1,91 @@
|
||||
#include <linux/boardtest/SpiTestClass.h>
|
||||
#include "SpiTestClass.h"
|
||||
|
||||
SpiTestClass::SpiTestClass(object_id_t objectId): TestTask(objectId) {
|
||||
#include <fsfwconfig/devices/gpioIds.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
||||
#include <linux/spi/spidev.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/gpio/gpioDefinitions.h>
|
||||
#include <linux/gpio/GpioCookie.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
||||
SpiTestClass::SpiTestClass(object_id_t objectId, GpioIF* gpioIF): TestTask(objectId),
|
||||
gpioIF(gpioIF) {
|
||||
if(gpioIF == nullptr) {
|
||||
sif::error << "SpiTestClass::SpiTestClass: Invalid GPIO ComIF!" << std::endl;
|
||||
}
|
||||
testMode = TestModes::MGM_RM3100;
|
||||
spiTransferStruct.rx_buf = reinterpret_cast<__u64>(recvBuffer.data());
|
||||
spiTransferStruct.tx_buf = reinterpret_cast<__u64>(sendBuffer.data());
|
||||
}
|
||||
|
||||
ReturnValue_t SpiTestClass::performOneShotAction() {
|
||||
switch(testMode) {
|
||||
case(TestModes::MGM_LIS3MDL): {
|
||||
break;
|
||||
}
|
||||
case(TestModes::MGM_RM3100): {
|
||||
performRm3100Test();
|
||||
break;
|
||||
}
|
||||
case(TestModes::GYRO_L3GD20H): {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t SpiTestClass::performPeriodicAction() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void SpiTestClass::performRm3100Test() {
|
||||
/* Adapt accordingly */
|
||||
uint8_t chipSelectPin = mgm1Rm3100ChipSelect;
|
||||
acsInit();
|
||||
}
|
||||
|
||||
void SpiTestClass::acsInit() {
|
||||
GpioCookie* gpioCookie = new GpioCookie();
|
||||
std::string rpiGpioName = "gpiochip0";
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName.c_str(), mgm0Lis3ChipSelect, "MGM_0_LIS3",
|
||||
gpio::Direction::OUT, 1);
|
||||
gpioCookie->addGpio(gpioIds::MGM_0_LIS3_CS, gpio);
|
||||
}
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName.c_str(), mgm1Rm3100ChipSelect, "MGM_1_RM3100",
|
||||
gpio::Direction::OUT, 1);
|
||||
gpioCookie->addGpio(gpioIds::MGM_1_RM3100_CS, gpio);
|
||||
}
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName.c_str(), gyro0AdisChipSelect, "GYRO_0_ADIS",
|
||||
gpio::Direction::OUT, 1);
|
||||
gpioCookie->addGpio(gpioIds::GYRO_0_ADIS_CS, gpio);
|
||||
}
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName.c_str(), gyro1L3gd20ChipSelect, "GYRO_1_L3G",
|
||||
gpio::Direction::OUT, 1);
|
||||
gpioCookie->addGpio(gpioIds::GYRO_1_L3G_CS, gpio);
|
||||
}
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName.c_str(), gyro2L3gd20ChipSelect, "GYRO_2_L3G",
|
||||
gpio::Direction::OUT, 1);
|
||||
gpioCookie->addGpio(gpioIds::GYRO_2_L3G_CS, gpio);
|
||||
}
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName.c_str(), mgm2Lis3mdlChipSelect, "MGM_2_LIS3",
|
||||
gpio::Direction::OUT, 1);
|
||||
gpioCookie->addGpio(gpioIds::MGM_2_LIS3_CS, gpio);
|
||||
}
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName.c_str(), mgm3Rm3100ChipSelect, "MGM_3_RM3100",
|
||||
gpio::Direction::OUT, 1);
|
||||
gpioCookie->addGpio(gpioIds::MGM_3_RM3100_CS, gpio);
|
||||
}
|
||||
if(gpioIF != nullptr) {
|
||||
gpioIF->addGpios(gpioCookie);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,47 @@
|
||||
#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:
|
||||
SpiTestClass(object_id_t objectId);
|
||||
enum TestModes {
|
||||
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;
|
||||
struct spi_ioc_transfer spiTransferStruct;
|
||||
|
||||
void performRm3100Test();
|
||||
/* 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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user