Updated standard library

Committer:
WiredHome
Date:
Sun Jul 28 00:21:15 2019 +0000
Revision:
180:4882e80cfcfe
Parent:
176:4ab96d33a8ec
new constructor for rect_t; much faster thick line drawing; additional debug diagnostics.

Who changed what in which revision?

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