0d6c8a6361c755af2f576fa83b17913910bbfa8d
10 #include <sys/ioctl.h>
12 #define UP(N) set_pin(N, 1)
13 #define DOWN(N) set_pin(N, 0)
18 #define ADDR_AUTO 0x44
32 volatile int g0
, g1
, g2
;
35 /* struct timespec ts, rem;
47 int name2dev(char *s
) {
48 if (! strncmp(s
, "ser", GPIOPINMAXNAME
))
50 else if (! strncmp(s
, "oe", GPIOPINMAXNAME
))
52 else if (! strncmp(s
, "rclk", GPIOPINMAXNAME
))
54 else if (! strncmp(s
, "srclk", GPIOPINMAXNAME
))
56 else if (! strncmp(s
, "srclr", GPIOPINMAXNAME
))
58 else if (! strncmp(s
, "dio", GPIOPINMAXNAME
))
60 else if (! strncmp(s
, "clk", GPIOPINMAXNAME
))
63 printf("no gpio pin w/ name %s, exiting..\n", s
);
77 struct gpio_pin_set p
;
83 p
.gp_flags
= GPIO_PIN_INPUT
| GPIO_PIN_PULLDOWN
;
86 ioctl(name2dev("dio"), GPIOPINWRITE
, &o
);
87 ioctl(name2dev("dio"), GPIOPINSET
, &p
);
90 printf("waiting..\n");
91 ioctl(name2dev("dio"), GPIOPINREAD
, &o
);
95 p
.gp_flags
= GPIO_PIN_OUTPUT
;
96 ioctl(name2dev("dio"), GPIOPINREAD
, &o
);
99 void set_pin(char *name
, int state
) {
100 struct gpio_pin_op op
;
102 strlcpy(op
.gp_name
, name
, GPIOPINMAXNAME
);
105 ioctl(name2dev(name
), GPIOPINWRITE
, &op
);
109 struct gpio_pin_set
*ser
, *oe
, *rclk
, *srclk
, *srclr
, *dio
, *clk
;
111 ser
= calloc(1, sizeof(struct gpio_pin_set
));
112 oe
= calloc(1, sizeof(struct gpio_pin_set
));
113 rclk
= calloc(1, sizeof(struct gpio_pin_set
));
114 srclk
= calloc(1, sizeof(struct gpio_pin_set
));
115 srclr
= calloc(1, sizeof(struct gpio_pin_set
));
116 dio
= calloc(1, sizeof(struct gpio_pin_set
));
117 clk
= calloc(1, sizeof(struct gpio_pin_set
));
120 ser
->gp_flags
= GPIO_PIN_OUTPUT
;
121 strlcpy(ser
->gp_name2
, "ser", GPIOPINMAXNAME
);
124 oe
->gp_flags
= GPIO_PIN_OUTPUT
;
125 strlcpy(oe
->gp_name2
, "oe", GPIOPINMAXNAME
);
128 rclk
->gp_flags
= GPIO_PIN_OUTPUT
;
129 strlcpy(rclk
->gp_name2
, "rclk", GPIOPINMAXNAME
);
132 srclk
->gp_flags
= GPIO_PIN_OUTPUT
;
133 strlcpy(srclk
->gp_name2
, "srclk", GPIOPINMAXNAME
);
136 srclr
->gp_flags
= GPIO_PIN_OUTPUT
;
137 strlcpy(srclr
->gp_name2
, "srclr", GPIOPINMAXNAME
);
140 dio
->gp_flags
= GPIO_PIN_OUTPUT
;
141 strlcpy(dio
->gp_name2
, "dio", GPIOPINMAXNAME
);
144 clk
->gp_flags
= GPIO_PIN_OUTPUT
;
145 strlcpy(clk
->gp_name2
, "clk", GPIOPINMAXNAME
);
147 ioctl(name2dev("ser"), GPIOPINSET
, ser
);
148 ioctl(name2dev("oe"), GPIOPINSET
, oe
);
149 ioctl(name2dev("rclk"), GPIOPINSET
, rclk
);
150 ioctl(name2dev("srclk"), GPIOPINSET
, srclk
);
151 ioctl(name2dev("srclr"), GPIOPINSET
, srclr
);
152 ioctl(name2dev("dio"), GPIOPINSET
, dio
);
153 ioctl(name2dev("clk"), GPIOPINSET
, clk
);
165 g0
= open("/dev/gpio0", O_RDWR
);
166 g1
= open("/dev/gpio1", O_RDWR
);
167 g2
= open("/dev/gpio2", O_RDWR
);
169 struct gpio_info
*inf0
, *inf1
, *inf2
;
170 inf0
= calloc(1, sizeof(struct gpio_info
));
171 inf1
= calloc(1, sizeof(struct gpio_info
));
172 inf2
= calloc(1, sizeof(struct gpio_info
));
174 ioctl(g0
, GPIOINFO
, inf0
);
175 ioctl(g1
, GPIOINFO
, inf1
);
176 ioctl(g2
, GPIOINFO
, inf2
);
178 printf("gpio0: %d\ngpio1: %d\ngpio2: %d\n", inf0
->gpio_npins
, inf1
->gpio_npins
, inf2
->gpio_npins
);
199 void byte(uint8_t b
) {
200 for(int i
= 0; i
< 8; i
++) {
203 (b
& 0x1) ? UP("dio") : DOWN("dio");
221 void blink(int c
, int ms
) {
222 for(int i
= 0; i
< c
; i
++) {