![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Forked to initiate the Current Loop Gain
Dependencies: mbed QEI DmTftLibraryEx
Display/DisplayDriver.cpp@0:9c0917bfde97, 2017-03-13 (annotated)
- Committer:
- GregCr
- Date:
- Mon Mar 13 15:12:05 2017 +0000
- Revision:
- 0:9c0917bfde97
- Child:
- 17:a0bbfc228415
alpha release
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 | 0:9c0917bfde97 | 134 | |
GregCr | 0:9c0917bfde97 | 135 | switch( goObject->Type ) |
GregCr | 0:9c0917bfde97 | 136 | { |
GregCr | 0:9c0917bfde97 | 137 | case GO_TEXT: |
GregCr | 0:9c0917bfde97 | 138 | if( source == NULL ) |
GregCr | 0:9c0917bfde97 | 139 | { |
GregCr | 0:9c0917bfde97 | 140 | status = GO_STATUS_BAD_ARG; |
GregCr | 0:9c0917bfde97 | 141 | } |
GregCr | 0:9c0917bfde97 | 142 | else |
GregCr | 0:9c0917bfde97 | 143 | { |
GregCr | 0:9c0917bfde97 | 144 | uint8_t i = 0; |
GregCr | 0:9c0917bfde97 | 145 | uint8_t j = 0; |
GregCr | 0:9c0917bfde97 | 146 | // max character in the object string |
GregCr | 0:9c0917bfde97 | 147 | maxChar = goObject->Width / FONT_WIDTH; |
GregCr | 0:9c0917bfde97 | 148 | Tft.setTextColor( goObject->BackColor, goObject->FrontColor ); |
GregCr | 0:9c0917bfde97 | 149 | for( i = 0; i < maxChar; i++) |
GregCr | 0:9c0917bfde97 | 150 | { |
GregCr | 0:9c0917bfde97 | 151 | if( *source != 0 ) |
GregCr | 0:9c0917bfde97 | 152 | { |
GregCr | 0:9c0917bfde97 | 153 | Tft.drawChar( goObject->Xpos + j, goObject->Ypos, \ |
GregCr | 0:9c0917bfde97 | 154 | ( char )*( source++ ), false ); |
GregCr | 0:9c0917bfde97 | 155 | j += FONT_WIDTH; |
GregCr | 0:9c0917bfde97 | 156 | } |
GregCr | 0:9c0917bfde97 | 157 | else |
GregCr | 0:9c0917bfde97 | 158 | { |
GregCr | 0:9c0917bfde97 | 159 | Tft.drawChar( goObject->Xpos + ( FONT_WIDTH * i ), \ |
GregCr | 0:9c0917bfde97 | 160 | goObject->Ypos, SPACE_ASCII, false); |
GregCr | 0:9c0917bfde97 | 161 | } |
GregCr | 0:9c0917bfde97 | 162 | } |
GregCr | 0:9c0917bfde97 | 163 | goObject->TouchActive = activeTouch; |
GregCr | 0:9c0917bfde97 | 164 | } |
GregCr | 0:9c0917bfde97 | 165 | break; |
GregCr | 0:9c0917bfde97 | 166 | |
GregCr | 0:9c0917bfde97 | 167 | case GO_RECTANGLE: |
GregCr | 0:9c0917bfde97 | 168 | Tft.drawRectangle( goObject->Xpos, goObject->Ypos, goObject->Xpos + \ |
GregCr | 0:9c0917bfde97 | 169 | goObject->Width - 1, goObject->Ypos + \ |
GregCr | 0:9c0917bfde97 | 170 | goObject->Height - 1, goObject->FrontColor ); |
GregCr | 0:9c0917bfde97 | 171 | if( doFill ) |
GregCr | 0:9c0917bfde97 | 172 | { |
GregCr | 0:9c0917bfde97 | 173 | Tft.fillRectangle( goObject->Xpos + 1, goObject->Ypos + 1, \ |
GregCr | 0:9c0917bfde97 | 174 | goObject->Xpos + goObject->Width - 2, \ |
GregCr | 0:9c0917bfde97 | 175 | goObject->Ypos + goObject->Height - 2, \ |
GregCr | 0:9c0917bfde97 | 176 | goObject->FillColor ); |
GregCr | 0:9c0917bfde97 | 177 | } |
GregCr | 0:9c0917bfde97 | 178 | goObject->TouchActive = activeTouch; |
GregCr | 0:9c0917bfde97 | 179 | break; |
GregCr | 0:9c0917bfde97 | 180 | |
GregCr | 0:9c0917bfde97 | 181 | case GO_CIRCLE: |
GregCr | 0:9c0917bfde97 | 182 | Tft.drawCircle( goObject->Xpos, goObject->Ypos, \ |
GregCr | 0:9c0917bfde97 | 183 | ( goObject->Height < goObject->Width ) ? \ |
GregCr | 0:9c0917bfde97 | 184 | ( goObject->Height / 2 ) : ( goObject->Width / 2 ), \ |
GregCr | 0:9c0917bfde97 | 185 | goObject->FrontColor ); |
GregCr | 0:9c0917bfde97 | 186 | if( doFill ) |
GregCr | 0:9c0917bfde97 | 187 | { |
GregCr | 0:9c0917bfde97 | 188 | Tft.fillCircle( goObject->Xpos, goObject->Ypos, \ |
GregCr | 0:9c0917bfde97 | 189 | ( goObject->Height < goObject->Width ) ? \ |
GregCr | 0:9c0917bfde97 | 190 | ( goObject->Height / 2 ) - 1 : ( goObject->Width / 2 ) - 1, \ |
GregCr | 0:9c0917bfde97 | 191 | goObject->FillColor ); |
GregCr | 0:9c0917bfde97 | 192 | } |
GregCr | 0:9c0917bfde97 | 193 | goObject->TouchActive = activeTouch; |
GregCr | 0:9c0917bfde97 | 194 | break; |
GregCr | 0:9c0917bfde97 | 195 | |
GregCr | 0:9c0917bfde97 | 196 | case GO_TRIANGLE: |
GregCr | 0:9c0917bfde97 | 197 | status = GO_STATUS_BAD_ARG; |
GregCr | 0:9c0917bfde97 | 198 | break; |
GregCr | 0:9c0917bfde97 | 199 | |
GregCr | 0:9c0917bfde97 | 200 | case GO_IMAGE: |
GregCr | 0:9c0917bfde97 | 201 | if( source == NULL ) |
GregCr | 0:9c0917bfde97 | 202 | { |
GregCr | 0:9c0917bfde97 | 203 | status = GO_STATUS_BAD_ARG; |
GregCr | 0:9c0917bfde97 | 204 | } |
GregCr | 0:9c0917bfde97 | 205 | else |
GregCr | 0:9c0917bfde97 | 206 | { |
GregCr | 0:9c0917bfde97 | 207 | if( BmpReadHeader( goObject->Source ) ) |
GregCr | 0:9c0917bfde97 | 208 | { |
GregCr | 0:9c0917bfde97 | 209 | DrawBmpFromFlash( goObject->Source, goObject->Xpos, \ |
GregCr | 0:9c0917bfde97 | 210 | goObject->Ypos ); |
GregCr | 0:9c0917bfde97 | 211 | } |
GregCr | 0:9c0917bfde97 | 212 | else |
GregCr | 0:9c0917bfde97 | 213 | { |
GregCr | 0:9c0917bfde97 | 214 | // draw a red rectangle with a line through, to show error |
GregCr | 0:9c0917bfde97 | 215 | Tft.drawRectangle( goObject->Xpos, goObject->Ypos, \ |
GregCr | 0:9c0917bfde97 | 216 | goObject->Xpos + goObject->Width - 1, \ |
GregCr | 0:9c0917bfde97 | 217 | goObject->Ypos + goObject->Height - 1, \ |
GregCr | 0:9c0917bfde97 | 218 | OBJECT_ERROR ); |
GregCr | 0:9c0917bfde97 | 219 | Tft.drawLine( goObject->Xpos, goObject->Ypos, goObject->Xpos + \ |
GregCr | 0:9c0917bfde97 | 220 | goObject->Width - 1, goObject->Ypos + \ |
GregCr | 0:9c0917bfde97 | 221 | goObject->Height - 1, OBJECT_ERROR ); |
GregCr | 0:9c0917bfde97 | 222 | } |
GregCr | 0:9c0917bfde97 | 223 | goObject->TouchActive = activeTouch; |
GregCr | 0:9c0917bfde97 | 224 | } |
GregCr | 0:9c0917bfde97 | 225 | break; |
GregCr | 0:9c0917bfde97 | 226 | |
GregCr | 0:9c0917bfde97 | 227 | case GO_LINE: |
GregCr | 0:9c0917bfde97 | 228 | Tft.drawLine( goObject->Xpos, goObject->Ypos, goObject->Xpos + \ |
GregCr | 0:9c0917bfde97 | 229 | goObject->Width - 1, goObject->Ypos + \ |
GregCr | 0:9c0917bfde97 | 230 | goObject->Height - 1, goObject->FrontColor ); |
GregCr | 0:9c0917bfde97 | 231 | break; |
GregCr | 0:9c0917bfde97 | 232 | |
GregCr | 0:9c0917bfde97 | 233 | default: |
GregCr | 0:9c0917bfde97 | 234 | status = GO_STATUS_BAD_ARG; |
GregCr | 0:9c0917bfde97 | 235 | } |
GregCr | 0:9c0917bfde97 | 236 | return status; |
GregCr | 0:9c0917bfde97 | 237 | } |
GregCr | 0:9c0917bfde97 | 238 | |
GregCr | 0:9c0917bfde97 | 239 | GraphObjectStatus_t GraphObjectClear( GraphObject_t* goObject, bool doFill ) |
GregCr | 0:9c0917bfde97 | 240 | { |
GregCr | 0:9c0917bfde97 | 241 | GraphObjectStatus_t status = GO_STATUS_NOERR; |
GregCr | 0:9c0917bfde97 | 242 | uint8_t maxChar; |
GregCr | 0:9c0917bfde97 | 243 | |
GregCr | 0:9c0917bfde97 | 244 | if( goObject == NULL ) |
GregCr | 0:9c0917bfde97 | 245 | { |
GregCr | 0:9c0917bfde97 | 246 | return GO_STATUS_BAD_ARG; |
GregCr | 0:9c0917bfde97 | 247 | } |
GregCr | 0:9c0917bfde97 | 248 | |
GregCr | 0:9c0917bfde97 | 249 | switch( goObject->Type ) |
GregCr | 0:9c0917bfde97 | 250 | { |
GregCr | 0:9c0917bfde97 | 251 | case GO_TEXT: |
GregCr | 0:9c0917bfde97 | 252 | // max character in the object string |
GregCr | 0:9c0917bfde97 | 253 | maxChar = goObject->Width / FONT_WIDTH; |
GregCr | 0:9c0917bfde97 | 254 | GoTmpString[maxChar] = NULL; |
GregCr | 0:9c0917bfde97 | 255 | Tft.setTextColor( goObject->BackColor, goObject->FrontColor ); |
GregCr | 0:9c0917bfde97 | 256 | Tft.drawString( goObject->Xpos, goObject->Ypos, GoTmpString ); |
GregCr | 0:9c0917bfde97 | 257 | GoTmpString[maxChar] = SPACE_ASCII; |
GregCr | 0:9c0917bfde97 | 258 | goObject->TouchActive = false; |
GregCr | 0:9c0917bfde97 | 259 | break; |
GregCr | 0:9c0917bfde97 | 260 | |
GregCr | 0:9c0917bfde97 | 261 | case GO_RECTANGLE: |
GregCr | 0:9c0917bfde97 | 262 | case GO_IMAGE: |
GregCr | 0:9c0917bfde97 | 263 | if( doFill ) |
GregCr | 0:9c0917bfde97 | 264 | { |
GregCr | 0:9c0917bfde97 | 265 | Tft.fillRectangle( goObject->Xpos, goObject->Ypos, \ |
GregCr | 0:9c0917bfde97 | 266 | goObject->Xpos + goObject->Width - 1, \ |
GregCr | 0:9c0917bfde97 | 267 | goObject->Ypos + goObject->Height - 1, \ |
GregCr | 0:9c0917bfde97 | 268 | goObject->BackColor ); |
GregCr | 0:9c0917bfde97 | 269 | } |
GregCr | 0:9c0917bfde97 | 270 | else |
GregCr | 0:9c0917bfde97 | 271 | { |
GregCr | 0:9c0917bfde97 | 272 | Tft.drawRectangle( goObject->Xpos, goObject->Ypos, goObject->Xpos + \ |
GregCr | 0:9c0917bfde97 | 273 | goObject->Width - 1, goObject->Ypos + \ |
GregCr | 0:9c0917bfde97 | 274 | goObject->Height - 1, goObject->BackColor ); |
GregCr | 0:9c0917bfde97 | 275 | } |
GregCr | 0:9c0917bfde97 | 276 | goObject->TouchActive = false; |
GregCr | 0:9c0917bfde97 | 277 | break; |
GregCr | 0:9c0917bfde97 | 278 | |
GregCr | 0:9c0917bfde97 | 279 | case GO_CIRCLE: |
GregCr | 0:9c0917bfde97 | 280 | if( doFill ) |
GregCr | 0:9c0917bfde97 | 281 | { |
GregCr | 0:9c0917bfde97 | 282 | Tft.fillCircle( goObject->Xpos, goObject->Ypos, \ |
GregCr | 0:9c0917bfde97 | 283 | ( goObject->Height < goObject->Width ) ? \ |
GregCr | 0:9c0917bfde97 | 284 | ( goObject->Height / 2 ) : ( goObject->Width / 2 ), \ |
GregCr | 0:9c0917bfde97 | 285 | goObject->BackColor ); |
GregCr | 0:9c0917bfde97 | 286 | } |
GregCr | 0:9c0917bfde97 | 287 | else |
GregCr | 0:9c0917bfde97 | 288 | { |
GregCr | 0:9c0917bfde97 | 289 | Tft.drawCircle( goObject->Xpos, goObject->Ypos, \ |
GregCr | 0:9c0917bfde97 | 290 | ( goObject->Height < goObject->Width ) ? \ |
GregCr | 0:9c0917bfde97 | 291 | ( goObject->Height / 2 ) : ( goObject->Width / 2 ), \ |
GregCr | 0:9c0917bfde97 | 292 | goObject->BackColor ); |
GregCr | 0:9c0917bfde97 | 293 | } |
GregCr | 0:9c0917bfde97 | 294 | goObject->TouchActive = false; |
GregCr | 0:9c0917bfde97 | 295 | break; |
GregCr | 0:9c0917bfde97 | 296 | |
GregCr | 0:9c0917bfde97 | 297 | case GO_TRIANGLE: |
GregCr | 0:9c0917bfde97 | 298 | status = GO_STATUS_BAD_ARG; |
GregCr | 0:9c0917bfde97 | 299 | goObject->TouchActive = false; |
GregCr | 0:9c0917bfde97 | 300 | break; |
GregCr | 0:9c0917bfde97 | 301 | |
GregCr | 0:9c0917bfde97 | 302 | case GO_LINE: |
GregCr | 0:9c0917bfde97 | 303 | Tft.drawLine( goObject->Xpos, goObject->Ypos, goObject->Xpos + \ |
GregCr | 0:9c0917bfde97 | 304 | goObject->Width - 1, goObject->Ypos + \ |
GregCr | 0:9c0917bfde97 | 305 | goObject->Height - 1, goObject->BackColor ); |
GregCr | 0:9c0917bfde97 | 306 | goObject->TouchActive = false; |
GregCr | 0:9c0917bfde97 | 307 | break; |
GregCr | 0:9c0917bfde97 | 308 | |
GregCr | 0:9c0917bfde97 | 309 | default: |
GregCr | 0:9c0917bfde97 | 310 | status = GO_STATUS_BAD_ARG; |
GregCr | 0:9c0917bfde97 | 311 | } |
GregCr | 0:9c0917bfde97 | 312 | return status; |
GregCr | 0:9c0917bfde97 | 313 | } |
GregCr | 0:9c0917bfde97 | 314 | |
GregCr | 0:9c0917bfde97 | 315 | void DisplayDriverDrawLogo( uint8_t *thisBmp, uint8_t xPos, uint8_t yPos ) |
GregCr | 0:9c0917bfde97 | 316 | { |
GregCr | 0:9c0917bfde97 | 317 | if( BmpReadHeader( thisBmp ) ) |
GregCr | 0:9c0917bfde97 | 318 | { |
GregCr | 0:9c0917bfde97 | 319 | DrawBmpFromFlash( thisBmp, xPos, yPos ); |
GregCr | 0:9c0917bfde97 | 320 | } |
GregCr | 0:9c0917bfde97 | 321 | } |
GregCr | 0:9c0917bfde97 | 322 | |
GregCr | 0:9c0917bfde97 | 323 | GraphObjectStatus_t GraphObjectTouched( GraphObject_t* objects, \ |
GregCr | 0:9c0917bfde97 | 324 | uint8_t objectsCount, \ |
GregCr | 0:9c0917bfde97 | 325 | uint8_t* touchedObject) |
GregCr | 0:9c0917bfde97 | 326 | { |
GregCr | 0:9c0917bfde97 | 327 | uint8_t objScan; |
GregCr | 0:9c0917bfde97 | 328 | uint16_t x, y = 0; |
GregCr | 0:9c0917bfde97 | 329 | bool touched = false; |
GregCr | 0:9c0917bfde97 | 330 | GraphObjectStatus_t status = GO_STATUS_BAD_COORD; |
GregCr | 0:9c0917bfde97 | 331 | |
GregCr | 0:9c0917bfde97 | 332 | __disable_irq( ); // Disable Interrupts |
GregCr | 0:9c0917bfde97 | 333 | |
GregCr | 0:9c0917bfde97 | 334 | if( Touch.isTouched( ) ) |
GregCr | 0:9c0917bfde97 | 335 | { |
GregCr | 0:9c0917bfde97 | 336 | Touch.readTouchData( x, y, touched ); |
GregCr | 0:9c0917bfde97 | 337 | |
GregCr | 0:9c0917bfde97 | 338 | if( touched == true ) |
GregCr | 0:9c0917bfde97 | 339 | { |
GregCr | 0:9c0917bfde97 | 340 | for( objScan = 0; objScan < objectsCount; objScan++) |
GregCr | 0:9c0917bfde97 | 341 | { |
GregCr | 0:9c0917bfde97 | 342 | if( objects[objScan].TouchActive == true ) |
GregCr | 0:9c0917bfde97 | 343 | { |
GregCr | 0:9c0917bfde97 | 344 | if( ( y >= objects[objScan].Ypos ) && ( y <= ( objects[objScan].Ypos + objects[objScan].Height - 1 ) ) ) |
GregCr | 0:9c0917bfde97 | 345 | { |
GregCr | 0:9c0917bfde97 | 346 | if( ( x >= objects[objScan].Xpos ) && ( x <= ( objects[objScan].Xpos + objects[objScan].Width - 1 ) ) ) |
GregCr | 0:9c0917bfde97 | 347 | { |
GregCr | 0:9c0917bfde97 | 348 | *touchedObject = objects[objScan].Id; |
GregCr | 0:9c0917bfde97 | 349 | status = GO_STATUS_NOERR; |
GregCr | 0:9c0917bfde97 | 350 | break; // return the first object match and no scan of other following objects |
GregCr | 0:9c0917bfde97 | 351 | } |
GregCr | 0:9c0917bfde97 | 352 | } |
GregCr | 0:9c0917bfde97 | 353 | } |
GregCr | 0:9c0917bfde97 | 354 | } |
GregCr | 0:9c0917bfde97 | 355 | } |
GregCr | 0:9c0917bfde97 | 356 | } |
GregCr | 0:9c0917bfde97 | 357 | |
GregCr | 0:9c0917bfde97 | 358 | __enable_irq( ); // Enable Interrupts |
GregCr | 0:9c0917bfde97 | 359 | |
GregCr | 0:9c0917bfde97 | 360 | return status; |
GregCr | 0:9c0917bfde97 | 361 | } |
GregCr | 0:9c0917bfde97 | 362 | |
GregCr | 0:9c0917bfde97 | 363 | static bool BmpReadHeader( uint8_t *thisBmp ) |
GregCr | 0:9c0917bfde97 | 364 | { |
GregCr | 0:9c0917bfde97 | 365 | uint16_t pos = 0; |
GregCr | 0:9c0917bfde97 | 366 | |
GregCr | 0:9c0917bfde97 | 367 | Read16( thisBmp ); |
GregCr | 0:9c0917bfde97 | 368 | if( Read16( thisBmp ) != 0x4D42 ) |
GregCr | 0:9c0917bfde97 | 369 | { // read magic byte |
GregCr | 0:9c0917bfde97 | 370 | return false; |
GregCr | 0:9c0917bfde97 | 371 | } |
GregCr | 0:9c0917bfde97 | 372 | pos += 2; |
GregCr | 0:9c0917bfde97 | 373 | |
GregCr | 0:9c0917bfde97 | 374 | // read file size |
GregCr | 0:9c0917bfde97 | 375 | pos += 4; |
GregCr | 0:9c0917bfde97 | 376 | pos += 4; // Skip creator bytes |
GregCr | 0:9c0917bfde97 | 377 | BmpImageoffset = Read32( thisBmp + pos ); |
GregCr | 0:9c0917bfde97 | 378 | pos += 4; |
GregCr | 0:9c0917bfde97 | 379 | // read DIB header |
GregCr | 0:9c0917bfde97 | 380 | pos +=4; |
GregCr | 0:9c0917bfde97 | 381 | BmpWidth = Read32( thisBmp + pos ); |
GregCr | 0:9c0917bfde97 | 382 | pos += 4; |
GregCr | 0:9c0917bfde97 | 383 | BmpHeight = Read32( thisBmp + pos ); |
GregCr | 0:9c0917bfde97 | 384 | pos += 4; |
GregCr | 0:9c0917bfde97 | 385 | if( Read16( thisBmp + pos ) != 1 ) |
GregCr | 0:9c0917bfde97 | 386 | { |
GregCr | 0:9c0917bfde97 | 387 | // number of color planes must be 1 |
GregCr | 0:9c0917bfde97 | 388 | return false; |
GregCr | 0:9c0917bfde97 | 389 | } |
GregCr | 0:9c0917bfde97 | 390 | pos += 2; |
GregCr | 0:9c0917bfde97 | 391 | pos += 2; |
GregCr | 0:9c0917bfde97 | 392 | if( Read16( thisBmp + pos ) != 0 ) |
GregCr | 0:9c0917bfde97 | 393 | { |
GregCr | 0:9c0917bfde97 | 394 | return false; // compression not supported! |
GregCr | 0:9c0917bfde97 | 395 | } |
GregCr | 0:9c0917bfde97 | 396 | pos += 2; // Should really be 2?? |
GregCr | 0:9c0917bfde97 | 397 | return true; |
GregCr | 0:9c0917bfde97 | 398 | } |
GregCr | 0:9c0917bfde97 | 399 | |
GregCr | 0:9c0917bfde97 | 400 | // LITTLE ENDIAN! |
GregCr | 0:9c0917bfde97 | 401 | static uint16_t Read16( uint8_t *src ) |
GregCr | 0:9c0917bfde97 | 402 | { |
GregCr | 0:9c0917bfde97 | 403 | uint16_t d; |
GregCr | 0:9c0917bfde97 | 404 | uint8_t b; |
GregCr | 0:9c0917bfde97 | 405 | b = *src; |
GregCr | 0:9c0917bfde97 | 406 | d = *( src + 1 ); |
GregCr | 0:9c0917bfde97 | 407 | d <<= 8; |
GregCr | 0:9c0917bfde97 | 408 | d |= b; |
GregCr | 0:9c0917bfde97 | 409 | return d; |
GregCr | 0:9c0917bfde97 | 410 | } |
GregCr | 0:9c0917bfde97 | 411 | |
GregCr | 0:9c0917bfde97 | 412 | // LITTLE ENDIAN! |
GregCr | 0:9c0917bfde97 | 413 | static uint32_t Read32( uint8_t *src ) |
GregCr | 0:9c0917bfde97 | 414 | { |
GregCr | 0:9c0917bfde97 | 415 | uint32_t d; |
GregCr | 0:9c0917bfde97 | 416 | uint16_t b; |
GregCr | 0:9c0917bfde97 | 417 | |
GregCr | 0:9c0917bfde97 | 418 | b = Read16( src ); |
GregCr | 0:9c0917bfde97 | 419 | d = Read16( src + 2 ); |
GregCr | 0:9c0917bfde97 | 420 | d <<= 16; |
GregCr | 0:9c0917bfde97 | 421 | d |= b; |
GregCr | 0:9c0917bfde97 | 422 | return d; |
GregCr | 0:9c0917bfde97 | 423 | } |
GregCr | 0:9c0917bfde97 | 424 | |
GregCr | 0:9c0917bfde97 | 425 | static void DrawBmpFromFlash( uint8_t *thisBmp, int xPos, int yPos ) |
GregCr | 0:9c0917bfde97 | 426 | { |
GregCr | 0:9c0917bfde97 | 427 | uint16_t pos = BmpImageoffset; |
GregCr | 0:9c0917bfde97 | 428 | uint16_t p; // pixel |
GregCr | 0:9c0917bfde97 | 429 | uint8_t g; |
GregCr | 0:9c0917bfde97 | 430 | uint8_t b; |
GregCr | 0:9c0917bfde97 | 431 | int i, j; // line, column |
GregCr | 0:9c0917bfde97 | 432 | |
GregCr | 0:9c0917bfde97 | 433 | for( i = BmpHeight; i > 0; i-- ) |
GregCr | 0:9c0917bfde97 | 434 | { |
GregCr | 0:9c0917bfde97 | 435 | for( j = 0; j < BmpWidth; j++ ) |
GregCr | 0:9c0917bfde97 | 436 | { |
GregCr | 0:9c0917bfde97 | 437 | b = *( thisBmp + pos++ ); |
GregCr | 0:9c0917bfde97 | 438 | g = *( thisBmp + pos++ ); |
GregCr | 0:9c0917bfde97 | 439 | p = *( thisBmp + pos++ ); |
GregCr | 0:9c0917bfde97 | 440 | |
GregCr | 0:9c0917bfde97 | 441 | p >>= 3; |
GregCr | 0:9c0917bfde97 | 442 | p <<= 6; |
GregCr | 0:9c0917bfde97 | 443 | |
GregCr | 0:9c0917bfde97 | 444 | g >>= 2; |
GregCr | 0:9c0917bfde97 | 445 | p |= g; |
GregCr | 0:9c0917bfde97 | 446 | p <<= 5; |
GregCr | 0:9c0917bfde97 | 447 | |
GregCr | 0:9c0917bfde97 | 448 | b >>= 3; |
GregCr | 0:9c0917bfde97 | 449 | p |= b; |
GregCr | 0:9c0917bfde97 | 450 | |
GregCr | 0:9c0917bfde97 | 451 | // write out the 16 bits of color |
GregCr | 0:9c0917bfde97 | 452 | Tft.setPixel( j + xPos, i + yPos, p ); |
GregCr | 0:9c0917bfde97 | 453 | } |
GregCr | 0:9c0917bfde97 | 454 | pos += 1; |
GregCr | 0:9c0917bfde97 | 455 | } |
GregCr | 0:9c0917bfde97 | 456 | } |