Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Sat Mar 05 16:20:11 2016 +0000
Revision:
107:f9ccffcb84f1
Parent:
106:c80828f5dea4
Child:
109:7b94f06f085b
Added rounded rectangle apis that accept rect_t instead of discreet x1,y1,x2,y2 values.

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