36 #include <sys/types.h> 43 #include <px4_platform_common/posix.h> 45 #define PIN_INDEX_BUFFER_MAX (16) 46 #define PIN_DIRECTION_BUFFER_MAX (30 + PIN_INDEX_BUFFER_MAX) 47 #define PIN_VALUE_BUFFER_MAX (26 + PIN_INDEX_BUFFER_MAX) 80 ret = stat(valuePath, &statbuf);
84 fd = open(
"/sys/class/gpio/export", O_WRONLY);
88 PX4_ERR(
"export %u: open: %s (%d)",
_pin, strerror(err), err);
93 ret =
write(fd, pinIndex, bytes_to_write);
97 PX4_ERR(
"export %u: write: %s (%d)",
_pin, strerror(err), err);
100 }
else if (ret != bytes_to_write) {
101 PX4_ERR(
"export %u: write incomplete %d != %d",
_pin, ret, bytes_to_write);
106 _fd = open(valuePath, O_RDWR);
111 PX4_ERR(
"export %u: open: %s (%d)",
_pin, strerror(err), err);
138 fd = open(
"/sys/class/gpio/unexport", O_WRONLY);
142 PX4_ERR(
"unexport %u: open: %s (%d)",
_pin, strerror(err), err);
147 ret =
write(fd, pinIndex, bytes_to_write);
151 PX4_ERR(
"unexport %u: write: %s (%d)",
_pin, strerror(err), err);
154 }
else if (ret != bytes_to_write) {
155 PX4_ERR(
"unexport %u: write incomplete %d != %d",
_pin, ret, bytes_to_write);
174 fd = open(path, O_WRONLY);
178 PX4_ERR(
"dir %u: open: %s (%d)",
_pin, strerror(err), err);
183 ret =
write(fd,
"in", 2);
186 ret =
write(fd,
"out", 3);
191 PX4_ERR(
"dir %u: write: %s (%d)",
_pin, strerror(err), err);
212 PX4_ERR(
"readValue %u: read: %s (%d)",
_pin, strerror(err), err);
216 ret = strtol(buf,
nullptr, 10);
230 int buflen = snprintf(buf,
sizeof(buf),
"%u", (
unsigned int)value);
236 PX4_ERR(
"writeValue %u: write: %s (%d)",
_pin, strerror(err), err);
int setDirection(LinuxGPIO::Direction dir)
LinuxGPIO(unsigned int pin)
#define PIN_INDEX_BUFFER_MAX
Linux sysfs GPIO Interface.
static void read(bootloader_app_shared_t *pshared)
#define PIN_VALUE_BUFFER_MAX
int writeValue(LinuxGPIO::Value value)
static void write(bootloader_app_shared_t *pshared)
#define PIN_DIRECTION_BUFFER_MAX