KSM edits

Dependencies:   mbed RA8875

Committer:
kerrysmartin
Date:
Thu Jul 11 14:04:19 2019 +0000
Revision:
20:d25fb9c55781
Parent:
19:fee3f71fab2d
Initial check in

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 16:231837aa2c37 1 //
WiredHome 16:231837aa2c37 2 // Demo Program
WiredHome 17:c8ef96a6e43b 3 // mbed version Graphics Working PrintScreen Working? "/local/file.bmp"
WiredHome 17:c8ef96a6e43b 4 // v148 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails
WiredHome 17:c8ef96a6e43b 5 // v142 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails
WiredHome 17:c8ef96a6e43b 6 // v140 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails
WiredHome 17:c8ef96a6e43b 7 // v138 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails
WiredHome 17:c8ef96a6e43b 8 // v137 Yes Yes
WiredHome 17:c8ef96a6e43b 9 // v136 Yes Yes
WiredHome 17:c8ef96a6e43b 10 // v128 Yes Yes
WiredHome 17:c8ef96a6e43b 11 //
WiredHome 17:c8ef96a6e43b 12 #include "mbed.h" // testing: v147 - working: v146, v145, v142, v136, v128, fails: v148
WiredHome 17:c8ef96a6e43b 13 #include "RA8875.h" // v138 - tested working
WiredHome 5:bb970d40cd7d 14 #include "MyFont18x32.h"
WiredHome 5:bb970d40cd7d 15 #include "BPG_Arial08x08.h"
WiredHome 5:bb970d40cd7d 16 #include "BPG_Arial10x10.h"
WiredHome 5:bb970d40cd7d 17 #include "BPG_Arial20x20.h"
WiredHome 5:bb970d40cd7d 18 #include "BPG_Arial31x32.h"
WiredHome 5:bb970d40cd7d 19 #include "BPG_Arial63x63.h"
lizard753 19:fee3f71fab2d 20 #include "Button.h"
WiredHome 0:037b95a5cc85 21
WiredHome 15:ab07c064c952 22 // These two defines can be enabled, or commented out
lizard753 19:fee3f71fab2d 23 //#define BIG_SCREEN
WiredHome 18:307303d9c8f6 24 //#define CAP_TOUCH
WiredHome 15:ab07c064c952 25 #define LCD_C 16 // color - bits per pixel
lizard753 19:fee3f71fab2d 26 // Needed for Resistive Touch
lizard753 19:fee3f71fab2d 27 void CalibrateTS(void);
kerrysmartin 20:d25fb9c55781 28 void InitTS(void);
WiredHome 15:ab07c064c952 29 #ifdef CAP_TOUCH
WiredHome 15:ab07c064c952 30 RA8875 lcd(p5, p6, p7, p12, NC, p9,p10,p13, "tft"); // MOSI,MISO,SCK,/ChipSelect,/reset, SDA,SCL,/IRQ, name
kerrysmartin 20:d25fb9c55781 31 LocalFileSystem local("local"); // access to calibration file for resistive touch and printscreen
kerrysmartin 20:d25fb9c55781 32
WiredHome 15:ab07c064c952 33 #else
WiredHome 15:ab07c064c952 34 RA8875 lcd(p5, p6, p7, p12, NC, "tft"); //MOSI, MISO, SCK, /ChipSelect, /reset, name
kerrysmartin 20:d25fb9c55781 35 void InitTS(void); // Needed for Resistive Touch
kerrysmartin 20:d25fb9c55781 36 void CalibrateTS(void); // Needed for Resistive Touch
kerrysmartin 20:d25fb9c55781 37 const char * TS_Config = "/local/tpcal.cfg"; // Path and file for storing touch config
kerrysmartin 20:d25fb9c55781 38 LocalFileSystem local("local"); // Needed for resistive touch config storage
WiredHome 16:231837aa2c37 39 #endif
WiredHome 15:ab07c064c952 40
WiredHome 15:ab07c064c952 41 #ifdef BIG_SCREEN
WiredHome 18:307303d9c8f6 42 #define LCD_W 800
WiredHome 18:307303d9c8f6 43 #define LCD_H 480
WiredHome 15:ab07c064c952 44 #else
WiredHome 18:307303d9c8f6 45 #define LCD_W 480
WiredHome 18:307303d9c8f6 46 #define LCD_H 272
WiredHome 15:ab07c064c952 47 #endif
WiredHome 15:ab07c064c952 48
WiredHome 5:bb970d40cd7d 49 Serial pc(USBTX, USBRX); // And a little feedback
WiredHome 13:43cc0a997c53 50 Timer measurement;
kerrysmartin 20:d25fb9c55781 51 //
kerrysmartin 20:d25fb9c55781 52 const rect_t button_1 = {10,10,50,50}; // if intersect button_1, poin_of_touch
kerrysmartin 20:d25fb9c55781 53 Button button_calibration((loc_t)10, (loc_t)10, (loc_t)50, (loc_t)50, (color_t)RGB(0,255,255), &lcd, "CAL");
lizard753 19:fee3f71fab2d 54 Button button_data_rate_select((loc_t)10, (loc_t)10, (loc_t)20, (loc_t)20, (color_t)RGB(255,255,0), &lcd, "250");
WiredHome 0:037b95a5cc85 55
WiredHome 18:307303d9c8f6 56 RetCode_t callback(RA8875::filecmd_t cmd, uint8_t * buffer, uint16_t size)
WiredHome 18:307303d9c8f6 57 {
WiredHome 18:307303d9c8f6 58 static FILE * fh = NULL;
WiredHome 18:307303d9c8f6 59 static unsigned int bytesDone = 0;
WiredHome 18:307303d9c8f6 60 static unsigned int totalBytes = 0;
WiredHome 18:307303d9c8f6 61
WiredHome 18:307303d9c8f6 62 switch(cmd) {
WiredHome 18:307303d9c8f6 63 case RA8875::OPEN:
WiredHome 18:307303d9c8f6 64 bytesDone = 0;
WiredHome 18:307303d9c8f6 65 totalBytes = *(uint32_t *)buffer;
WiredHome 18:307303d9c8f6 66 pc.printf("PrintScreen callback to write %u bytes\r\n", totalBytes);
WiredHome 18:307303d9c8f6 67 fh = fopen("/local/file.bmp", "w+b");
WiredHome 18:307303d9c8f6 68 if (!fh)
WiredHome 18:307303d9c8f6 69 return(file_not_found);
WiredHome 18:307303d9c8f6 70 break;
WiredHome 18:307303d9c8f6 71 case RA8875::WRITE:
WiredHome 18:307303d9c8f6 72 bytesDone += size;
WiredHome 18:307303d9c8f6 73 pc.printf(" Write %d bytes => %d of %d\r\n", size, bytesDone, totalBytes);
WiredHome 18:307303d9c8f6 74 fwrite(buffer, 1, size, fh);
WiredHome 18:307303d9c8f6 75 pc.printf(" %3d %% complete\r\n", ((100 * bytesDone)/totalBytes));
WiredHome 18:307303d9c8f6 76 break;
WiredHome 18:307303d9c8f6 77 case RA8875::CLOSE:
WiredHome 18:307303d9c8f6 78 fclose(fh);
WiredHome 18:307303d9c8f6 79 pc.printf("PrintScreen Closed.\r\n");
WiredHome 18:307303d9c8f6 80 break;
WiredHome 18:307303d9c8f6 81 default:
WiredHome 18:307303d9c8f6 82 pc.printf("Unexpected callback %d\r\n", cmd);
WiredHome 18:307303d9c8f6 83 break;
WiredHome 18:307303d9c8f6 84 }
WiredHome 18:307303d9c8f6 85 return noerror;
WiredHome 18:307303d9c8f6 86 }
WiredHome 18:307303d9c8f6 87
WiredHome 18:307303d9c8f6 88
WiredHome 0:037b95a5cc85 89 int main()
WiredHome 0:037b95a5cc85 90 {
WiredHome 5:bb970d40cd7d 91 pc.baud(460800); // I like a snappy terminal, so crank it up!
WiredHome 5:bb970d40cd7d 92 pc.printf("\r\nRA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");
WiredHome 2:2076d9cc6db9 93
WiredHome 13:43cc0a997c53 94 measurement.start();
WiredHome 18:307303d9c8f6 95 lcd.frequency(500000);
WiredHome 18:307303d9c8f6 96 lcd.Reset();
WiredHome 18:307303d9c8f6 97 lcd.init(LCD_W, LCD_H, LCD_C, 40);
kerrysmartin 20:d25fb9c55781 98 lcd.TouchPanelInit();
kerrysmartin 20:d25fb9c55781 99 #ifndef CAP_TOUCH
kerrysmartin 20:d25fb9c55781 100 InitTS(); // resistive touch calibration
kerrysmartin 20:d25fb9c55781 101 #endif
lizard753 19:fee3f71fab2d 102 lcd.Backlight(.9);
WiredHome 6:8e392d0ff74a 103 // **************************
WiredHome 9:02c622fa4969 104 //RunTestSet(lcd, pc); // If the library was compiled for test mode...
WiredHome 18:307303d9c8f6 105
WiredHome 9:02c622fa4969 106 lcd.foreground(RGB(255,255,0));
WiredHome 18:307303d9c8f6 107 lcd.puts(0,100, "RA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");
WiredHome 0:037b95a5cc85 108
WiredHome 5:bb970d40cd7d 109 lcd.SelectUserFont(Dave_Smart18x32);
WiredHome 5:bb970d40cd7d 110 lcd.puts("**** ! Soft Fonts ! **** 0123456789\r\n");
WiredHome 5:bb970d40cd7d 111 lcd.puts("ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
WiredHome 9:02c622fa4969 112 //lcd.puts("abcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 5:bb970d40cd7d 113 lcd.SelectUserFont();
WiredHome 5:bb970d40cd7d 114 lcd.puts("Back to normal\r\n");
WiredHome 5:bb970d40cd7d 115 lcd.SelectUserFont(BPG_Arial08x08);
WiredHome 5:bb970d40cd7d 116 lcd.puts("BPG_Arial08x08 ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
WiredHome 18:307303d9c8f6 117 //lcd.puts("BPG_Arial08x08 abcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 5:bb970d40cd7d 118 lcd.SelectUserFont(BPG_Arial10x10);
WiredHome 5:bb970d40cd7d 119 lcd.puts("BPG_Arial10x10 ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
WiredHome 9:02c622fa4969 120 //lcd.puts("BPG_Arial10x10 abcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 5:bb970d40cd7d 121 lcd.SelectUserFont(BPG_Arial20x20);
WiredHome 9:02c622fa4969 122 lcd.puts("BPG_Arial20x20 ");
WiredHome 5:bb970d40cd7d 123 lcd.SelectUserFont(BPG_Arial31x32);
WiredHome 9:02c622fa4969 124 lcd.puts("BPG_Arial31x32\r\n");
WiredHome 5:bb970d40cd7d 125 lcd.SelectUserFont(BPG_Arial63x63);
WiredHome 9:02c622fa4969 126 lcd.puts("BPG_Arial63x63");
WiredHome 13:43cc0a997c53 127 pc.printf("Time trial completed in %d uSec\r\n", measurement.read_us());
WiredHome 5:bb970d40cd7d 128
WiredHome 18:307303d9c8f6 129 lcd.rect(0,0, 10,10, BrightRed);
WiredHome 18:307303d9c8f6 130
kerrysmartin 20:d25fb9c55781 131 //pc.printf("PrintScreen activated ...\r\n");
kerrysmartin 20:d25fb9c55781 132 //RetCode_t r = lcd.PrintScreen(0,0,LCD_W,LCD_H,"/local/file.bmp", 8);
kerrysmartin 20:d25fb9c55781 133 //pc.printf(" PrintScreen returned %d - %s\r\n", r, lcd.GetErrorMessage(r));
WiredHome 18:307303d9c8f6 134
WiredHome 18:307303d9c8f6 135 //lcd.AttachPrintHandler(callback);
WiredHome 18:307303d9c8f6 136 //lcd.PrintScreen(0,0,LCD_W,LCD_H,8);
kerrysmartin 20:d25fb9c55781 137 lcd.SelectUserFont(Dave_Smart18x32);
lizard753 19:fee3f71fab2d 138 button_calibration.draw();
WiredHome 18:307303d9c8f6 139
kerrysmartin 20:d25fb9c55781 140 int cycle = 0;
kerrysmartin 20:d25fb9c55781 141
kerrysmartin 20:d25fb9c55781 142 int xxxx, yyyy;
kerrysmartin 20:d25fb9c55781 143 xxxx = 0;
kerrysmartin 20:d25fb9c55781 144 yyyy = 0;
kerrysmartin 20:d25fb9c55781 145
lizard753 19:fee3f71fab2d 146 while(1)
lizard753 19:fee3f71fab2d 147 {
kerrysmartin 20:d25fb9c55781 148
lizard753 19:fee3f71fab2d 149 TouchCode_t touch;
lizard753 19:fee3f71fab2d 150
lizard753 19:fee3f71fab2d 151 touch = lcd.TouchPanelReadable();
lizard753 19:fee3f71fab2d 152 if(touch)
lizard753 19:fee3f71fab2d 153 {
kerrysmartin 20:d25fb9c55781 154 cycle += 1;
kerrysmartin 20:d25fb9c55781 155
lizard753 19:fee3f71fab2d 156 for(int i = 0; i < lcd.TouchChannels(); i++)
lizard753 19:fee3f71fab2d 157 {
kerrysmartin 20:d25fb9c55781 158 TouchCode_t ev = lcd.TouchCode(i);
kerrysmartin 20:d25fb9c55781 159 point_t xy = lcd.TouchCoordinates(i);
kerrysmartin 20:d25fb9c55781 160 uint8_t id = lcd.TouchID(i); // 'id' tracks the individual touches
kerrysmartin 20:d25fb9c55781 161 //TouchCode_t ev = lcd.TouchCode(i); // 'ev'ent indicates no_touch, touch, held, release, ...
kerrysmartin 20:d25fb9c55781 162 //point_t xy = lcd.TouchCoordinates(i); // and of course the (x,y) coordinates
kerrysmartin 20:d25fb9c55781 163 int count = lcd.TouchCount(); // how many simultaneous touches
kerrysmartin 20:d25fb9c55781 164 printf("%2d,%d:(%4d,%4d) \n\r", id, ev, xy.x, xy.y);
lizard753 19:fee3f71fab2d 165 if(button_calibration.isPressed(xy.x, xy.y))
lizard753 19:fee3f71fab2d 166 {
kerrysmartin 20:d25fb9c55781 167 //lcd.rect(0,0, LCD_W,LCD_H, BrightCyan);
kerrysmartin 20:d25fb9c55781 168 //lcd.rect(xy.x, xy.y, xy.x+20, xy.y+20, BrightCyan);
kerrysmartin 20:d25fb9c55781 169 if(ev == touch)
kerrysmartin 20:d25fb9c55781 170 {
kerrysmartin 20:d25fb9c55781 171 button_calibration.button_color = Magenta;
kerrysmartin 20:d25fb9c55781 172 }
kerrysmartin 20:d25fb9c55781 173 if(ev == release)
kerrysmartin 20:d25fb9c55781 174 {
kerrysmartin 20:d25fb9c55781 175 button_calibration.button_color = BrightCyan;
kerrysmartin 20:d25fb9c55781 176 }
kerrysmartin 20:d25fb9c55781 177 xxxx = xy.x;
kerrysmartin 20:d25fb9c55781 178 yyyy = xy.y;
lizard753 19:fee3f71fab2d 179 }; // end
kerrysmartin 20:d25fb9c55781 180
kerrysmartin 20:d25fb9c55781 181
lizard753 19:fee3f71fab2d 182 }
kerrysmartin 20:d25fb9c55781 183
kerrysmartin 20:d25fb9c55781 184 lcd.printf("x: %d, y: %d, cy: %d\n\r", xxxx, yyyy, cycle);
kerrysmartin 20:d25fb9c55781 185 button_calibration.draw();
lizard753 19:fee3f71fab2d 186 }
kerrysmartin 20:d25fb9c55781 187
kerrysmartin 20:d25fb9c55781 188 //lcd.printf("Cycle: %i, Touch: %i\n\r", cycle, touch);
WiredHome 3:ca6a1026c28e 189 }
kerrysmartin 20:d25fb9c55781 190 }
kerrysmartin 20:d25fb9c55781 191
kerrysmartin 20:d25fb9c55781 192 //
kerrysmartin 20:d25fb9c55781 193 //
kerrysmartin 20:d25fb9c55781 194 // For the Resistive Touch Screen, the following are essential.
kerrysmartin 20:d25fb9c55781 195 // For the Capacitive Touch Screen, none of the following is required.
kerrysmartin 20:d25fb9c55781 196 //
kerrysmartin 20:d25fb9c55781 197 //
kerrysmartin 20:d25fb9c55781 198 #ifndef CAP_TOUCH
kerrysmartin 20:d25fb9c55781 199 // Calibrate the resistive touch screen, and store the data on the
kerrysmartin 20:d25fb9c55781 200 // file system.
kerrysmartin 20:d25fb9c55781 201 //
kerrysmartin 20:d25fb9c55781 202 void CalibrateTS(void)
kerrysmartin 20:d25fb9c55781 203 {
kerrysmartin 20:d25fb9c55781 204 FILE * fh;
kerrysmartin 20:d25fb9c55781 205 tpMatrix_t matrix;
kerrysmartin 20:d25fb9c55781 206 RetCode_t r;
kerrysmartin 20:d25fb9c55781 207 Timer testperiod;
kerrysmartin 20:d25fb9c55781 208
kerrysmartin 20:d25fb9c55781 209 r = lcd.TouchPanelCalibrate("Calibrate the touch panel", &matrix);
kerrysmartin 20:d25fb9c55781 210 if (r == noerror) {
kerrysmartin 20:d25fb9c55781 211 fh = fopen(TS_Config, "wb");
kerrysmartin 20:d25fb9c55781 212 if (fh) {
kerrysmartin 20:d25fb9c55781 213 fwrite(&matrix, sizeof(tpMatrix_t), 1, fh);
kerrysmartin 20:d25fb9c55781 214 fclose(fh);
kerrysmartin 20:d25fb9c55781 215 printf(" tp cal written.\r\n");
kerrysmartin 20:d25fb9c55781 216 lcd.cls();
kerrysmartin 20:d25fb9c55781 217 } else {
kerrysmartin 20:d25fb9c55781 218 printf(" couldn't open tpcal file.\r\n");
kerrysmartin 20:d25fb9c55781 219 }
kerrysmartin 20:d25fb9c55781 220 } else {
kerrysmartin 20:d25fb9c55781 221 printf("error return: %d\r\n", r);
kerrysmartin 20:d25fb9c55781 222 }
kerrysmartin 20:d25fb9c55781 223 lcd.cls();
kerrysmartin 20:d25fb9c55781 224 }
kerrysmartin 20:d25fb9c55781 225
kerrysmartin 20:d25fb9c55781 226 // Try to load a previous resistive touch screen calibration from storage. If it
kerrysmartin 20:d25fb9c55781 227 // doesn't exist, activate the touch screen calibration process.
kerrysmartin 20:d25fb9c55781 228 //
kerrysmartin 20:d25fb9c55781 229 void InitTS(void)
kerrysmartin 20:d25fb9c55781 230 {
kerrysmartin 20:d25fb9c55781 231 FILE * fh;
kerrysmartin 20:d25fb9c55781 232 tpMatrix_t matrix;
kerrysmartin 20:d25fb9c55781 233
kerrysmartin 20:d25fb9c55781 234 fh = fopen(TS_Config, "rb");
kerrysmartin 20:d25fb9c55781 235 if (fh) {
kerrysmartin 20:d25fb9c55781 236 fread(&matrix, sizeof(tpMatrix_t), 1, fh);
kerrysmartin 20:d25fb9c55781 237 fclose(fh);
kerrysmartin 20:d25fb9c55781 238 lcd.TouchPanelSetMatrix(&matrix);
kerrysmartin 20:d25fb9c55781 239 printf(" tp cal loaded.\r\n");
kerrysmartin 20:d25fb9c55781 240 } else {
kerrysmartin 20:d25fb9c55781 241 CalibrateTS();
kerrysmartin 20:d25fb9c55781 242 }
kerrysmartin 20:d25fb9c55781 243 }
kerrysmartin 20:d25fb9c55781 244 #endif // CAP_TOUCH