mcufriend 2.4 TFT LCD Shield Lib
Dependents: Nucleo_LCD_mcufriend_test
Fork of 24_TFT_STMNUCLEO by
mcufriend 2.4" TFT LCD Shield
Import program
00001 #include "mbed.h" 00002 #include "ili9328.h" 00003 00004 // prepare the data bus for writing commands and pixel data 00005 BusOut dataBus( D8, D9, D2, D3, D4, D5, D6, D7 ); // 8 pins 00006 // create the lcd instance 00007 ILI9328_LCD lcd( A3, A4, A2,A1, &dataBus, NC, A0); // control pins and data bus 00008 //ILI9328_LCD( CS, RESET, RS, WR, BusOut* DATA_PORT, PinName BL = NC, RD ); 00009 00010 int main() 00011 { 00012 int ii,height,width; 00013 00014 height = lcd.GetHeight(); 00015 width = lcd.GetWidth(); 00016 // initialize display - place it in standard portrait mode and set background to black and 00017 // foreground to white color. 00018 lcd.Initialize(); 00019 00020 // print something on the screen 00021 lcd.Print( "Hello, World!", CENTER, 50); // align text to center horizontally and use starndard colors 00022 00023 wait(2); 00024 00025 lcd.ClearScreen(); 00026 00027 for(ii=0;ii<width;ii++) 00028 { 00029 lcd.DrawLine(0, 0, height, ii,COLOR_GREEN); 00030 ii = ii+10; 00031 } 00032 wait(2); 00033 00034 lcd.DrawCircle(height/4, width/4, 20, COLOR_GREEN); 00035 wait(2); 00036 00037 lcd.FillCircle(height/2, width/2, 50, COLOR_GREEN); 00038 wait(2); 00039 00040 lcd.FillTriangle(height/4, width/4,(height/4)+20, (width/4)+40,(height/4)-20, (width/4)+40, COLOR_RED); 00041 00042 while ( 1 ) { } 00043 }
HW information about the mcufriend LCD Shield
Diff: lcd_base.cpp
- Revision:
- 20:4bdca8d8dadc
- Parent:
- 13:5ceeba86bbe4
- Child:
- 21:e5c1e8ffada1
--- a/lcd_base.cpp Thu Dec 13 03:37:22 2012 +0000 +++ b/lcd_base.cpp Fri Dec 21 06:05:15 2012 +0000 @@ -333,43 +333,18 @@ if ( scale == 1 ) { SetXY( x, y, x + img->Width - 1, y + img->Height - 1 ); - + if ( img->Format == RGB16 ) { const unsigned short *pixel = ( const unsigned short* ) img->PixelData; - if ( _colorDepth == RGB16 ) - for ( tc = 0; tc < ( img->Width * img->Height ); tc++ ) - WriteData( *pixel++ ); - else if ( _colorDepth == RGB18 ) - { - unsigned short r, g, b; - for ( tc = 0; tc < ( img->Width * img->Height ); tc++ ) - { - r = ( *pixel & 0xF800 ) >> 8; - g = ( *pixel & 0x07E0 ) >> 3; - b = ( *pixel & 0x001F ) << 3; - pixel++; - SetPixelColor( RGB( r, g, b ) ); - } - } + for ( tc = 0; tc < ( img->Width * img->Height ); tc++ ) + SetPixelColor( *pixel++, img->Format ); } else if ( img->Format == RGB18 ) { const unsigned int *pixel = ( const unsigned int* ) img->PixelData; - if ( _colorDepth == RGB16 ) - { - unsigned short r, g, b; - for ( tc = 0; tc < ( img->Width * img->Height ); tc++ ) - { - r = ( *pixel >> 16 ) & 0xF8; - g = ( *pixel >> 8 ) & 0xFC; - b = ( *pixel++ & 0xF8 ) >> 3; - WriteData( ( r << 8 ) | ( g >> 5 ) | ( g << 3 ) | b ); - } - } - else if ( _colorDepth == RGB18 ) - for ( tc = 0; tc < ( img->Width * img->Height ); tc++ ) - SetPixelColor( *pixel++ ); + for ( tc = 0; tc < ( img->Width * img->Height ); tc++ ) + SetPixelColor( *pixel++, img->Format ); } } else @@ -377,35 +352,6 @@ if ( img->Format == RGB16 ) { const unsigned short *pixel = ( const unsigned short* ) img->PixelData; - unsigned short r, g, b; - - for ( ty = 0; ty < img->Height; ty++ ) - { - SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale ); - for ( tsy = 0; tsy < scale; tsy++ ) - { - for ( tx = 0; tx < img->Width; tx++ ) - { - for ( tsx = 0; tsx < scale; tsx++ ) - { - if ( _colorDepth == RGB16 ) - WriteData( pixel[ ( ty * img->Width ) + tx ] ); - else if ( _colorDepth == RGB18 ) - { - r = ( pixel[ ( ty * img->Width ) + tx ] & 0xF800 ) >> 8; - g = ( pixel[ ( ty * img->Width ) + tx ] & 0x07E0 ) >> 3; - b = ( pixel[ ( ty * img->Width ) + tx ] & 0x001F ) << 3; - SetPixelColor( RGB( r, g, b ) ); - } - } - } - } - } - } - else if ( img->Format == RGB18 ) - { - const unsigned int *pixel = ( const unsigned int* ) img->PixelData; - unsigned short r, g, b; for ( ty = 0; ty < img->Height; ty++ ) { @@ -415,17 +361,24 @@ for ( tx = 0; tx < img->Width; tx++ ) { for ( tsx = 0; tsx < scale; tsx++ ) - { - if ( _colorDepth == RGB16 ) - { - r = ( pixel[ ( ty * img->Width ) + tx ] >> 16 ) & 0xF8; - g = ( pixel[ ( ty * img->Width ) + tx ] >> 8 ) & 0xFC; - b = ( pixel[ ( ty * img->Width ) + tx ] & 0xF8 ) >> 3; - WriteData( ( r << 8 ) | ( g >> 5 ) | ( g << 3 ) | b ); - } - else if ( _colorDepth == RGB18 ) - SetPixelColor( pixel[ ( ty * img->Width ) + tx ] ); - } + SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format ); + } + } + } + } + else if ( img->Format == RGB18 ) + { + const unsigned int *pixel = ( const unsigned int* ) img->PixelData; + + for ( ty = 0; ty < img->Height; ty++ ) + { + SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale ); + for ( tsy = 0; tsy < scale; tsy++ ) + { + for ( tx = 0; tx < img->Width; tx++ ) + { + for ( tsx = 0; tsx < scale; tsx++ ) + SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format ); } } } @@ -449,7 +402,6 @@ if ( img->Format == RGB16 ) { const unsigned short *pixel = ( const unsigned short* ) img->PixelData; - unsigned short r, g, b; for ( ty = 0; ty < img->Height; ty++ ) for ( tx = 0; tx < img->Width; tx++ ) @@ -458,21 +410,12 @@ newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) ); SetXY( newx, newy, newx, newy ); - if ( _colorDepth == RGB16 ) - WriteData( pixel[ ( ty * img->Width ) + tx ] ); - else if ( _colorDepth == RGB18 ) - { - r = ( pixel[ ( ty * img->Width ) + tx ] & 0xF800 ) >> 8; - g = ( pixel[ ( ty * img->Width ) + tx ] & 0x07E0 ) >> 3; - b = ( pixel[ ( ty * img->Width ) + tx ] & 0x001F ) << 3; - SetPixelColor( RGB( r, g, b ) ); - } + SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format ); } } else if ( img->Format == RGB18 ) { const unsigned int *pixel = ( const unsigned int* ) img->PixelData; - unsigned short r, g, b; for ( ty = 0; ty < img->Height; ty++ ) for ( tx = 0; tx < img->Width; tx++ ) @@ -481,15 +424,7 @@ newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) ); SetXY( newx, newy, newx, newy ); - if ( _colorDepth == RGB16 ) - { - r = ( pixel[ ( ty * img->Width ) + tx ] >> 16 ) & 0xF8; - g = ( pixel[ ( ty * img->Width ) + tx ] >> 8 ) & 0xFC; - b = ( pixel[ ( ty * img->Width ) + tx ] & 0xF8 ) >> 3; - WriteData( ( r << 8 ) | ( g >> 5 ) | ( g << 3 ) | b ); - } - else if ( _colorDepth == RGB18 ) - SetPixelColor( pixel[ ( ty * img->Width ) + tx ] ); + SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format ); } } Deactivate();