Sunday, July 02, 2006

Pinning down the UI

I have had a quick look at the LPC2148 user manual in the Device Database here

In chapter 8, I found that the LPC2148 has 2x32 bit GPIO I/O ports which I can configure to drive or be driven by all manner of things on the chip, one bit of which I could use for the LogStick's button. It's possible to poll the pins to see if they go high or low and it's also possible to connect some of them to such things as the chips external interrupts. Ultimately, the button should generate an interrupt that can trigger a state change. For now, for proof of concept of the button, I will initially work on polling the state of a pin connected to GPIO.

Looking at the examples in the RealView Microcontroller Development Kit, the simplest example: "blinky" for the LPC family waggles GPIO pins. Running this example on the simulator in uVision allows me see the pins changing in the GPIO peripheral simulator as it runs. It seems that pretty much every peripheral on LPC is simulated apart from USB, so I won't have to move to real hardware for a while.

The blinky example certainly shows me how to change pins high and low under program control, but what I want to do is change program flow by changing pins high and low.

Looking at the LPC2148 manual tells me that the pins on the GPIO are configured for input by default and hooked to some of the external chips pins. Looking at the Pin Connect Block peripheral in the simulator in uVision verifies that this is the case.

From the user manual is see I can read the pins state by reading the IOPINn register. Running blinky again I find that by clicking on a pin in the GPIO peripheral dialog, I can change its state (provided it hasn't been configured for output -- the simulator complains if you try this, as it should). This is neat; it would take a fair bit of hacking for me to do this in real hardware. Some boards do add buttons to GPIO, true, but I don't want to get into that yet.

So I now have a crude way of changing a pins state on the chip which I can poll in my program. The following couple of Macros allow me to test the pin/button to see if it has been taken low:

#define PINMASK 0x00000001 /* Let's do pin 1 */
/* IF masked pin number is low THEN button pressed */
#define BUTTON_PRESSED ((IOPIN0 & PINMASK)== 0)


0 Comments:

Post a Comment

<< Home