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