How to add new Key to Android from Kernel to Android framework and Android application test (Guide)

3,427 views
Skip to first unread message

tommy.hong

unread,
Oct 14, 2011, 8:31:58 PM10/14/11
to android-...@googlegroups.com, android...@googlegroups.com

How to add new Key to Android from Kernel to Android framework and Android application test


Kernel Layer:

1:We use Kernel matrix-keypad to register 3*3 key


#ifdef CONFIG_KEYBOARD_MATRIX
/*GPIO Matrix Keyboard*/
static const uint32_t s3c64xx_matrix_keys[] = {
        KEY(0, 0, KEY_P1),
        KEY(0, 1, KEY_LEFT),
        KEY(0, 2, KEY_UP),

        KEY(1, 0, KEY_P2),
        KEY(1, 1, KEY_ENTER),
        KEY(1, 2, KEY_RIGHT),

        KEY(2, 0, KEY_FRONTDOOR),
        KEY(2, 1, KEY_DOWN),
        KEY(2, 2, KEY_START),
};

const struct matrix_keymap_data s3c64xx_keymap_data = {
        .keymap = s3c64xx_matrix_keys,
        .keymap_size = ARRAY_SIZE(s3c64xx_matrix_keys),
};


/*ROW KEY
 GPN0,GPN1,GPN2
 INPUT-->Extern Interrupt
*/

static const unsigned int s3c64xx_keypad_row_gpios[] = {
        144,145,146
};

/*COL KEY:GPN3,GPN6,GPN7*/
static const unsigned int s3c64xx_keypad_col_gpios[] = {
        147,150,151
};

static struct matrix_keypad_platform_data s3c64xx_keypad_platform_data = {
        .keymap_data = &s3c64xx_keymap_data,
        .row_gpios = s3c64xx_keypad_row_gpios,
        .num_row_gpios = ARRAY_SIZE(s3c64xx_keypad_row_gpios),
        .col_gpios = s3c64xx_keypad_col_gpios,
        .num_col_gpios = ARRAY_SIZE(s3c64xx_keypad_col_gpios),
        .active_low = 1,

        .debounce_ms = 20,
        .col_scan_delay_us = 5,
};


static struct platform_device s3c64xx_matrix_keyboard = {
        .name = "matrix-keypad",
        .id = -1,
        .dev = {
                .platform_data = &s3c64xx_keypad_platform_data,
                },
};


static struct platform_device *smdk6410_devices[] __initdata = {
#ifdef CONFIG_KEYBOARD_MATRIX
        &s3c64xx_matrix_keyboard,
#endif
};


2:We add new defition of KEY_P1,KEY_P2,KEY_FRONTDOOR,KEY_START in linux/include/linux/input.h
/*Jiujin.hong 2011/1011
#define KEY_P1                  247
#define KEY_P2                  248
#define KEY_FRONTDOOR           249
#define KEY_START               250
/*END*/


3:We make menuconfig to support Matrix Keyboard arch to register into Kernel input subsystem



Android Framework Layer:

1:

+++ /project/sec_android/eclair/android2.1/smdk6410/android/frameworks/base/include/ui/KeycodeLabels.h    2011-07-04 11:23:23.326802179 +0800
@@ -114,12 +114,6 @@
     { "MEDIA_REWIND", 89 },
     { "MEDIA_FAST_FORWARD", 90 },
     { "MUTE", 91 },
-//Jiujin.hong 2011/10/12,3*3 Key new Key
-    { "P1",92},
-    { "P2",93},
-    { "FRONTDOOR",94},
-    { "START",95},
-//

     // NOTE: If you add a new keycode here you must also add it to:
     //   (enum KeyCode, in this file)
@@ -224,13 +218,7 @@
     kKeyCodePreviousSong = 88,
     kKeyCodeRewind = 89,
     kKeyCodeForward = 90,
-    kKeyCodeMute = 91,
-//Jiujin.hong 2011/1012,3*3 Key
-    kKeyCodeP1 =92,
-    kKeyCodeP2  =93,
-    kKeyCodeFRONTDOOR=94,
-    kKeyCodeSTART=95
-//End
+    kKeyCodeMute = 91
 } KeyCode;



2:

--- frameworks/base/core/java/android/view/KeyEvent.java    2011-10-14 16:29:55.480750044 +0800
+++ /project/sec_android/eclair/android2.1/smdk6410/android/frameworks/base/core/java/android/view/KeyEvent.java    2011-07-04 11:23:14.279382459 +0800
@@ -120,12 +120,6 @@
     public static final int KEYCODE_MEDIA_REWIND    = 89;
     public static final int KEYCODE_MEDIA_FAST_FORWARD = 90;
     public static final int KEYCODE_MUTE            = 91;
-//Jiujin.hong 2011/10/12 3*3  NEW KEY Exhibiton
-    public static final int KEYCODE_P1    = 92;
-    public static final int KEYCODE_P2    = 93;
-    public static final int KEYCODE_FRONTDOOR = 94;
-    public static final int KEYCODE_START = 95;
-//
 
     // NOTE: If you add a new keycode here you must also add it to:
     //  isSystem()
