From: Bartosz Golaszewski Date: Wed, 16 Sep 2015 13:24:40 +0000 (+0200) Subject: baylibre-acme: gpio: Don't set direction in get/set functions. X-Git-Tag: libsigrok-0.4.0~278 X-Git-Url: http://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=b41bbfdbe2ae6076a6e074ef9652d299657e83fd baylibre-acme: gpio: Don't set direction in get/set functions. GPIO direction should be set once right after exporting. There's no need to reset it again - in fact it's a bug which causes the probe to be reset every time the value is read/set and gives incorrect results when reading the GPIO values with direction == 'in'. Signed-off-by: Bartosz Golaszewski --- diff --git a/src/hardware/baylibre-acme/gpio.c b/src/hardware/baylibre-acme/gpio.c index cbabcf7f..d86d2411 100644 --- a/src/hardware/baylibre-acme/gpio.c +++ b/src/hardware/baylibre-acme/gpio.c @@ -64,6 +64,10 @@ SR_PRIV int sr_gpio_export(unsigned gpio) if (exported) return 0; /* Already exported. */ + status = sr_gpio_set_direction(gpio, GPIO_DIR_OUT); + if (status < 0) + return status; + buf = g_string_sized_new(16); g_string_printf(buf, "%u\n", gpio); status = open_and_write("/sys/class/gpio/export", buf->str); @@ -143,10 +147,6 @@ SR_PRIV int sr_gpio_setval_export(int gpio, int value) if (status < 0) return status; - status = sr_gpio_set_direction(gpio, GPIO_DIR_OUT); - if (status < 0) - return status; - status = sr_gpio_set_value(gpio, value); if (status < 0) return status; @@ -162,9 +162,5 @@ SR_PRIV int sr_gpio_getval_export(int gpio) if (status < 0) return status; - status = sr_gpio_set_direction(gpio, GPIO_DIR_IN); - if (status < 0) - return status; - return sr_gpio_get_value(gpio); }