Richard Nash
/
TFTtouch_F767ZI_working-clean
TFT Touch base
Fork of TFT_test_NUCLEO-F411RE by
main.cpp@1:0a7005226e61, 2018-07-30 (annotated)
- Committer:
- richnash
- Date:
- Mon Jul 30 14:18:06 2018 +0000
- Revision:
- 1:0a7005226e61
- Parent:
- 0:cd5e3d371b54
base version of TFT demo for F767ZI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
richnash | 1:0a7005226e61 | 1 | /* Adapted from other examples to work on a F767ZI |
richnash | 1:0a7005226e61 | 2 | */ |
richnash | 1:0a7005226e61 | 3 | |
Rhyme | 0:cd5e3d371b54 | 4 | /* mbed main.cpp to test adafruit 2.8" TFT LCD shiled w Touchscreen |
Rhyme | 0:cd5e3d371b54 | 5 | * Copyright (c) 2014, 2015 Motoo Tanaka @ Design Methodology Lab |
Rhyme | 0:cd5e3d371b54 | 6 | * |
Rhyme | 0:cd5e3d371b54 | 7 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Rhyme | 0:cd5e3d371b54 | 8 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Rhyme | 0:cd5e3d371b54 | 9 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Rhyme | 0:cd5e3d371b54 | 10 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Rhyme | 0:cd5e3d371b54 | 11 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Rhyme | 0:cd5e3d371b54 | 12 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Rhyme | 0:cd5e3d371b54 | 13 | * THE SOFTWARE. |
Rhyme | 0:cd5e3d371b54 | 14 | */ |
Rhyme | 0:cd5e3d371b54 | 15 | |
Rhyme | 0:cd5e3d371b54 | 16 | /* |
Rhyme | 0:cd5e3d371b54 | 17 | * Note: This program is derived from the SeeeStudioTFTv2 program. |
Rhyme | 0:cd5e3d371b54 | 18 | * Although both program share same ILI9341 TFT driver, |
Rhyme | 0:cd5e3d371b54 | 19 | * the touch sensor was not same with the Display I purchased from Akizuki. |
Rhyme | 0:cd5e3d371b54 | 20 | * http://akizukidenshi.com/catalog/g/gM-07747/ |
Rhyme | 0:cd5e3d371b54 | 21 | * The touch sensor on the display is STMPE610, |
Rhyme | 0:cd5e3d371b54 | 22 | * so I hacked the minimum spi driver for it (polling mode only). |
Rhyme | 0:cd5e3d371b54 | 23 | */ |
Rhyme | 0:cd5e3d371b54 | 24 | |
Rhyme | 0:cd5e3d371b54 | 25 | #include "mbed.h" |
Rhyme | 0:cd5e3d371b54 | 26 | #include <math.h> |
Rhyme | 0:cd5e3d371b54 | 27 | #include "ILI9341.h" |
Rhyme | 0:cd5e3d371b54 | 28 | #include "SPI_STMPE610.h" |
Rhyme | 0:cd5e3d371b54 | 29 | #include "Arial12x12.h" |
Rhyme | 0:cd5e3d371b54 | 30 | #include "Arial24x23.h" |
Rhyme | 0:cd5e3d371b54 | 31 | #include "Arial28x28.h" |
Rhyme | 0:cd5e3d371b54 | 32 | #include "Arial43x48_numb.h" |
Rhyme | 0:cd5e3d371b54 | 33 | |
Rhyme | 0:cd5e3d371b54 | 34 | #define PIN_RESET_TFT PC_13 /* place holder */ |
richnash | 1:0a7005226e61 | 35 | |
richnash | 1:0a7005226e61 | 36 | // ------------- FROM WORKING VERSION |
richnash | 1:0a7005226e61 | 37 | |
richnash | 1:0a7005226e61 | 38 | #define PIN_MOSI D11 |
richnash | 1:0a7005226e61 | 39 | #define PIN_MISO D12 |
richnash | 1:0a7005226e61 | 40 | #define PIN_SCLK D13 |
richnash | 1:0a7005226e61 | 41 | #define PIN_CS_TFT D5 |
richnash | 1:0a7005226e61 | 42 | #define PIN_DC_TFT D6 |
richnash | 1:0a7005226e61 | 43 | #define PIN_BL_TFT D7 |
richnash | 1:0a7005226e61 | 44 | #define PIN_CS_SD D4 |
richnash | 1:0a7005226e61 | 45 | |
richnash | 1:0a7005226e61 | 46 | // ===================================== |
richnash | 1:0a7005226e61 | 47 | |
richnash | 1:0a7005226e61 | 48 | #define PIN_XP A2 |
richnash | 1:0a7005226e61 | 49 | #define PIN_XM A0 |
richnash | 1:0a7005226e61 | 50 | #define PIN_YP A3 |
richnash | 1:0a7005226e61 | 51 | #define PIN_YM A1 |
richnash | 1:0a7005226e61 | 52 | |
richnash | 1:0a7005226e61 | 53 | |
richnash | 1:0a7005226e61 | 54 | struct point { |
richnash | 1:0a7005226e61 | 55 | int x; |
richnash | 1:0a7005226e61 | 56 | int y; |
richnash | 1:0a7005226e61 | 57 | }; |
Rhyme | 0:cd5e3d371b54 | 58 | |
richnash | 1:0a7005226e61 | 59 | void calibrate(void); |
richnash | 1:0a7005226e61 | 60 | bool getPixel(point& p); |
richnash | 1:0a7005226e61 | 61 | point toPixel(point p); |
richnash | 1:0a7005226e61 | 62 | |
richnash | 1:0a7005226e61 | 63 | typedef enum { YES, MAYBE, NO } TOUCH; |
richnash | 1:0a7005226e61 | 64 | |
richnash | 1:0a7005226e61 | 65 | TOUCH getTouch(point& p); |
richnash | 1:0a7005226e61 | 66 | |
richnash | 1:0a7005226e61 | 67 | int readTouch(PinName p, PinName m, PinName a, PinName i); |
richnash | 1:0a7005226e61 | 68 | |
richnash | 1:0a7005226e61 | 69 | |
richnash | 1:0a7005226e61 | 70 | int x_off = 22071; |
richnash | 1:0a7005226e61 | 71 | int y_off = 18707; |
richnash | 1:0a7005226e61 | 72 | int pp_tx = 373; |
richnash | 1:0a7005226e61 | 73 | int pp_ty = 297; |
richnash | 1:0a7005226e61 | 74 | |
richnash | 1:0a7005226e61 | 75 | // ===================================== |
richnash | 1:0a7005226e61 | 76 | |
richnash | 1:0a7005226e61 | 77 | DigitalOut backlight(PIN_BL_TFT) ; |
richnash | 1:0a7005226e61 | 78 | |
richnash | 1:0a7005226e61 | 79 | ILI9341 TFT(SPI_8, 10000000, PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Seeed2.8") ; |
richnash | 1:0a7005226e61 | 80 | |
richnash | 1:0a7005226e61 | 81 | int page = 1 ; |
richnash | 1:0a7005226e61 | 82 | int numPage = 3 ; |
richnash | 1:0a7005226e61 | 83 | |
richnash | 1:0a7005226e61 | 84 | Serial logger(SERIAL_TX, SERIAL_RX); |
richnash | 1:0a7005226e61 | 85 | |
richnash | 1:0a7005226e61 | 86 | |
richnash | 1:0a7005226e61 | 87 | /// ================================================================================================ |
Rhyme | 0:cd5e3d371b54 | 88 | |
Rhyme | 0:cd5e3d371b54 | 89 | |
richnash | 1:0a7005226e61 | 90 | int readTouch(PinName p, PinName m, PinName a, PinName i) |
richnash | 1:0a7005226e61 | 91 | { |
richnash | 1:0a7005226e61 | 92 | DigitalOut _p(p); |
richnash | 1:0a7005226e61 | 93 | _p = 1; |
richnash | 1:0a7005226e61 | 94 | DigitalOut _m(m); |
richnash | 1:0a7005226e61 | 95 | _m = 0; |
richnash | 1:0a7005226e61 | 96 | AnalogIn _a(a); |
richnash | 1:0a7005226e61 | 97 | AnalogIn _i(i); // this pin has to be high Z (DigitalIn may also work) |
richnash | 1:0a7005226e61 | 98 | wait_us(10); |
richnash | 1:0a7005226e61 | 99 | return _a.read_u16(); |
richnash | 1:0a7005226e61 | 100 | } |
richnash | 1:0a7005226e61 | 101 | |
richnash | 1:0a7005226e61 | 102 | TOUCH getTouch(point& p) |
richnash | 1:0a7005226e61 | 103 | { |
richnash | 1:0a7005226e61 | 104 | int y2 = readTouch(PIN_XP,PIN_XM,PIN_YP,PIN_YM); |
richnash | 1:0a7005226e61 | 105 | int x2 = readTouch(PIN_YP,PIN_YM,PIN_XP,PIN_XM); |
richnash | 1:0a7005226e61 | 106 | int y1 = readTouch(PIN_XP,PIN_XM,PIN_YP,PIN_YM); |
richnash | 1:0a7005226e61 | 107 | int x1 = readTouch(PIN_YP,PIN_YM,PIN_XP,PIN_XM); |
richnash | 1:0a7005226e61 | 108 | int xd = x1 - x2; |
richnash | 1:0a7005226e61 | 109 | int yd = y1 - y2; |
richnash | 1:0a7005226e61 | 110 | xd = (xd > 0) ? xd : -xd; |
richnash | 1:0a7005226e61 | 111 | yd = (yd > 0) ? xd : -xd; |
richnash | 1:0a7005226e61 | 112 | p.x = x1 + x2; |
richnash | 1:0a7005226e61 | 113 | p.y = y1 + y2; |
richnash | 1:0a7005226e61 | 114 | |
richnash | 1:0a7005226e61 | 115 | const int th = 8000; |
richnash | 1:0a7005226e61 | 116 | const int df = 100; |
richnash | 1:0a7005226e61 | 117 | TOUCH touch; |
richnash | 1:0a7005226e61 | 118 | if (x1 < th || x2 < th || |
richnash | 1:0a7005226e61 | 119 | y1 < th || y2 < th) { |
richnash | 1:0a7005226e61 | 120 | p.x = 0; |
richnash | 1:0a7005226e61 | 121 | p.y = 0; |
richnash | 1:0a7005226e61 | 122 | touch = NO; |
richnash | 1:0a7005226e61 | 123 | } else if (xd > df || yd > df) { |
richnash | 1:0a7005226e61 | 124 | touch = MAYBE; |
richnash | 1:0a7005226e61 | 125 | } else { |
richnash | 1:0a7005226e61 | 126 | touch = YES; |
richnash | 1:0a7005226e61 | 127 | } |
richnash | 1:0a7005226e61 | 128 | //TFT.locate(0,50); |
richnash | 1:0a7005226e61 | 129 | //TFT.printf("x: %6i y: %6i",p.x,p.y); |
richnash | 1:0a7005226e61 | 130 | return touch; |
richnash | 1:0a7005226e61 | 131 | } |
Rhyme | 0:cd5e3d371b54 | 132 | |
richnash | 1:0a7005226e61 | 133 | void calibrate(void) |
richnash | 1:0a7005226e61 | 134 | { |
richnash | 1:0a7005226e61 | 135 | int i; |
richnash | 1:0a7005226e61 | 136 | int a = 0,b = 0,c = 0, d = 0; |
richnash | 1:0a7005226e61 | 137 | int pos_x = 0, pos_y = 0; |
richnash | 1:0a7005226e61 | 138 | point p; |
richnash | 1:0a7005226e61 | 139 | |
richnash | 1:0a7005226e61 | 140 | backlight = 0 ; |
richnash | 1:0a7005226e61 | 141 | //TFT.BusEnable(true) ; |
richnash | 1:0a7005226e61 | 142 | |
richnash | 1:0a7005226e61 | 143 | TFT.background(Black); |
richnash | 1:0a7005226e61 | 144 | wait(0.1) ; |
richnash | 1:0a7005226e61 | 145 | TFT.foreground(White); |
richnash | 1:0a7005226e61 | 146 | wait(0.1) ; |
richnash | 1:0a7005226e61 | 147 | TFT.cls() ; |
richnash | 1:0a7005226e61 | 148 | wait(0.1) ; |
richnash | 1:0a7005226e61 | 149 | TFT.set_font((unsigned char*) Arial12x12); |
richnash | 1:0a7005226e61 | 150 | TFT.locate(90,0); |
richnash | 1:0a7005226e61 | 151 | TFT.printf("Graphics"); |
richnash | 1:0a7005226e61 | 152 | |
richnash | 1:0a7005226e61 | 153 | TFT.line(0,3,6,3,White); |
richnash | 1:0a7005226e61 | 154 | TFT.line(3,0,3,6,White); |
richnash | 1:0a7005226e61 | 155 | |
richnash | 1:0a7005226e61 | 156 | backlight = 1 ; |
richnash | 1:0a7005226e61 | 157 | |
richnash | 1:0a7005226e61 | 158 | //if (font) |
richnash | 1:0a7005226e61 | 159 | //{ |
richnash | 1:0a7005226e61 | 160 | // get the center of the screen |
richnash | 1:0a7005226e61 | 161 | pos_x = TFT.columns() / 2 - 3; |
richnash | 1:0a7005226e61 | 162 | pos_x = pos_x * Arial12x12[1]; |
richnash | 1:0a7005226e61 | 163 | pos_y = (TFT.rows() / 2) - 1; |
richnash | 1:0a7005226e61 | 164 | pos_y = pos_y * Arial12x12[2]; |
richnash | 1:0a7005226e61 | 165 | TFT.locate(pos_x,pos_y); |
richnash | 1:0a7005226e61 | 166 | TFT.printf("press cross "); |
richnash | 1:0a7005226e61 | 167 | TFT.locate(pos_x,pos_y + Arial12x12[2]); |
richnash | 1:0a7005226e61 | 168 | TFT.printf("to calibrate "); |
richnash | 1:0a7005226e61 | 169 | //} |
richnash | 1:0a7005226e61 | 170 | |
richnash | 1:0a7005226e61 | 171 | for (i=0; i<5; i++) { |
richnash | 1:0a7005226e61 | 172 | while (getTouch(p) != YES) |
richnash | 1:0a7005226e61 | 173 | /*nothing*/; |
richnash | 1:0a7005226e61 | 174 | a += p.x; |
richnash | 1:0a7005226e61 | 175 | b += p.y; |
richnash | 1:0a7005226e61 | 176 | } |
richnash | 1:0a7005226e61 | 177 | a = a / 5; |
richnash | 1:0a7005226e61 | 178 | b = b / 5; |
richnash | 1:0a7005226e61 | 179 | //if (font) |
richnash | 1:0a7005226e61 | 180 | //{ |
richnash | 1:0a7005226e61 | 181 | TFT.locate(pos_x,pos_y); |
richnash | 1:0a7005226e61 | 182 | TFT.printf("ok "); |
richnash | 1:0a7005226e61 | 183 | TFT.locate(pos_x,pos_y + Arial12x12[2]); |
richnash | 1:0a7005226e61 | 184 | TFT.printf("release touch "); |
richnash | 1:0a7005226e61 | 185 | //} |
richnash | 1:0a7005226e61 | 186 | while (getTouch(p) != NO) |
richnash | 1:0a7005226e61 | 187 | /*nothing*/; |
richnash | 1:0a7005226e61 | 188 | |
richnash | 1:0a7005226e61 | 189 | TFT.cls(); |
richnash | 1:0a7005226e61 | 190 | TFT.line(TFT.width() -5, TFT.height() - 8,TFT.width() - 5,TFT.height() -1,White); // paint cross |
richnash | 1:0a7005226e61 | 191 | TFT.line(TFT.width() - 8,TFT.height() - 5,TFT.width() - 1,TFT.height() - 5,White); |
richnash | 1:0a7005226e61 | 192 | //if (font) |
richnash | 1:0a7005226e61 | 193 | //{ |
richnash | 1:0a7005226e61 | 194 | TFT.locate(pos_x,pos_y); |
richnash | 1:0a7005226e61 | 195 | TFT.printf("press cross "); |
richnash | 1:0a7005226e61 | 196 | TFT.locate(pos_x,pos_y + Arial12x12[2]); |
richnash | 1:0a7005226e61 | 197 | TFT.printf("to calibrate "); |
richnash | 1:0a7005226e61 | 198 | //} |
richnash | 1:0a7005226e61 | 199 | for (i=0; i<5; i++) { |
richnash | 1:0a7005226e61 | 200 | while (getTouch(p) != YES) |
richnash | 1:0a7005226e61 | 201 | /*nothing*/; |
richnash | 1:0a7005226e61 | 202 | c+= p.x; |
richnash | 1:0a7005226e61 | 203 | d+= p.y; |
richnash | 1:0a7005226e61 | 204 | } |
richnash | 1:0a7005226e61 | 205 | c = c / 5; |
richnash | 1:0a7005226e61 | 206 | d = d / 5; |
richnash | 1:0a7005226e61 | 207 | x_off = a; |
richnash | 1:0a7005226e61 | 208 | y_off = b; |
richnash | 1:0a7005226e61 | 209 | i = c-a; // delta x |
richnash | 1:0a7005226e61 | 210 | pp_tx = i / (TFT.width() - 6); |
richnash | 1:0a7005226e61 | 211 | i = d-b; // delta y |
richnash | 1:0a7005226e61 | 212 | pp_ty = i / (TFT.height() - 6); |
richnash | 1:0a7005226e61 | 213 | //if (font) |
richnash | 1:0a7005226e61 | 214 | //{ |
richnash | 1:0a7005226e61 | 215 | TFT.locate(pos_x,pos_y); |
richnash | 1:0a7005226e61 | 216 | TFT.printf("Calibrated "); |
richnash | 1:0a7005226e61 | 217 | TFT.locate(pos_x,pos_y + Arial12x12[2]); |
richnash | 1:0a7005226e61 | 218 | TFT.printf("x %6i %4i", x_off, pp_tx); |
richnash | 1:0a7005226e61 | 219 | TFT.locate(pos_x,pos_y + 2*Arial12x12[2]); |
richnash | 1:0a7005226e61 | 220 | TFT.printf("y %6i %4i", y_off, pp_ty); |
richnash | 1:0a7005226e61 | 221 | //} |
richnash | 1:0a7005226e61 | 222 | while (getTouch(p) != NO) |
richnash | 1:0a7005226e61 | 223 | /*nothing*/; |
richnash | 1:0a7005226e61 | 224 | TFT.cls(); |
richnash | 1:0a7005226e61 | 225 | |
richnash | 1:0a7005226e61 | 226 | //TFT.BusEnable(false) ; |
richnash | 1:0a7005226e61 | 227 | |
richnash | 1:0a7005226e61 | 228 | printf("x_off:%6i pp_tx:%4i \n\r", x_off, pp_tx); |
richnash | 1:0a7005226e61 | 229 | printf("y_off:%6i pp_ty:%4i \n\r", y_off, pp_ty); |
richnash | 1:0a7005226e61 | 230 | } |
Rhyme | 0:cd5e3d371b54 | 231 | |
richnash | 1:0a7005226e61 | 232 | point toPixel(point p) |
richnash | 1:0a7005226e61 | 233 | { |
richnash | 1:0a7005226e61 | 234 | p.x -= x_off; |
richnash | 1:0a7005226e61 | 235 | p.x /= pp_tx; |
richnash | 1:0a7005226e61 | 236 | int w = TFT.width(); |
richnash | 1:0a7005226e61 | 237 | if (p.x > w) p.x = w; |
richnash | 1:0a7005226e61 | 238 | if (p.x < 0) p.x = 0; |
richnash | 1:0a7005226e61 | 239 | p.y -= y_off; |
richnash | 1:0a7005226e61 | 240 | p.y /= pp_ty; |
richnash | 1:0a7005226e61 | 241 | int h = TFT.height(); |
richnash | 1:0a7005226e61 | 242 | if (p.y > h) p.y = h; |
richnash | 1:0a7005226e61 | 243 | if (p.y < 0) p.y = 0; |
richnash | 1:0a7005226e61 | 244 | return (p); |
richnash | 1:0a7005226e61 | 245 | } |
richnash | 1:0a7005226e61 | 246 | |
richnash | 1:0a7005226e61 | 247 | bool getPixel(point& p) |
richnash | 1:0a7005226e61 | 248 | { |
richnash | 1:0a7005226e61 | 249 | TOUCH touch = getTouch(p); |
richnash | 1:0a7005226e61 | 250 | p = toPixel(p); |
richnash | 1:0a7005226e61 | 251 | return touch == YES; |
richnash | 1:0a7005226e61 | 252 | } |
richnash | 1:0a7005226e61 | 253 | |
richnash | 1:0a7005226e61 | 254 | |
richnash | 1:0a7005226e61 | 255 | // =================================================== |
Rhyme | 0:cd5e3d371b54 | 256 | |
Rhyme | 0:cd5e3d371b54 | 257 | void initTFT(void) |
Rhyme | 0:cd5e3d371b54 | 258 | { |
Rhyme | 0:cd5e3d371b54 | 259 | //Configure the display driver |
richnash | 1:0a7005226e61 | 260 | //TFT.BusEnable(true) ; |
Rhyme | 0:cd5e3d371b54 | 261 | TFT.FastWindow(true) ; |
Rhyme | 0:cd5e3d371b54 | 262 | TFT.background(Black); |
Rhyme | 0:cd5e3d371b54 | 263 | TFT.foreground(White); |
Rhyme | 0:cd5e3d371b54 | 264 | wait(0.01) ; |
Rhyme | 0:cd5e3d371b54 | 265 | TFT.cls(); |
richnash | 1:0a7005226e61 | 266 | //TFT.BusEnable(false) ; |
Rhyme | 0:cd5e3d371b54 | 267 | } |
Rhyme | 0:cd5e3d371b54 | 268 | |
Rhyme | 0:cd5e3d371b54 | 269 | void screen1(void) // Welcome Screen |
Rhyme | 0:cd5e3d371b54 | 270 | { |
richnash | 1:0a7005226e61 | 271 | //TFT.BusEnable(true) ; |
Rhyme | 0:cd5e3d371b54 | 272 | backlight = 0 ; |
Rhyme | 0:cd5e3d371b54 | 273 | TFT.background(White) ; |
Rhyme | 0:cd5e3d371b54 | 274 | wait(0.1) ; |
Rhyme | 0:cd5e3d371b54 | 275 | TFT.cls() ; |
Rhyme | 0:cd5e3d371b54 | 276 | wait(0.1) ; |
Rhyme | 0:cd5e3d371b54 | 277 | |
Rhyme | 0:cd5e3d371b54 | 278 | TFT.set_font((unsigned char*) Arial24x23); |
Rhyme | 0:cd5e3d371b54 | 279 | TFT.foreground(Red) ; |
Rhyme | 0:cd5e3d371b54 | 280 | TFT.locate(80, 40) ; |
Rhyme | 0:cd5e3d371b54 | 281 | TFT.printf("MBED") ; |
Rhyme | 0:cd5e3d371b54 | 282 | TFT.foreground(Blue); |
Rhyme | 0:cd5e3d371b54 | 283 | TFT.locate(60, 80) ; |
Rhyme | 0:cd5e3d371b54 | 284 | TFT.printf("2.8\"TFT") ; |
Rhyme | 0:cd5e3d371b54 | 285 | TFT.locate(40, 120) ; |
Rhyme | 0:cd5e3d371b54 | 286 | TFT.printf("with touch") ; |
Rhyme | 0:cd5e3d371b54 | 287 | TFT.foreground(Black); |
Rhyme | 0:cd5e3d371b54 | 288 | TFT.set_font((unsigned char*) Arial12x12); |
Rhyme | 0:cd5e3d371b54 | 289 | TFT.foreground(Blue) ; |
Rhyme | 0:cd5e3d371b54 | 290 | TFT.locate(30, 180) ; |
Rhyme | 0:cd5e3d371b54 | 291 | TFT.printf("This program is running on") ; |
Rhyme | 0:cd5e3d371b54 | 292 | TFT.locate(30, 200) ; |
Rhyme | 0:cd5e3d371b54 | 293 | TFT.printf("ST Nucleo F411RE with") ; |
Rhyme | 0:cd5e3d371b54 | 294 | TFT.locate(30, 220) ; |
Rhyme | 0:cd5e3d371b54 | 295 | TFT.printf("a program developed in mbed") ; |
Rhyme | 0:cd5e3d371b54 | 296 | TFT.foreground(Green) ; |
Rhyme | 0:cd5e3d371b54 | 297 | TFT.locate(30, 260) ; |
Rhyme | 0:cd5e3d371b54 | 298 | TFT.printf("To advance demo page, touch") ; |
Rhyme | 0:cd5e3d371b54 | 299 | TFT.locate(30, 280) ; |
Rhyme | 0:cd5e3d371b54 | 300 | TFT.printf("and hold right side of screen") ; |
Rhyme | 0:cd5e3d371b54 | 301 | TFT.locate(30, 300) ; |
Rhyme | 0:cd5e3d371b54 | 302 | TFT.printf("until the next screen starts") ; |
richnash | 1:0a7005226e61 | 303 | //TFT.BusEnable(false) ; |
Rhyme | 0:cd5e3d371b54 | 304 | backlight = 1 ; |
Rhyme | 0:cd5e3d371b54 | 305 | } |
Rhyme | 0:cd5e3d371b54 | 306 | |
Rhyme | 0:cd5e3d371b54 | 307 | void screen2(void) // Graphics |
Rhyme | 0:cd5e3d371b54 | 308 | { |
Rhyme | 0:cd5e3d371b54 | 309 | //Draw some graphics |
Rhyme | 0:cd5e3d371b54 | 310 | int i, x[2], y[2] ; |
Rhyme | 0:cd5e3d371b54 | 311 | backlight = 0 ; |
richnash | 1:0a7005226e61 | 312 | //TFT.BusEnable(true) ; |
Rhyme | 0:cd5e3d371b54 | 313 | TFT.background(Black); |
Rhyme | 0:cd5e3d371b54 | 314 | wait(0.1) ; |
Rhyme | 0:cd5e3d371b54 | 315 | TFT.foreground(White); |
Rhyme | 0:cd5e3d371b54 | 316 | wait(0.1) ; |
Rhyme | 0:cd5e3d371b54 | 317 | TFT.cls() ; |
Rhyme | 0:cd5e3d371b54 | 318 | wait(0.1) ; |
Rhyme | 0:cd5e3d371b54 | 319 | TFT.set_font((unsigned char*) Arial12x12); |
Rhyme | 0:cd5e3d371b54 | 320 | TFT.locate(90,0); |
Rhyme | 0:cd5e3d371b54 | 321 | TFT.printf("Graphics"); |
Rhyme | 0:cd5e3d371b54 | 322 | |
Rhyme | 0:cd5e3d371b54 | 323 | x[0] = 25 ; x[1] = 224 ; |
Rhyme | 0:cd5e3d371b54 | 324 | y[0] = 20 ; y[1] = 219 ; |
Rhyme | 0:cd5e3d371b54 | 325 | for (i = 20 ; i < 220 ; i += 10) { |
Rhyme | 0:cd5e3d371b54 | 326 | TFT.line(i+5, y[0], i+5, y[1], Blue) ; |
Rhyme | 0:cd5e3d371b54 | 327 | TFT.line(x[0], i, x[1], i, Blue) ; |
Rhyme | 0:cd5e3d371b54 | 328 | } |
Rhyme | 0:cd5e3d371b54 | 329 | TFT.line(125, y[0], 125, y[1], Green) ; |
Rhyme | 0:cd5e3d371b54 | 330 | TFT.line(x[0], 120, x[1], 120, Green) ; |
Rhyme | 0:cd5e3d371b54 | 331 | TFT.rect(x[0],y[0], x[1], y[1], Green) ; |
Rhyme | 0:cd5e3d371b54 | 332 | TFT.locate(10, 20) ; |
Rhyme | 0:cd5e3d371b54 | 333 | TFT.printf("V") ; |
Rhyme | 0:cd5e3d371b54 | 334 | TFT.locate(0, 115) ; |
Rhyme | 0:cd5e3d371b54 | 335 | TFT.printf("0.0") ; |
Rhyme | 0:cd5e3d371b54 | 336 | TFT.locate(115, 225) ; |
Rhyme | 0:cd5e3d371b54 | 337 | TFT.printf("0.0") ; |
Rhyme | 0:cd5e3d371b54 | 338 | TFT.locate(215, 225) ; |
Rhyme | 0:cd5e3d371b54 | 339 | TFT.printf("T") ; |
Rhyme | 0:cd5e3d371b54 | 340 | |
Rhyme | 0:cd5e3d371b54 | 341 | double s; |
Rhyme | 0:cd5e3d371b54 | 342 | for (int i = x[0]; i < 225; i++) { |
Rhyme | 0:cd5e3d371b54 | 343 | s = 40 * sin((long double)i / 20); |
Rhyme | 0:cd5e3d371b54 | 344 | TFT.pixel(i, 120 + (int)s, White); |
Rhyme | 0:cd5e3d371b54 | 345 | } |
Rhyme | 0:cd5e3d371b54 | 346 | |
Rhyme | 0:cd5e3d371b54 | 347 | TFT.fillrect(10, 240, 229, 309, White) ; |
Rhyme | 0:cd5e3d371b54 | 348 | TFT.rect(10, 240, 229, 309, Red) ; |
Rhyme | 0:cd5e3d371b54 | 349 | TFT.rect(11, 241, 228, 308, Red) ; |
Rhyme | 0:cd5e3d371b54 | 350 | |
Rhyme | 0:cd5e3d371b54 | 351 | TFT.background(White) ; |
Rhyme | 0:cd5e3d371b54 | 352 | TFT.foreground(Black) ; |
Rhyme | 0:cd5e3d371b54 | 353 | TFT.locate(20, 250) ; |
Rhyme | 0:cd5e3d371b54 | 354 | TFT.printf("With QVGA resolution") ; |
Rhyme | 0:cd5e3d371b54 | 355 | TFT.locate(20, 270) ; |
Rhyme | 0:cd5e3d371b54 | 356 | TFT.printf("simple graphics drawing") ; |
Rhyme | 0:cd5e3d371b54 | 357 | TFT.locate(20, 290) ; |
Rhyme | 0:cd5e3d371b54 | 358 | TFT.printf("capability is provided") ; |
richnash | 1:0a7005226e61 | 359 | //TFT.BusEnable(false) ; |
Rhyme | 0:cd5e3d371b54 | 360 | backlight = 1 ; |
Rhyme | 0:cd5e3d371b54 | 361 | } |
Rhyme | 0:cd5e3d371b54 | 362 | |
richnash | 1:0a7005226e61 | 363 | void screen3(void) // Graphics |
Rhyme | 0:cd5e3d371b54 | 364 | { |
richnash | 1:0a7005226e61 | 365 | //int rowX; |
richnash | 1:0a7005226e61 | 366 | int rowY; |
richnash | 1:0a7005226e61 | 367 | //int x = Terminal6x8[1]; |
richnash | 1:0a7005226e61 | 368 | int y = Terminal6x8[2]; |
richnash | 1:0a7005226e61 | 369 | |
richnash | 1:0a7005226e61 | 370 | //Draw some text |
richnash | 1:0a7005226e61 | 371 | backlight = 0 ; |
richnash | 1:0a7005226e61 | 372 | |
richnash | 1:0a7005226e61 | 373 | TFT.background(Black); |
richnash | 1:0a7005226e61 | 374 | wait(0.1) ; |
richnash | 1:0a7005226e61 | 375 | TFT.foreground(White); |
richnash | 1:0a7005226e61 | 376 | wait(0.1) ; |
richnash | 1:0a7005226e61 | 377 | TFT.cls() ; |
richnash | 1:0a7005226e61 | 378 | wait(0.1) ; |
richnash | 1:0a7005226e61 | 379 | |
richnash | 1:0a7005226e61 | 380 | backlight = 1 ; |
richnash | 1:0a7005226e61 | 381 | |
richnash | 1:0a7005226e61 | 382 | TFT.set_font((unsigned char*) Terminal6x8); |
richnash | 1:0a7005226e61 | 383 | |
richnash | 1:0a7005226e61 | 384 | for( rowY=0; rowY<100; ++rowY ) |
richnash | 1:0a7005226e61 | 385 | { |
richnash | 1:0a7005226e61 | 386 | TFT.locate(0, (rowY%25)*y); |
richnash | 1:0a7005226e61 | 387 | TFT.printf("%3d TFT width = %d, height = %d", rowY, TFT.width(), TFT.height()) ; |
richnash | 1:0a7005226e61 | 388 | } |
richnash | 1:0a7005226e61 | 389 | |
Rhyme | 0:cd5e3d371b54 | 390 | } |
Rhyme | 0:cd5e3d371b54 | 391 | |
Rhyme | 0:cd5e3d371b54 | 392 | void incPage(void) |
Rhyme | 0:cd5e3d371b54 | 393 | { |
Rhyme | 0:cd5e3d371b54 | 394 | page++ ; |
Rhyme | 0:cd5e3d371b54 | 395 | if (page >= numPage) { |
Rhyme | 0:cd5e3d371b54 | 396 | page = 0 ; |
Rhyme | 0:cd5e3d371b54 | 397 | } |
Rhyme | 0:cd5e3d371b54 | 398 | } |
Rhyme | 0:cd5e3d371b54 | 399 | |
Rhyme | 0:cd5e3d371b54 | 400 | void decPage(void) |
Rhyme | 0:cd5e3d371b54 | 401 | { |
Rhyme | 0:cd5e3d371b54 | 402 | page-- ; |
Rhyme | 0:cd5e3d371b54 | 403 | if (page < 0) { |
Rhyme | 0:cd5e3d371b54 | 404 | page = numPage - 1 ; |
Rhyme | 0:cd5e3d371b54 | 405 | } |
Rhyme | 0:cd5e3d371b54 | 406 | } |
Rhyme | 0:cd5e3d371b54 | 407 | |
Rhyme | 0:cd5e3d371b54 | 408 | int main() |
Rhyme | 0:cd5e3d371b54 | 409 | { |
richnash | 1:0a7005226e61 | 410 | point p; |
richnash | 1:0a7005226e61 | 411 | |
richnash | 1:0a7005226e61 | 412 | // setup the pc serial logger |
richnash | 1:0a7005226e61 | 413 | logger.baud(115200); |
richnash | 1:0a7005226e61 | 414 | logger.printf("\r\n\r\n<<<<<<<<< TFT SCREEN TEST >>>>>>>>>>>\r\n" ); |
richnash | 1:0a7005226e61 | 415 | |
Rhyme | 0:cd5e3d371b54 | 416 | int prevPage = 99 ; |
Rhyme | 0:cd5e3d371b54 | 417 | bool waitTouch = false ; |
Rhyme | 0:cd5e3d371b54 | 418 | |
richnash | 1:0a7005226e61 | 419 | initTFT() ; |
Rhyme | 0:cd5e3d371b54 | 420 | |
richnash | 1:0a7005226e61 | 421 | printf("Program Started!\n\r") ; |
richnash | 1:0a7005226e61 | 422 | printf("TFT width = %d, height = %d\n\r", TFT.width(), TFT.height()) ; |
Rhyme | 0:cd5e3d371b54 | 423 | |
richnash | 1:0a7005226e61 | 424 | //calibrate(); |
Rhyme | 0:cd5e3d371b54 | 425 | |
Rhyme | 0:cd5e3d371b54 | 426 | for(;;) { |
richnash | 1:0a7005226e61 | 427 | |
richnash | 1:0a7005226e61 | 428 | printf("page %d of %d\r\n", page, numPage ); |
richnash | 1:0a7005226e61 | 429 | |
Rhyme | 0:cd5e3d371b54 | 430 | switch(page) { |
Rhyme | 0:cd5e3d371b54 | 431 | case 0: |
Rhyme | 0:cd5e3d371b54 | 432 | if (prevPage != page) { |
Rhyme | 0:cd5e3d371b54 | 433 | screen1() ; |
Rhyme | 0:cd5e3d371b54 | 434 | } |
Rhyme | 0:cd5e3d371b54 | 435 | waitTouch = true ; |
Rhyme | 0:cd5e3d371b54 | 436 | break ; |
Rhyme | 0:cd5e3d371b54 | 437 | case 1: |
Rhyme | 0:cd5e3d371b54 | 438 | if (prevPage != page) { |
Rhyme | 0:cd5e3d371b54 | 439 | screen2() ; |
Rhyme | 0:cd5e3d371b54 | 440 | } |
Rhyme | 0:cd5e3d371b54 | 441 | waitTouch = true ; |
Rhyme | 0:cd5e3d371b54 | 442 | break ; |
richnash | 1:0a7005226e61 | 443 | case 2: |
richnash | 1:0a7005226e61 | 444 | if (prevPage != page) { |
richnash | 1:0a7005226e61 | 445 | screen3() ; |
richnash | 1:0a7005226e61 | 446 | } |
richnash | 1:0a7005226e61 | 447 | waitTouch = true ; |
richnash | 1:0a7005226e61 | 448 | break ; |
Rhyme | 0:cd5e3d371b54 | 449 | default: |
Rhyme | 0:cd5e3d371b54 | 450 | page = 0 ; |
Rhyme | 0:cd5e3d371b54 | 451 | break ; |
Rhyme | 0:cd5e3d371b54 | 452 | } |
Rhyme | 0:cd5e3d371b54 | 453 | prevPage = page ; |
richnash | 1:0a7005226e61 | 454 | |
richnash | 1:0a7005226e61 | 455 | do { |
richnash | 1:0a7005226e61 | 456 | if( getPixel(p) ) |
richnash | 1:0a7005226e61 | 457 | { |
richnash | 1:0a7005226e61 | 458 | printf("TFT Touch x = %d, y = %d\n\r", p.x, p.y) ; |
richnash | 1:0a7005226e61 | 459 | |
richnash | 1:0a7005226e61 | 460 | if (p.x < 100) |
richnash | 1:0a7005226e61 | 461 | { // left |
Rhyme | 0:cd5e3d371b54 | 462 | decPage() ; |
richnash | 1:0a7005226e61 | 463 | } |
richnash | 1:0a7005226e61 | 464 | else if (p.x > 150) |
richnash | 1:0a7005226e61 | 465 | { // right |
Rhyme | 0:cd5e3d371b54 | 466 | incPage() ; |
richnash | 1:0a7005226e61 | 467 | } |
Rhyme | 0:cd5e3d371b54 | 468 | waitTouch = false ; |
richnash | 1:0a7005226e61 | 469 | } |
richnash | 1:0a7005226e61 | 470 | } while(waitTouch != false) ; |
Rhyme | 0:cd5e3d371b54 | 471 | } |
Rhyme | 0:cd5e3d371b54 | 472 | } |