From 623a7e73cf79ecdda28fe5d3ff429090dbae359d Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Fri, 10 Jul 2020 11:08:51 +0100 Subject: make GPIO a parameter --- Makefile | 5 +++++ out-of-tree.mk | 6 ++++-- pingid.c | 19 ++++++++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7fe50e9..0da8d7d 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,8 @@ + +ifneq (${GPIO},) + CFLAGS+=-DGPIO=${GPIO} +endif + pingid:pingid.o ${CC} ${CFLAGS} ${LDFLAGS} -o $@ $< ${LIBS} diff --git a/out-of-tree.mk b/out-of-tree.mk index 524fdb6..9a65f7d 100644 --- a/out-of-tree.mk +++ b/out-of-tree.mk @@ -1,6 +1,8 @@ -STAGING_DIR=/home/openwrt/gl-inet-mt300n-v2/master-d20f4fc/staging_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl +#STAGING_DIR=/home/openwrt/gl-inet-mt300n-v2/master-d20f4fc/staging_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl +STAGING_DIR=/home//openwrt/gl-inet-ar300m/master-fa83455/staging_dir/toolchain-mips_24kc_gcc-8.3.0_musl/ export STAGING_DIR -CROSS=${STAGING_DIR}/bin/mipsel-openwrt-linux-musl- +#CROSS=${STAGING_DIR}/bin/mipsel-openwrt-linux-musl- +CROSS=${STAGING_DIR}/bin/mips-openwrt-linux- CC=${CROSS}gcc diff --git a/pingid.c b/pingid.c index 6e33510..0dc182a 100644 --- a/pingid.c +++ b/pingid.c @@ -6,6 +6,14 @@ #include #include +#ifndef GPIO +#define GPIO 4 +#endif + +#define STRINGIFY(a) #a +#define STRINGIFY_HARDER(a) STRINGIFY(a) +#define GPIO_STR STRINGIFY_HARDER(GPIO) + char *names[KEY_MAX + 1] = { "", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "", @@ -132,16 +140,17 @@ main (int argc, char *argv[]) struct timeval tv; char ret[128]; - squirt ("/sys/class/gpio/export", "4"); - squirt ("/sys/class/gpio/gpio4/direction", "out"); - squirt ("/sys/class/gpio/gpio4/value", "0"); + + squirt ("/sys/class/gpio/export", GPIO_STR); + squirt ("/sys/class/gpio/gpio" GPIO_STR "/direction", "out"); + squirt ("/sys/class/gpio/gpio" GPIO_STR "/value", "0"); tv.tv_sec = 0; tv.tv_usec = 100; get_string_with_timeout (fd, &tv, NULL, 0); - squirt ("/sys/class/gpio/gpio4/value", "1"); + squirt ("/sys/class/gpio/gpio" GPIO_STR "/value", "1"); tv.tv_sec = 2; @@ -149,7 +158,7 @@ main (int argc, char *argv[]) get_string_with_timeout (fd, &tv, ret, sizeof (ret)); - squirt ("/sys/class/gpio/gpio4/value", "0"); + squirt ("/sys/class/gpio/gpio" GPIO_STR "/value", "0"); printf ("Access-Control-Allow-Origin: *\n"); printf ("Content-Type: text/plain\n\n%s\n", ret); -- cgit v1.2.3