X-Git-Url: https://uglyman.kremlin.cc/gitweb/gitweb.cgi?p=bort-panel.git;a=blobdiff_plain;f=pins.c;h=cd49a5c9482e91c3e372659401b4238e0aafbbaa;hp=1c60712a948bc9352a2b5e63d56de17f5ca27af5;hb=HEAD;hpb=3bacb654b3471617c2e2ef7c338fef0b497de7fa diff --git a/pins.c b/pins.c index 1c60712..cd49a5c 100644 --- a/pins.c +++ b/pins.c @@ -19,22 +19,201 @@ #define HI(N) set(N, 1) #define LO(N) set(N, 0) +void test_7seg(); + +void kd2() { + usleep(5000); +} + +void kdh() { + usleep(2500); +} + +void kd1() { + usleep(1); +} + +uint8_t sample(char *name) { + struct gpio_pin_op op; + struct pin2dev *p = pin(name); + int fd = num2fd(p->dev), t; + + strlcpy(op.gp_name, name, GPIOPINMAXNAME); + + t = ioctl(fd, GPIOPINREAD, &op); + +// printf("read %d, err: %d\n", op.gp_value, t); + + return op.gp_value; +} + +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(); + } + sample("srq1"); +} + +void clear() { + HI("clk"); + LO("clkinh"); + kdh(); + LO("clr"); + kdh(); + LO("clk"); + kdh(); + HI("clr"); + kdh(); + HI("clk"); + kd2(); +} + +uint8_t sample_byte(char *name) { + uint8_t ret = 0; + int i = 8; + + for(; i > 0; i--) { + ret |= (sample(name) << i); + kd2(); + LO("clk"); + kd2(); + HI("clk"); + } + + return ret; +} + +void sample_bytes() { + uint8_t ret[6]; + int i = 8, j = 0; + char *s; + + s = calloc(10, 1); + memset(&ret[0], 0, 6); + + for(; i > 0; i--) { + for(j = 0; j < 6; j++) { + sprintf(s, "srq%d", j + 1); + ret[j] |= sample(s); + } + kd2(); + LO("clk"); + kd2(); + HI("clk"); + } + + for(i = 0; i < 6; i++) + printf("SRQ%d: %02x\n", i + 1, ret[i]); + + printf("\n\n\n"); +} + int main(int argc, char *argv[]) { + + uint8_t b; + + signal(SIGINT, inth); + pins_init(); config_pins(); pincnt(); - sleep(1); - - pcfg(1, 6, -1, INPUT | PULLDOWN, "ser"); + pcfg(1, 7, -1, INPUT | PULLDOWN, "srq1"); + pcfg(1, 3, -1, INPUT | PULLDOWN, "srq2"); + pcfg(1, 12, -1, INPUT | PULLDOWN, "srq3"); + pcfg(0, 26, -1, INPUT | PULLDOWN, "srq4"); + pcfg(1, 14, -1, INPUT | PULLDOWN, "srq5"); + pcfg(2, 1, -1, INPUT | PULLDOWN, "srq6"); pcfg(1, 13, 0, OUTPUT, "clk"); pcfg(1, 15, 0, OUTPUT, "shld"); pcfg(0, 27, 0, OUTPUT, "clr"); + pcfg(2, 2, 0, OUTPUT, "clkinh"); + + /* 7 seg */ + pcfg(2, 10, 0, OUTPUT, "ss-rst"); + pcfg(2, 12, 0, OUTPUT, "ss-clk"); +// test_7seg(); + + start(); + byte(0x8f); + stop(); + + LO("clk"); + HI("clkinh"); + HI("clr"); + HI("shld"); + + sleep(1); +for(;;){ + LO("clk"); + HI("clkinh"); + HI("clr"); + HI("shld"); + kd2(); + kd2(); + clear(); + + LO("clk"); + LO("shld"); + kd2(); + HI("clk"); + kdh(); + HI("clkinh"); + kdh(); + LO("clk"); + + HI("shld"); + kdh(); + kdh(); + HI("clk"); + kd2(); + LO("clk"); + LO("clkinh"); + kd2(); + HI("clk"); + + b = sample_byte("srq1"); + printf("TEST: 0x%02x\n", b); +// sample_bytes(); + + kd2(); +// tick(16); +// tick(7); +} +} + +void test_7seg() { + + HI("ss-rst"); + sleep(1); + LO("ss-rst"); for(;;) { - HI("shld"); - usleep(1); - LO("shld"); - usleep(1); + HI("ss-clk"); + usleep(50000); + LO("ss-clk"); + usleep(50000); } + }