#ifndef SAM9G20_COMIF_COOKIES_GPIO_COOKIE_H_ #define SAM9G20_COMIF_COOKIES_GPIO_COOKIE_H_ #include "GpioIF.h" #include #include #include #include namespace gpio { enum Direction { IN = 0, OUT = 1 }; } /** * @brief Struct containing information about the GPIO to use. This is * required by the libgpiod to access and drive a GPIO. * @param chipname String of the chipname specifying the group which contains * the GPIO to access. E.g. gpiochip0. To detect names of * GPIO groups run gpiodetect on the linux command line. * @param lineNum The offset of the GPIO within the GPIO group. * @param consumer Name of the consumer. Simply a description of the GPIO configuration. * @param direction Specifies whether the GPIO should be used as in- or output. * @param initValue Defines the initial state of the GPIO when configured as output. Only required * for output GPIOs. * @param lineHandle The handle returned by gpiod_chip_get_line will be later written to this * pointer. */ typedef struct GpioConfig { GpioConfig(std::string chipname_, int lineNum_, std::string consumer_, gpio::Direction direction_, int initValue_) : chipname(chipname_), lineNum(lineNum_), consumer(consumer_), direction(direction_), initValue(initValue_) { } std::string chipname; int lineNum; std::string consumer; gpio::Direction direction; int initValue; struct gpiod_line* lineHandle = nullptr; } GpioConfig_t; using GpioMap = std::unordered_map; using GpioMapIter = GpioMap::iterator; /** * @brief Cookie for the GpioIF. Allows the GpioIF to determine which * GPIOs to initialize and whether they should be configured as in- or * output. * @details One GpioCookie can hold multiple GPIO configurations. To add a new * GPIO configuration to a GpioCookie use the GpioCookie::addGpio * function. * * @author J. Meier */ class GpioCookie: public CookieIF { public: GpioCookie(); virtual ~GpioCookie(); void addGpio(gpioId_t gpioId, GpioConfig_t gpioConfig); /** * @brief Get map with registered GPIOs. */ GpioMap& getGpioMap() const; private: GpioMap gpioMap; GpioMapIter gpioMapIter; }; #endif