fsfw/src/fsfw_hal/linux/rpi/GpioRPi.cpp

39 lines
1.3 KiB
C++
Raw Normal View History

2021-08-02 20:58:56 +02:00
#include "fsfw_hal/linux/rpi/GpioRPi.h"
2021-07-13 19:19:25 +02:00
#include <fsfw/serviceinterface/ServiceInterface.h>
2022-02-02 10:29:30 +01:00
#include "fsfw/FSFW.h"
#include "fsfw_hal/common/gpio/GpioCookie.h"
2021-07-13 19:19:25 +02:00
ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
2022-02-02 10:29:30 +01:00
std::string consumer, gpio::Direction direction,
2022-03-07 16:07:01 +01:00
gpio::Levels initValue) {
2022-02-02 10:29:30 +01:00
if (cookie == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
2021-07-13 19:19:25 +02:00
2022-02-02 10:29:30 +01:00
auto config = new GpiodRegularByChip();
/* Default chipname for Raspberry Pi. There is still gpiochip1 for expansion, but most users
will not need this */
config->chipname = "gpiochip0";
2021-07-13 19:19:25 +02:00
2022-02-02 10:29:30 +01:00
config->consumer = consumer;
config->direction = direction;
config->initValue = initValue;
2021-07-13 19:19:25 +02:00
2022-02-02 10:29:30 +01:00
/* Sanity check for the BCM pins before assigning it */
if (bcmPin > 27) {
2021-07-13 19:19:25 +02:00
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::error << "createRpiGpioConfig: BCM pin " << bcmPin << " invalid!" << std::endl;
2021-07-13 19:19:25 +02:00
#else
2022-02-02 10:29:30 +01:00
sif::printError("createRpiGpioConfig: BCM pin %d invalid!\n", bcmPin);
2021-07-13 19:19:25 +02:00
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
2022-02-02 10:29:30 +01:00
return HasReturnvaluesIF::RETURN_FAILED;
}
config->lineNum = bcmPin;
cookie->addGpio(gpioId, config);
return HasReturnvaluesIF::RETURN_OK;
2021-07-13 19:19:25 +02:00
}