GPIO Access

jdmulloy

New member
For our project we're considering adding push button or two instead of using the touchscreen so that we can make our project more robust by putting the display behind a piece of clear plastic. Unfortunately the placement of the buttons on the top of the CFA don't really work for our purposes. As far as I can tell we have 4 options.

1. Attach our buttons to some GPIOs via the connector on the debug board
2. Solder wires to the CFA to replace the stock buttons
3. Make some sort of USB keyboard device and attach it to the USB port
4. Make a pushbutton circuit that communicates over I2C

We have 15 days left so we'd prefer to go with one of the first 2 since they should hopefully be easy and reliable.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

jdmulloy

New member
I think I can find the code to work with the GPIOs in the kernel sources linked to in the other thread about the buttons and LEDs. The only question left is about the hardware side. I probed the GPIOs on the header on the debug board and they were all HIGH (3.3V). However I have no idea if they were set to Input or Output mode. I'm assuming that they are pulled high on the board. To use them for input can I connect them directly to ground or do I need to use a pull down resistor? If so what resistor value is ideal?

Thanks
 

CF Support

Administrator
There is this demo tool here:

https://github.com/crystalfontz/at91sam9g45_tools/blob/master/mem.cpp

This tool maps the physical address to a virtual address so you can act on it.

This example would write a 32 bit value of 0x1 to the physical address at 0xffffe200.

Code:
root@cfa10022# ./mem --write=0xffffe200 --bits=32 --value=0x00000001
You can then use that pattern to write or read the hardware addresses and toggle pins as you need to. Alternatively if you are doing i/o in the kernel you can use the kernel gpio routines.

The GPIOs are listed in the datasheet with their atmel processor mappings. All gpio's start up as inputs pulled-up to 3.3V if they have not been configured. You can connect them directly ground and read them. I would go with choice 1.
 

jdmulloy

New member
Thanks this is very helpful. I can't believe I missed that table in the data sheet.

Thank you for all of your help. I'll post some pics and info about our project when it's done.
 

jdmulloy

New member
Thinking about this a bit more I think the ideal solution would be to patch the kernel so that the GPIOs exposed on the header produce key presses like the buttons on the top of the display. I think I I found the code that does this but I do have a question about it. From the cod it looks like the buttons on the top of the screen are supposed to produce Left and Right mouse clicks but what I actually experience on the CFA-910 is key presses for "q" and "w". Perhaps the kernel that came installed on our CFA-910 is older and the mapping was changed from key presses to mouse clicks. This is the kernel code I am referring to.

Code:
static struct gpio_keys_button cfa_10022_buttons[] = {
	{	/* S1, "rightclick" */
		.code		= BTN_RIGHT,
		.gpio		= AT91_PIN_PD30,
		.active_low	= 1,
		.desc		= "right_click",
		.wakeup		= 1,
		.debounce_interval = 70,
	},
	{	/* S2, "leftclick" */
		.code		= BTN_LEFT,
		.gpio		= AT91_PIN_PD29,
		.active_low	= 1,
		.desc		= "left_click",
		.wakeup		= 1,
		.debounce_interval = 70,
	},
	{	/* SW_WAKE, "wakeup/shutdown gpio" */
		.code		= KEY_POWER,
		.gpio		= AT91_PIN_PB30,
		.active_low	= 1,
		.desc		= "wake_shdn",
		.wakeup		= 1,
		.debounce_interval = 70,
	},
};
File: board-cfa10022.c

I'm thinking if I add more entries as shown below I can generate more key presses with the GPIOs on the header on the debug board.

Code:
static struct gpio_keys_button cfa_10022_buttons[] = {
	{	/* S1, "rightclick" */
		.code		= BTN_RIGHT,
		.gpio		= AT91_PIN_PD30,
		.active_low	= 1,
		.desc		= "right_click",
		.wakeup		= 1,
		.debounce_interval = 70,
	},
	{	/* S2, "leftclick" */
		.code		= BTN_LEFT,
		.gpio		= AT91_PIN_PD29,
		.active_low	= 1,
		.desc		= "left_click",
		.wakeup		= 1,
		.debounce_interval = 70,
	},
	{	/* SW_WAKE, "wakeup/shutdown gpio" */
		.code		= KEY_POWER,
		.gpio		= AT91_PIN_PB30,
		.active_low	= 1,
		.desc		= "wake_shdn",
		.wakeup		= 1,
		.debounce_interval = 70,
	},
	{	/* GPIO0 */
		.code		= KEY_0,
		.gpio		= AT91_PIN_PE0,
		.active_low	= 1,
		.desc		= "0_key",
		.wakeup		= 1,
		.debounce_interval = 70,
	},
	{	/* GPIO1 */
		.code		= KEY_1,
		.gpio		= AT91_PIN_PE1,
		.active_low	= 1,
		.desc		= "0_key",
		.wakeup		= 1,
		.debounce_interval = 70,
	},
};
 

CF Support

Administrator
That should generate the key presses you're looking for. You'll need to look at the appropriate header files for the valid key macros.

You may want to look at how other platforms do the same thing in order to get other ideas.

We look forward to hearing more about your project.
 

jdmulloy

New member
Well I think I've managed to build a kernel that has the changes I need. I won't have a chance to try this for a few days but I post again after I've tried it. Hope it works.
 
Top