LPC1768 Mini-DK board with 2.8" SPI TFT and SPI touch

Dependencies:   Mini-DK mbed SDFileSystem

WARNING: filetoflash (SD to CPU flash)

The SPI_TFT library called from Mini-DK.lib 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).

Files at this revision

API Documentation at this revision

Comitter:
frankvnk
Date:
Fri Jan 04 09:52:16 2013 +0000
Parent:
6:b547fb6c1095
Child:
8:94f3d4c62f6a
Commit message:
Code cleanup / comments added

Changed in this revision

Mini-DK/Mini_DK.h Show annotated file Show diff for this revision Revisions of this file
Mini-DK/SPI_TFT/BurstSPI.lib Show annotated file Show diff for this revision Revisions of this file
Mini-DK/SPI_TFT/SPI_TFT.cpp Show annotated file Show diff for this revision Revisions of this file
Mini-DK/SPI_TFT/SPI_TFT.h Show annotated file Show diff for this revision Revisions of this file
Mini-DK/TouchADS7843/Touch.cpp Show annotated file Show diff for this revision Revisions of this file
Mini-DK/TouchADS7843/Touch.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Mini-DK/Mini_DK.h	Thu Jan 03 21:24:05 2013 +0000
+++ b/Mini-DK/Mini_DK.h	Fri Jan 04 09:52:16 2013 +0000
@@ -1,3 +1,12 @@
+/**************************************************************************************************
+ *****                                                                                        *****
+ *****  Name: Mini_DK.h                                                                       *****
+ *****  Ver.: 1.0                                                                             *****
+ *****  Date: 04/01/2013                                                                      *****
+ *****  Auth: Erik Olieman                                                                    *****
+ *****  Func: Includes, pin and macro Declarations for the Mini DK board                      *****
+ *****                                                                                        *****
+ **************************************************************************************************/
 #include "SPI_TFT.h"
 #include "Arial12x12.h"
 #include "Arial24x23.h"
--- a/Mini-DK/SPI_TFT/BurstSPI.lib	Thu Jan 03 21:24:05 2013 +0000
+++ b/Mini-DK/SPI_TFT/BurstSPI.lib	Fri Jan 04 09:52:16 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Sissors/code/BurstSPI/#5ef4a019e0db
+http://mbed.org/users/Sissors/code/BurstSPI/#a8e55f7cbfee
--- a/Mini-DK/SPI_TFT/SPI_TFT.cpp	Thu Jan 03 21:24:05 2013 +0000
+++ b/Mini-DK/SPI_TFT/SPI_TFT.cpp	Fri Jan 04 09:52:16 2013 +0000
@@ -1,8 +1,17 @@
-/* mbed library for 240*320 pixel TFT with ILI9320 LCD Controller
- * Rewrite from Peter Drescher code - http://mbed.org/cookbook/SPI-driven-QVGA-TFT
- *
- * TODO : BMP routine
- */
+/**************************************************************************************************
+ *****                                                                                        *****
+ *****  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       *****
+ *****                                                                                        *****
+ **************************************************************************************************/
+
+// TODO : BMP routine
 
 
 
@@ -33,23 +42,12 @@
     else return 240;
 }
 
-//
 void SPI_TFT::set_orientation(unsigned int o)
 {
     orientation = o;
     WindowMax();
 }
 
