Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Thu Jan 01 20:35:37 2015 +0000
Revision:
83:7bad0068cca0
Parent:
82:f7d300f26540
Child:
84:e102021864b5
Improve touch interface to automatically provide no_touch, touch, held, release, no_cal value.; Touch API return codes were modified to accommodate this.; Enhance some APIs with (point_t p) parameters.; Minor internal documentation improvement.

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