shift register works
authorIan Sutton <ian.sutton@ibm.com>
Thu, 27 Dec 2018 21:20:43 +0000 (15:20 -0600)
committerIan Sutton <ian.sutton@ibm.com>
Thu, 27 Dec 2018 21:20:43 +0000 (15:20 -0600)
166.sh [new file with mode: 0755]
Makefile [changed mode: 0644->0755]
pins.c [changed mode: 0644->0755]
pins.h [changed mode: 0644->0755]
seg.c [changed mode: 0644->0755]
seg.h [changed mode: 0644->0755]

diff --git a/166.sh b/166.sh
new file mode 100755 (executable)
index 0000000..17a3169
--- /dev/null
+++ b/166.sh
@@ -0,0 +1,13 @@
+#!/bin/ksh
+
+gpioctl gpio1 6 set ser
+gpioctl gpio1 ser set in pd
+gpioctl gpio1 2 set clkinh
+gpioctl gpio1 clkinh set out
+gpioctl gpio1 13 set clk
+gpioctl gpio1 clk set out
+gpioctl gpio1 15 set shld
+gpioctl gpio1 shld set out
+gpioctl gpio0 27 set clr
+gpioctl gpio0 clr set out
+
old mode 100644 (file)
new mode 100755 (executable)
diff --git a/pins.c b/pins.c
old mode 100644 (file)
new mode 100755 (executable)
index 1c60712..839ba98
--- a/pins.c
+++ b/pins.c
 #define HI(N)  set(N, 1)
 #define LO(N)  set(N, 0)
 
+void kd2() {
+       usleep(10000);
+}
+
+void kdh() {
+    usleep(5000);
+}
+
+void kd1() {
+       usleep(1);
+}
+
+void test_pins() {
+       for(;;) {
+               HI("clk");
+               HI("clkinh");
+               LO("shld");
+               HI("clr");
+               kd1();
+               LO("clk");
+               LO("clkinh");
+               LO("shld");
+               LO("clr");
+               kd1();
+       }
+}
+
+/* call when clk is hi */
+void tick(int n) {
+       int i = 0;
+
+       for(; i < n; i++) {
+               LO("clk");
+               kd2();
+               HI("clk");
+               kd2();
+       }
+}
+
+void clear() {
+       HI("clk");
+       LO("clkinh");
+       kdh();
+       LO("clr");
+       kdh();
+       LO("clk");
+       kdh();
+       HI("clr");
+       kdh();
+       HI("clk");
+       kd2();
+}
+
 int main(int argc, char *argv[]) {
+
+       signal(SIGINT, inth);
+
        pins_init();
-       config_pins();
+//     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");
+       pcfg(1, 2,   0, OUTPUT, "clkinh");
 
-       for(;;) {
-           HI("shld");
-           usleep(1);
-           LO("shld");
-           usleep(1);
-       }
+       LO("clk");
+       HI("clkinh");
+       HI("clr");
+       LO("shld");
+
+       sleep(1);
+for(;;){
+       LO("clk");
+       HI("clkinh");
+       HI("clr");
+       LO("shld");
+       kd2();
+       kd2();
+       clear();
+
+       tick(4);
+       LO("clk");
+       LO("shld");
+       kd2();
+       HI("clk");
+       kdh();
+       HI("clkinh");
+       kdh();
+       LO("clk");
+
+       LO("shld");
+       kdh();
+       kdh();
+       HI("clk");
+       kd2();
+       tick(2);
+       LO("clk");
+       LO("clkinh");
+       kd2();
+       HI("clk");
+       kd2();
+       tick(10);
+}
 }
diff --git a/pins.h b/pins.h
old mode 100644 (file)
new mode 100755 (executable)
index fe53ef5..cb30477
--- a/pins.h
+++ b/pins.h
@@ -54,12 +54,12 @@ void set(char *name, int val) {
        int fd;
 
        p = pin(name);
-       op.gp_pin = p->pin;
+       strlcpy(op.gp_name, name, GPIOPINMAXNAME);
        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("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);
 
@@ -80,7 +80,6 @@ void pcfg(int devno, int pin, int val, uint8_t mode, char *name) {
        char *nm   = calloc(1, 255);
        char *md   = calloc(1, 255);
 
-       usleep(1000 * 500);
        strlcpy(nm, name, GPIOPINMAXNAME);
 
        if (mode & OUTPUT)
diff --git a/seg.c b/seg.c
old mode 100644 (file)
new mode 100755 (executable)
index 7eef5f8..2f6867f
--- a/seg.c
+++ b/seg.c
@@ -52,9 +52,9 @@ int main(int argc, char *argv[]) {
 
 for(;;) {
        UP("clk");
-       kd();
+       usleep(1);
        DOWN("clk");
-       kd();
+       usleep(1);
 }
 
 for(;;) {
diff --git a/seg.h b/seg.h
old mode 100644 (file)
new mode 100755 (executable)