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