Programme de test pour lcd ITDB02

Fork of TFTLCD by Todor Todorov

Files at this revision

API Documentation at this revision

Comitter:
ttodorov
Date:
Sat Jun 15 05:34:53 2013 +0000
Parent:
23:eca4414196ca
Child:
25:6cffb758c075
Commit message:
- ported ILI9328 (actually ILI9325D) driver from UTFT; still need to fix screen rotation.

Changed in this revision

ili9328.cpp Show annotated file Show diff for this revision Revisions of this file
ili9328.h Show annotated file Show diff for this revision Revisions of this file
ssd1289.h Show annotated file Show diff for this revision Revisions of this file
--- a/ili9328.cpp	Thu Jun 13 03:47:51 2013 +0000
+++ b/ili9328.cpp	Sat Jun 15 05:34:53 2013 +0000
@@ -22,58 +22,6 @@
 #include "ili9328.h"
 #include "helpers.h"
 
-#define REG_START_OSC                   0x00
-
-#define REG_DRIV_OUT_CTRL               0x01
-#define REG_DRIV_WAV_CTRL               0x02
-#define REG_ENTRY_MOD                   0x03
-#define REG_RESIZE_CTRL                 0x04
-#define REG_DISP_CTRL1                  0x07
-#define REG_DISP_CTRL2                  0x08
-#define REG_DISP_CTRL3                  0x09
-#define REG_DISP_CTRL4                  0x0A
-#define REG_RGB_DISP_IF_CTRL1           0x0C
-#define REG_FRM_MARKER_POS              0x0D
-#define REG_RGB_DISP_IF_CTRL2           0x0F
-#define REG_PWR_CTRL1                   0x10
-#define REG_PWR_CTRL2                   0x11
-#define REG_PWR_CTRL3                   0x12
-#define REG_PWR_CTRL4                   0x13
-#define REG_GRAM_HORIZONTAL_ADDR        0x20
-#define REG_GRAM_VERTICAL_ADDR          0x21
-#define REG_GRAM_READWRITE              0x22
-#define REG_PWR_CTRL7                   0x29
-#define REG_FRM_RATE_COL_CTRL           0x2B
-#define REG_GAMMA_CTRL1                 0x30
-#define REG_GAMMA_CTRL2                 0x31
-#define REG_GAMMA_CTRL3                 0x32
-#define REG_GAMMA_CTRL4                 0x35
-#define REG_GAMMA_CTRL5                 0x36
-#define REG_GAMMA_CTRL6                 0x37
-#define REG_GAMMA_CTRL7                 0x38
-#define REG_GAMMA_CTRL8                 0x39
-#define REG_GAMMA_CTRL9                 0x3C
-#define REG_GAMMA_CTRL10                0x3D
-#define REG_HORIZONTAL_START_ADDR       0x50
-#define REG_HORIZONTAL_END_ADDR         0x51
-#define REG_VERTICAL_START_ADDR         0x52
-#define REG_VERTICAL_END_ADDR           0x53
-#define REG_GATE_SCAN_CTRL1             0x60
-#define REG_GATE_SCAN_CTRL2             0x61
-#define REG_GATE_SCAN_CTRL3             0x6A
-#define REG_PART_IMG1_DISP_POS          0x80
-#define REG_PART_IMG1_START_ADDR        0x81
-#define REG_PART_IMG1_END_ADDR          0x82
-#define REG_PART_IMG2_DISP_POS          0x83
-#define REG_PART_IMG2_START_ADDR        0x84
-#define REG_PART_IMG2_END_ADDR          0x85
-#define REG_PANEL_IF_CTRL1              0x90
-#define REG_PANEL_IF_CTRL2              0x92
-#define REG_PANEL_IF_CTRL3              0x93
-#define REG_PANEL_IF_CTRL4              0x95
-#define REG_PANEL_IF_CTRL5              0x97
-#define REG_PANEL_IF_CTRL6              0x98
-
 ILI9328_LCD::ILI9328_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, BusOut* DATA_PORT, PinName BL, PinName RD, backlight_t blType, float defaultBackLightLevel )
     : LCD( 240, 320, CS, RS, RESET, BL, blType, defaultBackLightLevel ), _lcd_pin_wr( WR )
 {
@@ -104,50 +52,85 @@
     wait_ms( 15 );
     
     Activate();
-    //WriteCmdData( 0x00, 0x0001 ); // oscillator: 1 = on, 0 = off
-    //wait_ms( 1 );
-    WriteCmdData( REG_DRIV_OUT_CTRL, 0x0100 );  // Driver Output Control Register (R01h)
-    WriteCmdData( REG_DRIV_WAV_CTRL, 0x0700 );  // LCD Driving Waveform Control (R02h)
-    WriteCmdData( REG_ENTRY_MOD, 0x1030 );      // Entry Mode (R03h) (BGR=on;ID1=on;ID2=on;AM=0)
-    WriteCmdData( REG_DISP_CTRL2, 0x0302 );
-    WriteCmdData( REG_DISP_CTRL3, 0x0000 );
-    WriteCmdData( REG_DISP_CTRL4, 0x0000 );     // Fmark On
-    WriteCmdData( REG_PWR_CTRL1, 0x0000 );      // Power Control 1 (R10h)
-    WriteCmdData( REG_PWR_CTRL2, 0x0007 );      // Power Control 2 (R11h)
-    WriteCmdData( REG_PWR_CTRL3, 0x0000 );      // Power Control 3 (R12h)
-    WriteCmdData( REG_PWR_CTRL4, 0x0000 );      // Power Control 4 (R13h)
-    wait_ms( 1000 );  
-    WriteCmdData( REG_PWR_CTRL1, 0x14B0 );      // Power Control 1 (R10h)  
-    wait_ms( 500 );  
-    WriteCmdData( REG_PWR_CTRL2, 0x0007 );      // Power Control 2 (R11h)  
-    wait_ms( 500 );  
-    WriteCmdData( REG_PWR_CTRL3, 0x008E );      // Power Control 3 (R12h)
-    WriteCmdData( REG_PWR_CTRL4, 0x0C00 );      // Power Control 4 (R13h)
-    WriteCmdData( REG_PWR_CTRL7, 0x0015 );      // NVM read data 2 (R29h)
-    wait_ms( 500 );
-    WriteCmdData( REG_GAMMA_CTRL1, 0x0000 );         // Gamma Control 1
-    WriteCmdData( REG_GAMMA_CTRL2, 0x0107 );         // Gamma Control 2
-    WriteCmdData( REG_GAMMA_CTRL3, 0x0000 );         // Gamma Control 3
-    WriteCmdData( REG_GAMMA_CTRL4, 0x0203 );         // Gamma Control 4
-    WriteCmdData( REG_GAMMA_CTRL5, 0x0402 );         // Gamma Control 5
-    WriteCmdData( REG_GAMMA_CTRL6, 0x0000 );         // Gamma Control 6
-    WriteCmdData( REG_GAMMA_CTRL7, 0x0207 );         // Gamma Control 7
-    WriteCmdData( REG_GAMMA_CTRL8, 0x0000 );         // Gamma Control 8
-    WriteCmdData( REG_GAMMA_CTRL9, 0x0203 );         // Gamma Control 9
-    WriteCmdData( REG_GAMMA_CTRL10, 0x0403 );        // Gamma Control 10
-    WriteCmdData( REG_HORIZONTAL_START_ADDR, 0x0000 );                      // Window Horizontal RAM Address Start (R50h)
-    WriteCmdData( REG_HORIZONTAL_END_ADDR, _disp_width - 1);   // Window Horizontal RAM Address End (R51h)
-    WriteCmdData( REG_VERTICAL_START_ADDR, 0x0000 );                        // Window Vertical RAM Address Start (R52h)
-    WriteCmdData( REG_VERTICAL_END_ADDR, _disp_height - 1);    // Window Vertical RAM Address End (R53h)
-    WriteCmdData( REG_GATE_SCAN_CTRL1, 0xa700 );    // Driver Output Control (R60h)
-    WriteCmdData( REG_GATE_SCAN_CTRL2, 0x0003 ); // Driver Output Control (R61h) - enable VLE
-    WriteCmdData( REG_PANEL_IF_CTRL1, 0x0010 );  // Panel Interface Control 1 (R90h)
-
-    // Display On
-    WriteCmdData( REG_DISP_CTRL1, 0x0133 );     // Display Control (R07h)
-    wait_ms( 500 );
-    WriteCmd( REG_GRAM_READWRITE );
-  
+    /*
+    short payload = 0;
+    switch ( _orientation )
+    {
+        case PORTRAIT:
+        default:
+            payload |= 0x0020;
+            break;
+    }
+    switch ( _colorDepth )
+    {
+        case RGB16:
+        default:
+            payload |= 0x1000;
+            break;
+    }
+    //WriteCmdData( REG_ENTRY_MOD, payload );
+    */
+    
+    WriteCmdData( 0xE5, 0x78F0 ); // set SRAM internal timing
+    WriteCmdData( 0x01, 0x0100 ); // set Driver Output Control
+    WriteCmdData( 0x02, 0x0200 ); // set 1 line inversion
+    WriteCmdData( 0x03, 0x1030 ); // set GRAM write direction and BGR=1.
+    WriteCmdData( 0x04, 0x0000 ); // Resize register
+    WriteCmdData( 0x08, 0x0207 ); // set the back porch and front porch
+    WriteCmdData( 0x09, 0x0000 ); // set non-display area refresh cycle ISC[3:0]
+    WriteCmdData( 0x0A, 0x0000 ); // FMARK function
+    WriteCmdData( 0x0C, 0x0000 ); // RGB interface setting
+    WriteCmdData( 0x0D, 0x0000 ); // Frame marker Position
+    WriteCmdData( 0x0F, 0x0000 ); // RGB interface polarity
+    // ----------- Power On sequence ----------- //
+    WriteCmdData( 0x10, 0x0000 ); // SAP, BT[3:0], AP, DSTB, SLP, STB
+    WriteCmdData( 0x11, 0x0007 ); // DC1[2:0], DC0[2:0], VC[2:0]
+    WriteCmdData( 0x12, 0x0000 ); // VREG1OUT voltage
+    WriteCmdData( 0x13, 0x0000 ); // VDV[4:0] for VCOM amplitude
+    WriteCmdData( 0x07, 0x0001 );
+    wait_ms( 200 ); // Dis-charge capacitor power voltage
+    WriteCmdData( 0x10, 0x1690 ); // SAP, BT[3:0], AP, DSTB, SLP, STB
+    WriteCmdData( 0x11, 0x0227 ); // Set DC1[2:0], DC0[2:0], VC[2:0]
+    wait_ms( 50 ); // Delay 50ms
+    WriteCmdData( 0x12, 0x000D ); // 0012
+    wait_ms( 50 ); // Delay 50ms
+    WriteCmdData( 0x13, 0x1200 ); // VDV[4:0] for VCOM amplitude
+    WriteCmdData( 0x29, 0x000A ); // 04  VCM[5:0] for VCOMH
+    WriteCmdData( 0x2B, 0x000D ); // Set Frame Rate
+    wait_ms( 50 ); // Delay 50ms
+    WriteCmdData( 0x20, 0x0000 ); // GRAM horizontal Address
+    WriteCmdData( 0x21, 0x0000 ); // GRAM Vertical Address
+    // ----------- Adjust the Gamma Curve ----------//
+    WriteCmdData( 0x30, 0x0000 );
+    WriteCmdData( 0x31, 0x0404 );
+    WriteCmdData( 0x32, 0x0003 );
+    WriteCmdData( 0x35, 0x0405 );
+    WriteCmdData( 0x36, 0x0808 );
+    WriteCmdData( 0x37, 0x0407 );
+    WriteCmdData( 0x38, 0x0303 );
+    WriteCmdData( 0x39, 0x0707 );
+    WriteCmdData( 0x3C, 0x0504 );
+    WriteCmdData( 0x3D, 0x0808 );
+    //------------------ Set GRAM area ---------------//
+    WriteCmdData( 0x50, 0x0000 ); // Horizontal GRAM Start Address
+    WriteCmdData( 0x51, 0x00EF ); // Horizontal GRAM End Address
+    WriteCmdData( 0x52, 0x0000 ); // Vertical GRAM Start Address
+    WriteCmdData( 0x53, 0x013F ); // Vertical GRAM Start Address
+    WriteCmdData( 0x60, 0xA700 ); // Gate Scan Line
+    WriteCmdData( 0x61, 0x0000 ); // NDL,VLE, REV
+    WriteCmdData( 0x6A, 0x0000 ); // set scrolling line
+    //-------------- Partial Display Control ---------//
+    WriteCmdData( 0x80, 0x0000 );
+    WriteCmdData( 0x81, 0x0000 );
+    WriteCmdData( 0x82, 0x0000 );
+    WriteCmdData( 0x83, 0x0000 );
+    WriteCmdData( 0x84, 0x0000 );
+    WriteCmdData( 0x85, 0x0000 );
+    //-------------- Panel Control -------------------//
+    WriteCmdData( 0x90, 0x0010 ); 
+    WriteCmdData( 0x92, 0x0000 );
+    WriteCmdData( 0x07, 0x0133 ); // 262K color and display ON
+    
     Deactivate();
 }
 
