Fork of TFTLCD with new support for SSD1963 ad HX8352-A controller.

Dependents:   TFTLCD_Fork_Test

Fork of TFTLCD by Todor Todorov

Files at this revision

API Documentation at this revision

Comitter:
RobertFischer
Date:
Fri May 30 08:39:59 2014 +0000
Parent:
27:26491d710e72
Commit message:
First test of TFTLCD with new support for SSD1963 and HX8352-A display controller. Still some scrambled output

Changed in this revision

hx8352a.cpp Show annotated file Show diff for this revision Revisions of this file
hx8352a.h Show annotated file Show diff for this revision Revisions of this file
ssd1963.cpp Show annotated file Show diff for this revision Revisions of this file
ssd1963.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hx8352a.cpp	Fri May 30 08:39:59 2014 +0000
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
+ * Copyright (C)2012 Todor Todorov.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to:
+ *
+ * Free Software Foundation, Inc.
+ * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
+ *
+ *********************************************************************/
+#include "hx8352a.h"
+#include "helpers.h"
+
+HX8352A_LCD::HX8352A_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, BusOut* DATA_PORT, PinName BL, PinName RD, backlight_t blType, float defaultBackLightLevel )
+    : LCD( 240, 400, CS, RS, RESET, BL, blType, defaultBackLightLevel ), _lcd_pin_wr( WR )
+{
+    _lcd_port = DATA_PORT;
+    if ( RD != NC ) _lcd_pin_rd = new DigitalOut( RD );
+    else _lcd_pin_rd = 0;
+}
+
+void HX8352A_LCD::Initialize( orientation_t orientation, colordepth_t colors )
+{
+    _orientation = orientation;
+    _colorDepth = colors;
+    
+    wait_ms( 100 );
+    _lcd_pin_reset = HIGH;
+    wait_ms( 50 );
+    _lcd_pin_reset = LOW;
+    wait_ms( 50 );
+    _lcd_pin_reset = HIGH;
+    _lcd_pin_cs = HIGH;
+    //_lcd_pin_rd = HIGH;
+     if ( _lcd_pin_bl != 0 )
+        *_lcd_pin_bl = HIGH;
+    else if ( _bl_pwm != 0 )
+        *_bl_pwm = _bl_pwm_default;
+    _lcd_pin_wr = HIGH;
+    wait_ms( 55 );
+    
+    Activate();
+    Activate();
+    WriteCmdData( 0x83, 0x0002 );   //TESTM=1 
+    
+    WriteCmdData( 0x85, 0x0003 );  //VDC_SEL=011
+    WriteCmdData( 0x8B, 0x0001 );
+    WriteCmdData( 0x8C, 0x0093 ); //STBA[7]=1,STBA[5:4]=01,STBA[1:0]=11
+    
+    WriteCmdData( 0x91, 0x0001 ); //DCDC_SYNC=1
+    
+    WriteCmdData( 0x83, 0x0000 );
+    //WriteCmdData( 0x00, 0x0001 ); //TESTM=0
+    
+    //Gamma Setting   
+    WriteCmdData( 0x3E, 0x00B0);
+    WriteCmdData( 0x3F, 0x0003 );
+    WriteCmdData( 0x40, 0x0010 );
+    WriteCmdData( 0x41, 0x0056 );
+    WriteCmdData( 0x42, 0x0013 );
+    WriteCmdData( 0x43, 0x0046 );
+    WriteCmdData( 0x44, 0x0023 );
+    WriteCmdData( 0x45, 0x0076 );
+    WriteCmdData( 0x46, 0x0000 );
+    WriteCmdData( 0x47, 0x005E );
+    WriteCmdData( 0x48, 0x004F );
+    WriteCmdData( 0x49, 0x0040 );
+
+    //**********Power On sequence************
+    WriteCmdData( 0x17, 0x0091 );
+    
+    WriteCmdData( 0x2B, 0x00F9 );
+    wait_ms( 15 );
+    
+    WriteCmdData( 0x1B, 0x0014 );
+    
+    WriteCmdData( 0x1A, 0x0011 );
+    
+    WriteCmdData( 0x1C, 0x0006 );
+    
+    WriteCmdData( 0x1F, 0x0042 );
+    wait_ms( 20 );
+    
+    WriteCmdData( 0x19, 0x000A );
+    
+    WriteCmdData( 0x19, 0x001A );
+    wait_ms( 40 );
+    
+    WriteCmdData( 0x19, 0x0012 );
+    wait_ms( 40 );
+    
+    WriteCmdData( 0x1E, 0x0027 );
+    wait_ms( 100 );
+    
+    //**********DISPLAY ON SETTING***********
+
+    WriteCmdData( 0x24, 0x0060 );
+
+    WriteCmdData( 0x3D, 0x0040 );
+
+    WriteCmdData( 0x34, 0x0038 );
+
+    WriteCmdData( 0x35, 0x0038 );
+
+    WriteCmdData( 0x24, 0x0038 );
+    wait_ms( 40 );
+
+    WriteCmdData( 0x24, 0x003C );
+
+    //WriteCmdData( 0x16, 0x00B8 );
+
+    WriteCmdData( 0x01, 0x0006 );
+
+    WriteCmdData( 0x55, 0x0000 );
+
+    WriteCmdData( 0x02, 0x0000 );
+    WriteCmdData( 0x03, 0x0000 );
+    WriteCmdData( 0x04, 0x0000 );
+    WriteCmdData( 0x05, 0x00EF );
+
+    WriteCmdData( 0x06, 0x0000 );
+    WriteCmdData( 0x07, 0x0000 );
+    WriteCmdData( 0x08, 0x0001 );
+    WriteCmdData( 0x09, 0x008F );
+    
+    
+    WriteCmd( 0x16 );
+    switch ( _orientation )
+    {
+        case LANDSCAPE: WriteData( 0xA8 ); break;
+        case PORTRAIT_REV: WriteData( 0xDC ); break;
+        case LANDSCAPE_REV: WriteData( 0x6C ); break;
+        case PORTRAIT:
+        default: WriteData( 0x08 ); break;
+    }
+    
+    WriteCmd( 0x22 );
+    wait_ms( 10 );
+    
+    ClearXY();
+    Deactivate();
+}
+
+/*
+void HX8352A_LCD::Sleep( void )
+{
+    Activate();
+    WriteCmd( 0x28 );
+    wait_ms( 10 );
+    WriteCmd( 0x10 );
+    wait_ms( 125 );
+    LCD::Sleep();
+    Deactivate();
+}
+
+void HX8352A_LCD::WakeUp( void )
+{
+    Activate();
+    WriteCmd( 0x29 );
+    wait_ms( 10 );
+    WriteCmd( 0x11 );
+    wait_ms( 125 );
+    LCD::WakeUp();
+    Deactivate();
+}
+*/
+
+void HX8352A_LCD::WriteCmd( unsigned short cmd )
+{
+    _lcd_pin_rs = LOW;
+    _lcd_port->write( cmd );
+    pulseLow( _lcd_pin_wr );}
+
+void HX8352A_LCD::WriteData( unsigned short data )
+{
+    _lcd_pin_rs = HIGH;
+    _lcd_port->write( data );
+    pulseLow( _lcd_pin_wr );
+}
+
+void HX8352A_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 )
+{
+    switch ( _orientation ) {
+        case LANDSCAPE:
+        case LANDSCAPE_REV:
+            WriteCmdData( 0x02,x1>>8 );
+            WriteCmdData( 0x03,x1 );
+            WriteCmdData( 0x04,x2>>8 );
+            WriteCmdData( 0x05,x2 );
+            WriteCmdData( 0x06,y1>>8 );
+            WriteCmdData( 0x07,y1 );
+            WriteCmdData( 0x08,y2>>8 );
+            WriteCmdData( 0x09,y2 );
+            break;
+            
+        case PORTRAIT_REV:
+        case PORTRAIT:
+        default:
+            WriteCmdData( 0x02,x1>>8 );
+            WriteCmdData( 0x03,x1 );
+            WriteCmdData( 0x04,x2>>8 );
+            WriteCmdData( 0x05,x2 );
+            WriteCmdData( 0x06,y1>>8 );
+            WriteCmdData( 0x07,y1 );
+            WriteCmdData( 0x08,y2>>8 );
+            WriteCmdData( 0x09,y2 );
+            break;
+    }
+    WriteCmd( 0x22 ); // RAMWR
+}
+
+void HX8352A_LCD::SetPixelColor( unsigned int color, colordepth_t mode )
+{
+    unsigned char r = 0, g = 0, b = 0;
+    unsigned short clr;
+    if ( _colorDepth == RGB16 )
+    {
+        switch ( mode )
+        {
+            case RGB16:
+                WriteData( color & 0xFFFF );
+                break;
+            case RGB18:
+                r = ( color >> 10 ) & 0xF8;
+                g = ( color >> 4 ) & 0xFC;
+                b = ( color >> 1 ) & 0x1F;
+                clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | b );
+                WriteData( clr );
+                break;
+            case RGB24:
+                r = ( color >> 16 ) & 0xF8;
+                g = ( color >> 8 ) & 0xFC;
+                b = color & 0xF8;
+                clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | ( b >> 3 ) );
+                WriteData( clr );
+                break;
+        }
+    }
+    else if ( _colorDepth == RGB18 )
+    {
+        switch ( mode )
+        {
+            case RGB16:
+                r = ( ( color >> 8 ) & 0xF8 ) | ( ( color & 0x8000 ) >> 13 );
+                g = ( color >> 3 ) & 0xFC;
+                b = ( ( color << 3 ) & 0xFC ) | ( ( color >> 3 ) & 0x01 );
+                break;
+            case RGB18:
+                b = ( color << 2 ) & 0xFC;
+                g = ( color >> 4 ) & 0xFC;
+                r = ( color >> 10 ) & 0xFC;
+                break;
+            case RGB24:
+                r = ( color >> 16 ) & 0xFC;
+                g = ( color >> 8 ) & 0xFC;
+                b = color & 0xFC;
+                break;
+        }
+        WriteData( r );
+        WriteData( g );
+        WriteData( b );
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hx8352a.h	Fri May 30 08:39:59 2014 +0000
@@ -0,0 +1,188 @@
+/** \file hx8352.h
+ *  \brief mbed TFT LCD controller for displays with the HX8352-A IC (serial interface).
+ *  \copyright GNU Public License, v2. or later
+ *
+ * A known display with this type of controller chip is the 
+ * 3.2" Width 400*240 TFT LCD Module Display
+ *
+ * This library is based on the Arduino/chipKIT UTFT library by Henning
+ * Karlsen, http://henningkarlsen.com/electronics/library.php?id=52
+ *
+ * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
+ *
+ * Copyright (C)2012 Todor Todorov.
+ *
+ * Copyright (C)2012 Robert Fischer.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to:
+ *
+ * Free Software Foundation, Inc.
+ * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
+ *
+ *********************************************************************/
+#ifndef TFTLCD_HX8352A
+#define TFTLCD_HX8352A
+
+#include "lcd_base.h"
+
+#ifdef __cplusplus
+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 ITDB02-2.2SP from iTeadStudio - a RGB TFT
+ * with 176x220 pixels resolution and 65K/256K colors, using serial interface.
+ *
+ * The display needs 4 or 5 pins to work with mbed. As it uses +3.3V for power
+ * and logic, as well as the backlight, interfacing could happen directly
+ * to the mbed without the need of shields or level shifters as with Arduino.
+ *
+ * How to use:
+ * \code
+ * // include the library, this will also pull in the header for the provided fonts
+ * #include "hx8352a.h"
+ * 
+ * // create the lcd instance
+ * HX8352A_LCD lcd( p14, p13, p12, p11 ); // control pins
+ *
+ * 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 HX8352A_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 SCL Pin for the serial clock signal.
+     * \param SDI Pin for the serial data signal.
+     * \param BL Pin for controlling the backlight. By default not used.
+     * \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.
+     */
+    HX8352A_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, BusOut* DATA_PORT, PinName BL, PinName RD, 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.
+     */
+    virtual void Initialize( orientation_t orientation = PORTRAIT, 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 Sendin 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 = RGB16 );
+    
+    
+private:
+    DigitalOut  _lcd_pin_wr;
+    BusOut*     _lcd_port;
+    DigitalOut* _lcd_pin_bl;
+    DigitalOut* _lcd_pin_rd;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TFTLCD_HX8352A */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ssd1963.cpp	Fri May 30 08:39:59 2014 +0000
@@ -0,0 +1,308 @@
+/*
+ * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
+ * Copyright (C)2012 Todor Todorov.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to:
+ *
+ * Free Software Foundation, Inc.
+ * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
+ *
+ *********************************************************************/
+#include "ssd1963.h"
+#include "helpers.h"
+
+SSD1963_LCD::SSD1963_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, BusOut* DATA_PORT, PinName BL, PinName RD, backlight_t blType, float defaultBackLightLevel )
+    : LCD( 272, 480, CS, RS, RESET, BL, blType, defaultBackLightLevel ), _lcd_pin_wr( WR )
+{
+    _lcd_port = DATA_PORT;
+    if ( RD != NC ) _lcd_pin_rd = new DigitalOut( RD );
+    else _lcd_pin_rd = 0;
+}
+
+void SSD1963_LCD::Initialize( orientation_t orientation, colordepth_t colors )
+{
+    _orientation = orientation;
+    _colorDepth = colors;
+    
+    _lcd_pin_reset = HIGH;
+    wait_ms( 5 );
+    _lcd_pin_reset = LOW;
+    wait_ms( 15 );
+    _lcd_pin_reset = HIGH;
+    _lcd_pin_cs = HIGH;
+    if ( _lcd_pin_bl != 0 )
+        *_lcd_pin_bl = HIGH;
+    else if ( _bl_pwm != 0 )
+        *_bl_pwm = _bl_pwm_default;
+    if ( _lcd_pin_rd != 0 )
+        *_lcd_pin_rd = HIGH;
+    _lcd_pin_wr = HIGH;
+    wait_ms( 15 );
+    
+    Activate();
+    // Set PLL MN -------------------------------------------------------------
+    // @Parameters : 3
+    WriteCmd(0xE2);
+    WriteData(0x23);             // N[7:0] : Multiplier (N) of PLL. (POR = 00101101) b00100011
+    WriteData(0x02);             // M[3:0] : Divider (M) of PLL. (POR = 0011)
+    WriteData(0x04);             // C[2] : Effectuate MN value (POR = 100) - Effectuate the multiplier and divider value
+    //WriteData(0x54);
+    
+    // Set PLL
+    // @Parameters : 1
+    WriteCmd(0xE0);
+    WriteData(0x01);             // Use reference clock as system clock & Enable PLL
+    wait_ms(1);                  // Wait 100us to let the PLL stable
+    WriteCmd(0xE0);             // Set PLL
+    WriteData(0x03);             // Use PLL output as system clock & Enable PLL
+    wait_ms(1); 
+
+    // Software Reset ---------------------------------------------------------
+    WriteCmd(0x01);
+    wait_ms(1);   
+
+    // Set LSHIFT Frequency ---------------------------------------------------
+    // @Parameters : 3
+    WriteCmd(0xE6);             // Set LSHIFT Frequency
+    WriteData(0x03);             // LCDC_FPR[19:16] : The highest 4 bits for the pixel clock frequency settings
+    WriteData(0xFF);             // LCDC_FPR[15:8]  : The higher byte for the pixel clock frequency settings
+    WriteData(0xFF);             // LCDC_FPR[7:0]   : The low byte for the pixel clock frequency settings
+
+    // Set LCD Mode
+    // @Parameters : 7
+    WriteCmd(0xB0);
+    /*
+    WriteData(0x00);             // A[5..0] TFT
+    //WriteData(0x10);
+    WriteData(0x00);             // B[7..5]   : Hsync+Vsync +DE mode & TFT mode
+    //WriteData(0x80);
+    WriteData((HDP>>8)&0xFF);    // HPS[10:8] : Set the horizontal panel size (POR = 010)
+    WriteData(HDP&0xFF);         // HPS[7:0]  : Set the horizontal panel size (POR = 01111111)
+    WriteData((VDP>>8)&0xFF);    // VPS[10:8] : Set the vertical panel size (POR = 001)
+    WriteData(VDP&0xFF);         // VPS[7:0]  : Set the vertical panel size (POR = 11011111)
+    WriteData(0x00);             // G[5..0]   : Even line RGB sequence & Odd line RGB sequence
+    */
+    //WriteData(0x10);                // set 18-bit for 7" panel TY700TFT800480
+    WriteData(0x20);                // set 18-bit for 7" panel TY700TFT800480
+    //WriteData(0x80);                // set TTL mode
+    WriteData(0x00);                // set TTL mode
+    WriteData((DISP_HOR_RESOLUTION-1)>>8); //Set panel size
+    WriteData(DISP_HOR_RESOLUTION-1);
+    WriteData((DISP_VER_RESOLUTION-1)>>8);
+    WriteData(DISP_VER_RESOLUTION-1);
+    WriteData(0x00);
+    
+    
+    // Set Horizontal Period --------------------------------------------------
+    // @Parameters : 8
+    WriteCmd(0xB4);
+    /*
+    WriteData((HT>>8)&0xFF);     // HT[10:8]   : High byte of horizontal total period (display + non-display) in pixel clock
+    WriteData(HT&0xFF);          // HT[7:0]    : Low byte of the horizontal total period (display + non-display) in pixel clock
+    WriteData((HPS>>8)&0xFF);    // HPS[10:8]  : High byte of the non-display period between the start of the horizontal sync (LLINE) signal
+    WriteData(HPS&0xFF);         // HPS[7:0]   : Low byte of the non-display period between the start of the horizontal sync (LLINE) signal
+    WriteData(HPW&0xFF);         // HPW[6:0]   : Set the horizontal sync pulse width (LLINE) in pixel clock
+    WriteData((LPS>>8)&0xFF);    // LPS[10:8]  : Set the horizontal sync pulse (LLINE) start location in pixel clock
+    WriteData(LPS&0xFF);         // LPS[7:0]   : Set the horizontal sync pulse width (LLINE) in start.
+    WriteData(0x00);             // LPSPP[1:0] : Set the horizontal sync pulse subpixel start position
+    */
+    #define HT (DISP_HOR_RESOLUTION+DISP_HOR_PULSE_WIDTH+DISP_HOR_BACK_PORCH+DISP_HOR_FRONT_PORCH)
+    WriteData((HT-1)>>8);   
+    WriteData(HT-1);
+    #define HPS (DISP_HOR_PULSE_WIDTH+DISP_HOR_BACK_PORCH)
+    WriteData((HPS-1)>>8);
+    WriteData(HPS-1);
+    WriteData(DISP_HOR_PULSE_WIDTH-1);
+    WriteData(0x00);
+    WriteData(0x00);
+    WriteData(0x00);
+    
+    // Set Vertical Period ----------------------------------------------------
+    // @Parameters : 7
+    WriteCmd(0xB6);
+    /*
+    WriteData((VT>>8)&0xFF);     // VT[10:8]  : High byte of the vertical total (display + non-display) period in lines
+    WriteData(VT&0xFF);          // VT[7:0]   : Low byte of the vertical total (display + non-display) period in lines
+    WriteData((VPS>>8)&0xFF);    // VPS[10:8] : High byte the non-display period in lines between the start of the frame and the first display data in line
+    WriteData(VPS&0xFF);         // VPS[7:0]  : The non-display period in lines between the start of the frame and the first display data in line
+    WriteData(VPW&0xFF);         // VPW[6:0]  : Set the vertical sync pulse width (LFRAME) in lines
+    WriteData((FPS>>8)&0xFF);    // FPS[10:8] : High byte of the vertical sync pulse (LFRAME) start location in lines
+    WriteData(FPS&0xFF);         // FPS[7:0]  : Low byte of the vertical sync pulse (LFRAME) start location in lines
+    */
+    #define VT (DISP_VER_PULSE_WIDTH+DISP_VER_BACK_PORCH+DISP_VER_FRONT_PORCH+DISP_VER_RESOLUTION)
+    WriteData((VT-1)>>8);
+    WriteData(VT-1);
+    #define VSP (DISP_VER_PULSE_WIDTH+DISP_VER_BACK_PORCH)
+    WriteData((VSP-1)>>8);
+    WriteData(VSP-1);
+    WriteData(DISP_VER_PULSE_WIDTH-1);
+    WriteData(0x00);
+    WriteData(0x00);
+    
+    // Set GPIO Value ---------------------------------------------------------
+    // @Parameters : 1
+    WriteCmd(0xBA);
+    WriteData(0x05);             // A[3..0] : GPIO[2:0] Output 1
+    
+    // Set GPIO Configuration
+    // @Parameters : 2
+    WriteCmd(0xB8);
+    WriteData(0x07);             // A[7..0] : GPIO3 = Input, GPIO[2:0] = Output
+    WriteData(0x01);             // B[0] : GPIO0 Normal
+    
+        //Set pixel format, i.e. the bpp
+    WriteCmd(0x3A);
+    WriteData(0x55);                // set 16bpp
+
+    // Set Address Mode -------------------------------------------------------
+    // @Parameters : 1
+    //WriteCmd(0x36);             // Set Rotation
+    //WriteData(0x00);             // A[7..0] : Set the read order from host processor to frame buffer by A[7:5] and A[3] and 
+                                                       // from frame buffer to the display panel by A[2:0] and A[4].
+                                                       // A[7] : Page address order
+    // Set Pixel Data Interface -----------------------------------------------
+    // @Parameters : 1
+    WriteCmd(0xF0);             // A[2:0] : Pixel Data Interface Format
+    WriteData(0x03);             // 16-bit (565 format)
+    wait_ms(1);
+    
+    // enter_partial_mode
+    //WriteCmd(0x12);             // Part of the display area is used for image display
+    // set_display_on
+    WriteCmd(0x29);             // Show the image on the display device
+
+    Deactivate();
+}
+
+void SSD1963_LCD::Sleep( void )
+{
+    WriteCmdData( 0x10, 0x0001 ); // sleep mode: 0 = exit, 1 = enter
+    LCD::Sleep();
+}
+
+void SSD1963_LCD::WakeUp( void )
+{
+    WriteCmdData( 0x10, 0x0000 ); // sleep mode: 0 = exit, 1 = enter
+    LCD::WakeUp();
+}
+
+void SSD1963_LCD::WriteCmd( unsigned short cmd )
+{
+    _lcd_pin_rs = LOW;
+    _lcd_port->write( cmd );
+    _lcd_pin_wr = LOW;
+    wait_us(1);
+    _lcd_pin_wr = HIGH;
+    //pulseLow( _lcd_pin_wr );
+}
+
+void SSD1963_LCD::WriteData( unsigned short data )
+{
+    _lcd_pin_rs = HIGH;
+    _lcd_port->write( data );
+    _lcd_pin_wr = LOW;
+    wait_us(1);
+    _lcd_pin_wr = HIGH;
+    
+    //pulseLow( _lcd_pin_wr );
+}
+
+void SSD1963_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 )
+{
+    //if ( _orientation == PORTRAIT || _orientation == PORTRAIT_REV )
+    //{
+        WriteCmd( 0x2A);
+        WriteData( x1>>8 );
+        WriteData( x1 );
+        WriteData( x2>>8 );
+        WriteData( x2 );
+        WriteCmd( 0x2B);
+        WriteData( y1>>8 );
+        WriteData( y1 );
+        WriteData( y2>>8 );
+        WriteData( y2 );
+        WriteCmd( 0x2B);
+    /*}
+    else
+    {
+        WriteCmd( 0x2A);
+        WriteData( y1>>8 );
+        WriteData( y1 );
+        WriteData( y2>>8 );
+        WriteData( y2 );
+        WriteCmd( 0x2B);
+        WriteData( x1>>8 );
+        WriteData( x1 );
+        WriteData( x2>>8 );
+        WriteData( x2 );
+        WriteCmd( 0x2B);
+    }*/
+    WriteCmd( 0x2C );
+}
+
+void SSD1963_LCD::SetPixelColor( unsigned int color, colordepth_t mode )
+{
+    unsigned char r, g, b;
+    unsigned short clr;
+    if ( _colorDepth == RGB16 )
+    {
+        switch ( mode )
+        {
+            case RGB16:
+                WriteData( color & 0xFFFF );
+                break;
+            case RGB18:
+                r = ( color >> 10 ) & 0xF8;
+                g = ( color >> 4 ) & 0xFC;
+                b = ( color >> 1 ) & 0x1F;
+                clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | b );
+                WriteData( clr );
+                break;
+            case RGB24:
+                r = ( color >> 16 ) & 0xF8;
+                g = ( color >> 8 ) & 0xFC;
+                b = color & 0xF8;
+                clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | ( b >> 3 ) );
+                WriteData( clr );
+                break;
+        }
+    }
+    else if ( _colorDepth == RGB18 )
+    {
+        switch ( mode )
+        {
+            case RGB16:
+                r = ( ( color >> 8 ) & 0xF8 ) | ( ( color & 0x8000 ) >> 13 );
+                g = ( color >> 3 ) & 0xFC;
+                b = ( ( color << 3 ) & 0xFC ) | ( ( color >> 3 ) & 0x01 );
+                WriteData( ( r << 8 ) | g );
+                WriteData( b );
+                break;
+            case RGB18:
+                b = ( color << 2 ) & 0xFC;
+                g = ( color >> 4 ) & 0xFC;
+                r = ( color >> 10 ) & 0xFC;
+                WriteData( ( r << 8 ) | g );
+                WriteData( b );
+                break;
+            case RGB24:
+                r = ( color >> 16 ) & 0xFC;
+                g = ( color >> 8 ) & 0xFC;
+                b = color & 0xFC;
+                WriteData( ( r << 8 ) | g );
+                WriteData( b );
+                break;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ssd1963.h	Fri May 30 08:39:59 2014 +0000
@@ -0,0 +1,215 @@
+/** \file ssd1963.h
+ *  \brief mbed TFT LCD controller for displays with the SSD1963 IC.
+ *  \copyright GNU Public License, v2. or later
+ *
+ *
+ * This library is based on the Arduino/chipKIT UTFT library by Henning
+ * Karlsen, http://henningkarlsen.com/electronics/library.php?id=52
+ *
+ * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
+ *
+ * Copyright (C)2012 Todor Todorov.
+ *
+ * Copyright (C)2014 Robert Fischer
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to:
+ *
+ * Free Software Foundation, Inc.
+ * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
+ *
+ *********************************************************************/
+#ifndef TFTLCD_SSD1963_H
+#define TFTLCD_SSD1963_H
+
+#include "lcd_base.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*********************************************************************
+* Overview: Panel Data Width (R,G,B) in (6,6,6)
+*********************************************************************/
+#define DISP_DATA_WIDTH                 18
+/*********************************************************************
+* Overview: Horizontal and vertical display resolution
+*                  (from the glass datasheet).
+*********************************************************************/
+#define DISP_HOR_RESOLUTION 480 //800
+#define DISP_VER_RESOLUTION 272 //480
+/*********************************************************************
+* Overview: Horizontal synchronization timing in pixels
+*                  (from the glass datasheet).
+*********************************************************************/
+#define DISP_HOR_PULSE_WIDTH        1
+#define DISP_HOR_BACK_PORCH         210
+#define DISP_HOR_FRONT_PORCH        45
+/*********************************************************************
+* Overview: Vertical synchronization timing in lines
+*                  (from the glass datasheet).
+*********************************************************************/
+#define DISP_VER_PULSE_WIDTH        1
+#define DISP_VER_BACK_PORCH         34
+#define DISP_VER_FRONT_PORCH        10
+
+/** 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. 
+ *
+ * The display needs 20 to 22 pins to work with mbed, so it is possibly not
+ * the best of choices out there, but other than that it uses +3.3V for
+ * power and logic, as well as the backlight, thus can be interfaced directly
+ * to the mbed without the need of shields or level shifters as with Arduino.
+ *
+ * How to use:
+ * \code
+ * // include the library, this will also pull in the header for the provided fonts
+ * #include "ssd1963.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
+ * SSD1963_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 SSD1963_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.
+     */
+    SSD1963_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:
+    DigitalOut  _lcd_pin_wr;
+    BusOut*     _lcd_port;
+    DigitalOut* _lcd_pin_bl;
+    DigitalOut* _lcd_pin_rd;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TFTLCD_SSD1963_H */