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