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