Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: SSD1963.cpp
- Revision:
- 2:d8a9ebd28f0a
- Parent:
- 1:74bac5f988d8
- Child:
- 3:31ca3cd96572
--- a/SSD1963.cpp	Sun Oct 04 13:19:05 2020 +0000
+++ b/SSD1963.cpp	Thu Oct 08 06:50:37 2020 +0000
@@ -18,8 +18,6 @@
  *****************************************************************************/
 #include "mbed.h"
 #include "SSD1963.h"
-//#include "tFontLCD.c"
-//#include "stm32f4xx.h"
 
 /*
 #define  HDP 799     // [ 799][ 799] Horizontal Display Period
@@ -35,23 +33,12 @@
 */
 
 SSD1963::SSD1963(PinName CS, PinName RESET, PinName RS, PinName WR, BusInOut* DATA_PORT, PinName RD):
-_lcd_pin_cs( CS ), _lcd_pin_rs( RS ), _lcd_pin_reset( RESET ), _lcd_pin_wr( WR ), _lcd_pin_rd(RD)
+LCD( 272, 480, CS, RS, RESET, NC, Constant, 1.0 ), _lcd_pin_wr( WR ), _lcd_pin_rd(RD)
 {
-    begin();
+    _lcd_port = DATA_PORT;
 }
 
