Difference between revisions of "GPIO keys"
From ArmadeusWiki
m |
m (→For APF27) |
||
Line 65: | Line 65: | ||
<source lang="c"> | <source lang="c"> | ||
/* GPIO KEYS */ | /* GPIO KEYS */ | ||
− | #if | + | #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE) |
− | + | static struct gpio_keys_button apf27dev_gpio_keys[] = { | |
− | + | ||
− | static struct gpio_keys_button | + | |
{ | { | ||
− | .code = | + | .code = BTN_EXTRA, /* See include/linux/input.h */ |
− | .gpio = ( | + | .gpio = (GPIO_PORTF | 13), /* GPIO number */ |
− | .active_low = | + | .active_low = 1, |
− | .desc = " | + | .desc = "s1", /* Button description*/ |
− | . | + | .wakeup = 0, |
}, | }, | ||
}; | }; | ||
− | static struct gpio_keys_platform_data | + | static struct gpio_keys_platform_data apf27dev_gpio_keys_data = { |
− | .buttons = | + | .buttons = apf27dev_gpio_keys, |
− | .nbuttons = ARRAY_SIZE( | + | .nbuttons = ARRAY_SIZE(apf27dev_gpio_keys), |
}; | }; | ||
− | static struct platform_device | + | static struct platform_device apf27dev_gpio_keys_device = { |
.name = "gpio-keys", | .name = "gpio-keys", | ||
− | .id = | + | .id = -1, |
.dev = { | .dev = { | ||
− | .platform_data = & | + | .platform_data = &apf27dev_gpio_keys_data, |
}, | }, | ||
}; | }; | ||
− | # | + | #endif /* CONFIG_KEYBOARD_GPIO */ |
− | + | ||
− | + | ||
− | + | ||
</source> | </source> | ||
Line 100: | Line 96: | ||
<source lang="c"> | <source lang="c"> | ||
static struct platform_device *platform_devices[] __initdata = { | static struct platform_device *platform_devices[] __initdata = { | ||
+ | #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE) | ||
+ | &apf27dev_gpio_keys_device, | ||
+ | #endif | ||
ALSA_SOUND | ALSA_SOUND | ||
− | |||
}; | }; | ||
</source> | </source> | ||
[[Category:UserInput]] | [[Category:UserInput]] |
Revision as of 19:14, 14 May 2012
Introduction
How to use gpio-keys driver to read states of the user switch of your Armadeus board. Your APF51|APF27|APF28 development board feature a user switch connected to a GPIO pin. The driver gpio-keys translates GPIO events in key/button events. Here are the GPIO used for the user button/switch for each APF board:
- APF27: GPIO_PORTF | 13
- APF28: PINID_GPMI_CE1N (Bank 0 - bit 17)
- APF51: GPIO1_3
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 defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
static struct gpio_keys_button apf27dev_gpio_keys[] = {
{
.code = BTN_EXTRA, /* See include/linux/input.h */
.gpio = (GPIO_PORTF | 13), /* GPIO number */
.active_low = 1,
.desc = "s1", /* Button description*/
.wakeup = 0,
},
};
static struct gpio_keys_platform_data apf27dev_gpio_keys_data = {
.buttons = apf27dev_gpio_keys,
.nbuttons = ARRAY_SIZE(apf27dev_gpio_keys),
};
static struct platform_device apf27dev_gpio_keys_device = {
.name = "gpio-keys",
.id = -1,
.dev = {
.platform_data = &apf27dev_gpio_keys_data,
},
};
#endif /* CONFIG_KEYBOARD_GPIO */
Add the button to get it recognized by the card.
static struct platform_device *platform_devices[] __initdata = {
#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
&apf27dev_gpio_keys_device,
#endif
ALSA_SOUND
};