Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
gstedile
Date:
Fri Jun 23 03:58:47 2017 +0000
Revision:
118:0973c6527882
Parent:
109:7b94f06f085b
20170622

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 29:422616aa04bd 859 cursor_x = 0;
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 101:e0aad446094a 868 INFO("(%d,%d) ,charWidth: %d '%c", cursor_x, cursor_y, charWidth, c);
WiredHome 101:e0aad446094a 869 if (charRecord) {
WiredHome 101:e0aad446094a 870 //cursor_x += advance;
WiredHome 105:4f116006ba1f 871 if (cursor_x + charWidth >= screenwidth) {
WiredHome 29:422616aa04bd 872 cursor_x = 0;
WiredHome 101:e0aad446094a 873 cursor_y += charHeight;
WiredHome 29:422616aa04bd 874 }
WiredHome 105:4f116006ba1f 875 if (cursor_y + charHeight >= screenheight) {
WiredHome 101:e0aad446094a 876 cursor_y = 0; // @todo Should it scroll?
WiredHome 101:e0aad446094a 877 }
WiredHome 101:e0aad446094a 878 (void)character(cursor_x, cursor_y, c);
WiredHome 101:e0aad446094a 879 cursor_x += charWidth;
WiredHome 29:422616aa04bd 880 }
WiredHome 29:422616aa04bd 881 }
WiredHome 29:422616aa04bd 882 }
WiredHome 29:422616aa04bd 883 return c;
WiredHome 29:422616aa04bd 884 }
WiredHome 29:422616aa04bd 885
WiredHome 44:207594dece70 886
WiredHome 29:422616aa04bd 887 int RA8875::_internal_putc(int c)
WiredHome 29:422616aa04bd 888 {
WiredHome 29:422616aa04bd 889 if (c) {
WiredHome 29:422616aa04bd 890 unsigned char mwcr0;
WiredHome 73:f22a18707b5e 891
WiredHome 29:422616aa04bd 892 mwcr0 = ReadCommand(0x40);
WiredHome 29:422616aa04bd 893 if ((mwcr0 & 0x80) == 0x00) {
WiredHome 29:422616aa04bd 894 WriteCommand(0x40, 0x80 | mwcr0); // Put in Text mode if not already
WiredHome 29:422616aa04bd 895 }
WiredHome 29:422616aa04bd 896 if (c == '\r') {
WiredHome 37:f19b7e7449dc 897 loc_t x;
WiredHome 19:3f82c1161fd2 898 x = ReadCommand(0x30) | (ReadCommand(0x31) << 8); // Left edge of active window
WiredHome 38:38d503b4fad6 899 WriteCommandW(0x2A, x);
WiredHome 19:3f82c1161fd2 900 } else if (c == '\n') {
WiredHome 37:f19b7e7449dc 901 loc_t y;
WiredHome 19:3f82c1161fd2 902 y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); // current y location
WiredHome 19:3f82c1161fd2 903 y += fontheight();
WiredHome 47:d96a09269f91 904 if (y >= height()) // @TODO after bottom of active window, then scroll window?
WiredHome 19:3f82c1161fd2 905 y = 0;
WiredHome 38:38d503b4fad6 906 WriteCommandW(0x2C, y);
WiredHome 19:3f82c1161fd2 907 } else {
WiredHome 29:422616aa04bd 908 WriteCommand(0x02); // RA8875 Internal Fonts
WiredHome 79:544eb4964795 909 _select(true);
WiredHome 29:422616aa04bd 910 WriteData(c);
WiredHome 66:468a11f05580 911 _WaitWhileBusy(0x80);
WiredHome 79:544eb4964795 912 _select(false);
WiredHome 19:3f82c1161fd2 913 }
WiredHome 19:3f82c1161fd2 914 }
WiredHome 19:3f82c1161fd2 915 return c;
WiredHome 19:3f82c1161fd2 916 }
WiredHome 19:3f82c1161fd2 917
WiredHome 44:207594dece70 918
WiredHome 32:0e4f2ae512e2 919 RetCode_t RA8875::_StartGraphicsStream(void)
WiredHome 32:0e4f2ae512e2 920 {
WiredHome 32:0e4f2ae512e2 921 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 32:0e4f2ae512e2 922 WriteCommand(0x02); // Prepare for streaming data
WiredHome 32:0e4f2ae512e2 923 return noerror;
WiredHome 32:0e4f2ae512e2 924 }
WiredHome 32:0e4f2ae512e2 925
WiredHome 44:207594dece70 926
WiredHome 32:0e4f2ae512e2 927 RetCode_t RA8875::_EndGraphicsStream(void)
WiredHome 32:0e4f2ae512e2 928 {
WiredHome 32:0e4f2ae512e2 929 return noerror;
WiredHome 32:0e4f2ae512e2 930 }
WiredHome 32:0e4f2ae512e2 931
WiredHome 44:207594dece70 932
WiredHome 55:dfbabef7003e 933 RetCode_t RA8875::_putp(color_t pixel)
WiredHome 32:0e4f2ae512e2 934 {
WiredHome 38:38d503b4fad6 935 WriteDataW((pixel>>8) | (pixel<<8));
WiredHome 73:f22a18707b5e 936 return noerror;
WiredHome 32:0e4f2ae512e2 937 }
WiredHome 29:422616aa04bd 938
WiredHome 44:207594dece70 939
WiredHome 37:f19b7e7449dc 940 void RA8875::puts(loc_t x, loc_t y, const char * string)
WiredHome 19:3f82c1161fd2 941 {
WiredHome 19:3f82c1161fd2 942 SetTextCursor(x,y);
WiredHome 19:3f82c1161fd2 943 puts(string);
WiredHome 19:3f82c1161fd2 944 }
WiredHome 19:3f82c1161fd2 945
WiredHome 44:207594dece70 946
WiredHome 19:3f82c1161fd2 947 void RA8875::puts(const char * string)
WiredHome 19:3f82c1161fd2 948 {
WiredHome 37:f19b7e7449dc 949 if (font == NULL) {
WiredHome 100:0b084475d5a9 950 WriteCommand(0x40,0x80); // Put in Text mode if internal font
WiredHome 37:f19b7e7449dc 951 }
WiredHome 19:3f82c1161fd2 952 if (*string != '\0') {
WiredHome 29:422616aa04bd 953 while (*string) { // @TODO calling individual _putc is slower... optimizations?
WiredHome 19:3f82c1161fd2 954 _putc(*string++);
WiredHome 19:3f82c1161fd2 955 }
WiredHome 19:3f82c1161fd2 956 }
WiredHome 19:3f82c1161fd2 957 }
WiredHome 19:3f82c1161fd2 958
WiredHome 44:207594dece70 959
WiredHome 37:f19b7e7449dc 960 RetCode_t RA8875::SetGraphicsCursor(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 961 {
WiredHome 38:38d503b4fad6 962 WriteCommandW(0x46, x);
WiredHome 38:38d503b4fad6 963 WriteCommandW(0x48, y);
WiredHome 19:3f82c1161fd2 964 return noerror;
WiredHome 19:3f82c1161fd2 965 }
WiredHome 19:3f82c1161fd2 966
WiredHome 44:207594dece70 967
WiredHome 41:2956a0a221e5 968 RetCode_t RA8875::SetGraphicsCursorRead(loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 969 {
WiredHome 41:2956a0a221e5 970 WriteCommandW(0x4A, x);
WiredHome 41:2956a0a221e5 971 WriteCommandW(0x4C, y);
WiredHome 41:2956a0a221e5 972 return noerror;
WiredHome 41:2956a0a221e5 973 }
WiredHome 41:2956a0a221e5 974
WiredHome 44:207594dece70 975
WiredHome 37:f19b7e7449dc 976 RetCode_t RA8875::window(loc_t x, loc_t y, dim_t width, dim_t height)
WiredHome 19:3f82c1161fd2 977 {
WiredHome 37:f19b7e7449dc 978 GraphicsDisplay::window(x,y, width,height);
WiredHome 38:38d503b4fad6 979 WriteCommandW(0x30, x);
WiredHome 38:38d503b4fad6 980 WriteCommandW(0x32, y);
WiredHome 38:38d503b4fad6 981 WriteCommandW(0x34, (x+width-1));
WiredHome 38:38d503b4fad6 982 WriteCommandW(0x36, (y+height-1));
WiredHome 37:f19b7e7449dc 983 SetGraphicsCursor(x,y);
WiredHome 19:3f82c1161fd2 984 return noerror;
WiredHome 19:3f82c1161fd2 985 }
WiredHome 19:3f82c1161fd2 986
WiredHome 44:207594dece70 987
WiredHome 61:8f3153bf0baa 988 RetCode_t RA8875::cls(uint16_t layers)
WiredHome 19:3f82c1161fd2 989 {
WiredHome 61:8f3153bf0baa 990 RetCode_t ret;
WiredHome 73:f22a18707b5e 991
WiredHome 19:3f82c1161fd2 992 PERFORMANCE_RESET;
WiredHome 61:8f3153bf0baa 993 if (layers == 0) {
WiredHome 61:8f3153bf0baa 994 ret = clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 995 ret = SetTextCursor(0,0);
WiredHome 61:8f3153bf0baa 996 } else if (layers > 3) {
WiredHome 61:8f3153bf0baa 997 ret = bad_parameter;
WiredHome 61:8f3153bf0baa 998 } else {
WiredHome 61:8f3153bf0baa 999 uint16_t prevLayer = GetDrawingLayer();
WiredHome 61:8f3153bf0baa 1000 if (layers & 1) {
WiredHome 61:8f3153bf0baa 1001 SelectDrawingLayer(0);
WiredHome 61:8f3153bf0baa 1002 clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1003 }
WiredHome 61:8f3153bf0baa 1004 if (layers & 2) {
WiredHome 61:8f3153bf0baa 1005 SelectDrawingLayer(1);
WiredHome 61:8f3153bf0baa 1006 clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1007 }
WiredHome 61:8f3153bf0baa 1008 ret = SelectDrawingLayer(prevLayer);
WiredHome 61:8f3153bf0baa 1009 }
WiredHome 19:3f82c1161fd2 1010 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 61:8f3153bf0baa 1011 return ret;
WiredHome 19:3f82c1161fd2 1012 }
WiredHome 19:3f82c1161fd2 1013
WiredHome 44:207594dece70 1014
WiredHome 19:3f82c1161fd2 1015 RetCode_t RA8875::clsw(RA8875::Region_t region)
WiredHome 19:3f82c1161fd2 1016 {
WiredHome 19:3f82c1161fd2 1017 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1018 WriteCommand(0x8E, (region == ACTIVEWINDOW) ? 0xC0 : 0x80);
WiredHome 66:468a11f05580 1019 _WaitWhileReg(0x8E, 0x80);
WiredHome 19:3f82c1161fd2 1020 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 19:3f82c1161fd2 1021 return noerror;
WiredHome 19:3f82c1161fd2 1022 }
WiredHome 19:3f82c1161fd2 1023
WiredHome 44:207594dece70 1024
WiredHome 87:ee2240581aa7 1025 RetCode_t RA8875::pixel(point_t p, color_t color)
WiredHome 87:ee2240581aa7 1026 {
WiredHome 87:ee2240581aa7 1027 return pixel(p.x, p.y, color);
WiredHome 87:ee2240581aa7 1028 }
WiredHome 87:ee2240581aa7 1029
WiredHome 87:ee2240581aa7 1030 RetCode_t RA8875::pixel(point_t p)
WiredHome 87:ee2240581aa7 1031 {
WiredHome 87:ee2240581aa7 1032 return pixel(p.x, p.y);
WiredHome 87:ee2240581aa7 1033 }
WiredHome 87:ee2240581aa7 1034
WiredHome 37:f19b7e7449dc 1035 RetCode_t RA8875::pixel(loc_t x, loc_t y, color_t color)
WiredHome 19:3f82c1161fd2 1036 {
WiredHome 62:ba5d33438fda 1037 RetCode_t ret;
WiredHome 73:f22a18707b5e 1038
WiredHome 62:ba5d33438fda 1039 PERFORMANCE_RESET;
WiredHome 62:ba5d33438fda 1040 ret = pixelStream(&color, 1, x,y);
WiredHome 62:ba5d33438fda 1041 REGISTERPERFORMANCE(PRF_DRAWPIXEL);
WiredHome 62:ba5d33438fda 1042 return ret;
WiredHome 19:3f82c1161fd2 1043 }
WiredHome 19:3f82c1161fd2 1044
WiredHome 44:207594dece70 1045
WiredHome 37:f19b7e7449dc 1046 RetCode_t RA8875::pixel(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 1047 {
WiredHome 19:3f82c1161fd2 1048 RetCode_t ret;
WiredHome 73:f22a18707b5e 1049
WiredHome 19:3f82c1161fd2 1050 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1051 color_t color = GetForeColor();
WiredHome 62:ba5d33438fda 1052 ret = pixelStream(&color, 1, x, y);
WiredHome 41:2956a0a221e5 1053 REGISTERPERFORMANCE(PRF_DRAWPIXEL);
WiredHome 19:3f82c1161fd2 1054 return ret;
WiredHome 19:3f82c1161fd2 1055 }
WiredHome 19:3f82c1161fd2 1056
WiredHome 44:207594dece70 1057
WiredHome 41:2956a0a221e5 1058 RetCode_t RA8875::pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1059 {
WiredHome 41:2956a0a221e5 1060 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 1061 SetGraphicsCursor(x, y);
WiredHome 109:7b94f06f085b 1062 _StartGraphicsStream();
WiredHome 79:544eb4964795 1063 _select(true);
WiredHome 79:544eb4964795 1064 _spiwrite(0x00); // Cmd: write data
WiredHome 41:2956a0a221e5 1065 while (count--) {
WiredHome 105:4f116006ba1f 1066 if (screenbpp == 16) {
WiredHome 105:4f116006ba1f 1067 _spiwrite(*p >> 8);
WiredHome 105:4f116006ba1f 1068 _spiwrite(*p & 0xFF);
WiredHome 105:4f116006ba1f 1069 } else {
WiredHome 105:4f116006ba1f 1070 _spiwrite(_cvt16to8(*p));
WiredHome 105:4f116006ba1f 1071 }
WiredHome 41:2956a0a221e5 1072 p++;
WiredHome 41:2956a0a221e5 1073 }
WiredHome 79:544eb4964795 1074 _select(false);
WiredHome 109:7b94f06f085b 1075 _EndGraphicsStream();
WiredHome 41:2956a0a221e5 1076 REGISTERPERFORMANCE(PRF_PIXELSTREAM);
WiredHome 41:2956a0a221e5 1077 return(noerror);
WiredHome 41:2956a0a221e5 1078 }
WiredHome 41:2956a0a221e5 1079
WiredHome 109:7b94f06f085b 1080 RetCode_t RA8875::booleanStream(loc_t x, loc_t y, dim_t w, dim_t h, const uint8_t * boolStream)
WiredHome 109:7b94f06f085b 1081 {
WiredHome 109:7b94f06f085b 1082 PERFORMANCE_RESET;
WiredHome 109:7b94f06f085b 1083 window(x, y, w, h);
WiredHome 109:7b94f06f085b 1084 SetGraphicsCursor(x, y);
WiredHome 109:7b94f06f085b 1085 _StartGraphicsStream();
WiredHome 109:7b94f06f085b 1086 _select(true);
WiredHome 109:7b94f06f085b 1087 _spiwrite(0x00); // Cmd: write data
WiredHome 109:7b94f06f085b 1088 while (h--) {
WiredHome 109:7b94f06f085b 1089 uint8_t pixels = w;
WiredHome 109:7b94f06f085b 1090 uint8_t bitmask = 0x01;
WiredHome 109:7b94f06f085b 1091
WiredHome 109:7b94f06f085b 1092 while (pixels) {
WiredHome 109:7b94f06f085b 1093 uint8_t byte = *boolStream;
WiredHome 109:7b94f06f085b 1094 INFO("byte, mask: %02X, %02X", byte, bitmask);
WiredHome 109:7b94f06f085b 1095 color_t c = (byte & bitmask) ? _foreground : _background;
WiredHome 109:7b94f06f085b 1096 if (screenbpp == 16) {
WiredHome 109:7b94f06f085b 1097 _spiwrite(c >> 8);
WiredHome 109:7b94f06f085b 1098 _spiwrite(c & 0xFF);
WiredHome 109:7b94f06f085b 1099 } else {
WiredHome 109:7b94f06f085b 1100 _spiwrite(_cvt16to8(c));
WiredHome 109:7b94f06f085b 1101 }
WiredHome 109:7b94f06f085b 1102 bitmask <<= 1;
WiredHome 109:7b94f06f085b 1103 if (pixels > 1 && bitmask == 0) {
WiredHome 109:7b94f06f085b 1104 bitmask = 0x01;
WiredHome 109:7b94f06f085b 1105 boolStream++;
WiredHome 109:7b94f06f085b 1106 }
WiredHome 109:7b94f06f085b 1107 pixels--;
WiredHome 109:7b94f06f085b 1108 }
WiredHome 109:7b94f06f085b 1109 boolStream++;
WiredHome 109:7b94f06f085b 1110 }
WiredHome 109:7b94f06f085b 1111 _select(false);
WiredHome 109:7b94f06f085b 1112 _EndGraphicsStream();
WiredHome 109:7b94f06f085b 1113 WindowMax();
WiredHome 109:7b94f06f085b 1114 REGISTERPERFORMANCE(PRF_BOOLSTREAM);
WiredHome 109:7b94f06f085b 1115 return(noerror);
WiredHome 109:7b94f06f085b 1116 }
WiredHome 44:207594dece70 1117
WiredHome 41:2956a0a221e5 1118 color_t RA8875::getPixel(loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1119 {
WiredHome 41:2956a0a221e5 1120 color_t pixel;
WiredHome 73:f22a18707b5e 1121
WiredHome 41:2956a0a221e5 1122 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 1123 //WriteCommand(0x45,0x00); // read left->right, top->bottom
WiredHome 41:2956a0a221e5 1124 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 41:2956a0a221e5 1125 SetGraphicsCursorRead(x, y);
WiredHome 41:2956a0a221e5 1126 WriteCommand(0x02);
WiredHome 79:544eb4964795 1127 _select(true);
WiredHome 79:544eb4964795 1128 _spiwrite(0x40); // Cmd: read data
WiredHome 79:544eb4964795 1129 _spiwrite(0x00); // dummy read
WiredHome 105:4f116006ba1f 1130 if (screenbpp == 16) {
WiredHome 105:4f116006ba1f 1131 pixel = _spiread();
WiredHome 105:4f116006ba1f 1132 pixel |= (_spiread() << 8);
WiredHome 105:4f116006ba1f 1133 } else {
WiredHome 105:4f116006ba1f 1134 pixel = _cvt8to16(_spiread());
WiredHome 105:4f116006ba1f 1135 }
WiredHome 79:544eb4964795 1136 _select(false);
WiredHome 41:2956a0a221e5 1137 REGISTERPERFORMANCE(PRF_READPIXEL);
WiredHome 41:2956a0a221e5 1138 return pixel;
WiredHome 41:2956a0a221e5 1139 }
WiredHome 41:2956a0a221e5 1140
WiredHome 44:207594dece70 1141
WiredHome 41:2956a0a221e5 1142 RetCode_t RA8875::getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1143 {
WiredHome 41:2956a0a221e5 1144 color_t pixel;
WiredHome 86:e86b355940f4 1145 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1146
WiredHome 41:2956a0a221e5 1147 PERFORMANCE_RESET;
WiredHome 86:e86b355940f4 1148 ret = WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 86:e86b355940f4 1149 ret = SetGraphicsCursorRead(x, y);
WiredHome 86:e86b355940f4 1150 ret = WriteCommand(0x02);
WiredHome 79:544eb4964795 1151 _select(true);
WiredHome 79:544eb4964795 1152 _spiwrite(0x40); // Cmd: read data
WiredHome 79:544eb4964795 1153 _spiwrite(0x00); // dummy read
WiredHome 106:c80828f5dea4 1154 if (screenbpp == 16)
WiredHome 106:c80828f5dea4 1155 _spiwrite(0x00); // dummy read is only necessary when in 16-bit mode
WiredHome 41:2956a0a221e5 1156 while (count--) {
WiredHome 105:4f116006ba1f 1157 if (screenbpp == 16) {
WiredHome 105:4f116006ba1f 1158 pixel = _spiread();
WiredHome 105:4f116006ba1f 1159 pixel |= (_spiread() << 8);
WiredHome 105:4f116006ba1f 1160 } else {
WiredHome 105:4f116006ba1f 1161 pixel = _cvt8to16(_spiread());
WiredHome 105:4f116006ba1f 1162 }
WiredHome 41:2956a0a221e5 1163 *p++ = pixel;
WiredHome 41:2956a0a221e5 1164 }
WiredHome 79:544eb4964795 1165 _select(false);
WiredHome 41:2956a0a221e5 1166 REGISTERPERFORMANCE(PRF_READPIXELSTREAM);
WiredHome 86:e86b355940f4 1167 return ret;
WiredHome 41:2956a0a221e5 1168 }
WiredHome 41:2956a0a221e5 1169
WiredHome 44:207594dece70 1170
WiredHome 83:7bad0068cca0 1171 RetCode_t RA8875::line(point_t p1, point_t p2)
WiredHome 83:7bad0068cca0 1172 {
WiredHome 83:7bad0068cca0 1173 return line(p1.x, p1.y, p2.x, p2.y);
WiredHome 83:7bad0068cca0 1174 }
WiredHome 83:7bad0068cca0 1175
WiredHome 83:7bad0068cca0 1176
WiredHome 83:7bad0068cca0 1177 RetCode_t RA8875::line(point_t p1, point_t p2, color_t color)
WiredHome 83:7bad0068cca0 1178 {
WiredHome 83:7bad0068cca0 1179 return line(p1.x, p1.y, p2.x, p2.y, color);
WiredHome 83:7bad0068cca0 1180 }
WiredHome 83:7bad0068cca0 1181
WiredHome 83:7bad0068cca0 1182
WiredHome 37:f19b7e7449dc 1183 RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color)
WiredHome 19:3f82c1161fd2 1184 {
WiredHome 19:3f82c1161fd2 1185 foreground(color);
WiredHome 19:3f82c1161fd2 1186 return line(x1,y1,x2,y2);
WiredHome 19:3f82c1161fd2 1187 }
WiredHome 19:3f82c1161fd2 1188
WiredHome 44:207594dece70 1189
WiredHome 37:f19b7e7449dc 1190 RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2)
WiredHome 19:3f82c1161fd2 1191 {
WiredHome 19:3f82c1161fd2 1192 PERFORMANCE_RESET;
WiredHome 62:ba5d33438fda 1193 if (x1 == x2 && y1 == y2) {
WiredHome 60:2dfd574f63bd 1194 pixel(x1, y1);
WiredHome 62:ba5d33438fda 1195 } else {
WiredHome 60:2dfd574f63bd 1196 WriteCommandW(0x91, x1);
WiredHome 60:2dfd574f63bd 1197 WriteCommandW(0x93, y1);
WiredHome 60:2dfd574f63bd 1198 WriteCommandW(0x95, x2);
WiredHome 60:2dfd574f63bd 1199 WriteCommandW(0x97, y2);
WiredHome 60:2dfd574f63bd 1200 unsigned char drawCmd = 0x00; // Line
WiredHome 60:2dfd574f63bd 1201 WriteCommand(0x90, drawCmd);
WiredHome 60:2dfd574f63bd 1202 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1203 _WaitWhileReg(0x90, 0x80);
WiredHome 60:2dfd574f63bd 1204 }
WiredHome 19:3f82c1161fd2 1205 REGISTERPERFORMANCE(PRF_DRAWLINE);
WiredHome 19:3f82c1161fd2 1206 return noerror;
WiredHome 19:3f82c1161fd2 1207 }
WiredHome 19:3f82c1161fd2 1208
WiredHome 107:f9ccffcb84f1 1209 //
WiredHome 107:f9ccffcb84f1 1210 // Rectangle functions all mostly helpers to the basic rectangle function
WiredHome 107:f9ccffcb84f1 1211 //
WiredHome 107:f9ccffcb84f1 1212
WiredHome 81:01da2e34283d 1213 RetCode_t RA8875::fillrect(rect_t r, color_t color, fill_t fillit)
WiredHome 81:01da2e34283d 1214 {
WiredHome 81:01da2e34283d 1215 return rect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, color, fillit);
WiredHome 81:01da2e34283d 1216 }
WiredHome 44:207594dece70 1217
WiredHome 73:f22a18707b5e 1218 RetCode_t RA8875::fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1219 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1220 {
WiredHome 19:3f82c1161fd2 1221 return rect(x1,y1,x2,y2,color,fillit);
WiredHome 19:3f82c1161fd2 1222 }
WiredHome 19:3f82c1161fd2 1223
WiredHome 81:01da2e34283d 1224 RetCode_t RA8875::rect(rect_t r, color_t color, fill_t fillit)
WiredHome 81:01da2e34283d 1225 {
WiredHome 81:01da2e34283d 1226 return rect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, color, fillit);
WiredHome 81:01da2e34283d 1227 }
WiredHome 44:207594dece70 1228
WiredHome 73:f22a18707b5e 1229 RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1230 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1231 {
WiredHome 19:3f82c1161fd2 1232 foreground(color);
WiredHome 19:3f82c1161fd2 1233 return rect(x1,y1,x2,y2,fillit);
WiredHome 19:3f82c1161fd2 1234 }
WiredHome 19:3f82c1161fd2 1235
WiredHome 73:f22a18707b5e 1236 RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1237 fill_t fillit)
WiredHome 19:3f82c1161fd2 1238 {
WiredHome 85:022bba13c5c4 1239 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 1240 PERFORMANCE_RESET;
WiredHome 85:022bba13c5c4 1241 // check for bad_parameter
WiredHome 105:4f116006ba1f 1242 if (x1 < 0 || x1 >= screenwidth || x2 < 0 || x2 >= screenwidth
WiredHome 105:4f116006ba1f 1243 || y1 < 0 || y1 >= screenheight || y2 < 0 || y2 >= screenheight) {
WiredHome 85:022bba13c5c4 1244 ret = bad_parameter;
WiredHome 100:0b084475d5a9 1245 } else {
WiredHome 85:022bba13c5c4 1246 if (x1 == x2 && y1 == y2) {
WiredHome 85:022bba13c5c4 1247 pixel(x1, y1);
WiredHome 85:022bba13c5c4 1248 } else if (x1 == x2) {
WiredHome 85:022bba13c5c4 1249 line(x1, y1, x2, y2);
WiredHome 85:022bba13c5c4 1250 } else if (y1 == y2) {
WiredHome 85:022bba13c5c4 1251 line(x1, y1, x2, y2);
WiredHome 85:022bba13c5c4 1252 } else {
WiredHome 85:022bba13c5c4 1253 WriteCommandW(0x91, x1);
WiredHome 85:022bba13c5c4 1254 WriteCommandW(0x93, y1);
WiredHome 85:022bba13c5c4 1255 WriteCommandW(0x95, x2);
WiredHome 85:022bba13c5c4 1256 WriteCommandW(0x97, y2);
WiredHome 85:022bba13c5c4 1257 unsigned char drawCmd = 0x10; // Rectangle
WiredHome 85:022bba13c5c4 1258 if (fillit == FILL)
WiredHome 85:022bba13c5c4 1259 drawCmd |= 0x20;
WiredHome 85:022bba13c5c4 1260 WriteCommand(0x90, drawCmd);
WiredHome 85:022bba13c5c4 1261 ret = WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 85:022bba13c5c4 1262 _WaitWhileReg(0x90, 0x80);
WiredHome 85:022bba13c5c4 1263 }
WiredHome 19:3f82c1161fd2 1264 }
WiredHome 19:3f82c1161fd2 1265 REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
WiredHome 85:022bba13c5c4 1266 return ret;
WiredHome 19:3f82c1161fd2 1267 }
WiredHome 19:3f82c1161fd2 1268
WiredHome 44:207594dece70 1269
WiredHome 107:f9ccffcb84f1 1270 //
WiredHome 107:f9ccffcb84f1 1271 // rounded rectangle functions are mostly helpers to the base round rect
WiredHome 107:f9ccffcb84f1 1272 //
WiredHome 107:f9ccffcb84f1 1273
WiredHome 107:f9ccffcb84f1 1274 RetCode_t RA8875::fillroundrect(rect_t r, dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 107:f9ccffcb84f1 1275 {
WiredHome 107:f9ccffcb84f1 1276 return roundrect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, radius1, radius2, color, fillit);
WiredHome 107:f9ccffcb84f1 1277 }
WiredHome 107:f9ccffcb84f1 1278
WiredHome 73:f22a18707b5e 1279 RetCode_t RA8875::fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1280 dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1281 {
WiredHome 19:3f82c1161fd2 1282 foreground(color);
WiredHome 19:3f82c1161fd2 1283 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1284 }
WiredHome 19:3f82c1161fd2 1285
WiredHome 107:f9ccffcb84f1 1286 RetCode_t RA8875::roundrect(rect_t r, dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 107:f9ccffcb84f1 1287 {
WiredHome 107:f9ccffcb84f1 1288 return roundrect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, radius1, radius2, color, fillit);
WiredHome 107:f9ccffcb84f1 1289 }
WiredHome 44:207594dece70 1290
WiredHome 73:f22a18707b5e 1291 RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1292 dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1293 {
WiredHome 19:3f82c1161fd2 1294 foreground(color);
WiredHome 19:3f82c1161fd2 1295 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1296 }
WiredHome 19:3f82c1161fd2 1297
WiredHome 44:207594dece70 1298
WiredHome 73:f22a18707b5e 1299 RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1300 dim_t radius1, dim_t radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 1301 {
WiredHome 19:3f82c1161fd2 1302 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1303
WiredHome 19:3f82c1161fd2 1304 PERFORMANCE_RESET;
WiredHome 105:4f116006ba1f 1305 if (x1 < 0 || x1 >= screenwidth || x2 < 0 || x2 >= screenwidth
WiredHome 105:4f116006ba1f 1306 || y1 < 0 || y1 >= screenheight || y2 < 0 || y2 >= screenheight) {
WiredHome 85:022bba13c5c4 1307 ret = bad_parameter;
WiredHome 85:022bba13c5c4 1308 } else if (x1 > x2 || y1 > y2 || (radius1 > (x2-x1)/2) || (radius2 > (y2-y1)/2) ) {
WiredHome 21:3c1efb192927 1309 ret = bad_parameter;
WiredHome 21:3c1efb192927 1310 } else if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 1311 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1312 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 1313 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1314 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 1315 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1316 } else {
WiredHome 38:38d503b4fad6 1317 WriteCommandW(0x91, x1);
WiredHome 38:38d503b4fad6 1318 WriteCommandW(0x93, y1);
WiredHome 38:38d503b4fad6 1319 WriteCommandW(0x95, x2);
WiredHome 38:38d503b4fad6 1320 WriteCommandW(0x97, y2);
WiredHome 38:38d503b4fad6 1321 WriteCommandW(0xA1, radius1);
WiredHome 38:38d503b4fad6 1322 WriteCommandW(0xA3, radius2);
WiredHome 21:3c1efb192927 1323 // Should not need this...
WiredHome 38:38d503b4fad6 1324 WriteCommandW(0xA5, 0);
WiredHome 38:38d503b4fad6 1325 WriteCommandW(0xA7, 0);
WiredHome 19:3f82c1161fd2 1326 unsigned char drawCmd = 0x20; // Rounded Rectangle
WiredHome 19:3f82c1161fd2 1327 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1328 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 1329 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 1330 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1331 _WaitWhileReg(0xA0, 0x80);
WiredHome 19:3f82c1161fd2 1332 }
WiredHome 19:3f82c1161fd2 1333 REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
WiredHome 19:3f82c1161fd2 1334 return ret;
WiredHome 19:3f82c1161fd2 1335 }
WiredHome 19:3f82c1161fd2 1336
WiredHome 44:207594dece70 1337
WiredHome 107:f9ccffcb84f1 1338 //
WiredHome 107:f9ccffcb84f1 1339 // triangle functions
WiredHome 107:f9ccffcb84f1 1340 //
WiredHome 107:f9ccffcb84f1 1341
WiredHome 73:f22a18707b5e 1342 RetCode_t RA8875::triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1343 loc_t x3, loc_t y3, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1344 {
WiredHome 20:6e2e4a8372eb 1345 RetCode_t ret;
WiredHome 20:6e2e4a8372eb 1346
WiredHome 105:4f116006ba1f 1347 if (x1 < 0 || x1 >= screenwidth || x2 < 0 || x2 >= screenwidth || x3 < 0 || x3 >= screenwidth
WiredHome 105:4f116006ba1f 1348 || y1 < 0 || y1 >= screenheight || y2 < 0 || y2 >= screenheight || y3 < 0 || y3 >= screenheight)
WiredHome 85:022bba13c5c4 1349 ret = bad_parameter;
WiredHome 19:3f82c1161fd2 1350 foreground(color);
WiredHome 20:6e2e4a8372eb 1351 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 20:6e2e4a8372eb 1352 return ret;
WiredHome 19:3f82c1161fd2 1353 }
WiredHome 19:3f82c1161fd2 1354
WiredHome 44:207594dece70 1355
WiredHome 73:f22a18707b5e 1356 RetCode_t RA8875::filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1357 loc_t x3, loc_t y3, color_t color, fill_t fillit)
WiredHome 73:f22a18707b5e 1358 {
WiredHome 73:f22a18707b5e 1359 RetCode_t ret;
WiredHome 73:f22a18707b5e 1360
WiredHome 73:f22a18707b5e 1361 foreground(color);
WiredHome 73:f22a18707b5e 1362 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 73:f22a18707b5e 1363 return ret;
WiredHome 73:f22a18707b5e 1364 }
WiredHome 73:f22a18707b5e 1365
WiredHome 73:f22a18707b5e 1366
WiredHome 73:f22a18707b5e 1367 RetCode_t RA8875::triangle(loc_t x1, loc_t y1 ,loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1368 loc_t x3, loc_t y3, fill_t fillit)
WiredHome 19:3f82c1161fd2 1369 {
WiredHome 19:3f82c1161fd2 1370 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1371
WiredHome 19:3f82c1161fd2 1372 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1373 if (x1 == x2 && y1 == y2 && x1 == x3 && y1 == y3) {
WiredHome 19:3f82c1161fd2 1374 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1375 } else {
WiredHome 38:38d503b4fad6 1376 WriteCommandW(0x91, x1);
WiredHome 38:38d503b4fad6 1377 WriteCommandW(0x93, y1);
WiredHome 38:38d503b4fad6 1378 WriteCommandW(0x95, x2);
WiredHome 38:38d503b4fad6 1379 WriteCommandW(0x97, y2);
WiredHome 38:38d503b4fad6 1380 WriteCommandW(0xA9, x3);
WiredHome 38:38d503b4fad6 1381 WriteCommandW(0xAB, y3);
WiredHome 19:3f82c1161fd2 1382 unsigned char drawCmd = 0x01; // Triangle
WiredHome 19:3f82c1161fd2 1383 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1384 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 1385 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 1386 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1387 _WaitWhileReg(0x90, 0x80);
WiredHome 19:3f82c1161fd2 1388 }
WiredHome 19:3f82c1161fd2 1389 REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
WiredHome 19:3f82c1161fd2 1390 return ret;
WiredHome 19:3f82c1161fd2 1391 }
WiredHome 19:3f82c1161fd2 1392
WiredHome 83:7bad0068cca0 1393
WiredHome 83:7bad0068cca0 1394 RetCode_t RA8875::circle(point_t p, dim_t radius,
WiredHome 83:7bad0068cca0 1395 color_t color, fill_t fillit)
WiredHome 83:7bad0068cca0 1396 {
WiredHome 83:7bad0068cca0 1397 foreground(color);
WiredHome 83:7bad0068cca0 1398 return circle(p.x,p.y,radius,fillit);
WiredHome 83:7bad0068cca0 1399 }
WiredHome 83:7bad0068cca0 1400
WiredHome 83:7bad0068cca0 1401
WiredHome 83:7bad0068cca0 1402 RetCode_t RA8875::fillcircle(point_t p, dim_t radius,
WiredHome 83:7bad0068cca0 1403 color_t color, fill_t fillit)
WiredHome 83:7bad0068cca0 1404 {
WiredHome 83:7bad0068cca0 1405 foreground(color);
WiredHome 83:7bad0068cca0 1406 return circle(p.x,p.y,radius,fillit);
WiredHome 83:7bad0068cca0 1407 }
WiredHome 83:7bad0068cca0 1408
WiredHome 83:7bad0068cca0 1409
WiredHome 83:7bad0068cca0 1410 RetCode_t RA8875::circle(point_t p, dim_t radius, fill_t fillit)
WiredHome 83:7bad0068cca0 1411 {
WiredHome 83:7bad0068cca0 1412 return circle(p.x,p.y,radius,fillit);
WiredHome 83:7bad0068cca0 1413 }
WiredHome 83:7bad0068cca0 1414
WiredHome 83:7bad0068cca0 1415
WiredHome 73:f22a18707b5e 1416 RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius,
WiredHome 73:f22a18707b5e 1417 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1418 {
WiredHome 19:3f82c1161fd2 1419 foreground(color);
WiredHome 19:3f82c1161fd2 1420 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 1421 }
WiredHome 19:3f82c1161fd2 1422
WiredHome 44:207594dece70 1423
WiredHome 73:f22a18707b5e 1424 RetCode_t RA8875::fillcircle(loc_t x, loc_t y, dim_t radius,
WiredHome 73:f22a18707b5e 1425 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1426 {
WiredHome 19:3f82c1161fd2 1427 foreground(color);
WiredHome 19:3f82c1161fd2 1428 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 1429 }
WiredHome 19:3f82c1161fd2 1430
WiredHome 44:207594dece70 1431
WiredHome 37:f19b7e7449dc 1432 RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius, fill_t fillit)
WiredHome 19:3f82c1161fd2 1433 {
WiredHome 19:3f82c1161fd2 1434 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1435
WiredHome 19:3f82c1161fd2 1436 PERFORMANCE_RESET;
WiredHome 105:4f116006ba1f 1437 if (radius <= 0 || (x - radius) < 0 || (x + radius) > screenwidth
WiredHome 105:4f116006ba1f 1438 || (y - radius) < 0 || (y + radius) > screenheight) {
WiredHome 19:3f82c1161fd2 1439 ret = bad_parameter;
WiredHome 19:3f82c1161fd2 1440 } else if (radius == 1) {
WiredHome 19:3f82c1161fd2 1441 pixel(x,y);
WiredHome 19:3f82c1161fd2 1442 } else {
WiredHome 38:38d503b4fad6 1443 WriteCommandW(0x99, x);
WiredHome 38:38d503b4fad6 1444 WriteCommandW(0x9B, y);
WiredHome 19:3f82c1161fd2 1445 WriteCommand(0x9d, radius & 0xFF);
WiredHome 19:3f82c1161fd2 1446 unsigned char drawCmd = 0x00; // Circle
WiredHome 19:3f82c1161fd2 1447 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1448 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 1449 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 1450 WriteCommand(0x90, 0x40 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1451 _WaitWhileReg(0x90, 0x40);
WiredHome 19:3f82c1161fd2 1452 }
WiredHome 19:3f82c1161fd2 1453 REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
WiredHome 19:3f82c1161fd2 1454 return ret;
WiredHome 19:3f82c1161fd2 1455 }
WiredHome 19:3f82c1161fd2 1456
WiredHome 44:207594dece70 1457
WiredHome 37:f19b7e7449dc 1458 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 1459 {
WiredHome 19:3f82c1161fd2 1460 foreground(color);
WiredHome 25:9556a3a9b7cc 1461 return ellipse(x,y,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1462 }
WiredHome 19:3f82c1161fd2 1463
WiredHome 44:207594dece70 1464
WiredHome 37:f19b7e7449dc 1465 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 1466 {
WiredHome 25:9556a3a9b7cc 1467 foreground(color);
WiredHome 25:9556a3a9b7cc 1468 return ellipse(x,y,radius1,radius2,fillit);
WiredHome 25:9556a3a9b7cc 1469 }
WiredHome 44:207594dece70 1470
WiredHome 73:f22a18707b5e 1471
WiredHome 37:f19b7e7449dc 1472 RetCode_t RA8875::ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 1473 {
WiredHome 19:3f82c1161fd2 1474 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1475
WiredHome 19:3f82c1161fd2 1476 PERFORMANCE_RESET;
WiredHome 105:4f116006ba1f 1477 if (radius1 <= 0 || radius2 <= 0 || (x - radius1) < 0 || (x + radius1) > screenwidth
WiredHome 105:4f116006ba1f 1478 || (y - radius2) < 0 || (y + radius2) > screenheight) {
WiredHome 85:022bba13c5c4 1479 ret = bad_parameter;
WiredHome 25:9556a3a9b7cc 1480 } else if (radius1 == 1 && radius2 == 1) {
WiredHome 19:3f82c1161fd2 1481 pixel(x, y);
WiredHome 19:3f82c1161fd2 1482 } else {
WiredHome 38:38d503b4fad6 1483 WriteCommandW(0xA5, x);
WiredHome 38:38d503b4fad6 1484 WriteCommandW(0xA7, y);
WiredHome 38:38d503b4fad6 1485 WriteCommandW(0xA1, radius1);
WiredHome 38:38d503b4fad6 1486 WriteCommandW(0xA3, radius2);
WiredHome 19:3f82c1161fd2 1487 unsigned char drawCmd = 0x00; // Ellipse
WiredHome 19:3f82c1161fd2 1488 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1489 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 1490 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 1491 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1492 _WaitWhileReg(0xA0, 0x80);
WiredHome 19:3f82c1161fd2 1493 }
WiredHome 19:3f82c1161fd2 1494 REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
WiredHome 19:3f82c1161fd2 1495 return ret;
WiredHome 19:3f82c1161fd2 1496 }
WiredHome 19:3f82c1161fd2 1497
WiredHome 44:207594dece70 1498
WiredHome 68:ab08efabfc88 1499 RetCode_t RA8875::frequency(unsigned long Hz, unsigned long Hz2)
WiredHome 19:3f82c1161fd2 1500 {
WiredHome 66:468a11f05580 1501 spiwritefreq = Hz;
WiredHome 68:ab08efabfc88 1502 if (Hz2 != 0)
WiredHome 68:ab08efabfc88 1503 spireadfreq = Hz2;
WiredHome 68:ab08efabfc88 1504 else
WiredHome 68:ab08efabfc88 1505 spireadfreq = Hz/2;
WiredHome 68:ab08efabfc88 1506 _setWriteSpeed(true);
WiredHome 19:3f82c1161fd2 1507 // __ ___
WiredHome 19:3f82c1161fd2 1508 // Clock ___A Rising edge latched
WiredHome 19:3f82c1161fd2 1509 // ___ ____
WiredHome 19:3f82c1161fd2 1510 // Data ___X____
WiredHome 19:3f82c1161fd2 1511 spi.format(8, 3); // 8 bits and clock to data phase 0
WiredHome 19:3f82c1161fd2 1512 return noerror;
WiredHome 19:3f82c1161fd2 1513 }
WiredHome 19:3f82c1161fd2 1514
WiredHome 68:ab08efabfc88 1515 void RA8875::_setWriteSpeed(bool writeSpeed)
WiredHome 68:ab08efabfc88 1516 {
WiredHome 68:ab08efabfc88 1517 if (writeSpeed) {
WiredHome 68:ab08efabfc88 1518 spi.frequency(spiwritefreq);
WiredHome 68:ab08efabfc88 1519 spiWriteSpeed = true;
WiredHome 68:ab08efabfc88 1520 } else {
WiredHome 68:ab08efabfc88 1521 spi.frequency(spireadfreq);
WiredHome 68:ab08efabfc88 1522 spiWriteSpeed = false;
WiredHome 68:ab08efabfc88 1523 }
WiredHome 68:ab08efabfc88 1524 }
WiredHome 44:207594dece70 1525
WiredHome 19:3f82c1161fd2 1526 RetCode_t RA8875::Power(bool on)
WiredHome 19:3f82c1161fd2 1527 {
WiredHome 19:3f82c1161fd2 1528 WriteCommand(0x01, (on) ? 0x80 : 0x00);
WiredHome 19:3f82c1161fd2 1529 return noerror;
WiredHome 19:3f82c1161fd2 1530 }
WiredHome 19:3f82c1161fd2 1531
WiredHome 44:207594dece70 1532
WiredHome 19:3f82c1161fd2 1533 RetCode_t RA8875::Backlight_u8(unsigned char brightness)
WiredHome 19:3f82c1161fd2 1534 {
WiredHome 19:3f82c1161fd2 1535 static bool is_enabled = false;
WiredHome 19:3f82c1161fd2 1536 if (brightness == 0) {
WiredHome 19:3f82c1161fd2 1537 WriteCommand(0x8a); // Disable the PWM
WiredHome 19:3f82c1161fd2 1538 WriteData(0x00);
WiredHome 19:3f82c1161fd2 1539 is_enabled = false;
WiredHome 19:3f82c1161fd2 1540 } else if (!is_enabled) {
WiredHome 19:3f82c1161fd2 1541 WriteCommand(0x8a); // Enable the PWM
WiredHome 19:3f82c1161fd2 1542 WriteData(0x80);
WiredHome 19:3f82c1161fd2 1543 WriteCommand(0x8a); // Not sure why this is needed, but following the pattern
WiredHome 19:3f82c1161fd2 1544 WriteData(0x81); // open PWM (SYS_CLK / 2 as best I can tell)
WiredHome 19:3f82c1161fd2 1545 is_enabled = true;
WiredHome 19:3f82c1161fd2 1546 }
WiredHome 19:3f82c1161fd2 1547 WriteCommand(0x8b, brightness); // Brightness parameter 0xff-0x00
WiredHome 19:3f82c1161fd2 1548 return noerror;
WiredHome 19:3f82c1161fd2 1549 }
WiredHome 19:3f82c1161fd2 1550
WiredHome 86:e86b355940f4 1551 uint8_t RA8875::GetBacklight_u8(void)
WiredHome 86:e86b355940f4 1552 {
WiredHome 86:e86b355940f4 1553 return ReadCommand(0x8b);
WiredHome 86:e86b355940f4 1554 }
WiredHome 44:207594dece70 1555
WiredHome 19:3f82c1161fd2 1556 RetCode_t RA8875::Backlight(float brightness)
WiredHome 19:3f82c1161fd2 1557 {
WiredHome 19:3f82c1161fd2 1558 unsigned char b;
WiredHome 73:f22a18707b5e 1559
WiredHome 29:422616aa04bd 1560 if (brightness >= 1.0)
WiredHome 19:3f82c1161fd2 1561 b = 255;
WiredHome 29:422616aa04bd 1562 else if (brightness <= 0.0)
WiredHome 19:3f82c1161fd2 1563 b = 0;
WiredHome 19:3f82c1161fd2 1564 else
WiredHome 19:3f82c1161fd2 1565 b = (unsigned char)(brightness * 255);
WiredHome 19:3f82c1161fd2 1566 return Backlight_u8(b);
WiredHome 19:3f82c1161fd2 1567 }
WiredHome 19:3f82c1161fd2 1568
WiredHome 86:e86b355940f4 1569 float RA8875::GetBacklight(void)
WiredHome 86:e86b355940f4 1570 {
WiredHome 86:e86b355940f4 1571 return (float)(GetBacklight_u8())/255;
WiredHome 86:e86b355940f4 1572 }
WiredHome 44:207594dece70 1573
WiredHome 98:ecebed9b80b2 1574 RetCode_t RA8875::SelectUserFont(const uint8_t * _font)
WiredHome 98:ecebed9b80b2 1575 {
WiredHome 98:ecebed9b80b2 1576 INFO("Cursor(%d,%d) %p", cursor_x, cursor_y, _font);
WiredHome 98:ecebed9b80b2 1577 INFO("Text C(%d,%d)", GetTextCursor_X(), GetTextCursor_Y());
WiredHome 98:ecebed9b80b2 1578 if (_font) {
WiredHome 98:ecebed9b80b2 1579 HexDump("Font Memory", _font, 16);
WiredHome 98:ecebed9b80b2 1580 extFontHeight = _font[6];
WiredHome 98:ecebed9b80b2 1581 uint32_t totalWidth = 0;
WiredHome 98:ecebed9b80b2 1582 uint16_t firstChar = _font[3] * 256 + _font[2];
WiredHome 98:ecebed9b80b2 1583 uint16_t lastChar = _font[5] * 256 + _font[4];
WiredHome 98:ecebed9b80b2 1584 uint16_t i;
WiredHome 98:ecebed9b80b2 1585
WiredHome 98:ecebed9b80b2 1586 for (i=firstChar; i<=lastChar; i++) {
WiredHome 98:ecebed9b80b2 1587 // 8 bytes of preamble to the first level lookup table
WiredHome 98:ecebed9b80b2 1588 uint16_t offsetToCharLookup = 8 + 4 * (i - firstChar); // 4-bytes: width(pixels), 16-bit offset from table start, 0
WiredHome 98:ecebed9b80b2 1589 totalWidth += _font[offsetToCharLookup];
WiredHome 98:ecebed9b80b2 1590 }
WiredHome 98:ecebed9b80b2 1591 extFontWidth = totalWidth / (lastChar - firstChar);
WiredHome 98:ecebed9b80b2 1592 INFO("Font Metrics: Avg W: %2d, H: %2d, First:%d, Last:%d", extFontWidth, extFontHeight, firstChar, lastChar);
WiredHome 98:ecebed9b80b2 1593 }
WiredHome 98:ecebed9b80b2 1594 SetTextCursor(GetTextCursor_X(), GetTextCursor_Y()); // soft-font cursor -> hw cursor
WiredHome 98:ecebed9b80b2 1595 font = _font;
WiredHome 98:ecebed9b80b2 1596 return GraphicsDisplay::SelectUserFont(_font);
WiredHome 98:ecebed9b80b2 1597 }
WiredHome 44:207594dece70 1598
WiredHome 19:3f82c1161fd2 1599 RetCode_t RA8875::background(color_t color)
WiredHome 19:3f82c1161fd2 1600 {
WiredHome 37:f19b7e7449dc 1601 GraphicsDisplay::background(color);
WiredHome 19:3f82c1161fd2 1602 WriteCommand(0x60, (color>>11)); // BGCR0
WiredHome 19:3f82c1161fd2 1603 WriteCommand(0x61, (unsigned char)(color>>5)); // BGCR0
WiredHome 19:3f82c1161fd2 1604 WriteCommand(0x62, (unsigned char)(color)); // BGCR0
WiredHome 19:3f82c1161fd2 1605 return noerror;
WiredHome 19:3f82c1161fd2 1606 }
WiredHome 19:3f82c1161fd2 1607
WiredHome 44:207594dece70 1608
WiredHome 19:3f82c1161fd2 1609 RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 1610 {
WiredHome 37:f19b7e7449dc 1611 background(RGB(r,g,b));
WiredHome 19:3f82c1161fd2 1612 return noerror;
WiredHome 19:3f82c1161fd2 1613 }
WiredHome 19:3f82c1161fd2 1614
WiredHome 44:207594dece70 1615
WiredHome 19:3f82c1161fd2 1616 RetCode_t RA8875::foreground(color_t color)
WiredHome 19:3f82c1161fd2 1617 {
WiredHome 37:f19b7e7449dc 1618 GraphicsDisplay::foreground(color);
WiredHome 19:3f82c1161fd2 1619 WriteCommand(0x63, (unsigned char)(color>>11));
WiredHome 19:3f82c1161fd2 1620 WriteCommand(0x64, (unsigned char)(color>>5));
WiredHome 19:3f82c1161fd2 1621 WriteCommand(0x65, (unsigned char)(color));
WiredHome 19:3f82c1161fd2 1622 return noerror;
WiredHome 19:3f82c1161fd2 1623 }
WiredHome 19:3f82c1161fd2 1624
WiredHome 44:207594dece70 1625
WiredHome 37:f19b7e7449dc 1626 RetCode_t RA8875::foreground(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 1627 {
WiredHome 37:f19b7e7449dc 1628 foreground(RGB(r,g,b));
WiredHome 19:3f82c1161fd2 1629 return noerror;
WiredHome 19:3f82c1161fd2 1630 }
WiredHome 19:3f82c1161fd2 1631
WiredHome 44:207594dece70 1632
WiredHome 37:f19b7e7449dc 1633 color_t RA8875::GetForeColor(void)
WiredHome 19:3f82c1161fd2 1634 {
WiredHome 19:3f82c1161fd2 1635 color_t color;
WiredHome 73:f22a18707b5e 1636
WiredHome 19:3f82c1161fd2 1637 color = (ReadCommand(0x63) & 0x1F) << 11;
WiredHome 19:3f82c1161fd2 1638 color |= (ReadCommand(0x64) & 0x3F) << 5;
WiredHome 19:3f82c1161fd2 1639 color |= (ReadCommand(0x65) & 0x1F);
WiredHome 19:3f82c1161fd2 1640 return color;
WiredHome 19:3f82c1161fd2 1641 }
WiredHome 19:3f82c1161fd2 1642
WiredHome 44:207594dece70 1643
WiredHome 19:3f82c1161fd2 1644 color_t RA8875::DOSColor(int i)
WiredHome 73:f22a18707b5e 1645 {
WiredHome 73:f22a18707b5e 1646 const color_t colors[16] = {
WiredHome 19:3f82c1161fd2 1647 Black, Blue, Green, Cyan,
WiredHome 19:3f82c1161fd2 1648 Red, Magenta, Brown, Gray,
WiredHome 19:3f82c1161fd2 1649 Charcoal, BrightBlue, BrightGreen, BrightCyan,
WiredHome 19:3f82c1161fd2 1650 Orange, Pink, Yellow, White
WiredHome 73:f22a18707b5e 1651 };
WiredHome 85:022bba13c5c4 1652 if (i >= 0 && i < 16)
WiredHome 19:3f82c1161fd2 1653 return colors[i];
WiredHome 19:3f82c1161fd2 1654 else
WiredHome 19:3f82c1161fd2 1655 return 0;
WiredHome 73:f22a18707b5e 1656 }
WiredHome 19:3f82c1161fd2 1657
WiredHome 44:207594dece70 1658
WiredHome 73:f22a18707b5e 1659 const char * RA8875::DOSColorNames(int i)
WiredHome 73:f22a18707b5e 1660 {
WiredHome 73:f22a18707b5e 1661 const char * names[16] = {
WiredHome 19:3f82c1161fd2 1662 "Black", "Blue", "Green", "Cyan",
WiredHome 19:3f82c1161fd2 1663 "Red", "Magenta", "Brown", "Gray",
WiredHome 19:3f82c1161fd2 1664 "Charcoal", "BrightBlue", "BrightGreen", "BrightCyan",
WiredHome 19:3f82c1161fd2 1665 "Orange", "Pink", "Yellow", "White"
WiredHome 73:f22a18707b5e 1666 };
WiredHome 85:022bba13c5c4 1667 if (i >= 0 && i < 16)
WiredHome 19:3f82c1161fd2 1668 return names[i];
WiredHome 19:3f82c1161fd2 1669 else
WiredHome 19:3f82c1161fd2 1670 return NULL;
WiredHome 73:f22a18707b5e 1671 }
WiredHome 19:3f82c1161fd2 1672
WiredHome 19:3f82c1161fd2 1673
WiredHome 19:3f82c1161fd2 1674 ///////////////////////////////////////////////////////////////
WiredHome 19:3f82c1161fd2 1675 // Private functions
WiredHome 19:3f82c1161fd2 1676
WiredHome 79:544eb4964795 1677 unsigned char RA8875::_spiwrite(unsigned char data)
WiredHome 19:3f82c1161fd2 1678 {
WiredHome 19:3f82c1161fd2 1679 unsigned char retval;
WiredHome 73:f22a18707b5e 1680
WiredHome 68:ab08efabfc88 1681 if (!spiWriteSpeed)
WiredHome 68:ab08efabfc88 1682 _setWriteSpeed(true);
WiredHome 19:3f82c1161fd2 1683 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 1684 return retval;
WiredHome 19:3f82c1161fd2 1685 }
WiredHome 19:3f82c1161fd2 1686
WiredHome 44:207594dece70 1687
WiredHome 79:544eb4964795 1688 unsigned char RA8875::_spiread(void)
WiredHome 19:3f82c1161fd2 1689 {
WiredHome 19:3f82c1161fd2 1690 unsigned char retval;
WiredHome 19:3f82c1161fd2 1691 unsigned char data = 0;
WiredHome 73:f22a18707b5e 1692
WiredHome 68:ab08efabfc88 1693 if (spiWriteSpeed)
WiredHome 68:ab08efabfc88 1694 _setWriteSpeed(false);
WiredHome 19:3f82c1161fd2 1695 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 1696 return retval;
WiredHome 19:3f82c1161fd2 1697 }
WiredHome 19:3f82c1161fd2 1698
WiredHome 44:207594dece70 1699
WiredHome 79:544eb4964795 1700 RetCode_t RA8875::_select(bool chipsel)
WiredHome 19:3f82c1161fd2 1701 {
WiredHome 19:3f82c1161fd2 1702 cs = (chipsel == true) ? 0 : 1;
WiredHome 19:3f82c1161fd2 1703 return noerror;
WiredHome 19:3f82c1161fd2 1704 }
WiredHome 19:3f82c1161fd2 1705
WiredHome 44:207594dece70 1706
WiredHome 72:ecffe56af969 1707 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 1708 {
WiredHome 74:686faa218914 1709 (void)layer;
WiredHome 96:40b74dd3695b 1710
WiredHome 96:40b74dd3695b 1711 // AttachPrintHandler(this, RA8875::_printCallback);
WiredHome 96:40b74dd3695b 1712 // return PrintScreen(x,y,w,h);
WiredHome 74:686faa218914 1713 return PrintScreen(x, y, w, h, Name_BMP);
WiredHome 72:ecffe56af969 1714 }
WiredHome 72:ecffe56af969 1715
WiredHome 96:40b74dd3695b 1716 RetCode_t RA8875::_printCallback(RA8875::filecmd_t cmd, uint8_t * buffer, uint16_t size)
WiredHome 96:40b74dd3695b 1717 {
WiredHome 96:40b74dd3695b 1718 HexDump("CB", buffer, size);
WiredHome 96:40b74dd3695b 1719 switch(cmd) {
WiredHome 96:40b74dd3695b 1720 case RA8875::OPEN:
WiredHome 96:40b74dd3695b 1721 //pc.printf("About to write %lu bytes\r\n", *(uint32_t *)buffer);
WiredHome 96:40b74dd3695b 1722 _printFH = fopen("file.bmp", "w+b");
WiredHome 96:40b74dd3695b 1723 if (_printFH == 0)
WiredHome 96:40b74dd3695b 1724 return file_not_found;
WiredHome 96:40b74dd3695b 1725 break;
WiredHome 96:40b74dd3695b 1726 case RA8875::WRITE:
WiredHome 96:40b74dd3695b 1727 //pc.printf(" Write %4u bytes\r\n", size);
WiredHome 96:40b74dd3695b 1728 fwrite(buffer, 1, size, _printFH);
WiredHome 96:40b74dd3695b 1729 break;
WiredHome 96:40b74dd3695b 1730 case RA8875::CLOSE:
WiredHome 96:40b74dd3695b 1731 //pc.printf(" close\r\n");
WiredHome 96:40b74dd3695b 1732 fclose(_printFH);
WiredHome 96:40b74dd3695b 1733 _printFH = 0;
WiredHome 96:40b74dd3695b 1734 break;
WiredHome 96:40b74dd3695b 1735 default:
WiredHome 96:40b74dd3695b 1736 //pc.printf("Unexpected callback %d\r\n", cmd);
WiredHome 96:40b74dd3695b 1737 return file_not_found;
WiredHome 96:40b74dd3695b 1738 //break;
WiredHome 96:40b74dd3695b 1739 }
WiredHome 96:40b74dd3695b 1740 return noerror;
WiredHome 96:40b74dd3695b 1741 }
WiredHome 96:40b74dd3695b 1742
WiredHome 96:40b74dd3695b 1743 RetCode_t RA8875::PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h)
WiredHome 96:40b74dd3695b 1744 {
WiredHome 96:40b74dd3695b 1745 BITMAPFILEHEADER BMP_Header;
WiredHome 96:40b74dd3695b 1746 BITMAPINFOHEADER BMP_Info;
WiredHome 96:40b74dd3695b 1747 uint8_t * lineBuffer = NULL;
WiredHome 96:40b74dd3695b 1748 color_t * pixelBuffer = NULL;
WiredHome 96:40b74dd3695b 1749 color_t * pixelBuffer2 = NULL;
WiredHome 96:40b74dd3695b 1750
WiredHome 98:ecebed9b80b2 1751 INFO("(%d,%d) - (%d,%d)", x,y,w,h);
WiredHome 105:4f116006ba1f 1752 if (x >= 0 && x < screenwidth
WiredHome 105:4f116006ba1f 1753 && y >= 0 && y < screenheight
WiredHome 105:4f116006ba1f 1754 && w > 0 && x + w <= screenwidth
WiredHome 105:4f116006ba1f 1755 && h > 0 && y + h <= screenheight) {
WiredHome 96:40b74dd3695b 1756
WiredHome 96:40b74dd3695b 1757 BMP_Header.bfType = BF_TYPE;
WiredHome 96:40b74dd3695b 1758 BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Header);
WiredHome 96:40b74dd3695b 1759 BMP_Header.bfReserved1 = 0;
WiredHome 96:40b74dd3695b 1760 BMP_Header.bfReserved2 = 0;
WiredHome 96:40b74dd3695b 1761 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Header);
WiredHome 96:40b74dd3695b 1762
WiredHome 96:40b74dd3695b 1763 BMP_Info.biSize = sizeof(BMP_Info);
WiredHome 96:40b74dd3695b 1764 BMP_Info.biWidth = w;
WiredHome 96:40b74dd3695b 1765 BMP_Info.biHeight = h;
WiredHome 96:40b74dd3695b 1766 BMP_Info.biPlanes = 1;
WiredHome 96:40b74dd3695b 1767 BMP_Info.biBitCount = 24;
WiredHome 96:40b74dd3695b 1768 BMP_Info.biCompression = BI_RGB;
WiredHome 96:40b74dd3695b 1769 BMP_Info.biSizeImage = 0;
WiredHome 96:40b74dd3695b 1770 BMP_Info.biXPelsPerMeter = 0;
WiredHome 96:40b74dd3695b 1771 BMP_Info.biYPelsPerMeter = 0;
WiredHome 96:40b74dd3695b 1772 BMP_Info.biClrUsed = 0;
WiredHome 96:40b74dd3695b 1773 BMP_Info.biClrImportant = 0;
WiredHome 96:40b74dd3695b 1774
WiredHome 96:40b74dd3695b 1775 // Allocate the memory we need to proceed
WiredHome 96:40b74dd3695b 1776 int lineBufSize = ((24 * w + 7)/8);
WiredHome 96:40b74dd3695b 1777 lineBuffer = (uint8_t *)malloc(lineBufSize);
WiredHome 96:40b74dd3695b 1778 if (lineBuffer == NULL) {
WiredHome 96:40b74dd3695b 1779 ERR("Not enough RAM for PrintScreen lineBuffer");
WiredHome 96:40b74dd3695b 1780 return(not_enough_ram);
WiredHome 96:40b74dd3695b 1781 }
WiredHome 96:40b74dd3695b 1782
WiredHome 96:40b74dd3695b 1783 #define DOUBLEBUF /* one larger buffer instead of two */
WiredHome 96:40b74dd3695b 1784
WiredHome 96:40b74dd3695b 1785 #ifdef DOUBLEBUF
WiredHome 96:40b74dd3695b 1786 // In the "#else", pixelBuffer2 malloc returns a value,
WiredHome 96:40b74dd3695b 1787 // but is actually causing a failure later.
WiredHome 96:40b74dd3695b 1788 // This test helps determine if it is truly out of memory,
WiredHome 96:40b74dd3695b 1789 // or if malloc is broken.
WiredHome 96:40b74dd3695b 1790 pixelBuffer = (color_t *)malloc(2 * w * sizeof(color_t));
WiredHome 96:40b74dd3695b 1791 pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
WiredHome 96:40b74dd3695b 1792 #else
WiredHome 96:40b74dd3695b 1793 pixelBuffer = (color_t *)malloc(w * sizeof(color_t));
WiredHome 96:40b74dd3695b 1794 pixelBuffer2 = (color_t *)malloc(w * sizeof(color_t));
WiredHome 96:40b74dd3695b 1795 #endif
WiredHome 96:40b74dd3695b 1796 if (pixelBuffer == NULL || pixelBuffer2 == NULL) {
WiredHome 96:40b74dd3695b 1797 ERR("Not enough RAM for pixelBuffer");
WiredHome 96:40b74dd3695b 1798 #ifndef DOUBLEBUF
WiredHome 96:40b74dd3695b 1799 if (pixelBuffer2)
WiredHome 96:40b74dd3695b 1800 free(pixelBuffer2);
WiredHome 96:40b74dd3695b 1801 #endif
WiredHome 96:40b74dd3695b 1802 if (pixelBuffer)
WiredHome 96:40b74dd3695b 1803 free(pixelBuffer);
WiredHome 96:40b74dd3695b 1804 free(lineBuffer);
WiredHome 96:40b74dd3695b 1805 return(not_enough_ram);
WiredHome 96:40b74dd3695b 1806 }
WiredHome 96:40b74dd3695b 1807
WiredHome 96:40b74dd3695b 1808 // Get the file primed...
WiredHome 96:40b74dd3695b 1809 privateCallback(OPEN, (uint8_t *)&BMP_Header.bfSize, 4);
WiredHome 96:40b74dd3695b 1810
WiredHome 96:40b74dd3695b 1811 // Be optimistic - don't check for errors.
WiredHome 96:40b74dd3695b 1812 HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 96:40b74dd3695b 1813 //fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image);
WiredHome 96:40b74dd3695b 1814 privateCallback(WRITE, (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 96:40b74dd3695b 1815
WiredHome 96:40b74dd3695b 1816 HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 96:40b74dd3695b 1817 //fwrite(&BMP_Info, sizeof(char), sizeof(BMP_Info), Image);
WiredHome 96:40b74dd3695b 1818 privateCallback(WRITE, (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 96:40b74dd3695b 1819
WiredHome 96:40b74dd3695b 1820 //color_t transparency = GetBackgroundTransparencyColor();
WiredHome 96:40b74dd3695b 1821 LayerMode_T ltpr0 = GetLayerMode();
WiredHome 96:40b74dd3695b 1822
WiredHome 96:40b74dd3695b 1823 uint16_t prevLayer = GetDrawingLayer();
WiredHome 96:40b74dd3695b 1824 // If only one of the layers is visible, select that layer
WiredHome 96:40b74dd3695b 1825 switch(ltpr0) {
WiredHome 96:40b74dd3695b 1826 case ShowLayer0:
WiredHome 96:40b74dd3695b 1827 SelectDrawingLayer(0);
WiredHome 96:40b74dd3695b 1828 break;
WiredHome 96:40b74dd3695b 1829 case ShowLayer1:
WiredHome 96:40b74dd3695b 1830 SelectDrawingLayer(1);
WiredHome 96:40b74dd3695b 1831 break;
WiredHome 96:40b74dd3695b 1832 default:
WiredHome 96:40b74dd3695b 1833 break;
WiredHome 96:40b74dd3695b 1834 }
WiredHome 96:40b74dd3695b 1835
WiredHome 96:40b74dd3695b 1836 // Read the display from the last line toward the top
WiredHome 96:40b74dd3695b 1837 // so we can write the file in one pass.
WiredHome 96:40b74dd3695b 1838 for (int j = h - 1; j >= 0; j--) {
WiredHome 96:40b74dd3695b 1839 if (ltpr0 >= 2) // Need to combine the layers...
WiredHome 96:40b74dd3695b 1840 SelectDrawingLayer(0); // so read layer 0 first
WiredHome 96:40b74dd3695b 1841 // Read one line of pixels to a local buffer
WiredHome 96:40b74dd3695b 1842 if (getPixelStream(pixelBuffer, w, x,y+j) != noerror) {
WiredHome 96:40b74dd3695b 1843 ERR("getPixelStream error, and no recovery handler...");
WiredHome 96:40b74dd3695b 1844 }
WiredHome 96:40b74dd3695b 1845 if (ltpr0 >= 2) { // Need to combine the layers...
WiredHome 96:40b74dd3695b 1846 SelectDrawingLayer(1); // so read layer 1 next
WiredHome 96:40b74dd3695b 1847 if (getPixelStream(pixelBuffer2, w, x,y+j) != noerror) {
WiredHome 96:40b74dd3695b 1848 ERR("getPixelStream error, and no recovery handler...");
WiredHome 96:40b74dd3695b 1849 }
WiredHome 96:40b74dd3695b 1850 }
WiredHome 96:40b74dd3695b 1851 INFO("1st Color: %04X", pixelBuffer[0]);
WiredHome 96:40b74dd3695b 1852 HexDump("Raster", (uint8_t *)pixelBuffer, w);
WiredHome 96:40b74dd3695b 1853 // Convert the local buffer to RGBQUAD format
WiredHome 96:40b74dd3695b 1854 int lb = 0;
WiredHome 96:40b74dd3695b 1855 for (int i=0; i<w; i++) {
WiredHome 96:40b74dd3695b 1856 RGBQUAD q0 = RGB16ToRGBQuad(pixelBuffer[x+i]); // Scale to 24-bits
WiredHome 96:40b74dd3695b 1857 RGBQUAD q1 = RGB16ToRGBQuad(pixelBuffer2[x+i]); // Scale to 24-bits
WiredHome 96:40b74dd3695b 1858 switch (ltpr0) {
WiredHome 96:40b74dd3695b 1859 case 0:
WiredHome 96:40b74dd3695b 1860 case 1:
WiredHome 96:40b74dd3695b 1861 case 2: // lighten-overlay (@TODO Not supported yet)
WiredHome 96:40b74dd3695b 1862 case 6: // Floating Windows (@TODO not sure how to support)
WiredHome 96:40b74dd3695b 1863 default: // Reserved...
WiredHome 96:40b74dd3695b 1864 lineBuffer[lb++] = q0.rgbBlue;
WiredHome 96:40b74dd3695b 1865 lineBuffer[lb++] = q0.rgbGreen;
WiredHome 96:40b74dd3695b 1866 lineBuffer[lb++] = q0.rgbRed;
WiredHome 96:40b74dd3695b 1867 break;
WiredHome 96:40b74dd3695b 1868 case 3: // transparent mode (@TODO Read the background color register for transparent)
WiredHome 96:40b74dd3695b 1869 case 4: // boolean or
WiredHome 96:40b74dd3695b 1870 lineBuffer[lb++] = q0.rgbBlue | q1.rgbBlue;
WiredHome 96:40b74dd3695b 1871 lineBuffer[lb++] = q0.rgbGreen | q1.rgbGreen;
WiredHome 96:40b74dd3695b 1872 lineBuffer[lb++] = q0.rgbRed | q1.rgbRed;
WiredHome 96:40b74dd3695b 1873 break;
WiredHome 96:40b74dd3695b 1874 case 5: // boolean AND
WiredHome 96:40b74dd3695b 1875 lineBuffer[lb++] = q0.rgbBlue & q1.rgbBlue;
WiredHome 96:40b74dd3695b 1876 lineBuffer[lb++] = q0.rgbGreen & q1.rgbGreen;
WiredHome 96:40b74dd3695b 1877 lineBuffer[lb++] = q0.rgbRed & q1.rgbRed;
WiredHome 96:40b74dd3695b 1878 break;
WiredHome 96:40b74dd3695b 1879 }
WiredHome 96:40b74dd3695b 1880 }
WiredHome 96:40b74dd3695b 1881 if (j == h - 1) {
WiredHome 96:40b74dd3695b 1882 HexDump("Line", lineBuffer, lineBufSize);
WiredHome 96:40b74dd3695b 1883 }
WiredHome 96:40b74dd3695b 1884 // Write to disk
WiredHome 96:40b74dd3695b 1885 //fwrite(lineBuffer, sizeof(char), lb, Image);
WiredHome 96:40b74dd3695b 1886 privateCallback(WRITE, (uint8_t *)lineBuffer, lb);
WiredHome 96:40b74dd3695b 1887 }
WiredHome 96:40b74dd3695b 1888 SelectDrawingLayer(prevLayer);
WiredHome 96:40b74dd3695b 1889 //fclose(Image);
WiredHome 96:40b74dd3695b 1890 privateCallback(CLOSE, NULL, 0);
WiredHome 96:40b74dd3695b 1891
WiredHome 96:40b74dd3695b 1892 #ifndef DOUBLEBUF
WiredHome 96:40b74dd3695b 1893 if (pixelBuffer2)
WiredHome 96:40b74dd3695b 1894 free(pixelBuffer2);
WiredHome 96:40b74dd3695b 1895 #endif
WiredHome 96:40b74dd3695b 1896 if (pixelBuffer)
WiredHome 96:40b74dd3695b 1897 free(pixelBuffer);
WiredHome 96:40b74dd3695b 1898 free(lineBuffer);
WiredHome 96:40b74dd3695b 1899 INFO("Image closed");
WiredHome 96:40b74dd3695b 1900 return noerror;
WiredHome 96:40b74dd3695b 1901 } else {
WiredHome 96:40b74dd3695b 1902 return bad_parameter;
WiredHome 96:40b74dd3695b 1903 }
WiredHome 96:40b74dd3695b 1904 }
WiredHome 79:544eb4964795 1905
WiredHome 72:ecffe56af969 1906 RetCode_t RA8875::PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP)
WiredHome 72:ecffe56af969 1907 {
WiredHome 72:ecffe56af969 1908 BITMAPFILEHEADER BMP_Header;
WiredHome 72:ecffe56af969 1909 BITMAPINFOHEADER BMP_Info;
WiredHome 86:e86b355940f4 1910 uint8_t * lineBuffer = NULL;
WiredHome 86:e86b355940f4 1911 color_t * pixelBuffer = NULL;
WiredHome 86:e86b355940f4 1912 color_t * pixelBuffer2 = NULL;
WiredHome 86:e86b355940f4 1913
WiredHome 72:ecffe56af969 1914 INFO("(%d,%d) - (%d,%d) %s", x,y,w,h,Name_BMP);
WiredHome 105:4f116006ba1f 1915 if (x >= 0 && x < screenwidth
WiredHome 105:4f116006ba1f 1916 && y >= 0 && y < screenheight
WiredHome 105:4f116006ba1f 1917 && w > 0 && x + w <= screenwidth
WiredHome 105:4f116006ba1f 1918 && h > 0 && y + h <= screenheight) {
WiredHome 72:ecffe56af969 1919
WiredHome 72:ecffe56af969 1920 BMP_Header.bfType = BF_TYPE;
WiredHome 72:ecffe56af969 1921 BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Header);
WiredHome 72:ecffe56af969 1922 BMP_Header.bfReserved1 = 0;
WiredHome 72:ecffe56af969 1923 BMP_Header.bfReserved2 = 0;
WiredHome 72:ecffe56af969 1924 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Header);
WiredHome 73:f22a18707b5e 1925
WiredHome 72:ecffe56af969 1926 BMP_Info.biSize = sizeof(BMP_Info);
WiredHome 72:ecffe56af969 1927 BMP_Info.biWidth = w;
WiredHome 72:ecffe56af969 1928 BMP_Info.biHeight = h;
WiredHome 72:ecffe56af969 1929 BMP_Info.biPlanes = 1;
WiredHome 72:ecffe56af969 1930 BMP_Info.biBitCount = 24;
WiredHome 72:ecffe56af969 1931 BMP_Info.biCompression = BI_RGB;
WiredHome 72:ecffe56af969 1932 BMP_Info.biSizeImage = 0;
WiredHome 72:ecffe56af969 1933 BMP_Info.biXPelsPerMeter = 0;
WiredHome 72:ecffe56af969 1934 BMP_Info.biYPelsPerMeter = 0;
WiredHome 72:ecffe56af969 1935 BMP_Info.biClrUsed = 0;
WiredHome 72:ecffe56af969 1936 BMP_Info.biClrImportant = 0;
WiredHome 72:ecffe56af969 1937
WiredHome 86:e86b355940f4 1938 // Allocate the memory we need to proceed
WiredHome 86:e86b355940f4 1939 int lineBufSize = ((24 * w + 7)/8);
WiredHome 86:e86b355940f4 1940 lineBuffer = (uint8_t *)malloc(lineBufSize);
WiredHome 86:e86b355940f4 1941 if (lineBuffer == NULL) {
WiredHome 86:e86b355940f4 1942 ERR("Not enough RAM for PrintScreen lineBuffer");
WiredHome 86:e86b355940f4 1943 return(not_enough_ram);
WiredHome 86:e86b355940f4 1944 }
WiredHome 86:e86b355940f4 1945
WiredHome 86:e86b355940f4 1946 #define DOUBLEBUF /* one larger buffer instead of two */
WiredHome 86:e86b355940f4 1947
WiredHome 86:e86b355940f4 1948 #ifdef DOUBLEBUF
WiredHome 86:e86b355940f4 1949 // In the "#else", pixelBuffer2 malloc returns a value,
WiredHome 86:e86b355940f4 1950 // but is actually causing a failure later.
WiredHome 86:e86b355940f4 1951 // This test helps determine if it is truly out of memory,
WiredHome 86:e86b355940f4 1952 // or if malloc is broken.
WiredHome 86:e86b355940f4 1953 pixelBuffer = (color_t *)malloc(2 * w * sizeof(color_t));
WiredHome 86:e86b355940f4 1954 pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
WiredHome 86:e86b355940f4 1955 #else
WiredHome 86:e86b355940f4 1956 pixelBuffer = (color_t *)malloc(w * sizeof(color_t));
WiredHome 86:e86b355940f4 1957 pixelBuffer2 = (color_t *)malloc(w * sizeof(color_t));
WiredHome 86:e86b355940f4 1958 #endif
WiredHome 86:e86b355940f4 1959 if (pixelBuffer == NULL || pixelBuffer2 == NULL) {
WiredHome 86:e86b355940f4 1960 ERR("Not enough RAM for pixelBuffer");
WiredHome 86:e86b355940f4 1961 #ifndef DOUBLEBUF
WiredHome 86:e86b355940f4 1962 if (pixelBuffer2)
WiredHome 86:e86b355940f4 1963 free(pixelBuffer2);
WiredHome 86:e86b355940f4 1964 #endif
WiredHome 86:e86b355940f4 1965 if (pixelBuffer)
WiredHome 86:e86b355940f4 1966 free(pixelBuffer);
WiredHome 86:e86b355940f4 1967 free(lineBuffer);
WiredHome 86:e86b355940f4 1968 return(not_enough_ram);
WiredHome 86:e86b355940f4 1969 }
WiredHome 86:e86b355940f4 1970
WiredHome 72:ecffe56af969 1971 FILE *Image = fopen(Name_BMP, "wb");
WiredHome 72:ecffe56af969 1972 if (!Image) {
WiredHome 86:e86b355940f4 1973 ERR("Can't open file for write");
WiredHome 86:e86b355940f4 1974 #ifndef DOUBLEBUF
WiredHome 86:e86b355940f4 1975 if (pixelBuffer2)
WiredHome 86:e86b355940f4 1976 free(pixelBuffer2);
WiredHome 86:e86b355940f4 1977 #endif
WiredHome 86:e86b355940f4 1978 if (pixelBuffer)
WiredHome 86:e86b355940f4 1979 free(pixelBuffer);
WiredHome 86:e86b355940f4 1980 free(lineBuffer);
WiredHome 72:ecffe56af969 1981 return(file_not_found);
WiredHome 72:ecffe56af969 1982 }
WiredHome 72:ecffe56af969 1983
WiredHome 72:ecffe56af969 1984 // Be optimistic - don't check for errors.
WiredHome 93:6fbc516de05e 1985 HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 95:ef538bd687c0 1986 fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image);
WiredHome 73:f22a18707b5e 1987
WiredHome 93:6fbc516de05e 1988 HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 95:ef538bd687c0 1989 fwrite(&BMP_Info, sizeof(char), sizeof(BMP_Info), Image);
WiredHome 73:f22a18707b5e 1990
WiredHome 95:ef538bd687c0 1991 //color_t transparency = GetBackgroundTransparencyColor();
WiredHome 95:ef538bd687c0 1992 LayerMode_T ltpr0 = GetLayerMode();
WiredHome 73:f22a18707b5e 1993
WiredHome 73:f22a18707b5e 1994 uint16_t prevLayer = GetDrawingLayer();
WiredHome 73:f22a18707b5e 1995 // If only one of the layers is visible, select that layer
WiredHome 73:f22a18707b5e 1996 switch(ltpr0) {
WiredHome 95:ef538bd687c0 1997 case ShowLayer0:
WiredHome 73:f22a18707b5e 1998 SelectDrawingLayer(0);
WiredHome 73:f22a18707b5e 1999 break;
WiredHome 95:ef538bd687c0 2000 case ShowLayer1:
WiredHome 73:f22a18707b5e 2001 SelectDrawingLayer(1);
WiredHome 73:f22a18707b5e 2002 break;
WiredHome 73:f22a18707b5e 2003 default:
WiredHome 73:f22a18707b5e 2004 break;
WiredHome 73:f22a18707b5e 2005 }
WiredHome 73:f22a18707b5e 2006
WiredHome 72:ecffe56af969 2007 // Read the display from the last line toward the top
WiredHome 72:ecffe56af969 2008 // so we can write the file in one pass.
WiredHome 72:ecffe56af969 2009 for (int j = h - 1; j >= 0; j--) {
WiredHome 73:f22a18707b5e 2010 if (ltpr0 >= 2) // Need to combine the layers...
WiredHome 73:f22a18707b5e 2011 SelectDrawingLayer(0); // so read layer 0 first
WiredHome 72:ecffe56af969 2012 // Read one line of pixels to a local buffer
WiredHome 72:ecffe56af969 2013 if (getPixelStream(pixelBuffer, w, x,y+j) != noerror) {
WiredHome 72:ecffe56af969 2014 ERR("getPixelStream error, and no recovery handler...");
WiredHome 72:ecffe56af969 2015 }
WiredHome 73:f22a18707b5e 2016 if (ltpr0 >= 2) { // Need to combine the layers...
WiredHome 86:e86b355940f4 2017 SelectDrawingLayer(1); // so read layer 1 next
WiredHome 73:f22a18707b5e 2018 if (getPixelStream(pixelBuffer2, w, x,y+j) != noerror) {
WiredHome 73:f22a18707b5e 2019 ERR("getPixelStream error, and no recovery handler...");
WiredHome 73:f22a18707b5e 2020 }
WiredHome 73:f22a18707b5e 2021 }
WiredHome 93:6fbc516de05e 2022 INFO("1st Color: %04X", pixelBuffer[0]);
WiredHome 93:6fbc516de05e 2023 HexDump("Raster", (uint8_t *)pixelBuffer, w);
WiredHome 72:ecffe56af969 2024 // Convert the local buffer to RGBQUAD format
WiredHome 72:ecffe56af969 2025 int lb = 0;
WiredHome 72:ecffe56af969 2026 for (int i=0; i<w; i++) {
WiredHome 73:f22a18707b5e 2027 RGBQUAD q0 = RGB16ToRGBQuad(pixelBuffer[x+i]); // Scale to 24-bits
WiredHome 73:f22a18707b5e 2028 RGBQUAD q1 = RGB16ToRGBQuad(pixelBuffer2[x+i]); // Scale to 24-bits
WiredHome 73:f22a18707b5e 2029 switch (ltpr0) {
WiredHome 73:f22a18707b5e 2030 case 0:
WiredHome 73:f22a18707b5e 2031 case 1:
WiredHome 73:f22a18707b5e 2032 case 2: // lighten-overlay (@TODO Not supported yet)
WiredHome 73:f22a18707b5e 2033 case 6: // Floating Windows (@TODO not sure how to support)
WiredHome 73:f22a18707b5e 2034 default: // Reserved...
WiredHome 73:f22a18707b5e 2035 lineBuffer[lb++] = q0.rgbBlue;
WiredHome 73:f22a18707b5e 2036 lineBuffer[lb++] = q0.rgbGreen;
WiredHome 73:f22a18707b5e 2037 lineBuffer[lb++] = q0.rgbRed;
WiredHome 73:f22a18707b5e 2038 break;
WiredHome 73:f22a18707b5e 2039 case 3: // transparent mode (@TODO Read the background color register for transparent)
WiredHome 73:f22a18707b5e 2040 case 4: // boolean or
WiredHome 73:f22a18707b5e 2041 lineBuffer[lb++] = q0.rgbBlue | q1.rgbBlue;
WiredHome 73:f22a18707b5e 2042 lineBuffer[lb++] = q0.rgbGreen | q1.rgbGreen;
WiredHome 73:f22a18707b5e 2043 lineBuffer[lb++] = q0.rgbRed | q1.rgbRed;
WiredHome 73:f22a18707b5e 2044 break;
WiredHome 73:f22a18707b5e 2045 case 5: // boolean AND
WiredHome 73:f22a18707b5e 2046 lineBuffer[lb++] = q0.rgbBlue & q1.rgbBlue;
WiredHome 73:f22a18707b5e 2047 lineBuffer[lb++] = q0.rgbGreen & q1.rgbGreen;
WiredHome 73:f22a18707b5e 2048 lineBuffer[lb++] = q0.rgbRed & q1.rgbRed;
WiredHome 73:f22a18707b5e 2049 break;
WiredHome 73:f22a18707b5e 2050 }
WiredHome 72:ecffe56af969 2051 }
WiredHome 95:ef538bd687c0 2052 if (j == h - 1) {
WiredHome 73:f22a18707b5e 2053 HexDump("Line", lineBuffer, lineBufSize);
WiredHome 95:ef538bd687c0 2054 }
WiredHome 72:ecffe56af969 2055 // Write to disk
WiredHome 72:ecffe56af969 2056 fwrite(lineBuffer, sizeof(char), lb, Image);
WiredHome 72:ecffe56af969 2057 }
WiredHome 73:f22a18707b5e 2058 SelectDrawingLayer(prevLayer);
WiredHome 72:ecffe56af969 2059 fclose(Image);
WiredHome 86:e86b355940f4 2060 #ifndef DOUBLEBUF
WiredHome 86:e86b355940f4 2061 if (pixelBuffer2)
WiredHome 86:e86b355940f4 2062 free(pixelBuffer2);
WiredHome 86:e86b355940f4 2063 #endif
WiredHome 86:e86b355940f4 2064 if (pixelBuffer)
WiredHome 86:e86b355940f4 2065 free(pixelBuffer);
WiredHome 72:ecffe56af969 2066 free(lineBuffer);
WiredHome 73:f22a18707b5e 2067 INFO("Image closed");
WiredHome 72:ecffe56af969 2068 return noerror;
WiredHome 72:ecffe56af969 2069 } else {
WiredHome 72:ecffe56af969 2070 return bad_parameter;
WiredHome 72:ecffe56af969 2071 }
WiredHome 72:ecffe56af969 2072 }
WiredHome 72:ecffe56af969 2073
WiredHome 72:ecffe56af969 2074
WiredHome 72:ecffe56af969 2075 // ##########################################################################
WiredHome 72:ecffe56af969 2076 // ##########################################################################
WiredHome 72:ecffe56af969 2077 // ##########################################################################
WiredHome 72:ecffe56af969 2078
WiredHome 23:a50ded45dbaf 2079 #ifdef TESTENABLE
WiredHome 23:a50ded45dbaf 2080
WiredHome 98:ecebed9b80b2 2081 #include "BPG_Arial08x08.h"
WiredHome 98:ecebed9b80b2 2082 #include "BPG_Arial20x20.h"
WiredHome 37:f19b7e7449dc 2083
WiredHome 23:a50ded45dbaf 2084 // ______________ ______________ ______________ _______________
WiredHome 23:a50ded45dbaf 2085 // /_____ _____/ / ___________/ / ___________/ /_____ ______/
WiredHome 23:a50ded45dbaf 2086 // / / / / / / / /
WiredHome 23:a50ded45dbaf 2087 // / / / /___ / /__________ / /
WiredHome 23:a50ded45dbaf 2088 // / / / ____/ /__________ / / /
WiredHome 23:a50ded45dbaf 2089 // / / / / / / / /
WiredHome 23:a50ded45dbaf 2090 // / / / /__________ ___________/ / / /
WiredHome 23:a50ded45dbaf 2091 // /__/ /_____________/ /_____________/ /__/
WiredHome 23:a50ded45dbaf 2092 //
WiredHome 23:a50ded45dbaf 2093 // Everything from here down is test code.
WiredHome 75:ca78388cfd77 2094 //
WiredHome 41:2956a0a221e5 2095 bool SuppressSlowStuff = false;
WiredHome 23:a50ded45dbaf 2096
WiredHome 49:c5182231d1b9 2097 void TextWrapTest(RA8875 & display, Serial & pc)
WiredHome 49:c5182231d1b9 2098 {
WiredHome 49:c5182231d1b9 2099 if (!SuppressSlowStuff)
WiredHome 49:c5182231d1b9 2100 pc.printf("Text Wrap Test\r\n");
WiredHome 49:c5182231d1b9 2101 display.background(Black);
WiredHome 49:c5182231d1b9 2102 display.foreground(Blue);
WiredHome 49:c5182231d1b9 2103 display.cls();
WiredHome 49:c5182231d1b9 2104 display.Backlight_u8(255);
WiredHome 100:0b084475d5a9 2105 display.puts("Text Wrap Test.\r\n");
WiredHome 52:e6039a823420 2106 for (int i=1; i<60; i++) {
WiredHome 52:e6039a823420 2107 display.printf("L%2d\n", i % 17);
WiredHome 49:c5182231d1b9 2108 if (!SuppressSlowStuff)
WiredHome 52:e6039a823420 2109 wait_ms(100);
WiredHome 49:c5182231d1b9 2110 }
WiredHome 49:c5182231d1b9 2111 if (!SuppressSlowStuff)
WiredHome 49:c5182231d1b9 2112 wait_ms(3000);
WiredHome 49:c5182231d1b9 2113 }
WiredHome 49:c5182231d1b9 2114
WiredHome 75:ca78388cfd77 2115
WiredHome 75:ca78388cfd77 2116 void ShowKey(RA8875 & display, int key)
WiredHome 75:ca78388cfd77 2117 {
WiredHome 75:ca78388cfd77 2118 loc_t col, row;
WiredHome 75:ca78388cfd77 2119 dim_t r1 = 25;
WiredHome 75:ca78388cfd77 2120 color_t color = (key & 0x80) ? Red : Green;
WiredHome 75:ca78388cfd77 2121
WiredHome 75:ca78388cfd77 2122 key &= 0x7F; // remove the long-press flag
WiredHome 75:ca78388cfd77 2123 row = (key - 1) / 5;
WiredHome 75:ca78388cfd77 2124 col = (key - 1) % 5;
WiredHome 75:ca78388cfd77 2125 if (col > 5) col = 5;
WiredHome 75:ca78388cfd77 2126 if (row > 4) row = 4;
WiredHome 75:ca78388cfd77 2127 display.circle(450 - + (2 * r1) * col, 200 - (2 * r1) * row, r1-2, color, FILL);
WiredHome 75:ca78388cfd77 2128 }
WiredHome 75:ca78388cfd77 2129
WiredHome 75:ca78388cfd77 2130 void HideKey(RA8875 & display, int key)
WiredHome 75:ca78388cfd77 2131 {
WiredHome 75:ca78388cfd77 2132 loc_t col, row;
WiredHome 75:ca78388cfd77 2133 dim_t r1 = 25;
WiredHome 75:ca78388cfd77 2134
WiredHome 75:ca78388cfd77 2135 row = (key - 1) / 5;
WiredHome 75:ca78388cfd77 2136 col = (key - 1) % 5;
WiredHome 75:ca78388cfd77 2137 if (col > 5) col = 5;
WiredHome 75:ca78388cfd77 2138 if (row > 4) row = 4;
WiredHome 75:ca78388cfd77 2139 display.background(Black);
WiredHome 75:ca78388cfd77 2140 display.circle(450 - (2 * r1) * col, 200 - (2 * r1) * row, r1-2, Black, FILL);
WiredHome 75:ca78388cfd77 2141 display.circle(450 - (2 * r1) * col, 200 - (2 * r1) * row, r1-2, Blue);
WiredHome 75:ca78388cfd77 2142 }
WiredHome 75:ca78388cfd77 2143
WiredHome 75:ca78388cfd77 2144 void KeyPadTest(RA8875 & display, Serial & pc)
WiredHome 75:ca78388cfd77 2145 {
WiredHome 75:ca78388cfd77 2146 const uint8_t myMap[22] = {
WiredHome 77:9206c13aa527 2147 0,
WiredHome 75:ca78388cfd77 2148 'a', 'b', 'c', 'd', 'e',
WiredHome 75:ca78388cfd77 2149 'f', 'g', 'h', 'i', 'j',
WiredHome 75:ca78388cfd77 2150 'k', 'l', 'm', 'n', 'o',
WiredHome 75:ca78388cfd77 2151 'p', 'q', 'r', 's', 't',
WiredHome 75:ca78388cfd77 2152 'x'
WiredHome 75:ca78388cfd77 2153 };
WiredHome 77:9206c13aa527 2154
WiredHome 75:ca78388cfd77 2155 display.background(Black);
WiredHome 75:ca78388cfd77 2156 display.foreground(Blue);
WiredHome 75:ca78388cfd77 2157 display.cls();
WiredHome 75:ca78388cfd77 2158 display.Backlight_u8(255);
WiredHome 100:0b084475d5a9 2159 display.puts("KeyPad Test. Touch the keypad...");
WiredHome 75:ca78388cfd77 2160 pc.printf("\r\n"
WiredHome 75:ca78388cfd77 2161 "Raw KeyPad Test. Keypad returns the key-number.\r\n"
WiredHome 75:ca78388cfd77 2162 "Press [most] any PC keyboard key to advance to next test.\r\n");
WiredHome 75:ca78388cfd77 2163 RetCode_t ret = display.KeypadInit(true, true, 3, 7, 3);
WiredHome 75:ca78388cfd77 2164 if (ret != noerror)
WiredHome 75:ca78388cfd77 2165 pc.printf("returncode from KeypadInit is %d\r\n", ret);
WiredHome 75:ca78388cfd77 2166 int lastKey = 0;
WiredHome 75:ca78388cfd77 2167 while (!pc.readable()) {
WiredHome 75:ca78388cfd77 2168 if (display.readable()) {
WiredHome 75:ca78388cfd77 2169 int key = display.getc();
WiredHome 75:ca78388cfd77 2170 if (key) {
WiredHome 75:ca78388cfd77 2171 if (((key & 0x7F) != lastKey) && (lastKey != 0))
WiredHome 75:ca78388cfd77 2172 HideKey(display, lastKey);
WiredHome 75:ca78388cfd77 2173 ShowKey(display, key);
WiredHome 75:ca78388cfd77 2174 lastKey = key & 0x7F;
WiredHome 75:ca78388cfd77 2175 } else {
WiredHome 75:ca78388cfd77 2176 // erase the last one
WiredHome 75:ca78388cfd77 2177 if (lastKey)
WiredHome 75:ca78388cfd77 2178 HideKey(display, lastKey);
WiredHome 75:ca78388cfd77 2179 }
WiredHome 75:ca78388cfd77 2180 }
WiredHome 75:ca78388cfd77 2181 }
WiredHome 75:ca78388cfd77 2182 (void)pc.getc();
WiredHome 75:ca78388cfd77 2183 pc.printf("\r\n"
WiredHome 75:ca78388cfd77 2184 "Map KeyPad Test. Keypad returns the remapped key 'a' - 't'.\r\n"
WiredHome 75:ca78388cfd77 2185 "Press [most] any PC keyboard key to advance to exit test.\r\n");
WiredHome 75:ca78388cfd77 2186 display.SetKeyMap(myMap);
WiredHome 75:ca78388cfd77 2187 while (!pc.readable()) {
WiredHome 75:ca78388cfd77 2188 if (display.readable()) {
WiredHome 75:ca78388cfd77 2189 int key = display.getc();
WiredHome 75:ca78388cfd77 2190 bool longPress = key & 0x80;
WiredHome 75:ca78388cfd77 2191 display.SetTextCursor(0, 120);
WiredHome 75:ca78388cfd77 2192 display.printf("Long Press: %d\r\n", longPress);
WiredHome 75:ca78388cfd77 2193 display.printf(" Remapped: %c %02X\r\n", (key) ? key & 0x7F : ' ', key);
WiredHome 75:ca78388cfd77 2194 }
WiredHome 75:ca78388cfd77 2195 }
WiredHome 75:ca78388cfd77 2196 (void)pc.getc();
WiredHome 75:ca78388cfd77 2197 display.SetKeyMap();
WiredHome 75:ca78388cfd77 2198 pc.printf("\r\n");
WiredHome 75:ca78388cfd77 2199 }
WiredHome 75:ca78388cfd77 2200
WiredHome 23:a50ded45dbaf 2201 void TextCursorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2202 {
WiredHome 75:ca78388cfd77 2203 const char * iCursor = "The I-Beam cursor should be visible for this text.\r\n";
WiredHome 75:ca78388cfd77 2204 const char * uCursor = "The Underscore cursor should be visible for this text.\r\n";
WiredHome 75:ca78388cfd77 2205 const char * bCursor = "The Block cursor should be visible for this text.\r\n";
WiredHome 37:f19b7e7449dc 2206 const char * bbCursor = "The Blinking Block cursor should be visible for this text.\r\n";
WiredHome 23:a50ded45dbaf 2207 const char * p;
WiredHome 100:0b084475d5a9 2208 int delay = 60;
WiredHome 73:f22a18707b5e 2209
WiredHome 41:2956a0a221e5 2210 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2211 pc.printf("Text Cursor Test\r\n");
WiredHome 73:f22a18707b5e 2212 else
WiredHome 41:2956a0a221e5 2213 delay = 0;
WiredHome 23:a50ded45dbaf 2214 display.background(Black);
WiredHome 23:a50ded45dbaf 2215 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2216 display.cls();
WiredHome 25:9556a3a9b7cc 2217 display.Backlight_u8(255);
WiredHome 100:0b084475d5a9 2218 display.puts("Text Cursor Test.");
WiredHome 73:f22a18707b5e 2219
WiredHome 23:a50ded45dbaf 2220 // visible, non-blinking
WiredHome 24:8ca861acf12d 2221 display.SetTextCursor(0,20);
WiredHome 53:86d24b9480b9 2222 display.SetTextCursorControl(RA8875::IBEAM, false);
WiredHome 24:8ca861acf12d 2223 p = iCursor;
WiredHome 23:a50ded45dbaf 2224 while (*p) {
WiredHome 24:8ca861acf12d 2225 display._putc(*p++);
WiredHome 41:2956a0a221e5 2226 wait_ms(delay);
WiredHome 24:8ca861acf12d 2227 }
WiredHome 24:8ca861acf12d 2228
WiredHome 53:86d24b9480b9 2229 display.SetTextCursorControl(RA8875::UNDER, false);
WiredHome 24:8ca861acf12d 2230 p = uCursor;
WiredHome 24:8ca861acf12d 2231 while (*p) {
WiredHome 24:8ca861acf12d 2232 display._putc(*p++);
WiredHome 41:2956a0a221e5 2233 wait_ms(delay);
WiredHome 23:a50ded45dbaf 2234 }
WiredHome 73:f22a18707b5e 2235
WiredHome 53:86d24b9480b9 2236 display.SetTextCursorControl(RA8875::BLOCK, false);
WiredHome 24:8ca861acf12d 2237 p = bCursor;
WiredHome 24:8ca861acf12d 2238 while (*p) {
WiredHome 24:8ca861acf12d 2239 display._putc(*p++);
WiredHome 41:2956a0a221e5 2240 wait_ms(delay);
WiredHome 24:8ca861acf12d 2241 }
WiredHome 24:8ca861acf12d 2242
WiredHome 53:86d24b9480b9 2243 display.SetTextCursorControl(RA8875::BLOCK, true);
WiredHome 24:8ca861acf12d 2244 p = bbCursor;
WiredHome 24:8ca861acf12d 2245 while (*p) {
WiredHome 24:8ca861acf12d 2246 display._putc(*p++);
WiredHome 41:2956a0a221e5 2247 wait_ms(delay);
WiredHome 24:8ca861acf12d 2248 }
WiredHome 41:2956a0a221e5 2249 wait_ms(delay * 20);
WiredHome 53:86d24b9480b9 2250 display.SetTextCursorControl(RA8875::NOCURSOR, false);
WiredHome 23:a50ded45dbaf 2251 }
WiredHome 23:a50ded45dbaf 2252
WiredHome 44:207594dece70 2253
WiredHome 23:a50ded45dbaf 2254 void BacklightTest(RA8875 & display, Serial & pc, float ramptime)
WiredHome 23:a50ded45dbaf 2255 {
WiredHome 29:422616aa04bd 2256 char buf[60];
WiredHome 41:2956a0a221e5 2257 unsigned int w = (ramptime * 1000)/ 256;
WiredHome 41:2956a0a221e5 2258 int delay = 200;
WiredHome 41:2956a0a221e5 2259
WiredHome 41:2956a0a221e5 2260 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2261 pc.printf("Backlight Test - ramp over %f sec.\r\n", ramptime);
WiredHome 41:2956a0a221e5 2262 else {
WiredHome 41:2956a0a221e5 2263 delay = 0;
WiredHome 41:2956a0a221e5 2264 w = 0;
WiredHome 41:2956a0a221e5 2265 }
WiredHome 23:a50ded45dbaf 2266 display.Backlight_u8(0);
WiredHome 29:422616aa04bd 2267 display.background(White);
WiredHome 23:a50ded45dbaf 2268 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2269 display.cls();
WiredHome 100:0b084475d5a9 2270 display.puts("RA8875 Backlight Test - Ramp up.");
WiredHome 41:2956a0a221e5 2271 wait_ms(delay);
WiredHome 38:38d503b4fad6 2272 for (int i=0; i <= 255; i++) {
WiredHome 29:422616aa04bd 2273 sprintf(buf, "%3d, %4d", i, w);
WiredHome 37:f19b7e7449dc 2274 display.puts(100,100,buf);
WiredHome 23:a50ded45dbaf 2275 display.Backlight_u8(i);
WiredHome 29:422616aa04bd 2276 wait_ms(w);
WiredHome 23:a50ded45dbaf 2277 }
WiredHome 23:a50ded45dbaf 2278 }
WiredHome 23:a50ded45dbaf 2279
WiredHome 44:207594dece70 2280
WiredHome 23:a50ded45dbaf 2281 void BacklightTest2(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2282 {
WiredHome 41:2956a0a221e5 2283 int delay = 20;
WiredHome 41:2956a0a221e5 2284
WiredHome 41:2956a0a221e5 2285 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2286 pc.printf("Backlight Test 2\r\n");
WiredHome 41:2956a0a221e5 2287 else
WiredHome 41:2956a0a221e5 2288 delay = 0;
WiredHome 41:2956a0a221e5 2289
WiredHome 23:a50ded45dbaf 2290 // Dim it out at the end of the tests.
WiredHome 37:f19b7e7449dc 2291 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2292 display.puts(0,0, "Ramp Backlight down.");
WiredHome 23:a50ded45dbaf 2293 // Ramp it off
WiredHome 23:a50ded45dbaf 2294 for (int i=255; i != 0; i--) {
WiredHome 23:a50ded45dbaf 2295 display.Backlight_u8(i);
WiredHome 41:2956a0a221e5 2296 wait_ms(delay);
WiredHome 23:a50ded45dbaf 2297 }
WiredHome 23:a50ded45dbaf 2298 display.Backlight_u8(0);
WiredHome 23:a50ded45dbaf 2299 }
WiredHome 23:a50ded45dbaf 2300
WiredHome 44:207594dece70 2301
WiredHome 23:a50ded45dbaf 2302 void ExternalFontTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2303 {
WiredHome 41:2956a0a221e5 2304 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2305 pc.printf("External Font Test\r\n");
WiredHome 23:a50ded45dbaf 2306 display.background(Black);
WiredHome 23:a50ded45dbaf 2307 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2308 display.cls();
WiredHome 100:0b084475d5a9 2309 display.puts("External Font Test.");
WiredHome 23:a50ded45dbaf 2310 display.Backlight(1);
WiredHome 37:f19b7e7449dc 2311
WiredHome 98:ecebed9b80b2 2312 display.SelectUserFont(BPG_Arial08x08);
WiredHome 73:f22a18707b5e 2313 display.puts(0,30, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 37:f19b7e7449dc 2314
WiredHome 98:ecebed9b80b2 2315 display.SelectUserFont(BPG_Arial20x20);
WiredHome 37:f19b7e7449dc 2316 display.puts("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 98:ecebed9b80b2 2317
WiredHome 98:ecebed9b80b2 2318 display.SelectUserFont();
WiredHome 73:f22a18707b5e 2319
WiredHome 37:f19b7e7449dc 2320 display.puts("Normal font again.");
WiredHome 37:f19b7e7449dc 2321 //display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 2322 }
WiredHome 23:a50ded45dbaf 2323
WiredHome 44:207594dece70 2324
WiredHome 23:a50ded45dbaf 2325 void DOSColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2326 {
WiredHome 41:2956a0a221e5 2327 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2328 pc.printf("DOS Color Test\r\n");
WiredHome 23:a50ded45dbaf 2329 display.background(Black);
WiredHome 23:a50ded45dbaf 2330 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2331 display.cls();
WiredHome 100:0b084475d5a9 2332 display.puts("DOS Colors - Fore");
WiredHome 23:a50ded45dbaf 2333 display.puts(280,0, "Back");
WiredHome 23:a50ded45dbaf 2334 display.background(Gray);
WiredHome 23:a50ded45dbaf 2335 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2336 display.foreground(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2337 display.puts(160, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 2338 display.background(Black);
WiredHome 23:a50ded45dbaf 2339 }
WiredHome 23:a50ded45dbaf 2340 display.foreground(White);
WiredHome 23:a50ded45dbaf 2341 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2342 display.background(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2343 display.puts(360, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 2344 display.foreground(White);
WiredHome 23:a50ded45dbaf 2345 }
WiredHome 23:a50ded45dbaf 2346 }
WiredHome 23:a50ded45dbaf 2347
WiredHome 44:207594dece70 2348
WiredHome 23:a50ded45dbaf 2349 void WebColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2350 {
WiredHome 41:2956a0a221e5 2351 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2352 pc.printf("Web Color Test\r\n");
WiredHome 23:a50ded45dbaf 2353 display.background(Black);
WiredHome 23:a50ded45dbaf 2354 display.foreground(Blue);
WiredHome 32:0e4f2ae512e2 2355 display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 2356 display.cls();
WiredHome 59:fb40aad4efd4 2357 display.SetTextFontSize(1,1);
WiredHome 59:fb40aad4efd4 2358 display.puts(200,0, "Web Color Test");
WiredHome 59:fb40aad4efd4 2359 display.SetTextCursor(0,0);
WiredHome 59:fb40aad4efd4 2360 display.puts(" ");
WiredHome 59:fb40aad4efd4 2361 for (int i=0; i<16; i++)
WiredHome 59:fb40aad4efd4 2362 display.printf("%X", i&0xF);
WiredHome 59:fb40aad4efd4 2363 display.puts("\r\n0 ");
WiredHome 23:a50ded45dbaf 2364 for (int i=0; i<sizeof(WebColors)/sizeof(WebColors[0]); i++) {
WiredHome 23:a50ded45dbaf 2365 display.background(WebColors[i]);
WiredHome 23:a50ded45dbaf 2366 display.puts(" ");
WiredHome 59:fb40aad4efd4 2367 if (i % 16 == 15 && i < 255) {
WiredHome 59:fb40aad4efd4 2368 display.printf("\r\n%X ", ((i+1)/16));
WiredHome 59:fb40aad4efd4 2369 }
WiredHome 23:a50ded45dbaf 2370 }
WiredHome 23:a50ded45dbaf 2371 display.SetTextFontSize(1,1);
WiredHome 23:a50ded45dbaf 2372 }
WiredHome 23:a50ded45dbaf 2373
WiredHome 44:207594dece70 2374
WiredHome 37:f19b7e7449dc 2375 void PixelTest(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 2376 {
WiredHome 37:f19b7e7449dc 2377 int i, c, x, y;
WiredHome 37:f19b7e7449dc 2378
WiredHome 41:2956a0a221e5 2379 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2380 pc.printf("Pixel Test\r\n");
WiredHome 37:f19b7e7449dc 2381 display.background(Black);
WiredHome 37:f19b7e7449dc 2382 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 2383 display.cls();
WiredHome 100:0b084475d5a9 2384 display.puts("Pixel Test");
WiredHome 37:f19b7e7449dc 2385 for (i=0; i<1000; i++) {
WiredHome 37:f19b7e7449dc 2386 x = rand() % 480;
WiredHome 37:f19b7e7449dc 2387 y = 16 + rand() % (272-16);
WiredHome 37:f19b7e7449dc 2388 c = rand() % 16;
WiredHome 37:f19b7e7449dc 2389 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 37:f19b7e7449dc 2390 display.pixel(x,y, display.DOSColor(c));
WiredHome 37:f19b7e7449dc 2391 }
WiredHome 37:f19b7e7449dc 2392 }
WiredHome 37:f19b7e7449dc 2393
WiredHome 44:207594dece70 2394
WiredHome 23:a50ded45dbaf 2395 void LineTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2396 {
WiredHome 23:a50ded45dbaf 2397 int i, x, y, x2, y2;
WiredHome 23:a50ded45dbaf 2398
WiredHome 41:2956a0a221e5 2399 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2400 pc.printf("Line Test\r\n");
WiredHome 23:a50ded45dbaf 2401 display.background(Black);
WiredHome 23:a50ded45dbaf 2402 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2403 display.cls();
WiredHome 100:0b084475d5a9 2404 display.puts("Line Test");
WiredHome 23:a50ded45dbaf 2405 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2406 // Lines
WiredHome 23:a50ded45dbaf 2407 x = rand() % 480;
WiredHome 23:a50ded45dbaf 2408 y = rand() % 272;
WiredHome 23:a50ded45dbaf 2409 x2 = rand() % 480;
WiredHome 23:a50ded45dbaf 2410 y2 = rand() % 272;
WiredHome 23:a50ded45dbaf 2411 display.line(x,y, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2412 }
WiredHome 62:ba5d33438fda 2413 display.foreground(BrightRed);
WiredHome 62:ba5d33438fda 2414 display.foreground(BrightGreen);
WiredHome 62:ba5d33438fda 2415 display.foreground(BrightBlue);
WiredHome 62:ba5d33438fda 2416 display.line(55,50, 79,74, BrightRed);
WiredHome 62:ba5d33438fda 2417 display.line(57,50, 81,74, BrightGreen);
WiredHome 62:ba5d33438fda 2418 display.line(59,50, 83,74, BrightBlue);
WiredHome 62:ba5d33438fda 2419 // horz
WiredHome 62:ba5d33438fda 2420 display.line(30,40, 32,40, BrightRed);
WiredHome 62:ba5d33438fda 2421 display.line(30,42, 32,42, BrightGreen);
WiredHome 62:ba5d33438fda 2422 display.line(30,44, 32,44, BrightBlue);
WiredHome 62:ba5d33438fda 2423 // vert
WiredHome 62:ba5d33438fda 2424 display.line(20,40, 20,42, BrightRed);
WiredHome 62:ba5d33438fda 2425 display.line(22,40, 22,42, BrightGreen);
WiredHome 62:ba5d33438fda 2426 display.line(24,40, 24,42, BrightBlue);
WiredHome 62:ba5d33438fda 2427 // compare point to line-point
WiredHome 62:ba5d33438fda 2428 display.pixel(20,50, BrightRed);
WiredHome 62:ba5d33438fda 2429 display.pixel(22,50, BrightGreen);
WiredHome 62:ba5d33438fda 2430 display.pixel(24,50, BrightBlue);
WiredHome 62:ba5d33438fda 2431 display.line(20,52, 20,52, BrightRed);
WiredHome 62:ba5d33438fda 2432 display.line(22,52, 22,52, BrightGreen);
WiredHome 62:ba5d33438fda 2433 display.line(24,52, 24,52, BrightBlue);
WiredHome 73:f22a18707b5e 2434
WiredHome 62:ba5d33438fda 2435 // point
WiredHome 62:ba5d33438fda 2436 display.line(50,50, 50,50, Red);
WiredHome 62:ba5d33438fda 2437 display.line(52,52, 52,52, Green);
WiredHome 62:ba5d33438fda 2438 display.line(54,54, 54,54, Blue);
WiredHome 62:ba5d33438fda 2439 display.line(60,60, 60,60, BrightRed);
WiredHome 62:ba5d33438fda 2440 display.line(62,62, 62,62, BrightGreen);
WiredHome 62:ba5d33438fda 2441 display.line(64,64, 64,64, BrightBlue);
WiredHome 62:ba5d33438fda 2442 display.line(70,70, 70,70, DarkRed);
WiredHome 62:ba5d33438fda 2443 display.line(72,72, 72,72, DarkGreen);
WiredHome 62:ba5d33438fda 2444 display.line(74,74, 74,74, DarkBlue);
WiredHome 23:a50ded45dbaf 2445 }
WiredHome 23:a50ded45dbaf 2446
WiredHome 44:207594dece70 2447
WiredHome 23:a50ded45dbaf 2448 void RectangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2449 {
WiredHome 23:a50ded45dbaf 2450 int i, x1,y1, x2,y2;
WiredHome 23:a50ded45dbaf 2451
WiredHome 41:2956a0a221e5 2452 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2453 pc.printf("Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 2454 display.background(Black);
WiredHome 23:a50ded45dbaf 2455 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2456 display.cls();
WiredHome 100:0b084475d5a9 2457 display.puts("Rectangle Test");
WiredHome 23:a50ded45dbaf 2458 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2459 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 2460 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2461 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 2462 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2463 display.rect(x1,y1, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2464
WiredHome 23:a50ded45dbaf 2465 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2466 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2467 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2468 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2469 display.rect(x1,y1, x2,y2, FILL);
WiredHome 23:a50ded45dbaf 2470 }
WiredHome 23:a50ded45dbaf 2471 }
WiredHome 23:a50ded45dbaf 2472
WiredHome 44:207594dece70 2473
WiredHome 44:207594dece70 2474 void LayerTest(RA8875 & display, Serial & pc)
WiredHome 44:207594dece70 2475 {
WiredHome 44:207594dece70 2476 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 44:207594dece70 2477
WiredHome 44:207594dece70 2478 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2479 pc.printf("Layer Test\r\n");
WiredHome 44:207594dece70 2480
WiredHome 50:2c4f474a2453 2481 display.SelectDrawingLayer(0);
WiredHome 44:207594dece70 2482 display.background(Black);
WiredHome 44:207594dece70 2483 display.foreground(Blue);
WiredHome 44:207594dece70 2484 display.cls();
WiredHome 100:0b084475d5a9 2485 display.puts("Layer 0");
WiredHome 44:207594dece70 2486 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 2487 x1 = rand() % 240;
WiredHome 44:207594dece70 2488 y1 = 50 + rand() % 200;
WiredHome 44:207594dece70 2489 x2 = x1 + rand() % 100;
WiredHome 44:207594dece70 2490 y2 = y1 + rand() % 100;
WiredHome 44:207594dece70 2491 r1 = rand() % (x2 - x1)/2;
WiredHome 44:207594dece70 2492 r2 = rand() % (y2 - y1)/2;
WiredHome 44:207594dece70 2493 display.roundrect(x1,y1, x2,y2, r1,r2, display.DOSColor(i));
WiredHome 44:207594dece70 2494 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2495 wait_ms(20);
WiredHome 44:207594dece70 2496 }
WiredHome 44:207594dece70 2497 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2498 wait_ms(1000);
WiredHome 44:207594dece70 2499
WiredHome 50:2c4f474a2453 2500 display.SelectDrawingLayer(1);
WiredHome 44:207594dece70 2501 display.background(Black);
WiredHome 44:207594dece70 2502 display.foreground(Yellow);
WiredHome 44:207594dece70 2503 display.cls();
WiredHome 44:207594dece70 2504 display.puts(240,0, "Layer 1");
WiredHome 44:207594dece70 2505 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 2506 x1 = 300 + rand() % 100;
WiredHome 44:207594dece70 2507 y1 = 70 + rand() % 200;
WiredHome 44:207594dece70 2508 r1 = rand() % min(y1 - 20, 100);
WiredHome 44:207594dece70 2509 display.circle(x1,y1,r1, display.DOSColor(i));
WiredHome 44:207594dece70 2510 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2511 wait_ms(20);
WiredHome 44:207594dece70 2512 }
WiredHome 56:7a85d226ad0d 2513 display.SetLayerMode(RA8875::ShowLayer1); // Show it after the build-up
WiredHome 44:207594dece70 2514 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2515 wait_ms(2000);
WiredHome 44:207594dece70 2516
WiredHome 50:2c4f474a2453 2517 display.SelectDrawingLayer(0);
WiredHome 56:7a85d226ad0d 2518 display.SetLayerMode(RA8875::ShowLayer0); // Show Layer 0 again
WiredHome 44:207594dece70 2519 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2520 wait_ms(1000);
WiredHome 53:86d24b9480b9 2521 display.SetLayerMode(RA8875::TransparentMode); // Transparent mode
WiredHome 44:207594dece70 2522 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2523 wait_ms(1000);
WiredHome 44:207594dece70 2524 for (i=0; i<=8; i++) {
WiredHome 44:207594dece70 2525 display.SetLayerTransparency(i, 8-i);
WiredHome 44:207594dece70 2526 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2527 wait_ms(200);
WiredHome 44:207594dece70 2528 }
WiredHome 73:f22a18707b5e 2529
WiredHome 44:207594dece70 2530 // Restore before we exit
WiredHome 44:207594dece70 2531 display.SetLayerTransparency(0, 0);
WiredHome 56:7a85d226ad0d 2532 display.SetLayerMode(RA8875::ShowLayer0); // Restore to layer 0
WiredHome 44:207594dece70 2533 }
WiredHome 44:207594dece70 2534
WiredHome 44:207594dece70 2535
WiredHome 23:a50ded45dbaf 2536 void RoundRectTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2537 {
WiredHome 37:f19b7e7449dc 2538 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 23:a50ded45dbaf 2539
WiredHome 41:2956a0a221e5 2540 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2541 pc.printf("Round Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 2542 display.background(Black);
WiredHome 23:a50ded45dbaf 2543 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2544 display.cls();
WiredHome 100:0b084475d5a9 2545 display.puts("Rounded Rectangle Test");
WiredHome 73:f22a18707b5e 2546
WiredHome 23:a50ded45dbaf 2547 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2548 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 2549 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2550 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 2551 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 2552 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 2553 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 2554 display.roundrect(x1,y1, x2,y2, 5,8, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2555
WiredHome 23:a50ded45dbaf 2556 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2557 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2558 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 2559 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 2560 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 2561 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 2562 display.roundrect(x1,y1, x2,y2, r1,r2, FILL);
WiredHome 23:a50ded45dbaf 2563 }
WiredHome 23:a50ded45dbaf 2564 }
WiredHome 23:a50ded45dbaf 2565
WiredHome 44:207594dece70 2566
WiredHome 23:a50ded45dbaf 2567 void TriangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2568 {
WiredHome 23:a50ded45dbaf 2569 int i, x1, y1, x2, y2, x3, y3;
WiredHome 23:a50ded45dbaf 2570
WiredHome 41:2956a0a221e5 2571 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2572 pc.printf("Triangle Test\r\n");
WiredHome 23:a50ded45dbaf 2573 display.background(Black);
WiredHome 23:a50ded45dbaf 2574 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2575 display.cls();
WiredHome 23:a50ded45dbaf 2576 display.puts(0,0, "Triangle Test");
WiredHome 23:a50ded45dbaf 2577
WiredHome 23:a50ded45dbaf 2578 x1 = 150;
WiredHome 23:a50ded45dbaf 2579 y1 = 2;
WiredHome 23:a50ded45dbaf 2580 x2 = 190;
WiredHome 23:a50ded45dbaf 2581 y2 = 7;
WiredHome 23:a50ded45dbaf 2582 x3 = 170;
WiredHome 23:a50ded45dbaf 2583 y3 = 16;
WiredHome 23:a50ded45dbaf 2584 display.triangle(x1,y1, x2,y2, x3,y3);
WiredHome 23:a50ded45dbaf 2585
WiredHome 23:a50ded45dbaf 2586 x1 = 200;
WiredHome 23:a50ded45dbaf 2587 y1 = 2;
WiredHome 23:a50ded45dbaf 2588 x2 = 240;
WiredHome 23:a50ded45dbaf 2589 y2 = 7;
WiredHome 23:a50ded45dbaf 2590 x3 = 220;
WiredHome 23:a50ded45dbaf 2591 y3 = 16;
WiredHome 23:a50ded45dbaf 2592 display.filltriangle(x1,y1, x2,y2, x3,y3, BrightRed);
WiredHome 23:a50ded45dbaf 2593
WiredHome 23:a50ded45dbaf 2594 x1 = 300;
WiredHome 23:a50ded45dbaf 2595 y1 = 2;
WiredHome 23:a50ded45dbaf 2596 x2 = 340;
WiredHome 23:a50ded45dbaf 2597 y2 = 7;
WiredHome 23:a50ded45dbaf 2598 x3 = 320;
WiredHome 23:a50ded45dbaf 2599 y3 = 16;
WiredHome 23:a50ded45dbaf 2600 display.triangle(x1,y1, x2,y2, x3,y3, NOFILL);
WiredHome 23:a50ded45dbaf 2601
WiredHome 23:a50ded45dbaf 2602 x1 = 400;
WiredHome 23:a50ded45dbaf 2603 y1 = 2;
WiredHome 23:a50ded45dbaf 2604 x2 = 440;
WiredHome 23:a50ded45dbaf 2605 y2 = 7;
WiredHome 23:a50ded45dbaf 2606 x3 = 420;
WiredHome 23:a50ded45dbaf 2607 y3 = 16;
WiredHome 23:a50ded45dbaf 2608 display.triangle(x1,y1, x2,y2, x3,y3, Blue);
WiredHome 23:a50ded45dbaf 2609
WiredHome 23:a50ded45dbaf 2610 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2611 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 2612 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2613 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 2614 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2615 x3 = rand() % 240;
WiredHome 23:a50ded45dbaf 2616 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2617 display.triangle(x1,y1, x2,y2, x3,y3, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2618 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2619 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2620 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2621 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2622 x3 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2623 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2624 display.triangle(x1,y1, x2,y2, x3,y3, FILL);
WiredHome 23:a50ded45dbaf 2625 }
WiredHome 23:a50ded45dbaf 2626 }
WiredHome 23:a50ded45dbaf 2627
WiredHome 44:207594dece70 2628
WiredHome 23:a50ded45dbaf 2629 void CircleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2630 {
WiredHome 23:a50ded45dbaf 2631 int i, x, y, r1;
WiredHome 23:a50ded45dbaf 2632
WiredHome 41:2956a0a221e5 2633 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2634 pc.printf("Circle Test\r\n");
WiredHome 23:a50ded45dbaf 2635 display.background(Black);
WiredHome 23:a50ded45dbaf 2636 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2637 display.cls();
WiredHome 100:0b084475d5a9 2638 display.puts("Circle Test");
WiredHome 23:a50ded45dbaf 2639 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2640 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 2641 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2642 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2643 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 2644 display.circle(x,y,r1, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2645
WiredHome 23:a50ded45dbaf 2646 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 2647 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2648 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2649 //pc.printf(" (%d,%d) - %d FILL\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 2650 display.circle(x,y,r1, display.DOSColor(i), FILL);
WiredHome 23:a50ded45dbaf 2651 }
WiredHome 23:a50ded45dbaf 2652 }
WiredHome 23:a50ded45dbaf 2653
WiredHome 44:207594dece70 2654
WiredHome 23:a50ded45dbaf 2655 void EllipseTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2656 {
WiredHome 23:a50ded45dbaf 2657 int i,x,y,r1,r2;
WiredHome 23:a50ded45dbaf 2658
WiredHome 41:2956a0a221e5 2659 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2660 pc.printf("Ellipse Test\r\n");
WiredHome 23:a50ded45dbaf 2661 display.background(Black);
WiredHome 23:a50ded45dbaf 2662 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2663 display.cls();
WiredHome 100:0b084475d5a9 2664 display.puts("Ellipse Test");
WiredHome 23:a50ded45dbaf 2665 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2666 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 2667 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2668 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2669 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2670 display.ellipse(x,y,r1,r2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2671
WiredHome 23:a50ded45dbaf 2672 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 2673 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2674 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2675 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2676 display.ellipse(x,y,r1,r2, FILL);
WiredHome 23:a50ded45dbaf 2677 }
WiredHome 23:a50ded45dbaf 2678 }
WiredHome 23:a50ded45dbaf 2679
WiredHome 44:207594dece70 2680
WiredHome 37:f19b7e7449dc 2681 void TestGraphicsBitmap(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 2682 {
WiredHome 37:f19b7e7449dc 2683 LocalFileSystem local("local");
WiredHome 41:2956a0a221e5 2684 if (!SuppressSlowStuff)
WiredHome 73:f22a18707b5e 2685 pc.printf("Bitmap File Load\r\n");
WiredHome 37:f19b7e7449dc 2686 display.background(Black);
WiredHome 37:f19b7e7449dc 2687 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 2688 display.cls();
WiredHome 100:0b084475d5a9 2689 display.puts("Graphics Test, loading /local/TestPat.bmp");
WiredHome 37:f19b7e7449dc 2690 wait(3);
WiredHome 37:f19b7e7449dc 2691
WiredHome 37:f19b7e7449dc 2692 int r = display.RenderBitmapFile(0,0, "/local/TestPat.bmp");
WiredHome 59:fb40aad4efd4 2693 if (!SuppressSlowStuff)
WiredHome 59:fb40aad4efd4 2694 pc.printf(" returned %d\r\n", r);
WiredHome 37:f19b7e7449dc 2695 }
WiredHome 37:f19b7e7449dc 2696
WiredHome 44:207594dece70 2697
WiredHome 77:9206c13aa527 2698 void TouchPanelTest(RA8875 & display, Serial & pc)
WiredHome 77:9206c13aa527 2699 {
WiredHome 77:9206c13aa527 2700 Timer t;
WiredHome 98:ecebed9b80b2 2701 int x, y;
WiredHome 78:faf49c381591 2702 tpMatrix_t calmatrix;
WiredHome 78:faf49c381591 2703
WiredHome 77:9206c13aa527 2704 display.background(Black);
WiredHome 77:9206c13aa527 2705 display.foreground(Blue);
WiredHome 77:9206c13aa527 2706 display.cls();
WiredHome 100:0b084475d5a9 2707 display.puts("Touch Panel Test\r\n");
WiredHome 78:faf49c381591 2708 pc.printf("Touch Panel Test\r\n");
WiredHome 77:9206c13aa527 2709 display.TouchPanelInit();
WiredHome 78:faf49c381591 2710 pc.printf(" TP: c - calibrate, r - restore, t - test\r\n");
WiredHome 78:faf49c381591 2711 int c = pc.getc();
WiredHome 78:faf49c381591 2712 if (c == 'c') {
WiredHome 78:faf49c381591 2713 point_t pTest[3] =
WiredHome 78:faf49c381591 2714 { { 50, 50 }, {450, 150}, {225,250} };
WiredHome 78:faf49c381591 2715 point_t pSample[3];
WiredHome 78:faf49c381591 2716 for (int i=0; i<3; i++) {
WiredHome 78:faf49c381591 2717 display.foreground(Blue);
WiredHome 78:faf49c381591 2718 display.printf(" (%3d,%3d) => ", pTest[i].x, pTest[i].y);
WiredHome 78:faf49c381591 2719 display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, White);
WiredHome 78:faf49c381591 2720 display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, White);
WiredHome 79:544eb4964795 2721 while (!display.TouchPanelA2DFiltered(&x, &y))
WiredHome 78:faf49c381591 2722 wait_ms(20);
WiredHome 78:faf49c381591 2723 pSample[i].x = x;
WiredHome 78:faf49c381591 2724 pSample[i].y = y;
WiredHome 78:faf49c381591 2725 display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, Black);
WiredHome 78:faf49c381591 2726 display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, Black);
WiredHome 78:faf49c381591 2727 display.foreground(Blue);
WiredHome 78:faf49c381591 2728 display.printf(" (%4d,%4d)\r\n", x,y);
WiredHome 79:544eb4964795 2729 while (display.TouchPanelA2DFiltered(&x, &y))
WiredHome 78:faf49c381591 2730 wait_ms(20);
WiredHome 78:faf49c381591 2731 wait(2);
WiredHome 78:faf49c381591 2732 }
WiredHome 81:01da2e34283d 2733 display.TouchPanelComputeCalibration(pTest, pSample, &calmatrix);
WiredHome 78:faf49c381591 2734 display.printf(" Writing calibration to tpcal.cfg\r\n");
WiredHome 78:faf49c381591 2735 FILE * fh = fopen("/local/tpcal.cfg", "wb");
WiredHome 78:faf49c381591 2736 if (fh) {
WiredHome 78:faf49c381591 2737 fwrite(&calmatrix, sizeof(calmatrix), 1, fh);
WiredHome 78:faf49c381591 2738 fclose(fh);
WiredHome 78:faf49c381591 2739 }
WiredHome 78:faf49c381591 2740 display.printf(" Calibration is complete.");
WiredHome 78:faf49c381591 2741 } else if (c == 'r') {
WiredHome 78:faf49c381591 2742 display.printf(" Reading calibration from tpcal.cfg\r\n");
WiredHome 78:faf49c381591 2743 FILE * fh = fopen("/local/tpcal.cfg", "rb");
WiredHome 78:faf49c381591 2744 if (fh) {
WiredHome 78:faf49c381591 2745 fread(&calmatrix, sizeof(calmatrix), 1, fh);
WiredHome 78:faf49c381591 2746 fclose(fh);
WiredHome 78:faf49c381591 2747 }
WiredHome 78:faf49c381591 2748 display.printf(" Calibration is complete.");
WiredHome 78:faf49c381591 2749 display.TouchPanelSetMatrix(&calmatrix);
WiredHome 77:9206c13aa527 2750 }
WiredHome 77:9206c13aa527 2751 t.start();
WiredHome 77:9206c13aa527 2752 do {
WiredHome 77:9206c13aa527 2753 point_t point = {0, 0};
WiredHome 79:544eb4964795 2754 if (display.TouchPanelReadable(&point)) {
WiredHome 77:9206c13aa527 2755 display.pixel(point.x, point.y, Red);
WiredHome 77:9206c13aa527 2756 }
WiredHome 77:9206c13aa527 2757 } while (t.read_ms() < 30000);
WiredHome 77:9206c13aa527 2758 pc.printf(">");
WiredHome 77:9206c13aa527 2759 }
WiredHome 77:9206c13aa527 2760
WiredHome 77:9206c13aa527 2761
WiredHome 41:2956a0a221e5 2762 void SpeedTest(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 2763 {
WiredHome 41:2956a0a221e5 2764 Timer t;
WiredHome 41:2956a0a221e5 2765 SuppressSlowStuff = true;
WiredHome 41:2956a0a221e5 2766 pc.printf("\r\nSpeedTest disables delays, runs tests, reports overall time.\r\n");
WiredHome 41:2956a0a221e5 2767 t.start();
WiredHome 41:2956a0a221e5 2768 // do stuff fast
WiredHome 41:2956a0a221e5 2769 TextCursorTest(display, pc);
WiredHome 49:c5182231d1b9 2770 TextWrapTest(display, pc);
WiredHome 41:2956a0a221e5 2771 BacklightTest(display, pc, 0);
WiredHome 41:2956a0a221e5 2772 BacklightTest2(display, pc);
WiredHome 41:2956a0a221e5 2773 ExternalFontTest(display, pc);
WiredHome 41:2956a0a221e5 2774 DOSColorTest(display, pc);
WiredHome 41:2956a0a221e5 2775 WebColorTest(display, pc);
WiredHome 41:2956a0a221e5 2776 PixelTest(display, pc);
WiredHome 41:2956a0a221e5 2777 LineTest(display, pc);
WiredHome 41:2956a0a221e5 2778 RectangleTest(display, pc);
WiredHome 41:2956a0a221e5 2779 RoundRectTest(display, pc);
WiredHome 41:2956a0a221e5 2780 TriangleTest(display, pc);
WiredHome 41:2956a0a221e5 2781 CircleTest(display, pc);
WiredHome 41:2956a0a221e5 2782 EllipseTest(display, pc);
WiredHome 44:207594dece70 2783 LayerTest(display, pc);
WiredHome 41:2956a0a221e5 2784 //TestGraphicsBitmap(display, pc);
WiredHome 41:2956a0a221e5 2785 pc.printf("SpeedTest completed in %d msec\r\n", t.read_ms());
WiredHome 73:f22a18707b5e 2786 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 2787 display.ReportPerformance(pc);
WiredHome 73:f22a18707b5e 2788 #endif
WiredHome 41:2956a0a221e5 2789 SuppressSlowStuff = false;
WiredHome 41:2956a0a221e5 2790 }
WiredHome 41:2956a0a221e5 2791
WiredHome 44:207594dece70 2792
WiredHome 41:2956a0a221e5 2793 void PrintScreen(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 2794 {
WiredHome 41:2956a0a221e5 2795 if (!SuppressSlowStuff)
WiredHome 73:f22a18707b5e 2796 pc.printf("PrintScreen\r\n");
WiredHome 41:2956a0a221e5 2797 display.PrintScreen( 0,0, 480,272, "/local/Capture.bmp");
WiredHome 41:2956a0a221e5 2798 }
WiredHome 41:2956a0a221e5 2799
WiredHome 44:207594dece70 2800
WiredHome 23:a50ded45dbaf 2801 void RunTestSet(RA8875 & lcd, Serial & pc)
WiredHome 23:a50ded45dbaf 2802 {
WiredHome 23:a50ded45dbaf 2803 int q = 0;
WiredHome 23:a50ded45dbaf 2804 int automode = 0;
WiredHome 49:c5182231d1b9 2805 const unsigned char modelist[] = "BDWtGLlFROTPCEbw"; // auto-test in this order.
WiredHome 23:a50ded45dbaf 2806
WiredHome 23:a50ded45dbaf 2807 while(1) {
WiredHome 23:a50ded45dbaf 2808 pc.printf("\r\n"
WiredHome 41:2956a0a221e5 2809 "B - Backlight up b - backlight dim\r\n"
WiredHome 41:2956a0a221e5 2810 "D - DOS Colors W - Web Colors\r\n"
WiredHome 41:2956a0a221e5 2811 "t - text cursor G - Graphics Bitmap\r\n"
WiredHome 41:2956a0a221e5 2812 "L - Lines F - external Font\r\n"
WiredHome 41:2956a0a221e5 2813 "R - Rectangles O - rOund rectangles\r\n"
WiredHome 41:2956a0a221e5 2814 "T - Triangles P - Pixels \r\n"
WiredHome 41:2956a0a221e5 2815 "C - Circles E - Ellipses\r\n"
WiredHome 41:2956a0a221e5 2816 "A - Auto Test mode S - Speed Test\r\n"
WiredHome 77:9206c13aa527 2817 "K - Keypad Test s - touch screen test\r\n"
WiredHome 41:2956a0a221e5 2818 "p - print screen r - reset \r\n"
WiredHome 49:c5182231d1b9 2819 "l - layer test w - wrapping text \r\n"
WiredHome 73:f22a18707b5e 2820 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 2821 "0 - clear performance 1 - report performance\r\n"
WiredHome 73:f22a18707b5e 2822 #endif
WiredHome 23:a50ded45dbaf 2823 "> ");
WiredHome 23:a50ded45dbaf 2824 if (automode == -1 || pc.readable()) {
WiredHome 23:a50ded45dbaf 2825 automode = -1;
WiredHome 37:f19b7e7449dc 2826 q = pc.getc();
WiredHome 37:f19b7e7449dc 2827 while (pc.readable())
WiredHome 37:f19b7e7449dc 2828 pc.getc();
WiredHome 23:a50ded45dbaf 2829 } else if (automode >= 0) {
WiredHome 23:a50ded45dbaf 2830 q = modelist[automode];
WiredHome 23:a50ded45dbaf 2831 }
WiredHome 23:a50ded45dbaf 2832 switch(q) {
WiredHome 73:f22a18707b5e 2833 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 2834 case '0':
WiredHome 41:2956a0a221e5 2835 lcd.ClearPerformance();
WiredHome 41:2956a0a221e5 2836 break;
WiredHome 41:2956a0a221e5 2837 case '1':
WiredHome 41:2956a0a221e5 2838 lcd.ReportPerformance(pc);
WiredHome 41:2956a0a221e5 2839 break;
WiredHome 73:f22a18707b5e 2840 #endif
WiredHome 23:a50ded45dbaf 2841 case 'A':
WiredHome 23:a50ded45dbaf 2842 automode = 0;
WiredHome 23:a50ded45dbaf 2843 break;
WiredHome 23:a50ded45dbaf 2844 case 'B':
WiredHome 41:2956a0a221e5 2845 BacklightTest(lcd, pc, 2);
WiredHome 23:a50ded45dbaf 2846 break;
WiredHome 23:a50ded45dbaf 2847 case 'b':
WiredHome 23:a50ded45dbaf 2848 BacklightTest2(lcd, pc);
WiredHome 23:a50ded45dbaf 2849 break;
WiredHome 23:a50ded45dbaf 2850 case 'D':
WiredHome 23:a50ded45dbaf 2851 DOSColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2852 break;
WiredHome 75:ca78388cfd77 2853 case 'K':
WiredHome 75:ca78388cfd77 2854 KeyPadTest(lcd, pc);
WiredHome 75:ca78388cfd77 2855 break;
WiredHome 23:a50ded45dbaf 2856 case 'W':
WiredHome 23:a50ded45dbaf 2857 WebColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2858 break;
WiredHome 23:a50ded45dbaf 2859 case 't':
WiredHome 23:a50ded45dbaf 2860 TextCursorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2861 break;
WiredHome 49:c5182231d1b9 2862 case 'w':
WiredHome 49:c5182231d1b9 2863 TextWrapTest(lcd, pc);
WiredHome 49:c5182231d1b9 2864 break;
WiredHome 23:a50ded45dbaf 2865 case 'F':
WiredHome 23:a50ded45dbaf 2866 ExternalFontTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2867 break;
WiredHome 23:a50ded45dbaf 2868 case 'L':
WiredHome 23:a50ded45dbaf 2869 LineTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2870 break;
WiredHome 44:207594dece70 2871 case 'l':
WiredHome 44:207594dece70 2872 LayerTest(lcd, pc);
WiredHome 44:207594dece70 2873 break;
WiredHome 23:a50ded45dbaf 2874 case 'R':
WiredHome 23:a50ded45dbaf 2875 RectangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2876 break;
WiredHome 23:a50ded45dbaf 2877 case 'O':
WiredHome 23:a50ded45dbaf 2878 RoundRectTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2879 break;
WiredHome 41:2956a0a221e5 2880 case 'p':
WiredHome 41:2956a0a221e5 2881 PrintScreen(lcd, pc);
WiredHome 41:2956a0a221e5 2882 break;
WiredHome 41:2956a0a221e5 2883 case 'S':
WiredHome 41:2956a0a221e5 2884 SpeedTest(lcd, pc);
WiredHome 41:2956a0a221e5 2885 break;
WiredHome 77:9206c13aa527 2886 case 's':
WiredHome 77:9206c13aa527 2887 TouchPanelTest(lcd, pc);
WiredHome 77:9206c13aa527 2888 break;
WiredHome 23:a50ded45dbaf 2889 case 'T':
WiredHome 23:a50ded45dbaf 2890 TriangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2891 break;
WiredHome 37:f19b7e7449dc 2892 case 'P':
WiredHome 37:f19b7e7449dc 2893 PixelTest(lcd, pc);
WiredHome 37:f19b7e7449dc 2894 break;
WiredHome 37:f19b7e7449dc 2895 case 'G':
WiredHome 37:f19b7e7449dc 2896 TestGraphicsBitmap(lcd, pc);
WiredHome 37:f19b7e7449dc 2897 break;
WiredHome 23:a50ded45dbaf 2898 case 'C':
WiredHome 23:a50ded45dbaf 2899 CircleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2900 break;
WiredHome 23:a50ded45dbaf 2901 case 'E':
WiredHome 23:a50ded45dbaf 2902 EllipseTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2903 break;
WiredHome 23:a50ded45dbaf 2904 case 'r':
WiredHome 23:a50ded45dbaf 2905 pc.printf("Resetting ...\r\n");
WiredHome 23:a50ded45dbaf 2906 wait_ms(20);
WiredHome 23:a50ded45dbaf 2907 mbed_reset();
WiredHome 23:a50ded45dbaf 2908 break;
WiredHome 75:ca78388cfd77 2909 case ' ':
WiredHome 75:ca78388cfd77 2910 break;
WiredHome 23:a50ded45dbaf 2911 default:
WiredHome 23:a50ded45dbaf 2912 printf("huh?\n");
WiredHome 23:a50ded45dbaf 2913 break;
WiredHome 23:a50ded45dbaf 2914 }
WiredHome 23:a50ded45dbaf 2915 if (automode >= 0) {
WiredHome 23:a50ded45dbaf 2916 automode++;
WiredHome 23:a50ded45dbaf 2917 if (automode >= sizeof(modelist))
WiredHome 23:a50ded45dbaf 2918 automode = 0;
WiredHome 23:a50ded45dbaf 2919 wait_ms(2000);
WiredHome 23:a50ded45dbaf 2920 }
WiredHome 23:a50ded45dbaf 2921 wait_ms(200);
WiredHome 23:a50ded45dbaf 2922 }
WiredHome 23:a50ded45dbaf 2923 }
WiredHome 23:a50ded45dbaf 2924
WiredHome 79:544eb4964795 2925 #endif // TESTENABLE