--- /dev/null
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include <sys/types.h>
+#include <sys/gpio.h>
+#include <sys/ioctl.h>
+
+#include "pins.h"
+
+#define UP(N) set_pin(N, 1)
+#define DOWN(N) set_pin(N, 0)
+
+#define HI(N) set(N, 1)
+#define LO(N) set(N, 0)
+
+int main(int argc, char *argv[]) {
+ pins_init();
+ config_pins();
+ pincnt();
+
+ sleep(1);
+
+ pcfg(1, 6, -1, INPUT | PULLDOWN, "ser");
+ pcfg(1, 13, 0, OUTPUT, "clk");
+ pcfg(1, 15, 0, OUTPUT, "shld");
+ pcfg(0, 27, 0, OUTPUT, "clr");
+
+ for(;;) {
+ HI("shld");
+ usleep(1);
+ LO("shld");
+ usleep(1);
+ }
+}
--- /dev/null
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <time.h>
+
+#include <sys/types.h>
+#include <sys/gpio.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+
+#include "seg.h"
+
+#define INPUT 1 << 0
+#define OUTPUT 1 << 1
+#define PULLUP 1 << 2
+#define PULLDOWN 1 << 3
+
+struct pin2dev {
+ int pin;
+ int dev;
+ char *name;
+};
+
+int pin_cnt;
+struct pin2dev *pinmap;
+volatile int g0, g1, g2;
+
+int num2fd(int i) {
+ if (i == 0)
+ return g0;
+ else if (i == 1)
+ return g1;
+ else if (i == 2)
+ return g2;
+
+ return 0;
+}
+
+struct pin2dev *pin(char *name) {
+ for(int i = 0; i < pin_cnt; i++) {
+ if (! strncmp(name, pinmap[i].name, GPIOPINMAXNAME))
+ return &pinmap[i];
+ }
+
+ return NULL;
+}
+
+void set(char *name, int val) {
+ struct pin2dev *p;
+ struct gpio_pin_op op;
+ int fd;
+
+ p = pin(name);
+ op.gp_pin = p->pin;
+ op.gp_value = val;
+ fd = num2fd(p->dev);
+
+ //printf("given name: %s\nderived name: %s\nderived pin: %d\nval: %d\nfd: %d\nreal fd: %d\n", name, p->name,
+ // p->pin, op.gp_value, fd, g1);
+
+// printf("g0: %d g1: %d g2: %d\n", g0, g1, g2);
+
+ ioctl(fd, GPIOPINWRITE, &op);
+
+// printf("old: %d new: %d\n", op.gp_value, val);
+}
+
+void pins_init() {
+ pinmap = calloc(100, sizeof(struct pin2dev));
+ pin_cnt = 0;
+}
+
+void pcfg(int devno, int pin, int val, uint8_t mode, char *name) {
+ char *fill = calloc(1, 255);
+ char *pill = calloc(1, 255);
+ char *vl = calloc(1, 255);
+ char *nm = calloc(1, 255);
+ char *md = calloc(1, 255);
+
+ usleep(1000 * 500);
+ strlcpy(nm, name, GPIOPINMAXNAME);
+
+ if (mode & OUTPUT)
+ strlcpy(md, "out", 255);
+ else if (mode & INPUT) {
+ if (mode & PULLUP)
+ strlcpy(md, "in,pu", 255);
+ else if (mode & PULLDOWN)
+ strlcpy(md, "in,pd", 255);
+ else
+ strlcpy(md, "in", 255);
+ }
+
+ pinmap[pin_cnt].name = calloc(1, GPIOPINMAXNAME);
+ strlcpy(pinmap[pin_cnt].name, name, GPIOPINMAXNAME);
+ strlcpy(nm, name, GPIOPINMAXNAME);
+ pinmap[pin_cnt].pin = pin;
+ pinmap[pin_cnt].dev = devno;
+ pin_cnt++;
+
+ sprintf(fill, "gpioctl gpio%d %d set %s", devno, pin, nm);
+ sprintf(pill, "gpioctl gpio%d %s set %s", devno, nm, md);
+ sprintf(vl, "gpioctl gpio%d %d %d", devno, pin, val);
+ printf("%s\n%s\n", fill, pill);
+ system(fill);
+ system(pill);
+ if (val < 0)
+ return;
+ printf("%s\n", vl);
+ system(vl);
+}
#include <unistd.h>
#include <string.h>
#include <stdio.h>
+#include <time.h>
#include <sys/types.h>
#include <sys/gpio.h>
#include <sys/ioctl.h>
+#include <sys/time.h>
#define UP(N) set_pin(N, 1)
#define DOWN(N) set_pin(N, 0)
#define DISP_7 0x8e
#define DISP_8 0x8f
-
volatile int g0, g1, g2;
+const uint8_t d2seg[] = {
+ 0x3F
+ , 0x06
+ , 0x5B
+ , 0x4F
+ , 0x66
+ , 0x6D
+ , 0x7D
+ , 0x07
+ , 0x7F
+ , 0x6F
+ , 0x77
+ , 0x7C
+ , 0x39
+ , 0x5E
+ , 0x79
+ , 0x71
+};
+
+uint8_t dig(uint8_t d) {
+ return d2seg[d];
+}
+
+/*void timer(long usec) {
+ sigset_t sigs;
+ int s;
+
+ sigemptyset(&sigs);
+ sigaddset(&sigs, SIGALRM);
+
+ ualarm(usec, 0);
+ sigwait(&sigs, &s);
+}*/
+
+/*void timer(long usec) {
+ struct timespec t;
+ t.tv_nsec = usec;
+ t.tv_sec = 0;
+
+ nanosleep(&t, NULL);
+}*/
+
void kd() {
+
+ asm("movs r0, #0");
+
+ for(int i = 0; i < 10; i++) {
+ asm("movs r0, #10\n\t"
+ "1: subs r0, r0, #1\n\t"
+ "bne 1b");
+ }
+
+/* volatile int t = 0;
+
+ while(t != 80000)
+ t++; */
/* struct timespec ts, rem;
ts.tv_sec = 0;
rem.tv_sec = 0;
rem.tv_nsec = 0;
- nanosleep(&ts, &rem);
- */
+ nanosleep(&ts, &rem); */
}
int name2dev(char *s) {
return g2;
else if (! strncmp(s, "clk", GPIOPINMAXNAME))
return g2;
+ else if (! strncmp(s, "ser2", GPIOPINMAXNAME))
+ return g1;
+ else if (! strncmp(s, "clk-sr", GPIOPINMAXNAME))
+ return g1;
+ else if (! strncmp(s, "shld", GPIOPINMAXNAME))
+ return g1;
+ else if (! strncmp(s, "clr", GPIOPINMAXNAME))
+ return g0;
+
+
else {
printf("no gpio pin w/ name %s, exiting..\n", s);
exit(2);
}
}
-