@@ -141,9 +135,7 @@
     //  those new codes.  This is intended to maintain a consistent
     //  set of key code definitions across all Android devices.
   
-//    private static final int LAST_KEYCODE           = KEYCODE_MUTE;
-//Jiujin.hong 2011/10/12 3*3 KEY Exhibition
-    private static final int LAST_KEYCODE           = KEYCODE_START;
+    private static final int LAST_KEYCODE           = KEYCODE_MUTE;
    
     /**
      * @deprecated There are now more than MAX_KEYCODE keycodes.
@@ -700,12 +692,6 @@
         case KEYCODE_CAMERA:
         case KEYCODE_FOCUS:
         case KEYCODE_SEARCH:
-//Jiujin.hong 2011/10/12 3*3 KEY  new Key
-        case KEYCODE_P1:
-        case KEYCODE_P2:
-        case KEYCODE_FRONTDOOR:
-        case KEYCODE_START:
-//END
             return true;
         default:
             return false;


3:
--- frameworks/base/core/res/res/values/attrs.xml    2011-10-14 16:29:19.448748629 +0800
+++ /project/sec_android/eclair/android2.1_6410/smdk6410/android/frameworks/base/core/res/res/values/attrs.xml    2011-07-04 11:23:16.606738864 +0800
@@ -912,12 +912,6 @@
         <enum name="KEYCODE_MEDIA_REWIND" value="89" />
         <enum name="KEYCODE_MEDIA_FAST_FORWARD" value="90" />
         <enum name="KEYCODE_MUTE" value="91" />
-    <!-- Jiujin.hong 2011/1012 3*3 Key New Key -->
-        <enum name="KEYCODE_P1" value="92" />
-        <enum name="KEYCODE_P2" value="93" />
-        <enum name="KEYCODE_FRONTDOOR" value="94" />
-        <enum name="KEYCODE_START" value="95" />
-    <!-- End -->
     </attr>
 
     <!-- ***************************************************************** -->

4:qwerty.kl
key 247   P1
key 248   P2
key 249   FRONTDOOR
key 250   START



Android Application test:

1:Android has setFocusable /request Focus for View if you use onKeyDown,so we need dispatch event

//Since we register new keycode map in frameworks/base/core/res/res/values/attrs.xml
//So we use it to judge
//KEYCODE_P1 ---92
//KEYCODE_P2 ---93
//KEYCODE_FRONTDOOR ---94
//KEYCODE_START ---95
 @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        int action = event.getAction();
        int keyCode = event.getKeyCode();
        System.out.println("Keycode--->"+keyCode);
            switch (keyCode) {
         
            case 92:
                if (action == KeyEvent.ACTION_DOWN) {
                    //TODO
                    System.out.println("P1 DOWN");
                }
                if (action == KeyEvent.ACTION_UP) {
                    //TODO
                    System.out.println("P1 UP");
                }
                return true;
               
            case 93:
                if (action == KeyEvent.ACTION_DOWN) {
                    //TODO
                    System.out.println("P2 DOWN");
                }
                if (action == KeyEvent.ACTION_UP) {
                    //TODO
                    System.out.println("P2 UP");
                }
                return true;

            case 94:
                if (action == KeyEvent.ACTION_DOWN) {
                    //TODO
                    System.out.println("FRONTDOOR DOWN");
                }
                if (action == KeyEvent.ACTION_UP) {
                    //TODO
                    System.out.println("FRONTDOOR UP");
                }
                return true;
            case 95:
                if (action == KeyEvent.ACTION_DOWN) {
                    //TODO
                    System.out.println("START DOWN");
                }
                if (action == KeyEvent.ACTION_UP) {
                    //TODO
                    System.out.println("START UP");
                }
                return true;
            default:
                return super.dispatchKeyEvent(event);
            }
        }
   
    // End




adb logcat:






I/System.out( 1687): Keycode--->92
I/System.out( 1687): P1 DOWN
I/System.out( 1687): Keycode--->92
I/System.out( 1687): P1 UP


I/System.out( 1687): Keycode--->92
I/System.out( 1687): P1 DOWN
I/System.out( 1687): Keycode--->92
I/System.out( 1687): P1 UP
I/System.out( 1687): Keycode--->92
I/System.out( 1687): P1 DOWN
I/System.out( 1687): Keycode--->92
I/System.out( 1687): P1 UP
I/System.out( 1687): Keycode--->92
I/System.out( 1687): P1 DOWN
I/System.out( 1687): Keycode--->92
I/System.out( 1687): P1 UP




I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 DOWN
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 UP
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 DOWN
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 UP
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 DOWN
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 UP
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 DOWN
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 UP
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 DOWN
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 UP
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 DOWN
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 UP
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 DOWN
I/System.out( 1687): Keycode--->93
I/System.out( 1687): P2 UP




I/System.out( 1687): Keycode--->94
I/System.out( 1687): FRONTDOOR DOWN
I/System.out( 1687): Keycode--->94
I/System.out( 1687): FRONTDOOR UP
I/System.out( 1687): Keycode--->94
I/System.out( 1687): FRONTDOOR DOWN
I/System.out( 1687): Keycode--->94
I/System.out( 1687): FRONTDOOR UP
I/System.out( 1687): Keycode--->94
I/System.out( 1687): FRONTDOOR DOWN
I/System.out( 1687): Keycode--->94
I/System.out( 1687): FRONTDOOR UP
I/System.out( 1687): Keycode--->94
I/System.out( 1687): FRONTDOOR DOWN
I/System.out( 1687): Keycode--->94
I/System.out( 1687): FRONTDOOR UP
I/System.out( 1687): Keycode--->94
I/System.out( 1687): FRONTDOOR DOWN
I/System.out( 1687): Keycode--->94
I/System.out( 1687): FRONTDOOR UP



I/System.out( 1687): Keycode--->95
I/System.out( 1687): START DOWN
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START UP
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START DOWN
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START UP
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START DOWN
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START UP
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START DOWN
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START UP
D/dalvikvm( 1687): GC freed 9526 objects / 375728 bytes in 66ms
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START DOWN
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START UP
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START DOWN
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START UP
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START DOWN
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START UP
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START DOWN
I/System.out( 1687): Keycode--->95
I/System.out( 1687): START UP



--
Chinese Name:Hong jiu jin
Android,Internet of Things,Embedded System Design and Develop
English Name:Tommy
Tel: +86 1367514 8249
Skype ID:hongjiujing 
Blog: http://internetofthings.blogbus.com/
Country:China
There are three types of people in this world: those who make things happen, those who watch things happen and those who wonder what happened.

ESL_Phani RajKiran

unread,
Oct 15, 2011, 1:50:01 PM10/15/11
to hongj...@gmail.com, android-...@googlegroups.com, android...@googlegroups.com
Hi friend 

Please find the standard document.

Keymaps and Keyboard Input

This document describes how keyboard input gets translated into Android actions and how you can customize key layout and key character maps to match the needs of your own device.

Android uses the standard Linux input event device (/dev/event0) and driver as described in the linux/input.h kernel header file. For more information regarding standard Linux input drivers, please see Linux Input drivers at http://kernel.org.

Functionality

Android's input event device is structured around an interrupt or polling routine that captures the device-specific scancode and converts it to a standard form acceptable to Linux (as defined in input.h) before passing it to the kernel with input_event().

The keymap driver's other primary function is to establish a probe function that sets up the interrupt or polling function, handles hardware initialization, and attaches the driver to the input subsystem with input_register_device().

The table below describes the steps required to translate from keyboard input to application action:

Step Action Explanation
1. Window manager reads key event from Linux keyboard driver. Events are typically positional. For example, the top-left position on a keypad returns 16 regardless of whether that key is printed with a Q (as on a QWERTY keypad) or an A (as on an AZERTY keypads). This first conversion by the Linux Keyboard Driver yields a scancode (for example, 16).
2. Window manager maps scancode to keycode. When the window manager reads a key event out of the driver, it maps the scancode to a keycode using a key layout map file. Typically, the keycode is the primary symbol screen-printed on a key. For example, KEYCODE_DPAD_CENTER is the center button on the five-way navigation control. Even though ALT + G generates a "?" character, KEYCODE_G is the keycode.
3. Window manager sends both the scancode and the keycode to the application. Both the scancode and keycode are handled by the view with focus. How the application interprets both depend on the application.

Key Layout Map

Selection of a Key Layout Map

Key layout maps are installed in /system/usr/keylayout and /data/usr/keylayout.

For each keyboard device xxx, set the android.keylayout.xxx system property (see Building New Device for help setting system properties). If you don't specify a keylayout file, Android will default to /system/usr/keylayout/qwerty.kl.

File Format

Key layout maps are stored on the device as UTF-8 text files and have the following characteristics:

  • Comments: The pound symbol (#) denotes a comment and everything after the pound symbol on a line is ignored.
  • Whitespace: All empty lines are ignored.
  • Key definitions: Key definitions follow the syntax key SCANCODE KEYCODE [FLAGS...], where SCANCODE is a number, KEYCODE is defined in your specific keylayout file (android.keylayout.xxx), and potential FLAGS are defined as follows:
    • SHIFT: While pressed, the shift key modifier is set
    • ALT: While pressed, the alt key modifier is set
    • CAPS: While pressed, the caps lock key modifier is set
    • WAKE: When this key is pressed while the device is asleep, the device will wake up and the key event gets sent to the app.
    • WAKE_DROPPED: When this key is pressed while the device is asleep, the device will wake up and the key event does not get sent to the app.

Example of a Key Layout Map File

The following code comes from android/src/device/product/generic/tuttle2.kl and is an example of a complete key layout file:

# Copyright 2007 Google Inc.

key 2     1
key 3     2
key 4     3
key 5     4
key 6     5
key 7     6
key 8     7
key 9     8
key 10    9
key 11    0
key 158   BACK              WAKE_DROPPED
key 230   SOFT_RIGHT        WAKE
key 60    SOFT_RIGHT        WAKE
key 107   ENDCALL           WAKE_DROPPED
key 62    ENDCALL           WAKE_DROPPED
key 229   MENU         WAKE_DROPPED
key 59    MENU         WAKE_DROPPED
key 228   POUND
key 227   STAR
key 231   CALL              WAKE_DROPPED
key 61    CALL              WAKE_DROPPED
key 232   DPAD_CENTER       WAKE_DROPPED
key 108   DPAD_DOWN         WAKE_DROPPED
key 103   DPAD_UP           WAKE_DROPPED
key 102   HOME              WAKE
key 105   DPAD_LEFT         WAKE_DROPPED
key 106   DPAD_RIGHT        WAKE_DROPPED
key 115   VOLUME_UP
key 114   VOLUME_DOWN
key 116   POWER             WAKE
key 212   SLASH

key 16    Q
key 17    W
key 18    E
key 19    R
key 20    T
key 21    Y
key 22    U
key 23    I
key 24    O
key 25    P

key 30    A
key 31    S
key 32    D
key 33    F
key 34    G
key 35    H
key 36    J
key 37    K
key 38    L
key 14    DEL
        
key 44    Z
key 45    X
key 46    C
key 47    V
key 48    B
key 49    N
key 50    M
key 51    COMMA
key 52    PERIOD
key 28    NEWLINE
        
key 56    ALT_LEFT
key 42    SHIFT_LEFT
key 215   AT
key 57    SPACE
key 53    SLASH
key 127   SYM
key 100   ALT_LEFT

key 399   GRAVE

Key Character Map

Selection of a Key Character Map

Key character maps are installed in /system/usr/keychars and /data/usr/keychars.

For each keyboard device xxx, set the android.keychar.xxx system property to the full path of the desired keychar file. If you don't specify a keychar file, Android will default to/system/usr/keychar/qwerty.kl.

File Format

Key character maps are stored on the device as binary resources in order to reduce loading time. Key character maps have the following characteristics:

  • Comments: The pound symbol (#) denotes a comment and everything after the pound symbol on a line is ignored.
  • Whitespace: All empty lines are ignored.
  • Column definitions: Column definitions follow the syntax columns MODIFIERS [...], where MODIFIERS are defined as follows:
    Character in MODIFIERS Corresponding bit in the modifiers
    O no modifiers
    S MODIFIER_SHIFT
    C MODIFIER_CONTROL
    L MODIFIER_CAPS_LOCK
    A MODIFIER_ALT
  • Key definitions: Key definitions have the syntax key SCANCODE CHARACTER [...] where SCANCODE is a number and CHARACTER values are either UTF-8 characters in quotation marks (for example, "a") or a numeric value that strtol can parse.

Example of a Key Character Map File

The following code comes from android/src/device/product/generic/tuttle2.kcm and represents a complete key character file:

The type line indicates what kind of keyboard your device implements. Possible types include:

  • NUMERIC: A numeric (12-key) keyboard.
  • Q14: A keyboard that includes all letters but multiple letters per key.
  • QWERTY: A keyboard with all letters and possibly numbers. This option applies to all full keyboard configurations, such as AZERTY.

# Copyright 2007 Google Inc.

[type=QWERTY]

# keycode   base    caps    fn      caps_fn number  display_label

A           'a'     'A'     '%'     0x00    '%'     'A'
B           'b'     'B'     '='     0x00    '='     'B'
C           'c'     'C'     '8'     0x00E7  '8'     'C'
D           'd'     'D'     '5'     0x00    '5'     'D'
E           'e'     'E'     '2'     0x0301  '2'     'E'
F           'f'     'F'     '6'     0x00A5  '6'     'F'
G           'g'     'G'     '-'     '_'     '-'     'G'
H           'h'     'H'     '['     '{'     '['     'H'
I           'i'     'I'     '$'     0x0302  '$'     'I'
J           'j'     'J'     ']'     '}'     ']'     'J'
K           'k'     'K'     '"'     '~'     '"'     'K'
L           'l'     'L'     '''     '`'     '''     'L'
M           'm'     'M'     '>'     0x00    '>'     'M'
N           'n'     'N'     '<'     0x0303  '<'     'N'
O           'o'     'O'     '('     0x00    '('     'O'
P           'p'     'P'     ')'     0x00    ')'     'P'
Q           'q'     'Q'     '*'     0x0300  '*'     'Q'
R           'r'     'R'     '3'     0x20AC  '3'     'R'
S           's'     'S'     '4'     0x00DF  '4'     'S'
T           't'     'T'     '+'     0x00A3  '+'     'T'
U           'u'     'U'     '&'     0x0308  '&'     'U'
V           'v'     'V'     '9'     '^'     '9'     'V'
W           'w'     'W'     '1'     0x00    '1'     'W'
X           'x'     'X'     '7'     0xEF00  '7'     'X'
Y           'y'     'Y'     '!'     0x00A1  '!'     'Y'
Z           'z'     'Z'     '#'     0x00    '#'     'Z'

COMMA       ','     ';'     ';'     '|'     ','     ','
PERIOD      '.'     ':'     ':'     0x2026  '.'     '.'
AT          '@'     '0'     '0'     0x2022  '0'     '@'
SLASH       '/'     '?'     '?'     '\'     '/'     '/'

SPACE       0x20    0x20    0x9     0x9     0x20    0x20
NEWLINE     0xa     0xa     0xa     0xa     0xa     0xa

# on pc keyboards
TAB         0x9     0x9     0x9     0x9     0x9     0x9
0           '0'     ')'     ')'     ')'     '0'     '0'
1           '1'     '!'     '!'     '!'     '1'     '1'
2           '2'     '@'     '@'     '@'     '2'     '2'
3           '3'     '#'     '#'     '#'     '3'     '3'
4           '4'     '$'     '$'     '$'     '4'     '4'
5           '5'     '%'     '%'     '%'     '5'     '5'
6           '6'     '^'     '^'     '^'     '6'     '6'
7           '7'     '&'     '&'     '&'     '7'     '7'
8           '8'     '*'     '*'     '*'     '8'     '8'
9           '9'     '('     '('     '('     '9'     '9'

GRAVE         '`'     '~'     '`'     '~'     '`'     '`'
MINUS         '-'     '_'     '-'     '_'     '-'     '-'
EQUALS        '='     '+'     '='     '+'     '='     '='
LEFT_BRACKET  '['     '{'     '['     '{'     '['     '['
RIGHT_BRACKET ']'     '}'     ']'     '}'     ']'     ']'
BACKSLASH     '\'     '|'     '\'     '|'     '\'     '\'
SEMICOLON     ';'     ':'     ';'     ':'     ';'     ';'
APOSTROPHE    '''     '"'     '''     '"'     '''     '''
STAR          '*'     '*'     '*'     '*'     '*'     '*'
POUND         '#'     '#'     '#'     '#'     '#'     '#'
PLUS          '+'     '+'     '+'     '+'     '+'     '+'

Resource Binary File Format

The file snippet above gets converted to the following by the makekcharmap tool as part of the build process. You can mmap this file in and share the approximately 4k of memory that it uses between processes to minimize load time.

Offset Size (bytes) Description
0x00-0x0b The ascii value "keycharmap1" including the null character
0x0c-0x0f padding
0x10-0x13 The number of entries in the modifiers table (COLS)
0x14-0x17 The number of entries in the characters table (ROWS)
0x18-0x1f padding
4*COLS Modifiers table. The modifier mask values that each of the columns in the characters table correspond to.
padding to the next 16 byte boundary
4*COLS*ROWS Characters table. The modifier mask values that each of the columns correspond to.

Implementing Your Own Driver (Driver Template)

The following file, pguide_events.c, illustrates how to implement an Android keymap driver.

/*
 * pguide_events.c
 *
 * ANDROID PORTING GUIDE: INPUT EVENTS DRIVER TEMPLATE
 *
 * This template is designed to an example of the functionality
 * necessary for Android to recieve input events.  The PGUIDE_EVENT
 * macros are meant as pointers indicating where to implement the
 * hardware specific code necessary for the new device.  The existence
 * of the macros is not meant to trivialize the work required, just as
 * an indication of where the work needs to be done.
 * 
 * Copyright 2007, Google Inc.
 * Based on goldfish-events.c
 *
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 


#include 
#include 



#define PGUIDE_EVENTS_INTERRUPT do{} while(0)
#define PGUIDE_EVENTS_PROBE do{} while(0)

struct event_dev {
    struct input_dev *input;
    int irq;
};

static irqreturn_t pguide_events_interrupt(int irq, void *dev_id)
{
    struct event_dev *edev = dev_id;
    unsigned type=0, code=0, value=0;

    /* Set up type, code, and value per input.h
     */
    PGUIDE_EVENTS_INTERRUPT;

    input_event(edev->input, type, code, value);
    return IRQ_HANDLED;
}

