eive-obsw/bsp_rpi/gpio/GPIORPi.cpp
2021-03-04 18:29:28 +01:00

37 lines
1.2 KiB
C++

#include "GPIORPi.h"
#include <FSFWConfig.h>
#include <fsfw/serviceinterface/ServiceInterface.h>
#include <linux/gpio/GpioCookie.h>
ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
std::string consumer, gpio::Direction direction, int initValue) {
if(cookie == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
GpiodRegular config;
/* Default chipname for Raspberry Pi. There is still gpiochip1 for expansion, but most users
will not need this */
config.chipname = "gpiochip0";
config.consumer = consumer;
config.direction = direction;
config.initValue = initValue;
/* Sanity check for the BCM pins before assigning it */
if(bcmPin > 27) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "createRpiGpioConfig: BCM pin " << bcmPin << " invalid!" << std::endl;
#else
sif::printError("createRpiGpioConfig: BCM pin %d invalid!\n", bcmPin);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return HasReturnvaluesIF::RETURN_FAILED;
}
config.lineNum = bcmPin;
cookie->addGpio(gpioId, config);
return HasReturnvaluesIF::RETURN_OK;
}