1st Fork

Dependencies:   mbed QEI DmTftLibrary

Committer:
lex9296
Date:
Tue Feb 15 07:22:09 2022 +0000
Revision:
27:654100855f5c
Parent:
24:9f96fd6764d2
Release "Stabile"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mverdy 20:626b92b70bf7 1 /*
mverdy 20:626b92b70bf7 2 ______ _
mverdy 20:626b92b70bf7 3 / _____) _ | |
mverdy 20:626b92b70bf7 4 ( (____ _____ ____ _| |_ _____ ____| |__
mverdy 20:626b92b70bf7 5 \____ \| ___ | (_ _) ___ |/ ___) _ \
mverdy 20:626b92b70bf7 6 _____) ) ____| | | || |_| ____( (___| | | |
mverdy 20:626b92b70bf7 7 (______/|_____)_|_|_| \__)_____)\____)_| |_|
mverdy 20:626b92b70bf7 8 (C)2016 Semtech
mverdy 20:626b92b70bf7 9
mverdy 20:626b92b70bf7 10 Description: Display driver implementation
mverdy 20:626b92b70bf7 11
mverdy 20:626b92b70bf7 12 Maintainer: Gregory Cristian & Gilbert Menth
mverdy 20:626b92b70bf7 13 */
mverdy 20:626b92b70bf7 14
mverdy 20:626b92b70bf7 15 #include "mbed.h"
mverdy 20:626b92b70bf7 16 #include "Eeprom.h"
mverdy 20:626b92b70bf7 17 #include "DisplayDriver.h"
mverdy 20:626b92b70bf7 18 #include "DmTftIli9341.h"
mverdy 20:626b92b70bf7 19 #include "DmTouch.h"
mverdy 20:626b92b70bf7 20 #include "DmTouchCalibration.h"
mverdy 20:626b92b70bf7 21
mverdy 20:626b92b70bf7 22 //If DISPLAY_INVERT is defined as 1 then the display will be inverted from its native orientation
mverdy 20:626b92b70bf7 23 #define DISPLAY_INVERT 1
mverdy 20:626b92b70bf7 24
mverdy 20:626b92b70bf7 25 #define MAX_GO_STRING 30
mverdy 20:626b92b70bf7 26 #define SPACE_ASCII 0x20
mverdy 20:626b92b70bf7 27 #define FONT_WIDTH 8
mverdy 20:626b92b70bf7 28
mverdy 20:626b92b70bf7 29 // DmTftIli9341( PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk )
mverdy 20:626b92b70bf7 30 // DM_TFT28_105
mverdy 20:626b92b70bf7 31 DmTftIli9341 Tft( D10, D9, D11, D12, D13 );
mverdy 20:626b92b70bf7 32 DmTouch Touch( DmTouch::DM_TFT28_105, D9, D11, D12 );
mverdy 20:626b92b70bf7 33 DmTouchCalibration Calibration = DmTouchCalibration( &Tft, &Touch );
mverdy 20:626b92b70bf7 34
mverdy 20:626b92b70bf7 35 /*
mverdy 20:626b92b70bf7 36 * Used only to define pull-up on the CS lines
mverdy 20:626b92b70bf7 37 */
mverdy 20:626b92b70bf7 38 DigitalInOut CsTouch( D4, PIN_OUTPUT, PullUp, 1 );
mverdy 20:626b92b70bf7 39 DigitalInOut CsDisplay( D10, PIN_OUTPUT, PullUp, 1 );
mverdy 20:626b92b70bf7 40 DigitalInOut CsSDCard( D8, PIN_OUTPUT, PullUp, 1 );
mverdy 20:626b92b70bf7 41 DigitalInOut CsFlash( D6, PIN_OUTPUT, PullUp, 1 );
mverdy 20:626b92b70bf7 42
mverdy 20:626b92b70bf7 43 MenuSettings_t MenuSettings;
mverdy 20:626b92b70bf7 44 char GoTmpString[MAX_GO_STRING];
mverdy 20:626b92b70bf7 45
mverdy 20:626b92b70bf7 46 static int BmpWidth;
mverdy 20:626b92b70bf7 47 static int BmpHeight;
mverdy 20:626b92b70bf7 48 static uint8_t BmpImageoffset;
mverdy 20:626b92b70bf7 49
mverdy 20:626b92b70bf7 50 static bool BmpReadHeader( uint8_t *thisBmp );
mverdy 20:626b92b70bf7 51 static uint16_t Read16( uint8_t *src );
mverdy 20:626b92b70bf7 52 static uint32_t Read32( uint8_t *src );
mverdy 20:626b92b70bf7 53 static void DrawBmpFromFlash( uint8_t *thisBmp, int x, int y );
mverdy 20:626b92b70bf7 54
mverdy 20:626b92b70bf7 55
lex9296 27:654100855f5c 56 void DisplayDriverInit (void) {
lex9296 27:654100855f5c 57 Tft.init();
lex9296 27:654100855f5c 58 Touch.init();
mverdy 20:626b92b70bf7 59
lex9296 27:654100855f5c 60 DisplayDriverCalibrate();
lex9296 27:654100855f5c 61 Tft.clearScreen();
mverdy 20:626b92b70bf7 62
lex9296 27:654100855f5c 63 for (uint8_t i = 0; i < MAX_GO_STRING; i++)
lex9296 27:654100855f5c 64 GoTmpString[i] = SPACE_ASCII;
mverdy 20:626b92b70bf7 65 }
mverdy 20:626b92b70bf7 66
mverdy 20:626b92b70bf7 67 // Calibrates the touch screen
lex9296 27:654100855f5c 68 void DisplayDriverCalibrate (void) {
mverdy 20:626b92b70bf7 69 uint16_t x, y = 0;
mverdy 20:626b92b70bf7 70 bool touched = false;
mverdy 20:626b92b70bf7 71
mverdy 20:626b92b70bf7 72 if( Eeprom.EepromData.MenuSettings.ScreenCalibrated == false )
mverdy 20:626b92b70bf7 73 {
mverdy 20:626b92b70bf7 74 Tft.drawString( 5, 5, "Press and hold on cross" );
mverdy 20:626b92b70bf7 75 Tft.drawString( 5, 25, "until it turns green. " );
mverdy 20:626b92b70bf7 76
mverdy 20:626b92b70bf7 77 Point displayRefPoint[5];
mverdy 20:626b92b70bf7 78 Point touchRefPoint[5];
mverdy 20:626b92b70bf7 79
mverdy 20:626b92b70bf7 80 if( Calibration.getTouchReferencePoints( displayRefPoint, touchRefPoint,\
mverdy 20:626b92b70bf7 81 Tft.width( ), Tft.height( ) ) )
mverdy 20:626b92b70bf7 82 {
mverdy 20:626b92b70bf7 83 CalibrationMatrix calibrationMatrix = \
mverdy 20:626b92b70bf7 84 Calibration.calculateCalibrationMatrix( displayRefPoint, \
mverdy 20:626b92b70bf7 85 touchRefPoint );
mverdy 20:626b92b70bf7 86
mverdy 20:626b92b70bf7 87 Touch.setCalibrationMatrix( calibrationMatrix );
mverdy 20:626b92b70bf7 88 Tft.clearScreen( );
mverdy 20:626b92b70bf7 89 Eeprom.EepromData.MenuSettings.Calibration.a = calibrationMatrix.a;
mverdy 20:626b92b70bf7 90 Eeprom.EepromData.MenuSettings.Calibration.b = calibrationMatrix.b;
mverdy 20:626b92b70bf7 91 Eeprom.EepromData.MenuSettings.Calibration.c = calibrationMatrix.c;
mverdy 20:626b92b70bf7 92 Eeprom.EepromData.MenuSettings.Calibration.d = calibrationMatrix.d;
mverdy 20:626b92b70bf7 93 Eeprom.EepromData.MenuSettings.Calibration.e = calibrationMatrix.e;
mverdy 20:626b92b70bf7 94 Eeprom.EepromData.MenuSettings.Calibration.f = calibrationMatrix.f;
mverdy 20:626b92b70bf7 95 Eeprom.EepromData.MenuSettings.ScreenCalibrated = true;
mverdy 20:626b92b70bf7 96 EepromSaveSettings( SCREEN_DATA );
mverdy 20:626b92b70bf7 97 }
mverdy 20:626b92b70bf7 98 else
mverdy 20:626b92b70bf7 99 {
mverdy 20:626b92b70bf7 100 Tft.clearScreen( );
mverdy 20:626b92b70bf7 101 Tft.drawString( 5, 5, "Calibration failed" );
mverdy 20:626b92b70bf7 102 Tft.drawString( 5, 25, "Please try again." );
lex9296 27:654100855f5c 103 delay( 2000 );
lex9296 24:9f96fd6764d2 104
mverdy 20:626b92b70bf7 105 Tft.clearScreen( );
mverdy 20:626b92b70bf7 106 return;
mverdy 20:626b92b70bf7 107 }
mverdy 20:626b92b70bf7 108 }
mverdy 20:626b92b70bf7 109 else
mverdy 20:626b92b70bf7 110 {
mverdy 20:626b92b70bf7 111 Touch.setCalibrationMatrix( Eeprom.EepromData.MenuSettings.Calibration );
mverdy 20:626b92b70bf7 112 Tft.clearScreen( );
mverdy 20:626b92b70bf7 113 }
mverdy 20:626b92b70bf7 114
mverdy 20:626b92b70bf7 115 if( Touch.isTouched( ) )
mverdy 20:626b92b70bf7 116 {
mverdy 20:626b92b70bf7 117 Touch.readTouchData( x, y, touched );
mverdy 20:626b92b70bf7 118 Calibration.drawCalibPoint( x, y );
mverdy 20:626b92b70bf7 119 }
mverdy 20:626b92b70bf7 120 }
mverdy 20:626b92b70bf7 121
mverdy 20:626b92b70bf7 122 GraphObjectStatus_t GraphObjectDraw( GraphObject_t* goObject, uint8_t* source, \
mverdy 20:626b92b70bf7 123 bool doFill, bool activeTouch)
mverdy 20:626b92b70bf7 124 {
mverdy 20:626b92b70bf7 125 GraphObjectStatus_t status = GO_STATUS_NOERR;
mverdy 20:626b92b70bf7 126 uint8_t maxChar;
mverdy 20:626b92b70bf7 127
mverdy 20:626b92b70bf7 128 if( goObject == NULL )
mverdy 20:626b92b70bf7 129 {
mverdy 20:626b92b70bf7 130 return GO_STATUS_BAD_ARG;
mverdy 20:626b92b70bf7 131 }
mverdy 20:626b92b70bf7 132 if( goObject->Xpos + goObject->Width > SCREEN_WIDTH )
mverdy 20:626b92b70bf7 133 {
mverdy 20:626b92b70bf7 134 return GO_STATUS_BAD_COORD;
mverdy 20:626b92b70bf7 135 }
mverdy 20:626b92b70bf7 136 if( goObject->Ypos + goObject->Height > SCREEN_HEIGHT )
mverdy 20:626b92b70bf7 137 {
mverdy 20:626b92b70bf7 138 return GO_STATUS_BAD_COORD;
mverdy 20:626b92b70bf7 139 }
mverdy 20:626b92b70bf7 140 switch( goObject->Type )
mverdy 20:626b92b70bf7 141 {
mverdy 20:626b92b70bf7 142 case GO_TEXT:
mverdy 20:626b92b70bf7 143 if( source == NULL )
mverdy 20:626b92b70bf7 144 {
mverdy 20:626b92b70bf7 145 status = GO_STATUS_BAD_ARG;
mverdy 20:626b92b70bf7 146 }
mverdy 20:626b92b70bf7 147 else
mverdy 20:626b92b70bf7 148 {
mverdy 20:626b92b70bf7 149 uint8_t i = 0;
mverdy 20:626b92b70bf7 150 uint8_t j = 0;
mverdy 20:626b92b70bf7 151 // max character in the object string
mverdy 20:626b92b70bf7 152 maxChar = goObject->Width / FONT_WIDTH;
mverdy 20:626b92b70bf7 153 Tft.setTextColor( goObject->BackColor, goObject->FrontColor );
mverdy 20:626b92b70bf7 154 for( i = 0; i < maxChar; i++)
mverdy 20:626b92b70bf7 155 {
mverdy 20:626b92b70bf7 156 if( *source != 0 )
mverdy 20:626b92b70bf7 157 {
mverdy 20:626b92b70bf7 158 Tft.drawChar( goObject->Xpos + j, goObject->Ypos, \
mverdy 20:626b92b70bf7 159 ( char )*( source++ ), false );
mverdy 20:626b92b70bf7 160 j += FONT_WIDTH;
mverdy 20:626b92b70bf7 161 }
mverdy 20:626b92b70bf7 162 else
mverdy 20:626b92b70bf7 163 {
mverdy 20:626b92b70bf7 164 Tft.drawChar( goObject->Xpos + ( FONT_WIDTH * i ), \
mverdy 20:626b92b70bf7 165 goObject->Ypos, SPACE_ASCII, false);
mverdy 20:626b92b70bf7 166 }
mverdy 20:626b92b70bf7 167 }
mverdy 20:626b92b70bf7 168 goObject->TouchActive = activeTouch;
mverdy 20:626b92b70bf7 169 }
mverdy 20:626b92b70bf7 170 break;
mverdy 20:626b92b70bf7 171
mverdy 20:626b92b70bf7 172 case GO_RECTANGLE:
mverdy 20:626b92b70bf7 173 Tft.drawRectangle( goObject->Xpos, goObject->Ypos, goObject->Xpos + \
mverdy 20:626b92b70bf7 174 goObject->Width - 1, goObject->Ypos + \
mverdy 20:626b92b70bf7 175 goObject->Height - 1, goObject->FrontColor );
mverdy 20:626b92b70bf7 176 if( doFill )
mverdy 20:626b92b70bf7 177 {
mverdy 20:626b92b70bf7 178 Tft.fillRectangle( goObject->Xpos + 1, goObject->Ypos + 1, \
mverdy 20:626b92b70bf7 179 goObject->Xpos + goObject->Width - 2, \
mverdy 20:626b92b70bf7 180 goObject->Ypos + goObject->Height - 2, \
mverdy 20:626b92b70bf7 181 goObject->FillColor );
mverdy 20:626b92b70bf7 182 }
mverdy 20:626b92b70bf7 183 goObject->TouchActive = activeTouch;
mverdy 20:626b92b70bf7 184 break;
mverdy 20:626b92b70bf7 185
mverdy 20:626b92b70bf7 186 case GO_CIRCLE:
mverdy 20:626b92b70bf7 187 Tft.drawCircle( goObject->Xpos, goObject->Ypos, \
mverdy 20:626b92b70bf7 188 ( goObject->Height < goObject->Width ) ? \
mverdy 20:626b92b70bf7 189 ( goObject->Height / 2 ) : ( goObject->Width / 2 ), \
mverdy 20:626b92b70bf7 190 goObject->FrontColor );
mverdy 20:626b92b70bf7 191 if( doFill )
mverdy 20:626b92b70bf7 192 {
mverdy 20:626b92b70bf7 193 Tft.fillCircle( goObject->Xpos, goObject->Ypos, \
mverdy 20:626b92b70bf7 194 ( goObject->Height < goObject->Width ) ? \
mverdy 20:626b92b70bf7 195 ( goObject->Height / 2 ) - 1 : ( goObject->Width / 2 ) - 1, \
mverdy 20:626b92b70bf7 196 goObject->FillColor );
mverdy 20:626b92b70bf7 197 }
mverdy 20:626b92b70bf7 198 goObject->TouchActive = activeTouch;
mverdy 20:626b92b70bf7 199 break;
mverdy 20:626b92b70bf7 200
mverdy 20:626b92b70bf7 201 case GO_TRIANGLE:
mverdy 20:626b92b70bf7 202 status = GO_STATUS_BAD_ARG;
mverdy 20:626b92b70bf7 203 break;
mverdy 20:626b92b70bf7 204
mverdy 20:626b92b70bf7 205 case GO_IMAGE:
mverdy 20:626b92b70bf7 206 if( source == NULL )
mverdy 20:626b92b70bf7 207 {
mverdy 20:626b92b70bf7 208 status = GO_STATUS_BAD_ARG;
mverdy 20:626b92b70bf7 209 }
mverdy 20:626b92b70bf7 210 else
mverdy 20:626b92b70bf7 211 {
mverdy 20:626b92b70bf7 212 if( BmpReadHeader( goObject->Source ) )
mverdy 20:626b92b70bf7 213 {
mverdy 20:626b92b70bf7 214 DrawBmpFromFlash( goObject->Source, goObject->Xpos, \
mverdy 20:626b92b70bf7 215 goObject->Ypos );
mverdy 20:626b92b70bf7 216 }
mverdy 20:626b92b70bf7 217 else
mverdy 20:626b92b70bf7 218 {
mverdy 20:626b92b70bf7 219 // draw a red rectangle with a line through, to show error
mverdy 20:626b92b70bf7 220 Tft.drawRectangle( goObject->Xpos, goObject->Ypos, \
mverdy 20:626b92b70bf7 221 goObject->Xpos + goObject->Width - 1, \
mverdy 20:626b92b70bf7 222 goObject->Ypos + goObject->Height - 1, \
mverdy 20:626b92b70bf7 223 OBJECT_ERROR );
mverdy 20:626b92b70bf7 224 Tft.drawLine( goObject->Xpos, goObject->Ypos, goObject->Xpos + \
mverdy 20:626b92b70bf7 225 goObject->Width - 1, goObject->Ypos + \
mverdy 20:626b92b70bf7 226 goObject->Height - 1, OBJECT_ERROR );
mverdy 20:626b92b70bf7 227 }
mverdy 20:626b92b70bf7 228 goObject->TouchActive = activeTouch;
mverdy 20:626b92b70bf7 229 }
mverdy 20:626b92b70bf7 230 break;
mverdy 20:626b92b70bf7 231
mverdy 20:626b92b70bf7 232 case GO_LINE:
mverdy 20:626b92b70bf7 233 Tft.drawLine( goObject->Xpos, goObject->Ypos, goObject->Xpos + \
mverdy 20:626b92b70bf7 234 goObject->Width - 1, goObject->Ypos + \
mverdy 20:626b92b70bf7 235 goObject->Height - 1, goObject->FrontColor );
mverdy 20:626b92b70bf7 236 break;
mverdy 20:626b92b70bf7 237
mverdy 20:626b92b70bf7 238 default:
mverdy 20:626b92b70bf7 239 status = GO_STATUS_BAD_ARG;
mverdy 20:626b92b70bf7 240 }
mverdy 20:626b92b70bf7 241 return status;
mverdy 20:626b92b70bf7 242 }
mverdy 20:626b92b70bf7 243
mverdy 20:626b92b70bf7 244 GraphObjectStatus_t GraphObjectClear( GraphObject_t* goObject, bool doFill )
mverdy 20:626b92b70bf7 245 {
mverdy 20:626b92b70bf7 246 GraphObjectStatus_t status = GO_STATUS_NOERR;
mverdy 20:626b92b70bf7 247 uint8_t maxChar;
mverdy 20:626b92b70bf7 248
mverdy 20:626b92b70bf7 249 if( goObject == NULL )
mverdy 20:626b92b70bf7 250 {
mverdy 20:626b92b70bf7 251 return GO_STATUS_BAD_ARG;
mverdy 20:626b92b70bf7 252 }
mverdy 20:626b92b70bf7 253 if( goObject->Xpos + goObject->Width > SCREEN_WIDTH )
mverdy 20:626b92b70bf7 254 {
mverdy 20:626b92b70bf7 255 return GO_STATUS_BAD_COORD;
mverdy 20:626b92b70bf7 256 }
mverdy 20:626b92b70bf7 257 if( goObject->Ypos + goObject->Height > SCREEN_HEIGHT )
mverdy 20:626b92b70bf7 258 {
mverdy 20:626b92b70bf7 259 return GO_STATUS_BAD_COORD;
mverdy 20:626b92b70bf7 260 }
mverdy 20:626b92b70bf7 261 switch( goObject->Type )
mverdy 20:626b92b70bf7 262 {
mverdy 20:626b92b70bf7 263 case GO_TEXT:
mverdy 20:626b92b70bf7 264 // max character in the object string
mverdy 20:626b92b70bf7 265 maxChar = goObject->Width / FONT_WIDTH;
mverdy 20:626b92b70bf7 266 GoTmpString[maxChar] = NULL;
mverdy 20:626b92b70bf7 267 Tft.setTextColor( goObject->BackColor, goObject->FrontColor );
mverdy 20:626b92b70bf7 268 Tft.drawString( goObject->Xpos, goObject->Ypos, GoTmpString );
mverdy 20:626b92b70bf7 269 GoTmpString[maxChar] = SPACE_ASCII;
mverdy 20:626b92b70bf7 270 goObject->TouchActive = false;
mverdy 20:626b92b70bf7 271 break;
mverdy 20:626b92b70bf7 272
mverdy 20:626b92b70bf7 273 case GO_RECTANGLE:
mverdy 20:626b92b70bf7 274 case GO_IMAGE:
mverdy 20:626b92b70bf7 275 if( doFill )
mverdy 20:626b92b70bf7 276 {
mverdy 20:626b92b70bf7 277 Tft.fillRectangle( goObject->Xpos, goObject->Ypos, \
mverdy 20:626b92b70bf7 278 goObject->Xpos + goObject->Width - 1, \
mverdy 20:626b92b70bf7 279 goObject->Ypos + goObject->Height - 1, \
mverdy 20:626b92b70bf7 280 goObject->BackColor );
mverdy 20:626b92b70bf7 281 }
mverdy 20:626b92b70bf7 282 else
mverdy 20:626b92b70bf7 283 {
mverdy 20:626b92b70bf7 284 Tft.drawRectangle( goObject->Xpos, goObject->Ypos, goObject->Xpos + \
mverdy 20:626b92b70bf7 285 goObject->Width - 1, goObject->Ypos + \
mverdy 20:626b92b70bf7 286 goObject->Height - 1, goObject->BackColor );
mverdy 20:626b92b70bf7 287 }
mverdy 20:626b92b70bf7 288 goObject->TouchActive = false;
mverdy 20:626b92b70bf7 289 break;
mverdy 20:626b92b70bf7 290
mverdy 20:626b92b70bf7 291 case GO_CIRCLE:
mverdy 20:626b92b70bf7 292 if( doFill )
mverdy 20:626b92b70bf7 293 {
mverdy 20:626b92b70bf7 294 Tft.fillCircle( goObject->Xpos, goObject->Ypos, \
mverdy 20:626b92b70bf7 295 ( goObject->Height < goObject->Width ) ? \
mverdy 20:626b92b70bf7 296 ( goObject->Height / 2 ) : ( goObject->Width / 2 ), \
mverdy 20:626b92b70bf7 297 goObject->BackColor );
mverdy 20:626b92b70bf7 298 }
mverdy 20:626b92b70bf7 299 else
mverdy 20:626b92b70bf7 300 {
mverdy 20:626b92b70bf7 301 Tft.drawCircle( goObject->Xpos, goObject->Ypos, \
mverdy 20:626b92b70bf7 302 ( goObject->Height < goObject->Width ) ? \
mverdy 20:626b92b70bf7 303 ( goObject->Height / 2 ) : ( goObject->Width / 2 ), \
mverdy 20:626b92b70bf7 304 goObject->BackColor );
mverdy 20:626b92b70bf7 305 }
mverdy 20:626b92b70bf7 306 goObject->TouchActive = false;
mverdy 20:626b92b70bf7 307 break;
mverdy 20:626b92b70bf7 308
mverdy 20:626b92b70bf7 309 case GO_TRIANGLE:
mverdy 20:626b92b70bf7 310 status = GO_STATUS_BAD_ARG;
mverdy 20:626b92b70bf7 311 goObject->TouchActive = false;
mverdy 20:626b92b70bf7 312 break;
mverdy 20:626b92b70bf7 313
mverdy 20:626b92b70bf7 314 case GO_LINE:
mverdy 20:626b92b70bf7 315 Tft.drawLine( goObject->Xpos, goObject->Ypos, goObject->Xpos + \
mverdy 20:626b92b70bf7 316 goObject->Width - 1, goObject->Ypos + \
mverdy 20:626b92b70bf7 317 goObject->Height - 1, goObject->BackColor );
mverdy 20:626b92b70bf7 318 goObject->TouchActive = false;
mverdy 20:626b92b70bf7 319 break;
mverdy 20:626b92b70bf7 320
mverdy 20:626b92b70bf7 321 default:
mverdy 20:626b92b70bf7 322 status = GO_STATUS_BAD_ARG;
mverdy 20:626b92b70bf7 323 }
mverdy 20:626b92b70bf7 324 return status;
mverdy 20:626b92b70bf7 325 }
mverdy 20:626b92b70bf7 326
mverdy 20:626b92b70bf7 327 void DisplayDriverDrawLogo( uint8_t *thisBmp, uint8_t xPos, uint8_t yPos )
mverdy 20:626b92b70bf7 328 {
mverdy 20:626b92b70bf7 329 if( BmpReadHeader( thisBmp ) )
mverdy 20:626b92b70bf7 330 {
mverdy 20:626b92b70bf7 331 DrawBmpFromFlash( thisBmp, xPos, yPos );
mverdy 20:626b92b70bf7 332 }
mverdy 20:626b92b70bf7 333 }
mverdy 20:626b92b70bf7 334
lex9296 21:ab8027016a2c 335 void TouchedXYT (uint16_t* x, uint16_t* y, bool* t) {
lex9296 21:ab8027016a2c 336 uint16_t ui16_x;
lex9296 21:ab8027016a2c 337 uint16_t ui16_y;
lex9296 21:ab8027016a2c 338 bool b_t;
lex9296 21:ab8027016a2c 339 Touch.readTouchData (ui16_x,
lex9296 21:ab8027016a2c 340 ui16_y,
lex9296 21:ab8027016a2c 341 b_t);
lex9296 21:ab8027016a2c 342
lex9296 21:ab8027016a2c 343 *x = ui16_x;
lex9296 21:ab8027016a2c 344 *y = ui16_y;
lex9296 21:ab8027016a2c 345 *t = b_t;
lex9296 21:ab8027016a2c 346 }
lex9296 21:ab8027016a2c 347
mverdy 20:626b92b70bf7 348 GraphObjectStatus_t GraphObjectTouched( GraphObject_t* objects, \
mverdy 20:626b92b70bf7 349 uint8_t objectsCount, \
mverdy 20:626b92b70bf7 350 uint8_t* touchedObject)
mverdy 20:626b92b70bf7 351 {
mverdy 20:626b92b70bf7 352 uint8_t objScan;
mverdy 20:626b92b70bf7 353 uint16_t x, y = 0;
mverdy 20:626b92b70bf7 354 bool touched = false;
mverdy 20:626b92b70bf7 355 GraphObjectStatus_t status = GO_STATUS_BAD_COORD;
mverdy 20:626b92b70bf7 356
mverdy 20:626b92b70bf7 357 if( Touch.isTouched( ) )
mverdy 20:626b92b70bf7 358 {
mverdy 20:626b92b70bf7 359 Touch.readTouchData( x, y, touched );
mverdy 20:626b92b70bf7 360
mverdy 20:626b92b70bf7 361 if( touched == true )
mverdy 20:626b92b70bf7 362 {
mverdy 20:626b92b70bf7 363 for( objScan = 0; objScan < objectsCount; objScan++)
mverdy 20:626b92b70bf7 364 {
mverdy 20:626b92b70bf7 365 if( objects[objScan].TouchActive == true )
mverdy 20:626b92b70bf7 366 {
mverdy 20:626b92b70bf7 367 if( ( y >= objects[objScan].Ypos ) && ( y <= ( objects[objScan].Ypos + objects[objScan].Height - 1 ) ) )
mverdy 20:626b92b70bf7 368 {
mverdy 20:626b92b70bf7 369 if( ( x >= objects[objScan].Xpos ) && ( x <= ( objects[objScan].Xpos + objects[objScan].Width - 1 ) ) )
mverdy 20:626b92b70bf7 370 {
mverdy 20:626b92b70bf7 371 *touchedObject = objects[objScan].Id;
mverdy 20:626b92b70bf7 372 status = GO_STATUS_NOERR;
mverdy 20:626b92b70bf7 373 break; // return the first object match and no scan of other following objects
mverdy 20:626b92b70bf7 374 }
mverdy 20:626b92b70bf7 375 }
mverdy 20:626b92b70bf7 376 }
mverdy 20:626b92b70bf7 377 }
mverdy 20:626b92b70bf7 378 }
mverdy 20:626b92b70bf7 379 }
mverdy 20:626b92b70bf7 380
mverdy 20:626b92b70bf7 381 return status;
mverdy 20:626b92b70bf7 382 }
mverdy 20:626b92b70bf7 383
mverdy 20:626b92b70bf7 384 static bool BmpReadHeader( uint8_t *thisBmp )
mverdy 20:626b92b70bf7 385 {
mverdy 20:626b92b70bf7 386 uint16_t pos = 0;
mverdy 20:626b92b70bf7 387
mverdy 20:626b92b70bf7 388 Read16( thisBmp );
mverdy 20:626b92b70bf7 389 if( Read16( thisBmp ) != 0x4D42 )
mverdy 20:626b92b70bf7 390 { // read magic byte
mverdy 20:626b92b70bf7 391 return false;
mverdy 20:626b92b70bf7 392 }
mverdy 20:626b92b70bf7 393 pos += 2;
mverdy 20:626b92b70bf7 394
mverdy 20:626b92b70bf7 395 // read file size
mverdy 20:626b92b70bf7 396 pos += 4;
mverdy 20:626b92b70bf7 397 pos += 4; // Skip creator bytes
mverdy 20:626b92b70bf7 398 BmpImageoffset = Read32( thisBmp + pos );
mverdy 20:626b92b70bf7 399 pos += 4;
mverdy 20:626b92b70bf7 400 // read DIB header
mverdy 20:626b92b70bf7 401 pos +=4;
mverdy 20:626b92b70bf7 402 BmpWidth = Read32( thisBmp + pos );
mverdy 20:626b92b70bf7 403 pos += 4;
mverdy 20:626b92b70bf7 404 BmpHeight = Read32( thisBmp + pos );
mverdy 20:626b92b70bf7 405 pos += 4;
mverdy 20:626b92b70bf7 406 if( Read16( thisBmp + pos ) != 1 )
mverdy 20:626b92b70bf7 407 {
mverdy 20:626b92b70bf7 408 // number of color planes must be 1
mverdy 20:626b92b70bf7 409 return false;
mverdy 20:626b92b70bf7 410 }
mverdy 20:626b92b70bf7 411 pos += 2;
mverdy 20:626b92b70bf7 412 pos += 2;
mverdy 20:626b92b70bf7 413 if( Read16( thisBmp + pos ) != 0 )
mverdy 20:626b92b70bf7 414 {
mverdy 20:626b92b70bf7 415 return false; // compression not supported!
mverdy 20:626b92b70bf7 416 }
mverdy 20:626b92b70bf7 417 pos += 2; // Should really be 2??
mverdy 20:626b92b70bf7 418 return true;
mverdy 20:626b92b70bf7 419 }
mverdy 20:626b92b70bf7 420
mverdy 20:626b92b70bf7 421 // LITTLE ENDIAN!
mverdy 20:626b92b70bf7 422 static uint16_t Read16( uint8_t *src )
mverdy 20:626b92b70bf7 423 {
mverdy 20:626b92b70bf7 424 uint16_t d;
mverdy 20:626b92b70bf7 425 uint8_t b;
mverdy 20:626b92b70bf7 426 b = *src;
mverdy 20:626b92b70bf7 427 d = *( src + 1 );
mverdy 20:626b92b70bf7 428 d <<= 8;
mverdy 20:626b92b70bf7 429 d |= b;
mverdy 20:626b92b70bf7 430 return d;
mverdy 20:626b92b70bf7 431 }
mverdy 20:626b92b70bf7 432
mverdy 20:626b92b70bf7 433 // LITTLE ENDIAN!
mverdy 20:626b92b70bf7 434 static uint32_t Read32( uint8_t *src )
mverdy 20:626b92b70bf7 435 {
mverdy 20:626b92b70bf7 436 uint32_t d;
mverdy 20:626b92b70bf7 437 uint16_t b;
mverdy 20:626b92b70bf7 438
mverdy 20:626b92b70bf7 439 b = Read16( src );
mverdy 20:626b92b70bf7 440 d = Read16( src + 2 );
mverdy 20:626b92b70bf7 441 d <<= 16;
mverdy 20:626b92b70bf7 442 d |= b;
mverdy 20:626b92b70bf7 443 return d;
mverdy 20:626b92b70bf7 444 }
mverdy 20:626b92b70bf7 445
mverdy 20:626b92b70bf7 446 static void DrawBmpFromFlash( uint8_t *thisBmp, int xPos, int yPos )
mverdy 20:626b92b70bf7 447 {
mverdy 20:626b92b70bf7 448 uint16_t pos = BmpImageoffset;
mverdy 20:626b92b70bf7 449 uint16_t p; // pixel
mverdy 20:626b92b70bf7 450 uint8_t g;
mverdy 20:626b92b70bf7 451 uint8_t b;
mverdy 20:626b92b70bf7 452 int i, j; // line, column
mverdy 20:626b92b70bf7 453
mverdy 20:626b92b70bf7 454 for( i = BmpHeight; i > 0; i-- )
mverdy 20:626b92b70bf7 455 {
mverdy 20:626b92b70bf7 456 for( j = 0; j < BmpWidth; j++ )
mverdy 20:626b92b70bf7 457 {
mverdy 20:626b92b70bf7 458 b = *( thisBmp + pos++ );
mverdy 20:626b92b70bf7 459 g = *( thisBmp + pos++ );
mverdy 20:626b92b70bf7 460 p = *( thisBmp + pos++ );
mverdy 20:626b92b70bf7 461
mverdy 20:626b92b70bf7 462 p >>= 3;
mverdy 20:626b92b70bf7 463 p <<= 6;
mverdy 20:626b92b70bf7 464
mverdy 20:626b92b70bf7 465 g >>= 2;
mverdy 20:626b92b70bf7 466 p |= g;
mverdy 20:626b92b70bf7 467 p <<= 5;
mverdy 20:626b92b70bf7 468
mverdy 20:626b92b70bf7 469 b >>= 3;
mverdy 20:626b92b70bf7 470 p |= b;
mverdy 20:626b92b70bf7 471
mverdy 20:626b92b70bf7 472 // write out the 16 bits of color
mverdy 20:626b92b70bf7 473 Tft.setPixel( j + xPos, i + yPos, p );
mverdy 20:626b92b70bf7 474 }
mverdy 20:626b92b70bf7 475 pos += 1;
mverdy 20:626b92b70bf7 476 }
mverdy 20:626b92b70bf7 477 }
mverdy 20:626b92b70bf7 478
lex9296 27:654100855f5c 479 void LCM_ClearScreen (uint16_t color) {
lex9296 27:654100855f5c 480 Tft.clearScreen (color);
lex9296 27:654100855f5c 481 }
lex9296 27:654100855f5c 482
lex9296 27:654100855f5c 483 void LCM_DrawString (uint16_t x, uint16_t y, const char *p) {
lex9296 27:654100855f5c 484 Tft.drawString (x, y, (char *)p);
lex9296 27:654100855f5c 485 }
lex9296 27:654100855f5c 486
lex9296 27:654100855f5c 487 void LCM_SetTextColor (uint16_t background, uint16_t foreground) {
lex9296 27:654100855f5c 488 Tft.setTextColor (background, foreground);
lex9296 27:654100855f5c 489 }
lex9296 27:654100855f5c 490
lex9296 27:654100855f5c 491 // LA: Color RGB Component(s)
lex9296 27:654100855f5c 492 // ======================
lex9296 27:654100855f5c 493 //
lex9296 27:654100855f5c 494 // RED 0000 1000 0000 0000 min 0x0800 02048
lex9296 27:654100855f5c 495 // 1111 1000 0000 0000 max 0xf800 63488
lex9296 27:654100855f5c 496 //
lex9296 27:654100855f5c 497 // GREEN 0000 0000 0010 0000 min 0x0020 00032 Real
lex9296 27:654100855f5c 498 // 0000 0111 1110 0000 max 0x07e0 02016
lex9296 27:654100855f5c 499 //
lex9296 27:654100855f5c 500 // GREEN 0000 0000 0100 0000 min 0x0040 00064 This
lex9296 27:654100855f5c 501 // 0000 0111 1100 0000 max 0x07c0 01984
lex9296 27:654100855f5c 502 //
lex9296 27:654100855f5c 503 // BLUE 0000 0000 0000 0001 min 0x0001 00001
lex9296 27:654100855f5c 504 // 0000 0000 0001 1111 max 0x001f 00031
lex9296 27:654100855f5c 505 //
lex9296 27:654100855f5c 506 // La componente ROSSA ha 5 bit di escursione (0.. 31),
lex9296 27:654100855f5c 507 // La componente VERDE ha 6 bit di escursione (0.. 63), Normalmente
lex9296 27:654100855f5c 508 // La componente VERDE ha 5 bit di escursione (0.. 31), In qst applicazione
lex9296 27:654100855f5c 509 // La componente BLU ha 5 bit di escursione (0.. 31),
lex9296 27:654100855f5c 510 //
lex9296 27:654100855f5c 511 // Le componenti RGB di "Color" sono quindi scritte negli appropriati registri come segue:
lex9296 27:654100855f5c 512 //
lex9296 27:654100855f5c 513 // writeReg(RED, (Color & 0xf800) >> 11);
lex9296 27:654100855f5c 514 // writeReg(GREEN, (Color & 0x07e0) >> 5);
lex9296 27:654100855f5c 515 // writeReg(BLUE, (Color & 0x001f));
lex9296 27:654100855f5c 516 //
lex9296 27:654100855f5c 517 uint16_t Scale2RGBColor (uint16_t R, uint16_t G, uint16_t B) {
lex9296 27:654100855f5c 518
lex9296 27:654100855f5c 519 R = ((R& 0x1f)<< 11)& 0xf800;
lex9296 27:654100855f5c 520 G = ((G& 0x1f)<< 6)& 0x07c0;
lex9296 27:654100855f5c 521 B &= 0x001f;
lex9296 27:654100855f5c 522 //
lex9296 27:654100855f5c 523 return (R+ G+ B);
lex9296 27:654100855f5c 524 }
lex9296 27:654100855f5c 525