Difference between revisions of "GPIO keys"

From ArmadeusWiki
Jump to: navigation, search
(Test)
m (For APF27)
Line 54: Line 54:
 
</pre>
 
</pre>
  
Then, in your ''apf27-dev.c'', you need to define your GPIO button <b>before</b> the variable ''platform_devices[]''.
+
Then, in your ''apf27-dev.c'', you need to define your GPIO button <b>before</b> the variable ''platform_devices[]'' and also include gpio_keys.h and input.h.
 +
 
 +
<source lang="c">
 +
#include <linux/gpio_keys.h>
 +
#include <linux/input.h>
 +
</source>
  
 
<source lang="c">
 
<source lang="c">

Revision as of 11:40, 4 May 2012

How to use gpio-keys driver to read states of the user switch of your Armadeus board (APF51)

Introduction

Your APF51 board features a user switch connected to a GPIO pin (GPIO1_3). The driver gpio-keys translates GPIO events in key/button events.


Test

# cat /dev/input/event0

Then you should see weirds characters when pressing the user button of the apf51_dev board:

 T
 ����T
      �T
        �
         ��T
            %�
  • if the test wiped out your console, you can get it back with:
# reset

You also can use the tool evtest.

Hardware handling  --->
     [*] input-tools
          [*]   evtest
 # evtest /dev/input/event0
...
Event: time 1335981358.550329, type 22 (EV_PWR), code 0 (), value 1
Event: time 1335981358.550330, -------------- SYN_REPORT ------------
Event: time 1335981358.550329, type 22 (EV_PWR), code 0 (), value 0
Event: time 1335981358.550330, -------------- SYN_REPORT ------------

For APF27

First, you need to enable the gpio_keys in your kernel.

Device Drivers  --->
     Input device support  --->
           <*>   Event interface
           [*]   Keyboards  --->
               <*>   GPIO Buttons

Then, in your apf27-dev.c, you need to define your GPIO button before the variable platform_devices[] and also include gpio_keys.h and input.h.

#include <linux/gpio_keys.h>
#include <linux/input.h>
/* GPIO KEYS */
#if 1

/* PORTA_6 used as gpio_keys (GPIO used as input event) */
static struct gpio_keys_button apf27_gpio_keys[] = {
	{
		.code = EV_PWR, /* See include/linux/input.h for more event code */
		.gpio = (GPIO_PORTA | 6), /* GPIO number */
		.active_low = 0,
		.desc = "Notification when the AC is deconnected", /* Button description*/
		.type = 0, /* See include/linux/input.h for more type code */
	},
};

static struct gpio_keys_platform_data apf27_gpio_keys_data = {
	.buttons = apf27_gpio_keys,
	.nbuttons = ARRAY_SIZE(apf27_gpio_keys),
};

static struct platform_device apf27_gpio_keys_device = {
	.name = "gpio-keys",
	.id = 0,
	.dev = {
		.platform_data = &apf27_gpio_keys_data,
	},
};
# define GPIO_KEYS &apf27_gpio_keys_device,
#else
# define GPIO_KEYS
#endif

Add the button to get it recognized by the card.

static struct platform_device *platform_devices[] __initdata = {
	ALSA_SOUND
	GPIO_KEYS
};