11 #include <sys/ioctl.h>
19 #define PULLDOWN 1 << 3
28 struct pin2dev
*pinmap
;
29 volatile int g0
, g1
, g2
;
42 struct pin2dev
*pin(char *name
) {
43 for(int i
= 0; i
< pin_cnt
; i
++) {
44 if (! strncmp(name
, pinmap
[i
].name
, GPIOPINMAXNAME
))
51 void set(char *name
, int val
) {
53 struct gpio_pin_op op
;
61 //printf("given name: %s\nderived name: %s\nderived pin: %d\nval: %d\nfd: %d\nreal fd: %d\n", name, p->name,
62 // p->pin, op.gp_value, fd, g1);
64 // printf("g0: %d g1: %d g2: %d\n", g0, g1, g2);
66 ioctl(fd
, GPIOPINWRITE
, &op
);
68 // printf("old: %d new: %d\n", op.gp_value, val);
72 pinmap
= calloc(100, sizeof(struct pin2dev
));
76 void pcfg(int devno
, int pin
, int val
, uint8_t mode
, char *name
) {
77 char *fill
= calloc(1, 255);
78 char *pill
= calloc(1, 255);
79 char *vl
= calloc(1, 255);
80 char *nm
= calloc(1, 255);
81 char *md
= calloc(1, 255);
84 strlcpy(nm
, name
, GPIOPINMAXNAME
);
87 strlcpy(md
, "out", 255);
88 else if (mode
& INPUT
) {
90 strlcpy(md
, "in,pu", 255);
91 else if (mode
& PULLDOWN
)
92 strlcpy(md
, "in,pd", 255);
94 strlcpy(md
, "in", 255);
97 pinmap
[pin_cnt
].name
= calloc(1, GPIOPINMAXNAME
);
98 strlcpy(pinmap
[pin_cnt
].name
, name
, GPIOPINMAXNAME
);
99 strlcpy(nm
, name
, GPIOPINMAXNAME
);
100 pinmap
[pin_cnt
].pin
= pin
;
101 pinmap
[pin_cnt
].dev
= devno
;
104 sprintf(fill
, "gpioctl gpio%d %d set %s", devno
, pin
, nm
);
105 sprintf(pill
, "gpioctl gpio%d %s set %s", devno
, nm
, md
);
106 sprintf(vl
, "gpioctl gpio%d %d %d", devno
, pin
, val
);
107 printf("%s\n%s\n", fill
, pill
);