| Classes - Annotated - Tree - Functions - Home - Structure

# Qt/Embedded Case Study - Cassiopeia E-100

## Introduction

This document describes the steps involved in installing Linux on an embedded device and building a Qt/Embedded application. The target device is the Cassiopeia E-100/E-105. The device has a MIPS Vr4121 processor, 16MB RAM (32MB in E-105), a Compact Flash slot and a 240x320 16 bit per pixel LCD display.

The only part of this document that is specific to the Cassiopeia is the installation of Linux and the development tools. The example application can be compiled and run on your desktop machine.

## Installing Linux

All the information and software required to get Linux running on the VR series of processors is available from the Linux VR web site. In Summary:

### Install the tools

Follow the instructions at http://www.linux-vr.org/tools.html.

### Build the kernel

Get a sample root ramdisk from ftp://ftp.ltc.com/pub/linux/mips/ramdisk/ramdisk

Follow the instructions at http://www.linux-vr.org/ramdisk.html to create a ramdisk.o file.

Now build your kernel http://www.linux-vr.org/kernel.html using this ramdisk object. Make sure you have at least the following configuration:

- Development/incomplete drivers
- Casio E105 Platform
- Network and System V IPC
- RAM disk and Initial RAM disk support
- Support for console on virtual terminal (so that you can see boot messages)
- /proc and ext2 filesystem support
- Simple Frame Buffer with HPC device control

### Booting Linux

Follow the instructions at http://www.linux-vr.org/booting.html.

You should see the linux boot messages on the LCD display.

## A Qt/Embedded Application

Usually a device such as the Cassiopeia would have a shell, configured as the Qt/Embedded server, that allows client applications to be launched. For the purposes of this tutorial, we will write a simple application that serves as the Qt/Embedded server and client. A more complete Qt/Embbeded server can be found in $QTDIR/examples/compact.

The application that we will write is a simple note pad. It will allow notes to be created, viewed and deleted. Since the Cassiopeia doesn't have a keyboard, we will include a simple on-screen keyboard for input.

### Note Pad

Our note pad user interface is very simple. It consists of a toolbar with "New" and "Delete" buttons, a combo box to select the note to view and an editing area.

Take a moment to browse the source code for Note Pad in $QTDIR/examples/notepad/. The code is quite simple, but there are some things worth noting:

1. Two fonts are set - helvetica 10 point as the application default font, and helvetica 12 point for the editor. Since we will use prerendered fonts these fonts must be prepared as described here.
2. The QApplication is constructed with the QApplication::GuiServer type specified. This makes the note pad a Qt/Embedded server. One server must be running for Qt/Embedded clients to run. In this case our application is both server and client because it is the only application we wish to run on our device.
3. The Cassiopeia has no keyboard (generally) so we must provide some means of character input with the pen. The simplest method is to display a small keyboard. The compact example includes a keyboard, so we use this code. Key and pointer input is Qt/Embedded specific, so it is surrounded by #ifdef _WS_QWS_ ... #endif so that we can compile the example with Qt/X11 or Qt/Windows if we wish.
4. The touch panel needs to be calibrated. There is a calibration module included in the compact demo, so we use this.

### Creating a suitable Qt/Embedded Library

Since our application is quite simple we can remove some unneeded features from Qt/Embedded. Edit $QTDIR/src/tools/qconfig.h and disable unneeded features as follows:

        #define QT_NO_IMAGEIO_BMP
        #define QT_NO_IMAGEIO_PPM
        #define QT_NO_IMAGEIO_XBM
        #define QT_NO_IMAGEIO_PNG
        #define QT_NO_ASYNC_IO
        #define QT_NO_ASYNC_IMAGE_IO
        #define QT_NO_TRUETYPE
        #define QT_NO_BDF
        #define QT_NO_FONTDATABASE
        #define QT_NO_MIME
        #define QT_NO_SOUND
        #define QT_NO_PROPERTIES
        #define QT_NO_CURSOR
        #define QT_NO_NETWORKPROTOCOL
        #define QT_NO_COLORNAMES
        #define QT_NO_TRANSFORMATIONS
        #define QT_NO_PSPRINTER
        #define QT_NO_PICTURE
        #define QT_NO_LISTVIEW
        #define QT_NO_CANVAS
        #define QT_NO_DIAL
        #define QT_NO_WORKSPACE
        #define QT_NO_TABLE
        #define QT_NO_LCDNUMBER
        #define QT_NO_STYLE_MOTIF
        #define QT_NO_STYLE_PLATINUM
        #define QT_NO_COLORDIALOG
        #define QT_NO_PROGRESSDIALOG
        #define QT_NO_TABDIALOG
        #define QT_NO_WIZARD
        #define QT_NO_EFFECTS

See Qt Features for a description of the features that can be disabled. This leaves us with a small set of widgets and dialogs necessary for our application. Cross-compile the library for the mips target on the x86 platform:

        cd $QTDIR
        ./configure -xplatform linux-mips-g++ -platform linux-x86-g++
        make
        mipsel-linux-strip $QTDIR/lib/libqt.so.2.2.0

The library is stripped to conserve ramdisk space.

### Installation

Compile the application:

        cd examples/notepad
        make
        mipsel-linux-strip notepad

We have chosen to link the application dynamically. While this is important if we plan to run multiple applications, it is a waste of space in an application such as notepad that is supposed to be the only application running. You can link statically by configuring with:

        ./configure -static -xplatform linux-mips-g++ -platform linux-x86-g++

We must install our application and its support files in the ramdisk. Mount the ramdisk using loopback device (you will need loopback device support in your kernel):

        mkdir /mnt/ramdisk
        mount -o loop ~/ramdisk /mnt/ramdisk

Copy the Qt/Embedded library to the ramdisk /lib directory and make the necessary links:

        cd /mnt/ramdisk/lib
        cp $QTDIR/lib/libqt.so.2.2.0 .
        ln -s libqt.so.2.2.0 libqt.so.2.2
        ln -s libqt.so.2.2.0 libqt.so.2

The fonts must be installed in /usr/local/qt-embedded/etc/fonts:

        cd /mnt/ramdisk
        mkdir usr/local
        mkdir usr/local/qt-embedded
        mkdir usr/local/qt-embedded/etc
        mkdir usr/local/qt-embedded/etc/fonts
        cp helvetica_100_50.qlf helvetica_120_50.qlf usr/local/qt-embedded/etc/fonts

When the kernel boots it looks for several files to run. In order to have our application run when the kernel boots, we rename it to /bin/sh. A /tmp directory is also used by Qt/Embedded:

        cp $QTDIR/examples/notepad/notepad /mnt/ramdisk/bin/sh
        mkdir /mnt/ramdisk/tmp
        umount /mnt/ramdisk

Create a ramdisk object, link it with the kernel, copy it to the compact flash and boot Linux. You should see the calibration screen appear on the LCD display.