Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Sun Feb 07 23:18:01 2016 +0000
Revision:
103:7e0464ca6c5c
Parent:
101:e0aad446094a
Child:
105:4f116006ba1f
Added missing APIs for Get/SetTextCursor using point_t.; Fixed a defect in touch; if no point was requested, just polling for touch-state, it would return the no calibration value during a touch.

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