2021-02-14 18:39:50 +01:00
|
|
|
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
|
|
|
|
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
|
2021-01-23 17:22:40 +01:00
|
|
|
|
2021-02-14 12:35:08 +01:00
|
|
|
#include <linux/gpio/GpioIF.h>
|
2021-01-23 17:22:40 +01:00
|
|
|
#include <fsfwconfig/returnvalues/classIds.h>
|
2021-02-01 11:17:20 +01:00
|
|
|
#include <fsfw/objectmanager/SystemObject.h>
|
2021-01-23 17:22:40 +01:00
|
|
|
|
2021-02-14 18:39:50 +01:00
|
|
|
class GpioCookie;
|
2021-02-14 18:45:31 +01:00
|
|
|
|
2021-01-23 17:22:40 +01:00
|
|
|
/**
|
|
|
|
* @brief This class implements the GpioIF for a linux based system. The
|
|
|
|
* implementation is based on the libgpiod lib which requires linux 4.8
|
|
|
|
* or higher.
|
|
|
|
* @note The Petalinux SDK from Xilinx supports libgpiod since Petalinux
|
|
|
|
* 2019.1.
|
|
|
|
*/
|
2021-02-01 11:17:20 +01:00
|
|
|
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
2021-01-23 17:22:40 +01:00
|
|
|
public:
|
|
|
|
|
2021-02-01 11:17:20 +01:00
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::LINUX_LIBGPIO_IF;
|
|
|
|
|
2021-02-12 21:23:35 +01:00
|
|
|
static const ReturnValue_t DRIVE_GPIO_FAILURE = MAKE_RETURN_CODE(0x2);
|
2021-01-23 17:22:40 +01:00
|
|
|
|
|
|
|
LinuxLibgpioIF(object_id_t objectId);
|
|
|
|
virtual ~LinuxLibgpioIF();
|
|
|
|
|
2021-02-14 18:39:50 +01:00
|
|
|
ReturnValue_t initialize(GpioCookie* gpioCookie) override;
|
2021-01-23 17:22:40 +01:00
|
|
|
ReturnValue_t pullHigh(gpioId_t gpioId) override;
|
|
|
|
ReturnValue_t pullLow(gpioId_t gpioId) override;
|
2021-02-12 21:23:35 +01:00
|
|
|
ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override;
|
2021-01-23 17:22:40 +01:00
|
|
|
|
|
|
|
private:
|
2021-02-14 18:21:59 +01:00
|
|
|
/* Holds the information and configuration of all used GPIOs */
|
2021-01-23 17:22:40 +01:00
|
|
|
GpioMap gpioMap;
|
2021-02-14 18:52:40 +01:00
|
|
|
GpioMapIter gpioMapIter;
|
2021-01-23 17:22:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This functions drives line of a GPIO specified by the GPIO ID.
|
|
|
|
*
|
|
|
|
* @param gpioId The GPIO ID of the GPIO to drive.
|
|
|
|
* @param logiclevel The logic level to set. O or 1.
|
|
|
|
*/
|
|
|
|
ReturnValue_t driveGpio(gpioId_t gpioId,
|
|
|
|
unsigned int logiclevel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function checks if GPIOs are already registered and whether
|
|
|
|
* there exists a conflict in the GPIO configuration. E.g. the
|
|
|
|
* direction.
|
|
|
|
*
|
|
|
|
* @param mapToAdd The GPIOs which shall be added to the gpioMap.
|
|
|
|
*
|
|
|
|
* @return RETURN_OK if successful, otherwise RETURN_FAILED
|
|
|
|
*/
|
2021-02-14 18:21:59 +01:00
|
|
|
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
2021-02-12 21:23:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
|
|
|
*/
|
2021-02-14 18:21:59 +01:00
|
|
|
ReturnValue_t configureGpios(GpioMap& mapToAdd);
|
2021-01-23 17:22:40 +01:00
|
|
|
};
|
|
|
|
|
2021-02-14 18:39:50 +01:00
|
|
|
#endif /* LINUX_GPIO_LINUXLIBGPIOIF_H_ */
|