68#ifndef __LINUXGPIO_HXX
69#define __LINUXGPIO_HXX
91 static constexpr const uint32_t
PIN = PIN_NUM;
96 FILE *fp = fopen(
"/sys/class/gpio/export",
"w");
97 fprintf(fp,
"%d\n",
PIN);
107 snprintf(dirname,
sizeof(dirname),
"/sys/class/gpio/gpio%d/direction",
PIN);
109 while ((dfd = open(dirname,O_WRONLY)) < 0) {
112 write(dfd,
"out\n",4);
119 snprintf(dirname,
sizeof(dirname),
"/sys/class/gpio/gpio%d/direction",
PIN);
121 while ((dfd = open(dirname,O_WRONLY)) < 0) {
131 snprintf(valname,
sizeof(valname),
"/sys/class/gpio/gpio%d/value",
PIN);
132 int vfd = open(valname,O_WRONLY);
140 snprintf(valname,
sizeof(valname),
"/sys/class/gpio/gpio%d/value",
PIN);
141 int vfd = open(valname,O_WRONLY);
149 snprintf(valname,
sizeof(valname),
"/sys/class/gpio/gpio%d/value",
PIN);
150 int vfd = open(valname,O_RDONLY);
156 static void set(
bool value)
178 snprintf(dirname,
sizeof(dirname),
"/sys/class/gpio/gpio%d/direction",
PIN);
179 int dfd = open(dirname,O_RDONLY);
188template <
class Base,
bool SAFE_VALUE,
bool INVERT = false>
197 Base::set(SAFE_VALUE);
202 Base::set(SAFE_VALUE);
206 static void set(
bool value)
258template <
class Base,
bool ACTIVE_HIGH = true>
324#define GPIO_PIN(NAME, BaseClass, NUM) \
325 typedef BaseClass<LinuxGpio<NUM>> NAME##_Pin
Creates an implementation of an os-independent Gpio object from a hardware-specific static Gpio struc...
OS-independent abstraction for GPIO.
Defines a GPIO output pin.
static void toggle()
Toggles output pin value.
static void set(bool value)
Set output pin level.
static constexpr const uint32_t PIN
Number of the pin.
static void export_pin()
Export pin.
static void set_on()
Sets output to HIGH.
static void set_off()
Sets output to LOW.
static void set_input()
Sets pin to input.
static void set_output()
Sets pin to output.
Parametric GPIO output class.
static constexpr const Gpio * instance()
static void hw_init()
Initializes the hardware pin.
static void set(bool value)
Sets the output pinm.
static void hw_set_to_safe()
Sets the hardware pin to a safe value.
Defines a GPIO output pin, initialized to be an output pin with high level.
Defines a GPIO output pin, initialized to be an output pin with high level.
Defines a GPIO output pin, initialized to be an output pin with low level.
Defines a GPIO output pin, initialized to be an output pin with low level.