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