fsfw-hal/linux/rpi/GpioRPi.cpp

38 lines
1.2 KiB
C++
Raw Normal View History

2021-03-23 16:05:01 +01:00
#include "GpioRPi.h"
#include "../../common/gpio/GpioCookie.h"
2021-03-23 16:05:01 +01:00
#include <FSFWConfig.h>
#include <fsfw/serviceinterface/ServiceInterface.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;
}
2021-04-11 12:29:54 +02:00
GpiodRegular* config = new GpiodRegular();
2021-03-23 16:05:01 +01:00
/* Default chipname for Raspberry Pi. There is still gpiochip1 for expansion, but most users
will not need this */
2021-04-11 12:29:54 +02:00
config->chipname = "gpiochip0";
2021-03-23 16:05:01 +01:00
2021-04-11 12:29:54 +02:00
config->consumer = consumer;
config->direction = direction;
config->initValue = initValue;
2021-03-23 16:05:01 +01:00
/* 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;
}
2021-04-11 12:29:54 +02:00
config->lineNum = bcmPin;
2021-03-23 16:05:01 +01:00
cookie->addGpio(gpioId, config);
return HasReturnvaluesIF::RETURN_OK;
}