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