diff --git a/linux/rpi/CMakeLists.txt b/linux/rpi/CMakeLists.txt index 8b13789..053583a 100644 --- a/linux/rpi/CMakeLists.txt +++ b/linux/rpi/CMakeLists.txt @@ -1 +1,3 @@ - +target_sources(${LIB_FSFW_HAL_NAME} PRIVATE + GpioRPi.cpp +) \ No newline at end of file diff --git a/linux/rpi/GpioRPi.cpp b/linux/rpi/GpioRPi.cpp new file mode 100644 index 0000000..daf16f2 --- /dev/null +++ b/linux/rpi/GpioRPi.cpp @@ -0,0 +1,37 @@ +#include "GpioRPi.h" +#include "../GpioCookie.h" +#include + +#include + + +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; +} diff --git a/linux/rpi/GpioRPi.h b/linux/rpi/GpioRPi.h new file mode 100644 index 0000000..a2e30da --- /dev/null +++ b/linux/rpi/GpioRPi.h @@ -0,0 +1,26 @@ +#ifndef BSP_RPI_GPIO_GPIORPI_H_ +#define BSP_RPI_GPIO_GPIORPI_H_ + +#include +#include "../gpioDefinitions.h" + +class GpioCookie; + +namespace gpio { + +/** + * Create a GpioConfig_t. This function does a sanity check on the BCM pin number and fails if the + * BCM pin is invalid. + * @param cookie Adds the configuration to this cookie directly + * @param gpioId ID which identifies the GPIO configuration + * @param bcmPin Raspberry Pi BCM pin + * @param consumer Information string + * @param direction GPIO direction + * @param initValue Intial value for output pins, 0 for low, 1 for high + * @return + */ +ReturnValue_t createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin, + std::string consumer, gpio::Direction direction, int initValue); +} + +#endif /* BSP_RPI_GPIO_GPIORPI_H_ */