Library to control a Graphics TFT connected to 4-wire SPI - revised for the Raio RA8875 Display Controller.

Dependents:   FRDM_RA8875_mPaint RA8875_Demo RA8875_KeyPadDemo SignalGenerator ... more

Fork of SPI_TFT by Peter Drescher

See Components - RA8875 Based Display

Enhanced touch-screen support - where it previous supported both the Resistive Touch and Capacitive Touch based on the FT5206 Touch Controller, now it also has support for the GSL1680 Touch Controller.

Offline Help Manual (Windows chm)

/media/uploads/WiredHome/ra8875.zip.bin (download, rename to .zip and unzip)

Committer:
WiredHome
Date:
Wed Feb 13 04:20:12 2019 +0000
Revision:
163:17526689a3ed
Parent:
162:a2d7f1988711
Child:
164:76edd7d9cb68
Add ability to PrintScreen as an 8-bit bitmap, as an alternate to the default of 24-bit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 152:a013ac0133e4 1 // RA8875 Display Controller Library.
WiredHome 152:a013ac0133e4 2 //
WiredHome 152:a013ac0133e4 3 // This is being created for a Raio RA8875-based display from buydisplay.com,
WiredHome 152:a013ac0133e4 4 // which is either 480 x 272 or 800 x 480, using a 4-wire SPI interface.
WiredHome 152:a013ac0133e4 5 // Support is provided for both a keypad and a resistive touch-screen.
WiredHome 152:a013ac0133e4 6 //
WiredHome 152:a013ac0133e4 7 // See the RA8875.h file for full details.
WiredHome 152:a013ac0133e4 8 //
WiredHome 152:a013ac0133e4 9 // 20161106: Updated the initialization to set the various registers based on
WiredHome 152:a013ac0133e4 10 // the BuyDisplay.com example code. This altered several registers
WiredHome 152:a013ac0133e4 11 // for the 800x480 display driver.
WiredHome 152:a013ac0133e4 12 //
WiredHome 19:3f82c1161fd2 13 #include "RA8875.h"
WiredHome 19:3f82c1161fd2 14
WiredHome 145:5eb2492acdda 15 //#include "Utility.h" // private memory manager
WiredHome 145:5eb2492acdda 16 #ifndef UTILITY_H
WiredHome 145:5eb2492acdda 17 #define swMalloc malloc // use the standard
WiredHome 145:5eb2492acdda 18 #define swFree free
WiredHome 145:5eb2492acdda 19 #endif
WiredHome 145:5eb2492acdda 20
WiredHome 41:2956a0a221e5 21 //#define DEBUG "RAIO"
WiredHome 19:3f82c1161fd2 22 // ...
WiredHome 19:3f82c1161fd2 23 // INFO("Stuff to show %d", var); // new-line is automatically appended
WiredHome 19:3f82c1161fd2 24 //
WiredHome 19:3f82c1161fd2 25 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
WiredHome 98:ecebed9b80b2 26 #define INFO(x, ...) std::printf("[INF %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 98:ecebed9b80b2 27 #define WARN(x, ...) std::printf("[WRN %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 98:ecebed9b80b2 28 #define ERR(x, ...) std::printf("[ERR %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 98:ecebed9b80b2 29 static void HexDump(const char * title, const uint8_t * p, int count)
WiredHome 73:f22a18707b5e 30 {
WiredHome 73:f22a18707b5e 31 int i;
WiredHome 73:f22a18707b5e 32 char buf[100] = "0000: ";
WiredHome 73:f22a18707b5e 33
WiredHome 73:f22a18707b5e 34 if (*title)
WiredHome 73:f22a18707b5e 35 INFO("%s", title);
WiredHome 73:f22a18707b5e 36 for (i=0; i<count; ) {
WiredHome 73:f22a18707b5e 37 sprintf(buf + strlen(buf), "%02X ", *(p+i));
WiredHome 73:f22a18707b5e 38 if ((++i & 0x0F) == 0x00) {
WiredHome 73:f22a18707b5e 39 INFO("%s", buf);
WiredHome 73:f22a18707b5e 40 if (i < count)
WiredHome 73:f22a18707b5e 41 sprintf(buf, "%04X: ", i);
WiredHome 73:f22a18707b5e 42 else
WiredHome 73:f22a18707b5e 43 buf[0] = '\0';
WiredHome 73:f22a18707b5e 44 }
WiredHome 73:f22a18707b5e 45 }
WiredHome 73:f22a18707b5e 46 if (strlen(buf))
WiredHome 73:f22a18707b5e 47 INFO("%s", buf);
WiredHome 73:f22a18707b5e 48 }
WiredHome 19:3f82c1161fd2 49 #else
WiredHome 19:3f82c1161fd2 50 #define INFO(x, ...)
WiredHome 19:3f82c1161fd2 51 #define WARN(x, ...)
WiredHome 19:3f82c1161fd2 52 #define ERR(x, ...)
WiredHome 73:f22a18707b5e 53 #define HexDump(a, b, c)
WiredHome 19:3f82c1161fd2 54 #endif
WiredHome 19:3f82c1161fd2 55
WiredHome 109:7b94f06f085b 56 // Defaults. Users can override this with the init() method.
WiredHome 19:3f82c1161fd2 57 #define RA8875_DISPLAY_WIDTH 480
WiredHome 19:3f82c1161fd2 58 #define RA8875_DISPLAY_HEIGHT 272
WiredHome 43:3becae133285 59 #define RA8875_COLORDEPTH_BPP 16 /* Not an API */
WiredHome 19:3f82c1161fd2 60
WiredHome 19:3f82c1161fd2 61 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 62 #define PERFORMANCE_RESET performance.reset()
WiredHome 19:3f82c1161fd2 63 #define REGISTERPERFORMANCE(a) RegisterPerformance(a)
WiredHome 68:ab08efabfc88 64 #define COUNTIDLETIME(a) CountIdleTime(a)
WiredHome 73:f22a18707b5e 65 static const char *metricsName[] = {
WiredHome 109:7b94f06f085b 66 "Cls", "Pixel", "Pixel Stream", "Boolean Stream",
WiredHome 41:2956a0a221e5 67 "Read Pixel", "Read Pixel Stream",
WiredHome 73:f22a18707b5e 68 "Line",
WiredHome 73:f22a18707b5e 69 "Rectangle", "Rounded Rectangle",
WiredHome 68:ab08efabfc88 70 "Triangle", "Circle", "Ellipse"
WiredHome 19:3f82c1161fd2 71 };
WiredHome 91:ca5f829e6d27 72 uint16_t commandsUsed[256]; // track which commands are used with simple counter of number of hits.
WiredHome 19:3f82c1161fd2 73 #else
WiredHome 19:3f82c1161fd2 74 #define PERFORMANCE_RESET
WiredHome 19:3f82c1161fd2 75 #define REGISTERPERFORMANCE(a)
WiredHome 68:ab08efabfc88 76 #define COUNTIDLETIME(a)
WiredHome 19:3f82c1161fd2 77 #endif
WiredHome 19:3f82c1161fd2 78
WiredHome 73:f22a18707b5e 79 // When it is going to poll a register for completion, how many
WiredHome 19:3f82c1161fd2 80 // uSec should it wait between each polling activity.
WiredHome 19:3f82c1161fd2 81 #define POLLWAITuSec 10
WiredHome 19:3f82c1161fd2 82
WiredHome 75:ca78388cfd77 83 // Private RawKeyMap for the Keyboard interface
WiredHome 79:544eb4964795 84 static const uint8_t DefaultKeyMap[22] = {
WiredHome 77:9206c13aa527 85 0,
WiredHome 77:9206c13aa527 86 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
WiredHome 75:ca78388cfd77 87 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
WiredHome 75:ca78388cfd77 88 255
WiredHome 77:9206c13aa527 89 };
WiredHome 75:ca78388cfd77 90
WiredHome 79:544eb4964795 91 static const char * ErrMessages[] = {
WiredHome 79:544eb4964795 92 "noerror", ///< no errors, command completed successfully
WiredHome 89:04575562c961 93 "bad parameter", ///< one or more parameters are invalid
WiredHome 89:04575562c961 94 "file not found", ///< specified file could not be found
WiredHome 89:04575562c961 95 "not bmp format", ///< file is not a .bmp file
WiredHome 89:04575562c961 96 "not ico format", ///< file is not a .ico file
WiredHome 89:04575562c961 97 "not supported format", ///< file format is not yet supported
WiredHome 89:04575562c961 98 "image too big", ///< image is too large for the screen
WiredHome 89:04575562c961 99 "not enough ram", ///< could not allocate ram for scanline
WiredHome 125:7a0b70f56550 100 "touch cal. timeout", ///< calibration could not complete in time
WiredHome 125:7a0b70f56550 101 "external abort", ///< during an idle callback, the user code initiated an abort
WiredHome 79:544eb4964795 102 };
WiredHome 19:3f82c1161fd2 103
WiredHome 163:17526689a3ed 104 typedef struct {
WiredHome 163:17526689a3ed 105 uint8_t b;
WiredHome 163:17526689a3ed 106 uint8_t g;
WiredHome 163:17526689a3ed 107 uint8_t r;
WiredHome 163:17526689a3ed 108 uint8_t a;
WiredHome 163:17526689a3ed 109 } rgbTrio_t;
WiredHome 163:17526689a3ed 110
WiredHome 163:17526689a3ed 111 static const rgbTrio_t WebColorPalette[] = {
WiredHome 163:17526689a3ed 112 {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x33,0xFF}, {0x00,0x00,0x66,0xFF}, {0x00,0x00,0x99,0xFF}, {0x00,0x00,0xCC,0xFF}, {0x00,0x00,0xFF,0xFF},
WiredHome 163:17526689a3ed 113 {0x00,0x33,0x00,0xFF}, {0x00,0x33,0x33,0xFF}, {0x00,0x33,0x66,0xFF}, {0x00,0x33,0x99,0xFF}, {0x00,0x33,0xCC,0xFF}, {0x00,0x33,0xFF,0xFF},
WiredHome 163:17526689a3ed 114 {0x00,0x66,0x00,0xFF}, {0x00,0x66,0x33,0xFF}, {0x00,0x66,0x66,0xFF}, {0x00,0x66,0x99,0xFF}, {0x00,0x66,0xCC,0xFF}, {0x00,0x66,0xFF,0xFF},
WiredHome 163:17526689a3ed 115 {0x00,0x99,0x00,0xFF}, {0x00,0x99,0x33,0xFF}, {0x00,0x99,0x66,0xFF}, {0x00,0x99,0x99,0xFF}, {0x00,0x99,0xCC,0xFF}, {0x00,0x99,0xFF,0xFF},
WiredHome 163:17526689a3ed 116 {0x00,0xCC,0x00,0xFF}, {0x00,0xCC,0x33,0xFF}, {0x00,0xCC,0x66,0xFF}, {0x00,0xCC,0x99,0xFF}, {0x00,0xCC,0xCC,0xFF}, {0x00,0xCC,0xFF,0xFF},
WiredHome 163:17526689a3ed 117 {0x00,0xFF,0x00,0xFF}, {0x00,0xFF,0x33,0xFF}, {0x00,0xFF,0x66,0xFF}, {0x00,0xFF,0x99,0xFF}, {0x00,0xFF,0xCC,0xFF}, {0x00,0xFF,0xFF,0xFF},
WiredHome 163:17526689a3ed 118 {0x33,0x00,0x00,0xFF}, {0x33,0x00,0x33,0xFF}, {0x33,0x00,0x66,0xFF}, {0x33,0x00,0x99,0xFF}, {0x33,0x00,0xCC,0xFF}, {0x33,0x00,0xFF,0xFF},
WiredHome 163:17526689a3ed 119 {0x33,0x33,0x00,0xFF}, {0x33,0x33,0x33,0xFF}, {0x33,0x33,0x66,0xFF}, {0x33,0x33,0x99,0xFF}, {0x33,0x33,0xCC,0xFF}, {0x33,0x33,0xFF,0xFF},
WiredHome 163:17526689a3ed 120 {0x33,0x66,0x00,0xFF}, {0x33,0x66,0x33,0xFF}, {0x33,0x66,0x66,0xFF}, {0x33,0x66,0x99,0xFF}, {0x33,0x66,0xCC,0xFF}, {0x33,0x66,0xFF,0xFF},
WiredHome 163:17526689a3ed 121 {0x33,0x99,0x00,0xFF}, {0x33,0x99,0x33,0xFF}, {0x33,0x99,0x66,0xFF}, {0x33,0x99,0x99,0xFF}, {0x33,0x99,0xCC,0xFF}, {0x33,0x99,0xFF,0xFF},
WiredHome 163:17526689a3ed 122 {0x33,0xCC,0x00,0xFF}, {0x33,0xCC,0x33,0xFF}, {0x33,0xCC,0x66,0xFF}, {0x33,0xCC,0x99,0xFF}, {0x33,0xCC,0xCC,0xFF}, {0x33,0xCC,0xFF,0xFF},
WiredHome 163:17526689a3ed 123 {0x33,0xFF,0x00,0xFF}, {0x33,0xFF,0x33,0xFF}, {0x33,0xFF,0x66,0xFF}, {0x33,0xFF,0x99,0xFF}, {0x33,0xFF,0xCC,0xFF}, {0x33,0xFF,0xFF,0xFF},
WiredHome 163:17526689a3ed 124 {0x66,0x00,0x00,0xFF}, {0x66,0x00,0x33,0xFF}, {0x66,0x00,0x66,0xFF}, {0x66,0x00,0x99,0xFF}, {0x66,0x00,0xCC,0xFF}, {0x66,0x00,0xFF,0xFF},
WiredHome 163:17526689a3ed 125 {0x66,0x33,0x00,0xFF}, {0x66,0x33,0x33,0xFF}, {0x66,0x33,0x66,0xFF}, {0x66,0x33,0x99,0xFF}, {0x66,0x33,0xCC,0xFF}, {0x66,0x33,0xFF,0xFF},
WiredHome 163:17526689a3ed 126 {0x66,0x66,0x00,0xFF}, {0x66,0x66,0x33,0xFF}, {0x66,0x66,0x66,0xFF}, {0x66,0x66,0x99,0xFF}, {0x66,0x66,0xCC,0xFF}, {0x66,0x66,0xFF,0xFF},
WiredHome 163:17526689a3ed 127 {0x66,0x99,0x00,0xFF}, {0x66,0x99,0x33,0xFF}, {0x66,0x99,0x66,0xFF}, {0x66,0x99,0x99,0xFF}, {0x66,0x99,0xCC,0xFF}, {0x66,0x99,0xFF,0xFF},
WiredHome 163:17526689a3ed 128 {0x66,0xCC,0x00,0xFF}, {0x66,0xCC,0x33,0xFF}, {0x66,0xCC,0x66,0xFF}, {0x66,0xCC,0x99,0xFF}, {0x66,0xCC,0xCC,0xFF}, {0x66,0xCC,0xFF,0xFF},
WiredHome 163:17526689a3ed 129 {0x66,0xFF,0x00,0xFF}, {0x66,0xFF,0x33,0xFF}, {0x66,0xFF,0x66,0xFF}, {0x66,0xFF,0x99,0xFF}, {0x66,0xFF,0xCC,0xFF}, {0x66,0xFF,0xFF,0xFF},
WiredHome 163:17526689a3ed 130 {0x99,0x00,0x00,0xFF}, {0x99,0x00,0x33,0xFF}, {0x99,0x00,0x66,0xFF}, {0x99,0x00,0x99,0xFF}, {0x99,0x00,0xCC,0xFF}, {0x99,0x00,0xFF,0xFF},
WiredHome 163:17526689a3ed 131 {0x99,0x33,0x00,0xFF}, {0x99,0x33,0x33,0xFF}, {0x99,0x33,0x66,0xFF}, {0x99,0x33,0x99,0xFF}, {0x99,0x33,0xCC,0xFF}, {0x99,0x33,0xFF,0xFF},
WiredHome 163:17526689a3ed 132 {0x99,0x66,0x00,0xFF}, {0x99,0x66,0x33,0xFF}, {0x99,0x66,0x66,0xFF}, {0x99,0x66,0x99,0xFF}, {0x99,0x66,0xCC,0xFF}, {0x99,0x66,0xFF,0xFF},
WiredHome 163:17526689a3ed 133 {0x99,0x99,0x00,0xFF}, {0x99,0x99,0x33,0xFF}, {0x99,0x99,0x66,0xFF}, {0x99,0x99,0x99,0xFF}, {0x99,0x99,0xCC,0xFF}, {0x99,0x99,0xFF,0xFF},
WiredHome 163:17526689a3ed 134 {0x99,0xCC,0x00,0xFF}, {0x99,0xCC,0x33,0xFF}, {0x99,0xCC,0x66,0xFF}, {0x99,0xCC,0x99,0xFF}, {0x99,0xCC,0xCC,0xFF}, {0x99,0xCC,0xFF,0xFF},
WiredHome 163:17526689a3ed 135 {0x99,0xFF,0x00,0xFF}, {0x99,0xFF,0x33,0xFF}, {0x99,0xFF,0x66,0xFF}, {0x99,0xFF,0x99,0xFF}, {0x99,0xFF,0xCC,0xFF}, {0x99,0xFF,0xFF,0xFF},
WiredHome 163:17526689a3ed 136 {0xCC,0x00,0x00,0xFF}, {0xCC,0x00,0x33,0xFF}, {0xCC,0x00,0x66,0xFF}, {0xCC,0x00,0x99,0xFF}, {0xCC,0x00,0xCC,0xFF}, {0xCC,0x00,0xFF,0xFF},
WiredHome 163:17526689a3ed 137 {0xCC,0x33,0x00,0xFF}, {0xCC,0x33,0x33,0xFF}, {0xCC,0x33,0x66,0xFF}, {0xCC,0x33,0x99,0xFF}, {0xCC,0x33,0xCC,0xFF}, {0xCC,0x33,0xFF,0xFF},
WiredHome 163:17526689a3ed 138 {0xCC,0x66,0x00,0xFF}, {0xCC,0x66,0x33,0xFF}, {0xCC,0x66,0x66,0xFF}, {0xCC,0x66,0x99,0xFF}, {0xCC,0x66,0xCC,0xFF}, {0xCC,0x66,0xFF,0xFF},
WiredHome 163:17526689a3ed 139 {0xCC,0x99,0x00,0xFF}, {0xCC,0x99,0x33,0xFF}, {0xCC,0x99,0x66,0xFF}, {0xCC,0x99,0x99,0xFF}, {0xCC,0x99,0xCC,0xFF}, {0xCC,0x99,0xFF,0xFF},
WiredHome 163:17526689a3ed 140 {0xCC,0xCC,0x00,0xFF}, {0xCC,0xCC,0x33,0xFF}, {0xCC,0xCC,0x66,0xFF}, {0xCC,0xCC,0x99,0xFF}, {0xCC,0xCC,0xCC,0xFF}, {0xCC,0xCC,0xFF,0xFF},
WiredHome 163:17526689a3ed 141 {0xCC,0xFF,0x00,0xFF}, {0xCC,0xFF,0x33,0xFF}, {0xCC,0xFF,0x66,0xFF}, {0xCC,0xFF,0x99,0xFF}, {0xCC,0xFF,0xCC,0xFF}, {0xCC,0xFF,0xFF,0xFF},
WiredHome 163:17526689a3ed 142 {0xFF,0x00,0x00,0xFF}, {0xFF,0x00,0x33,0xFF}, {0xFF,0x00,0x66,0xFF}, {0xFF,0x00,0x99,0xFF}, {0xFF,0x00,0xCC,0xFF}, {0xFF,0x00,0xFF,0xFF},
WiredHome 163:17526689a3ed 143 {0xFF,0x33,0x00,0xFF}, {0xFF,0x33,0x33,0xFF}, {0xFF,0x33,0x66,0xFF}, {0xFF,0x33,0x99,0xFF}, {0xFF,0x33,0xCC,0xFF}, {0xFF,0x33,0xFF,0xFF},
WiredHome 163:17526689a3ed 144 {0xFF,0x66,0x00,0xFF}, {0xFF,0x66,0x33,0xFF}, {0xFF,0x66,0x66,0xFF}, {0xFF,0x66,0x99,0xFF}, {0xFF,0x66,0xCC,0xFF}, {0xFF,0x66,0xFF,0xFF},
WiredHome 163:17526689a3ed 145 {0xFF,0x99,0x00,0xFF}, {0xFF,0x99,0x33,0xFF}, {0xFF,0x99,0x66,0xFF}, {0xFF,0x99,0x99,0xFF}, {0xFF,0x99,0xCC,0xFF}, {0xFF,0x99,0xFF,0xFF},
WiredHome 163:17526689a3ed 146 {0xFF,0xCC,0x00,0xFF}, {0xFF,0xCC,0x33,0xFF}, {0xFF,0xCC,0x66,0xFF}, {0xFF,0xCC,0x99,0xFF}, {0xFF,0xCC,0xCC,0xFF}, {0xFF,0xCC,0xFF,0xFF},
WiredHome 163:17526689a3ed 147 {0xFF,0xFF,0x00,0xFF}, {0xFF,0xFF,0x33,0xFF}, {0xFF,0xFF,0x66,0xFF}, {0xFF,0xFF,0x99,0xFF}, {0xFF,0xFF,0xCC,0xFF}, {0xFF,0xFF,0xFF,0xFF},
WiredHome 163:17526689a3ed 148
WiredHome 163:17526689a3ed 149 {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF},
WiredHome 163:17526689a3ed 150 {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF},
WiredHome 163:17526689a3ed 151 {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF},
WiredHome 163:17526689a3ed 152 {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF},
WiredHome 163:17526689a3ed 153 {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF},
WiredHome 163:17526689a3ed 154 {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF},
WiredHome 163:17526689a3ed 155 {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF}, {0x00,0x00,0x00,0xFF},
WiredHome 163:17526689a3ed 156 };
WiredHome 163:17526689a3ed 157
WiredHome 163:17526689a3ed 158 #define sqr(a) (double)((a) * (a))
WiredHome 163:17526689a3ed 159
WiredHome 163:17526689a3ed 160 static int FindNearestWebColor(uint8_t r, uint8_t g, uint8_t b) {
WiredHome 163:17526689a3ed 161 int bestNdx = 0;
WiredHome 163:17526689a3ed 162 float bestDiff = sqrt(sqr(r - WebColorPalette[0].r) + sqr(g - WebColorPalette[0].g) + sqr(b - WebColorPalette[0].b));
WiredHome 163:17526689a3ed 163 for (int i=1; i<216; i++) {
WiredHome 163:17526689a3ed 164 float thisDiff = sqrt(sqr(r - WebColorPalette[i].r) + sqr(g - WebColorPalette[i].g) + sqr(b - WebColorPalette[i].b));
WiredHome 163:17526689a3ed 165 if (thisDiff < bestDiff) {
WiredHome 163:17526689a3ed 166 bestDiff = thisDiff;
WiredHome 163:17526689a3ed 167 bestNdx = i;
WiredHome 163:17526689a3ed 168 }
WiredHome 163:17526689a3ed 169 }
WiredHome 163:17526689a3ed 170 return bestNdx;
WiredHome 163:17526689a3ed 171 }
WiredHome 163:17526689a3ed 172
WiredHome 124:1690a7ae871c 173 RA8875::RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset,
WiredHome 124:1690a7ae871c 174 const char *name)
WiredHome 58:26658a56112a 175 : GraphicsDisplay(name)
WiredHome 58:26658a56112a 176 , spi(mosi, miso, sclk)
WiredHome 19:3f82c1161fd2 177 , cs(csel)
WiredHome 19:3f82c1161fd2 178 , res(reset)
WiredHome 19:3f82c1161fd2 179 {
WiredHome 124:1690a7ae871c 180 useTouchPanel = TP_NONE;
WiredHome 157:1565f38ca44b 181 tpFQFN = NULL;
WiredHome 157:1565f38ca44b 182 tpCalMessage = NULL;
WiredHome 124:1690a7ae871c 183 m_irq = NULL;
WiredHome 124:1690a7ae871c 184 m_i2c = NULL;
WiredHome 96:40b74dd3695b 185 c_callback = NULL;
WiredHome 96:40b74dd3695b 186 obj_callback = NULL;
WiredHome 96:40b74dd3695b 187 method_callback = NULL;
WiredHome 123:2f45e80fec5f 188 idle_callback = NULL;
WiredHome 153:8a85efb3eb71 189 fontScaleX = fontScaleY = 1;
WiredHome 19:3f82c1161fd2 190 }
WiredHome 19:3f82c1161fd2 191
WiredHome 124:1690a7ae871c 192
WiredHome 124:1690a7ae871c 193 RA8875::RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset,
WiredHome 124:1690a7ae871c 194 PinName sda, PinName scl, PinName irq, const char * name)
WiredHome 124:1690a7ae871c 195 : GraphicsDisplay(name)
WiredHome 124:1690a7ae871c 196 , spi(mosi, miso, sclk)
WiredHome 124:1690a7ae871c 197 , cs(csel)
WiredHome 124:1690a7ae871c 198 , res(reset)
WiredHome 124:1690a7ae871c 199 {
WiredHome 124:1690a7ae871c 200 useTouchPanel = TP_CAP;
WiredHome 157:1565f38ca44b 201 tpFQFN = NULL;
WiredHome 157:1565f38ca44b 202 tpCalMessage = NULL;
WiredHome 124:1690a7ae871c 203 m_irq = new InterruptIn(irq);
WiredHome 124:1690a7ae871c 204 m_i2c = new I2C(sda, scl);
WiredHome 124:1690a7ae871c 205 c_callback = NULL;
WiredHome 124:1690a7ae871c 206 obj_callback = NULL;
WiredHome 124:1690a7ae871c 207 method_callback = NULL;
WiredHome 124:1690a7ae871c 208 idle_callback = NULL;
WiredHome 153:8a85efb3eb71 209 fontScaleX = fontScaleY = 1;
WiredHome 124:1690a7ae871c 210
WiredHome 124:1690a7ae871c 211 // Cap touch panel config
WiredHome 124:1690a7ae871c 212 m_addr = (FT5206_I2C_ADDRESS << 1);
WiredHome 124:1690a7ae871c 213 m_i2c->frequency(FT5206_I2C_FREQUENCY);
WiredHome 124:1690a7ae871c 214
WiredHome 124:1690a7ae871c 215 // Interrupt
WiredHome 124:1690a7ae871c 216 m_irq->mode(PullUp);
WiredHome 124:1690a7ae871c 217 m_irq->enable_irq();
WiredHome 155:b3f225ae572c 218 #if MBED_VERSION >= MBED_ENCODE_VERSION(5,8,0)
WiredHome 155:b3f225ae572c 219 eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
WiredHome 155:b3f225ae572c 220 m_irq->fall(queue.event(callback(this, &RA8875::TouchPanelISR)));
WiredHome 155:b3f225ae572c 221 #elif (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 128) // Is this the right version?
WiredHome 145:5eb2492acdda 222 m_irq->fall(callback(this, &RA8875::TouchPanelISR));
WiredHome 150:35a4db3081c1 223 #else
WiredHome 150:35a4db3081c1 224 m_irq->fall(this, &RA8875::TouchPanelISR);
WiredHome 150:35a4db3081c1 225 #endif
WiredHome 124:1690a7ae871c 226 TouchPanelInit();
WiredHome 124:1690a7ae871c 227 }
WiredHome 124:1690a7ae871c 228
WiredHome 124:1690a7ae871c 229
WiredHome 19:3f82c1161fd2 230 //RA8875::~RA8875()
WiredHome 19:3f82c1161fd2 231 //{
WiredHome 19:3f82c1161fd2 232 //}
WiredHome 19:3f82c1161fd2 233
WiredHome 154:ad2450fc3dc3 234
WiredHome 131:5bd6ba2ee4a1 235 RetCode_t RA8875::init(int width, int height, int color_bpp, uint8_t poweron, bool keypadon, bool touchscreenon)
WiredHome 79:544eb4964795 236 {
WiredHome 98:ecebed9b80b2 237 font = NULL; // no external font, use internal.
WiredHome 98:ecebed9b80b2 238 pKeyMap = DefaultKeyMap; // set default key map
WiredHome 98:ecebed9b80b2 239 _select(false); // deselect the display
WiredHome 98:ecebed9b80b2 240 frequency(RA8875_DEFAULT_SPI_FREQ); // data rate
WiredHome 79:544eb4964795 241 Reset();
WiredHome 134:f028ed71a0af 242 // Set PLL based on display size from buy-display.com sample code
WiredHome 134:f028ed71a0af 243 if (width == 800) {
WiredHome 134:f028ed71a0af 244 WriteCommand(0x88, 0x0C); // PLLC1 - Phase Lock Loop registers
WiredHome 134:f028ed71a0af 245 } else {
WiredHome 134:f028ed71a0af 246 WriteCommand(0x88, 0x0B); // PLLC1 - Phase Lock Loop registers
WiredHome 134:f028ed71a0af 247 }
WiredHome 79:544eb4964795 248 wait_ms(1);
WiredHome 79:544eb4964795 249 WriteCommand(0x89, 0x02);
WiredHome 79:544eb4964795 250 wait_ms(1);
WiredHome 79:544eb4964795 251
WiredHome 79:544eb4964795 252 // System Config Register (SYSR)
WiredHome 105:4f116006ba1f 253 screenbpp = color_bpp;
WiredHome 79:544eb4964795 254 if (color_bpp == 16) {
WiredHome 79:544eb4964795 255 WriteCommand(0x10, 0x0C); // 16-bpp (65K colors) color depth, 8-bit interface
WiredHome 79:544eb4964795 256 } else { // color_bpp == 8
WiredHome 79:544eb4964795 257 WriteCommand(0x10, 0x00); // 8-bpp (256 colors)
WiredHome 79:544eb4964795 258 }
WiredHome 134:f028ed71a0af 259
WiredHome 134:f028ed71a0af 260 // Set Pixel Clock Setting Register (PCSR) based on display size from buy-display.com sample code
WiredHome 134:f028ed71a0af 261 if (width == 800) {
WiredHome 134:f028ed71a0af 262 WriteCommand(0x04, 0x81); // PDAT on PCLK falling edge, PCLK = 4 x System Clock
WiredHome 134:f028ed71a0af 263 wait_ms(1);
WiredHome 134:f028ed71a0af 264
WiredHome 134:f028ed71a0af 265 // Horizontal Settings
WiredHome 134:f028ed71a0af 266 screenwidth = width;
WiredHome 134:f028ed71a0af 267 WriteCommand(0x14, width/8 - 1); //HDWR//Horizontal Display Width Setting Bit[6:0]
WiredHome 134:f028ed71a0af 268 WriteCommand(0x15, 0x00); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
WiredHome 134:f028ed71a0af 269 WriteCommand(0x16, 0x03); //HNDR//Horizontal Non-Display Period Bit[4:0]
WiredHome 134:f028ed71a0af 270 WriteCommand(0x17, 0x03); //HSTR//HSYNC Start Position[4:0]
WiredHome 134:f028ed71a0af 271 WriteCommand(0x18, 0x0B); //HPWR//HSYNC Polarity ,The period width of HSYNC.
WiredHome 134:f028ed71a0af 272
WiredHome 134:f028ed71a0af 273 // Vertical Settings
WiredHome 134:f028ed71a0af 274 screenheight = height;
WiredHome 134:f028ed71a0af 275 WriteCommand(0x19, (height-1)&0xFF); //VDHR0 //Vertical Display Height Bit [7:0]
WiredHome 134:f028ed71a0af 276 WriteCommand(0x1a, (height-1)>>8); //VDHR1 //Vertical Display Height Bit [8]
WiredHome 134:f028ed71a0af 277 WriteCommand(0x1b, 0x20); //VNDR0 //Vertical Non-Display Period Bit [7:0]
WiredHome 134:f028ed71a0af 278 WriteCommand(0x1c, 0x00); //VNDR1 //Vertical Non-Display Period Bit [8]
WiredHome 134:f028ed71a0af 279 WriteCommand(0x1d, 0x16); //VSTR0 //VSYNC Start Position[7:0]
WiredHome 134:f028ed71a0af 280 WriteCommand(0x1e, 0x00); //VSTR1 //VSYNC Start Position[8]
WiredHome 134:f028ed71a0af 281 WriteCommand(0x1f, 0x01); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
WiredHome 134:f028ed71a0af 282 } else {
WiredHome 134:f028ed71a0af 283 WriteCommand(0x04, 0x82); // PDAT on PCLK falling edge, PCLK = 4 x System Clock
WiredHome 134:f028ed71a0af 284 wait_ms(1);
WiredHome 134:f028ed71a0af 285
WiredHome 134:f028ed71a0af 286 // Horizontal Settings
WiredHome 134:f028ed71a0af 287 screenwidth = width;
WiredHome 134:f028ed71a0af 288 WriteCommand(0x14, width/8 - 1); //HDWR//Horizontal Display Width Setting Bit[6:0]
WiredHome 134:f028ed71a0af 289 WriteCommand(0x15, 0x02); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
WiredHome 134:f028ed71a0af 290 WriteCommand(0x16, 0x03); //HNDR//Horizontal Non-Display Period Bit[4:0]
WiredHome 134:f028ed71a0af 291 WriteCommand(0x17, 0x01); //HSTR//HSYNC Start Position[4:0]
WiredHome 134:f028ed71a0af 292 WriteCommand(0x18, 0x03); //HPWR//HSYNC Polarity ,The period width of HSYNC.
WiredHome 134:f028ed71a0af 293
WiredHome 134:f028ed71a0af 294 // Vertical Settings
WiredHome 134:f028ed71a0af 295 screenheight = height;
WiredHome 134:f028ed71a0af 296 WriteCommand(0x19, (height-1)&0xFF); //VDHR0 //Vertical Display Height Bit [7:0]
WiredHome 134:f028ed71a0af 297 WriteCommand(0x1a, (height-1)>>8); //VDHR1 //Vertical Display Height Bit [8]
WiredHome 134:f028ed71a0af 298 WriteCommand(0x1b, 0x0F); //VNDR0 //Vertical Non-Display Period Bit [7:0]
WiredHome 134:f028ed71a0af 299 WriteCommand(0x1c, 0x00); //VNDR1 //Vertical Non-Display Period Bit [8]
WiredHome 134:f028ed71a0af 300 WriteCommand(0x1d, 0x0e); //VSTR0 //VSYNC Start Position[7:0]
WiredHome 134:f028ed71a0af 301 WriteCommand(0x1e, 0x06); //VSTR1 //VSYNC Start Position[8]
WiredHome 134:f028ed71a0af 302 WriteCommand(0x1f, 0x01); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
WiredHome 134:f028ed71a0af 303 }
WiredHome 79:544eb4964795 304
WiredHome 100:0b084475d5a9 305 portraitmode = false;
WiredHome 133:e36dcfc2d756 306
WiredHome 79:544eb4964795 307 if (width >= 800 && height >= 480 && color_bpp > 8) {
WiredHome 79:544eb4964795 308 WriteCommand(0x20, 0x00); // DPCR - 1-layer mode when the resolution is too high
WiredHome 79:544eb4964795 309 } else {
WiredHome 79:544eb4964795 310 WriteCommand(0x20, 0x80); // DPCR - 2-layer mode
WiredHome 79:544eb4964795 311 }
WiredHome 79:544eb4964795 312
WiredHome 79:544eb4964795 313 // Set display image to Blue on Black as default
WiredHome 79:544eb4964795 314 window(0,0, width, height); // Initialize to full screen
WiredHome 79:544eb4964795 315 SetTextCursorControl();
WiredHome 79:544eb4964795 316 foreground(Blue);
WiredHome 79:544eb4964795 317 background(Black);
WiredHome 79:544eb4964795 318 cls(3);
WiredHome 79:544eb4964795 319
WiredHome 79:544eb4964795 320 Power(poweron);
WiredHome 131:5bd6ba2ee4a1 321 Backlight_u8(poweron);
WiredHome 81:01da2e34283d 322 if (keypadon)
WiredHome 81:01da2e34283d 323 KeypadInit();
WiredHome 124:1690a7ae871c 324 if (touchscreenon) {
WiredHome 124:1690a7ae871c 325 if (useTouchPanel == TP_NONE)
WiredHome 124:1690a7ae871c 326 useTouchPanel = TP_RES;
WiredHome 81:01da2e34283d 327 TouchPanelInit();
WiredHome 124:1690a7ae871c 328 }
WiredHome 79:544eb4964795 329 #ifdef PERF_METRICS
WiredHome 79:544eb4964795 330 performance.start();
WiredHome 79:544eb4964795 331 ClearPerformance();
WiredHome 79:544eb4964795 332 #endif
WiredHome 79:544eb4964795 333 return noerror;
WiredHome 79:544eb4964795 334 }
WiredHome 79:544eb4964795 335
WiredHome 79:544eb4964795 336
WiredHome 79:544eb4964795 337 RetCode_t RA8875::Reset(void)
WiredHome 79:544eb4964795 338 {
WiredHome 79:544eb4964795 339 RetCode_t ret;
WiredHome 79:544eb4964795 340
WiredHome 94:203729061e48 341 #if 0
WiredHome 94:203729061e48 342 if (res != (PinName)NC) {
WiredHome 94:203729061e48 343 res = 0; // Active low - assert reset
WiredHome 94:203729061e48 344 wait_ms(2); // must be > 1024 clock periods. (@25 MHz, this is 40.96 usec)
WiredHome 94:203729061e48 345 res = 1; // de-assert reset
WiredHome 94:203729061e48 346 }
WiredHome 94:203729061e48 347 #endif
WiredHome 94:203729061e48 348 ret = WriteCommand(0x01, 0x01); // Apply Display Off, Reset
WiredHome 94:203729061e48 349 wait_ms(2); // no idea if I need to wait, or how long
WiredHome 79:544eb4964795 350 if (ret == noerror) {
WiredHome 94:203729061e48 351 ret = WriteCommand(0x01, 0x00); // Display off, Remove reset
WiredHome 94:203729061e48 352 wait_ms(2); // no idea if I need to wait, or how long
WiredHome 79:544eb4964795 353 }
WiredHome 79:544eb4964795 354 return ret;
WiredHome 79:544eb4964795 355 }
WiredHome 79:544eb4964795 356
WiredHome 79:544eb4964795 357
WiredHome 79:544eb4964795 358 const char * RA8875::GetErrorMessage(RetCode_t code)
WiredHome 79:544eb4964795 359 {
WiredHome 79:544eb4964795 360 if (code >= LastErrCode)
WiredHome 79:544eb4964795 361 code = bad_parameter;
WiredHome 79:544eb4964795 362 return ErrMessages[code];
WiredHome 79:544eb4964795 363 }
WiredHome 79:544eb4964795 364
WiredHome 79:544eb4964795 365
WiredHome 61:8f3153bf0baa 366 uint16_t RA8875::GetDrawingLayer(void)
WiredHome 61:8f3153bf0baa 367 {
WiredHome 61:8f3153bf0baa 368 return (ReadCommand(0x41) & 0x01);
WiredHome 61:8f3153bf0baa 369 }
WiredHome 43:3becae133285 370
WiredHome 79:544eb4964795 371
WiredHome 143:e872d65a710d 372 RetCode_t RA8875::SelectDrawingLayer(uint16_t layer, uint16_t * prevLayer)
WiredHome 43:3becae133285 373 {
WiredHome 142:6e9bff59878a 374 unsigned char mwcr1 = ReadCommand(0x41); // retain all but the currently selected layer
WiredHome 143:e872d65a710d 375
WiredHome 143:e872d65a710d 376 if (prevLayer)
WiredHome 143:e872d65a710d 377 *prevLayer = mwcr1 & 1;
WiredHome 142:6e9bff59878a 378
WiredHome 142:6e9bff59878a 379 mwcr1 &= ~0x01; // remove the current layer
WiredHome 106:c80828f5dea4 380 if (screenwidth >= 800 && screenheight >= 480 && screenbpp > 8) {
WiredHome 142:6e9bff59878a 381 layer = 0;
WiredHome 43:3becae133285 382 } else if (layer > 1) {
WiredHome 142:6e9bff59878a 383 layer = 0;
WiredHome 43:3becae133285 384 }
WiredHome 143:e872d65a710d 385 return WriteCommand(0x41, mwcr1 | layer);
WiredHome 43:3becae133285 386 }
WiredHome 43:3becae133285 387
WiredHome 44:207594dece70 388
WiredHome 82:f7d300f26540 389 RA8875::LayerMode_T RA8875::GetLayerMode(void)
WiredHome 82:f7d300f26540 390 {
WiredHome 82:f7d300f26540 391 return (LayerMode_T)(ReadCommand(0x52) & 0x7);
WiredHome 82:f7d300f26540 392 }
WiredHome 82:f7d300f26540 393
WiredHome 82:f7d300f26540 394
WiredHome 53:86d24b9480b9 395 RetCode_t RA8875::SetLayerMode(LayerMode_T mode)
WiredHome 44:207594dece70 396 {
WiredHome 53:86d24b9480b9 397 unsigned char ltpr0 = ReadCommand(0x52) & ~0x7; // retain all but the display layer mode
WiredHome 105:4f116006ba1f 398
WiredHome 53:86d24b9480b9 399 if (mode <= (LayerMode_T)6) {
WiredHome 53:86d24b9480b9 400 WriteCommand(0x52, ltpr0 | (mode & 0x7));
WiredHome 53:86d24b9480b9 401 return noerror;
WiredHome 53:86d24b9480b9 402 } else {
WiredHome 53:86d24b9480b9 403 return bad_parameter;
WiredHome 53:86d24b9480b9 404 }
WiredHome 44:207594dece70 405 }
WiredHome 44:207594dece70 406
WiredHome 44:207594dece70 407
WiredHome 44:207594dece70 408 RetCode_t RA8875::SetLayerTransparency(uint8_t layer1, uint8_t layer2)
WiredHome 44:207594dece70 409 {
WiredHome 44:207594dece70 410 if (layer1 > 8)
WiredHome 44:207594dece70 411 layer1 = 8;
WiredHome 44:207594dece70 412 if (layer2 > 8)
WiredHome 44:207594dece70 413 layer2 = 8;
WiredHome 44:207594dece70 414 WriteCommand(0x53, ((layer2 & 0xF) << 4) | (layer1 & 0xF));
WiredHome 44:207594dece70 415 return noerror;
WiredHome 44:207594dece70 416 }
WiredHome 44:207594dece70 417
WiredHome 44:207594dece70 418
WiredHome 53:86d24b9480b9 419 RetCode_t RA8875::SetBackgroundTransparencyColor(color_t color)
WiredHome 53:86d24b9480b9 420 {
WiredHome 133:e36dcfc2d756 421 return _writeColorTrio(0x67, color);
WiredHome 53:86d24b9480b9 422 }
WiredHome 53:86d24b9480b9 423
WiredHome 79:544eb4964795 424
WiredHome 73:f22a18707b5e 425 color_t RA8875::GetBackgroundTransparencyColor(void)
WiredHome 73:f22a18707b5e 426 {
WiredHome 73:f22a18707b5e 427 RGBQUAD q;
WiredHome 105:4f116006ba1f 428
WiredHome 73:f22a18707b5e 429 q.rgbRed = ReadCommand(0x67);
WiredHome 73:f22a18707b5e 430 q.rgbGreen = ReadCommand(0x68);
WiredHome 73:f22a18707b5e 431 q.rgbBlue = ReadCommand(0x69);
WiredHome 73:f22a18707b5e 432 return RGBQuadToRGB16(&q, 0);
WiredHome 73:f22a18707b5e 433 }
WiredHome 73:f22a18707b5e 434
WiredHome 71:dcac8efd842d 435
WiredHome 77:9206c13aa527 436 RetCode_t RA8875::KeypadInit(bool scanEnable, bool longDetect, uint8_t sampleTime, uint8_t scanFrequency,
WiredHome 77:9206c13aa527 437 uint8_t longTimeAdjustment, bool interruptEnable, bool wakeupEnable)
WiredHome 71:dcac8efd842d 438 {
WiredHome 71:dcac8efd842d 439 uint8_t value = 0;
WiredHome 77:9206c13aa527 440
WiredHome 71:dcac8efd842d 441 if (sampleTime > 3 || scanFrequency > 7 || longTimeAdjustment > 3)
WiredHome 71:dcac8efd842d 442 return bad_parameter;
WiredHome 71:dcac8efd842d 443 value |= (scanEnable) ? 0x80 : 0x00;
WiredHome 71:dcac8efd842d 444 value |= (longDetect) ? 0x40 : 0x00;
WiredHome 71:dcac8efd842d 445 value |= (sampleTime & 0x03) << 4;
WiredHome 71:dcac8efd842d 446 value |= (scanFrequency & 0x07);
WiredHome 75:ca78388cfd77 447 WriteCommand(0xC0, value); // KSCR1 - Enable Key Scan (and ignore possibility of an error)
WiredHome 77:9206c13aa527 448
WiredHome 71:dcac8efd842d 449 value = 0;
WiredHome 71:dcac8efd842d 450 value |= (wakeupEnable) ? 0x80 : 0x00;
WiredHome 71:dcac8efd842d 451 value |= (longTimeAdjustment & 0x03) << 2;
WiredHome 75:ca78388cfd77 452 WriteCommand(0xC1, value); // KSCR2 - (and ignore possibility of an error)
WiredHome 77:9206c13aa527 453
WiredHome 75:ca78388cfd77 454 value = ReadCommand(0xF0); // (and ignore possibility of an error)
WiredHome 71:dcac8efd842d 455 value &= ~0x10;
WiredHome 71:dcac8efd842d 456 value |= (interruptEnable) ? 0x10 : 0x00;
WiredHome 75:ca78388cfd77 457 return WriteCommand(0xF0, value); // INT
WiredHome 71:dcac8efd842d 458 }
WiredHome 71:dcac8efd842d 459
WiredHome 79:544eb4964795 460
WiredHome 75:ca78388cfd77 461 RetCode_t RA8875::SetKeyMap(const uint8_t * CodeList)
WiredHome 75:ca78388cfd77 462 {
WiredHome 75:ca78388cfd77 463 pKeyMap = CodeList;
WiredHome 75:ca78388cfd77 464 return noerror;
WiredHome 75:ca78388cfd77 465 }
WiredHome 75:ca78388cfd77 466
WiredHome 79:544eb4964795 467
WiredHome 75:ca78388cfd77 468 bool RA8875::readable(void)
WiredHome 71:dcac8efd842d 469 {
WiredHome 71:dcac8efd842d 470 return (ReadCommand(0xF1) & 0x10); // check KS status - true if kbhit
WiredHome 71:dcac8efd842d 471 }
WiredHome 71:dcac8efd842d 472
WiredHome 79:544eb4964795 473
WiredHome 75:ca78388cfd77 474 uint8_t RA8875::getc(void)
WiredHome 71:dcac8efd842d 475 {
WiredHome 79:544eb4964795 476 //#define GETC_DEV // for development
WiredHome 77:9206c13aa527 477 #ifdef GETC_DEV
WiredHome 75:ca78388cfd77 478 uint8_t keyCode1, keyCode2;
WiredHome 77:9206c13aa527 479 #endif
WiredHome 75:ca78388cfd77 480 uint8_t keyCode3;
WiredHome 75:ca78388cfd77 481 static uint8_t count = 0;
WiredHome 75:ca78388cfd77 482 uint8_t col, row;
WiredHome 75:ca78388cfd77 483 uint8_t key;
WiredHome 123:2f45e80fec5f 484
WiredHome 75:ca78388cfd77 485 while (!readable()) {
WiredHome 71:dcac8efd842d 486 wait_us(POLLWAITuSec);
WiredHome 75:ca78388cfd77 487 // COUNTIDLETIME(POLLWAITuSec); // As it is voluntary to call the getc and pend. Don't tally it.
WiredHome 123:2f45e80fec5f 488 if (idle_callback) {
WiredHome 149:c62c4b2d6a15 489 if (external_abort == (*idle_callback)(getc_wait, 0)) {
WiredHome 123:2f45e80fec5f 490 return 0;
WiredHome 123:2f45e80fec5f 491 }
WiredHome 123:2f45e80fec5f 492 }
WiredHome 71:dcac8efd842d 493 }
WiredHome 71:dcac8efd842d 494 // read the key press number
WiredHome 71:dcac8efd842d 495 uint8_t keyNumReg = ReadCommand(0xC1) & 0x03;
WiredHome 75:ca78388cfd77 496 count++;
WiredHome 75:ca78388cfd77 497 switch (keyNumReg) {
WiredHome 75:ca78388cfd77 498 case 0x01: // one key
WiredHome 75:ca78388cfd77 499 keyCode3 = ReadCommand(0xC2);
WiredHome 77:9206c13aa527 500 #ifdef GETC_DEV
WiredHome 75:ca78388cfd77 501 keyCode2 = 0;
WiredHome 75:ca78388cfd77 502 keyCode1 = 0;
WiredHome 77:9206c13aa527 503 #endif
WiredHome 75:ca78388cfd77 504 break;
WiredHome 75:ca78388cfd77 505 case 0x02: // two keys
WiredHome 75:ca78388cfd77 506 keyCode3 = ReadCommand(0xC3);
WiredHome 77:9206c13aa527 507 #ifdef GETC_DEV
WiredHome 75:ca78388cfd77 508 keyCode2 = ReadCommand(0xC2);
WiredHome 75:ca78388cfd77 509 keyCode1 = 0;
WiredHome 77:9206c13aa527 510 #endif
WiredHome 75:ca78388cfd77 511 break;
WiredHome 75:ca78388cfd77 512 case 0x03: // three keys
WiredHome 75:ca78388cfd77 513 keyCode3 = ReadCommand(0xC4);
WiredHome 77:9206c13aa527 514 #ifdef GETC_DEV
WiredHome 75:ca78388cfd77 515 keyCode2 = ReadCommand(0xC3);
WiredHome 75:ca78388cfd77 516 keyCode1 = ReadCommand(0xC2);
WiredHome 77:9206c13aa527 517 #endif
WiredHome 75:ca78388cfd77 518 break;
WiredHome 75:ca78388cfd77 519 default: // no keys (key released)
WiredHome 75:ca78388cfd77 520 keyCode3 = 0xFF;
WiredHome 77:9206c13aa527 521 #ifdef GETC_DEV
WiredHome 75:ca78388cfd77 522 keyCode2 = 0;
WiredHome 75:ca78388cfd77 523 keyCode1 = 0;
WiredHome 77:9206c13aa527 524 #endif
WiredHome 75:ca78388cfd77 525 break;
WiredHome 75:ca78388cfd77 526 }
WiredHome 75:ca78388cfd77 527 if (keyCode3 == 0xFF)
WiredHome 75:ca78388cfd77 528 key = pKeyMap[0]; // Key value 0
WiredHome 75:ca78388cfd77 529 else {
WiredHome 75:ca78388cfd77 530 row = (keyCode3 >> 4) & 0x03;
WiredHome 75:ca78388cfd77 531 col = (keyCode3 & 7);
WiredHome 75:ca78388cfd77 532 key = row * 5 + col + 1; // Keys value 1 - 20
WiredHome 75:ca78388cfd77 533 if (key > 21) {
WiredHome 75:ca78388cfd77 534 key = 21;
WiredHome 75:ca78388cfd77 535 }
WiredHome 75:ca78388cfd77 536 key = pKeyMap[key];
WiredHome 75:ca78388cfd77 537 key |= (keyCode3 & 0x80); // combine the key held flag
WiredHome 75:ca78388cfd77 538 }
WiredHome 77:9206c13aa527 539 #if GETC_DEV // for Development only
WiredHome 75:ca78388cfd77 540 SetTextCursor(0, 20);
WiredHome 75:ca78388cfd77 541 printf(" Reg: %02x\r\n", keyNumReg);
WiredHome 75:ca78388cfd77 542 printf(" key1: %02x\r\n", keyCode1);
WiredHome 75:ca78388cfd77 543 printf(" key2: %02x\r\n", keyCode2);
WiredHome 75:ca78388cfd77 544 printf(" key3: %02x\r\n", keyCode3);
WiredHome 75:ca78388cfd77 545 printf(" count: %02X\r\n", count);
WiredHome 75:ca78388cfd77 546 printf(" key: %02X\r\n", key);
WiredHome 77:9206c13aa527 547 #endif
WiredHome 75:ca78388cfd77 548 WriteCommand(0xF1, 0x10); // Clear KS status
WiredHome 75:ca78388cfd77 549 return key;
WiredHome 71:dcac8efd842d 550 }
WiredHome 71:dcac8efd842d 551
WiredHome 79:544eb4964795 552
WiredHome 19:3f82c1161fd2 553 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 554 void RA8875::ClearPerformance()
WiredHome 19:3f82c1161fd2 555 {
WiredHome 100:0b084475d5a9 556 int i;
WiredHome 100:0b084475d5a9 557
WiredHome 100:0b084475d5a9 558 for (i=0; i<METRICCOUNT; i++)
WiredHome 19:3f82c1161fd2 559 metrics[i] = 0;
WiredHome 75:ca78388cfd77 560 idletime_usec = 0;
WiredHome 100:0b084475d5a9 561 for (i=0; i<256; i++)
WiredHome 100:0b084475d5a9 562 commandsUsed[i] = 0;
WiredHome 19:3f82c1161fd2 563 }
WiredHome 19:3f82c1161fd2 564
WiredHome 79:544eb4964795 565
WiredHome 19:3f82c1161fd2 566 void RA8875::RegisterPerformance(method_e method)
WiredHome 19:3f82c1161fd2 567 {
WiredHome 19:3f82c1161fd2 568 unsigned long elapsed = performance.read_us();
WiredHome 73:f22a18707b5e 569
WiredHome 19:3f82c1161fd2 570 if (method < METRICCOUNT && elapsed > metrics[method])
WiredHome 19:3f82c1161fd2 571 metrics[method] = elapsed;
WiredHome 19:3f82c1161fd2 572 }
WiredHome 19:3f82c1161fd2 573
WiredHome 79:544eb4964795 574
WiredHome 66:468a11f05580 575 void RA8875::CountIdleTime(uint32_t t)
WiredHome 66:468a11f05580 576 {
WiredHome 75:ca78388cfd77 577 idletime_usec += t;
WiredHome 66:468a11f05580 578 }
WiredHome 44:207594dece70 579
WiredHome 79:544eb4964795 580
WiredHome 41:2956a0a221e5 581 void RA8875::ReportPerformance(Serial & pc)
WiredHome 19:3f82c1161fd2 582 {
WiredHome 100:0b084475d5a9 583 int i;
WiredHome 100:0b084475d5a9 584
WiredHome 41:2956a0a221e5 585 pc.printf("\r\nPerformance Metrics\r\n");
WiredHome 100:0b084475d5a9 586 for (i=0; i<METRICCOUNT; i++) {
WiredHome 41:2956a0a221e5 587 pc.printf("%10d uS %s\r\n", metrics[i], metricsName[i]);
WiredHome 66:468a11f05580 588 }
WiredHome 75:ca78388cfd77 589 pc.printf("%10d uS Idle time polling display for ready.\r\n", idletime_usec);
WiredHome 91:ca5f829e6d27 590 for (i=0; i<256; i++) {
WiredHome 91:ca5f829e6d27 591 if (commandsUsed[i])
WiredHome 100:0b084475d5a9 592 pc.printf("Command %02X used %5d times.\r\n", i, commandsUsed[i]);
WiredHome 91:ca5f829e6d27 593 }
WiredHome 19:3f82c1161fd2 594 }
WiredHome 19:3f82c1161fd2 595 #endif
WiredHome 19:3f82c1161fd2 596
WiredHome 44:207594dece70 597
WiredHome 82:f7d300f26540 598 bool RA8875::Intersect(rect_t rect, point_t p)
WiredHome 82:f7d300f26540 599 {
WiredHome 82:f7d300f26540 600 if (p.x >= min(rect.p1.x, rect.p2.x) && p.x <= max(rect.p1.x, rect.p2.x)
WiredHome 82:f7d300f26540 601 && p.y >= min(rect.p1.y, rect.p2.y) && p.y <= max(rect.p1.y, rect.p2.y))
WiredHome 82:f7d300f26540 602 return true;
WiredHome 82:f7d300f26540 603 else
WiredHome 82:f7d300f26540 604 return false;
WiredHome 82:f7d300f26540 605 }
WiredHome 82:f7d300f26540 606
WiredHome 82:f7d300f26540 607
WiredHome 131:5bd6ba2ee4a1 608 bool RA8875::Intersect(rect_t rect1, rect_t rect2)
WiredHome 131:5bd6ba2ee4a1 609 {
WiredHome 147:3494792458d9 610 #if 1
WiredHome 147:3494792458d9 611 // If one rectangle is on left side of other
WiredHome 147:3494792458d9 612 if (max(rect1.p1.x,rect1.p2.x) < min(rect2.p1.x,rect2.p2.x)
WiredHome 147:3494792458d9 613 || min(rect1.p1.x, rect1.p2.x) > max(rect2.p1.x, rect2.p2.x))
WiredHome 147:3494792458d9 614 return false;
WiredHome 147:3494792458d9 615 // If one rectangle is above other
WiredHome 147:3494792458d9 616 if (max(rect1.p1.y, rect1.p2.y) < min(rect2.p1.y, rect2.p2.y)
WiredHome 147:3494792458d9 617 || min(rect1.p1.y, rect1.p2.y) > max(rect2.p1.y, rect2.p2.y))
WiredHome 147:3494792458d9 618 return false;
WiredHome 147:3494792458d9 619 return true; // all that's left is they overlap
WiredHome 147:3494792458d9 620 #else
WiredHome 131:5bd6ba2ee4a1 621 point_t bl, tr;
WiredHome 131:5bd6ba2ee4a1 622 bl.x = rect2.p1.x;
WiredHome 131:5bd6ba2ee4a1 623 bl.y = rect2.p2.y;
WiredHome 131:5bd6ba2ee4a1 624 tr.x = rect2.p2.x;
WiredHome 131:5bd6ba2ee4a1 625 tr.y = rect2.p1.y;
WiredHome 131:5bd6ba2ee4a1 626 if (Intersect(rect1, rect2.p1) || Intersect(rect1, rect2.p2)
WiredHome 147:3494792458d9 627 || Intersect(rect1, bl) || Intersect(rect1, tr))
WiredHome 131:5bd6ba2ee4a1 628 return true;
WiredHome 131:5bd6ba2ee4a1 629 else
WiredHome 131:5bd6ba2ee4a1 630 return false;
WiredHome 147:3494792458d9 631 #endif
WiredHome 131:5bd6ba2ee4a1 632 }
WiredHome 131:5bd6ba2ee4a1 633
WiredHome 131:5bd6ba2ee4a1 634
WiredHome 147:3494792458d9 635 bool RA8875::Intersect(rect_t * pRect1, const rect_t * pRect2)
WiredHome 147:3494792458d9 636 {
WiredHome 147:3494792458d9 637 if (Intersect(*pRect1, *pRect2)) {
WiredHome 147:3494792458d9 638 rect_t iSect;
WiredHome 147:3494792458d9 639
WiredHome 148:33e99de1aca6 640 iSect.p1.x = max(min(pRect1->p1.x,pRect1->p2.x),min(pRect2->p1.x,pRect2->p2.x));
WiredHome 148:33e99de1aca6 641 iSect.p1.y = max(min(pRect1->p1.y,pRect1->p2.y),min(pRect2->p1.y,pRect2->p2.y));
WiredHome 148:33e99de1aca6 642 iSect.p2.x = min(max(pRect1->p1.x,pRect1->p2.x),max(pRect2->p1.x,pRect2->p2.x));
WiredHome 148:33e99de1aca6 643 iSect.p2.y = min(max(pRect1->p1.y,pRect1->p2.y),max(pRect2->p1.y,pRect2->p2.y));
WiredHome 147:3494792458d9 644 *pRect1 = iSect;
WiredHome 147:3494792458d9 645 return true;
WiredHome 147:3494792458d9 646 } else {
WiredHome 147:3494792458d9 647 return false;
WiredHome 147:3494792458d9 648 }
WiredHome 147:3494792458d9 649 }
WiredHome 147:3494792458d9 650
WiredHome 82:f7d300f26540 651
WiredHome 38:38d503b4fad6 652 RetCode_t RA8875::WriteCommandW(uint8_t command, uint16_t data)
WiredHome 38:38d503b4fad6 653 {
WiredHome 38:38d503b4fad6 654 WriteCommand(command, data & 0xFF);
WiredHome 38:38d503b4fad6 655 WriteCommand(command+1, data >> 8);
WiredHome 38:38d503b4fad6 656 return noerror;
WiredHome 38:38d503b4fad6 657 }
WiredHome 38:38d503b4fad6 658
WiredHome 44:207594dece70 659
WiredHome 19:3f82c1161fd2 660 RetCode_t RA8875::WriteCommand(unsigned char command, unsigned int data)
WiredHome 19:3f82c1161fd2 661 {
WiredHome 91:ca5f829e6d27 662 #ifdef PERF_METRICS
WiredHome 92:ce1ab76e8614 663 if (commandsUsed[command] < 65535)
WiredHome 91:ca5f829e6d27 664 commandsUsed[command]++;
WiredHome 91:ca5f829e6d27 665 #endif
WiredHome 79:544eb4964795 666 _select(true);
WiredHome 83:7bad0068cca0 667 _spiwrite(0x80); // RS:1 (Cmd/Status), RW:0 (Write)
WiredHome 79:544eb4964795 668 _spiwrite(command);
WiredHome 19:3f82c1161fd2 669 if (data <= 0xFF) { // only if in the valid range
WiredHome 79:544eb4964795 670 _spiwrite(0x00);
WiredHome 79:544eb4964795 671 _spiwrite(data);
WiredHome 19:3f82c1161fd2 672 }
WiredHome 79:544eb4964795 673 _select(false);
WiredHome 19:3f82c1161fd2 674 return noerror;
WiredHome 19:3f82c1161fd2 675 }
WiredHome 19:3f82c1161fd2 676
WiredHome 44:207594dece70 677
WiredHome 38:38d503b4fad6 678 RetCode_t RA8875::WriteDataW(uint16_t data)
WiredHome 38:38d503b4fad6 679 {
WiredHome 79:544eb4964795 680 _select(true);
WiredHome 83:7bad0068cca0 681 _spiwrite(0x00); // RS:0 (Data), RW:0 (Write)
WiredHome 79:544eb4964795 682 _spiwrite(data & 0xFF);
WiredHome 79:544eb4964795 683 _spiwrite(data >> 8);
WiredHome 79:544eb4964795 684 _select(false);
WiredHome 38:38d503b4fad6 685 return noerror;
WiredHome 38:38d503b4fad6 686 }
WiredHome 38:38d503b4fad6 687
WiredHome 44:207594dece70 688
WiredHome 19:3f82c1161fd2 689 RetCode_t RA8875::WriteData(unsigned char data)
WiredHome 19:3f82c1161fd2 690 {
WiredHome 79:544eb4964795 691 _select(true);
WiredHome 83:7bad0068cca0 692 _spiwrite(0x00); // RS:0 (Data), RW:0 (Write)
WiredHome 79:544eb4964795 693 _spiwrite(data);
WiredHome 79:544eb4964795 694 _select(false);
WiredHome 19:3f82c1161fd2 695 return noerror;
WiredHome 19:3f82c1161fd2 696 }
WiredHome 19:3f82c1161fd2 697
WiredHome 44:207594dece70 698
WiredHome 19:3f82c1161fd2 699 unsigned char RA8875::ReadCommand(unsigned char command)
WiredHome 19:3f82c1161fd2 700 {
WiredHome 19:3f82c1161fd2 701 WriteCommand(command);
WiredHome 19:3f82c1161fd2 702 return ReadData();
WiredHome 19:3f82c1161fd2 703 }
WiredHome 19:3f82c1161fd2 704
WiredHome 136:224e03d5c31f 705 uint16_t RA8875::ReadCommandW(unsigned char command)
WiredHome 136:224e03d5c31f 706 {
WiredHome 136:224e03d5c31f 707 WriteCommand(command);
WiredHome 136:224e03d5c31f 708 return ReadDataW();
WiredHome 136:224e03d5c31f 709 }
WiredHome 44:207594dece70 710
WiredHome 19:3f82c1161fd2 711 unsigned char RA8875::ReadData(void)
WiredHome 19:3f82c1161fd2 712 {
WiredHome 19:3f82c1161fd2 713 unsigned char data;
WiredHome 73:f22a18707b5e 714
WiredHome 79:544eb4964795 715 _select(true);
WiredHome 83:7bad0068cca0 716 _spiwrite(0x40); // RS:0 (Data), RW:1 (Read)
WiredHome 79:544eb4964795 717 data = _spiread();
WiredHome 79:544eb4964795 718 _select(false);
WiredHome 19:3f82c1161fd2 719 return data;
WiredHome 19:3f82c1161fd2 720 }
WiredHome 19:3f82c1161fd2 721
WiredHome 44:207594dece70 722
WiredHome 41:2956a0a221e5 723 uint16_t RA8875::ReadDataW(void)
WiredHome 41:2956a0a221e5 724 {
WiredHome 41:2956a0a221e5 725 uint16_t data;
WiredHome 73:f22a18707b5e 726
WiredHome 79:544eb4964795 727 _select(true);
WiredHome 83:7bad0068cca0 728 _spiwrite(0x40); // RS:0 (Data), RW:1 (Read)
WiredHome 79:544eb4964795 729 data = _spiread();
WiredHome 79:544eb4964795 730 data |= (_spiread() << 8);
WiredHome 79:544eb4964795 731 _select(false);
WiredHome 41:2956a0a221e5 732 return data;
WiredHome 41:2956a0a221e5 733 }
WiredHome 41:2956a0a221e5 734
WiredHome 44:207594dece70 735
WiredHome 19:3f82c1161fd2 736 unsigned char RA8875::ReadStatus(void)
WiredHome 19:3f82c1161fd2 737 {
WiredHome 19:3f82c1161fd2 738 unsigned char data;
WiredHome 73:f22a18707b5e 739
WiredHome 79:544eb4964795 740 _select(true);
WiredHome 83:7bad0068cca0 741 _spiwrite(0xC0); // RS:1 (Cmd/Status), RW:1 (Read) (Read STSR)
WiredHome 79:544eb4964795 742 data = _spiread();
WiredHome 79:544eb4964795 743 _select(false);
WiredHome 19:3f82c1161fd2 744 return data;
WiredHome 19:3f82c1161fd2 745 }
WiredHome 19:3f82c1161fd2 746
WiredHome 79:544eb4964795 747
WiredHome 66:468a11f05580 748 /// @todo add a timeout and return false, but how long
WiredHome 66:468a11f05580 749 /// to wait since some operations can be very long.
WiredHome 66:468a11f05580 750 bool RA8875::_WaitWhileBusy(uint8_t mask)
WiredHome 66:468a11f05580 751 {
WiredHome 66:468a11f05580 752 int i = 20000/POLLWAITuSec; // 20 msec max
WiredHome 66:468a11f05580 753
WiredHome 67:9f834f0ff97d 754 while (i-- && ReadStatus() & mask) {
WiredHome 66:468a11f05580 755 wait_us(POLLWAITuSec);
WiredHome 68:ab08efabfc88 756 COUNTIDLETIME(POLLWAITuSec);
WiredHome 123:2f45e80fec5f 757 if (idle_callback) {
WiredHome 149:c62c4b2d6a15 758 if (external_abort == (*idle_callback)(status_wait, 0)) {
WiredHome 123:2f45e80fec5f 759 return false;
WiredHome 123:2f45e80fec5f 760 }
WiredHome 123:2f45e80fec5f 761 }
WiredHome 67:9f834f0ff97d 762 }
WiredHome 66:468a11f05580 763 if (i)
WiredHome 66:468a11f05580 764 return true;
WiredHome 66:468a11f05580 765 else
WiredHome 66:468a11f05580 766 return false;
WiredHome 66:468a11f05580 767 }
WiredHome 66:468a11f05580 768
WiredHome 79:544eb4964795 769
WiredHome 66:468a11f05580 770 /// @todo add a timeout and return false, but how long
WiredHome 66:468a11f05580 771 /// to wait since some operations can be very long.
WiredHome 66:468a11f05580 772 bool RA8875::_WaitWhileReg(uint8_t reg, uint8_t mask)
WiredHome 66:468a11f05580 773 {
WiredHome 66:468a11f05580 774 int i = 20000/POLLWAITuSec; // 20 msec max
WiredHome 66:468a11f05580 775
WiredHome 67:9f834f0ff97d 776 while (i-- && ReadCommand(reg) & mask) {
WiredHome 66:468a11f05580 777 wait_us(POLLWAITuSec);
WiredHome 68:ab08efabfc88 778 COUNTIDLETIME(POLLWAITuSec);
WiredHome 123:2f45e80fec5f 779 if (idle_callback) {
WiredHome 149:c62c4b2d6a15 780 if (external_abort == (*idle_callback)(command_wait, 0)) {
WiredHome 123:2f45e80fec5f 781 return false;
WiredHome 123:2f45e80fec5f 782 }
WiredHome 123:2f45e80fec5f 783 }
WiredHome 67:9f834f0ff97d 784 }
WiredHome 66:468a11f05580 785 if (i)
WiredHome 66:468a11f05580 786 return true;
WiredHome 66:468a11f05580 787 else
WiredHome 66:468a11f05580 788 return false;
WiredHome 66:468a11f05580 789 }
WiredHome 66:468a11f05580 790
WiredHome 106:c80828f5dea4 791 // RRRR RGGG GGGB BBBB
WiredHome 106:c80828f5dea4 792 // 4321 0543 2104 3210
WiredHome 106:c80828f5dea4 793 // RRRG GGBB
WiredHome 106:c80828f5dea4 794 // 2102 1010
WiredHome 105:4f116006ba1f 795 uint8_t RA8875::_cvt16to8(color_t c16)
WiredHome 105:4f116006ba1f 796 {
WiredHome 105:4f116006ba1f 797 return ((c16 >> 8) & 0xE0)
WiredHome 105:4f116006ba1f 798 | ((c16 >> 6) & 0x1C)
WiredHome 105:4f116006ba1f 799 | ((c16 >> 3) & 0x03);
WiredHome 105:4f116006ba1f 800 }
WiredHome 105:4f116006ba1f 801
WiredHome 106:c80828f5dea4 802 // RRRG GGBB
WiredHome 106:c80828f5dea4 803 // 2102 1010
WiredHome 106:c80828f5dea4 804 // RRRR RGGG GGGB BBBB
WiredHome 106:c80828f5dea4 805 // 2101 0543 2104 3210
WiredHome 105:4f116006ba1f 806 color_t RA8875::_cvt8to16(uint8_t c8)
WiredHome 105:4f116006ba1f 807 {
WiredHome 106:c80828f5dea4 808 color_t c16;
WiredHome 106:c80828f5dea4 809 color_t temp = (color_t)c8;
WiredHome 106:c80828f5dea4 810
WiredHome 106:c80828f5dea4 811 c16 = ((temp & 0xE0) << 8)
WiredHome 106:c80828f5dea4 812 | ((temp & 0xC0) << 5)
WiredHome 106:c80828f5dea4 813 | ((temp & 0x1C) << 6)
WiredHome 106:c80828f5dea4 814 | ((temp & 0x1C) << 3)
WiredHome 106:c80828f5dea4 815 | ((temp & 0x03) << 3)
WiredHome 106:c80828f5dea4 816 | ((temp & 0x03) << 1)
WiredHome 106:c80828f5dea4 817 | ((temp & 0x03) >> 1);
WiredHome 106:c80828f5dea4 818 c16 = (c16 << 8) | (c16 >> 8);
WiredHome 105:4f116006ba1f 819 return c16;
WiredHome 105:4f116006ba1f 820 }
WiredHome 66:468a11f05580 821
WiredHome 133:e36dcfc2d756 822 RetCode_t RA8875::_writeColorTrio(uint8_t regAddr, color_t color)
WiredHome 133:e36dcfc2d756 823 {
WiredHome 133:e36dcfc2d756 824 RetCode_t rt = noerror;
WiredHome 133:e36dcfc2d756 825
WiredHome 133:e36dcfc2d756 826 if (screenbpp == 16) {
WiredHome 133:e36dcfc2d756 827 WriteCommand(regAddr+0, (color>>11)); // BGCR0
WiredHome 133:e36dcfc2d756 828 WriteCommand(regAddr+1, (unsigned char)(color>>5)); // BGCR1
WiredHome 133:e36dcfc2d756 829 rt = WriteCommand(regAddr+2, (unsigned char)(color)); // BGCR2
WiredHome 133:e36dcfc2d756 830 } else {
WiredHome 133:e36dcfc2d756 831 uint8_t r, g, b;
WiredHome 133:e36dcfc2d756 832
WiredHome 133:e36dcfc2d756 833 // RRRR RGGG GGGB BBBB RGB
WiredHome 133:e36dcfc2d756 834 // RRR GGG B B
WiredHome 133:e36dcfc2d756 835 r = (uint8_t)((color) >> 13);
WiredHome 133:e36dcfc2d756 836 g = (uint8_t)((color) >> 8);
WiredHome 133:e36dcfc2d756 837 b = (uint8_t)((color) >> 3);
WiredHome 133:e36dcfc2d756 838 WriteCommand(regAddr+0, r); // BGCR0
WiredHome 133:e36dcfc2d756 839 WriteCommand(regAddr+1, g); // BGCR1
WiredHome 133:e36dcfc2d756 840 rt = WriteCommand(regAddr+2, b); // BGCR2
WiredHome 133:e36dcfc2d756 841 }
WiredHome 133:e36dcfc2d756 842 return rt;
WiredHome 133:e36dcfc2d756 843 }
WiredHome 133:e36dcfc2d756 844
WiredHome 133:e36dcfc2d756 845 color_t RA8875::_readColorTrio(uint8_t regAddr)
WiredHome 133:e36dcfc2d756 846 {
WiredHome 133:e36dcfc2d756 847 color_t color;
WiredHome 133:e36dcfc2d756 848 uint8_t r, g, b;
WiredHome 133:e36dcfc2d756 849
WiredHome 133:e36dcfc2d756 850 r = ReadCommand(regAddr+0);
WiredHome 133:e36dcfc2d756 851 g = ReadCommand(regAddr+1);
WiredHome 133:e36dcfc2d756 852 b = ReadCommand(regAddr+2);
WiredHome 133:e36dcfc2d756 853 if (screenbpp == 16) {
WiredHome 133:e36dcfc2d756 854 // 000R RRRR 00GG GGGG 000B BBBB
WiredHome 133:e36dcfc2d756 855 // RRRR RGGG GGGB BBBB
WiredHome 133:e36dcfc2d756 856 color = (r & 0x1F) << 11;
WiredHome 133:e36dcfc2d756 857 color |= (g & 0x3F) << 5;
WiredHome 133:e36dcfc2d756 858 color |= (b & 0x1F);
WiredHome 133:e36dcfc2d756 859 } else {
WiredHome 133:e36dcfc2d756 860 // RRRG GGBB
WiredHome 133:e36dcfc2d756 861 // RRRR RGGG GGGB BBBB
WiredHome 133:e36dcfc2d756 862 color = (r & 0x07) << 13;
WiredHome 133:e36dcfc2d756 863 color |= (g & 0x07) << 8;
WiredHome 133:e36dcfc2d756 864 color |= (b & 0x03) << 3;
WiredHome 133:e36dcfc2d756 865 }
WiredHome 133:e36dcfc2d756 866 return color;
WiredHome 133:e36dcfc2d756 867 }
WiredHome 133:e36dcfc2d756 868
WiredHome 133:e36dcfc2d756 869
WiredHome 37:f19b7e7449dc 870 dim_t RA8875::fontwidth(void)
WiredHome 19:3f82c1161fd2 871 {
WiredHome 19:3f82c1161fd2 872 if (font == NULL)
WiredHome 55:dfbabef7003e 873 return (((ReadCommand(0x22) >> 2) & 0x3) + 1) * 8;
WiredHome 19:3f82c1161fd2 874 else
WiredHome 98:ecebed9b80b2 875 return extFontWidth;
WiredHome 19:3f82c1161fd2 876 }
WiredHome 19:3f82c1161fd2 877
WiredHome 44:207594dece70 878
WiredHome 37:f19b7e7449dc 879 dim_t RA8875::fontheight(void)
WiredHome 19:3f82c1161fd2 880 {
WiredHome 19:3f82c1161fd2 881 if (font == NULL)
WiredHome 23:a50ded45dbaf 882 return (((ReadCommand(0x22) >> 0) & 0x3) + 1) * 16;
WiredHome 19:3f82c1161fd2 883 else
WiredHome 98:ecebed9b80b2 884 return extFontHeight;
WiredHome 19:3f82c1161fd2 885 }
WiredHome 19:3f82c1161fd2 886
WiredHome 44:207594dece70 887
WiredHome 37:f19b7e7449dc 888 RetCode_t RA8875::locate(textloc_t column, textloc_t row)
WiredHome 19:3f82c1161fd2 889 {
WiredHome 32:0e4f2ae512e2 890 return SetTextCursor(column * fontwidth(), row * fontheight());
WiredHome 19:3f82c1161fd2 891 }
WiredHome 19:3f82c1161fd2 892
WiredHome 44:207594dece70 893
WiredHome 19:3f82c1161fd2 894 int RA8875::columns(void)
WiredHome 19:3f82c1161fd2 895 {
WiredHome 105:4f116006ba1f 896 return screenwidth / fontwidth();
WiredHome 19:3f82c1161fd2 897 }
WiredHome 19:3f82c1161fd2 898
WiredHome 44:207594dece70 899
WiredHome 19:3f82c1161fd2 900 int RA8875::rows(void)
WiredHome 19:3f82c1161fd2 901 {
WiredHome 105:4f116006ba1f 902 return screenheight / fontheight();
WiredHome 19:3f82c1161fd2 903 }
WiredHome 19:3f82c1161fd2 904
WiredHome 44:207594dece70 905
WiredHome 38:38d503b4fad6 906 dim_t RA8875::width(void)
WiredHome 19:3f82c1161fd2 907 {
WiredHome 90:d113d71ae4f0 908 if (portraitmode)
WiredHome 90:d113d71ae4f0 909 return screenheight;
WiredHome 90:d113d71ae4f0 910 else
WiredHome 90:d113d71ae4f0 911 return screenwidth;
WiredHome 19:3f82c1161fd2 912 }
WiredHome 19:3f82c1161fd2 913
WiredHome 44:207594dece70 914
WiredHome 38:38d503b4fad6 915 dim_t RA8875::height(void)
WiredHome 19:3f82c1161fd2 916 {
WiredHome 90:d113d71ae4f0 917 if (portraitmode)
WiredHome 90:d113d71ae4f0 918 return screenwidth;
WiredHome 90:d113d71ae4f0 919 else
WiredHome 90:d113d71ae4f0 920 return screenheight;
WiredHome 19:3f82c1161fd2 921 }
WiredHome 19:3f82c1161fd2 922
WiredHome 44:207594dece70 923
WiredHome 43:3becae133285 924 dim_t RA8875::color_bpp(void)
WiredHome 43:3becae133285 925 {
WiredHome 105:4f116006ba1f 926 return screenbpp;
WiredHome 43:3becae133285 927 }
WiredHome 43:3becae133285 928
WiredHome 103:7e0464ca6c5c 929 RetCode_t RA8875::SetTextCursor(point_t p)
WiredHome 103:7e0464ca6c5c 930 {
WiredHome 103:7e0464ca6c5c 931 return SetTextCursor(p.x, p.y);
WiredHome 103:7e0464ca6c5c 932 }
WiredHome 44:207594dece70 933
WiredHome 37:f19b7e7449dc 934 RetCode_t RA8875::SetTextCursor(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 935 {
WiredHome 98:ecebed9b80b2 936 INFO("SetTextCursor(%d, %d)", x, y);
WiredHome 75:ca78388cfd77 937 cursor_x = x; // set these values for non-internal fonts
WiredHome 75:ca78388cfd77 938 cursor_y = y;
WiredHome 38:38d503b4fad6 939 WriteCommandW(0x2A, x);
WiredHome 38:38d503b4fad6 940 WriteCommandW(0x2C, y);
WiredHome 19:3f82c1161fd2 941 return noerror;
WiredHome 19:3f82c1161fd2 942 }
WiredHome 19:3f82c1161fd2 943
WiredHome 103:7e0464ca6c5c 944 point_t RA8875::GetTextCursor(void)
WiredHome 103:7e0464ca6c5c 945 {
WiredHome 103:7e0464ca6c5c 946 point_t p;
WiredHome 103:7e0464ca6c5c 947
WiredHome 103:7e0464ca6c5c 948 p.x = GetTextCursor_X();
WiredHome 103:7e0464ca6c5c 949 p.y = GetTextCursor_Y();
WiredHome 103:7e0464ca6c5c 950 return p;
WiredHome 103:7e0464ca6c5c 951 }
WiredHome 44:207594dece70 952
WiredHome 37:f19b7e7449dc 953 loc_t RA8875::GetTextCursor_Y(void)
WiredHome 29:422616aa04bd 954 {
WiredHome 98:ecebed9b80b2 955 loc_t y;
WiredHome 98:ecebed9b80b2 956
WiredHome 29:422616aa04bd 957 if (font == NULL)
WiredHome 98:ecebed9b80b2 958 y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8);
WiredHome 29:422616aa04bd 959 else
WiredHome 98:ecebed9b80b2 960 y = cursor_y;
WiredHome 98:ecebed9b80b2 961 INFO("GetTextCursor_Y = %d", y);
WiredHome 98:ecebed9b80b2 962 return y;
WiredHome 29:422616aa04bd 963 }
WiredHome 29:422616aa04bd 964
WiredHome 44:207594dece70 965
WiredHome 37:f19b7e7449dc 966 loc_t RA8875::GetTextCursor_X(void)
WiredHome 29:422616aa04bd 967 {
WiredHome 98:ecebed9b80b2 968 loc_t x;
WiredHome 98:ecebed9b80b2 969
WiredHome 29:422616aa04bd 970 if (font == NULL)
WiredHome 98:ecebed9b80b2 971 x = ReadCommand(0x2A) | (ReadCommand(0x2B) << 8);
WiredHome 29:422616aa04bd 972 else
WiredHome 98:ecebed9b80b2 973 x = cursor_x;
WiredHome 98:ecebed9b80b2 974 INFO("GetTextCursor_X = %d", x);
WiredHome 98:ecebed9b80b2 975 return x;
WiredHome 29:422616aa04bd 976 }
WiredHome 29:422616aa04bd 977
WiredHome 44:207594dece70 978
WiredHome 24:8ca861acf12d 979 RetCode_t RA8875::SetTextCursorControl(cursor_t cursor, bool blink)
WiredHome 23:a50ded45dbaf 980 {
WiredHome 23:a50ded45dbaf 981 unsigned char mwcr0 = ReadCommand(0x40) & 0x0F; // retain direction, auto-increase
WiredHome 43:3becae133285 982 unsigned char mwcr1 = ReadCommand(0x41) & 0x01; // retain currently selected layer
WiredHome 24:8ca861acf12d 983 unsigned char horz = 0;
WiredHome 24:8ca861acf12d 984 unsigned char vert = 0;
WiredHome 73:f22a18707b5e 985
WiredHome 24:8ca861acf12d 986 mwcr0 |= 0x80; // text mode
WiredHome 24:8ca861acf12d 987 if (cursor != NOCURSOR)
WiredHome 24:8ca861acf12d 988 mwcr0 |= 0x40; // visible
WiredHome 23:a50ded45dbaf 989 if (blink)
WiredHome 24:8ca861acf12d 990 mwcr0 |= 0x20; // blink
WiredHome 23:a50ded45dbaf 991 WriteCommand(0x40, mwcr0); // configure the cursor
WiredHome 43:3becae133285 992 WriteCommand(0x41, mwcr1); // close the graphics cursor
WiredHome 24:8ca861acf12d 993 WriteCommand(0x44, 0x1f); // The cursor flashing cycle
WiredHome 24:8ca861acf12d 994 switch (cursor) {
WiredHome 24:8ca861acf12d 995 case IBEAM:
WiredHome 24:8ca861acf12d 996 horz = 0x01;
WiredHome 24:8ca861acf12d 997 vert = 0x1F;
WiredHome 24:8ca861acf12d 998 break;
WiredHome 24:8ca861acf12d 999 case UNDER:
WiredHome 24:8ca861acf12d 1000 horz = 0x07;
WiredHome 24:8ca861acf12d 1001 vert = 0x01;
WiredHome 24:8ca861acf12d 1002 break;
WiredHome 24:8ca861acf12d 1003 case BLOCK:
WiredHome 24:8ca861acf12d 1004 horz = 0x07;
WiredHome 24:8ca861acf12d 1005 vert = 0x1F;
WiredHome 24:8ca861acf12d 1006 break;
WiredHome 24:8ca861acf12d 1007 case NOCURSOR:
WiredHome 24:8ca861acf12d 1008 default:
WiredHome 24:8ca861acf12d 1009 break;
WiredHome 24:8ca861acf12d 1010 }
WiredHome 24:8ca861acf12d 1011 WriteCommand(0x4e, horz); // The cursor size horz
WiredHome 24:8ca861acf12d 1012 WriteCommand(0x4f, vert); // The cursor size vert
WiredHome 23:a50ded45dbaf 1013 return noerror;
WiredHome 23:a50ded45dbaf 1014 }
WiredHome 23:a50ded45dbaf 1015
WiredHome 44:207594dece70 1016
WiredHome 19:3f82c1161fd2 1017 RetCode_t RA8875::SetTextFont(RA8875::font_t font)
WiredHome 19:3f82c1161fd2 1018 {
WiredHome 19:3f82c1161fd2 1019 if (/*font >= RA8875::ISO8859_1 && */ font <= RA8875::ISO8859_4) {
WiredHome 19:3f82c1161fd2 1020 WriteCommand(0x21, (unsigned int)(font));
WiredHome 19:3f82c1161fd2 1021 return noerror;
WiredHome 19:3f82c1161fd2 1022 } else {
WiredHome 19:3f82c1161fd2 1023 return bad_parameter;
WiredHome 19:3f82c1161fd2 1024 }
WiredHome 19:3f82c1161fd2 1025 }
WiredHome 19:3f82c1161fd2 1026
WiredHome 44:207594dece70 1027
WiredHome 84:e102021864b5 1028 RetCode_t RA8875::SetOrientation(RA8875::orientation_t angle)
WiredHome 84:e102021864b5 1029 {
WiredHome 84:e102021864b5 1030 uint8_t fncr1Val = ReadCommand(0x22);
WiredHome 84:e102021864b5 1031 uint8_t dpcrVal = ReadCommand(0x20);
WiredHome 84:e102021864b5 1032
WiredHome 84:e102021864b5 1033 fncr1Val &= ~0x10; // remove the old direction bit
WiredHome 84:e102021864b5 1034 dpcrVal &= ~0x0C; // remove the old scan direction bits
WiredHome 84:e102021864b5 1035 switch (angle) {
WiredHome 84:e102021864b5 1036 case RA8875::normal:
WiredHome 84:e102021864b5 1037 //fncr1Val |= 0x10;
WiredHome 84:e102021864b5 1038 //dpcrVal |= 0x00;
WiredHome 90:d113d71ae4f0 1039 portraitmode = false;
WiredHome 84:e102021864b5 1040 break;
WiredHome 84:e102021864b5 1041 case RA8875::rotate_90:
WiredHome 84:e102021864b5 1042 fncr1Val |= 0x10;
WiredHome 84:e102021864b5 1043 dpcrVal |= 0x08;
WiredHome 90:d113d71ae4f0 1044 portraitmode = true;
WiredHome 84:e102021864b5 1045 break;
WiredHome 84:e102021864b5 1046 case RA8875::rotate_180:
WiredHome 84:e102021864b5 1047 //fncr1Val |= 0x00;
WiredHome 84:e102021864b5 1048 dpcrVal |= 0x0C;
WiredHome 90:d113d71ae4f0 1049 portraitmode = false;
WiredHome 84:e102021864b5 1050 break;
WiredHome 84:e102021864b5 1051 case RA8875::rotate_270:
WiredHome 84:e102021864b5 1052 fncr1Val |= 0x10;
WiredHome 84:e102021864b5 1053 dpcrVal |= 0x04;
WiredHome 90:d113d71ae4f0 1054 portraitmode = true;
WiredHome 84:e102021864b5 1055 break;
WiredHome 84:e102021864b5 1056 default:
WiredHome 84:e102021864b5 1057 return bad_parameter;
WiredHome 84:e102021864b5 1058 }
WiredHome 100:0b084475d5a9 1059 INFO("Orientation: %d, %d", angle, portraitmode);
WiredHome 84:e102021864b5 1060 WriteCommand(0x22, fncr1Val);
WiredHome 84:e102021864b5 1061 return WriteCommand(0x20, dpcrVal);
WiredHome 84:e102021864b5 1062 }
WiredHome 84:e102021864b5 1063
WiredHome 84:e102021864b5 1064
WiredHome 19:3f82c1161fd2 1065 RetCode_t RA8875::SetTextFontControl(fill_t fillit,
WiredHome 73:f22a18707b5e 1066 RA8875::HorizontalScale hScale,
WiredHome 73:f22a18707b5e 1067 RA8875::VerticalScale vScale,
WiredHome 73:f22a18707b5e 1068 RA8875::alignment_t alignment)
WiredHome 19:3f82c1161fd2 1069 {
WiredHome 73:f22a18707b5e 1070 if (hScale >= 1 && hScale <= 4 &&
WiredHome 73:f22a18707b5e 1071 vScale >= 1 && vScale <= 4) {
WiredHome 84:e102021864b5 1072 uint8_t fncr1Val = ReadCommand(0x22);
WiredHome 84:e102021864b5 1073
WiredHome 98:ecebed9b80b2 1074 fncr1Val &= ~0x10; // do not disturb the rotate flag
WiredHome 19:3f82c1161fd2 1075 if (alignment == align_full)
WiredHome 84:e102021864b5 1076 fncr1Val |= 0x80;
WiredHome 19:3f82c1161fd2 1077 if (fillit == NOFILL)
WiredHome 84:e102021864b5 1078 fncr1Val |= 0x40;
WiredHome 84:e102021864b5 1079 fncr1Val |= ((hScale - 1) << 2);
WiredHome 84:e102021864b5 1080 fncr1Val |= ((vScale - 1) << 0);
WiredHome 84:e102021864b5 1081 return WriteCommand(0x22, fncr1Val);
WiredHome 19:3f82c1161fd2 1082 } else {
WiredHome 19:3f82c1161fd2 1083 return bad_parameter;
WiredHome 19:3f82c1161fd2 1084 }
WiredHome 19:3f82c1161fd2 1085 }
WiredHome 19:3f82c1161fd2 1086
WiredHome 44:207594dece70 1087
WiredHome 19:3f82c1161fd2 1088 RetCode_t RA8875::SetTextFontSize(RA8875::HorizontalScale hScale, RA8875::VerticalScale vScale)
WiredHome 19:3f82c1161fd2 1089 {
WiredHome 19:3f82c1161fd2 1090 unsigned char reg = ReadCommand(0x22);
WiredHome 73:f22a18707b5e 1091
WiredHome 40:04aa280dfa39 1092 if (vScale == -1)
WiredHome 40:04aa280dfa39 1093 vScale = hScale;
WiredHome 19:3f82c1161fd2 1094 if (hScale >= 1 && hScale <= 4 && vScale >= 1 && vScale <= 4) {
WiredHome 153:8a85efb3eb71 1095 fontScaleX = hScale; // save for use with a Soft Font
WiredHome 153:8a85efb3eb71 1096 fontScaleY = vScale;
WiredHome 19:3f82c1161fd2 1097 reg &= 0xF0; // keep the high nibble as is.
WiredHome 19:3f82c1161fd2 1098 reg |= ((hScale - 1) << 2);
WiredHome 19:3f82c1161fd2 1099 reg |= ((vScale - 1) << 0);
WiredHome 19:3f82c1161fd2 1100 WriteCommand(0x22, reg);
WiredHome 19:3f82c1161fd2 1101 return noerror;
WiredHome 19:3f82c1161fd2 1102 } else {
WiredHome 19:3f82c1161fd2 1103 return bad_parameter;
WiredHome 19:3f82c1161fd2 1104 }
WiredHome 19:3f82c1161fd2 1105 }
WiredHome 19:3f82c1161fd2 1106
WiredHome 127:db7f2c704693 1107 RetCode_t RA8875::GetTextFontSize(RA8875::HorizontalScale * hScale, RA8875::VerticalScale * vScale)
WiredHome 127:db7f2c704693 1108 {
WiredHome 127:db7f2c704693 1109 unsigned char reg = ReadCommand(0x22);
WiredHome 127:db7f2c704693 1110
WiredHome 127:db7f2c704693 1111 if (hScale)
WiredHome 127:db7f2c704693 1112 *hScale = 1 + (reg >> 2) & 0x03;
WiredHome 127:db7f2c704693 1113 if (vScale)
WiredHome 127:db7f2c704693 1114 *vScale = 1 + reg & 0x03;
WiredHome 127:db7f2c704693 1115 return noerror;
WiredHome 127:db7f2c704693 1116 }
WiredHome 44:207594dece70 1117
WiredHome 19:3f82c1161fd2 1118 int RA8875::_putc(int c)
WiredHome 19:3f82c1161fd2 1119 {
WiredHome 29:422616aa04bd 1120 if (font == NULL) {
WiredHome 29:422616aa04bd 1121 return _internal_putc(c);
WiredHome 29:422616aa04bd 1122 } else {
WiredHome 29:422616aa04bd 1123 return _external_putc(c);
WiredHome 29:422616aa04bd 1124 }
WiredHome 29:422616aa04bd 1125 }
WiredHome 29:422616aa04bd 1126
WiredHome 44:207594dece70 1127
WiredHome 101:e0aad446094a 1128
WiredHome 101:e0aad446094a 1129 // Questions to ponder -
WiredHome 101:e0aad446094a 1130 // - if we choose to wrap to the next line, because the character won't fit on the current line,
WiredHome 101:e0aad446094a 1131 // should it erase the space to the width of the screen (in case there is leftover junk there)?
WiredHome 101:e0aad446094a 1132 // - it currently wraps from the bottom of the screen back to the top. I have pondered what
WiredHome 101:e0aad446094a 1133 // it might take to scroll the screen - but haven't thought hard enough about it.
WiredHome 101:e0aad446094a 1134 //
WiredHome 29:422616aa04bd 1135 int RA8875::_external_putc(int c)
WiredHome 29:422616aa04bd 1136 {
WiredHome 19:3f82c1161fd2 1137 if (c) {
WiredHome 19:3f82c1161fd2 1138 if (c == '\r') {
WiredHome 111:efe436c43aba 1139 cursor_x = windowrect.p1.x;
WiredHome 29:422616aa04bd 1140 } else if (c == '\n') {
WiredHome 98:ecebed9b80b2 1141 cursor_y += extFontHeight;
WiredHome 29:422616aa04bd 1142 } else {
WiredHome 109:7b94f06f085b 1143 dim_t charWidth, charHeight;
WiredHome 101:e0aad446094a 1144 const uint8_t * charRecord;
WiredHome 101:e0aad446094a 1145
WiredHome 101:e0aad446094a 1146 charRecord = getCharMetrics(c, &charWidth, &charHeight);
WiredHome 101:e0aad446094a 1147 //int advance = charwidth(c);
WiredHome 111:efe436c43aba 1148 INFO("(%d,%d) - (%d,%d):(%d,%d), charWidth: %d '%c", cursor_x, cursor_y,
WiredHome 111:efe436c43aba 1149 windowrect.p1.x, windowrect.p1.y, windowrect.p2.x, windowrect.p2.y,
WiredHome 111:efe436c43aba 1150 charWidth, c);
WiredHome 101:e0aad446094a 1151 if (charRecord) {
WiredHome 101:e0aad446094a 1152 //cursor_x += advance;
WiredHome 111:efe436c43aba 1153 if (cursor_x + charWidth >= windowrect.p2.x) {
WiredHome 111:efe436c43aba 1154 cursor_x = windowrect.p1.x;
WiredHome 101:e0aad446094a 1155 cursor_y += charHeight;
WiredHome 29:422616aa04bd 1156 }
WiredHome 111:efe436c43aba 1157 if (cursor_y + charHeight >= windowrect.p2.y) {
WiredHome 111:efe436c43aba 1158 cursor_y = windowrect.p1.y; // @todo Should it scroll?
WiredHome 101:e0aad446094a 1159 }
WiredHome 101:e0aad446094a 1160 (void)character(cursor_x, cursor_y, c);
WiredHome 153:8a85efb3eb71 1161 cursor_x += charWidth * fontScaleX;
WiredHome 29:422616aa04bd 1162 }
WiredHome 29:422616aa04bd 1163 }
WiredHome 29:422616aa04bd 1164 }
WiredHome 29:422616aa04bd 1165 return c;
WiredHome 29:422616aa04bd 1166 }
WiredHome 29:422616aa04bd 1167
WiredHome 44:207594dece70 1168
WiredHome 29:422616aa04bd 1169 int RA8875::_internal_putc(int c)
WiredHome 29:422616aa04bd 1170 {
WiredHome 29:422616aa04bd 1171 if (c) {
WiredHome 29:422616aa04bd 1172 unsigned char mwcr0;
WiredHome 73:f22a18707b5e 1173
WiredHome 29:422616aa04bd 1174 mwcr0 = ReadCommand(0x40);
WiredHome 29:422616aa04bd 1175 if ((mwcr0 & 0x80) == 0x00) {
WiredHome 29:422616aa04bd 1176 WriteCommand(0x40, 0x80 | mwcr0); // Put in Text mode if not already
WiredHome 29:422616aa04bd 1177 }
WiredHome 29:422616aa04bd 1178 if (c == '\r') {
WiredHome 37:f19b7e7449dc 1179 loc_t x;
WiredHome 19:3f82c1161fd2 1180 x = ReadCommand(0x30) | (ReadCommand(0x31) << 8); // Left edge of active window
WiredHome 38:38d503b4fad6 1181 WriteCommandW(0x2A, x);
WiredHome 19:3f82c1161fd2 1182 } else if (c == '\n') {
WiredHome 37:f19b7e7449dc 1183 loc_t y;
WiredHome 19:3f82c1161fd2 1184 y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); // current y location
WiredHome 19:3f82c1161fd2 1185 y += fontheight();
WiredHome 47:d96a09269f91 1186 if (y >= height()) // @TODO after bottom of active window, then scroll window?
WiredHome 19:3f82c1161fd2 1187 y = 0;
WiredHome 38:38d503b4fad6 1188 WriteCommandW(0x2C, y);
WiredHome 19:3f82c1161fd2 1189 } else {
WiredHome 29:422616aa04bd 1190 WriteCommand(0x02); // RA8875 Internal Fonts
WiredHome 79:544eb4964795 1191 _select(true);
WiredHome 29:422616aa04bd 1192 WriteData(c);
WiredHome 66:468a11f05580 1193 _WaitWhileBusy(0x80);
WiredHome 79:544eb4964795 1194 _select(false);
WiredHome 19:3f82c1161fd2 1195 }
WiredHome 19:3f82c1161fd2 1196 }
WiredHome 19:3f82c1161fd2 1197 return c;
WiredHome 19:3f82c1161fd2 1198 }
WiredHome 19:3f82c1161fd2 1199
WiredHome 44:207594dece70 1200
WiredHome 32:0e4f2ae512e2 1201 RetCode_t RA8875::_StartGraphicsStream(void)
WiredHome 32:0e4f2ae512e2 1202 {
WiredHome 32:0e4f2ae512e2 1203 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 32:0e4f2ae512e2 1204 WriteCommand(0x02); // Prepare for streaming data
WiredHome 32:0e4f2ae512e2 1205 return noerror;
WiredHome 32:0e4f2ae512e2 1206 }
WiredHome 32:0e4f2ae512e2 1207
WiredHome 44:207594dece70 1208
WiredHome 32:0e4f2ae512e2 1209 RetCode_t RA8875::_EndGraphicsStream(void)
WiredHome 32:0e4f2ae512e2 1210 {
WiredHome 32:0e4f2ae512e2 1211 return noerror;
WiredHome 32:0e4f2ae512e2 1212 }
WiredHome 32:0e4f2ae512e2 1213
WiredHome 44:207594dece70 1214
WiredHome 55:dfbabef7003e 1215 RetCode_t RA8875::_putp(color_t pixel)
WiredHome 32:0e4f2ae512e2 1216 {
WiredHome 38:38d503b4fad6 1217 WriteDataW((pixel>>8) | (pixel<<8));
WiredHome 73:f22a18707b5e 1218 return noerror;
WiredHome 32:0e4f2ae512e2 1219 }
WiredHome 29:422616aa04bd 1220
WiredHome 44:207594dece70 1221
WiredHome 37:f19b7e7449dc 1222 void RA8875::puts(loc_t x, loc_t y, const char * string)
WiredHome 19:3f82c1161fd2 1223 {
WiredHome 19:3f82c1161fd2 1224 SetTextCursor(x,y);
WiredHome 19:3f82c1161fd2 1225 puts(string);
WiredHome 19:3f82c1161fd2 1226 }
WiredHome 19:3f82c1161fd2 1227
WiredHome 44:207594dece70 1228
WiredHome 19:3f82c1161fd2 1229 void RA8875::puts(const char * string)
WiredHome 19:3f82c1161fd2 1230 {
WiredHome 37:f19b7e7449dc 1231 if (font == NULL) {
WiredHome 100:0b084475d5a9 1232 WriteCommand(0x40,0x80); // Put in Text mode if internal font
WiredHome 37:f19b7e7449dc 1233 }
WiredHome 19:3f82c1161fd2 1234 if (*string != '\0') {
WiredHome 29:422616aa04bd 1235 while (*string) { // @TODO calling individual _putc is slower... optimizations?
WiredHome 19:3f82c1161fd2 1236 _putc(*string++);
WiredHome 19:3f82c1161fd2 1237 }
WiredHome 19:3f82c1161fd2 1238 }
WiredHome 19:3f82c1161fd2 1239 }
WiredHome 19:3f82c1161fd2 1240
WiredHome 44:207594dece70 1241
WiredHome 37:f19b7e7449dc 1242 RetCode_t RA8875::SetGraphicsCursor(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 1243 {
WiredHome 38:38d503b4fad6 1244 WriteCommandW(0x46, x);
WiredHome 38:38d503b4fad6 1245 WriteCommandW(0x48, y);
WiredHome 19:3f82c1161fd2 1246 return noerror;
WiredHome 19:3f82c1161fd2 1247 }
WiredHome 19:3f82c1161fd2 1248
WiredHome 136:224e03d5c31f 1249 RetCode_t RA8875::SetGraphicsCursor(point_t p)
WiredHome 136:224e03d5c31f 1250 {
WiredHome 136:224e03d5c31f 1251 return SetGraphicsCursor(p.x, p.y);
WiredHome 136:224e03d5c31f 1252 }
WiredHome 136:224e03d5c31f 1253
WiredHome 136:224e03d5c31f 1254 point_t RA8875::GetGraphicsCursor(void)
WiredHome 136:224e03d5c31f 1255 {
WiredHome 136:224e03d5c31f 1256 point_t p;
WiredHome 136:224e03d5c31f 1257
WiredHome 136:224e03d5c31f 1258 p.x = ReadCommandW(0x46);
WiredHome 136:224e03d5c31f 1259 p.y = ReadCommandW(0x48);
WiredHome 136:224e03d5c31f 1260 return p;
WiredHome 136:224e03d5c31f 1261 }
WiredHome 44:207594dece70 1262
WiredHome 41:2956a0a221e5 1263 RetCode_t RA8875::SetGraphicsCursorRead(loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1264 {
WiredHome 41:2956a0a221e5 1265 WriteCommandW(0x4A, x);
WiredHome 41:2956a0a221e5 1266 WriteCommandW(0x4C, y);
WiredHome 41:2956a0a221e5 1267 return noerror;
WiredHome 41:2956a0a221e5 1268 }
WiredHome 41:2956a0a221e5 1269
WiredHome 111:efe436c43aba 1270 RetCode_t RA8875::window(rect_t r)
WiredHome 111:efe436c43aba 1271 {
WiredHome 111:efe436c43aba 1272 return window(r.p1.x, r.p1.y, r.p2.x + 1 - r.p1.x, r.p2.y + 1 - r.p1.y);
WiredHome 111:efe436c43aba 1273 }
WiredHome 44:207594dece70 1274
WiredHome 37:f19b7e7449dc 1275 RetCode_t RA8875::window(loc_t x, loc_t y, dim_t width, dim_t height)
WiredHome 19:3f82c1161fd2 1276 {
WiredHome 111:efe436c43aba 1277 INFO("window(%d,%d,%d,%d)", x, y, width, height);
WiredHome 111:efe436c43aba 1278 if (width == (dim_t)-1)
WiredHome 111:efe436c43aba 1279 width = screenwidth - x;
WiredHome 111:efe436c43aba 1280 if (height == (dim_t)-1)
WiredHome 111:efe436c43aba 1281 height = screenheight - y;
WiredHome 111:efe436c43aba 1282 windowrect.p1.x = x;
WiredHome 111:efe436c43aba 1283 windowrect.p1.y = y;
WiredHome 111:efe436c43aba 1284 windowrect.p2.x = x + width - 1;
WiredHome 111:efe436c43aba 1285 windowrect.p2.y = y + height - 1;
WiredHome 37:f19b7e7449dc 1286 GraphicsDisplay::window(x,y, width,height);
WiredHome 38:38d503b4fad6 1287 WriteCommandW(0x30, x);
WiredHome 38:38d503b4fad6 1288 WriteCommandW(0x32, y);
WiredHome 38:38d503b4fad6 1289 WriteCommandW(0x34, (x+width-1));
WiredHome 38:38d503b4fad6 1290 WriteCommandW(0x36, (y+height-1));
WiredHome 111:efe436c43aba 1291 //SetTextCursor(x,y);
WiredHome 111:efe436c43aba 1292 //SetGraphicsCursor(x,y);
WiredHome 19:3f82c1161fd2 1293 return noerror;
WiredHome 19:3f82c1161fd2 1294 }
WiredHome 19:3f82c1161fd2 1295
WiredHome 44:207594dece70 1296
WiredHome 61:8f3153bf0baa 1297 RetCode_t RA8875::cls(uint16_t layers)
WiredHome 19:3f82c1161fd2 1298 {
WiredHome 61:8f3153bf0baa 1299 RetCode_t ret;
WiredHome 73:f22a18707b5e 1300
WiredHome 19:3f82c1161fd2 1301 PERFORMANCE_RESET;
WiredHome 61:8f3153bf0baa 1302 if (layers == 0) {
WiredHome 61:8f3153bf0baa 1303 ret = clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1304 } else if (layers > 3) {
WiredHome 61:8f3153bf0baa 1305 ret = bad_parameter;
WiredHome 61:8f3153bf0baa 1306 } else {
WiredHome 61:8f3153bf0baa 1307 uint16_t prevLayer = GetDrawingLayer();
WiredHome 61:8f3153bf0baa 1308 if (layers & 1) {
WiredHome 61:8f3153bf0baa 1309 SelectDrawingLayer(0);
WiredHome 61:8f3153bf0baa 1310 clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1311 }
WiredHome 61:8f3153bf0baa 1312 if (layers & 2) {
WiredHome 61:8f3153bf0baa 1313 SelectDrawingLayer(1);
WiredHome 61:8f3153bf0baa 1314 clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1315 }
WiredHome 142:6e9bff59878a 1316 SelectDrawingLayer(prevLayer);
WiredHome 61:8f3153bf0baa 1317 }
WiredHome 135:af519fe4ba91 1318 ret = SetTextCursor(0,0);
WiredHome 135:af519fe4ba91 1319 ret = locate(0,0);
WiredHome 19:3f82c1161fd2 1320 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 61:8f3153bf0baa 1321 return ret;
WiredHome 19:3f82c1161fd2 1322 }
WiredHome 19:3f82c1161fd2 1323
WiredHome 44:207594dece70 1324
WiredHome 19:3f82c1161fd2 1325 RetCode_t RA8875::clsw(RA8875::Region_t region)
WiredHome 19:3f82c1161fd2 1326 {
WiredHome 19:3f82c1161fd2 1327 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1328 WriteCommand(0x8E, (region == ACTIVEWINDOW) ? 0xC0 : 0x80);
WiredHome 131:5bd6ba2ee4a1 1329 if (!_WaitWhileReg(0x8E, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1330 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 131:5bd6ba2ee4a1 1331 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1332 }
WiredHome 19:3f82c1161fd2 1333 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 19:3f82c1161fd2 1334 return noerror;
WiredHome 19:3f82c1161fd2 1335 }
WiredHome 19:3f82c1161fd2 1336
WiredHome 44:207594dece70 1337
WiredHome 87:ee2240581aa7 1338 RetCode_t RA8875::pixel(point_t p, color_t color)
WiredHome 87:ee2240581aa7 1339 {
WiredHome 87:ee2240581aa7 1340 return pixel(p.x, p.y, color);
WiredHome 87:ee2240581aa7 1341 }
WiredHome 87:ee2240581aa7 1342
WiredHome 87:ee2240581aa7 1343 RetCode_t RA8875::pixel(point_t p)
WiredHome 87:ee2240581aa7 1344 {
WiredHome 87:ee2240581aa7 1345 return pixel(p.x, p.y);
WiredHome 87:ee2240581aa7 1346 }
WiredHome 87:ee2240581aa7 1347
WiredHome 37:f19b7e7449dc 1348 RetCode_t RA8875::pixel(loc_t x, loc_t y, color_t color)
WiredHome 19:3f82c1161fd2 1349 {
WiredHome 62:ba5d33438fda 1350 RetCode_t ret;
WiredHome 73:f22a18707b5e 1351
WiredHome 62:ba5d33438fda 1352 PERFORMANCE_RESET;
WiredHome 62:ba5d33438fda 1353 ret = pixelStream(&color, 1, x,y);
WiredHome 62:ba5d33438fda 1354 REGISTERPERFORMANCE(PRF_DRAWPIXEL);
WiredHome 62:ba5d33438fda 1355 return ret;
WiredHome 19:3f82c1161fd2 1356 }
WiredHome 19:3f82c1161fd2 1357
WiredHome 44:207594dece70 1358
WiredHome 37:f19b7e7449dc 1359 RetCode_t RA8875::pixel(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 1360 {
WiredHome 19:3f82c1161fd2 1361 RetCode_t ret;
WiredHome 73:f22a18707b5e 1362
WiredHome 19:3f82c1161fd2 1363 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1364 color_t color = GetForeColor();
WiredHome 62:ba5d33438fda 1365 ret = pixelStream(&color, 1, x, y);
WiredHome 41:2956a0a221e5 1366 REGISTERPERFORMANCE(PRF_DRAWPIXEL);
WiredHome 19:3f82c1161fd2 1367 return ret;
WiredHome 19:3f82c1161fd2 1368 }
WiredHome 19:3f82c1161fd2 1369
WiredHome 44:207594dece70 1370
WiredHome 41:2956a0a221e5 1371 RetCode_t RA8875::pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1372 {
WiredHome 41:2956a0a221e5 1373 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 1374 SetGraphicsCursor(x, y);
WiredHome 109:7b94f06f085b 1375 _StartGraphicsStream();
WiredHome 79:544eb4964795 1376 _select(true);
WiredHome 79:544eb4964795 1377 _spiwrite(0x00); // Cmd: write data
WiredHome 41:2956a0a221e5 1378 while (count--) {
WiredHome 105:4f116006ba1f 1379 if (screenbpp == 16) {
WiredHome 105:4f116006ba1f 1380 _spiwrite(*p >> 8);
WiredHome 105:4f116006ba1f 1381 _spiwrite(*p & 0xFF);
WiredHome 105:4f116006ba1f 1382 } else {
WiredHome 105:4f116006ba1f 1383 _spiwrite(_cvt16to8(*p));
WiredHome 105:4f116006ba1f 1384 }
WiredHome 41:2956a0a221e5 1385 p++;
WiredHome 41:2956a0a221e5 1386 }
WiredHome 79:544eb4964795 1387 _select(false);
WiredHome 109:7b94f06f085b 1388 _EndGraphicsStream();
WiredHome 41:2956a0a221e5 1389 REGISTERPERFORMANCE(PRF_PIXELSTREAM);
WiredHome 41:2956a0a221e5 1390 return(noerror);
WiredHome 41:2956a0a221e5 1391 }
WiredHome 41:2956a0a221e5 1392
WiredHome 153:8a85efb3eb71 1393 // With a font scale X = 1, a pixel stream is "abcdefg..."
WiredHome 153:8a85efb3eb71 1394 // With a font scale X = 2, a pixel stream is "aabbccddeeffgg..."
WiredHome 153:8a85efb3eb71 1395 // With a font scale Y = 2, a pixel stream is "abcdefg..."
WiredHome 153:8a85efb3eb71 1396 // "abcdefg..."
WiredHome 153:8a85efb3eb71 1397 //
WiredHome 109:7b94f06f085b 1398 RetCode_t RA8875::booleanStream(loc_t x, loc_t y, dim_t w, dim_t h, const uint8_t * boolStream)
WiredHome 109:7b94f06f085b 1399 {
WiredHome 109:7b94f06f085b 1400 PERFORMANCE_RESET;
WiredHome 153:8a85efb3eb71 1401 const uint8_t * rowStream;
WiredHome 111:efe436c43aba 1402 rect_t restore = windowrect;
WiredHome 153:8a85efb3eb71 1403 window(x, y, w * fontScaleX, h * fontScaleY); // Scale from font scale factors
WiredHome 109:7b94f06f085b 1404 SetGraphicsCursor(x, y);
WiredHome 109:7b94f06f085b 1405 _StartGraphicsStream();
WiredHome 109:7b94f06f085b 1406 _select(true);
WiredHome 109:7b94f06f085b 1407 _spiwrite(0x00); // Cmd: write data
WiredHome 109:7b94f06f085b 1408 while (h--) {
WiredHome 153:8a85efb3eb71 1409 for (int dy=0; dy<fontScaleY; dy++) { // Vertical Font Scale Factor
WiredHome 153:8a85efb3eb71 1410 uint8_t pixels = w;
WiredHome 153:8a85efb3eb71 1411 uint8_t bitmask = 0x01;
WiredHome 153:8a85efb3eb71 1412 rowStream = boolStream;
WiredHome 153:8a85efb3eb71 1413 while (pixels) {
WiredHome 153:8a85efb3eb71 1414 uint8_t byte = *rowStream;
WiredHome 153:8a85efb3eb71 1415 //INFO("byte, mask: %02X, %02X", byte, bitmask);
WiredHome 153:8a85efb3eb71 1416 color_t c = (byte & bitmask) ? _foreground : _background;
WiredHome 153:8a85efb3eb71 1417
WiredHome 153:8a85efb3eb71 1418 for (int dx=0; dx<fontScaleX; dx++) { // Horizontal Font Scale Factor
WiredHome 153:8a85efb3eb71 1419 if (screenbpp == 16) {
WiredHome 153:8a85efb3eb71 1420 _spiwrite(c >> 8);
WiredHome 153:8a85efb3eb71 1421 _spiwrite(c & 0xFF);
WiredHome 153:8a85efb3eb71 1422 } else {
WiredHome 153:8a85efb3eb71 1423 _spiwrite(_cvt16to8(c));
WiredHome 153:8a85efb3eb71 1424 }
WiredHome 109:7b94f06f085b 1425 }
WiredHome 153:8a85efb3eb71 1426 bitmask <<= 1;
WiredHome 153:8a85efb3eb71 1427 if (pixels > 1 && bitmask == 0) {
WiredHome 153:8a85efb3eb71 1428 bitmask = 0x01;
WiredHome 153:8a85efb3eb71 1429 rowStream++;
WiredHome 153:8a85efb3eb71 1430 }
WiredHome 153:8a85efb3eb71 1431 pixels--;
WiredHome 109:7b94f06f085b 1432 }
WiredHome 109:7b94f06f085b 1433 }
WiredHome 153:8a85efb3eb71 1434 boolStream += (rowStream - boolStream + 1);
WiredHome 109:7b94f06f085b 1435 }
WiredHome 109:7b94f06f085b 1436 _select(false);
WiredHome 109:7b94f06f085b 1437 _EndGraphicsStream();
WiredHome 111:efe436c43aba 1438 window(restore);
WiredHome 109:7b94f06f085b 1439 REGISTERPERFORMANCE(PRF_BOOLSTREAM);
WiredHome 109:7b94f06f085b 1440 return(noerror);
WiredHome 109:7b94f06f085b 1441 }
WiredHome 44:207594dece70 1442
WiredHome 41:2956a0a221e5 1443 color_t RA8875::getPixel(loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1444 {
WiredHome 41:2956a0a221e5 1445 color_t pixel;
WiredHome 73:f22a18707b5e 1446
WiredHome 41:2956a0a221e5 1447 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 1448 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 41:2956a0a221e5 1449 SetGraphicsCursorRead(x, y);
WiredHome 41:2956a0a221e5 1450 WriteCommand(0x02);
WiredHome 79:544eb4964795 1451 _select(true);
WiredHome 79:544eb4964795 1452 _spiwrite(0x40); // Cmd: read data
WiredHome 79:544eb4964795 1453 _spiwrite(0x00); // dummy read
WiredHome 105:4f116006ba1f 1454 if (screenbpp == 16) {
WiredHome 105:4f116006ba1f 1455 pixel = _spiread();
WiredHome 105:4f116006ba1f 1456 pixel |= (_spiread() << 8);
WiredHome 105:4f116006ba1f 1457 } else {
WiredHome 105:4f116006ba1f 1458 pixel = _cvt8to16(_spiread());
WiredHome 105:4f116006ba1f 1459 }
WiredHome 79:544eb4964795 1460 _select(false);
WiredHome 41:2956a0a221e5 1461 REGISTERPERFORMANCE(PRF_READPIXEL);
WiredHome 41:2956a0a221e5 1462 return pixel;
WiredHome 41:2956a0a221e5 1463 }
WiredHome 41:2956a0a221e5 1464
WiredHome 44:207594dece70 1465
WiredHome 41:2956a0a221e5 1466 RetCode_t RA8875::getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1467 {
WiredHome 41:2956a0a221e5 1468 color_t pixel;
WiredHome 86:e86b355940f4 1469 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1470
WiredHome 41:2956a0a221e5 1471 PERFORMANCE_RESET;
WiredHome 86:e86b355940f4 1472 ret = WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 86:e86b355940f4 1473 ret = SetGraphicsCursorRead(x, y);
WiredHome 86:e86b355940f4 1474 ret = WriteCommand(0x02);
WiredHome 79:544eb4964795 1475 _select(true);
WiredHome 79:544eb4964795 1476 _spiwrite(0x40); // Cmd: read data
WiredHome 79:544eb4964795 1477 _spiwrite(0x00); // dummy read
WiredHome 106:c80828f5dea4 1478 if (screenbpp == 16)
WiredHome 106:c80828f5dea4 1479 _spiwrite(0x00); // dummy read is only necessary when in 16-bit mode
WiredHome 41:2956a0a221e5 1480 while (count--) {
WiredHome 105:4f116006ba1f 1481 if (screenbpp == 16) {
WiredHome 105:4f116006ba1f 1482 pixel = _spiread();
WiredHome 105:4f116006ba1f 1483 pixel |= (_spiread() << 8);
WiredHome 105:4f116006ba1f 1484 } else {
WiredHome 105:4f116006ba1f 1485 pixel = _cvt8to16(_spiread());
WiredHome 105:4f116006ba1f 1486 }
WiredHome 41:2956a0a221e5 1487 *p++ = pixel;
WiredHome 41:2956a0a221e5 1488 }
WiredHome 79:544eb4964795 1489 _select(false);
WiredHome 41:2956a0a221e5 1490 REGISTERPERFORMANCE(PRF_READPIXELSTREAM);
WiredHome 86:e86b355940f4 1491 return ret;
WiredHome 41:2956a0a221e5 1492 }
WiredHome 41:2956a0a221e5 1493
WiredHome 44:207594dece70 1494
WiredHome 83:7bad0068cca0 1495 RetCode_t RA8875::line(point_t p1, point_t p2)
WiredHome 83:7bad0068cca0 1496 {
WiredHome 83:7bad0068cca0 1497 return line(p1.x, p1.y, p2.x, p2.y);
WiredHome 83:7bad0068cca0 1498 }
WiredHome 83:7bad0068cca0 1499
WiredHome 83:7bad0068cca0 1500
WiredHome 83:7bad0068cca0 1501 RetCode_t RA8875::line(point_t p1, point_t p2, color_t color)
WiredHome 83:7bad0068cca0 1502 {
WiredHome 83:7bad0068cca0 1503 return line(p1.x, p1.y, p2.x, p2.y, color);
WiredHome 83:7bad0068cca0 1504 }
WiredHome 83:7bad0068cca0 1505
WiredHome 83:7bad0068cca0 1506
WiredHome 37:f19b7e7449dc 1507 RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color)
WiredHome 19:3f82c1161fd2 1508 {
WiredHome 19:3f82c1161fd2 1509 foreground(color);
WiredHome 19:3f82c1161fd2 1510 return line(x1,y1,x2,y2);
WiredHome 19:3f82c1161fd2 1511 }
WiredHome 19:3f82c1161fd2 1512
WiredHome 44:207594dece70 1513
WiredHome 37:f19b7e7449dc 1514 RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2)
WiredHome 19:3f82c1161fd2 1515 {
WiredHome 19:3f82c1161fd2 1516 PERFORMANCE_RESET;
WiredHome 62:ba5d33438fda 1517 if (x1 == x2 && y1 == y2) {
WiredHome 60:2dfd574f63bd 1518 pixel(x1, y1);
WiredHome 62:ba5d33438fda 1519 } else {
WiredHome 60:2dfd574f63bd 1520 WriteCommandW(0x91, x1);
WiredHome 60:2dfd574f63bd 1521 WriteCommandW(0x93, y1);
WiredHome 60:2dfd574f63bd 1522 WriteCommandW(0x95, x2);
WiredHome 60:2dfd574f63bd 1523 WriteCommandW(0x97, y2);
WiredHome 60:2dfd574f63bd 1524 unsigned char drawCmd = 0x00; // Line
WiredHome 60:2dfd574f63bd 1525 WriteCommand(0x90, drawCmd);
WiredHome 60:2dfd574f63bd 1526 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1527 if (!_WaitWhileReg(0x90, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1528 REGISTERPERFORMANCE(PRF_DRAWLINE);
WiredHome 131:5bd6ba2ee4a1 1529 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1530 }
WiredHome 60:2dfd574f63bd 1531 }
WiredHome 19:3f82c1161fd2 1532 REGISTERPERFORMANCE(PRF_DRAWLINE);
WiredHome 19:3f82c1161fd2 1533 return noerror;
WiredHome 19:3f82c1161fd2 1534 }
WiredHome 19:3f82c1161fd2 1535
WiredHome 144:ba002c4b21b3 1536
WiredHome 144:ba002c4b21b3 1537 RetCode_t RA8875::ThickLine(point_t p1, point_t p2, dim_t thickness, color_t color)
WiredHome 144:ba002c4b21b3 1538 {
WiredHome 144:ba002c4b21b3 1539 if (thickness == 1) {
WiredHome 144:ba002c4b21b3 1540 line(p1,p2, color);
WiredHome 144:ba002c4b21b3 1541 } else {
WiredHome 144:ba002c4b21b3 1542 int dx = abs(p2.x-p1.x), sx = p1.x<p2.x ? 1 : -1;
WiredHome 144:ba002c4b21b3 1543 int dy = abs(p2.y-p1.y), sy = p1.y<p2.y ? 1 : -1;
WiredHome 144:ba002c4b21b3 1544 int err = (dx>dy ? dx : -dy)/2, e2;
WiredHome 144:ba002c4b21b3 1545
WiredHome 144:ba002c4b21b3 1546 for (;;) {
WiredHome 144:ba002c4b21b3 1547 fillcircle(p1.x, p1.y, thickness/2, color);
WiredHome 144:ba002c4b21b3 1548 if (p1.x==p2.x && p1.y==p2.y)
WiredHome 144:ba002c4b21b3 1549 break;
WiredHome 144:ba002c4b21b3 1550 e2 = err;
WiredHome 144:ba002c4b21b3 1551 if (e2 >-dx)
WiredHome 144:ba002c4b21b3 1552 { err -= dy; p1.x += sx; }
WiredHome 144:ba002c4b21b3 1553 if (e2 < dy)
WiredHome 144:ba002c4b21b3 1554 { err += dx; p1.y += sy; }
WiredHome 144:ba002c4b21b3 1555 }
WiredHome 144:ba002c4b21b3 1556 }
WiredHome 144:ba002c4b21b3 1557 return noerror;
WiredHome 144:ba002c4b21b3 1558 }
WiredHome 144:ba002c4b21b3 1559
WiredHome 144:ba002c4b21b3 1560
WiredHome 107:f9ccffcb84f1 1561 //
WiredHome 107:f9ccffcb84f1 1562 // Rectangle functions all mostly helpers to the basic rectangle function
WiredHome 107:f9ccffcb84f1 1563 //
WiredHome 107:f9ccffcb84f1 1564
WiredHome 81:01da2e34283d 1565 RetCode_t RA8875::fillrect(rect_t r, color_t color, fill_t fillit)
WiredHome 81:01da2e34283d 1566 {
WiredHome 81:01da2e34283d 1567 return rect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, color, fillit);
WiredHome 81:01da2e34283d 1568 }
WiredHome 44:207594dece70 1569
WiredHome 73:f22a18707b5e 1570 RetCode_t RA8875::fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1571 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1572 {
WiredHome 19:3f82c1161fd2 1573 return rect(x1,y1,x2,y2,color,fillit);
WiredHome 19:3f82c1161fd2 1574 }
WiredHome 19:3f82c1161fd2 1575
WiredHome 81:01da2e34283d 1576 RetCode_t RA8875::rect(rect_t r, color_t color, fill_t fillit)
WiredHome 81:01da2e34283d 1577 {
WiredHome 81:01da2e34283d 1578 return rect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, color, fillit);
WiredHome 81:01da2e34283d 1579 }
WiredHome 44:207594dece70 1580
WiredHome 73:f22a18707b5e 1581 RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1582 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1583 {
WiredHome 19:3f82c1161fd2 1584 foreground(color);
WiredHome 19:3f82c1161fd2 1585 return rect(x1,y1,x2,y2,fillit);
WiredHome 19:3f82c1161fd2 1586 }
WiredHome 19:3f82c1161fd2 1587
WiredHome 73:f22a18707b5e 1588 RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1589 fill_t fillit)
WiredHome 19:3f82c1161fd2 1590 {
WiredHome 85:022bba13c5c4 1591 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 1592 PERFORMANCE_RESET;
WiredHome 85:022bba13c5c4 1593 // check for bad_parameter
WiredHome 105:4f116006ba1f 1594 if (x1 < 0 || x1 >= screenwidth || x2 < 0 || x2 >= screenwidth
WiredHome 105:4f116006ba1f 1595 || y1 < 0 || y1 >= screenheight || y2 < 0 || y2 >= screenheight) {
WiredHome 85:022bba13c5c4 1596 ret = bad_parameter;
WiredHome 100:0b084475d5a9 1597 } else {
WiredHome 85:022bba13c5c4 1598 if (x1 == x2 && y1 == y2) {
WiredHome 85:022bba13c5c4 1599 pixel(x1, y1);
WiredHome 85:022bba13c5c4 1600 } else if (x1 == x2) {
WiredHome 85:022bba13c5c4 1601 line(x1, y1, x2, y2);
WiredHome 85:022bba13c5c4 1602 } else if (y1 == y2) {
WiredHome 85:022bba13c5c4 1603 line(x1, y1, x2, y2);
WiredHome 85:022bba13c5c4 1604 } else {
WiredHome 85:022bba13c5c4 1605 WriteCommandW(0x91, x1);
WiredHome 85:022bba13c5c4 1606 WriteCommandW(0x93, y1);
WiredHome 85:022bba13c5c4 1607 WriteCommandW(0x95, x2);
WiredHome 85:022bba13c5c4 1608 WriteCommandW(0x97, y2);
WiredHome 85:022bba13c5c4 1609 unsigned char drawCmd = 0x10; // Rectangle
WiredHome 85:022bba13c5c4 1610 if (fillit == FILL)
WiredHome 85:022bba13c5c4 1611 drawCmd |= 0x20;
WiredHome 85:022bba13c5c4 1612 WriteCommand(0x90, drawCmd);
WiredHome 85:022bba13c5c4 1613 ret = WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1614 if (!_WaitWhileReg(0x90, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1615 REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
WiredHome 131:5bd6ba2ee4a1 1616 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1617 }
WiredHome 85:022bba13c5c4 1618 }
WiredHome 19:3f82c1161fd2 1619 }
WiredHome 19:3f82c1161fd2 1620 REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
WiredHome 85:022bba13c5c4 1621 return ret;
WiredHome 19:3f82c1161fd2 1622 }
WiredHome 19:3f82c1161fd2 1623
WiredHome 44:207594dece70 1624
WiredHome 107:f9ccffcb84f1 1625 //
WiredHome 107:f9ccffcb84f1 1626 // rounded rectangle functions are mostly helpers to the base round rect
WiredHome 107:f9ccffcb84f1 1627 //
WiredHome 107:f9ccffcb84f1 1628
WiredHome 107:f9ccffcb84f1 1629 RetCode_t RA8875::fillroundrect(rect_t r, dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 107:f9ccffcb84f1 1630 {
WiredHome 107:f9ccffcb84f1 1631 return roundrect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, radius1, radius2, color, fillit);
WiredHome 107:f9ccffcb84f1 1632 }
WiredHome 107:f9ccffcb84f1 1633
WiredHome 73:f22a18707b5e 1634 RetCode_t RA8875::fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1635 dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1636 {
WiredHome 19:3f82c1161fd2 1637 foreground(color);
WiredHome 19:3f82c1161fd2 1638 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1639 }
WiredHome 19:3f82c1161fd2 1640
WiredHome 107:f9ccffcb84f1 1641 RetCode_t RA8875::roundrect(rect_t r, dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 107:f9ccffcb84f1 1642 {
WiredHome 107:f9ccffcb84f1 1643 return roundrect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, radius1, radius2, color, fillit);
WiredHome 107:f9ccffcb84f1 1644 }
WiredHome 44:207594dece70 1645
WiredHome 73:f22a18707b5e 1646 RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1647 dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1648 {
WiredHome 19:3f82c1161fd2 1649 foreground(color);
WiredHome 19:3f82c1161fd2 1650 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1651 }
WiredHome 19:3f82c1161fd2 1652
WiredHome 44:207594dece70 1653
WiredHome 73:f22a18707b5e 1654 RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1655 dim_t radius1, dim_t radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 1656 {
WiredHome 19:3f82c1161fd2 1657 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1658
WiredHome 19:3f82c1161fd2 1659 PERFORMANCE_RESET;
WiredHome 105:4f116006ba1f 1660 if (x1 < 0 || x1 >= screenwidth || x2 < 0 || x2 >= screenwidth
WiredHome 105:4f116006ba1f 1661 || y1 < 0 || y1 >= screenheight || y2 < 0 || y2 >= screenheight) {
WiredHome 85:022bba13c5c4 1662 ret = bad_parameter;
WiredHome 85:022bba13c5c4 1663 } else if (x1 > x2 || y1 > y2 || (radius1 > (x2-x1)/2) || (radius2 > (y2-y1)/2) ) {
WiredHome 21:3c1efb192927 1664 ret = bad_parameter;
WiredHome 21:3c1efb192927 1665 } else if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 1666 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1667 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 1668 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1669 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 1670 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1671 } else {
WiredHome 38:38d503b4fad6 1672 WriteCommandW(0x91, x1);
WiredHome 38:38d503b4fad6 1673 WriteCommandW(0x93, y1);
WiredHome 38:38d503b4fad6 1674 WriteCommandW(0x95, x2);
WiredHome 38:38d503b4fad6 1675 WriteCommandW(0x97, y2);
WiredHome 38:38d503b4fad6 1676 WriteCommandW(0xA1, radius1);
WiredHome 38:38d503b4fad6 1677 WriteCommandW(0xA3, radius2);
WiredHome 21:3c1efb192927 1678 // Should not need this...
WiredHome 38:38d503b4fad6 1679 WriteCommandW(0xA5, 0);
WiredHome 38:38d503b4fad6 1680 WriteCommandW(0xA7, 0);
WiredHome 19:3f82c1161fd2 1681 unsigned char drawCmd = 0x20; // Rounded Rectangle
WiredHome 19:3f82c1161fd2 1682 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1683 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 1684 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 1685 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1686 if (!_WaitWhileReg(0xA0, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1687 REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
WiredHome 131:5bd6ba2ee4a1 1688 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1689 }
WiredHome 19:3f82c1161fd2 1690 }
WiredHome 19:3f82c1161fd2 1691 REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
WiredHome 19:3f82c1161fd2 1692 return ret;
WiredHome 19:3f82c1161fd2 1693 }
WiredHome 19:3f82c1161fd2 1694
WiredHome 44:207594dece70 1695
WiredHome 107:f9ccffcb84f1 1696 //
WiredHome 107:f9ccffcb84f1 1697 // triangle functions
WiredHome 107:f9ccffcb84f1 1698 //
WiredHome 107:f9ccffcb84f1 1699
WiredHome 73:f22a18707b5e 1700 RetCode_t RA8875::triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1701 loc_t x3, loc_t y3, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1702 {
WiredHome 20:6e2e4a8372eb 1703 RetCode_t ret;
WiredHome 20:6e2e4a8372eb 1704
WiredHome 105:4f116006ba1f 1705 if (x1 < 0 || x1 >= screenwidth || x2 < 0 || x2 >= screenwidth || x3 < 0 || x3 >= screenwidth
WiredHome 105:4f116006ba1f 1706 || y1 < 0 || y1 >= screenheight || y2 < 0 || y2 >= screenheight || y3 < 0 || y3 >= screenheight)
WiredHome 85:022bba13c5c4 1707 ret = bad_parameter;
WiredHome 19:3f82c1161fd2 1708 foreground(color);
WiredHome 20:6e2e4a8372eb 1709 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 20:6e2e4a8372eb 1710 return ret;
WiredHome 19:3f82c1161fd2 1711 }
WiredHome 19:3f82c1161fd2 1712
WiredHome 44:207594dece70 1713
WiredHome 73:f22a18707b5e 1714 RetCode_t RA8875::filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1715 loc_t x3, loc_t y3, color_t color, fill_t fillit)
WiredHome 73:f22a18707b5e 1716 {
WiredHome 73:f22a18707b5e 1717 RetCode_t ret;
WiredHome 73:f22a18707b5e 1718
WiredHome 73:f22a18707b5e 1719 foreground(color);
WiredHome 73:f22a18707b5e 1720 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 73:f22a18707b5e 1721 return ret;
WiredHome 73:f22a18707b5e 1722 }
WiredHome 73:f22a18707b5e 1723
WiredHome 73:f22a18707b5e 1724
WiredHome 73:f22a18707b5e 1725 RetCode_t RA8875::triangle(loc_t x1, loc_t y1 ,loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1726 loc_t x3, loc_t y3, fill_t fillit)
WiredHome 19:3f82c1161fd2 1727 {
WiredHome 19:3f82c1161fd2 1728 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1729
WiredHome 19:3f82c1161fd2 1730 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1731 if (x1 == x2 && y1 == y2 && x1 == x3 && y1 == y3) {
WiredHome 19:3f82c1161fd2 1732 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1733 } else {
WiredHome 38:38d503b4fad6 1734 WriteCommandW(0x91, x1);
WiredHome 38:38d503b4fad6 1735 WriteCommandW(0x93, y1);
WiredHome 38:38d503b4fad6 1736 WriteCommandW(0x95, x2);
WiredHome 38:38d503b4fad6 1737 WriteCommandW(0x97, y2);
WiredHome 38:38d503b4fad6 1738 WriteCommandW(0xA9, x3);
WiredHome 38:38d503b4fad6 1739 WriteCommandW(0xAB, y3);
WiredHome 19:3f82c1161fd2 1740 unsigned char drawCmd = 0x01; // Triangle
WiredHome 19:3f82c1161fd2 1741 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1742 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 1743 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 1744 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1745 if (!_WaitWhileReg(0x90, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1746 REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
WiredHome 131:5bd6ba2ee4a1 1747 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1748 }
WiredHome 19:3f82c1161fd2 1749 }
WiredHome 19:3f82c1161fd2 1750 REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
WiredHome 19:3f82c1161fd2 1751 return ret;
WiredHome 19:3f82c1161fd2 1752 }
WiredHome 19:3f82c1161fd2 1753
WiredHome 83:7bad0068cca0 1754
WiredHome 83:7bad0068cca0 1755 RetCode_t RA8875::circle(point_t p, dim_t radius,
WiredHome 83:7bad0068cca0 1756 color_t color, fill_t fillit)
WiredHome 83:7bad0068cca0 1757 {
WiredHome 83:7bad0068cca0 1758 foreground(color);
WiredHome 83:7bad0068cca0 1759 return circle(p.x,p.y,radius,fillit);
WiredHome 83:7bad0068cca0 1760 }
WiredHome 83:7bad0068cca0 1761
WiredHome 83:7bad0068cca0 1762
WiredHome 83:7bad0068cca0 1763 RetCode_t RA8875::fillcircle(point_t p, dim_t radius,
WiredHome 83:7bad0068cca0 1764 color_t color, fill_t fillit)
WiredHome 83:7bad0068cca0 1765 {
WiredHome 83:7bad0068cca0 1766 foreground(color);
WiredHome 83:7bad0068cca0 1767 return circle(p.x,p.y,radius,fillit);
WiredHome 83:7bad0068cca0 1768 }
WiredHome 83:7bad0068cca0 1769
WiredHome 83:7bad0068cca0 1770
WiredHome 83:7bad0068cca0 1771 RetCode_t RA8875::circle(point_t p, dim_t radius, fill_t fillit)
WiredHome 83:7bad0068cca0 1772 {
WiredHome 83:7bad0068cca0 1773 return circle(p.x,p.y,radius,fillit);
WiredHome 83:7bad0068cca0 1774 }
WiredHome 83:7bad0068cca0 1775
WiredHome 83:7bad0068cca0 1776
WiredHome 73:f22a18707b5e 1777 RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius,
WiredHome 73:f22a18707b5e 1778 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1779 {
WiredHome 19:3f82c1161fd2 1780 foreground(color);
WiredHome 19:3f82c1161fd2 1781 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 1782 }
WiredHome 19:3f82c1161fd2 1783
WiredHome 44:207594dece70 1784
WiredHome 73:f22a18707b5e 1785 RetCode_t RA8875::fillcircle(loc_t x, loc_t y, dim_t radius,
WiredHome 73:f22a18707b5e 1786 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1787 {
WiredHome 19:3f82c1161fd2 1788 foreground(color);
WiredHome 19:3f82c1161fd2 1789 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 1790 }
WiredHome 19:3f82c1161fd2 1791
WiredHome 44:207594dece70 1792
WiredHome 37:f19b7e7449dc 1793 RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius, fill_t fillit)
WiredHome 19:3f82c1161fd2 1794 {
WiredHome 19:3f82c1161fd2 1795 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1796
WiredHome 19:3f82c1161fd2 1797 PERFORMANCE_RESET;
WiredHome 105:4f116006ba1f 1798 if (radius <= 0 || (x - radius) < 0 || (x + radius) > screenwidth
WiredHome 105:4f116006ba1f 1799 || (y - radius) < 0 || (y + radius) > screenheight) {
WiredHome 19:3f82c1161fd2 1800 ret = bad_parameter;
WiredHome 19:3f82c1161fd2 1801 } else if (radius == 1) {
WiredHome 19:3f82c1161fd2 1802 pixel(x,y);
WiredHome 19:3f82c1161fd2 1803 } else {
WiredHome 38:38d503b4fad6 1804 WriteCommandW(0x99, x);
WiredHome 38:38d503b4fad6 1805 WriteCommandW(0x9B, y);
WiredHome 19:3f82c1161fd2 1806 WriteCommand(0x9d, radius & 0xFF);
WiredHome 19:3f82c1161fd2 1807 unsigned char drawCmd = 0x00; // Circle
WiredHome 19:3f82c1161fd2 1808 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1809 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 1810 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 1811 WriteCommand(0x90, 0x40 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1812 if (!_WaitWhileReg(0x90, 0x40)) {
WiredHome 131:5bd6ba2ee4a1 1813 REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
WiredHome 131:5bd6ba2ee4a1 1814 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1815 }
WiredHome 19:3f82c1161fd2 1816 }
WiredHome 19:3f82c1161fd2 1817 REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
WiredHome 19:3f82c1161fd2 1818 return ret;
WiredHome 19:3f82c1161fd2 1819 }
WiredHome 19:3f82c1161fd2 1820
WiredHome 44:207594dece70 1821
WiredHome 37:f19b7e7449dc 1822 RetCode_t RA8875::ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1823 {
WiredHome 19:3f82c1161fd2 1824 foreground(color);
WiredHome 25:9556a3a9b7cc 1825 return ellipse(x,y,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1826 }
WiredHome 19:3f82c1161fd2 1827
WiredHome 44:207594dece70 1828
WiredHome 37:f19b7e7449dc 1829 RetCode_t RA8875::fillellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 25:9556a3a9b7cc 1830 {
WiredHome 25:9556a3a9b7cc 1831 foreground(color);
WiredHome 25:9556a3a9b7cc 1832 return ellipse(x,y,radius1,radius2,fillit);
WiredHome 25:9556a3a9b7cc 1833 }
WiredHome 44:207594dece70 1834
WiredHome 73:f22a18707b5e 1835
WiredHome 37:f19b7e7449dc 1836 RetCode_t RA8875::ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 1837 {
WiredHome 19:3f82c1161fd2 1838 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1839
WiredHome 19:3f82c1161fd2 1840 PERFORMANCE_RESET;
WiredHome 105:4f116006ba1f 1841 if (radius1 <= 0 || radius2 <= 0 || (x - radius1) < 0 || (x + radius1) > screenwidth
WiredHome 105:4f116006ba1f 1842 || (y - radius2) < 0 || (y + radius2) > screenheight) {
WiredHome 85:022bba13c5c4 1843 ret = bad_parameter;
WiredHome 25:9556a3a9b7cc 1844 } else if (radius1 == 1 && radius2 == 1) {
WiredHome 19:3f82c1161fd2 1845 pixel(x, y);
WiredHome 19:3f82c1161fd2 1846 } else {
WiredHome 38:38d503b4fad6 1847 WriteCommandW(0xA5, x);
WiredHome 38:38d503b4fad6 1848 WriteCommandW(0xA7, y);
WiredHome 38:38d503b4fad6 1849 WriteCommandW(0xA1, radius1);
WiredHome 38:38d503b4fad6 1850 WriteCommandW(0xA3, radius2);
WiredHome 19:3f82c1161fd2 1851 unsigned char drawCmd = 0x00; // Ellipse
WiredHome 19:3f82c1161fd2 1852 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1853 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 1854 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 1855 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1856 if (!_WaitWhileReg(0xA0, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1857 REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
WiredHome 131:5bd6ba2ee4a1 1858 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1859 }
WiredHome 19:3f82c1161fd2 1860 }
WiredHome 19:3f82c1161fd2 1861 REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
WiredHome 19:3f82c1161fd2 1862 return ret;
WiredHome 19:3f82c1161fd2 1863 }
WiredHome 19:3f82c1161fd2 1864
WiredHome 44:207594dece70 1865
WiredHome 68:ab08efabfc88 1866 RetCode_t RA8875::frequency(unsigned long Hz, unsigned long Hz2)
WiredHome 19:3f82c1161fd2 1867 {
WiredHome 66:468a11f05580 1868 spiwritefreq = Hz;
WiredHome 68:ab08efabfc88 1869 if (Hz2 != 0)
WiredHome 68:ab08efabfc88 1870 spireadfreq = Hz2;
WiredHome 68:ab08efabfc88 1871 else
WiredHome 68:ab08efabfc88 1872 spireadfreq = Hz/2;
WiredHome 68:ab08efabfc88 1873 _setWriteSpeed(true);
WiredHome 19:3f82c1161fd2 1874 // __ ___
WiredHome 19:3f82c1161fd2 1875 // Clock ___A Rising edge latched
WiredHome 19:3f82c1161fd2 1876 // ___ ____
WiredHome 19:3f82c1161fd2 1877 // Data ___X____
WiredHome 19:3f82c1161fd2 1878 spi.format(8, 3); // 8 bits and clock to data phase 0
WiredHome 19:3f82c1161fd2 1879 return noerror;
WiredHome 19:3f82c1161fd2 1880 }
WiredHome 19:3f82c1161fd2 1881
WiredHome 68:ab08efabfc88 1882 void RA8875::_setWriteSpeed(bool writeSpeed)
WiredHome 68:ab08efabfc88 1883 {
WiredHome 68:ab08efabfc88 1884 if (writeSpeed) {
WiredHome 68:ab08efabfc88 1885 spi.frequency(spiwritefreq);
WiredHome 68:ab08efabfc88 1886 spiWriteSpeed = true;
WiredHome 68:ab08efabfc88 1887 } else {
WiredHome 68:ab08efabfc88 1888 spi.frequency(spireadfreq);
WiredHome 68:ab08efabfc88 1889 spiWriteSpeed = false;
WiredHome 68:ab08efabfc88 1890 }
WiredHome 68:ab08efabfc88 1891 }
WiredHome 44:207594dece70 1892
WiredHome 131:5bd6ba2ee4a1 1893
WiredHome 131:5bd6ba2ee4a1 1894
WiredHome 131:5bd6ba2ee4a1 1895 RetCode_t RA8875::BlockMove(uint8_t dstLayer, uint8_t dstDataSelect, point_t dstPoint,
WiredHome 131:5bd6ba2ee4a1 1896 uint8_t srcLayer, uint8_t srcDataSelect, point_t srcPoint,
WiredHome 137:9e09f6081ef1 1897 dim_t bte_width, dim_t bte_height,
WiredHome 131:5bd6ba2ee4a1 1898 uint8_t bte_op_code, uint8_t bte_rop_code)
WiredHome 131:5bd6ba2ee4a1 1899 {
WiredHome 131:5bd6ba2ee4a1 1900 uint8_t cmd;
WiredHome 131:5bd6ba2ee4a1 1901
WiredHome 131:5bd6ba2ee4a1 1902 PERFORMANCE_RESET;
WiredHome 137:9e09f6081ef1 1903 ///@todo range check and error return rather than to secretly fix
WiredHome 131:5bd6ba2ee4a1 1904 srcPoint.x &= 0x3FF; // prevent high bits from doing unexpected things
WiredHome 131:5bd6ba2ee4a1 1905 srcPoint.y &= 0x1FF;
WiredHome 131:5bd6ba2ee4a1 1906 dstPoint.x &= 0x3FF;
WiredHome 131:5bd6ba2ee4a1 1907 dstPoint.y &= 0x1FF;
WiredHome 131:5bd6ba2ee4a1 1908 WriteCommandW(0x54, srcPoint.x);
WiredHome 137:9e09f6081ef1 1909 WriteCommandW(0x56, ((dim_t)(srcLayer & 1) << 15) | srcPoint.y);
WiredHome 131:5bd6ba2ee4a1 1910 WriteCommandW(0x58, dstPoint.x);
WiredHome 137:9e09f6081ef1 1911 WriteCommandW(0x5A, ((dim_t)(dstLayer & 1) << 15) | dstPoint.y);
WiredHome 131:5bd6ba2ee4a1 1912 WriteCommandW(0x5C, bte_width);
WiredHome 131:5bd6ba2ee4a1 1913 WriteCommandW(0x5E, bte_height);
WiredHome 131:5bd6ba2ee4a1 1914 WriteCommand(0x51, ((bte_rop_code & 0x0F) << 4) | (bte_op_code & 0x0F));
WiredHome 131:5bd6ba2ee4a1 1915 cmd = ((srcDataSelect & 1) << 6) | ((dstDataSelect & 1) << 5);
WiredHome 131:5bd6ba2ee4a1 1916 WriteCommand(0x50, 0x80 | cmd); // enable the BTE
WiredHome 131:5bd6ba2ee4a1 1917 if (!_WaitWhileBusy(0x40)) {
WiredHome 131:5bd6ba2ee4a1 1918 REGISTERPERFORMANCE(PRF_BLOCKMOVE);
WiredHome 131:5bd6ba2ee4a1 1919 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1920 }
WiredHome 131:5bd6ba2ee4a1 1921 REGISTERPERFORMANCE(PRF_BLOCKMOVE);
WiredHome 131:5bd6ba2ee4a1 1922 return noerror;
WiredHome 131:5bd6ba2ee4a1 1923 }
WiredHome 131:5bd6ba2ee4a1 1924
WiredHome 131:5bd6ba2ee4a1 1925
WiredHome 19:3f82c1161fd2 1926 RetCode_t RA8875::Power(bool on)
WiredHome 19:3f82c1161fd2 1927 {
WiredHome 19:3f82c1161fd2 1928 WriteCommand(0x01, (on) ? 0x80 : 0x00);
WiredHome 19:3f82c1161fd2 1929 return noerror;
WiredHome 19:3f82c1161fd2 1930 }
WiredHome 19:3f82c1161fd2 1931
WiredHome 44:207594dece70 1932
WiredHome 131:5bd6ba2ee4a1 1933 RetCode_t RA8875::Backlight_u8(uint8_t brightness)
WiredHome 19:3f82c1161fd2 1934 {
WiredHome 19:3f82c1161fd2 1935 static bool is_enabled = false;
WiredHome 131:5bd6ba2ee4a1 1936
WiredHome 19:3f82c1161fd2 1937 if (brightness == 0) {
WiredHome 19:3f82c1161fd2 1938 WriteCommand(0x8a); // Disable the PWM
WiredHome 19:3f82c1161fd2 1939 WriteData(0x00);
WiredHome 19:3f82c1161fd2 1940 is_enabled = false;
WiredHome 19:3f82c1161fd2 1941 } else if (!is_enabled) {
WiredHome 19:3f82c1161fd2 1942 WriteCommand(0x8a); // Enable the PWM
WiredHome 19:3f82c1161fd2 1943 WriteData(0x80);
WiredHome 19:3f82c1161fd2 1944 WriteCommand(0x8a); // Not sure why this is needed, but following the pattern
WiredHome 19:3f82c1161fd2 1945 WriteData(0x81); // open PWM (SYS_CLK / 2 as best I can tell)
WiredHome 19:3f82c1161fd2 1946 is_enabled = true;
WiredHome 19:3f82c1161fd2 1947 }
WiredHome 19:3f82c1161fd2 1948 WriteCommand(0x8b, brightness); // Brightness parameter 0xff-0x00
WiredHome 19:3f82c1161fd2 1949 return noerror;
WiredHome 19:3f82c1161fd2 1950 }
WiredHome 19:3f82c1161fd2 1951
WiredHome 86:e86b355940f4 1952 uint8_t RA8875::GetBacklight_u8(void)
WiredHome 86:e86b355940f4 1953 {
WiredHome 86:e86b355940f4 1954 return ReadCommand(0x8b);
WiredHome 86:e86b355940f4 1955 }
WiredHome 44:207594dece70 1956
WiredHome 19:3f82c1161fd2 1957 RetCode_t RA8875::Backlight(float brightness)
WiredHome 19:3f82c1161fd2 1958 {
WiredHome 19:3f82c1161fd2 1959 unsigned char b;
WiredHome 73:f22a18707b5e 1960
WiredHome 29:422616aa04bd 1961 if (brightness >= 1.0)
WiredHome 19:3f82c1161fd2 1962 b = 255;
WiredHome 29:422616aa04bd 1963 else if (brightness <= 0.0)
WiredHome 19:3f82c1161fd2 1964 b = 0;
WiredHome 19:3f82c1161fd2 1965 else
WiredHome 19:3f82c1161fd2 1966 b = (unsigned char)(brightness * 255);
WiredHome 19:3f82c1161fd2 1967 return Backlight_u8(b);
WiredHome 19:3f82c1161fd2 1968 }
WiredHome 19:3f82c1161fd2 1969
WiredHome 86:e86b355940f4 1970 float RA8875::GetBacklight(void)
WiredHome 86:e86b355940f4 1971 {
WiredHome 86:e86b355940f4 1972 return (float)(GetBacklight_u8())/255;
WiredHome 86:e86b355940f4 1973 }
WiredHome 44:207594dece70 1974
WiredHome 98:ecebed9b80b2 1975 RetCode_t RA8875::SelectUserFont(const uint8_t * _font)
WiredHome 98:ecebed9b80b2 1976 {
WiredHome 98:ecebed9b80b2 1977 INFO("Cursor(%d,%d) %p", cursor_x, cursor_y, _font);
WiredHome 98:ecebed9b80b2 1978 INFO("Text C(%d,%d)", GetTextCursor_X(), GetTextCursor_Y());
WiredHome 98:ecebed9b80b2 1979 if (_font) {
WiredHome 98:ecebed9b80b2 1980 HexDump("Font Memory", _font, 16);
WiredHome 98:ecebed9b80b2 1981 extFontHeight = _font[6];
WiredHome 98:ecebed9b80b2 1982 uint32_t totalWidth = 0;
WiredHome 98:ecebed9b80b2 1983 uint16_t firstChar = _font[3] * 256 + _font[2];
WiredHome 98:ecebed9b80b2 1984 uint16_t lastChar = _font[5] * 256 + _font[4];
WiredHome 98:ecebed9b80b2 1985 uint16_t i;
WiredHome 98:ecebed9b80b2 1986
WiredHome 98:ecebed9b80b2 1987 for (i=firstChar; i<=lastChar; i++) {
WiredHome 98:ecebed9b80b2 1988 // 8 bytes of preamble to the first level lookup table
WiredHome 98:ecebed9b80b2 1989 uint16_t offsetToCharLookup = 8 + 4 * (i - firstChar); // 4-bytes: width(pixels), 16-bit offset from table start, 0
WiredHome 98:ecebed9b80b2 1990 totalWidth += _font[offsetToCharLookup];
WiredHome 98:ecebed9b80b2 1991 }
WiredHome 98:ecebed9b80b2 1992 extFontWidth = totalWidth / (lastChar - firstChar);
WiredHome 98:ecebed9b80b2 1993 INFO("Font Metrics: Avg W: %2d, H: %2d, First:%d, Last:%d", extFontWidth, extFontHeight, firstChar, lastChar);
WiredHome 98:ecebed9b80b2 1994 }
WiredHome 98:ecebed9b80b2 1995 SetTextCursor(GetTextCursor_X(), GetTextCursor_Y()); // soft-font cursor -> hw cursor
WiredHome 98:ecebed9b80b2 1996 font = _font;
WiredHome 98:ecebed9b80b2 1997 return GraphicsDisplay::SelectUserFont(_font);
WiredHome 98:ecebed9b80b2 1998 }
WiredHome 44:207594dece70 1999
WiredHome 19:3f82c1161fd2 2000 RetCode_t RA8875::background(color_t color)
WiredHome 19:3f82c1161fd2 2001 {
WiredHome 37:f19b7e7449dc 2002 GraphicsDisplay::background(color);
WiredHome 133:e36dcfc2d756 2003 return _writeColorTrio(0x60, color);
WiredHome 19:3f82c1161fd2 2004 }
WiredHome 19:3f82c1161fd2 2005
WiredHome 44:207594dece70 2006
WiredHome 19:3f82c1161fd2 2007 RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 2008 {
WiredHome 37:f19b7e7449dc 2009 background(RGB(r,g,b));
WiredHome 19:3f82c1161fd2 2010 return noerror;
WiredHome 19:3f82c1161fd2 2011 }
WiredHome 19:3f82c1161fd2 2012
WiredHome 44:207594dece70 2013
WiredHome 19:3f82c1161fd2 2014 RetCode_t RA8875::foreground(color_t color)
WiredHome 19:3f82c1161fd2 2015 {
WiredHome 37:f19b7e7449dc 2016 GraphicsDisplay::foreground(color);
WiredHome 133:e36dcfc2d756 2017 return _writeColorTrio(0x63, color);
WiredHome 19:3f82c1161fd2 2018 }
WiredHome 19:3f82c1161fd2 2019
WiredHome 44:207594dece70 2020
WiredHome 37:f19b7e7449dc 2021 RetCode_t RA8875::foreground(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 2022 {
WiredHome 37:f19b7e7449dc 2023 foreground(RGB(r,g,b));
WiredHome 19:3f82c1161fd2 2024 return noerror;
WiredHome 19:3f82c1161fd2 2025 }
WiredHome 19:3f82c1161fd2 2026
WiredHome 44:207594dece70 2027
WiredHome 37:f19b7e7449dc 2028 color_t RA8875::GetForeColor(void)
WiredHome 19:3f82c1161fd2 2029 {
WiredHome 133:e36dcfc2d756 2030 return _readColorTrio(0x63);
WiredHome 19:3f82c1161fd2 2031 }
WiredHome 19:3f82c1161fd2 2032
WiredHome 44:207594dece70 2033
WiredHome 19:3f82c1161fd2 2034 color_t RA8875::DOSColor(int i)
WiredHome 73:f22a18707b5e 2035 {
WiredHome 73:f22a18707b5e 2036 const color_t colors[16] = {
WiredHome 19:3f82c1161fd2 2037 Black, Blue, Green, Cyan,
WiredHome 19:3f82c1161fd2 2038 Red, Magenta, Brown, Gray,
WiredHome 19:3f82c1161fd2 2039 Charcoal, BrightBlue, BrightGreen, BrightCyan,
WiredHome 19:3f82c1161fd2 2040 Orange, Pink, Yellow, White
WiredHome 73:f22a18707b5e 2041 };
WiredHome 85:022bba13c5c4 2042 if (i >= 0 && i < 16)
WiredHome 19:3f82c1161fd2 2043 return colors[i];
WiredHome 19:3f82c1161fd2 2044 else
WiredHome 19:3f82c1161fd2 2045 return 0;
WiredHome 73:f22a18707b5e 2046 }
WiredHome 19:3f82c1161fd2 2047
WiredHome 44:207594dece70 2048
WiredHome 73:f22a18707b5e 2049 const char * RA8875::DOSColorNames(int i)
WiredHome 73:f22a18707b5e 2050 {
WiredHome 73:f22a18707b5e 2051 const char * names[16] = {
WiredHome 19:3f82c1161fd2 2052 "Black", "Blue", "Green", "Cyan",
WiredHome 19:3f82c1161fd2 2053 "Red", "Magenta", "Brown", "Gray",
WiredHome 19:3f82c1161fd2 2054 "Charcoal", "BrightBlue", "BrightGreen", "BrightCyan",
WiredHome 19:3f82c1161fd2 2055 "Orange", "Pink", "Yellow", "White"
WiredHome 73:f22a18707b5e 2056 };
WiredHome 85:022bba13c5c4 2057 if (i >= 0 && i < 16)
WiredHome 19:3f82c1161fd2 2058 return names[i];
WiredHome 19:3f82c1161fd2 2059 else
WiredHome 19:3f82c1161fd2 2060 return NULL;
WiredHome 73:f22a18707b5e 2061 }
WiredHome 19:3f82c1161fd2 2062
WiredHome 19:3f82c1161fd2 2063
WiredHome 19:3f82c1161fd2 2064 ///////////////////////////////////////////////////////////////
WiredHome 19:3f82c1161fd2 2065 // Private functions
WiredHome 19:3f82c1161fd2 2066
WiredHome 79:544eb4964795 2067 unsigned char RA8875::_spiwrite(unsigned char data)
WiredHome 19:3f82c1161fd2 2068 {
WiredHome 19:3f82c1161fd2 2069 unsigned char retval;
WiredHome 73:f22a18707b5e 2070
WiredHome 68:ab08efabfc88 2071 if (!spiWriteSpeed)
WiredHome 68:ab08efabfc88 2072 _setWriteSpeed(true);
WiredHome 19:3f82c1161fd2 2073 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 2074 return retval;
WiredHome 19:3f82c1161fd2 2075 }
WiredHome 19:3f82c1161fd2 2076
WiredHome 44:207594dece70 2077
WiredHome 79:544eb4964795 2078 unsigned char RA8875::_spiread(void)
WiredHome 19:3f82c1161fd2 2079 {
WiredHome 19:3f82c1161fd2 2080 unsigned char retval;
WiredHome 19:3f82c1161fd2 2081 unsigned char data = 0;
WiredHome 73:f22a18707b5e 2082
WiredHome 68:ab08efabfc88 2083 if (spiWriteSpeed)
WiredHome 68:ab08efabfc88 2084 _setWriteSpeed(false);
WiredHome 19:3f82c1161fd2 2085 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 2086 return retval;
WiredHome 19:3f82c1161fd2 2087 }
WiredHome 19:3f82c1161fd2 2088
WiredHome 44:207594dece70 2089
WiredHome 79:544eb4964795 2090 RetCode_t RA8875::_select(bool chipsel)
WiredHome 19:3f82c1161fd2 2091 {
WiredHome 19:3f82c1161fd2 2092 cs = (chipsel == true) ? 0 : 1;
WiredHome 19:3f82c1161fd2 2093 return noerror;
WiredHome 19:3f82c1161fd2 2094 }
WiredHome 19:3f82c1161fd2 2095
WiredHome 44:207594dece70 2096
WiredHome 72:ecffe56af969 2097 RetCode_t RA8875::PrintScreen(uint16_t layer, loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP)
WiredHome 72:ecffe56af969 2098 {
WiredHome 74:686faa218914 2099 (void)layer;
WiredHome 96:40b74dd3695b 2100
WiredHome 96:40b74dd3695b 2101 // AttachPrintHandler(this, RA8875::_printCallback);
WiredHome 96:40b74dd3695b 2102 // return PrintScreen(x,y,w,h);
WiredHome 74:686faa218914 2103 return PrintScreen(x, y, w, h, Name_BMP);
WiredHome 72:ecffe56af969 2104 }
WiredHome 72:ecffe56af969 2105
WiredHome 96:40b74dd3695b 2106 RetCode_t RA8875::_printCallback(RA8875::filecmd_t cmd, uint8_t * buffer, uint16_t size)
WiredHome 96:40b74dd3695b 2107 {
WiredHome 96:40b74dd3695b 2108 HexDump("CB", buffer, size);
WiredHome 96:40b74dd3695b 2109 switch(cmd) {
WiredHome 96:40b74dd3695b 2110 case RA8875::OPEN:
WiredHome 96:40b74dd3695b 2111 //pc.printf("About to write %lu bytes\r\n", *(uint32_t *)buffer);
WiredHome 96:40b74dd3695b 2112 _printFH = fopen("file.bmp", "w+b");
WiredHome 96:40b74dd3695b 2113 if (_printFH == 0)
WiredHome 96:40b74dd3695b 2114 return file_not_found;
WiredHome 96:40b74dd3695b 2115 break;
WiredHome 96:40b74dd3695b 2116 case RA8875::WRITE:
WiredHome 96:40b74dd3695b 2117 //pc.printf(" Write %4u bytes\r\n", size);
WiredHome 96:40b74dd3695b 2118 fwrite(buffer, 1, size, _printFH);
WiredHome 96:40b74dd3695b 2119 break;
WiredHome 96:40b74dd3695b 2120 case RA8875::CLOSE:
WiredHome 96:40b74dd3695b 2121 //pc.printf(" close\r\n");
WiredHome 96:40b74dd3695b 2122 fclose(_printFH);
WiredHome 96:40b74dd3695b 2123 _printFH = 0;
WiredHome 96:40b74dd3695b 2124 break;
WiredHome 96:40b74dd3695b 2125 default:
WiredHome 96:40b74dd3695b 2126 //pc.printf("Unexpected callback %d\r\n", cmd);
WiredHome 96:40b74dd3695b 2127 return file_not_found;
WiredHome 96:40b74dd3695b 2128 //break;
WiredHome 96:40b74dd3695b 2129 }
WiredHome 96:40b74dd3695b 2130 return noerror;
WiredHome 96:40b74dd3695b 2131 }
WiredHome 96:40b74dd3695b 2132
WiredHome 162:a2d7f1988711 2133 int RA8875::RoundUp(int value, int roundTo)
WiredHome 162:a2d7f1988711 2134 {
WiredHome 162:a2d7f1988711 2135 if (roundTo == 0)
WiredHome 162:a2d7f1988711 2136 return 0;
WiredHome 162:a2d7f1988711 2137 return ((value + roundTo - 1) / roundTo) * roundTo;
WiredHome 162:a2d7f1988711 2138 }
WiredHome 162:a2d7f1988711 2139
WiredHome 96:40b74dd3695b 2140 RetCode_t RA8875::PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h)
WiredHome 96:40b74dd3695b 2141 {
WiredHome 96:40b74dd3695b 2142 BITMAPFILEHEADER BMP_Header;
WiredHome 96:40b74dd3695b 2143 BITMAPINFOHEADER BMP_Info;
WiredHome 96:40b74dd3695b 2144 uint8_t * lineBuffer = NULL;
WiredHome 96:40b74dd3695b 2145 color_t * pixelBuffer = NULL;
WiredHome 96:40b74dd3695b 2146 color_t * pixelBuffer2 = NULL;
WiredHome 96:40b74dd3695b 2147
WiredHome 98:ecebed9b80b2 2148 INFO("(%d,%d) - (%d,%d)", x,y,w,h);
WiredHome 105:4f116006ba1f 2149 if (x >= 0 && x < screenwidth
WiredHome 105:4f116006ba1f 2150 && y >= 0 && y < screenheight
WiredHome 105:4f116006ba1f 2151 && w > 0 && x + w <= screenwidth
WiredHome 105:4f116006ba1f 2152 && h > 0 && y + h <= screenheight) {
WiredHome 96:40b74dd3695b 2153
WiredHome 96:40b74dd3695b 2154 BMP_Header.bfType = BF_TYPE;
WiredHome 162:a2d7f1988711 2155 BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Info);
WiredHome 96:40b74dd3695b 2156 BMP_Header.bfReserved1 = 0;
WiredHome 96:40b74dd3695b 2157 BMP_Header.bfReserved2 = 0;
WiredHome 162:a2d7f1988711 2158 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Info);
WiredHome 162:a2d7f1988711 2159
WiredHome 162:a2d7f1988711 2160 // Bytes in the line buffer
WiredHome 162:a2d7f1988711 2161 int lineBufSize = RoundUp(3 * w, 4); // ((24 * w + 7)/8);
WiredHome 162:a2d7f1988711 2162 INFO("LineBufSize: %d", lineBufSize);
WiredHome 96:40b74dd3695b 2163
WiredHome 96:40b74dd3695b 2164 BMP_Info.biSize = sizeof(BMP_Info);
WiredHome 96:40b74dd3695b 2165 BMP_Info.biWidth = w;
WiredHome 96:40b74dd3695b 2166 BMP_Info.biHeight = h;
WiredHome 96:40b74dd3695b 2167 BMP_Info.biPlanes = 1;
WiredHome 96:40b74dd3695b 2168 BMP_Info.biBitCount = 24;
WiredHome 96:40b74dd3695b 2169 BMP_Info.biCompression = BI_RGB;
WiredHome 162:a2d7f1988711 2170 BMP_Info.biSizeImage = lineBufSize * h;
WiredHome 96:40b74dd3695b 2171 BMP_Info.biXPelsPerMeter = 0;
WiredHome 96:40b74dd3695b 2172 BMP_Info.biYPelsPerMeter = 0;
WiredHome 96:40b74dd3695b 2173 BMP_Info.biClrUsed = 0;
WiredHome 96:40b74dd3695b 2174 BMP_Info.biClrImportant = 0;
WiredHome 96:40b74dd3695b 2175
WiredHome 96:40b74dd3695b 2176 // Allocate the memory we need to proceed
WiredHome 145:5eb2492acdda 2177 lineBuffer = (uint8_t *)swMalloc(lineBufSize);
WiredHome 96:40b74dd3695b 2178 if (lineBuffer == NULL) {
WiredHome 96:40b74dd3695b 2179 ERR("Not enough RAM for PrintScreen lineBuffer");
WiredHome 96:40b74dd3695b 2180 return(not_enough_ram);
WiredHome 96:40b74dd3695b 2181 }
WiredHome 162:a2d7f1988711 2182 memset(lineBuffer, 0, lineBufSize); // zero-Fill
WiredHome 96:40b74dd3695b 2183
WiredHome 96:40b74dd3695b 2184 #define DOUBLEBUF /* one larger buffer instead of two */
WiredHome 96:40b74dd3695b 2185
WiredHome 96:40b74dd3695b 2186 #ifdef DOUBLEBUF
WiredHome 96:40b74dd3695b 2187 // In the "#else", pixelBuffer2 malloc returns a value,
WiredHome 96:40b74dd3695b 2188 // but is actually causing a failure later.
WiredHome 96:40b74dd3695b 2189 // This test helps determine if it is truly out of memory,
WiredHome 96:40b74dd3695b 2190 // or if malloc is broken.
WiredHome 145:5eb2492acdda 2191 pixelBuffer = (color_t *)swMalloc(2 * w * sizeof(color_t));
WiredHome 96:40b74dd3695b 2192 pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
WiredHome 96:40b74dd3695b 2193 #else
WiredHome 145:5eb2492acdda 2194 pixelBuffer = (color_t *)swMalloc(w * sizeof(color_t));
WiredHome 145:5eb2492acdda 2195 pixelBuffer2 = (color_t *)swMalloc(w * sizeof(color_t));
WiredHome 96:40b74dd3695b 2196 #endif
WiredHome 96:40b74dd3695b 2197 if (pixelBuffer == NULL || pixelBuffer2 == NULL) {
WiredHome 96:40b74dd3695b 2198 ERR("Not enough RAM for pixelBuffer");
WiredHome 96:40b74dd3695b 2199 #ifndef DOUBLEBUF
WiredHome 96:40b74dd3695b 2200 if (pixelBuffer2)
WiredHome 145:5eb2492acdda 2201 swFree(pixelBuffer2);
WiredHome 96:40b74dd3695b 2202 #endif
WiredHome 96:40b74dd3695b 2203 if (pixelBuffer)
WiredHome 145:5eb2492acdda 2204 swFree(pixelBuffer);
WiredHome 145:5eb2492acdda 2205 swFree(lineBuffer);
WiredHome 96:40b74dd3695b 2206 return(not_enough_ram);
WiredHome 96:40b74dd3695b 2207 }
WiredHome 96:40b74dd3695b 2208
WiredHome 96:40b74dd3695b 2209 // Get the file primed...
WiredHome 96:40b74dd3695b 2210 privateCallback(OPEN, (uint8_t *)&BMP_Header.bfSize, 4);
WiredHome 96:40b74dd3695b 2211
WiredHome 96:40b74dd3695b 2212 // Be optimistic - don't check for errors.
WiredHome 162:a2d7f1988711 2213 HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 96:40b74dd3695b 2214 //fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image);
WiredHome 96:40b74dd3695b 2215 privateCallback(WRITE, (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 96:40b74dd3695b 2216
WiredHome 96:40b74dd3695b 2217 HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 96:40b74dd3695b 2218 //fwrite(&BMP_Info, sizeof(char), sizeof(BMP_Info), Image);
WiredHome 96:40b74dd3695b 2219 privateCallback(WRITE, (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 96:40b74dd3695b 2220
WiredHome 96:40b74dd3695b 2221 //color_t transparency = GetBackgroundTransparencyColor();
WiredHome 96:40b74dd3695b 2222 LayerMode_T ltpr0 = GetLayerMode();
WiredHome 96:40b74dd3695b 2223
WiredHome 96:40b74dd3695b 2224 uint16_t prevLayer = GetDrawingLayer();
WiredHome 96:40b74dd3695b 2225 // If only one of the layers is visible, select that layer
WiredHome 96:40b74dd3695b 2226 switch(ltpr0) {
WiredHome 96:40b74dd3695b 2227 case ShowLayer0:
WiredHome 96:40b74dd3695b 2228 SelectDrawingLayer(0);
WiredHome 96:40b74dd3695b 2229 break;
WiredHome 96:40b74dd3695b 2230 case ShowLayer1:
WiredHome 96:40b74dd3695b 2231 SelectDrawingLayer(1);
WiredHome 96:40b74dd3695b 2232 break;
WiredHome 96:40b74dd3695b 2233 default:
WiredHome 96:40b74dd3695b 2234 break;
WiredHome 96:40b74dd3695b 2235 }
WiredHome 96:40b74dd3695b 2236
WiredHome 96:40b74dd3695b 2237 // Read the display from the last line toward the top
WiredHome 96:40b74dd3695b 2238 // so we can write the file in one pass.
WiredHome 96:40b74dd3695b 2239 for (int j = h - 1; j >= 0; j--) {
WiredHome 149:c62c4b2d6a15 2240 if (idle_callback) {
WiredHome 149:c62c4b2d6a15 2241 (*idle_callback)(progress, (h - 1 - j) * 100 / (h - 1));
WiredHome 149:c62c4b2d6a15 2242 }
WiredHome 149:c62c4b2d6a15 2243
WiredHome 96:40b74dd3695b 2244 if (ltpr0 >= 2) // Need to combine the layers...
WiredHome 96:40b74dd3695b 2245 SelectDrawingLayer(0); // so read layer 0 first
WiredHome 96:40b74dd3695b 2246 // Read one line of pixels to a local buffer
WiredHome 96:40b74dd3695b 2247 if (getPixelStream(pixelBuffer, w, x,y+j) != noerror) {
WiredHome 96:40b74dd3695b 2248 ERR("getPixelStream error, and no recovery handler...");
WiredHome 96:40b74dd3695b 2249 }
WiredHome 96:40b74dd3695b 2250 if (ltpr0 >= 2) { // Need to combine the layers...
WiredHome 96:40b74dd3695b 2251 SelectDrawingLayer(1); // so read layer 1 next
WiredHome 96:40b74dd3695b 2252 if (getPixelStream(pixelBuffer2, w, x,y+j) != noerror) {
WiredHome 96:40b74dd3695b 2253 ERR("getPixelStream error, and no recovery handler...");
WiredHome 96:40b74dd3695b 2254 }
WiredHome 96:40b74dd3695b 2255 }
WiredHome 96:40b74dd3695b 2256 INFO("1st Color: %04X", pixelBuffer[0]);
WiredHome 162:a2d7f1988711 2257 HexDump("Raster", (uint8_t *)pixelBuffer, w * 3);
WiredHome 96:40b74dd3695b 2258 // Convert the local buffer to RGBQUAD format
WiredHome 96:40b74dd3695b 2259 int lb = 0;
WiredHome 96:40b74dd3695b 2260 for (int i=0; i<w; i++) {
WiredHome 162:a2d7f1988711 2261 color_t tColor = pixelBuffer[x+i];
WiredHome 162:a2d7f1988711 2262 tColor = (tColor >> 8) | (tColor << 8); // Byte Swap
WiredHome 162:a2d7f1988711 2263 RGBQUAD q0 = RGB16ToRGBQuad(tColor); // Scale to 24-bits
WiredHome 162:a2d7f1988711 2264 tColor = pixelBuffer2[x+i];
WiredHome 162:a2d7f1988711 2265 tColor = (tColor >> 8) | (tColor << 8); // Byte Swap
WiredHome 162:a2d7f1988711 2266 RGBQUAD q1 = RGB16ToRGBQuad(tColor); // Scale to 24-bits
WiredHome 96:40b74dd3695b 2267 switch (ltpr0) {
WiredHome 96:40b74dd3695b 2268 case 0:
WiredHome 96:40b74dd3695b 2269 case 1:
WiredHome 96:40b74dd3695b 2270 case 2: // lighten-overlay (@TODO Not supported yet)
WiredHome 96:40b74dd3695b 2271 case 6: // Floating Windows (@TODO not sure how to support)
WiredHome 96:40b74dd3695b 2272 default: // Reserved...
WiredHome 96:40b74dd3695b 2273 lineBuffer[lb++] = q0.rgbBlue;
WiredHome 96:40b74dd3695b 2274 lineBuffer[lb++] = q0.rgbGreen;
WiredHome 96:40b74dd3695b 2275 lineBuffer[lb++] = q0.rgbRed;
WiredHome 96:40b74dd3695b 2276 break;
WiredHome 96:40b74dd3695b 2277 case 3: // transparent mode (@TODO Read the background color register for transparent)
WiredHome 96:40b74dd3695b 2278 case 4: // boolean or
WiredHome 96:40b74dd3695b 2279 lineBuffer[lb++] = q0.rgbBlue | q1.rgbBlue;
WiredHome 96:40b74dd3695b 2280 lineBuffer[lb++] = q0.rgbGreen | q1.rgbGreen;
WiredHome 96:40b74dd3695b 2281 lineBuffer[lb++] = q0.rgbRed | q1.rgbRed;
WiredHome 96:40b74dd3695b 2282 break;
WiredHome 96:40b74dd3695b 2283 case 5: // boolean AND
WiredHome 96:40b74dd3695b 2284 lineBuffer[lb++] = q0.rgbBlue & q1.rgbBlue;
WiredHome 96:40b74dd3695b 2285 lineBuffer[lb++] = q0.rgbGreen & q1.rgbGreen;
WiredHome 96:40b74dd3695b 2286 lineBuffer[lb++] = q0.rgbRed & q1.rgbRed;
WiredHome 96:40b74dd3695b 2287 break;
WiredHome 96:40b74dd3695b 2288 }
WiredHome 96:40b74dd3695b 2289 }
WiredHome 96:40b74dd3695b 2290 if (j == h - 1) {
WiredHome 162:a2d7f1988711 2291 HexDump("LineBuffer", lineBuffer, lineBufSize);
WiredHome 96:40b74dd3695b 2292 }
WiredHome 96:40b74dd3695b 2293 // Write to disk
WiredHome 162:a2d7f1988711 2294 privateCallback(WRITE, (uint8_t *)lineBuffer, lineBufSize);
WiredHome 96:40b74dd3695b 2295 }
WiredHome 96:40b74dd3695b 2296 SelectDrawingLayer(prevLayer);
WiredHome 96:40b74dd3695b 2297 privateCallback(CLOSE, NULL, 0);
WiredHome 96:40b74dd3695b 2298
WiredHome 96:40b74dd3695b 2299 #ifndef DOUBLEBUF
WiredHome 96:40b74dd3695b 2300 if (pixelBuffer2)
WiredHome 145:5eb2492acdda 2301 swFree(pixelBuffer2);
WiredHome 96:40b74dd3695b 2302 #endif
WiredHome 96:40b74dd3695b 2303 if (pixelBuffer)
WiredHome 145:5eb2492acdda 2304 swFree(pixelBuffer);
WiredHome 145:5eb2492acdda 2305 swFree(lineBuffer);
WiredHome 96:40b74dd3695b 2306 INFO("Image closed");
WiredHome 96:40b74dd3695b 2307 return noerror;
WiredHome 96:40b74dd3695b 2308 } else {
WiredHome 96:40b74dd3695b 2309 return bad_parameter;
WiredHome 96:40b74dd3695b 2310 }
WiredHome 96:40b74dd3695b 2311 }
WiredHome 79:544eb4964795 2312
WiredHome 163:17526689a3ed 2313
WiredHome 163:17526689a3ed 2314 RetCode_t RA8875::PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP, uint8_t bitsPerPixel)
WiredHome 72:ecffe56af969 2315 {
WiredHome 72:ecffe56af969 2316 BITMAPFILEHEADER BMP_Header;
WiredHome 72:ecffe56af969 2317 BITMAPINFOHEADER BMP_Info;
WiredHome 86:e86b355940f4 2318 uint8_t * lineBuffer = NULL;
WiredHome 86:e86b355940f4 2319 color_t * pixelBuffer = NULL;
WiredHome 86:e86b355940f4 2320 color_t * pixelBuffer2 = NULL;
WiredHome 86:e86b355940f4 2321
WiredHome 163:17526689a3ed 2322 INFO("(%d,%d)-(%d,%d)x%d %s", x,y,w,h,bitsPerPixel,Name_BMP);
WiredHome 105:4f116006ba1f 2323 if (x >= 0 && x < screenwidth
WiredHome 105:4f116006ba1f 2324 && y >= 0 && y < screenheight
WiredHome 105:4f116006ba1f 2325 && w > 0 && x + w <= screenwidth
WiredHome 105:4f116006ba1f 2326 && h > 0 && y + h <= screenheight) {
WiredHome 72:ecffe56af969 2327 BMP_Header.bfType = BF_TYPE;
WiredHome 72:ecffe56af969 2328 BMP_Header.bfReserved1 = 0;
WiredHome 72:ecffe56af969 2329 BMP_Header.bfReserved2 = 0;
WiredHome 163:17526689a3ed 2330 switch (bitsPerPixel) {
WiredHome 163:17526689a3ed 2331 case 24:
WiredHome 163:17526689a3ed 2332 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Info);
WiredHome 163:17526689a3ed 2333 BMP_Header.bfSize = (h * RoundUp(w * sizeof(RGBQUAD),4)) + BMP_Header.bfOffBits;
WiredHome 163:17526689a3ed 2334 break;
WiredHome 163:17526689a3ed 2335 case 8:
WiredHome 163:17526689a3ed 2336 default:
WiredHome 163:17526689a3ed 2337 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Info) + sizeof(WebColorPalette);
WiredHome 163:17526689a3ed 2338 INFO("Initial Offset to Bitstream %X", BMP_Header.bfOffBits);
WiredHome 163:17526689a3ed 2339 //if (BMP_Header.bfOffBits & 0x03) {
WiredHome 163:17526689a3ed 2340 // BMP_Header.bfOffBits += (4 - (BMP_Header.bfOffBits & 0x03));
WiredHome 163:17526689a3ed 2341 //}
WiredHome 163:17526689a3ed 2342 BMP_Header.bfSize = (h * RoundUp(w * 1,4)) + BMP_Header.bfOffBits;
WiredHome 163:17526689a3ed 2343 break;
WiredHome 163:17526689a3ed 2344 }
WiredHome 163:17526689a3ed 2345 INFO("Offset to Bitstream %X", BMP_Header.bfOffBits);
WiredHome 162:a2d7f1988711 2346
WiredHome 162:a2d7f1988711 2347 // Bytes in the line buffer
WiredHome 163:17526689a3ed 2348 int lineBufSize = RoundUp(((bitsPerPixel == 24) ? 3 : 1) * w, 4);
WiredHome 162:a2d7f1988711 2349 INFO("LineBufSize: %d", lineBufSize);
WiredHome 73:f22a18707b5e 2350
WiredHome 72:ecffe56af969 2351 BMP_Info.biSize = sizeof(BMP_Info);
WiredHome 72:ecffe56af969 2352 BMP_Info.biWidth = w;
WiredHome 72:ecffe56af969 2353 BMP_Info.biHeight = h;
WiredHome 72:ecffe56af969 2354 BMP_Info.biPlanes = 1;
WiredHome 163:17526689a3ed 2355 BMP_Info.biBitCount = bitsPerPixel;
WiredHome 72:ecffe56af969 2356 BMP_Info.biCompression = BI_RGB;
WiredHome 162:a2d7f1988711 2357 BMP_Info.biSizeImage = lineBufSize * h;
WiredHome 72:ecffe56af969 2358 BMP_Info.biXPelsPerMeter = 0;
WiredHome 72:ecffe56af969 2359 BMP_Info.biYPelsPerMeter = 0;
WiredHome 163:17526689a3ed 2360 // for 24-bit, there is no palette, so these are zero
WiredHome 163:17526689a3ed 2361 // for 8-bit, there can be up to 256 RGB values in the palette
WiredHome 163:17526689a3ed 2362
WiredHome 163:17526689a3ed 2363 BMP_Info.biClrUsed = (bitsPerPixel == 24) ? 0 : sizeof(WebColorPalette)/sizeof(WebColorPalette[0]); // for 8b/pixel
WiredHome 163:17526689a3ed 2364 BMP_Info.biClrImportant = BMP_Info.biClrUsed;
WiredHome 72:ecffe56af969 2365
WiredHome 86:e86b355940f4 2366 // Allocate the memory we need to proceed
WiredHome 145:5eb2492acdda 2367 lineBuffer = (uint8_t *)swMalloc(lineBufSize);
WiredHome 86:e86b355940f4 2368 if (lineBuffer == NULL) {
WiredHome 86:e86b355940f4 2369 ERR("Not enough RAM for PrintScreen lineBuffer");
WiredHome 86:e86b355940f4 2370 return(not_enough_ram);
WiredHome 86:e86b355940f4 2371 }
WiredHome 162:a2d7f1988711 2372 memset(lineBuffer, 0, lineBufSize); // zero-Fill
WiredHome 86:e86b355940f4 2373
WiredHome 86:e86b355940f4 2374 #define DOUBLEBUF /* one larger buffer instead of two */
WiredHome 86:e86b355940f4 2375
WiredHome 86:e86b355940f4 2376 #ifdef DOUBLEBUF
WiredHome 86:e86b355940f4 2377 // In the "#else", pixelBuffer2 malloc returns a value,
WiredHome 86:e86b355940f4 2378 // but is actually causing a failure later.
WiredHome 86:e86b355940f4 2379 // This test helps determine if it is truly out of memory,
WiredHome 86:e86b355940f4 2380 // or if malloc is broken.
WiredHome 145:5eb2492acdda 2381 pixelBuffer = (color_t *)swMalloc(2 * w * sizeof(color_t));
WiredHome 86:e86b355940f4 2382 pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
WiredHome 86:e86b355940f4 2383 #else
WiredHome 145:5eb2492acdda 2384 pixelBuffer = (color_t *)swMalloc(w * sizeof(color_t));
WiredHome 145:5eb2492acdda 2385 pixelBuffer2 = (color_t *)swMalloc(w * sizeof(color_t));
WiredHome 86:e86b355940f4 2386 #endif
WiredHome 86:e86b355940f4 2387 if (pixelBuffer == NULL || pixelBuffer2 == NULL) {
WiredHome 86:e86b355940f4 2388 ERR("Not enough RAM for pixelBuffer");
WiredHome 86:e86b355940f4 2389 #ifndef DOUBLEBUF
WiredHome 86:e86b355940f4 2390 if (pixelBuffer2)
WiredHome 145:5eb2492acdda 2391 swFree(pixelBuffer2);
WiredHome 86:e86b355940f4 2392 #endif
WiredHome 86:e86b355940f4 2393 if (pixelBuffer)
WiredHome 145:5eb2492acdda 2394 swFree(pixelBuffer);
WiredHome 145:5eb2492acdda 2395 swFree(lineBuffer);
WiredHome 86:e86b355940f4 2396 return(not_enough_ram);
WiredHome 86:e86b355940f4 2397 }
WiredHome 86:e86b355940f4 2398
WiredHome 72:ecffe56af969 2399 FILE *Image = fopen(Name_BMP, "wb");
WiredHome 72:ecffe56af969 2400 if (!Image) {
WiredHome 86:e86b355940f4 2401 ERR("Can't open file for write");
WiredHome 86:e86b355940f4 2402 #ifndef DOUBLEBUF
WiredHome 86:e86b355940f4 2403 if (pixelBuffer2)
WiredHome 145:5eb2492acdda 2404 swFree(pixelBuffer2);
WiredHome 86:e86b355940f4 2405 #endif
WiredHome 86:e86b355940f4 2406 if (pixelBuffer)
WiredHome 145:5eb2492acdda 2407 swFree(pixelBuffer);
WiredHome 145:5eb2492acdda 2408 swFree(lineBuffer);
WiredHome 72:ecffe56af969 2409 return(file_not_found);
WiredHome 72:ecffe56af969 2410 }
WiredHome 72:ecffe56af969 2411
WiredHome 72:ecffe56af969 2412 // Be optimistic - don't check for errors.
WiredHome 93:6fbc516de05e 2413 HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 95:ef538bd687c0 2414 fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image);
WiredHome 73:f22a18707b5e 2415
WiredHome 93:6fbc516de05e 2416 HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 95:ef538bd687c0 2417 fwrite(&BMP_Info, sizeof(char), sizeof(BMP_Info), Image);
WiredHome 163:17526689a3ed 2418
WiredHome 163:17526689a3ed 2419 if (bitsPerPixel != 24) {
WiredHome 163:17526689a3ed 2420 HexDump("Palette", (uint8_t *)&WebColorPalette, sizeof(WebColorPalette));
WiredHome 163:17526689a3ed 2421 fwrite(&WebColorPalette, sizeof(char), sizeof(WebColorPalette), Image);
WiredHome 163:17526689a3ed 2422 if (0 && sizeof(WebColorPalette) % 4) {
WiredHome 163:17526689a3ed 2423 const uint8_t padd[] = { 0, 0, 0 };
WiredHome 163:17526689a3ed 2424 fwrite(&padd, sizeof(char),
WiredHome 163:17526689a3ed 2425 (sizeof(BMP_Header) + sizeof(BMP_Info) + sizeof(WebColorPalette)) % 4, Image);
WiredHome 163:17526689a3ed 2426 }
WiredHome 163:17526689a3ed 2427 }
WiredHome 95:ef538bd687c0 2428 //color_t transparency = GetBackgroundTransparencyColor();
WiredHome 95:ef538bd687c0 2429 LayerMode_T ltpr0 = GetLayerMode();
WiredHome 73:f22a18707b5e 2430
WiredHome 73:f22a18707b5e 2431 uint16_t prevLayer = GetDrawingLayer();
WiredHome 73:f22a18707b5e 2432 // If only one of the layers is visible, select that layer
WiredHome 73:f22a18707b5e 2433 switch(ltpr0) {
WiredHome 95:ef538bd687c0 2434 case ShowLayer0:
WiredHome 73:f22a18707b5e 2435 SelectDrawingLayer(0);
WiredHome 73:f22a18707b5e 2436 break;
WiredHome 95:ef538bd687c0 2437 case ShowLayer1:
WiredHome 73:f22a18707b5e 2438 SelectDrawingLayer(1);
WiredHome 73:f22a18707b5e 2439 break;
WiredHome 73:f22a18707b5e 2440 default:
WiredHome 73:f22a18707b5e 2441 break;
WiredHome 73:f22a18707b5e 2442 }
WiredHome 73:f22a18707b5e 2443
WiredHome 72:ecffe56af969 2444 // Read the display from the last line toward the top
WiredHome 72:ecffe56af969 2445 // so we can write the file in one pass.
WiredHome 72:ecffe56af969 2446 for (int j = h - 1; j >= 0; j--) {
WiredHome 149:c62c4b2d6a15 2447 if (idle_callback) {
WiredHome 149:c62c4b2d6a15 2448 (*idle_callback)(progress, (h - 1 - j) * 100 / (h - 1));
WiredHome 149:c62c4b2d6a15 2449 }
WiredHome 149:c62c4b2d6a15 2450
WiredHome 73:f22a18707b5e 2451 if (ltpr0 >= 2) // Need to combine the layers...
WiredHome 73:f22a18707b5e 2452 SelectDrawingLayer(0); // so read layer 0 first
WiredHome 72:ecffe56af969 2453 // Read one line of pixels to a local buffer
WiredHome 72:ecffe56af969 2454 if (getPixelStream(pixelBuffer, w, x,y+j) != noerror) {
WiredHome 72:ecffe56af969 2455 ERR("getPixelStream error, and no recovery handler...");
WiredHome 72:ecffe56af969 2456 }
WiredHome 73:f22a18707b5e 2457 if (ltpr0 >= 2) { // Need to combine the layers...
WiredHome 86:e86b355940f4 2458 SelectDrawingLayer(1); // so read layer 1 next
WiredHome 73:f22a18707b5e 2459 if (getPixelStream(pixelBuffer2, w, x,y+j) != noerror) {
WiredHome 73:f22a18707b5e 2460 ERR("getPixelStream error, and no recovery handler...");
WiredHome 73:f22a18707b5e 2461 }
WiredHome 73:f22a18707b5e 2462 }
WiredHome 162:a2d7f1988711 2463 INFO("Line: %3d", j);
WiredHome 163:17526689a3ed 2464 //HexDump("Raster", (uint8_t *)pixelBuffer, w * sizeof(color_t));
WiredHome 72:ecffe56af969 2465 // Convert the local buffer to RGBQUAD format
WiredHome 72:ecffe56af969 2466 int lb = 0;
WiredHome 72:ecffe56af969 2467 for (int i=0; i<w; i++) {
WiredHome 162:a2d7f1988711 2468 color_t tColor = pixelBuffer[x+i];
WiredHome 162:a2d7f1988711 2469 tColor = (tColor >> 8) | (tColor << 8); // Byte Swap
WiredHome 162:a2d7f1988711 2470 RGBQUAD q0 = RGB16ToRGBQuad(tColor); // Scale to 24-bits
WiredHome 162:a2d7f1988711 2471 tColor = pixelBuffer2[x+i];
WiredHome 162:a2d7f1988711 2472 tColor = (tColor >> 8) | (tColor << 8); // Byte Swap
WiredHome 162:a2d7f1988711 2473 RGBQUAD q1 = RGB16ToRGBQuad(tColor); // Scale to 24-bits
WiredHome 73:f22a18707b5e 2474 switch (ltpr0) {
WiredHome 73:f22a18707b5e 2475 case 0:
WiredHome 73:f22a18707b5e 2476 case 1:
WiredHome 73:f22a18707b5e 2477 case 2: // lighten-overlay (@TODO Not supported yet)
WiredHome 73:f22a18707b5e 2478 case 6: // Floating Windows (@TODO not sure how to support)
WiredHome 73:f22a18707b5e 2479 default: // Reserved...
WiredHome 163:17526689a3ed 2480 //lineBuffer[lb++] = q0.rgbBlue;
WiredHome 163:17526689a3ed 2481 //lineBuffer[lb++] = q0.rgbGreen;
WiredHome 163:17526689a3ed 2482 //lineBuffer[lb++] = q0.rgbRed;
WiredHome 163:17526689a3ed 2483 break;
WiredHome 163:17526689a3ed 2484 case 3: // transparent mode (@TODO Read the background color register for transparent)
WiredHome 163:17526689a3ed 2485 case 4: // boolean or
WiredHome 163:17526689a3ed 2486 q0.rgbBlue = q0.rgbBlue | q1.rgbBlue;
WiredHome 163:17526689a3ed 2487 q0.rgbGreen = q0.rgbGreen | q1.rgbGreen;
WiredHome 163:17526689a3ed 2488 q0.rgbRed = q0.rgbRed | q1.rgbRed;
WiredHome 163:17526689a3ed 2489 break;
WiredHome 163:17526689a3ed 2490 case 5: // boolean AND
WiredHome 163:17526689a3ed 2491 q0.rgbBlue = q0.rgbBlue & q1.rgbBlue;
WiredHome 163:17526689a3ed 2492 q0.rgbGreen = q0.rgbGreen & q1.rgbGreen;
WiredHome 163:17526689a3ed 2493 q0.rgbRed = q0.rgbRed & q1.rgbRed;
WiredHome 163:17526689a3ed 2494 break;
WiredHome 163:17526689a3ed 2495 }
WiredHome 163:17526689a3ed 2496 switch (bitsPerPixel) {
WiredHome 163:17526689a3ed 2497 case 24:
WiredHome 73:f22a18707b5e 2498 lineBuffer[lb++] = q0.rgbBlue;
WiredHome 73:f22a18707b5e 2499 lineBuffer[lb++] = q0.rgbGreen;
WiredHome 73:f22a18707b5e 2500 lineBuffer[lb++] = q0.rgbRed;
WiredHome 73:f22a18707b5e 2501 break;
WiredHome 163:17526689a3ed 2502 case 8:
WiredHome 163:17526689a3ed 2503 default:
WiredHome 163:17526689a3ed 2504 lineBuffer[lb++] = FindNearestWebColor(q0.rgbRed,q0.rgbGreen,q0.rgbBlue);
WiredHome 73:f22a18707b5e 2505 break;
WiredHome 73:f22a18707b5e 2506 }
WiredHome 72:ecffe56af969 2507 }
WiredHome 162:a2d7f1988711 2508 //if (j == h - 1) {
WiredHome 163:17526689a3ed 2509 // HexDump("Line", lineBuffer, lineBufSize);
WiredHome 162:a2d7f1988711 2510 //}
WiredHome 72:ecffe56af969 2511 // Write to disk
WiredHome 162:a2d7f1988711 2512 fwrite(lineBuffer, sizeof(char), lineBufSize, Image);
WiredHome 72:ecffe56af969 2513 }
WiredHome 73:f22a18707b5e 2514 SelectDrawingLayer(prevLayer);
WiredHome 72:ecffe56af969 2515 fclose(Image);
WiredHome 86:e86b355940f4 2516 #ifndef DOUBLEBUF
WiredHome 86:e86b355940f4 2517 if (pixelBuffer2)
WiredHome 145:5eb2492acdda 2518 swFree(pixelBuffer2);
WiredHome 86:e86b355940f4 2519 #endif
WiredHome 86:e86b355940f4 2520 if (pixelBuffer)
WiredHome 145:5eb2492acdda 2521 swFree(pixelBuffer);
WiredHome 145:5eb2492acdda 2522 swFree(lineBuffer);
WiredHome 73:f22a18707b5e 2523 INFO("Image closed");
WiredHome 72:ecffe56af969 2524 return noerror;
WiredHome 72:ecffe56af969 2525 } else {
WiredHome 72:ecffe56af969 2526 return bad_parameter;
WiredHome 72:ecffe56af969 2527 }
WiredHome 72:ecffe56af969 2528 }
WiredHome 72:ecffe56af969 2529
WiredHome 72:ecffe56af969 2530
WiredHome 72:ecffe56af969 2531 // ##########################################################################
WiredHome 72:ecffe56af969 2532 // ##########################################################################
WiredHome 72:ecffe56af969 2533 // ##########################################################################
WiredHome 72:ecffe56af969 2534
WiredHome 23:a50ded45dbaf 2535 #ifdef TESTENABLE
WiredHome 23:a50ded45dbaf 2536
WiredHome 98:ecebed9b80b2 2537 #include "BPG_Arial08x08.h"
WiredHome 98:ecebed9b80b2 2538 #include "BPG_Arial20x20.h"
WiredHome 37:f19b7e7449dc 2539
WiredHome 23:a50ded45dbaf 2540 // ______________ ______________ ______________ _______________
WiredHome 23:a50ded45dbaf 2541 // /_____ _____/ / ___________/ / ___________/ /_____ ______/
WiredHome 23:a50ded45dbaf 2542 // / / / / / / / /
WiredHome 23:a50ded45dbaf 2543 // / / / /___ / /__________ / /
WiredHome 23:a50ded45dbaf 2544 // / / / ____/ /__________ / / /
WiredHome 23:a50ded45dbaf 2545 // / / / / / / / /
WiredHome 23:a50ded45dbaf 2546 // / / / /__________ ___________/ / / /
WiredHome 23:a50ded45dbaf 2547 // /__/ /_____________/ /_____________/ /__/
WiredHome 23:a50ded45dbaf 2548 //
WiredHome 23:a50ded45dbaf 2549 // Everything from here down is test code.
WiredHome 75:ca78388cfd77 2550 //
WiredHome 41:2956a0a221e5 2551 bool SuppressSlowStuff = false;
WiredHome 23:a50ded45dbaf 2552
WiredHome 49:c5182231d1b9 2553 void TextWrapTest(RA8875 & display, Serial & pc)
WiredHome 49:c5182231d1b9 2554 {
WiredHome 49:c5182231d1b9 2555 if (!SuppressSlowStuff)
WiredHome 49:c5182231d1b9 2556 pc.printf("Text Wrap Test\r\n");
WiredHome 49:c5182231d1b9 2557 display.background(Black);
WiredHome 49:c5182231d1b9 2558 display.foreground(Blue);
WiredHome 49:c5182231d1b9 2559 display.cls();
WiredHome 49:c5182231d1b9 2560 display.Backlight_u8(255);
WiredHome 100:0b084475d5a9 2561 display.puts("Text Wrap Test.\r\n");
WiredHome 52:e6039a823420 2562 for (int i=1; i<60; i++) {
WiredHome 52:e6039a823420 2563 display.printf("L%2d\n", i % 17);
WiredHome 49:c5182231d1b9 2564 if (!SuppressSlowStuff)
WiredHome 52:e6039a823420 2565 wait_ms(100);
WiredHome 49:c5182231d1b9 2566 }
WiredHome 49:c5182231d1b9 2567 if (!SuppressSlowStuff)
WiredHome 49:c5182231d1b9 2568 wait_ms(3000);
WiredHome 49:c5182231d1b9 2569 }
WiredHome 49:c5182231d1b9 2570
WiredHome 75:ca78388cfd77 2571
WiredHome 75:ca78388cfd77 2572 void ShowKey(RA8875 & display, int key)
WiredHome 75:ca78388cfd77 2573 {
WiredHome 75:ca78388cfd77 2574 loc_t col, row;
WiredHome 75:ca78388cfd77 2575 dim_t r1 = 25;
WiredHome 75:ca78388cfd77 2576 color_t color = (key & 0x80) ? Red : Green;
WiredHome 75:ca78388cfd77 2577
WiredHome 75:ca78388cfd77 2578 key &= 0x7F; // remove the long-press flag
WiredHome 75:ca78388cfd77 2579 row = (key - 1) / 5;
WiredHome 75:ca78388cfd77 2580 col = (key - 1) % 5;
WiredHome 75:ca78388cfd77 2581 if (col > 5) col = 5;
WiredHome 75:ca78388cfd77 2582 if (row > 4) row = 4;
WiredHome 75:ca78388cfd77 2583 display.circle(450 - + (2 * r1) * col, 200 - (2 * r1) * row, r1-2, color, FILL);
WiredHome 75:ca78388cfd77 2584 }
WiredHome 75:ca78388cfd77 2585
WiredHome 75:ca78388cfd77 2586 void HideKey(RA8875 & display, int key)
WiredHome 75:ca78388cfd77 2587 {
WiredHome 75:ca78388cfd77 2588 loc_t col, row;
WiredHome 75:ca78388cfd77 2589 dim_t r1 = 25;
WiredHome 75:ca78388cfd77 2590
WiredHome 75:ca78388cfd77 2591 row = (key - 1) / 5;
WiredHome 75:ca78388cfd77 2592 col = (key - 1) % 5;
WiredHome 75:ca78388cfd77 2593 if (col > 5) col = 5;
WiredHome 75:ca78388cfd77 2594 if (row > 4) row = 4;
WiredHome 75:ca78388cfd77 2595 display.background(Black);
WiredHome 75:ca78388cfd77 2596 display.circle(450 - (2 * r1) * col, 200 - (2 * r1) * row, r1-2, Black, FILL);
WiredHome 75:ca78388cfd77 2597 display.circle(450 - (2 * r1) * col, 200 - (2 * r1) * row, r1-2, Blue);
WiredHome 75:ca78388cfd77 2598 }
WiredHome 75:ca78388cfd77 2599
WiredHome 75:ca78388cfd77 2600 void KeyPadTest(RA8875 & display, Serial & pc)
WiredHome 75:ca78388cfd77 2601 {
WiredHome 75:ca78388cfd77 2602 const uint8_t myMap[22] = {
WiredHome 77:9206c13aa527 2603 0,
WiredHome 75:ca78388cfd77 2604 'a', 'b', 'c', 'd', 'e',
WiredHome 75:ca78388cfd77 2605 'f', 'g', 'h', 'i', 'j',
WiredHome 75:ca78388cfd77 2606 'k', 'l', 'm', 'n', 'o',
WiredHome 75:ca78388cfd77 2607 'p', 'q', 'r', 's', 't',
WiredHome 75:ca78388cfd77 2608 'x'
WiredHome 75:ca78388cfd77 2609 };
WiredHome 77:9206c13aa527 2610
WiredHome 75:ca78388cfd77 2611 display.background(Black);
WiredHome 75:ca78388cfd77 2612 display.foreground(Blue);
WiredHome 75:ca78388cfd77 2613 display.cls();
WiredHome 75:ca78388cfd77 2614 display.Backlight_u8(255);
WiredHome 100:0b084475d5a9 2615 display.puts("KeyPad Test. Touch the keypad...");
WiredHome 75:ca78388cfd77 2616 pc.printf("\r\n"
WiredHome 75:ca78388cfd77 2617 "Raw KeyPad Test. Keypad returns the key-number.\r\n"
WiredHome 75:ca78388cfd77 2618 "Press [most] any PC keyboard key to advance to next test.\r\n");
WiredHome 75:ca78388cfd77 2619 RetCode_t ret = display.KeypadInit(true, true, 3, 7, 3);
WiredHome 75:ca78388cfd77 2620 if (ret != noerror)
WiredHome 75:ca78388cfd77 2621 pc.printf("returncode from KeypadInit is %d\r\n", ret);
WiredHome 75:ca78388cfd77 2622 int lastKey = 0;
WiredHome 75:ca78388cfd77 2623 while (!pc.readable()) {
WiredHome 75:ca78388cfd77 2624 if (display.readable()) {
WiredHome 75:ca78388cfd77 2625 int key = display.getc();
WiredHome 75:ca78388cfd77 2626 if (key) {
WiredHome 75:ca78388cfd77 2627 if (((key & 0x7F) != lastKey) && (lastKey != 0))
WiredHome 75:ca78388cfd77 2628 HideKey(display, lastKey);
WiredHome 75:ca78388cfd77 2629 ShowKey(display, key);
WiredHome 75:ca78388cfd77 2630 lastKey = key & 0x7F;
WiredHome 75:ca78388cfd77 2631 } else {
WiredHome 75:ca78388cfd77 2632 // erase the last one
WiredHome 75:ca78388cfd77 2633 if (lastKey)
WiredHome 75:ca78388cfd77 2634 HideKey(display, lastKey);
WiredHome 75:ca78388cfd77 2635 }
WiredHome 75:ca78388cfd77 2636 }
WiredHome 75:ca78388cfd77 2637 }
WiredHome 75:ca78388cfd77 2638 (void)pc.getc();
WiredHome 75:ca78388cfd77 2639 pc.printf("\r\n"
WiredHome 75:ca78388cfd77 2640 "Map KeyPad Test. Keypad returns the remapped key 'a' - 't'.\r\n"
WiredHome 75:ca78388cfd77 2641 "Press [most] any PC keyboard key to advance to exit test.\r\n");
WiredHome 75:ca78388cfd77 2642 display.SetKeyMap(myMap);
WiredHome 75:ca78388cfd77 2643 while (!pc.readable()) {
WiredHome 75:ca78388cfd77 2644 if (display.readable()) {
WiredHome 75:ca78388cfd77 2645 int key = display.getc();
WiredHome 75:ca78388cfd77 2646 bool longPress = key & 0x80;
WiredHome 75:ca78388cfd77 2647 display.SetTextCursor(0, 120);
WiredHome 75:ca78388cfd77 2648 display.printf("Long Press: %d\r\n", longPress);
WiredHome 75:ca78388cfd77 2649 display.printf(" Remapped: %c %02X\r\n", (key) ? key & 0x7F : ' ', key);
WiredHome 75:ca78388cfd77 2650 }
WiredHome 75:ca78388cfd77 2651 }
WiredHome 75:ca78388cfd77 2652 (void)pc.getc();
WiredHome 75:ca78388cfd77 2653 display.SetKeyMap();
WiredHome 75:ca78388cfd77 2654 pc.printf("\r\n");
WiredHome 75:ca78388cfd77 2655 }
WiredHome 75:ca78388cfd77 2656
WiredHome 23:a50ded45dbaf 2657 void TextCursorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2658 {
WiredHome 75:ca78388cfd77 2659 const char * iCursor = "The I-Beam cursor should be visible for this text.\r\n";
WiredHome 75:ca78388cfd77 2660 const char * uCursor = "The Underscore cursor should be visible for this text.\r\n";
WiredHome 75:ca78388cfd77 2661 const char * bCursor = "The Block cursor should be visible for this text.\r\n";
WiredHome 37:f19b7e7449dc 2662 const char * bbCursor = "The Blinking Block cursor should be visible for this text.\r\n";
WiredHome 23:a50ded45dbaf 2663 const char * p;
WiredHome 100:0b084475d5a9 2664 int delay = 60;
WiredHome 73:f22a18707b5e 2665
WiredHome 41:2956a0a221e5 2666 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2667 pc.printf("Text Cursor Test\r\n");
WiredHome 73:f22a18707b5e 2668 else
WiredHome 41:2956a0a221e5 2669 delay = 0;
WiredHome 23:a50ded45dbaf 2670 display.background(Black);
WiredHome 23:a50ded45dbaf 2671 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2672 display.cls();
WiredHome 25:9556a3a9b7cc 2673 display.Backlight_u8(255);
WiredHome 100:0b084475d5a9 2674 display.puts("Text Cursor Test.");
WiredHome 73:f22a18707b5e 2675
WiredHome 23:a50ded45dbaf 2676 // visible, non-blinking
WiredHome 24:8ca861acf12d 2677 display.SetTextCursor(0,20);
WiredHome 53:86d24b9480b9 2678 display.SetTextCursorControl(RA8875::IBEAM, false);
WiredHome 24:8ca861acf12d 2679 p = iCursor;
WiredHome 23:a50ded45dbaf 2680 while (*p) {
WiredHome 24:8ca861acf12d 2681 display._putc(*p++);
WiredHome 41:2956a0a221e5 2682 wait_ms(delay);
WiredHome 24:8ca861acf12d 2683 }
WiredHome 24:8ca861acf12d 2684
WiredHome 53:86d24b9480b9 2685 display.SetTextCursorControl(RA8875::UNDER, false);
WiredHome 24:8ca861acf12d 2686 p = uCursor;
WiredHome 24:8ca861acf12d 2687 while (*p) {
WiredHome 24:8ca861acf12d 2688 display._putc(*p++);
WiredHome 41:2956a0a221e5 2689 wait_ms(delay);
WiredHome 23:a50ded45dbaf 2690 }
WiredHome 73:f22a18707b5e 2691
WiredHome 53:86d24b9480b9 2692 display.SetTextCursorControl(RA8875::BLOCK, false);
WiredHome 24:8ca861acf12d 2693 p = bCursor;
WiredHome 24:8ca861acf12d 2694 while (*p) {
WiredHome 24:8ca861acf12d 2695 display._putc(*p++);
WiredHome 41:2956a0a221e5 2696 wait_ms(delay);
WiredHome 24:8ca861acf12d 2697 }
WiredHome 24:8ca861acf12d 2698
WiredHome 53:86d24b9480b9 2699 display.SetTextCursorControl(RA8875::BLOCK, true);
WiredHome 24:8ca861acf12d 2700 p = bbCursor;
WiredHome 24:8ca861acf12d 2701 while (*p) {
WiredHome 24:8ca861acf12d 2702 display._putc(*p++);
WiredHome 41:2956a0a221e5 2703 wait_ms(delay);
WiredHome 24:8ca861acf12d 2704 }
WiredHome 41:2956a0a221e5 2705 wait_ms(delay * 20);
WiredHome 53:86d24b9480b9 2706 display.SetTextCursorControl(RA8875::NOCURSOR, false);
WiredHome 23:a50ded45dbaf 2707 }
WiredHome 23:a50ded45dbaf 2708
WiredHome 44:207594dece70 2709
WiredHome 23:a50ded45dbaf 2710 void BacklightTest(RA8875 & display, Serial & pc, float ramptime)
WiredHome 23:a50ded45dbaf 2711 {
WiredHome 29:422616aa04bd 2712 char buf[60];
WiredHome 41:2956a0a221e5 2713 unsigned int w = (ramptime * 1000)/ 256;
WiredHome 41:2956a0a221e5 2714 int delay = 200;
WiredHome 41:2956a0a221e5 2715
WiredHome 41:2956a0a221e5 2716 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2717 pc.printf("Backlight Test - ramp over %f sec.\r\n", ramptime);
WiredHome 41:2956a0a221e5 2718 else {
WiredHome 41:2956a0a221e5 2719 delay = 0;
WiredHome 41:2956a0a221e5 2720 w = 0;
WiredHome 41:2956a0a221e5 2721 }
WiredHome 23:a50ded45dbaf 2722 display.Backlight_u8(0);
WiredHome 29:422616aa04bd 2723 display.background(White);
WiredHome 23:a50ded45dbaf 2724 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2725 display.cls();
WiredHome 100:0b084475d5a9 2726 display.puts("RA8875 Backlight Test - Ramp up.");
WiredHome 41:2956a0a221e5 2727 wait_ms(delay);
WiredHome 38:38d503b4fad6 2728 for (int i=0; i <= 255; i++) {
WiredHome 141:2ec78a50dc98 2729 snprintf(buf, sizeof(buf), "%3d, %4d", i, w);
WiredHome 37:f19b7e7449dc 2730 display.puts(100,100,buf);
WiredHome 23:a50ded45dbaf 2731 display.Backlight_u8(i);
WiredHome 29:422616aa04bd 2732 wait_ms(w);
WiredHome 23:a50ded45dbaf 2733 }
WiredHome 23:a50ded45dbaf 2734 }
WiredHome 23:a50ded45dbaf 2735
WiredHome 44:207594dece70 2736
WiredHome 23:a50ded45dbaf 2737 void BacklightTest2(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2738 {
WiredHome 41:2956a0a221e5 2739 int delay = 20;
WiredHome 41:2956a0a221e5 2740
WiredHome 41:2956a0a221e5 2741 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2742 pc.printf("Backlight Test 2\r\n");
WiredHome 41:2956a0a221e5 2743 else
WiredHome 41:2956a0a221e5 2744 delay = 0;
WiredHome 41:2956a0a221e5 2745
WiredHome 23:a50ded45dbaf 2746 // Dim it out at the end of the tests.
WiredHome 37:f19b7e7449dc 2747 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2748 display.puts(0,0, "Ramp Backlight down.");
WiredHome 23:a50ded45dbaf 2749 // Ramp it off
WiredHome 23:a50ded45dbaf 2750 for (int i=255; i != 0; i--) {
WiredHome 23:a50ded45dbaf 2751 display.Backlight_u8(i);
WiredHome 41:2956a0a221e5 2752 wait_ms(delay);
WiredHome 23:a50ded45dbaf 2753 }
WiredHome 23:a50ded45dbaf 2754 display.Backlight_u8(0);
WiredHome 23:a50ded45dbaf 2755 }
WiredHome 23:a50ded45dbaf 2756
WiredHome 44:207594dece70 2757
WiredHome 23:a50ded45dbaf 2758 void ExternalFontTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2759 {
WiredHome 41:2956a0a221e5 2760 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2761 pc.printf("External Font Test\r\n");
WiredHome 23:a50ded45dbaf 2762 display.background(Black);
WiredHome 23:a50ded45dbaf 2763 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2764 display.cls();
WiredHome 100:0b084475d5a9 2765 display.puts("External Font Test.");
WiredHome 23:a50ded45dbaf 2766 display.Backlight(1);
WiredHome 37:f19b7e7449dc 2767
WiredHome 98:ecebed9b80b2 2768 display.SelectUserFont(BPG_Arial08x08);
WiredHome 73:f22a18707b5e 2769 display.puts(0,30, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 37:f19b7e7449dc 2770
WiredHome 98:ecebed9b80b2 2771 display.SelectUserFont(BPG_Arial20x20);
WiredHome 37:f19b7e7449dc 2772 display.puts("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 98:ecebed9b80b2 2773
WiredHome 98:ecebed9b80b2 2774 display.SelectUserFont();
WiredHome 73:f22a18707b5e 2775
WiredHome 37:f19b7e7449dc 2776 display.puts("Normal font again.");
WiredHome 37:f19b7e7449dc 2777 //display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 2778 }
WiredHome 23:a50ded45dbaf 2779
WiredHome 44:207594dece70 2780
WiredHome 23:a50ded45dbaf 2781 void DOSColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2782 {
WiredHome 41:2956a0a221e5 2783 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2784 pc.printf("DOS Color Test\r\n");
WiredHome 23:a50ded45dbaf 2785 display.background(Black);
WiredHome 23:a50ded45dbaf 2786 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2787 display.cls();
WiredHome 100:0b084475d5a9 2788 display.puts("DOS Colors - Fore");
WiredHome 23:a50ded45dbaf 2789 display.puts(280,0, "Back");
WiredHome 23:a50ded45dbaf 2790 display.background(Gray);
WiredHome 23:a50ded45dbaf 2791 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2792 display.foreground(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2793 display.puts(160, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 2794 display.background(Black);
WiredHome 23:a50ded45dbaf 2795 }
WiredHome 23:a50ded45dbaf 2796 display.foreground(White);
WiredHome 23:a50ded45dbaf 2797 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2798 display.background(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2799 display.puts(360, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 2800 display.foreground(White);
WiredHome 23:a50ded45dbaf 2801 }
WiredHome 23:a50ded45dbaf 2802 }
WiredHome 23:a50ded45dbaf 2803
WiredHome 44:207594dece70 2804
WiredHome 23:a50ded45dbaf 2805 void WebColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2806 {
WiredHome 41:2956a0a221e5 2807 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2808 pc.printf("Web Color Test\r\n");
WiredHome 23:a50ded45dbaf 2809 display.background(Black);
WiredHome 23:a50ded45dbaf 2810 display.foreground(Blue);
WiredHome 32:0e4f2ae512e2 2811 display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 2812 display.cls();
WiredHome 59:fb40aad4efd4 2813 display.SetTextFontSize(1,1);
WiredHome 59:fb40aad4efd4 2814 display.puts(200,0, "Web Color Test");
WiredHome 59:fb40aad4efd4 2815 display.SetTextCursor(0,0);
WiredHome 59:fb40aad4efd4 2816 display.puts(" ");
WiredHome 59:fb40aad4efd4 2817 for (int i=0; i<16; i++)
WiredHome 59:fb40aad4efd4 2818 display.printf("%X", i&0xF);
WiredHome 59:fb40aad4efd4 2819 display.puts("\r\n0 ");
WiredHome 23:a50ded45dbaf 2820 for (int i=0; i<sizeof(WebColors)/sizeof(WebColors[0]); i++) {
WiredHome 23:a50ded45dbaf 2821 display.background(WebColors[i]);
WiredHome 23:a50ded45dbaf 2822 display.puts(" ");
WiredHome 59:fb40aad4efd4 2823 if (i % 16 == 15 && i < 255) {
WiredHome 59:fb40aad4efd4 2824 display.printf("\r\n%X ", ((i+1)/16));
WiredHome 59:fb40aad4efd4 2825 }
WiredHome 23:a50ded45dbaf 2826 }
WiredHome 23:a50ded45dbaf 2827 display.SetTextFontSize(1,1);
WiredHome 23:a50ded45dbaf 2828 }
WiredHome 23:a50ded45dbaf 2829
WiredHome 44:207594dece70 2830
WiredHome 37:f19b7e7449dc 2831 void PixelTest(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 2832 {
WiredHome 37:f19b7e7449dc 2833 int i, c, x, y;
WiredHome 37:f19b7e7449dc 2834
WiredHome 41:2956a0a221e5 2835 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2836 pc.printf("Pixel Test\r\n");
WiredHome 37:f19b7e7449dc 2837 display.background(Black);
WiredHome 37:f19b7e7449dc 2838 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 2839 display.cls();
WiredHome 100:0b084475d5a9 2840 display.puts("Pixel Test");
WiredHome 37:f19b7e7449dc 2841 for (i=0; i<1000; i++) {
WiredHome 37:f19b7e7449dc 2842 x = rand() % 480;
WiredHome 37:f19b7e7449dc 2843 y = 16 + rand() % (272-16);
WiredHome 37:f19b7e7449dc 2844 c = rand() % 16;
WiredHome 37:f19b7e7449dc 2845 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 37:f19b7e7449dc 2846 display.pixel(x,y, display.DOSColor(c));
WiredHome 37:f19b7e7449dc 2847 }
WiredHome 37:f19b7e7449dc 2848 }
WiredHome 37:f19b7e7449dc 2849
WiredHome 44:207594dece70 2850
WiredHome 23:a50ded45dbaf 2851 void LineTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2852 {
WiredHome 23:a50ded45dbaf 2853 int i, x, y, x2, y2;
WiredHome 23:a50ded45dbaf 2854
WiredHome 41:2956a0a221e5 2855 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2856 pc.printf("Line Test\r\n");
WiredHome 23:a50ded45dbaf 2857 display.background(Black);
WiredHome 23:a50ded45dbaf 2858 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2859 display.cls();
WiredHome 100:0b084475d5a9 2860 display.puts("Line Test");
WiredHome 23:a50ded45dbaf 2861 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2862 // Lines
WiredHome 23:a50ded45dbaf 2863 x = rand() % 480;
WiredHome 23:a50ded45dbaf 2864 y = rand() % 272;
WiredHome 23:a50ded45dbaf 2865 x2 = rand() % 480;
WiredHome 23:a50ded45dbaf 2866 y2 = rand() % 272;
WiredHome 23:a50ded45dbaf 2867 display.line(x,y, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2868 }
WiredHome 62:ba5d33438fda 2869 display.foreground(BrightRed);
WiredHome 62:ba5d33438fda 2870 display.foreground(BrightGreen);
WiredHome 62:ba5d33438fda 2871 display.foreground(BrightBlue);
WiredHome 62:ba5d33438fda 2872 display.line(55,50, 79,74, BrightRed);
WiredHome 62:ba5d33438fda 2873 display.line(57,50, 81,74, BrightGreen);
WiredHome 62:ba5d33438fda 2874 display.line(59,50, 83,74, BrightBlue);
WiredHome 62:ba5d33438fda 2875 // horz
WiredHome 62:ba5d33438fda 2876 display.line(30,40, 32,40, BrightRed);
WiredHome 62:ba5d33438fda 2877 display.line(30,42, 32,42, BrightGreen);
WiredHome 62:ba5d33438fda 2878 display.line(30,44, 32,44, BrightBlue);
WiredHome 62:ba5d33438fda 2879 // vert
WiredHome 62:ba5d33438fda 2880 display.line(20,40, 20,42, BrightRed);
WiredHome 62:ba5d33438fda 2881 display.line(22,40, 22,42, BrightGreen);
WiredHome 62:ba5d33438fda 2882 display.line(24,40, 24,42, BrightBlue);
WiredHome 62:ba5d33438fda 2883 // compare point to line-point
WiredHome 62:ba5d33438fda 2884 display.pixel(20,50, BrightRed);
WiredHome 62:ba5d33438fda 2885 display.pixel(22,50, BrightGreen);
WiredHome 62:ba5d33438fda 2886 display.pixel(24,50, BrightBlue);
WiredHome 62:ba5d33438fda 2887 display.line(20,52, 20,52, BrightRed);
WiredHome 62:ba5d33438fda 2888 display.line(22,52, 22,52, BrightGreen);
WiredHome 62:ba5d33438fda 2889 display.line(24,52, 24,52, BrightBlue);
WiredHome 73:f22a18707b5e 2890
WiredHome 62:ba5d33438fda 2891 // point
WiredHome 62:ba5d33438fda 2892 display.line(50,50, 50,50, Red);
WiredHome 62:ba5d33438fda 2893 display.line(52,52, 52,52, Green);
WiredHome 62:ba5d33438fda 2894 display.line(54,54, 54,54, Blue);
WiredHome 62:ba5d33438fda 2895 display.line(60,60, 60,60, BrightRed);
WiredHome 62:ba5d33438fda 2896 display.line(62,62, 62,62, BrightGreen);
WiredHome 62:ba5d33438fda 2897 display.line(64,64, 64,64, BrightBlue);
WiredHome 62:ba5d33438fda 2898 display.line(70,70, 70,70, DarkRed);
WiredHome 62:ba5d33438fda 2899 display.line(72,72, 72,72, DarkGreen);
WiredHome 62:ba5d33438fda 2900 display.line(74,74, 74,74, DarkBlue);
WiredHome 23:a50ded45dbaf 2901 }
WiredHome 23:a50ded45dbaf 2902
WiredHome 44:207594dece70 2903
WiredHome 23:a50ded45dbaf 2904 void RectangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2905 {
WiredHome 23:a50ded45dbaf 2906 int i, x1,y1, x2,y2;
WiredHome 23:a50ded45dbaf 2907
WiredHome 41:2956a0a221e5 2908 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2909 pc.printf("Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 2910 display.background(Black);
WiredHome 23:a50ded45dbaf 2911 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2912 display.cls();
WiredHome 100:0b084475d5a9 2913 display.puts("Rectangle Test");
WiredHome 23:a50ded45dbaf 2914 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2915 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 2916 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2917 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 2918 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2919 display.rect(x1,y1, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2920
WiredHome 23:a50ded45dbaf 2921 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2922 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2923 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2924 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2925 display.rect(x1,y1, x2,y2, FILL);
WiredHome 23:a50ded45dbaf 2926 }
WiredHome 23:a50ded45dbaf 2927 }
WiredHome 23:a50ded45dbaf 2928
WiredHome 44:207594dece70 2929
WiredHome 44:207594dece70 2930 void LayerTest(RA8875 & display, Serial & pc)
WiredHome 44:207594dece70 2931 {
WiredHome 44:207594dece70 2932 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 44:207594dece70 2933
WiredHome 44:207594dece70 2934 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2935 pc.printf("Layer Test\r\n");
WiredHome 44:207594dece70 2936
WiredHome 50:2c4f474a2453 2937 display.SelectDrawingLayer(0);
WiredHome 44:207594dece70 2938 display.background(Black);
WiredHome 44:207594dece70 2939 display.foreground(Blue);
WiredHome 44:207594dece70 2940 display.cls();
WiredHome 100:0b084475d5a9 2941 display.puts("Layer 0");
WiredHome 44:207594dece70 2942 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 2943 x1 = rand() % 240;
WiredHome 44:207594dece70 2944 y1 = 50 + rand() % 200;
WiredHome 44:207594dece70 2945 x2 = x1 + rand() % 100;
WiredHome 44:207594dece70 2946 y2 = y1 + rand() % 100;
WiredHome 44:207594dece70 2947 r1 = rand() % (x2 - x1)/2;
WiredHome 44:207594dece70 2948 r2 = rand() % (y2 - y1)/2;
WiredHome 44:207594dece70 2949 display.roundrect(x1,y1, x2,y2, r1,r2, display.DOSColor(i));
WiredHome 44:207594dece70 2950 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2951 wait_ms(20);
WiredHome 44:207594dece70 2952 }
WiredHome 44:207594dece70 2953 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2954 wait_ms(1000);
WiredHome 44:207594dece70 2955
WiredHome 50:2c4f474a2453 2956 display.SelectDrawingLayer(1);
WiredHome 44:207594dece70 2957 display.background(Black);
WiredHome 44:207594dece70 2958 display.foreground(Yellow);
WiredHome 44:207594dece70 2959 display.cls();
WiredHome 44:207594dece70 2960 display.puts(240,0, "Layer 1");
WiredHome 44:207594dece70 2961 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 2962 x1 = 300 + rand() % 100;
WiredHome 44:207594dece70 2963 y1 = 70 + rand() % 200;
WiredHome 44:207594dece70 2964 r1 = rand() % min(y1 - 20, 100);
WiredHome 44:207594dece70 2965 display.circle(x1,y1,r1, display.DOSColor(i));
WiredHome 44:207594dece70 2966 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2967 wait_ms(20);
WiredHome 44:207594dece70 2968 }
WiredHome 56:7a85d226ad0d 2969 display.SetLayerMode(RA8875::ShowLayer1); // Show it after the build-up
WiredHome 44:207594dece70 2970 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2971 wait_ms(2000);
WiredHome 44:207594dece70 2972
WiredHome 50:2c4f474a2453 2973 display.SelectDrawingLayer(0);
WiredHome 56:7a85d226ad0d 2974 display.SetLayerMode(RA8875::ShowLayer0); // Show Layer 0 again
WiredHome 44:207594dece70 2975 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2976 wait_ms(1000);
WiredHome 53:86d24b9480b9 2977 display.SetLayerMode(RA8875::TransparentMode); // Transparent mode
WiredHome 44:207594dece70 2978 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2979 wait_ms(1000);
WiredHome 44:207594dece70 2980 for (i=0; i<=8; i++) {
WiredHome 44:207594dece70 2981 display.SetLayerTransparency(i, 8-i);
WiredHome 44:207594dece70 2982 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2983 wait_ms(200);
WiredHome 44:207594dece70 2984 }
WiredHome 73:f22a18707b5e 2985
WiredHome 44:207594dece70 2986 // Restore before we exit
WiredHome 44:207594dece70 2987 display.SetLayerTransparency(0, 0);
WiredHome 56:7a85d226ad0d 2988 display.SetLayerMode(RA8875::ShowLayer0); // Restore to layer 0
WiredHome 44:207594dece70 2989 }
WiredHome 44:207594dece70 2990
WiredHome 44:207594dece70 2991
WiredHome 23:a50ded45dbaf 2992 void RoundRectTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2993 {
WiredHome 37:f19b7e7449dc 2994 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 23:a50ded45dbaf 2995
WiredHome 41:2956a0a221e5 2996 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2997 pc.printf("Round Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 2998 display.background(Black);
WiredHome 23:a50ded45dbaf 2999 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 3000 display.cls();
WiredHome 100:0b084475d5a9 3001 display.puts("Rounded Rectangle Test");
WiredHome 73:f22a18707b5e 3002
WiredHome 23:a50ded45dbaf 3003 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3004 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 3005 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3006 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 3007 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 3008 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 3009 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 3010 display.roundrect(x1,y1, x2,y2, 5,8, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3011
WiredHome 23:a50ded45dbaf 3012 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 3013 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3014 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 3015 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 3016 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 3017 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 3018 display.roundrect(x1,y1, x2,y2, r1,r2, FILL);
WiredHome 23:a50ded45dbaf 3019 }
WiredHome 23:a50ded45dbaf 3020 }
WiredHome 23:a50ded45dbaf 3021
WiredHome 44:207594dece70 3022
WiredHome 23:a50ded45dbaf 3023 void TriangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 3024 {
WiredHome 23:a50ded45dbaf 3025 int i, x1, y1, x2, y2, x3, y3;
WiredHome 23:a50ded45dbaf 3026
WiredHome 41:2956a0a221e5 3027 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3028 pc.printf("Triangle Test\r\n");
WiredHome 23:a50ded45dbaf 3029 display.background(Black);
WiredHome 23:a50ded45dbaf 3030 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 3031 display.cls();
WiredHome 23:a50ded45dbaf 3032 display.puts(0,0, "Triangle Test");
WiredHome 23:a50ded45dbaf 3033
WiredHome 23:a50ded45dbaf 3034 x1 = 150;
WiredHome 23:a50ded45dbaf 3035 y1 = 2;
WiredHome 23:a50ded45dbaf 3036 x2 = 190;
WiredHome 23:a50ded45dbaf 3037 y2 = 7;
WiredHome 23:a50ded45dbaf 3038 x3 = 170;
WiredHome 23:a50ded45dbaf 3039 y3 = 16;
WiredHome 23:a50ded45dbaf 3040 display.triangle(x1,y1, x2,y2, x3,y3);
WiredHome 23:a50ded45dbaf 3041
WiredHome 23:a50ded45dbaf 3042 x1 = 200;
WiredHome 23:a50ded45dbaf 3043 y1 = 2;
WiredHome 23:a50ded45dbaf 3044 x2 = 240;
WiredHome 23:a50ded45dbaf 3045 y2 = 7;
WiredHome 23:a50ded45dbaf 3046 x3 = 220;
WiredHome 23:a50ded45dbaf 3047 y3 = 16;
WiredHome 23:a50ded45dbaf 3048 display.filltriangle(x1,y1, x2,y2, x3,y3, BrightRed);
WiredHome 23:a50ded45dbaf 3049
WiredHome 23:a50ded45dbaf 3050 x1 = 300;
WiredHome 23:a50ded45dbaf 3051 y1 = 2;
WiredHome 23:a50ded45dbaf 3052 x2 = 340;
WiredHome 23:a50ded45dbaf 3053 y2 = 7;
WiredHome 23:a50ded45dbaf 3054 x3 = 320;
WiredHome 23:a50ded45dbaf 3055 y3 = 16;
WiredHome 23:a50ded45dbaf 3056 display.triangle(x1,y1, x2,y2, x3,y3, NOFILL);
WiredHome 23:a50ded45dbaf 3057
WiredHome 23:a50ded45dbaf 3058 x1 = 400;
WiredHome 23:a50ded45dbaf 3059 y1 = 2;
WiredHome 23:a50ded45dbaf 3060 x2 = 440;
WiredHome 23:a50ded45dbaf 3061 y2 = 7;
WiredHome 23:a50ded45dbaf 3062 x3 = 420;
WiredHome 23:a50ded45dbaf 3063 y3 = 16;
WiredHome 23:a50ded45dbaf 3064 display.triangle(x1,y1, x2,y2, x3,y3, Blue);
WiredHome 23:a50ded45dbaf 3065
WiredHome 23:a50ded45dbaf 3066 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3067 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 3068 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3069 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 3070 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3071 x3 = rand() % 240;
WiredHome 23:a50ded45dbaf 3072 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3073 display.triangle(x1,y1, x2,y2, x3,y3, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3074 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 3075 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3076 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 3077 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3078 x3 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 3079 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3080 display.triangle(x1,y1, x2,y2, x3,y3, FILL);
WiredHome 23:a50ded45dbaf 3081 }
WiredHome 23:a50ded45dbaf 3082 }
WiredHome 23:a50ded45dbaf 3083
WiredHome 44:207594dece70 3084
WiredHome 23:a50ded45dbaf 3085 void CircleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 3086 {
WiredHome 23:a50ded45dbaf 3087 int i, x, y, r1;
WiredHome 23:a50ded45dbaf 3088
WiredHome 41:2956a0a221e5 3089 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3090 pc.printf("Circle Test\r\n");
WiredHome 23:a50ded45dbaf 3091 display.background(Black);
WiredHome 23:a50ded45dbaf 3092 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 3093 display.cls();
WiredHome 100:0b084475d5a9 3094 display.puts("Circle Test");
WiredHome 23:a50ded45dbaf 3095 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3096 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 3097 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 3098 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3099 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 3100 display.circle(x,y,r1, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3101
WiredHome 23:a50ded45dbaf 3102 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 3103 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 3104 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3105 //pc.printf(" (%d,%d) - %d FILL\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 3106 display.circle(x,y,r1, display.DOSColor(i), FILL);
WiredHome 23:a50ded45dbaf 3107 }
WiredHome 23:a50ded45dbaf 3108 }
WiredHome 23:a50ded45dbaf 3109
WiredHome 44:207594dece70 3110
WiredHome 23:a50ded45dbaf 3111 void EllipseTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 3112 {
WiredHome 23:a50ded45dbaf 3113 int i,x,y,r1,r2;
WiredHome 23:a50ded45dbaf 3114
WiredHome 41:2956a0a221e5 3115 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3116 pc.printf("Ellipse Test\r\n");
WiredHome 23:a50ded45dbaf 3117 display.background(Black);
WiredHome 23:a50ded45dbaf 3118 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 3119 display.cls();
WiredHome 100:0b084475d5a9 3120 display.puts("Ellipse Test");
WiredHome 23:a50ded45dbaf 3121 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3122 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 3123 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 3124 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3125 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3126 display.ellipse(x,y,r1,r2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3127
WiredHome 23:a50ded45dbaf 3128 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 3129 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 3130 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3131 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3132 display.ellipse(x,y,r1,r2, FILL);
WiredHome 23:a50ded45dbaf 3133 }
WiredHome 23:a50ded45dbaf 3134 }
WiredHome 23:a50ded45dbaf 3135
WiredHome 44:207594dece70 3136
WiredHome 37:f19b7e7449dc 3137 void TestGraphicsBitmap(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 3138 {
WiredHome 37:f19b7e7449dc 3139 LocalFileSystem local("local");
WiredHome 41:2956a0a221e5 3140 if (!SuppressSlowStuff)
WiredHome 73:f22a18707b5e 3141 pc.printf("Bitmap File Load\r\n");
WiredHome 37:f19b7e7449dc 3142 display.background(Black);
WiredHome 37:f19b7e7449dc 3143 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 3144 display.cls();
WiredHome 100:0b084475d5a9 3145 display.puts("Graphics Test, loading /local/TestPat.bmp");
WiredHome 37:f19b7e7449dc 3146 wait(3);
WiredHome 37:f19b7e7449dc 3147
WiredHome 37:f19b7e7449dc 3148 int r = display.RenderBitmapFile(0,0, "/local/TestPat.bmp");
WiredHome 59:fb40aad4efd4 3149 if (!SuppressSlowStuff)
WiredHome 59:fb40aad4efd4 3150 pc.printf(" returned %d\r\n", r);
WiredHome 37:f19b7e7449dc 3151 }
WiredHome 37:f19b7e7449dc 3152
WiredHome 44:207594dece70 3153
WiredHome 77:9206c13aa527 3154 void TouchPanelTest(RA8875 & display, Serial & pc)
WiredHome 77:9206c13aa527 3155 {
WiredHome 77:9206c13aa527 3156 Timer t;
WiredHome 98:ecebed9b80b2 3157 int x, y;
WiredHome 78:faf49c381591 3158 tpMatrix_t calmatrix;
WiredHome 78:faf49c381591 3159
WiredHome 77:9206c13aa527 3160 display.background(Black);
WiredHome 77:9206c13aa527 3161 display.foreground(Blue);
WiredHome 77:9206c13aa527 3162 display.cls();
WiredHome 100:0b084475d5a9 3163 display.puts("Touch Panel Test\r\n");
WiredHome 78:faf49c381591 3164 pc.printf("Touch Panel Test\r\n");
WiredHome 77:9206c13aa527 3165 display.TouchPanelInit();
WiredHome 78:faf49c381591 3166 pc.printf(" TP: c - calibrate, r - restore, t - test\r\n");
WiredHome 78:faf49c381591 3167 int c = pc.getc();
WiredHome 78:faf49c381591 3168 if (c == 'c') {
WiredHome 78:faf49c381591 3169 point_t pTest[3] =
WiredHome 78:faf49c381591 3170 { { 50, 50 }, {450, 150}, {225,250} };
WiredHome 78:faf49c381591 3171 point_t pSample[3];
WiredHome 78:faf49c381591 3172 for (int i=0; i<3; i++) {
WiredHome 78:faf49c381591 3173 display.foreground(Blue);
WiredHome 78:faf49c381591 3174 display.printf(" (%3d,%3d) => ", pTest[i].x, pTest[i].y);
WiredHome 78:faf49c381591 3175 display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, White);
WiredHome 78:faf49c381591 3176 display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, White);
WiredHome 79:544eb4964795 3177 while (!display.TouchPanelA2DFiltered(&x, &y))
WiredHome 78:faf49c381591 3178 wait_ms(20);
WiredHome 78:faf49c381591 3179 pSample[i].x = x;
WiredHome 78:faf49c381591 3180 pSample[i].y = y;
WiredHome 78:faf49c381591 3181 display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, Black);
WiredHome 78:faf49c381591 3182 display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, Black);
WiredHome 78:faf49c381591 3183 display.foreground(Blue);
WiredHome 78:faf49c381591 3184 display.printf(" (%4d,%4d)\r\n", x,y);
WiredHome 79:544eb4964795 3185 while (display.TouchPanelA2DFiltered(&x, &y))
WiredHome 78:faf49c381591 3186 wait_ms(20);
WiredHome 78:faf49c381591 3187 wait(2);
WiredHome 78:faf49c381591 3188 }
WiredHome 81:01da2e34283d 3189 display.TouchPanelComputeCalibration(pTest, pSample, &calmatrix);
WiredHome 78:faf49c381591 3190 display.printf(" Writing calibration to tpcal.cfg\r\n");
WiredHome 78:faf49c381591 3191 FILE * fh = fopen("/local/tpcal.cfg", "wb");
WiredHome 78:faf49c381591 3192 if (fh) {
WiredHome 78:faf49c381591 3193 fwrite(&calmatrix, sizeof(calmatrix), 1, fh);
WiredHome 78:faf49c381591 3194 fclose(fh);
WiredHome 78:faf49c381591 3195 }
WiredHome 78:faf49c381591 3196 display.printf(" Calibration is complete.");
WiredHome 78:faf49c381591 3197 } else if (c == 'r') {
WiredHome 78:faf49c381591 3198 display.printf(" Reading calibration from tpcal.cfg\r\n");
WiredHome 78:faf49c381591 3199 FILE * fh = fopen("/local/tpcal.cfg", "rb");
WiredHome 78:faf49c381591 3200 if (fh) {
WiredHome 78:faf49c381591 3201 fread(&calmatrix, sizeof(calmatrix), 1, fh);
WiredHome 78:faf49c381591 3202 fclose(fh);
WiredHome 78:faf49c381591 3203 }
WiredHome 78:faf49c381591 3204 display.printf(" Calibration is complete.");
WiredHome 78:faf49c381591 3205 display.TouchPanelSetMatrix(&calmatrix);
WiredHome 77:9206c13aa527 3206 }
WiredHome 77:9206c13aa527 3207 t.start();
WiredHome 77:9206c13aa527 3208 do {
WiredHome 77:9206c13aa527 3209 point_t point = {0, 0};
WiredHome 79:544eb4964795 3210 if (display.TouchPanelReadable(&point)) {
WiredHome 77:9206c13aa527 3211 display.pixel(point.x, point.y, Red);
WiredHome 77:9206c13aa527 3212 }
WiredHome 77:9206c13aa527 3213 } while (t.read_ms() < 30000);
WiredHome 77:9206c13aa527 3214 pc.printf(">");
WiredHome 77:9206c13aa527 3215 }
WiredHome 77:9206c13aa527 3216
WiredHome 77:9206c13aa527 3217
WiredHome 41:2956a0a221e5 3218 void SpeedTest(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 3219 {
WiredHome 41:2956a0a221e5 3220 Timer t;
WiredHome 41:2956a0a221e5 3221 SuppressSlowStuff = true;
WiredHome 41:2956a0a221e5 3222 pc.printf("\r\nSpeedTest disables delays, runs tests, reports overall time.\r\n");
WiredHome 41:2956a0a221e5 3223 t.start();
WiredHome 41:2956a0a221e5 3224 // do stuff fast
WiredHome 41:2956a0a221e5 3225 TextCursorTest(display, pc);
WiredHome 49:c5182231d1b9 3226 TextWrapTest(display, pc);
WiredHome 41:2956a0a221e5 3227 BacklightTest(display, pc, 0);
WiredHome 41:2956a0a221e5 3228 BacklightTest2(display, pc);
WiredHome 41:2956a0a221e5 3229 ExternalFontTest(display, pc);
WiredHome 41:2956a0a221e5 3230 DOSColorTest(display, pc);
WiredHome 41:2956a0a221e5 3231 WebColorTest(display, pc);
WiredHome 41:2956a0a221e5 3232 PixelTest(display, pc);
WiredHome 41:2956a0a221e5 3233 LineTest(display, pc);
WiredHome 41:2956a0a221e5 3234 RectangleTest(display, pc);
WiredHome 41:2956a0a221e5 3235 RoundRectTest(display, pc);
WiredHome 41:2956a0a221e5 3236 TriangleTest(display, pc);
WiredHome 41:2956a0a221e5 3237 CircleTest(display, pc);
WiredHome 41:2956a0a221e5 3238 EllipseTest(display, pc);
WiredHome 44:207594dece70 3239 LayerTest(display, pc);
WiredHome 41:2956a0a221e5 3240 //TestGraphicsBitmap(display, pc);
WiredHome 41:2956a0a221e5 3241 pc.printf("SpeedTest completed in %d msec\r\n", t.read_ms());
WiredHome 73:f22a18707b5e 3242 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 3243 display.ReportPerformance(pc);
WiredHome 73:f22a18707b5e 3244 #endif
WiredHome 41:2956a0a221e5 3245 SuppressSlowStuff = false;
WiredHome 41:2956a0a221e5 3246 }
WiredHome 41:2956a0a221e5 3247
WiredHome 44:207594dece70 3248
WiredHome 41:2956a0a221e5 3249 void PrintScreen(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 3250 {
WiredHome 41:2956a0a221e5 3251 if (!SuppressSlowStuff)
WiredHome 73:f22a18707b5e 3252 pc.printf("PrintScreen\r\n");
WiredHome 41:2956a0a221e5 3253 display.PrintScreen( 0,0, 480,272, "/local/Capture.bmp");
WiredHome 41:2956a0a221e5 3254 }
WiredHome 41:2956a0a221e5 3255
WiredHome 44:207594dece70 3256
WiredHome 23:a50ded45dbaf 3257 void RunTestSet(RA8875 & lcd, Serial & pc)
WiredHome 23:a50ded45dbaf 3258 {
WiredHome 23:a50ded45dbaf 3259 int q = 0;
WiredHome 23:a50ded45dbaf 3260 int automode = 0;
WiredHome 49:c5182231d1b9 3261 const unsigned char modelist[] = "BDWtGLlFROTPCEbw"; // auto-test in this order.
WiredHome 23:a50ded45dbaf 3262
WiredHome 23:a50ded45dbaf 3263 while(1) {
WiredHome 23:a50ded45dbaf 3264 pc.printf("\r\n"
WiredHome 41:2956a0a221e5 3265 "B - Backlight up b - backlight dim\r\n"
WiredHome 41:2956a0a221e5 3266 "D - DOS Colors W - Web Colors\r\n"
WiredHome 41:2956a0a221e5 3267 "t - text cursor G - Graphics Bitmap\r\n"
WiredHome 41:2956a0a221e5 3268 "L - Lines F - external Font\r\n"
WiredHome 41:2956a0a221e5 3269 "R - Rectangles O - rOund rectangles\r\n"
WiredHome 41:2956a0a221e5 3270 "T - Triangles P - Pixels \r\n"
WiredHome 41:2956a0a221e5 3271 "C - Circles E - Ellipses\r\n"
WiredHome 41:2956a0a221e5 3272 "A - Auto Test mode S - Speed Test\r\n"
WiredHome 77:9206c13aa527 3273 "K - Keypad Test s - touch screen test\r\n"
WiredHome 41:2956a0a221e5 3274 "p - print screen r - reset \r\n"
WiredHome 49:c5182231d1b9 3275 "l - layer test w - wrapping text \r\n"
WiredHome 73:f22a18707b5e 3276 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 3277 "0 - clear performance 1 - report performance\r\n"
WiredHome 73:f22a18707b5e 3278 #endif
WiredHome 23:a50ded45dbaf 3279 "> ");
WiredHome 23:a50ded45dbaf 3280 if (automode == -1 || pc.readable()) {
WiredHome 23:a50ded45dbaf 3281 automode = -1;
WiredHome 37:f19b7e7449dc 3282 q = pc.getc();
WiredHome 37:f19b7e7449dc 3283 while (pc.readable())
WiredHome 37:f19b7e7449dc 3284 pc.getc();
WiredHome 23:a50ded45dbaf 3285 } else if (automode >= 0) {
WiredHome 23:a50ded45dbaf 3286 q = modelist[automode];
WiredHome 23:a50ded45dbaf 3287 }
WiredHome 23:a50ded45dbaf 3288 switch(q) {
WiredHome 73:f22a18707b5e 3289 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 3290 case '0':
WiredHome 41:2956a0a221e5 3291 lcd.ClearPerformance();
WiredHome 41:2956a0a221e5 3292 break;
WiredHome 41:2956a0a221e5 3293 case '1':
WiredHome 41:2956a0a221e5 3294 lcd.ReportPerformance(pc);
WiredHome 41:2956a0a221e5 3295 break;
WiredHome 73:f22a18707b5e 3296 #endif
WiredHome 23:a50ded45dbaf 3297 case 'A':
WiredHome 23:a50ded45dbaf 3298 automode = 0;
WiredHome 23:a50ded45dbaf 3299 break;
WiredHome 23:a50ded45dbaf 3300 case 'B':
WiredHome 41:2956a0a221e5 3301 BacklightTest(lcd, pc, 2);
WiredHome 23:a50ded45dbaf 3302 break;
WiredHome 23:a50ded45dbaf 3303 case 'b':
WiredHome 23:a50ded45dbaf 3304 BacklightTest2(lcd, pc);
WiredHome 23:a50ded45dbaf 3305 break;
WiredHome 23:a50ded45dbaf 3306 case 'D':
WiredHome 23:a50ded45dbaf 3307 DOSColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3308 break;
WiredHome 75:ca78388cfd77 3309 case 'K':
WiredHome 75:ca78388cfd77 3310 KeyPadTest(lcd, pc);
WiredHome 75:ca78388cfd77 3311 break;
WiredHome 23:a50ded45dbaf 3312 case 'W':
WiredHome 23:a50ded45dbaf 3313 WebColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3314 break;
WiredHome 23:a50ded45dbaf 3315 case 't':
WiredHome 23:a50ded45dbaf 3316 TextCursorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3317 break;
WiredHome 49:c5182231d1b9 3318 case 'w':
WiredHome 49:c5182231d1b9 3319 TextWrapTest(lcd, pc);
WiredHome 49:c5182231d1b9 3320 break;
WiredHome 23:a50ded45dbaf 3321 case 'F':
WiredHome 23:a50ded45dbaf 3322 ExternalFontTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3323 break;
WiredHome 23:a50ded45dbaf 3324 case 'L':
WiredHome 23:a50ded45dbaf 3325 LineTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3326 break;
WiredHome 44:207594dece70 3327 case 'l':
WiredHome 44:207594dece70 3328 LayerTest(lcd, pc);
WiredHome 44:207594dece70 3329 break;
WiredHome 23:a50ded45dbaf 3330 case 'R':
WiredHome 23:a50ded45dbaf 3331 RectangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3332 break;
WiredHome 23:a50ded45dbaf 3333 case 'O':
WiredHome 23:a50ded45dbaf 3334 RoundRectTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3335 break;
WiredHome 41:2956a0a221e5 3336 case 'p':
WiredHome 41:2956a0a221e5 3337 PrintScreen(lcd, pc);
WiredHome 41:2956a0a221e5 3338 break;
WiredHome 41:2956a0a221e5 3339 case 'S':
WiredHome 41:2956a0a221e5 3340 SpeedTest(lcd, pc);
WiredHome 41:2956a0a221e5 3341 break;
WiredHome 77:9206c13aa527 3342 case 's':
WiredHome 77:9206c13aa527 3343 TouchPanelTest(lcd, pc);
WiredHome 77:9206c13aa527 3344 break;
WiredHome 23:a50ded45dbaf 3345 case 'T':
WiredHome 23:a50ded45dbaf 3346 TriangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3347 break;
WiredHome 37:f19b7e7449dc 3348 case 'P':
WiredHome 37:f19b7e7449dc 3349 PixelTest(lcd, pc);
WiredHome 37:f19b7e7449dc 3350 break;
WiredHome 37:f19b7e7449dc 3351 case 'G':
WiredHome 37:f19b7e7449dc 3352 TestGraphicsBitmap(lcd, pc);
WiredHome 37:f19b7e7449dc 3353 break;
WiredHome 23:a50ded45dbaf 3354 case 'C':
WiredHome 23:a50ded45dbaf 3355 CircleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3356 break;
WiredHome 23:a50ded45dbaf 3357 case 'E':
WiredHome 23:a50ded45dbaf 3358 EllipseTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3359 break;
WiredHome 23:a50ded45dbaf 3360 case 'r':
WiredHome 23:a50ded45dbaf 3361 pc.printf("Resetting ...\r\n");
WiredHome 23:a50ded45dbaf 3362 wait_ms(20);
WiredHome 23:a50ded45dbaf 3363 mbed_reset();
WiredHome 23:a50ded45dbaf 3364 break;
WiredHome 75:ca78388cfd77 3365 case ' ':
WiredHome 75:ca78388cfd77 3366 break;
WiredHome 23:a50ded45dbaf 3367 default:
WiredHome 23:a50ded45dbaf 3368 printf("huh?\n");
WiredHome 23:a50ded45dbaf 3369 break;
WiredHome 23:a50ded45dbaf 3370 }
WiredHome 23:a50ded45dbaf 3371 if (automode >= 0) {
WiredHome 23:a50ded45dbaf 3372 automode++;
WiredHome 23:a50ded45dbaf 3373 if (automode >= sizeof(modelist))
WiredHome 23:a50ded45dbaf 3374 automode = 0;
WiredHome 23:a50ded45dbaf 3375 wait_ms(2000);
WiredHome 23:a50ded45dbaf 3376 }
WiredHome 23:a50ded45dbaf 3377 wait_ms(200);
WiredHome 23:a50ded45dbaf 3378 }
WiredHome 23:a50ded45dbaf 3379 }
WiredHome 23:a50ded45dbaf 3380
WiredHome 79:544eb4964795 3381 #endif // TESTENABLE