OpenWrt Forum Archive

Topic: GPIO to Button functionality

The content of this topic has been archived on 2 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I am trying to get a gpio line (GPIO29) on a wr703n to be recognised as a button.
I want this as it seems the easiest way to have system polling of the state of it without tying up CPU.
So I edited: openwrt/trunk/target/linux/ar71xx/files/arch/mips/ath7/mach-tl-wr703n.c to look like this:


snip snip

#define TL_WR703N_GPIO_LED_SYSTEM    27
#define SENSOR_BTN_29            29


static struct gpio_keys_button tl_wr703n_gpio_keys[] __initdata = {
    {
        .desc        = "reset",
        .type        = EV_KEY,
        .code        = KEY_RESTART,
        .debounce_interval = TL_WR703N_KEYS_DEBOUNCE_INTERVAL,
        .gpio        = TL_WR703N_GPIO_BTN_RESET,
        .active_low    = 0,
    },{
        .desc        = "sensor",
        .type        = EV_KEY,
        .code        = BTN_1,
        .debounce_interval = TL_WR703N_KEYS_DEBOUNCE_INTERVAL,
        .gpio        = SENSOR_BTN_29,
        .active_low    = 1,
    }
};

But when I toggle the sensor (ie GPIO29) from low to high and back, nothing shows in the syslog (via logview, the real button shows actions).
What am I missing?
I have included all gpio related addons in the build.

First, if you let the kernel module take control of a gpio, this is not avalaible from userspace. You have to unload the module, export the gpio to userspace, then you can use it

Second, according to http://wiki.openwrt.org/toh/tp-link/tl-wr703n this gpio isn't connected at all, i.e. maybe hw disabled with a pull up resistor. How do you trigger it if itsn't connected?

rAndy,
I have removed the pull down resistor and soldered a wire to gpio29. That is how I am physically accessing it. (3v3 for high, gnd for low).
I can use it as an input or output gpio via export gpio user space functions, but I don't want that, otherwise I have to cat continuously to see when it gets toggled.
As to user space control: I don't want to control it, I want to monitor it (ie input, not output). Exactly like the button functions.
Any ideas?

Maybe there are kernel modules generating events, which are captured by hotplug subsystem, don't know; maybe dig into input-gpio-buttons kmod package

But do you see transition changes on the line? I.e. when you export it in userspace gpio29/value does change?

I think I need to be looking at kmod-input-evdev.
I am still up for advice though, really in the dark here!
L8R

Sorry to squat this topic, but for those of you that are subscribed to this topic, please also check the topic "TP-Link TL-WR703N Reverse Engineering", as it is closely related.

Just for completeness: I am an idiot!
Using the mod I listed in my first post, along with the info in the hardware button link posted above, everything works like a charm IF YOU USE THE RIGHT WIRE!
I had been using gpio7 instead of gpio29, due to bad labelling.

tongue

Don't be to hard, this happens to anybody.

Thank you for posting the final word on this!

Is it necessary to compile an own image to be able to use a GPIO as a button on the TL-WR703N? I can chech the state of a GPIO pin with cat but I would not like to poll it several times per minute because it eats cpu. Is there any way to do it without recompiling?

You have to compile your own after editing the file I mentioned in the first post. Obviously you will need to set the pin number to what you are using. The debounce interval is worth thinking about too: in my case I am monitoring the digital out from an air wick motion detector. Setting the debounce to 1 second filters out background noise. The latest attitude adjustment source (as of last friday) works fine.

edit: in case I didn't answer your question, this is the only way I have found of having an interrupt, rather than manually polling (via cat).

(Last edited by robthebrew on 9 Oct 2012, 11:24)

The discussion might have continued from here.