@@ -179,30 +162,12 @@
 
 void ILI9328_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 )
 {
-    /*
-    if ( _orientation == PORTRAIT || _orientation == PORTRAIT_REV )
-    {
-        WriteCmdData( 0x44, ( x2 << 8 ) + x1 );
-        WriteCmdData( 0x45, y1 );
-        WriteCmdData( 0x46, y2 );
-        WriteCmdData( 0x4e, x1 );
-        WriteCmdData( 0x4f, y1 );
-    }
-    else
-    {
-        WriteCmdData( 0x44, ( y2 << 8 ) + y1 );
-        WriteCmdData( 0x45, x1 );
-        WriteCmdData( 0x46, x2 );
-        WriteCmdData( 0x4e, y1 );
-        WriteCmdData( 0x4f, x1 );
-    }
-    */
-    WriteCmdData( REG_HORIZONTAL_START_ADDR, x1 );
-    WriteCmdData( REG_HORIZONTAL_END_ADDR, x2 );
-    WriteCmdData( REG_VERTICAL_START_ADDR, y1 );
-    WriteCmdData( REG_VERTICAL_END_ADDR, y2 );
-    WriteCmdData( REG_GRAM_HORIZONTAL_ADDR, x1 );
-    WriteCmdData( REG_GRAM_VERTICAL_ADDR, y1 );
+    WriteCmdData( 0x20, x1 );
+    WriteCmdData( 0x21, y1 );
+    WriteCmdData( 0x50, x1 );
+    WriteCmdData( 0x52, y1 );
+    WriteCmdData( 0x51, x2 );
+    WriteCmdData( 0x53, y2 );
     WriteCmd( 0x22 );
 }
 
