Difference between revisions of "GPIO keys"
From ArmadeusWiki
m (→Test) |
(→Test) |
||
Line 23: | Line 23: | ||
# reset | # reset | ||
</pre> | </pre> | ||
+ | ==For APF27== | ||
+ | First, you need to enable the gpio_keys in your kernel. | ||
+ | |||
+ | <pre class="config"> | ||
+ | Device Drivers ---> | ||
+ | Input device support ---> | ||
+ | <*> Event interface | ||
+ | [*] Keyboards ---> | ||
+ | <*> GPIO Buttons | ||
+ | </pre> | ||
+ | |||
+ | Then, in your ''apf27-dev.c'', you need to define your GPIO button <b>before</b> the variable ''platform_devices[]''. | ||
+ | |||
+ | <source lang="c"> | ||
+ | /* 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 | ||
+ | </source> | ||
+ | |||
+ | Add the button to get it recognized by the card. | ||
+ | |||
+ | <source lang="c"> | ||
+ | static struct platform_device *platform_devices[] __initdata = { | ||
+ | ALSA_SOUND | ||
+ | GPIO_KEYS | ||
+ | }; | ||
+ | </source> | ||
[[Category:UserInput]] | [[Category:UserInput]] |
Revision as of 18:45, 2 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
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[].
/* 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
};