Good news for those who always wanted a microtouch but didn’t have the time to build one: they are now available from the nice folks at adafruit. If you get one be sure to use the “rossum” coupon code at checkout for a 10% discount.
This version is powered by the delightful atmega32u4. It features a 320×240 pixel touchscreen, an accelerometer, full speed usb, a microsd card reader and a support for a lithium ion battery.
It has an application framework of sorts and it is possible to run a variety of applications with varying degrees of utility. Possibilites are bounded only by your imagination (and the 8 bit cpu + 2.5k of RAM). Tools support includes a PC simulator and a live sampling profiler. Code at https://github.com/rossumur/microtouch.
Building an App
Create HelloApp.cpp in apps/demos:
#include "Platform.h" class HelloState { public: int OnEvent(Event* e) { switch (e->Type) { case Event::OpenApp: Graphics.DrawString("hello",110,100,0); break; default: ; } return 0; } }; INSTALL_APP(hello,HelloState);
Build, Flash and test. You should get a little app that says ‘hello’ and never quits.
Ok. What is going on here? Microtouch as an application framework of sorts that allows multiple applications to be built into the firmware. An application is ‘installed’ with the INSTALL_APP
macro: the first parameter is the name that will appear in the shell, the second defines a c++ object that maintains the applications state.
The framework (Shell.cpp) sends events to the app thorugh the OnEvent method; in this example the app draws “hello” on the OpenApp event which will always be the first event an app will see. The most common events come from the touch screen: TouchDown, TouchMove and TouchUp.
Because there is only 2k of RAM in this device we really don’t have the luxury of things like memory managers. The applications state is all the heap it will ever know; its maximum size is defined by MAX_APP_BUFFER
in Platform.h and is set to 768 bytes by default. If the app state is larger thanMAX_APP_BUFFER
then the application won’t be visible in the ShellApp.
Lets try a slightly more complicated version:
class HelloState { public: void Draw(int x, int y, int color) { Graphics.DrawString("Hello",x-10,y-6,color); } int OnEvent(Event* e) { switch (e->Type) { case Event::OpenApp: Draw(120,160,0); break; case Event::TouchDown: if (e->Touch->y > 320) return -1; // Quit case Event::TouchMove: Draw(e->Touch->x,e->Touch->y,RandomBits(1)); break; default: ; } return 0; } }; INSTALL_APP(hello,HelloState);
Now we can scrawl lots of randomly colored hellos over the screen and we can even quit by touching the bottom of the screen. The Graphics.h api is fairly self explanatory: it uses 5:6:5 RGB color and supports circles, rectangles and blitting as well as text.
Stdout is connected to the USB serial port so feel free to use printf for debugging.
Sample Applications
There are a number of example applications that exercise various parts of system. They don’t all fit in the device at the same time. The APPLICATIONS
path in the Makefile defines which apps get built into the firmware.
Shell
The shell is the Microtouch equivalent of the Finder or Explorer. It displays a list of installed apps and files found on the microSD card, and is responsible for lauching apps and delegating file opening to the View app. It also has code for a simple serial console:
- ls – list files on microSD if present
- p1/p0 – turn profiling on/off
- lcd – dump lcd registers
- appname – launch appname if installed
Off
The simplest app. It turns the Microtouch off unless it is plugged into USB. The Microtouch will turn itself off after 5 minutes of inactivity so you don’t absolutely need this one, but I find it somehow comforting.
Calibrate
Calibrates touchscreen and stores calibration data in EEPROM. You probably will only need to run this app once if at all. Click in the red circles with a stylus until the application is satisfied with the consistency of the clicks. If you have a shattered touchscreen this app may give up after half a dozen attempts.
View
Displays files with inertial scrolling, currently IM2 files created with the MicrotouchTool are supported.
HWTest
Exercises major hardware components including touchscreen, accelerometer, microSD and backlight.
Accelerate
Accelerometer demo draws XYZ values and bounces a ball depending on the orientation of the device.
View
Displays files with inertial scrolling, currently IM2 files created with the MicrotouchTool are supported.
3D
The classic 3D Microtouch engine with accelerometer support. Tilt the device to move the object, touch the screen to select diffent platonic solids.
Pacman
Omage to the greatest game ever written, demonstrates a technique for flicker free sprites at >60Fps.
Doomed
A simple raycasting demo. Touchscreen controls speed and direction of movement. Despite the humble 8 bittyness of the CPU it manages 25fps. Play with it until you find the red wall.
Flip
Try and make all the dots the same color by touching to flip a pattern of 5. I find it bloody hard, I have only managed to complete it once. Could someone please publish a deterministic solution?
Lattice
Graphics demo generates a nice infinite mesh. Looks like it is complex 3D engine with lighting, shading and geometry. It isn’t.
Mines
Click. Click. Boom.
Paint
Fingerpainting with touchscreen. Press harder for a bigger brush, select one of three brushes:
- Cycle Chroma
- Cycle Luminance
- Color from accelerometer XYZ
Tools
Microtouch Tool
A simple tool to create IM2 slideshow files from jpg,png or other image files. Add as many images as you like, right click to change background, image fit or remove and image. Drag to reorder. when you are satisfied save the image to a microSD card and open from the Microtouch Shell.
Microtouch Profiler
This tool is a GUI for the built-in sampling profiler. To use:
- Connect Microtouch to USB
- Make sure the Shell is running on the Microtouch
- Launch MicrotouchProfiler.exe
- File/Open the .lss listing file that was generated when the .hex file was built
- Launch the target Microtouch app
The left panel displays a list of modules sorted by activity. The right panel shows the .lss file which is a mixture of source and assembly plus red bars hiliting hotspots in the code. Click on a module to move to its start in the lss file.
The built-in profiler works by sampling the PC from a timer ISR and printing it over the USB serial. If you like hexidecimal numbers you can turn the profiler on and off by typing ‘p1’ and ‘p0’ in the console.
Microtouch Simulator
A Win32 based simulator for developing Microtouch applications without the actual hardware. Simulation is pixel accurate and includes a console window that emulates usb serial stdio. The accelerometer is emulated by a series sine waves of varing period, touch pressure is selected with keys ‘1’ thru ‘9’ CPU performance is not accurately emulated.