![](/media/cache/profiles/0d382a5fec7012c843c1bdfb0935c9a6.50x50_q85.jpg)
My first mbed-os 5.x test project with MAX32630FTHR and Adafruit 2.4" TFT with touch.
Dependencies: BMI160 SPI_STMPE610 USBDevice UniGraphic max32630fthr
My first test program of mbed-os 5.x, using MAX32630FTHR and Adafruit 2.4" TFT with Touch.
On 22-Sep-2017 Monitoring both Acc and Gyr added to the screen 3 Controlling the backlight via STMPE610 GPIO-2 added
main.cpp@0:a4d7417f7672, 2017-09-21 (annotated)
- Committer:
- Rhyme
- Date:
- Thu Sep 21 05:16:39 2017 +0000
- Revision:
- 0:a4d7417f7672
- Child:
- 1:a890937c9c30
first working version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:a4d7417f7672 | 1 | /** |
Rhyme | 0:a4d7417f7672 | 2 | * TFT test MAX32630FTHR |
Rhyme | 0:a4d7417f7672 | 3 | * MCU Board: MAX32630FTHR |
Rhyme | 0:a4d7417f7672 | 4 | * TFT Module: Adafruit 2.4 TFT with touch |
Rhyme | 0:a4d7417f7672 | 5 | */ |
Rhyme | 0:a4d7417f7672 | 6 | #include "mbed.h" |
Rhyme | 0:a4d7417f7672 | 7 | #include "max32630fthr.h" |
Rhyme | 0:a4d7417f7672 | 8 | #include "USBSerial.h" |
Rhyme | 0:a4d7417f7672 | 9 | #include "ILI9341.h" |
Rhyme | 0:a4d7417f7672 | 10 | #include "SPI_STMPE610.h" |
Rhyme | 0:a4d7417f7672 | 11 | #include "Arial12x12.h" |
Rhyme | 0:a4d7417f7672 | 12 | #include "Arial24x23.h" |
Rhyme | 0:a4d7417f7672 | 13 | #include "Arial28x28.h" |
Rhyme | 0:a4d7417f7672 | 14 | #include "Arial43x48_numb.h" |
Rhyme | 0:a4d7417f7672 | 15 | #include "BMI160.h" |
Rhyme | 0:a4d7417f7672 | 16 | |
Rhyme | 0:a4d7417f7672 | 17 | #define PIN_MOSI SPI2_MOSI |
Rhyme | 0:a4d7417f7672 | 18 | #define PIN_MISO SPI2_MISO |
Rhyme | 0:a4d7417f7672 | 19 | #define PIN_SCLK SPI2_SCK |
Rhyme | 0:a4d7417f7672 | 20 | #define PIN_TSC_CS P3_3 |
Rhyme | 0:a4d7417f7672 | 21 | #define PIN_CS_TFT P5_3 |
Rhyme | 0:a4d7417f7672 | 22 | #define PIN_RESET_TFT P1_7 // dummy |
Rhyme | 0:a4d7417f7672 | 23 | #define PIN_DC_TFT P5_4 |
Rhyme | 0:a4d7417f7672 | 24 | #define PIN_LED_R P2_4 |
Rhyme | 0:a4d7417f7672 | 25 | #define PIN_LED_G P2_5 |
Rhyme | 0:a4d7417f7672 | 26 | #define PIN_LED_B P2_6 |
Rhyme | 0:a4d7417f7672 | 27 | #define PIN_RX2 P2_0 |
Rhyme | 0:a4d7417f7672 | 28 | #define PIN_TX2 P2_1 |
Rhyme | 0:a4d7417f7672 | 29 | #define PIN_SDA2 P5_7 |
Rhyme | 0:a4d7417f7672 | 30 | #define PIN_SCL2 P6_0 |
Rhyme | 0:a4d7417f7672 | 31 | #define BMI160_I2C_ADDRESS 0x68 |
Rhyme | 0:a4d7417f7672 | 32 | |
Rhyme | 0:a4d7417f7672 | 33 | MAX32630FTHR *sakura = 0 ; |
Rhyme | 0:a4d7417f7672 | 34 | ILI9341 *tft = 0 ; |
Rhyme | 0:a4d7417f7672 | 35 | SPI_STMPE610 *tsc = 0 ; |
Rhyme | 0:a4d7417f7672 | 36 | DigitalOut *ledR = 0 ; |
Rhyme | 0:a4d7417f7672 | 37 | DigitalOut *ledG = 0 ; |
Rhyme | 0:a4d7417f7672 | 38 | DigitalOut *ledB = 0 ; |
Rhyme | 0:a4d7417f7672 | 39 | BMI160 *acc = 0 ; |
Rhyme | 0:a4d7417f7672 | 40 | |
Rhyme | 0:a4d7417f7672 | 41 | // Hardware serial port over DAPLink |
Rhyme | 0:a4d7417f7672 | 42 | // Serial daplink(P2_1, P2_0); |
Rhyme | 0:a4d7417f7672 | 43 | |
Rhyme | 0:a4d7417f7672 | 44 | // Virtual serial port over USB |
Rhyme | 0:a4d7417f7672 | 45 | USBSerial *tty = 0 ; |
Rhyme | 0:a4d7417f7672 | 46 | // USBSerial microUSB; |
Rhyme | 0:a4d7417f7672 | 47 | |
Rhyme | 0:a4d7417f7672 | 48 | int page = 0 ; |
Rhyme | 0:a4d7417f7672 | 49 | int numPage = 4 ; |
Rhyme | 0:a4d7417f7672 | 50 | |
Rhyme | 0:a4d7417f7672 | 51 | extern void doMaze(void) ; |
Rhyme | 0:a4d7417f7672 | 52 | |
Rhyme | 0:a4d7417f7672 | 53 | void init_hardware(void) |
Rhyme | 0:a4d7417f7672 | 54 | { |
Rhyme | 0:a4d7417f7672 | 55 | sakura = new MAX32630FTHR(MAX32630FTHR::VIO_3V3) ; |
Rhyme | 0:a4d7417f7672 | 56 | tty = new USBSerial() ; |
Rhyme | 0:a4d7417f7672 | 57 | tsc = new SPI_STMPE610(SPI2_MOSI, SPI2_MISO, SPI2_SCK, PIN_TSC_CS) ; |
Rhyme | 0:a4d7417f7672 | 58 | tsc->spi_format(8, 0) ; |
Rhyme | 0:a4d7417f7672 | 59 | tsc->calibrate(3552, 400, 439, 3680) ; |
Rhyme | 0:a4d7417f7672 | 60 | tft = new ILI9341(SPI_8, 16000000, |
Rhyme | 0:a4d7417f7672 | 61 | SPI2_MOSI, SPI2_MISO, SPI2_SCK, |
Rhyme | 0:a4d7417f7672 | 62 | PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.4") ; |
Rhyme | 0:a4d7417f7672 | 63 | ledR = new DigitalOut(PIN_LED_R) ; |
Rhyme | 0:a4d7417f7672 | 64 | ledG = new DigitalOut(PIN_LED_G) ; |
Rhyme | 0:a4d7417f7672 | 65 | ledB = new DigitalOut(PIN_LED_B) ; |
Rhyme | 0:a4d7417f7672 | 66 | acc = new BMI160(PIN_SDA2, PIN_SCL2, BMI160_I2C_ADDRESS) ; |
Rhyme | 0:a4d7417f7672 | 67 | // acc_set_pmu_mode 0x10 | ACC_PMU_XXX |
Rhyme | 0:a4d7417f7672 | 68 | acc->setCMD(0x10 | ACC_PMU_NORMAL) ; |
Rhyme | 0:a4d7417f7672 | 69 | Thread::wait(100) ; |
Rhyme | 0:a4d7417f7672 | 70 | acc->setCMD(0x14 | GYR_PMU_NORMAL) ; |
Rhyme | 0:a4d7417f7672 | 71 | Thread::wait(100) ; |
Rhyme | 0:a4d7417f7672 | 72 | acc->setCMD(0x08 | MAG_PMU_SUSPEND) ; |
Rhyme | 0:a4d7417f7672 | 73 | Thread::wait(100) ; |
Rhyme | 0:a4d7417f7672 | 74 | acc->setCMD(0x03) ; /* start_foc */ |
Rhyme | 0:a4d7417f7672 | 75 | Thread::wait(100) ; |
Rhyme | 0:a4d7417f7672 | 76 | } |
Rhyme | 0:a4d7417f7672 | 77 | |
Rhyme | 0:a4d7417f7672 | 78 | void initTFT(void) |
Rhyme | 0:a4d7417f7672 | 79 | { |
Rhyme | 0:a4d7417f7672 | 80 | //Configure the display driver |
Rhyme | 0:a4d7417f7672 | 81 | tft->BusEnable(true) ; |
Rhyme | 0:a4d7417f7672 | 82 | tft->FastWindow(true) ; |
Rhyme | 0:a4d7417f7672 | 83 | tft->background(Black); |
Rhyme | 0:a4d7417f7672 | 84 | tft->foreground(White); |
Rhyme | 0:a4d7417f7672 | 85 | Thread::wait(0.01) ; |
Rhyme | 0:a4d7417f7672 | 86 | tft->cls(); |
Rhyme | 0:a4d7417f7672 | 87 | tft->BusEnable(false) ; |
Rhyme | 0:a4d7417f7672 | 88 | } |
Rhyme | 0:a4d7417f7672 | 89 | |
Rhyme | 0:a4d7417f7672 | 90 | void screen1(void) // Welcome Screen |
Rhyme | 0:a4d7417f7672 | 91 | { |
Rhyme | 0:a4d7417f7672 | 92 | tft->BusEnable(true) ; |
Rhyme | 0:a4d7417f7672 | 93 | // backlight = 0 ; |
Rhyme | 0:a4d7417f7672 | 94 | tft->background(White) ; |
Rhyme | 0:a4d7417f7672 | 95 | wait(0.1) ; |
Rhyme | 0:a4d7417f7672 | 96 | tft->cls() ; |
Rhyme | 0:a4d7417f7672 | 97 | wait(0.1) ; |
Rhyme | 0:a4d7417f7672 | 98 | |
Rhyme | 0:a4d7417f7672 | 99 | tft->set_font((unsigned char*) Arial24x23); |
Rhyme | 0:a4d7417f7672 | 100 | tft->foreground(Red) ; |
Rhyme | 0:a4d7417f7672 | 101 | tft->locate(80, 40) ; |
Rhyme | 0:a4d7417f7672 | 102 | tft->printf("MBED") ; |
Rhyme | 0:a4d7417f7672 | 103 | tft->foreground(Blue); |
Rhyme | 0:a4d7417f7672 | 104 | tft->locate(60, 80) ; |
Rhyme | 0:a4d7417f7672 | 105 | tft->printf("2.4\"TFT") ; |
Rhyme | 0:a4d7417f7672 | 106 | tft->locate(40, 120) ; |
Rhyme | 0:a4d7417f7672 | 107 | tft->printf("with touch") ; |
Rhyme | 0:a4d7417f7672 | 108 | tft->foreground(Black); |
Rhyme | 0:a4d7417f7672 | 109 | tft->set_font((unsigned char*) Arial12x12); |
Rhyme | 0:a4d7417f7672 | 110 | tft->foreground(Blue) ; |
Rhyme | 0:a4d7417f7672 | 111 | tft->locate(30, 180) ; |
Rhyme | 0:a4d7417f7672 | 112 | tft->printf("This program is running on") ; |
Rhyme | 0:a4d7417f7672 | 113 | tft->locate(30, 200) ; |
Rhyme | 0:a4d7417f7672 | 114 | tft->printf("Maxim MAX32630FTHR with") ; |
Rhyme | 0:a4d7417f7672 | 115 | tft->locate(30, 220) ; |
Rhyme | 0:a4d7417f7672 | 116 | tft->printf("a program developed in mbed") ; |
Rhyme | 0:a4d7417f7672 | 117 | tft->foreground(Green) ; |
Rhyme | 0:a4d7417f7672 | 118 | tft->locate(30, 260) ; |
Rhyme | 0:a4d7417f7672 | 119 | tft->printf("To advance demo page, touch") ; |
Rhyme | 0:a4d7417f7672 | 120 | tft->locate(30, 280) ; |
Rhyme | 0:a4d7417f7672 | 121 | tft->printf("and hold right side of screen") ; |
Rhyme | 0:a4d7417f7672 | 122 | tft->locate(30, 300) ; |
Rhyme | 0:a4d7417f7672 | 123 | tft->printf("until the next screen starts") ; |
Rhyme | 0:a4d7417f7672 | 124 | tft->BusEnable(false) ; |
Rhyme | 0:a4d7417f7672 | 125 | // backlight = 1 ; |
Rhyme | 0:a4d7417f7672 | 126 | } |
Rhyme | 0:a4d7417f7672 | 127 | |
Rhyme | 0:a4d7417f7672 | 128 | |
Rhyme | 0:a4d7417f7672 | 129 | void screen2(void) // Graphics |
Rhyme | 0:a4d7417f7672 | 130 | { |
Rhyme | 0:a4d7417f7672 | 131 | //Draw some graphics |
Rhyme | 0:a4d7417f7672 | 132 | int i, x[2], y[2] ; |
Rhyme | 0:a4d7417f7672 | 133 | // backlight = 0 ; |
Rhyme | 0:a4d7417f7672 | 134 | tft->BusEnable(true) ; |
Rhyme | 0:a4d7417f7672 | 135 | tft->background(Black); |
Rhyme | 0:a4d7417f7672 | 136 | wait(0.1) ; |
Rhyme | 0:a4d7417f7672 | 137 | tft->foreground(White); |
Rhyme | 0:a4d7417f7672 | 138 | wait(0.1) ; |
Rhyme | 0:a4d7417f7672 | 139 | tft->cls() ; |
Rhyme | 0:a4d7417f7672 | 140 | wait(0.1) ; |
Rhyme | 0:a4d7417f7672 | 141 | tft->set_font((unsigned char*) Arial12x12); |
Rhyme | 0:a4d7417f7672 | 142 | tft->locate(90,0); |
Rhyme | 0:a4d7417f7672 | 143 | tft->printf("Graphics"); |
Rhyme | 0:a4d7417f7672 | 144 | |
Rhyme | 0:a4d7417f7672 | 145 | x[0] = 25 ; x[1] = 224 ; |
Rhyme | 0:a4d7417f7672 | 146 | y[0] = 20 ; y[1] = 219 ; |
Rhyme | 0:a4d7417f7672 | 147 | for (i = 20 ; i < 220 ; i += 10) { |
Rhyme | 0:a4d7417f7672 | 148 | tft->line(i+5, y[0], i+5, y[1], Blue) ; |
Rhyme | 0:a4d7417f7672 | 149 | tft->line(x[0], i, x[1], i, Blue) ; |
Rhyme | 0:a4d7417f7672 | 150 | } |
Rhyme | 0:a4d7417f7672 | 151 | tft->line(125, y[0], 125, y[1], Green) ; |
Rhyme | 0:a4d7417f7672 | 152 | tft->line(x[0], 120, x[1], 120, Green) ; |
Rhyme | 0:a4d7417f7672 | 153 | tft->rect(x[0],y[0], x[1], y[1], Green) ; |
Rhyme | 0:a4d7417f7672 | 154 | tft->locate(10, 20) ; |
Rhyme | 0:a4d7417f7672 | 155 | tft->printf("V") ; |
Rhyme | 0:a4d7417f7672 | 156 | tft->locate(0, 115) ; |
Rhyme | 0:a4d7417f7672 | 157 | tft->printf("0.0") ; |
Rhyme | 0:a4d7417f7672 | 158 | tft->locate(115, 225) ; |
Rhyme | 0:a4d7417f7672 | 159 | tft->printf("0.0") ; |
Rhyme | 0:a4d7417f7672 | 160 | tft->locate(215, 225) ; |
Rhyme | 0:a4d7417f7672 | 161 | tft->printf("T") ; |
Rhyme | 0:a4d7417f7672 | 162 | |
Rhyme | 0:a4d7417f7672 | 163 | double s; |
Rhyme | 0:a4d7417f7672 | 164 | for (int i = x[0]; i < 225; i++) { |
Rhyme | 0:a4d7417f7672 | 165 | s = 40 * sin((long double)i / 20); |
Rhyme | 0:a4d7417f7672 | 166 | tft->pixel(i, 120 + (int)s, White); |
Rhyme | 0:a4d7417f7672 | 167 | } |
Rhyme | 0:a4d7417f7672 | 168 | |
Rhyme | 0:a4d7417f7672 | 169 | tft->fillrect(10, 240, 229, 309, White) ; |
Rhyme | 0:a4d7417f7672 | 170 | tft->rect(10, 240, 229, 309, Red) ; |
Rhyme | 0:a4d7417f7672 | 171 | tft->rect(11, 241, 228, 308, Red) ; |
Rhyme | 0:a4d7417f7672 | 172 | |
Rhyme | 0:a4d7417f7672 | 173 | tft->background(White) ; |
Rhyme | 0:a4d7417f7672 | 174 | tft->foreground(Black) ; |
Rhyme | 0:a4d7417f7672 | 175 | tft->locate(20, 250) ; |
Rhyme | 0:a4d7417f7672 | 176 | tft->printf("With QVGA resolution") ; |
Rhyme | 0:a4d7417f7672 | 177 | tft->locate(20, 270) ; |
Rhyme | 0:a4d7417f7672 | 178 | tft->printf("simple graphics drawing") ; |
Rhyme | 0:a4d7417f7672 | 179 | tft->locate(20, 290) ; |
Rhyme | 0:a4d7417f7672 | 180 | tft->printf("capability is provided") ; |
Rhyme | 0:a4d7417f7672 | 181 | tft->BusEnable(false) ; |
Rhyme | 0:a4d7417f7672 | 182 | // backlight = 1 ; |
Rhyme | 0:a4d7417f7672 | 183 | } |
Rhyme | 0:a4d7417f7672 | 184 | |
Rhyme | 0:a4d7417f7672 | 185 | double clip(double src) |
Rhyme | 0:a4d7417f7672 | 186 | { |
Rhyme | 0:a4d7417f7672 | 187 | double value ; |
Rhyme | 0:a4d7417f7672 | 188 | value = src ; |
Rhyme | 0:a4d7417f7672 | 189 | if (value < 0.0) { |
Rhyme | 0:a4d7417f7672 | 190 | value = 0.0 ; |
Rhyme | 0:a4d7417f7672 | 191 | } else if (value > 2.0) { |
Rhyme | 0:a4d7417f7672 | 192 | value = 2.0 ; |
Rhyme | 0:a4d7417f7672 | 193 | } |
Rhyme | 0:a4d7417f7672 | 194 | return( value ) ; |
Rhyme | 0:a4d7417f7672 | 195 | } |
Rhyme | 0:a4d7417f7672 | 196 | |
Rhyme | 0:a4d7417f7672 | 197 | void screen3(void) |
Rhyme | 0:a4d7417f7672 | 198 | { |
Rhyme | 0:a4d7417f7672 | 199 | int t = 0 ; |
Rhyme | 0:a4d7417f7672 | 200 | int pt = 0 ; // previous t |
Rhyme | 0:a4d7417f7672 | 201 | int i, x, y ; |
Rhyme | 0:a4d7417f7672 | 202 | unsigned int data[3] ; // for x, y, z |
Rhyme | 0:a4d7417f7672 | 203 | unsigned int prev[3] ; |
Rhyme | 0:a4d7417f7672 | 204 | unsigned short signalHeight = 39 ; |
Rhyme | 0:a4d7417f7672 | 205 | unsigned short xoffset = 30 ; |
Rhyme | 0:a4d7417f7672 | 206 | unsigned short yoffset = 120 ; |
Rhyme | 0:a4d7417f7672 | 207 | unsigned short zoffset = 210 ; |
Rhyme | 0:a4d7417f7672 | 208 | unsigned short paneX[2] = {20, 235} ; |
Rhyme | 0:a4d7417f7672 | 209 | unsigned short paneH = 81 ; |
Rhyme | 0:a4d7417f7672 | 210 | float value[3] ; |
Rhyme | 0:a4d7417f7672 | 211 | float acc_range ; |
Rhyme | 0:a4d7417f7672 | 212 | |
Rhyme | 0:a4d7417f7672 | 213 | // backlight = 1 ; |
Rhyme | 0:a4d7417f7672 | 214 | acc_range = (float)acc->getAccRange() ; |
Rhyme | 0:a4d7417f7672 | 215 | tft->BusEnable(true) ; |
Rhyme | 0:a4d7417f7672 | 216 | tft->background(Black) ; |
Rhyme | 0:a4d7417f7672 | 217 | tft->foreground(White) ; |
Rhyme | 0:a4d7417f7672 | 218 | // tft->cls() ; |
Rhyme | 0:a4d7417f7672 | 219 | |
Rhyme | 0:a4d7417f7672 | 220 | |
Rhyme | 0:a4d7417f7672 | 221 | tft->fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ; |
Rhyme | 0:a4d7417f7672 | 222 | tft->fillrect(paneX[0], yoffset, paneX[1], yoffset+paneH, Black) ; |
Rhyme | 0:a4d7417f7672 | 223 | tft->fillrect(paneX[0], zoffset, paneX[1], zoffset+paneH, Black) ; |
Rhyme | 0:a4d7417f7672 | 224 | tft->fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ; |
Rhyme | 0:a4d7417f7672 | 225 | for (i = 0 ; i < 10 ; i++ ) { |
Rhyme | 0:a4d7417f7672 | 226 | y = i * 8 ; |
Rhyme | 0:a4d7417f7672 | 227 | tft->line(paneX[0], xoffset + y, paneX[1], xoffset + y, Blue) ; |
Rhyme | 0:a4d7417f7672 | 228 | tft->line(paneX[0], yoffset + y, paneX[1], yoffset + y, Blue) ; |
Rhyme | 0:a4d7417f7672 | 229 | tft->line(paneX[0], zoffset + y, paneX[1], zoffset + y, Blue) ; |
Rhyme | 0:a4d7417f7672 | 230 | } |
Rhyme | 0:a4d7417f7672 | 231 | for (x = 30 ; x < paneX[1] ; x += 10 ) { |
Rhyme | 0:a4d7417f7672 | 232 | tft->line(x, xoffset, x, xoffset+paneH, Blue) ; |
Rhyme | 0:a4d7417f7672 | 233 | tft->line(x, yoffset, x, yoffset+paneH, Blue) ; |
Rhyme | 0:a4d7417f7672 | 234 | tft->line(x, zoffset, x, zoffset+paneH, Blue) ; |
Rhyme | 0:a4d7417f7672 | 235 | } |
Rhyme | 0:a4d7417f7672 | 236 | tft->rect(paneX[0], xoffset, paneX[1], xoffset+paneH, White) ; |
Rhyme | 0:a4d7417f7672 | 237 | tft->rect(paneX[0], yoffset, paneX[1], yoffset+paneH, White) ; |
Rhyme | 0:a4d7417f7672 | 238 | tft->rect(paneX[0], zoffset, paneX[1], zoffset+paneH, White) ; |
Rhyme | 0:a4d7417f7672 | 239 | tft->set_font((unsigned char*) Arial12x12); |
Rhyme | 0:a4d7417f7672 | 240 | tft->locate(5, xoffset+30) ; |
Rhyme | 0:a4d7417f7672 | 241 | tft->printf("X") ; |
Rhyme | 0:a4d7417f7672 | 242 | tft->locate(5, yoffset+30) ; |
Rhyme | 0:a4d7417f7672 | 243 | tft->printf("Y") ; |
Rhyme | 0:a4d7417f7672 | 244 | tft->locate(5, zoffset+30) ; |
Rhyme | 0:a4d7417f7672 | 245 | tft->printf("Z") ; |
Rhyme | 0:a4d7417f7672 | 246 | tft->locate(70, 10) ; |
Rhyme | 0:a4d7417f7672 | 247 | tft->printf("MAX32630FTHR") ; |
Rhyme | 0:a4d7417f7672 | 248 | tft->locate(90, 300) ; |
Rhyme | 0:a4d7417f7672 | 249 | tft->printf("BMI160") ; |
Rhyme | 0:a4d7417f7672 | 250 | |
Rhyme | 0:a4d7417f7672 | 251 | acc->getAcc(value) ; |
Rhyme | 0:a4d7417f7672 | 252 | prev[0] = xoffset + (signalHeight * clip((acc_range + value[0])/(acc_range * 1.1))) ; |
Rhyme | 0:a4d7417f7672 | 253 | prev[1] = yoffset + (signalHeight * clip((acc_range + value[1])/(acc_range * 1.1))) ; |
Rhyme | 0:a4d7417f7672 | 254 | prev[2] = zoffset + (signalHeight * clip((acc_range + value[2])/(acc_range * 1.1))) ; |
Rhyme | 0:a4d7417f7672 | 255 | pt = paneX[0] ; |
Rhyme | 0:a4d7417f7672 | 256 | // backlight = 1 ; |
Rhyme | 0:a4d7417f7672 | 257 | for(t = 21 ; t < paneX[1] ; t++) { |
Rhyme | 0:a4d7417f7672 | 258 | acc->getAcc(value) ; |
Rhyme | 0:a4d7417f7672 | 259 | data[0] = xoffset + (signalHeight * clip((acc_range + value[0])/(acc_range * 1.1))) ; |
Rhyme | 0:a4d7417f7672 | 260 | data[1] = yoffset + (signalHeight * clip((acc_range + value[1])/(acc_range * 1.1))) ; |
Rhyme | 0:a4d7417f7672 | 261 | data[2] = zoffset + (signalHeight * clip((acc_range + value[2])/(acc_range * 1.1))) ; |
Rhyme | 0:a4d7417f7672 | 262 | tft->line(pt, prev[0], t, data[0], Red) ; |
Rhyme | 0:a4d7417f7672 | 263 | tft->line(pt, prev[1], t, data[1], Green) ; |
Rhyme | 0:a4d7417f7672 | 264 | tft->line(pt, prev[2], t, data[2], Yellow) ; |
Rhyme | 0:a4d7417f7672 | 265 | prev[0] = data[0] ; |
Rhyme | 0:a4d7417f7672 | 266 | prev[1] = data[1] ; |
Rhyme | 0:a4d7417f7672 | 267 | prev[2] = data[2] ; |
Rhyme | 0:a4d7417f7672 | 268 | pt = t ; |
Rhyme | 0:a4d7417f7672 | 269 | Thread::wait(20) ; |
Rhyme | 0:a4d7417f7672 | 270 | } |
Rhyme | 0:a4d7417f7672 | 271 | tft->BusEnable(false) ; |
Rhyme | 0:a4d7417f7672 | 272 | } |
Rhyme | 0:a4d7417f7672 | 273 | |
Rhyme | 0:a4d7417f7672 | 274 | void incPage(void) |
Rhyme | 0:a4d7417f7672 | 275 | { |
Rhyme | 0:a4d7417f7672 | 276 | page++ ; |
Rhyme | 0:a4d7417f7672 | 277 | if (page >= numPage) { |
Rhyme | 0:a4d7417f7672 | 278 | page = 0 ; |
Rhyme | 0:a4d7417f7672 | 279 | } |
Rhyme | 0:a4d7417f7672 | 280 | } |
Rhyme | 0:a4d7417f7672 | 281 | |
Rhyme | 0:a4d7417f7672 | 282 | void decPage(void) |
Rhyme | 0:a4d7417f7672 | 283 | { |
Rhyme | 0:a4d7417f7672 | 284 | page-- ; |
Rhyme | 0:a4d7417f7672 | 285 | if (page < 0) { |
Rhyme | 0:a4d7417f7672 | 286 | page = numPage - 1 ; |
Rhyme | 0:a4d7417f7672 | 287 | } |
Rhyme | 0:a4d7417f7672 | 288 | } |
Rhyme | 0:a4d7417f7672 | 289 | |
Rhyme | 0:a4d7417f7672 | 290 | // main() runs in its own thread in the OS |
Rhyme | 0:a4d7417f7672 | 291 | // (note the calls to Thread::wait below for delays) |
Rhyme | 0:a4d7417f7672 | 292 | int main() |
Rhyme | 0:a4d7417f7672 | 293 | { |
Rhyme | 0:a4d7417f7672 | 294 | int prevPage = 99 ; |
Rhyme | 0:a4d7417f7672 | 295 | bool waitTouch = false ; |
Rhyme | 0:a4d7417f7672 | 296 | uint16_t x, y, z ; |
Rhyme | 0:a4d7417f7672 | 297 | |
Rhyme | 0:a4d7417f7672 | 298 | init_hardware() ; |
Rhyme | 0:a4d7417f7672 | 299 | initTFT() ; |
Rhyme | 0:a4d7417f7672 | 300 | |
Rhyme | 0:a4d7417f7672 | 301 | tty->printf("MAX32630 test (%s)\n", __DATE__) ; |
Rhyme | 0:a4d7417f7672 | 302 | tft->cls() ; |
Rhyme | 0:a4d7417f7672 | 303 | for(;;) { |
Rhyme | 0:a4d7417f7672 | 304 | switch(page) { |
Rhyme | 0:a4d7417f7672 | 305 | case 0: |
Rhyme | 0:a4d7417f7672 | 306 | if (prevPage != page) { |
Rhyme | 0:a4d7417f7672 | 307 | screen1() ; |
Rhyme | 0:a4d7417f7672 | 308 | } |
Rhyme | 0:a4d7417f7672 | 309 | waitTouch = true ; |
Rhyme | 0:a4d7417f7672 | 310 | break ; |
Rhyme | 0:a4d7417f7672 | 311 | case 1: |
Rhyme | 0:a4d7417f7672 | 312 | if (prevPage != page) { |
Rhyme | 0:a4d7417f7672 | 313 | screen2() ; |
Rhyme | 0:a4d7417f7672 | 314 | } |
Rhyme | 0:a4d7417f7672 | 315 | waitTouch = true ; |
Rhyme | 0:a4d7417f7672 | 316 | break ; |
Rhyme | 0:a4d7417f7672 | 317 | case 2: |
Rhyme | 0:a4d7417f7672 | 318 | if (prevPage != page) { |
Rhyme | 0:a4d7417f7672 | 319 | tft->BusEnable(true) ; |
Rhyme | 0:a4d7417f7672 | 320 | tft->background(Black) ; |
Rhyme | 0:a4d7417f7672 | 321 | tft->foreground(White) ; |
Rhyme | 0:a4d7417f7672 | 322 | tft->cls() ; |
Rhyme | 0:a4d7417f7672 | 323 | tft->BusEnable(false) ; |
Rhyme | 0:a4d7417f7672 | 324 | } |
Rhyme | 0:a4d7417f7672 | 325 | screen3() ; |
Rhyme | 0:a4d7417f7672 | 326 | waitTouch = false ; |
Rhyme | 0:a4d7417f7672 | 327 | break ; |
Rhyme | 0:a4d7417f7672 | 328 | case 3: |
Rhyme | 0:a4d7417f7672 | 329 | if (prevPage != page) { |
Rhyme | 0:a4d7417f7672 | 330 | doMaze() ; |
Rhyme | 0:a4d7417f7672 | 331 | waitTouch = true ; |
Rhyme | 0:a4d7417f7672 | 332 | } |
Rhyme | 0:a4d7417f7672 | 333 | break ; |
Rhyme | 0:a4d7417f7672 | 334 | default: |
Rhyme | 0:a4d7417f7672 | 335 | page = 0 ; |
Rhyme | 0:a4d7417f7672 | 336 | break ; |
Rhyme | 0:a4d7417f7672 | 337 | } |
Rhyme | 0:a4d7417f7672 | 338 | prevPage = page ; |
Rhyme | 0:a4d7417f7672 | 339 | |
Rhyme | 0:a4d7417f7672 | 340 | do { |
Rhyme | 0:a4d7417f7672 | 341 | tsc->getPoint(&x, &y, &z) ; |
Rhyme | 0:a4d7417f7672 | 342 | if ((x != 0)&&(y != 0)) { |
Rhyme | 0:a4d7417f7672 | 343 | tty->printf("%d, %d, %d\n", x, y, z) ; |
Rhyme | 0:a4d7417f7672 | 344 | if (x < 50) { // left |
Rhyme | 0:a4d7417f7672 | 345 | decPage() ; |
Rhyme | 0:a4d7417f7672 | 346 | } else if (x > 190) { // right |
Rhyme | 0:a4d7417f7672 | 347 | incPage() ; |
Rhyme | 0:a4d7417f7672 | 348 | } |
Rhyme | 0:a4d7417f7672 | 349 | waitTouch = false ; |
Rhyme | 0:a4d7417f7672 | 350 | } |
Rhyme | 0:a4d7417f7672 | 351 | } while(waitTouch != false) ; |
Rhyme | 0:a4d7417f7672 | 352 | |
Rhyme | 0:a4d7417f7672 | 353 | Thread::wait(100) ; |
Rhyme | 0:a4d7417f7672 | 354 | } |
Rhyme | 0:a4d7417f7672 | 355 | } |
Rhyme | 0:a4d7417f7672 | 356 |