static int pguide_events_probe(struct platform_device *pdev)
{
    struct input_dev *input_dev;
    struct event_dev *edev;
    
    printk("*** pguide events probe ***\n");

    edev = kzalloc(sizeof(struct event_dev), GFP_KERNEL);
    input_dev = input_allocate_device();

    /* Setup edev->irq and do any hardware init */
    PGUIDE_EVENTS_PROBE;

    if(request_irq(edev->irq, pguide_events_interrupt, 0,
                   "pguide_events", edev) < 0) {
        goto fail;
    }
    
        /* indicate that we generate key events */
    set_bit(EV_KEY, input_dev->evbit);
    set_bit(EV_REL, input_dev->evbit);
    set_bit(EV_ABS, input_dev->evbit);

    /* indicate that we generate *any* key event */

    bitmap_fill(input_dev->keybit, KEY_MAX);
    bitmap_fill(input_dev->relbit, REL_MAX);
    bitmap_fill(input_dev->absbit, ABS_MAX);
    
    platform_set_drvdata(pdev, edev);

    input_dev->name = "pguide_events";
    input_dev->private = edev;
    input_dev->cdev.dev = &pdev->dev;
    
    input_register_device(input_dev);
    return 0;

fail:
    kfree(edev);
    input_free_device(input_dev);
    
    return -EINVAL;
}

