small fixes and refactoring
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
#ifndef LINUX_GPIO_GPIODEFINITIONS_H_
|
||||
#define LINUX_GPIO_GPIODEFINITIONS_H_
|
||||
#ifndef COMMON_GPIO_GPIODEFINITIONS_H_
|
||||
#define COMMON_GPIO_GPIODEFINITIONS_H_
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
using gpioId_t = uint16_t;
|
||||
|
||||
@ -25,11 +26,14 @@ enum GpioOperation {
|
||||
|
||||
enum GpioTypes {
|
||||
NONE,
|
||||
GPIOD_REGULAR,
|
||||
GPIO_REGULAR,
|
||||
CALLBACK
|
||||
};
|
||||
|
||||
static constexpr gpioId_t NO_GPIO = -1;
|
||||
|
||||
using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,12 +70,12 @@ public:
|
||||
|
||||
class GpiodRegular: public GpioBase {
|
||||
public:
|
||||
GpiodRegular(): GpioBase(gpio::GpioTypes::GPIOD_REGULAR, std::string(),
|
||||
GpiodRegular(): GpioBase(gpio::GpioTypes::GPIO_REGULAR, std::string(),
|
||||
gpio::Direction::IN, 0) {};
|
||||
|
||||
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_,
|
||||
gpio::Direction direction_, int initValue_):
|
||||
GpioBase(gpio::GpioTypes::GPIOD_REGULAR, consumer_, direction_, initValue_),
|
||||
GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, direction_, initValue_),
|
||||
chipname(chipname_), lineNum(lineNum_) {}
|
||||
std::string chipname;
|
||||
int lineNum = 0;
|
||||
@ -81,18 +85,18 @@ public:
|
||||
class GpioCallback: public GpioBase {
|
||||
public:
|
||||
GpioCallback(std::string consumer, gpio::Direction direction_, int initValue_,
|
||||
void (* callback) (gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args),
|
||||
void* callbackArgs):
|
||||
gpio::gpio_cb_t callback, void* callbackArgs):
|
||||
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
|
||||
callback(callback), callbackArgs(callbackArgs) {}
|
||||
|
||||
void (* callback) (gpioId_t gpioId, gpio::GpioOperation gpioOp,
|
||||
int value, void* args) = nullptr;
|
||||
gpio::gpio_cb_t callback = nullptr;
|
||||
void* callbackArgs = nullptr;
|
||||
};
|
||||
|
||||
|
||||
using GpioMap = std::unordered_map<gpioId_t, GpioBase*>;
|
||||
using GpioMap = std::map<gpioId_t, GpioBase*>;
|
||||
using GpioUnorderedMap = std::unordered_map<gpioId_t, GpioBase*>;
|
||||
using GpioMapIter = GpioMap::iterator;
|
||||
using GpioUnorderedMapIter = GpioUnorderedMap::iterator;
|
||||
|
||||
#endif /* LINUX_GPIO_GPIODEFINITIONS_H_ */
|
||||
|
Reference in New Issue
Block a user