This is a port of Henning Kralsen's UTFT library for Arduino/chipKIT to mbed, refactored to make full use of C inheritance and access control, in order to reduce work when implementing new drivers and at the same time make the code more readable and easier to maintain. As of now supported are SSD1289 (16-bit interface), HX8340-B (serial interface) and ST7735 (serial interface). Drivers for other controllers will be added as time and resources to acquire the displays to test the code permit.
Fork of TFTLCD by
lcd_base.cpp@3:64a5b67d5b51, 2012-12-02 (annotated)
- Committer:
- ttodorov
- Date:
- Sun Dec 02 01:44:23 2012 +0000
- Revision:
- 3:64a5b67d5b51
- Parent:
- 2:81ed304b7e9b
- Child:
- 4:3ac4239f6c9c
- fixed documentation; - renamed ssd* source files to match the name of the LCD controller
Who changed what in which revision?
User | Revision | Line number | New 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" |
ttodorov | 0:881ff0b71102 | 24 | |
ttodorov | 0:881ff0b71102 | 25 | LCD::LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS ) |
ttodorov | 0:881ff0b71102 | 26 | : _disp_width( width ), _disp_height( height ), _lcd_pin_cs( CS ), _lcd_pin_rs( RS ) |
ttodorov | 0:881ff0b71102 | 27 | {} |
ttodorov | 0:881ff0b71102 | 28 | |
ttodorov | 0:881ff0b71102 | 29 | inline |
ttodorov | 0:881ff0b71102 | 30 | void LCD::SetForeground( unsigned short color ) |
ttodorov | 0:881ff0b71102 | 31 | { |
ttodorov | 0:881ff0b71102 | 32 | _foreground = color; |
ttodorov | 0:881ff0b71102 | 33 | } |
ttodorov | 0:881ff0b71102 | 34 | |
ttodorov | 0:881ff0b71102 | 35 | inline |
ttodorov | 0:881ff0b71102 | 36 | void LCD::SetBackground( unsigned short color ) |
ttodorov | 0:881ff0b71102 | 37 | { |
ttodorov | 0:881ff0b71102 | 38 | _background = color; |
ttodorov | 0:881ff0b71102 | 39 | } |
ttodorov | 0:881ff0b71102 | 40 | |
ttodorov | 0:881ff0b71102 | 41 | void LCD::SetFont( const char *font ) |
ttodorov | 0:881ff0b71102 | 42 | { |
ttodorov | 0:881ff0b71102 | 43 | _font.font = font; |
ttodorov | 0:881ff0b71102 | 44 | _font.width = font[ 0 ]; |
ttodorov | 0:881ff0b71102 | 45 | _font.height = font[ 1 ]; |
ttodorov | 0:881ff0b71102 | 46 | _font.offset = font[ 2 ]; |
ttodorov | 0:881ff0b71102 | 47 | _font.numchars = font[ 3 ]; |
ttodorov | 0:881ff0b71102 | 48 | } |
ttodorov | 0:881ff0b71102 | 49 | |
ttodorov | 0:881ff0b71102 | 50 | inline |
ttodorov | 0:881ff0b71102 | 51 | unsigned short LCD::GetWidth( void ) |
ttodorov | 0:881ff0b71102 | 52 | { |
ttodorov | 0:881ff0b71102 | 53 | if ( _orientation == LANDSCAPE ) return _disp_height; |
ttodorov | 0:881ff0b71102 | 54 | return _disp_width; |
ttodorov | 0:881ff0b71102 | 55 | } |
ttodorov | 0:881ff0b71102 | 56 | |
ttodorov | 0:881ff0b71102 | 57 | inline |
ttodorov | 0:881ff0b71102 | 58 | unsigned short LCD::GetHeight( void ) |
ttodorov | 0:881ff0b71102 | 59 | { |
ttodorov | 0:881ff0b71102 | 60 | if ( _orientation == LANDSCAPE ) return _disp_width; |
ttodorov | 0:881ff0b71102 | 61 | return _disp_height; |
ttodorov | 0:881ff0b71102 | 62 | } |
ttodorov | 0:881ff0b71102 | 63 | |
ttodorov | 0:881ff0b71102 | 64 | void LCD::FillScreen( int color ) |
ttodorov | 0:881ff0b71102 | 65 | { |
ttodorov | 0:881ff0b71102 | 66 | unsigned short rgb = color == -1 ? _background : color == -2 ? _foreground : ( unsigned short ) color; |
ttodorov | 0:881ff0b71102 | 67 | _lcd_pin_cs = LOW; |
ttodorov | 2:81ed304b7e9b | 68 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 69 | _lcd_pin_rs = HIGH; |
ttodorov | 1:14bef43daf6f | 70 | for ( int i = 0; i < ( ( _disp_width ) * ( _disp_height ) ); i++ ) |
ttodorov | 2:81ed304b7e9b | 71 | WriteData( rgb ); |
ttodorov | 0:881ff0b71102 | 72 | _lcd_pin_cs = HIGH; |
ttodorov | 0:881ff0b71102 | 73 | } |
ttodorov | 0:881ff0b71102 | 74 | |
ttodorov | 0:881ff0b71102 | 75 | inline |
ttodorov | 0:881ff0b71102 | 76 | void LCD::ClearScreen( void ) |
ttodorov | 0:881ff0b71102 | 77 | { |
ttodorov | 0:881ff0b71102 | 78 | FillScreen( -1 ); |
ttodorov | 0:881ff0b71102 | 79 | } |
ttodorov | 0:881ff0b71102 | 80 | |
ttodorov | 0:881ff0b71102 | 81 | void LCD::DrawPixel( unsigned short x, unsigned short y, int color ) |
ttodorov | 0:881ff0b71102 | 82 | { |
ttodorov | 0:881ff0b71102 | 83 | _lcd_pin_cs = LOW; |
ttodorov | 2:81ed304b7e9b | 84 | SetXY( x, y, x, y ); |
ttodorov | 2:81ed304b7e9b | 85 | WriteData( color == -1 ? _background : |
ttodorov | 0:881ff0b71102 | 86 | color == -2 ? _foreground : color ); |
ttodorov | 0:881ff0b71102 | 87 | _lcd_pin_cs = HIGH; |
ttodorov | 2:81ed304b7e9b | 88 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 89 | } |
ttodorov | 0:881ff0b71102 | 90 | |
ttodorov | 0:881ff0b71102 | 91 | void LCD::DrawLine( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color ) |
ttodorov | 0:881ff0b71102 | 92 | { |
ttodorov | 0:881ff0b71102 | 93 | |
ttodorov | 0:881ff0b71102 | 94 | double delta, tx, ty; |
ttodorov | 0:881ff0b71102 | 95 | |
ttodorov | 0:881ff0b71102 | 96 | if ( ( ( x2 - x1 ) < 0 ) ) |
ttodorov | 0:881ff0b71102 | 97 | { |
ttodorov | 0:881ff0b71102 | 98 | swap( ushort, x1, x2 ) |
ttodorov | 0:881ff0b71102 | 99 | swap( ushort, y1, y2 ) |
ttodorov | 0:881ff0b71102 | 100 | } |
ttodorov | 0:881ff0b71102 | 101 | if ( ( ( y2 - y1 ) < 0 ) ) |
ttodorov | 0:881ff0b71102 | 102 | { |
ttodorov | 0:881ff0b71102 | 103 | swap( ushort, x1, x2 ) |
ttodorov | 0:881ff0b71102 | 104 | swap( ushort, y1, y2 ) |
ttodorov | 0:881ff0b71102 | 105 | } |
ttodorov | 0:881ff0b71102 | 106 | |
ttodorov | 0:881ff0b71102 | 107 | if ( y1 == y2 ) |
ttodorov | 0:881ff0b71102 | 108 | { |
ttodorov | 0:881ff0b71102 | 109 | if ( x1 > x2 ) |
ttodorov | 0:881ff0b71102 | 110 | swap( ushort, x1, x2 ) |
ttodorov | 2:81ed304b7e9b | 111 | DrawHLine( x1, y1, x2 - x1, color ); |
ttodorov | 0:881ff0b71102 | 112 | } |
ttodorov | 0:881ff0b71102 | 113 | else if ( x1 == x2 ) |
ttodorov | 0:881ff0b71102 | 114 | { |
ttodorov | 0:881ff0b71102 | 115 | if ( y1 > y2 ) |
ttodorov | 0:881ff0b71102 | 116 | swap( ushort, y1, y2 ) |
ttodorov | 2:81ed304b7e9b | 117 | DrawVLine( x1, y1, y2 - y1, color ); |
ttodorov | 0:881ff0b71102 | 118 | } |
ttodorov | 0:881ff0b71102 | 119 | else if ( abs( x2 - x1 ) > abs( y2 - y1 ) ) |
ttodorov | 0:881ff0b71102 | 120 | { |
ttodorov | 0:881ff0b71102 | 121 | unsigned short usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned short ) color; |
ttodorov | 0:881ff0b71102 | 122 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 123 | delta = ( double( y2 - y1 ) / double( x2 - x1 ) ); |
ttodorov | 0:881ff0b71102 | 124 | ty = double( y1 ); |
ttodorov | 0:881ff0b71102 | 125 | if ( x1 > x2 ) |
ttodorov | 0:881ff0b71102 | 126 | { |
ttodorov | 0:881ff0b71102 | 127 | for ( int i = x1; i >= x2; i-- ) |
ttodorov | 0:881ff0b71102 | 128 | { |
ttodorov | 2:81ed304b7e9b | 129 | SetXY( i, int( ty + 0.5 ), i, int( ty + 0.5 ) ); |
ttodorov | 2:81ed304b7e9b | 130 | WriteData( usedColor ); |
ttodorov | 0:881ff0b71102 | 131 | ty = ty - delta; |
ttodorov | 0:881ff0b71102 | 132 | } |
ttodorov | 0:881ff0b71102 | 133 | } |
ttodorov | 0:881ff0b71102 | 134 | else |
ttodorov | 0:881ff0b71102 | 135 | { |
ttodorov | 0:881ff0b71102 | 136 | for ( int i = x1; i <= x2; i++ ) |
ttodorov | 0:881ff0b71102 | 137 | { |
ttodorov | 2:81ed304b7e9b | 138 | SetXY( i, int( ty + 0.5 ), i, int( ty + 0.5 ) ); |
ttodorov | 2:81ed304b7e9b | 139 | WriteData( usedColor ); |
ttodorov | 0:881ff0b71102 | 140 | ty = ty + delta; |
ttodorov | 0:881ff0b71102 | 141 | } |
ttodorov | 0:881ff0b71102 | 142 | } |
ttodorov | 0:881ff0b71102 | 143 | _lcd_pin_cs = HIGH; |
ttodorov | 0:881ff0b71102 | 144 | } |
ttodorov | 0:881ff0b71102 | 145 | else |
ttodorov | 0:881ff0b71102 | 146 | { |
ttodorov | 0:881ff0b71102 | 147 | unsigned short usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned short ) color; |
ttodorov | 0:881ff0b71102 | 148 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 149 | delta = ( float( x2 - x1 ) / float( y2 - y1 ) ); |
ttodorov | 0:881ff0b71102 | 150 | tx = float( x1 ); |
ttodorov | 0:881ff0b71102 | 151 | if ( y1 > y2 ) |
ttodorov | 0:881ff0b71102 | 152 | { |
ttodorov | 0:881ff0b71102 | 153 | for ( int i = y2 + 1; i > y1; i-- ) |
ttodorov | 0:881ff0b71102 | 154 | { |
ttodorov | 2:81ed304b7e9b | 155 | SetXY( int( tx + 0.5 ), i, int( tx + 0.5 ), i ); |
ttodorov | 2:81ed304b7e9b | 156 | WriteData( usedColor ); |
ttodorov | 0:881ff0b71102 | 157 | tx = tx + delta; |
ttodorov | 0:881ff0b71102 | 158 | } |
ttodorov | 0:881ff0b71102 | 159 | } |
ttodorov | 0:881ff0b71102 | 160 | else |
ttodorov | 0:881ff0b71102 | 161 | { |
ttodorov | 0:881ff0b71102 | 162 | for ( int i = y1; i < y2 + 1; i++ ) |
ttodorov | 0:881ff0b71102 | 163 | { |
ttodorov | 2:81ed304b7e9b | 164 | SetXY( int( tx + 0.5 ), i, int( tx + 0.5 ), i ); |
ttodorov | 2:81ed304b7e9b | 165 | WriteData( usedColor ); |
ttodorov | 0:881ff0b71102 | 166 | tx = tx + delta; |
ttodorov | 0:881ff0b71102 | 167 | } |
ttodorov | 0:881ff0b71102 | 168 | } |
ttodorov | 0:881ff0b71102 | 169 | _lcd_pin_cs = HIGH; |
ttodorov | 0:881ff0b71102 | 170 | } |
ttodorov | 0:881ff0b71102 | 171 | |
ttodorov | 2:81ed304b7e9b | 172 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 173 | } |
ttodorov | 0:881ff0b71102 | 174 | |
ttodorov | 0:881ff0b71102 | 175 | void LCD::DrawRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color ) |
ttodorov | 0:881ff0b71102 | 176 | { |
ttodorov | 0:881ff0b71102 | 177 | if ( x1 > x2 ) swap( ushort, x1, x2 ) |
ttodorov | 0:881ff0b71102 | 178 | if ( y1 > y2 ) swap( ushort, y1, y2 ) |
ttodorov | 0:881ff0b71102 | 179 | |
ttodorov | 2:81ed304b7e9b | 180 | DrawHLine( x1, y1, x2 - x1, color ); |
ttodorov | 2:81ed304b7e9b | 181 | DrawHLine( x1, y2, x2 - x1, color ); |
ttodorov | 2:81ed304b7e9b | 182 | DrawVLine( x1, y1, y2 - y1, color ); |
ttodorov | 2:81ed304b7e9b | 183 | DrawVLine( x2, y1, y2 - y1, color ); |
ttodorov | 0:881ff0b71102 | 184 | } |
ttodorov | 0:881ff0b71102 | 185 | |
ttodorov | 0:881ff0b71102 | 186 | void LCD::DrawRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color ) |
ttodorov | 0:881ff0b71102 | 187 | { |
ttodorov | 0:881ff0b71102 | 188 | if ( x1 > x2 ) swap( ushort, x1, x2 ) |
ttodorov | 0:881ff0b71102 | 189 | if ( y1 > y2 ) swap( ushort, y1, y2 ) |
ttodorov | 0:881ff0b71102 | 190 | |
ttodorov | 0:881ff0b71102 | 191 | if ( ( x2 - x1 ) > 4 && ( y2 - y1 ) > 4 ) |
ttodorov | 0:881ff0b71102 | 192 | { |
ttodorov | 0:881ff0b71102 | 193 | DrawPixel( x1 + 1, y1 + 1, color ); |
ttodorov | 0:881ff0b71102 | 194 | DrawPixel( x2 - 1, y1 + 1, color ); |
ttodorov | 0:881ff0b71102 | 195 | DrawPixel( x1 + 1, y2 - 1, color ); |
ttodorov | 0:881ff0b71102 | 196 | DrawPixel( x2 - 1, y2 - 1, color ); |
ttodorov | 2:81ed304b7e9b | 197 | DrawHLine( x1 + 2, y1, x2 - x1 - 4, color ); |
ttodorov | 2:81ed304b7e9b | 198 | DrawHLine( x1 + 2, y2, x2 - x1 - 4, color ); |
ttodorov | 2:81ed304b7e9b | 199 | DrawVLine( x1, y1 + 2, y2 - y1 - 4, color ); |
ttodorov | 2:81ed304b7e9b | 200 | DrawVLine( x2, y1 + 2, y2 - y1 - 4, color ); |
ttodorov | 0:881ff0b71102 | 201 | } |
ttodorov | 0:881ff0b71102 | 202 | } |
ttodorov | 0:881ff0b71102 | 203 | |
ttodorov | 0:881ff0b71102 | 204 | void LCD::FillRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color ) |
ttodorov | 0:881ff0b71102 | 205 | { |
ttodorov | 0:881ff0b71102 | 206 | if ( x1 > x2 ) swap( ushort, x1, x2 ); |
ttodorov | 0:881ff0b71102 | 207 | if ( y1 > y2 ) swap( ushort, y1, y2 ); |
ttodorov | 0:881ff0b71102 | 208 | |
ttodorov | 0:881ff0b71102 | 209 | if ( _orientation == PORTRAIT ) |
ttodorov | 0:881ff0b71102 | 210 | { |
ttodorov | 0:881ff0b71102 | 211 | for ( int i = 0; i < ( ( y2 - y1 ) / 2 ) + 1; i++ ) |
ttodorov | 0:881ff0b71102 | 212 | { |
ttodorov | 2:81ed304b7e9b | 213 | DrawHLine( x1, y1 + i, x2 - x1, color ); |
ttodorov | 2:81ed304b7e9b | 214 | DrawHLine( x1, y2 - i, x2 - x1, color ); |
ttodorov | 0:881ff0b71102 | 215 | } |
ttodorov | 0:881ff0b71102 | 216 | } |
ttodorov | 0:881ff0b71102 | 217 | else |
ttodorov | 0:881ff0b71102 | 218 | { |
ttodorov | 0:881ff0b71102 | 219 | for ( int i = 0; i < ( ( x2 - x1 ) / 2 ) + 1; i++ ) |
ttodorov | 0:881ff0b71102 | 220 | { |
ttodorov | 2:81ed304b7e9b | 221 | DrawVLine( x1 + i, y1, y2 - y1, color ); |
ttodorov | 2:81ed304b7e9b | 222 | DrawVLine( x2 - i, y1, y2 - y1, color ); |
ttodorov | 0:881ff0b71102 | 223 | } |
ttodorov | 0:881ff0b71102 | 224 | } |
ttodorov | 0:881ff0b71102 | 225 | } |
ttodorov | 0:881ff0b71102 | 226 | |
ttodorov | 0:881ff0b71102 | 227 | void LCD::FillRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color ) |
ttodorov | 0:881ff0b71102 | 228 | { |
ttodorov | 0:881ff0b71102 | 229 | if ( x1 > x2 ) swap( ushort, x1, x2 ) |
ttodorov | 0:881ff0b71102 | 230 | if ( y1 > y2 ) swap( ushort, y1, y2 ) |
ttodorov | 0:881ff0b71102 | 231 | |
ttodorov | 0:881ff0b71102 | 232 | if ( ( x2 - x1 ) > 4 && ( y2 - y1 ) > 4 ) |
ttodorov | 0:881ff0b71102 | 233 | { |
ttodorov | 0:881ff0b71102 | 234 | for ( int i = 0; i < ( ( y2 - y1 ) / 2 ) + 1; i++ ) |
ttodorov | 0:881ff0b71102 | 235 | { |
ttodorov | 0:881ff0b71102 | 236 | switch ( i ) |
ttodorov | 0:881ff0b71102 | 237 | { |
ttodorov | 0:881ff0b71102 | 238 | case 0: |
ttodorov | 2:81ed304b7e9b | 239 | DrawHLine( x1 + 2, y1 + i, x2 - x1 - 4, color ); |
ttodorov | 2:81ed304b7e9b | 240 | DrawHLine( x1 + 2, y2 - i, x2 - x1 - 4, color ); |
ttodorov | 0:881ff0b71102 | 241 | break; |
ttodorov | 0:881ff0b71102 | 242 | |
ttodorov | 0:881ff0b71102 | 243 | case 1: |
ttodorov | 2:81ed304b7e9b | 244 | DrawHLine( x1 + 1, y1 + i, x2 - x1 - 2, color ); |
ttodorov | 2:81ed304b7e9b | 245 | DrawHLine( x1 + 1, y2 - i, x2 - x1 - 2, color ); |
ttodorov | 0:881ff0b71102 | 246 | break; |
ttodorov | 0:881ff0b71102 | 247 | |
ttodorov | 0:881ff0b71102 | 248 | default: |
ttodorov | 2:81ed304b7e9b | 249 | DrawHLine( x1, y1 + i, x2 - x1, color ); |
ttodorov | 2:81ed304b7e9b | 250 | DrawHLine( x1, y2 - i, x2 - x1, color ); |
ttodorov | 0:881ff0b71102 | 251 | break; |
ttodorov | 0:881ff0b71102 | 252 | } |
ttodorov | 0:881ff0b71102 | 253 | } |
ttodorov | 0:881ff0b71102 | 254 | } |
ttodorov | 0:881ff0b71102 | 255 | } |
ttodorov | 0:881ff0b71102 | 256 | |
ttodorov | 0:881ff0b71102 | 257 | void LCD::DrawCircle( unsigned short x, unsigned short y, unsigned short radius, int color ) |
ttodorov | 0:881ff0b71102 | 258 | { |
ttodorov | 0:881ff0b71102 | 259 | int f = 1 - radius; |
ttodorov | 0:881ff0b71102 | 260 | int ddF_x = 1; |
ttodorov | 0:881ff0b71102 | 261 | int ddF_y = -2 * radius; |
ttodorov | 0:881ff0b71102 | 262 | int x1 = 0; |
ttodorov | 0:881ff0b71102 | 263 | int y1 = radius; |
ttodorov | 0:881ff0b71102 | 264 | unsigned short usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned short ) color; |
ttodorov | 0:881ff0b71102 | 265 | |
ttodorov | 0:881ff0b71102 | 266 | _lcd_pin_cs = LOW; |
ttodorov | 2:81ed304b7e9b | 267 | SetXY( x, y + radius, x, y + radius ); |
ttodorov | 2:81ed304b7e9b | 268 | WriteData( usedColor ); |
ttodorov | 2:81ed304b7e9b | 269 | SetXY( x, y - radius, x, y - radius ); |
ttodorov | 2:81ed304b7e9b | 270 | WriteData( usedColor ); |
ttodorov | 2:81ed304b7e9b | 271 | SetXY( x + radius, y, x + radius, y ); |
ttodorov | 2:81ed304b7e9b | 272 | WriteData( usedColor ); |
ttodorov | 2:81ed304b7e9b | 273 | SetXY( x - radius, y, x - radius, y ); |
ttodorov | 2:81ed304b7e9b | 274 | WriteData( usedColor ); |
ttodorov | 0:881ff0b71102 | 275 | |
ttodorov | 0:881ff0b71102 | 276 | while ( x1 < y1 ) |
ttodorov | 0:881ff0b71102 | 277 | { |
ttodorov | 0:881ff0b71102 | 278 | if ( f >= 0 ) |
ttodorov | 0:881ff0b71102 | 279 | { |
ttodorov | 0:881ff0b71102 | 280 | y1--; |
ttodorov | 0:881ff0b71102 | 281 | ddF_y += 2; |
ttodorov | 0:881ff0b71102 | 282 | f += ddF_y; |
ttodorov | 0:881ff0b71102 | 283 | } |
ttodorov | 0:881ff0b71102 | 284 | x1++; |
ttodorov | 0:881ff0b71102 | 285 | ddF_x += 2; |
ttodorov | 0:881ff0b71102 | 286 | f += ddF_x; |
ttodorov | 2:81ed304b7e9b | 287 | SetXY( x + x1, y + y1, x + x1, y + y1 ); |
ttodorov | 2:81ed304b7e9b | 288 | WriteData( usedColor ); |
ttodorov | 2:81ed304b7e9b | 289 | SetXY( x - x1, y + y1, x - x1, y + y1 ); |
ttodorov | 2:81ed304b7e9b | 290 | WriteData( usedColor ); |
ttodorov | 2:81ed304b7e9b | 291 | SetXY( x + x1, y - y1, x + x1, y - y1 ); |
ttodorov | 2:81ed304b7e9b | 292 | WriteData( usedColor ); |
ttodorov | 2:81ed304b7e9b | 293 | SetXY( x - x1, y - y1, x - x1, y - y1 ); |
ttodorov | 2:81ed304b7e9b | 294 | WriteData( usedColor ); |
ttodorov | 2:81ed304b7e9b | 295 | SetXY( x + y1, y + x1, x + y1, y + x1 ); |
ttodorov | 2:81ed304b7e9b | 296 | WriteData( usedColor ); |
ttodorov | 2:81ed304b7e9b | 297 | SetXY( x - y1, y + x1, x - y1, y + x1 ); |
ttodorov | 2:81ed304b7e9b | 298 | WriteData( usedColor ); |
ttodorov | 2:81ed304b7e9b | 299 | SetXY( x + y1, y - x1, x + y1, y - x1 ); |
ttodorov | 2:81ed304b7e9b | 300 | WriteData( usedColor ); |
ttodorov | 2:81ed304b7e9b | 301 | SetXY( x - y1, y - x1, x - y1, y - x1 ); |
ttodorov | 2:81ed304b7e9b | 302 | WriteData( usedColor ); |
ttodorov | 0:881ff0b71102 | 303 | } |
ttodorov | 0:881ff0b71102 | 304 | _lcd_pin_cs = HIGH; |
ttodorov | 2:81ed304b7e9b | 305 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 306 | } |
ttodorov | 0:881ff0b71102 | 307 | |
ttodorov | 0:881ff0b71102 | 308 | void LCD::FillCircle( unsigned short x, unsigned short y, unsigned short radius, int color ) |
ttodorov | 0:881ff0b71102 | 309 | { |
ttodorov | 0:881ff0b71102 | 310 | unsigned short usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned short ) color; |
ttodorov | 0:881ff0b71102 | 311 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 312 | for ( int y1 = -radius; y1 <= radius; y1++ ) |
ttodorov | 0:881ff0b71102 | 313 | for ( int x1 = -radius; x1 <= radius; x1++ ) |
ttodorov | 0:881ff0b71102 | 314 | if ( x1 * x1 + y1 * y1 <= radius * radius ) |
ttodorov | 0:881ff0b71102 | 315 | { |
ttodorov | 2:81ed304b7e9b | 316 | SetXY( x + x1, y + y1, x + x1, y + y1 ); |
ttodorov | 2:81ed304b7e9b | 317 | WriteData( usedColor ); |
ttodorov | 0:881ff0b71102 | 318 | } |
ttodorov | 0:881ff0b71102 | 319 | _lcd_pin_cs = HIGH; |
ttodorov | 2:81ed304b7e9b | 320 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 321 | } |
ttodorov | 0:881ff0b71102 | 322 | |
ttodorov | 0:881ff0b71102 | 323 | void LCD::Print( const char *str, unsigned short x, unsigned short y, int fgColor, int bgColor, unsigned short deg ) |
ttodorov | 0:881ff0b71102 | 324 | { |
ttodorov | 0:881ff0b71102 | 325 | int stl, i; |
ttodorov | 0:881ff0b71102 | 326 | |
ttodorov | 0:881ff0b71102 | 327 | stl = strlen( str ); |
ttodorov | 0:881ff0b71102 | 328 | |
ttodorov | 0:881ff0b71102 | 329 | if ( _orientation == PORTRAIT ) |
ttodorov | 0:881ff0b71102 | 330 | { |
ttodorov | 0:881ff0b71102 | 331 | if ( x == RIGHT ) |
ttodorov | 1:14bef43daf6f | 332 | x = _disp_width - ( stl * _font.width ); |
ttodorov | 0:881ff0b71102 | 333 | if ( x == CENTER ) |
ttodorov | 1:14bef43daf6f | 334 | x = ( _disp_width - ( stl * _font.width ) ) / 2; |
ttodorov | 0:881ff0b71102 | 335 | } |
ttodorov | 0:881ff0b71102 | 336 | else |
ttodorov | 0:881ff0b71102 | 337 | { |
ttodorov | 0:881ff0b71102 | 338 | if ( x == RIGHT ) |
ttodorov | 1:14bef43daf6f | 339 | x = _disp_height - ( stl * _font.width ); |
ttodorov | 0:881ff0b71102 | 340 | if ( x == CENTER ) |
ttodorov | 1:14bef43daf6f | 341 | x = ( _disp_height - ( stl * _font.width ) ) / 2; |
ttodorov | 0:881ff0b71102 | 342 | } |
ttodorov | 0:881ff0b71102 | 343 | |
ttodorov | 0:881ff0b71102 | 344 | for ( i = 0; i < stl; i++ ) |
ttodorov | 0:881ff0b71102 | 345 | if ( deg == 0 ) |
ttodorov | 2:81ed304b7e9b | 346 | PrintChar( *str++, x + ( i * ( _font.width ) ), y, fgColor, bgColor ); |
ttodorov | 0:881ff0b71102 | 347 | else |
ttodorov | 2:81ed304b7e9b | 348 | RotateChar( *str++, x, y, i, fgColor, bgColor, deg ); |
ttodorov | 0:881ff0b71102 | 349 | } |
ttodorov | 0:881ff0b71102 | 350 | |
ttodorov | 0:881ff0b71102 | 351 | void LCD::DrawBitmap( unsigned short x, unsigned short y, unsigned short sx, unsigned short sy, bitmap_t data, unsigned char scale ) |
ttodorov | 0:881ff0b71102 | 352 | { |
ttodorov | 0:881ff0b71102 | 353 | int tx, ty, tc, tsx, tsy; |
ttodorov | 0:881ff0b71102 | 354 | |
ttodorov | 0:881ff0b71102 | 355 | if ( scale == 1 ) |
ttodorov | 0:881ff0b71102 | 356 | { |
ttodorov | 0:881ff0b71102 | 357 | if ( _orientation == PORTRAIT ) |
ttodorov | 0:881ff0b71102 | 358 | { |
ttodorov | 0:881ff0b71102 | 359 | _lcd_pin_cs = LOW; |
ttodorov | 2:81ed304b7e9b | 360 | SetXY( x, y, x + sx - 1, y + sy - 1 ); |
ttodorov | 0:881ff0b71102 | 361 | for ( tc = 0; tc < ( sx * sy ); tc++ ) |
ttodorov | 2:81ed304b7e9b | 362 | WriteData( data[ tc ] ); |
ttodorov | 0:881ff0b71102 | 363 | _lcd_pin_cs = HIGH; |
ttodorov | 0:881ff0b71102 | 364 | } |
ttodorov | 0:881ff0b71102 | 365 | else |
ttodorov | 0:881ff0b71102 | 366 | { |
ttodorov | 0:881ff0b71102 | 367 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 368 | for ( ty = 0; ty < sy; ty++ ) |
ttodorov | 0:881ff0b71102 | 369 | { |
ttodorov | 2:81ed304b7e9b | 370 | SetXY( x, y + ty, x + sx - 1, y + ty ); |
ttodorov | 0:881ff0b71102 | 371 | for ( tx = sx; tx >= 0; tx-- ) |
ttodorov | 2:81ed304b7e9b | 372 | WriteData( data[ ( ty * sx ) + tx ] ); |
ttodorov | 0:881ff0b71102 | 373 | } |
ttodorov | 0:881ff0b71102 | 374 | _lcd_pin_cs = HIGH; |
ttodorov | 0:881ff0b71102 | 375 | } |
ttodorov | 0:881ff0b71102 | 376 | } |
ttodorov | 0:881ff0b71102 | 377 | else |
ttodorov | 0:881ff0b71102 | 378 | { |
ttodorov | 0:881ff0b71102 | 379 | if ( _orientation == PORTRAIT ) |
ttodorov | 0:881ff0b71102 | 380 | { |
ttodorov | 0:881ff0b71102 | 381 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 382 | for ( ty = 0; ty < sy; ty++ ) |
ttodorov | 0:881ff0b71102 | 383 | { |
ttodorov | 2:81ed304b7e9b | 384 | SetXY( x, y + ( ty * scale ), x + ( ( sx * scale ) - 1 ), y + ( ty * scale ) + scale ); |
ttodorov | 0:881ff0b71102 | 385 | for ( tsy = 0; tsy < scale; tsy++ ) |
ttodorov | 0:881ff0b71102 | 386 | for ( tx = 0; tx < sx; tx++ ) |
ttodorov | 0:881ff0b71102 | 387 | for ( tsx = 0; tsx < scale; tsx++ ) |
ttodorov | 2:81ed304b7e9b | 388 | WriteData( data[ ( ty * sx ) + tx ] ); |
ttodorov | 0:881ff0b71102 | 389 | } |
ttodorov | 0:881ff0b71102 | 390 | _lcd_pin_cs = HIGH; |
ttodorov | 0:881ff0b71102 | 391 | } |
ttodorov | 0:881ff0b71102 | 392 | else |
ttodorov | 0:881ff0b71102 | 393 | { |
ttodorov | 0:881ff0b71102 | 394 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 395 | for ( ty = 0; ty < sy; ty++ ) |
ttodorov | 0:881ff0b71102 | 396 | { |
ttodorov | 0:881ff0b71102 | 397 | for ( tsy = 0; tsy < scale; tsy++ ) |
ttodorov | 0:881ff0b71102 | 398 | { |
ttodorov | 2:81ed304b7e9b | 399 | SetXY( x, y + ( ty * scale ) + tsy, x + ( ( sx * scale ) - 1 ), y + ( ty * scale ) + tsy ); |
ttodorov | 0:881ff0b71102 | 400 | for ( tx = sx; tx >= 0; tx-- ) |
ttodorov | 0:881ff0b71102 | 401 | for ( tsx = 0; tsx < scale; tsx++ ) |
ttodorov | 2:81ed304b7e9b | 402 | WriteData( data[ ( ty * sx ) + tx ] ); |
ttodorov | 0:881ff0b71102 | 403 | } |
ttodorov | 0:881ff0b71102 | 404 | } |
ttodorov | 0:881ff0b71102 | 405 | _lcd_pin_cs = HIGH; |
ttodorov | 0:881ff0b71102 | 406 | } |
ttodorov | 0:881ff0b71102 | 407 | } |
ttodorov | 2:81ed304b7e9b | 408 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 409 | } |
ttodorov | 0:881ff0b71102 | 410 | |
ttodorov | 0:881ff0b71102 | 411 | void LCD::DrawBitmap( unsigned short x, unsigned short y, unsigned short sx, unsigned short sy, bitmap_t data, unsigned short deg, unsigned short rox, unsigned short roy ) |
ttodorov | 0:881ff0b71102 | 412 | { |
ttodorov | 0:881ff0b71102 | 413 | int tx, ty, newx, newy; |
ttodorov | 0:881ff0b71102 | 414 | double radian; |
ttodorov | 0:881ff0b71102 | 415 | radian = deg * 0.0175; |
ttodorov | 0:881ff0b71102 | 416 | |
ttodorov | 0:881ff0b71102 | 417 | if ( deg == 0 ) |
ttodorov | 0:881ff0b71102 | 418 | DrawBitmap( x, y, sx, sy, data ); |
ttodorov | 0:881ff0b71102 | 419 | else |
ttodorov | 0:881ff0b71102 | 420 | { |
ttodorov | 0:881ff0b71102 | 421 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 422 | for ( ty = 0; ty < sy; ty++ ) |
ttodorov | 0:881ff0b71102 | 423 | for ( tx = 0; tx < sx; tx++ ) |
ttodorov | 0:881ff0b71102 | 424 | { |
ttodorov | 0:881ff0b71102 | 425 | newx = x + rox + ( ( ( tx - rox ) * cos( radian ) ) - ( ( ty - roy ) * sin( radian ) ) ); |
ttodorov | 0:881ff0b71102 | 426 | newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) ); |
ttodorov | 0:881ff0b71102 | 427 | |
ttodorov | 2:81ed304b7e9b | 428 | SetXY( newx, newy, newx, newy ); |
ttodorov | 2:81ed304b7e9b | 429 | WriteData( data[ ( ty * sx ) + tx ] ); |
ttodorov | 0:881ff0b71102 | 430 | } |
ttodorov | 0:881ff0b71102 | 431 | _lcd_pin_cs = HIGH; |
ttodorov | 0:881ff0b71102 | 432 | } |
ttodorov | 2:81ed304b7e9b | 433 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 434 | } |
ttodorov | 0:881ff0b71102 | 435 | |
ttodorov | 0:881ff0b71102 | 436 | /* |
ttodorov | 0:881ff0b71102 | 437 | void LCD::writeCmd( unsigned short cmd ) |
ttodorov | 0:881ff0b71102 | 438 | { |
ttodorov | 0:881ff0b71102 | 439 | _lcd_pin_rs = LOW; |
ttodorov | 0:881ff0b71102 | 440 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 441 | _lcd_port->write( cmd ); |
ttodorov | 0:881ff0b71102 | 442 | pulseLow( _lcd_pin_wr ); |
ttodorov | 0:881ff0b71102 | 443 | _lcd_pin_cs = HIGH; |
ttodorov | 0:881ff0b71102 | 444 | } |
ttodorov | 0:881ff0b71102 | 445 | */ |
ttodorov | 0:881ff0b71102 | 446 | |
ttodorov | 0:881ff0b71102 | 447 | /* |
ttodorov | 0:881ff0b71102 | 448 | void LCD::writeData( unsigned short data ) |
ttodorov | 0:881ff0b71102 | 449 | { |
ttodorov | 0:881ff0b71102 | 450 | _lcd_pin_rs = HIGH; |
ttodorov | 0:881ff0b71102 | 451 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 452 | _lcd_port->write( data ); |
ttodorov | 0:881ff0b71102 | 453 | pulseLow( _lcd_pin_wr ); |
ttodorov | 0:881ff0b71102 | 454 | _lcd_pin_cs = HIGH; |
ttodorov | 0:881ff0b71102 | 455 | } |
ttodorov | 0:881ff0b71102 | 456 | */ |
ttodorov | 0:881ff0b71102 | 457 | |
ttodorov | 0:881ff0b71102 | 458 | inline |
ttodorov | 2:81ed304b7e9b | 459 | void LCD::WriteCmdData( unsigned short cmd, unsigned short data ) |
ttodorov | 0:881ff0b71102 | 460 | { |
ttodorov | 2:81ed304b7e9b | 461 | WriteCmd( cmd ); |
ttodorov | 2:81ed304b7e9b | 462 | WriteData( data ); |
ttodorov | 0:881ff0b71102 | 463 | } |
ttodorov | 0:881ff0b71102 | 464 | |
ttodorov | 0:881ff0b71102 | 465 | /* |
ttodorov | 0:881ff0b71102 | 466 | void LCD::setXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ) |
ttodorov | 0:881ff0b71102 | 467 | { |
ttodorov | 0:881ff0b71102 | 468 | if ( _orientation == LANDSCAPE ) |
ttodorov | 0:881ff0b71102 | 469 | { |
ttodorov | 0:881ff0b71102 | 470 | swap( uint16_t, x1, y1 ) |
ttodorov | 0:881ff0b71102 | 471 | swap( uint16_t, x2, y2 ) |
ttodorov | 0:881ff0b71102 | 472 | y1 = _disp_height - y1; |
ttodorov | 0:881ff0b71102 | 473 | y2 = _disp_height - y2; |
ttodorov | 0:881ff0b71102 | 474 | swap( uint16_t, y1, y2 ) |
ttodorov | 0:881ff0b71102 | 475 | } |
ttodorov | 0:881ff0b71102 | 476 | |
ttodorov | 0:881ff0b71102 | 477 | writeCmdData( 0x44, ( x2 << 8 ) + x1 ); |
ttodorov | 0:881ff0b71102 | 478 | writeCmdData( 0x45, y1 ); |
ttodorov | 0:881ff0b71102 | 479 | writeCmdData( 0x46, y2 ); |
ttodorov | 0:881ff0b71102 | 480 | writeCmdData( 0x4e, x1 ); |
ttodorov | 0:881ff0b71102 | 481 | writeCmdData( 0x4f, y1 ); |
ttodorov | 0:881ff0b71102 | 482 | writeCmd( 0x22 ); |
ttodorov | 0:881ff0b71102 | 483 | } |
ttodorov | 0:881ff0b71102 | 484 | */ |
ttodorov | 0:881ff0b71102 | 485 | |
ttodorov | 2:81ed304b7e9b | 486 | void LCD::ClearXY() |
ttodorov | 0:881ff0b71102 | 487 | { |
ttodorov | 0:881ff0b71102 | 488 | if ( _orientation == PORTRAIT ) |
ttodorov | 2:81ed304b7e9b | 489 | SetXY( 0, 0, _disp_width - 1, _disp_height - 1 ); |
ttodorov | 0:881ff0b71102 | 490 | else |
ttodorov | 2:81ed304b7e9b | 491 | SetXY( 0, 0, _disp_height - 1, _disp_width - 1 ); |
ttodorov | 0:881ff0b71102 | 492 | } |
ttodorov | 0:881ff0b71102 | 493 | |
ttodorov | 2:81ed304b7e9b | 494 | void LCD::DrawHLine( unsigned short x, unsigned short y, unsigned short len, int color ) |
ttodorov | 0:881ff0b71102 | 495 | { |
ttodorov | 0:881ff0b71102 | 496 | unsigned short usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned short ) color; |
ttodorov | 0:881ff0b71102 | 497 | |
ttodorov | 0:881ff0b71102 | 498 | _lcd_pin_cs = LOW; |
ttodorov | 2:81ed304b7e9b | 499 | SetXY( x, y, x + len, y ); |
ttodorov | 0:881ff0b71102 | 500 | for ( int i = 0; i < len + 1; i++ ) |
ttodorov | 2:81ed304b7e9b | 501 | WriteData( usedColor ); |
ttodorov | 0:881ff0b71102 | 502 | _lcd_pin_cs = HIGH; |
ttodorov | 2:81ed304b7e9b | 503 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 504 | } |
ttodorov | 0:881ff0b71102 | 505 | |
ttodorov | 2:81ed304b7e9b | 506 | void LCD::DrawVLine( unsigned short x, unsigned short y, unsigned short len, int color ) |
ttodorov | 0:881ff0b71102 | 507 | { |
ttodorov | 0:881ff0b71102 | 508 | unsigned short usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned short ) color; |
ttodorov | 0:881ff0b71102 | 509 | |
ttodorov | 0:881ff0b71102 | 510 | _lcd_pin_cs = LOW; |
ttodorov | 2:81ed304b7e9b | 511 | SetXY( x, y, x, y + len ); |
ttodorov | 0:881ff0b71102 | 512 | for ( int i = 0; i < len; i++ ) |
ttodorov | 2:81ed304b7e9b | 513 | WriteData( usedColor ); |
ttodorov | 0:881ff0b71102 | 514 | _lcd_pin_cs = HIGH; |
ttodorov | 2:81ed304b7e9b | 515 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 516 | } |
ttodorov | 0:881ff0b71102 | 517 | |
ttodorov | 2:81ed304b7e9b | 518 | void LCD::PrintChar( char c, unsigned short x, unsigned short y, int fgColor, int bgColor ) |
ttodorov | 0:881ff0b71102 | 519 | { |
ttodorov | 0:881ff0b71102 | 520 | uint8_t i, ch; |
ttodorov | 0:881ff0b71102 | 521 | uint16_t j; |
ttodorov | 0:881ff0b71102 | 522 | uint16_t temp; |
ttodorov | 0:881ff0b71102 | 523 | unsigned short usedColorFG = fgColor == -1 ? _background : fgColor == -2 ? _foreground : ( unsigned short ) fgColor; |
ttodorov | 0:881ff0b71102 | 524 | unsigned short usedColorBG = bgColor == -1 ? _background : bgColor == -2 ? _foreground : ( unsigned short ) bgColor; |
ttodorov | 0:881ff0b71102 | 525 | |
ttodorov | 0:881ff0b71102 | 526 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 527 | |
ttodorov | 0:881ff0b71102 | 528 | if ( _orientation == PORTRAIT ) |
ttodorov | 0:881ff0b71102 | 529 | { |
ttodorov | 2:81ed304b7e9b | 530 | SetXY( x, y, x + _font.width - 1, y + _font.height - 1 ); |
ttodorov | 0:881ff0b71102 | 531 | |
ttodorov | 0:881ff0b71102 | 532 | temp = ( ( c - _font.offset ) * ( ( _font.width / 8 ) * _font.height ) ) + 4; |
ttodorov | 0:881ff0b71102 | 533 | for ( j = 0; j < ( ( _font.width / 8 ) * _font.height ); j++ ) |
ttodorov | 0:881ff0b71102 | 534 | { |
ttodorov | 0:881ff0b71102 | 535 | ch = _font.font[ temp ]; |
ttodorov | 0:881ff0b71102 | 536 | for ( i = 0; i < 8; i++ ) |
ttodorov | 0:881ff0b71102 | 537 | { |
ttodorov | 0:881ff0b71102 | 538 | if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) |
ttodorov | 2:81ed304b7e9b | 539 | WriteData( usedColorFG ); |
ttodorov | 0:881ff0b71102 | 540 | else |
ttodorov | 2:81ed304b7e9b | 541 | WriteData( usedColorBG ); |
ttodorov | 0:881ff0b71102 | 542 | } |
ttodorov | 0:881ff0b71102 | 543 | temp++; |
ttodorov | 0:881ff0b71102 | 544 | } |
ttodorov | 0:881ff0b71102 | 545 | } |
ttodorov | 0:881ff0b71102 | 546 | else |
ttodorov | 0:881ff0b71102 | 547 | { |
ttodorov | 0:881ff0b71102 | 548 | temp = ( ( c - _font.offset ) * ( ( _font.width / 8 ) * _font.height ) ) + 4; |
ttodorov | 0:881ff0b71102 | 549 | |
ttodorov | 0:881ff0b71102 | 550 | for ( j = 0; j < ( ( _font.width / 8 ) * _font.height ); j += ( _font.width / 8 ) ) |
ttodorov | 0:881ff0b71102 | 551 | { |
ttodorov | 2:81ed304b7e9b | 552 | SetXY( x, y + ( j / ( _font.width / 8 ) ), x + _font.width - 1, y + ( j / ( _font.width / 8 ) ) ); |
ttodorov | 0:881ff0b71102 | 553 | for ( int zz = ( _font.width / 8 ) - 1; zz >= 0; zz-- ) |
ttodorov | 0:881ff0b71102 | 554 | { |
ttodorov | 0:881ff0b71102 | 555 | ch = _font.font[ temp + zz ]; |
ttodorov | 0:881ff0b71102 | 556 | for ( i = 0; i < 8; i++ ) |
ttodorov | 0:881ff0b71102 | 557 | { |
ttodorov | 0:881ff0b71102 | 558 | if ( ( ch & ( 1 << i ) ) != 0 ) |
ttodorov | 2:81ed304b7e9b | 559 | WriteData( usedColorFG ); |
ttodorov | 0:881ff0b71102 | 560 | else |
ttodorov | 2:81ed304b7e9b | 561 | WriteData( usedColorBG ); |
ttodorov | 0:881ff0b71102 | 562 | } |
ttodorov | 0:881ff0b71102 | 563 | } |
ttodorov | 0:881ff0b71102 | 564 | temp += ( _font.width / 8 ); |
ttodorov | 0:881ff0b71102 | 565 | } |
ttodorov | 0:881ff0b71102 | 566 | } |
ttodorov | 0:881ff0b71102 | 567 | _lcd_pin_cs = HIGH; |
ttodorov | 2:81ed304b7e9b | 568 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 569 | } |
ttodorov | 0:881ff0b71102 | 570 | |
ttodorov | 2:81ed304b7e9b | 571 | void LCD::RotateChar( char c, unsigned short x, unsigned short y, int pos, int fgColor, int bgColor, unsigned short deg ) |
ttodorov | 0:881ff0b71102 | 572 | { |
ttodorov | 0:881ff0b71102 | 573 | uint8_t i, j, ch; |
ttodorov | 0:881ff0b71102 | 574 | uint16_t temp; |
ttodorov | 0:881ff0b71102 | 575 | int newx, newy; |
ttodorov | 0:881ff0b71102 | 576 | double radian; |
ttodorov | 0:881ff0b71102 | 577 | radian = deg * 0.0175; |
ttodorov | 0:881ff0b71102 | 578 | |
ttodorov | 0:881ff0b71102 | 579 | unsigned short usedColorFG = fgColor == -1 ? _background : fgColor == -2 ? _foreground : ( unsigned short ) fgColor; |
ttodorov | 0:881ff0b71102 | 580 | unsigned short usedColorBG = bgColor == -1 ? _background : bgColor == -2 ? _foreground : ( unsigned short ) bgColor; |
ttodorov | 0:881ff0b71102 | 581 | |
ttodorov | 0:881ff0b71102 | 582 | _lcd_pin_cs = LOW; |
ttodorov | 0:881ff0b71102 | 583 | |
ttodorov | 0:881ff0b71102 | 584 | temp = ( ( c - _font.offset ) * ( ( _font.width / 8 ) * _font.height ) ) + 4; |
ttodorov | 0:881ff0b71102 | 585 | for ( j = 0; j < _font.height; j++ ) |
ttodorov | 0:881ff0b71102 | 586 | { |
ttodorov | 0:881ff0b71102 | 587 | for ( int zz = 0; zz < ( _font.width / 8 ); zz++ ) |
ttodorov | 0:881ff0b71102 | 588 | { |
ttodorov | 0:881ff0b71102 | 589 | ch = _font.font[ temp + zz ]; |
ttodorov | 0:881ff0b71102 | 590 | for ( i = 0; i < 8; i++ ) |
ttodorov | 0:881ff0b71102 | 591 | { |
ttodorov | 0:881ff0b71102 | 592 | newx = x + ( ( ( i + ( zz * 8 ) + ( pos * _font.width ) ) * cos( radian ) ) - ( ( j ) * sin( radian ) ) ); |
ttodorov | 0:881ff0b71102 | 593 | newy = y + ( ( ( j ) * cos( radian ) ) + ( ( i + ( zz * 8 ) + ( pos * _font.width ) ) * sin( radian ) ) ); |
ttodorov | 0:881ff0b71102 | 594 | |
ttodorov | 2:81ed304b7e9b | 595 | SetXY( newx, newy, newx + 1, newy + 1 ); |
ttodorov | 0:881ff0b71102 | 596 | |
ttodorov | 0:881ff0b71102 | 597 | if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) |
ttodorov | 2:81ed304b7e9b | 598 | WriteData( usedColorFG ); |
ttodorov | 0:881ff0b71102 | 599 | else |
ttodorov | 2:81ed304b7e9b | 600 | WriteData( usedColorBG ); |
ttodorov | 0:881ff0b71102 | 601 | } |
ttodorov | 0:881ff0b71102 | 602 | } |
ttodorov | 0:881ff0b71102 | 603 | temp += ( _font.width / 8 ); |
ttodorov | 0:881ff0b71102 | 604 | } |
ttodorov | 0:881ff0b71102 | 605 | _lcd_pin_cs = HIGH; |
ttodorov | 2:81ed304b7e9b | 606 | ClearXY(); |
ttodorov | 0:881ff0b71102 | 607 | } |