Programme de test pour lcd ITDB02
Fork of TFTLCD by
Revision 10:69571adcfad5, committed 2012-12-11
- Comitter:
- ttodorov
- Date:
- Tue Dec 11 03:18:43 2012 +0000
- Parent:
- 9:58b328831d0a
- Child:
- 11:aeceefc5f9f2
- Commit message:
- - preliminary support for using 18-bit colors
Changed in this revision
--- a/hx8340bs.cpp Fri Dec 07 16:14:13 2012 +0000 +++ b/hx8340bs.cpp Tue Dec 11 03:18:43 2012 +0000 @@ -186,6 +186,11 @@ WriteCmd( 0x2c ); } +void HX8340S_LCD::SetPixelColor( unsigned short color ) +{ + WriteData( color ); +} + void HX8340S_LCD::serializeByte( unsigned char data ) { for ( int i = 0; i < 8; i++ )
--- a/hx8340bs.h Fri Dec 07 16:14:13 2012 +0000 +++ b/hx8340bs.h Tue Dec 11 03:18:43 2012 +0000 @@ -167,6 +167,14 @@ */ virtual void SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t 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. + */ + virtual void SetPixelColor( unsigned short color ); + private: void serializeByte( unsigned char data );
--- a/lcd_base.cpp Fri Dec 07 16:14:13 2012 +0000 +++ b/lcd_base.cpp Tue Dec 11 03:18:43 2012 +0000 @@ -71,7 +71,7 @@ Activate(); ClearXY(); for ( int i = 0; i < ( ( _disp_width ) * ( _disp_height ) ); i++ ) - WriteData( rgb ); + SetPixelColor( rgb ); Deactivate(); } @@ -85,7 +85,7 @@ { Activate(); SetXY( x, y, x, y ); - WriteData( color == -1 ? _background : + SetPixelColor( color == -1 ? _background : color == -2 ? _foreground : color ); Deactivate(); } @@ -131,7 +131,7 @@ for ( int i = x1; i >= x2; i-- ) { SetXY( i, int( ty + 0.5 ), i, int( ty + 0.5 ) ); - WriteData( usedColor ); + SetPixelColor( usedColor ); ty = ty - delta; } } @@ -140,7 +140,7 @@ for ( int i = x1; i <= x2; i++ ) { SetXY( i, int( ty + 0.5 ), i, int( ty + 0.5 ) ); - WriteData( usedColor ); + SetPixelColor( usedColor ); ty = ty + delta; } } @@ -154,7 +154,7 @@ for ( int i = y2 + 1; i > y1; i-- ) { SetXY( int( tx + 0.5 ), i, int( tx + 0.5 ), i ); - WriteData( usedColor ); + SetPixelColor( usedColor ); tx = tx + delta; } } @@ -163,7 +163,7 @@ for ( int i = y1; i < y2 + 1; i++ ) { SetXY( int( tx + 0.5 ), i, int( tx + 0.5 ), i ); - WriteData( usedColor ); + SetPixelColor( usedColor ); tx = tx + delta; } } @@ -265,13 +265,13 @@ Activate(); SetXY( x, y + radius, x, y + radius ); - WriteData( usedColor ); + SetPixelColor( usedColor ); SetXY( x, y - radius, x, y - radius ); - WriteData( usedColor ); + SetPixelColor( usedColor ); SetXY( x + radius, y, x + radius, y ); - WriteData( usedColor ); + SetPixelColor( usedColor ); SetXY( x - radius, y, x - radius, y ); - WriteData( usedColor ); + SetPixelColor( usedColor ); while ( x1 < y1 ) { @@ -285,21 +285,21 @@ ddF_x += 2; f += ddF_x; SetXY( x + x1, y + y1, x + x1, y + y1 ); - WriteData( usedColor ); + SetPixelColor( usedColor ); SetXY( x - x1, y + y1, x - x1, y + y1 ); - WriteData( usedColor ); + SetPixelColor( usedColor ); SetXY( x + x1, y - y1, x + x1, y - y1 ); - WriteData( usedColor ); + SetPixelColor( usedColor ); SetXY( x - x1, y - y1, x - x1, y - y1 ); - WriteData( usedColor ); + SetPixelColor( usedColor ); SetXY( x + y1, y + x1, x + y1, y + x1 ); - WriteData( usedColor ); + SetPixelColor( usedColor ); SetXY( x - y1, y + x1, x - y1, y + x1 ); - WriteData( usedColor ); + SetPixelColor( usedColor ); SetXY( x + y1, y - x1, x + y1, y - x1 ); - WriteData( usedColor ); + SetPixelColor( usedColor ); SetXY( x - y1, y - x1, x - y1, y - x1 ); - WriteData( usedColor ); + SetPixelColor( usedColor ); } Deactivate(); } @@ -313,7 +313,7 @@ if ( x1 * x1 + y1 * y1 <= radius * radius ) { SetXY( x + x1, y + y1, x + x1, y + y1 ); - WriteData( usedColor ); + SetPixelColor( usedColor ); } Deactivate(); } @@ -357,7 +357,7 @@ { SetXY( x, y, x + sx - 1, y + sy - 1 ); for ( tc = 0; tc < ( sx * sy ); tc++ ) - WriteData( imgPixelData[ tc ] ); + SetPixelColor( imgPixelData[ tc ] ); } else { @@ -365,7 +365,7 @@ { SetXY( x, y + ty, x + sx - 1, y + ty ); for ( tx = sx; tx >= 0; tx-- ) - WriteData( imgPixelData[ ( ty * sx ) + tx ] ); + SetPixelColor( imgPixelData[ ( ty * sx ) + tx ] ); } } } @@ -379,7 +379,7 @@ for ( tsy = 0; tsy < scale; tsy++ ) for ( tx = 0; tx < sx; tx++ ) for ( tsx = 0; tsx < scale; tsx++ ) - WriteData( imgPixelData[ ( ty * sx ) + tx ] ); + SetPixelColor( imgPixelData[ ( ty * sx ) + tx ] ); } } else @@ -391,7 +391,7 @@ SetXY( x, y + ( ty * scale ) + tsy, x + ( ( sx * scale ) - 1 ), y + ( ty * scale ) + tsy ); for ( tx = sx; tx >= 0; tx-- ) for ( tsx = 0; tsx < scale; tsx++ ) - WriteData( imgPixelData[ ( ty * sx ) + tx ] ); + SetPixelColor( imgPixelData[ ( ty * sx ) + tx ] ); } } } @@ -417,7 +417,7 @@ newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) ); SetXY( newx, newy, newx, newy ); - WriteData( imgPixelData[ ( ty * sx ) + tx ] ); + SetPixelColor( imgPixelData[ ( ty * sx ) + tx ] ); } Deactivate(); } @@ -496,7 +496,7 @@ Activate(); SetXY( x, y, x + len, y ); for ( int i = 0; i < len + 1; i++ ) - WriteData( usedColor ); + SetPixelColor( usedColor ); Deactivate(); } @@ -507,7 +507,7 @@ Activate(); SetXY( x, y, x, y + len ); for ( int i = 0; i < len; i++ ) - WriteData( usedColor ); + SetPixelColor( usedColor ); Deactivate(); } @@ -532,9 +532,9 @@ for ( i = 0; i < 8; i++ ) { if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) - WriteData( usedColorFG ); + SetPixelColor( usedColorFG ); else - WriteData( usedColorBG ); + SetPixelColor( usedColorBG ); } temp++; } @@ -552,9 +552,9 @@ for ( i = 0; i < 8; i++ ) { if ( ( ch & ( 1 << i ) ) != 0 ) - WriteData( usedColorFG ); + SetPixelColor( usedColorFG ); else - WriteData( usedColorBG ); + SetPixelColor( usedColorBG ); } } temp += ( _font.width / 8 ); @@ -590,9 +590,9 @@ SetXY( newx, newy, newx + 1, newy + 1 ); if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) - WriteData( usedColorFG ); + SetPixelColor( usedColorFG ); else - WriteData( usedColorBG ); + SetPixelColor( usedColorBG ); } } temp += ( _font.width / 8 );
--- a/lcd_base.h Fri Dec 07 16:14:13 2012 +0000 +++ b/lcd_base.h Tue Dec 11 03:18:43 2012 +0000 @@ -68,37 +68,62 @@ */ #define COLOR_BLUE RGB( 0x00, 0x00, 0xFF ) -/** \typedef orientation_t +/** \enum Orientation_enum * \brief Display orientation. */ -typedef enum Orientation_enum +enum Orientation_enum { PORTRAIT = 0, /**< Display height is bigger than its width. */ LANDSCAPE = 1, /**< Display width is bigger than its height. */ -} orientation_t; +}; +/** \typedef orientation_t + * \brief Convenience shortcut for display orientation. + */ +typedef enum Orientation_enum orientation_t; -/** \typedef align_t +/** \enum ColorDepth_enum + * \brief Color depth + */ +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 */ +}; +/** \typedef colordepth_t + * \brief Convenience shortcut for display color depth. + */ +typedef enum ColorDepth_enum colordepth_t; + +/** \enum Alignment_enum * \brief Horizontal text alignment on the line. */ -typedef enum Alignment_enum +enum Alignment_enum { LEFT = 0, /**< Left-oriented, naturally gravitate closer to the left edge of the screen. */ CENTER = 9998, /**< Center-oriented, try to fit in the middle of the available space with equal free space to the left and right of the text. */ RIGHT = 9999, /**< Right-oriented, naturally gravitate closer to the right edge of the screen, leaving any remaining free space to the left of the text. */ -} align_t; +}; +/** \typedef align_t + * \brief Convenience shortcut for text alignment. + */ +typedef enum Alignment_enum align_t; -/** \typedef font_metrics_t +/** \struct Font_struct * \brief Describes fonts and their properties. * \sa Comments in fonts.h */ -typedef struct Font_struct +struct Font_struct { const char* font; /**< A pointer to the first byte in the font. */ unsigned char width; /**< The width of each character, in pixels. */ unsigned char height; /**< Height of each character, in pixels. */ unsigned char offset; /**< Offset of the first character in the font. */ unsigned char numchars; /**< Count of the available characters in the font. */ -} font_metrics_t; +}; +/** \typedef font_metrics_t + * \brief Convenience shortcut for fonts properties. + */ +typedef struct Font_struct font_metrics_t; /** Base class for LCD implementations. * @@ -405,6 +430,14 @@ */ virtual void ClearXY( void ); + /** 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. + */ + virtual void SetPixelColor( unsigned short color ) = 0; + /** Draws a horizontal line. * * This is a utility function to draw horizontal-only lines
--- a/ssd1289.cpp Fri Dec 07 16:14:13 2012 +0000 +++ b/ssd1289.cpp Tue Dec 11 03:18:43 2012 +0000 @@ -141,3 +141,8 @@ WriteCmdData( 0x4f, y1 ); WriteCmd( 0x22 ); } + +void SSD1289_LCD::SetPixelColor( unsigned short color ) +{ + WriteData( color ); +}
--- a/ssd1289.h Fri Dec 07 16:14:13 2012 +0000 +++ b/ssd1289.h Tue Dec 11 03:18:43 2012 +0000 @@ -166,6 +166,14 @@ */ virtual void SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t 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. + */ + virtual void SetPixelColor( unsigned short color ); + private: DigitalOut _lcd_pin_wr; BusOut* _lcd_port;
--- a/st7735.cpp Fri Dec 07 16:14:13 2012 +0000 +++ b/st7735.cpp Tue Dec 11 03:18:43 2012 +0000 @@ -216,6 +216,11 @@ WriteCmd( 0x2c ); } +void ST7735_LCD::SetPixelColor( unsigned short color ) +{ + WriteData( color ); +} + void ST7735_LCD::serializeByte( unsigned char data ) { for ( int i = 0; i < 8; i++ )
--- a/st7735.h Fri Dec 07 16:14:13 2012 +0000 +++ b/st7735.h Tue Dec 11 03:18:43 2012 +0000 @@ -168,6 +168,14 @@ */ virtual void SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t 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. + */ + virtual void SetPixelColor( unsigned short color ); + private: void serializeByte( unsigned char data );