2022-03-30 17:44:07 +02:00
|
|
|
#include "gpioInit.h"
|
|
|
|
|
|
|
|
#include <devices/gpioIds.h>
|
|
|
|
#include <fsfw/serviceinterface/ServiceInterface.h>
|
|
|
|
#include <fsfw_hal/common/gpio/GpioCookie.h>
|
|
|
|
#include <fsfw_hal/common/gpio/GpioIF.h>
|
|
|
|
|
2022-03-30 17:50:36 +02:00
|
|
|
#include "definitions.h"
|
|
|
|
#include "fsfw_hal/linux/rpi/GpioRPi.h"
|
|
|
|
|
2022-03-30 17:44:07 +02:00
|
|
|
#ifdef RASPBERRY_PI
|
|
|
|
|
|
|
|
struct MuxInfo {
|
|
|
|
MuxInfo(gpioId_t gpioId, int bcmNum, std::string consumer)
|
2022-03-30 17:50:36 +02:00
|
|
|
: gpioId(gpioId), bcmNum(bcmNum), consumer(consumer) {}
|
2022-03-30 17:44:07 +02:00
|
|
|
gpioId_t gpioId;
|
|
|
|
int bcmNum;
|
|
|
|
std::string consumer;
|
|
|
|
};
|
|
|
|
|
|
|
|
void rpi::gpio::initSpiCsDecoder(GpioIF* gpioComIF) {
|
|
|
|
using namespace ::gpio;
|
|
|
|
ReturnValue_t result;
|
|
|
|
|
|
|
|
if (gpioComIF == nullptr) {
|
|
|
|
sif::debug << "initSpiCsDecoder: Invalid gpioComIF" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-30 17:50:36 +02:00
|
|
|
std::array<::MuxInfo, 6> muxInfo{
|
|
|
|
MuxInfo(gpioIds::SPI_MUX_BIT_0, SPI_MUX_0_BCM, "SPI_MUX_0"),
|
|
|
|
MuxInfo(gpioIds::SPI_MUX_BIT_1, SPI_MUX_1_BCM, "SPI_MUX_1"),
|
|
|
|
MuxInfo(gpioIds::SPI_MUX_BIT_2, SPI_MUX_2_BCM, "SPI_MUX_2"),
|
|
|
|
MuxInfo(gpioIds::SPI_MUX_BIT_3, SPI_MUX_3_BCM, "SPI_MUX_3"),
|
|
|
|
MuxInfo(gpioIds::SPI_MUX_BIT_4, SPI_MUX_4_BCM, "SPI_MUX_4"),
|
|
|
|
MuxInfo(gpioIds::SPI_MUX_BIT_5, SPI_MUX_5_BCM, "SPI_MUX_5"),
|
2022-03-30 17:44:07 +02:00
|
|
|
};
|
|
|
|
GpioCookie* spiMuxGpios = new GpioCookie;
|
|
|
|
|
2022-03-30 17:50:36 +02:00
|
|
|
for (const auto& info : muxInfo) {
|
2022-03-30 17:44:07 +02:00
|
|
|
result = createRpiGpioConfig(spiMuxGpios, info.gpioId, info.bcmNum, info.consumer,
|
2022-03-30 17:50:36 +02:00
|
|
|
Direction::OUT, Levels::LOW);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
2022-03-30 17:44:07 +02:00
|
|
|
sif::error << "Creating Raspberry Pi SPI Mux GPIO failed with code " << result << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = gpioComIF->addGpios(spiMuxGpios);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
sif::error << "initSpiCsDecoder: Failed to add mux bit gpios to gpioComIF" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|