Wednesday, March 24, 2010

GPIO solution found!!!

First of all, thanks to Project Kennel.
http://www.projectkennel.com/phpBB3/viewtopic.php?f=4&t=3

There are 5 files you might need when using GPIO. They are
=========================
arch/arm/plat-omap/include/mach/mux.h
============================
This file defines the name of the GPIO. You can change your GPIO name in here. The name can be anything you want. The same reference name will be used thereafter. A good idea will be following the same pattern. For example GPIO133, the name should be: AH4_34XX_GPIO133_DOWN

Since you are switch the mux from MODE0 to MODE4, you have to comment out the AH4_3430_MMC2_DAT1 line in the same file.


=========================
arch/arm/mach-omap2/mux.c
=========================
This file defines the register of the GPIO. This is the most important file. It defines the register location, the MUX mode and I/O. For the GPIO133 example, you can use:

MUX_CFG_34XX("AH4_34XX_GPIO133_DOWN", 0x15e,
OMAP34XX_MUX_MODE4 | OMAP34XX_PIN_INPUT_PULLDOWN)

Once again, the MMC2_DAT1 should be commented out. If you forget this, the MUX will be set to MODE0 again somewhere.

//MUX_CFG_34XX("AH4_3430_MMC2_DAT1", 0x15e,
// OMAP34XX_MUX_MODE0 | OMAP34XX_PIN_INPUT_PULLUP)

=========================
include/linux/input.h
=========================
Key definitions. There is nothing you need to change here. This file is a reference file. You will need to map your GPIO input as a button. Each button has a name. The name is define in this file. For example:
#define BTN_BACK 0x116
BTN_BACK is the name we are going to use in the kernel file. 278, which is 0x116, will be used in the python code for identification. The USER button use BTN_EXTRA, code 276.



=========================
arch/arm/mach-omap2/devices.c
=========================
This file initializes several devices. If you are following the example so far, you are using GPIO133, which is MMC2_DAT1. Therefore, you have to commented out that line to remove the conflict.

=========================
arch/arm/mach-omap2/board-omap3beagle.c
=========================
This file init the board. All the additional extra key, led, and touch screens will be inited here. The line you want to add is. In this file, you also link the GPIO133 to a user button code 278

---------
static struct gpio_keys_button gpio_buttons[] = {
{
.code = BTN_EXTRA, // User button returns code BTN_EXTRA
.gpio = 7, //User button gpio 7
.desc = "user",
.wakeup = 1,
},

++++++++++++++

{
.code = BTN_SIDE, //give a mapped code name. Find the code in the input.h.
.gpio = 133, //The gpio number, someone said you need the full name.
.active_low = 1, //active low, refer the mux.c file (PULLDOWN)
.desc = "Side button 278", //description, used in the /proc/interrupts
.type = EV_KEY, //Not sure we need it. Indicate it's an event triggered key. The other type is EV_SW. check include/linux/gpio_keys.h for more info
.wakeup = 0,
},
++++++++++++++

};
----------------

I also add another line in:
----------------
static void __init omap3_beagle_init(void)
{
omap3_beagle_i2c_init();
+ omap_cfg_reg(AH4_34XX_GPIO133_DOWN); //I think it will be inited in the next line. well, just to be safe.
platform_add_devices(omap3_beagle_devices,
ARRAY_SIZE(omap3_beagle_devices));
----------------


So far, you should be ok to go. Your GPIO-133, expansion pin 15, will generate an event in /dev/input/event0 if you press the tie down button connected to it. The python code will be introduced later. Your /proc/interrupts file will record all the interrupts. Every time you tie down your GPIO133, the number increase twice.

No comments:

Post a Comment