2021-01-28 14:55:21 +01:00
|
|
|
#ifndef SAM9G20_COMIF_COOKIES_GPIO_COOKIE_H_
|
|
|
|
#define SAM9G20_COMIF_COOKIES_GPIO_COOKIE_H_
|
2021-01-23 17:22:40 +01:00
|
|
|
|
2021-02-14 12:35:08 +01:00
|
|
|
#include "GpioIF.h"
|
2021-01-23 17:22:40 +01:00
|
|
|
#include <fsfw/devicehandlers/CookieIF.h>
|
2021-01-28 14:55:21 +01:00
|
|
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
2021-01-23 17:22:40 +01:00
|
|
|
#include <string>
|
2021-02-01 11:17:20 +01:00
|
|
|
#include <unordered_map>
|
2021-01-23 17:22:40 +01:00
|
|
|
|
2021-02-14 12:35:08 +01:00
|
|
|
namespace gpio {
|
|
|
|
enum Direction {
|
|
|
|
IN = 0,
|
|
|
|
OUT = 1
|
|
|
|
};
|
2021-01-23 17:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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.
|
2021-02-12 21:23:35 +01:00
|
|
|
* @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.
|
2021-01-23 17:22:40 +01:00
|
|
|
*/
|
|
|
|
typedef struct GpioConfig {
|
2021-02-14 12:35:08 +01:00
|
|
|
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;
|
2021-01-23 17:22:40 +01:00
|
|
|
} GpioConfig_t;
|
|
|
|
using GpioMap = std::unordered_map<gpioId_t, GpioConfig_t>;
|
|
|
|
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:
|
|
|
|
|
2021-02-14 12:35:08 +01:00
|
|
|
GpioCookie();
|
2021-01-23 17:22:40 +01:00
|
|
|
|
2021-02-14 12:35:08 +01:00
|
|
|
virtual ~GpioCookie();
|
2021-01-23 17:22:40 +01:00
|
|
|
|
2021-02-14 12:35:08 +01:00
|
|
|
void addGpio(gpioId_t gpioId, GpioConfig_t gpioConfig);
|
|
|
|
/**
|
|
|
|
* @brief Get map with registered GPIOs.
|
|
|
|
*/
|
2021-02-14 17:44:16 +01:00
|
|
|
GpioMap& getGpioMap() const;
|
2021-01-23 17:22:40 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2021-02-14 12:35:08 +01:00
|
|
|
GpioMap gpioMap;
|
|
|
|
GpioMapIter gpioMapIter;
|
2021-01-23 17:22:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|