Skip to content

Commit bbac61a

Browse files
committed
Handle bonescript compatible pin names in ocp set pin mode function (bonescript uses eg, P8_6 instead of P8_06 which OCP needs)
1 parent bc37399 commit bbac61a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

source/c_pinmux.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@ BBIO_err set_pin_mode(const char *key, const char *mode)
1010
// char ocp_dir[] defined in common.h
1111
char path[60]; // "/sys/devices/platform/ocp/ocp:P#_##_pinmux/state"
1212
char pinmux_dir[20]; // "ocp:P#_##_pinmux"
13+
char pin[6]; //"P#_##"
1314
FILE *f = NULL;
15+
16+
if (strlen(key) == 4) // Key P#_# format, must inject '0' to be P#_0#
17+
snprintf(pin, sizeof(pin), "%.3s0%c", key,key[3]);
18+
else //copy string
19+
snprintf(pin, sizeof(pin), "%s", key);
1420

1521
#ifndef BBBVERSION41
1622
BBIO_err err;
17-
err = build_path("/sys/devices", "ocp", ocp_dir, sizeof(ocp_dir));
23+
err = build_path("/sys/devices/platform", "ocp", ocp_dir, sizeof(ocp_dir));
1824
if (err != BBIO_OK) {
1925
return err;
2026
}
2127
#else
2228
strncpy(ocp_dir, "/sys/devices/platform/ocp", sizeof(ocp_dir));
2329
#endif
2430

25-
snprintf(pinmux_dir, sizeof(pinmux_dir), "ocp:%s_pinmux", key);
31+
snprintf(pinmux_dir, sizeof(pinmux_dir), "ocp:%s_pinmux", pin);
2632
snprintf(path, sizeof(path), "%s/%s/state", ocp_dir, pinmux_dir);
2733

2834
f = fopen(path, "w");

0 commit comments

Comments
 (0)