Library for Mini-DK board

Dependencies:   SPI_TFT_ILI9320

Dependents:   LPC1768_Mini-DK_EasyWeb_DM9161 LPC1768_Mini-DK LPC1768_Mini-DK

Fork of Mini-DK by Frank Vannieuwkerke

Mini-DK board overview (Micro SD connector is at the bottom side)

One serial interface , uses CP2102 (USB to RS232 interface, support ISP download )

RJ45-10/100M Ethernet network interface (Ethernet PHY: DM9161)

2.8 inch TFT color LCD interface (SPI interface or 16Bit parallel interface)

Touch panel controller XPT2046 (ADS7843 compatible)

USB 2.0 interface, USB host and USB Device interface.

TF SD / MMC card (SPI) interface.

Two user buttons, One Reset button and ISP button , One INT0 button, two user-programmable LED lights

Serial ISP download, Standard 20-pin JTAG download simulation debugging interface.

Selection between external 5V power supply or USB 5V supply.

Board size: 95mm * 78mm

All IO available on extension connectors

/media/uploads/frankvnk/mini-dk_top.jpg

04/01/13

Erik Olieman (http://mbed.org/users/Sissors/) joined the code development for the Mini-DK board.

Thanks to his input, we were able to obtain a tremendous speed gain, remove warnings, ...

An overview of all modifications is stored in modifs.h

The old page (http://mbed.org/users/frankvnk/code/LPC1768_Mini-DK/) contains the demo code.

IMPORTANT : Due to a change in the mbed libraries (Stream()), we cannot use the printf instruction - we need to use <SPI_TFT>.printf (example - see main.cpp in http://mbed.org/users/frankvnk/code/LPC1768_Mini-DK/)

WARNING: filetoflash (SD to CPU flash)

The SPI_TFT library contains an option to copy an image from the SD card to the CPU flash memory. This allows you to use an image as background without speed loss when writing other text and graphics.

By default, this option is enabled.

It can be disabled by uncommenting the #define mentioned below in Mini_DK.h:

#define NO_FLASH_BUFFER

Since the flash memory has limited write endurance, DO NOT use this feature when you intend to read multiple images from the SD card (eg: when used as a photo frame).

14/01/13

A newer version of the Mini-DK has been released by the manufacturer: Mini-DK2. They replaced the DM9161 PHY with a LAN8720A PHY and better buttons are fitted on the board. All other hardware remains the same. Code for this PHY is available from the NXP MCU SW application team. This allows us to use the mbed 'EthernetInterface' library with little modifications. Further info - see http://mbed.org/forum/mbed/topic/3684/?page=1#comment-18473.

Notes:

The code in 'lpc_phy_lan8720.c' uses 'msDelay' - needs to be replaced with 'osDelay'.

A custom MAC address can be defined using following code:

extern "C" void mbed_mac_address(char * mac) {
 
// define your own MAC Address
  mac[0] = 0x00;  
  mac[1] = 0x01;  
  mac[2] = 0x02;  
  mac[3] = 0x03;  
  mac[4] = 0x04;  
  mac[5] = 0x05;           
  
};

Files at this revision

API Documentation at this revision

Comitter:
frankvnk
Date:
Fri Jan 11 16:17:42 2013 +0000
Parent:
17:66c4e84d8571
Child:
19:6816fa47b39e
Commit message:
SPI_TFT renamed to SPI_TFT_ILI9320 and published as separate library

Changed in this revision

SPI_TFT/BurstSPI.lib Show diff for this revision Revisions of this file
SPI_TFT/GraphicsDisplay.cpp Show diff for this revision Revisions of this file
SPI_TFT/GraphicsDisplay.h Show diff for this revision Revisions of this file
SPI_TFT/IAP/IAP.cpp Show diff for this revision Revisions of this file
SPI_TFT/IAP/IAP.h Show diff for this revision Revisions of this file
SPI_TFT/SPI_TFT.cpp Show diff for this revision Revisions of this file
SPI_TFT/SPI_TFT.h Show diff for this revision Revisions of this file
SPI_TFT/TextDisplay.cpp Show diff for this revision Revisions of this file
SPI_TFT/TextDisplay.h Show diff for this revision Revisions of this file
SPI_TFT_ILI9320.lib Show annotated file Show diff for this revision Revisions of this file
TouchADS7843/Touch.h Show annotated file Show diff for this revision Revisions of this file
--- a/SPI_TFT/BurstSPI.lib	Wed Jan 09 20:54:35 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/Sissors/code/BurstSPI/#a8e55f7cbfee
--- a/SPI_TFT/GraphicsDisplay.cpp	Wed Jan 09 20:54:35 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,176 +0,0 @@
-/* mbed GraphicsDisplay Display Library Base Class
- * Copyright (c) 2007-2009 sford
- * Released under the MIT License: http://mbed.org/license/mit
- */
- 
-#include "GraphicsDisplay.h"
-
-const unsigned char FONT8x8[97][8] = {
-0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
-0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
-0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
-0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
-0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
-0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
-0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
-0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
-0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
-0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
-0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
-0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
-0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
-0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
-0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
-0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
-0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
-0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
-0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
-0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
-0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
-0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
-0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
-0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
-0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
-0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
-0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
-0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
-0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
-0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
-0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
-0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
-0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
-0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
-0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
-0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
-0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
-0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
-0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
-0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
-0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
-0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
-0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
-0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
-0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
-0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
-0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
-0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
-0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
-0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
-0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
-0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
-0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
-0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
-0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
-0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
-0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
-0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
-0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
-0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
-0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
-0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
-0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
-0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
-0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
-0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
-0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
-0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
-0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
-0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
-0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
-0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
-0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
-0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
-0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
-0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
-0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
-0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
-0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
-0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
-0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
-0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
-0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
-0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
-0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
-0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
-0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
-0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
-0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
-0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
-0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
-0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
-0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
-0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
-0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL
-    
-GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) {
-    foreground(0xFFFF);
-    background(0x0000);
-}
-    
-void GraphicsDisplay::character(int column, int row, int value) { 
-    blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
-}
-
-void GraphicsDisplay::window(int x, int y, int w, int h) {
-    // current pixel location
-    _x = x;
-    _y = y;
-    // window settings
-    _x1 = x;
-    _x2 = x + w - 1;
-    _y1 = y;
-    _y2 = y + h - 1;
-}
-    
-void GraphicsDisplay::putp(int colour) {
-    // put pixel at current pixel location
-    pixel(_x, _y, colour);
-    // update pixel location based on window settings
-    _x++;
-    if(_x > _x2) {
-        _x = _x1;
-        _y++;
-        if(_y > _y2) {
-            _y = _y1;
-        }
-    }
-}
-
-void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) { 
-    window(x, y, w, h);
-    for(int i=0; i<w*h; i++) {
-        putp(colour);
-    }
-}
-    
-void GraphicsDisplay::cls() {
-    fill(0, 0, width(), height(), _background);
-}
-    
-void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) { 
-    window(x, y, w, h);
-    for(int i=0; i<w*h; i++) {
-        putp(colour[i]);
-    }
-}
-    
-void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) {
-    window(x, y, w, h);
-    for(int i = 0; i < w*h; i++) {
-        char byte = colour[i >> 3];
-        int offset = i & 0x7;
-        int c = ((byte << offset) & 0x80) ? _foreground : _background;
-        putp(c);
-    }
-}
-    
-int GraphicsDisplay::columns() { 
-    return width() / 8; 
-}
-
-int GraphicsDisplay::rows() { 
-    return height() / 8; 
-}
-
--- a/SPI_TFT/GraphicsDisplay.h	Wed Jan 09 20:54:35 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/* mbed GraphicsDisplay Display Library Base Class
- * Copyright (c) 2007-2009 sford
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * A library for providing a common base class for Graphics displays
- * To port a new display, derive from this class and implement
- * the constructor (setup the display), pixel (put a pixel
- * at a location), width and height functions. Everything else
- * (locate, printf, putc, cls, window, putp, fill, blit, blitbit) 
- * will come for free. You can also provide a specialised implementation
- * of window and putp to speed up the results
- */
-
-#ifndef MBED_GRAPHICSDISPLAY_H
-#define MBED_GRAPHICSDISPLAY_H
-
-#include "TextDisplay.h"
-
-class GraphicsDisplay : public TextDisplay {
-
-public:         
-          
-    GraphicsDisplay(const char* name);
-     
-    virtual void pixel(int x, int y, int colour) = 0;
-    virtual int width() = 0;
-    virtual int height() = 0;
-        
-    virtual void window(int x, int y, int w, int h);
-    virtual void putp(int colour);
-    
-    virtual void cls();
-    virtual void fill(int x, int y, int w, int h, int colour);
-    virtual void blit(int x, int y, int w, int h, const int *colour);    
-    virtual void blitbit(int x, int y, int w, int h, const char* colour);
-    
-    virtual void character(int column, int row, int value);
-    virtual int columns();
-    virtual int rows();
-    
-protected:
-
-    // pixel location
-    short _x;
-    short _y;
-    
-    // window location
-    short _x1;
-    short _x2;
-    short _y1;
-    short _y2;
-
-};
-
-#endif
--- a/SPI_TFT/IAP/IAP.cpp	Wed Jan 09 20:54:35 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,271 +0,0 @@
-/**    IAP : internal Flash memory access library
- *
- *        The internal Flash memory access is described in the LPC1768 and LPC11U24 usermanual. 
- *            http://www.nxp.com/documents/user_manual/UM10360.pdf
- *            http://www.nxp.com/documents/user_manual/UM10462.pdf
- *
- *               LPC1768 --
- *                    Chapter  2: "LPC17xx Memory map"
- *                    Chapter 32: "LPC17xx Flash memory interface and programming"
- *                    refering Rev. 01 - 4 January 2010
- * 
- *               LPC11U24 --
- *                    Chapter  2: "LPC11Uxx Memory mapping"
- *                    Chapter 20: "LPC11Uxx Flash programming firmware"
- *                    refering Rev. 03 - 16 July 2012
- * 
- *        Released under the MIT License: http://mbed.org/license/mit
- *
- *        revision 1.0  09-Mar-2010   1st release
- *        revision 1.1  12-Mar-2010   chaged: to make possible to reserve flash area for user
- *                                            it can be set by USER_FLASH_AREA_START and USER_FLASH_AREA_SIZE in IAP.h
- *        revision 2.0  26-Nov-2012   LPC11U24 code added
- *        revision 2.1  26-Nov-2012   EEPROM access code imported from Suga koubou san's (http://mbed.org/users/okini3939/) library
- *                                            http://mbed.org/users/okini3939/code/M0_EEPROM_test/
- */
-
-#include    "mbed.h"
-#include    "IAP.h"
-
-#define     USER_FLASH_AREA_START_STR( x )      STR( x )
-#define     STR( x )                            #x
-
-unsigned char user_area[ USER_FLASH_AREA_SIZE ] __attribute__((section( ".ARM.__at_" USER_FLASH_AREA_START_STR( USER_FLASH_AREA_START ) ), zero_init));
-
-
-/*
- *  Reserve of flash area is explained by Igor. Please refer next URL
- *    http://mbed.org/users/okano/notebook/iap-in-application-programming-internal-flash-eras/?page=1#comment-271
- */
- 
-//unsigned char user_area[ size ] __attribute__((section(".ARM.__at_0x78000"), zero_init));
-
-/*
- *  IAP command codes
- *  Table 589. "IAP Command Summary", Chapter 8. "IAP commands", usermanual
- */
-
-enum command_code
-        {
-            IAPCommand_Prepare_sector_for_write_operation    = 50,
-            IAPCommand_Copy_RAM_to_Flash,
-            IAPCommand_Erase_sector,
-            IAPCommand_Blank_check_sector,
-            IAPCommand_Read_part_ID,
-            IAPCommand_Read_Boot_Code_version,
-            IAPCommand_Compare,
-            IAPCommand_Reinvoke_ISP,
-            IAPCommand_Read_device_serial_number,
-#if defined(TARGET_LPC11U24)
-            IAPCommand_EEPROM_Write = 61,
-            IAPCommand_EEPROM_Read,
-#endif
-        };
-
-
-/** Read part identification number
- *
- *  @return    device ID
- *  @see       read_serial()
- */
-
-int IAP::read_ID( void ) {
-    IAP_command[ 0 ]    = IAPCommand_Read_part_ID;
-    
-    iap_entry( IAP_command, IAP_result );
-    
-    //  return ( (int)IAP_result[ 0 ] );
-    return ( (int)IAP_result[ 1 ] );    //  to return the number itself (this command always returns CMD_SUCCESS)
-}
-
-
-/** Read device serial number
- *
- *  @return    device serial number
- *  @see       read_ID()
- */
-
-int IAP::read_serial( void ) {
-    IAP_command[ 0 ]    = IAPCommand_Read_device_serial_number;
-    
-    iap_entry( IAP_command, IAP_result );
-    
-    //  return ( (int)IAP_result[ 0 ] );
-    return ( (int)IAP_result[ 1 ] );    //  to return the number itself (this command always returns CMD_SUCCESS)
-}
-
-
-/** Blank check sector(s)
- *  
- *  @param    start    a Start Sector Number
- *  @param    end      an End Sector Number (should be greater than or equal to start sector number).
- *  @return error code: CMD_SUCCESS | BUSY | SECTOR_NOT_BLANK | INVALID_SECTOR
- */
-
-int IAP::blank_check( int start, int end ) {
-    IAP_command[ 0 ]    = IAPCommand_Blank_check_sector;
-    IAP_command[ 1 ]    = (unsigned int)start;  //  Start Sector Number
-    IAP_command[ 2 ]    = (unsigned int)end;    //  End Sector Number (should be greater than or equal to start sector number)
-
-    iap_entry( IAP_command, IAP_result );
-
-    return ( (int)IAP_result[ 0 ] );
-}
-
-
-/** Erase Sector(s)
- *  
- *  @param    start    a Start Sector Number
- *  @param    end      an End Sector Number (should be greater than or equal to start sector number).
- *  @return   error code: CMD_SUCCESS | BUSY | SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | INVALID_SECTOR
- */
-
-int IAP::erase( int start, int end ) {
-    IAP_command[ 0 ]    = IAPCommand_Erase_sector;
-    IAP_command[ 1 ]    = (unsigned int)start;  //  Start Sector Number
-    IAP_command[ 2 ]    = (unsigned int)end;    //  End Sector Number (should be greater than or equal to start sector number)
-    IAP_command[ 3 ]    = cclk_kHz;             //  CPU Clock Frequency (CCLK) in kHz
-
-    iap_entry( IAP_command, IAP_result );
-
-    return ( (int)IAP_result[ 0 ] );
-}
-
-
-/** Prepare sector(s) for write operation
- *  
- *  @param    start    a Start Sector Number
- *  @param    end      an End Sector Number (should be greater than or equal to start sector number).
- *  @return   error code: CMD_SUCCESS | BUSY | INVALID_SECTOR
- */
-
-int IAP::prepare( int start, int end ) {
-    IAP_command[ 0 ]    = IAPCommand_Prepare_sector_for_write_operation;
-    IAP_command[ 1 ]    = (unsigned int)start;  //  Start Sector Number
-    IAP_command[ 2 ]    = (unsigned int)end;    //  End Sector Number (should be greater than or equal to start sector number).
-    
-    iap_entry( IAP_command, IAP_result );
-    
-    return ( (int)IAP_result[ 0 ] );
-}
-
-
-/** Copy RAM to Flash
- *  
- *  @param    source_addr    Source RAM address from which data bytes are to be read. This address should be a word boundary.
- *  @param    target_addr    Destination flash address where data bytes are to be written. This address should be a 256 byte boundary.
- *  @param    size           Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
- *  @return   error code: CMD_SUCCESS | SRC_ADDR_ERROR (Address not a word boundary) | DST_ADDR_ERROR (Address not on correct boundary) | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED | COUNT_ERROR (Byte count is not 256 | 512 | 1024 | 4096) | SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | BUSY
- */
-
-int IAP::write( char *source_addr, char *target_addr, int size ) {
-    IAP_command[ 0 ]    = IAPCommand_Copy_RAM_to_Flash;
-    IAP_command[ 1 ]    = (unsigned int)target_addr;    //  Destination flash address where data bytes are to be written. This address should be a 256 byte boundary.
-    IAP_command[ 2 ]    = (unsigned int)source_addr;    //  Source RAM address from which data bytes are to be read. This address should be a word boundary.
-    IAP_command[ 3 ]    = size;                         //  Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
-    IAP_command[ 4 ]    = cclk_kHz;                     //  CPU Clock Frequency (CCLK) in kHz.
-
-    iap_entry( IAP_command, IAP_result );
-
-    return ( (int)IAP_result[ 0 ] );
-}
-
-
-/** Compare <address1> <address2> <no of bytes>
- *  
- *  @param    source_addr Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
- *  @param    target_addr Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
- *  @param    size         Number of bytes to be compared; should be a multiple of 4.
- *  @return   error code: CMD_SUCCESS | COMPARE_ERROR | COUNT_ERROR (Byte count is not a multiple of 4) | ADDR_ERROR | ADDR_NOT_MAPPED     
- */
-
-int IAP::compare( char *source_addr, char *target_addr, int size ) {
-    IAP_command[ 0 ]    = IAPCommand_Compare;
-    IAP_command[ 1 ]    = (unsigned int)target_addr;    //  Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
-    IAP_command[ 2 ]    = (unsigned int)source_addr;    //  Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
-    IAP_command[ 3 ]    = size;                         //  Number of bytes to be compared; should be a multiple of 4.
-
-    iap_entry( IAP_command, IAP_result );
-
-    return ( (int)IAP_result[ 0 ] );
-}
-
-/** Compare <address1> <address2> <no of bytes>
- *  
- *  @param    source_addr Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
- *  @param    target_addr Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
- *  @param    size         Number of bytes to be compared; should be a multiple of 4.
- *  @return   error code: CMD_SUCCESS | COMPARE_ERROR | COUNT_ERROR (Byte count is not a multiple of 4) | ADDR_ERROR | ADDR_NOT_MAPPED     
- */
-
-int IAP::read_BootVer(void) {
-    IAP_command[0] = IAPCommand_Read_Boot_Code_version;
-    IAP_result[1] = 0; // not sure if in high or low bits.
-    iap_entry(IAP_command, IAP_result);
-    return ((int)IAP_result[1]);
-}
-
-/** Get user reserved flash start address
- *
- *  @return    start address of user reserved flash memory
- *  @see       reserved_flash_area_size()
- */
-
-char * IAP::reserved_flash_area_start( void )
-{
-    return ( (char *)USER_FLASH_AREA_START );
-}
-
-
-/** Get user reserved flash size
- *
- *  @return    size of user reserved flash memory
- *  @see       reserved_flash_area_start()
- */
-
-int IAP::reserved_flash_area_size( void )
-{
-    return ( USER_FLASH_AREA_SIZE );
-}
-
-#if defined(TARGET_LPC11U24)
-/** Copy RAM to EEPROM (LPC11U24)
- *  
- *  @param    source_addr    Source RAM address from which data bytes are to be read.
- *  @param    target_addr    Destination EEPROM address where data bytes are to be written.
- *  @param    size           Number of bytes to be written.
- *  @return   error code: CMD_SUCCESS | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED
- *  Remark: The top 64 bytes of the EEPROM memory are reserved and cannot be written to.
- */
-int IAP::write_eeprom( char *source_addr, char *target_addr, int size ) {
-    IAP_command[ 0 ]    = IAPCommand_EEPROM_Write;
-    IAP_command[ 1 ]    = (unsigned int)target_addr;    //  Destination EEPROM address where data bytes are to be written. This address should be a 256 byte boundary.
-    IAP_command[ 2 ]    = (unsigned int)source_addr;    //  Source RAM address from which data bytes are to be read. This address should be a word boundary.
-    IAP_command[ 3 ]    = size;                         //  Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
-    IAP_command[ 4 ]    = cclk_kHz;                     //  CPU Clock Frequency (CCLK) in kHz.
- 
-    iap_entry( IAP_command, IAP_result );
- 
-    return ( (int)IAP_result[ 0 ] );
-}
- 
-/** Copy EEPROM to RAM (LPC11U24)
- *  
- *  @param    source_addr    Source EEPROM address from which data bytes are to be read.
- *  @param    target_addr    Destination RAM address where data bytes are to be written.
- *  @param    size           Number of bytes to be written.
- *  @return   error code: CMD_SUCCESS | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED
- *  Remark: The top 64 bytes of the EEPROM memory are reserved and cannot be written to.
- */
-int IAP::read_eeprom( char *source_addr, char *target_addr, int size ) {
-    IAP_command[ 0 ]    = IAPCommand_EEPROM_Read;
-    IAP_command[ 1 ]    = (unsigned int)source_addr;    //  Source EEPROM address from which data bytes are to be read. This address should be a word boundary.
-    IAP_command[ 2 ]    = (unsigned int)target_addr;    //  Destination RAM address where data bytes are to be written. This address should be a 256 byte boundary.
-    IAP_command[ 3 ]    = size;                         //  Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
-    IAP_command[ 4 ]    = cclk_kHz;                     //  CPU Clock Frequency (CCLK) in kHz.
- 
-    iap_entry( IAP_command, IAP_result );
- 
-    return ( (int)IAP_result[ 0 ] );
-}
-#endif
--- a/SPI_TFT/IAP/IAP.h	Wed Jan 09 20:54:35 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,286 +0,0 @@
-/**    IAP : internal Flash memory access library
- *
- *        The internal Flash memory access is described in the LPC1768 and LPC11U24 usermanual. 
- *            http://www.nxp.com/documents/user_manual/UM10360.pdf
- *            http://www.nxp.com/documents/user_manual/UM10462.pdf
- *
- *               LPC1768 --
- *                    Chapter  2: "LPC17xx Memory map"
- *                    Chapter 32: "LPC17xx Flash memory interface and programming"
- *                    refering Rev. 01 - 4 January 2010
- * 
- *               LPC11U24 --
- *                    Chapter  2: "LPC11Uxx Memory mapping"
- *                    Chapter 20: "LPC11Uxx Flash programming firmware"
- *                    refering Rev. 03 - 16 July 2012
- * 
- *        Released under the MIT License: http://mbed.org/license/mit
- *
- *        revision 1.0  09-Mar-2010   1st release
- *        revision 1.1  12-Mar-2010   chaged: to make possible to reserve flash area for user
- *                                            it can be set by USER_FLASH_AREA_START and USER_FLASH_AREA_SIZE in IAP.h
- *        revision 2.0  26-Nov.2012   LPC11U24 code added
- *        revision 2.1  26-Nov-2012   EEPROM access code imported from Suga koubou san's (http://mbed.org/users/okini3939/) library
- *                                            http://mbed.org/users/okini3939/code/M0_EEPROM_test/
- */
-
-#ifndef        MBED_IAP
-#define        MBED_IAP
-
-#include    "mbed.h"
-
-#if defined(TARGET_LPC1768)
-
-#define     USER_FLASH_AREA_START   FLASH_SECTOR_25
-#define     USER_FLASH_AREA_SIZE    (FLASH_SECTOR_SIZE_16_TO_29 * 5)
-
-/*
- *  memory map information is available in next URL also.
- *    http://mbed.org/projects/libraries/svn/mbed/trunk/LPC1768/LPC17xx.h
- */
- 
-/**    Table for start adress of sectors
- *    
- *        LPC1768 internal flash memory sector numbers and addresses
- *
- *        LPC1768 flash memory are and sector number/size
- *        Table 568 "Sectors in a LPC17xx device", Section 5. "Sector numbers", usermanual
- *
- *        0x00000000 - 0x0007FFFF        flash (29 sectors)
- *
- *      Sector0:     0x00000000 - 0x00000FFF        4K
- *      Sector1:     0x00001000 - 0x00001FFF        4K
- *      Sector2:     0x00002000 - 0x00002FFF        4K
- *      Sector3:     0x00003000 - 0x00003FFF        4K
- *      Sector4:     0x00004000 - 0x00004FFF        4K
- *      Sector5:     0x00005000 - 0x00005FFF        4K
- *      Sector6:     0x00006000 - 0x00006FFF        4K
- *      Sector7:     0x00007000 - 0x00007FFF        4K
- *      Sector8:     0x00008000 - 0x00008FFF        4K
- *      Sector9:     0x00009000 - 0x00009FFF        4K
- *      Sector10:    0x0000A000 - 0x0000AFFF        4K
- *      Sector11:    0x0000B000 - 0x0000BFFF        4K
- *      Sector12:    0x0000C000 - 0x0000CFFF        4K
- *      Sector13:    0x0000D000 - 0x0000DFFF        4K
- *      Sector14:    0x0000E000 - 0x0000EFFF        4K
- *      Sector15:    0x0000F000 - 0x0000FFFF        4K
- *
- *      Sector16:    0x00010000 - 0x00017FFF        32K
- *      Sector17:    0x00018000 - 0x0001FFFF        32K
- *      Sector18:    0x00020000 - 0x00027FFF        32K
- *      Sector19:    0x00028000 - 0x0002FFFF        32K
- *      Sector20:    0x00030000 - 0x00037FFF        32K
- *      Sector21:    0x00038000 - 0x0003FFFF        32K
- *      Sector22:    0x00040000 - 0x00047FFF        32K
- *      Sector23:    0x00048000 - 0x0004FFFF        32K
- *      Sector24:    0x00050000 - 0x00057FFF        32K
- *      Sector25:    0x00058000 - 0x0005FFFF        32K
- *      Sector26:    0x00060000 - 0x00067FFF        32K
- *      Sector27:    0x00068000 - 0x0006FFFF        32K
- *      Sector28:    0x00070000 - 0x00077FFF        32K
- *      Sector29:    0x00078000 - 0x0007FFFF        32K
- */
-
-#define     FLASH_SECTOR_0       0x00000000
-#define     FLASH_SECTOR_1       0x00001000
-#define     FLASH_SECTOR_2       0x00002000
-#define     FLASH_SECTOR_3       0x00003000
-#define     FLASH_SECTOR_4       0x00004000
-#define     FLASH_SECTOR_5       0x00005000
-#define     FLASH_SECTOR_6       0x00006000
-#define     FLASH_SECTOR_7       0x00007000
-#define     FLASH_SECTOR_8       0x00008000
-#define     FLASH_SECTOR_9       0x00009000
-#define     FLASH_SECTOR_10      0x0000A000
-#define     FLASH_SECTOR_11      0x0000B000
-#define     FLASH_SECTOR_12      0x0000C000
-#define     FLASH_SECTOR_13      0x0000D000
-#define     FLASH_SECTOR_14      0x0000E000
-#define     FLASH_SECTOR_15      0x0000F000
-#define     FLASH_SECTOR_16      0x00010000
-#define     FLASH_SECTOR_17      0x00018000
-#define     FLASH_SECTOR_18      0x00020000
-#define     FLASH_SECTOR_19      0x00028000
-#define     FLASH_SECTOR_20      0x00030000
-#define     FLASH_SECTOR_21      0x00038000
-#define     FLASH_SECTOR_22      0x00040000
-#define     FLASH_SECTOR_23      0x00048000
-#define     FLASH_SECTOR_24      0x00050000
-#define     FLASH_SECTOR_25      0x00058000
-#define     FLASH_SECTOR_26      0x00060000
-#define     FLASH_SECTOR_27      0x00068000
-#define     FLASH_SECTOR_28      0x00070000
-#define     FLASH_SECTOR_29      0x00078000
-#define     FLASH_SECTOR_SIZE_0_TO_15    ( 4 * 1024)
-#define     FLASH_SECTOR_SIZE_16_TO_29   (32 * 1024)
-
-static char * sector_start_adress[]    = {
-    (char *)FLASH_SECTOR_0,
-    (char *)FLASH_SECTOR_1,
-    (char *)FLASH_SECTOR_2,
-    (char *)FLASH_SECTOR_3,
-    (char *)FLASH_SECTOR_4,
-    (char *)FLASH_SECTOR_5,
-    (char *)FLASH_SECTOR_6,
-    (char *)FLASH_SECTOR_7,
-    (char *)FLASH_SECTOR_8,
-    (char *)FLASH_SECTOR_9,
-    (char *)FLASH_SECTOR_10,
-    (char *)FLASH_SECTOR_11,
-    (char *)FLASH_SECTOR_12,
-    (char *)FLASH_SECTOR_13,
-    (char *)FLASH_SECTOR_14,
-    (char *)FLASH_SECTOR_15,
-    (char *)FLASH_SECTOR_16,
-    (char *)FLASH_SECTOR_17,
-    (char *)FLASH_SECTOR_18,
-    (char *)FLASH_SECTOR_19,
-    (char *)FLASH_SECTOR_20,
-    (char *)FLASH_SECTOR_21,
-    (char *)FLASH_SECTOR_22,
-    (char *)FLASH_SECTOR_23,
-    (char *)FLASH_SECTOR_24,
-    (char *)FLASH_SECTOR_25,
-    (char *)FLASH_SECTOR_26,
-    (char *)FLASH_SECTOR_27,
-    (char *)FLASH_SECTOR_28,
-    (char *)FLASH_SECTOR_29    
-};
-
-#elif defined(TARGET_LPC11U24)
-
-#define     USER_FLASH_AREA_START   FLASH_SECTOR_7
-#define     USER_FLASH_AREA_SIZE    (FLASH_SECTOR_SIZE * 1)
- 
-/**    Table for start adress of sectors
- *    
- *        LPC11U24 internal flash memory sector numbers and addresses
- *
- *        LPC11U24 flash memory are and sector number/size
- *        Table 334 "LPC11U1x/2x flash sectors", Section 20. "Sector numbers", usermanual
- *
- *        0x00000000 - 0x00007FFF        flash (8 sectors)
- *
- *      Sector0:     0x00000000 - 0x00000FFF        4K
- *      Sector1:     0x00001000 - 0x00001FFF        4K
- *      Sector2:     0x00002000 - 0x00002FFF        4K
- *      Sector3:     0x00003000 - 0x00003FFF        4K
- *      Sector4:     0x00004000 - 0x00004FFF        4K
- *      Sector5:     0x00005000 - 0x00005FFF        4K
- *      Sector6:     0x00006000 - 0x00006FFF        4K
- *      Sector7:     0x00007000 - 0x00007FFF        4K
- */
-
-#define     FLASH_SECTOR_0       0x00000000
-#define     FLASH_SECTOR_1       0x00001000
-#define     FLASH_SECTOR_2       0x00002000
-#define     FLASH_SECTOR_3       0x00003000
-#define     FLASH_SECTOR_4       0x00004000
-#define     FLASH_SECTOR_5       0x00005000
-#define     FLASH_SECTOR_6       0x00006000
-#define     FLASH_SECTOR_7       0x00007000
-#define     FLASH_SECTOR_SIZE    (4 * 1024)
-
-static char * sector_start_adress[]    = {
-    (char *)FLASH_SECTOR_0,
-    (char *)FLASH_SECTOR_1,
-    (char *)FLASH_SECTOR_2,
-    (char *)FLASH_SECTOR_3,
-    (char *)FLASH_SECTOR_4,
-    (char *)FLASH_SECTOR_5,
-    (char *)FLASH_SECTOR_6,
-    (char *)FLASH_SECTOR_7,
-};
-
-#endif
-
-
-/**    Error code by IAP routine
- *  
- *        Table 588 "ISP Return Codes Summary", Section 7.15 "ISP Return Codes", usermanual
- */
-
-enum error_code
-    {
-            CMD_SUCCESS,
-            INVALID_COMMAND,
-            SRC_ADDR_ERROR,
-            DST_ADDR_ERROR,
-            SRC_ADDR_NOT_MAPPED,
-            DST_ADDR_NOT_MAPPED,
-            COUNT_ERROR,
-            INVALID_SECTOR,
-            SECTOR_NOT_BLANK,
-            SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION,
-            COMPARE_ERROR,
-            BUSY,
-            PARAM_ERROR,
-            ADDR_ERROR,
-            ADDR_NOT_MAPPED,
-            CMD_LOCKED,
-            INVALID_CODE,
-            INVALID_BAUD_RATE,
-            INVALID_STOP_BIT,
-            CODE_READ_PROTECTION_ENABLED
-    };
-
-
-
-/*
- *  IAP routine entry
- *
- *        "IAP commands"
- */
-
-#define     IAP_LOCATION    0x1fff1ff1
-typedef     void (*IAP_call)(unsigned int [], unsigned int []);
-
-/**    IAP class
- *  
- *        Interface for internal flash memory access
- */
-
-
-class IAP {
-public:
-
-    /*
-     *  SystemCoreClock ??? :  
-     *    http://mbed.org/forum/mbed/topic/229/
-     *    http://mbed.org/users/simon/programs/SystemCoreClock/16mhsh/
-     */
-
-    
-    /**    Constructor for IAP
-     *
-     */
-
-    IAP() : iap_entry( reinterpret_cast<IAP_call>(IAP_LOCATION) ), cclk_kHz( SystemCoreClock / 1000 ) {}
-    int read_ID( void );
-    int read_serial( void );
-    int blank_check( int start, int end );
-    int erase( int start, int end );
-    int prepare( int start, int end );
-    int write( char *source_addr, char *target_addr, int size );
-    int compare( char *source_addr, char *target_addr, int size );
-    int read_BootVer( void );
-    
-    char *reserved_flash_area_start( void );
-    int   reserved_flash_area_size( void );
-
-#if defined(TARGET_LPC11U24)
-    int write_eeprom( char *source_addr, char *target_addr, int size );
-    int read_eeprom( char *source_addr, char *target_addr, int size );
-#endif
-
-private:
-    IAP_call        iap_entry;
-    unsigned int    IAP_command[ 5 ];
-    unsigned int    IAP_result[ 5 ];
-    int             cclk_kHz;
-    
-    //int cpu_clock( void );
-}
-;
-
-#endif    //  #ifndef  MBED_IAP
--- a/SPI_TFT/SPI_TFT.cpp	Wed Jan 09 20:54:35 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,898 +0,0 @@
-/**************************************************************************************************
- *****                                                                                        *****
- *****  Name: SPI_TFT.cpp                                                                     *****
- *****  Ver.: 1.0                                                                             *****
- *****  Date: 04/01/2013                                                                      *****
- *****  Auth: Frank Vannieuwkerke                                                             *****
- *****        Erik Olieman                                                                    *****
- *****  Func: library for 240*320 pixel TFT with ILI9320 LCD Controller                       *****
- *****                                                                                        *****
- *****  Rewrite from Peter Drescher code - http://mbed.org/cookbook/SPI-driven-QVGA-TFT       *****
- *****                                                                                        *****
- **************************************************************************************************/
-
-#include "SPI_TFT.h"
-#include "mbed.h"
-
-
-#define BPP         16                  // Bits per pixel
-
-
-SPI_TFT::SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, const char *name)
-    : GraphicsDisplay(name), _spi(mosi, miso, sclk), _cs(cs)
-{
-    char_x = 0;
-    tft_reset();
-    set_orientation(0);
-    backgroundimage = false;
-    #ifndef NO_FLASH_BUFFER
-    backgroundOrientation = 0;
-    #endif
-}
-
-int SPI_TFT::width()
-{
-    if (orientation == 0 || orientation == 2) return 240;
-    else return 320;
-}
-
-int SPI_TFT::height()
-{
-    if (orientation == 0 || orientation == 2) return 320;
-    else return 240;
-}
-
-void SPI_TFT::set_orientation(unsigned int o)
-{
-    orientation = o;
-    WindowMax();
-}
-
-void SPI_TFT::mod_orientation(void)
-{
-    switch (orientation) {
-        case 0:
-            wr_reg(0x03, 0x10b0);        // ID1 = 1, ID0 = 1, AM = 0 - Portrait
-            break;
-        case 1:
-            wr_reg(0x03, 0x10a8);        // ID1 = 1, ID0 = 0, AM = 0 - Landscape
-            break;
-        case 2:
-            wr_reg(0x03, 0x1080);        // ID1 = 0, ID0 = 0, AM = 1 - Portrait upside down
-            break;
-        case 3:
-            wr_reg(0x03, 0x1098);        // ID1 = 0, ID0 = 1, AM = 1 - Landscape upside down
-            break;
-    }
-}
-
-void SPI_TFT::wr_cmd(unsigned char cmd)
-{
-    _cs = 0;
-    _spi.write(0x70);
-    _spi.write(0x00);
-    _spi.write(cmd);
-    _cs = 1;
-}
-
-void SPI_TFT::wr_dat(unsigned short dat)
-{
-    unsigned char u,l;
-    u = (dat >> 0x08);
-    l = (dat & 0xff);
-    _cs = 0;
-    _spi.write(0x72);
-    _spi.write(u);
-    _spi.write(l);
-    _cs = 1;
-}
-
-void SPI_TFT::wr_dat_start(void)
-{
-    _spi.write(0x72);
-}
-
-unsigned short SPI_TFT::rd_dat(void)              // IMPORTANT : SPI frequency needs to be lowered when reading
-{
-    unsigned short val = 0;
-    _cs = 0;
-    _spi.frequency(SPI_F_LO);
-    _spi.write(0x73);
-    _spi.write(0x00);
-    val = _spi.write(0x00);                          // Dummy read
-    val = _spi.write(0x00);                          // Read D8..D15
-    val <<= 8;
-    val |= _spi.write(0x00);                         // Read D0..D7
-    _cs = 1;
-    _spi.frequency(SPI_F_HI);
-    return (val);
-}
-
-void SPI_TFT::wr_reg(unsigned char reg, unsigned short val)
-{
-    wr_cmd(reg);
-    wr_dat(val);
-}
-
-unsigned short SPI_TFT::rd_reg(unsigned char reg)
-{
-    wr_cmd(reg);
-    return(rd_dat());
-}
-
-unsigned short SPI_TFT::Read_ID(void)             // IMPORTANT : SPI frequency needs to be lowered when reading
-{
-    unsigned short val = 0;
-    _cs = 0;
-    _spi.write(0x70);
-    _spi.write(0x00);
-    _spi.write(0x00);
-    _cs = 1;
-    _spi.frequency(SPI_F_LO);
-    _cs = 0;
-    _spi.write(0x73);
-    val = _spi.write(0x00);                       // Dummy read
-    val = _spi.write(0x00);                       // Read D8..D15
-    val <<= 8;
-    val |= _spi.write(0x00);                      // Read D0..D7
-    _cs = 1;
-    _spi.frequency(SPI_F_HI);
-    return (val);
-}
-
-void SPI_TFT::SetCursor( unsigned short Xpos, unsigned short Ypos )
-{
-    wr_reg(0x20, Xpos );
-    wr_reg(0x21, Ypos );
-}
-
-void SPI_TFT::tft_reset()
-{
-    _spi.format(8,3);                                   // 8 bit spi mode 3
-    _spi.frequency(SPI_F_HI);                           // 48 Mhz SPI clock
-
-    wr_reg(0x00,0x0000);
-    wr_reg(0x01,0x0100);                                // Driver Output Control
-    wr_reg(0x02,0x0700);                                // LCD Driver Waveform Control
-    wr_reg(0x03,0x1030);                                // Set the scan mode
-    wr_reg(0x04,0x0000);                                // Scaling Control
-    wr_reg(0x08,0x0202);                                // Display Control 2
-    wr_reg(0x09,0x0000);                                // Display Control 3
-    wr_reg(0x0a,0x0000);                                // Frame Cycle Contal
-    wr_reg(0x0c,(1<<0));                                // Extern Display Interface Control 1
-    wr_reg(0x0d,0x0000);                                // Frame Maker Position
-    wr_reg(0x0f,0x0000);                                // Extern Display Interface Control 2
-
-    wait_ms(50);
-
-    wr_reg(0x07,0x0101);                                // Display Control
-
-    wait_ms(50);
-
-    wr_reg(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4));   // Power Control 1
-    wr_reg(0x11,0x0007);                                // Power Control 2
-    wr_reg(0x12,(1<<8)|(1<<4)|(0<<0));                  // Power Control 3
-    wr_reg(0x13,0x0b00);                                // Power Control 4
-    wr_reg(0x29,0x0000);                                // Power Control 7
-    wr_reg(0x2b,(1<<14)|(1<<4));
-
-    wr_reg(0x50,0);                                     // Set X Start
-    wr_reg(0x51,239);                                   // Set X End
-    wr_reg(0x52,0);                                     // Set Y Start
-    wr_reg(0x53,319);                                   // Set Y End
-
-    wait_ms(50);
-
-    wr_reg(0x60,0x2700);                                // Driver Output Control
-    wr_reg(0x61,0x0001);                                // Driver Output Control
-    wr_reg(0x6a,0x0000);                                // Vertical Srcoll Control
-
-    wr_reg(0x80,0x0000);                                // Display Position Partial Display 1
-    wr_reg(0x81,0x0000);                                // RAM Address Start Partial Display 1
-    wr_reg(0x82,0x0000);                                // RAM Address End-Partial Display 1
-    wr_reg(0x83,0x0000);                                // Displsy Position Partial Display 2
-    wr_reg(0x84,0x0000);                                // RAM Address Start Partial Display 2
-    wr_reg(0x85,0x0000);                                // RAM Address End Partial Display 2
-
-    wr_reg(0x90,(0<<7)|(16<<0));                        // Frame Cycle Control
-    wr_reg(0x92,0x0000);                                // Panel Interface Control 2
-    wr_reg(0x93,0x0001);                                // Panel Interface Control 3
-    wr_reg(0x95,0x0110);                                // Frame Cycle Control
-    wr_reg(0x97,(0<<8));
-    wr_reg(0x98,0x0000);                                // Frame Cycle Control
-    wr_reg(0x07,0x0133);
-
-    wait_ms(100);
-    WindowMax();
-}
-
-
-void SPI_TFT::pixel(int x, int y, int color)
-{
-    switch (orientation) {
-        case 0:
-            wr_reg(0x20, x);
-            wr_reg(0x21, y);
-            break;
-        case 1:
-            wr_reg(0x20, 239-y);
-            wr_reg(0x21, x);
-            break;
-        case 2:
-            wr_reg(0x20, 239-x);
-            wr_reg(0x21, 319-y);
-            break;
-        case 3:
-            wr_reg(0x20, y);
-            wr_reg(0x21, 319-x);
-            break;
-    }
-    wr_cmd(0x22);
-    wr_dat(color);
-}
-
-
-void SPI_TFT::window(int x, int y, int w, int h)
-{
-    unsigned int xw1, yh1;
-    xw1 = x + w - 1;
-    yh1 = y + h - 1;
-    wr_reg(0x20, x);
-    wr_reg(0x21, y);
-    switch (orientation) {
-        case 0:
-            wr_reg(0x50, x);
-            wr_reg(0x51, xw1);
-            wr_reg(0x52, y);
-            wr_reg(0x53, yh1);
-            break;
-        case 1:
-            wr_reg(0x50, 239 - yh1);
-            wr_reg(0x51, 239 - y);
-            wr_reg(0x52, x);
-            wr_reg(0x53, xw1);
-            break;
-        case 2:
-            wr_reg(0x50, 239 - xw1);
-            wr_reg(0x51, 239 - x);
-            wr_reg(0x52, 319 - yh1);
-            wr_reg(0x53, 319 - y);
-            break;
-        case 3:
-            wr_reg(0x50, y);
-            wr_reg(0x51, yh1);
-            wr_reg(0x52, 319 - xw1);
-            wr_reg(0x53, 319 - x);
-            break;
-    }
-}
-
-
-void SPI_TFT::WindowMax(void)
-{
-    window(0, 0, width(),  height());
-}
-
-
-void SPI_TFT::cls (void)
-{
-    if (backgroundimage == false) {
-    unsigned long int index=0;
-    wr_reg(0x03, 0x1030);
-    WindowMax();
-    SetCursor(0,0);
-    wr_cmd(0x22);
-    _cs = 0;
-    wr_dat_start();
-    _spi.format(16,3);
-    int num = width()*height();
-
-    for( index = 0; index<num; index++ ) {
-        _spi.fastWrite(_background);
-    }
-    _spi.clearRX();
-
-    _spi.format(8,3);
-    _cs = 1;
-    }
-    #ifndef NO_FLASH_BUFFER
-    else {
-        int _orientation=orientation;
-        set_orientation(backgroundOrientation);
-        Bitmap(0,0,width(),height(),(unsigned char*) sector_start_adress[ 25 ]);
-        set_orientation(_orientation);
-        }
-    #endif
-}
-
-void SPI_TFT::hline(int x0, int x1, int y, int color)
-{
-    unsigned int index=0;
-    int w;
-    w = x1 - x0 + 1;
-    mod_orientation();
-    window(x0,y,w,1);
-    wr_cmd(0x22);
-    _cs = 0;
-    wr_dat_start();
-
-    _spi.format(16,3);
-    int num = x1-x0;
-    for( index = 0; index<num; index++ ) {
-        _spi.fastWrite(color);
-    }
-    _spi.clearRX();
-
-    _spi.format(8,3);
-    _cs = 1;
-    return;
-}
-
-void SPI_TFT::vline(int x, int y0, int y1, int color)
-{
-    unsigned int index=0;
-    int h;
-    h = y1 - y0 + 1;
-    mod_orientation();
-    window(x,y0,1,h);
-    wr_cmd(0x22);
-    _cs = 0;
-    wr_dat_start();
-    _spi.format(16,3);
-    int num = y1-y0;
-    for( index = 0; index<num; index++ ) {
-        _spi.fastWrite(color);
-    }
-    _spi.clearRX();
-    _spi.format(8,3);
-    _cs = 1;
-    return;
-}
-
-void SPI_TFT::line(int x0, int y0, int x1, int y1, int color)
-{
-    wr_reg(0x03, 0x1030);
-    WindowMax();
-    int   dx = 0, dy = 0;
-    int   dx_sym = 0, dy_sym = 0;
-    int   dx_x2 = 0, dy_x2 = 0;
-    int   di = 0;
-
-    dx = x1-x0;
-    dy = y1-y0;
-
-    if (dx == 0) {                          // vertical line
-        if (y1 > y0) vline(x0,y0,y1,color);
-        else vline(x0,y1,y0,color);
-        return;
-    }
-
-    if (dx > 0) {
-        dx_sym = 1;
-    } else {
-        dx_sym = -1;
-    }
-    if (dy == 0) {                          // horizontal line
-        if (x1 > x0) hline(x0,x1,y0,color);
-        else  hline(x1,x0,y0,color);
-        return;
-    }
-
-    if (dy > 0) {
-        dy_sym = 1;
-    } else {
-        dy_sym = -1;
-    }
-
-    dx = dx_sym*dx;
-    dy = dy_sym*dy;
-
-    dx_x2 = dx*2;
-    dy_x2 = dy*2;
-
-    if (dx >= dy) {
-        di = dy_x2 - dx;
-        while (x0 != x1) {
-
-            pixel(x0, y0, color);
-            x0 += dx_sym;
-            if (di<0) {
-                di += dy_x2;
-            } else {
-                di += dy_x2 - dx_x2;
-                y0 += dy_sym;
-            }
-        }
-        pixel(x0, y0, color);
-    } else {
-        di = dx_x2 - dy;
-        while (y0 != y1) {
-            pixel(x0, y0, color);
-            y0 += dy_sym;
-            if (di < 0) {
-                di += dx_x2;
-            } else {
-                di += dx_x2 - dy_x2;
-                x0 += dx_sym;
-            }
-        }
-        pixel(x0, y0, color);
-    }
-    return;
-}
-
-
-void SPI_TFT::rect(int x0, int y0, int w, int h, int color)
-{
-    hline(x0,x0+w,y0,color);
-    vline(x0,y0,y0+h,color);
-    hline(x0,x0+w,y0+h,color);
-    vline(x0+w,y0,y0+h,color);
-
-    return;
-}
-
-void SPI_TFT::fillrect(int x0, int y0, int w, int h, int color)
-{
-    unsigned long int index=0;
-    if (w < 0) {
-        x0 = x0 + w;
-        w = -w;
-    }
-    if (h < 0) {
-        y0 = y0 + h;
-        h = -h;
-    }
-    mod_orientation();
-    window(x0,y0,w,h);
-    wr_cmd(0x22);
-    _cs = 0;
-    wr_dat_start();
-    _spi.format(16,3);
-    int num = h*w;
-    for( index = 0; index<num; index++ ) {
-        _spi.fastWrite(color);
-    }
-    _spi.clearRX();
-    _spi.format(8,3);
-    _cs = 1;
-    return;
-}
-
-void SPI_TFT::draw_ellipse(int xc, int yc, int a, int b, unsigned int color)
-{
-    /* e(x,y) = b^2*x^2 + a^2*y^2 - a^2*b^2 */
-    wr_reg(0x03, 0x1030);
-    WindowMax();
-    int x = 0, y = b;
-    long a2 = (long)a*a, b2 = (long)b*b;
-    long crit1 = -(a2/4 + a%2 + b2);
-    long crit2 = -(b2/4 + b%2 + a2);
-    long crit3 = -(b2/4 + b%2);
-    long t = -a2*y;                         // e(x+1/2,y-1/2) - (a^2+b^2)/4
-    long dxt = 2*b2*x, dyt = -2*a2*y;
-    long d2xt = 2*b2, d2yt = 2*a2;
-
-    while (y>=0 && x<=a) {
-        pixel(xc+x, yc+y, color);
-        if (x!=0 || y!=0)
-            pixel(xc-x, yc-y, color);
-        if (x!=0 && y!=0) {
-            pixel(xc+x, yc-y, color);
-            pixel(xc-x, yc+y, color);
-        }
-        if (t + b2*x <= crit1 ||            // e(x+1,y-1/2) <= 0
-                t + a2*y <= crit3)          // e(x+1/2,y) <= 0
-            incx();
-        else if (t - a2*y > crit2)          // e(x+1/2,y-1) > 0
-            incy();
-        else {
-            incx();
-            incy();
-        }
-    }
-}
-
-void SPI_TFT::fill_ellipse(int xc, int yc, int a, int b, unsigned int color)
-{
-    /* e(x,y) = b^2*x^2 + a^2*y^2 - a^2*b^2 */
-    int x = 0, y = b;
-    int rx = x, ry = y;
-    unsigned int width = 1;
-    unsigned int height = 1;
-    long a2 = (long)a*a, b2 = (long)b*b;
-    long crit1 = -(a2/4 + a%2 + b2);
-    long crit2 = -(b2/4 + b%2 + a2);
-    long crit3 = -(b2/4 + b%2);
-    long t = -a2*y;                         // e(x+1/2,y-1/2) - (a^2+b^2)/4
-    long dxt = 2*b2*x, dyt = -2*a2*y;
-    long d2xt = 2*b2, d2yt = 2*a2;
-
-    if (b == 0) {
-        fillrect(xc-a, yc, 2*a+1, 1, color);
-        return;
-    }
-
-    while (y>=0 && x<=a) {
-        if (t + b2*x <= crit1 ||            // e(x+1,y-1/2) <= 0
-                t + a2*y <= crit3) {        // e(x+1/2,y) <= 0
-            if (height == 1)
-                ;                           // draw nothing
-            else if (ry*2+1 > (height-1)*2) {
-                fillrect(xc-rx, yc-ry, width, height-1, color);
-                fillrect(xc-rx, yc+ry+1, width, 1-height, color);
-                ry -= height-1;
-                height = 1;
-            } else {
-                fillrect(xc-rx, yc-ry, width, ry*2+1, color);
-                ry -= ry;
-                height = 1;
-            }
-            incx();
-            rx++;
-            width += 2;
-        } else if (t - a2*y > crit2) {      // e(x+1/2,y-1) > 0
-            incy();
-            height++;
-        } else {
-            if (ry*2+1 > height*2) {
-                fillrect(xc-rx, yc-ry, width, height, color);
-                fillrect(xc-rx, yc+ry+1, width, -height, color);
-            } else {
-                fillrect(xc-rx, yc-ry, width, ry*2+1, color);
-            }
-            incx();
-            incy();
-            rx++;
-            width += 2;
-            ry -= height;
-            height = 1;
-        }
-    }
-
-    if (ry > height) {
-        fillrect(xc-rx, yc-ry, width, height, color);
-        fillrect(xc-rx, yc+ry+1, width, -height, color);
-    } else {
-        fillrect(xc-rx, yc-ry, width, ry*2+1, color);
-    }
-}
-
-
-void SPI_TFT::locate(int x, int y)
-{
-    char_x = x;
-    char_y = y;
-}
-
-int SPI_TFT::columns()
-{
-    return width() / font[1];
-}
-
-int SPI_TFT::rows()
-{
-    return height() / font[2];
-}
-
-int SPI_TFT::_putc(int value)
-{
-    if (value == '\n') {                    // new line
-        char_x = 0;
-        char_y = char_y + font[2];
-        if (char_y >= height() - font[2]) {
-            char_y = 0;
-        }
-    } else {
-        character(char_x, char_y, value);
-    }
-    return value;
-}
-
-void SPI_TFT::character(int x, int y, int c)
-{
-    unsigned int hor,vert,offset,bpl,j,i,b;
-    unsigned char* bitmap_char;
-    unsigned char z,w;
-
-    if ((c < 31) || (c > 127)) return;      // test char range
-
-    // read font parameter from start of array
-    offset = font[0];                       // bytes / char
-    hor = font[1];                          // get hor size of font
-    vert = font[2];                         // get vert size of font
-    bpl = font[3];                          // bytes per line
-
-    if (char_x + hor > width()) {
-        char_x = 0;
-        char_y = char_y + vert;
-        if (char_y >= height() - font[2]) {
-            char_y = 0;
-        }
-    }
-    mod_orientation();
-
-    bitmap_char = &font[((c -32) * offset) + 4];    // start of char bitmap
-    w = bitmap_char[0];                             // width of actual char
-    window(char_x, char_y,w,vert); // char box
-    wr_cmd(0x22);
-    _cs = 0;
-    wr_dat_start();
-    _spi.format(16,3);
-    for (j=0; j<vert; j++) {                        //  vert line
-        for (i=0; i<w; i++) {                       //  horz line
-            z =  bitmap_char[bpl * i + ((j & 0xF8) >> 3)+1];
-            b = 1 << (j & 0x07);
-            if (( z & b ) == 0x00) {
-                #ifndef NO_FLASH_BUFFER
-                if (backgroundimage==false)
-                #endif
-                    _spi.fastWrite(_background);
-                #ifndef NO_FLASH_BUFFER
-                else
-                {
-                    unsigned short *bitmap_ptr = (unsigned short *)sector_start_adress[ 25 ];
-                    int angle = (orientation - backgroundOrientation)%4; //Get the difference in orientation between background and current
-                    switch (angle) {
-                        case 0:         //Same orientation
-                            bitmap_ptr += width() * (height()-(y+j+1))+x+i;
-                        break;
-                        case 1:         //Rotated 1 (don't ask me which direction)
-                            bitmap_ptr += height() * (width()-(x+i+1))+height()-(y+j + 1);
-                        break;
-                        case 2:         //Upside down
-                            bitmap_ptr += width() * (y+j)+width() - (x+i + 1);
-                        break; 
-                        case 3:         //Rotated 3
-                            bitmap_ptr += height() * (x+i)+y+j;                            
-                        break;
-                        default:
-                        break;
-                    }
-                    
-                    _spi.fastWrite(*bitmap_ptr);
-                }
-                #endif    
-            } else {
-                _spi.fastWrite(_foreground);
-            }
-        }
-    }
-    _spi.clearRX();
-    _spi.format(8,3);
-    _cs = 1;
-    if ((w + 2) < hor) {                 // x offset to next char
-        char_x += w + 2;
-    } else char_x += hor;
-}
-
-void SPI_TFT::set_font(unsigned char* f)
-{
-    font = f;
-}
-
-
-void SPI_TFT::Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap)
-{
-    unsigned int    i,j;
-    unsigned short *bitmap_ptr = (unsigned short *)bitmap;
-    mod_orientation();
-    window(x, y, w, h);
-    wr_cmd(0x22);
-    _cs = 0;
-    wr_dat_start();
-    _spi.format(16,3);
-    bitmap_ptr += ((h - 1)*w);
-    for (j = 0; j < h; j++) {               //Lines
-        for (i = 0; i < w; i++) {           // copy pixel data to TFT
-            _spi.fastWrite(*bitmap_ptr);    // one line
-            bitmap_ptr++;
-        }
-        bitmap_ptr -= 2*w;
-    }
-    _spi.clearRX();
-    _spi.format(8,3);
-    _cs = 1;
-}
-
-int SPI_TFT::Bitmap(unsigned int x, unsigned int y, const char *Name_BMP)
-{
-    #define RGB565CONVERT(red, green, blue) (uint16_t)( (( red   >> 3 ) << 11 ) | (( green >> 2 ) << 5  ) | ( blue  >> 3 ))
-    mod_orientation();
-    
-    bitmapData bmp = getBitmapData(Name_BMP);
-    if (bmp.return_code != 1)
-        return bmp.return_code;
-    
-
-    unsigned char *line = (unsigned char *) malloc (bmp.bits/8 * bmp.width);    // we need a buffer for a line
-    unsigned short *line_short = (unsigned short*) (line);                      // Same one, addressed as short
-
-
-    if ((bmp.height > height()+y) || (bmp.width > width()+x))
-        return -3;          //Size mismatch
-
-    if (line == NULL)
-        return(-4);         // error no memory
-
-
-    for (int j = bmp.height-1; j >= 0; j--) {                                   //Lines bottom up
-        int off = j * (bmp.width  * bmp.bits/8 + bmp.pad) + bmp.start_data;     // start of line
-        fseek(bmp.file, off ,SEEK_SET);
-        fread(line,1,bmp.width * bmp.bits/8,bmp.file);                          // read a line - slow !
-        
-        //If 24 bit format, convert to 565
-        if (bmp.bits == 24) {
-            for (int i = 0; i<bmp.width; i++) {
-                line_short[i] = RGB565CONVERT(line[3*i+2], line[3*i+1], line[3*i]);
-            }
-        }
-
-        window(x, y+bmp.height - 1 - j,bmp.width ,1);
-        wr_cmd(0x22);
-
-        _cs = 0;
-        wr_dat_start();
-        _spi.format(16, 3);
-        _spi.setFormat();
-
-        for (int i = 0; i < bmp.width; i++) {       // copy pixel data to TFT
-            _spi.fastWrite(line_short[i]);          // one line
-        }
-
-        _spi.clearRX();
-        _spi.format(8,3);
-        _cs = 1;
-
-    }
-
-
-    free (line);
-    fclose(bmp.file);
-    WindowMax();
-
-    return(1);
-}
-
-#ifndef NO_FLASH_BUFFER
-
-int SPI_TFT::fileToFlash(const char *Name_BMP)
-{
-    #define RGB565CONVERT(red, green, blue) (uint16_t)( (( red   >> 3 ) << 11 ) | (( green >> 2 ) << 5  ) | ( blue  >> 3 ))
-   
-    mod_orientation();
-    
-    bitmapData bmp = getBitmapData(Name_BMP);
-    if (bmp.return_code != 1)
-        return bmp.return_code;
-    
-
-    unsigned char *line = (unsigned char *) malloc (bmp.bits/8 * bmp.width);    // we need a buffer for a line
-    unsigned short *line_short = (unsigned short*) (line);                      // Same one, addressed as short
-
-    unsigned short *flashSector = (unsigned short *) malloc (256);              //And one to send to flash
-
-    if ((bmp.height != height()) || (bmp.width != width()))
-        return -3;          //Size mismatch
-
-    if ((line == NULL) || (flashSector == NULL))
-        return(-4);         // error no memory
-    
-
-    int flashPointer = 0, flashWrites = 0;
-
-    //Erase Flash that will be used:
-    if ( iap.blank_check( 25, 29 ) == SECTOR_NOT_BLANK ) {
-        iap.prepare( 25, 29 );
-        iap.erase( 25, 29 );
-    }
-
-    for (int j = 0; j < bmp.height; j++) {                                      //Lines bottom up
-        int off = j * (bmp.width  * bmp.bits/8 + bmp.pad) + bmp.start_data;     // start of line
-        fseek(bmp.file, off ,SEEK_SET);
-        fread(line,1,bmp.width * bmp.bits/8,bmp.file);                          // read a line - slow !
-
-        //If 24 bit format, do some processing
-        if (bmp.bits == 24) {
-            for (int i = 0; i<bmp.width; i++) {
-                line_short[i] = RGB565CONVERT(line[3*i+2], line[3*i+1], line[3*i]);
-            }
-        }
-
-
-        for (int i = 0; i < bmp.width; i++) {               // copy pixel data to TFT
-            flashSector[flashPointer] = line_short[i];      // one line
-            flashPointer++;
-
-            //If flashpointer reached the end, write to flash
-            if (flashPointer == 128) {
-                iap.prepare( 25, 29 );
-                iap.write((char *)flashSector, sector_start_adress[ 25 ] + 256 * flashWrites, 256);
-                flashPointer = 0;
-                flashWrites++;
-                if (flashWrites == 1000)
-                    error("Too many flashwrites");
-            }
-        }
-    }
-    //write remaining data
-    if (flashPointer!=0) {
-        iap.prepare( 25, 29 );
-        iap.write((char*)flashSector, sector_start_adress[ 25 ] + 256 * flashWrites, 256);
-        flashPointer = 0;
-        flashWrites++;
-        if (flashWrites == 1000)
-            error("Too many flashwrites");
-    }
-
-
-
-    free (line);
-    fclose(bmp.file);
-    backgroundImage(true);
-    backgroundOrientation = orientation;
-    return(1);
-}
-
-void SPI_TFT::backgroundImage( bool active) {
-    backgroundimage = active;
-}
-#endif
-
-
-SPI_TFT::bitmapData SPI_TFT::getBitmapData(const char *Name_BMP){
-    #define OffsetPixelWidth    18
-    #define OffsetPixelHeigh    22
-    #define OffsetFileSize      34
-    #define OffsetPixData       10
-    #define OffsetBPP           28
-    
-
-    bitmapData retval;
-    retval.return_code = 1;
-    unsigned char BMP_Header[54];
-
-    retval.file = fopen(Name_BMP, "rb");                    // open the bmp file
-    if (!retval.file) {
-        retval.return_code = 0;
-        return(retval);                                     // error file not found !
-    }
-
-    fread(&BMP_Header[0],1,54,retval.file);                 // get the BMP Header
-
-    if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) {   // check magic byte
-        fclose(retval.file);
-        retval.return_code = -1;
-        return(retval);                                     // error not a BMP file
-    }
-
-    int BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8);
-    if (BPP_t == 0x0010)
-        retval.bits = 16;
-    else if (BPP_t == 0x0018)
-        retval.bits = 24;
-    else {
-        fclose(retval.file);
-        retval.return_code = -2;
-        return(retval);                                     // error no 16/24 bit BMP
-    }
-
-    retval.height = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24);
-    retval.width = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24);
-    if (retval.height > height()|| retval.width > width()) {
-        fclose(retval.file);
-        retval.return_code = -3;
-        return(retval);                                     // too big
-    }
-
-
-    retval.start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24);
-
-    // the bmp lines are padded to multiple of 4 bytes
-    retval.pad = -1;
-    do {
-        retval.pad ++;
-    } while ((retval.width * retval.bits/8 + retval.pad)%4 != 0);
-    return retval;
-
-}
\ No newline at end of file
--- a/SPI_TFT/SPI_TFT.h	Wed Jan 09 20:54:35 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,427 +0,0 @@
-/**************************************************************************************************
- *****                                                                                        *****
- *****  Name: SPI_TFT.h                                                                       *****
- *****  Ver.: 1.0                                                                             *****
- *****  Date: 04/01/2013                                                                      *****
- *****  Auth: Frank Vannieuwkerke                                                             *****
- *****        Erik Olieman                                                                    *****
- *****  Func: library for 240*320 pixel TFT with ILI9320 LCD Controller                       *****
- *****                                                                                        *****
- *****  Rewrite from Peter Drescher code - http://mbed.org/cookbook/SPI-driven-QVGA-TFT       *****
- *****                                                                                        *****
- **************************************************************************************************/
-
-#ifndef MBED_SPI_TFT_H
-#define MBED_SPI_TFT_H
-
-/* This library allows you to store a background image on the local flash memory of the microcontroller, 
-from any filesystem (such as SD cards). This allows very fast writing of this specific image, and it allows
-you to write text in a nice way over the image. However it does cost the last 5 flash sectors of the LPC1768.
-Generally that won't be a problem, if it is a problem, add #define NO_FLASH_BUFFER before including this file.
-*/
-
-
-#include "GraphicsDisplay.h"
-#include "BurstSPI.h"
-#include "mbed.h"
-
-#ifndef NO_FLASH_BUFFER
-    #include "IAP.h"
-#endif
-
-
-#define incx() x++, dxt += d2xt, t += dxt
-#define incy() y--, dyt += d2yt, t += dyt
-
-#define SPI_F_LO    10000000
-#define SPI_F_HI    48000000
-
-/* some RGB565 color definitions                                                 */
-#define Black           0x0000      /*   0,   0,   0 */
-#define Navy            0x000F      /*   0,   0, 128 */
-#define DarkGreen       0x03E0      /*   0, 128,   0 */
-#define DarkCyan        0x03EF      /*   0, 128, 128 */
-#define Maroon          0x7800      /* 128,   0,   0 */
-#define Purple          0x780F      /* 128,   0, 128 */
-#define Olive           0x7BE0      /* 128, 128,   0 */
-#define LightGrey       0xC618      /* 192, 192, 192 */
-#define DarkGrey        0x7BEF      /* 128, 128, 128 */
-#define Blue            0x001F      /*   0,   0, 255 */
-#define Green           0x07E0      /*   0, 255,   0 */
-#define Cyan            0x07FF      /*   0, 255, 255 */
-#define Red             0xF800      /* 255,   0,   0 */
-#define Magenta         0xF81F      /* 255,   0, 255 */
-#define Yellow          0xFFE0      /* 255, 255,   0 */
-#define White           0xFFFF      /* 255, 255, 255 */
-#define Orange          0xFD20      /* 255, 165,   0 */
-#define GreenYellow     0xAFE5      /* 173, 255,  47 */
-
- class SPI_TFT : public GraphicsDisplay {
- public:
-
-  /** Create a SPI_TFT object connected to SPI and two pins
-   *
-   * @param mosi,miso,sclk SPI
-   * @param cs pin connected to CS of display
-   * @param reset pin connected to RESET of display
-   *
-   */
-  SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name ="TFT");
-
-  /** Write a value to the to a LCD register
-   *
-   * @param reg register to be written
-   * @param val data to be written
-   */
-  void wr_reg (unsigned char reg, unsigned short val);
-
-  /** Get the width of the screen in pixels
-   *
-   * @param
-   * @returns width of screen in pixels
-   *
-   */
-  virtual int width();
-
-  /** Get the height of the screen in pixels
-   *
-   * @returns height of screen in pixels
-   *
-   */
-  virtual int height();
-
-  /** Draw a pixel at x,y with color
-   *
-   * @param x (horizontal position)
-   * @param y (vertical position)
-   * @param color (16 bit pixel color)
-   */
-  virtual void pixel(int x, int y,int colour);
-
-  /** Set draw window region to whole screen
-   *
-   */
-  void WindowMax (void);
-
-  /** draw a 1 pixel line
-   *
-   * @param x0,y0 start point
-   * @param x1,y1 stop point
-   * @param color 16 bit color
-   *
-   */
-  void line(int x0, int y0, int x1, int y1, int colour);
-
-  /** draw a rect
-   *
-   * @param x0,y0 top left corner
-   * @param w,h   width and height
-   * @param color 16 bit color
-   *                                                   *
-   */
-  void rect(int x0, int y0, int w, int h, int colour);
-
-  /** draw a filled rect
-   *
-   * @param x0,y0 top left corner
-   * @param w,h   width and height
-   * @param color 16 bit color
-   *
-   */
-  void fillrect(int x0, int y0, int w, int h, int colour);
-
-  /** draw an ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html
-   *
-   * @param xc,yc center point
-   * @param a,b semi-major axis and semi-minor axis
-   * @param color 16 bit color
-   *
-   */
-  void draw_ellipse(int xc, int yc, int a, int b, unsigned int color);
-
-  /** draw a filled ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html
-   *
-   * @param xc,yc center point
-   * @param a,b semi-major axis and semi-minor axis
-   * @param color 16 bit color
-   *
-   */
-  void fill_ellipse(int xc, int yc, int a, int b, unsigned int color);
-
-  /** setup cursor position
-   *
-   * @param x x-position (top left)
-   * @param y y-position
-   */
-  virtual void locate(int x, int y);
-
-  /** Fill the screen with _background color
-   *
-   */
-  virtual void cls (void);
-
-  /** Read ILI9320 ID
-   *
-   * @returns LCD ID code
-   *
-   */
-  unsigned short Read_ID(void);
-
-  /** calculate the max number of char in a line
-   *
-   * @returns max columns
-   * depends on actual font size
-   *
-   */
-  virtual int columns(void);
-
-  /** calculate the max number of rows
-   *
-   * @returns max rows
-   * depends on actual font size
-   *
-   */
-  virtual int rows(void);
-
-  /** put a char on the screen
-   *
-   * @param value char to print
-   * @returns printed char
-   *
-   */
-  virtual int _putc(int value);
-
-  /** draw a character on given position out of the active font to the TFT
-   *
-   * @param x x-position of char (top left)
-   * @param y y-position
-   * @param c char to print
-   *
-   */
-  virtual void character(int x, int y, int c);
-
-  /** paint a bitmap on the TFT
-   *
-   * @param x,y : upper left corner
-   * @param w width of bitmap
-   * @param h high of bitmap
-   * @param *bitmap pointer to the bitmap data
-   *
-   *   bitmap format: 16 bit R5 G6 B5
-   *
-   *   use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
-   *   use winhex to load this file and mark data stating at offset 0x46 to end
-   *   use edit -> copy block -> C Source to export C array
-   *   paste this array into your program
-   *
-   *   define the array as static const unsigned char to put it into flash memory
-   *   cast the pointer to (unsigned char *) :
-   *   tft.Bitmap(10,40,309,50,(unsigned char *)scala);
-   */
-  void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *Name_BMP);
-
-
-   /** paint a BMP (16/24 bit) from filesytem on the TFT (slow)
-   *
-   * The 16-bit format is RGB-565. Using 16-bit is faster than 24-bit, however every program can
-   * output 24 bit BMPs (including MS paint), while it is hard to get them in the correct 16-bit format.
-   *
-   * @param x,y : upper left corner
-   * @param *Name_BMP location of the BMP file (for example "/sd/test.bmp")
-   * @returns 1 if bmp file was found and stored
-   * @returns 0 if file was not found
-   * @returns -1 if file was not a bmp
-   * @returns -2 if bmp file is not 16/24bit
-   * @returns -3 if bmp file is wrong for screen
-   * @returns -4 if buffer malloc goes wrong
-   *
-   */
-
-  int Bitmap(unsigned int x, unsigned int y, const char *Name_BMP);
-
-
-
-  /** select the font to use
-   *
-   * @param f pointer to font array
-   *
-   *   font array can be created with GLCD Font Creator from http://www.mikroe.com
-   *   you have to add 4 parameter at the beginning of the font array to use:
-   *   - the number of bytes / char
-   *   - the vertial size in pixels
-   *   - the horizontal size in pixels
-   *   - the number of bytes per vertical line
-   *   you also have to change the array to char[]
-   *
-   */
-  void set_font(unsigned char* f);
-
-  /** Set the orientation of the screen
-   *  x,y: 0,0 is always top left
-   *
-   * @param o direction to use the screen (0-3) 90&#65533; Steps
-   *
-   */
-  void set_orientation(unsigned int o);
-
-
-  /** Modify the orientation of the screen
-   *  x,y: 0,0 is always top left
-   *
-   * @param none
-   *
-   * ILI9320 limitation: The orientation can only be used with a window command (registers 0x50..0x53)
-   * 
-   * reg 03h (Entry Mode) : BGR = 1 - ORG = 1 - ID0, ID1 and AM are set according to the orientation variable.
-   * IMPORTANT : when ORG = 1, the GRAM writing direction follows the orientation (ID0, ID1, AM bits)
-   *             AND we need to use the window command (reg 50h..53h) to write to an area on the display
-   *             because we cannot change reg 20h and 21h to set the GRAM address (they both remain at 00h).
-   *             This means that the pixel routine does not work when ORG = 1.
-   *             Routines relying on the pixel routine first need to set reg 03h = 0x1030
-   *             (cls, circle and line do so) AND need to write the data according to the orientation variable.
-   */
-  void mod_orientation(void);
-  
-  #ifndef NO_FLASH_BUFFER
-  /** Move an image to the background buffer
-  * 
-  * The image must fit exactly on the screen (240x320). This function takes quite some time, depending on source filesystem.
-  *
-  * @param *Name_BMP location of the BMP file (for example "/sd/test.bmp")
-  * @returns 1 if bmp file was found and stored
-  * @returns 0 if file was not found
-  * @returns -1 if file was not a bmp
-  * @returns -2 if bmp file is not 16/24bit
-  * @returns -3 if bmp file is wrong for screen
-  * @returns -4 if buffer malloc goes wrong
-  */
-  int fileToFlash(const char *Name_BMP);
-  
-  /** Use the image on the flash memory as background
-  *
-  * @param active - true to use the image, false to use static color
-  */
-  void backgroundImage(bool active);
-  #endif
-
-
-
-
-  
-// ------------------ PROTECTED PART ------------------
-protected:
-
-  /** draw a horizontal line
-   *
-   * @param x0 horizontal start
-   * @param x1 horizontal stop
-   * @param y vertical position
-   * @param color 16 bit color
-   *
-   */
-  void hline(int x0, int x1, int y, int colour);
-
-  /** draw a vertical line
-   *
-   * @param x horizontal position
-   * @param y0 vertical start
-   * @param y1 vertical stop
-   * @param color 16 bit color
-   */
-  void vline(int y0, int y1, int x, int colour);
-
-  /** Set draw window region
-   *
-   * @param x horizontal position
-   * @param y vertical position
-   * @param w window width in pixel
-   * @param h window height in pixels
-   */
-  virtual void window (int x, int y, int w, int h);
-
-  /** Init the ILI9320 controller
-   *
-   */
-  void tft_reset();
-
-   /** Write data to the LCD controller
-   *
-   * @param dat data written to LCD controller
-   *
-   */
-  void wr_dat(unsigned short value);
-
-   /** Start data sequence to the LCD controller
-   *
-   */
-  void wr_dat_start(void);
-
-  /** Write a command the LCD controller
-   *
-   * @param cmd: command to be written
-   *
-   */
-  void wr_cmd(unsigned char value);
-
-  /** Read data from the LCD controller
-   *
-   * @returns data from LCD controller
-   *
-   */
-  unsigned short rd_dat(void);
-
-  /** Read a LCD register
-   *
-   * @param reg register to be read
-   * @returns value of the register
-   */
-  unsigned short rd_reg (unsigned char reg);
-
-  /** Set the cursor position
-   *
-   * @param x (horizontal position)
-   * @param y (vertical position)
-   *
-   * Can only be used when reg 03h = 0x1030 (see note in mod_orientation).
-   *
-   */
-  void SetCursor( unsigned short Xpos, unsigned short Ypos );
-  
-    struct bitmapData {
-        int return_code;
-        int width, height;
-        int bits, pad;
-        int start_data;
-        FILE *file;
-    };
-    
-  /** Get bitmap info
-   *
-   * @param   *Name_BMP  Bitmap filename
-   * @returns structure: return_code        1 if bmp file was found and stored
-   *                                        0 if file was not found
-   *                                        -1 if file was not a bmp
-   *                                        -2 if bmp file is not 16/24bit
-   *                                        -3 if bmp file is wrong for screen
-   *                     width, height      Bitmap size
-   *                     bits, pad          BPP, padding (multiple of 4 bytes)
-   *                     start_data         Starting address of the byte where the bitmap image data (pixel array) can be found
-   *                     *file              Bitmap filename
-   */
-    bitmapData getBitmapData(const char *Name_BMP);
-
-  unsigned int orientation;
-  unsigned int char_x;
-  unsigned int char_y;
-  bool backgroundimage;
-  BurstSPI _spi;
-  DigitalOut _cs;
-  unsigned char* font;
-  #ifndef NO_FLASH_BUFFER
-  IAP     iap;
-  int backgroundOrientation;
-  #endif
-
-};
-
-#endif
--- a/SPI_TFT/TextDisplay.cpp	Wed Jan 09 20:54:35 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/* mbed TextDisplay Display Library Base Class
- * Copyright (c) 2007-2009 sford
- * Released under the MIT License: http://mbed.org/license/mit
- */
- 
-#include "TextDisplay.h"
-
-TextDisplay::TextDisplay(const char *name) : Stream(name){
-    _row = 0;
-    _column = 0;
-    if (name == NULL) {
-        _path = NULL;
-    } else {
-        _path = new char[strlen(name) + 2];
-        sprintf(_path, "/%s", name);
-    }
-}
-    
-int TextDisplay::_putc(int value) {
-    if(value == '\n') {
-        _column = 0;
-        _row++;
-        if(_row >= rows()) {
-            _row = 0;
-        }
-    } else {
-        character(_column, _row, value);
-        _column++;
-        if(_column >= columns()) {
-            _column = 0;
-            _row++;
-            if(_row >= rows()) {
-                _row = 0;
-            }
-        }
-    }
-    return value;
-}
-
-// crude cls implementation, should generally be overwritten in derived class
-void TextDisplay::cls() {
-    locate(0, 0);
-    for(int i=0; i<columns()*rows(); i++) {
-        putc(' ');
-    }
-}
-
-void TextDisplay::locate(int column, int row) {
-    _column = column;
-    _row = row;
-}
-
-int TextDisplay::_getc() {
-    return -1;
-}
-        
-void TextDisplay::foreground(uint16_t colour) {
-    _foreground = colour;
-}
-
-void TextDisplay::background(uint16_t colour) {
-    _background = colour;
-}
-
-bool TextDisplay::claim (FILE *stream) {
-    if ( _path == NULL) {
-        fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
-        return false;
-    }
-    if (freopen(_path, "w", stream) == NULL) {
-        // Failed, should not happen
-        return false;
-    }
-    // make sure we use line buffering
-    setvbuf(stdout, NULL, _IOLBF, columns());
-    return true;
-} 
--- a/SPI_TFT/TextDisplay.h	Wed Jan 09 20:54:35 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/* mbed TextDisplay Library Base Class
- * Copyright (c) 2007-2009 sford
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * A common base class for Text displays
- * To port a new display, derive from this class and implement
- * the constructor (setup the display), character (put a character
- * at a location), rows and columns (number of rows/cols) functions.
- * Everything else (locate, printf, putc, cls) will come for free
- *
- * The model is the display will wrap at the right and bottom, so you can
- * keep writing and will always get valid characters. The location is 
- * maintained internally to the class to make this easy
- */
-
-#ifndef MBED_TEXTDISPLAY_H
-#define MBED_TEXTDISPLAY_H
-
-#include "mbed.h"
-
-class TextDisplay : public Stream {
-public:
-
-  // functions needing implementation in derived implementation class
-  /** Create a TextDisplay interface
-     *
-     * @param name The name used in the path to access the strean through the filesystem
-     */
-    TextDisplay(const char *name = NULL);
-
-    /** output a character at the given position
-     *
-     * @param column column where charater must be written
-     * @param  row where character must be written
-     * @param c the character to be written to the TextDisplay
-     */
-    virtual void character(int column, int row, int c) = 0;
-
-    /** return number if rows on TextDisplay
-     * @result number of rows
-     */
-    virtual int rows() = 0;
-
-    /** return number if columns on TextDisplay
-    * @result number of rows
-    */
-    virtual int columns() = 0;
-    
-    // functions that come for free, but can be overwritten
-
-    /** redirect output from a stream (stoud, sterr) to  display
-    * @param stream stream that shall be redirected to the TextDisplay
-    */
-    virtual bool claim (FILE *stream);
-
-    /** clear screen
-    */
-    virtual void cls();
-    virtual void locate(int column, int row);
-    virtual void foreground(uint16_t colour);
-    virtual void background(uint16_t colour);
-    // putc (from Stream)
-    // printf (from Stream)
-    
-protected:
-
-    virtual int _putc(int value);
-    virtual int _getc();
-
-    // character location
-    uint16_t _column;
-    uint16_t _row;
-
-    // colours
-    uint16_t _foreground;
-    uint16_t _background;
-    char *_path;
-};
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SPI_TFT_ILI9320.lib	Fri Jan 11 16:17:42 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/frankvnk/code/SPI_TFT_ILI9320/#630b4da97968
--- a/TouchADS7843/Touch.h	Wed Jan 09 20:54:35 2013 +0000
+++ b/TouchADS7843/Touch.h	Fri Jan 11 16:17:42 2013 +0000
@@ -12,7 +12,7 @@
 #ifndef MBED_Touch_H
 #define MBED_Touch_H
 
-#include "SPI_TFT.h"
+#include "SPI_TFT_ILI9320.h"
 #include "mbed.h"
 
     typedef struct