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