-#ifndef MT_RFID_H
-#define MT_RFID_H
+#ifndef MT_GPIO_H
+#define MT_GPIO_H
#include <ev.h>
+#include <gpiod.h>
-// reader open parameters, see uFR manual
-#define UFR_READER_TYPE 1 // uFR type (1Mbps)
-#define UFR_PORT_INTERFACE 1 // serial; auto->ftdi->FAIL
-#define UFR_PORT_NAME "/dev/ttyUSB0" // reader device
-#define UFR_ASYNC_BAUD_RATE 1000000 // 1Mbps, otherwise UFR_COMMUNICATION_BREAK
+typedef struct mt_gpio_dev_t {
+ unsigned int chip;
+ unsigned int offset;
+ char key;
+} mt_gpio_dev_t;
-#define UFR_BEEP // define this to annoy people
-
-typedef struct ev_io_ufr {
- ev_io w; // fd watcher
- char uid_data[24]; // store uid here (uid is 10 bytes max)
- char *uid; // current position in uid_data
- int fd; // PORT_NAME file descriptor
-} ev_io_ufr;
-
-typedef struct mt_rfid_t {
- ev_io_ufr w; // reader watcher
- int fd; // print JSON output here
-} mt_rfid_t;
-
-// connect to the reader, add self to loop and make it write to fd
-// return 0 on success, negative number otherwise
-int mt_rfid_init(mt_rfid_t *self, struct ev_loop *loop, int fd);
-
-// disconnect from reader
-void mt_rfid_deinit(mt_rfid_t *self);
+#define GPIO_COUNT 20
+#ifndef GPIO_CONSUMER
+#define GPIO_CONSUMER "mtgpio"
+#endif
+#define GPIO_ACTIVE_LOW 1
+
+#define ADV_GPIO_PINS \
+{ \
+ {0, 27, 'A'}, \
+ {0, 29, 'B'}, \
+ {0, 25, 'C'}, \
+ {0, 30, 'D'}, \
+ {5, 31, 'E'}, \
+ {2, 30, 'F'}, \
+ {2, 31, 'G'}, \
+ {2, 21, 'H'}, \
+ {4, 2, 'I'}, \
+ {2, 20, 'J'}, \
+ {2, 23, 'K'}, \
+ {5, 11, 'L'}, \
+ {1, 2, 'M'}, \
+ {5, 9, 'N'}, \
+ {1, 3, 'O'}, \
+ {5, 16, 'P'}, \
+ {5, 7, 'Q'}, \
+ {1, 4, 'R'}, \
+ {1, 0, 'S'}, \
+ {5, 8, 'T'} \
+}
+
+const mt_gpio_dev_t pins[GPIO_COUNT] = ADV_GPIO_PINS;
+
+typedef struct ev_io_gpio {
+ ev_io w;
+ int fd;
+ char key;
+} ev_io_gpio;
+
+typedef struct mt_gpio_t {
+ ev_io_gpio w[GPIO_COUNT];
+ struct gpiod_chip *chip[GPIO_COUNT];
+} mt_gpio_t;
+
+int mt_gpio_init(mt_gpio_t *self, struct ev_loop *loop, int fd);
+
+void mt_gpio_deinit(mt_gpio_t *self);
#endif