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) {
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
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-08-16 01:08:26 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
config->lineNum = bcmPin;
|
|
|
|
cookie->addGpio(gpioId, config);
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::OK;
|
2021-07-13 19:19:25 +02:00
|
|
|
}
|