mcufriend 2.4 TFT LCD Shield Lib

Dependents:   Nucleo_LCD_mcufriend_test

Fork of 24_TFT_STMNUCLEO by Carlos Silva

mcufriend 2.4" TFT LCD Shield

front back

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

Committer:
rlanghbv
Date:
Wed Nov 09 09:33:04 2016 +0000
Revision:
30:ede1a0a32e04
Parent:
22:4c169297f374
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ttodorov 0:881ff0b71102 1 /*
ttodorov 0:881ff0b71102 2 * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
ttodorov 0:881ff0b71102 3 * Copyright (C)2012 Todor Todorov.
ttodorov 0:881ff0b71102 4 *
ttodorov 0:881ff0b71102 5 * This library is free software; you can redistribute it and/or
ttodorov 0:881ff0b71102 6 * modify it under the terms of the GNU Lesser General Public
ttodorov 0:881ff0b71102 7 * License as published by the Free Software Foundation; either
ttodorov 0:881ff0b71102 8 * version 2.1 of the License, or (at your option) any later version.
ttodorov 0:881ff0b71102 9 *
ttodorov 0:881ff0b71102 10 * This library is distributed in the hope that it will be useful,
ttodorov 0:881ff0b71102 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ttodorov 0:881ff0b71102 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ttodorov 0:881ff0b71102 13 * Lesser General Public License for more details.
ttodorov 0:881ff0b71102 14 *
ttodorov 0:881ff0b71102 15 * You should have received a copy of the GNU Lesser General Public
ttodorov 0:881ff0b71102 16 * License along with this library; if not, write to:
ttodorov 0:881ff0b71102 17 *
ttodorov 0:881ff0b71102 18 * Free Software Foundation, Inc.
ttodorov 0:881ff0b71102 19 * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
ttodorov 0:881ff0b71102 20 *
ttodorov 0:881ff0b71102 21 *********************************************************************/
ttodorov 0:881ff0b71102 22 #include "lcd_base.h"
ttodorov 3:64a5b67d5b51 23 #include "helpers.h"
rlanghbv 30:ede1a0a32e04 24
ttodorov 22:4c169297f374 25 LCD::LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS, PinName RESET, PinName BL, backlight_t blType, float defaultBacklight )
ttodorov 22:4c169297f374 26 : _disp_width( width ), _disp_height( height ), _lcd_pin_cs( CS ), _lcd_pin_rs( RS ), _lcd_pin_reset( RESET ), _bl_type( blType )
ttodorov 4:3ac4239f6c9c 27 {
ttodorov 4:3ac4239f6c9c 28 SetForeground();
ttodorov 4:3ac4239f6c9c 29 SetBackground();
rlanghbv 30:ede1a0a32e04 30 // _font = &TerminusFont;
rlanghbv 30:ede1a0a32e04 31 _font = &TerminusBigFont;
ttodorov 22:4c169297f374 32 if ( defaultBacklight < 0 ) _bl_pwm_default = 0;
ttodorov 22:4c169297f374 33 else if ( defaultBacklight > 1.0 ) _bl_pwm_default = 1.0;
ttodorov 22:4c169297f374 34 else _bl_pwm_default = defaultBacklight;
ttodorov 22:4c169297f374 35 if ( BL != NC )
ttodorov 22:4c169297f374 36 {
ttodorov 22:4c169297f374 37 if ( blType == Constant )
ttodorov 22:4c169297f374 38 {
ttodorov 22:4c169297f374 39 _bl_pwm = 0;
ttodorov 22:4c169297f374 40 _lcd_pin_bl = new DigitalOut( BL );
ttodorov 22:4c169297f374 41 }
ttodorov 22:4c169297f374 42 else
ttodorov 22:4c169297f374 43 {
ttodorov 22:4c169297f374 44 _lcd_pin_bl = 0;
ttodorov 22:4c169297f374 45 _bl_pwm = new PwmOut( BL );
ttodorov 22:4c169297f374 46 _bl_pwm->period_ms( 8.33 ); // 120 Hz
ttodorov 22:4c169297f374 47 _bl_pwm_current = _bl_pwm_default;
ttodorov 22:4c169297f374 48 // initially off
ttodorov 22:4c169297f374 49 *_bl_pwm = 0;
ttodorov 22:4c169297f374 50 }
ttodorov 22:4c169297f374 51
ttodorov 22:4c169297f374 52 }
ttodorov 22:4c169297f374 53 else
ttodorov 22:4c169297f374 54 {
ttodorov 22:4c169297f374 55 _lcd_pin_bl = 0;
ttodorov 22:4c169297f374 56 _bl_pwm = 0;
ttodorov 22:4c169297f374 57 }
ttodorov 22:4c169297f374 58 }
rlanghbv 30:ede1a0a32e04 59
ttodorov 22:4c169297f374 60 void LCD::Sleep( void )
ttodorov 22:4c169297f374 61 {
ttodorov 22:4c169297f374 62 if ( _lcd_pin_bl != 0 )
ttodorov 22:4c169297f374 63 *_lcd_pin_bl = LOW;
ttodorov 22:4c169297f374 64 else if ( _bl_pwm != 0 )
ttodorov 22:4c169297f374 65 *_bl_pwm = 0;
ttodorov 22:4c169297f374 66 }
rlanghbv 30:ede1a0a32e04 67
ttodorov 22:4c169297f374 68 void LCD::WakeUp( void )
ttodorov 22:4c169297f374 69 {
ttodorov 22:4c169297f374 70 if ( _lcd_pin_bl != 0 )
ttodorov 22:4c169297f374 71 *_lcd_pin_bl = HIGH;
ttodorov 22:4c169297f374 72 else if ( _bl_pwm != 0 )
ttodorov 22:4c169297f374 73 *_bl_pwm = _bl_pwm_current;
ttodorov 4:3ac4239f6c9c 74 }
rlanghbv 30:ede1a0a32e04 75
ttodorov 0:881ff0b71102 76 inline
ttodorov 12:d0978272a340 77 void LCD::SetForeground( unsigned int color )
ttodorov 0:881ff0b71102 78 {
ttodorov 0:881ff0b71102 79 _foreground = color;
ttodorov 0:881ff0b71102 80 }
rlanghbv 30:ede1a0a32e04 81
ttodorov 0:881ff0b71102 82 inline
ttodorov 12:d0978272a340 83 void LCD::SetBackground( unsigned int color )
ttodorov 0:881ff0b71102 84 {
ttodorov 0:881ff0b71102 85 _background = color;
ttodorov 0:881ff0b71102 86 }
rlanghbv 30:ede1a0a32e04 87
ttodorov 21:e5c1e8ffada1 88 void LCD::SetFont( const font_t *font )
ttodorov 0:881ff0b71102 89 {
ttodorov 21:e5c1e8ffada1 90 _font = font;
ttodorov 0:881ff0b71102 91 }
rlanghbv 30:ede1a0a32e04 92
rlanghbv 30:ede1a0a32e04 93 //inline
rlanghbv 30:ede1a0a32e04 94 unsigned short LCD::GetHeight( void )
rlanghbv 30:ede1a0a32e04 95 {
rlanghbv 30:ede1a0a32e04 96 if ( _orientation == LANDSCAPE || _orientation == LANDSCAPE_REV ) return _disp_width;
rlanghbv 30:ede1a0a32e04 97 return _disp_height;
rlanghbv 30:ede1a0a32e04 98 }
rlanghbv 30:ede1a0a32e04 99
rlanghbv 30:ede1a0a32e04 100
rlanghbv 30:ede1a0a32e04 101 //inline
ttodorov 0:881ff0b71102 102 unsigned short LCD::GetWidth( void )
ttodorov 0:881ff0b71102 103 {
ttodorov 12:d0978272a340 104 if ( _orientation == LANDSCAPE || _orientation == LANDSCAPE_REV ) return _disp_height;
ttodorov 0:881ff0b71102 105 return _disp_width;
ttodorov 0:881ff0b71102 106 }
rlanghbv 30:ede1a0a32e04 107
rlanghbv 30:ede1a0a32e04 108
rlanghbv 30:ede1a0a32e04 109 //inline
ttodorov 21:e5c1e8ffada1 110 uint8_t LCD::GetFontWidth( void )
ttodorov 21:e5c1e8ffada1 111 {
ttodorov 21:e5c1e8ffada1 112 if ( _font != 0 ) return _font->Width;
ttodorov 21:e5c1e8ffada1 113 return 0;
ttodorov 21:e5c1e8ffada1 114 }
rlanghbv 30:ede1a0a32e04 115
ttodorov 21:e5c1e8ffada1 116 inline
ttodorov 21:e5c1e8ffada1 117 uint8_t LCD::GetFontHeight( void )
ttodorov 21:e5c1e8ffada1 118 {
ttodorov 21:e5c1e8ffada1 119 if ( _font != 0 ) return _font->Height;
ttodorov 21:e5c1e8ffada1 120 return 0;
ttodorov 21:e5c1e8ffada1 121 }
rlanghbv 30:ede1a0a32e04 122
ttodorov 22:4c169297f374 123 void LCD::SetBacklightLevel( float level )
ttodorov 22:4c169297f374 124 {
ttodorov 22:4c169297f374 125 switch ( _bl_type )
ttodorov 22:4c169297f374 126 {
ttodorov 22:4c169297f374 127 case Direct:
ttodorov 22:4c169297f374 128 if ( _bl_pwm != 0 )
ttodorov 22:4c169297f374 129 {
ttodorov 22:4c169297f374 130 *_bl_pwm = level;
ttodorov 22:4c169297f374 131 _bl_pwm_current = level;
ttodorov 22:4c169297f374 132 }
ttodorov 22:4c169297f374 133 break;
ttodorov 22:4c169297f374 134
ttodorov 22:4c169297f374 135 case Indirect:
ttodorov 22:4c169297f374 136 break;
ttodorov 22:4c169297f374 137 case Constant:
ttodorov 22:4c169297f374 138 default:
ttodorov 22:4c169297f374 139 break;
ttodorov 22:4c169297f374 140 }
ttodorov 22:4c169297f374 141 }
rlanghbv 30:ede1a0a32e04 142
ttodorov 0:881ff0b71102 143 void LCD::FillScreen( int color )
ttodorov 0:881ff0b71102 144 {
ttodorov 12:d0978272a340 145 unsigned int rgb = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 4:3ac4239f6c9c 146 Activate();
ttodorov 2:81ed304b7e9b 147 ClearXY();
ttodorov 1:14bef43daf6f 148 for ( int i = 0; i < ( ( _disp_width ) * ( _disp_height ) ); i++ )
ttodorov 10:69571adcfad5 149 SetPixelColor( rgb );
ttodorov 4:3ac4239f6c9c 150 Deactivate();
ttodorov 0:881ff0b71102 151 }
rlanghbv 30:ede1a0a32e04 152
ttodorov 0:881ff0b71102 153 inline
ttodorov 0:881ff0b71102 154 void LCD::ClearScreen( void )
ttodorov 0:881ff0b71102 155 {
ttodorov 0:881ff0b71102 156 FillScreen( -1 );
ttodorov 0:881ff0b71102 157 }
rlanghbv 30:ede1a0a32e04 158
ttodorov 0:881ff0b71102 159 void LCD::DrawPixel( unsigned short x, unsigned short y, int color )
ttodorov 0:881ff0b71102 160 {
ttodorov 4:3ac4239f6c9c 161 Activate();
ttodorov 2:81ed304b7e9b 162 SetXY( x, y, x, y );
ttodorov 10:69571adcfad5 163 SetPixelColor( color == -1 ? _background :
ttodorov 0:881ff0b71102 164 color == -2 ? _foreground : color );
ttodorov 4:3ac4239f6c9c 165 Deactivate();
ttodorov 0:881ff0b71102 166 }
rlanghbv 30:ede1a0a32e04 167
ttodorov 0:881ff0b71102 168 void LCD::DrawLine( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
ttodorov 0:881ff0b71102 169 {
ttodorov 0:881ff0b71102 170
ttodorov 0:881ff0b71102 171 double delta, tx, ty;
rlanghbv 30:ede1a0a32e04 172
ttodorov 0:881ff0b71102 173 if ( ( ( x2 - x1 ) < 0 ) )
ttodorov 0:881ff0b71102 174 {
ttodorov 0:881ff0b71102 175 swap( ushort, x1, x2 )
ttodorov 0:881ff0b71102 176 swap( ushort, y1, y2 )
ttodorov 0:881ff0b71102 177 }
ttodorov 0:881ff0b71102 178 if ( ( ( y2 - y1 ) < 0 ) )
ttodorov 0:881ff0b71102 179 {
ttodorov 0:881ff0b71102 180 swap( ushort, x1, x2 )
ttodorov 0:881ff0b71102 181 swap( ushort, y1, y2 )
ttodorov 0:881ff0b71102 182 }
rlanghbv 30:ede1a0a32e04 183
ttodorov 0:881ff0b71102 184 if ( y1 == y2 )
ttodorov 0:881ff0b71102 185 {
ttodorov 0:881ff0b71102 186 if ( x1 > x2 )
ttodorov 0:881ff0b71102 187 swap( ushort, x1, x2 )
ttodorov 2:81ed304b7e9b 188 DrawHLine( x1, y1, x2 - x1, color );
ttodorov 0:881ff0b71102 189 }
ttodorov 0:881ff0b71102 190 else if ( x1 == x2 )
ttodorov 0:881ff0b71102 191 {
ttodorov 0:881ff0b71102 192 if ( y1 > y2 )
ttodorov 0:881ff0b71102 193 swap( ushort, y1, y2 )
ttodorov 2:81ed304b7e9b 194 DrawVLine( x1, y1, y2 - y1, color );
ttodorov 0:881ff0b71102 195 }
ttodorov 4:3ac4239f6c9c 196 else
ttodorov 0:881ff0b71102 197 {
ttodorov 12:d0978272a340 198 unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 4:3ac4239f6c9c 199 Activate();
ttodorov 4:3ac4239f6c9c 200 if ( abs( x2 - x1 ) > abs( y2 - y1 ) )
ttodorov 0:881ff0b71102 201 {
ttodorov 4:3ac4239f6c9c 202 delta = ( double( y2 - y1 ) / double( x2 - x1 ) );
ttodorov 4:3ac4239f6c9c 203 ty = double( y1 );
ttodorov 4:3ac4239f6c9c 204 if ( x1 > x2 )
ttodorov 0:881ff0b71102 205 {
ttodorov 4:3ac4239f6c9c 206 for ( int i = x1; i >= x2; i-- )
ttodorov 4:3ac4239f6c9c 207 {
ttodorov 4:3ac4239f6c9c 208 SetXY( i, int( ty + 0.5 ), i, int( ty + 0.5 ) );
ttodorov 10:69571adcfad5 209 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 210 ty = ty - delta;
ttodorov 4:3ac4239f6c9c 211 }
ttodorov 4:3ac4239f6c9c 212 }
ttodorov 4:3ac4239f6c9c 213 else
ttodorov 4:3ac4239f6c9c 214 {
ttodorov 4:3ac4239f6c9c 215 for ( int i = x1; i <= x2; i++ )
ttodorov 4:3ac4239f6c9c 216 {
ttodorov 4:3ac4239f6c9c 217 SetXY( i, int( ty + 0.5 ), i, int( ty + 0.5 ) );
ttodorov 10:69571adcfad5 218 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 219 ty = ty + delta;
ttodorov 4:3ac4239f6c9c 220 }
ttodorov 0:881ff0b71102 221 }
ttodorov 0:881ff0b71102 222 }
ttodorov 0:881ff0b71102 223 else
ttodorov 0:881ff0b71102 224 {
ttodorov 4:3ac4239f6c9c 225 delta = ( float( x2 - x1 ) / float( y2 - y1 ) );
ttodorov 4:3ac4239f6c9c 226 tx = float( x1 );
ttodorov 4:3ac4239f6c9c 227 if ( y1 > y2 )
ttodorov 0:881ff0b71102 228 {
ttodorov 4:3ac4239f6c9c 229 for ( int i = y2 + 1; i > y1; i-- )
ttodorov 4:3ac4239f6c9c 230 {
ttodorov 4:3ac4239f6c9c 231 SetXY( int( tx + 0.5 ), i, int( tx + 0.5 ), i );
ttodorov 10:69571adcfad5 232 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 233 tx = tx + delta;
ttodorov 4:3ac4239f6c9c 234 }
ttodorov 4:3ac4239f6c9c 235 }
ttodorov 4:3ac4239f6c9c 236 else
ttodorov 4:3ac4239f6c9c 237 {
ttodorov 4:3ac4239f6c9c 238 for ( int i = y1; i < y2 + 1; i++ )
ttodorov 4:3ac4239f6c9c 239 {
ttodorov 4:3ac4239f6c9c 240 SetXY( int( tx + 0.5 ), i, int( tx + 0.5 ), i );
ttodorov 10:69571adcfad5 241 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 242 tx = tx + delta;
ttodorov 4:3ac4239f6c9c 243 }
ttodorov 0:881ff0b71102 244 }
ttodorov 0:881ff0b71102 245 }
ttodorov 4:3ac4239f6c9c 246 Deactivate();
ttodorov 0:881ff0b71102 247 }
ttodorov 0:881ff0b71102 248 }
rlanghbv 30:ede1a0a32e04 249 void LCD::DrawTriangle( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned short x3, unsigned short y3, int color )
rlanghbv 30:ede1a0a32e04 250 {
rlanghbv 30:ede1a0a32e04 251 // if ( x1 > x2 ) swap( ushort, x1, x2 )
rlanghbv 30:ede1a0a32e04 252 // if ( y1 > y2 ) swap( ushort, y1, y2 )
rlanghbv 30:ede1a0a32e04 253
rlanghbv 30:ede1a0a32e04 254 DrawLine( x1, y1, x2, y2, color );
rlanghbv 30:ede1a0a32e04 255 DrawLine( x2, y2, x3, y3, color );
rlanghbv 30:ede1a0a32e04 256 DrawLine( x3, y3, x1, y1, color );
rlanghbv 30:ede1a0a32e04 257 }
rlanghbv 30:ede1a0a32e04 258
rlanghbv 30:ede1a0a32e04 259 void LCD::FillTriangle( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned short x3, unsigned short y3, int color )
rlanghbv 30:ede1a0a32e04 260 {
rlanghbv 30:ede1a0a32e04 261 int dx1, dx2, dx3;
rlanghbv 30:ede1a0a32e04 262 int sx1, sx2, sy;
rlanghbv 30:ede1a0a32e04 263
rlanghbv 30:ede1a0a32e04 264
rlanghbv 30:ede1a0a32e04 265 if ( y1 > y2 ) { swap( ushort, y1, y2 ); swap( ushort, x1, x2 ); }
rlanghbv 30:ede1a0a32e04 266 if ( y2 > y3 ) { swap( ushort, y3, y2 ); swap( ushort, x3, x2 ); }
rlanghbv 30:ede1a0a32e04 267 if ( y1 > y2 ) { swap( ushort, y1, y2 ); swap( ushort, x1, x2 ); }
rlanghbv 30:ede1a0a32e04 268
rlanghbv 30:ede1a0a32e04 269 sx2= x1 * 1000; // Use fixed point math for x axis values
rlanghbv 30:ede1a0a32e04 270 sx1 = sx2;
rlanghbv 30:ede1a0a32e04 271 sy=y1;
rlanghbv 30:ede1a0a32e04 272
rlanghbv 30:ede1a0a32e04 273 // Calculate interpolation deltas
rlanghbv 30:ede1a0a32e04 274 if (y2-y1 > 0) dx1=((x2-x1)*1000)/(y2-y1);
rlanghbv 30:ede1a0a32e04 275 else dx1=0;
rlanghbv 30:ede1a0a32e04 276 if (y3-y1 > 0) dx2=((x3-x1)*1000)/(y3-y1);
rlanghbv 30:ede1a0a32e04 277 else dx2=0;
rlanghbv 30:ede1a0a32e04 278 if (y3-y2 > 0) dx3=((x3-x2)*1000)/(y3-y2);
rlanghbv 30:ede1a0a32e04 279 else dx3=0;
rlanghbv 30:ede1a0a32e04 280
rlanghbv 30:ede1a0a32e04 281 // Render scanlines (horizontal lines are the fastest rendering method)
rlanghbv 30:ede1a0a32e04 282 if (dx1 > dx2)
rlanghbv 30:ede1a0a32e04 283 {
rlanghbv 30:ede1a0a32e04 284 for(; sy<=y2; sy++, sx1+=dx2, sx2+=dx1)
rlanghbv 30:ede1a0a32e04 285 {
rlanghbv 30:ede1a0a32e04 286 DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
rlanghbv 30:ede1a0a32e04 287 }
rlanghbv 30:ede1a0a32e04 288 sx2 = x2*1000;
rlanghbv 30:ede1a0a32e04 289 sy = y2;
rlanghbv 30:ede1a0a32e04 290 for(; sy<=y3; sy++, sx1+=dx2, sx2+=dx3)
rlanghbv 30:ede1a0a32e04 291 {
rlanghbv 30:ede1a0a32e04 292 DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
rlanghbv 30:ede1a0a32e04 293 }
rlanghbv 30:ede1a0a32e04 294 }
rlanghbv 30:ede1a0a32e04 295 else
rlanghbv 30:ede1a0a32e04 296 {
rlanghbv 30:ede1a0a32e04 297 for(; sy<=y2; sy++, sx1+=dx1, sx2+=dx2)
rlanghbv 30:ede1a0a32e04 298 {
rlanghbv 30:ede1a0a32e04 299 DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
rlanghbv 30:ede1a0a32e04 300 }
rlanghbv 30:ede1a0a32e04 301 sx1 = x2*1000;
rlanghbv 30:ede1a0a32e04 302 sy = y2;
rlanghbv 30:ede1a0a32e04 303 for(; sy<=y3; sy++, sx1+=dx3, sx2+=dx2)
rlanghbv 30:ede1a0a32e04 304 {
rlanghbv 30:ede1a0a32e04 305 DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
rlanghbv 30:ede1a0a32e04 306 }
rlanghbv 30:ede1a0a32e04 307 }
rlanghbv 30:ede1a0a32e04 308
rlanghbv 30:ede1a0a32e04 309 }
rlanghbv 30:ede1a0a32e04 310
ttodorov 0:881ff0b71102 311 void LCD::DrawRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
ttodorov 0:881ff0b71102 312 {
ttodorov 0:881ff0b71102 313 if ( x1 > x2 ) swap( ushort, x1, x2 )
ttodorov 0:881ff0b71102 314 if ( y1 > y2 ) swap( ushort, y1, y2 )
rlanghbv 30:ede1a0a32e04 315
ttodorov 2:81ed304b7e9b 316 DrawHLine( x1, y1, x2 - x1, color );
ttodorov 2:81ed304b7e9b 317 DrawHLine( x1, y2, x2 - x1, color );
ttodorov 2:81ed304b7e9b 318 DrawVLine( x1, y1, y2 - y1, color );
ttodorov 2:81ed304b7e9b 319 DrawVLine( x2, y1, y2 - y1, color );
ttodorov 0:881ff0b71102 320 }
rlanghbv 30:ede1a0a32e04 321
ttodorov 0:881ff0b71102 322 void LCD::DrawRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
ttodorov 0:881ff0b71102 323 {
ttodorov 0:881ff0b71102 324 if ( x1 > x2 ) swap( ushort, x1, x2 )
ttodorov 0:881ff0b71102 325 if ( y1 > y2 ) swap( ushort, y1, y2 )
rlanghbv 30:ede1a0a32e04 326
ttodorov 0:881ff0b71102 327 if ( ( x2 - x1 ) > 4 && ( y2 - y1 ) > 4 )
ttodorov 0:881ff0b71102 328 {
ttodorov 0:881ff0b71102 329 DrawPixel( x1 + 1, y1 + 1, color );
ttodorov 0:881ff0b71102 330 DrawPixel( x2 - 1, y1 + 1, color );
ttodorov 0:881ff0b71102 331 DrawPixel( x1 + 1, y2 - 1, color );
ttodorov 0:881ff0b71102 332 DrawPixel( x2 - 1, y2 - 1, color );
ttodorov 2:81ed304b7e9b 333 DrawHLine( x1 + 2, y1, x2 - x1 - 4, color );
ttodorov 2:81ed304b7e9b 334 DrawHLine( x1 + 2, y2, x2 - x1 - 4, color );
ttodorov 2:81ed304b7e9b 335 DrawVLine( x1, y1 + 2, y2 - y1 - 4, color );
ttodorov 2:81ed304b7e9b 336 DrawVLine( x2, y1 + 2, y2 - y1 - 4, color );
ttodorov 0:881ff0b71102 337 }
ttodorov 0:881ff0b71102 338 }
rlanghbv 30:ede1a0a32e04 339
ttodorov 0:881ff0b71102 340 void LCD::FillRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
ttodorov 0:881ff0b71102 341 {
ttodorov 0:881ff0b71102 342 if ( x1 > x2 ) swap( ushort, x1, x2 );
ttodorov 0:881ff0b71102 343 if ( y1 > y2 ) swap( ushort, y1, y2 );
rlanghbv 30:ede1a0a32e04 344
ttodorov 12:d0978272a340 345 for ( int i = 0; i < ( ( y2 - y1 ) / 2 ) + 1; i++ )
ttodorov 0:881ff0b71102 346 {
ttodorov 12:d0978272a340 347 DrawHLine( x1, y1 + i, x2 - x1, color );
ttodorov 12:d0978272a340 348 DrawHLine( x1, y2 - i, x2 - x1, color );
ttodorov 0:881ff0b71102 349 }
ttodorov 0:881ff0b71102 350 }
rlanghbv 30:ede1a0a32e04 351
ttodorov 0:881ff0b71102 352 void LCD::FillRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
ttodorov 0:881ff0b71102 353 {
ttodorov 0:881ff0b71102 354 if ( x1 > x2 ) swap( ushort, x1, x2 )
ttodorov 0:881ff0b71102 355 if ( y1 > y2 ) swap( ushort, y1, y2 )
rlanghbv 30:ede1a0a32e04 356
ttodorov 0:881ff0b71102 357 if ( ( x2 - x1 ) > 4 && ( y2 - y1 ) > 4 )
ttodorov 0:881ff0b71102 358 {
ttodorov 0:881ff0b71102 359 for ( int i = 0; i < ( ( y2 - y1 ) / 2 ) + 1; i++ )
ttodorov 0:881ff0b71102 360 {
ttodorov 0:881ff0b71102 361 switch ( i )
ttodorov 0:881ff0b71102 362 {
ttodorov 0:881ff0b71102 363 case 0:
ttodorov 2:81ed304b7e9b 364 DrawHLine( x1 + 2, y1 + i, x2 - x1 - 4, color );
ttodorov 2:81ed304b7e9b 365 DrawHLine( x1 + 2, y2 - i, x2 - x1 - 4, color );
ttodorov 0:881ff0b71102 366 break;
rlanghbv 30:ede1a0a32e04 367
ttodorov 0:881ff0b71102 368 case 1:
ttodorov 2:81ed304b7e9b 369 DrawHLine( x1 + 1, y1 + i, x2 - x1 - 2, color );
ttodorov 2:81ed304b7e9b 370 DrawHLine( x1 + 1, y2 - i, x2 - x1 - 2, color );
ttodorov 0:881ff0b71102 371 break;
rlanghbv 30:ede1a0a32e04 372
ttodorov 0:881ff0b71102 373 default:
ttodorov 2:81ed304b7e9b 374 DrawHLine( x1, y1 + i, x2 - x1, color );
ttodorov 2:81ed304b7e9b 375 DrawHLine( x1, y2 - i, x2 - x1, color );
ttodorov 0:881ff0b71102 376 break;
ttodorov 0:881ff0b71102 377 }
ttodorov 0:881ff0b71102 378 }
ttodorov 0:881ff0b71102 379 }
ttodorov 0:881ff0b71102 380 }
rlanghbv 30:ede1a0a32e04 381
ttodorov 0:881ff0b71102 382 void LCD::DrawCircle( unsigned short x, unsigned short y, unsigned short radius, int color )
ttodorov 0:881ff0b71102 383 {
ttodorov 0:881ff0b71102 384 int f = 1 - radius;
ttodorov 0:881ff0b71102 385 int ddF_x = 1;
ttodorov 0:881ff0b71102 386 int ddF_y = -2 * radius;
ttodorov 0:881ff0b71102 387 int x1 = 0;
ttodorov 0:881ff0b71102 388 int y1 = radius;
ttodorov 12:d0978272a340 389 unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
rlanghbv 30:ede1a0a32e04 390
ttodorov 4:3ac4239f6c9c 391 Activate();
ttodorov 2:81ed304b7e9b 392 SetXY( x, y + radius, x, y + radius );
ttodorov 10:69571adcfad5 393 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 394 SetXY( x, y - radius, x, y - radius );
ttodorov 10:69571adcfad5 395 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 396 SetXY( x + radius, y, x + radius, y );
ttodorov 10:69571adcfad5 397 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 398 SetXY( x - radius, y, x - radius, y );
ttodorov 10:69571adcfad5 399 SetPixelColor( usedColor );
rlanghbv 30:ede1a0a32e04 400
ttodorov 0:881ff0b71102 401 while ( x1 < y1 )
ttodorov 0:881ff0b71102 402 {
ttodorov 0:881ff0b71102 403 if ( f >= 0 )
ttodorov 0:881ff0b71102 404 {
ttodorov 0:881ff0b71102 405 y1--;
ttodorov 0:881ff0b71102 406 ddF_y += 2;
ttodorov 0:881ff0b71102 407 f += ddF_y;
ttodorov 0:881ff0b71102 408 }
ttodorov 0:881ff0b71102 409 x1++;
ttodorov 0:881ff0b71102 410 ddF_x += 2;
ttodorov 0:881ff0b71102 411 f += ddF_x;
ttodorov 2:81ed304b7e9b 412 SetXY( x + x1, y + y1, x + x1, y + y1 );
ttodorov 10:69571adcfad5 413 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 414 SetXY( x - x1, y + y1, x - x1, y + y1 );
ttodorov 10:69571adcfad5 415 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 416 SetXY( x + x1, y - y1, x + x1, y - y1 );
ttodorov 10:69571adcfad5 417 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 418 SetXY( x - x1, y - y1, x - x1, y - y1 );
ttodorov 10:69571adcfad5 419 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 420 SetXY( x + y1, y + x1, x + y1, y + x1 );
ttodorov 10:69571adcfad5 421 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 422 SetXY( x - y1, y + x1, x - y1, y + x1 );
ttodorov 10:69571adcfad5 423 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 424 SetXY( x + y1, y - x1, x + y1, y - x1 );
ttodorov 10:69571adcfad5 425 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 426 SetXY( x - y1, y - x1, x - y1, y - x1 );
ttodorov 10:69571adcfad5 427 SetPixelColor( usedColor );
ttodorov 0:881ff0b71102 428 }
ttodorov 4:3ac4239f6c9c 429 Deactivate();
ttodorov 0:881ff0b71102 430 }
rlanghbv 30:ede1a0a32e04 431
ttodorov 0:881ff0b71102 432 void LCD::FillCircle( unsigned short x, unsigned short y, unsigned short radius, int color )
ttodorov 0:881ff0b71102 433 {
ttodorov 12:d0978272a340 434 unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 4:3ac4239f6c9c 435 Activate();
ttodorov 0:881ff0b71102 436 for ( int y1 = -radius; y1 <= radius; y1++ )
ttodorov 0:881ff0b71102 437 for ( int x1 = -radius; x1 <= radius; x1++ )
ttodorov 0:881ff0b71102 438 if ( x1 * x1 + y1 * y1 <= radius * radius )
ttodorov 0:881ff0b71102 439 {
ttodorov 2:81ed304b7e9b 440 SetXY( x + x1, y + y1, x + x1, y + y1 );
ttodorov 10:69571adcfad5 441 SetPixelColor( usedColor );
ttodorov 0:881ff0b71102 442 }
ttodorov 4:3ac4239f6c9c 443 Deactivate();
ttodorov 0:881ff0b71102 444 }
rlanghbv 30:ede1a0a32e04 445
ttodorov 0:881ff0b71102 446 void LCD::Print( const char *str, unsigned short x, unsigned short y, int fgColor, int bgColor, unsigned short deg )
ttodorov 0:881ff0b71102 447 {
ttodorov 0:881ff0b71102 448 int stl, i;
rlanghbv 30:ede1a0a32e04 449
ttodorov 0:881ff0b71102 450 stl = strlen( str );
rlanghbv 30:ede1a0a32e04 451
ttodorov 12:d0978272a340 452 if ( x == RIGHT )
ttodorov 21:e5c1e8ffada1 453 x = GetWidth() - ( stl * _font->Width );
ttodorov 12:d0978272a340 454 if ( x == CENTER )
ttodorov 21:e5c1e8ffada1 455 x = ( GetWidth() - ( stl * _font->Width ) ) / 2;
rlanghbv 30:ede1a0a32e04 456
ttodorov 0:881ff0b71102 457 for ( i = 0; i < stl; i++ )
ttodorov 0:881ff0b71102 458 if ( deg == 0 )
ttodorov 21:e5c1e8ffada1 459 PrintChar( *str++, x + ( i * ( _font->Width ) ), y, fgColor, bgColor );
ttodorov 0:881ff0b71102 460 else
ttodorov 2:81ed304b7e9b 461 RotateChar( *str++, x, y, i, fgColor, bgColor, deg );
ttodorov 0:881ff0b71102 462 }
rlanghbv 30:ede1a0a32e04 463
ttodorov 12:d0978272a340 464 void LCD::DrawBitmap( unsigned short x, unsigned short y, const bitmap_t* img, unsigned char scale )
ttodorov 0:881ff0b71102 465 {
ttodorov 0:881ff0b71102 466 int tx, ty, tc, tsx, tsy;
rlanghbv 30:ede1a0a32e04 467
ttodorov 4:3ac4239f6c9c 468 Activate();
ttodorov 0:881ff0b71102 469 if ( scale == 1 )
ttodorov 0:881ff0b71102 470 {
ttodorov 12:d0978272a340 471 SetXY( x, y, x + img->Width - 1, y + img->Height - 1 );
rlanghbv 30:ede1a0a32e04 472
ttodorov 13:5ceeba86bbe4 473 if ( img->Format == RGB16 )
ttodorov 0:881ff0b71102 474 {
ttodorov 13:5ceeba86bbe4 475 const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
ttodorov 20:4bdca8d8dadc 476 for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
ttodorov 20:4bdca8d8dadc 477 SetPixelColor( *pixel++, img->Format );
ttodorov 13:5ceeba86bbe4 478 }
ttodorov 13:5ceeba86bbe4 479 else if ( img->Format == RGB18 )
ttodorov 13:5ceeba86bbe4 480 {
ttodorov 13:5ceeba86bbe4 481 const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
ttodorov 20:4bdca8d8dadc 482 for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
ttodorov 20:4bdca8d8dadc 483 SetPixelColor( *pixel++, img->Format );
ttodorov 0:881ff0b71102 484 }
ttodorov 0:881ff0b71102 485 }
ttodorov 0:881ff0b71102 486 else
ttodorov 0:881ff0b71102 487 {
ttodorov 13:5ceeba86bbe4 488 if ( img->Format == RGB16 )
ttodorov 0:881ff0b71102 489 {
ttodorov 13:5ceeba86bbe4 490 const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
ttodorov 13:5ceeba86bbe4 491
ttodorov 13:5ceeba86bbe4 492 for ( ty = 0; ty < img->Height; ty++ )
ttodorov 13:5ceeba86bbe4 493 {
ttodorov 13:5ceeba86bbe4 494 SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale );
ttodorov 13:5ceeba86bbe4 495 for ( tsy = 0; tsy < scale; tsy++ )
ttodorov 13:5ceeba86bbe4 496 {
ttodorov 13:5ceeba86bbe4 497 for ( tx = 0; tx < img->Width; tx++ )
ttodorov 13:5ceeba86bbe4 498 {
ttodorov 13:5ceeba86bbe4 499 for ( tsx = 0; tsx < scale; tsx++ )
ttodorov 20:4bdca8d8dadc 500 SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
ttodorov 20:4bdca8d8dadc 501 }
ttodorov 20:4bdca8d8dadc 502 }
ttodorov 20:4bdca8d8dadc 503 }
ttodorov 20:4bdca8d8dadc 504 }
ttodorov 20:4bdca8d8dadc 505 else if ( img->Format == RGB18 )
ttodorov 20:4bdca8d8dadc 506 {
ttodorov 20:4bdca8d8dadc 507 const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
ttodorov 20:4bdca8d8dadc 508
ttodorov 20:4bdca8d8dadc 509 for ( ty = 0; ty < img->Height; ty++ )
ttodorov 20:4bdca8d8dadc 510 {
ttodorov 20:4bdca8d8dadc 511 SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale );
ttodorov 20:4bdca8d8dadc 512 for ( tsy = 0; tsy < scale; tsy++ )
ttodorov 20:4bdca8d8dadc 513 {
ttodorov 20:4bdca8d8dadc 514 for ( tx = 0; tx < img->Width; tx++ )
ttodorov 20:4bdca8d8dadc 515 {
ttodorov 20:4bdca8d8dadc 516 for ( tsx = 0; tsx < scale; tsx++ )
ttodorov 20:4bdca8d8dadc 517 SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
ttodorov 13:5ceeba86bbe4 518 }
ttodorov 13:5ceeba86bbe4 519 }
ttodorov 13:5ceeba86bbe4 520 }
ttodorov 13:5ceeba86bbe4 521 }
ttodorov 0:881ff0b71102 522 }
ttodorov 4:3ac4239f6c9c 523 Deactivate();
ttodorov 0:881ff0b71102 524 }
rlanghbv 30:ede1a0a32e04 525
ttodorov 12:d0978272a340 526 void LCD::DrawBitmap( unsigned short x, unsigned short y, const bitmap_t* img, unsigned short deg, unsigned short rox, unsigned short roy )
ttodorov 0:881ff0b71102 527 {
ttodorov 0:881ff0b71102 528 int tx, ty, newx, newy;
ttodorov 0:881ff0b71102 529 double radian;
ttodorov 0:881ff0b71102 530 radian = deg * 0.0175;
rlanghbv 30:ede1a0a32e04 531
ttodorov 0:881ff0b71102 532 if ( deg == 0 )
ttodorov 12:d0978272a340 533 DrawBitmap( x, y, img );
ttodorov 0:881ff0b71102 534 else
ttodorov 0:881ff0b71102 535 {
ttodorov 4:3ac4239f6c9c 536 Activate();
ttodorov 13:5ceeba86bbe4 537
ttodorov 13:5ceeba86bbe4 538 if ( img->Format == RGB16 )
ttodorov 13:5ceeba86bbe4 539 {
ttodorov 13:5ceeba86bbe4 540 const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
ttodorov 13:5ceeba86bbe4 541
ttodorov 13:5ceeba86bbe4 542 for ( ty = 0; ty < img->Height; ty++ )
ttodorov 13:5ceeba86bbe4 543 for ( tx = 0; tx < img->Width; tx++ )
ttodorov 13:5ceeba86bbe4 544 {
ttodorov 13:5ceeba86bbe4 545 newx = x + rox + ( ( ( tx - rox ) * cos( radian ) ) - ( ( ty - roy ) * sin( radian ) ) );
ttodorov 13:5ceeba86bbe4 546 newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) );
ttodorov 13:5ceeba86bbe4 547
ttodorov 13:5ceeba86bbe4 548 SetXY( newx, newy, newx, newy );
ttodorov 20:4bdca8d8dadc 549 SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
ttodorov 13:5ceeba86bbe4 550 }
ttodorov 13:5ceeba86bbe4 551 }
ttodorov 13:5ceeba86bbe4 552 else if ( img->Format == RGB18 )
ttodorov 13:5ceeba86bbe4 553 {
ttodorov 13:5ceeba86bbe4 554 const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
ttodorov 13:5ceeba86bbe4 555
ttodorov 13:5ceeba86bbe4 556 for ( ty = 0; ty < img->Height; ty++ )
ttodorov 13:5ceeba86bbe4 557 for ( tx = 0; tx < img->Width; tx++ )
ttodorov 13:5ceeba86bbe4 558 {
ttodorov 13:5ceeba86bbe4 559 newx = x + rox + ( ( ( tx - rox ) * cos( radian ) ) - ( ( ty - roy ) * sin( radian ) ) );
ttodorov 13:5ceeba86bbe4 560 newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) );
ttodorov 13:5ceeba86bbe4 561
ttodorov 13:5ceeba86bbe4 562 SetXY( newx, newy, newx, newy );
ttodorov 20:4bdca8d8dadc 563 SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
ttodorov 13:5ceeba86bbe4 564 }
ttodorov 13:5ceeba86bbe4 565 }
ttodorov 4:3ac4239f6c9c 566 Deactivate();
ttodorov 0:881ff0b71102 567 }
ttodorov 4:3ac4239f6c9c 568 }
rlanghbv 30:ede1a0a32e04 569
ttodorov 4:3ac4239f6c9c 570 inline
ttodorov 4:3ac4239f6c9c 571 void LCD::Activate( void )
ttodorov 4:3ac4239f6c9c 572 {
ttodorov 4:3ac4239f6c9c 573 _lcd_pin_cs = LOW;
ttodorov 4:3ac4239f6c9c 574 }
rlanghbv 30:ede1a0a32e04 575
ttodorov 4:3ac4239f6c9c 576 inline
ttodorov 4:3ac4239f6c9c 577 void LCD::Deactivate( void )
ttodorov 4:3ac4239f6c9c 578 {
ttodorov 4:3ac4239f6c9c 579 _lcd_pin_cs = HIGH;
ttodorov 0:881ff0b71102 580 }
rlanghbv 30:ede1a0a32e04 581
ttodorov 0:881ff0b71102 582 inline
ttodorov 2:81ed304b7e9b 583 void LCD::WriteCmdData( unsigned short cmd, unsigned short data )
ttodorov 0:881ff0b71102 584 {
ttodorov 2:81ed304b7e9b 585 WriteCmd( cmd );
ttodorov 2:81ed304b7e9b 586 WriteData( data );
ttodorov 0:881ff0b71102 587 }
rlanghbv 30:ede1a0a32e04 588
ttodorov 12:d0978272a340 589 inline
ttodorov 12:d0978272a340 590 void LCD::ClearXY( void )
ttodorov 0:881ff0b71102 591 {
ttodorov 12:d0978272a340 592 SetXY( 0, 0, GetWidth() - 1, GetHeight() - 1 );
ttodorov 0:881ff0b71102 593 }
rlanghbv 30:ede1a0a32e04 594
ttodorov 2:81ed304b7e9b 595 void LCD::DrawHLine( unsigned short x, unsigned short y, unsigned short len, int color )
ttodorov 0:881ff0b71102 596 {
ttodorov 12:d0978272a340 597 unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 0:881ff0b71102 598
ttodorov 4:3ac4239f6c9c 599 Activate();
ttodorov 2:81ed304b7e9b 600 SetXY( x, y, x + len, y );
ttodorov 0:881ff0b71102 601 for ( int i = 0; i < len + 1; i++ )
ttodorov 10:69571adcfad5 602 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 603 Deactivate();
ttodorov 0:881ff0b71102 604 }
rlanghbv 30:ede1a0a32e04 605
ttodorov 2:81ed304b7e9b 606 void LCD::DrawVLine( unsigned short x, unsigned short y, unsigned short len, int color )
ttodorov 0:881ff0b71102 607 {
ttodorov 12:d0978272a340 608 unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 0:881ff0b71102 609
ttodorov 4:3ac4239f6c9c 610 Activate();
ttodorov 2:81ed304b7e9b 611 SetXY( x, y, x, y + len );
ttodorov 0:881ff0b71102 612 for ( int i = 0; i < len; i++ )
ttodorov 10:69571adcfad5 613 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 614 Deactivate();
ttodorov 0:881ff0b71102 615 }
rlanghbv 30:ede1a0a32e04 616
ttodorov 2:81ed304b7e9b 617 void LCD::PrintChar( char c, unsigned short x, unsigned short y, int fgColor, int bgColor )
ttodorov 0:881ff0b71102 618 {
ttodorov 0:881ff0b71102 619 uint8_t i, ch;
ttodorov 0:881ff0b71102 620 uint16_t j;
ttodorov 12:d0978272a340 621 unsigned int usedColorFG = fgColor == -1 ? _background : fgColor == -2 ? _foreground : ( unsigned int ) fgColor;
ttodorov 12:d0978272a340 622 unsigned int usedColorBG = bgColor == -1 ? _background : bgColor == -2 ? _foreground : ( unsigned int ) bgColor;
ttodorov 21:e5c1e8ffada1 623
ttodorov 21:e5c1e8ffada1 624 uint16_t totalCharBytes = ( _font->Width * _font->Height ) / 8;
ttodorov 21:e5c1e8ffada1 625 int16_t position = _font->Position[ c - _font->Offset ];
ttodorov 21:e5c1e8ffada1 626 if ( position == -1 ) position = 0; // will print space character
ttodorov 21:e5c1e8ffada1 627
ttodorov 4:3ac4239f6c9c 628 Activate();
rlanghbv 30:ede1a0a32e04 629
ttodorov 21:e5c1e8ffada1 630 SetXY( x, y, x + _font->Width - 1, y + _font->Height - 1 );
ttodorov 21:e5c1e8ffada1 631
ttodorov 21:e5c1e8ffada1 632 for ( j = 0; j < totalCharBytes; j++ )
ttodorov 0:881ff0b71102 633 {
ttodorov 21:e5c1e8ffada1 634 ch = _font->Data[ position ];
ttodorov 12:d0978272a340 635 for ( i = 0; i < 8; i++ )
ttodorov 0:881ff0b71102 636 {
ttodorov 21:e5c1e8ffada1 637 if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) SetPixelColor( usedColorFG );
ttodorov 21:e5c1e8ffada1 638 else SetPixelColor( usedColorBG );
ttodorov 0:881ff0b71102 639 }
ttodorov 21:e5c1e8ffada1 640 position++;
ttodorov 0:881ff0b71102 641 }
ttodorov 4:3ac4239f6c9c 642 Deactivate();
ttodorov 0:881ff0b71102 643 }
rlanghbv 30:ede1a0a32e04 644
ttodorov 2:81ed304b7e9b 645 void LCD::RotateChar( char c, unsigned short x, unsigned short y, int pos, int fgColor, int bgColor, unsigned short deg )
ttodorov 0:881ff0b71102 646 {
ttodorov 0:881ff0b71102 647 uint8_t i, j, ch;
ttodorov 0:881ff0b71102 648 int newx, newy;
ttodorov 0:881ff0b71102 649 double radian;
ttodorov 0:881ff0b71102 650 radian = deg * 0.0175;
ttodorov 0:881ff0b71102 651
ttodorov 12:d0978272a340 652 unsigned int usedColorFG = fgColor == -1 ? _background : fgColor == -2 ? _foreground : ( unsigned int ) fgColor;
ttodorov 12:d0978272a340 653 unsigned int usedColorBG = bgColor == -1 ? _background : bgColor == -2 ? _foreground : ( unsigned int ) bgColor;
rlanghbv 30:ede1a0a32e04 654
ttodorov 21:e5c1e8ffada1 655 int16_t position = _font->Position[ c - _font->Offset ];
ttodorov 21:e5c1e8ffada1 656 if ( position == -1 ) position = 0; // will print space character
ttodorov 21:e5c1e8ffada1 657
ttodorov 4:3ac4239f6c9c 658 Activate();
ttodorov 21:e5c1e8ffada1 659
ttodorov 21:e5c1e8ffada1 660 for ( j = 0; j < _font->Height; j++ )
ttodorov 0:881ff0b71102 661 {
ttodorov 21:e5c1e8ffada1 662 for ( uint16_t zz = 0; zz < ( ( double ) _font->Width / 8 ); zz++ )
ttodorov 0:881ff0b71102 663 {
ttodorov 21:e5c1e8ffada1 664 ch = _font->Data[ position + zz ];
ttodorov 0:881ff0b71102 665 for ( i = 0; i < 8; i++ )
ttodorov 0:881ff0b71102 666 {
ttodorov 21:e5c1e8ffada1 667 newx = x + ( ( ( i + ( zz * 8 ) + ( pos * _font->Width ) ) * cos( radian ) ) - ( ( j ) * sin( radian ) ) );
ttodorov 21:e5c1e8ffada1 668 newy = y + ( ( ( j ) * cos( radian ) ) + ( ( i + ( zz * 8 ) + ( pos * _font->Width ) ) * sin( radian ) ) );
rlanghbv 30:ede1a0a32e04 669
ttodorov 2:81ed304b7e9b 670 SetXY( newx, newy, newx + 1, newy + 1 );
rlanghbv 30:ede1a0a32e04 671
ttodorov 21:e5c1e8ffada1 672 if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) SetPixelColor( usedColorFG );
ttodorov 21:e5c1e8ffada1 673 else SetPixelColor( usedColorBG );
ttodorov 0:881ff0b71102 674 }
ttodorov 0:881ff0b71102 675 }
ttodorov 21:e5c1e8ffada1 676 position += ( _font->Width / 8 );
ttodorov 0:881ff0b71102 677 }
rlanghbv 30:ede1a0a32e04 678
ttodorov 4:3ac4239f6c9c 679 Deactivate();
rlanghbv 30:ede1a0a32e04 680 }