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