Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Sat Dec 19 15:55:09 2015 +0000
Revision:
100:0b084475d5a9
Parent:
98:ecebed9b80b2
Child:
101:e0aad446094a
Corrected a defect where the portrait mode might be incorrectly inferred - then limits many commands to partial screen.; Remove set_font(). Use SelectUserFont() instead.; Removed unnecessary code in several places (redundant work).

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