-void SSD1963::Activate( void )
-{
-    _lcd_pin_cs = LOW;
-}
-
-inline
-void SSD1963::Deactivate( void )
-{
-    _lcd_pin_cs = HIGH;
-}
-
-void SSD1963::writeData(uint16_t data) {
+void SSD1963::WriteData(unsigned short data) {
     Activate();
     _lcd_pin_rs = HIGH;
     _lcd_pin_wr = LOW;
@@ -62,7 +49,7 @@
     Deactivate();
 }
 
-void SSD1963::writeCommand(uint16_t cmd) {
+void SSD1963::WriteCmd(unsigned short cmd) {
     Activate();
     _lcd_pin_rs = LOW;
     _lcd_pin_wr = LOW;
@@ -88,8 +75,8 @@
 }
 
 void SSD1963::writeRegister(uint16_t addr, uint16_t data) {
-    writeCommand(addr);
-    writeData(data);
+    WriteCmd(addr);
+    WriteData(data);
 }
 
 void SSD1963::reset(void) {
@@ -109,34 +96,36 @@
     wait_ms(10);
     // Set PLL MN -------------------------------------------------------------
     // @Parameters : 3
-    writeCommand(0xE2);
-    writeData(0x01);             // N[7:0] : Multiplier (N) of PLL. (POR = 00101101) b00100011
-    writeData(0x02);             // M[3:0] : Divider (M) of PLL. (POR = 0011)
-    writeData(0x54);             // C[2] : Effectuate MN value (POR = 100) - Effectuate the multiplier and divider value
-    
+    WriteCmd(Com_SetPLLConfig);
+    WriteData(0x1d);             // N[7:0] : Multiplier (N) of PLL. (POR = 00101101) b00100011
+    WriteData(0x02);             // M[3:0] : Divider (M) of PLL. (POR = 0011)
+    WriteData(0x54);             // C[2] : Effectuate MN value (POR = 100) - Effectuate the multiplier and divider 
+
     // Set PLL
     // @Parameters : 1
-    writeCommand(0xE0);
-    writeData(0x01);             // Use reference clock as system clock & Enable PLL
-    wait_us(100);                  // Wait 100us to let the PLL stable
-    writeCommand(0xE0);             // Set PLL
-    writeData(0x03);             // Use PLL output as system clock & Enable PLL
-    wait_us(100); 
+    WriteCmd(Com_SetPLLStart);
+    WriteData(0x01);             // Use reference clock as system clock & Enable PLL
+    wait_us(100);                // Wait 100us to let the PLL stable
+    WriteCmd(Com_SetPLLStart);             // Set PLL
+    WriteData(0x03);             // Use PLL output as system clock & Enable PLL
+    wait_us(100);
 
     // Software Reset ---------------------------------------------------------
-    writeCommand(0x01);
-    wait_us(100);   
+    WriteCmd(Com_Reset);
+    wait_ms(100);
 
     // Set LSHIFT Frequency ---------------------------------------------------
     // @Parameters : 3
-    writeCommand(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
+    WriteCmd(Com_SetPixelClock);             // Set LSHIFT Frequency
+    WriteData(0x01);             // LCDC_FPR[19:16] : The highest 4 bits for the pixel clock frequency settings
+    WriteData(0x70);             // LCDC_FPR[15:8]  : The higher byte for the pixel clock frequency settings
+    WriteData(0xa2);             // LCDC_FPR[7:0]   : The low byte for the pixel clock frequency settings
+    wait_ms(1);
 
+    // Set Horizontal Period ---------------------
     // Set LCD Mode
     // @Parameters : 7
-    writeCommand(0xB0);
+    WriteCmd(Com_SetLCDMode);
     /*
     writeData(0x00);             // A[5..0] TFT
     //writeData(0x10);
@@ -148,18 +137,17 @@
     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(0x80);                // 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);
-    
-    
+    WriteData(0x0c);                // set 18-bit for 7" panel TY700TFT800480
+    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
-    writeCommand(0xB4);
+    WriteCmd(Com_SetHoriPeriod);
     /*
     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
@@ -170,20 +158,20 @@
     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);
-    
+    #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
-    writeCommand(0xB6);
+    WriteCmd(Com_SetVertPeriod);
     /*
     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
@@ -193,81 +181,145 @@
     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);
-    
+    #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
-    writeCommand(0xBA);
-    writeData(0x05);             // A[3..0] : GPIO[2:0] Output 1
+    WriteCmd(Com_SetGPIOValue);
+    WriteData(0x0f);             // A[3..0] : GPIO[2:0] Output 1
     
     // Set GPIO Configuration
     // @Parameters : 2
-    writeCommand(0xB8);
-    writeData(0x07);             // A[7..0] : GPIO3 = Input, GPIO[2:0] = Output
-    writeData(0x01);             // B[0] : GPIO0 Normal
+    WriteCmd(Com_SetGPIOConf);
+    WriteData(0x07);             // A[7..0] : GPIO3 = Input, GPIO[2:0] = Output
+    WriteData(0x01);             // B[0] : GPIO0 Normal
     
-        //Set pixel format, i.e. the bpp
-    writeCommand(0x3A);
-    writeData(0x55);                // set 16bpp
+    //Set pixel format, i.e. the bpp
+    //writeCommand(Com_SetPixelFormat);
+    //writeData(0x55);                // set 16bpp
 
     // Set Address Mode -------------------------------------------------------
     // @Parameters : 1
     //writeCommand(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 
+    //writeData(0x2a);                // 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
-    writeCommand(0xF0);             // A[2:0] : Pixel Data Interface Format
-    writeData(0x03);             // 16-bit (565 format)
+    WriteCmd(Com_SetPixelInterface);             // A[2:0] : Pixel Data Interface Format
+    WriteData(0x03);             // 16-bit (565 format)
     wait_us(100);
     
-    writeCommand(0x34);
+    /*writeCommand(Com_SetTearOff);*/
     wait_ms(1);
+    WriteCmd(Com_SetGPIOConf);
+    WriteData(0x0f);    //GPIO is controlled by host GPIO[3:0]=output   GPIO[0]=1  LCD ON  GPIO[0]=1  LCD OFF 
+    WriteData(0x01);    //GPIO0 normal
+
+    WriteCmd(Com_SetGPIOValue);
+    WriteData(0x01);    //GPIO[0] out 1 --- LCD display on/off control PIN
     
     // enter_partial_mode
     //writeCommand(0x12);             // Part of the display area is used for image display
     // set_display_on
-    writeCommand(0x29);             // Show the image on the display device
-    
+    WriteCmd(Com_SetDisplayOn);             // Show the image on the display device
+
     //writeCommand(0x2C);
 }
 
-void SSD1963::fillScreen(uint16_t color){
-    uint16_t start_x = 0;
-    uint16_t end_x   = 799;
-    uint16_t start_y = 0;
-    uint16_t end_y   = 479;
-    
-    writeCommand(0x2A);
-    //nCS_LOW;
-    writeData(start_x >> 8);
-    writeData(start_x);
-    writeData(end_x >> 8);
-    writeData(end_x);
-    //nCS_HIGH;
-    writeCommand(0x2B);
-    //nCS_LOW;
-    writeData(start_y >> 8);
-    writeData(start_y);
-    writeData(end_y >> 8);
-    writeData(end_y);
-    //nCS_HIGH;
-    
-    writeCommand(0x2C);
+void SSD1963::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 )
+{
+    //if ( _orientation == PORTRAIT || _orientation == PORTRAIT_REV )
+    //{
+        WriteCmd(Com_SetColumnAddress);
+        WriteData( x1>>8 );
+        WriteData( x1 );
+        WriteData( x2>>8 );
+        WriteData( x2 );
+        WriteCmd( Com_SetPageAddress);
+        WriteData( y1>>8 );
+        WriteData( y1 );
+        WriteData( y2>>8 );
+        WriteData( y2 );
+    /*}
+    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(Com_WriteMemory);
+}
 
-    uint16_t i,j;
-    for(i = 0; i < TFTWIDTH; i++){
-        for (j = 0; j < TFTHEIGHT; j++){
-            writeData(color);
+void SSD1963::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;
         }
     }
 }
@@ -282,8 +334,3 @@
   c |= b >> 3;
   return c;
 }
-
-uint8_t SSD1963::readID(void){
-    writeCommand(0x0000);
-    return readData();
-}