Forked para SNOCC
Fork of RA8875 by
RA8875.cpp@78:faf49c381591, 2014-12-28 (annotated)
- Committer:
- WiredHome
- Date:
- Sun Dec 28 03:14:35 2014 +0000
- Revision:
- 78:faf49c381591
- Parent:
- 77:9206c13aa527
- Child:
- 79:544eb4964795
Continue work on touch screen, and some file refactoring for easier maintenance.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WiredHome | 19:3f82c1161fd2 | 1 | /// RA8875 Display Controller Library. |
WiredHome | 73:f22a18707b5e | 2 | /// |
WiredHome | 68:ab08efabfc88 | 3 | /// This is being created for a Raio RA8875-based display from buydisplay.com, |
WiredHome | 73:f22a18707b5e | 4 | /// which is 480 x 272 using a 4-wire SPI interface. |
WiredHome | 68:ab08efabfc88 | 5 | /// This display controller is used in other display resolutions, up to 800x600. |
WiredHome | 68:ab08efabfc88 | 6 | /// While this driver has not been tested with these variants, nothing was done |
WiredHome | 68:ab08efabfc88 | 7 | /// to prevent easily supporting them. |
WiredHome | 19:3f82c1161fd2 | 8 | /// |
WiredHome | 19:3f82c1161fd2 | 9 | #include "RA8875.h" |
WiredHome | 19:3f82c1161fd2 | 10 | |
WiredHome | 41:2956a0a221e5 | 11 | //#define DEBUG "RAIO" |
WiredHome | 19:3f82c1161fd2 | 12 | // ... |
WiredHome | 19:3f82c1161fd2 | 13 | // INFO("Stuff to show %d", var); // new-line is automatically appended |
WiredHome | 19:3f82c1161fd2 | 14 | // |
WiredHome | 19:3f82c1161fd2 | 15 | #if (defined(DEBUG) && !defined(TARGET_LPC11U24)) |
WiredHome | 19:3f82c1161fd2 | 16 | #define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 19:3f82c1161fd2 | 17 | #define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 19:3f82c1161fd2 | 18 | #define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 73:f22a18707b5e | 19 | static void HexDump(char * title, uint8_t * p, int count) |
WiredHome | 73:f22a18707b5e | 20 | { |
WiredHome | 73:f22a18707b5e | 21 | int i; |
WiredHome | 73:f22a18707b5e | 22 | char buf[100] = "0000: "; |
WiredHome | 73:f22a18707b5e | 23 | |
WiredHome | 73:f22a18707b5e | 24 | if (*title) |
WiredHome | 73:f22a18707b5e | 25 | INFO("%s", title); |
WiredHome | 73:f22a18707b5e | 26 | for (i=0; i<count; ) { |
WiredHome | 73:f22a18707b5e | 27 | sprintf(buf + strlen(buf), "%02X ", *(p+i)); |
WiredHome | 73:f22a18707b5e | 28 | if ((++i & 0x0F) == 0x00) { |
WiredHome | 73:f22a18707b5e | 29 | INFO("%s", buf); |
WiredHome | 73:f22a18707b5e | 30 | if (i < count) |
WiredHome | 73:f22a18707b5e | 31 | sprintf(buf, "%04X: ", i); |
WiredHome | 73:f22a18707b5e | 32 | else |
WiredHome | 73:f22a18707b5e | 33 | buf[0] = '\0'; |
WiredHome | 73:f22a18707b5e | 34 | } |
WiredHome | 73:f22a18707b5e | 35 | } |
WiredHome | 73:f22a18707b5e | 36 | if (strlen(buf)) |
WiredHome | 73:f22a18707b5e | 37 | INFO("%s", buf); |
WiredHome | 73:f22a18707b5e | 38 | } |
WiredHome | 19:3f82c1161fd2 | 39 | #else |
WiredHome | 19:3f82c1161fd2 | 40 | #define INFO(x, ...) |
WiredHome | 19:3f82c1161fd2 | 41 | #define WARN(x, ...) |
WiredHome | 19:3f82c1161fd2 | 42 | #define ERR(x, ...) |
WiredHome | 73:f22a18707b5e | 43 | #define HexDump(a, b, c) |
WiredHome | 19:3f82c1161fd2 | 44 | #endif |
WiredHome | 19:3f82c1161fd2 | 45 | |
WiredHome | 19:3f82c1161fd2 | 46 | |
WiredHome | 19:3f82c1161fd2 | 47 | #define RA8875_DISPLAY_WIDTH 480 |
WiredHome | 19:3f82c1161fd2 | 48 | #define RA8875_DISPLAY_HEIGHT 272 |
WiredHome | 43:3becae133285 | 49 | #define RA8875_COLORDEPTH_BPP 16 /* Not an API */ |
WiredHome | 19:3f82c1161fd2 | 50 | |
WiredHome | 19:3f82c1161fd2 | 51 | #ifdef PERF_METRICS |
WiredHome | 19:3f82c1161fd2 | 52 | #define PERFORMANCE_RESET performance.reset() |
WiredHome | 19:3f82c1161fd2 | 53 | #define REGISTERPERFORMANCE(a) RegisterPerformance(a) |
WiredHome | 68:ab08efabfc88 | 54 | #define COUNTIDLETIME(a) CountIdleTime(a) |
WiredHome | 73:f22a18707b5e | 55 | static const char *metricsName[] = { |
WiredHome | 73:f22a18707b5e | 56 | "Cls", "Pixel", "Pixel Stream", |
WiredHome | 41:2956a0a221e5 | 57 | "Read Pixel", "Read Pixel Stream", |
WiredHome | 73:f22a18707b5e | 58 | "Line", |
WiredHome | 73:f22a18707b5e | 59 | "Rectangle", "Rounded Rectangle", |
WiredHome | 68:ab08efabfc88 | 60 | "Triangle", "Circle", "Ellipse" |
WiredHome | 19:3f82c1161fd2 | 61 | }; |
WiredHome | 19:3f82c1161fd2 | 62 | #else |
WiredHome | 19:3f82c1161fd2 | 63 | #define PERFORMANCE_RESET |
WiredHome | 19:3f82c1161fd2 | 64 | #define REGISTERPERFORMANCE(a) |
WiredHome | 68:ab08efabfc88 | 65 | #define COUNTIDLETIME(a) |
WiredHome | 19:3f82c1161fd2 | 66 | #endif |
WiredHome | 19:3f82c1161fd2 | 67 | |
WiredHome | 73:f22a18707b5e | 68 | // When it is going to poll a register for completion, how many |
WiredHome | 19:3f82c1161fd2 | 69 | // uSec should it wait between each polling activity. |
WiredHome | 19:3f82c1161fd2 | 70 | #define POLLWAITuSec 10 |
WiredHome | 19:3f82c1161fd2 | 71 | |
WiredHome | 75:ca78388cfd77 | 72 | // Private RawKeyMap for the Keyboard interface |
WiredHome | 77:9206c13aa527 | 73 | static const uint8_t KeyMap[22] = { |
WiredHome | 77:9206c13aa527 | 74 | 0, |
WiredHome | 77:9206c13aa527 | 75 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, |
WiredHome | 75:ca78388cfd77 | 76 | 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
WiredHome | 75:ca78388cfd77 | 77 | 255 |
WiredHome | 77:9206c13aa527 | 78 | }; |
WiredHome | 75:ca78388cfd77 | 79 | |
WiredHome | 19:3f82c1161fd2 | 80 | |
WiredHome | 19:3f82c1161fd2 | 81 | RA8875::RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, const char *name) |
WiredHome | 58:26658a56112a | 82 | : GraphicsDisplay(name) |
WiredHome | 58:26658a56112a | 83 | , spi(mosi, miso, sclk) |
WiredHome | 19:3f82c1161fd2 | 84 | , cs(csel) |
WiredHome | 19:3f82c1161fd2 | 85 | , res(reset) |
WiredHome | 19:3f82c1161fd2 | 86 | { |
WiredHome | 19:3f82c1161fd2 | 87 | font = NULL; // no external font, use internal. |
WiredHome | 19:3f82c1161fd2 | 88 | select(false); // deselect the display |
WiredHome | 19:3f82c1161fd2 | 89 | frequency(RA8875_DEFAULT_SPI_FREQ); // data rate |
WiredHome | 28:ed102fc442c4 | 90 | Reset(); |
WiredHome | 28:ed102fc442c4 | 91 | Power(true); |
WiredHome | 28:ed102fc442c4 | 92 | Backlight_u8(255); |
WiredHome | 75:ca78388cfd77 | 93 | pKeyMap = KeyMap; |
WiredHome | 19:3f82c1161fd2 | 94 | #ifdef PERF_METRICS |
WiredHome | 19:3f82c1161fd2 | 95 | performance.start(); |
WiredHome | 19:3f82c1161fd2 | 96 | ClearPerformance(); |
WiredHome | 19:3f82c1161fd2 | 97 | #endif |
WiredHome | 19:3f82c1161fd2 | 98 | } |
WiredHome | 19:3f82c1161fd2 | 99 | |
WiredHome | 43:3becae133285 | 100 | |
WiredHome | 19:3f82c1161fd2 | 101 | //RA8875::~RA8875() |
WiredHome | 19:3f82c1161fd2 | 102 | //{ |
WiredHome | 19:3f82c1161fd2 | 103 | //} |
WiredHome | 19:3f82c1161fd2 | 104 | |
WiredHome | 61:8f3153bf0baa | 105 | uint16_t RA8875::GetDrawingLayer(void) |
WiredHome | 61:8f3153bf0baa | 106 | { |
WiredHome | 61:8f3153bf0baa | 107 | return (ReadCommand(0x41) & 0x01); |
WiredHome | 61:8f3153bf0baa | 108 | } |
WiredHome | 43:3becae133285 | 109 | |
WiredHome | 50:2c4f474a2453 | 110 | RetCode_t RA8875::SelectDrawingLayer(uint16_t layer) |
WiredHome | 43:3becae133285 | 111 | { |
WiredHome | 43:3becae133285 | 112 | unsigned char mwcr1 = ReadCommand(0x41) & ~0x01; // retain all but the currently selected layer |
WiredHome | 43:3becae133285 | 113 | |
WiredHome | 43:3becae133285 | 114 | if (width() >= 800 && height() >= 480 && color_bpp() == 8) { |
WiredHome | 43:3becae133285 | 115 | return bad_parameter; |
WiredHome | 43:3becae133285 | 116 | } else if (layer > 1) { |
WiredHome | 43:3becae133285 | 117 | return bad_parameter; |
WiredHome | 43:3becae133285 | 118 | } else { // layer == 0 ro 1 |
WiredHome | 72:ecffe56af969 | 119 | return WriteCommand(0x41, mwcr1 | layer); |
WiredHome | 43:3becae133285 | 120 | } |
WiredHome | 43:3becae133285 | 121 | } |
WiredHome | 43:3becae133285 | 122 | |
WiredHome | 44:207594dece70 | 123 | |
WiredHome | 53:86d24b9480b9 | 124 | RetCode_t RA8875::SetLayerMode(LayerMode_T mode) |
WiredHome | 44:207594dece70 | 125 | { |
WiredHome | 53:86d24b9480b9 | 126 | unsigned char ltpr0 = ReadCommand(0x52) & ~0x7; // retain all but the display layer mode |
WiredHome | 53:86d24b9480b9 | 127 | if (mode <= (LayerMode_T)6) { |
WiredHome | 53:86d24b9480b9 | 128 | WriteCommand(0x52, ltpr0 | (mode & 0x7)); |
WiredHome | 53:86d24b9480b9 | 129 | return noerror; |
WiredHome | 53:86d24b9480b9 | 130 | } else { |
WiredHome | 53:86d24b9480b9 | 131 | return bad_parameter; |
WiredHome | 53:86d24b9480b9 | 132 | } |
WiredHome | 44:207594dece70 | 133 | } |
WiredHome | 44:207594dece70 | 134 | |
WiredHome | 44:207594dece70 | 135 | |
WiredHome | 44:207594dece70 | 136 | RetCode_t RA8875::SetLayerTransparency(uint8_t layer1, uint8_t layer2) |
WiredHome | 44:207594dece70 | 137 | { |
WiredHome | 44:207594dece70 | 138 | if (layer1 > 8) |
WiredHome | 44:207594dece70 | 139 | layer1 = 8; |
WiredHome | 44:207594dece70 | 140 | if (layer2 > 8) |
WiredHome | 44:207594dece70 | 141 | layer2 = 8; |
WiredHome | 44:207594dece70 | 142 | WriteCommand(0x53, ((layer2 & 0xF) << 4) | (layer1 & 0xF)); |
WiredHome | 44:207594dece70 | 143 | return noerror; |
WiredHome | 44:207594dece70 | 144 | } |
WiredHome | 44:207594dece70 | 145 | |
WiredHome | 44:207594dece70 | 146 | |
WiredHome | 53:86d24b9480b9 | 147 | RetCode_t RA8875::SetBackgroundTransparencyColor(color_t color) |
WiredHome | 53:86d24b9480b9 | 148 | { |
WiredHome | 53:86d24b9480b9 | 149 | WriteCommand(0x67, (color >> 11) & 0x1F); |
WiredHome | 53:86d24b9480b9 | 150 | WriteCommand(0x68, (color >> 5) & 0x3F); |
WiredHome | 53:86d24b9480b9 | 151 | WriteCommand(0x69, (color & 0x1F)); |
WiredHome | 53:86d24b9480b9 | 152 | return noerror; |
WiredHome | 53:86d24b9480b9 | 153 | } |
WiredHome | 53:86d24b9480b9 | 154 | |
WiredHome | 73:f22a18707b5e | 155 | color_t RA8875::GetBackgroundTransparencyColor(void) |
WiredHome | 73:f22a18707b5e | 156 | { |
WiredHome | 73:f22a18707b5e | 157 | RGBQUAD q; |
WiredHome | 73:f22a18707b5e | 158 | q.rgbRed = ReadCommand(0x67); |
WiredHome | 73:f22a18707b5e | 159 | q.rgbGreen = ReadCommand(0x68); |
WiredHome | 73:f22a18707b5e | 160 | q.rgbBlue = ReadCommand(0x69); |
WiredHome | 73:f22a18707b5e | 161 | return RGBQuadToRGB16(&q, 0); |
WiredHome | 73:f22a18707b5e | 162 | } |
WiredHome | 73:f22a18707b5e | 163 | |
WiredHome | 71:dcac8efd842d | 164 | |
WiredHome | 77:9206c13aa527 | 165 | RetCode_t RA8875::KeypadInit(bool scanEnable, bool longDetect, uint8_t sampleTime, uint8_t scanFrequency, |
WiredHome | 77:9206c13aa527 | 166 | uint8_t longTimeAdjustment, bool interruptEnable, bool wakeupEnable) |
WiredHome | 71:dcac8efd842d | 167 | { |
WiredHome | 71:dcac8efd842d | 168 | uint8_t value = 0; |
WiredHome | 77:9206c13aa527 | 169 | |
WiredHome | 71:dcac8efd842d | 170 | if (sampleTime > 3 || scanFrequency > 7 || longTimeAdjustment > 3) |
WiredHome | 71:dcac8efd842d | 171 | return bad_parameter; |
WiredHome | 71:dcac8efd842d | 172 | value |= (scanEnable) ? 0x80 : 0x00; |
WiredHome | 71:dcac8efd842d | 173 | value |= (longDetect) ? 0x40 : 0x00; |
WiredHome | 71:dcac8efd842d | 174 | value |= (sampleTime & 0x03) << 4; |
WiredHome | 71:dcac8efd842d | 175 | value |= (scanFrequency & 0x07); |
WiredHome | 75:ca78388cfd77 | 176 | WriteCommand(0xC0, value); // KSCR1 - Enable Key Scan (and ignore possibility of an error) |
WiredHome | 77:9206c13aa527 | 177 | |
WiredHome | 71:dcac8efd842d | 178 | value = 0; |
WiredHome | 71:dcac8efd842d | 179 | value |= (wakeupEnable) ? 0x80 : 0x00; |
WiredHome | 71:dcac8efd842d | 180 | value |= (longTimeAdjustment & 0x03) << 2; |
WiredHome | 75:ca78388cfd77 | 181 | WriteCommand(0xC1, value); // KSCR2 - (and ignore possibility of an error) |
WiredHome | 77:9206c13aa527 | 182 | |
WiredHome | 75:ca78388cfd77 | 183 | value = ReadCommand(0xF0); // (and ignore possibility of an error) |
WiredHome | 71:dcac8efd842d | 184 | value &= ~0x10; |
WiredHome | 71:dcac8efd842d | 185 | value |= (interruptEnable) ? 0x10 : 0x00; |
WiredHome | 75:ca78388cfd77 | 186 | return WriteCommand(0xF0, value); // INT |
WiredHome | 71:dcac8efd842d | 187 | } |
WiredHome | 71:dcac8efd842d | 188 | |
WiredHome | 75:ca78388cfd77 | 189 | RetCode_t RA8875::SetKeyMap(const uint8_t * CodeList) |
WiredHome | 75:ca78388cfd77 | 190 | { |
WiredHome | 75:ca78388cfd77 | 191 | pKeyMap = CodeList; |
WiredHome | 75:ca78388cfd77 | 192 | return noerror; |
WiredHome | 75:ca78388cfd77 | 193 | } |
WiredHome | 75:ca78388cfd77 | 194 | |
WiredHome | 75:ca78388cfd77 | 195 | bool RA8875::readable(void) |
WiredHome | 71:dcac8efd842d | 196 | { |
WiredHome | 71:dcac8efd842d | 197 | return (ReadCommand(0xF1) & 0x10); // check KS status - true if kbhit |
WiredHome | 71:dcac8efd842d | 198 | } |
WiredHome | 71:dcac8efd842d | 199 | |
WiredHome | 75:ca78388cfd77 | 200 | uint8_t RA8875::getc(void) |
WiredHome | 71:dcac8efd842d | 201 | { |
WiredHome | 75:ca78388cfd77 | 202 | //#define GETC_DEV |
WiredHome | 77:9206c13aa527 | 203 | #ifdef GETC_DEV |
WiredHome | 75:ca78388cfd77 | 204 | uint8_t keyCode1, keyCode2; |
WiredHome | 77:9206c13aa527 | 205 | #endif |
WiredHome | 75:ca78388cfd77 | 206 | uint8_t keyCode3; |
WiredHome | 75:ca78388cfd77 | 207 | static uint8_t count = 0; |
WiredHome | 75:ca78388cfd77 | 208 | uint8_t col, row; |
WiredHome | 75:ca78388cfd77 | 209 | uint8_t key; |
WiredHome | 77:9206c13aa527 | 210 | |
WiredHome | 75:ca78388cfd77 | 211 | while (!readable()) { |
WiredHome | 71:dcac8efd842d | 212 | wait_us(POLLWAITuSec); |
WiredHome | 75:ca78388cfd77 | 213 | // COUNTIDLETIME(POLLWAITuSec); // As it is voluntary to call the getc and pend. Don't tally it. |
WiredHome | 71:dcac8efd842d | 214 | } |
WiredHome | 71:dcac8efd842d | 215 | // read the key press number |
WiredHome | 71:dcac8efd842d | 216 | uint8_t keyNumReg = ReadCommand(0xC1) & 0x03; |
WiredHome | 75:ca78388cfd77 | 217 | count++; |
WiredHome | 75:ca78388cfd77 | 218 | switch (keyNumReg) { |
WiredHome | 75:ca78388cfd77 | 219 | case 0x01: // one key |
WiredHome | 75:ca78388cfd77 | 220 | keyCode3 = ReadCommand(0xC2); |
WiredHome | 77:9206c13aa527 | 221 | #ifdef GETC_DEV |
WiredHome | 75:ca78388cfd77 | 222 | keyCode2 = 0; |
WiredHome | 75:ca78388cfd77 | 223 | keyCode1 = 0; |
WiredHome | 77:9206c13aa527 | 224 | #endif |
WiredHome | 75:ca78388cfd77 | 225 | break; |
WiredHome | 75:ca78388cfd77 | 226 | case 0x02: // two keys |
WiredHome | 75:ca78388cfd77 | 227 | keyCode3 = ReadCommand(0xC3); |
WiredHome | 77:9206c13aa527 | 228 | #ifdef GETC_DEV |
WiredHome | 75:ca78388cfd77 | 229 | keyCode2 = ReadCommand(0xC2); |
WiredHome | 75:ca78388cfd77 | 230 | keyCode1 = 0; |
WiredHome | 77:9206c13aa527 | 231 | #endif |
WiredHome | 75:ca78388cfd77 | 232 | break; |
WiredHome | 75:ca78388cfd77 | 233 | case 0x03: // three keys |
WiredHome | 75:ca78388cfd77 | 234 | keyCode3 = ReadCommand(0xC4); |
WiredHome | 77:9206c13aa527 | 235 | #ifdef GETC_DEV |
WiredHome | 75:ca78388cfd77 | 236 | keyCode2 = ReadCommand(0xC3); |
WiredHome | 75:ca78388cfd77 | 237 | keyCode1 = ReadCommand(0xC2); |
WiredHome | 77:9206c13aa527 | 238 | #endif |
WiredHome | 75:ca78388cfd77 | 239 | break; |
WiredHome | 75:ca78388cfd77 | 240 | default: // no keys (key released) |
WiredHome | 75:ca78388cfd77 | 241 | keyCode3 = 0xFF; |
WiredHome | 77:9206c13aa527 | 242 | #ifdef GETC_DEV |
WiredHome | 75:ca78388cfd77 | 243 | keyCode2 = 0; |
WiredHome | 75:ca78388cfd77 | 244 | keyCode1 = 0; |
WiredHome | 77:9206c13aa527 | 245 | #endif |
WiredHome | 75:ca78388cfd77 | 246 | break; |
WiredHome | 75:ca78388cfd77 | 247 | } |
WiredHome | 75:ca78388cfd77 | 248 | if (keyCode3 == 0xFF) |
WiredHome | 75:ca78388cfd77 | 249 | key = pKeyMap[0]; // Key value 0 |
WiredHome | 75:ca78388cfd77 | 250 | else { |
WiredHome | 75:ca78388cfd77 | 251 | row = (keyCode3 >> 4) & 0x03; |
WiredHome | 75:ca78388cfd77 | 252 | col = (keyCode3 & 7); |
WiredHome | 75:ca78388cfd77 | 253 | key = row * 5 + col + 1; // Keys value 1 - 20 |
WiredHome | 75:ca78388cfd77 | 254 | if (key > 21) { |
WiredHome | 75:ca78388cfd77 | 255 | key = 21; |
WiredHome | 75:ca78388cfd77 | 256 | } |
WiredHome | 75:ca78388cfd77 | 257 | key = pKeyMap[key]; |
WiredHome | 75:ca78388cfd77 | 258 | key |= (keyCode3 & 0x80); // combine the key held flag |
WiredHome | 75:ca78388cfd77 | 259 | } |
WiredHome | 77:9206c13aa527 | 260 | #if GETC_DEV // for Development only |
WiredHome | 75:ca78388cfd77 | 261 | SetTextCursor(0, 20); |
WiredHome | 75:ca78388cfd77 | 262 | printf(" Reg: %02x\r\n", keyNumReg); |
WiredHome | 75:ca78388cfd77 | 263 | printf(" key1: %02x\r\n", keyCode1); |
WiredHome | 75:ca78388cfd77 | 264 | printf(" key2: %02x\r\n", keyCode2); |
WiredHome | 75:ca78388cfd77 | 265 | printf(" key3: %02x\r\n", keyCode3); |
WiredHome | 75:ca78388cfd77 | 266 | printf(" count: %02X\r\n", count); |
WiredHome | 75:ca78388cfd77 | 267 | printf(" key: %02X\r\n", key); |
WiredHome | 77:9206c13aa527 | 268 | #endif |
WiredHome | 75:ca78388cfd77 | 269 | WriteCommand(0xF1, 0x10); // Clear KS status |
WiredHome | 75:ca78388cfd77 | 270 | return key; |
WiredHome | 71:dcac8efd842d | 271 | } |
WiredHome | 71:dcac8efd842d | 272 | |
WiredHome | 19:3f82c1161fd2 | 273 | #ifdef PERF_METRICS |
WiredHome | 19:3f82c1161fd2 | 274 | void RA8875::ClearPerformance() |
WiredHome | 19:3f82c1161fd2 | 275 | { |
WiredHome | 19:3f82c1161fd2 | 276 | for (int i=0; i<METRICCOUNT; i++) |
WiredHome | 19:3f82c1161fd2 | 277 | metrics[i] = 0; |
WiredHome | 75:ca78388cfd77 | 278 | idletime_usec = 0; |
WiredHome | 19:3f82c1161fd2 | 279 | } |
WiredHome | 19:3f82c1161fd2 | 280 | |
WiredHome | 19:3f82c1161fd2 | 281 | void RA8875::RegisterPerformance(method_e method) |
WiredHome | 19:3f82c1161fd2 | 282 | { |
WiredHome | 19:3f82c1161fd2 | 283 | unsigned long elapsed = performance.read_us(); |
WiredHome | 73:f22a18707b5e | 284 | |
WiredHome | 19:3f82c1161fd2 | 285 | if (method < METRICCOUNT && elapsed > metrics[method]) |
WiredHome | 19:3f82c1161fd2 | 286 | metrics[method] = elapsed; |
WiredHome | 19:3f82c1161fd2 | 287 | } |
WiredHome | 19:3f82c1161fd2 | 288 | |
WiredHome | 66:468a11f05580 | 289 | void RA8875::CountIdleTime(uint32_t t) |
WiredHome | 66:468a11f05580 | 290 | { |
WiredHome | 75:ca78388cfd77 | 291 | idletime_usec += t; |
WiredHome | 66:468a11f05580 | 292 | } |
WiredHome | 44:207594dece70 | 293 | |
WiredHome | 41:2956a0a221e5 | 294 | void RA8875::ReportPerformance(Serial & pc) |
WiredHome | 19:3f82c1161fd2 | 295 | { |
WiredHome | 41:2956a0a221e5 | 296 | pc.printf("\r\nPerformance Metrics\r\n"); |
WiredHome | 19:3f82c1161fd2 | 297 | for (int i=0; i<METRICCOUNT; i++) { |
WiredHome | 41:2956a0a221e5 | 298 | pc.printf("%10d uS %s\r\n", metrics[i], metricsName[i]); |
WiredHome | 66:468a11f05580 | 299 | } |
WiredHome | 75:ca78388cfd77 | 300 | pc.printf("%10d uS Idle time polling display for ready.\r\n", idletime_usec); |
WiredHome | 19:3f82c1161fd2 | 301 | } |
WiredHome | 19:3f82c1161fd2 | 302 | #endif |
WiredHome | 19:3f82c1161fd2 | 303 | |
WiredHome | 44:207594dece70 | 304 | |
WiredHome | 38:38d503b4fad6 | 305 | RetCode_t RA8875::WriteCommandW(uint8_t command, uint16_t data) |
WiredHome | 38:38d503b4fad6 | 306 | { |
WiredHome | 73:f22a18707b5e | 307 | #if 1 |
WiredHome | 38:38d503b4fad6 | 308 | WriteCommand(command, data & 0xFF); |
WiredHome | 38:38d503b4fad6 | 309 | WriteCommand(command+1, data >> 8); |
WiredHome | 73:f22a18707b5e | 310 | #else |
WiredHome | 41:2956a0a221e5 | 311 | // This should be a little faster, but doesn't work... |
WiredHome | 38:38d503b4fad6 | 312 | INFO("WriteCommandW(%02X, %04X)", command, data); |
WiredHome | 38:38d503b4fad6 | 313 | select(true); |
WiredHome | 38:38d503b4fad6 | 314 | spiwrite(0x80); |
WiredHome | 38:38d503b4fad6 | 315 | spiwrite(command); |
WiredHome | 41:2956a0a221e5 | 316 | //spiwrite(0x00); // dummy |
WiredHome | 38:38d503b4fad6 | 317 | spiwrite(data & 0xFF); |
WiredHome | 38:38d503b4fad6 | 318 | spiwrite(data >> 8); |
WiredHome | 38:38d503b4fad6 | 319 | select(false); |
WiredHome | 73:f22a18707b5e | 320 | #endif |
WiredHome | 38:38d503b4fad6 | 321 | return noerror; |
WiredHome | 38:38d503b4fad6 | 322 | } |
WiredHome | 38:38d503b4fad6 | 323 | |
WiredHome | 44:207594dece70 | 324 | |
WiredHome | 19:3f82c1161fd2 | 325 | RetCode_t RA8875::WriteCommand(unsigned char command, unsigned int data) |
WiredHome | 19:3f82c1161fd2 | 326 | { |
WiredHome | 19:3f82c1161fd2 | 327 | select(true); |
WiredHome | 41:2956a0a221e5 | 328 | spiwrite(0x80); // cmd: write command |
WiredHome | 19:3f82c1161fd2 | 329 | spiwrite(command); |
WiredHome | 19:3f82c1161fd2 | 330 | if (data <= 0xFF) { // only if in the valid range |
WiredHome | 19:3f82c1161fd2 | 331 | spiwrite(0x00); |
WiredHome | 19:3f82c1161fd2 | 332 | spiwrite(data); |
WiredHome | 19:3f82c1161fd2 | 333 | } |
WiredHome | 19:3f82c1161fd2 | 334 | select(false); |
WiredHome | 19:3f82c1161fd2 | 335 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 336 | } |
WiredHome | 19:3f82c1161fd2 | 337 | |
WiredHome | 44:207594dece70 | 338 | |
WiredHome | 38:38d503b4fad6 | 339 | RetCode_t RA8875::WriteDataW(uint16_t data) |
WiredHome | 38:38d503b4fad6 | 340 | { |
WiredHome | 38:38d503b4fad6 | 341 | select(true); |
WiredHome | 41:2956a0a221e5 | 342 | spiwrite(0x00); // cmd: write data |
WiredHome | 38:38d503b4fad6 | 343 | spiwrite(data & 0xFF); |
WiredHome | 38:38d503b4fad6 | 344 | spiwrite(data >> 8); |
WiredHome | 38:38d503b4fad6 | 345 | select(false); |
WiredHome | 38:38d503b4fad6 | 346 | return noerror; |
WiredHome | 38:38d503b4fad6 | 347 | } |
WiredHome | 38:38d503b4fad6 | 348 | |
WiredHome | 44:207594dece70 | 349 | |
WiredHome | 19:3f82c1161fd2 | 350 | RetCode_t RA8875::WriteData(unsigned char data) |
WiredHome | 19:3f82c1161fd2 | 351 | { |
WiredHome | 19:3f82c1161fd2 | 352 | select(true); |
WiredHome | 19:3f82c1161fd2 | 353 | spiwrite(0x00); |
WiredHome | 19:3f82c1161fd2 | 354 | spiwrite(data); |
WiredHome | 19:3f82c1161fd2 | 355 | select(false); |
WiredHome | 19:3f82c1161fd2 | 356 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 357 | } |
WiredHome | 19:3f82c1161fd2 | 358 | |
WiredHome | 44:207594dece70 | 359 | |
WiredHome | 19:3f82c1161fd2 | 360 | unsigned char RA8875::ReadCommand(unsigned char command) |
WiredHome | 19:3f82c1161fd2 | 361 | { |
WiredHome | 19:3f82c1161fd2 | 362 | WriteCommand(command); |
WiredHome | 19:3f82c1161fd2 | 363 | return ReadData(); |
WiredHome | 19:3f82c1161fd2 | 364 | } |
WiredHome | 19:3f82c1161fd2 | 365 | |
WiredHome | 44:207594dece70 | 366 | |
WiredHome | 19:3f82c1161fd2 | 367 | unsigned char RA8875::ReadData(void) |
WiredHome | 19:3f82c1161fd2 | 368 | { |
WiredHome | 19:3f82c1161fd2 | 369 | unsigned char data; |
WiredHome | 73:f22a18707b5e | 370 | |
WiredHome | 19:3f82c1161fd2 | 371 | select(true); |
WiredHome | 19:3f82c1161fd2 | 372 | spiwrite(0x40); |
WiredHome | 19:3f82c1161fd2 | 373 | data = spiread(); |
WiredHome | 19:3f82c1161fd2 | 374 | select(false); |
WiredHome | 19:3f82c1161fd2 | 375 | return data; |
WiredHome | 19:3f82c1161fd2 | 376 | } |
WiredHome | 19:3f82c1161fd2 | 377 | |
WiredHome | 44:207594dece70 | 378 | |
WiredHome | 41:2956a0a221e5 | 379 | uint16_t RA8875::ReadDataW(void) |
WiredHome | 41:2956a0a221e5 | 380 | { |
WiredHome | 41:2956a0a221e5 | 381 | uint16_t data; |
WiredHome | 73:f22a18707b5e | 382 | |
WiredHome | 41:2956a0a221e5 | 383 | select(true); |
WiredHome | 41:2956a0a221e5 | 384 | spiwrite(0x40); |
WiredHome | 41:2956a0a221e5 | 385 | data = spiread(); |
WiredHome | 41:2956a0a221e5 | 386 | data |= (spiread() << 8); |
WiredHome | 41:2956a0a221e5 | 387 | select(false); |
WiredHome | 41:2956a0a221e5 | 388 | return data; |
WiredHome | 41:2956a0a221e5 | 389 | } |
WiredHome | 41:2956a0a221e5 | 390 | |
WiredHome | 44:207594dece70 | 391 | |
WiredHome | 19:3f82c1161fd2 | 392 | unsigned char RA8875::ReadStatus(void) |
WiredHome | 19:3f82c1161fd2 | 393 | { |
WiredHome | 19:3f82c1161fd2 | 394 | unsigned char data; |
WiredHome | 73:f22a18707b5e | 395 | |
WiredHome | 19:3f82c1161fd2 | 396 | select(true); |
WiredHome | 66:468a11f05580 | 397 | spiwrite(0xC0); // These two bits are for the special "Status Read" [STSR] |
WiredHome | 19:3f82c1161fd2 | 398 | data = spiread(); |
WiredHome | 19:3f82c1161fd2 | 399 | select(false); |
WiredHome | 19:3f82c1161fd2 | 400 | return data; |
WiredHome | 19:3f82c1161fd2 | 401 | } |
WiredHome | 19:3f82c1161fd2 | 402 | |
WiredHome | 66:468a11f05580 | 403 | /// @todo add a timeout and return false, but how long |
WiredHome | 66:468a11f05580 | 404 | /// to wait since some operations can be very long. |
WiredHome | 66:468a11f05580 | 405 | bool RA8875::_WaitWhileBusy(uint8_t mask) |
WiredHome | 66:468a11f05580 | 406 | { |
WiredHome | 66:468a11f05580 | 407 | int i = 20000/POLLWAITuSec; // 20 msec max |
WiredHome | 66:468a11f05580 | 408 | |
WiredHome | 67:9f834f0ff97d | 409 | while (i-- && ReadStatus() & mask) { |
WiredHome | 66:468a11f05580 | 410 | wait_us(POLLWAITuSec); |
WiredHome | 68:ab08efabfc88 | 411 | COUNTIDLETIME(POLLWAITuSec); |
WiredHome | 67:9f834f0ff97d | 412 | } |
WiredHome | 66:468a11f05580 | 413 | if (i) |
WiredHome | 66:468a11f05580 | 414 | return true; |
WiredHome | 66:468a11f05580 | 415 | else |
WiredHome | 66:468a11f05580 | 416 | return false; |
WiredHome | 66:468a11f05580 | 417 | } |
WiredHome | 66:468a11f05580 | 418 | |
WiredHome | 66:468a11f05580 | 419 | /// @todo add a timeout and return false, but how long |
WiredHome | 66:468a11f05580 | 420 | /// to wait since some operations can be very long. |
WiredHome | 66:468a11f05580 | 421 | bool RA8875::_WaitWhileReg(uint8_t reg, uint8_t mask) |
WiredHome | 66:468a11f05580 | 422 | { |
WiredHome | 66:468a11f05580 | 423 | int i = 20000/POLLWAITuSec; // 20 msec max |
WiredHome | 66:468a11f05580 | 424 | |
WiredHome | 67:9f834f0ff97d | 425 | while (i-- && ReadCommand(reg) & mask) { |
WiredHome | 66:468a11f05580 | 426 | wait_us(POLLWAITuSec); |
WiredHome | 68:ab08efabfc88 | 427 | COUNTIDLETIME(POLLWAITuSec); |
WiredHome | 67:9f834f0ff97d | 428 | } |
WiredHome | 66:468a11f05580 | 429 | if (i) |
WiredHome | 66:468a11f05580 | 430 | return true; |
WiredHome | 66:468a11f05580 | 431 | else |
WiredHome | 66:468a11f05580 | 432 | return false; |
WiredHome | 66:468a11f05580 | 433 | } |
WiredHome | 66:468a11f05580 | 434 | |
WiredHome | 66:468a11f05580 | 435 | |
WiredHome | 44:207594dece70 | 436 | |
WiredHome | 37:f19b7e7449dc | 437 | dim_t RA8875::fontwidth(void) |
WiredHome | 19:3f82c1161fd2 | 438 | { |
WiredHome | 19:3f82c1161fd2 | 439 | if (font == NULL) |
WiredHome | 55:dfbabef7003e | 440 | return (((ReadCommand(0x22) >> 2) & 0x3) + 1) * 8; |
WiredHome | 19:3f82c1161fd2 | 441 | else |
WiredHome | 29:422616aa04bd | 442 | return font[1]; |
WiredHome | 19:3f82c1161fd2 | 443 | } |
WiredHome | 19:3f82c1161fd2 | 444 | |
WiredHome | 44:207594dece70 | 445 | |
WiredHome | 37:f19b7e7449dc | 446 | dim_t RA8875::fontheight(void) |
WiredHome | 19:3f82c1161fd2 | 447 | { |
WiredHome | 19:3f82c1161fd2 | 448 | if (font == NULL) |
WiredHome | 23:a50ded45dbaf | 449 | return (((ReadCommand(0x22) >> 0) & 0x3) + 1) * 16; |
WiredHome | 19:3f82c1161fd2 | 450 | else |
WiredHome | 29:422616aa04bd | 451 | return font[2]; |
WiredHome | 19:3f82c1161fd2 | 452 | } |
WiredHome | 19:3f82c1161fd2 | 453 | |
WiredHome | 44:207594dece70 | 454 | |
WiredHome | 37:f19b7e7449dc | 455 | RetCode_t RA8875::locate(textloc_t column, textloc_t row) |
WiredHome | 19:3f82c1161fd2 | 456 | { |
WiredHome | 32:0e4f2ae512e2 | 457 | return SetTextCursor(column * fontwidth(), row * fontheight()); |
WiredHome | 19:3f82c1161fd2 | 458 | } |
WiredHome | 19:3f82c1161fd2 | 459 | |
WiredHome | 44:207594dece70 | 460 | |
WiredHome | 19:3f82c1161fd2 | 461 | int RA8875::columns(void) |
WiredHome | 19:3f82c1161fd2 | 462 | { |
WiredHome | 19:3f82c1161fd2 | 463 | return width() / fontwidth(); |
WiredHome | 19:3f82c1161fd2 | 464 | } |
WiredHome | 19:3f82c1161fd2 | 465 | |
WiredHome | 44:207594dece70 | 466 | |
WiredHome | 19:3f82c1161fd2 | 467 | int RA8875::rows(void) |
WiredHome | 19:3f82c1161fd2 | 468 | { |
WiredHome | 19:3f82c1161fd2 | 469 | return height() / fontheight(); |
WiredHome | 19:3f82c1161fd2 | 470 | } |
WiredHome | 19:3f82c1161fd2 | 471 | |
WiredHome | 44:207594dece70 | 472 | |
WiredHome | 38:38d503b4fad6 | 473 | dim_t RA8875::width(void) |
WiredHome | 19:3f82c1161fd2 | 474 | { |
WiredHome | 29:422616aa04bd | 475 | return (ReadCommand(0x14) + 1) * 8; |
WiredHome | 19:3f82c1161fd2 | 476 | } |
WiredHome | 19:3f82c1161fd2 | 477 | |
WiredHome | 44:207594dece70 | 478 | |
WiredHome | 38:38d503b4fad6 | 479 | dim_t RA8875::height(void) |
WiredHome | 19:3f82c1161fd2 | 480 | { |
WiredHome | 29:422616aa04bd | 481 | return (ReadCommand(0x19) | (ReadCommand(0x1A) << 8)) + 1; |
WiredHome | 19:3f82c1161fd2 | 482 | } |
WiredHome | 19:3f82c1161fd2 | 483 | |
WiredHome | 44:207594dece70 | 484 | |
WiredHome | 43:3becae133285 | 485 | dim_t RA8875::color_bpp(void) |
WiredHome | 43:3becae133285 | 486 | { |
WiredHome | 43:3becae133285 | 487 | if ((ReadCommand(0x10) & 0x0C) == 0x04) |
WiredHome | 43:3becae133285 | 488 | return 16; |
WiredHome | 43:3becae133285 | 489 | else |
WiredHome | 43:3becae133285 | 490 | return 8; |
WiredHome | 43:3becae133285 | 491 | } |
WiredHome | 43:3becae133285 | 492 | |
WiredHome | 44:207594dece70 | 493 | |
WiredHome | 37:f19b7e7449dc | 494 | RetCode_t RA8875::SetTextCursor(loc_t x, loc_t y) |
WiredHome | 19:3f82c1161fd2 | 495 | { |
WiredHome | 75:ca78388cfd77 | 496 | cursor_x = x; // set these values for non-internal fonts |
WiredHome | 75:ca78388cfd77 | 497 | cursor_y = y; |
WiredHome | 38:38d503b4fad6 | 498 | WriteCommandW(0x2A, x); |
WiredHome | 38:38d503b4fad6 | 499 | WriteCommandW(0x2C, y); |
WiredHome | 19:3f82c1161fd2 | 500 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 501 | } |
WiredHome | 19:3f82c1161fd2 | 502 | |
WiredHome | 44:207594dece70 | 503 | |
WiredHome | 37:f19b7e7449dc | 504 | loc_t RA8875::GetTextCursor_Y(void) |
WiredHome | 29:422616aa04bd | 505 | { |
WiredHome | 29:422616aa04bd | 506 | if (font == NULL) |
WiredHome | 29:422616aa04bd | 507 | return ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); |
WiredHome | 29:422616aa04bd | 508 | else |
WiredHome | 29:422616aa04bd | 509 | return cursor_y; |
WiredHome | 29:422616aa04bd | 510 | } |
WiredHome | 29:422616aa04bd | 511 | |
WiredHome | 44:207594dece70 | 512 | |
WiredHome | 37:f19b7e7449dc | 513 | loc_t RA8875::GetTextCursor_X(void) |
WiredHome | 29:422616aa04bd | 514 | { |
WiredHome | 29:422616aa04bd | 515 | if (font == NULL) |
WiredHome | 29:422616aa04bd | 516 | return ReadCommand(0x2A) | (ReadCommand(0x2B) << 8); |
WiredHome | 29:422616aa04bd | 517 | else |
WiredHome | 29:422616aa04bd | 518 | return cursor_x; |
WiredHome | 29:422616aa04bd | 519 | } |
WiredHome | 29:422616aa04bd | 520 | |
WiredHome | 44:207594dece70 | 521 | |
WiredHome | 24:8ca861acf12d | 522 | RetCode_t RA8875::SetTextCursorControl(cursor_t cursor, bool blink) |
WiredHome | 23:a50ded45dbaf | 523 | { |
WiredHome | 23:a50ded45dbaf | 524 | unsigned char mwcr0 = ReadCommand(0x40) & 0x0F; // retain direction, auto-increase |
WiredHome | 43:3becae133285 | 525 | unsigned char mwcr1 = ReadCommand(0x41) & 0x01; // retain currently selected layer |
WiredHome | 24:8ca861acf12d | 526 | unsigned char horz = 0; |
WiredHome | 24:8ca861acf12d | 527 | unsigned char vert = 0; |
WiredHome | 73:f22a18707b5e | 528 | |
WiredHome | 24:8ca861acf12d | 529 | mwcr0 |= 0x80; // text mode |
WiredHome | 24:8ca861acf12d | 530 | if (cursor != NOCURSOR) |
WiredHome | 24:8ca861acf12d | 531 | mwcr0 |= 0x40; // visible |
WiredHome | 23:a50ded45dbaf | 532 | if (blink) |
WiredHome | 24:8ca861acf12d | 533 | mwcr0 |= 0x20; // blink |
WiredHome | 23:a50ded45dbaf | 534 | WriteCommand(0x40, mwcr0); // configure the cursor |
WiredHome | 43:3becae133285 | 535 | WriteCommand(0x41, mwcr1); // close the graphics cursor |
WiredHome | 24:8ca861acf12d | 536 | WriteCommand(0x44, 0x1f); // The cursor flashing cycle |
WiredHome | 24:8ca861acf12d | 537 | switch (cursor) { |
WiredHome | 24:8ca861acf12d | 538 | case IBEAM: |
WiredHome | 24:8ca861acf12d | 539 | horz = 0x01; |
WiredHome | 24:8ca861acf12d | 540 | vert = 0x1F; |
WiredHome | 24:8ca861acf12d | 541 | break; |
WiredHome | 24:8ca861acf12d | 542 | case UNDER: |
WiredHome | 24:8ca861acf12d | 543 | horz = 0x07; |
WiredHome | 24:8ca861acf12d | 544 | vert = 0x01; |
WiredHome | 24:8ca861acf12d | 545 | break; |
WiredHome | 24:8ca861acf12d | 546 | case BLOCK: |
WiredHome | 24:8ca861acf12d | 547 | horz = 0x07; |
WiredHome | 24:8ca861acf12d | 548 | vert = 0x1F; |
WiredHome | 24:8ca861acf12d | 549 | break; |
WiredHome | 24:8ca861acf12d | 550 | case NOCURSOR: |
WiredHome | 24:8ca861acf12d | 551 | default: |
WiredHome | 24:8ca861acf12d | 552 | break; |
WiredHome | 24:8ca861acf12d | 553 | } |
WiredHome | 24:8ca861acf12d | 554 | WriteCommand(0x4e, horz); // The cursor size horz |
WiredHome | 24:8ca861acf12d | 555 | WriteCommand(0x4f, vert); // The cursor size vert |
WiredHome | 23:a50ded45dbaf | 556 | return noerror; |
WiredHome | 23:a50ded45dbaf | 557 | } |
WiredHome | 23:a50ded45dbaf | 558 | |
WiredHome | 44:207594dece70 | 559 | |
WiredHome | 19:3f82c1161fd2 | 560 | RetCode_t RA8875::SetTextFont(RA8875::font_t font) |
WiredHome | 19:3f82c1161fd2 | 561 | { |
WiredHome | 19:3f82c1161fd2 | 562 | if (/*font >= RA8875::ISO8859_1 && */ font <= RA8875::ISO8859_4) { |
WiredHome | 19:3f82c1161fd2 | 563 | WriteCommand(0x21, (unsigned int)(font)); |
WiredHome | 19:3f82c1161fd2 | 564 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 565 | } else { |
WiredHome | 19:3f82c1161fd2 | 566 | return bad_parameter; |
WiredHome | 19:3f82c1161fd2 | 567 | } |
WiredHome | 19:3f82c1161fd2 | 568 | } |
WiredHome | 19:3f82c1161fd2 | 569 | |
WiredHome | 44:207594dece70 | 570 | |
WiredHome | 19:3f82c1161fd2 | 571 | RetCode_t RA8875::SetTextFontControl(fill_t fillit, |
WiredHome | 73:f22a18707b5e | 572 | RA8875::font_angle_t angle, |
WiredHome | 73:f22a18707b5e | 573 | RA8875::HorizontalScale hScale, |
WiredHome | 73:f22a18707b5e | 574 | RA8875::VerticalScale vScale, |
WiredHome | 73:f22a18707b5e | 575 | RA8875::alignment_t alignment) |
WiredHome | 19:3f82c1161fd2 | 576 | { |
WiredHome | 73:f22a18707b5e | 577 | if (hScale >= 1 && hScale <= 4 && |
WiredHome | 73:f22a18707b5e | 578 | vScale >= 1 && vScale <= 4) { |
WiredHome | 19:3f82c1161fd2 | 579 | unsigned char x = 0; |
WiredHome | 73:f22a18707b5e | 580 | |
WiredHome | 19:3f82c1161fd2 | 581 | if (alignment == align_full) |
WiredHome | 19:3f82c1161fd2 | 582 | x |= 0x80; |
WiredHome | 19:3f82c1161fd2 | 583 | if (fillit == NOFILL) |
WiredHome | 19:3f82c1161fd2 | 584 | x |= 0x40; |
WiredHome | 19:3f82c1161fd2 | 585 | if (angle == rotated) |
WiredHome | 19:3f82c1161fd2 | 586 | x |= 0x10; |
WiredHome | 19:3f82c1161fd2 | 587 | x |= ((hScale - 1) << 2); |
WiredHome | 19:3f82c1161fd2 | 588 | x |= ((vScale - 1) << 0); |
WiredHome | 19:3f82c1161fd2 | 589 | WriteCommand(0x22, x); |
WiredHome | 19:3f82c1161fd2 | 590 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 591 | } else { |
WiredHome | 19:3f82c1161fd2 | 592 | return bad_parameter; |
WiredHome | 19:3f82c1161fd2 | 593 | } |
WiredHome | 19:3f82c1161fd2 | 594 | } |
WiredHome | 19:3f82c1161fd2 | 595 | |
WiredHome | 44:207594dece70 | 596 | |
WiredHome | 19:3f82c1161fd2 | 597 | RetCode_t RA8875::SetTextFontSize(RA8875::HorizontalScale hScale, RA8875::VerticalScale vScale) |
WiredHome | 19:3f82c1161fd2 | 598 | { |
WiredHome | 19:3f82c1161fd2 | 599 | unsigned char reg = ReadCommand(0x22); |
WiredHome | 73:f22a18707b5e | 600 | |
WiredHome | 40:04aa280dfa39 | 601 | if (vScale == -1) |
WiredHome | 40:04aa280dfa39 | 602 | vScale = hScale; |
WiredHome | 19:3f82c1161fd2 | 603 | if (hScale >= 1 && hScale <= 4 && vScale >= 1 && vScale <= 4) { |
WiredHome | 19:3f82c1161fd2 | 604 | reg &= 0xF0; // keep the high nibble as is. |
WiredHome | 19:3f82c1161fd2 | 605 | reg |= ((hScale - 1) << 2); |
WiredHome | 19:3f82c1161fd2 | 606 | reg |= ((vScale - 1) << 0); |
WiredHome | 19:3f82c1161fd2 | 607 | WriteCommand(0x22, reg); |
WiredHome | 19:3f82c1161fd2 | 608 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 609 | } else { |
WiredHome | 19:3f82c1161fd2 | 610 | return bad_parameter; |
WiredHome | 19:3f82c1161fd2 | 611 | } |
WiredHome | 19:3f82c1161fd2 | 612 | } |
WiredHome | 19:3f82c1161fd2 | 613 | |
WiredHome | 44:207594dece70 | 614 | |
WiredHome | 19:3f82c1161fd2 | 615 | int RA8875::_putc(int c) |
WiredHome | 19:3f82c1161fd2 | 616 | { |
WiredHome | 29:422616aa04bd | 617 | if (font == NULL) { |
WiredHome | 29:422616aa04bd | 618 | return _internal_putc(c); |
WiredHome | 29:422616aa04bd | 619 | } else { |
WiredHome | 29:422616aa04bd | 620 | return _external_putc(c); |
WiredHome | 29:422616aa04bd | 621 | } |
WiredHome | 29:422616aa04bd | 622 | } |
WiredHome | 29:422616aa04bd | 623 | |
WiredHome | 44:207594dece70 | 624 | |
WiredHome | 29:422616aa04bd | 625 | int RA8875::_external_putc(int c) |
WiredHome | 29:422616aa04bd | 626 | { |
WiredHome | 19:3f82c1161fd2 | 627 | if (c) { |
WiredHome | 19:3f82c1161fd2 | 628 | if (c == '\r') { |
WiredHome | 29:422616aa04bd | 629 | cursor_x = 0; |
WiredHome | 29:422616aa04bd | 630 | } else if (c == '\n') { |
WiredHome | 29:422616aa04bd | 631 | cursor_y += font[2]; |
WiredHome | 29:422616aa04bd | 632 | } else { |
WiredHome | 29:422616aa04bd | 633 | int advance = character(cursor_x, cursor_y, c); // advance tells us how many pixels we advanced |
WiredHome | 37:f19b7e7449dc | 634 | //INFO("x,y,advance %d,%d,%d", cursor_x, cursor_y, advance); |
WiredHome | 29:422616aa04bd | 635 | if (advance) { |
WiredHome | 29:422616aa04bd | 636 | cursor_x += advance; |
WiredHome | 29:422616aa04bd | 637 | if (cursor_x >= width()) { |
WiredHome | 29:422616aa04bd | 638 | cursor_x = 0; |
WiredHome | 29:422616aa04bd | 639 | cursor_y += font[2]; |
WiredHome | 29:422616aa04bd | 640 | if (cursor_y >= height()) { |
WiredHome | 29:422616aa04bd | 641 | cursor_y = 0; // @todo Should it scroll? |
WiredHome | 29:422616aa04bd | 642 | } |
WiredHome | 29:422616aa04bd | 643 | } |
WiredHome | 29:422616aa04bd | 644 | } |
WiredHome | 29:422616aa04bd | 645 | } |
WiredHome | 29:422616aa04bd | 646 | } |
WiredHome | 29:422616aa04bd | 647 | return c; |
WiredHome | 29:422616aa04bd | 648 | } |
WiredHome | 29:422616aa04bd | 649 | |
WiredHome | 44:207594dece70 | 650 | |
WiredHome | 29:422616aa04bd | 651 | int RA8875::_internal_putc(int c) |
WiredHome | 29:422616aa04bd | 652 | { |
WiredHome | 29:422616aa04bd | 653 | if (c) { |
WiredHome | 29:422616aa04bd | 654 | unsigned char mwcr0; |
WiredHome | 73:f22a18707b5e | 655 | |
WiredHome | 29:422616aa04bd | 656 | mwcr0 = ReadCommand(0x40); |
WiredHome | 29:422616aa04bd | 657 | if ((mwcr0 & 0x80) == 0x00) { |
WiredHome | 29:422616aa04bd | 658 | WriteCommand(0x40, 0x80 | mwcr0); // Put in Text mode if not already |
WiredHome | 29:422616aa04bd | 659 | } |
WiredHome | 29:422616aa04bd | 660 | if (c == '\r') { |
WiredHome | 37:f19b7e7449dc | 661 | loc_t x; |
WiredHome | 19:3f82c1161fd2 | 662 | x = ReadCommand(0x30) | (ReadCommand(0x31) << 8); // Left edge of active window |
WiredHome | 38:38d503b4fad6 | 663 | WriteCommandW(0x2A, x); |
WiredHome | 19:3f82c1161fd2 | 664 | } else if (c == '\n') { |
WiredHome | 37:f19b7e7449dc | 665 | loc_t y; |
WiredHome | 19:3f82c1161fd2 | 666 | y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); // current y location |
WiredHome | 19:3f82c1161fd2 | 667 | y += fontheight(); |
WiredHome | 47:d96a09269f91 | 668 | if (y >= height()) // @TODO after bottom of active window, then scroll window? |
WiredHome | 19:3f82c1161fd2 | 669 | y = 0; |
WiredHome | 38:38d503b4fad6 | 670 | WriteCommandW(0x2C, y); |
WiredHome | 19:3f82c1161fd2 | 671 | } else { |
WiredHome | 29:422616aa04bd | 672 | WriteCommand(0x02); // RA8875 Internal Fonts |
WiredHome | 29:422616aa04bd | 673 | select(true); |
WiredHome | 29:422616aa04bd | 674 | WriteData(c); |
WiredHome | 66:468a11f05580 | 675 | _WaitWhileBusy(0x80); |
WiredHome | 29:422616aa04bd | 676 | select(false); |
WiredHome | 19:3f82c1161fd2 | 677 | } |
WiredHome | 19:3f82c1161fd2 | 678 | } |
WiredHome | 19:3f82c1161fd2 | 679 | return c; |
WiredHome | 19:3f82c1161fd2 | 680 | } |
WiredHome | 19:3f82c1161fd2 | 681 | |
WiredHome | 44:207594dece70 | 682 | |
WiredHome | 32:0e4f2ae512e2 | 683 | RetCode_t RA8875::_StartGraphicsStream(void) |
WiredHome | 32:0e4f2ae512e2 | 684 | { |
WiredHome | 32:0e4f2ae512e2 | 685 | WriteCommand(0x40,0x00); // Graphics write mode |
WiredHome | 32:0e4f2ae512e2 | 686 | WriteCommand(0x02); // Prepare for streaming data |
WiredHome | 32:0e4f2ae512e2 | 687 | return noerror; |
WiredHome | 32:0e4f2ae512e2 | 688 | } |
WiredHome | 32:0e4f2ae512e2 | 689 | |
WiredHome | 44:207594dece70 | 690 | |
WiredHome | 32:0e4f2ae512e2 | 691 | RetCode_t RA8875::_EndGraphicsStream(void) |
WiredHome | 32:0e4f2ae512e2 | 692 | { |
WiredHome | 32:0e4f2ae512e2 | 693 | return noerror; |
WiredHome | 32:0e4f2ae512e2 | 694 | } |
WiredHome | 32:0e4f2ae512e2 | 695 | |
WiredHome | 44:207594dece70 | 696 | |
WiredHome | 55:dfbabef7003e | 697 | RetCode_t RA8875::_putp(color_t pixel) |
WiredHome | 32:0e4f2ae512e2 | 698 | { |
WiredHome | 38:38d503b4fad6 | 699 | WriteDataW((pixel>>8) | (pixel<<8)); |
WiredHome | 73:f22a18707b5e | 700 | return noerror; |
WiredHome | 32:0e4f2ae512e2 | 701 | } |
WiredHome | 29:422616aa04bd | 702 | |
WiredHome | 44:207594dece70 | 703 | |
WiredHome | 37:f19b7e7449dc | 704 | void RA8875::puts(loc_t x, loc_t y, const char * string) |
WiredHome | 19:3f82c1161fd2 | 705 | { |
WiredHome | 19:3f82c1161fd2 | 706 | SetTextCursor(x,y); |
WiredHome | 19:3f82c1161fd2 | 707 | puts(string); |
WiredHome | 19:3f82c1161fd2 | 708 | } |
WiredHome | 19:3f82c1161fd2 | 709 | |
WiredHome | 44:207594dece70 | 710 | |
WiredHome | 19:3f82c1161fd2 | 711 | void RA8875::puts(const char * string) |
WiredHome | 19:3f82c1161fd2 | 712 | { |
WiredHome | 29:422616aa04bd | 713 | unsigned char mwcr0 = ReadCommand(0x40); |
WiredHome | 73:f22a18707b5e | 714 | |
WiredHome | 37:f19b7e7449dc | 715 | if (font == NULL) { |
WiredHome | 37:f19b7e7449dc | 716 | if ((mwcr0 & 0x80) == 0x00) |
WiredHome | 37:f19b7e7449dc | 717 | WriteCommand(0x40,0x80); // Put in Text mode if not already |
WiredHome | 37:f19b7e7449dc | 718 | } else { |
WiredHome | 37:f19b7e7449dc | 719 | _StartGraphicsStream(); |
WiredHome | 37:f19b7e7449dc | 720 | } |
WiredHome | 19:3f82c1161fd2 | 721 | if (*string != '\0') { |
WiredHome | 73:f22a18707b5e | 722 | #if 1 |
WiredHome | 29:422616aa04bd | 723 | while (*string) { // @TODO calling individual _putc is slower... optimizations? |
WiredHome | 19:3f82c1161fd2 | 724 | _putc(*string++); |
WiredHome | 19:3f82c1161fd2 | 725 | } |
WiredHome | 73:f22a18707b5e | 726 | #else |
WiredHome | 19:3f82c1161fd2 | 727 | WriteCommand(0x02); |
WiredHome | 19:3f82c1161fd2 | 728 | select(true); |
WiredHome | 19:3f82c1161fd2 | 729 | while (*string != '\0') { |
WiredHome | 19:3f82c1161fd2 | 730 | WriteData(*string); |
WiredHome | 19:3f82c1161fd2 | 731 | ++string; |
WiredHome | 66:468a11f05580 | 732 | _WaitWhileBusy(0x80); |
WiredHome | 19:3f82c1161fd2 | 733 | } |
WiredHome | 19:3f82c1161fd2 | 734 | select(false); |
WiredHome | 73:f22a18707b5e | 735 | #endif |
WiredHome | 19:3f82c1161fd2 | 736 | } |
WiredHome | 37:f19b7e7449dc | 737 | if (font) |
WiredHome | 37:f19b7e7449dc | 738 | _EndGraphicsStream(); |
WiredHome | 19:3f82c1161fd2 | 739 | } |
WiredHome | 19:3f82c1161fd2 | 740 | |
WiredHome | 44:207594dece70 | 741 | |
WiredHome | 37:f19b7e7449dc | 742 | RetCode_t RA8875::SetGraphicsCursor(loc_t x, loc_t y) |
WiredHome | 19:3f82c1161fd2 | 743 | { |
WiredHome | 38:38d503b4fad6 | 744 | WriteCommandW(0x46, x); |
WiredHome | 38:38d503b4fad6 | 745 | WriteCommandW(0x48, y); |
WiredHome | 19:3f82c1161fd2 | 746 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 747 | } |
WiredHome | 19:3f82c1161fd2 | 748 | |
WiredHome | 44:207594dece70 | 749 | |
WiredHome | 41:2956a0a221e5 | 750 | RetCode_t RA8875::SetGraphicsCursorRead(loc_t x, loc_t y) |
WiredHome | 41:2956a0a221e5 | 751 | { |
WiredHome | 41:2956a0a221e5 | 752 | //WriteCommand(0x40, 0); // Graphics mode |
WiredHome | 41:2956a0a221e5 | 753 | //WriteCommand(0x45, 0); // left->right, top->bottom |
WiredHome | 41:2956a0a221e5 | 754 | WriteCommandW(0x4A, x); |
WiredHome | 41:2956a0a221e5 | 755 | WriteCommandW(0x4C, y); |
WiredHome | 41:2956a0a221e5 | 756 | return noerror; |
WiredHome | 41:2956a0a221e5 | 757 | } |
WiredHome | 41:2956a0a221e5 | 758 | |
WiredHome | 44:207594dece70 | 759 | |
WiredHome | 37:f19b7e7449dc | 760 | RetCode_t RA8875::window(loc_t x, loc_t y, dim_t width, dim_t height) |
WiredHome | 19:3f82c1161fd2 | 761 | { |
WiredHome | 37:f19b7e7449dc | 762 | GraphicsDisplay::window(x,y, width,height); |
WiredHome | 38:38d503b4fad6 | 763 | WriteCommandW(0x30, x); |
WiredHome | 38:38d503b4fad6 | 764 | WriteCommandW(0x32, y); |
WiredHome | 38:38d503b4fad6 | 765 | WriteCommandW(0x34, (x+width-1)); |
WiredHome | 38:38d503b4fad6 | 766 | WriteCommandW(0x36, (y+height-1)); |
WiredHome | 37:f19b7e7449dc | 767 | SetGraphicsCursor(x,y); |
WiredHome | 19:3f82c1161fd2 | 768 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 769 | } |
WiredHome | 19:3f82c1161fd2 | 770 | |
WiredHome | 44:207594dece70 | 771 | |
WiredHome | 61:8f3153bf0baa | 772 | RetCode_t RA8875::cls(uint16_t layers) |
WiredHome | 19:3f82c1161fd2 | 773 | { |
WiredHome | 61:8f3153bf0baa | 774 | RetCode_t ret; |
WiredHome | 73:f22a18707b5e | 775 | |
WiredHome | 19:3f82c1161fd2 | 776 | PERFORMANCE_RESET; |
WiredHome | 61:8f3153bf0baa | 777 | if (layers == 0) { |
WiredHome | 61:8f3153bf0baa | 778 | ret = clsw(FULLWINDOW); |
WiredHome | 61:8f3153bf0baa | 779 | ret = SetTextCursor(0,0); |
WiredHome | 61:8f3153bf0baa | 780 | } else if (layers > 3) { |
WiredHome | 61:8f3153bf0baa | 781 | ret = bad_parameter; |
WiredHome | 61:8f3153bf0baa | 782 | } else { |
WiredHome | 61:8f3153bf0baa | 783 | uint16_t prevLayer = GetDrawingLayer(); |
WiredHome | 61:8f3153bf0baa | 784 | if (layers & 1) { |
WiredHome | 61:8f3153bf0baa | 785 | SelectDrawingLayer(0); |
WiredHome | 61:8f3153bf0baa | 786 | clsw(FULLWINDOW); |
WiredHome | 61:8f3153bf0baa | 787 | } |
WiredHome | 61:8f3153bf0baa | 788 | if (layers & 2) { |
WiredHome | 61:8f3153bf0baa | 789 | SelectDrawingLayer(1); |
WiredHome | 61:8f3153bf0baa | 790 | clsw(FULLWINDOW); |
WiredHome | 61:8f3153bf0baa | 791 | } |
WiredHome | 61:8f3153bf0baa | 792 | ret = SelectDrawingLayer(prevLayer); |
WiredHome | 61:8f3153bf0baa | 793 | } |
WiredHome | 19:3f82c1161fd2 | 794 | REGISTERPERFORMANCE(PRF_CLS); |
WiredHome | 61:8f3153bf0baa | 795 | return ret; |
WiredHome | 19:3f82c1161fd2 | 796 | } |
WiredHome | 19:3f82c1161fd2 | 797 | |
WiredHome | 44:207594dece70 | 798 | |
WiredHome | 19:3f82c1161fd2 | 799 | RetCode_t RA8875::clsw(RA8875::Region_t region) |
WiredHome | 19:3f82c1161fd2 | 800 | { |
WiredHome | 19:3f82c1161fd2 | 801 | PERFORMANCE_RESET; |
WiredHome | 19:3f82c1161fd2 | 802 | WriteCommand(0x8E, (region == ACTIVEWINDOW) ? 0xC0 : 0x80); |
WiredHome | 66:468a11f05580 | 803 | _WaitWhileReg(0x8E, 0x80); |
WiredHome | 19:3f82c1161fd2 | 804 | REGISTERPERFORMANCE(PRF_CLS); |
WiredHome | 19:3f82c1161fd2 | 805 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 806 | } |
WiredHome | 19:3f82c1161fd2 | 807 | |
WiredHome | 44:207594dece70 | 808 | |
WiredHome | 37:f19b7e7449dc | 809 | RetCode_t RA8875::pixel(loc_t x, loc_t y, color_t color) |
WiredHome | 19:3f82c1161fd2 | 810 | { |
WiredHome | 62:ba5d33438fda | 811 | RetCode_t ret; |
WiredHome | 73:f22a18707b5e | 812 | |
WiredHome | 62:ba5d33438fda | 813 | PERFORMANCE_RESET; |
WiredHome | 73:f22a18707b5e | 814 | #if 1 |
WiredHome | 62:ba5d33438fda | 815 | ret = pixelStream(&color, 1, x,y); |
WiredHome | 73:f22a18707b5e | 816 | #else |
WiredHome | 19:3f82c1161fd2 | 817 | foreground(color); |
WiredHome | 62:ba5d33438fda | 818 | ret = pixel(x,y); |
WiredHome | 73:f22a18707b5e | 819 | #endif |
WiredHome | 62:ba5d33438fda | 820 | REGISTERPERFORMANCE(PRF_DRAWPIXEL); |
WiredHome | 62:ba5d33438fda | 821 | return ret; |
WiredHome | 19:3f82c1161fd2 | 822 | } |
WiredHome | 19:3f82c1161fd2 | 823 | |
WiredHome | 44:207594dece70 | 824 | |
WiredHome | 37:f19b7e7449dc | 825 | RetCode_t RA8875::pixel(loc_t x, loc_t y) |
WiredHome | 19:3f82c1161fd2 | 826 | { |
WiredHome | 19:3f82c1161fd2 | 827 | RetCode_t ret; |
WiredHome | 73:f22a18707b5e | 828 | |
WiredHome | 19:3f82c1161fd2 | 829 | PERFORMANCE_RESET; |
WiredHome | 19:3f82c1161fd2 | 830 | color_t color = GetForeColor(); |
WiredHome | 73:f22a18707b5e | 831 | #if 1 |
WiredHome | 62:ba5d33438fda | 832 | ret = pixelStream(&color, 1, x, y); |
WiredHome | 73:f22a18707b5e | 833 | #else |
WiredHome | 19:3f82c1161fd2 | 834 | WriteCommand(0x40,0x00); // Graphics write mode |
WiredHome | 32:0e4f2ae512e2 | 835 | SetGraphicsCursor(x, y); |
WiredHome | 38:38d503b4fad6 | 836 | WriteCommand(0x02); |
WiredHome | 38:38d503b4fad6 | 837 | WriteDataW(color); |
WiredHome | 19:3f82c1161fd2 | 838 | ret = noerror; |
WiredHome | 73:f22a18707b5e | 839 | #endif |
WiredHome | 41:2956a0a221e5 | 840 | REGISTERPERFORMANCE(PRF_DRAWPIXEL); |
WiredHome | 19:3f82c1161fd2 | 841 | return ret; |
WiredHome | 19:3f82c1161fd2 | 842 | } |
WiredHome | 19:3f82c1161fd2 | 843 | |
WiredHome | 44:207594dece70 | 844 | |
WiredHome | 41:2956a0a221e5 | 845 | RetCode_t RA8875::pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y) |
WiredHome | 41:2956a0a221e5 | 846 | { |
WiredHome | 41:2956a0a221e5 | 847 | PERFORMANCE_RESET; |
WiredHome | 41:2956a0a221e5 | 848 | WriteCommand(0x40,0x00); // Graphics write mode |
WiredHome | 41:2956a0a221e5 | 849 | SetGraphicsCursor(x, y); |
WiredHome | 41:2956a0a221e5 | 850 | WriteCommand(0x02); |
WiredHome | 41:2956a0a221e5 | 851 | select(true); |
WiredHome | 41:2956a0a221e5 | 852 | spiwrite(0x00); // Cmd: write data |
WiredHome | 41:2956a0a221e5 | 853 | while (count--) { |
WiredHome | 41:2956a0a221e5 | 854 | spiwrite(*p >> 8); |
WiredHome | 41:2956a0a221e5 | 855 | spiwrite(*p & 0xFF); |
WiredHome | 41:2956a0a221e5 | 856 | p++; |
WiredHome | 41:2956a0a221e5 | 857 | } |
WiredHome | 41:2956a0a221e5 | 858 | select(false); |
WiredHome | 41:2956a0a221e5 | 859 | REGISTERPERFORMANCE(PRF_PIXELSTREAM); |
WiredHome | 41:2956a0a221e5 | 860 | return(noerror); |
WiredHome | 41:2956a0a221e5 | 861 | } |
WiredHome | 41:2956a0a221e5 | 862 | |
WiredHome | 44:207594dece70 | 863 | |
WiredHome | 41:2956a0a221e5 | 864 | color_t RA8875::getPixel(loc_t x, loc_t y) |
WiredHome | 41:2956a0a221e5 | 865 | { |
WiredHome | 41:2956a0a221e5 | 866 | color_t pixel; |
WiredHome | 73:f22a18707b5e | 867 | |
WiredHome | 41:2956a0a221e5 | 868 | PERFORMANCE_RESET; |
WiredHome | 41:2956a0a221e5 | 869 | //WriteCommand(0x45,0x00); // read left->right, top->bottom |
WiredHome | 41:2956a0a221e5 | 870 | WriteCommand(0x40,0x00); // Graphics write mode |
WiredHome | 41:2956a0a221e5 | 871 | SetGraphicsCursorRead(x, y); |
WiredHome | 41:2956a0a221e5 | 872 | WriteCommand(0x02); |
WiredHome | 41:2956a0a221e5 | 873 | select(true); |
WiredHome | 41:2956a0a221e5 | 874 | spiwrite(0x40); // Cmd: read data |
WiredHome | 41:2956a0a221e5 | 875 | spiwrite(0x00); // dummy read |
WiredHome | 41:2956a0a221e5 | 876 | pixel = spiread(); |
WiredHome | 41:2956a0a221e5 | 877 | pixel |= (spiread() << 8); |
WiredHome | 41:2956a0a221e5 | 878 | select(false); |
WiredHome | 41:2956a0a221e5 | 879 | REGISTERPERFORMANCE(PRF_READPIXEL); |
WiredHome | 41:2956a0a221e5 | 880 | return pixel; |
WiredHome | 41:2956a0a221e5 | 881 | } |
WiredHome | 41:2956a0a221e5 | 882 | |
WiredHome | 44:207594dece70 | 883 | |
WiredHome | 41:2956a0a221e5 | 884 | RetCode_t RA8875::getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y) |
WiredHome | 41:2956a0a221e5 | 885 | { |
WiredHome | 41:2956a0a221e5 | 886 | color_t pixel; |
WiredHome | 73:f22a18707b5e | 887 | |
WiredHome | 41:2956a0a221e5 | 888 | PERFORMANCE_RESET; |
WiredHome | 41:2956a0a221e5 | 889 | //WriteCommand(0x45,0x00); // read left->right, top->bottom |
WiredHome | 41:2956a0a221e5 | 890 | WriteCommand(0x40,0x00); // Graphics write mode |
WiredHome | 41:2956a0a221e5 | 891 | SetGraphicsCursorRead(x, y); |
WiredHome | 41:2956a0a221e5 | 892 | WriteCommand(0x02); |
WiredHome | 41:2956a0a221e5 | 893 | select(true); |
WiredHome | 41:2956a0a221e5 | 894 | spiwrite(0x40); // Cmd: read data |
WiredHome | 41:2956a0a221e5 | 895 | spiwrite(0x00); // dummy read |
WiredHome | 41:2956a0a221e5 | 896 | while (count--) { |
WiredHome | 41:2956a0a221e5 | 897 | pixel = spiread(); |
WiredHome | 41:2956a0a221e5 | 898 | pixel |= (spiread() << 8); |
WiredHome | 41:2956a0a221e5 | 899 | *p++ = pixel; |
WiredHome | 41:2956a0a221e5 | 900 | } |
WiredHome | 41:2956a0a221e5 | 901 | select(false); |
WiredHome | 41:2956a0a221e5 | 902 | REGISTERPERFORMANCE(PRF_READPIXELSTREAM); |
WiredHome | 41:2956a0a221e5 | 903 | return noerror; |
WiredHome | 41:2956a0a221e5 | 904 | } |
WiredHome | 41:2956a0a221e5 | 905 | |
WiredHome | 44:207594dece70 | 906 | |
WiredHome | 37:f19b7e7449dc | 907 | RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color) |
WiredHome | 19:3f82c1161fd2 | 908 | { |
WiredHome | 19:3f82c1161fd2 | 909 | foreground(color); |
WiredHome | 19:3f82c1161fd2 | 910 | return line(x1,y1,x2,y2); |
WiredHome | 19:3f82c1161fd2 | 911 | } |
WiredHome | 19:3f82c1161fd2 | 912 | |
WiredHome | 44:207594dece70 | 913 | |
WiredHome | 37:f19b7e7449dc | 914 | RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2) |
WiredHome | 19:3f82c1161fd2 | 915 | { |
WiredHome | 19:3f82c1161fd2 | 916 | PERFORMANCE_RESET; |
WiredHome | 62:ba5d33438fda | 917 | if (x1 == x2 && y1 == y2) { |
WiredHome | 60:2dfd574f63bd | 918 | pixel(x1, y1); |
WiredHome | 62:ba5d33438fda | 919 | } else { |
WiredHome | 60:2dfd574f63bd | 920 | WriteCommandW(0x91, x1); |
WiredHome | 60:2dfd574f63bd | 921 | WriteCommandW(0x93, y1); |
WiredHome | 60:2dfd574f63bd | 922 | WriteCommandW(0x95, x2); |
WiredHome | 60:2dfd574f63bd | 923 | WriteCommandW(0x97, y2); |
WiredHome | 60:2dfd574f63bd | 924 | unsigned char drawCmd = 0x00; // Line |
WiredHome | 60:2dfd574f63bd | 925 | WriteCommand(0x90, drawCmd); |
WiredHome | 60:2dfd574f63bd | 926 | WriteCommand(0x90, 0x80 + drawCmd); // Start drawing. |
WiredHome | 66:468a11f05580 | 927 | _WaitWhileReg(0x90, 0x80); |
WiredHome | 60:2dfd574f63bd | 928 | } |
WiredHome | 19:3f82c1161fd2 | 929 | REGISTERPERFORMANCE(PRF_DRAWLINE); |
WiredHome | 19:3f82c1161fd2 | 930 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 931 | } |
WiredHome | 19:3f82c1161fd2 | 932 | |
WiredHome | 44:207594dece70 | 933 | |
WiredHome | 73:f22a18707b5e | 934 | RetCode_t RA8875::fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, |
WiredHome | 73:f22a18707b5e | 935 | color_t color, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 936 | { |
WiredHome | 19:3f82c1161fd2 | 937 | return rect(x1,y1,x2,y2,color,fillit); |
WiredHome | 19:3f82c1161fd2 | 938 | } |
WiredHome | 19:3f82c1161fd2 | 939 | |
WiredHome | 44:207594dece70 | 940 | |
WiredHome | 73:f22a18707b5e | 941 | RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, |
WiredHome | 73:f22a18707b5e | 942 | color_t color, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 943 | { |
WiredHome | 19:3f82c1161fd2 | 944 | foreground(color); |
WiredHome | 19:3f82c1161fd2 | 945 | return rect(x1,y1,x2,y2,fillit); |
WiredHome | 19:3f82c1161fd2 | 946 | } |
WiredHome | 19:3f82c1161fd2 | 947 | |
WiredHome | 44:207594dece70 | 948 | |
WiredHome | 73:f22a18707b5e | 949 | RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, |
WiredHome | 73:f22a18707b5e | 950 | fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 951 | { |
WiredHome | 19:3f82c1161fd2 | 952 | PERFORMANCE_RESET; |
WiredHome | 19:3f82c1161fd2 | 953 | if (x1 == x2 && y1 == y2) { |
WiredHome | 19:3f82c1161fd2 | 954 | pixel(x1, y1); |
WiredHome | 19:3f82c1161fd2 | 955 | } else if (x1 == x2) { |
WiredHome | 19:3f82c1161fd2 | 956 | line(x1, y1, x2, y2); |
WiredHome | 19:3f82c1161fd2 | 957 | } else if (y1 == y2) { |
WiredHome | 19:3f82c1161fd2 | 958 | line(x1, y1, x2, y2); |
WiredHome | 19:3f82c1161fd2 | 959 | } else { |
WiredHome | 38:38d503b4fad6 | 960 | WriteCommandW(0x91, x1); |
WiredHome | 38:38d503b4fad6 | 961 | WriteCommandW(0x93, y1); |
WiredHome | 38:38d503b4fad6 | 962 | WriteCommandW(0x95, x2); |
WiredHome | 38:38d503b4fad6 | 963 | WriteCommandW(0x97, y2); |
WiredHome | 19:3f82c1161fd2 | 964 | unsigned char drawCmd = 0x10; // Rectangle |
WiredHome | 19:3f82c1161fd2 | 965 | if (fillit == FILL) |
WiredHome | 19:3f82c1161fd2 | 966 | drawCmd |= 0x20; |
WiredHome | 19:3f82c1161fd2 | 967 | WriteCommand(0x90, drawCmd); |
WiredHome | 19:3f82c1161fd2 | 968 | WriteCommand(0x90, 0x80 + drawCmd); // Start drawing. |
WiredHome | 66:468a11f05580 | 969 | _WaitWhileReg(0x90, 0x80); |
WiredHome | 19:3f82c1161fd2 | 970 | } |
WiredHome | 19:3f82c1161fd2 | 971 | REGISTERPERFORMANCE(PRF_DRAWRECTANGLE); |
WiredHome | 19:3f82c1161fd2 | 972 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 973 | } |
WiredHome | 19:3f82c1161fd2 | 974 | |
WiredHome | 44:207594dece70 | 975 | |
WiredHome | 73:f22a18707b5e | 976 | RetCode_t RA8875::fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, |
WiredHome | 73:f22a18707b5e | 977 | dim_t radius1, dim_t radius2, color_t color, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 978 | { |
WiredHome | 19:3f82c1161fd2 | 979 | foreground(color); |
WiredHome | 19:3f82c1161fd2 | 980 | return roundrect(x1,y1,x2,y2,radius1,radius2,fillit); |
WiredHome | 19:3f82c1161fd2 | 981 | } |
WiredHome | 19:3f82c1161fd2 | 982 | |
WiredHome | 44:207594dece70 | 983 | |
WiredHome | 73:f22a18707b5e | 984 | RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, |
WiredHome | 73:f22a18707b5e | 985 | dim_t radius1, dim_t radius2, color_t color, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 986 | { |
WiredHome | 19:3f82c1161fd2 | 987 | foreground(color); |
WiredHome | 19:3f82c1161fd2 | 988 | return roundrect(x1,y1,x2,y2,radius1,radius2,fillit); |
WiredHome | 19:3f82c1161fd2 | 989 | } |
WiredHome | 19:3f82c1161fd2 | 990 | |
WiredHome | 44:207594dece70 | 991 | |
WiredHome | 73:f22a18707b5e | 992 | RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, |
WiredHome | 73:f22a18707b5e | 993 | dim_t radius1, dim_t radius2, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 994 | { |
WiredHome | 19:3f82c1161fd2 | 995 | RetCode_t ret = noerror; |
WiredHome | 73:f22a18707b5e | 996 | |
WiredHome | 19:3f82c1161fd2 | 997 | PERFORMANCE_RESET; |
WiredHome | 21:3c1efb192927 | 998 | if (x1 > x2 || y1 > y2 || (radius1 > (x2-x1)/2) || (radius2 > (y2-y1)/2) ) { |
WiredHome | 21:3c1efb192927 | 999 | ret = bad_parameter; |
WiredHome | 21:3c1efb192927 | 1000 | } else if (x1 == x2 && y1 == y2) { |
WiredHome | 19:3f82c1161fd2 | 1001 | pixel(x1, y1); |
WiredHome | 19:3f82c1161fd2 | 1002 | } else if (x1 == x2) { |
WiredHome | 19:3f82c1161fd2 | 1003 | line(x1, y1, x2, y2); |
WiredHome | 19:3f82c1161fd2 | 1004 | } else if (y1 == y2) { |
WiredHome | 19:3f82c1161fd2 | 1005 | line(x1, y1, x2, y2); |
WiredHome | 19:3f82c1161fd2 | 1006 | } else { |
WiredHome | 38:38d503b4fad6 | 1007 | WriteCommandW(0x91, x1); |
WiredHome | 38:38d503b4fad6 | 1008 | WriteCommandW(0x93, y1); |
WiredHome | 38:38d503b4fad6 | 1009 | WriteCommandW(0x95, x2); |
WiredHome | 38:38d503b4fad6 | 1010 | WriteCommandW(0x97, y2); |
WiredHome | 38:38d503b4fad6 | 1011 | WriteCommandW(0xA1, radius1); |
WiredHome | 38:38d503b4fad6 | 1012 | WriteCommandW(0xA3, radius2); |
WiredHome | 21:3c1efb192927 | 1013 | // Should not need this... |
WiredHome | 38:38d503b4fad6 | 1014 | WriteCommandW(0xA5, 0); |
WiredHome | 38:38d503b4fad6 | 1015 | WriteCommandW(0xA7, 0); |
WiredHome | 19:3f82c1161fd2 | 1016 | unsigned char drawCmd = 0x20; // Rounded Rectangle |
WiredHome | 19:3f82c1161fd2 | 1017 | if (fillit == FILL) |
WiredHome | 19:3f82c1161fd2 | 1018 | drawCmd |= 0x40; |
WiredHome | 19:3f82c1161fd2 | 1019 | WriteCommand(0xA0, drawCmd); |
WiredHome | 19:3f82c1161fd2 | 1020 | WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing. |
WiredHome | 66:468a11f05580 | 1021 | _WaitWhileReg(0xA0, 0x80); |
WiredHome | 19:3f82c1161fd2 | 1022 | } |
WiredHome | 19:3f82c1161fd2 | 1023 | REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE); |
WiredHome | 19:3f82c1161fd2 | 1024 | return ret; |
WiredHome | 19:3f82c1161fd2 | 1025 | } |
WiredHome | 19:3f82c1161fd2 | 1026 | |
WiredHome | 44:207594dece70 | 1027 | |
WiredHome | 73:f22a18707b5e | 1028 | RetCode_t RA8875::triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, |
WiredHome | 73:f22a18707b5e | 1029 | loc_t x3, loc_t y3, color_t color, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 1030 | { |
WiredHome | 20:6e2e4a8372eb | 1031 | RetCode_t ret; |
WiredHome | 20:6e2e4a8372eb | 1032 | |
WiredHome | 19:3f82c1161fd2 | 1033 | foreground(color); |
WiredHome | 20:6e2e4a8372eb | 1034 | ret = triangle(x1,y1,x2,y2,x3,y3,fillit); |
WiredHome | 20:6e2e4a8372eb | 1035 | return ret; |
WiredHome | 19:3f82c1161fd2 | 1036 | } |
WiredHome | 19:3f82c1161fd2 | 1037 | |
WiredHome | 44:207594dece70 | 1038 | |
WiredHome | 73:f22a18707b5e | 1039 | RetCode_t RA8875::filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, |
WiredHome | 73:f22a18707b5e | 1040 | loc_t x3, loc_t y3, color_t color, fill_t fillit) |
WiredHome | 73:f22a18707b5e | 1041 | { |
WiredHome | 73:f22a18707b5e | 1042 | RetCode_t ret; |
WiredHome | 73:f22a18707b5e | 1043 | |
WiredHome | 73:f22a18707b5e | 1044 | foreground(color); |
WiredHome | 73:f22a18707b5e | 1045 | ret = triangle(x1,y1,x2,y2,x3,y3,fillit); |
WiredHome | 73:f22a18707b5e | 1046 | return ret; |
WiredHome | 73:f22a18707b5e | 1047 | } |
WiredHome | 73:f22a18707b5e | 1048 | |
WiredHome | 73:f22a18707b5e | 1049 | |
WiredHome | 73:f22a18707b5e | 1050 | RetCode_t RA8875::triangle(loc_t x1, loc_t y1 ,loc_t x2, loc_t y2, |
WiredHome | 73:f22a18707b5e | 1051 | loc_t x3, loc_t y3, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 1052 | { |
WiredHome | 19:3f82c1161fd2 | 1053 | RetCode_t ret = noerror; |
WiredHome | 73:f22a18707b5e | 1054 | |
WiredHome | 19:3f82c1161fd2 | 1055 | PERFORMANCE_RESET; |
WiredHome | 19:3f82c1161fd2 | 1056 | if (x1 == x2 && y1 == y2 && x1 == x3 && y1 == y3) { |
WiredHome | 19:3f82c1161fd2 | 1057 | pixel(x1, y1); |
WiredHome | 19:3f82c1161fd2 | 1058 | } else { |
WiredHome | 38:38d503b4fad6 | 1059 | WriteCommandW(0x91, x1); |
WiredHome | 38:38d503b4fad6 | 1060 | WriteCommandW(0x93, y1); |
WiredHome | 38:38d503b4fad6 | 1061 | WriteCommandW(0x95, x2); |
WiredHome | 38:38d503b4fad6 | 1062 | WriteCommandW(0x97, y2); |
WiredHome | 38:38d503b4fad6 | 1063 | WriteCommandW(0xA9, x3); |
WiredHome | 38:38d503b4fad6 | 1064 | WriteCommandW(0xAB, y3); |
WiredHome | 19:3f82c1161fd2 | 1065 | unsigned char drawCmd = 0x01; // Triangle |
WiredHome | 19:3f82c1161fd2 | 1066 | if (fillit == FILL) |
WiredHome | 19:3f82c1161fd2 | 1067 | drawCmd |= 0x20; |
WiredHome | 19:3f82c1161fd2 | 1068 | WriteCommand(0x90, drawCmd); |
WiredHome | 19:3f82c1161fd2 | 1069 | WriteCommand(0x90, 0x80 + drawCmd); // Start drawing. |
WiredHome | 66:468a11f05580 | 1070 | _WaitWhileReg(0x90, 0x80); |
WiredHome | 19:3f82c1161fd2 | 1071 | } |
WiredHome | 19:3f82c1161fd2 | 1072 | REGISTERPERFORMANCE(PRF_DRAWTRIANGLE); |
WiredHome | 19:3f82c1161fd2 | 1073 | return ret; |
WiredHome | 19:3f82c1161fd2 | 1074 | } |
WiredHome | 19:3f82c1161fd2 | 1075 | |
WiredHome | 73:f22a18707b5e | 1076 | RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius, |
WiredHome | 73:f22a18707b5e | 1077 | color_t color, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 1078 | { |
WiredHome | 19:3f82c1161fd2 | 1079 | foreground(color); |
WiredHome | 19:3f82c1161fd2 | 1080 | return circle(x,y,radius,fillit); |
WiredHome | 19:3f82c1161fd2 | 1081 | } |
WiredHome | 19:3f82c1161fd2 | 1082 | |
WiredHome | 44:207594dece70 | 1083 | |
WiredHome | 73:f22a18707b5e | 1084 | RetCode_t RA8875::fillcircle(loc_t x, loc_t y, dim_t radius, |
WiredHome | 73:f22a18707b5e | 1085 | color_t color, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 1086 | { |
WiredHome | 19:3f82c1161fd2 | 1087 | foreground(color); |
WiredHome | 19:3f82c1161fd2 | 1088 | return circle(x,y,radius,fillit); |
WiredHome | 19:3f82c1161fd2 | 1089 | } |
WiredHome | 19:3f82c1161fd2 | 1090 | |
WiredHome | 44:207594dece70 | 1091 | |
WiredHome | 37:f19b7e7449dc | 1092 | RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 1093 | { |
WiredHome | 19:3f82c1161fd2 | 1094 | RetCode_t ret = noerror; |
WiredHome | 73:f22a18707b5e | 1095 | |
WiredHome | 19:3f82c1161fd2 | 1096 | PERFORMANCE_RESET; |
WiredHome | 19:3f82c1161fd2 | 1097 | if (radius <= 0) { |
WiredHome | 19:3f82c1161fd2 | 1098 | ret = bad_parameter; |
WiredHome | 19:3f82c1161fd2 | 1099 | } else if (radius == 1) { |
WiredHome | 19:3f82c1161fd2 | 1100 | pixel(x,y); |
WiredHome | 19:3f82c1161fd2 | 1101 | } else { |
WiredHome | 38:38d503b4fad6 | 1102 | WriteCommandW(0x99, x); |
WiredHome | 38:38d503b4fad6 | 1103 | WriteCommandW(0x9B, y); |
WiredHome | 19:3f82c1161fd2 | 1104 | WriteCommand(0x9d, radius & 0xFF); |
WiredHome | 19:3f82c1161fd2 | 1105 | unsigned char drawCmd = 0x00; // Circle |
WiredHome | 19:3f82c1161fd2 | 1106 | if (fillit == FILL) |
WiredHome | 19:3f82c1161fd2 | 1107 | drawCmd |= 0x20; |
WiredHome | 19:3f82c1161fd2 | 1108 | WriteCommand(0x90, drawCmd); |
WiredHome | 19:3f82c1161fd2 | 1109 | WriteCommand(0x90, 0x40 + drawCmd); // Start drawing. |
WiredHome | 66:468a11f05580 | 1110 | _WaitWhileReg(0x90, 0x40); |
WiredHome | 19:3f82c1161fd2 | 1111 | } |
WiredHome | 19:3f82c1161fd2 | 1112 | REGISTERPERFORMANCE(PRF_DRAWCIRCLE); |
WiredHome | 19:3f82c1161fd2 | 1113 | return ret; |
WiredHome | 19:3f82c1161fd2 | 1114 | } |
WiredHome | 19:3f82c1161fd2 | 1115 | |
WiredHome | 44:207594dece70 | 1116 | |
WiredHome | 37:f19b7e7449dc | 1117 | 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 | 1118 | { |
WiredHome | 19:3f82c1161fd2 | 1119 | foreground(color); |
WiredHome | 25:9556a3a9b7cc | 1120 | return ellipse(x,y,radius1,radius2,fillit); |
WiredHome | 19:3f82c1161fd2 | 1121 | } |
WiredHome | 19:3f82c1161fd2 | 1122 | |
WiredHome | 44:207594dece70 | 1123 | |
WiredHome | 37:f19b7e7449dc | 1124 | 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 | 1125 | { |
WiredHome | 25:9556a3a9b7cc | 1126 | foreground(color); |
WiredHome | 25:9556a3a9b7cc | 1127 | return ellipse(x,y,radius1,radius2,fillit); |
WiredHome | 25:9556a3a9b7cc | 1128 | } |
WiredHome | 44:207594dece70 | 1129 | |
WiredHome | 73:f22a18707b5e | 1130 | |
WiredHome | 37:f19b7e7449dc | 1131 | RetCode_t RA8875::ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit) |
WiredHome | 19:3f82c1161fd2 | 1132 | { |
WiredHome | 19:3f82c1161fd2 | 1133 | RetCode_t ret = noerror; |
WiredHome | 73:f22a18707b5e | 1134 | |
WiredHome | 19:3f82c1161fd2 | 1135 | PERFORMANCE_RESET; |
WiredHome | 25:9556a3a9b7cc | 1136 | if (radius1 <= 0 || radius2 <= 0) { |
WiredHome | 19:3f82c1161fd2 | 1137 | ; // do nothing |
WiredHome | 25:9556a3a9b7cc | 1138 | } else if (radius1 == 1 && radius2 == 1) { |
WiredHome | 19:3f82c1161fd2 | 1139 | pixel(x, y); |
WiredHome | 19:3f82c1161fd2 | 1140 | } else { |
WiredHome | 38:38d503b4fad6 | 1141 | WriteCommandW(0xA5, x); |
WiredHome | 38:38d503b4fad6 | 1142 | WriteCommandW(0xA7, y); |
WiredHome | 38:38d503b4fad6 | 1143 | WriteCommandW(0xA1, radius1); |
WiredHome | 38:38d503b4fad6 | 1144 | WriteCommandW(0xA3, radius2); |
WiredHome | 19:3f82c1161fd2 | 1145 | unsigned char drawCmd = 0x00; // Ellipse |
WiredHome | 19:3f82c1161fd2 | 1146 | if (fillit == FILL) |
WiredHome | 19:3f82c1161fd2 | 1147 | drawCmd |= 0x40; |
WiredHome | 19:3f82c1161fd2 | 1148 | WriteCommand(0xA0, drawCmd); |
WiredHome | 19:3f82c1161fd2 | 1149 | WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing. |
WiredHome | 66:468a11f05580 | 1150 | _WaitWhileReg(0xA0, 0x80); |
WiredHome | 19:3f82c1161fd2 | 1151 | } |
WiredHome | 19:3f82c1161fd2 | 1152 | REGISTERPERFORMANCE(PRF_DRAWELLIPSE); |
WiredHome | 19:3f82c1161fd2 | 1153 | return ret; |
WiredHome | 19:3f82c1161fd2 | 1154 | } |
WiredHome | 19:3f82c1161fd2 | 1155 | |
WiredHome | 44:207594dece70 | 1156 | |
WiredHome | 68:ab08efabfc88 | 1157 | RetCode_t RA8875::frequency(unsigned long Hz, unsigned long Hz2) |
WiredHome | 19:3f82c1161fd2 | 1158 | { |
WiredHome | 66:468a11f05580 | 1159 | spiwritefreq = Hz; |
WiredHome | 68:ab08efabfc88 | 1160 | if (Hz2 != 0) |
WiredHome | 68:ab08efabfc88 | 1161 | spireadfreq = Hz2; |
WiredHome | 68:ab08efabfc88 | 1162 | else |
WiredHome | 68:ab08efabfc88 | 1163 | spireadfreq = Hz/2; |
WiredHome | 68:ab08efabfc88 | 1164 | _setWriteSpeed(true); |
WiredHome | 19:3f82c1161fd2 | 1165 | // __ ___ |
WiredHome | 19:3f82c1161fd2 | 1166 | // Clock ___A Rising edge latched |
WiredHome | 19:3f82c1161fd2 | 1167 | // ___ ____ |
WiredHome | 19:3f82c1161fd2 | 1168 | // Data ___X____ |
WiredHome | 19:3f82c1161fd2 | 1169 | spi.format(8, 3); // 8 bits and clock to data phase 0 |
WiredHome | 19:3f82c1161fd2 | 1170 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 1171 | } |
WiredHome | 19:3f82c1161fd2 | 1172 | |
WiredHome | 68:ab08efabfc88 | 1173 | void RA8875::_setWriteSpeed(bool writeSpeed) |
WiredHome | 68:ab08efabfc88 | 1174 | { |
WiredHome | 68:ab08efabfc88 | 1175 | if (writeSpeed) { |
WiredHome | 68:ab08efabfc88 | 1176 | spi.frequency(spiwritefreq); |
WiredHome | 68:ab08efabfc88 | 1177 | spiWriteSpeed = true; |
WiredHome | 68:ab08efabfc88 | 1178 | } else { |
WiredHome | 68:ab08efabfc88 | 1179 | spi.frequency(spireadfreq); |
WiredHome | 68:ab08efabfc88 | 1180 | spiWriteSpeed = false; |
WiredHome | 68:ab08efabfc88 | 1181 | } |
WiredHome | 68:ab08efabfc88 | 1182 | } |
WiredHome | 44:207594dece70 | 1183 | |
WiredHome | 19:3f82c1161fd2 | 1184 | RetCode_t RA8875::Power(bool on) |
WiredHome | 19:3f82c1161fd2 | 1185 | { |
WiredHome | 19:3f82c1161fd2 | 1186 | WriteCommand(0x01, (on) ? 0x80 : 0x00); |
WiredHome | 19:3f82c1161fd2 | 1187 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 1188 | } |
WiredHome | 19:3f82c1161fd2 | 1189 | |
WiredHome | 44:207594dece70 | 1190 | |
WiredHome | 19:3f82c1161fd2 | 1191 | RetCode_t RA8875::Reset(void) |
WiredHome | 19:3f82c1161fd2 | 1192 | { |
WiredHome | 19:3f82c1161fd2 | 1193 | WriteCommand(0x01, 0x01); // Apply Display Off, Reset |
WiredHome | 19:3f82c1161fd2 | 1194 | wait_ms(2); // no idea if I need to wait, or how long |
WiredHome | 19:3f82c1161fd2 | 1195 | WriteCommand(0x01, 0x00); // Display off, Remove reset |
WiredHome | 73:f22a18707b5e | 1196 | wait_ms(2); // no idea if I need to wait, or how long |
WiredHome | 43:3becae133285 | 1197 | init(RA8875_DISPLAY_WIDTH, RA8875_DISPLAY_HEIGHT, RA8875_COLORDEPTH_BPP); |
WiredHome | 19:3f82c1161fd2 | 1198 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 1199 | } |
WiredHome | 19:3f82c1161fd2 | 1200 | |
WiredHome | 19:3f82c1161fd2 | 1201 | |
WiredHome | 19:3f82c1161fd2 | 1202 | RetCode_t RA8875::Backlight_u8(unsigned char brightness) |
WiredHome | 19:3f82c1161fd2 | 1203 | { |
WiredHome | 19:3f82c1161fd2 | 1204 | static bool is_enabled = false; |
WiredHome | 19:3f82c1161fd2 | 1205 | if (brightness == 0) { |
WiredHome | 19:3f82c1161fd2 | 1206 | WriteCommand(0x8a); // Disable the PWM |
WiredHome | 19:3f82c1161fd2 | 1207 | WriteData(0x00); |
WiredHome | 19:3f82c1161fd2 | 1208 | is_enabled = false; |
WiredHome | 19:3f82c1161fd2 | 1209 | } else if (!is_enabled) { |
WiredHome | 19:3f82c1161fd2 | 1210 | WriteCommand(0x8a); // Enable the PWM |
WiredHome | 19:3f82c1161fd2 | 1211 | WriteData(0x80); |
WiredHome | 19:3f82c1161fd2 | 1212 | WriteCommand(0x8a); // Not sure why this is needed, but following the pattern |
WiredHome | 19:3f82c1161fd2 | 1213 | WriteData(0x81); // open PWM (SYS_CLK / 2 as best I can tell) |
WiredHome | 19:3f82c1161fd2 | 1214 | is_enabled = true; |
WiredHome | 19:3f82c1161fd2 | 1215 | } |
WiredHome | 19:3f82c1161fd2 | 1216 | WriteCommand(0x8b, brightness); // Brightness parameter 0xff-0x00 |
WiredHome | 19:3f82c1161fd2 | 1217 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 1218 | } |
WiredHome | 19:3f82c1161fd2 | 1219 | |
WiredHome | 44:207594dece70 | 1220 | |
WiredHome | 19:3f82c1161fd2 | 1221 | RetCode_t RA8875::Backlight(float brightness) |
WiredHome | 19:3f82c1161fd2 | 1222 | { |
WiredHome | 19:3f82c1161fd2 | 1223 | unsigned char b; |
WiredHome | 73:f22a18707b5e | 1224 | |
WiredHome | 29:422616aa04bd | 1225 | if (brightness >= 1.0) |
WiredHome | 19:3f82c1161fd2 | 1226 | b = 255; |
WiredHome | 29:422616aa04bd | 1227 | else if (brightness <= 0.0) |
WiredHome | 19:3f82c1161fd2 | 1228 | b = 0; |
WiredHome | 19:3f82c1161fd2 | 1229 | else |
WiredHome | 19:3f82c1161fd2 | 1230 | b = (unsigned char)(brightness * 255); |
WiredHome | 19:3f82c1161fd2 | 1231 | return Backlight_u8(b); |
WiredHome | 19:3f82c1161fd2 | 1232 | } |
WiredHome | 19:3f82c1161fd2 | 1233 | |
WiredHome | 44:207594dece70 | 1234 | |
WiredHome | 19:3f82c1161fd2 | 1235 | RetCode_t RA8875::set_font(const unsigned char * _font) |
WiredHome | 19:3f82c1161fd2 | 1236 | { |
WiredHome | 37:f19b7e7449dc | 1237 | if (font && ! _font) { |
WiredHome | 37:f19b7e7449dc | 1238 | SetTextCursor(cursor_x, cursor_y); // soft-font cursor -> hw cursor |
WiredHome | 37:f19b7e7449dc | 1239 | } |
WiredHome | 19:3f82c1161fd2 | 1240 | font = _font; |
WiredHome | 29:422616aa04bd | 1241 | GraphicsDisplay::set_font(_font); |
WiredHome | 29:422616aa04bd | 1242 | return noerror; // trusting them, but it might be good to put some checks in here... |
WiredHome | 19:3f82c1161fd2 | 1243 | } |
WiredHome | 19:3f82c1161fd2 | 1244 | |
WiredHome | 44:207594dece70 | 1245 | |
WiredHome | 19:3f82c1161fd2 | 1246 | RetCode_t RA8875::background(color_t color) |
WiredHome | 19:3f82c1161fd2 | 1247 | { |
WiredHome | 37:f19b7e7449dc | 1248 | GraphicsDisplay::background(color); |
WiredHome | 19:3f82c1161fd2 | 1249 | WriteCommand(0x60, (color>>11)); // BGCR0 |
WiredHome | 19:3f82c1161fd2 | 1250 | WriteCommand(0x61, (unsigned char)(color>>5)); // BGCR0 |
WiredHome | 19:3f82c1161fd2 | 1251 | WriteCommand(0x62, (unsigned char)(color)); // BGCR0 |
WiredHome | 19:3f82c1161fd2 | 1252 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 1253 | } |
WiredHome | 19:3f82c1161fd2 | 1254 | |
WiredHome | 44:207594dece70 | 1255 | |
WiredHome | 19:3f82c1161fd2 | 1256 | RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b) |
WiredHome | 19:3f82c1161fd2 | 1257 | { |
WiredHome | 37:f19b7e7449dc | 1258 | background(RGB(r,g,b)); |
WiredHome | 37:f19b7e7449dc | 1259 | // WriteCommand(0x60, r); |
WiredHome | 37:f19b7e7449dc | 1260 | // WriteCommand(0x61, g); |
WiredHome | 37:f19b7e7449dc | 1261 | // WriteCommand(0x62, b); |
WiredHome | 19:3f82c1161fd2 | 1262 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 1263 | } |
WiredHome | 19:3f82c1161fd2 | 1264 | |
WiredHome | 44:207594dece70 | 1265 | |
WiredHome | 19:3f82c1161fd2 | 1266 | RetCode_t RA8875::foreground(color_t color) |
WiredHome | 19:3f82c1161fd2 | 1267 | { |
WiredHome | 37:f19b7e7449dc | 1268 | GraphicsDisplay::foreground(color); |
WiredHome | 19:3f82c1161fd2 | 1269 | WriteCommand(0x63, (unsigned char)(color>>11)); |
WiredHome | 19:3f82c1161fd2 | 1270 | WriteCommand(0x64, (unsigned char)(color>>5)); |
WiredHome | 19:3f82c1161fd2 | 1271 | WriteCommand(0x65, (unsigned char)(color)); |
WiredHome | 19:3f82c1161fd2 | 1272 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 1273 | } |
WiredHome | 19:3f82c1161fd2 | 1274 | |
WiredHome | 44:207594dece70 | 1275 | |
WiredHome | 37:f19b7e7449dc | 1276 | RetCode_t RA8875::foreground(unsigned char r, unsigned char g, unsigned char b) |
WiredHome | 19:3f82c1161fd2 | 1277 | { |
WiredHome | 37:f19b7e7449dc | 1278 | foreground(RGB(r,g,b)); |
WiredHome | 37:f19b7e7449dc | 1279 | // WriteCommand(0x63, r); |
WiredHome | 37:f19b7e7449dc | 1280 | // WriteCommand(0x64, g); |
WiredHome | 37:f19b7e7449dc | 1281 | // WriteCommand(0x65, b); |
WiredHome | 19:3f82c1161fd2 | 1282 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 1283 | } |
WiredHome | 19:3f82c1161fd2 | 1284 | |
WiredHome | 44:207594dece70 | 1285 | |
WiredHome | 37:f19b7e7449dc | 1286 | color_t RA8875::GetForeColor(void) |
WiredHome | 19:3f82c1161fd2 | 1287 | { |
WiredHome | 19:3f82c1161fd2 | 1288 | color_t color; |
WiredHome | 73:f22a18707b5e | 1289 | |
WiredHome | 19:3f82c1161fd2 | 1290 | color = (ReadCommand(0x63) & 0x1F) << 11; |
WiredHome | 19:3f82c1161fd2 | 1291 | color |= (ReadCommand(0x64) & 0x3F) << 5; |
WiredHome | 19:3f82c1161fd2 | 1292 | color |= (ReadCommand(0x65) & 0x1F); |
WiredHome | 19:3f82c1161fd2 | 1293 | return color; |
WiredHome | 19:3f82c1161fd2 | 1294 | } |
WiredHome | 19:3f82c1161fd2 | 1295 | |
WiredHome | 44:207594dece70 | 1296 | |
WiredHome | 19:3f82c1161fd2 | 1297 | color_t RA8875::DOSColor(int i) |
WiredHome | 73:f22a18707b5e | 1298 | { |
WiredHome | 73:f22a18707b5e | 1299 | const color_t colors[16] = { |
WiredHome | 19:3f82c1161fd2 | 1300 | Black, Blue, Green, Cyan, |
WiredHome | 19:3f82c1161fd2 | 1301 | Red, Magenta, Brown, Gray, |
WiredHome | 19:3f82c1161fd2 | 1302 | Charcoal, BrightBlue, BrightGreen, BrightCyan, |
WiredHome | 19:3f82c1161fd2 | 1303 | Orange, Pink, Yellow, White |
WiredHome | 73:f22a18707b5e | 1304 | }; |
WiredHome | 19:3f82c1161fd2 | 1305 | if (i < 16) |
WiredHome | 19:3f82c1161fd2 | 1306 | return colors[i]; |
WiredHome | 19:3f82c1161fd2 | 1307 | else |
WiredHome | 19:3f82c1161fd2 | 1308 | return 0; |
WiredHome | 73:f22a18707b5e | 1309 | } |
WiredHome | 19:3f82c1161fd2 | 1310 | |
WiredHome | 44:207594dece70 | 1311 | |
WiredHome | 73:f22a18707b5e | 1312 | const char * RA8875::DOSColorNames(int i) |
WiredHome | 73:f22a18707b5e | 1313 | { |
WiredHome | 73:f22a18707b5e | 1314 | const char * names[16] = { |
WiredHome | 19:3f82c1161fd2 | 1315 | "Black", "Blue", "Green", "Cyan", |
WiredHome | 19:3f82c1161fd2 | 1316 | "Red", "Magenta", "Brown", "Gray", |
WiredHome | 19:3f82c1161fd2 | 1317 | "Charcoal", "BrightBlue", "BrightGreen", "BrightCyan", |
WiredHome | 19:3f82c1161fd2 | 1318 | "Orange", "Pink", "Yellow", "White" |
WiredHome | 73:f22a18707b5e | 1319 | }; |
WiredHome | 19:3f82c1161fd2 | 1320 | if (i < 16) |
WiredHome | 19:3f82c1161fd2 | 1321 | return names[i]; |
WiredHome | 19:3f82c1161fd2 | 1322 | else |
WiredHome | 19:3f82c1161fd2 | 1323 | return NULL; |
WiredHome | 73:f22a18707b5e | 1324 | } |
WiredHome | 19:3f82c1161fd2 | 1325 | |
WiredHome | 19:3f82c1161fd2 | 1326 | |
WiredHome | 19:3f82c1161fd2 | 1327 | /////////////////////////////////////////////////////////////// |
WiredHome | 19:3f82c1161fd2 | 1328 | // Private functions |
WiredHome | 19:3f82c1161fd2 | 1329 | |
WiredHome | 19:3f82c1161fd2 | 1330 | unsigned char RA8875::spiwrite(unsigned char data) |
WiredHome | 19:3f82c1161fd2 | 1331 | { |
WiredHome | 19:3f82c1161fd2 | 1332 | unsigned char retval; |
WiredHome | 73:f22a18707b5e | 1333 | |
WiredHome | 68:ab08efabfc88 | 1334 | if (!spiWriteSpeed) |
WiredHome | 68:ab08efabfc88 | 1335 | _setWriteSpeed(true); |
WiredHome | 19:3f82c1161fd2 | 1336 | retval = spi.write(data); |
WiredHome | 19:3f82c1161fd2 | 1337 | return retval; |
WiredHome | 19:3f82c1161fd2 | 1338 | } |
WiredHome | 19:3f82c1161fd2 | 1339 | |
WiredHome | 44:207594dece70 | 1340 | |
WiredHome | 19:3f82c1161fd2 | 1341 | unsigned char RA8875::spiread(void) |
WiredHome | 19:3f82c1161fd2 | 1342 | { |
WiredHome | 19:3f82c1161fd2 | 1343 | unsigned char retval; |
WiredHome | 19:3f82c1161fd2 | 1344 | unsigned char data = 0; |
WiredHome | 73:f22a18707b5e | 1345 | |
WiredHome | 68:ab08efabfc88 | 1346 | if (spiWriteSpeed) |
WiredHome | 68:ab08efabfc88 | 1347 | _setWriteSpeed(false); |
WiredHome | 19:3f82c1161fd2 | 1348 | retval = spi.write(data); |
WiredHome | 19:3f82c1161fd2 | 1349 | return retval; |
WiredHome | 19:3f82c1161fd2 | 1350 | } |
WiredHome | 19:3f82c1161fd2 | 1351 | |
WiredHome | 44:207594dece70 | 1352 | |
WiredHome | 19:3f82c1161fd2 | 1353 | RetCode_t RA8875::select(bool chipsel) |
WiredHome | 19:3f82c1161fd2 | 1354 | { |
WiredHome | 19:3f82c1161fd2 | 1355 | cs = (chipsel == true) ? 0 : 1; |
WiredHome | 19:3f82c1161fd2 | 1356 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 1357 | } |
WiredHome | 19:3f82c1161fd2 | 1358 | |
WiredHome | 44:207594dece70 | 1359 | |
WiredHome | 43:3becae133285 | 1360 | RetCode_t RA8875::init(int width, int height, int color_bpp) |
WiredHome | 19:3f82c1161fd2 | 1361 | { |
WiredHome | 19:3f82c1161fd2 | 1362 | Backlight_u8(0); |
WiredHome | 66:468a11f05580 | 1363 | WriteCommand(0x88, 0x0B); // PLLC1 - Phase Lock Loop registers |
WiredHome | 19:3f82c1161fd2 | 1364 | wait_ms(1); |
WiredHome | 19:3f82c1161fd2 | 1365 | WriteCommand(0x89, 0x02); |
WiredHome | 19:3f82c1161fd2 | 1366 | wait_ms(1); |
WiredHome | 73:f22a18707b5e | 1367 | |
WiredHome | 23:a50ded45dbaf | 1368 | // System Config Register (SYSR) |
WiredHome | 43:3becae133285 | 1369 | if (color_bpp == 16) { |
WiredHome | 43:3becae133285 | 1370 | WriteCommand(0x10, 0x0C); // 16-bpp (65K colors) color depth, 8-bit interface |
WiredHome | 43:3becae133285 | 1371 | } else { // color_bpp == 8 |
WiredHome | 43:3becae133285 | 1372 | WriteCommand(0x10, 0x00); // 8-bpp (256 colors) |
WiredHome | 43:3becae133285 | 1373 | } |
WiredHome | 23:a50ded45dbaf | 1374 | // Pixel Clock Setting Register (PCSR) |
WiredHome | 37:f19b7e7449dc | 1375 | WriteCommand(0x04, 0x82); // PDAT on PCLK falling edge, PCLK = 4 x System Clock |
WiredHome | 19:3f82c1161fd2 | 1376 | wait_ms(1); |
WiredHome | 19:3f82c1161fd2 | 1377 | |
WiredHome | 19:3f82c1161fd2 | 1378 | // Horizontal Settings |
WiredHome | 43:3becae133285 | 1379 | WriteCommand(0x14, width/8 - 1); //HDWR//Horizontal Display Width Setting Bit[6:0] |
WiredHome | 43:3becae133285 | 1380 | WriteCommand(0x15, 0x02); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0] |
WiredHome | 43:3becae133285 | 1381 | WriteCommand(0x16, 0x03); //HNDR//Horizontal Non-Display Period Bit[4:0] |
WiredHome | 43:3becae133285 | 1382 | WriteCommand(0x17, 0x01); //HSTR//HSYNC Start Position[4:0] |
WiredHome | 43:3becae133285 | 1383 | WriteCommand(0x18, 0x03); //HPWR//HSYNC Polarity ,The period width of HSYNC. |
WiredHome | 19:3f82c1161fd2 | 1384 | |
WiredHome | 19:3f82c1161fd2 | 1385 | // Vertical Settings |
WiredHome | 43:3becae133285 | 1386 | WriteCommand(0x19, (height-1)&0xFF); //VDHR0 //Vertical Display Height Bit [7:0] |
WiredHome | 43:3becae133285 | 1387 | WriteCommand(0x1a, (height-1)>>8); //VDHR1 //Vertical Display Height Bit [8] |
WiredHome | 43:3becae133285 | 1388 | WriteCommand(0x1b, 0x0F); //VNDR0 //Vertical Non-Display Period Bit [7:0] |
WiredHome | 43:3becae133285 | 1389 | WriteCommand(0x1c, 0x00); //VNDR1 //Vertical Non-Display Period Bit [8] |
WiredHome | 43:3becae133285 | 1390 | WriteCommand(0x1d, 0x0e); //VSTR0 //VSYNC Start Position[7:0] |
WiredHome | 43:3becae133285 | 1391 | WriteCommand(0x1e, 0x06); //VSTR1 //VSYNC Start Position[8] |
WiredHome | 43:3becae133285 | 1392 | WriteCommand(0x1f, 0x01); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0] |
WiredHome | 19:3f82c1161fd2 | 1393 | |
WiredHome | 43:3becae133285 | 1394 | if (width >= 800 && height >= 480 && color_bpp > 8) { |
WiredHome | 43:3becae133285 | 1395 | WriteCommand(0x20, 0x00); // DPCR - 1-layer mode when the resolution is too high |
WiredHome | 43:3becae133285 | 1396 | } else { |
WiredHome | 43:3becae133285 | 1397 | WriteCommand(0x20, 0x80); // DPCR - 2-layer mode |
WiredHome | 43:3becae133285 | 1398 | } |
WiredHome | 73:f22a18707b5e | 1399 | |
WiredHome | 50:2c4f474a2453 | 1400 | // Set display image to Blue on Black as default |
WiredHome | 43:3becae133285 | 1401 | window(0,0, width, height); // Initialize to full screen |
WiredHome | 24:8ca861acf12d | 1402 | SetTextCursorControl(); |
WiredHome | 28:ed102fc442c4 | 1403 | foreground(Blue); |
WiredHome | 19:3f82c1161fd2 | 1404 | background(Black); |
WiredHome | 50:2c4f474a2453 | 1405 | SelectDrawingLayer(1); |
WiredHome | 50:2c4f474a2453 | 1406 | cls(); |
WiredHome | 50:2c4f474a2453 | 1407 | SelectDrawingLayer(0); |
WiredHome | 19:3f82c1161fd2 | 1408 | cls(); |
WiredHome | 19:3f82c1161fd2 | 1409 | return noerror; |
WiredHome | 19:3f82c1161fd2 | 1410 | } |
WiredHome | 19:3f82c1161fd2 | 1411 | |
WiredHome | 72:ecffe56af969 | 1412 | 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 | 1413 | { |
WiredHome | 77:9206c13aa527 | 1414 | #if 1 |
WiredHome | 74:686faa218914 | 1415 | (void)layer; |
WiredHome | 74:686faa218914 | 1416 | return PrintScreen(x, y, w, h, Name_BMP); |
WiredHome | 77:9206c13aa527 | 1417 | #else |
WiredHome | 74:686faa218914 | 1418 | // This is the deprecated interface and with the changes it is no longer implemented correctly. |
WiredHome | 72:ecffe56af969 | 1419 | uint16_t curLayer = GetDrawingLayer(); |
WiredHome | 72:ecffe56af969 | 1420 | RetCode_t ret = SelectDrawingLayer(layer); |
WiredHome | 72:ecffe56af969 | 1421 | if (ret == noerror) { |
WiredHome | 72:ecffe56af969 | 1422 | ret = PrintScreen(x, y, w, h, Name_BMP); |
WiredHome | 72:ecffe56af969 | 1423 | } |
WiredHome | 72:ecffe56af969 | 1424 | SelectDrawingLayer(curLayer); |
WiredHome | 72:ecffe56af969 | 1425 | return ret; |
WiredHome | 77:9206c13aa527 | 1426 | #endif |
WiredHome | 72:ecffe56af969 | 1427 | } |
WiredHome | 72:ecffe56af969 | 1428 | |
WiredHome | 72:ecffe56af969 | 1429 | RetCode_t RA8875::PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP) |
WiredHome | 72:ecffe56af969 | 1430 | { |
WiredHome | 72:ecffe56af969 | 1431 | BITMAPFILEHEADER BMP_Header; |
WiredHome | 72:ecffe56af969 | 1432 | BITMAPINFOHEADER BMP_Info; |
WiredHome | 73:f22a18707b5e | 1433 | |
WiredHome | 72:ecffe56af969 | 1434 | INFO("(%d,%d) - (%d,%d) %s", x,y,w,h,Name_BMP); |
WiredHome | 72:ecffe56af969 | 1435 | if (x >= 0 && x < width() |
WiredHome | 73:f22a18707b5e | 1436 | && y >= 0 && y < height() |
WiredHome | 73:f22a18707b5e | 1437 | && w > 0 && x + w <= width() |
WiredHome | 73:f22a18707b5e | 1438 | && h > 0 && y + h <= height()) { |
WiredHome | 72:ecffe56af969 | 1439 | |
WiredHome | 72:ecffe56af969 | 1440 | BMP_Header.bfType = BF_TYPE; |
WiredHome | 72:ecffe56af969 | 1441 | BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Header); |
WiredHome | 72:ecffe56af969 | 1442 | BMP_Header.bfReserved1 = 0; |
WiredHome | 72:ecffe56af969 | 1443 | BMP_Header.bfReserved2 = 0; |
WiredHome | 72:ecffe56af969 | 1444 | BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Header); |
WiredHome | 73:f22a18707b5e | 1445 | |
WiredHome | 72:ecffe56af969 | 1446 | BMP_Info.biSize = sizeof(BMP_Info); |
WiredHome | 72:ecffe56af969 | 1447 | BMP_Info.biWidth = w; |
WiredHome | 72:ecffe56af969 | 1448 | BMP_Info.biHeight = h; |
WiredHome | 72:ecffe56af969 | 1449 | BMP_Info.biPlanes = 1; |
WiredHome | 72:ecffe56af969 | 1450 | BMP_Info.biBitCount = 24; |
WiredHome | 72:ecffe56af969 | 1451 | BMP_Info.biCompression = BI_RGB; |
WiredHome | 72:ecffe56af969 | 1452 | BMP_Info.biSizeImage = 0; |
WiredHome | 72:ecffe56af969 | 1453 | BMP_Info.biXPelsPerMeter = 0; |
WiredHome | 72:ecffe56af969 | 1454 | BMP_Info.biYPelsPerMeter = 0; |
WiredHome | 72:ecffe56af969 | 1455 | BMP_Info.biClrUsed = 0; |
WiredHome | 72:ecffe56af969 | 1456 | BMP_Info.biClrImportant = 0; |
WiredHome | 72:ecffe56af969 | 1457 | |
WiredHome | 72:ecffe56af969 | 1458 | INFO("Writing {%s}", Name_BMP); |
WiredHome | 72:ecffe56af969 | 1459 | FILE *Image = fopen(Name_BMP, "wb"); |
WiredHome | 72:ecffe56af969 | 1460 | if (!Image) { |
WiredHome | 72:ecffe56af969 | 1461 | ERR("File not found"); |
WiredHome | 72:ecffe56af969 | 1462 | return(file_not_found); |
WiredHome | 72:ecffe56af969 | 1463 | } |
WiredHome | 72:ecffe56af969 | 1464 | |
WiredHome | 72:ecffe56af969 | 1465 | // Be optimistic - don't check for errors. |
WiredHome | 72:ecffe56af969 | 1466 | //HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header)); |
WiredHome | 72:ecffe56af969 | 1467 | fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image); |
WiredHome | 72:ecffe56af969 | 1468 | //INFO("fwrite returned %d", r); |
WiredHome | 73:f22a18707b5e | 1469 | |
WiredHome | 72:ecffe56af969 | 1470 | //HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info)); |
WiredHome | 72:ecffe56af969 | 1471 | fwrite(&BMP_Info, sizeof(char), sizeof(BMP_Info), Image); |
WiredHome | 72:ecffe56af969 | 1472 | //INFO("fwrite returned %d", r); |
WiredHome | 73:f22a18707b5e | 1473 | |
WiredHome | 72:ecffe56af969 | 1474 | int lineBufSize = ((24 * w + 7)/8); |
WiredHome | 72:ecffe56af969 | 1475 | uint8_t * lineBuffer = (uint8_t *)malloc(lineBufSize); |
WiredHome | 72:ecffe56af969 | 1476 | if (lineBuffer == NULL) { |
WiredHome | 72:ecffe56af969 | 1477 | fclose(Image); |
WiredHome | 72:ecffe56af969 | 1478 | ERR("Not enough RAM for lineBuffer"); |
WiredHome | 72:ecffe56af969 | 1479 | return(not_enough_ram); |
WiredHome | 72:ecffe56af969 | 1480 | } |
WiredHome | 72:ecffe56af969 | 1481 | color_t * pixelBuffer = (color_t *)malloc(w * sizeof(color_t)); |
WiredHome | 73:f22a18707b5e | 1482 | color_t * pixelBuffer2 = (color_t *)malloc(w * sizeof(color_t)); |
WiredHome | 73:f22a18707b5e | 1483 | color_t transparency = GetBackgroundTransparencyColor(); |
WiredHome | 73:f22a18707b5e | 1484 | unsigned char ltpr0 = ReadCommand(0x52) & 0x7; |
WiredHome | 73:f22a18707b5e | 1485 | |
WiredHome | 73:f22a18707b5e | 1486 | if (pixelBuffer == NULL || pixelBuffer2 == NULL) { |
WiredHome | 72:ecffe56af969 | 1487 | fclose(Image); |
WiredHome | 72:ecffe56af969 | 1488 | free(lineBuffer); |
WiredHome | 72:ecffe56af969 | 1489 | ERR("Not enough RAM for pixelBuffer"); |
WiredHome | 73:f22a18707b5e | 1490 | if (pixelBuffer) |
WiredHome | 73:f22a18707b5e | 1491 | free(pixelBuffer); |
WiredHome | 72:ecffe56af969 | 1492 | return(not_enough_ram); |
WiredHome | 72:ecffe56af969 | 1493 | } |
WiredHome | 73:f22a18707b5e | 1494 | |
WiredHome | 73:f22a18707b5e | 1495 | uint16_t prevLayer = GetDrawingLayer(); |
WiredHome | 73:f22a18707b5e | 1496 | // If only one of the layers is visible, select that layer |
WiredHome | 73:f22a18707b5e | 1497 | switch(ltpr0) { |
WiredHome | 73:f22a18707b5e | 1498 | case 0: |
WiredHome | 73:f22a18707b5e | 1499 | SelectDrawingLayer(0); |
WiredHome | 73:f22a18707b5e | 1500 | break; |
WiredHome | 73:f22a18707b5e | 1501 | case 1: |
WiredHome | 73:f22a18707b5e | 1502 | SelectDrawingLayer(1); |
WiredHome | 73:f22a18707b5e | 1503 | break; |
WiredHome | 73:f22a18707b5e | 1504 | default: |
WiredHome | 73:f22a18707b5e | 1505 | break; |
WiredHome | 73:f22a18707b5e | 1506 | } |
WiredHome | 73:f22a18707b5e | 1507 | |
WiredHome | 72:ecffe56af969 | 1508 | // Read the display from the last line toward the top |
WiredHome | 72:ecffe56af969 | 1509 | // so we can write the file in one pass. |
WiredHome | 72:ecffe56af969 | 1510 | for (int j = h - 1; j >= 0; j--) { |
WiredHome | 73:f22a18707b5e | 1511 | if (ltpr0 >= 2) // Need to combine the layers... |
WiredHome | 73:f22a18707b5e | 1512 | SelectDrawingLayer(0); // so read layer 0 first |
WiredHome | 72:ecffe56af969 | 1513 | // Read one line of pixels to a local buffer |
WiredHome | 72:ecffe56af969 | 1514 | if (getPixelStream(pixelBuffer, w, x,y+j) != noerror) { |
WiredHome | 72:ecffe56af969 | 1515 | ERR("getPixelStream error, and no recovery handler..."); |
WiredHome | 72:ecffe56af969 | 1516 | } |
WiredHome | 73:f22a18707b5e | 1517 | if (ltpr0 >= 2) { // Need to combine the layers... |
WiredHome | 73:f22a18707b5e | 1518 | SelectDrawingLayer(1); // so read layer 0 first |
WiredHome | 73:f22a18707b5e | 1519 | if (getPixelStream(pixelBuffer2, w, x,y+j) != noerror) { |
WiredHome | 73:f22a18707b5e | 1520 | ERR("getPixelStream error, and no recovery handler..."); |
WiredHome | 73:f22a18707b5e | 1521 | } |
WiredHome | 73:f22a18707b5e | 1522 | } |
WiredHome | 72:ecffe56af969 | 1523 | // Convert the local buffer to RGBQUAD format |
WiredHome | 72:ecffe56af969 | 1524 | int lb = 0; |
WiredHome | 72:ecffe56af969 | 1525 | for (int i=0; i<w; i++) { |
WiredHome | 73:f22a18707b5e | 1526 | RGBQUAD q0 = RGB16ToRGBQuad(pixelBuffer[x+i]); // Scale to 24-bits |
WiredHome | 73:f22a18707b5e | 1527 | RGBQUAD q1 = RGB16ToRGBQuad(pixelBuffer2[x+i]); // Scale to 24-bits |
WiredHome | 73:f22a18707b5e | 1528 | switch (ltpr0) { |
WiredHome | 73:f22a18707b5e | 1529 | case 0: |
WiredHome | 73:f22a18707b5e | 1530 | case 1: |
WiredHome | 73:f22a18707b5e | 1531 | case 2: // lighten-overlay (@TODO Not supported yet) |
WiredHome | 73:f22a18707b5e | 1532 | case 6: // Floating Windows (@TODO not sure how to support) |
WiredHome | 73:f22a18707b5e | 1533 | default: // Reserved... |
WiredHome | 73:f22a18707b5e | 1534 | lineBuffer[lb++] = q0.rgbBlue; |
WiredHome | 73:f22a18707b5e | 1535 | lineBuffer[lb++] = q0.rgbGreen; |
WiredHome | 73:f22a18707b5e | 1536 | lineBuffer[lb++] = q0.rgbRed; |
WiredHome | 73:f22a18707b5e | 1537 | break; |
WiredHome | 73:f22a18707b5e | 1538 | case 3: // transparent mode (@TODO Read the background color register for transparent) |
WiredHome | 73:f22a18707b5e | 1539 | case 4: // boolean or |
WiredHome | 73:f22a18707b5e | 1540 | lineBuffer[lb++] = q0.rgbBlue | q1.rgbBlue; |
WiredHome | 73:f22a18707b5e | 1541 | lineBuffer[lb++] = q0.rgbGreen | q1.rgbGreen; |
WiredHome | 73:f22a18707b5e | 1542 | lineBuffer[lb++] = q0.rgbRed | q1.rgbRed; |
WiredHome | 73:f22a18707b5e | 1543 | break; |
WiredHome | 73:f22a18707b5e | 1544 | case 5: // boolean AND |
WiredHome | 73:f22a18707b5e | 1545 | lineBuffer[lb++] = q0.rgbBlue & q1.rgbBlue; |
WiredHome | 73:f22a18707b5e | 1546 | lineBuffer[lb++] = q0.rgbGreen & q1.rgbGreen; |
WiredHome | 73:f22a18707b5e | 1547 | lineBuffer[lb++] = q0.rgbRed & q1.rgbRed; |
WiredHome | 73:f22a18707b5e | 1548 | break; |
WiredHome | 73:f22a18707b5e | 1549 | } |
WiredHome | 72:ecffe56af969 | 1550 | } |
WiredHome | 73:f22a18707b5e | 1551 | if (j == h - 1) |
WiredHome | 73:f22a18707b5e | 1552 | HexDump("Line", lineBuffer, lineBufSize); |
WiredHome | 72:ecffe56af969 | 1553 | // Write to disk |
WiredHome | 72:ecffe56af969 | 1554 | fwrite(lineBuffer, sizeof(char), lb, Image); |
WiredHome | 72:ecffe56af969 | 1555 | } |
WiredHome | 73:f22a18707b5e | 1556 | SelectDrawingLayer(prevLayer); |
WiredHome | 72:ecffe56af969 | 1557 | fclose(Image); |
WiredHome | 73:f22a18707b5e | 1558 | free(pixelBuffer2); // don't leak memory. |
WiredHome | 73:f22a18707b5e | 1559 | free(pixelBuffer); |
WiredHome | 72:ecffe56af969 | 1560 | free(lineBuffer); |
WiredHome | 73:f22a18707b5e | 1561 | INFO("Image closed"); |
WiredHome | 72:ecffe56af969 | 1562 | return noerror; |
WiredHome | 72:ecffe56af969 | 1563 | } else { |
WiredHome | 72:ecffe56af969 | 1564 | return bad_parameter; |
WiredHome | 72:ecffe56af969 | 1565 | } |
WiredHome | 72:ecffe56af969 | 1566 | } |
WiredHome | 72:ecffe56af969 | 1567 | |
WiredHome | 72:ecffe56af969 | 1568 | |
WiredHome | 72:ecffe56af969 | 1569 | // ########################################################################## |
WiredHome | 72:ecffe56af969 | 1570 | // ########################################################################## |
WiredHome | 72:ecffe56af969 | 1571 | // ########################################################################## |
WiredHome | 72:ecffe56af969 | 1572 | |
WiredHome | 23:a50ded45dbaf | 1573 | #ifdef TESTENABLE |
WiredHome | 23:a50ded45dbaf | 1574 | |
WiredHome | 37:f19b7e7449dc | 1575 | #include "Arial12x12.h" |
WiredHome | 37:f19b7e7449dc | 1576 | #include "Small_6.h" |
WiredHome | 37:f19b7e7449dc | 1577 | |
WiredHome | 23:a50ded45dbaf | 1578 | // ______________ ______________ ______________ _______________ |
WiredHome | 23:a50ded45dbaf | 1579 | // /_____ _____/ / ___________/ / ___________/ /_____ ______/ |
WiredHome | 23:a50ded45dbaf | 1580 | // / / / / / / / / |
WiredHome | 23:a50ded45dbaf | 1581 | // / / / /___ / /__________ / / |
WiredHome | 23:a50ded45dbaf | 1582 | // / / / ____/ /__________ / / / |
WiredHome | 23:a50ded45dbaf | 1583 | // / / / / / / / / |
WiredHome | 23:a50ded45dbaf | 1584 | // / / / /__________ ___________/ / / / |
WiredHome | 23:a50ded45dbaf | 1585 | // /__/ /_____________/ /_____________/ /__/ |
WiredHome | 23:a50ded45dbaf | 1586 | // |
WiredHome | 23:a50ded45dbaf | 1587 | // Everything from here down is test code. |
WiredHome | 75:ca78388cfd77 | 1588 | // |
WiredHome | 41:2956a0a221e5 | 1589 | bool SuppressSlowStuff = false; |
WiredHome | 23:a50ded45dbaf | 1590 | |
WiredHome | 49:c5182231d1b9 | 1591 | void TextWrapTest(RA8875 & display, Serial & pc) |
WiredHome | 49:c5182231d1b9 | 1592 | { |
WiredHome | 49:c5182231d1b9 | 1593 | if (!SuppressSlowStuff) |
WiredHome | 49:c5182231d1b9 | 1594 | pc.printf("Text Wrap Test\r\n"); |
WiredHome | 49:c5182231d1b9 | 1595 | display.background(Black); |
WiredHome | 49:c5182231d1b9 | 1596 | display.foreground(Blue); |
WiredHome | 49:c5182231d1b9 | 1597 | display.cls(); |
WiredHome | 49:c5182231d1b9 | 1598 | display.Backlight_u8(255); |
WiredHome | 49:c5182231d1b9 | 1599 | display.puts(0,0, "Text Wrap Test.\r\n"); |
WiredHome | 52:e6039a823420 | 1600 | for (int i=1; i<60; i++) { |
WiredHome | 52:e6039a823420 | 1601 | display.printf("L%2d\n", i % 17); |
WiredHome | 49:c5182231d1b9 | 1602 | if (!SuppressSlowStuff) |
WiredHome | 52:e6039a823420 | 1603 | wait_ms(100); |
WiredHome | 49:c5182231d1b9 | 1604 | } |
WiredHome | 49:c5182231d1b9 | 1605 | if (!SuppressSlowStuff) |
WiredHome | 49:c5182231d1b9 | 1606 | wait_ms(3000); |
WiredHome | 49:c5182231d1b9 | 1607 | } |
WiredHome | 49:c5182231d1b9 | 1608 | |
WiredHome | 75:ca78388cfd77 | 1609 | |
WiredHome | 75:ca78388cfd77 | 1610 | void ShowKey(RA8875 & display, int key) |
WiredHome | 75:ca78388cfd77 | 1611 | { |
WiredHome | 75:ca78388cfd77 | 1612 | loc_t col, row; |
WiredHome | 75:ca78388cfd77 | 1613 | dim_t r1 = 25; |
WiredHome | 75:ca78388cfd77 | 1614 | color_t color = (key & 0x80) ? Red : Green; |
WiredHome | 75:ca78388cfd77 | 1615 | |
WiredHome | 75:ca78388cfd77 | 1616 | key &= 0x7F; // remove the long-press flag |
WiredHome | 75:ca78388cfd77 | 1617 | row = (key - 1) / 5; |
WiredHome | 75:ca78388cfd77 | 1618 | col = (key - 1) % 5; |
WiredHome | 75:ca78388cfd77 | 1619 | if (col > 5) col = 5; |
WiredHome | 75:ca78388cfd77 | 1620 | if (row > 4) row = 4; |
WiredHome | 75:ca78388cfd77 | 1621 | display.circle(450 - + (2 * r1) * col, 200 - (2 * r1) * row, r1-2, color, FILL); |
WiredHome | 75:ca78388cfd77 | 1622 | } |
WiredHome | 75:ca78388cfd77 | 1623 | |
WiredHome | 75:ca78388cfd77 | 1624 | void HideKey(RA8875 & display, int key) |
WiredHome | 75:ca78388cfd77 | 1625 | { |
WiredHome | 75:ca78388cfd77 | 1626 | loc_t col, row; |
WiredHome | 75:ca78388cfd77 | 1627 | dim_t r1 = 25; |
WiredHome | 75:ca78388cfd77 | 1628 | |
WiredHome | 75:ca78388cfd77 | 1629 | row = (key - 1) / 5; |
WiredHome | 75:ca78388cfd77 | 1630 | col = (key - 1) % 5; |
WiredHome | 75:ca78388cfd77 | 1631 | if (col > 5) col = 5; |
WiredHome | 75:ca78388cfd77 | 1632 | if (row > 4) row = 4; |
WiredHome | 75:ca78388cfd77 | 1633 | display.background(Black); |
WiredHome | 75:ca78388cfd77 | 1634 | display.circle(450 - (2 * r1) * col, 200 - (2 * r1) * row, r1-2, Black, FILL); |
WiredHome | 75:ca78388cfd77 | 1635 | display.circle(450 - (2 * r1) * col, 200 - (2 * r1) * row, r1-2, Blue); |
WiredHome | 75:ca78388cfd77 | 1636 | } |
WiredHome | 75:ca78388cfd77 | 1637 | |
WiredHome | 75:ca78388cfd77 | 1638 | void KeyPadTest(RA8875 & display, Serial & pc) |
WiredHome | 75:ca78388cfd77 | 1639 | { |
WiredHome | 75:ca78388cfd77 | 1640 | const uint8_t myMap[22] = { |
WiredHome | 77:9206c13aa527 | 1641 | 0, |
WiredHome | 75:ca78388cfd77 | 1642 | 'a', 'b', 'c', 'd', 'e', |
WiredHome | 75:ca78388cfd77 | 1643 | 'f', 'g', 'h', 'i', 'j', |
WiredHome | 75:ca78388cfd77 | 1644 | 'k', 'l', 'm', 'n', 'o', |
WiredHome | 75:ca78388cfd77 | 1645 | 'p', 'q', 'r', 's', 't', |
WiredHome | 75:ca78388cfd77 | 1646 | 'x' |
WiredHome | 75:ca78388cfd77 | 1647 | }; |
WiredHome | 77:9206c13aa527 | 1648 | |
WiredHome | 75:ca78388cfd77 | 1649 | display.background(Black); |
WiredHome | 75:ca78388cfd77 | 1650 | display.foreground(Blue); |
WiredHome | 75:ca78388cfd77 | 1651 | display.cls(); |
WiredHome | 75:ca78388cfd77 | 1652 | display.Backlight_u8(255); |
WiredHome | 75:ca78388cfd77 | 1653 | display.puts(0,0, "KeyPad Test. Touch the keypad..."); |
WiredHome | 75:ca78388cfd77 | 1654 | pc.printf("\r\n" |
WiredHome | 75:ca78388cfd77 | 1655 | "Raw KeyPad Test. Keypad returns the key-number.\r\n" |
WiredHome | 75:ca78388cfd77 | 1656 | "Press [most] any PC keyboard key to advance to next test.\r\n"); |
WiredHome | 75:ca78388cfd77 | 1657 | RetCode_t ret = display.KeypadInit(true, true, 3, 7, 3); |
WiredHome | 75:ca78388cfd77 | 1658 | if (ret != noerror) |
WiredHome | 75:ca78388cfd77 | 1659 | pc.printf("returncode from KeypadInit is %d\r\n", ret); |
WiredHome | 75:ca78388cfd77 | 1660 | int lastKey = 0; |
WiredHome | 75:ca78388cfd77 | 1661 | while (!pc.readable()) { |
WiredHome | 75:ca78388cfd77 | 1662 | if (display.readable()) { |
WiredHome | 75:ca78388cfd77 | 1663 | int key = display.getc(); |
WiredHome | 75:ca78388cfd77 | 1664 | if (key) { |
WiredHome | 75:ca78388cfd77 | 1665 | if (((key & 0x7F) != lastKey) && (lastKey != 0)) |
WiredHome | 75:ca78388cfd77 | 1666 | HideKey(display, lastKey); |
WiredHome | 75:ca78388cfd77 | 1667 | ShowKey(display, key); |
WiredHome | 75:ca78388cfd77 | 1668 | lastKey = key & 0x7F; |
WiredHome | 75:ca78388cfd77 | 1669 | } else { |
WiredHome | 75:ca78388cfd77 | 1670 | // erase the last one |
WiredHome | 75:ca78388cfd77 | 1671 | if (lastKey) |
WiredHome | 75:ca78388cfd77 | 1672 | HideKey(display, lastKey); |
WiredHome | 75:ca78388cfd77 | 1673 | } |
WiredHome | 75:ca78388cfd77 | 1674 | } |
WiredHome | 75:ca78388cfd77 | 1675 | } |
WiredHome | 75:ca78388cfd77 | 1676 | (void)pc.getc(); |
WiredHome | 75:ca78388cfd77 | 1677 | pc.printf("\r\n" |
WiredHome | 75:ca78388cfd77 | 1678 | "Map KeyPad Test. Keypad returns the remapped key 'a' - 't'.\r\n" |
WiredHome | 75:ca78388cfd77 | 1679 | "Press [most] any PC keyboard key to advance to exit test.\r\n"); |
WiredHome | 75:ca78388cfd77 | 1680 | display.SetKeyMap(myMap); |
WiredHome | 75:ca78388cfd77 | 1681 | while (!pc.readable()) { |
WiredHome | 75:ca78388cfd77 | 1682 | if (display.readable()) { |
WiredHome | 75:ca78388cfd77 | 1683 | int key = display.getc(); |
WiredHome | 75:ca78388cfd77 | 1684 | bool longPress = key & 0x80; |
WiredHome | 75:ca78388cfd77 | 1685 | display.SetTextCursor(0, 120); |
WiredHome | 75:ca78388cfd77 | 1686 | display.printf("Long Press: %d\r\n", longPress); |
WiredHome | 75:ca78388cfd77 | 1687 | display.printf(" Remapped: %c %02X\r\n", (key) ? key & 0x7F : ' ', key); |
WiredHome | 75:ca78388cfd77 | 1688 | } |
WiredHome | 75:ca78388cfd77 | 1689 | } |
WiredHome | 75:ca78388cfd77 | 1690 | (void)pc.getc(); |
WiredHome | 75:ca78388cfd77 | 1691 | display.SetKeyMap(); |
WiredHome | 75:ca78388cfd77 | 1692 | pc.printf("\r\n"); |
WiredHome | 75:ca78388cfd77 | 1693 | } |
WiredHome | 75:ca78388cfd77 | 1694 | |
WiredHome | 23:a50ded45dbaf | 1695 | void TextCursorTest(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 1696 | { |
WiredHome | 75:ca78388cfd77 | 1697 | const char * iCursor = "The I-Beam cursor should be visible for this text.\r\n"; |
WiredHome | 75:ca78388cfd77 | 1698 | const char * uCursor = "The Underscore cursor should be visible for this text.\r\n"; |
WiredHome | 75:ca78388cfd77 | 1699 | const char * bCursor = "The Block cursor should be visible for this text.\r\n"; |
WiredHome | 37:f19b7e7449dc | 1700 | const char * bbCursor = "The Blinking Block cursor should be visible for this text.\r\n"; |
WiredHome | 23:a50ded45dbaf | 1701 | const char * p; |
WiredHome | 41:2956a0a221e5 | 1702 | int delay = 100; |
WiredHome | 73:f22a18707b5e | 1703 | |
WiredHome | 41:2956a0a221e5 | 1704 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 1705 | pc.printf("Text Cursor Test\r\n"); |
WiredHome | 73:f22a18707b5e | 1706 | else |
WiredHome | 41:2956a0a221e5 | 1707 | delay = 0; |
WiredHome | 23:a50ded45dbaf | 1708 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 1709 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 1710 | display.cls(); |
WiredHome | 25:9556a3a9b7cc | 1711 | display.Backlight_u8(255); |
WiredHome | 23:a50ded45dbaf | 1712 | display.puts(0,0, "Text Cursor Test."); |
WiredHome | 73:f22a18707b5e | 1713 | |
WiredHome | 23:a50ded45dbaf | 1714 | // visible, non-blinking |
WiredHome | 24:8ca861acf12d | 1715 | display.SetTextCursor(0,20); |
WiredHome | 53:86d24b9480b9 | 1716 | display.SetTextCursorControl(RA8875::IBEAM, false); |
WiredHome | 24:8ca861acf12d | 1717 | p = iCursor; |
WiredHome | 23:a50ded45dbaf | 1718 | while (*p) { |
WiredHome | 24:8ca861acf12d | 1719 | display._putc(*p++); |
WiredHome | 41:2956a0a221e5 | 1720 | wait_ms(delay); |
WiredHome | 24:8ca861acf12d | 1721 | } |
WiredHome | 24:8ca861acf12d | 1722 | |
WiredHome | 53:86d24b9480b9 | 1723 | display.SetTextCursorControl(RA8875::UNDER, false); |
WiredHome | 24:8ca861acf12d | 1724 | p = uCursor; |
WiredHome | 24:8ca861acf12d | 1725 | while (*p) { |
WiredHome | 24:8ca861acf12d | 1726 | display._putc(*p++); |
WiredHome | 41:2956a0a221e5 | 1727 | wait_ms(delay); |
WiredHome | 23:a50ded45dbaf | 1728 | } |
WiredHome | 73:f22a18707b5e | 1729 | |
WiredHome | 53:86d24b9480b9 | 1730 | display.SetTextCursorControl(RA8875::BLOCK, false); |
WiredHome | 24:8ca861acf12d | 1731 | p = bCursor; |
WiredHome | 24:8ca861acf12d | 1732 | while (*p) { |
WiredHome | 24:8ca861acf12d | 1733 | display._putc(*p++); |
WiredHome | 41:2956a0a221e5 | 1734 | wait_ms(delay); |
WiredHome | 24:8ca861acf12d | 1735 | } |
WiredHome | 24:8ca861acf12d | 1736 | |
WiredHome | 53:86d24b9480b9 | 1737 | display.SetTextCursorControl(RA8875::BLOCK, true); |
WiredHome | 24:8ca861acf12d | 1738 | p = bbCursor; |
WiredHome | 24:8ca861acf12d | 1739 | while (*p) { |
WiredHome | 24:8ca861acf12d | 1740 | display._putc(*p++); |
WiredHome | 41:2956a0a221e5 | 1741 | wait_ms(delay); |
WiredHome | 24:8ca861acf12d | 1742 | } |
WiredHome | 41:2956a0a221e5 | 1743 | wait_ms(delay * 20); |
WiredHome | 53:86d24b9480b9 | 1744 | display.SetTextCursorControl(RA8875::NOCURSOR, false); |
WiredHome | 23:a50ded45dbaf | 1745 | } |
WiredHome | 23:a50ded45dbaf | 1746 | |
WiredHome | 44:207594dece70 | 1747 | |
WiredHome | 23:a50ded45dbaf | 1748 | void BacklightTest(RA8875 & display, Serial & pc, float ramptime) |
WiredHome | 23:a50ded45dbaf | 1749 | { |
WiredHome | 29:422616aa04bd | 1750 | char buf[60]; |
WiredHome | 41:2956a0a221e5 | 1751 | unsigned int w = (ramptime * 1000)/ 256; |
WiredHome | 41:2956a0a221e5 | 1752 | int delay = 200; |
WiredHome | 41:2956a0a221e5 | 1753 | |
WiredHome | 41:2956a0a221e5 | 1754 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 1755 | pc.printf("Backlight Test - ramp over %f sec.\r\n", ramptime); |
WiredHome | 41:2956a0a221e5 | 1756 | else { |
WiredHome | 41:2956a0a221e5 | 1757 | delay = 0; |
WiredHome | 41:2956a0a221e5 | 1758 | w = 0; |
WiredHome | 41:2956a0a221e5 | 1759 | } |
WiredHome | 23:a50ded45dbaf | 1760 | display.Backlight_u8(0); |
WiredHome | 29:422616aa04bd | 1761 | display.background(White); |
WiredHome | 23:a50ded45dbaf | 1762 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 1763 | display.cls(); |
WiredHome | 41:2956a0a221e5 | 1764 | wait_ms(delay); |
WiredHome | 23:a50ded45dbaf | 1765 | display.puts(0,0, "RA8875 Backlight Test - Ramp up."); |
WiredHome | 38:38d503b4fad6 | 1766 | for (int i=0; i <= 255; i++) { |
WiredHome | 29:422616aa04bd | 1767 | sprintf(buf, "%3d, %4d", i, w); |
WiredHome | 37:f19b7e7449dc | 1768 | display.puts(100,100,buf); |
WiredHome | 23:a50ded45dbaf | 1769 | display.Backlight_u8(i); |
WiredHome | 29:422616aa04bd | 1770 | wait_ms(w); |
WiredHome | 23:a50ded45dbaf | 1771 | } |
WiredHome | 23:a50ded45dbaf | 1772 | } |
WiredHome | 23:a50ded45dbaf | 1773 | |
WiredHome | 44:207594dece70 | 1774 | |
WiredHome | 23:a50ded45dbaf | 1775 | void BacklightTest2(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 1776 | { |
WiredHome | 41:2956a0a221e5 | 1777 | int delay = 20; |
WiredHome | 41:2956a0a221e5 | 1778 | |
WiredHome | 41:2956a0a221e5 | 1779 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 1780 | pc.printf("Backlight Test 2\r\n"); |
WiredHome | 41:2956a0a221e5 | 1781 | else |
WiredHome | 41:2956a0a221e5 | 1782 | delay = 0; |
WiredHome | 41:2956a0a221e5 | 1783 | |
WiredHome | 23:a50ded45dbaf | 1784 | // Dim it out at the end of the tests. |
WiredHome | 37:f19b7e7449dc | 1785 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 1786 | display.puts(0,0, "Ramp Backlight down."); |
WiredHome | 23:a50ded45dbaf | 1787 | // Ramp it off |
WiredHome | 23:a50ded45dbaf | 1788 | for (int i=255; i != 0; i--) { |
WiredHome | 23:a50ded45dbaf | 1789 | display.Backlight_u8(i); |
WiredHome | 41:2956a0a221e5 | 1790 | wait_ms(delay); |
WiredHome | 23:a50ded45dbaf | 1791 | } |
WiredHome | 23:a50ded45dbaf | 1792 | display.Backlight_u8(0); |
WiredHome | 23:a50ded45dbaf | 1793 | } |
WiredHome | 23:a50ded45dbaf | 1794 | |
WiredHome | 44:207594dece70 | 1795 | |
WiredHome | 23:a50ded45dbaf | 1796 | void ExternalFontTest(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 1797 | { |
WiredHome | 41:2956a0a221e5 | 1798 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 1799 | pc.printf("External Font Test\r\n"); |
WiredHome | 23:a50ded45dbaf | 1800 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 1801 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 1802 | display.cls(); |
WiredHome | 23:a50ded45dbaf | 1803 | display.Backlight(1); |
WiredHome | 37:f19b7e7449dc | 1804 | display.puts(0,0, "External Font Test."); |
WiredHome | 37:f19b7e7449dc | 1805 | |
WiredHome | 37:f19b7e7449dc | 1806 | display.set_font(Small_6); |
WiredHome | 73:f22a18707b5e | 1807 | display.puts(0,30, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n"); |
WiredHome | 37:f19b7e7449dc | 1808 | |
WiredHome | 23:a50ded45dbaf | 1809 | display.set_font(Arial12x12); |
WiredHome | 37:f19b7e7449dc | 1810 | display.puts("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n"); |
WiredHome | 37:f19b7e7449dc | 1811 | display.set_font(); // restore to internal |
WiredHome | 73:f22a18707b5e | 1812 | |
WiredHome | 37:f19b7e7449dc | 1813 | display.puts("Normal font again."); |
WiredHome | 37:f19b7e7449dc | 1814 | //display.window(0,0, display.width(), display.height()); |
WiredHome | 23:a50ded45dbaf | 1815 | } |
WiredHome | 23:a50ded45dbaf | 1816 | |
WiredHome | 44:207594dece70 | 1817 | |
WiredHome | 23:a50ded45dbaf | 1818 | void DOSColorTest(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 1819 | { |
WiredHome | 41:2956a0a221e5 | 1820 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 1821 | pc.printf("DOS Color Test\r\n"); |
WiredHome | 23:a50ded45dbaf | 1822 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 1823 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 1824 | display.cls(); |
WiredHome | 23:a50ded45dbaf | 1825 | display.puts(0,0, "DOS Colors - Fore"); |
WiredHome | 23:a50ded45dbaf | 1826 | display.puts(280,0, "Back"); |
WiredHome | 23:a50ded45dbaf | 1827 | display.background(Gray); |
WiredHome | 23:a50ded45dbaf | 1828 | for (int i=0; i<16; i++) { |
WiredHome | 23:a50ded45dbaf | 1829 | display.foreground(display.DOSColor(i)); |
WiredHome | 23:a50ded45dbaf | 1830 | display.puts(160, i*16, display.DOSColorNames(i)); |
WiredHome | 23:a50ded45dbaf | 1831 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 1832 | } |
WiredHome | 23:a50ded45dbaf | 1833 | display.foreground(White); |
WiredHome | 23:a50ded45dbaf | 1834 | for (int i=0; i<16; i++) { |
WiredHome | 23:a50ded45dbaf | 1835 | display.background(display.DOSColor(i)); |
WiredHome | 23:a50ded45dbaf | 1836 | display.puts(360, i*16, display.DOSColorNames(i)); |
WiredHome | 23:a50ded45dbaf | 1837 | display.foreground(White); |
WiredHome | 23:a50ded45dbaf | 1838 | } |
WiredHome | 23:a50ded45dbaf | 1839 | } |
WiredHome | 23:a50ded45dbaf | 1840 | |
WiredHome | 44:207594dece70 | 1841 | |
WiredHome | 23:a50ded45dbaf | 1842 | void WebColorTest(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 1843 | { |
WiredHome | 41:2956a0a221e5 | 1844 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 1845 | pc.printf("Web Color Test\r\n"); |
WiredHome | 23:a50ded45dbaf | 1846 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 1847 | display.foreground(Blue); |
WiredHome | 32:0e4f2ae512e2 | 1848 | display.window(0,0, display.width(), display.height()); |
WiredHome | 23:a50ded45dbaf | 1849 | display.cls(); |
WiredHome | 59:fb40aad4efd4 | 1850 | display.SetTextFontSize(1,1); |
WiredHome | 59:fb40aad4efd4 | 1851 | display.puts(200,0, "Web Color Test"); |
WiredHome | 59:fb40aad4efd4 | 1852 | display.SetTextCursor(0,0); |
WiredHome | 59:fb40aad4efd4 | 1853 | display.puts(" "); |
WiredHome | 59:fb40aad4efd4 | 1854 | for (int i=0; i<16; i++) |
WiredHome | 59:fb40aad4efd4 | 1855 | display.printf("%X", i&0xF); |
WiredHome | 59:fb40aad4efd4 | 1856 | display.puts("\r\n0 "); |
WiredHome | 23:a50ded45dbaf | 1857 | for (int i=0; i<sizeof(WebColors)/sizeof(WebColors[0]); i++) { |
WiredHome | 23:a50ded45dbaf | 1858 | display.background(WebColors[i]); |
WiredHome | 23:a50ded45dbaf | 1859 | display.puts(" "); |
WiredHome | 59:fb40aad4efd4 | 1860 | if (i % 16 == 15 && i < 255) { |
WiredHome | 59:fb40aad4efd4 | 1861 | display.printf("\r\n%X ", ((i+1)/16)); |
WiredHome | 59:fb40aad4efd4 | 1862 | } |
WiredHome | 23:a50ded45dbaf | 1863 | } |
WiredHome | 23:a50ded45dbaf | 1864 | display.SetTextFontSize(1,1); |
WiredHome | 23:a50ded45dbaf | 1865 | } |
WiredHome | 23:a50ded45dbaf | 1866 | |
WiredHome | 44:207594dece70 | 1867 | |
WiredHome | 37:f19b7e7449dc | 1868 | void PixelTest(RA8875 & display, Serial & pc) |
WiredHome | 37:f19b7e7449dc | 1869 | { |
WiredHome | 37:f19b7e7449dc | 1870 | int i, c, x, y; |
WiredHome | 37:f19b7e7449dc | 1871 | |
WiredHome | 41:2956a0a221e5 | 1872 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 1873 | pc.printf("Pixel Test\r\n"); |
WiredHome | 37:f19b7e7449dc | 1874 | display.background(Black); |
WiredHome | 37:f19b7e7449dc | 1875 | display.foreground(Blue); |
WiredHome | 37:f19b7e7449dc | 1876 | display.cls(); |
WiredHome | 37:f19b7e7449dc | 1877 | display.puts(0,0, "Pixel Test"); |
WiredHome | 37:f19b7e7449dc | 1878 | for (i=0; i<1000; i++) { |
WiredHome | 37:f19b7e7449dc | 1879 | x = rand() % 480; |
WiredHome | 37:f19b7e7449dc | 1880 | y = 16 + rand() % (272-16); |
WiredHome | 37:f19b7e7449dc | 1881 | c = rand() % 16; |
WiredHome | 37:f19b7e7449dc | 1882 | //pc.printf(" (%d,%d) - %d\r\n", x,y,r1); |
WiredHome | 37:f19b7e7449dc | 1883 | display.pixel(x,y, display.DOSColor(c)); |
WiredHome | 37:f19b7e7449dc | 1884 | } |
WiredHome | 37:f19b7e7449dc | 1885 | } |
WiredHome | 37:f19b7e7449dc | 1886 | |
WiredHome | 44:207594dece70 | 1887 | |
WiredHome | 23:a50ded45dbaf | 1888 | void LineTest(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 1889 | { |
WiredHome | 23:a50ded45dbaf | 1890 | int i, x, y, x2, y2; |
WiredHome | 23:a50ded45dbaf | 1891 | |
WiredHome | 41:2956a0a221e5 | 1892 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 1893 | pc.printf("Line Test\r\n"); |
WiredHome | 23:a50ded45dbaf | 1894 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 1895 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 1896 | display.cls(); |
WiredHome | 23:a50ded45dbaf | 1897 | display.puts(0,0, "Line Test"); |
WiredHome | 23:a50ded45dbaf | 1898 | for (i=0; i<16; i++) { |
WiredHome | 23:a50ded45dbaf | 1899 | // Lines |
WiredHome | 23:a50ded45dbaf | 1900 | x = rand() % 480; |
WiredHome | 23:a50ded45dbaf | 1901 | y = rand() % 272; |
WiredHome | 23:a50ded45dbaf | 1902 | x2 = rand() % 480; |
WiredHome | 23:a50ded45dbaf | 1903 | y2 = rand() % 272; |
WiredHome | 23:a50ded45dbaf | 1904 | display.line(x,y, x2,y2, display.DOSColor(i)); |
WiredHome | 23:a50ded45dbaf | 1905 | } |
WiredHome | 62:ba5d33438fda | 1906 | display.foreground(BrightRed); |
WiredHome | 62:ba5d33438fda | 1907 | display.foreground(BrightGreen); |
WiredHome | 62:ba5d33438fda | 1908 | display.foreground(BrightBlue); |
WiredHome | 62:ba5d33438fda | 1909 | display.line(55,50, 79,74, BrightRed); |
WiredHome | 62:ba5d33438fda | 1910 | display.line(57,50, 81,74, BrightGreen); |
WiredHome | 62:ba5d33438fda | 1911 | display.line(59,50, 83,74, BrightBlue); |
WiredHome | 62:ba5d33438fda | 1912 | // horz |
WiredHome | 62:ba5d33438fda | 1913 | display.line(30,40, 32,40, BrightRed); |
WiredHome | 62:ba5d33438fda | 1914 | display.line(30,42, 32,42, BrightGreen); |
WiredHome | 62:ba5d33438fda | 1915 | display.line(30,44, 32,44, BrightBlue); |
WiredHome | 62:ba5d33438fda | 1916 | // vert |
WiredHome | 62:ba5d33438fda | 1917 | display.line(20,40, 20,42, BrightRed); |
WiredHome | 62:ba5d33438fda | 1918 | display.line(22,40, 22,42, BrightGreen); |
WiredHome | 62:ba5d33438fda | 1919 | display.line(24,40, 24,42, BrightBlue); |
WiredHome | 62:ba5d33438fda | 1920 | // compare point to line-point |
WiredHome | 62:ba5d33438fda | 1921 | display.pixel(20,50, BrightRed); |
WiredHome | 62:ba5d33438fda | 1922 | display.pixel(22,50, BrightGreen); |
WiredHome | 62:ba5d33438fda | 1923 | display.pixel(24,50, BrightBlue); |
WiredHome | 62:ba5d33438fda | 1924 | display.line(20,52, 20,52, BrightRed); |
WiredHome | 62:ba5d33438fda | 1925 | display.line(22,52, 22,52, BrightGreen); |
WiredHome | 62:ba5d33438fda | 1926 | display.line(24,52, 24,52, BrightBlue); |
WiredHome | 73:f22a18707b5e | 1927 | |
WiredHome | 62:ba5d33438fda | 1928 | // point |
WiredHome | 62:ba5d33438fda | 1929 | display.line(50,50, 50,50, Red); |
WiredHome | 62:ba5d33438fda | 1930 | display.line(52,52, 52,52, Green); |
WiredHome | 62:ba5d33438fda | 1931 | display.line(54,54, 54,54, Blue); |
WiredHome | 62:ba5d33438fda | 1932 | display.line(60,60, 60,60, BrightRed); |
WiredHome | 62:ba5d33438fda | 1933 | display.line(62,62, 62,62, BrightGreen); |
WiredHome | 62:ba5d33438fda | 1934 | display.line(64,64, 64,64, BrightBlue); |
WiredHome | 62:ba5d33438fda | 1935 | display.line(70,70, 70,70, DarkRed); |
WiredHome | 62:ba5d33438fda | 1936 | display.line(72,72, 72,72, DarkGreen); |
WiredHome | 62:ba5d33438fda | 1937 | display.line(74,74, 74,74, DarkBlue); |
WiredHome | 23:a50ded45dbaf | 1938 | } |
WiredHome | 23:a50ded45dbaf | 1939 | |
WiredHome | 44:207594dece70 | 1940 | |
WiredHome | 23:a50ded45dbaf | 1941 | void RectangleTest(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 1942 | { |
WiredHome | 23:a50ded45dbaf | 1943 | int i, x1,y1, x2,y2; |
WiredHome | 23:a50ded45dbaf | 1944 | |
WiredHome | 41:2956a0a221e5 | 1945 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 1946 | pc.printf("Rectangle Test\r\n"); |
WiredHome | 23:a50ded45dbaf | 1947 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 1948 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 1949 | display.cls(); |
WiredHome | 23:a50ded45dbaf | 1950 | display.puts(0,0, "Rectangle Test"); |
WiredHome | 23:a50ded45dbaf | 1951 | for (i=0; i<16; i++) { |
WiredHome | 23:a50ded45dbaf | 1952 | x1 = rand() % 240; |
WiredHome | 23:a50ded45dbaf | 1953 | y1 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 1954 | x2 = rand() % 240; |
WiredHome | 23:a50ded45dbaf | 1955 | y2 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 1956 | display.rect(x1,y1, x2,y2, display.DOSColor(i)); |
WiredHome | 23:a50ded45dbaf | 1957 | |
WiredHome | 23:a50ded45dbaf | 1958 | x1 = 240 + rand() % 240; |
WiredHome | 23:a50ded45dbaf | 1959 | y1 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 1960 | x2 = 240 + rand() % 240; |
WiredHome | 23:a50ded45dbaf | 1961 | y2 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 1962 | display.rect(x1,y1, x2,y2, FILL); |
WiredHome | 23:a50ded45dbaf | 1963 | } |
WiredHome | 23:a50ded45dbaf | 1964 | } |
WiredHome | 23:a50ded45dbaf | 1965 | |
WiredHome | 44:207594dece70 | 1966 | |
WiredHome | 44:207594dece70 | 1967 | void LayerTest(RA8875 & display, Serial & pc) |
WiredHome | 44:207594dece70 | 1968 | { |
WiredHome | 44:207594dece70 | 1969 | loc_t i, x1,y1, x2,y2, r1,r2; |
WiredHome | 44:207594dece70 | 1970 | |
WiredHome | 44:207594dece70 | 1971 | if (!SuppressSlowStuff) |
WiredHome | 44:207594dece70 | 1972 | pc.printf("Layer Test\r\n"); |
WiredHome | 44:207594dece70 | 1973 | |
WiredHome | 50:2c4f474a2453 | 1974 | display.SelectDrawingLayer(0); |
WiredHome | 44:207594dece70 | 1975 | display.background(Black); |
WiredHome | 44:207594dece70 | 1976 | display.foreground(Blue); |
WiredHome | 44:207594dece70 | 1977 | display.cls(); |
WiredHome | 44:207594dece70 | 1978 | display.puts(0,0, "Layer 0"); |
WiredHome | 44:207594dece70 | 1979 | for (i=0; i<16; i++) { |
WiredHome | 44:207594dece70 | 1980 | x1 = rand() % 240; |
WiredHome | 44:207594dece70 | 1981 | y1 = 50 + rand() % 200; |
WiredHome | 44:207594dece70 | 1982 | x2 = x1 + rand() % 100; |
WiredHome | 44:207594dece70 | 1983 | y2 = y1 + rand() % 100; |
WiredHome | 44:207594dece70 | 1984 | r1 = rand() % (x2 - x1)/2; |
WiredHome | 44:207594dece70 | 1985 | r2 = rand() % (y2 - y1)/2; |
WiredHome | 44:207594dece70 | 1986 | display.roundrect(x1,y1, x2,y2, r1,r2, display.DOSColor(i)); |
WiredHome | 44:207594dece70 | 1987 | if (!SuppressSlowStuff) |
WiredHome | 44:207594dece70 | 1988 | wait_ms(20); |
WiredHome | 44:207594dece70 | 1989 | } |
WiredHome | 44:207594dece70 | 1990 | if (!SuppressSlowStuff) |
WiredHome | 44:207594dece70 | 1991 | wait_ms(1000); |
WiredHome | 44:207594dece70 | 1992 | |
WiredHome | 50:2c4f474a2453 | 1993 | display.SelectDrawingLayer(1); |
WiredHome | 44:207594dece70 | 1994 | display.background(Black); |
WiredHome | 44:207594dece70 | 1995 | display.foreground(Yellow); |
WiredHome | 44:207594dece70 | 1996 | display.cls(); |
WiredHome | 44:207594dece70 | 1997 | display.puts(240,0, "Layer 1"); |
WiredHome | 44:207594dece70 | 1998 | for (i=0; i<16; i++) { |
WiredHome | 44:207594dece70 | 1999 | x1 = 300 + rand() % 100; |
WiredHome | 44:207594dece70 | 2000 | y1 = 70 + rand() % 200; |
WiredHome | 44:207594dece70 | 2001 | r1 = rand() % min(y1 - 20, 100); |
WiredHome | 44:207594dece70 | 2002 | display.circle(x1,y1,r1, display.DOSColor(i)); |
WiredHome | 44:207594dece70 | 2003 | if (!SuppressSlowStuff) |
WiredHome | 44:207594dece70 | 2004 | wait_ms(20); |
WiredHome | 44:207594dece70 | 2005 | } |
WiredHome | 56:7a85d226ad0d | 2006 | display.SetLayerMode(RA8875::ShowLayer1); // Show it after the build-up |
WiredHome | 44:207594dece70 | 2007 | if (!SuppressSlowStuff) |
WiredHome | 44:207594dece70 | 2008 | wait_ms(2000); |
WiredHome | 44:207594dece70 | 2009 | |
WiredHome | 50:2c4f474a2453 | 2010 | display.SelectDrawingLayer(0); |
WiredHome | 56:7a85d226ad0d | 2011 | display.SetLayerMode(RA8875::ShowLayer0); // Show Layer 0 again |
WiredHome | 44:207594dece70 | 2012 | if (!SuppressSlowStuff) |
WiredHome | 44:207594dece70 | 2013 | wait_ms(1000); |
WiredHome | 53:86d24b9480b9 | 2014 | display.SetLayerMode(RA8875::TransparentMode); // Transparent mode |
WiredHome | 44:207594dece70 | 2015 | if (!SuppressSlowStuff) |
WiredHome | 44:207594dece70 | 2016 | wait_ms(1000); |
WiredHome | 44:207594dece70 | 2017 | for (i=0; i<=8; i++) { |
WiredHome | 44:207594dece70 | 2018 | display.SetLayerTransparency(i, 8-i); |
WiredHome | 44:207594dece70 | 2019 | if (!SuppressSlowStuff) |
WiredHome | 44:207594dece70 | 2020 | wait_ms(200); |
WiredHome | 44:207594dece70 | 2021 | } |
WiredHome | 73:f22a18707b5e | 2022 | |
WiredHome | 44:207594dece70 | 2023 | // Restore before we exit |
WiredHome | 44:207594dece70 | 2024 | display.SetLayerTransparency(0, 0); |
WiredHome | 56:7a85d226ad0d | 2025 | display.SetLayerMode(RA8875::ShowLayer0); // Restore to layer 0 |
WiredHome | 44:207594dece70 | 2026 | } |
WiredHome | 44:207594dece70 | 2027 | |
WiredHome | 44:207594dece70 | 2028 | |
WiredHome | 23:a50ded45dbaf | 2029 | void RoundRectTest(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 2030 | { |
WiredHome | 37:f19b7e7449dc | 2031 | loc_t i, x1,y1, x2,y2, r1,r2; |
WiredHome | 23:a50ded45dbaf | 2032 | |
WiredHome | 41:2956a0a221e5 | 2033 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 2034 | pc.printf("Round Rectangle Test\r\n"); |
WiredHome | 23:a50ded45dbaf | 2035 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 2036 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 2037 | display.cls(); |
WiredHome | 23:a50ded45dbaf | 2038 | display.puts(0,0, "Rounded Rectangle Test"); |
WiredHome | 73:f22a18707b5e | 2039 | |
WiredHome | 23:a50ded45dbaf | 2040 | for (i=0; i<16; i++) { |
WiredHome | 23:a50ded45dbaf | 2041 | x1 = rand() % 240; |
WiredHome | 23:a50ded45dbaf | 2042 | y1 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2043 | x2 = x1 + rand() % 100; |
WiredHome | 23:a50ded45dbaf | 2044 | y2 = y1 + rand() % 100; |
WiredHome | 23:a50ded45dbaf | 2045 | r1 = rand() % (x2 - x1)/2; |
WiredHome | 23:a50ded45dbaf | 2046 | r2 = rand() % (y2 - y1)/2; |
WiredHome | 23:a50ded45dbaf | 2047 | display.roundrect(x1,y1, x2,y2, 5,8, display.DOSColor(i)); |
WiredHome | 23:a50ded45dbaf | 2048 | |
WiredHome | 23:a50ded45dbaf | 2049 | x1 = 240 + rand() % 240; |
WiredHome | 23:a50ded45dbaf | 2050 | y1 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2051 | x2 = x1 + rand() % 100; |
WiredHome | 23:a50ded45dbaf | 2052 | y2 = y1 + rand() % 100; |
WiredHome | 23:a50ded45dbaf | 2053 | r1 = rand() % (x2 - x1)/2; |
WiredHome | 23:a50ded45dbaf | 2054 | r2 = rand() % (y2 - y1)/2; |
WiredHome | 23:a50ded45dbaf | 2055 | display.roundrect(x1,y1, x2,y2, r1,r2, FILL); |
WiredHome | 23:a50ded45dbaf | 2056 | } |
WiredHome | 23:a50ded45dbaf | 2057 | } |
WiredHome | 23:a50ded45dbaf | 2058 | |
WiredHome | 44:207594dece70 | 2059 | |
WiredHome | 23:a50ded45dbaf | 2060 | void TriangleTest(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 2061 | { |
WiredHome | 23:a50ded45dbaf | 2062 | int i, x1, y1, x2, y2, x3, y3; |
WiredHome | 23:a50ded45dbaf | 2063 | |
WiredHome | 41:2956a0a221e5 | 2064 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 2065 | pc.printf("Triangle Test\r\n"); |
WiredHome | 23:a50ded45dbaf | 2066 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 2067 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 2068 | display.cls(); |
WiredHome | 23:a50ded45dbaf | 2069 | display.puts(0,0, "Triangle Test"); |
WiredHome | 23:a50ded45dbaf | 2070 | |
WiredHome | 23:a50ded45dbaf | 2071 | x1 = 150; |
WiredHome | 23:a50ded45dbaf | 2072 | y1 = 2; |
WiredHome | 23:a50ded45dbaf | 2073 | x2 = 190; |
WiredHome | 23:a50ded45dbaf | 2074 | y2 = 7; |
WiredHome | 23:a50ded45dbaf | 2075 | x3 = 170; |
WiredHome | 23:a50ded45dbaf | 2076 | y3 = 16; |
WiredHome | 23:a50ded45dbaf | 2077 | display.triangle(x1,y1, x2,y2, x3,y3); |
WiredHome | 23:a50ded45dbaf | 2078 | |
WiredHome | 23:a50ded45dbaf | 2079 | x1 = 200; |
WiredHome | 23:a50ded45dbaf | 2080 | y1 = 2; |
WiredHome | 23:a50ded45dbaf | 2081 | x2 = 240; |
WiredHome | 23:a50ded45dbaf | 2082 | y2 = 7; |
WiredHome | 23:a50ded45dbaf | 2083 | x3 = 220; |
WiredHome | 23:a50ded45dbaf | 2084 | y3 = 16; |
WiredHome | 23:a50ded45dbaf | 2085 | display.filltriangle(x1,y1, x2,y2, x3,y3, BrightRed); |
WiredHome | 23:a50ded45dbaf | 2086 | |
WiredHome | 23:a50ded45dbaf | 2087 | x1 = 300; |
WiredHome | 23:a50ded45dbaf | 2088 | y1 = 2; |
WiredHome | 23:a50ded45dbaf | 2089 | x2 = 340; |
WiredHome | 23:a50ded45dbaf | 2090 | y2 = 7; |
WiredHome | 23:a50ded45dbaf | 2091 | x3 = 320; |
WiredHome | 23:a50ded45dbaf | 2092 | y3 = 16; |
WiredHome | 23:a50ded45dbaf | 2093 | display.triangle(x1,y1, x2,y2, x3,y3, NOFILL); |
WiredHome | 23:a50ded45dbaf | 2094 | |
WiredHome | 23:a50ded45dbaf | 2095 | x1 = 400; |
WiredHome | 23:a50ded45dbaf | 2096 | y1 = 2; |
WiredHome | 23:a50ded45dbaf | 2097 | x2 = 440; |
WiredHome | 23:a50ded45dbaf | 2098 | y2 = 7; |
WiredHome | 23:a50ded45dbaf | 2099 | x3 = 420; |
WiredHome | 23:a50ded45dbaf | 2100 | y3 = 16; |
WiredHome | 23:a50ded45dbaf | 2101 | display.triangle(x1,y1, x2,y2, x3,y3, Blue); |
WiredHome | 23:a50ded45dbaf | 2102 | |
WiredHome | 23:a50ded45dbaf | 2103 | for (i=0; i<16; i++) { |
WiredHome | 23:a50ded45dbaf | 2104 | x1 = rand() % 240; |
WiredHome | 23:a50ded45dbaf | 2105 | y1 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2106 | x2 = rand() % 240; |
WiredHome | 23:a50ded45dbaf | 2107 | y2 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2108 | x3 = rand() % 240; |
WiredHome | 23:a50ded45dbaf | 2109 | y3 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2110 | display.triangle(x1,y1, x2,y2, x3,y3, display.DOSColor(i)); |
WiredHome | 23:a50ded45dbaf | 2111 | x1 = 240 + rand() % 240; |
WiredHome | 23:a50ded45dbaf | 2112 | y1 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2113 | x2 = 240 + rand() % 240; |
WiredHome | 23:a50ded45dbaf | 2114 | y2 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2115 | x3 = 240 + rand() % 240; |
WiredHome | 23:a50ded45dbaf | 2116 | y3 = 50 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2117 | display.triangle(x1,y1, x2,y2, x3,y3, FILL); |
WiredHome | 23:a50ded45dbaf | 2118 | } |
WiredHome | 23:a50ded45dbaf | 2119 | } |
WiredHome | 23:a50ded45dbaf | 2120 | |
WiredHome | 44:207594dece70 | 2121 | |
WiredHome | 23:a50ded45dbaf | 2122 | void CircleTest(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 2123 | { |
WiredHome | 23:a50ded45dbaf | 2124 | int i, x, y, r1; |
WiredHome | 23:a50ded45dbaf | 2125 | |
WiredHome | 41:2956a0a221e5 | 2126 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 2127 | pc.printf("Circle Test\r\n"); |
WiredHome | 23:a50ded45dbaf | 2128 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 2129 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 2130 | display.cls(); |
WiredHome | 23:a50ded45dbaf | 2131 | display.puts(0,0, "Circle Test"); |
WiredHome | 23:a50ded45dbaf | 2132 | for (i=0; i<16; i++) { |
WiredHome | 23:a50ded45dbaf | 2133 | x = 100 + rand() % 100; |
WiredHome | 23:a50ded45dbaf | 2134 | y = 70 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2135 | r1 = rand() % min(y - 20, 100); |
WiredHome | 23:a50ded45dbaf | 2136 | //pc.printf(" (%d,%d) - %d\r\n", x,y,r1); |
WiredHome | 23:a50ded45dbaf | 2137 | display.circle(x,y,r1, display.DOSColor(i)); |
WiredHome | 23:a50ded45dbaf | 2138 | |
WiredHome | 23:a50ded45dbaf | 2139 | x = 300 + rand() % 100; |
WiredHome | 23:a50ded45dbaf | 2140 | y = 70 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2141 | r1 = rand() % min(y - 20, 100); |
WiredHome | 23:a50ded45dbaf | 2142 | //pc.printf(" (%d,%d) - %d FILL\r\n", x,y,r1); |
WiredHome | 23:a50ded45dbaf | 2143 | display.circle(x,y,r1, display.DOSColor(i), FILL); |
WiredHome | 23:a50ded45dbaf | 2144 | } |
WiredHome | 23:a50ded45dbaf | 2145 | } |
WiredHome | 23:a50ded45dbaf | 2146 | |
WiredHome | 44:207594dece70 | 2147 | |
WiredHome | 23:a50ded45dbaf | 2148 | void EllipseTest(RA8875 & display, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 2149 | { |
WiredHome | 23:a50ded45dbaf | 2150 | int i,x,y,r1,r2; |
WiredHome | 23:a50ded45dbaf | 2151 | |
WiredHome | 41:2956a0a221e5 | 2152 | if (!SuppressSlowStuff) |
WiredHome | 41:2956a0a221e5 | 2153 | pc.printf("Ellipse Test\r\n"); |
WiredHome | 23:a50ded45dbaf | 2154 | display.background(Black); |
WiredHome | 23:a50ded45dbaf | 2155 | display.foreground(Blue); |
WiredHome | 23:a50ded45dbaf | 2156 | display.cls(); |
WiredHome | 23:a50ded45dbaf | 2157 | display.puts(0,0, "Ellipse Test"); |
WiredHome | 23:a50ded45dbaf | 2158 | for (i=0; i<16; i++) { |
WiredHome | 23:a50ded45dbaf | 2159 | x = 100 + rand() % 100; |
WiredHome | 23:a50ded45dbaf | 2160 | y = 70 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2161 | r1 = rand() % min(y - 20, 100); |
WiredHome | 23:a50ded45dbaf | 2162 | r2 = rand() % min(y - 20, 100); |
WiredHome | 23:a50ded45dbaf | 2163 | display.ellipse(x,y,r1,r2, display.DOSColor(i)); |
WiredHome | 23:a50ded45dbaf | 2164 | |
WiredHome | 23:a50ded45dbaf | 2165 | x = 300 + rand() % 100; |
WiredHome | 23:a50ded45dbaf | 2166 | y = 70 + rand() % 200; |
WiredHome | 23:a50ded45dbaf | 2167 | r1 = rand() % min(y - 20, 100); |
WiredHome | 23:a50ded45dbaf | 2168 | r2 = rand() % min(y - 20, 100); |
WiredHome | 23:a50ded45dbaf | 2169 | display.ellipse(x,y,r1,r2, FILL); |
WiredHome | 23:a50ded45dbaf | 2170 | } |
WiredHome | 23:a50ded45dbaf | 2171 | } |
WiredHome | 23:a50ded45dbaf | 2172 | |
WiredHome | 44:207594dece70 | 2173 | |
WiredHome | 37:f19b7e7449dc | 2174 | void TestGraphicsBitmap(RA8875 & display, Serial & pc) |
WiredHome | 37:f19b7e7449dc | 2175 | { |
WiredHome | 37:f19b7e7449dc | 2176 | LocalFileSystem local("local"); |
WiredHome | 41:2956a0a221e5 | 2177 | if (!SuppressSlowStuff) |
WiredHome | 73:f22a18707b5e | 2178 | pc.printf("Bitmap File Load\r\n"); |
WiredHome | 37:f19b7e7449dc | 2179 | display.background(Black); |
WiredHome | 37:f19b7e7449dc | 2180 | display.foreground(Blue); |
WiredHome | 37:f19b7e7449dc | 2181 | display.cls(); |
WiredHome | 37:f19b7e7449dc | 2182 | display.puts(0,0, "Graphics Test, loading /local/TestPat.bmp"); |
WiredHome | 37:f19b7e7449dc | 2183 | wait(3); |
WiredHome | 37:f19b7e7449dc | 2184 | |
WiredHome | 37:f19b7e7449dc | 2185 | int r = display.RenderBitmapFile(0,0, "/local/TestPat.bmp"); |
WiredHome | 59:fb40aad4efd4 | 2186 | if (!SuppressSlowStuff) |
WiredHome | 59:fb40aad4efd4 | 2187 | pc.printf(" returned %d\r\n", r); |
WiredHome | 37:f19b7e7449dc | 2188 | } |
WiredHome | 37:f19b7e7449dc | 2189 | |
WiredHome | 44:207594dece70 | 2190 | |
WiredHome | 77:9206c13aa527 | 2191 | void TouchPanelTest(RA8875 & display, Serial & pc) |
WiredHome | 77:9206c13aa527 | 2192 | { |
WiredHome | 77:9206c13aa527 | 2193 | Timer t; |
WiredHome | 77:9206c13aa527 | 2194 | loc_t x, y; |
WiredHome | 78:faf49c381591 | 2195 | tpMatrix_t calmatrix; |
WiredHome | 78:faf49c381591 | 2196 | |
WiredHome | 77:9206c13aa527 | 2197 | display.background(Black); |
WiredHome | 77:9206c13aa527 | 2198 | display.foreground(Blue); |
WiredHome | 77:9206c13aa527 | 2199 | display.cls(); |
WiredHome | 77:9206c13aa527 | 2200 | display.puts(0,0, "Touch Panel Test\r\n"); |
WiredHome | 78:faf49c381591 | 2201 | pc.printf("Touch Panel Test\r\n"); |
WiredHome | 77:9206c13aa527 | 2202 | display.TouchPanelInit(); |
WiredHome | 78:faf49c381591 | 2203 | pc.printf(" TP: c - calibrate, r - restore, t - test\r\n"); |
WiredHome | 78:faf49c381591 | 2204 | int c = pc.getc(); |
WiredHome | 78:faf49c381591 | 2205 | if (c == 'c') { |
WiredHome | 78:faf49c381591 | 2206 | point_t pTest[3] = |
WiredHome | 78:faf49c381591 | 2207 | { { 50, 50 }, {450, 150}, {225,250} }; |
WiredHome | 78:faf49c381591 | 2208 | point_t pSample[3]; |
WiredHome | 78:faf49c381591 | 2209 | for (int i=0; i<3; i++) { |
WiredHome | 78:faf49c381591 | 2210 | display.foreground(Blue); |
WiredHome | 78:faf49c381591 | 2211 | display.printf(" (%3d,%3d) => ", pTest[i].x, pTest[i].y); |
WiredHome | 78:faf49c381591 | 2212 | display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, White); |
WiredHome | 78:faf49c381591 | 2213 | display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, White); |
WiredHome | 78:faf49c381591 | 2214 | while (!display.TouchPanelRead(&x, &y)) |
WiredHome | 78:faf49c381591 | 2215 | wait_ms(20); |
WiredHome | 78:faf49c381591 | 2216 | pSample[i].x = x; |
WiredHome | 78:faf49c381591 | 2217 | pSample[i].y = y; |
WiredHome | 78:faf49c381591 | 2218 | display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, Black); |
WiredHome | 78:faf49c381591 | 2219 | display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, Black); |
WiredHome | 78:faf49c381591 | 2220 | display.foreground(Blue); |
WiredHome | 78:faf49c381591 | 2221 | display.printf(" (%4d,%4d)\r\n", x,y); |
WiredHome | 78:faf49c381591 | 2222 | while (display.TouchPanelRead(&x, &y)) |
WiredHome | 78:faf49c381591 | 2223 | wait_ms(20); |
WiredHome | 78:faf49c381591 | 2224 | wait(2); |
WiredHome | 78:faf49c381591 | 2225 | } |
WiredHome | 78:faf49c381591 | 2226 | display.TouchPanelCalibrate(pTest, pSample, &calmatrix); |
WiredHome | 78:faf49c381591 | 2227 | display.printf(" Writing calibration to tpcal.cfg\r\n"); |
WiredHome | 78:faf49c381591 | 2228 | FILE * fh = fopen("/local/tpcal.cfg", "wb"); |
WiredHome | 78:faf49c381591 | 2229 | if (fh) { |
WiredHome | 78:faf49c381591 | 2230 | fwrite(&calmatrix, sizeof(calmatrix), 1, fh); |
WiredHome | 78:faf49c381591 | 2231 | fclose(fh); |
WiredHome | 78:faf49c381591 | 2232 | } |
WiredHome | 78:faf49c381591 | 2233 | display.printf(" Calibration is complete."); |
WiredHome | 78:faf49c381591 | 2234 | } else if (c == 'r') { |
WiredHome | 78:faf49c381591 | 2235 | display.printf(" Reading calibration from tpcal.cfg\r\n"); |
WiredHome | 78:faf49c381591 | 2236 | FILE * fh = fopen("/local/tpcal.cfg", "rb"); |
WiredHome | 78:faf49c381591 | 2237 | if (fh) { |
WiredHome | 78:faf49c381591 | 2238 | fread(&calmatrix, sizeof(calmatrix), 1, fh); |
WiredHome | 78:faf49c381591 | 2239 | fclose(fh); |
WiredHome | 78:faf49c381591 | 2240 | } |
WiredHome | 78:faf49c381591 | 2241 | display.printf(" Calibration is complete."); |
WiredHome | 78:faf49c381591 | 2242 | display.TouchPanelSetMatrix(&calmatrix); |
WiredHome | 77:9206c13aa527 | 2243 | } |
WiredHome | 77:9206c13aa527 | 2244 | t.start(); |
WiredHome | 77:9206c13aa527 | 2245 | do { |
WiredHome | 77:9206c13aa527 | 2246 | point_t point = {0, 0}; |
WiredHome | 77:9206c13aa527 | 2247 | if (display.TouchPanelPoint(&point)) { |
WiredHome | 77:9206c13aa527 | 2248 | display.pixel(point.x, point.y, Red); |
WiredHome | 77:9206c13aa527 | 2249 | } |
WiredHome | 77:9206c13aa527 | 2250 | } while (t.read_ms() < 30000); |
WiredHome | 77:9206c13aa527 | 2251 | pc.printf(">"); |
WiredHome | 77:9206c13aa527 | 2252 | } |
WiredHome | 77:9206c13aa527 | 2253 | |
WiredHome | 77:9206c13aa527 | 2254 | |
WiredHome | 41:2956a0a221e5 | 2255 | void SpeedTest(RA8875 & display, Serial & pc) |
WiredHome | 41:2956a0a221e5 | 2256 | { |
WiredHome | 41:2956a0a221e5 | 2257 | Timer t; |
WiredHome | 41:2956a0a221e5 | 2258 | SuppressSlowStuff = true; |
WiredHome | 41:2956a0a221e5 | 2259 | pc.printf("\r\nSpeedTest disables delays, runs tests, reports overall time.\r\n"); |
WiredHome | 41:2956a0a221e5 | 2260 | t.start(); |
WiredHome | 41:2956a0a221e5 | 2261 | // do stuff fast |
WiredHome | 41:2956a0a221e5 | 2262 | TextCursorTest(display, pc); |
WiredHome | 49:c5182231d1b9 | 2263 | TextWrapTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2264 | BacklightTest(display, pc, 0); |
WiredHome | 41:2956a0a221e5 | 2265 | BacklightTest2(display, pc); |
WiredHome | 41:2956a0a221e5 | 2266 | ExternalFontTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2267 | DOSColorTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2268 | WebColorTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2269 | PixelTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2270 | LineTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2271 | RectangleTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2272 | RoundRectTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2273 | TriangleTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2274 | CircleTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2275 | EllipseTest(display, pc); |
WiredHome | 44:207594dece70 | 2276 | LayerTest(display, pc); |
WiredHome | 41:2956a0a221e5 | 2277 | //TestGraphicsBitmap(display, pc); |
WiredHome | 41:2956a0a221e5 | 2278 | pc.printf("SpeedTest completed in %d msec\r\n", t.read_ms()); |
WiredHome | 73:f22a18707b5e | 2279 | #ifdef PERF_METRICS |
WiredHome | 41:2956a0a221e5 | 2280 | display.ReportPerformance(pc); |
WiredHome | 73:f22a18707b5e | 2281 | #endif |
WiredHome | 41:2956a0a221e5 | 2282 | SuppressSlowStuff = false; |
WiredHome | 41:2956a0a221e5 | 2283 | } |
WiredHome | 41:2956a0a221e5 | 2284 | |
WiredHome | 44:207594dece70 | 2285 | |
WiredHome | 41:2956a0a221e5 | 2286 | void PrintScreen(RA8875 & display, Serial & pc) |
WiredHome | 41:2956a0a221e5 | 2287 | { |
WiredHome | 41:2956a0a221e5 | 2288 | if (!SuppressSlowStuff) |
WiredHome | 73:f22a18707b5e | 2289 | pc.printf("PrintScreen\r\n"); |
WiredHome | 41:2956a0a221e5 | 2290 | display.PrintScreen( 0,0, 480,272, "/local/Capture.bmp"); |
WiredHome | 41:2956a0a221e5 | 2291 | } |
WiredHome | 41:2956a0a221e5 | 2292 | |
WiredHome | 44:207594dece70 | 2293 | |
WiredHome | 23:a50ded45dbaf | 2294 | void RunTestSet(RA8875 & lcd, Serial & pc) |
WiredHome | 23:a50ded45dbaf | 2295 | { |
WiredHome | 23:a50ded45dbaf | 2296 | int q = 0; |
WiredHome | 23:a50ded45dbaf | 2297 | int automode = 0; |
WiredHome | 49:c5182231d1b9 | 2298 | const unsigned char modelist[] = "BDWtGLlFROTPCEbw"; // auto-test in this order. |
WiredHome | 23:a50ded45dbaf | 2299 | |
WiredHome | 23:a50ded45dbaf | 2300 | while(1) { |
WiredHome | 23:a50ded45dbaf | 2301 | pc.printf("\r\n" |
WiredHome | 41:2956a0a221e5 | 2302 | "B - Backlight up b - backlight dim\r\n" |
WiredHome | 41:2956a0a221e5 | 2303 | "D - DOS Colors W - Web Colors\r\n" |
WiredHome | 41:2956a0a221e5 | 2304 | "t - text cursor G - Graphics Bitmap\r\n" |
WiredHome | 41:2956a0a221e5 | 2305 | "L - Lines F - external Font\r\n" |
WiredHome | 41:2956a0a221e5 | 2306 | "R - Rectangles O - rOund rectangles\r\n" |
WiredHome | 41:2956a0a221e5 | 2307 | "T - Triangles P - Pixels \r\n" |
WiredHome | 41:2956a0a221e5 | 2308 | "C - Circles E - Ellipses\r\n" |
WiredHome | 41:2956a0a221e5 | 2309 | "A - Auto Test mode S - Speed Test\r\n" |
WiredHome | 77:9206c13aa527 | 2310 | "K - Keypad Test s - touch screen test\r\n" |
WiredHome | 41:2956a0a221e5 | 2311 | "p - print screen r - reset \r\n" |
WiredHome | 49:c5182231d1b9 | 2312 | "l - layer test w - wrapping text \r\n" |
WiredHome | 73:f22a18707b5e | 2313 | #ifdef PERF_METRICS |
WiredHome | 41:2956a0a221e5 | 2314 | "0 - clear performance 1 - report performance\r\n" |
WiredHome | 73:f22a18707b5e | 2315 | #endif |
WiredHome | 23:a50ded45dbaf | 2316 | "> "); |
WiredHome | 23:a50ded45dbaf | 2317 | if (automode == -1 || pc.readable()) { |
WiredHome | 23:a50ded45dbaf | 2318 | automode = -1; |
WiredHome | 37:f19b7e7449dc | 2319 | q = pc.getc(); |
WiredHome | 37:f19b7e7449dc | 2320 | while (pc.readable()) |
WiredHome | 37:f19b7e7449dc | 2321 | pc.getc(); |
WiredHome | 23:a50ded45dbaf | 2322 | } else if (automode >= 0) { |
WiredHome | 23:a50ded45dbaf | 2323 | q = modelist[automode]; |
WiredHome | 23:a50ded45dbaf | 2324 | } |
WiredHome | 23:a50ded45dbaf | 2325 | switch(q) { |
WiredHome | 73:f22a18707b5e | 2326 | #ifdef PERF_METRICS |
WiredHome | 41:2956a0a221e5 | 2327 | case '0': |
WiredHome | 41:2956a0a221e5 | 2328 | lcd.ClearPerformance(); |
WiredHome | 41:2956a0a221e5 | 2329 | break; |
WiredHome | 41:2956a0a221e5 | 2330 | case '1': |
WiredHome | 41:2956a0a221e5 | 2331 | lcd.ReportPerformance(pc); |
WiredHome | 41:2956a0a221e5 | 2332 | break; |
WiredHome | 73:f22a18707b5e | 2333 | #endif |
WiredHome | 23:a50ded45dbaf | 2334 | case 'A': |
WiredHome | 23:a50ded45dbaf | 2335 | automode = 0; |
WiredHome | 23:a50ded45dbaf | 2336 | break; |
WiredHome | 23:a50ded45dbaf | 2337 | case 'B': |
WiredHome | 41:2956a0a221e5 | 2338 | BacklightTest(lcd, pc, 2); |
WiredHome | 23:a50ded45dbaf | 2339 | break; |
WiredHome | 23:a50ded45dbaf | 2340 | case 'b': |
WiredHome | 23:a50ded45dbaf | 2341 | BacklightTest2(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2342 | break; |
WiredHome | 23:a50ded45dbaf | 2343 | case 'D': |
WiredHome | 23:a50ded45dbaf | 2344 | DOSColorTest(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2345 | break; |
WiredHome | 75:ca78388cfd77 | 2346 | case 'K': |
WiredHome | 75:ca78388cfd77 | 2347 | KeyPadTest(lcd, pc); |
WiredHome | 75:ca78388cfd77 | 2348 | break; |
WiredHome | 23:a50ded45dbaf | 2349 | case 'W': |
WiredHome | 23:a50ded45dbaf | 2350 | WebColorTest(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2351 | break; |
WiredHome | 23:a50ded45dbaf | 2352 | case 't': |
WiredHome | 23:a50ded45dbaf | 2353 | TextCursorTest(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2354 | break; |
WiredHome | 49:c5182231d1b9 | 2355 | case 'w': |
WiredHome | 49:c5182231d1b9 | 2356 | TextWrapTest(lcd, pc); |
WiredHome | 49:c5182231d1b9 | 2357 | break; |
WiredHome | 23:a50ded45dbaf | 2358 | case 'F': |
WiredHome | 23:a50ded45dbaf | 2359 | ExternalFontTest(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2360 | break; |
WiredHome | 23:a50ded45dbaf | 2361 | case 'L': |
WiredHome | 23:a50ded45dbaf | 2362 | LineTest(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2363 | break; |
WiredHome | 44:207594dece70 | 2364 | case 'l': |
WiredHome | 44:207594dece70 | 2365 | LayerTest(lcd, pc); |
WiredHome | 44:207594dece70 | 2366 | break; |
WiredHome | 23:a50ded45dbaf | 2367 | case 'R': |
WiredHome | 23:a50ded45dbaf | 2368 | RectangleTest(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2369 | break; |
WiredHome | 23:a50ded45dbaf | 2370 | case 'O': |
WiredHome | 23:a50ded45dbaf | 2371 | RoundRectTest(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2372 | break; |
WiredHome | 41:2956a0a221e5 | 2373 | case 'p': |
WiredHome | 41:2956a0a221e5 | 2374 | PrintScreen(lcd, pc); |
WiredHome | 41:2956a0a221e5 | 2375 | break; |
WiredHome | 41:2956a0a221e5 | 2376 | case 'S': |
WiredHome | 41:2956a0a221e5 | 2377 | SpeedTest(lcd, pc); |
WiredHome | 41:2956a0a221e5 | 2378 | break; |
WiredHome | 77:9206c13aa527 | 2379 | case 's': |
WiredHome | 77:9206c13aa527 | 2380 | TouchPanelTest(lcd, pc); |
WiredHome | 77:9206c13aa527 | 2381 | break; |
WiredHome | 23:a50ded45dbaf | 2382 | case 'T': |
WiredHome | 23:a50ded45dbaf | 2383 | TriangleTest(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2384 | break; |
WiredHome | 37:f19b7e7449dc | 2385 | case 'P': |
WiredHome | 37:f19b7e7449dc | 2386 | PixelTest(lcd, pc); |
WiredHome | 37:f19b7e7449dc | 2387 | break; |
WiredHome | 37:f19b7e7449dc | 2388 | case 'G': |
WiredHome | 37:f19b7e7449dc | 2389 | TestGraphicsBitmap(lcd, pc); |
WiredHome | 37:f19b7e7449dc | 2390 | break; |
WiredHome | 23:a50ded45dbaf | 2391 | case 'C': |
WiredHome | 23:a50ded45dbaf | 2392 | CircleTest(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2393 | break; |
WiredHome | 23:a50ded45dbaf | 2394 | case 'E': |
WiredHome | 23:a50ded45dbaf | 2395 | EllipseTest(lcd, pc); |
WiredHome | 23:a50ded45dbaf | 2396 | break; |
WiredHome | 23:a50ded45dbaf | 2397 | case 'r': |
WiredHome | 23:a50ded45dbaf | 2398 | pc.printf("Resetting ...\r\n"); |
WiredHome | 23:a50ded45dbaf | 2399 | wait_ms(20); |
WiredHome | 23:a50ded45dbaf | 2400 | mbed_reset(); |
WiredHome | 23:a50ded45dbaf | 2401 | break; |
WiredHome | 75:ca78388cfd77 | 2402 | case ' ': |
WiredHome | 75:ca78388cfd77 | 2403 | break; |
WiredHome | 23:a50ded45dbaf | 2404 | default: |
WiredHome | 23:a50ded45dbaf | 2405 | printf("huh?\n"); |
WiredHome | 23:a50ded45dbaf | 2406 | break; |
WiredHome | 23:a50ded45dbaf | 2407 | } |
WiredHome | 23:a50ded45dbaf | 2408 | if (automode >= 0) { |
WiredHome | 23:a50ded45dbaf | 2409 | automode++; |
WiredHome | 23:a50ded45dbaf | 2410 | if (automode >= sizeof(modelist)) |
WiredHome | 23:a50ded45dbaf | 2411 | automode = 0; |
WiredHome | 23:a50ded45dbaf | 2412 | wait_ms(2000); |
WiredHome | 23:a50ded45dbaf | 2413 | } |
WiredHome | 23:a50ded45dbaf | 2414 | wait_ms(200); |
WiredHome | 23:a50ded45dbaf | 2415 | } |
WiredHome | 23:a50ded45dbaf | 2416 | } |
WiredHome | 23:a50ded45dbaf | 2417 | |
WiredHome | 23:a50ded45dbaf | 2418 | #endif // TESTENABLE |