static struct platform_driver pguide_events_driver = {
    .probe = pguide_events_probe,
    .driver = {
        .name = "pguide_events",
    },
};

static int __devinit pguide_events_init(void)
{
    return platform_driver_register(&pguide_events_driver);
}


static void __exit pguide_events_exit(void)
{
}

module_init(pguide_events_init);
module_exit(pguide_events_exit);

MODULE_DESCRIPTION("Pguide Event Device");
MODULE_LICENSE("GPL");

Sample Implementation

Assume the following for the setup of a new keypad device:

android.keylayout.partnerxx_keypad = /system/usr/keylayout/partnerxx_keypad.kl
android.keychar.partnerxx_keypad = /system/usr/keychars/partnerxx.kcm

The following example log file indicates that you have correctly registered the new keypad:

I/EventHub( 1548): New device: path=/dev/input/event0 name=partnerxx_keypad id=0x10000 (of 0x1) index=1 fd=30
I/EventHub( 1548): new keyboard input device added, name = partnerxx_keypad
D/WindowManager( 1548): Starting input thread.
D/WindowManager( 1548): Startup complete!
I/EventHub( 1548): New keyboard: name=partnerxx_keypad 
  keymap=partnerxx_keypad.kl 
  keymapPath=/system/usr/keychars/partnerxx_keypad.kcm.bin
