Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Mon Nov 30 11:58:32 2015 +0000
Revision:
97:03c509c3db18
Parent:
96:40b74dd3695b
Fixed comment - typo

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