8#include <nuttx/ioexpander/gpio.h>
12#include "dawn/debug.hxx"
13#include "dawn/porting/config.hxx"
23int gpi_open(
const char *path)
27 fd = open(path, O_RDWR);
28 DAWNINFO(
"GPI: open %s %d\n", path, fd);
31 DAWNERR(
"Failed to open GPI file %s (error %d)\n", path, fd);
60 ret = ioctl(fd, GPIOC_PINTYPE,
reinterpret_cast<unsigned long>(&pintype));
63 DAWNERR(
"GPI ioctl GPIOC_PINTYPE failed (error %d)\n", ret);
67 if (pintype == GPIO_OUTPUT_PIN)
69 DAWNERR(
"GPIO pin is output, expected input (pintype %d)\n", pintype);
80int gpi_read(
int fd,
bool *invalue)
84 ret = ioctl(fd, GPIOC_READ,
reinterpret_cast<unsigned long>(invalue));
87 DAWNERR(
"GPIOC_READ failed %d\n", -errno);
98bool gpi_notify(
int fd)
100 return ioctl(fd, GPIOC_REGISTER,
nullptr) < 0 ? false :
true;
107int gpo_open(
const char *path)
111 fd = open(path, O_RDWR);
112 DAWNINFO(
"GPO: open %s %d\n", path, fd);
115 DAWNERR(
"Failed to open GPO file %s (error %d)\n", path, fd);
125void gpo_close(
int fd)
144 ret = ioctl(fd, GPIOC_PINTYPE,
reinterpret_cast<unsigned long>(&pintype));
147 DAWNERR(
"GPO ioctl GPIOC_PINTYPE failed (error %d)\n", ret);
151 if (pintype != GPIO_OUTPUT_PIN)
153 DAWNERR(
"GPIO pin is input, expected output (pintype %d)\n", pintype);
164int gpo_read(
int fd,
bool *invalue)
168 ret = ioctl(fd, GPIOC_READ,
reinterpret_cast<unsigned long>(invalue));
171 DAWNERR(
"GPIOC_READ failed %d\n", -errno);
182int gpo_write(
int fd,
bool invalue)
186 ret = ioctl(fd, GPIOC_WRITE,
static_cast<unsigned long>(invalue));
189 DAWNERR(
"GPIOC_WRITE failed %d\n", -errno);