KSM edits to RA8875

Dependents:   Liz_Test_Code

Committer:
WiredHome
Date:
Sun Feb 24 00:40:00 2019 +0000
Revision:
165:695c24cc5197
Parent:
164:76edd7d9cb68
Child:
166:53fd4a876dac
Initial refactoring to add support for another Cap Sense touch controller - based on the GSL1680.

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