KSM edits to RA8875

Dependents:   Liz_Test_Code

Committer:
WiredHome
Date:
Sun Feb 24 19:28:26 2019 +0000
Revision:
166:53fd4a876dac
Parent:
165:695c24cc5197
Child:
175:7be3a1fb7fc2
Some refactoring, but mostly to improve support for GSL1680 controller to extract the touch id.

Who changed what in which revision?

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