Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Sat Feb 27 18:40:35 2016 +0000
Revision:
105:4f116006ba1f
Parent:
103:7e0464ca6c5c
Child:
106:c80828f5dea4
Improved 8-bit color support, which permits dual-layer at higher resolutions.

Who changed what in which revision?

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