a831f5831c4fe8d0dce6f2c8e9ae739cedbd0a30
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
;
112 system("gpioctl gpio2 6 set out clk");
113 system("gpioctl gpio2 8 set out dio");
115 ser
= calloc(1, sizeof(struct gpio_pin_set
));
116 oe
= calloc(1, sizeof(struct gpio_pin_set
));
117 rclk
= calloc(1, sizeof(struct gpio_pin_set
));
118 srclk
= calloc(1, sizeof(struct gpio_pin_set
));
119 srclr
= calloc(1, sizeof(struct gpio_pin_set
));
120 dio
= calloc(1, sizeof(struct gpio_pin_set
));
121 clk
= calloc(1, sizeof(struct gpio_pin_set
));
124 ser
->gp_flags
= GPIO_PIN_OUTPUT
;
125 strlcpy(ser
->gp_name2
, "ser", GPIOPINMAXNAME
);
128 oe
->gp_flags
= GPIO_PIN_OUTPUT
;
129 strlcpy(oe
->gp_name2
, "oe", GPIOPINMAXNAME
);
132 rclk
->gp_flags
= GPIO_PIN_OUTPUT
;
133 strlcpy(rclk
->gp_name2
, "rclk", GPIOPINMAXNAME
);
136 srclk
->gp_flags
= GPIO_PIN_OUTPUT
;
137 strlcpy(srclk
->gp_name2
, "srclk", GPIOPINMAXNAME
);
140 srclr
->gp_flags
= GPIO_PIN_OUTPUT
;
141 strlcpy(srclr
->gp_name2
, "srclr", GPIOPINMAXNAME
);
144 dio
->gp_flags
= GPIO_PIN_OUTPUT
;
145 strlcpy(dio
->gp_name2
, "dio", GPIOPINMAXNAME
);
148 clk
->gp_flags
= GPIO_PIN_OUTPUT
;
149 strlcpy(clk
->gp_name2
, "clk", GPIOPINMAXNAME
);
151 ioctl(name2dev("ser"), GPIOPINSET
, ser
);
152 ioctl(name2dev("oe"), GPIOPINSET
, oe
);
153 ioctl(name2dev("rclk"), GPIOPINSET
, rclk
);
154 ioctl(name2dev("srclk"), GPIOPINSET
, srclk
);
155 ioctl(name2dev("srclr"), GPIOPINSET
, srclr
);
156 ioctl(name2dev("dio"), GPIOPINSET
, dio
);
157 ioctl(name2dev("clk"), GPIOPINSET
, clk
);
169 g0
= open("/dev/gpio0", O_RDWR
);
170 g1
= open("/dev/gpio1", O_RDWR
);
171 g2
= open("/dev/gpio2", O_RDWR
);
173 struct gpio_info
*inf0
, *inf1
, *inf2
;
174 inf0
= calloc(1, sizeof(struct gpio_info
));
175 inf1
= calloc(1, sizeof(struct gpio_info
));
176 inf2
= calloc(1, sizeof(struct gpio_info
));
178 ioctl(g0
, GPIOINFO
, inf0
);
179 ioctl(g1
, GPIOINFO
, inf1
);
180 ioctl(g2
, GPIOINFO
, inf2
);
182 printf("gpio0: %d\ngpio1: %d\ngpio2: %d\n", inf0
->gpio_npins
, inf1
->gpio_npins
, inf2
->gpio_npins
);
203 void byte(uint8_t b
) {
204 for(int i
= 0; i
< 8; i
++) {
207 (b
& 0x1) ? UP("dio") : DOWN("dio");
225 void blink(int c
, int ms
) {
226 for(int i
= 0; i
< c
; i
++) {