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