Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Wed Jan 28 12:21:11 2015 +0000
Revision:
90:d113d71ae4f0
Parent:
89:04575562c961
Child:
91:ca5f829e6d27
persist screen width/height in the private data so that it does not have the burn the cycles to query the hardware on every need.

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