Blackberry's Pearl controlled with ARM7

I found really interesting a small protoboard created by Sparkfun that allows you to easily connect a Pearl (the one made famous by RIM / Blackberry devices) with a microcontroller. This time I choose the LPC2138 from NXP because I also have a complete 2D graphic engine for interfacing the LPC2138 with a Nokia 128×128 LCD with 16 bits per pixel. One issue with this device is that a small movement on the pearl is detected. And sometimes you want to move in a direction but this little ball moves in more than one direction at a time. So the big problem was designing a software able to detect the movements correctly, providing anti bouncing and a way to easily modify how many pulses of the pearl are detected as one movement.



void pearl_Task() {
    if ((!(PEARL_INPUT_PIN & (1 << PEARL_LEFT_PIN))) && (pearl_state_left == 0)) {
        pearl_dir_left_changes++;
        pearl_state_left = 1;
    }
    else if (((PEARL_INPUT_PIN & (1 << PEARL_LEFT_PIN)))
                  && (pearl_state_left == 1)) {
        pearl_dir_left_changes++;
        pearl_state_left = 0;
    }
    if ((!(PEARL_INPUT_PIN & (1 << PEARL_RIGHT_PIN))) && (pearl_state_right == 0)) {
        pearl_dir_right_changes++;
        pearl_state_right = 1;
    }
    else if (((PEARL_INPUT_PIN & (1 << PEARL_RIGHT_PIN)))
                  && (pearl_state_right == 1)) {
        pearl_dir_right_changes++;
        pearl_state_right = 0;
    }
    if ((!(PEARL_INPUT_PIN & (1 << PEARL_DOWN_PIN))) && (pearl_state_down == 0)) {
        pearl_dir_down_changes++;
        pearl_state_down = 1;
    }
    else if (((PEARL_INPUT_PIN & (1 << PEARL_DOWN_PIN)))
                  && (pearl_state_down == 1)) {
        pearl_dir_down_changes++;
        pearl_state_down = 0;
    }
    if ((!(PEARL_INPUT_PIN & (1 << PEARL_UP_PIN))) && (pearl_state_up == 0)) {
        pearl_dir_up_changes++;
        pearl_state_up = 1;
    }
    else if (((PEARL_INPUT_PIN & (1 << PEARL_UP_PIN)))
                  && (pearl_state_up == 1)) {
        pearl_dir_up_changes++;
        pearl_state_up = 0;
    }
}


This task can be perform in a main loop, or can be called by a timer when it overflows (as I do in my code). The following piece of code is an example of how to ask if a movement in a particular direction was performed.



unsigned char pearl_IsMovingLeft() {
	if (pearl_dir_left_changes >= PEARL_DIR_LEFT_LIMIT) {
		pearl_dir_left_changes = 0;
		return 1;
	}
	return 0;
}


Where if PEARL_DIR_LEFT_LIMIT is between 3 or 5 and you run the pearl task every 50mSec the movement is quite smooth.

Pearl (Blackberry’s Trackball) Driver [Header]

Pearl (Blackberry’s Trackball) Driver [Source]

Trackball schematic

ARM7 Programming under Mac OS X: Part 1 – ISP

Programming on a Mac is quite similar as you do on a Linux PC, and developing for ARM7 is not the exception. In this first post I’ll show you how to setup the In System Programming feature of the LPC2138/01 in your Mac, and check that the MCU is communicating successfully with your Mac.
The first thing you have to download  is lpc21isp, this minimalistic piece of software is a programming tool that communicates with the ARM7 bootloader. You can find it at Yahoo Groups (http://tech.groups.yahoo.com/group/lpc21isp/). The lastest version (lpc21isp_180) is OS-X compatible.
Once you have it in your disk, unpack (yes, this is done automatically once downloaded) and open a Terminal. Locate the unpacked folder and type ‘make -f Makefile clean all’. This  should produce an output as you see in this screenshot

The result of the build process produces a file called “lpc21isp” which is executable. You have to invoce this file specifying the operations to perform, the serial port, the speed of the serial port, and the xtal frecuency in KHz.

For locating the serial port on a Mac, just look into /dev. In my enviroment I was using a custom USB-RS232 I have created a long time ago, which OS X identifies as /dev/tty.usbserial-A800cwuH

The following image shows how to invoke a detection and its result.

While lpc21isp says “Synchronizing” you should enter bootloader mode by holding P0.14 in low and performing a reset.

Last, but not least, here there are some pictures of the LPC2138/01 board and the Mac. The LPC2138/01 is mounted on an adapter I made, and near that adapter you can see the RS232 to USB adapter. Everything is powered with a 3.3V power supply.