Simple program to test BlockMove API on the RA8875 display. Tested with RA8875 v148 and mbed v148

Dependencies:   mbed RA8875

Committer:
WiredHome
Date:
Sun Mar 29 18:14:15 2020 +0000
Revision:
4:e5375f29d8d4
Parent:
3:db0f8dc64407
Pick up a bug-fix on jpeg rendering

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:d06677ab6ca6 1 /// Block Move demo
WiredHome 0:d06677ab6ca6 2 ///
WiredHome 0:d06677ab6ca6 3 /// This demo will simulate a scope. It will place a grid on one layer, and data-points
WiredHome 0:d06677ab6ca6 4 /// on the other layer. Rather than redrawing the entire grid space to simulate time
WiredHome 0:d06677ab6ca6 5 /// elapsing, it will BlockMove the data and then add a single new data point.
WiredHome 0:d06677ab6ca6 6 ///
WiredHome 0:d06677ab6ca6 7 ///
WiredHome 0:d06677ab6ca6 8 /// Place a jpg on the local file system named 'fullscrn.jpg'. The WxH of this jpg
WiredHome 0:d06677ab6ca6 9 /// should match the display size you have set below.
WiredHome 0:d06677ab6ca6 10 ///
WiredHome 0:d06677ab6ca6 11
WiredHome 0:d06677ab6ca6 12 #include "mbed.h" // Last known good: v148, Most work was with v129
WiredHome 0:d06677ab6ca6 13 #include "RA8875.h" // Last known good: v148
WiredHome 0:d06677ab6ca6 14 #include "ResistiveTouchCal.h"
WiredHome 0:d06677ab6ca6 15
WiredHome 0:d06677ab6ca6 16 // These two defines can be enabled, or commented out
WiredHome 0:d06677ab6ca6 17 #define BIG_SCREEN
WiredHome 0:d06677ab6ca6 18 #define CAP_TOUCH
WiredHome 0:d06677ab6ca6 19
WiredHome 0:d06677ab6ca6 20 #ifdef CAP_TOUCH
WiredHome 2:a6a8695af935 21 RA8875 lcd(p5,p6,p7,p12,NC, p9,p10,p13, "tft"); // MOSI,MISO,SCK,/ChipSelect,/reset, SDA,SCL,/IRQ, name
WiredHome 0:d06677ab6ca6 22 #else
WiredHome 2:a6a8695af935 23 RA8875 lcd(p5,p6,p7,p12,NC, "tft"); //MOSI, MISO, SCK, /ChipSelect, /reset, name
WiredHome 0:d06677ab6ca6 24 #endif
WiredHome 0:d06677ab6ca6 25 LocalFileSystem local("local"); // access to calibration file for resistive touch.
WiredHome 0:d06677ab6ca6 26
WiredHome 0:d06677ab6ca6 27 #define LCD_C 8 // color - bits per pixel in order to have 2 layers
WiredHome 0:d06677ab6ca6 28 #define BL_NORM 25 // Backlight Normal setting (0 to 255)
WiredHome 0:d06677ab6ca6 29
WiredHome 0:d06677ab6ca6 30 #ifdef BIG_SCREEN
WiredHome 0:d06677ab6ca6 31 #define LCD_W 800
WiredHome 0:d06677ab6ca6 32 #define LCD_H 480
WiredHome 0:d06677ab6ca6 33 #else
WiredHome 0:d06677ab6ca6 34 #define LCD_W 480
WiredHome 0:d06677ab6ca6 35 #define LCD_H 272
WiredHome 0:d06677ab6ca6 36 #endif
WiredHome 0:d06677ab6ca6 37
WiredHome 0:d06677ab6ca6 38 Serial pc(USBTX, USBRX);
WiredHome 0:d06677ab6ca6 39
WiredHome 0:d06677ab6ca6 40 void DrawGrid(rect_t r, int hDiv, int vDiv, color_t color)
WiredHome 0:d06677ab6ca6 41 {
WiredHome 0:d06677ab6ca6 42 point_t p1, p2;
WiredHome 0:d06677ab6ca6 43 int i;
WiredHome 0:d06677ab6ca6 44
WiredHome 0:d06677ab6ca6 45 lcd.rect(r, color);
WiredHome 0:d06677ab6ca6 46 p1.y = r.p1.y; p2.y = r.p2.y;
WiredHome 0:d06677ab6ca6 47 for (i=0; i<hDiv; i++) {
WiredHome 0:d06677ab6ca6 48 p1.x = p2.x = i * (r.p2.x - r.p1.x) / hDiv + r.p1.x;
WiredHome 0:d06677ab6ca6 49 lcd.line(p1, p2, color);
WiredHome 0:d06677ab6ca6 50 }
WiredHome 0:d06677ab6ca6 51 p1.x = r.p1.x; p2.x = r.p2.x;
WiredHome 0:d06677ab6ca6 52 for (i=0; i<vDiv; i++) {
WiredHome 0:d06677ab6ca6 53 p1.y = p2.y = i * (r.p2.y - r.p1.y) / vDiv + r.p1.y;
WiredHome 0:d06677ab6ca6 54 lcd.line(p1, p2, color);
WiredHome 0:d06677ab6ca6 55 }
WiredHome 0:d06677ab6ca6 56 }
WiredHome 0:d06677ab6ca6 57
WiredHome 0:d06677ab6ca6 58 int main()
WiredHome 0:d06677ab6ca6 59 {
WiredHome 0:d06677ab6ca6 60 point_t src;
WiredHome 0:d06677ab6ca6 61 point_t dst;
WiredHome 0:d06677ab6ca6 62 dim_t w, h;
WiredHome 0:d06677ab6ca6 63
WiredHome 0:d06677ab6ca6 64 pc.baud(460800); //I like a snappy terminal, so crank it up!
WiredHome 0:d06677ab6ca6 65 pc.printf("\r\nRA8875 BTE Move Test - Build " __DATE__ " " __TIME__ "\r\n");
WiredHome 0:d06677ab6ca6 66 lcd.init(LCD_W,LCD_H,LCD_C, BL_NORM);
WiredHome 0:d06677ab6ca6 67 lcd.TouchPanelInit();
WiredHome 0:d06677ab6ca6 68 #ifndef CAP_TOUCH
WiredHome 0:d06677ab6ca6 69 InitTS(lcd); // Calibration for resistive touch panel
WiredHome 0:d06677ab6ca6 70 #endif
WiredHome 3:db0f8dc64407 71 rect_t grid = {50,50,LCD_W-50,LCD_H-50};
WiredHome 0:d06677ab6ca6 72 lcd.SelectDrawingLayer(0);
WiredHome 0:d06677ab6ca6 73 DrawGrid(grid,10,10,Green);
WiredHome 0:d06677ab6ca6 74
WiredHome 0:d06677ab6ca6 75 w = grid.p2.x - grid.p1.x;
WiredHome 0:d06677ab6ca6 76 h = grid.p2.y - grid.p1.y;
WiredHome 0:d06677ab6ca6 77
WiredHome 0:d06677ab6ca6 78 lcd.SetLayerMode(RA8875::BooleanOR);
WiredHome 0:d06677ab6ca6 79 lcd.SelectDrawingLayer(1);
WiredHome 0:d06677ab6ca6 80 RetCode_t r = lcd.RenderImageFile(0,0,"/local/fullscrn.jpg");
WiredHome 0:d06677ab6ca6 81 if (r) pc.printf(" Error: %d; %s\r\n", r, lcd.GetErrorMessage(r));
WiredHome 0:d06677ab6ca6 82 float y;
WiredHome 0:d06677ab6ca6 83 float t;
WiredHome 0:d06677ab6ca6 84 while (1) {
WiredHome 0:d06677ab6ca6 85 //wait_us(100);
WiredHome 0:d06677ab6ca6 86 dst = grid.p1;
WiredHome 0:d06677ab6ca6 87 src.x = dst.x + 1;
WiredHome 0:d06677ab6ca6 88 src.y = dst.y;
WiredHome 0:d06677ab6ca6 89 lcd.BlockMove(1,0,dst, 1,0,src, w+2,h, 0x2, 0xC);
WiredHome 0:d06677ab6ca6 90
WiredHome 0:d06677ab6ca6 91 y = sin(t) * (grid.p2.y - grid.p1.y)/2;
WiredHome 0:d06677ab6ca6 92 t += 0.1f;
WiredHome 0:d06677ab6ca6 93 lcd.pixel(grid.p2.x, y + grid.p1.y + (grid.p2.y - grid.p1.y)/2, White);
WiredHome 0:d06677ab6ca6 94
WiredHome 0:d06677ab6ca6 95 volatile TouchCode_t tc = lcd.TouchCode();
WiredHome 0:d06677ab6ca6 96 while (tc == touch || tc == held) {
WiredHome 0:d06677ab6ca6 97 #if 1 // This fails: on the first touch, it never exits the while
WiredHome 0:d06677ab6ca6 98 tc = lcd.TouchCode(); // returns 0:no_touch, 1:touch, 2:held, 3:release
WiredHome 0:d06677ab6ca6 99 wait_us(0); // Adding this makes it work, even if the wait is 0 or 1
WiredHome 0:d06677ab6ca6 100 #elif 0 // This works: but includes the useless committment of a digital output
WiredHome 0:d06677ab6ca6 101 tc = lcd.TouchCode();
WiredHome 0:d06677ab6ca6 102 DigitalOut led(LED1);
WiredHome 0:d06677ab6ca6 103 led = !led;
WiredHome 0:d06677ab6ca6 104 #else // This works: but includes the undesired printf
WiredHome 0:d06677ab6ca6 105 tc = lcd.TouchCode(); // returns 0:no_touch, 1:touch, 2:held, 3:release
WiredHome 0:d06677ab6ca6 106 pc.printf("tc: %d\r", tc);
WiredHome 0:d06677ab6ca6 107 #endif
WiredHome 0:d06677ab6ca6 108 }
WiredHome 0:d06677ab6ca6 109 }
WiredHome 0:d06677ab6ca6 110 }