fixaroonie
[bort-panel.git] / pins.c
1 #include <stdlib.h>
2 #include <fcntl.h>
3 #include <signal.h>
4 #include <unistd.h>
5 #include <string.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <time.h>
9
10 #include <sys/types.h>
11 #include <sys/gpio.h>
12 #include <sys/ioctl.h>
13
14 #include "pins.h"
15
16 #define UP(N) set_pin(N, 1)
17 #define DOWN(N) set_pin(N, 0)
18
19 #define HI(N) set(N, 1)
20 #define LO(N) set(N, 0)
21
22 void kd2() {
23 usleep(10000);
24 }
25
26 void kdh() {
27 usleep(5000);
28 }
29
30 void kd1() {
31 usleep(1);
32 }
33
34 void test_pins() {
35 for(;;) {
36 HI("clk");
37 HI("clkinh");
38 LO("shld");
39 HI("clr");
40 kd1();
41 LO("clk");
42 LO("clkinh");
43 LO("shld");
44 LO("clr");
45 kd1();
46 }
47 }
48
49 /* call when clk is hi */
50 void tick(int n) {
51 int i = 0;
52
53 for(; i < n; i++) {
54 LO("clk");
55 kd2();
56 HI("clk");
57 kd2();
58 }
59 }
60
61 void clear() {
62 HI("clk");
63 LO("clkinh");
64 kdh();
65 LO("clr");
66 kdh();
67 LO("clk");
68 kdh();
69 HI("clr");
70 kdh();
71 HI("clk");
72 kd2();
73 }
74
75 int main(int argc, char *argv[]) {
76
77 signal(SIGINT, inth);
78
79 pins_init();
80 // config_pins();
81 pincnt();
82
83 pcfg(1, 6, -1, INPUT | PULLDOWN, "ser");
84 pcfg(1, 13, 0, OUTPUT, "clk");
85 pcfg(1, 15, 0, OUTPUT, "shld");
86 pcfg(0, 27, 0, OUTPUT, "clr");
87 pcfg(1, 2, 0, OUTPUT, "clkinh");
88
89 LO("clk");
90 HI("clkinh");
91 HI("clr");
92 HI("shld");
93
94 sleep(1);
95 for(;;){
96 LO("clk");
97 HI("clkinh");
98 HI("clr");
99 HI("shld");
100 kd2();
101 kd2();
102 clear();
103
104 LO("clk");
105 LO("shld");
106 kd2();
107 HI("clk");
108 kdh();
109 HI("clkinh");
110 kdh();
111 LO("clk");
112
113 HI("shld");
114 kdh();
115 kdh();
116 HI("clk");
117 kd2();
118 tick(2);
119 LO("clk");
120 LO("clkinh");
121 kd2();
122 HI("clk");
123 kd2();
124 tick(8);
125 }
126 }