--- /dev/null
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <sys/types.h>
+#include <sys/gpio.h>
+#include <sys/ioctl.h>
+
+#define UP(N) set_pin(N, 1)
+#define DOWN(N) set_pin(N, 0)
+
+#define DEL 100000
+
+#define MEM_WR 0x40
+#define ADDR_AUTO 0x44
+
+#define DISP_ON 0x8f
+#define DISP_OFF 0x80
+#define DISP_1 0x88
+#define DISP_2 0x89
+#define DISP_3 0x8a
+#define DISP_4 0x8b
+#define DISP_5 0x8c
+#define DISP_6 0x8d
+#define DISP_7 0x8e
+#define DISP_8 0x8f
+
+
+volatile int g0, g1, g2;
+
+void kd() {
+/* struct timespec ts, rem;
+
+ ts.tv_sec = 0;
+ ts.tv_nsec = DEL;
+
+ rem.tv_sec = 0;
+ rem.tv_nsec = 0;
+
+ nanosleep(&ts, &rem);
+ */
+}
+
+int name2dev(char *s) {
+ if (! strncmp(s, "ser", GPIOPINMAXNAME))
+ return g1;
+ else if (! strncmp(s, "oe", GPIOPINMAXNAME))
+ return g0;
+ else if (! strncmp(s, "rclk", GPIOPINMAXNAME))
+ return g1;
+ else if (! strncmp(s, "srclk", GPIOPINMAXNAME))
+ return g2;
+ else if (! strncmp(s, "srclr", GPIOPINMAXNAME))
+ return g1;
+ else if (! strncmp(s, "dio", GPIOPINMAXNAME))
+ return g2;
+ else if (! strncmp(s, "clk", GPIOPINMAXNAME))
+ return g2;
+ else {
+ printf("no gpio pin w/ name %s, exiting..\n", s);
+ exit(2);
+ }
+}
+
+void inth(int f) {
+ close(g0);
+ close(g1);
+ close(g2);
+
+ exit(9);
+}
+
+void ack_wait() {
+ struct gpio_pin_set p;
+ struct gpio_pin_op o;
+ int read = 0;
+
+ p.gp_pin = 6;
+ o.gp_pin = 6;
+ p.gp_flags = GPIO_PIN_INPUT | GPIO_PIN_PULLDOWN;
+ o.gp_value = 0;
+
+ ioctl(name2dev("dio"), GPIOPINWRITE, &o);
+ ioctl(name2dev("dio"), GPIOPINSET, &p);
+
+ while(!read) {
+ printf("waiting..\n");
+ ioctl(name2dev("dio"), GPIOPINREAD, &o);
+ read = o.gp_value;
+ }
+
+ p.gp_flags = GPIO_PIN_OUTPUT;
+ ioctl(name2dev("dio"), GPIOPINREAD, &o);
+}
+
+void set_pin(char *name, int state) {
+ struct gpio_pin_op op;
+
+ strlcpy(op.gp_name, name, GPIOPINMAXNAME);
+ op.gp_value = state;
+
+ ioctl(name2dev(name), GPIOPINWRITE, &op);
+}
+
+void config_pins() {
+ struct gpio_pin_set *ser, *oe, *rclk, *srclk, *srclr, *dio, *clk;
+
+ ser = calloc(1, sizeof(struct gpio_pin_set));
+ oe = calloc(1, sizeof(struct gpio_pin_set));
+ rclk = calloc(1, sizeof(struct gpio_pin_set));
+ srclk = calloc(1, sizeof(struct gpio_pin_set));
+ srclr = calloc(1, sizeof(struct gpio_pin_set));
+ dio = calloc(1, sizeof(struct gpio_pin_set));
+ clk = calloc(1, sizeof(struct gpio_pin_set));
+
+ ser->gp_pin = 12;
+ ser->gp_flags = GPIO_PIN_OUTPUT;
+ strlcpy(ser->gp_name2, "ser", GPIOPINMAXNAME);
+
+ oe->gp_pin = 26;
+ oe->gp_flags = GPIO_PIN_OUTPUT;
+ strlcpy(oe->gp_name2, "oe", GPIOPINMAXNAME);
+
+ rclk->gp_pin = 14;
+ rclk->gp_flags = GPIO_PIN_OUTPUT;
+ strlcpy(rclk->gp_name2, "rclk", GPIOPINMAXNAME);
+
+ srclk->gp_pin = 1;
+ srclk->gp_flags = GPIO_PIN_OUTPUT;
+ strlcpy(srclk->gp_name2, "srclk", GPIOPINMAXNAME);
+
+ srclr->gp_pin = 31;
+ srclr->gp_flags = GPIO_PIN_OUTPUT;
+ strlcpy(srclr->gp_name2, "srclr", GPIOPINMAXNAME);
+
+ dio->gp_pin = 8;
+ dio->gp_flags = GPIO_PIN_OUTPUT;
+ strlcpy(dio->gp_name2, "dio", GPIOPINMAXNAME);
+
+ clk->gp_pin = 6;
+ clk->gp_flags = GPIO_PIN_OUTPUT;
+ strlcpy(clk->gp_name2, "clk", GPIOPINMAXNAME);
+
+ ioctl(name2dev("ser"), GPIOPINSET, ser);
+ ioctl(name2dev("oe"), GPIOPINSET, oe);
+ ioctl(name2dev("rclk"), GPIOPINSET, rclk);
+ ioctl(name2dev("srclk"), GPIOPINSET, srclk);
+ ioctl(name2dev("srclr"), GPIOPINSET, srclr);
+ ioctl(name2dev("dio"), GPIOPINSET, dio);
+ ioctl(name2dev("clk"), GPIOPINSET, clk);
+
+ free(ser);
+ free(oe);
+ free(rclk);
+ free(srclk);
+ free(srclr);
+ free(dio);
+ free(clk);
+}
+
+void pincnt() {
+ g0 = open("/dev/gpio0", O_RDWR);
+ g1 = open("/dev/gpio1", O_RDWR);
+ g2 = open("/dev/gpio2", O_RDWR);
+
+ struct gpio_info *inf0, *inf1, *inf2;
+ inf0 = calloc(1, sizeof(struct gpio_info));
+ inf1 = calloc(1, sizeof(struct gpio_info));
+ inf2 = calloc(1, sizeof(struct gpio_info));
+
+ ioctl(g0, GPIOINFO, inf0);
+ ioctl(g1, GPIOINFO, inf1);
+ ioctl(g2, GPIOINFO, inf2);
+
+ printf("gpio0: %d\ngpio1: %d\ngpio2: %d\n", inf0->gpio_npins, inf1->gpio_npins, inf2->gpio_npins);
+
+ free(inf0);
+ free(inf1);
+ free(inf2);
+}
+
+void start() {
+ DOWN("dio");
+ kd();
+}
+
+void stop() {
+ DOWN("dio");
+ kd();
+ UP("clk");
+ kd();
+ UP("dio");
+ kd();
+}
+
+void byte(uint8_t b) {
+ for(int i = 0; i < 8; i++) {
+ DOWN("clk");
+ kd();
+ (b & 0x1) ? UP("dio") : DOWN("dio");
+ kd();
+ UP("clk");
+ kd();
+ b >>= 1;
+ }
+
+ DOWN("clk");
+ UP("dio");
+ kd();
+ UP("clk");
+ kd();
+ DOWN("dio");
+ kd();
+ DOWN("clk");
+ kd();
+}
+
+void blink(int c, int ms) {
+ for(int i = 0; i < c; i++) {
+ byte(DISP_ON);
+ kd();
+ byte(DISP_OFF);
+ kd();
+ }
+}
+
+