X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fbaylibre-acme%2Fgpio.c;h=d86d24113b9b3c7fe647a4f1733f64f4d0f3feee;hb=ce19d4c6157b2998aa88a2f32670dd7bdcca02e8;hp=fb5d298c7e3b018f9730daedb4c3b0e08c277728;hpb=515ab0889ebde4b373d620044a1a98da37153056;p=libsigrok.git
diff --git a/src/hardware/baylibre-acme/gpio.c b/src/hardware/baylibre-acme/gpio.c
index fb5d298c..d86d2411 100644
--- a/src/hardware/baylibre-acme/gpio.c
+++ b/src/hardware/baylibre-acme/gpio.c
@@ -17,13 +17,14 @@
* along with this program. If not, see .
*/
+#include
#include
#include
#include
#include
#include
#include
-#include "libsigrok.h"
+#include
#include "libsigrok-internal.h"
#include "gpio.h"
@@ -36,14 +37,14 @@ static int open_and_write(const gchar *path, const gchar *buf)
fd = g_fopen(path, "w");
if (!fd) {
- sr_err("Error opening %s: %s", path, strerror(errno));
+ sr_err("Error opening %s: %s", path, g_strerror(errno));
return -1;
}
wr = g_fprintf(fd, "%s", buf);
fclose(fd);
if (wr < 0) {
- sr_err("Error writing to %s: %s", path, strerror(errno));
+ sr_err("Error writing to %s: %s", path, g_strerror(errno));
return -1;
}
@@ -63,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);
@@ -117,7 +122,7 @@ SR_PRIV int sr_gpio_get_value(int gpio)
g_string_printf(path, "/sys/class/gpio/gpio%d/value", gpio);
fd = g_fopen(path->str, "r");
if (!fd) {
- sr_err("Error opening %s: %s", path->str, strerror(errno));
+ sr_err("Error opening %s: %s", path->str, g_strerror(errno));
g_string_free(path, TRUE);
return -1;
}
@@ -125,7 +130,7 @@ SR_PRIV int sr_gpio_get_value(int gpio)
status = fscanf(fd, "%d", &ret);
fclose(fd);
if (status != 1) {
- sr_err("Error reading from %s: %s", path, strerror(errno));
+ sr_err("Error reading from %s: %s", path->str, g_strerror(errno));
g_string_free(path, TRUE);
return -1;
}
@@ -142,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;
@@ -161,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);
}