![](/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
Diff: main.cpp
- Revision:
- 1:a890937c9c30
- Parent:
- 0:a4d7417f7672
- Child:
- 2:d810dbdd716b
--- a/main.cpp Thu Sep 21 05:16:39 2017 +0000 +++ b/main.cpp Fri Sep 22 01:39:14 2017 +0000 @@ -30,6 +30,8 @@ #define PIN_SCL2 P6_0 #define BMI160_I2C_ADDRESS 0x68 +#define USE_TTY 1 + MAX32630FTHR *sakura = 0 ; ILI9341 *tft = 0 ; SPI_STMPE610 *tsc = 0 ; @@ -53,13 +55,21 @@ void init_hardware(void) { sakura = new MAX32630FTHR(MAX32630FTHR::VIO_3V3) ; + Thread::wait(0.1) ; + sakura->init(MAX32630FTHR::VIO_3V3) ; +#if USE_TTY tty = new USBSerial() ; +#endif + tft = new ILI9341(SPI_8, 16000000, + SPI2_MOSI, SPI2_MISO, SPI2_SCK, + PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.4") ; + tft->BusEnable(false) ; + wait(0.1) ; + tsc = new SPI_STMPE610(SPI2_MOSI, SPI2_MISO, SPI2_SCK, PIN_TSC_CS) ; tsc->spi_format(8, 0) ; tsc->calibrate(3552, 400, 439, 3680) ; - tft = new ILI9341(SPI_8, 16000000, - SPI2_MOSI, SPI2_MISO, SPI2_SCK, - PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.4") ; + ledR = new DigitalOut(PIN_LED_R) ; ledG = new DigitalOut(PIN_LED_G) ; ledB = new DigitalOut(PIN_LED_B) ; @@ -182,89 +192,98 @@ // backlight = 1 ; } -double clip(double src) +float clip(float src) { - double value ; + float value ; value = src ; - if (value < 0.0) { - value = 0.0 ; - } else if (value > 2.0) { - value = 2.0 ; + if (value < (float)0.0) { + value = (float)0.0 ; + } else if (value > (float)2.0) { + value = (float)2.0 ; } return( value ) ; } void screen3(void) { + const int num_signal = 6 ; int t = 0 ; int pt = 0 ; // previous t - int i, x, y ; - unsigned int data[3] ; // for x, y, z - unsigned int prev[3] ; - unsigned short signalHeight = 39 ; - unsigned short xoffset = 30 ; - unsigned short yoffset = 120 ; - unsigned short zoffset = 210 ; + int i, s, x, y ; + unsigned int data[num_signal] ; // for x, y, z + unsigned int prev[num_signal] ; + unsigned short signalHeight = 19 ; // 39 ; + unsigned short voffset[num_signal] = { 30, 80, 130, 180, 230, 280 } ; // for x, y, z + unsigned short color[num_signal] = { Red, Green, Yellow, Red, Green, Yellow } ; + char *label[num_signal] = { "X", "Y", "Z", "x", "y", "z" } ; unsigned short paneX[2] = {20, 235} ; - unsigned short paneH = 81 ; - float value[3] ; + unsigned short paneH = 41 ; // 81 ; + float value[num_signal] ; float acc_range ; + float gyr_range ; // backlight = 1 ; acc_range = (float)acc->getAccRange() ; + gyr_range = (float)acc->getGyrRange() ; tft->BusEnable(true) ; tft->background(Black) ; tft->foreground(White) ; // tft->cls() ; - - tft->fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ; - tft->fillrect(paneX[0], yoffset, paneX[1], yoffset+paneH, Black) ; - tft->fillrect(paneX[0], zoffset, paneX[1], zoffset+paneH, Black) ; - tft->fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ; + for (s = 0 ; s < num_signal ; s++ ) { + tft->fillrect(paneX[0], voffset[s], paneX[1], voffset[s]+paneH, Black) ; + } for (i = 0 ; i < 10 ; i++ ) { - y = i * 8 ; - tft->line(paneX[0], xoffset + y, paneX[1], xoffset + y, Blue) ; - tft->line(paneX[0], yoffset + y, paneX[1], yoffset + y, Blue) ; - tft->line(paneX[0], zoffset + y, paneX[1], zoffset + y, Blue) ; + y = i * 4 ; // i * 8 ; + for (s = 0 ; s < num_signal ; s++) { + tft->line(paneX[0], voffset[s] + y, paneX[1], voffset[s] + y, Blue) ; + } } for (x = 30 ; x < paneX[1] ; x += 10 ) { - tft->line(x, xoffset, x, xoffset+paneH, Blue) ; - tft->line(x, yoffset, x, yoffset+paneH, Blue) ; - tft->line(x, zoffset, x, zoffset+paneH, Blue) ; + for (s = 0 ; s < num_signal ; s++) { + tft->line(x, voffset[s], x, voffset[s]+paneH, Blue) ; + } } - tft->rect(paneX[0], xoffset, paneX[1], xoffset+paneH, White) ; - tft->rect(paneX[0], yoffset, paneX[1], yoffset+paneH, White) ; - tft->rect(paneX[0], zoffset, paneX[1], zoffset+paneH, White) ; + for (s = 0 ; s < num_signal ; s++ ) { + tft->rect(paneX[0], voffset[s], paneX[1], voffset[s]+paneH, White) ; + } tft->set_font((unsigned char*) Arial12x12); - tft->locate(5, xoffset+30) ; - tft->printf("X") ; - tft->locate(5, yoffset+30) ; - tft->printf("Y") ; - tft->locate(5, zoffset+30) ; - tft->printf("Z") ; - tft->locate(70, 10) ; - tft->printf("MAX32630FTHR") ; - tft->locate(90, 300) ; - tft->printf("BMI160") ; + + for (s = 0 ; s < num_signal ; s++ ) { + tft->locate(5, voffset[s]+15) ; + tft->printf(label[s]) ; + } + + tft->locate(40, 10) ; + tft->printf("MAX32630FTHR / BMI160") ; acc->getAcc(value) ; - prev[0] = xoffset + (signalHeight * clip((acc_range + value[0])/(acc_range * 1.1))) ; - prev[1] = yoffset + (signalHeight * clip((acc_range + value[1])/(acc_range * 1.1))) ; - prev[2] = zoffset + (signalHeight * clip((acc_range + value[2])/(acc_range * 1.1))) ; + for (s = 0 ; s < 3 ; s++) { + prev[s] = voffset[s] + (signalHeight * clip((acc_range + value[s])/(acc_range * (float)1.1))) ; + } + acc->getGyr(&value[3]) ; + for ( ; s < num_signal ; s++ ) { + prev[s] = voffset[s] + (signalHeight * clip((gyr_range + value[s])/(gyr_range * (float)1.1))) ; + } pt = paneX[0] ; // backlight = 1 ; for(t = 21 ; t < paneX[1] ; t++) { acc->getAcc(value) ; - data[0] = xoffset + (signalHeight * clip((acc_range + value[0])/(acc_range * 1.1))) ; - data[1] = yoffset + (signalHeight * clip((acc_range + value[1])/(acc_range * 1.1))) ; - data[2] = zoffset + (signalHeight * clip((acc_range + value[2])/(acc_range * 1.1))) ; - tft->line(pt, prev[0], t, data[0], Red) ; - tft->line(pt, prev[1], t, data[1], Green) ; - tft->line(pt, prev[2], t, data[2], Yellow) ; - prev[0] = data[0] ; - prev[1] = data[1] ; - prev[2] = data[2] ; + data[0] = voffset[0] + (signalHeight * clip((acc_range + value[0])/(acc_range * (float)1.1))) ; + data[1] = voffset[1] + (signalHeight * clip((acc_range + value[1])/(acc_range * (float)1.1))) ; + data[2] = voffset[2] + (signalHeight * clip((acc_range + value[2])/(acc_range * (float)1.1))) ; + + acc->getGyr(&value[3]) ; + data[3] = voffset[3] + (signalHeight * clip((gyr_range + value[3])/(gyr_range * (float)1.1))) ; + data[4] = voffset[4] + (signalHeight * clip((gyr_range + value[4])/(gyr_range * (float)1.1))) ; + data[5] = voffset[5] + (signalHeight * clip((gyr_range + value[5])/(gyr_range * (float)1.1))) ; + + for (s = 0 ; s < num_signal ; s++ ) { + tft->line(pt, prev[s], t, data[s], color[s]) ; + } + for (s = 0 ; s < num_signal ; s++ ) { + prev[s] = data[s] ; + } pt = t ; Thread::wait(20) ; } @@ -298,7 +317,9 @@ init_hardware() ; initTFT() ; +#if USE_TTY tty->printf("MAX32630 test (%s)\n", __DATE__) ; +#endif tft->cls() ; for(;;) { switch(page) { @@ -340,7 +361,9 @@ do { tsc->getPoint(&x, &y, &z) ; if ((x != 0)&&(y != 0)) { +#if USE_TTY tty->printf("%d, %d, %d\n", x, y, z) ; +#endif if (x < 50) { // left decPage() ; } else if (x > 190) { // right