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