Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Sun Jan 17 22:16:37 2016 +0000
Revision:
101:e0aad446094a
Parent:
100:0b084475d5a9
Child:
103:7e0464ca6c5c
External fonts now wrap correctly at the edge of the screen (right edge by moving down one line and to the left margin, and last row by wrapping to the top row.
; Altered the soft font <space> character; auto-generated fonts computed zero width.

Who changed what in which revision?

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