I/ServiceManager( 1535): ServiceManager: addService(window, 0x13610)
I/EventHub( 1548): Reporting device opened: id=0x10000, name=/dev/input/event0
I/KeyInputQueue( 1548): Device added: id=0x10000, name=partnerxx_keypad, classes=1
I/KeyInputQueue( 1548):   Keymap: partnerxx_keypad.kl

The snippet above contains artificial line breaks to maintain a print-friendly document.



For S3C6410.



We already have a keyboard dirver in Linux kernel.
Next, let us notice Android that we have a keyboard.


/* gpio buttons from linux*/
static struct gpio_keys_button gpio_buttons[] = {
{
   .gpio   = S3C64XX_GPN(0),
   .code   = 116,
   .desc   = "ENDCALL",
   .active_low = 1,
   .wakeup   = 0,
},
{
   .gpio   = S3C64XX_GPN(1),
   .code   = 139,
   .desc   = "MENU",
   .active_low = 1,
   .wakeup   = 0,
},
{
   .gpio   = S3C64XX_GPN(2),
   .code   = 99,
   .desc   = "ROTATE",
   .active_low = 1,
   .wakeup   = 0,
},
{
   .gpio   = S3C64XX_GPN(3),
   .code   = 102,
   .desc   = "HOME",
   .active_low = 1,
   .wakeup   = 0,
},
{
   .gpio   = S3C64XX_GPN(4),
   .code   = 42,
   .desc   = "BACK",
   .active_low = 1,
   .wakeup   = 0,
},
{
   .gpio   = S3C64XX_GPN(5),
   .code   = 158,
   .desc   = "BACK",
   .active_low = 1,
   .wakeup   = 0,
}
};


