LCD LIB

Dependents:   HagridOS5

Fork of RA8875 by David Smart

Committer:
WiredHome
Date:
Mon Apr 25 01:43:59 2016 +0000
Revision:
111:efe436c43aba
Parent:
109:7b94f06f085b
Child:
123:2f45e80fec5f
Soft fonts are now restricted by the window( ) setting, just as hard fonts were. Wraps right edge back to left and cycles from bottom edge back to top.

Who changed what in which revision?

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