Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Sat Feb 27 22:27:49 2016 +0000
Revision:
106:c80828f5dea4
Parent:
105:4f116006ba1f
Child:
107:f9ccffcb84f1
Improved support for 8-bit color, for pixel drawing, RenderImageFile and PrintScreen.

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