-// ILI9320
-// Orientation is only set before 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 SPI_TFT::mod_orientation(void)
 {
     switch (orientation)
--- a/Mini-DK/SPI_TFT/SPI_TFT.h	Thu Jan 03 21:24:05 2013 +0000
+++ b/Mini-DK/SPI_TFT/SPI_TFT.h	Fri Jan 04 09:52:16 2013 +0000
@@ -1,4 +1,15 @@
-// mbed library for 240*320 pixel display TFT
+/**************************************************************************************************
+ *****                                                                                        *****
+ *****  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
@@ -54,26 +65,26 @@
    */
   void wr_reg (unsigned char reg, unsigned short val);
 
-  /** Get the width of the screen in pixel
+  /** Get the width of the screen in pixels
    *
    * @param
-   * @returns width of screen in pixel
+   * @returns width of screen in pixels
    *
    */
   virtual int width();
 
-  /** Get the height of the screen in pixel
+  /** Get the height of the screen in pixels
    *
-   * @returns height of screen in pixel
+   * @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
+   * @param x (horizontal position)
+   * @param y (vertical position)
+   * @param color (16 bit pixel color)
    */
   virtual void pixel(int x, int y,int colour);
 
@@ -134,7 +145,7 @@
    */
   virtual void locate(int x, int y);
 
-  /** Fill the screen with _backgroun color
+  /** Fill the screen with _background color
    *
    */
   virtual void cls (void);
@@ -154,9 +165,9 @@
    */
   virtual int columns(void);
 
-  /** calculate the max number of columns
+  /** calculate the max number of rows
    *
-   * @returns max column
+   * @returns max rows
    * depends on actual font size
    *
    */
@@ -207,8 +218,8 @@
    * @returns 1 if bmp file was found and painted
    * @returns -1 if bmp file was not found
    * @returns -2 if bmp file is not 16bit
-   * @returns -3 if bmp file is to big for screen
-   * @returns -4 if buffer malloc go wrong
+   * @returns -3 if bmp file is too big for screen
+   * @returns -4 if buffer malloc goes wrong
    *
    *   bitmap format: 16 bit R5 G6 B5
    *
@@ -225,12 +236,12 @@
    *
    * @param f pointer to font array
    *
-   *   font array can created with GLCD Font Creator from http://www.mikroe.com
+   *   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 byte / char
-   *   - the vertial size in pixel
-   *   - the horizontal size in pixel
-   *   - the number of byte per vertical line
+   *   - 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[]
    *
    */
@@ -243,7 +254,25 @@
    *
    */
   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);
+
   BurstSPI _spi;
   DigitalOut _cs;
   unsigned char* font;
@@ -296,7 +325,6 @@
    /** Start data sequence to the LCD controller
    *
    */
-  //void wr_dat_start();
   void wr_dat_start(void);
 
   /** Write a command the LCD controller
@@ -320,6 +348,14 @@
    */
   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 );
 
   unsigned int orientation;
--- a/Mini-DK/TouchADS7843/Touch.cpp	Thu Jan 03 21:24:05 2013 +0000
+++ b/Mini-DK/TouchADS7843/Touch.cpp	Fri Jan 04 09:52:16 2013 +0000
@@ -1,5 +1,17 @@
-// Code based on Carlos E. Vidales tutorial : How To Calibrate Touch Screens
-// http://www.embedded.com/design/configurable-systems/4023968/How-To-Calibrate-Touch-Screens
+/**************************************************************************************************
+ *****                                                                                        *****
+ *****  Name: Touch.cpp                                                                       *****
+ *****  Ver.: 1.0                                                                             *****
+ *****  Date: 04/01/2013                                                                      *****
+ *****  Auth: Frank Vannieuwkerke                                                             *****
+ *****        Erik Olieman                                                                    *****
+ *****  Func: Touch driver for use with ADS7843                                               *****
+ *****                                                                                        *****
+ *****  Code based on Carlos E. Vidales tutorial :                                            *****
+ *****  How To Calibrate Touch Screens                                                        *****
+ *****  www.embedded.com/design/configurable-systems/4023968/How-To-Calibrate-Touch-Screens   *****
+ *****                                                                                        *****
+ **************************************************************************************************/
 
 #include "Touch.h"
 #include "mbed.h"
@@ -56,7 +68,6 @@
     Temp >>= 3;
     Temp &= 0xfff;
     Temp /= 4;        // Scaling : return value range must be between 0 and 1024
-//    Temp = (((msb & 0x7f) <<8) | lsb) >> 3;        // 12 bit
     return(Temp);
 }
 
--- a/Mini-DK/TouchADS7843/Touch.h	Thu Jan 03 21:24:05 2013 +0000
+++ b/Mini-DK/TouchADS7843/Touch.h	Fri Jan 04 09:52:16 2013 +0000
@@ -1,3 +1,13 @@
+/******************************************************************
+ *****                                                        *****
+ *****  Name: Touch.h                                         *****
+ *****  Ver.: 1.0                                             *****
+ *****  Date: 04/01/2013                                      *****
+ *****  Auth: Frank Vannieuwkerke                             *****
+ *****        Erik Olieman                                    *****
+ *****  Func: Touch driver for use with ADS7843               *****
+ *****                                                        *****
+ ******************************************************************/
 
 #ifndef MBED_Touch_H
 #define MBED_Touch_H
