Programme de test pour lcd ITDB02
Fork of TFTLCD by
Revision 20:4bdca8d8dadc, committed 2012-12-21
- Comitter:
- ttodorov
- Date:
- Fri Dec 21 06:05:15 2012 +0000
- Parent:
- 19:eb27effb8c07
- Child:
- 21:e5c1e8ffada1
- Commit message:
- - changed internals of SetPixelColor to allow more general and simple implementation of the bitmap drawing functions
Changed in this revision
--- a/hx8340bs.cpp Thu Dec 13 03:37:22 2012 +0000 +++ b/hx8340bs.cpp Fri Dec 21 06:05:15 2012 +0000 @@ -177,7 +177,7 @@ serializeByte( data ); } -void HX8340S_LCD::SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ) +void HX8340S_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 ) { WriteCmdData( 0x2A, x1 ); // CASET WriteData( x2 ); @@ -186,22 +186,56 @@ WriteCmd( 0x2C ); // RAMWR } -void HX8340S_LCD::SetPixelColor( unsigned int color ) +void HX8340S_LCD::SetPixelColor( unsigned int color, colordepth_t mode ) { - unsigned char r, g, b; - r = ( color >> 16 ) & 0xFF; - g = ( color >> 8 ) & 0xFF; - b = color & 0xFF; + unsigned char r = 0, g = 0, b = 0; + unsigned short clr; if ( _colorDepth == RGB16 ) { - unsigned short clr = ( ( ( ( r ) & 0xF8 ) | ( ( g ) >> 5 ) ) << 8 ) | ( ( ( ( g ) & 0x1C ) << 3 ) | ( ( b ) >> 3 ) ); - WriteData( clr ); + 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 ) { - WriteByteData( r & 0xFC ); - WriteByteData( g & 0xFC ); - WriteByteData( b & 0xFC ); + 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; + } + WriteByteData( r ); + WriteByteData( g ); + WriteByteData( b ); } }
--- a/hx8340bs.h Thu Dec 13 03:37:22 2012 +0000 +++ b/hx8340bs.h Fri Dec 21 06:05:15 2012 +0000 @@ -166,15 +166,16 @@ * \remarks Addressing commands are controller-specific and this function needs to be * implemented separately for each available controller. */ - virtual void SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ); + 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 ); + virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB24 ); private: void serializeByte( unsigned char data );
--- 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();
--- a/lcd_base.h Thu Dec 13 03:37:22 2012 +0000 +++ b/lcd_base.h Fri Dec 21 06:05:15 2012 +0000 @@ -103,8 +103,9 @@ */ enum ColorDepth_enum { - RGB16, /**< 16-bit colors, pixels can have 65K distinct color values */ - RGB18, /**< 18-bit colors, pixels can have 262K distinct color values */ + RGB16, /**< 16-bit colors, pixels can have 65K+ distinct color values */ + RGB18, /**< 18-bit colors, pixels can have 262K+ distinct color values */ + RGB24, /**< 24-bit colors, full 8 bits per component, 16M+ distinct color values */ }; /** \typedef colordepth_t * \brief Convenience shortcut for display color depth. @@ -454,7 +455,7 @@ * \remarks Addressing commands are controller-specific and this function needs to be * implemented separately for each available controller. */ - virtual void SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ) = 0; + virtual void SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 ) = 0; /** Resets the memory address for the next display write operation to the screen origins (0,0). */ @@ -465,8 +466,9 @@ * This function is to be provided by each implementation separately in * order to account for different color depths 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 ) = 0; + virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB24 ) = 0; /** Draws a horizontal line. *
--- a/ssd1289.cpp Thu Dec 13 03:37:22 2012 +0000 +++ b/ssd1289.cpp Fri Dec 21 06:05:15 2012 +0000 @@ -222,7 +222,7 @@ pulseLow( _lcd_pin_wr ); } -void SSD1289_LCD::SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ) +void SSD1289_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 ) { if ( _orientation == PORTRAIT || _orientation == PORTRAIT_REV ) { @@ -243,22 +243,58 @@ WriteCmd( 0x22 ); } -void SSD1289_LCD::SetPixelColor( unsigned int color ) +void SSD1289_LCD::SetPixelColor( unsigned int color, colordepth_t mode ) { unsigned char r, g, b; unsigned short clr; - r = ( color >> 16 ) & 0xFF; - g = ( color >> 8 ) & 0xFF; - b = color & 0xFF; if ( _colorDepth == RGB16 ) { - clr = ( ( ( ( r ) & 0xF8 ) | ( ( g ) >> 5 ) ) << 8 ) | ( ( ( ( g ) & 0x1C ) << 3 ) | ( ( b ) >> 3 ) ); - WriteData( clr ); + 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 ) { - clr = ( ( r & 0xFC ) << 8 ) | ( g & 0xFC ); - WriteData( clr ); - WriteData( b & 0xFC ); + 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; + } } }
--- a/ssd1289.h Thu Dec 13 03:37:22 2012 +0000 +++ b/ssd1289.h Fri Dec 21 06:05:15 2012 +0000 @@ -165,15 +165,16 @@ * \remarks Addressing commands are controller-specific and this function needs to be * implemented separately for each available controller. */ - virtual void SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ); + 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 ); + virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB24 ); private: DigitalOut _lcd_pin_wr;
--- a/st7735.cpp Thu Dec 13 03:37:22 2012 +0000 +++ b/st7735.cpp Fri Dec 21 06:05:15 2012 +0000 @@ -162,9 +162,9 @@ WriteCmd( 0x36 ); //MX, MY, RGB mode switch ( _orientation ) { - case LANDSCAPE: WriteByteData( 0xB8 ); break; + case LANDSCAPE: WriteByteData( 0x6C ); break; case PORTRAIT_REV: WriteByteData( 0xDC ); break; - case LANDSCAPE_REV: WriteByteData( 0x6C ); break; + case LANDSCAPE_REV: WriteByteData( 0xB8 ); break; case PORTRAIT: default: WriteByteData( 0x08 ); break; } @@ -217,7 +217,7 @@ serializeByte( data ); } -void ST7735_LCD::SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ) +void ST7735_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 ) { WriteCmdData( 0x2a, x1 ); WriteData( x2 ); @@ -226,22 +226,56 @@ WriteCmd( 0x2c ); } -void ST7735_LCD::SetPixelColor( unsigned int color ) +void ST7735_LCD::SetPixelColor( unsigned int color, colordepth_t mode ) { - unsigned char r, g, b; - r = ( color >> 16 ) & 0xFF; - g = ( color >> 8 ) & 0xFF; - b = color & 0xFF; + unsigned char r = 0, g = 0, b = 0; + unsigned short clr; if ( _colorDepth == RGB16 ) { - unsigned short clr = ( ( ( ( r ) & 0xF8 ) | ( ( g ) >> 5 ) ) << 8 ) | ( ( ( ( g ) & 0x1C ) << 3 ) | ( ( b ) >> 3 ) ); - WriteData( clr ); + 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 ) { - WriteByteData( r & 0xFC ); - WriteByteData( g & 0xFC ); - WriteByteData( b & 0xFC ); + 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; + } + WriteByteData( r ); + WriteByteData( g ); + WriteByteData( b ); } }
--- a/st7735.h Thu Dec 13 03:37:22 2012 +0000 +++ b/st7735.h Fri Dec 21 06:05:15 2012 +0000 @@ -167,15 +167,16 @@ * \remarks Addressing commands are controller-specific and this function needs to be * implemented separately for each available controller. */ - virtual void SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ); + 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 ); + virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB24 ); private: void serializeByte( unsigned char data );