#ifndef SAM9G20_COMIF_COOKIES_I2C_COOKIE_H_ #define SAM9G20_COMIF_COOKIES_I2C_COOKIE_H_ #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 currently accessing the GPIO. * @param direction Specifies whether the GPIO should be used as in- or output. */ typedef struct GpioConfig { GpioConfig(std::string chipname_, int lineNum_, std::string consumer_, Gpio::Direction direction_) : chipname(chipname_), lineNum(lineNum_), consumer(consumer_), direction( directio_) { } std::string chipname; int lineNum; std::string consumer; Gpio::Direction direction; } 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(GpioMap newEntry); /** * @brief Get map with registered GPIOs. */ GpioMap getGpioMap() const; private: GpioMap gpioMap; GpioMapIter gpioMapIter; }; #endif