KSM edits to RA8875

Dependents:   Liz_Test_Code

Committer:
WiredHome
Date:
Thu Feb 14 12:34:52 2019 +0000
Revision:
164:76edd7d9cb68
Parent:
163:17526689a3ed
Child:
165:695c24cc5197
PrintScreen - 24-bit or 8-bit BMP format support. Improved documentation to the palette and the performance factors.

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