![](/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@3:43de31beea45, 2017-09-22 (annotated)
- Committer:
- Rhyme
- Date:
- Fri Sep 22 05:35:56 2017 +0000
- Revision:
- 3:43de31beea45
- Parent:
- 2:d810dbdd716b
some backlight control added
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 | 1:a890937c9c30 | 33 | #define USE_TTY 1 |
Rhyme | 1:a890937c9c30 | 34 | |
Rhyme | 0:a4d7417f7672 | 35 | MAX32630FTHR *sakura = 0 ; |
Rhyme | 0:a4d7417f7672 | 36 | ILI9341 *tft = 0 ; |
Rhyme | 0:a4d7417f7672 | 37 | SPI_STMPE610 *tsc = 0 ; |
Rhyme | 0:a4d7417f7672 | 38 | DigitalOut *ledR = 0 ; |
Rhyme | 0:a4d7417f7672 | 39 | DigitalOut *ledG = 0 ; |
Rhyme | 0:a4d7417f7672 | 40 | DigitalOut *ledB = 0 ; |
Rhyme | 0:a4d7417f7672 | 41 | BMI160 *acc = 0 ; |
Rhyme | 0:a4d7417f7672 | 42 | |
Rhyme | 0:a4d7417f7672 | 43 | // Hardware serial port over DAPLink |
Rhyme | 0:a4d7417f7672 | 44 | // Serial daplink(P2_1, P2_0); |
Rhyme | 0:a4d7417f7672 | 45 | |
Rhyme | 0:a4d7417f7672 | 46 | // Virtual serial port over USB |
Rhyme | 0:a4d7417f7672 | 47 | USBSerial *tty = 0 ; |
Rhyme | 0:a4d7417f7672 | 48 | // USBSerial microUSB; |
Rhyme | 0:a4d7417f7672 | 49 | |
Rhyme | 0:a4d7417f7672 | 50 | int page = 0 ; |
Rhyme | 0:a4d7417f7672 | 51 | int numPage = 4 ; |
Rhyme | 0:a4d7417f7672 | 52 | |
Rhyme | 0:a4d7417f7672 | 53 | extern void doMaze(void) ; |
Rhyme | 0:a4d7417f7672 | 54 | |
Rhyme | 2:d810dbdd716b | 55 | void backlight(int value) |
Rhyme | 2:d810dbdd716b | 56 | { |
Rhyme | 2:d810dbdd716b | 57 | uint8_t data[2] ; |
Rhyme | 2:d810dbdd716b | 58 | data[1] = 0x04 ; // GPIO-2 as target pin |
Rhyme | 2:d810dbdd716b | 59 | if (value) { /* backlight on */ |
Rhyme | 2:d810dbdd716b | 60 | data[0] = 0x10 ; // GPIO_SET_PIN |
Rhyme | 2:d810dbdd716b | 61 | } else { |
Rhyme | 2:d810dbdd716b | 62 | data[0] = 0x11 ; // GPIO_CLR_PIN |
Rhyme | 2:d810dbdd716b | 63 | } |
Rhyme | 2:d810dbdd716b | 64 | tsc->writeRegs(data, 2) ; |
Rhyme | 2:d810dbdd716b | 65 | } |
Rhyme | 2:d810dbdd716b | 66 | |
Rhyme | 0:a4d7417f7672 | 67 | void init_hardware(void) |
Rhyme | 0:a4d7417f7672 | 68 | { |
Rhyme | 0:a4d7417f7672 | 69 | sakura = new MAX32630FTHR(MAX32630FTHR::VIO_3V3) ; |
Rhyme | 1:a890937c9c30 | 70 | Thread::wait(0.1) ; |
Rhyme | 1:a890937c9c30 | 71 | sakura->init(MAX32630FTHR::VIO_3V3) ; |
Rhyme | 1:a890937c9c30 | 72 | #if USE_TTY |
Rhyme | 0:a4d7417f7672 | 73 | tty = new USBSerial() ; |
Rhyme | 1:a890937c9c30 | 74 | #endif |
Rhyme | 1:a890937c9c30 | 75 | tft = new ILI9341(SPI_8, 16000000, |
Rhyme | 1:a890937c9c30 | 76 | SPI2_MOSI, SPI2_MISO, SPI2_SCK, |
Rhyme | 1:a890937c9c30 | 77 | PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.4") ; |
Rhyme | 1:a890937c9c30 | 78 | tft->BusEnable(false) ; |
Rhyme | 1:a890937c9c30 | 79 | wait(0.1) ; |
Rhyme | 1:a890937c9c30 | 80 | |
Rhyme | 0:a4d7417f7672 | 81 | tsc = new SPI_STMPE610(SPI2_MOSI, SPI2_MISO, SPI2_SCK, PIN_TSC_CS) ; |
Rhyme | 0:a4d7417f7672 | 82 | tsc->spi_format(8, 0) ; |
Rhyme | 0:a4d7417f7672 | 83 | tsc->calibrate(3552, 400, 439, 3680) ; |
Rhyme | 2:d810dbdd716b | 84 | /* enable tsc's gpio-2 for backlight */ |
Rhyme | 2:d810dbdd716b | 85 | uint8_t data[2] ; |
Rhyme | 2:d810dbdd716b | 86 | data[0] = 0x17 ; // GPIO_ALT_FUNC |
Rhyme | 2:d810dbdd716b | 87 | data[1] = 0x04 ; // GPIO-2 to be GPIO |
Rhyme | 2:d810dbdd716b | 88 | tsc->writeRegs(data, 2) ; |
Rhyme | 2:d810dbdd716b | 89 | data[0] = 0x13 ; // GPIO_DIR |
Rhyme | 2:d810dbdd716b | 90 | data[1] = 0x04 ; // GPIO-2 as output |
Rhyme | 2:d810dbdd716b | 91 | tsc->writeRegs(data, 2) ; |
Rhyme | 1:a890937c9c30 | 92 | |
Rhyme | 0:a4d7417f7672 | 93 | ledR = new DigitalOut(PIN_LED_R) ; |
Rhyme | 0:a4d7417f7672 | 94 | ledG = new DigitalOut(PIN_LED_G) ; |
Rhyme | 0:a4d7417f7672 | 95 | ledB = new DigitalOut(PIN_LED_B) ; |
Rhyme | 0:a4d7417f7672 | 96 | acc = new BMI160(PIN_SDA2, PIN_SCL2, BMI160_I2C_ADDRESS) ; |
Rhyme | 0:a4d7417f7672 | 97 | // acc_set_pmu_mode 0x10 | ACC_PMU_XXX |
Rhyme | 0:a4d7417f7672 | 98 | acc->setCMD(0x10 | ACC_PMU_NORMAL) ; |
Rhyme | 0:a4d7417f7672 | 99 | Thread::wait(100) ; |
Rhyme | 0:a4d7417f7672 | 100 | acc->setCMD(0x14 | GYR_PMU_NORMAL) ; |
Rhyme | 0:a4d7417f7672 | 101 | Thread::wait(100) ; |
Rhyme | 0:a4d7417f7672 | 102 | acc->setCMD(0x08 | MAG_PMU_SUSPEND) ; |
Rhyme | 0:a4d7417f7672 | 103 | Thread::wait(100) ; |
Rhyme | 0:a4d7417f7672 | 104 | acc->setCMD(0x03) ; /* start_foc */ |
Rhyme | 0:a4d7417f7672 | 105 | Thread::wait(100) ; |
Rhyme | 0:a4d7417f7672 | 106 | } |
Rhyme | 0:a4d7417f7672 | 107 | |
Rhyme | 0:a4d7417f7672 | 108 | void initTFT(void) |
Rhyme | 0:a4d7417f7672 | 109 | { |
Rhyme | 0:a4d7417f7672 | 110 | //Configure the display driver |
Rhyme | 0:a4d7417f7672 | 111 | tft->BusEnable(true) ; |
Rhyme | 0:a4d7417f7672 | 112 | tft->FastWindow(true) ; |
Rhyme | 0:a4d7417f7672 | 113 | tft->background(Black); |
Rhyme | 0:a4d7417f7672 | 114 | tft->foreground(White); |
Rhyme | 0:a4d7417f7672 | 115 | Thread::wait(0.01) ; |
Rhyme | 0:a4d7417f7672 | 116 | tft->cls(); |
Rhyme | 0:a4d7417f7672 | 117 | tft->BusEnable(false) ; |
Rhyme | 0:a4d7417f7672 | 118 | } |
Rhyme | 0:a4d7417f7672 | 119 | |
Rhyme | 0:a4d7417f7672 | 120 | void screen1(void) // Welcome Screen |
Rhyme | 0:a4d7417f7672 | 121 | { |
Rhyme | 0:a4d7417f7672 | 122 | tft->BusEnable(true) ; |
Rhyme | 0:a4d7417f7672 | 123 | // backlight = 0 ; |
Rhyme | 2:d810dbdd716b | 124 | backlight(0) ; |
Rhyme | 0:a4d7417f7672 | 125 | tft->background(White) ; |
Rhyme | 0:a4d7417f7672 | 126 | wait(0.1) ; |
Rhyme | 0:a4d7417f7672 | 127 | tft->cls() ; |
Rhyme | 0:a4d7417f7672 | 128 | wait(0.1) ; |
Rhyme | 0:a4d7417f7672 | 129 | |
Rhyme | 0:a4d7417f7672 | 130 | tft->set_font((unsigned char*) Arial24x23); |
Rhyme | 0:a4d7417f7672 | 131 | tft->foreground(Red) ; |
Rhyme | 0:a4d7417f7672 | 132 | tft->locate(80, 40) ; |
Rhyme | 0:a4d7417f7672 | 133 | tft->printf("MBED") ; |
Rhyme | 0:a4d7417f7672 | 134 | tft->foreground(Blue); |
Rhyme | 0:a4d7417f7672 | 135 | tft->locate(60, 80) ; |
Rhyme | 0:a4d7417f7672 | 136 | tft->printf("2.4\"TFT") ; |
Rhyme | 0:a4d7417f7672 | 137 | tft->locate(40, 120) ; |
Rhyme | 0:a4d7417f7672 | 138 | tft->printf("with touch") ; |
Rhyme | 0:a4d7417f7672 | 139 | tft->foreground(Black); |
Rhyme | 0:a4d7417f7672 | 140 | tft->set_font((unsigned char*) Arial12x12); |
Rhyme | 0:a4d7417f7672 | 141 | tft->foreground(Blue) ; |
Rhyme | 0:a4d7417f7672 | 142 | tft->locate(30, 180) ; |
Rhyme | 0:a4d7417f7672 | 143 | tft->printf("This program is running on") ; |
Rhyme | 0:a4d7417f7672 | 144 | tft->locate(30, 200) ; |
Rhyme | 0:a4d7417f7672 | 145 | tft->printf("Maxim MAX32630FTHR with") ; |
Rhyme | 0:a4d7417f7672 | 146 | tft->locate(30, 220) ; |
Rhyme | 0:a4d7417f7672 | 147 | tft->printf("a program developed in mbed") ; |
Rhyme | 0:a4d7417f7672 | 148 | tft->foreground(Green) ; |
Rhyme | 0:a4d7417f7672 | 149 | tft->locate(30, 260) ; |
Rhyme | 0:a4d7417f7672 | 150 | tft->printf("To advance demo page, touch") ; |
Rhyme | 0:a4d7417f7672 | 151 | tft->locate(30, 280) ; |
Rhyme | 0:a4d7417f7672 | 152 | tft->printf("and hold right side of screen") ; |
Rhyme | 0:a4d7417f7672 | 153 | tft->locate(30, 300) ; |
Rhyme | 0:a4d7417f7672 | 154 | tft->printf("until the next screen starts") ; |
Rhyme | 0:a4d7417f7672 | 155 | tft->BusEnable(false) ; |
Rhyme | 0:a4d7417f7672 | 156 | // backlight = 1 ; |
Rhyme | 2:d810dbdd716b | 157 | backlight(1) ; |
Rhyme | 0:a4d7417f7672 | 158 | } |
Rhyme | 0:a4d7417f7672 | 159 | |
Rhyme | 0:a4d7417f7672 | 160 | |
Rhyme | 0:a4d7417f7672 | 161 | void screen2(void) // Graphics |
Rhyme | 0:a4d7417f7672 | 162 | { |
Rhyme | 0:a4d7417f7672 | 163 | //Draw some graphics |
Rhyme | 0:a4d7417f7672 | 164 | int i, x[2], y[2] ; |
Rhyme | 0:a4d7417f7672 | 165 | // backlight = 0 ; |
Rhyme | 2:d810dbdd716b | 166 | backlight(0) ; |
Rhyme | 0:a4d7417f7672 | 167 | tft->BusEnable(true) ; |
Rhyme | 0:a4d7417f7672 | 168 | tft->background(Black); |
Rhyme | 0:a4d7417f7672 | 169 | wait(0.1) ; |
Rhyme | 0:a4d7417f7672 | 170 | tft->foreground(White); |
Rhyme | 0:a4d7417f7672 | 171 | wait(0.1) ; |
Rhyme | 0:a4d7417f7672 | 172 | tft->cls() ; |
Rhyme | 0:a4d7417f7672 | 173 | wait(0.1) ; |
Rhyme | 0:a4d7417f7672 | 174 | tft->set_font((unsigned char*) Arial12x12); |
Rhyme | 0:a4d7417f7672 | 175 | tft->locate(90,0); |
Rhyme | 0:a4d7417f7672 | 176 | tft->printf("Graphics"); |
Rhyme | 0:a4d7417f7672 | 177 | |
Rhyme | 0:a4d7417f7672 | 178 | x[0] = 25 ; x[1] = 224 ; |
Rhyme | 0:a4d7417f7672 | 179 | y[0] = 20 ; y[1] = 219 ; |
Rhyme | 0:a4d7417f7672 | 180 | for (i = 20 ; i < 220 ; i += 10) { |
Rhyme | 0:a4d7417f7672 | 181 | tft->line(i+5, y[0], i+5, y[1], Blue) ; |
Rhyme | 0:a4d7417f7672 | 182 | tft->line(x[0], i, x[1], i, Blue) ; |
Rhyme | 0:a4d7417f7672 | 183 | } |
Rhyme | 0:a4d7417f7672 | 184 | tft->line(125, y[0], 125, y[1], Green) ; |
Rhyme | 0:a4d7417f7672 | 185 | tft->line(x[0], 120, x[1], 120, Green) ; |
Rhyme | 0:a4d7417f7672 | 186 | tft->rect(x[0],y[0], x[1], y[1], Green) ; |
Rhyme | 0:a4d7417f7672 | 187 | tft->locate(10, 20) ; |
Rhyme | 0:a4d7417f7672 | 188 | tft->printf("V") ; |
Rhyme | 0:a4d7417f7672 | 189 | tft->locate(0, 115) ; |
Rhyme | 0:a4d7417f7672 | 190 | tft->printf("0.0") ; |
Rhyme | 0:a4d7417f7672 | 191 | tft->locate(115, 225) ; |
Rhyme | 0:a4d7417f7672 | 192 | tft->printf("0.0") ; |
Rhyme | 0:a4d7417f7672 | 193 | tft->locate(215, 225) ; |
Rhyme | 0:a4d7417f7672 | 194 | tft->printf("T") ; |
Rhyme | 0:a4d7417f7672 | 195 | |
Rhyme | 0:a4d7417f7672 | 196 | double s; |
Rhyme | 0:a4d7417f7672 | 197 | for (int i = x[0]; i < 225; i++) { |
Rhyme | 0:a4d7417f7672 | 198 | s = 40 * sin((long double)i / 20); |
Rhyme | 0:a4d7417f7672 | 199 | tft->pixel(i, 120 + (int)s, White); |
Rhyme | 0:a4d7417f7672 | 200 | } |
Rhyme | 0:a4d7417f7672 | 201 | |
Rhyme | 0:a4d7417f7672 | 202 | tft->fillrect(10, 240, 229, 309, White) ; |
Rhyme | 0:a4d7417f7672 | 203 | tft->rect(10, 240, 229, 309, Red) ; |
Rhyme | 0:a4d7417f7672 | 204 | tft->rect(11, 241, 228, 308, Red) ; |
Rhyme | 0:a4d7417f7672 | 205 | |
Rhyme | 0:a4d7417f7672 | 206 | tft->background(White) ; |
Rhyme | 0:a4d7417f7672 | 207 | tft->foreground(Black) ; |
Rhyme | 0:a4d7417f7672 | 208 | tft->locate(20, 250) ; |
Rhyme | 0:a4d7417f7672 | 209 | tft->printf("With QVGA resolution") ; |
Rhyme | 0:a4d7417f7672 | 210 | tft->locate(20, 270) ; |
Rhyme | 0:a4d7417f7672 | 211 | tft->printf("simple graphics drawing") ; |
Rhyme | 0:a4d7417f7672 | 212 | tft->locate(20, 290) ; |
Rhyme | 0:a4d7417f7672 | 213 | tft->printf("capability is provided") ; |
Rhyme | 0:a4d7417f7672 | 214 | tft->BusEnable(false) ; |
Rhyme | 0:a4d7417f7672 | 215 | // backlight = 1 ; |
Rhyme | 2:d810dbdd716b | 216 | backlight(1) ; |
Rhyme | 0:a4d7417f7672 | 217 | } |
Rhyme | 0:a4d7417f7672 | 218 | |
Rhyme | 1:a890937c9c30 | 219 | float clip(float src) |
Rhyme | 0:a4d7417f7672 | 220 | { |
Rhyme | 1:a890937c9c30 | 221 | float value ; |
Rhyme | 0:a4d7417f7672 | 222 | value = src ; |
Rhyme | 1:a890937c9c30 | 223 | if (value < (float)0.0) { |
Rhyme | 1:a890937c9c30 | 224 | value = (float)0.0 ; |
Rhyme | 1:a890937c9c30 | 225 | } else if (value > (float)2.0) { |
Rhyme | 1:a890937c9c30 | 226 | value = (float)2.0 ; |
Rhyme | 0:a4d7417f7672 | 227 | } |
Rhyme | 0:a4d7417f7672 | 228 | return( value ) ; |
Rhyme | 0:a4d7417f7672 | 229 | } |
Rhyme | 0:a4d7417f7672 | 230 | |
Rhyme | 0:a4d7417f7672 | 231 | void screen3(void) |
Rhyme | 0:a4d7417f7672 | 232 | { |
Rhyme | 1:a890937c9c30 | 233 | const int num_signal = 6 ; |
Rhyme | 0:a4d7417f7672 | 234 | int t = 0 ; |
Rhyme | 0:a4d7417f7672 | 235 | int pt = 0 ; // previous t |
Rhyme | 1:a890937c9c30 | 236 | int i, s, x, y ; |
Rhyme | 1:a890937c9c30 | 237 | unsigned int data[num_signal] ; // for x, y, z |
Rhyme | 1:a890937c9c30 | 238 | unsigned int prev[num_signal] ; |
Rhyme | 1:a890937c9c30 | 239 | unsigned short signalHeight = 19 ; // 39 ; |
Rhyme | 1:a890937c9c30 | 240 | unsigned short voffset[num_signal] = { 30, 80, 130, 180, 230, 280 } ; // for x, y, z |
Rhyme | 1:a890937c9c30 | 241 | unsigned short color[num_signal] = { Red, Green, Yellow, Red, Green, Yellow } ; |
Rhyme | 1:a890937c9c30 | 242 | char *label[num_signal] = { "X", "Y", "Z", "x", "y", "z" } ; |
Rhyme | 0:a4d7417f7672 | 243 | unsigned short paneX[2] = {20, 235} ; |
Rhyme | 1:a890937c9c30 | 244 | unsigned short paneH = 41 ; // 81 ; |
Rhyme | 1:a890937c9c30 | 245 | float value[num_signal] ; |
Rhyme | 0:a4d7417f7672 | 246 | float acc_range ; |
Rhyme | 1:a890937c9c30 | 247 | float gyr_range ; |
Rhyme | 0:a4d7417f7672 | 248 | |
Rhyme | 0:a4d7417f7672 | 249 | // backlight = 1 ; |
Rhyme | 2:d810dbdd716b | 250 | backlight(1) ; |
Rhyme | 0:a4d7417f7672 | 251 | acc_range = (float)acc->getAccRange() ; |
Rhyme | 1:a890937c9c30 | 252 | gyr_range = (float)acc->getGyrRange() ; |
Rhyme | 0:a4d7417f7672 | 253 | tft->BusEnable(true) ; |
Rhyme | 0:a4d7417f7672 | 254 | tft->background(Black) ; |
Rhyme | 0:a4d7417f7672 | 255 | tft->foreground(White) ; |
Rhyme | 0:a4d7417f7672 | 256 | // tft->cls() ; |
Rhyme | 0:a4d7417f7672 | 257 | |
Rhyme | 1:a890937c9c30 | 258 | for (s = 0 ; s < num_signal ; s++ ) { |
Rhyme | 1:a890937c9c30 | 259 | tft->fillrect(paneX[0], voffset[s], paneX[1], voffset[s]+paneH, Black) ; |
Rhyme | 1:a890937c9c30 | 260 | } |
Rhyme | 0:a4d7417f7672 | 261 | for (i = 0 ; i < 10 ; i++ ) { |
Rhyme | 1:a890937c9c30 | 262 | y = i * 4 ; // i * 8 ; |
Rhyme | 1:a890937c9c30 | 263 | for (s = 0 ; s < num_signal ; s++) { |
Rhyme | 1:a890937c9c30 | 264 | tft->line(paneX[0], voffset[s] + y, paneX[1], voffset[s] + y, Blue) ; |
Rhyme | 1:a890937c9c30 | 265 | } |
Rhyme | 0:a4d7417f7672 | 266 | } |
Rhyme | 0:a4d7417f7672 | 267 | for (x = 30 ; x < paneX[1] ; x += 10 ) { |
Rhyme | 1:a890937c9c30 | 268 | for (s = 0 ; s < num_signal ; s++) { |
Rhyme | 1:a890937c9c30 | 269 | tft->line(x, voffset[s], x, voffset[s]+paneH, Blue) ; |
Rhyme | 1:a890937c9c30 | 270 | } |
Rhyme | 0:a4d7417f7672 | 271 | } |
Rhyme | 1:a890937c9c30 | 272 | for (s = 0 ; s < num_signal ; s++ ) { |
Rhyme | 1:a890937c9c30 | 273 | tft->rect(paneX[0], voffset[s], paneX[1], voffset[s]+paneH, White) ; |
Rhyme | 1:a890937c9c30 | 274 | } |
Rhyme | 0:a4d7417f7672 | 275 | tft->set_font((unsigned char*) Arial12x12); |
Rhyme | 1:a890937c9c30 | 276 | |
Rhyme | 1:a890937c9c30 | 277 | for (s = 0 ; s < num_signal ; s++ ) { |
Rhyme | 1:a890937c9c30 | 278 | tft->locate(5, voffset[s]+15) ; |
Rhyme | 1:a890937c9c30 | 279 | tft->printf(label[s]) ; |
Rhyme | 1:a890937c9c30 | 280 | } |
Rhyme | 1:a890937c9c30 | 281 | |
Rhyme | 1:a890937c9c30 | 282 | tft->locate(40, 10) ; |
Rhyme | 1:a890937c9c30 | 283 | tft->printf("MAX32630FTHR / BMI160") ; |
Rhyme | 0:a4d7417f7672 | 284 | |
Rhyme | 0:a4d7417f7672 | 285 | acc->getAcc(value) ; |
Rhyme | 1:a890937c9c30 | 286 | for (s = 0 ; s < 3 ; s++) { |
Rhyme | 1:a890937c9c30 | 287 | prev[s] = voffset[s] + (signalHeight * clip((acc_range + value[s])/(acc_range * (float)1.1))) ; |
Rhyme | 1:a890937c9c30 | 288 | } |
Rhyme | 1:a890937c9c30 | 289 | acc->getGyr(&value[3]) ; |
Rhyme | 1:a890937c9c30 | 290 | for ( ; s < num_signal ; s++ ) { |
Rhyme | 1:a890937c9c30 | 291 | prev[s] = voffset[s] + (signalHeight * clip((gyr_range + value[s])/(gyr_range * (float)1.1))) ; |
Rhyme | 1:a890937c9c30 | 292 | } |
Rhyme | 0:a4d7417f7672 | 293 | pt = paneX[0] ; |
Rhyme | 0:a4d7417f7672 | 294 | // backlight = 1 ; |
Rhyme | 0:a4d7417f7672 | 295 | for(t = 21 ; t < paneX[1] ; t++) { |
Rhyme | 0:a4d7417f7672 | 296 | acc->getAcc(value) ; |
Rhyme | 1:a890937c9c30 | 297 | data[0] = voffset[0] + (signalHeight * clip((acc_range + value[0])/(acc_range * (float)1.1))) ; |
Rhyme | 1:a890937c9c30 | 298 | data[1] = voffset[1] + (signalHeight * clip((acc_range + value[1])/(acc_range * (float)1.1))) ; |
Rhyme | 1:a890937c9c30 | 299 | data[2] = voffset[2] + (signalHeight * clip((acc_range + value[2])/(acc_range * (float)1.1))) ; |
Rhyme | 1:a890937c9c30 | 300 | |
Rhyme | 1:a890937c9c30 | 301 | acc->getGyr(&value[3]) ; |
Rhyme | 1:a890937c9c30 | 302 | data[3] = voffset[3] + (signalHeight * clip((gyr_range + value[3])/(gyr_range * (float)1.1))) ; |
Rhyme | 1:a890937c9c30 | 303 | data[4] = voffset[4] + (signalHeight * clip((gyr_range + value[4])/(gyr_range * (float)1.1))) ; |
Rhyme | 1:a890937c9c30 | 304 | data[5] = voffset[5] + (signalHeight * clip((gyr_range + value[5])/(gyr_range * (float)1.1))) ; |
Rhyme | 1:a890937c9c30 | 305 | |
Rhyme | 1:a890937c9c30 | 306 | for (s = 0 ; s < num_signal ; s++ ) { |
Rhyme | 1:a890937c9c30 | 307 | tft->line(pt, prev[s], t, data[s], color[s]) ; |
Rhyme | 1:a890937c9c30 | 308 | } |
Rhyme | 1:a890937c9c30 | 309 | for (s = 0 ; s < num_signal ; s++ ) { |
Rhyme | 1:a890937c9c30 | 310 | prev[s] = data[s] ; |
Rhyme | 1:a890937c9c30 | 311 | } |
Rhyme | 0:a4d7417f7672 | 312 | pt = t ; |
Rhyme | 0:a4d7417f7672 | 313 | Thread::wait(20) ; |
Rhyme | 0:a4d7417f7672 | 314 | } |
Rhyme | 0:a4d7417f7672 | 315 | tft->BusEnable(false) ; |
Rhyme | 0:a4d7417f7672 | 316 | } |
Rhyme | 0:a4d7417f7672 | 317 | |
Rhyme | 0:a4d7417f7672 | 318 | void incPage(void) |
Rhyme | 0:a4d7417f7672 | 319 | { |
Rhyme | 0:a4d7417f7672 | 320 | page++ ; |
Rhyme | 0:a4d7417f7672 | 321 | if (page >= numPage) { |
Rhyme | 0:a4d7417f7672 | 322 | page = 0 ; |
Rhyme | 0:a4d7417f7672 | 323 | } |
Rhyme | 0:a4d7417f7672 | 324 | } |
Rhyme | 0:a4d7417f7672 | 325 | |
Rhyme | 0:a4d7417f7672 | 326 | void decPage(void) |
Rhyme | 0:a4d7417f7672 | 327 | { |
Rhyme | 0:a4d7417f7672 | 328 | page-- ; |
Rhyme | 0:a4d7417f7672 | 329 | if (page < 0) { |
Rhyme | 0:a4d7417f7672 | 330 | page = numPage - 1 ; |
Rhyme | 0:a4d7417f7672 | 331 | } |
Rhyme | 0:a4d7417f7672 | 332 | } |
Rhyme | 0:a4d7417f7672 | 333 | |
Rhyme | 0:a4d7417f7672 | 334 | // main() runs in its own thread in the OS |
Rhyme | 0:a4d7417f7672 | 335 | // (note the calls to Thread::wait below for delays) |
Rhyme | 0:a4d7417f7672 | 336 | int main() |
Rhyme | 0:a4d7417f7672 | 337 | { |
Rhyme | 0:a4d7417f7672 | 338 | int prevPage = 99 ; |
Rhyme | 0:a4d7417f7672 | 339 | bool waitTouch = false ; |
Rhyme | 0:a4d7417f7672 | 340 | uint16_t x, y, z ; |
Rhyme | 0:a4d7417f7672 | 341 | |
Rhyme | 0:a4d7417f7672 | 342 | init_hardware() ; |
Rhyme | 3:43de31beea45 | 343 | backlight(0) ; |
Rhyme | 0:a4d7417f7672 | 344 | initTFT() ; |
Rhyme | 3:43de31beea45 | 345 | backlight(1) ; |
Rhyme | 0:a4d7417f7672 | 346 | |
Rhyme | 1:a890937c9c30 | 347 | #if USE_TTY |
Rhyme | 0:a4d7417f7672 | 348 | tty->printf("MAX32630 test (%s)\n", __DATE__) ; |
Rhyme | 1:a890937c9c30 | 349 | #endif |
Rhyme | 3:43de31beea45 | 350 | // tft->cls() ; |
Rhyme | 0:a4d7417f7672 | 351 | for(;;) { |
Rhyme | 0:a4d7417f7672 | 352 | switch(page) { |
Rhyme | 0:a4d7417f7672 | 353 | case 0: |
Rhyme | 0:a4d7417f7672 | 354 | if (prevPage != page) { |
Rhyme | 0:a4d7417f7672 | 355 | screen1() ; |
Rhyme | 0:a4d7417f7672 | 356 | } |
Rhyme | 0:a4d7417f7672 | 357 | waitTouch = true ; |
Rhyme | 0:a4d7417f7672 | 358 | break ; |
Rhyme | 0:a4d7417f7672 | 359 | case 1: |
Rhyme | 0:a4d7417f7672 | 360 | if (prevPage != page) { |
Rhyme | 0:a4d7417f7672 | 361 | screen2() ; |
Rhyme | 0:a4d7417f7672 | 362 | } |
Rhyme | 0:a4d7417f7672 | 363 | waitTouch = true ; |
Rhyme | 0:a4d7417f7672 | 364 | break ; |
Rhyme | 0:a4d7417f7672 | 365 | case 2: |
Rhyme | 0:a4d7417f7672 | 366 | if (prevPage != page) { |
Rhyme | 2:d810dbdd716b | 367 | backlight(0) ; |
Rhyme | 0:a4d7417f7672 | 368 | tft->BusEnable(true) ; |
Rhyme | 0:a4d7417f7672 | 369 | tft->background(Black) ; |
Rhyme | 0:a4d7417f7672 | 370 | tft->foreground(White) ; |
Rhyme | 0:a4d7417f7672 | 371 | tft->cls() ; |
Rhyme | 0:a4d7417f7672 | 372 | tft->BusEnable(false) ; |
Rhyme | 0:a4d7417f7672 | 373 | } |
Rhyme | 0:a4d7417f7672 | 374 | screen3() ; |
Rhyme | 0:a4d7417f7672 | 375 | waitTouch = false ; |
Rhyme | 0:a4d7417f7672 | 376 | break ; |
Rhyme | 0:a4d7417f7672 | 377 | case 3: |
Rhyme | 0:a4d7417f7672 | 378 | if (prevPage != page) { |
Rhyme | 0:a4d7417f7672 | 379 | doMaze() ; |
Rhyme | 0:a4d7417f7672 | 380 | waitTouch = true ; |
Rhyme | 0:a4d7417f7672 | 381 | } |
Rhyme | 0:a4d7417f7672 | 382 | break ; |
Rhyme | 0:a4d7417f7672 | 383 | default: |
Rhyme | 0:a4d7417f7672 | 384 | page = 0 ; |
Rhyme | 0:a4d7417f7672 | 385 | break ; |
Rhyme | 0:a4d7417f7672 | 386 | } |
Rhyme | 0:a4d7417f7672 | 387 | prevPage = page ; |
Rhyme | 0:a4d7417f7672 | 388 | |
Rhyme | 0:a4d7417f7672 | 389 | do { |
Rhyme | 0:a4d7417f7672 | 390 | tsc->getPoint(&x, &y, &z) ; |
Rhyme | 0:a4d7417f7672 | 391 | if ((x != 0)&&(y != 0)) { |
Rhyme | 1:a890937c9c30 | 392 | #if USE_TTY |
Rhyme | 0:a4d7417f7672 | 393 | tty->printf("%d, %d, %d\n", x, y, z) ; |
Rhyme | 1:a890937c9c30 | 394 | #endif |
Rhyme | 0:a4d7417f7672 | 395 | if (x < 50) { // left |
Rhyme | 0:a4d7417f7672 | 396 | decPage() ; |
Rhyme | 0:a4d7417f7672 | 397 | } else if (x > 190) { // right |
Rhyme | 0:a4d7417f7672 | 398 | incPage() ; |
Rhyme | 0:a4d7417f7672 | 399 | } |
Rhyme | 0:a4d7417f7672 | 400 | waitTouch = false ; |
Rhyme | 0:a4d7417f7672 | 401 | } |
Rhyme | 0:a4d7417f7672 | 402 | } while(waitTouch != false) ; |
Rhyme | 0:a4d7417f7672 | 403 | |
Rhyme | 0:a4d7417f7672 | 404 | Thread::wait(100) ; |
Rhyme | 0:a4d7417f7672 | 405 | } |
Rhyme | 0:a4d7417f7672 | 406 | } |
Rhyme | 0:a4d7417f7672 | 407 |