Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Sun Dec 28 21:50:28 2014 +0000
Revision:
81:01da2e34283d
Parent:
80:cc4fab58179c
Child:
82:f7d300f26540
Refactored constructor() and init().; Added rect_t as a rectangle type.; Added new rect() methods that use rect_t.; Added touch panel calibration (and some renamed touch* methods).

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