android add external button

Android add external button: respond to external button input TQ210

Linux source code:

Platform

http://www.linuxidc.com/Linux/2012-12/76196.htm

/opt/EmbedSky/TQ210/Kernel_3.0.8_TQ210_for_Android_v1.0/drivers/input/keyboard/s3c-gpio-keys.c

Modify the driver: struct s3c_gpio_key s3c_gpio_keys[]= Inside add:

{

.pin = S5PV210_GPH2(3),// Select the GPH2_3 pin of the GPIO port

.eintcfg = 0X0f<<12,// Configure the GPH2_3 port as 1111 = EXT_INT[3]

.inputcfg = 0<<12,// Configure GPH2_3 pin as input

.eint = IRQ_EINT16_31,// Configure interrupt

},

{

.pin = S5PV210_GPH2(4), // Select the GPH2_4 pin of the GPIO port

.eintcfg = 0X0f<<16,// Configure the GPH2_4 port as 1111 = EXT_INT[4]

.inputcfg = 0<<16,// Configure GPH2_4 pin as input

.eint = IRQ_EINT16_31,// Configure interrupt

}

 

Under the android kernel source code, look for: /kernel/arch/arm/mach-s5p210/mach-tq210.c

1. Use platfrom_device to define the device:

static struct platform_device s3c_device_gpio_button = {

.name= "gpio-keys",

.id= -1,

.num_resources= 0,

.dev= {

.platform_data= &gpio_button_data,

}

};

where gpio_button_data

2. Join the kernel, create a platform_device array, and then add the platform_device of the KEY to this array .

static struct platform_device *tq210_devices[] __initdata = {

……………

#ifdef CONFIG_KEYBOARD_S3C_GPIO

&s3c_device_gpio_button,

#endif

…………

};

3. The platform_device array is registered to the kernel

static void __init tq210_machine_init(void)

{

………………………..

platform_add_devices(tq210_devices, ARRAY_SIZE(tq210_devices)); // register to the kernel

……………………………

}

So far, we have seen the whole process of adding platform_device and how this platform_device is registered to the kernel.

4. View the existing key definitions in /opt/EmbedSky/TQ210/Kernel_3.0.8_TQ210_for_Android_v1.0/include/linux/input.h , here select:

#define BTN_A0x130

#define BTN_B0x131

Then find in Android:

/TQ210_Android_4.0.4_V1.0/frameworks/base/include/ui/keycodeslabels.h Look at the names of the corresponding keys:

{ "BUTTON_A", 96 },

{ "BUTTON_B", 97 },

So, just add the registration information of the button in the /kernel/arch/arm/mach-s5p210/mach-tq210.c file:

Add the following to static struct gpio_keys_button gpio_buttons[] :

{

.gpio= S5PV210_GPH2(3),

.code= 304,

.desc= " BUTTON_A ",

.active_low= 1,

.wakeup= 0,

},

{

.gpio= S5PV210_GPH2(4),

.code= 305,

.desc= " BUTTON_B ",

.active_low= 1,

.wakeup= 0,

.debounce_interval = 100, //消抖

},

Add the mapping relationship in qwer.kl ( /TQ210_Android_4.0.4_V1.0/frameworks/base/data/keyboards ):

key 304BUTTON_A

key 305BUTTON_B

Then compile the kernel zImage.bin ! Compile Android rootfs_dir.bin !

Notes:

input.h (/Kernel_3.0.8_TQ210_for_Android_v1.0/include/linux scan value, which is in the driver ) defines the underlying existing key value; the value of input.h is the same as the value of the key in qwer.kl ; The strings in input.h are provided for linux to use.

qwer.kl ( / TQ210_Android_4.0.4_V1.0 /frameworks/base/data/keyboards , keyboard layout file) qwer.kl is the value in input.h (ie . code , scan value, in the driver) and keycodeLabels Strings in .h (ie . .desc ) are mapped. That is , the conversion relationship between the mapping scan code and the keycode .

KeycodeLabels.h ( / TQ210_Android_4.0.4_V1.0 /frameworks/base/include/ui/ ) converts the string to the integer value of the value, that is, converts it to the keycode value (in keycode.h ), and the keycode value is provided to the android call .

The value in Keycode.h ( / TQ210_Android_4.0.4_V1.0 /frameworks/base/native/android / ) is the same as the value in KeycodeLabels.h; it assigns the value in KeycodeLabels.h to the character, which is provided Give? ? ? ?

The value in KeyEvent.java ( / TQ210_Android_4.0.4_V1.0 /frameworks/base/core/java/android/view/ ) is the same as the value in Keycode.h and KeycodeLabels.h ; the character value of KeyEvent.java is provided to java The application layer is used, that is , the application written in eclipse corresponds to this character value.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327006084&siteId=291194637