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