@@ -38,9 +48,43 @@
     */
     TouchScreenADS7843(PinName tp_mosi, PinName tp_miso, PinName tp_sclk, PinName tp_cs, PinName tp_irq, SPI_TFT *_LCD);
 
+    /*
+    * Draw a 2 by 2 dot on the LCD screen
+    *
+    * @param x (horizontal position)
+    * @param y (vertical position)
+    * @param color (16 bit pixel color)
+    *
+    */
     void TP_DrawPoint(unsigned int Xpos,unsigned int Ypos,unsigned int color);
+    
+    /*
+    * Obtain averaged data from ADS7846
+    * does 9 consecutive reads and only stores averaged data
+    * when the 9 points are within the treshold limits.
+    *
+    * @param screenPTR (pointer to store data)
+    * @returns 1 on success
+    * @returns 0 on failure
+    *
+    * If called with screenPTR = NULL - 'screen' variable is used, otherwise (parameter) is used.
+    *
+    */
     unsigned char Read_Ads7846(Coordinate * screenPtr = NULL);
+
+    /*
+    * Calibrate the touch panel.
+    * Three crosshairs are drawn and need to be touched in sequence.  
+    * A calibration matrix is set accordingly.
+    *
+    */
     void TouchPanel_Calibrate(void);
+    
+    /*
+    * Obtain real x,y coordinates
+    * The x,y coordinates are calculated using the calibration matrix.
+    *
+    */
     unsigned char getDisplayPoint(void);
 
     SPI_TFT    *LCD;
@@ -58,9 +102,45 @@
     Coordinate ScreenSample[3];
     Matrix matrix;
 
+    /*
+    * Obtain raw x,y data from ADS7846
+    *
+    * @param pointer to raw x and y coordinates (pointer to store data)
+    * @returns x (horizontal position)
+    * @returns y (vertical position)
+    *
+    */
     void TP_GetAdXY(int *x,int *y);
+    
+    /*
+    * Obtain raw single channel data from ADS7846 (Called by TP_GetADXY)
+    *
+    * @param channel to be read (CHX or CHY)
+    * @returns raw scaled down value (return value range must be between 0 and 1024)
+    *
+    */
     int Read_XY(unsigned char XY);
+    
+    /*
+    * Draw a calibration crosshair on the LCD screen
+    *
+    * @param x (horizontal position)
+    * @param y (vertical position)
+    *
+    */
     void DrawCross(unsigned int Xpos,unsigned int Ypos);
+    
+    /*
+    * Set the calibration matrix
+    *
+    * @param displayPTR (pointer to display data)
+    * @param screenPTR  (pointer to screen data)
+    * @param matrixPTR  (pointer to calibration matrix)
+    *
+    * @returns 0 when matrix.divider != 0
+    * @returns 1 when matrix.divider = 0
+    *
+    */
     unsigned char setCalibrationMatrix( Coordinate * displayPtr,Coordinate * screenPtr,Matrix * matrixPtr);
 
 };
--- a/main.cpp	Thu Jan 03 21:24:05 2013 +0000
+++ b/main.cpp	Fri Jan 04 09:52:16 2013 +0000
@@ -123,7 +123,6 @@
     TP.TouchPanel_Calibrate();
     TFT.set_font((unsigned char*) Arial12x12);
     TFT.set_orientation(0);
-//    TFT.cls();
     TFT.locate(0,0);
     TFT.printf(" X:");
     TFT.locate(70,0);
@@ -136,11 +135,10 @@
             {
                 TP.getDisplayPoint() ;
                 TP.TP_DrawPoint(TP.display.x,TP.display.y, Blue);
-//                TFT.rect(TP.display.x,TP.display.y,1,1,Red);
                 TFT.locate(25,0);
-                printf("%03d",TP.display.x);
+                TFT.printf("%03d",TP.display.x);
                 TFT.locate(95,0);
-                printf("%03d",TP.display.y);
+                TFT.printf("%03d",TP.display.y);
                 // Touchscreen area is larger than LCD area.
                 // We use the bottom area outside the LCD area to clear the screen (y value > 320).
                 if (TP.display.y > 320)