
This is our GFX example for the Adafruit ILI9341 Breakout and Shield ----> http://www.adafruit.com/products/1651 Check out the links above for our tutorials and wiring diagrams These displays use SPI to communicate, 4 or 5 pins are required to interface (RST is optional) Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. MIT license, all text above must be included in any redistribution
Dependencies: Adafruit_GFX_MBED Adafruit_ILI9341 BurstSPI mbed
main.cpp@1:ad0604ca8377, 2014-12-05 (annotated)
- Committer:
- infotech1
- Date:
- Fri Dec 05 06:50:21 2014 +0000
- Revision:
- 1:ad0604ca8377
- Parent:
- 0:0697cb7bb5a1
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
infotech1 | 1:ad0604ca8377 | 1 | /*************************************************** |
infotech1 | 1:ad0604ca8377 | 2 | This is our GFX example for the Adafruit ILI9341 Breakout and Shield |
infotech1 | 1:ad0604ca8377 | 3 | ----> http://www.adafruit.com/products/1651 |
infotech1 | 1:ad0604ca8377 | 4 | Check out the links above for our tutorials and wiring diagrams |
infotech1 | 1:ad0604ca8377 | 5 | These displays use SPI to communicate, 4 or 5 pins are required to |
infotech1 | 1:ad0604ca8377 | 6 | interface (RST is optional) |
infotech1 | 1:ad0604ca8377 | 7 | Adafruit invests time and resources providing this open source code, |
infotech1 | 1:ad0604ca8377 | 8 | please support Adafruit and open-source hardware by purchasing |
infotech1 | 1:ad0604ca8377 | 9 | products from Adafruit! |
infotech1 | 1:ad0604ca8377 | 10 | Written by Limor Fried/Ladyada for Adafruit Industries. |
infotech1 | 1:ad0604ca8377 | 11 | MIT license, all text above must be included in any redistribution |
infotech1 | 1:ad0604ca8377 | 12 | ****************************************************/ |
infotech1 | 1:ad0604ca8377 | 13 | /* |
infotech1 | 1:ad0604ca8377 | 14 | Ported to mbed by James Kidd |
infotech1 | 1:ad0604ca8377 | 15 | */ |
infotech1 | 1:ad0604ca8377 | 16 | |
infotech1 | 0:0697cb7bb5a1 | 17 | #include "mbed.h" |
infotech1 | 0:0697cb7bb5a1 | 18 | #include "Adafruit_ILI9341.h" |
infotech1 | 0:0697cb7bb5a1 | 19 | // Change to your dc/cs/rst pins |
infotech1 | 0:0697cb7bb5a1 | 20 | Adafruit_ILI9341 tft = Adafruit_ILI9341(D10,D9,D8); |
infotech1 | 0:0697cb7bb5a1 | 21 | |
infotech1 | 0:0697cb7bb5a1 | 22 | Serial pc(SERIAL_TX,SERIAL_RX); |
infotech1 | 0:0697cb7bb5a1 | 23 | |
infotech1 | 0:0697cb7bb5a1 | 24 | Timer t; |
infotech1 | 0:0697cb7bb5a1 | 25 | |
infotech1 | 0:0697cb7bb5a1 | 26 | int min(int x, int y) { |
infotech1 | 0:0697cb7bb5a1 | 27 | if(x > y) |
infotech1 | 0:0697cb7bb5a1 | 28 | return y; |
infotech1 | 0:0697cb7bb5a1 | 29 | return x; |
infotech1 | 0:0697cb7bb5a1 | 30 | } |
infotech1 | 0:0697cb7bb5a1 | 31 | |
infotech1 | 0:0697cb7bb5a1 | 32 | int testFillScreen() { |
infotech1 | 0:0697cb7bb5a1 | 33 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 34 | tft.fillScreen(ILI9341_RED); |
infotech1 | 0:0697cb7bb5a1 | 35 | tft.fillScreen(ILI9341_GREEN); |
infotech1 | 0:0697cb7bb5a1 | 36 | tft.fillScreen(ILI9341_BLUE); |
infotech1 | 0:0697cb7bb5a1 | 37 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 38 | return 1; |
infotech1 | 0:0697cb7bb5a1 | 39 | } |
infotech1 | 0:0697cb7bb5a1 | 40 | |
infotech1 | 0:0697cb7bb5a1 | 41 | int testText() { |
infotech1 | 0:0697cb7bb5a1 | 42 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 43 | unsigned long start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 44 | tft.setCursor(0, 0); |
infotech1 | 0:0697cb7bb5a1 | 45 | tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1); |
infotech1 | 0:0697cb7bb5a1 | 46 | tft.print("Hello World!"); |
infotech1 | 0:0697cb7bb5a1 | 47 | tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2); |
infotech1 | 0:0697cb7bb5a1 | 48 | tft.print(1234.56); |
infotech1 | 0:0697cb7bb5a1 | 49 | tft.setTextColor(ILI9341_RED); tft.setTextSize(3); |
infotech1 | 0:0697cb7bb5a1 | 50 | tft.print(0xDEADBEEF, 16); |
infotech1 | 0:0697cb7bb5a1 | 51 | tft.println(); |
infotech1 | 0:0697cb7bb5a1 | 52 | tft.setTextColor(ILI9341_GREEN); |
infotech1 | 0:0697cb7bb5a1 | 53 | tft.setTextSize(5); |
infotech1 | 0:0697cb7bb5a1 | 54 | tft.print("Groop"); |
infotech1 | 0:0697cb7bb5a1 | 55 | tft.setTextSize(2); |
infotech1 | 0:0697cb7bb5a1 | 56 | tft.print("I implore thee,"); |
infotech1 | 0:0697cb7bb5a1 | 57 | tft.setTextSize(1); |
infotech1 | 0:0697cb7bb5a1 | 58 | tft.print("my foonting turlingdromes."); |
infotech1 | 0:0697cb7bb5a1 | 59 | tft.print("And hooptiously drangle me"); |
infotech1 | 0:0697cb7bb5a1 | 60 | tft.print("with crinkly bindlewurdles,"); |
infotech1 | 0:0697cb7bb5a1 | 61 | tft.print("Or I will rend thee"); |
infotech1 | 0:0697cb7bb5a1 | 62 | tft.print("in the gobberwarts"); |
infotech1 | 0:0697cb7bb5a1 | 63 | tft.print("with my blurglecruncheon,"); |
infotech1 | 0:0697cb7bb5a1 | 64 | tft.print("see if I don't!"); |
infotech1 | 0:0697cb7bb5a1 | 65 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 66 | } |
infotech1 | 0:0697cb7bb5a1 | 67 | |
infotech1 | 0:0697cb7bb5a1 | 68 | int testLines(uint16_t color) { |
infotech1 | 0:0697cb7bb5a1 | 69 | unsigned long start, tt; |
infotech1 | 0:0697cb7bb5a1 | 70 | int x1, y1, x2, y2, |
infotech1 | 0:0697cb7bb5a1 | 71 | w = tft.width(), |
infotech1 | 0:0697cb7bb5a1 | 72 | h = tft.height(); |
infotech1 | 0:0697cb7bb5a1 | 73 | |
infotech1 | 0:0697cb7bb5a1 | 74 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 75 | |
infotech1 | 0:0697cb7bb5a1 | 76 | x1 = y1 = 0; |
infotech1 | 0:0697cb7bb5a1 | 77 | y2 = h - 1; |
infotech1 | 0:0697cb7bb5a1 | 78 | start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 79 | for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
infotech1 | 0:0697cb7bb5a1 | 80 | x2 = w - 1; |
infotech1 | 0:0697cb7bb5a1 | 81 | for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
infotech1 | 0:0697cb7bb5a1 | 82 | tt = 1; // fillScreen doesn't count against timing |
infotech1 | 0:0697cb7bb5a1 | 83 | |
infotech1 | 0:0697cb7bb5a1 | 84 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 85 | |
infotech1 | 0:0697cb7bb5a1 | 86 | x1 = w - 1; |
infotech1 | 0:0697cb7bb5a1 | 87 | y1 = 0; |
infotech1 | 0:0697cb7bb5a1 | 88 | y2 = h - 1; |
infotech1 | 0:0697cb7bb5a1 | 89 | start = 1; |
infotech1 | 0:0697cb7bb5a1 | 90 | for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
infotech1 | 0:0697cb7bb5a1 | 91 | x2 = 0; |
infotech1 | 0:0697cb7bb5a1 | 92 | for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
infotech1 | 0:0697cb7bb5a1 | 93 | tt += 1; |
infotech1 | 0:0697cb7bb5a1 | 94 | |
infotech1 | 0:0697cb7bb5a1 | 95 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 96 | |
infotech1 | 0:0697cb7bb5a1 | 97 | x1 = 0; |
infotech1 | 0:0697cb7bb5a1 | 98 | y1 = h - 1; |
infotech1 | 0:0697cb7bb5a1 | 99 | y2 = 0; |
infotech1 | 0:0697cb7bb5a1 | 100 | start = 1; |
infotech1 | 0:0697cb7bb5a1 | 101 | for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
infotech1 | 0:0697cb7bb5a1 | 102 | x2 = w - 1; |
infotech1 | 0:0697cb7bb5a1 | 103 | for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
infotech1 | 0:0697cb7bb5a1 | 104 | tt += 1; |
infotech1 | 0:0697cb7bb5a1 | 105 | |
infotech1 | 0:0697cb7bb5a1 | 106 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 107 | |
infotech1 | 0:0697cb7bb5a1 | 108 | x1 = w - 1; |
infotech1 | 0:0697cb7bb5a1 | 109 | y1 = h - 1; |
infotech1 | 0:0697cb7bb5a1 | 110 | y2 = 0; |
infotech1 | 0:0697cb7bb5a1 | 111 | start = 1; |
infotech1 | 0:0697cb7bb5a1 | 112 | for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
infotech1 | 0:0697cb7bb5a1 | 113 | x2 = 0; |
infotech1 | 0:0697cb7bb5a1 | 114 | for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
infotech1 | 0:0697cb7bb5a1 | 115 | |
infotech1 | 0:0697cb7bb5a1 | 116 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 117 | } |
infotech1 | 0:0697cb7bb5a1 | 118 | |
infotech1 | 0:0697cb7bb5a1 | 119 | int testFastLines(uint16_t color1, uint16_t color2) { |
infotech1 | 0:0697cb7bb5a1 | 120 | unsigned long start; |
infotech1 | 0:0697cb7bb5a1 | 121 | int x, y, w = tft.width(), h = tft.height(); |
infotech1 | 0:0697cb7bb5a1 | 122 | |
infotech1 | 0:0697cb7bb5a1 | 123 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 124 | start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 125 | for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1); |
infotech1 | 0:0697cb7bb5a1 | 126 | for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2); |
infotech1 | 0:0697cb7bb5a1 | 127 | |
infotech1 | 0:0697cb7bb5a1 | 128 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 129 | } |
infotech1 | 0:0697cb7bb5a1 | 130 | |
infotech1 | 0:0697cb7bb5a1 | 131 | int testRects(uint16_t color) { |
infotech1 | 0:0697cb7bb5a1 | 132 | unsigned long start; |
infotech1 | 0:0697cb7bb5a1 | 133 | int n, i, i2, |
infotech1 | 0:0697cb7bb5a1 | 134 | cx = tft.width() / 2, |
infotech1 | 0:0697cb7bb5a1 | 135 | cy = tft.height() / 2; |
infotech1 | 0:0697cb7bb5a1 | 136 | |
infotech1 | 0:0697cb7bb5a1 | 137 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 138 | n = min(tft.width(), tft.height()); |
infotech1 | 0:0697cb7bb5a1 | 139 | start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 140 | for(i=2; i<n; i+=6) { |
infotech1 | 0:0697cb7bb5a1 | 141 | i2 = i / 2; |
infotech1 | 0:0697cb7bb5a1 | 142 | tft.drawRect(cx-i2, cy-i2, i, i, color); |
infotech1 | 0:0697cb7bb5a1 | 143 | } |
infotech1 | 0:0697cb7bb5a1 | 144 | |
infotech1 | 0:0697cb7bb5a1 | 145 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 146 | } |
infotech1 | 0:0697cb7bb5a1 | 147 | |
infotech1 | 0:0697cb7bb5a1 | 148 | int testFilledRects(uint16_t color1, uint16_t color2) { |
infotech1 | 0:0697cb7bb5a1 | 149 | unsigned long start, tt = 0; |
infotech1 | 0:0697cb7bb5a1 | 150 | int n, i, i2, |
infotech1 | 0:0697cb7bb5a1 | 151 | cx = tft.width() / 2 - 1, |
infotech1 | 0:0697cb7bb5a1 | 152 | cy = tft.height() / 2 - 1; |
infotech1 | 0:0697cb7bb5a1 | 153 | |
infotech1 | 0:0697cb7bb5a1 | 154 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 155 | n = min(tft.width(), tft.height()); |
infotech1 | 0:0697cb7bb5a1 | 156 | start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 157 | for(i=n; i>0; i-=6) { |
infotech1 | 0:0697cb7bb5a1 | 158 | i2 = i / 2; |
infotech1 | 0:0697cb7bb5a1 | 159 | start = 1; |
infotech1 | 0:0697cb7bb5a1 | 160 | tft.fillRect(cx-i2, cy-i2, i, i, color1); |
infotech1 | 0:0697cb7bb5a1 | 161 | tt += 1; |
infotech1 | 0:0697cb7bb5a1 | 162 | // Outlines are not included in timing results |
infotech1 | 0:0697cb7bb5a1 | 163 | tft.drawRect(cx-i2, cy-i2, i, i, color2); |
infotech1 | 0:0697cb7bb5a1 | 164 | } |
infotech1 | 0:0697cb7bb5a1 | 165 | |
infotech1 | 0:0697cb7bb5a1 | 166 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 167 | } |
infotech1 | 0:0697cb7bb5a1 | 168 | |
infotech1 | 0:0697cb7bb5a1 | 169 | int testFilledCircles(uint8_t radius, uint16_t color) { |
infotech1 | 0:0697cb7bb5a1 | 170 | unsigned long start; |
infotech1 | 0:0697cb7bb5a1 | 171 | int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; |
infotech1 | 0:0697cb7bb5a1 | 172 | |
infotech1 | 0:0697cb7bb5a1 | 173 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 174 | start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 175 | for(x=radius; x<w; x+=r2) { |
infotech1 | 0:0697cb7bb5a1 | 176 | for(y=radius; y<h; y+=r2) { |
infotech1 | 0:0697cb7bb5a1 | 177 | tft.fillCircle(x, y, radius, color); |
infotech1 | 0:0697cb7bb5a1 | 178 | } |
infotech1 | 0:0697cb7bb5a1 | 179 | } |
infotech1 | 0:0697cb7bb5a1 | 180 | |
infotech1 | 0:0697cb7bb5a1 | 181 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 182 | } |
infotech1 | 0:0697cb7bb5a1 | 183 | |
infotech1 | 0:0697cb7bb5a1 | 184 | int testCircles(uint8_t radius, uint16_t color) { |
infotech1 | 0:0697cb7bb5a1 | 185 | unsigned long start; |
infotech1 | 0:0697cb7bb5a1 | 186 | int x, y, r2 = radius * 2, |
infotech1 | 0:0697cb7bb5a1 | 187 | w = tft.width() + radius, |
infotech1 | 0:0697cb7bb5a1 | 188 | h = tft.height() + radius; |
infotech1 | 0:0697cb7bb5a1 | 189 | |
infotech1 | 0:0697cb7bb5a1 | 190 | // Screen is not cleared for this one -- this is |
infotech1 | 0:0697cb7bb5a1 | 191 | // intentional and does not affect the reported time. |
infotech1 | 0:0697cb7bb5a1 | 192 | start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 193 | for(x=0; x<w; x+=r2) { |
infotech1 | 0:0697cb7bb5a1 | 194 | for(y=0; y<h; y+=r2) { |
infotech1 | 0:0697cb7bb5a1 | 195 | tft.drawCircle(x, y, radius, color); |
infotech1 | 0:0697cb7bb5a1 | 196 | } |
infotech1 | 0:0697cb7bb5a1 | 197 | } |
infotech1 | 0:0697cb7bb5a1 | 198 | |
infotech1 | 0:0697cb7bb5a1 | 199 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 200 | } |
infotech1 | 0:0697cb7bb5a1 | 201 | |
infotech1 | 0:0697cb7bb5a1 | 202 | int testTriangles() { |
infotech1 | 0:0697cb7bb5a1 | 203 | unsigned long start; |
infotech1 | 0:0697cb7bb5a1 | 204 | int n, i, cx = tft.width() / 2 - 1, |
infotech1 | 0:0697cb7bb5a1 | 205 | cy = tft.height() / 2 - 1; |
infotech1 | 0:0697cb7bb5a1 | 206 | |
infotech1 | 0:0697cb7bb5a1 | 207 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 208 | n = min(cx, cy); |
infotech1 | 0:0697cb7bb5a1 | 209 | start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 210 | for(i=0; i<n; i+=5) { |
infotech1 | 0:0697cb7bb5a1 | 211 | tft.drawTriangle( |
infotech1 | 0:0697cb7bb5a1 | 212 | cx , cy - i, // peak |
infotech1 | 0:0697cb7bb5a1 | 213 | cx - i, cy + i, // bottom left |
infotech1 | 0:0697cb7bb5a1 | 214 | cx + i, cy + i, // bottom right |
infotech1 | 0:0697cb7bb5a1 | 215 | tft.color565(0, 0, i)); |
infotech1 | 0:0697cb7bb5a1 | 216 | } |
infotech1 | 0:0697cb7bb5a1 | 217 | |
infotech1 | 0:0697cb7bb5a1 | 218 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 219 | } |
infotech1 | 0:0697cb7bb5a1 | 220 | |
infotech1 | 0:0697cb7bb5a1 | 221 | int testFilledTriangles() { |
infotech1 | 0:0697cb7bb5a1 | 222 | unsigned long start, tt = 0; |
infotech1 | 0:0697cb7bb5a1 | 223 | int i, cx = tft.width() / 2 - 1, |
infotech1 | 0:0697cb7bb5a1 | 224 | cy = tft.height() / 2 - 1; |
infotech1 | 0:0697cb7bb5a1 | 225 | |
infotech1 | 0:0697cb7bb5a1 | 226 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 227 | start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 228 | for(i=min(cx,cy); i>10; i-=5) { |
infotech1 | 0:0697cb7bb5a1 | 229 | start = 1; |
infotech1 | 0:0697cb7bb5a1 | 230 | tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, |
infotech1 | 0:0697cb7bb5a1 | 231 | tft.color565(0, i, i)); |
infotech1 | 0:0697cb7bb5a1 | 232 | tt += 1; |
infotech1 | 0:0697cb7bb5a1 | 233 | tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, |
infotech1 | 0:0697cb7bb5a1 | 234 | tft.color565(i, i, 0)); |
infotech1 | 0:0697cb7bb5a1 | 235 | } |
infotech1 | 0:0697cb7bb5a1 | 236 | |
infotech1 | 0:0697cb7bb5a1 | 237 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 238 | } |
infotech1 | 0:0697cb7bb5a1 | 239 | |
infotech1 | 0:0697cb7bb5a1 | 240 | int testRoundRects() { |
infotech1 | 0:0697cb7bb5a1 | 241 | unsigned long start; |
infotech1 | 0:0697cb7bb5a1 | 242 | int w, i, i2, |
infotech1 | 0:0697cb7bb5a1 | 243 | cx = tft.width() / 2 - 1, |
infotech1 | 0:0697cb7bb5a1 | 244 | cy = tft.height() / 2 - 1; |
infotech1 | 0:0697cb7bb5a1 | 245 | |
infotech1 | 0:0697cb7bb5a1 | 246 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 247 | w = min(tft.width(), tft.height()); |
infotech1 | 0:0697cb7bb5a1 | 248 | start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 249 | for(i=0; i<w; i+=6) { |
infotech1 | 0:0697cb7bb5a1 | 250 | i2 = i / 2; |
infotech1 | 0:0697cb7bb5a1 | 251 | tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0)); |
infotech1 | 0:0697cb7bb5a1 | 252 | } |
infotech1 | 0:0697cb7bb5a1 | 253 | |
infotech1 | 0:0697cb7bb5a1 | 254 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 255 | } |
infotech1 | 0:0697cb7bb5a1 | 256 | |
infotech1 | 0:0697cb7bb5a1 | 257 | |
infotech1 | 0:0697cb7bb5a1 | 258 | |
infotech1 | 0:0697cb7bb5a1 | 259 | int testFilledRoundRects() { |
infotech1 | 0:0697cb7bb5a1 | 260 | unsigned long start; |
infotech1 | 0:0697cb7bb5a1 | 261 | int i, i2, |
infotech1 | 0:0697cb7bb5a1 | 262 | cx = tft.width() / 2 - 1, |
infotech1 | 0:0697cb7bb5a1 | 263 | cy = tft.height() / 2 - 1; |
infotech1 | 0:0697cb7bb5a1 | 264 | |
infotech1 | 0:0697cb7bb5a1 | 265 | tft.fillScreen(ILI9341_BLACK); |
infotech1 | 0:0697cb7bb5a1 | 266 | start = t.read_ms(); |
infotech1 | 0:0697cb7bb5a1 | 267 | |
infotech1 | 0:0697cb7bb5a1 | 268 | for(i=min(tft.width(), tft.height()); i>20; i-=6) { |
infotech1 | 0:0697cb7bb5a1 | 269 | i2 = i / 2; |
infotech1 | 0:0697cb7bb5a1 | 270 | tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); |
infotech1 | 0:0697cb7bb5a1 | 271 | } |
infotech1 | 0:0697cb7bb5a1 | 272 | |
infotech1 | 0:0697cb7bb5a1 | 273 | return t.read_ms() - start; |
infotech1 | 0:0697cb7bb5a1 | 274 | } |
infotech1 | 0:0697cb7bb5a1 | 275 | |
infotech1 | 0:0697cb7bb5a1 | 276 | |
infotech1 | 0:0697cb7bb5a1 | 277 | int main() { |
infotech1 | 0:0697cb7bb5a1 | 278 | tft.begin(); |
infotech1 | 0:0697cb7bb5a1 | 279 | t.start(); |
infotech1 | 0:0697cb7bb5a1 | 280 | |
infotech1 | 0:0697cb7bb5a1 | 281 | while(1) { |
infotech1 | 0:0697cb7bb5a1 | 282 | pc.printf("Ili9341 test\n"); |
infotech1 | 0:0697cb7bb5a1 | 283 | uint8_t x = tft.readcommand8(ILI9341_RDMODE); |
infotech1 | 0:0697cb7bb5a1 | 284 | pc.printf("Display Power Mode: 0x"); pc.printf("%d\n",x); |
infotech1 | 0:0697cb7bb5a1 | 285 | x = tft.readcommand8(ILI9341_RDMADCTL); |
infotech1 | 0:0697cb7bb5a1 | 286 | pc.printf("MADCTL Mode: 0x"); pc.printf("%d\n",x); |
infotech1 | 0:0697cb7bb5a1 | 287 | x = tft.readcommand8(ILI9341_RDPIXFMT); |
infotech1 | 0:0697cb7bb5a1 | 288 | pc.printf("Pixel Format: 0x"); pc.printf("%d\n",x); |
infotech1 | 0:0697cb7bb5a1 | 289 | x = tft.readcommand8(ILI9341_RDIMGFMT); |
infotech1 | 0:0697cb7bb5a1 | 290 | pc.printf("Image Format: 0x"); pc.printf("%d\n",x); |
infotech1 | 0:0697cb7bb5a1 | 291 | x = tft.readcommand8(ILI9341_RDSELFDIAG); |
infotech1 | 0:0697cb7bb5a1 | 292 | pc.printf("Self Diagnostic: 0x"); pc.printf("%d\n",x); |
infotech1 | 0:0697cb7bb5a1 | 293 | |
infotech1 | 0:0697cb7bb5a1 | 294 | pc.printf(("Benchmark Time (microseconds)\n")); |
infotech1 | 0:0697cb7bb5a1 | 295 | |
infotech1 | 0:0697cb7bb5a1 | 296 | pc.printf(("Screen fill ")); |
infotech1 | 0:0697cb7bb5a1 | 297 | pc.printf("%d",testFillScreen()); |
infotech1 | 0:0697cb7bb5a1 | 298 | wait_ms(500); |
infotech1 | 0:0697cb7bb5a1 | 299 | |
infotech1 | 0:0697cb7bb5a1 | 300 | pc.printf(("Text ")); |
infotech1 | 0:0697cb7bb5a1 | 301 | pc.printf("%d\n",testText()); |
infotech1 | 0:0697cb7bb5a1 | 302 | wait_ms(3000); |
infotech1 | 0:0697cb7bb5a1 | 303 | |
infotech1 | 0:0697cb7bb5a1 | 304 | pc.printf(("Lines ")); |
infotech1 | 0:0697cb7bb5a1 | 305 | pc.printf("%d\n",testLines(ILI9341_CYAN)); |
infotech1 | 0:0697cb7bb5a1 | 306 | wait_ms(500); |
infotech1 | 0:0697cb7bb5a1 | 307 | |
infotech1 | 0:0697cb7bb5a1 | 308 | pc.printf(("Horiz/Vert Lines ")); |
infotech1 | 0:0697cb7bb5a1 | 309 | pc.printf("%d\n",testFastLines(ILI9341_RED, ILI9341_BLUE)); |
infotech1 | 0:0697cb7bb5a1 | 310 | wait_ms(500); |
infotech1 | 0:0697cb7bb5a1 | 311 | |
infotech1 | 0:0697cb7bb5a1 | 312 | pc.printf(("Rectangles (outline) ")); |
infotech1 | 0:0697cb7bb5a1 | 313 | pc.printf("%d\n",testRects(ILI9341_GREEN)); |
infotech1 | 0:0697cb7bb5a1 | 314 | wait_ms(500); |
infotech1 | 0:0697cb7bb5a1 | 315 | |
infotech1 | 0:0697cb7bb5a1 | 316 | pc.printf(("Rectangles (filled) ")); |
infotech1 | 0:0697cb7bb5a1 | 317 | pc.printf("%d\n",testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA)); |
infotech1 | 0:0697cb7bb5a1 | 318 | wait_ms(500); |
infotech1 | 0:0697cb7bb5a1 | 319 | |
infotech1 | 0:0697cb7bb5a1 | 320 | pc.printf(("Circles (filled) ")); |
infotech1 | 0:0697cb7bb5a1 | 321 | pc.printf("%d\n",testFilledCircles(10, ILI9341_MAGENTA)); |
infotech1 | 0:0697cb7bb5a1 | 322 | |
infotech1 | 0:0697cb7bb5a1 | 323 | pc.printf(("Circles (outline) ")); |
infotech1 | 0:0697cb7bb5a1 | 324 | pc.printf("%d\n",testCircles(10, ILI9341_WHITE)); |
infotech1 | 0:0697cb7bb5a1 | 325 | wait_ms(500); |
infotech1 | 0:0697cb7bb5a1 | 326 | |
infotech1 | 0:0697cb7bb5a1 | 327 | pc.printf(("Triangles (outline) ")); |
infotech1 | 0:0697cb7bb5a1 | 328 | pc.printf("%d\n",testTriangles()); |
infotech1 | 0:0697cb7bb5a1 | 329 | wait_ms(500); |
infotech1 | 0:0697cb7bb5a1 | 330 | |
infotech1 | 0:0697cb7bb5a1 | 331 | pc.printf(("Triangles (filled) ")); |
infotech1 | 0:0697cb7bb5a1 | 332 | pc.printf("%d\n",testFilledTriangles()); |
infotech1 | 0:0697cb7bb5a1 | 333 | wait_ms(500); |
infotech1 | 0:0697cb7bb5a1 | 334 | tft.fillScreen(ILI9341_WHITE); |
infotech1 | 0:0697cb7bb5a1 | 335 | pc.printf(("Rounded rects (outline) ")); |
infotech1 | 0:0697cb7bb5a1 | 336 | pc.printf("%d\n",testRoundRects()); |
infotech1 | 0:0697cb7bb5a1 | 337 | wait_ms(500); |
infotech1 | 0:0697cb7bb5a1 | 338 | |
infotech1 | 0:0697cb7bb5a1 | 339 | pc.printf(("Rounded rects (filled) ")); |
infotech1 | 0:0697cb7bb5a1 | 340 | pc.printf("%d\n",testFilledRoundRects()); |
infotech1 | 0:0697cb7bb5a1 | 341 | wait_ms(500); |
infotech1 | 0:0697cb7bb5a1 | 342 | |
infotech1 | 0:0697cb7bb5a1 | 343 | pc.printf(("Done!")); |
infotech1 | 0:0697cb7bb5a1 | 344 | } |
infotech1 | 0:0697cb7bb5a1 | 345 | } |