--- a/ili9328.h	Thu Jun 13 03:47:51 2013 +0000
+++ b/ili9328.h	Sat Jun 15 05:34:53 2013 +0000
@@ -35,18 +35,143 @@
 extern "C" {
 #endif
 
+/** Represents a LCD instance.
+ *
+ * This is the utility class, through which the display can be manipulated
+ * and graphics objects can be shown to the user.  A known display, which
+ * works with this library is the INANBO-T24-ILI9328-V11 - a RGB TFT
+ * with 240x320 pixels resolution and 65K/262K colors, using 8/16-bit interface.
+ *
+ * The display works with a supply voltage of 2.8-3.3 volts for both logic and
+ * backlight.  It can be driven in 8bit or 16bit interface mode. (Current
+ * version of the driver works only in 16bit mode for now.)
+ *
+ * How to use:
+ * \code
+ * // include the library, this will also pull in the header for the provided fonts
+ * #include "ili9328.h"
+ * 
+ * // prepare the data bus for writing commands and pixel data
+ * BusOut dataBus( p30, p29, p28, p27, p26, p25, p24, p23, p22, p21, p20, p19, p18, p17, p16, p15 ); // 16 pins
+ * // create the lcd instance
+ * ILI9328_LCD lcd( p14, p13, p12, p11, &dataBus ); // control pins and data bus
+ *
+ * int main()
+ * {
+ *     // initialize display - place it in standard portrait mode and set background to black and
+ *     //                      foreground to white color.
+ *     lcd.Initialize();
+ *     // set current font to the smallest 8x12 pixels font.
+ *     lcd.SetFont( Font8x12 );
+ *     // print something on the screen
+ *     lcd.Print( "Hello, World!", CENTER, 25 ); // align text to center horizontally and use starndard colors
+ *
+ *     while ( 1 ) { }
+ * }
+ *
+ * \endcode
+ * \version 0.1
+ * \author Todor Todorov
+ */
 class ILI9328_LCD : public LCD
 {
 public:
+    /** Creates a new instance of the class.
+     *
+     * \param CS Pin for the ChipSelect signal.
+     * \param RESET Pin for the RESET line.
+     * \param RS Pin for the RS signal.
+     * \param WR Pin for the WR signal.
+     * \param DATA_PORT Address of the data bus for transfer of commands and pixel data.
+     * \param BL Pin for controlling the backlight. By default not used.
+     * \param RD Pin for the RD signal. This line is not needed by the driver, so if you would like to
+     *       use the pin on the mbed for something else, just pull-up the respective pin on the LCD high,
+     *       and do not assign a value to this parameter when creating the controller instance.
+     * \param blType The backlight type, the default is to utilize the pin - if supplied - as a simple on/off switch
+     * \param defaultBacklightLevel If using PWM to control backlight, this would be the default brightness in percent after LCD initialization.
+     */
     ILI9328_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, BusOut* DATA_PORT, PinName BL = NC, PinName RD = NC, backlight_t blType = Constant, float defaultBackLightLevel = 1.0 );
+    
+    /** Initialize display.
+     *
+     * Wakes up the display from sleep, initializes power parameters.
+     * This function must be called first, befor any painting on the
+     * display is done, otherwise the positioning of graphical elements
+     * will not work properly and any paynt operation will not be visible
+     * or produce garbage.
+     *
+     * \param oritentation The display orientation, landscape is default.
+     * \param colors The correct color depth to use for the pixel data. Value is disregarded.
+     */
     virtual void Initialize( orientation_t orientation = LANDSCAPE, colordepth_t colors = RGB16 );
+    
+    /** Puts the display to sleep.
+     *
+     * When the display is in sleep mode, its power consumption is
+     * minimized.  Before new pixel data can be written to the display
+     * memory, the controller needs to be brought out of sleep mode.
+     * \sa #WakeUp( void );
+     * \remarks The result of this operation might not be exactly as
+     *          expected. Putting the display to sleep will cause the
+     *          controller to switch to the standard color of the LCD,
+     *          so depending on whether the display is normally white,
+     *          or normally dark, the screen might or might not go
+     *          dark.  Additional power saving can be achieved, if
+     *          the backlight of the used display is not hardwired on
+     *          the PCB and can be controlled via the BL pin.
+     */
     virtual void Sleep( void );
+    
+    /** Wakes up the display from sleep mode.
+     *
+     * This function needs to be called before any other, when the
+     * display has been put into sleep mode by a previois call to
+     * #Sleep( void ).
+     */
     virtual void WakeUp( void );
 
 protected:
+    /** Sends a command to the display.
+     *
+     * \param cmd The display command.
+     * \remarks Commands are controller-specific and this function needs to
+     *          be implemented separately for each available controller.
+     */
     virtual void WriteCmd( unsigned short cmd );
+    
+    /** Sends pixel data to the display.
+     *
+     * \param data The display data.
+     * \remarks Sending data is controller-specific and this function needs to
+     *          be implemented separately for each available controller.
+     */
     virtual void WriteData( unsigned short data );
+    
+    /** Assigns a chunk of the display memory to receive data.
+     *
+     * When data is sent to the display after this function completes, the opertion will
+     * start from the begining of the assigned address (pixel position) and the pointer
+     * will be automatically incremented so that the next data write operation will continue
+     * with the next pixel from the memory block.  If more data is written than available
+     * pixels, at the end of the block the pointer will jump back to its beginning and
+     * commence again, until the next address change command is sent to the display.
+     *
+     * \param x1 The X coordinate of the pixel at the beginning of the block.
+     * \param y1 The Y coordinate of the pixel at the beginning of the block.
+     * \param x2 The X coordinate of the pixel at the end of the block.
+     * \param y2 The Y coordinate of the pixel at the end of the block.
+     * \remarks Addressing commands are controller-specific and this function needs to be
+     *          implemented separately for each available controller.
+     */
     virtual void SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 );
+    
+    /** Sets the color of the pixel at the address pointer of the controller.
+     *
+     * This function is to be provided by each implementation separately in
+     * order to account for different color depth used by the controller.
+     * \param color The color of the pixel.
+     * \param mode The depth (palette) of the color.
+     */
     virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB24 );
 
 private:
--- a/ssd1289.h	Thu Jun 13 03:47:51 2013 +0000
+++ b/ssd1289.h	Sat Jun 15 05:34:53 2013 +0000
@@ -146,7 +146,7 @@
     /** Sends pixel data to the display.
      *
      * \param data The display data.
-     * \remarks Sendin data is controller-specific and this function needs to
+     * \remarks Sending data is controller-specific and this function needs to
      *          be implemented separately for each available controller.
      */
     virtual void WriteData( unsigned short data );