From a315fde8357d7ab17b6ef5c8d2612abf51bfa78e Mon Sep 17 00:00:00 2001 From: Ian Sutton Date: Thu, 27 Dec 2018 15:20:43 -0600 Subject: [PATCH] shift register works --- 166.sh | 13 +++++++ Makefile | 0 pins.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++----- pins.h | 7 ++-- seg.c | 4 +-- seg.h | 0 6 files changed, 114 insertions(+), 15 deletions(-) create mode 100755 166.sh mode change 100644 => 100755 Makefile mode change 100644 => 100755 pins.c mode change 100644 => 100755 pins.h mode change 100644 => 100755 seg.c mode change 100644 => 100755 seg.h diff --git a/166.sh b/166.sh new file mode 100755 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 + diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/pins.c b/pins.c old mode 100644 new mode 100755 index 1c60712..839ba98 --- a/pins.c +++ b/pins.c @@ -19,22 +19,109 @@ #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 new mode 100755 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 new mode 100755 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 new mode 100755 -- 2.41.0