(1)Let me see logcat information.
I/EventHub(   58): New device: path=/dev/input/event1 name=S3C TouchScreen id=0x10000 (of 0x1) index=1 fd=45 classes=0x4
E/EventHub(   58): could not get driver version for /dev/input/mice, Not a typewriter
I/EventHub(   58): New keyboard: publicID=65537 device->id=0x10001 devname='gpio-keys' propName='hw.keyboards.65537.devname' keylayout='/system/usr/keylayout/qwerty.kl' <<<<<<<<Obviously this is not wht we want
I/EventHub(   58): New device: path=/dev/input/event0 name=gpio-keys id=0x10001 (of 0x2) index=2 fd=47 classes=0x1
E/EventHub(   58): could not get driver version for /dev/input/mouse0, Not a typewriter
I/KeyInputQueue(   58): Device added: id=0x0, name=gpio-keys, classes=1
I/KeyInputQueue(   58): Device added: id=0x10000, name=S3C TouchScreen, classes=4
I/KeyInputQueue(   58):   X: min=0 max=480 flat=0 fuzz=0
I/KeyInputQueue(   58):   Y: min=0 max=272 flat=0 fuzz=0
I/KeyInputQueue(   58):   Pressure: min=0 max=1 flat=0 fuzz=0
I/KeyInputQueue(   58):   Size: unknown values
I/KeyInputQueue(   58): No virtual keys found

(2)make a file build/target/board/idea6410/gpio-keys.kl
key 158   BACK              WAKE_DROPPED
key 139   MENU              WAKE_DROPPED
key 102   HOME              WAKE
key 116   ENDCALL           WAKE_DROPPED
key 99    ROTATOR
key 42   POWER      WAKE

(3)make another file build/target/board/idea6410/gpio-keys.kcm
First,I just copy it from tutule2.kcm,but it does not work.
So I find this form net,just a little change.
It seems like 9 number keyboard more than qwerty.

[type=QWERTY]                                           
                                                        
# keycode       display number base    caps    fn      caps_fn
                                                        
A               'A'     '2'     'a'     'A'     '#'     0x00
B               'B'     '2'     'b'     'B'     '<'     0x00
C               'C'     '2'     'c'     'C'     '9'     0x00E7
D               'D'     '3'     'd'     'D'     '5'     0x00
E               'E'     '3'     'e'     'E'     '2'     0x0301
F               'F'     '3'     'f'     'F'     '6'     0x00A5
G               'G'     '4'     'g'     'G'     '-'     '_'
H               'H'     '4'     'h'     'H'     '['     '{'
I               'I'     '4'     'i'     'I'     '$'     0x0302
J               'J'     '5'     'j'     'J'     ']'     '}'
K               'K'     '5'     'k'     'K'     '"'     '~'
L               'L'     '5'     'l'     'L'     '''     '`'
M               'M'     '6'     'm'     'M'     '!'     0x00
N               'N'     '6'     'n'     'N'     '>'     0x0303
O               'O'     '6'     'o'     'O'     '('     0x00
P               'P'     '7'     'p'     'P'     ')'     0x00
Q               'Q'     '7'     'q'     'Q'     '*'     0x0300
R               'R'     '7'     'r'     'R'     '3'     0x20AC
S               'S'     '7'     's'     'S'     '4'     0x00DF
T               'T'     '8'     't'     'T'     '+'     0x00A3
U               'U'     '8'     'u'     'U'     '&'     0x0308
V               'V'     '8'     'v'     'V'     '='     '^'
W               'W'     '9'     'w'     'W'     '1'     0x00
X               'X'     '9'     'x'     'X'     '8'     0xEF00
Y               'Y'     '9'     'y'     'Y'     '%'     0x00A1
Z               'Z'     '9'     'z'     'Z'     '7'     0x00
                                                        
# on pc keyboards
COMMA           ','     ','     ','     ';'     ';'     '|'
PERIOD          '.'     '.'     '.'     ':'     ':'     0x2026
AT              '@'     '0'     '@'     '0'     '0'     0x2022
SLASH           '/'     '/'     '/'     '?'     '?'     '\'
                                                        
SPACE           0x20    0x20    0x20    0x20    0xEF01 0xEF01
ENTER         0xa     0xa     0xa     0xa     0xa     0xa
                                                        
TAB             0x9     0x9     0x9     0x9     0x9     0x9
0               '0'     '0'     '0'     ')'     ')'     ')'
1               '1'     '1'     '1'     '!'     '!'     '!'
2               '2'     '2'     '2'     '@'     '@'     '@'
3               '3'     '3'     '3'     '#'     '#'     '#'
4               '4'     '4'     '4'     '$'     '$'     '$'
5               '5'     '5'     '5'     '%'     '%'     '%'
6               '6'     '6'     '6'     '^'     '^'     '^'
7               '7'     '7'     '7'     '&'     '&'     '&'
8               '8'     '8'     '8'     '*'     '*'     '*'
9               '9'     '9'     '9'     '('     '('     '('
                                                        
GRAVE           '`'     '`'     '`'     '~'     '`'     '~'
MINUS           '-'     '-'     '-'     '_'     '-'     '_'
EQUALS          '='     '='     '='     '+'     '='     '+'
LEFT_BRACKET    '['     '['     '['     '{'     '['     '{'
RIGHT_BRACKET   ']'     ']'     ']'     '}'     ']'     '}'
BACKSLASH       '\'     '\'     '\'     '|'     '\'     '|'
SEMICOLON       ';'     ';'     ';'     ':'     ';'     ':'
APOSTROPHE      '''     '''     '''     '"'     '''     '"'
STAR            '*'     '*'     '*'     '*'     '*'     '*'
POUND           '#'     '#'     '#'     '#'     '#'     '#'
PLUS            '+'     '+'     '+'     '+'     '+'     '+'
                                                        
                                                        
                                                        
(4)add these to AndroidBoard.mk

file := $(TARGET_OUT_KEYLAYOUT)/gpio-keys.kl
ALL_PREBUILT += $(file)
$(file) : $(LOCAL_PATH)/gpio-keys.kl | $(ACP)
$(transform-prebuilt-to-target)

include $(CLEAR_VARS)
LOCAL_SRC_FILES := gpio-keys.kcm
include $(BUILD_KEY_CHAR_MAP)

(5)add these to system.prop
android.keylayout.gpio-keys = /system/usr/keylayout/gpio-keys.kl
android.keychar.gpio-keys = /system/usr/keychars/gpio-keys.kcm

(6)build your system again
Now we can see the different:

I/EventHub(   63): New device: path=/dev/input/event1 name=S3C TouchScreen id=0x10000 (of 0x1) index=1 fd=50 classes=0x4
E/EventHub(   63): could not get driver version for /dev/input/mice, Not a typewriter
E/KeyLayoutMap(   63): /system/usr/keylayout/gpio-keys.kl:10: expected keycode, got 'ROTATOR'
I/EventHub(   63): New keyboard: publicID=0 device->id=0x10001 devname='gpio-keys' propName='hw.keyboards.0.devname' keylayout='/system/usr/keylayout/gpio-keys.kl'<<<<<<<<OK correct!
I/EventHub(   63): New device: path=/dev/input/event0 name=gpio-keys id=0x10001 (of 0x2) index=2 fd=52 classes=0x1
E/EventHub(   63): could not get driver version for /dev/input/mouse0, Not a typewriter
I/KeyInputQueue(   63): Device added: id=0x0, name=gpio-keys, classes=1
I/KeyInputQueue(   63): Device added: id=0x10000, name=S3C TouchScreen, classes=4
I/KeyInputQueue(   63):   X: min=0 max=480 flat=0 fuzz=0
I/KeyInputQueue(   63):   Y: min=0 max=272 flat=0 fuzz=0
I/KeyInputQueue(   63):   Pressure: min=0 max=1 flat=0 fuzz=0
I/KeyInputQueue(   63):   Size: unknown values
I/KeyInputQueue(   63): No virtual keys found


System do not know the word "ROTATOR" presently.
You can add a USB-KEYBOARD too.


Phanirajkiran.

mp...@embeddedsoftwarelabs.com

8790571697.






Navaneeth Sen B.

unread,
Oct 20, 2011, 6:20:13 AM10/20/11
to android...@googlegroups.com, android-...@googlegroups.com
Thanks for the Guide friend.
Right now i have a problem. I have mapped my new keys to the platform following your guide, but i am not able to get the repeatKey status.
I have Android froyo running on my custom MIPS platform.
I have written a test application, which try to trap the keyEvents. I tried to see if i can get the getRepeatCount value when i am doing a
continuous key press. But it is always returning zero.

But this correctly working in the Emulator(x86) and it is returning a non-zero value.

Could you shed some light into it. Do i need to make some patch in the Event handling section in the framework?


venkat k raju

unread,
Mar 9, 2012, 9:19:30 PM3/9/12
to sen4...@gmail.com, android...@googlegroups.com, android-...@googlegroups.com
Hi ESL_Phani RajKiran,

i want to integrate  power on/off key to my keyboard button.
here what i did in driver part is i had included KEY_POWER key in  keymap structure. then i tested and result was lcd and all going sleep mode . but how to resume again normal state, for this which key i have to use.

can you suggest me.






--
thanks&Regards
k.v.raju

venkat k raju

unread,
Mar 9, 2012, 9:21:36 PM3/9/12
to android-porting, rowboat, ESL_Phani RajKiran

Hi ESL_Phani RajKiran,

i want to integrate  power on/off key to my keyboard button.
here what i did in driver part is i had included KEY_POWER key in  keymap structure. then i tested and result was lcd and all going sleep mode . but how to resume again normal state, for this which key i have to use.

can you suggest me.



 
thanks&Regards
k.v.raju

Alvin Wong

unread,
Mar 10, 2012, 12:08:27 PM3/10/12
to android-porting
Isn't that you would need to set the key as a standard Linux wake
source?

venkat k raju

unread,
Mar 12, 2012, 8:24:36 AM3/12/12
to alvin...@gmail.com, android-porting
Hi Alvin Wong,
i am sorry i didn't get you .what your saying?





--
thanks&Regards
k.v.raju

venkat k raju

unread,
Mar 14, 2012, 2:10:52 AM3/14/12
to alvin...@gmail.com, android-porting, ESL_Phani RajKiran, rowboat
Hi all,

i have mapped  KEY_POWER flag to on of my 4x4 keypad button,when i pressed it power off android pop-up is coming with an option of power-off. if i choose power-off option then my lcd is going sleep mode.
can any body suggest me how wake-up again to normal mode.

i tried with command mode like this

#echo "1" > /sys/devices/platform/omapdss/display0/enabled

then i am able to resume lcd, but that power-off pop-up window still there...with busy symbol.

thanks in advance
--
thanks&Regards
k.v.raju

Alvin Wong

unread,
Mar 15, 2012, 11:58:33 PM3/15/12
to venkat k raju, rowboat, ESL_Phani RajKiran, android-porting

If you want to go into sleep mode you should single-press the power key, not long-pressong it.

For Power Off, can you check `dmesg` that whether there is a line 'System halted'? If yes you may need to check the power off sequence in kernel.

If you 'Power Off'ed, your device is supposed to turn off. If it is power off'ed correctly, the CPU should have some ways to get it on again, e.g. a  real power key.

Reply all
Reply to author
Forward
0 new messages