Skip to content

Instantly share code, notes, and snippets.

@jnewc
Created April 29, 2016 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnewc/e4bcfeaa9ab4d83d1609bf10d91e2a95 to your computer and use it in GitHub Desktop.
Save jnewc/e4bcfeaa9ab4d83d1609bf10d91e2a95 to your computer and use it in GitHub Desktop.
Reggie's gpio-keys driver
// Reggie added, simple gpio keys polled driver, adds button support via gpio
// will be useful for embedded devices, see gpio-mouse, gpio-fan and rotary-encoder
// for other examples of gpio access to devices from the linux kernel
// this will use GPIO4,17,21,22 as a simple test, they will be set to active_low
// so should have a pullup added to each pin and button tied to ground.
// We have to use polled at the moment because the current kernel doesn't have
// code to handle an interrupt driven gpio-keys driver, which would've been much nicer
// you should check the wiki to make sure that these gpio are correctly configured
// and see whether they are physically pulled up on the schematic, if they're not
// add a 10k pullup to the gpio-keys pins and tie the button to gnd
// buttons are set active low, so closing the switch should pull them to ground
// and press the button
#if defined(CONFIG_KEYBOARD_GPIO_POLLED)|| defined(CONFIG_KEYBOARD_GPIO_MODULE)
#include <linux/gpio_keys.h>
#include <linux/input.h>
#define BCM2708_KEYS_DEBOUNCE 5
static struct gpio_keys_button bcm2708_gpio_keys_table[] = {
{
.type = EV_KEY,
.code = KEY_ENTER,
.gpio = 4,
.active_low = 1,
.desc = "gpio-keys: enter",
.debounce_interval = BCM2708_KEYS_DEBOUNCE,
}, {
.type = EV_KEY,
.code = KEY_A,
.gpio = 17,
.active_low = 1,
.desc = "gpio-keys: A",
.debounce_interval = BCM2708_KEYS_DEBOUNCE,
}, {
.type = EV_KEY,
.code = KEY_B,
.gpio = 21,
.active_low = 1,
.desc = "gpio-keys: B",
.debounce_interval = BCM2708_KEYS_DEBOUNCE,
}, {
.type = EV_KEY,
.code = KEY_C,
.gpio = 22,
.active_low = 1,
.desc = "gpio-keys: C",
.debounce_interval = BCM2708_KEYS_DEBOUNCE,
},
};
static struct gpio_keys_platform_data bcm2708_gpio_keys_data = {
.buttons = bcm2708_gpio_keys_table,
.nbuttons = ARRAY_SIZE(bcm2708_gpio_keys_table),
.poll_interval = 20
};
static struct platform_device bcm2708_device_gpio_keys = {
.name = "gpio-keys-polled",
.dev = {
.platform_data = &bcm2708_gpio_keys_data,
},
};
static void __init bcm2708_init_gpio_keys(void)
{
platform_device_register(&bcm2708_device_gpio_keys);
}
#else
static inline void bcm2708_init_gpio_keys(void)
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment