This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Hardware buttons in android custom device

Other Parts Discussed in Thread: AM3352

Hello

I'm designing android device with ANDROID ICS. I need to use only 4  hardware buttons in my device

1--> Menu

2-->Home

3-->Back

4-->Power ON/OFF

I'm clear about Home,Back,Menu buttons from the android porting guide from TI Wiki, but very confusing about POWER ON/OFF button. 

Can any one advice me that how can i assign the key for  power ON/OFF ?

Thanks in advance. 

  • You need to define the Power Key in the .kl file corresponding to your keypad driver name.

    You can refer to the omap3evm sources:

    http://gitorious.org/rowboat/vendor-ti-omap3evm/blobs/rowboat-ics/TWL4030_Keypad.kl

  • Hi,

    You can use the standard POWER button for android. This key will have the functionality to Sleep/Wake on short press, and power down on long press.

    For this you can add an entry to the .kl file in your device directory.

    For example you can add to your keys.kl:

    key 28    POWER              WAKE

    Also you can refer to the following page for further information on key mapping on Android:

    http://source.android.com/tech/input/key-layout-files.htm

    Regards,

    Umakanta


  • Thanks for your reply

                Sorry for not disclose my device details here. I'm using AM3352 i'm designing schematic with the reference of AM335x EVM and Beaglebone.

    We decided to use only four buttons as mentioned above. We need to connect the button any of GPIO pin in processor . I'm very confused about at which pin i have to connect this buttons in my schematic.

    key 116 POWER WAKE
    key 102 HOME WAKE
    key 158 BACK WAKE_DROPPED
    key 229 MENU WAKE_DROPPED
    These are the key i'm going to be use.
    Can anyone clear me that how can i associate the KEY and its value with the GPIO. 

    Thanks in advance.

  • Hi Sangili,

    If you want any key to be acting as wake up key, please take a GPIO from GPIO bank 0 (1-32). GPIO bank 0 is in wake up domain.

    GPIO number to KEY number mapping is done in board file. You can check the arch/arm/mach-omap2/board-am335xevm.c

    You can map any GPIO number to any Key number.

    Key number to Android function mapping is done in the keylayout(kl) file as explained above.

    It is advisable to have POWER OFF/ON button maps to GPIO bank 0.

  • Thanks Mr.Arun Joseph.

  • I have add the this code in board-am335xevm.c ( using BEAGLEBONE REV A5)

    static struct gpio_keys_button BB_gpio_buttons[] = {
            {
                    .code                  = KEY_HOME,
                    .gpio                   = GPIO_TO_PIN(1,16),
                    .active_low        = true,
                    .desc                  = "Home",
                    .type                    = EV_KEY,
                    .wakeup             = 1,
            },
           {         .code                  = KEY_BACK,
                    .gpio                   = GPIO_TO_PIN(1,17),
                    .active_low         = true,
                    .desc                   = "Back",
                    .type                     = EV_KEY,
                    .wakeup              = 1,
            },
    };
    
    static struct gpio_keys_platform_data BB_gpio_key_info = {
            .buttons        =BB_gpio_buttons'
            .nbuttons       = ARRAY_SIZE(BB_gpio_buttons),
    };
    
    
    I'm using beaglebone. GPIO1_16, GPIO1_17 is available in header, so i am plan to use this. Its complied successfully and i have converted as image. then i have create the KEY layout file as 
    key 49 BACK WAKE_DROPPED
    key 48 HOME WAKE
    Then i  have booted the beaglebone and execute the " getevent " but my gpio-keys in not there.

    root@android:/ # getevent
    add device 1: /dev/input/event1
    name: "lm75-temp"
    add device 2: /dev/input/event0
    name: "lm75-temp"
    could not get driver version for /dev/input/mice, Not a typewriter

    I dono where i did the mistake, and can anyone explain how to configure the PINMUX for this GPIO and how to initiate the GPIO configuration..


  • Hello,

    These are the suggestions, you can follow/take care of:

    -> Enable the macro "CONFIG_KEYBOARD_GPIO" from your menuconfig. This enables the "gpio_keys" driver.

    -> Then there should be a platform data initialized from your board file, as following:

    static struct platform_device BB_gpio_keys = {
        .name = "gpio-keys",
        .id = -1,
        .dev = {
            .platform_data = &BB_gpio_key_info,

        },

    };

    -> And then the keypad platform device should be registered in your init function, as:

    platform_device_register(&BB_gpio_keys);

    If you have made sure, all three steps are executed properly, then you should be finding your gpio driver node while executing getevent, for example:

    root@android:/ # getevent
    could not get driver version for /dev/input/mice, Not a typewriter
    add device 1: /dev/input/event1
    name: "gpio-keys"
    add device 2: /dev/input/event0
    name: "ti-tsc-adcc"
    could not get driver version for /dev/input/mouse0, Not a typewriter

    And, if you are able to get the input node, then your keypad events will get displayed here.

    Next this can be used in your .kl file to map to the Android Key codes, which is described in the page: http://processors.wiki.ti.com/index.php/TI-Android-ICS-PortingGuide#Android_Keypad_Configuration

    Hope, this helps.

    Regards,

    Umakanta Patro

  • Thnks Mr.Umakanta 

    I tried the steps what you have mentioned here, but till i cant get the GPIO driver node. I have write the details below.

    1--> configured the GPIO driver  cd AOSP/kernel$ make menuconfig  in this i've select device drivers-->Inputdrivers-->keypad-->Gpio Buttons and GPIO driven matrix    keypad its selected as default 

    2--> my coding is 

    static struct gpio_keys_button BB_gpio_buttons[] = {
    {
    .code = KEY_HOME,
    .gpio = GPIO_TO_PIN(1, 16),
    .active_low = true,
    .desc = "volume-up",
    .type = EV_KEY,
    .wakeup = 1,
    },
    {
    .code = KEY_BACK,
    .gpio = GPIO_TO_PIN(1, 17),
    .active_low = true,
    .desc = "volume-down",
    .type = EV_KEY,
    .wakeup = 1,
    },
    };

    static struct gpio_keys_platform_data BB_gpio_key_info = {
    .buttons = BB_gpio_buttons,
    .nbuttons = ARRAY_SIZE(BB_gpio_buttons),
    };

    static struct platform_device BB_user_keys = {
    .name = "gpio-keys",
    .id = -1,
    .dev = {
    .platform_data = &BB_gpio_key_info,
    },
    };

    Its my coding written in board-am335xevm.c. i didn't implement PINMUX here. then i build the ANDROID source

    3--> Then i have registered the keypad device in init.rc as platform_device_register(&BB_user_keys);

                After complete these steps i have boot my device( Beaglebone REV A5) then execute the getevent its displays.

    root@android:/ #getevent 

    add device 1 : /dev/input/event1

        name: "lm75-temp"

    add device 2 : /dev/input/event0

        name: "lm75-temp"

    could not get drivers version for /dev/input/misc, Not a typewriter

         Here i didnt get my "gpio-keys" 

    Here i've enclosed my Gpio button implementaion just only one button conected with GPIO1_16 (p9-15)  

     Its my switch setup in Beaglebone.

    Can you guess where i did mistake, or i've to change anyother files or lines..?

    where i have to register my keypad device in inti.rc is there any specific section ?

    Guide me to fix this..

    Thanks in advance..!!


  • Hello,

    I meant you should register the keypad platform device in your init function in  your board file i.e. board-am335xevm.c, not in init.rc

    Also, note you need to carry out the pinmux initialization as well, to get your GPIO1 16 and 17 to act as GPIO.

    So, you can implement the below code, in addition to your existing code:

    static struct pinmux_config BB_user_keys_pin_mux[] = {
    {"gpmc_a0.gpio1_16", OMAP_MUX_MODE7 | AM33XX_PIN_INPUT},
    {"gpmc_a1.gpio1_17", OMAP_MUX_MODE7 | AM33XX_PIN_INPUT},
    {NULL, 0},
    };

    static void lcd_cape_keys_init(int evm_id, int profile)

    {
    int err;
    setup_pin_mux(BB_user_keys_pin_mux);
    err = platform_device_register(&BB_user_keys);
    if (err)
    pr_err("Failed to register Keypad for Beaglebone LCD cape\n");
    }

    And call the "lcd_cape_keys_init()", from the function where you execute your LCD and touch screen init functions.

    Also, do verify all your configurations, against the rowboat kernel for Beaglebone Key setup.

    Regards,

    Umakanta Patro

  • Thanks lot Mr.Umakanta Patro, you made my day.

    Your reply make me understand about boardconfig and gpio config. As per my knowledge the gpio keys were already written in board-am335xevm.c its written and called under lcd_cape function. Regarding the flow board-am335xevm.c check the EEPROM in lcd_cape when its pluged and call the lcd_cape_keys_init function so its activated as default when the lcd_cape plug with the beaglebone.

    By this knowledge i done the following things.

     copied the lcd_cape_keys_init(DEV_ON_DGHTR_BRD, PROFILE_NONE); from the board-am335xevm.c and i have paste under the dvi_init( DEV_ON_DGHTR_BRD, PROFILE_NONE); function. Hence when the Beaglebone activate the DVI_cape the LCD_cape_keys also configured as default.

    else{
    /* Setup DVI display if daughter card detected is not LCD cape. */
             dvi_init( DEV_ON_DGHTR_BRD, PROFILE_NONE);
             lcd_cape_keys_init(DEV_ON_DGHTR_BRD, PROFILE_NONE);
             return;
    }

    Then i booted my device and execute the " getevent" and its shows as

    add device 1: /dev/input/event1

       name:  "lm75-temp"

    add device 2: /dev/input/event0

       name:  "lm75-temp"

    could not get driver version for /dev/input/mice, Not a typewriter

    add device 3: /dev/input/event2

       name:  "gpio-keys"

    So my gpio driver node is enabled.

    But when i press the button i cant get the event like this

        /dev/input/event0: 0004 0004 00000002
        /dev/input/event0: 0001 009e 00000001
        /dev/input/event0: 0000 0000 00000000
        /dev/input/event0: 0004 0004 00000002
    At where i did the mistake,Its confusing me lot.   
    My circuit for gpio is mentioned in previous reply. 
    i have checked by root@android:/# cat /dev/input/event2 in this also no response 
    Can you guess my mistake.?
    I hope i'm very near to complete this. so can you help me.?
    Thanks in advance
    Regards
    Sangilikumar M


     


  • Hey,

    Glad to know, that you are getting your event node created.

    I checked your circuit for button, it looks fine to me. To verify the hardware setup generates interrupt, you can probe for a active LOW pulse on your button press by using a Multimeter or a Oscilloscope. And make sure, the same pulse reaches to any closest TP(Test point) for the pin GPIO1_16 to the controller.

    Mostly it looks as some hardware connectivity issue to me, as the initialization and the setup is done properly in kernel.

    Regards,

    Umakanta Patro

  • Thanks Mr.Umakanta Patro

         I have completed this task. I'm very happy to say this. you made my day. Its working fine. some prob in hardware i fixed it by testing with multi meter.

    Really i'm thankful to you. 

    Regards

    Sangilikumar M

  • You are Wel Come... :-)

  • Hello Mr.Umakanta Patro

    Have you handled USER LED in android via GPIO, or do you have idea about it.?

    I have explained my problem here, kindly see that and give me a idea if you aware of it.

    http://e2e.ti.com/support/embedded/android/f/509/p/212782/751724.aspx#751724

    Regards

    Sangilikumar M 


  • Hi ,

    Is there any way to handle the same from linux, where getevent is not found.

    I am trying to do the same and poll the value using cat but i have not observed any changes.

    Regards

    chandu

  • Hi chandu

             Are your sure dev node got created for our keypad ?

            If its created try to trace from dev node. i meant  cat /dev/<path to input node> you can observe something against your keypad status. 

         

    Regards

    Sangilikumar M

  • Hi Sangilikumar,

    Yes dev node got created for you keypad under /dev/input/by-path/ .

    I am trying to cat the event to capture the response (directly connecting a 3.3 v wire to pin and releasing instead of button), but i could not get the response.

    Now i have connected a button and tested the same we are getting proper output.

    So we have taken a evtest source to test this gpio keys, and it is working as expected.

    Thanks

    Chandu