This is the David Smart RA8875 Library with mods for working with FRDM-K64F

Committer:
WiredHome
Date:
Fri Aug 02 02:12:26 2019 +0000
Revision:
181:0032d1b8f5d4
Parent:
178:ae472eb22740
Child:
182:8832d03a2a29
A bit of experimenting on rotation.

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 178:ae472eb22740 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 178:ae472eb22740 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 178:ae472eb22740 227 INFO("m_i2c = %p", m_i2c);
WiredHome 178:ae472eb22740 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 181:0032d1b8f5d4 250 #elif (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 127)
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 178:ae472eb22740 255 m_irq->enable_irq();
WiredHome 124:1690a7ae871c 256 TouchPanelInit();
WiredHome 178:ae472eb22740 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 178:ae472eb22740 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 181:0032d1b8f5d4 298 #elif (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 127)
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 178:ae472eb22740 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 178:ae472eb22740 406 if (useTouchPanel == TP_RES)
WiredHome 178:ae472eb22740 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 178:ae472eb22740 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 181:0032d1b8f5d4 1113 RetCode_t r;
WiredHome 84:e102021864b5 1114
WiredHome 181:0032d1b8f5d4 1115 screen_orientation = angle;
WiredHome 84:e102021864b5 1116 fncr1Val &= ~0x10; // remove the old direction bit
WiredHome 84:e102021864b5 1117 dpcrVal &= ~0x0C; // remove the old scan direction bits
WiredHome 84:e102021864b5 1118 switch (angle) {
WiredHome 84:e102021864b5 1119 case RA8875::normal:
WiredHome 84:e102021864b5 1120 //fncr1Val |= 0x10;
WiredHome 84:e102021864b5 1121 //dpcrVal |= 0x00;
WiredHome 90:d113d71ae4f0 1122 portraitmode = false;
WiredHome 84:e102021864b5 1123 break;
WiredHome 84:e102021864b5 1124 case RA8875::rotate_90:
WiredHome 84:e102021864b5 1125 fncr1Val |= 0x10;
WiredHome 84:e102021864b5 1126 dpcrVal |= 0x08;
WiredHome 90:d113d71ae4f0 1127 portraitmode = true;
WiredHome 84:e102021864b5 1128 break;
WiredHome 84:e102021864b5 1129 case RA8875::rotate_180:
WiredHome 84:e102021864b5 1130 //fncr1Val |= 0x00;
WiredHome 84:e102021864b5 1131 dpcrVal |= 0x0C;
WiredHome 90:d113d71ae4f0 1132 portraitmode = false;
WiredHome 84:e102021864b5 1133 break;
WiredHome 84:e102021864b5 1134 case RA8875::rotate_270:
WiredHome 84:e102021864b5 1135 fncr1Val |= 0x10;
WiredHome 84:e102021864b5 1136 dpcrVal |= 0x04;
WiredHome 90:d113d71ae4f0 1137 portraitmode = true;
WiredHome 84:e102021864b5 1138 break;
WiredHome 84:e102021864b5 1139 default:
WiredHome 84:e102021864b5 1140 return bad_parameter;
WiredHome 84:e102021864b5 1141 }
WiredHome 100:0b084475d5a9 1142 INFO("Orientation: %d, %d", angle, portraitmode);
WiredHome 181:0032d1b8f5d4 1143 r = WriteCommand(RA8875_FNCR1, fncr1Val);
WiredHome 181:0032d1b8f5d4 1144 r = WriteCommand(RA8875_DPCR, dpcrVal);
WiredHome 181:0032d1b8f5d4 1145 return r;
WiredHome 84:e102021864b5 1146 }
WiredHome 84:e102021864b5 1147
WiredHome 84:e102021864b5 1148
WiredHome 19:3f82c1161fd2 1149 RetCode_t RA8875::SetTextFontControl(fill_t fillit,
WiredHome 73:f22a18707b5e 1150 RA8875::HorizontalScale hScale,
WiredHome 73:f22a18707b5e 1151 RA8875::VerticalScale vScale,
WiredHome 73:f22a18707b5e 1152 RA8875::alignment_t alignment)
WiredHome 19:3f82c1161fd2 1153 {
WiredHome 73:f22a18707b5e 1154 if (hScale >= 1 && hScale <= 4 &&
WiredHome 73:f22a18707b5e 1155 vScale >= 1 && vScale <= 4) {
WiredHome 84:e102021864b5 1156 uint8_t fncr1Val = ReadCommand(0x22);
WiredHome 84:e102021864b5 1157
WiredHome 98:ecebed9b80b2 1158 fncr1Val &= ~0x10; // do not disturb the rotate flag
WiredHome 19:3f82c1161fd2 1159 if (alignment == align_full)
WiredHome 84:e102021864b5 1160 fncr1Val |= 0x80;
WiredHome 19:3f82c1161fd2 1161 if (fillit == NOFILL)
WiredHome 84:e102021864b5 1162 fncr1Val |= 0x40;
WiredHome 84:e102021864b5 1163 fncr1Val |= ((hScale - 1) << 2);
WiredHome 84:e102021864b5 1164 fncr1Val |= ((vScale - 1) << 0);
WiredHome 175:7be3a1fb7fc2 1165 return WriteCommand(RA8875_FNCR1, fncr1Val);
WiredHome 19:3f82c1161fd2 1166 } else {
WiredHome 19:3f82c1161fd2 1167 return bad_parameter;
WiredHome 19:3f82c1161fd2 1168 }
WiredHome 19:3f82c1161fd2 1169 }
WiredHome 19:3f82c1161fd2 1170
WiredHome 44:207594dece70 1171
WiredHome 19:3f82c1161fd2 1172 RetCode_t RA8875::SetTextFontSize(RA8875::HorizontalScale hScale, RA8875::VerticalScale vScale)
WiredHome 19:3f82c1161fd2 1173 {
WiredHome 19:3f82c1161fd2 1174 unsigned char reg = ReadCommand(0x22);
WiredHome 73:f22a18707b5e 1175
WiredHome 40:04aa280dfa39 1176 if (vScale == -1)
WiredHome 40:04aa280dfa39 1177 vScale = hScale;
WiredHome 19:3f82c1161fd2 1178 if (hScale >= 1 && hScale <= 4 && vScale >= 1 && vScale <= 4) {
WiredHome 153:8a85efb3eb71 1179 fontScaleX = hScale; // save for use with a Soft Font
WiredHome 153:8a85efb3eb71 1180 fontScaleY = vScale;
WiredHome 19:3f82c1161fd2 1181 reg &= 0xF0; // keep the high nibble as is.
WiredHome 19:3f82c1161fd2 1182 reg |= ((hScale - 1) << 2);
WiredHome 19:3f82c1161fd2 1183 reg |= ((vScale - 1) << 0);
WiredHome 175:7be3a1fb7fc2 1184 WriteCommand(RA8875_FNCR1, reg);
WiredHome 19:3f82c1161fd2 1185 return noerror;
WiredHome 19:3f82c1161fd2 1186 } else {
WiredHome 19:3f82c1161fd2 1187 return bad_parameter;
WiredHome 19:3f82c1161fd2 1188 }
WiredHome 19:3f82c1161fd2 1189 }
WiredHome 19:3f82c1161fd2 1190
WiredHome 127:db7f2c704693 1191 RetCode_t RA8875::GetTextFontSize(RA8875::HorizontalScale * hScale, RA8875::VerticalScale * vScale)
WiredHome 127:db7f2c704693 1192 {
WiredHome 127:db7f2c704693 1193 unsigned char reg = ReadCommand(0x22);
WiredHome 127:db7f2c704693 1194
WiredHome 127:db7f2c704693 1195 if (hScale)
WiredHome 127:db7f2c704693 1196 *hScale = 1 + (reg >> 2) & 0x03;
WiredHome 127:db7f2c704693 1197 if (vScale)
WiredHome 127:db7f2c704693 1198 *vScale = 1 + reg & 0x03;
WiredHome 127:db7f2c704693 1199 return noerror;
WiredHome 127:db7f2c704693 1200 }
WiredHome 44:207594dece70 1201
WiredHome 19:3f82c1161fd2 1202 int RA8875::_putc(int c)
WiredHome 19:3f82c1161fd2 1203 {
WiredHome 29:422616aa04bd 1204 if (font == NULL) {
WiredHome 29:422616aa04bd 1205 return _internal_putc(c);
WiredHome 29:422616aa04bd 1206 } else {
WiredHome 29:422616aa04bd 1207 return _external_putc(c);
WiredHome 29:422616aa04bd 1208 }
WiredHome 29:422616aa04bd 1209 }
WiredHome 29:422616aa04bd 1210
WiredHome 44:207594dece70 1211
WiredHome 101:e0aad446094a 1212
WiredHome 101:e0aad446094a 1213 // Questions to ponder -
WiredHome 101:e0aad446094a 1214 // - if we choose to wrap to the next line, because the character won't fit on the current line,
WiredHome 101:e0aad446094a 1215 // should it erase the space to the width of the screen (in case there is leftover junk there)?
WiredHome 101:e0aad446094a 1216 // - it currently wraps from the bottom of the screen back to the top. I have pondered what
WiredHome 101:e0aad446094a 1217 // it might take to scroll the screen - but haven't thought hard enough about it.
WiredHome 101:e0aad446094a 1218 //
WiredHome 29:422616aa04bd 1219 int RA8875::_external_putc(int c)
WiredHome 29:422616aa04bd 1220 {
WiredHome 19:3f82c1161fd2 1221 if (c) {
WiredHome 19:3f82c1161fd2 1222 if (c == '\r') {
WiredHome 111:efe436c43aba 1223 cursor_x = windowrect.p1.x;
WiredHome 29:422616aa04bd 1224 } else if (c == '\n') {
WiredHome 98:ecebed9b80b2 1225 cursor_y += extFontHeight;
WiredHome 29:422616aa04bd 1226 } else {
WiredHome 109:7b94f06f085b 1227 dim_t charWidth, charHeight;
WiredHome 101:e0aad446094a 1228 const uint8_t * charRecord;
WiredHome 101:e0aad446094a 1229
WiredHome 101:e0aad446094a 1230 charRecord = getCharMetrics(c, &charWidth, &charHeight);
WiredHome 101:e0aad446094a 1231 //int advance = charwidth(c);
WiredHome 111:efe436c43aba 1232 INFO("(%d,%d) - (%d,%d):(%d,%d), charWidth: %d '%c", cursor_x, cursor_y,
WiredHome 111:efe436c43aba 1233 windowrect.p1.x, windowrect.p1.y, windowrect.p2.x, windowrect.p2.y,
WiredHome 111:efe436c43aba 1234 charWidth, c);
WiredHome 101:e0aad446094a 1235 if (charRecord) {
WiredHome 101:e0aad446094a 1236 //cursor_x += advance;
WiredHome 111:efe436c43aba 1237 if (cursor_x + charWidth >= windowrect.p2.x) {
WiredHome 111:efe436c43aba 1238 cursor_x = windowrect.p1.x;
WiredHome 101:e0aad446094a 1239 cursor_y += charHeight;
WiredHome 29:422616aa04bd 1240 }
WiredHome 111:efe436c43aba 1241 if (cursor_y + charHeight >= windowrect.p2.y) {
WiredHome 111:efe436c43aba 1242 cursor_y = windowrect.p1.y; // @todo Should it scroll?
WiredHome 101:e0aad446094a 1243 }
WiredHome 101:e0aad446094a 1244 (void)character(cursor_x, cursor_y, c);
WiredHome 153:8a85efb3eb71 1245 cursor_x += charWidth * fontScaleX;
WiredHome 29:422616aa04bd 1246 }
WiredHome 29:422616aa04bd 1247 }
WiredHome 29:422616aa04bd 1248 }
WiredHome 29:422616aa04bd 1249 return c;
WiredHome 29:422616aa04bd 1250 }
WiredHome 29:422616aa04bd 1251
WiredHome 44:207594dece70 1252
WiredHome 29:422616aa04bd 1253 int RA8875::_internal_putc(int c)
WiredHome 29:422616aa04bd 1254 {
WiredHome 29:422616aa04bd 1255 if (c) {
WiredHome 29:422616aa04bd 1256 unsigned char mwcr0;
WiredHome 73:f22a18707b5e 1257
WiredHome 29:422616aa04bd 1258 mwcr0 = ReadCommand(0x40);
WiredHome 29:422616aa04bd 1259 if ((mwcr0 & 0x80) == 0x00) {
WiredHome 175:7be3a1fb7fc2 1260 WriteCommand(RA8875_MWCR0, 0x80 | mwcr0); // Put in Text mode if not already
WiredHome 29:422616aa04bd 1261 }
WiredHome 29:422616aa04bd 1262 if (c == '\r') {
WiredHome 37:f19b7e7449dc 1263 loc_t x;
WiredHome 19:3f82c1161fd2 1264 x = ReadCommand(0x30) | (ReadCommand(0x31) << 8); // Left edge of active window
WiredHome 175:7be3a1fb7fc2 1265 WriteCommandW(RA8875_FCURXL, x);
WiredHome 19:3f82c1161fd2 1266 } else if (c == '\n') {
WiredHome 37:f19b7e7449dc 1267 loc_t y;
WiredHome 19:3f82c1161fd2 1268 y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); // current y location
WiredHome 19:3f82c1161fd2 1269 y += fontheight();
WiredHome 47:d96a09269f91 1270 if (y >= height()) // @TODO after bottom of active window, then scroll window?
WiredHome 19:3f82c1161fd2 1271 y = 0;
WiredHome 175:7be3a1fb7fc2 1272 WriteCommandW(RA8875_FCURYL, y);
WiredHome 19:3f82c1161fd2 1273 } else {
WiredHome 175:7be3a1fb7fc2 1274 WriteCommand(RA8875_MRWC); // RA8875 Internal Fonts
WiredHome 79:544eb4964795 1275 _select(true);
WiredHome 29:422616aa04bd 1276 WriteData(c);
WiredHome 66:468a11f05580 1277 _WaitWhileBusy(0x80);
WiredHome 79:544eb4964795 1278 _select(false);
WiredHome 19:3f82c1161fd2 1279 }
WiredHome 19:3f82c1161fd2 1280 }
WiredHome 19:3f82c1161fd2 1281 return c;
WiredHome 19:3f82c1161fd2 1282 }
WiredHome 19:3f82c1161fd2 1283
WiredHome 44:207594dece70 1284
WiredHome 32:0e4f2ae512e2 1285 RetCode_t RA8875::_StartGraphicsStream(void)
WiredHome 32:0e4f2ae512e2 1286 {
WiredHome 175:7be3a1fb7fc2 1287 WriteCommand(RA8875_MWCR0,0x00); // Graphics write mode
WiredHome 175:7be3a1fb7fc2 1288 WriteCommand(RA8875_MRWC); // Prepare for streaming data
WiredHome 32:0e4f2ae512e2 1289 return noerror;
WiredHome 32:0e4f2ae512e2 1290 }
WiredHome 32:0e4f2ae512e2 1291
WiredHome 44:207594dece70 1292
WiredHome 32:0e4f2ae512e2 1293 RetCode_t RA8875::_EndGraphicsStream(void)
WiredHome 32:0e4f2ae512e2 1294 {
WiredHome 32:0e4f2ae512e2 1295 return noerror;
WiredHome 32:0e4f2ae512e2 1296 }
WiredHome 32:0e4f2ae512e2 1297
WiredHome 44:207594dece70 1298
WiredHome 55:dfbabef7003e 1299 RetCode_t RA8875::_putp(color_t pixel)
WiredHome 32:0e4f2ae512e2 1300 {
WiredHome 38:38d503b4fad6 1301 WriteDataW((pixel>>8) | (pixel<<8));
WiredHome 73:f22a18707b5e 1302 return noerror;
WiredHome 32:0e4f2ae512e2 1303 }
WiredHome 29:422616aa04bd 1304
WiredHome 44:207594dece70 1305
WiredHome 37:f19b7e7449dc 1306 void RA8875::puts(loc_t x, loc_t y, const char * string)
WiredHome 19:3f82c1161fd2 1307 {
WiredHome 19:3f82c1161fd2 1308 SetTextCursor(x,y);
WiredHome 19:3f82c1161fd2 1309 puts(string);
WiredHome 19:3f82c1161fd2 1310 }
WiredHome 19:3f82c1161fd2 1311
WiredHome 44:207594dece70 1312
WiredHome 19:3f82c1161fd2 1313 void RA8875::puts(const char * string)
WiredHome 19:3f82c1161fd2 1314 {
WiredHome 37:f19b7e7449dc 1315 if (font == NULL) {
WiredHome 175:7be3a1fb7fc2 1316 WriteCommand(RA8875_MWCR0,0x80); // Put in Text mode if internal font
WiredHome 37:f19b7e7449dc 1317 }
WiredHome 19:3f82c1161fd2 1318 if (*string != '\0') {
WiredHome 29:422616aa04bd 1319 while (*string) { // @TODO calling individual _putc is slower... optimizations?
WiredHome 19:3f82c1161fd2 1320 _putc(*string++);
WiredHome 19:3f82c1161fd2 1321 }
WiredHome 19:3f82c1161fd2 1322 }
WiredHome 19:3f82c1161fd2 1323 }
WiredHome 19:3f82c1161fd2 1324
WiredHome 44:207594dece70 1325
WiredHome 37:f19b7e7449dc 1326 RetCode_t RA8875::SetGraphicsCursor(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 1327 {
WiredHome 175:7be3a1fb7fc2 1328 WriteCommandW(RA8875_CURH0, x);
WiredHome 175:7be3a1fb7fc2 1329 WriteCommandW(RA8875_CURV0, y);
WiredHome 19:3f82c1161fd2 1330 return noerror;
WiredHome 19:3f82c1161fd2 1331 }
WiredHome 19:3f82c1161fd2 1332
WiredHome 136:224e03d5c31f 1333 RetCode_t RA8875::SetGraphicsCursor(point_t p)
WiredHome 136:224e03d5c31f 1334 {
WiredHome 136:224e03d5c31f 1335 return SetGraphicsCursor(p.x, p.y);
WiredHome 136:224e03d5c31f 1336 }
WiredHome 136:224e03d5c31f 1337
WiredHome 136:224e03d5c31f 1338 point_t RA8875::GetGraphicsCursor(void)
WiredHome 136:224e03d5c31f 1339 {
WiredHome 136:224e03d5c31f 1340 point_t p;
WiredHome 136:224e03d5c31f 1341
WiredHome 136:224e03d5c31f 1342 p.x = ReadCommandW(0x46);
WiredHome 136:224e03d5c31f 1343 p.y = ReadCommandW(0x48);
WiredHome 136:224e03d5c31f 1344 return p;
WiredHome 136:224e03d5c31f 1345 }
WiredHome 44:207594dece70 1346
WiredHome 41:2956a0a221e5 1347 RetCode_t RA8875::SetGraphicsCursorRead(loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1348 {
WiredHome 175:7be3a1fb7fc2 1349 WriteCommandW(RA8875_RCURH0, x);
WiredHome 175:7be3a1fb7fc2 1350 WriteCommandW(RA8875_RCURV0, y);
WiredHome 41:2956a0a221e5 1351 return noerror;
WiredHome 41:2956a0a221e5 1352 }
WiredHome 41:2956a0a221e5 1353
WiredHome 111:efe436c43aba 1354 RetCode_t RA8875::window(rect_t r)
WiredHome 111:efe436c43aba 1355 {
WiredHome 111:efe436c43aba 1356 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 1357 }
WiredHome 44:207594dece70 1358
WiredHome 37:f19b7e7449dc 1359 RetCode_t RA8875::window(loc_t x, loc_t y, dim_t width, dim_t height)
WiredHome 19:3f82c1161fd2 1360 {
WiredHome 111:efe436c43aba 1361 INFO("window(%d,%d,%d,%d)", x, y, width, height);
WiredHome 111:efe436c43aba 1362 if (width == (dim_t)-1)
WiredHome 111:efe436c43aba 1363 width = screenwidth - x;
WiredHome 111:efe436c43aba 1364 if (height == (dim_t)-1)
WiredHome 111:efe436c43aba 1365 height = screenheight - y;
WiredHome 111:efe436c43aba 1366 windowrect.p1.x = x;
WiredHome 111:efe436c43aba 1367 windowrect.p1.y = y;
WiredHome 111:efe436c43aba 1368 windowrect.p2.x = x + width - 1;
WiredHome 111:efe436c43aba 1369 windowrect.p2.y = y + height - 1;
WiredHome 37:f19b7e7449dc 1370 GraphicsDisplay::window(x,y, width,height);
WiredHome 175:7be3a1fb7fc2 1371 WriteCommandW(RA8875_HSAW0, x);
WiredHome 175:7be3a1fb7fc2 1372 WriteCommandW(RA8875_VSAW0, y);
WiredHome 175:7be3a1fb7fc2 1373 WriteCommandW(RA8875_HEAW0, (x+width-1));
WiredHome 175:7be3a1fb7fc2 1374 WriteCommandW(RA8875_VEAW0, (y+height-1));
WiredHome 111:efe436c43aba 1375 //SetTextCursor(x,y);
WiredHome 111:efe436c43aba 1376 //SetGraphicsCursor(x,y);
WiredHome 19:3f82c1161fd2 1377 return noerror;
WiredHome 19:3f82c1161fd2 1378 }
WiredHome 19:3f82c1161fd2 1379
WiredHome 44:207594dece70 1380
WiredHome 61:8f3153bf0baa 1381 RetCode_t RA8875::cls(uint16_t layers)
WiredHome 19:3f82c1161fd2 1382 {
WiredHome 61:8f3153bf0baa 1383 RetCode_t ret;
WiredHome 73:f22a18707b5e 1384
WiredHome 178:ae472eb22740 1385 INFO("cls()");
WiredHome 19:3f82c1161fd2 1386 PERFORMANCE_RESET;
WiredHome 61:8f3153bf0baa 1387 if (layers == 0) {
WiredHome 61:8f3153bf0baa 1388 ret = clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1389 } else if (layers > 3) {
WiredHome 61:8f3153bf0baa 1390 ret = bad_parameter;
WiredHome 61:8f3153bf0baa 1391 } else {
WiredHome 61:8f3153bf0baa 1392 uint16_t prevLayer = GetDrawingLayer();
WiredHome 61:8f3153bf0baa 1393 if (layers & 1) {
WiredHome 61:8f3153bf0baa 1394 SelectDrawingLayer(0);
WiredHome 61:8f3153bf0baa 1395 clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1396 }
WiredHome 61:8f3153bf0baa 1397 if (layers & 2) {
WiredHome 61:8f3153bf0baa 1398 SelectDrawingLayer(1);
WiredHome 61:8f3153bf0baa 1399 clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1400 }
WiredHome 142:6e9bff59878a 1401 SelectDrawingLayer(prevLayer);
WiredHome 61:8f3153bf0baa 1402 }
WiredHome 135:af519fe4ba91 1403 ret = SetTextCursor(0,0);
WiredHome 178:ae472eb22740 1404 //ret = locate(0,0);
WiredHome 19:3f82c1161fd2 1405 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 61:8f3153bf0baa 1406 return ret;
WiredHome 19:3f82c1161fd2 1407 }
WiredHome 19:3f82c1161fd2 1408
WiredHome 44:207594dece70 1409
WiredHome 19:3f82c1161fd2 1410 RetCode_t RA8875::clsw(RA8875::Region_t region)
WiredHome 19:3f82c1161fd2 1411 {
WiredHome 178:ae472eb22740 1412 INFO("clsw()");
WiredHome 19:3f82c1161fd2 1413 PERFORMANCE_RESET;
WiredHome 175:7be3a1fb7fc2 1414 WriteCommand(RA8875_MCLR, (region == ACTIVEWINDOW) ? 0xC0 : 0x80);
WiredHome 131:5bd6ba2ee4a1 1415 if (!_WaitWhileReg(0x8E, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1416 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 131:5bd6ba2ee4a1 1417 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1418 }
WiredHome 19:3f82c1161fd2 1419 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 19:3f82c1161fd2 1420 return noerror;
WiredHome 19:3f82c1161fd2 1421 }
WiredHome 19:3f82c1161fd2 1422
WiredHome 44:207594dece70 1423
WiredHome 87:ee2240581aa7 1424 RetCode_t RA8875::pixel(point_t p, color_t color)
WiredHome 87:ee2240581aa7 1425 {
WiredHome 87:ee2240581aa7 1426 return pixel(p.x, p.y, color);
WiredHome 87:ee2240581aa7 1427 }
WiredHome 87:ee2240581aa7 1428
WiredHome 87:ee2240581aa7 1429 RetCode_t RA8875::pixel(point_t p)
WiredHome 87:ee2240581aa7 1430 {
WiredHome 87:ee2240581aa7 1431 return pixel(p.x, p.y);
WiredHome 87:ee2240581aa7 1432 }
WiredHome 87:ee2240581aa7 1433
WiredHome 37:f19b7e7449dc 1434 RetCode_t RA8875::pixel(loc_t x, loc_t y, color_t color)
WiredHome 19:3f82c1161fd2 1435 {
WiredHome 62:ba5d33438fda 1436 RetCode_t ret;
WiredHome 73:f22a18707b5e 1437
WiredHome 62:ba5d33438fda 1438 PERFORMANCE_RESET;
WiredHome 62:ba5d33438fda 1439 ret = pixelStream(&color, 1, x,y);
WiredHome 62:ba5d33438fda 1440 REGISTERPERFORMANCE(PRF_DRAWPIXEL);
WiredHome 62:ba5d33438fda 1441 return ret;
WiredHome 19:3f82c1161fd2 1442 }
WiredHome 19:3f82c1161fd2 1443
WiredHome 44:207594dece70 1444
WiredHome 37:f19b7e7449dc 1445 RetCode_t RA8875::pixel(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 1446 {
WiredHome 19:3f82c1161fd2 1447 RetCode_t ret;
WiredHome 73:f22a18707b5e 1448
WiredHome 19:3f82c1161fd2 1449 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1450 color_t color = GetForeColor();
WiredHome 62:ba5d33438fda 1451 ret = pixelStream(&color, 1, x, y);
WiredHome 41:2956a0a221e5 1452 REGISTERPERFORMANCE(PRF_DRAWPIXEL);
WiredHome 19:3f82c1161fd2 1453 return ret;
WiredHome 19:3f82c1161fd2 1454 }
WiredHome 19:3f82c1161fd2 1455
WiredHome 44:207594dece70 1456
WiredHome 41:2956a0a221e5 1457 RetCode_t RA8875::pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1458 {
WiredHome 41:2956a0a221e5 1459 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 1460 SetGraphicsCursor(x, y);
WiredHome 109:7b94f06f085b 1461 _StartGraphicsStream();
WiredHome 79:544eb4964795 1462 _select(true);
WiredHome 79:544eb4964795 1463 _spiwrite(0x00); // Cmd: write data
WiredHome 41:2956a0a221e5 1464 while (count--) {
WiredHome 105:4f116006ba1f 1465 if (screenbpp == 16) {
WiredHome 105:4f116006ba1f 1466 _spiwrite(*p >> 8);
WiredHome 105:4f116006ba1f 1467 _spiwrite(*p & 0xFF);
WiredHome 105:4f116006ba1f 1468 } else {
WiredHome 105:4f116006ba1f 1469 _spiwrite(_cvt16to8(*p));
WiredHome 105:4f116006ba1f 1470 }
WiredHome 41:2956a0a221e5 1471 p++;
WiredHome 41:2956a0a221e5 1472 }
WiredHome 79:544eb4964795 1473 _select(false);
WiredHome 109:7b94f06f085b 1474 _EndGraphicsStream();
WiredHome 41:2956a0a221e5 1475 REGISTERPERFORMANCE(PRF_PIXELSTREAM);
WiredHome 41:2956a0a221e5 1476 return(noerror);
WiredHome 41:2956a0a221e5 1477 }
WiredHome 41:2956a0a221e5 1478
WiredHome 153:8a85efb3eb71 1479 // With a font scale X = 1, a pixel stream is "abcdefg..."
WiredHome 153:8a85efb3eb71 1480 // With a font scale X = 2, a pixel stream is "aabbccddeeffgg..."
WiredHome 153:8a85efb3eb71 1481 // With a font scale Y = 2, a pixel stream is "abcdefg..."
WiredHome 153:8a85efb3eb71 1482 // "abcdefg..."
WiredHome 153:8a85efb3eb71 1483 //
WiredHome 109:7b94f06f085b 1484 RetCode_t RA8875::booleanStream(loc_t x, loc_t y, dim_t w, dim_t h, const uint8_t * boolStream)
WiredHome 109:7b94f06f085b 1485 {
WiredHome 109:7b94f06f085b 1486 PERFORMANCE_RESET;
WiredHome 153:8a85efb3eb71 1487 const uint8_t * rowStream;
WiredHome 111:efe436c43aba 1488 rect_t restore = windowrect;
WiredHome 153:8a85efb3eb71 1489 window(x, y, w * fontScaleX, h * fontScaleY); // Scale from font scale factors
WiredHome 109:7b94f06f085b 1490 SetGraphicsCursor(x, y);
WiredHome 109:7b94f06f085b 1491 _StartGraphicsStream();
WiredHome 109:7b94f06f085b 1492 _select(true);
WiredHome 109:7b94f06f085b 1493 _spiwrite(0x00); // Cmd: write data
WiredHome 109:7b94f06f085b 1494 while (h--) {
WiredHome 153:8a85efb3eb71 1495 for (int dy=0; dy<fontScaleY; dy++) { // Vertical Font Scale Factor
WiredHome 153:8a85efb3eb71 1496 uint8_t pixels = w;
WiredHome 153:8a85efb3eb71 1497 uint8_t bitmask = 0x01;
WiredHome 153:8a85efb3eb71 1498 rowStream = boolStream;
WiredHome 153:8a85efb3eb71 1499 while (pixels) {
WiredHome 153:8a85efb3eb71 1500 uint8_t byte = *rowStream;
WiredHome 153:8a85efb3eb71 1501 //INFO("byte, mask: %02X, %02X", byte, bitmask);
WiredHome 153:8a85efb3eb71 1502 color_t c = (byte & bitmask) ? _foreground : _background;
WiredHome 153:8a85efb3eb71 1503
WiredHome 153:8a85efb3eb71 1504 for (int dx=0; dx<fontScaleX; dx++) { // Horizontal Font Scale Factor
WiredHome 153:8a85efb3eb71 1505 if (screenbpp == 16) {
WiredHome 153:8a85efb3eb71 1506 _spiwrite(c >> 8);
WiredHome 153:8a85efb3eb71 1507 _spiwrite(c & 0xFF);
WiredHome 153:8a85efb3eb71 1508 } else {
WiredHome 153:8a85efb3eb71 1509 _spiwrite(_cvt16to8(c));
WiredHome 153:8a85efb3eb71 1510 }
WiredHome 109:7b94f06f085b 1511 }
WiredHome 153:8a85efb3eb71 1512 bitmask <<= 1;
WiredHome 153:8a85efb3eb71 1513 if (pixels > 1 && bitmask == 0) {
WiredHome 153:8a85efb3eb71 1514 bitmask = 0x01;
WiredHome 153:8a85efb3eb71 1515 rowStream++;
WiredHome 153:8a85efb3eb71 1516 }
WiredHome 153:8a85efb3eb71 1517 pixels--;
WiredHome 109:7b94f06f085b 1518 }
WiredHome 109:7b94f06f085b 1519 }
WiredHome 153:8a85efb3eb71 1520 boolStream += (rowStream - boolStream + 1);
WiredHome 109:7b94f06f085b 1521 }
WiredHome 109:7b94f06f085b 1522 _select(false);
WiredHome 109:7b94f06f085b 1523 _EndGraphicsStream();
WiredHome 111:efe436c43aba 1524 window(restore);
WiredHome 109:7b94f06f085b 1525 REGISTERPERFORMANCE(PRF_BOOLSTREAM);
WiredHome 109:7b94f06f085b 1526 return(noerror);
WiredHome 109:7b94f06f085b 1527 }
WiredHome 44:207594dece70 1528
WiredHome 41:2956a0a221e5 1529 color_t RA8875::getPixel(loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1530 {
WiredHome 41:2956a0a221e5 1531 color_t pixel;
WiredHome 73:f22a18707b5e 1532
WiredHome 41:2956a0a221e5 1533 PERFORMANCE_RESET;
WiredHome 175:7be3a1fb7fc2 1534 WriteCommand(RA8875_MWCR0,0x00); // Graphics write mode
WiredHome 41:2956a0a221e5 1535 SetGraphicsCursorRead(x, y);
WiredHome 175:7be3a1fb7fc2 1536 WriteCommand(RA8875_MRWC);
WiredHome 79:544eb4964795 1537 _select(true);
WiredHome 79:544eb4964795 1538 _spiwrite(0x40); // Cmd: read data
WiredHome 79:544eb4964795 1539 _spiwrite(0x00); // dummy read
WiredHome 105:4f116006ba1f 1540 if (screenbpp == 16) {
WiredHome 105:4f116006ba1f 1541 pixel = _spiread();
WiredHome 105:4f116006ba1f 1542 pixel |= (_spiread() << 8);
WiredHome 105:4f116006ba1f 1543 } else {
WiredHome 105:4f116006ba1f 1544 pixel = _cvt8to16(_spiread());
WiredHome 105:4f116006ba1f 1545 }
WiredHome 79:544eb4964795 1546 _select(false);
WiredHome 41:2956a0a221e5 1547 REGISTERPERFORMANCE(PRF_READPIXEL);
WiredHome 41:2956a0a221e5 1548 return pixel;
WiredHome 41:2956a0a221e5 1549 }
WiredHome 41:2956a0a221e5 1550
WiredHome 44:207594dece70 1551
WiredHome 41:2956a0a221e5 1552 RetCode_t RA8875::getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1553 {
WiredHome 41:2956a0a221e5 1554 color_t pixel;
WiredHome 86:e86b355940f4 1555 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1556
WiredHome 41:2956a0a221e5 1557 PERFORMANCE_RESET;
WiredHome 175:7be3a1fb7fc2 1558 ret = WriteCommand(RA8875_MWCR0,0x00); // Graphics write mode
WiredHome 86:e86b355940f4 1559 ret = SetGraphicsCursorRead(x, y);
WiredHome 175:7be3a1fb7fc2 1560 ret = WriteCommand(RA8875_MRWC);
WiredHome 79:544eb4964795 1561 _select(true);
WiredHome 79:544eb4964795 1562 _spiwrite(0x40); // Cmd: read data
WiredHome 79:544eb4964795 1563 _spiwrite(0x00); // dummy read
WiredHome 106:c80828f5dea4 1564 if (screenbpp == 16)
WiredHome 106:c80828f5dea4 1565 _spiwrite(0x00); // dummy read is only necessary when in 16-bit mode
WiredHome 41:2956a0a221e5 1566 while (count--) {
WiredHome 105:4f116006ba1f 1567 if (screenbpp == 16) {
WiredHome 105:4f116006ba1f 1568 pixel = _spiread();
WiredHome 105:4f116006ba1f 1569 pixel |= (_spiread() << 8);
WiredHome 105:4f116006ba1f 1570 } else {
WiredHome 105:4f116006ba1f 1571 pixel = _cvt8to16(_spiread());
WiredHome 105:4f116006ba1f 1572 }
WiredHome 41:2956a0a221e5 1573 *p++ = pixel;
WiredHome 41:2956a0a221e5 1574 }
WiredHome 79:544eb4964795 1575 _select(false);
WiredHome 41:2956a0a221e5 1576 REGISTERPERFORMANCE(PRF_READPIXELSTREAM);
WiredHome 86:e86b355940f4 1577 return ret;
WiredHome 41:2956a0a221e5 1578 }
WiredHome 41:2956a0a221e5 1579
WiredHome 44:207594dece70 1580
WiredHome 83:7bad0068cca0 1581 RetCode_t RA8875::line(point_t p1, point_t p2)
WiredHome 83:7bad0068cca0 1582 {
WiredHome 83:7bad0068cca0 1583 return line(p1.x, p1.y, p2.x, p2.y);
WiredHome 83:7bad0068cca0 1584 }
WiredHome 83:7bad0068cca0 1585
WiredHome 83:7bad0068cca0 1586
WiredHome 83:7bad0068cca0 1587 RetCode_t RA8875::line(point_t p1, point_t p2, color_t color)
WiredHome 83:7bad0068cca0 1588 {
WiredHome 83:7bad0068cca0 1589 return line(p1.x, p1.y, p2.x, p2.y, color);
WiredHome 83:7bad0068cca0 1590 }
WiredHome 83:7bad0068cca0 1591
WiredHome 83:7bad0068cca0 1592
WiredHome 37:f19b7e7449dc 1593 RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color)
WiredHome 19:3f82c1161fd2 1594 {
WiredHome 19:3f82c1161fd2 1595 foreground(color);
WiredHome 19:3f82c1161fd2 1596 return line(x1,y1,x2,y2);
WiredHome 19:3f82c1161fd2 1597 }
WiredHome 19:3f82c1161fd2 1598
WiredHome 44:207594dece70 1599
WiredHome 37:f19b7e7449dc 1600 RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2)
WiredHome 19:3f82c1161fd2 1601 {
WiredHome 19:3f82c1161fd2 1602 PERFORMANCE_RESET;
WiredHome 62:ba5d33438fda 1603 if (x1 == x2 && y1 == y2) {
WiredHome 60:2dfd574f63bd 1604 pixel(x1, y1);
WiredHome 62:ba5d33438fda 1605 } else {
WiredHome 175:7be3a1fb7fc2 1606 WriteCommandW(RA8875_DLHSR0, x1);
WiredHome 175:7be3a1fb7fc2 1607 WriteCommandW(RA8875_DLVSR0, y1);
WiredHome 175:7be3a1fb7fc2 1608 WriteCommandW(RA8875_DLHER0, x2);
WiredHome 175:7be3a1fb7fc2 1609 WriteCommandW(RA8875_DLVER0, y2);
WiredHome 60:2dfd574f63bd 1610 unsigned char drawCmd = 0x00; // Line
WiredHome 175:7be3a1fb7fc2 1611 WriteCommand(RA8875_DCR, drawCmd);
WiredHome 175:7be3a1fb7fc2 1612 WriteCommand(RA8875_DCR, 0x80 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1613 if (!_WaitWhileReg(0x90, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1614 REGISTERPERFORMANCE(PRF_DRAWLINE);
WiredHome 131:5bd6ba2ee4a1 1615 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1616 }
WiredHome 60:2dfd574f63bd 1617 }
WiredHome 19:3f82c1161fd2 1618 REGISTERPERFORMANCE(PRF_DRAWLINE);
WiredHome 19:3f82c1161fd2 1619 return noerror;
WiredHome 19:3f82c1161fd2 1620 }
WiredHome 19:3f82c1161fd2 1621
WiredHome 144:ba002c4b21b3 1622
WiredHome 144:ba002c4b21b3 1623 RetCode_t RA8875::ThickLine(point_t p1, point_t p2, dim_t thickness, color_t color)
WiredHome 144:ba002c4b21b3 1624 {
WiredHome 178:ae472eb22740 1625 INFO("ThickLine()");
WiredHome 144:ba002c4b21b3 1626 if (thickness == 1) {
WiredHome 144:ba002c4b21b3 1627 line(p1,p2, color);
WiredHome 144:ba002c4b21b3 1628 } else {
WiredHome 178:ae472eb22740 1629 if (p1.x == p2.x) {
WiredHome 178:ae472eb22740 1630 // vertical
WiredHome 178:ae472eb22740 1631 fillcircle(p1, thickness/2, color);
WiredHome 178:ae472eb22740 1632 fillcircle(p2, thickness/2, color);
WiredHome 178:ae472eb22740 1633 fillrect(p1.x-thickness/2,p1.y, p2.x+thickness/2,p2.y, color);
WiredHome 178:ae472eb22740 1634 } else if (p1.y == p2.y) {
WiredHome 178:ae472eb22740 1635 // horizontal
WiredHome 178:ae472eb22740 1636 fillcircle(p1, thickness/2, color);
WiredHome 178:ae472eb22740 1637 fillcircle(p2, thickness/2, color);
WiredHome 178:ae472eb22740 1638 fillrect(p1.x,p1.y-thickness/2, p2.x,p2.y+thickness/2, color);
WiredHome 178:ae472eb22740 1639 } else {
WiredHome 178:ae472eb22740 1640 // some diagonal, drawn rather slowly with filled circles
WiredHome 178:ae472eb22740 1641 // @todo draw the end-points with circles, then draw the diagonal
WiredHome 178:ae472eb22740 1642 // with 2 triangles.
WiredHome 178:ae472eb22740 1643 #if 1 // New Faster method
WiredHome 178:ae472eb22740 1644 //Round-caps
WiredHome 178:ae472eb22740 1645 fillcircle(p1, thickness/2, color);
WiredHome 178:ae472eb22740 1646 fillcircle(p2, thickness/2, color);
WiredHome 178:ae472eb22740 1647 // Compute the perpendicular points to draw the triangles
WiredHome 178:ae472eb22740 1648 // + fillTriangle: p1a,p1b,p2a
WiredHome 178:ae472eb22740 1649 // / + p1a p1a,p2a,p2b
WiredHome 178:ae472eb22740 1650 // + +p1+ . . . . .
WiredHome 178:ae472eb22740 1651 // p1b + / . angle
WiredHome 178:ae472eb22740 1652 // + .
WiredHome 178:ae472eb22740 1653 // .
WiredHome 178:ae472eb22740 1654 //
WiredHome 178:ae472eb22740 1655 // . +
WiredHome 178:ae472eb22740 1656 // / + p2a
WiredHome 178:ae472eb22740 1657 // + +p2+
WiredHome 178:ae472eb22740 1658 // p2b + /
WiredHome 178:ae472eb22740 1659 // +
WiredHome 178:ae472eb22740 1660 point_t pTri[4];
WiredHome 178:ae472eb22740 1661 float slope = (p2.y - p1.y) / (p2.x - p1.x);
WiredHome 178:ae472eb22740 1662 slope = -1/slope;
WiredHome 178:ae472eb22740 1663 //centerline
WiredHome 178:ae472eb22740 1664 //line(p1,p2,color);
WiredHome 178:ae472eb22740 1665 float dx = (thickness/2 / sqrt(thickness/2 + (slope * slope)));
WiredHome 178:ae472eb22740 1666 float dy = slope * dx;
WiredHome 178:ae472eb22740 1667 pTri[0].x = p1.x + dx;
WiredHome 178:ae472eb22740 1668 pTri[0].y = p1.y + dy;
WiredHome 178:ae472eb22740 1669 pTri[1].x = p1.x - dx;
WiredHome 178:ae472eb22740 1670 pTri[1].y = p1.y - dy;
WiredHome 178:ae472eb22740 1671 pTri[2].x = p2.x + dx;
WiredHome 178:ae472eb22740 1672 pTri[2].y = p2.y + dy;
WiredHome 178:ae472eb22740 1673 pTri[3].x = p2.x - dx;
WiredHome 178:ae472eb22740 1674 pTri[3].y = p2.y - dy;
WiredHome 178:ae472eb22740 1675 filltriangle(pTri[0],pTri[1],pTri[3], color);
WiredHome 178:ae472eb22740 1676 filltriangle(pTri[0],pTri[2],pTri[3], color);
WiredHome 178:ae472eb22740 1677 #else // old slower method
WiredHome 178:ae472eb22740 1678 // Draw with a lot of overlapping circles
WiredHome 178:ae472eb22740 1679 int dx = abs(p2.x-p1.x), sx = p1.x<p2.x ? 1 : -1;
WiredHome 178:ae472eb22740 1680 int dy = abs(p2.y-p1.y), sy = p1.y<p2.y ? 1 : -1;
WiredHome 178:ae472eb22740 1681 int err = (dx>dy ? dx : -dy)/2, e2;
WiredHome 178:ae472eb22740 1682
WiredHome 178:ae472eb22740 1683 for (;;) {
WiredHome 178:ae472eb22740 1684 fillcircle(p1.x, p1.y, thickness/2, color);
WiredHome 178:ae472eb22740 1685 if (p1.x==p2.x && p1.y==p2.y)
WiredHome 178:ae472eb22740 1686 break;
WiredHome 178:ae472eb22740 1687 e2 = err;
WiredHome 178:ae472eb22740 1688 if (e2 >-dx)
WiredHome 178:ae472eb22740 1689 { err -= dy; p1.x += sx; }
WiredHome 178:ae472eb22740 1690 if (e2 < dy)
WiredHome 178:ae472eb22740 1691 { err += dx; p1.y += sy; }
WiredHome 178:ae472eb22740 1692 }
WiredHome 178:ae472eb22740 1693 #endif
WiredHome 178:ae472eb22740 1694 }
WiredHome 144:ba002c4b21b3 1695 }
WiredHome 144:ba002c4b21b3 1696 return noerror;
WiredHome 144:ba002c4b21b3 1697 }
WiredHome 144:ba002c4b21b3 1698
WiredHome 144:ba002c4b21b3 1699
WiredHome 107:f9ccffcb84f1 1700 //
WiredHome 107:f9ccffcb84f1 1701 // Rectangle functions all mostly helpers to the basic rectangle function
WiredHome 107:f9ccffcb84f1 1702 //
WiredHome 107:f9ccffcb84f1 1703
WiredHome 81:01da2e34283d 1704 RetCode_t RA8875::fillrect(rect_t r, color_t color, fill_t fillit)
WiredHome 81:01da2e34283d 1705 {
WiredHome 81:01da2e34283d 1706 return rect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, color, fillit);
WiredHome 81:01da2e34283d 1707 }
WiredHome 44:207594dece70 1708
WiredHome 73:f22a18707b5e 1709 RetCode_t RA8875::fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1710 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1711 {
WiredHome 19:3f82c1161fd2 1712 return rect(x1,y1,x2,y2,color,fillit);
WiredHome 19:3f82c1161fd2 1713 }
WiredHome 19:3f82c1161fd2 1714
WiredHome 81:01da2e34283d 1715 RetCode_t RA8875::rect(rect_t r, color_t color, fill_t fillit)
WiredHome 81:01da2e34283d 1716 {
WiredHome 81:01da2e34283d 1717 return rect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, color, fillit);
WiredHome 81:01da2e34283d 1718 }
WiredHome 44:207594dece70 1719
WiredHome 73:f22a18707b5e 1720 RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1721 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1722 {
WiredHome 19:3f82c1161fd2 1723 foreground(color);
WiredHome 19:3f82c1161fd2 1724 return rect(x1,y1,x2,y2,fillit);
WiredHome 19:3f82c1161fd2 1725 }
WiredHome 19:3f82c1161fd2 1726
WiredHome 73:f22a18707b5e 1727 RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1728 fill_t fillit)
WiredHome 19:3f82c1161fd2 1729 {
WiredHome 85:022bba13c5c4 1730 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 1731 PERFORMANCE_RESET;
WiredHome 85:022bba13c5c4 1732 // check for bad_parameter
WiredHome 105:4f116006ba1f 1733 if (x1 < 0 || x1 >= screenwidth || x2 < 0 || x2 >= screenwidth
WiredHome 105:4f116006ba1f 1734 || y1 < 0 || y1 >= screenheight || y2 < 0 || y2 >= screenheight) {
WiredHome 85:022bba13c5c4 1735 ret = bad_parameter;
WiredHome 100:0b084475d5a9 1736 } else {
WiredHome 85:022bba13c5c4 1737 if (x1 == x2 && y1 == y2) {
WiredHome 85:022bba13c5c4 1738 pixel(x1, y1);
WiredHome 85:022bba13c5c4 1739 } else if (x1 == x2) {
WiredHome 85:022bba13c5c4 1740 line(x1, y1, x2, y2);
WiredHome 85:022bba13c5c4 1741 } else if (y1 == y2) {
WiredHome 85:022bba13c5c4 1742 line(x1, y1, x2, y2);
WiredHome 85:022bba13c5c4 1743 } else {
WiredHome 175:7be3a1fb7fc2 1744 WriteCommandW(RA8875_DLHSR0, x1);
WiredHome 175:7be3a1fb7fc2 1745 WriteCommandW(RA8875_DLVSR0, y1);
WiredHome 175:7be3a1fb7fc2 1746 WriteCommandW(RA8875_DLHER0, x2);
WiredHome 175:7be3a1fb7fc2 1747 WriteCommandW(RA8875_DLVER0, y2);
WiredHome 85:022bba13c5c4 1748 unsigned char drawCmd = 0x10; // Rectangle
WiredHome 85:022bba13c5c4 1749 if (fillit == FILL)
WiredHome 85:022bba13c5c4 1750 drawCmd |= 0x20;
WiredHome 175:7be3a1fb7fc2 1751 WriteCommand(RA8875_DCR, drawCmd);
WiredHome 175:7be3a1fb7fc2 1752 ret = WriteCommand(RA8875_DCR, 0x80 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1753 if (!_WaitWhileReg(0x90, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1754 REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
WiredHome 131:5bd6ba2ee4a1 1755 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1756 }
WiredHome 85:022bba13c5c4 1757 }
WiredHome 19:3f82c1161fd2 1758 }
WiredHome 19:3f82c1161fd2 1759 REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
WiredHome 85:022bba13c5c4 1760 return ret;
WiredHome 19:3f82c1161fd2 1761 }
WiredHome 19:3f82c1161fd2 1762
WiredHome 44:207594dece70 1763
WiredHome 107:f9ccffcb84f1 1764 //
WiredHome 107:f9ccffcb84f1 1765 // rounded rectangle functions are mostly helpers to the base round rect
WiredHome 107:f9ccffcb84f1 1766 //
WiredHome 107:f9ccffcb84f1 1767
WiredHome 107:f9ccffcb84f1 1768 RetCode_t RA8875::fillroundrect(rect_t r, dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 107:f9ccffcb84f1 1769 {
WiredHome 107:f9ccffcb84f1 1770 return roundrect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, radius1, radius2, color, fillit);
WiredHome 107:f9ccffcb84f1 1771 }
WiredHome 107:f9ccffcb84f1 1772
WiredHome 73:f22a18707b5e 1773 RetCode_t RA8875::fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1774 dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1775 {
WiredHome 19:3f82c1161fd2 1776 foreground(color);
WiredHome 19:3f82c1161fd2 1777 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1778 }
WiredHome 19:3f82c1161fd2 1779
WiredHome 107:f9ccffcb84f1 1780 RetCode_t RA8875::roundrect(rect_t r, dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 107:f9ccffcb84f1 1781 {
WiredHome 107:f9ccffcb84f1 1782 return roundrect(r.p1.x, r.p1.y, r.p2.x, r.p2.y, radius1, radius2, color, fillit);
WiredHome 107:f9ccffcb84f1 1783 }
WiredHome 44:207594dece70 1784
WiredHome 73:f22a18707b5e 1785 RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1786 dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1787 {
WiredHome 19:3f82c1161fd2 1788 foreground(color);
WiredHome 19:3f82c1161fd2 1789 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1790 }
WiredHome 19:3f82c1161fd2 1791
WiredHome 44:207594dece70 1792
WiredHome 73:f22a18707b5e 1793 RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1794 dim_t radius1, dim_t radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 1795 {
WiredHome 19:3f82c1161fd2 1796 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1797
WiredHome 178:ae472eb22740 1798 INFO("roundrect()");
WiredHome 19:3f82c1161fd2 1799 PERFORMANCE_RESET;
WiredHome 105:4f116006ba1f 1800 if (x1 < 0 || x1 >= screenwidth || x2 < 0 || x2 >= screenwidth
WiredHome 105:4f116006ba1f 1801 || y1 < 0 || y1 >= screenheight || y2 < 0 || y2 >= screenheight) {
WiredHome 85:022bba13c5c4 1802 ret = bad_parameter;
WiredHome 85:022bba13c5c4 1803 } else if (x1 > x2 || y1 > y2 || (radius1 > (x2-x1)/2) || (radius2 > (y2-y1)/2) ) {
WiredHome 21:3c1efb192927 1804 ret = bad_parameter;
WiredHome 21:3c1efb192927 1805 } else if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 1806 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1807 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 1808 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1809 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 1810 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1811 } else {
WiredHome 175:7be3a1fb7fc2 1812 WriteCommandW(RA8875_DLHSR0, x1);
WiredHome 175:7be3a1fb7fc2 1813 WriteCommandW(RA8875_DLVSR0, y1);
WiredHome 175:7be3a1fb7fc2 1814 WriteCommandW(RA8875_DLHER0, x2);
WiredHome 175:7be3a1fb7fc2 1815 WriteCommandW(RA8875_DLVER0, y2);
WiredHome 175:7be3a1fb7fc2 1816 WriteCommandW(RA8875_ELLA0, radius1);
WiredHome 175:7be3a1fb7fc2 1817 WriteCommandW(RA8875_ELLB0, radius2);
WiredHome 21:3c1efb192927 1818 // Should not need this...
WiredHome 175:7be3a1fb7fc2 1819 WriteCommandW(RA8875_DEHR0, 0);
WiredHome 175:7be3a1fb7fc2 1820 WriteCommandW(RA8875_DEVR0, 0);
WiredHome 19:3f82c1161fd2 1821 unsigned char drawCmd = 0x20; // Rounded Rectangle
WiredHome 19:3f82c1161fd2 1822 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1823 drawCmd |= 0x40;
WiredHome 175:7be3a1fb7fc2 1824 WriteCommand(RA8875_ELLIPSE, drawCmd);
WiredHome 175:7be3a1fb7fc2 1825 WriteCommand(RA8875_ELLIPSE, 0x80 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1826 if (!_WaitWhileReg(0xA0, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1827 REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
WiredHome 131:5bd6ba2ee4a1 1828 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1829 }
WiredHome 19:3f82c1161fd2 1830 }
WiredHome 19:3f82c1161fd2 1831 REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
WiredHome 19:3f82c1161fd2 1832 return ret;
WiredHome 19:3f82c1161fd2 1833 }
WiredHome 19:3f82c1161fd2 1834
WiredHome 44:207594dece70 1835
WiredHome 107:f9ccffcb84f1 1836 //
WiredHome 107:f9ccffcb84f1 1837 // triangle functions
WiredHome 107:f9ccffcb84f1 1838 //
WiredHome 178:ae472eb22740 1839 RetCode_t RA8875::filltriangle(point_t p1, point_t p2, point_t p3, color_t color, fill_t fillit)
WiredHome 178:ae472eb22740 1840 {
WiredHome 178:ae472eb22740 1841 return filltriangle(p1.x,p1.y, p2.x,p2.y, p3.x,p3.y, color, fillit);
WiredHome 178:ae472eb22740 1842 }
WiredHome 178:ae472eb22740 1843
WiredHome 178:ae472eb22740 1844 RetCode_t RA8875::triangle(point_t p1, point_t p2, point_t p3, color_t color, fill_t fillit)
WiredHome 178:ae472eb22740 1845 {
WiredHome 178:ae472eb22740 1846 return triangle(p1.x,p1.y, p2.x,p2.y, p3.x,p3.y, color, fillit);
WiredHome 178:ae472eb22740 1847 }
WiredHome 107:f9ccffcb84f1 1848
WiredHome 73:f22a18707b5e 1849 RetCode_t RA8875::triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1850 loc_t x3, loc_t y3, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1851 {
WiredHome 20:6e2e4a8372eb 1852 RetCode_t ret;
WiredHome 20:6e2e4a8372eb 1853
WiredHome 105:4f116006ba1f 1854 if (x1 < 0 || x1 >= screenwidth || x2 < 0 || x2 >= screenwidth || x3 < 0 || x3 >= screenwidth
WiredHome 105:4f116006ba1f 1855 || y1 < 0 || y1 >= screenheight || y2 < 0 || y2 >= screenheight || y3 < 0 || y3 >= screenheight)
WiredHome 85:022bba13c5c4 1856 ret = bad_parameter;
WiredHome 19:3f82c1161fd2 1857 foreground(color);
WiredHome 20:6e2e4a8372eb 1858 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 20:6e2e4a8372eb 1859 return ret;
WiredHome 19:3f82c1161fd2 1860 }
WiredHome 19:3f82c1161fd2 1861
WiredHome 44:207594dece70 1862
WiredHome 73:f22a18707b5e 1863 RetCode_t RA8875::filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1864 loc_t x3, loc_t y3, color_t color, fill_t fillit)
WiredHome 73:f22a18707b5e 1865 {
WiredHome 73:f22a18707b5e 1866 RetCode_t ret;
WiredHome 73:f22a18707b5e 1867
WiredHome 73:f22a18707b5e 1868 foreground(color);
WiredHome 73:f22a18707b5e 1869 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 73:f22a18707b5e 1870 return ret;
WiredHome 73:f22a18707b5e 1871 }
WiredHome 73:f22a18707b5e 1872
WiredHome 73:f22a18707b5e 1873
WiredHome 73:f22a18707b5e 1874 RetCode_t RA8875::triangle(loc_t x1, loc_t y1 ,loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1875 loc_t x3, loc_t y3, fill_t fillit)
WiredHome 19:3f82c1161fd2 1876 {
WiredHome 19:3f82c1161fd2 1877 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1878
WiredHome 178:ae472eb22740 1879 INFO("triangle");
WiredHome 19:3f82c1161fd2 1880 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1881 if (x1 == x2 && y1 == y2 && x1 == x3 && y1 == y3) {
WiredHome 19:3f82c1161fd2 1882 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1883 } else {
WiredHome 175:7be3a1fb7fc2 1884 WriteCommandW(RA8875_DLHSR0, x1);
WiredHome 175:7be3a1fb7fc2 1885 WriteCommandW(RA8875_DLVSR0, y1);
WiredHome 175:7be3a1fb7fc2 1886 WriteCommandW(RA8875_DLHER0, x2);
WiredHome 175:7be3a1fb7fc2 1887 WriteCommandW(RA8875_DLVER0, y2);
WiredHome 175:7be3a1fb7fc2 1888 WriteCommandW(RA8875_DTPH0, x3);
WiredHome 175:7be3a1fb7fc2 1889 WriteCommandW(RA8875_DTPV0, y3);
WiredHome 19:3f82c1161fd2 1890 unsigned char drawCmd = 0x01; // Triangle
WiredHome 19:3f82c1161fd2 1891 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1892 drawCmd |= 0x20;
WiredHome 175:7be3a1fb7fc2 1893 WriteCommand(RA8875_DCR, drawCmd);
WiredHome 175:7be3a1fb7fc2 1894 WriteCommand(RA8875_DCR, 0x80 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1895 if (!_WaitWhileReg(0x90, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 1896 REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
WiredHome 131:5bd6ba2ee4a1 1897 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1898 }
WiredHome 19:3f82c1161fd2 1899 }
WiredHome 19:3f82c1161fd2 1900 REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
WiredHome 19:3f82c1161fd2 1901 return ret;
WiredHome 19:3f82c1161fd2 1902 }
WiredHome 19:3f82c1161fd2 1903
WiredHome 83:7bad0068cca0 1904
WiredHome 83:7bad0068cca0 1905 RetCode_t RA8875::circle(point_t p, dim_t radius,
WiredHome 83:7bad0068cca0 1906 color_t color, fill_t fillit)
WiredHome 83:7bad0068cca0 1907 {
WiredHome 83:7bad0068cca0 1908 foreground(color);
WiredHome 83:7bad0068cca0 1909 return circle(p.x,p.y,radius,fillit);
WiredHome 83:7bad0068cca0 1910 }
WiredHome 83:7bad0068cca0 1911
WiredHome 83:7bad0068cca0 1912
WiredHome 83:7bad0068cca0 1913 RetCode_t RA8875::fillcircle(point_t p, dim_t radius,
WiredHome 83:7bad0068cca0 1914 color_t color, fill_t fillit)
WiredHome 83:7bad0068cca0 1915 {
WiredHome 83:7bad0068cca0 1916 foreground(color);
WiredHome 83:7bad0068cca0 1917 return circle(p.x,p.y,radius,fillit);
WiredHome 83:7bad0068cca0 1918 }
WiredHome 83:7bad0068cca0 1919
WiredHome 83:7bad0068cca0 1920
WiredHome 83:7bad0068cca0 1921 RetCode_t RA8875::circle(point_t p, dim_t radius, fill_t fillit)
WiredHome 83:7bad0068cca0 1922 {
WiredHome 83:7bad0068cca0 1923 return circle(p.x,p.y,radius,fillit);
WiredHome 83:7bad0068cca0 1924 }
WiredHome 83:7bad0068cca0 1925
WiredHome 83:7bad0068cca0 1926
WiredHome 73:f22a18707b5e 1927 RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius,
WiredHome 73:f22a18707b5e 1928 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1929 {
WiredHome 19:3f82c1161fd2 1930 foreground(color);
WiredHome 19:3f82c1161fd2 1931 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 1932 }
WiredHome 19:3f82c1161fd2 1933
WiredHome 44:207594dece70 1934
WiredHome 73:f22a18707b5e 1935 RetCode_t RA8875::fillcircle(loc_t x, loc_t y, dim_t radius,
WiredHome 73:f22a18707b5e 1936 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1937 {
WiredHome 19:3f82c1161fd2 1938 foreground(color);
WiredHome 19:3f82c1161fd2 1939 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 1940 }
WiredHome 19:3f82c1161fd2 1941
WiredHome 44:207594dece70 1942
WiredHome 37:f19b7e7449dc 1943 RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius, fill_t fillit)
WiredHome 19:3f82c1161fd2 1944 {
WiredHome 19:3f82c1161fd2 1945 RetCode_t ret = noerror;
WiredHome 181:0032d1b8f5d4 1946
WiredHome 178:ae472eb22740 1947 INFO("circle");
WiredHome 19:3f82c1161fd2 1948 PERFORMANCE_RESET;
WiredHome 181:0032d1b8f5d4 1949 #if 0
WiredHome 181:0032d1b8f5d4 1950 loc_t t;
WiredHome 181:0032d1b8f5d4 1951 SetTextCursor(0,10);
WiredHome 181:0032d1b8f5d4 1952 printf("Circle(%3d,%3d) => ", x,y);
WiredHome 181:0032d1b8f5d4 1953 switch (screen_orientation) {
WiredHome 181:0032d1b8f5d4 1954 default:
WiredHome 181:0032d1b8f5d4 1955 case rotate_0:
WiredHome 181:0032d1b8f5d4 1956 break;
WiredHome 181:0032d1b8f5d4 1957 case rotate_90:
WiredHome 181:0032d1b8f5d4 1958 t = x;
WiredHome 181:0032d1b8f5d4 1959 x = y;
WiredHome 181:0032d1b8f5d4 1960 y = t;
WiredHome 181:0032d1b8f5d4 1961 break;
WiredHome 181:0032d1b8f5d4 1962 case rotate_180:
WiredHome 181:0032d1b8f5d4 1963 break;
WiredHome 181:0032d1b8f5d4 1964 case rotate_270:
WiredHome 181:0032d1b8f5d4 1965 break;
WiredHome 181:0032d1b8f5d4 1966 }
WiredHome 181:0032d1b8f5d4 1967 printf(" => (%3d,%3d)\r\n", x,y);
WiredHome 181:0032d1b8f5d4 1968 #endif
WiredHome 181:0032d1b8f5d4 1969 if (radius <= 0 || (x - radius) < 0 || (x + radius) > width()
WiredHome 181:0032d1b8f5d4 1970 || (y - radius) < 0 || (y + radius) > height()) {
WiredHome 19:3f82c1161fd2 1971 ret = bad_parameter;
WiredHome 19:3f82c1161fd2 1972 } else if (radius == 1) {
WiredHome 19:3f82c1161fd2 1973 pixel(x,y);
WiredHome 19:3f82c1161fd2 1974 } else {
WiredHome 175:7be3a1fb7fc2 1975 WriteCommandW(RA8875_DCHR0, x);
WiredHome 175:7be3a1fb7fc2 1976 WriteCommandW(RA8875_DCVR0, y);
WiredHome 175:7be3a1fb7fc2 1977 WriteCommand(RA8875_DCRR, radius & 0xFF);
WiredHome 19:3f82c1161fd2 1978 unsigned char drawCmd = 0x00; // Circle
WiredHome 19:3f82c1161fd2 1979 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1980 drawCmd |= 0x20;
WiredHome 175:7be3a1fb7fc2 1981 WriteCommand(RA8875_DCR, drawCmd);
WiredHome 175:7be3a1fb7fc2 1982 WriteCommand(RA8875_DCR, 0x40 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 1983 if (!_WaitWhileReg(0x90, 0x40)) {
WiredHome 131:5bd6ba2ee4a1 1984 REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
WiredHome 131:5bd6ba2ee4a1 1985 return external_abort;
WiredHome 131:5bd6ba2ee4a1 1986 }
WiredHome 19:3f82c1161fd2 1987 }
WiredHome 19:3f82c1161fd2 1988 REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
WiredHome 19:3f82c1161fd2 1989 return ret;
WiredHome 19:3f82c1161fd2 1990 }
WiredHome 19:3f82c1161fd2 1991
WiredHome 44:207594dece70 1992
WiredHome 37:f19b7e7449dc 1993 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 1994 {
WiredHome 19:3f82c1161fd2 1995 foreground(color);
WiredHome 25:9556a3a9b7cc 1996 return ellipse(x,y,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1997 }
WiredHome 19:3f82c1161fd2 1998
WiredHome 44:207594dece70 1999
WiredHome 37:f19b7e7449dc 2000 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 2001 {
WiredHome 25:9556a3a9b7cc 2002 foreground(color);
WiredHome 25:9556a3a9b7cc 2003 return ellipse(x,y,radius1,radius2,fillit);
WiredHome 25:9556a3a9b7cc 2004 }
WiredHome 44:207594dece70 2005
WiredHome 73:f22a18707b5e 2006
WiredHome 37:f19b7e7449dc 2007 RetCode_t RA8875::ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 2008 {
WiredHome 19:3f82c1161fd2 2009 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 2010
WiredHome 178:ae472eb22740 2011 INFO("ellipse");
WiredHome 19:3f82c1161fd2 2012 PERFORMANCE_RESET;
WiredHome 105:4f116006ba1f 2013 if (radius1 <= 0 || radius2 <= 0 || (x - radius1) < 0 || (x + radius1) > screenwidth
WiredHome 105:4f116006ba1f 2014 || (y - radius2) < 0 || (y + radius2) > screenheight) {
WiredHome 85:022bba13c5c4 2015 ret = bad_parameter;
WiredHome 25:9556a3a9b7cc 2016 } else if (radius1 == 1 && radius2 == 1) {
WiredHome 19:3f82c1161fd2 2017 pixel(x, y);
WiredHome 19:3f82c1161fd2 2018 } else {
WiredHome 175:7be3a1fb7fc2 2019 WriteCommandW(RA8875_DEHR0, x);
WiredHome 175:7be3a1fb7fc2 2020 WriteCommandW(RA8875_DEVR0, y);
WiredHome 175:7be3a1fb7fc2 2021 WriteCommandW(RA8875_ELLA0, radius1);
WiredHome 175:7be3a1fb7fc2 2022 WriteCommandW(RA8875_ELLB0, radius2);
WiredHome 19:3f82c1161fd2 2023 unsigned char drawCmd = 0x00; // Ellipse
WiredHome 19:3f82c1161fd2 2024 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 2025 drawCmd |= 0x40;
WiredHome 175:7be3a1fb7fc2 2026 WriteCommand(RA8875_ELLIPSE, drawCmd);
WiredHome 175:7be3a1fb7fc2 2027 WriteCommand(RA8875_ELLIPSE, 0x80 + drawCmd); // Start drawing.
WiredHome 131:5bd6ba2ee4a1 2028 if (!_WaitWhileReg(0xA0, 0x80)) {
WiredHome 131:5bd6ba2ee4a1 2029 REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
WiredHome 131:5bd6ba2ee4a1 2030 return external_abort;
WiredHome 131:5bd6ba2ee4a1 2031 }
WiredHome 19:3f82c1161fd2 2032 }
WiredHome 19:3f82c1161fd2 2033 REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
WiredHome 19:3f82c1161fd2 2034 return ret;
WiredHome 19:3f82c1161fd2 2035 }
WiredHome 19:3f82c1161fd2 2036
WiredHome 44:207594dece70 2037
WiredHome 68:ab08efabfc88 2038 RetCode_t RA8875::frequency(unsigned long Hz, unsigned long Hz2)
WiredHome 19:3f82c1161fd2 2039 {
WiredHome 66:468a11f05580 2040 spiwritefreq = Hz;
WiredHome 68:ab08efabfc88 2041 if (Hz2 != 0)
WiredHome 68:ab08efabfc88 2042 spireadfreq = Hz2;
WiredHome 68:ab08efabfc88 2043 else
WiredHome 68:ab08efabfc88 2044 spireadfreq = Hz/2;
WiredHome 68:ab08efabfc88 2045 _setWriteSpeed(true);
WiredHome 19:3f82c1161fd2 2046 // __ ___
WiredHome 19:3f82c1161fd2 2047 // Clock ___A Rising edge latched
WiredHome 19:3f82c1161fd2 2048 // ___ ____
WiredHome 19:3f82c1161fd2 2049 // Data ___X____
WiredHome 19:3f82c1161fd2 2050 spi.format(8, 3); // 8 bits and clock to data phase 0
WiredHome 19:3f82c1161fd2 2051 return noerror;
WiredHome 19:3f82c1161fd2 2052 }
WiredHome 19:3f82c1161fd2 2053
WiredHome 68:ab08efabfc88 2054 void RA8875::_setWriteSpeed(bool writeSpeed)
WiredHome 68:ab08efabfc88 2055 {
WiredHome 68:ab08efabfc88 2056 if (writeSpeed) {
WiredHome 68:ab08efabfc88 2057 spi.frequency(spiwritefreq);
WiredHome 68:ab08efabfc88 2058 spiWriteSpeed = true;
WiredHome 68:ab08efabfc88 2059 } else {
WiredHome 68:ab08efabfc88 2060 spi.frequency(spireadfreq);
WiredHome 68:ab08efabfc88 2061 spiWriteSpeed = false;
WiredHome 68:ab08efabfc88 2062 }
WiredHome 68:ab08efabfc88 2063 }
WiredHome 44:207594dece70 2064
WiredHome 131:5bd6ba2ee4a1 2065
WiredHome 131:5bd6ba2ee4a1 2066
WiredHome 131:5bd6ba2ee4a1 2067 RetCode_t RA8875::BlockMove(uint8_t dstLayer, uint8_t dstDataSelect, point_t dstPoint,
WiredHome 131:5bd6ba2ee4a1 2068 uint8_t srcLayer, uint8_t srcDataSelect, point_t srcPoint,
WiredHome 137:9e09f6081ef1 2069 dim_t bte_width, dim_t bte_height,
WiredHome 131:5bd6ba2ee4a1 2070 uint8_t bte_op_code, uint8_t bte_rop_code)
WiredHome 131:5bd6ba2ee4a1 2071 {
WiredHome 131:5bd6ba2ee4a1 2072 uint8_t cmd;
WiredHome 131:5bd6ba2ee4a1 2073
WiredHome 131:5bd6ba2ee4a1 2074 PERFORMANCE_RESET;
WiredHome 137:9e09f6081ef1 2075 ///@todo range check and error return rather than to secretly fix
WiredHome 131:5bd6ba2ee4a1 2076 srcPoint.x &= 0x3FF; // prevent high bits from doing unexpected things
WiredHome 131:5bd6ba2ee4a1 2077 srcPoint.y &= 0x1FF;
WiredHome 131:5bd6ba2ee4a1 2078 dstPoint.x &= 0x3FF;
WiredHome 131:5bd6ba2ee4a1 2079 dstPoint.y &= 0x1FF;
WiredHome 175:7be3a1fb7fc2 2080 WriteCommandW(RA8875_HSBE0, srcPoint.x);
WiredHome 175:7be3a1fb7fc2 2081 WriteCommandW(RA8875_VSBE0, ((dim_t)(srcLayer & 1) << 15) | srcPoint.y);
WiredHome 175:7be3a1fb7fc2 2082 WriteCommandW(RA8875_HDBE0, dstPoint.x);
WiredHome 175:7be3a1fb7fc2 2083 WriteCommandW(RA8875_VDBE0, ((dim_t)(dstLayer & 1) << 15) | dstPoint.y);
WiredHome 175:7be3a1fb7fc2 2084 WriteCommandW(RA8875_BEWR0, bte_width);
WiredHome 175:7be3a1fb7fc2 2085 WriteCommandW(RA8875_BEHR0, bte_height);
WiredHome 175:7be3a1fb7fc2 2086 WriteCommand(RA8875_BECR1, ((bte_rop_code & 0x0F) << 4) | (bte_op_code & 0x0F));
WiredHome 131:5bd6ba2ee4a1 2087 cmd = ((srcDataSelect & 1) << 6) | ((dstDataSelect & 1) << 5);
WiredHome 175:7be3a1fb7fc2 2088 WriteCommand(RA8875_BECR0, 0x80 | cmd); // enable the BTE
WiredHome 131:5bd6ba2ee4a1 2089 if (!_WaitWhileBusy(0x40)) {
WiredHome 131:5bd6ba2ee4a1 2090 REGISTERPERFORMANCE(PRF_BLOCKMOVE);
WiredHome 131:5bd6ba2ee4a1 2091 return external_abort;
WiredHome 131:5bd6ba2ee4a1 2092 }
WiredHome 131:5bd6ba2ee4a1 2093 REGISTERPERFORMANCE(PRF_BLOCKMOVE);
WiredHome 131:5bd6ba2ee4a1 2094 return noerror;
WiredHome 131:5bd6ba2ee4a1 2095 }
WiredHome 131:5bd6ba2ee4a1 2096
WiredHome 131:5bd6ba2ee4a1 2097
WiredHome 19:3f82c1161fd2 2098 RetCode_t RA8875::Power(bool on)
WiredHome 19:3f82c1161fd2 2099 {
WiredHome 175:7be3a1fb7fc2 2100 WriteCommand(RA8875_PWRR, (on) ? 0x80 : 0x00);
WiredHome 19:3f82c1161fd2 2101 return noerror;
WiredHome 19:3f82c1161fd2 2102 }
WiredHome 19:3f82c1161fd2 2103
WiredHome 44:207594dece70 2104
WiredHome 131:5bd6ba2ee4a1 2105 RetCode_t RA8875::Backlight_u8(uint8_t brightness)
WiredHome 19:3f82c1161fd2 2106 {
WiredHome 19:3f82c1161fd2 2107 static bool is_enabled = false;
WiredHome 131:5bd6ba2ee4a1 2108
WiredHome 19:3f82c1161fd2 2109 if (brightness == 0) {
WiredHome 175:7be3a1fb7fc2 2110 WriteCommand(RA8875_P1CR); // Disable the PWM
WiredHome 19:3f82c1161fd2 2111 WriteData(0x00);
WiredHome 19:3f82c1161fd2 2112 is_enabled = false;
WiredHome 19:3f82c1161fd2 2113 } else if (!is_enabled) {
WiredHome 175:7be3a1fb7fc2 2114 WriteCommand(RA8875_P1CR); // Enable the PWM
WiredHome 19:3f82c1161fd2 2115 WriteData(0x80);
WiredHome 175:7be3a1fb7fc2 2116 WriteCommand(RA8875_P1CR); // Not sure why this is needed, but following the pattern
WiredHome 19:3f82c1161fd2 2117 WriteData(0x81); // open PWM (SYS_CLK / 2 as best I can tell)
WiredHome 19:3f82c1161fd2 2118 is_enabled = true;
WiredHome 19:3f82c1161fd2 2119 }
WiredHome 175:7be3a1fb7fc2 2120 WriteCommand(RA8875_P1DCR, brightness); // Brightness parameter 0xff-0x00
WiredHome 19:3f82c1161fd2 2121 return noerror;
WiredHome 19:3f82c1161fd2 2122 }
WiredHome 19:3f82c1161fd2 2123
WiredHome 86:e86b355940f4 2124 uint8_t RA8875::GetBacklight_u8(void)
WiredHome 86:e86b355940f4 2125 {
WiredHome 86:e86b355940f4 2126 return ReadCommand(0x8b);
WiredHome 86:e86b355940f4 2127 }
WiredHome 44:207594dece70 2128
WiredHome 19:3f82c1161fd2 2129 RetCode_t RA8875::Backlight(float brightness)
WiredHome 19:3f82c1161fd2 2130 {
WiredHome 19:3f82c1161fd2 2131 unsigned char b;
WiredHome 73:f22a18707b5e 2132
WiredHome 29:422616aa04bd 2133 if (brightness >= 1.0)
WiredHome 19:3f82c1161fd2 2134 b = 255;
WiredHome 29:422616aa04bd 2135 else if (brightness <= 0.0)
WiredHome 19:3f82c1161fd2 2136 b = 0;
WiredHome 19:3f82c1161fd2 2137 else
WiredHome 19:3f82c1161fd2 2138 b = (unsigned char)(brightness * 255);
WiredHome 19:3f82c1161fd2 2139 return Backlight_u8(b);
WiredHome 19:3f82c1161fd2 2140 }
WiredHome 19:3f82c1161fd2 2141
WiredHome 86:e86b355940f4 2142 float RA8875::GetBacklight(void)
WiredHome 86:e86b355940f4 2143 {
WiredHome 86:e86b355940f4 2144 return (float)(GetBacklight_u8())/255;
WiredHome 86:e86b355940f4 2145 }
WiredHome 44:207594dece70 2146
WiredHome 98:ecebed9b80b2 2147 RetCode_t RA8875::SelectUserFont(const uint8_t * _font)
WiredHome 98:ecebed9b80b2 2148 {
WiredHome 178:ae472eb22740 2149 INFO("SelectUserFont(%p)", _font);
WiredHome 98:ecebed9b80b2 2150 if (_font) {
WiredHome 98:ecebed9b80b2 2151 HexDump("Font Memory", _font, 16);
WiredHome 98:ecebed9b80b2 2152 extFontHeight = _font[6];
WiredHome 98:ecebed9b80b2 2153 uint32_t totalWidth = 0;
WiredHome 98:ecebed9b80b2 2154 uint16_t firstChar = _font[3] * 256 + _font[2];
WiredHome 98:ecebed9b80b2 2155 uint16_t lastChar = _font[5] * 256 + _font[4];
WiredHome 98:ecebed9b80b2 2156 uint16_t i;
WiredHome 98:ecebed9b80b2 2157
WiredHome 98:ecebed9b80b2 2158 for (i=firstChar; i<=lastChar; i++) {
WiredHome 98:ecebed9b80b2 2159 // 8 bytes of preamble to the first level lookup table
WiredHome 98:ecebed9b80b2 2160 uint16_t offsetToCharLookup = 8 + 4 * (i - firstChar); // 4-bytes: width(pixels), 16-bit offset from table start, 0
WiredHome 98:ecebed9b80b2 2161 totalWidth += _font[offsetToCharLookup];
WiredHome 98:ecebed9b80b2 2162 }
WiredHome 98:ecebed9b80b2 2163 extFontWidth = totalWidth / (lastChar - firstChar);
WiredHome 98:ecebed9b80b2 2164 INFO("Font Metrics: Avg W: %2d, H: %2d, First:%d, Last:%d", extFontWidth, extFontHeight, firstChar, lastChar);
WiredHome 98:ecebed9b80b2 2165 }
WiredHome 98:ecebed9b80b2 2166 SetTextCursor(GetTextCursor_X(), GetTextCursor_Y()); // soft-font cursor -> hw cursor
WiredHome 98:ecebed9b80b2 2167 font = _font;
WiredHome 98:ecebed9b80b2 2168 return GraphicsDisplay::SelectUserFont(_font);
WiredHome 98:ecebed9b80b2 2169 }
WiredHome 44:207594dece70 2170
WiredHome 19:3f82c1161fd2 2171 RetCode_t RA8875::background(color_t color)
WiredHome 19:3f82c1161fd2 2172 {
WiredHome 37:f19b7e7449dc 2173 GraphicsDisplay::background(color);
WiredHome 133:e36dcfc2d756 2174 return _writeColorTrio(0x60, color);
WiredHome 19:3f82c1161fd2 2175 }
WiredHome 19:3f82c1161fd2 2176
WiredHome 44:207594dece70 2177
WiredHome 19:3f82c1161fd2 2178 RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 2179 {
WiredHome 37:f19b7e7449dc 2180 background(RGB(r,g,b));
WiredHome 19:3f82c1161fd2 2181 return noerror;
WiredHome 19:3f82c1161fd2 2182 }
WiredHome 19:3f82c1161fd2 2183
WiredHome 44:207594dece70 2184
WiredHome 19:3f82c1161fd2 2185 RetCode_t RA8875::foreground(color_t color)
WiredHome 19:3f82c1161fd2 2186 {
WiredHome 37:f19b7e7449dc 2187 GraphicsDisplay::foreground(color);
WiredHome 133:e36dcfc2d756 2188 return _writeColorTrio(0x63, color);
WiredHome 19:3f82c1161fd2 2189 }
WiredHome 19:3f82c1161fd2 2190
WiredHome 44:207594dece70 2191
WiredHome 37:f19b7e7449dc 2192 RetCode_t RA8875::foreground(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 2193 {
WiredHome 37:f19b7e7449dc 2194 foreground(RGB(r,g,b));
WiredHome 19:3f82c1161fd2 2195 return noerror;
WiredHome 19:3f82c1161fd2 2196 }
WiredHome 19:3f82c1161fd2 2197
WiredHome 44:207594dece70 2198
WiredHome 37:f19b7e7449dc 2199 color_t RA8875::GetForeColor(void)
WiredHome 19:3f82c1161fd2 2200 {
WiredHome 133:e36dcfc2d756 2201 return _readColorTrio(0x63);
WiredHome 19:3f82c1161fd2 2202 }
WiredHome 19:3f82c1161fd2 2203
WiredHome 44:207594dece70 2204
WiredHome 19:3f82c1161fd2 2205 color_t RA8875::DOSColor(int i)
WiredHome 73:f22a18707b5e 2206 {
WiredHome 73:f22a18707b5e 2207 const color_t colors[16] = {
WiredHome 19:3f82c1161fd2 2208 Black, Blue, Green, Cyan,
WiredHome 19:3f82c1161fd2 2209 Red, Magenta, Brown, Gray,
WiredHome 19:3f82c1161fd2 2210 Charcoal, BrightBlue, BrightGreen, BrightCyan,
WiredHome 19:3f82c1161fd2 2211 Orange, Pink, Yellow, White
WiredHome 73:f22a18707b5e 2212 };
WiredHome 85:022bba13c5c4 2213 if (i >= 0 && i < 16)
WiredHome 19:3f82c1161fd2 2214 return colors[i];
WiredHome 19:3f82c1161fd2 2215 else
WiredHome 19:3f82c1161fd2 2216 return 0;
WiredHome 73:f22a18707b5e 2217 }
WiredHome 19:3f82c1161fd2 2218
WiredHome 44:207594dece70 2219
WiredHome 73:f22a18707b5e 2220 const char * RA8875::DOSColorNames(int i)
WiredHome 73:f22a18707b5e 2221 {
WiredHome 73:f22a18707b5e 2222 const char * names[16] = {
WiredHome 19:3f82c1161fd2 2223 "Black", "Blue", "Green", "Cyan",
WiredHome 19:3f82c1161fd2 2224 "Red", "Magenta", "Brown", "Gray",
WiredHome 19:3f82c1161fd2 2225 "Charcoal", "BrightBlue", "BrightGreen", "BrightCyan",
WiredHome 19:3f82c1161fd2 2226 "Orange", "Pink", "Yellow", "White"
WiredHome 73:f22a18707b5e 2227 };
WiredHome 85:022bba13c5c4 2228 if (i >= 0 && i < 16)
WiredHome 19:3f82c1161fd2 2229 return names[i];
WiredHome 19:3f82c1161fd2 2230 else
WiredHome 19:3f82c1161fd2 2231 return NULL;
WiredHome 73:f22a18707b5e 2232 }
WiredHome 19:3f82c1161fd2 2233
WiredHome 19:3f82c1161fd2 2234
WiredHome 19:3f82c1161fd2 2235 ///////////////////////////////////////////////////////////////
WiredHome 19:3f82c1161fd2 2236 // Private functions
WiredHome 19:3f82c1161fd2 2237
WiredHome 79:544eb4964795 2238 unsigned char RA8875::_spiwrite(unsigned char data)
WiredHome 19:3f82c1161fd2 2239 {
WiredHome 19:3f82c1161fd2 2240 unsigned char retval;
WiredHome 73:f22a18707b5e 2241
WiredHome 68:ab08efabfc88 2242 if (!spiWriteSpeed)
WiredHome 68:ab08efabfc88 2243 _setWriteSpeed(true);
WiredHome 19:3f82c1161fd2 2244 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 2245 return retval;
WiredHome 19:3f82c1161fd2 2246 }
WiredHome 19:3f82c1161fd2 2247
WiredHome 44:207594dece70 2248
WiredHome 79:544eb4964795 2249 unsigned char RA8875::_spiread(void)
WiredHome 19:3f82c1161fd2 2250 {
WiredHome 19:3f82c1161fd2 2251 unsigned char retval;
WiredHome 19:3f82c1161fd2 2252 unsigned char data = 0;
WiredHome 73:f22a18707b5e 2253
WiredHome 68:ab08efabfc88 2254 if (spiWriteSpeed)
WiredHome 68:ab08efabfc88 2255 _setWriteSpeed(false);
WiredHome 19:3f82c1161fd2 2256 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 2257 return retval;
WiredHome 19:3f82c1161fd2 2258 }
WiredHome 19:3f82c1161fd2 2259
WiredHome 44:207594dece70 2260
WiredHome 79:544eb4964795 2261 RetCode_t RA8875::_select(bool chipsel)
WiredHome 19:3f82c1161fd2 2262 {
WiredHome 19:3f82c1161fd2 2263 cs = (chipsel == true) ? 0 : 1;
WiredHome 19:3f82c1161fd2 2264 return noerror;
WiredHome 19:3f82c1161fd2 2265 }
WiredHome 19:3f82c1161fd2 2266
WiredHome 44:207594dece70 2267
WiredHome 72:ecffe56af969 2268 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 2269 {
WiredHome 74:686faa218914 2270 (void)layer;
WiredHome 96:40b74dd3695b 2271
WiredHome 96:40b74dd3695b 2272 // AttachPrintHandler(this, RA8875::_printCallback);
WiredHome 96:40b74dd3695b 2273 // return PrintScreen(x,y,w,h);
WiredHome 74:686faa218914 2274 return PrintScreen(x, y, w, h, Name_BMP);
WiredHome 72:ecffe56af969 2275 }
WiredHome 72:ecffe56af969 2276
WiredHome 96:40b74dd3695b 2277 RetCode_t RA8875::_printCallback(RA8875::filecmd_t cmd, uint8_t * buffer, uint16_t size)
WiredHome 96:40b74dd3695b 2278 {
WiredHome 96:40b74dd3695b 2279 HexDump("CB", buffer, size);
WiredHome 96:40b74dd3695b 2280 switch(cmd) {
WiredHome 96:40b74dd3695b 2281 case RA8875::OPEN:
WiredHome 96:40b74dd3695b 2282 //pc.printf("About to write %lu bytes\r\n", *(uint32_t *)buffer);
WiredHome 96:40b74dd3695b 2283 _printFH = fopen("file.bmp", "w+b");
WiredHome 96:40b74dd3695b 2284 if (_printFH == 0)
WiredHome 96:40b74dd3695b 2285 return file_not_found;
WiredHome 96:40b74dd3695b 2286 break;
WiredHome 96:40b74dd3695b 2287 case RA8875::WRITE:
WiredHome 96:40b74dd3695b 2288 //pc.printf(" Write %4u bytes\r\n", size);
WiredHome 96:40b74dd3695b 2289 fwrite(buffer, 1, size, _printFH);
WiredHome 96:40b74dd3695b 2290 break;
WiredHome 96:40b74dd3695b 2291 case RA8875::CLOSE:
WiredHome 96:40b74dd3695b 2292 //pc.printf(" close\r\n");
WiredHome 96:40b74dd3695b 2293 fclose(_printFH);
WiredHome 96:40b74dd3695b 2294 _printFH = 0;
WiredHome 96:40b74dd3695b 2295 break;
WiredHome 96:40b74dd3695b 2296 default:
WiredHome 96:40b74dd3695b 2297 //pc.printf("Unexpected callback %d\r\n", cmd);
WiredHome 96:40b74dd3695b 2298 return file_not_found;
WiredHome 96:40b74dd3695b 2299 //break;
WiredHome 96:40b74dd3695b 2300 }
WiredHome 96:40b74dd3695b 2301 return noerror;
WiredHome 96:40b74dd3695b 2302 }
WiredHome 96:40b74dd3695b 2303
WiredHome 162:a2d7f1988711 2304 int RA8875::RoundUp(int value, int roundTo)
WiredHome 162:a2d7f1988711 2305 {
WiredHome 162:a2d7f1988711 2306 if (roundTo == 0)
WiredHome 162:a2d7f1988711 2307 return 0;
WiredHome 162:a2d7f1988711 2308 return ((value + roundTo - 1) / roundTo) * roundTo;
WiredHome 162:a2d7f1988711 2309 }
WiredHome 162:a2d7f1988711 2310
WiredHome 164:76edd7d9cb68 2311 RetCode_t RA8875::PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, uint8_t bitsPerPixel)
WiredHome 96:40b74dd3695b 2312 {
WiredHome 96:40b74dd3695b 2313 BITMAPFILEHEADER BMP_Header;
WiredHome 96:40b74dd3695b 2314 BITMAPINFOHEADER BMP_Info;
WiredHome 96:40b74dd3695b 2315 uint8_t * lineBuffer = NULL;
WiredHome 96:40b74dd3695b 2316 color_t * pixelBuffer = NULL;
WiredHome 96:40b74dd3695b 2317 color_t * pixelBuffer2 = NULL;
WiredHome 96:40b74dd3695b 2318
WiredHome 164:76edd7d9cb68 2319 INFO("(%d,%d)-(%d,%d)x%d", x,y,w,h,bitsPerPixel);
WiredHome 105:4f116006ba1f 2320 if (x >= 0 && x < screenwidth
WiredHome 105:4f116006ba1f 2321 && y >= 0 && y < screenheight
WiredHome 105:4f116006ba1f 2322 && w > 0 && x + w <= screenwidth
WiredHome 105:4f116006ba1f 2323 && h > 0 && y + h <= screenheight) {
WiredHome 96:40b74dd3695b 2324 BMP_Header.bfType = BF_TYPE;
WiredHome 96:40b74dd3695b 2325 BMP_Header.bfReserved1 = 0;
WiredHome 96:40b74dd3695b 2326 BMP_Header.bfReserved2 = 0;
WiredHome 164:76edd7d9cb68 2327 switch (bitsPerPixel) {
WiredHome 164:76edd7d9cb68 2328 case 24:
WiredHome 164:76edd7d9cb68 2329 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Info);
WiredHome 164:76edd7d9cb68 2330 BMP_Header.bfSize = (h * RoundUp(w * sizeof(RGBQUAD),4)) + BMP_Header.bfOffBits;
WiredHome 164:76edd7d9cb68 2331 break;
WiredHome 164:76edd7d9cb68 2332 case 8:
WiredHome 164:76edd7d9cb68 2333 default:
WiredHome 164:76edd7d9cb68 2334 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Info) + sizeof(WebColorPalette);
WiredHome 164:76edd7d9cb68 2335 INFO("Initial Offset to Bitstream %X", BMP_Header.bfOffBits);
WiredHome 164:76edd7d9cb68 2336 //if (BMP_Header.bfOffBits & 0x03) {
WiredHome 164:76edd7d9cb68 2337 // BMP_Header.bfOffBits += (4 - (BMP_Header.bfOffBits & 0x03));
WiredHome 164:76edd7d9cb68 2338 //}
WiredHome 164:76edd7d9cb68 2339 BMP_Header.bfSize = (h * RoundUp(w * 1,4)) + BMP_Header.bfOffBits;
WiredHome 164:76edd7d9cb68 2340 break;
WiredHome 164:76edd7d9cb68 2341 }
WiredHome 164:76edd7d9cb68 2342 INFO("Offset to Bitstream %X", BMP_Header.bfOffBits);
WiredHome 162:a2d7f1988711 2343
WiredHome 162:a2d7f1988711 2344 // Bytes in the line buffer
WiredHome 164:76edd7d9cb68 2345 int lineBufSize = RoundUp(((bitsPerPixel == 24) ? 3 : 1) * w, 4);
WiredHome 162:a2d7f1988711 2346 INFO("LineBufSize: %d", lineBufSize);
WiredHome 96:40b74dd3695b 2347
WiredHome 96:40b74dd3695b 2348 BMP_Info.biSize = sizeof(BMP_Info);
WiredHome 96:40b74dd3695b 2349 BMP_Info.biWidth = w;
WiredHome 96:40b74dd3695b 2350 BMP_Info.biHeight = h;
WiredHome 96:40b74dd3695b 2351 BMP_Info.biPlanes = 1;
WiredHome 164:76edd7d9cb68 2352 BMP_Info.biBitCount = bitsPerPixel;
WiredHome 96:40b74dd3695b 2353 BMP_Info.biCompression = BI_RGB;
WiredHome 162:a2d7f1988711 2354 BMP_Info.biSizeImage = lineBufSize * h;
WiredHome 96:40b74dd3695b 2355 BMP_Info.biXPelsPerMeter = 0;
WiredHome 96:40b74dd3695b 2356 BMP_Info.biYPelsPerMeter = 0;
WiredHome 164:76edd7d9cb68 2357 // for 24-bit, there is no palette, so these are zero
WiredHome 164:76edd7d9cb68 2358 // for 8-bit, there can be up to 256 RGB values in the palette
WiredHome 164:76edd7d9cb68 2359
WiredHome 164:76edd7d9cb68 2360 BMP_Info.biClrUsed = (bitsPerPixel == 24) ? 0 : sizeof(WebColorPalette)/sizeof(WebColorPalette[0]); // for 8b/pixel
WiredHome 164:76edd7d9cb68 2361 BMP_Info.biClrImportant = BMP_Info.biClrUsed;
WiredHome 96:40b74dd3695b 2362
WiredHome 96:40b74dd3695b 2363 // Allocate the memory we need to proceed
WiredHome 145:5eb2492acdda 2364 lineBuffer = (uint8_t *)swMalloc(lineBufSize);
WiredHome 96:40b74dd3695b 2365 if (lineBuffer == NULL) {
WiredHome 96:40b74dd3695b 2366 ERR("Not enough RAM for PrintScreen lineBuffer");
WiredHome 96:40b74dd3695b 2367 return(not_enough_ram);
WiredHome 96:40b74dd3695b 2368 }
WiredHome 162:a2d7f1988711 2369 memset(lineBuffer, 0, lineBufSize); // zero-Fill
WiredHome 96:40b74dd3695b 2370
WiredHome 96:40b74dd3695b 2371 #define DOUBLEBUF /* one larger buffer instead of two */
WiredHome 96:40b74dd3695b 2372
WiredHome 96:40b74dd3695b 2373 #ifdef DOUBLEBUF
WiredHome 96:40b74dd3695b 2374 // In the "#else", pixelBuffer2 malloc returns a value,
WiredHome 96:40b74dd3695b 2375 // but is actually causing a failure later.
WiredHome 96:40b74dd3695b 2376 // This test helps determine if it is truly out of memory,
WiredHome 96:40b74dd3695b 2377 // or if malloc is broken.
WiredHome 145:5eb2492acdda 2378 pixelBuffer = (color_t *)swMalloc(2 * w * sizeof(color_t));
WiredHome 96:40b74dd3695b 2379 pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
WiredHome 96:40b74dd3695b 2380 #else
WiredHome 145:5eb2492acdda 2381 pixelBuffer = (color_t *)swMalloc(w * sizeof(color_t));
WiredHome 145:5eb2492acdda 2382 pixelBuffer2 = (color_t *)swMalloc(w * sizeof(color_t));
WiredHome 96:40b74dd3695b 2383 #endif
WiredHome 96:40b74dd3695b 2384 if (pixelBuffer == NULL || pixelBuffer2 == NULL) {
WiredHome 96:40b74dd3695b 2385 ERR("Not enough RAM for pixelBuffer");
WiredHome 96:40b74dd3695b 2386 #ifndef DOUBLEBUF
WiredHome 96:40b74dd3695b 2387 if (pixelBuffer2)
WiredHome 145:5eb2492acdda 2388 swFree(pixelBuffer2);
WiredHome 96:40b74dd3695b 2389 #endif
WiredHome 96:40b74dd3695b 2390 if (pixelBuffer)
WiredHome 145:5eb2492acdda 2391 swFree(pixelBuffer);
WiredHome 145:5eb2492acdda 2392 swFree(lineBuffer);
WiredHome 96:40b74dd3695b 2393 return(not_enough_ram);
WiredHome 96:40b74dd3695b 2394 }
WiredHome 96:40b74dd3695b 2395
WiredHome 96:40b74dd3695b 2396 // Get the file primed...
WiredHome 164:76edd7d9cb68 2397 /// @todo check return value for possibility of a fatal error
WiredHome 96:40b74dd3695b 2398 privateCallback(OPEN, (uint8_t *)&BMP_Header.bfSize, 4);
WiredHome 96:40b74dd3695b 2399
WiredHome 96:40b74dd3695b 2400 // Be optimistic - don't check for errors.
WiredHome 162:a2d7f1988711 2401 HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 96:40b74dd3695b 2402 //fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image);
WiredHome 96:40b74dd3695b 2403 privateCallback(WRITE, (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 96:40b74dd3695b 2404
WiredHome 96:40b74dd3695b 2405 HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 96:40b74dd3695b 2406 //fwrite(&BMP_Info, sizeof(char), sizeof(BMP_Info), Image);
WiredHome 96:40b74dd3695b 2407 privateCallback(WRITE, (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 164:76edd7d9cb68 2408 if (bitsPerPixel != 24) {
WiredHome 164:76edd7d9cb68 2409 HexDump("Palette", (uint8_t *)&WebColorPalette, sizeof(WebColorPalette));
WiredHome 164:76edd7d9cb68 2410 //fwrite(&WebColorPalette, sizeof(char), sizeof(WebColorPalette), Image);
WiredHome 164:76edd7d9cb68 2411 privateCallback(WRITE, (uint8_t *)&WebColorPalette, sizeof(WebColorPalette));
WiredHome 164:76edd7d9cb68 2412 if (0 && sizeof(WebColorPalette) % 4) {
WiredHome 164:76edd7d9cb68 2413 const uint8_t padd[] = { 0, 0, 0 };
WiredHome 164:76edd7d9cb68 2414 //fwrite(&padd, sizeof(char), (sizeof(BMP_Header) + sizeof(BMP_Info) + sizeof(WebColorPalette)) % 4, Image);
WiredHome 164:76edd7d9cb68 2415 privateCallback(WRITE, (uint8_t *)&padd, (sizeof(BMP_Header) + sizeof(BMP_Info) + sizeof(WebColorPalette)) % 4);
WiredHome 164:76edd7d9cb68 2416 }
WiredHome 164:76edd7d9cb68 2417 }
WiredHome 96:40b74dd3695b 2418 //color_t transparency = GetBackgroundTransparencyColor();
WiredHome 96:40b74dd3695b 2419 LayerMode_T ltpr0 = GetLayerMode();
WiredHome 96:40b74dd3695b 2420
WiredHome 96:40b74dd3695b 2421 uint16_t prevLayer = GetDrawingLayer();
WiredHome 96:40b74dd3695b 2422 // If only one of the layers is visible, select that layer
WiredHome 96:40b74dd3695b 2423 switch(ltpr0) {
WiredHome 96:40b74dd3695b 2424 case ShowLayer0:
WiredHome 96:40b74dd3695b 2425 SelectDrawingLayer(0);
WiredHome 96:40b74dd3695b 2426 break;
WiredHome 96:40b74dd3695b 2427 case ShowLayer1:
WiredHome 96:40b74dd3695b 2428 SelectDrawingLayer(1);
WiredHome 96:40b74dd3695b 2429 break;
WiredHome 96:40b74dd3695b 2430 default:
WiredHome 96:40b74dd3695b 2431 break;
WiredHome 96:40b74dd3695b 2432 }
WiredHome 96:40b74dd3695b 2433
WiredHome 96:40b74dd3695b 2434 // Read the display from the last line toward the top
WiredHome 96:40b74dd3695b 2435 // so we can write the file in one pass.
WiredHome 96:40b74dd3695b 2436 for (int j = h - 1; j >= 0; j--) {
WiredHome 149:c62c4b2d6a15 2437 if (idle_callback) {
WiredHome 149:c62c4b2d6a15 2438 (*idle_callback)(progress, (h - 1 - j) * 100 / (h - 1));
WiredHome 149:c62c4b2d6a15 2439 }
WiredHome 149:c62c4b2d6a15 2440
WiredHome 96:40b74dd3695b 2441 if (ltpr0 >= 2) // Need to combine the layers...
WiredHome 96:40b74dd3695b 2442 SelectDrawingLayer(0); // so read layer 0 first
WiredHome 96:40b74dd3695b 2443 // Read one line of pixels to a local buffer
WiredHome 96:40b74dd3695b 2444 if (getPixelStream(pixelBuffer, w, x,y+j) != noerror) {
WiredHome 96:40b74dd3695b 2445 ERR("getPixelStream error, and no recovery handler...");
WiredHome 96:40b74dd3695b 2446 }
WiredHome 96:40b74dd3695b 2447 if (ltpr0 >= 2) { // Need to combine the layers...
WiredHome 96:40b74dd3695b 2448 SelectDrawingLayer(1); // so read layer 1 next
WiredHome 96:40b74dd3695b 2449 if (getPixelStream(pixelBuffer2, w, x,y+j) != noerror) {
WiredHome 96:40b74dd3695b 2450 ERR("getPixelStream error, and no recovery handler...");
WiredHome 96:40b74dd3695b 2451 }
WiredHome 96:40b74dd3695b 2452 }
WiredHome 164:76edd7d9cb68 2453 INFO("Line: %3d", j);
WiredHome 164:76edd7d9cb68 2454 //HexDump("Raster", (uint8_t *)pixelBuffer, w * sizeof(color_t));
WiredHome 96:40b74dd3695b 2455 // Convert the local buffer to RGBQUAD format
WiredHome 96:40b74dd3695b 2456 int lb = 0;
WiredHome 96:40b74dd3695b 2457 for (int i=0; i<w; i++) {
WiredHome 162:a2d7f1988711 2458 color_t tColor = pixelBuffer[x+i];
WiredHome 162:a2d7f1988711 2459 tColor = (tColor >> 8) | (tColor << 8); // Byte Swap
WiredHome 162:a2d7f1988711 2460 RGBQUAD q0 = RGB16ToRGBQuad(tColor); // Scale to 24-bits
WiredHome 162:a2d7f1988711 2461 tColor = pixelBuffer2[x+i];
WiredHome 162:a2d7f1988711 2462 tColor = (tColor >> 8) | (tColor << 8); // Byte Swap
WiredHome 162:a2d7f1988711 2463 RGBQUAD q1 = RGB16ToRGBQuad(tColor); // Scale to 24-bits
WiredHome 96:40b74dd3695b 2464 switch (ltpr0) {
WiredHome 96:40b74dd3695b 2465 case 0:
WiredHome 96:40b74dd3695b 2466 case 1:
WiredHome 96:40b74dd3695b 2467 case 2: // lighten-overlay (@TODO Not supported yet)
WiredHome 96:40b74dd3695b 2468 case 6: // Floating Windows (@TODO not sure how to support)
WiredHome 96:40b74dd3695b 2469 default: // Reserved...
WiredHome 164:76edd7d9cb68 2470 //lineBuffer[lb++] = q0.rgbBlue;
WiredHome 164:76edd7d9cb68 2471 //lineBuffer[lb++] = q0.rgbGreen;
WiredHome 164:76edd7d9cb68 2472 //lineBuffer[lb++] = q0.rgbRed;
WiredHome 164:76edd7d9cb68 2473 break;
WiredHome 164:76edd7d9cb68 2474 case 3: // transparent mode (@TODO Read the background color register for transparent)
WiredHome 164:76edd7d9cb68 2475 case 4: // boolean or
WiredHome 164:76edd7d9cb68 2476 q0.rgbBlue = q0.rgbBlue | q1.rgbBlue;
WiredHome 164:76edd7d9cb68 2477 q0.rgbGreen = q0.rgbGreen | q1.rgbGreen;
WiredHome 164:76edd7d9cb68 2478 q0.rgbRed = q0.rgbRed | q1.rgbRed;
WiredHome 164:76edd7d9cb68 2479 break;
WiredHome 164:76edd7d9cb68 2480 case 5: // boolean AND
WiredHome 164:76edd7d9cb68 2481 q0.rgbBlue = q0.rgbBlue & q1.rgbBlue;
WiredHome 164:76edd7d9cb68 2482 q0.rgbGreen = q0.rgbGreen & q1.rgbGreen;
WiredHome 164:76edd7d9cb68 2483 q0.rgbRed = q0.rgbRed & q1.rgbRed;
WiredHome 164:76edd7d9cb68 2484 break;
WiredHome 164:76edd7d9cb68 2485 }
WiredHome 164:76edd7d9cb68 2486 switch (bitsPerPixel) {
WiredHome 164:76edd7d9cb68 2487 case 24:
WiredHome 96:40b74dd3695b 2488 lineBuffer[lb++] = q0.rgbBlue;
WiredHome 96:40b74dd3695b 2489 lineBuffer[lb++] = q0.rgbGreen;
WiredHome 96:40b74dd3695b 2490 lineBuffer[lb++] = q0.rgbRed;
WiredHome 96:40b74dd3695b 2491 break;
WiredHome 164:76edd7d9cb68 2492 case 8:
WiredHome 164:76edd7d9cb68 2493 default:
WiredHome 164:76edd7d9cb68 2494 lineBuffer[lb++] = FindNearestWebColor(q0.rgbRed,q0.rgbGreen,q0.rgbBlue);
WiredHome 96:40b74dd3695b 2495 break;
WiredHome 96:40b74dd3695b 2496 }
WiredHome 96:40b74dd3695b 2497 }
WiredHome 164:76edd7d9cb68 2498 //if (j == h - 1) {
WiredHome 164:76edd7d9cb68 2499 // HexDump("Line", lineBuffer, lineBufSize);
WiredHome 164:76edd7d9cb68 2500 //}
WiredHome 96:40b74dd3695b 2501 // Write to disk
WiredHome 162:a2d7f1988711 2502 privateCallback(WRITE, (uint8_t *)lineBuffer, lineBufSize);
WiredHome 96:40b74dd3695b 2503 }
WiredHome 96:40b74dd3695b 2504 SelectDrawingLayer(prevLayer);
WiredHome 96:40b74dd3695b 2505 privateCallback(CLOSE, NULL, 0);
WiredHome 96:40b74dd3695b 2506 #ifndef DOUBLEBUF
WiredHome 96:40b74dd3695b 2507 if (pixelBuffer2)
WiredHome 145:5eb2492acdda 2508 swFree(pixelBuffer2);
WiredHome 96:40b74dd3695b 2509 #endif
WiredHome 96:40b74dd3695b 2510 if (pixelBuffer)
WiredHome 145:5eb2492acdda 2511 swFree(pixelBuffer);
WiredHome 145:5eb2492acdda 2512 swFree(lineBuffer);
WiredHome 96:40b74dd3695b 2513 INFO("Image closed");
WiredHome 96:40b74dd3695b 2514 return noerror;
WiredHome 96:40b74dd3695b 2515 } else {
WiredHome 96:40b74dd3695b 2516 return bad_parameter;
WiredHome 96:40b74dd3695b 2517 }
WiredHome 96:40b74dd3695b 2518 }
WiredHome 79:544eb4964795 2519
WiredHome 163:17526689a3ed 2520
WiredHome 164:76edd7d9cb68 2521
WiredHome 163:17526689a3ed 2522 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 2523 {
WiredHome 72:ecffe56af969 2524 BITMAPFILEHEADER BMP_Header;
WiredHome 72:ecffe56af969 2525 BITMAPINFOHEADER BMP_Info;
WiredHome 86:e86b355940f4 2526 uint8_t * lineBuffer = NULL;
WiredHome 86:e86b355940f4 2527 color_t * pixelBuffer = NULL;
WiredHome 86:e86b355940f4 2528 color_t * pixelBuffer2 = NULL;
WiredHome 86:e86b355940f4 2529
WiredHome 163:17526689a3ed 2530 INFO("(%d,%d)-(%d,%d)x%d %s", x,y,w,h,bitsPerPixel,Name_BMP);
WiredHome 105:4f116006ba1f 2531 if (x >= 0 && x < screenwidth
WiredHome 105:4f116006ba1f 2532 && y >= 0 && y < screenheight
WiredHome 105:4f116006ba1f 2533 && w > 0 && x + w <= screenwidth
WiredHome 105:4f116006ba1f 2534 && h > 0 && y + h <= screenheight) {
WiredHome 72:ecffe56af969 2535 BMP_Header.bfType = BF_TYPE;
WiredHome 72:ecffe56af969 2536 BMP_Header.bfReserved1 = 0;
WiredHome 72:ecffe56af969 2537 BMP_Header.bfReserved2 = 0;
WiredHome 163:17526689a3ed 2538 switch (bitsPerPixel) {
WiredHome 163:17526689a3ed 2539 case 24:
WiredHome 163:17526689a3ed 2540 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Info);
WiredHome 163:17526689a3ed 2541 BMP_Header.bfSize = (h * RoundUp(w * sizeof(RGBQUAD),4)) + BMP_Header.bfOffBits;
WiredHome 163:17526689a3ed 2542 break;
WiredHome 163:17526689a3ed 2543 case 8:
WiredHome 163:17526689a3ed 2544 default:
WiredHome 163:17526689a3ed 2545 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Info) + sizeof(WebColorPalette);
WiredHome 163:17526689a3ed 2546 INFO("Initial Offset to Bitstream %X", BMP_Header.bfOffBits);
WiredHome 163:17526689a3ed 2547 //if (BMP_Header.bfOffBits & 0x03) {
WiredHome 163:17526689a3ed 2548 // BMP_Header.bfOffBits += (4 - (BMP_Header.bfOffBits & 0x03));
WiredHome 163:17526689a3ed 2549 //}
WiredHome 163:17526689a3ed 2550 BMP_Header.bfSize = (h * RoundUp(w * 1,4)) + BMP_Header.bfOffBits;
WiredHome 163:17526689a3ed 2551 break;
WiredHome 163:17526689a3ed 2552 }
WiredHome 163:17526689a3ed 2553 INFO("Offset to Bitstream %X", BMP_Header.bfOffBits);
WiredHome 162:a2d7f1988711 2554
WiredHome 162:a2d7f1988711 2555 // Bytes in the line buffer
WiredHome 163:17526689a3ed 2556 int lineBufSize = RoundUp(((bitsPerPixel == 24) ? 3 : 1) * w, 4);
WiredHome 162:a2d7f1988711 2557 INFO("LineBufSize: %d", lineBufSize);
WiredHome 73:f22a18707b5e 2558
WiredHome 72:ecffe56af969 2559 BMP_Info.biSize = sizeof(BMP_Info);
WiredHome 72:ecffe56af969 2560 BMP_Info.biWidth = w;
WiredHome 72:ecffe56af969 2561 BMP_Info.biHeight = h;
WiredHome 72:ecffe56af969 2562 BMP_Info.biPlanes = 1;
WiredHome 163:17526689a3ed 2563 BMP_Info.biBitCount = bitsPerPixel;
WiredHome 72:ecffe56af969 2564 BMP_Info.biCompression = BI_RGB;
WiredHome 162:a2d7f1988711 2565 BMP_Info.biSizeImage = lineBufSize * h;
WiredHome 72:ecffe56af969 2566 BMP_Info.biXPelsPerMeter = 0;
WiredHome 72:ecffe56af969 2567 BMP_Info.biYPelsPerMeter = 0;
WiredHome 163:17526689a3ed 2568 // for 24-bit, there is no palette, so these are zero
WiredHome 163:17526689a3ed 2569 // for 8-bit, there can be up to 256 RGB values in the palette
WiredHome 163:17526689a3ed 2570
WiredHome 163:17526689a3ed 2571 BMP_Info.biClrUsed = (bitsPerPixel == 24) ? 0 : sizeof(WebColorPalette)/sizeof(WebColorPalette[0]); // for 8b/pixel
WiredHome 163:17526689a3ed 2572 BMP_Info.biClrImportant = BMP_Info.biClrUsed;
WiredHome 72:ecffe56af969 2573
WiredHome 86:e86b355940f4 2574 // Allocate the memory we need to proceed
WiredHome 145:5eb2492acdda 2575 lineBuffer = (uint8_t *)swMalloc(lineBufSize);
WiredHome 86:e86b355940f4 2576 if (lineBuffer == NULL) {
WiredHome 86:e86b355940f4 2577 ERR("Not enough RAM for PrintScreen lineBuffer");
WiredHome 86:e86b355940f4 2578 return(not_enough_ram);
WiredHome 86:e86b355940f4 2579 }
WiredHome 162:a2d7f1988711 2580 memset(lineBuffer, 0, lineBufSize); // zero-Fill
WiredHome 86:e86b355940f4 2581
WiredHome 86:e86b355940f4 2582 #define DOUBLEBUF /* one larger buffer instead of two */
WiredHome 86:e86b355940f4 2583
WiredHome 86:e86b355940f4 2584 #ifdef DOUBLEBUF
WiredHome 86:e86b355940f4 2585 // In the "#else", pixelBuffer2 malloc returns a value,
WiredHome 86:e86b355940f4 2586 // but is actually causing a failure later.
WiredHome 86:e86b355940f4 2587 // This test helps determine if it is truly out of memory,
WiredHome 86:e86b355940f4 2588 // or if malloc is broken.
WiredHome 145:5eb2492acdda 2589 pixelBuffer = (color_t *)swMalloc(2 * w * sizeof(color_t));
WiredHome 86:e86b355940f4 2590 pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
WiredHome 86:e86b355940f4 2591 #else
WiredHome 145:5eb2492acdda 2592 pixelBuffer = (color_t *)swMalloc(w * sizeof(color_t));
WiredHome 145:5eb2492acdda 2593 pixelBuffer2 = (color_t *)swMalloc(w * sizeof(color_t));
WiredHome 86:e86b355940f4 2594 #endif
WiredHome 86:e86b355940f4 2595 if (pixelBuffer == NULL || pixelBuffer2 == NULL) {
WiredHome 86:e86b355940f4 2596 ERR("Not enough RAM for pixelBuffer");
WiredHome 86:e86b355940f4 2597 #ifndef DOUBLEBUF
WiredHome 86:e86b355940f4 2598 if (pixelBuffer2)
WiredHome 145:5eb2492acdda 2599 swFree(pixelBuffer2);
WiredHome 86:e86b355940f4 2600 #endif
WiredHome 86:e86b355940f4 2601 if (pixelBuffer)
WiredHome 145:5eb2492acdda 2602 swFree(pixelBuffer);
WiredHome 145:5eb2492acdda 2603 swFree(lineBuffer);
WiredHome 86:e86b355940f4 2604 return(not_enough_ram);
WiredHome 86:e86b355940f4 2605 }
WiredHome 86:e86b355940f4 2606
WiredHome 72:ecffe56af969 2607 FILE *Image = fopen(Name_BMP, "wb");
WiredHome 72:ecffe56af969 2608 if (!Image) {
WiredHome 86:e86b355940f4 2609 ERR("Can't open file for write");
WiredHome 86:e86b355940f4 2610 #ifndef DOUBLEBUF
WiredHome 86:e86b355940f4 2611 if (pixelBuffer2)
WiredHome 145:5eb2492acdda 2612 swFree(pixelBuffer2);
WiredHome 86:e86b355940f4 2613 #endif
WiredHome 86:e86b355940f4 2614 if (pixelBuffer)
WiredHome 145:5eb2492acdda 2615 swFree(pixelBuffer);
WiredHome 145:5eb2492acdda 2616 swFree(lineBuffer);
WiredHome 72:ecffe56af969 2617 return(file_not_found);
WiredHome 72:ecffe56af969 2618 }
WiredHome 72:ecffe56af969 2619
WiredHome 72:ecffe56af969 2620 // Be optimistic - don't check for errors.
WiredHome 93:6fbc516de05e 2621 HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 95:ef538bd687c0 2622 fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image);
WiredHome 73:f22a18707b5e 2623
WiredHome 93:6fbc516de05e 2624 HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 95:ef538bd687c0 2625 fwrite(&BMP_Info, sizeof(char), sizeof(BMP_Info), Image);
WiredHome 163:17526689a3ed 2626
WiredHome 163:17526689a3ed 2627 if (bitsPerPixel != 24) {
WiredHome 163:17526689a3ed 2628 HexDump("Palette", (uint8_t *)&WebColorPalette, sizeof(WebColorPalette));
WiredHome 163:17526689a3ed 2629 fwrite(&WebColorPalette, sizeof(char), sizeof(WebColorPalette), Image);
WiredHome 163:17526689a3ed 2630 if (0 && sizeof(WebColorPalette) % 4) {
WiredHome 163:17526689a3ed 2631 const uint8_t padd[] = { 0, 0, 0 };
WiredHome 163:17526689a3ed 2632 fwrite(&padd, sizeof(char),
WiredHome 163:17526689a3ed 2633 (sizeof(BMP_Header) + sizeof(BMP_Info) + sizeof(WebColorPalette)) % 4, Image);
WiredHome 163:17526689a3ed 2634 }
WiredHome 163:17526689a3ed 2635 }
WiredHome 95:ef538bd687c0 2636 //color_t transparency = GetBackgroundTransparencyColor();
WiredHome 95:ef538bd687c0 2637 LayerMode_T ltpr0 = GetLayerMode();
WiredHome 73:f22a18707b5e 2638
WiredHome 73:f22a18707b5e 2639 uint16_t prevLayer = GetDrawingLayer();
WiredHome 73:f22a18707b5e 2640 // If only one of the layers is visible, select that layer
WiredHome 73:f22a18707b5e 2641 switch(ltpr0) {
WiredHome 95:ef538bd687c0 2642 case ShowLayer0:
WiredHome 73:f22a18707b5e 2643 SelectDrawingLayer(0);
WiredHome 73:f22a18707b5e 2644 break;
WiredHome 95:ef538bd687c0 2645 case ShowLayer1:
WiredHome 73:f22a18707b5e 2646 SelectDrawingLayer(1);
WiredHome 73:f22a18707b5e 2647 break;
WiredHome 73:f22a18707b5e 2648 default:
WiredHome 73:f22a18707b5e 2649 break;
WiredHome 73:f22a18707b5e 2650 }
WiredHome 73:f22a18707b5e 2651
WiredHome 72:ecffe56af969 2652 // Read the display from the last line toward the top
WiredHome 72:ecffe56af969 2653 // so we can write the file in one pass.
WiredHome 72:ecffe56af969 2654 for (int j = h - 1; j >= 0; j--) {
WiredHome 149:c62c4b2d6a15 2655 if (idle_callback) {
WiredHome 149:c62c4b2d6a15 2656 (*idle_callback)(progress, (h - 1 - j) * 100 / (h - 1));
WiredHome 149:c62c4b2d6a15 2657 }
WiredHome 149:c62c4b2d6a15 2658
WiredHome 73:f22a18707b5e 2659 if (ltpr0 >= 2) // Need to combine the layers...
WiredHome 73:f22a18707b5e 2660 SelectDrawingLayer(0); // so read layer 0 first
WiredHome 72:ecffe56af969 2661 // Read one line of pixels to a local buffer
WiredHome 72:ecffe56af969 2662 if (getPixelStream(pixelBuffer, w, x,y+j) != noerror) {
WiredHome 72:ecffe56af969 2663 ERR("getPixelStream error, and no recovery handler...");
WiredHome 72:ecffe56af969 2664 }
WiredHome 73:f22a18707b5e 2665 if (ltpr0 >= 2) { // Need to combine the layers...
WiredHome 86:e86b355940f4 2666 SelectDrawingLayer(1); // so read layer 1 next
WiredHome 73:f22a18707b5e 2667 if (getPixelStream(pixelBuffer2, w, x,y+j) != noerror) {
WiredHome 73:f22a18707b5e 2668 ERR("getPixelStream error, and no recovery handler...");
WiredHome 73:f22a18707b5e 2669 }
WiredHome 73:f22a18707b5e 2670 }
WiredHome 162:a2d7f1988711 2671 INFO("Line: %3d", j);
WiredHome 163:17526689a3ed 2672 //HexDump("Raster", (uint8_t *)pixelBuffer, w * sizeof(color_t));
WiredHome 72:ecffe56af969 2673 // Convert the local buffer to RGBQUAD format
WiredHome 72:ecffe56af969 2674 int lb = 0;
WiredHome 72:ecffe56af969 2675 for (int i=0; i<w; i++) {
WiredHome 162:a2d7f1988711 2676 color_t tColor = pixelBuffer[x+i];
WiredHome 162:a2d7f1988711 2677 tColor = (tColor >> 8) | (tColor << 8); // Byte Swap
WiredHome 162:a2d7f1988711 2678 RGBQUAD q0 = RGB16ToRGBQuad(tColor); // Scale to 24-bits
WiredHome 162:a2d7f1988711 2679 tColor = pixelBuffer2[x+i];
WiredHome 162:a2d7f1988711 2680 tColor = (tColor >> 8) | (tColor << 8); // Byte Swap
WiredHome 162:a2d7f1988711 2681 RGBQUAD q1 = RGB16ToRGBQuad(tColor); // Scale to 24-bits
WiredHome 73:f22a18707b5e 2682 switch (ltpr0) {
WiredHome 73:f22a18707b5e 2683 case 0:
WiredHome 73:f22a18707b5e 2684 case 1:
WiredHome 73:f22a18707b5e 2685 case 2: // lighten-overlay (@TODO Not supported yet)
WiredHome 73:f22a18707b5e 2686 case 6: // Floating Windows (@TODO not sure how to support)
WiredHome 73:f22a18707b5e 2687 default: // Reserved...
WiredHome 163:17526689a3ed 2688 //lineBuffer[lb++] = q0.rgbBlue;
WiredHome 163:17526689a3ed 2689 //lineBuffer[lb++] = q0.rgbGreen;
WiredHome 163:17526689a3ed 2690 //lineBuffer[lb++] = q0.rgbRed;
WiredHome 163:17526689a3ed 2691 break;
WiredHome 163:17526689a3ed 2692 case 3: // transparent mode (@TODO Read the background color register for transparent)
WiredHome 163:17526689a3ed 2693 case 4: // boolean or
WiredHome 163:17526689a3ed 2694 q0.rgbBlue = q0.rgbBlue | q1.rgbBlue;
WiredHome 163:17526689a3ed 2695 q0.rgbGreen = q0.rgbGreen | q1.rgbGreen;
WiredHome 163:17526689a3ed 2696 q0.rgbRed = q0.rgbRed | q1.rgbRed;
WiredHome 163:17526689a3ed 2697 break;
WiredHome 163:17526689a3ed 2698 case 5: // boolean AND
WiredHome 163:17526689a3ed 2699 q0.rgbBlue = q0.rgbBlue & q1.rgbBlue;
WiredHome 163:17526689a3ed 2700 q0.rgbGreen = q0.rgbGreen & q1.rgbGreen;
WiredHome 163:17526689a3ed 2701 q0.rgbRed = q0.rgbRed & q1.rgbRed;
WiredHome 163:17526689a3ed 2702 break;
WiredHome 163:17526689a3ed 2703 }
WiredHome 163:17526689a3ed 2704 switch (bitsPerPixel) {
WiredHome 163:17526689a3ed 2705 case 24:
WiredHome 73:f22a18707b5e 2706 lineBuffer[lb++] = q0.rgbBlue;
WiredHome 73:f22a18707b5e 2707 lineBuffer[lb++] = q0.rgbGreen;
WiredHome 73:f22a18707b5e 2708 lineBuffer[lb++] = q0.rgbRed;
WiredHome 73:f22a18707b5e 2709 break;
WiredHome 163:17526689a3ed 2710 case 8:
WiredHome 163:17526689a3ed 2711 default:
WiredHome 163:17526689a3ed 2712 lineBuffer[lb++] = FindNearestWebColor(q0.rgbRed,q0.rgbGreen,q0.rgbBlue);
WiredHome 73:f22a18707b5e 2713 break;
WiredHome 73:f22a18707b5e 2714 }
WiredHome 72:ecffe56af969 2715 }
WiredHome 162:a2d7f1988711 2716 //if (j == h - 1) {
WiredHome 163:17526689a3ed 2717 // HexDump("Line", lineBuffer, lineBufSize);
WiredHome 162:a2d7f1988711 2718 //}
WiredHome 72:ecffe56af969 2719 // Write to disk
WiredHome 162:a2d7f1988711 2720 fwrite(lineBuffer, sizeof(char), lineBufSize, Image);
WiredHome 72:ecffe56af969 2721 }
WiredHome 73:f22a18707b5e 2722 SelectDrawingLayer(prevLayer);
WiredHome 72:ecffe56af969 2723 fclose(Image);
WiredHome 86:e86b355940f4 2724 #ifndef DOUBLEBUF
WiredHome 86:e86b355940f4 2725 if (pixelBuffer2)
WiredHome 145:5eb2492acdda 2726 swFree(pixelBuffer2);
WiredHome 86:e86b355940f4 2727 #endif
WiredHome 86:e86b355940f4 2728 if (pixelBuffer)
WiredHome 145:5eb2492acdda 2729 swFree(pixelBuffer);
WiredHome 145:5eb2492acdda 2730 swFree(lineBuffer);
WiredHome 73:f22a18707b5e 2731 INFO("Image closed");
WiredHome 72:ecffe56af969 2732 return noerror;
WiredHome 72:ecffe56af969 2733 } else {
WiredHome 72:ecffe56af969 2734 return bad_parameter;
WiredHome 72:ecffe56af969 2735 }
WiredHome 72:ecffe56af969 2736 }
WiredHome 72:ecffe56af969 2737
WiredHome 72:ecffe56af969 2738
WiredHome 72:ecffe56af969 2739 // ##########################################################################
WiredHome 72:ecffe56af969 2740 // ##########################################################################
WiredHome 72:ecffe56af969 2741 // ##########################################################################
WiredHome 72:ecffe56af969 2742
WiredHome 23:a50ded45dbaf 2743 #ifdef TESTENABLE
WiredHome 23:a50ded45dbaf 2744
WiredHome 98:ecebed9b80b2 2745 #include "BPG_Arial08x08.h"
WiredHome 98:ecebed9b80b2 2746 #include "BPG_Arial20x20.h"
WiredHome 37:f19b7e7449dc 2747
WiredHome 23:a50ded45dbaf 2748 // ______________ ______________ ______________ _______________
WiredHome 23:a50ded45dbaf 2749 // /_____ _____/ / ___________/ / ___________/ /_____ ______/
WiredHome 23:a50ded45dbaf 2750 // / / / / / / / /
WiredHome 23:a50ded45dbaf 2751 // / / / /___ / /__________ / /
WiredHome 23:a50ded45dbaf 2752 // / / / ____/ /__________ / / /
WiredHome 23:a50ded45dbaf 2753 // / / / / / / / /
WiredHome 23:a50ded45dbaf 2754 // / / / /__________ ___________/ / / /
WiredHome 23:a50ded45dbaf 2755 // /__/ /_____________/ /_____________/ /__/
WiredHome 23:a50ded45dbaf 2756 //
WiredHome 23:a50ded45dbaf 2757 // Everything from here down is test code.
WiredHome 75:ca78388cfd77 2758 //
WiredHome 41:2956a0a221e5 2759 bool SuppressSlowStuff = false;
WiredHome 23:a50ded45dbaf 2760
WiredHome 49:c5182231d1b9 2761 void TextWrapTest(RA8875 & display, Serial & pc)
WiredHome 49:c5182231d1b9 2762 {
WiredHome 49:c5182231d1b9 2763 if (!SuppressSlowStuff)
WiredHome 49:c5182231d1b9 2764 pc.printf("Text Wrap Test\r\n");
WiredHome 49:c5182231d1b9 2765 display.background(Black);
WiredHome 49:c5182231d1b9 2766 display.foreground(Blue);
WiredHome 49:c5182231d1b9 2767 display.cls();
WiredHome 49:c5182231d1b9 2768 display.Backlight_u8(255);
WiredHome 100:0b084475d5a9 2769 display.puts("Text Wrap Test.\r\n");
WiredHome 52:e6039a823420 2770 for (int i=1; i<60; i++) {
WiredHome 52:e6039a823420 2771 display.printf("L%2d\n", i % 17);
WiredHome 49:c5182231d1b9 2772 if (!SuppressSlowStuff)
WiredHome 52:e6039a823420 2773 wait_ms(100);
WiredHome 49:c5182231d1b9 2774 }
WiredHome 49:c5182231d1b9 2775 if (!SuppressSlowStuff)
WiredHome 49:c5182231d1b9 2776 wait_ms(3000);
WiredHome 49:c5182231d1b9 2777 }
WiredHome 49:c5182231d1b9 2778
WiredHome 75:ca78388cfd77 2779
WiredHome 75:ca78388cfd77 2780 void ShowKey(RA8875 & display, int key)
WiredHome 75:ca78388cfd77 2781 {
WiredHome 75:ca78388cfd77 2782 loc_t col, row;
WiredHome 75:ca78388cfd77 2783 dim_t r1 = 25;
WiredHome 75:ca78388cfd77 2784 color_t color = (key & 0x80) ? Red : Green;
WiredHome 75:ca78388cfd77 2785
WiredHome 75:ca78388cfd77 2786 key &= 0x7F; // remove the long-press flag
WiredHome 75:ca78388cfd77 2787 row = (key - 1) / 5;
WiredHome 75:ca78388cfd77 2788 col = (key - 1) % 5;
WiredHome 75:ca78388cfd77 2789 if (col > 5) col = 5;
WiredHome 75:ca78388cfd77 2790 if (row > 4) row = 4;
WiredHome 75:ca78388cfd77 2791 display.circle(450 - + (2 * r1) * col, 200 - (2 * r1) * row, r1-2, color, FILL);
WiredHome 75:ca78388cfd77 2792 }
WiredHome 75:ca78388cfd77 2793
WiredHome 75:ca78388cfd77 2794 void HideKey(RA8875 & display, int key)
WiredHome 75:ca78388cfd77 2795 {
WiredHome 75:ca78388cfd77 2796 loc_t col, row;
WiredHome 75:ca78388cfd77 2797 dim_t r1 = 25;
WiredHome 75:ca78388cfd77 2798
WiredHome 75:ca78388cfd77 2799 row = (key - 1) / 5;
WiredHome 75:ca78388cfd77 2800 col = (key - 1) % 5;
WiredHome 75:ca78388cfd77 2801 if (col > 5) col = 5;
WiredHome 75:ca78388cfd77 2802 if (row > 4) row = 4;
WiredHome 75:ca78388cfd77 2803 display.background(Black);
WiredHome 75:ca78388cfd77 2804 display.circle(450 - (2 * r1) * col, 200 - (2 * r1) * row, r1-2, Black, FILL);
WiredHome 75:ca78388cfd77 2805 display.circle(450 - (2 * r1) * col, 200 - (2 * r1) * row, r1-2, Blue);
WiredHome 75:ca78388cfd77 2806 }
WiredHome 75:ca78388cfd77 2807
WiredHome 75:ca78388cfd77 2808 void KeyPadTest(RA8875 & display, Serial & pc)
WiredHome 75:ca78388cfd77 2809 {
WiredHome 75:ca78388cfd77 2810 const uint8_t myMap[22] = {
WiredHome 77:9206c13aa527 2811 0,
WiredHome 75:ca78388cfd77 2812 'a', 'b', 'c', 'd', 'e',
WiredHome 75:ca78388cfd77 2813 'f', 'g', 'h', 'i', 'j',
WiredHome 75:ca78388cfd77 2814 'k', 'l', 'm', 'n', 'o',
WiredHome 75:ca78388cfd77 2815 'p', 'q', 'r', 's', 't',
WiredHome 75:ca78388cfd77 2816 'x'
WiredHome 75:ca78388cfd77 2817 };
WiredHome 77:9206c13aa527 2818
WiredHome 75:ca78388cfd77 2819 display.background(Black);
WiredHome 75:ca78388cfd77 2820 display.foreground(Blue);
WiredHome 75:ca78388cfd77 2821 display.cls();
WiredHome 75:ca78388cfd77 2822 display.Backlight_u8(255);
WiredHome 100:0b084475d5a9 2823 display.puts("KeyPad Test. Touch the keypad...");
WiredHome 75:ca78388cfd77 2824 pc.printf("\r\n"
WiredHome 75:ca78388cfd77 2825 "Raw KeyPad Test. Keypad returns the key-number.\r\n"
WiredHome 75:ca78388cfd77 2826 "Press [most] any PC keyboard key to advance to next test.\r\n");
WiredHome 75:ca78388cfd77 2827 RetCode_t ret = display.KeypadInit(true, true, 3, 7, 3);
WiredHome 75:ca78388cfd77 2828 if (ret != noerror)
WiredHome 75:ca78388cfd77 2829 pc.printf("returncode from KeypadInit is %d\r\n", ret);
WiredHome 75:ca78388cfd77 2830 int lastKey = 0;
WiredHome 75:ca78388cfd77 2831 while (!pc.readable()) {
WiredHome 75:ca78388cfd77 2832 if (display.readable()) {
WiredHome 75:ca78388cfd77 2833 int key = display.getc();
WiredHome 75:ca78388cfd77 2834 if (key) {
WiredHome 75:ca78388cfd77 2835 if (((key & 0x7F) != lastKey) && (lastKey != 0))
WiredHome 75:ca78388cfd77 2836 HideKey(display, lastKey);
WiredHome 75:ca78388cfd77 2837 ShowKey(display, key);
WiredHome 75:ca78388cfd77 2838 lastKey = key & 0x7F;
WiredHome 75:ca78388cfd77 2839 } else {
WiredHome 75:ca78388cfd77 2840 // erase the last one
WiredHome 75:ca78388cfd77 2841 if (lastKey)
WiredHome 75:ca78388cfd77 2842 HideKey(display, lastKey);
WiredHome 75:ca78388cfd77 2843 }
WiredHome 75:ca78388cfd77 2844 }
WiredHome 75:ca78388cfd77 2845 }
WiredHome 75:ca78388cfd77 2846 (void)pc.getc();
WiredHome 75:ca78388cfd77 2847 pc.printf("\r\n"
WiredHome 75:ca78388cfd77 2848 "Map KeyPad Test. Keypad returns the remapped key 'a' - 't'.\r\n"
WiredHome 75:ca78388cfd77 2849 "Press [most] any PC keyboard key to advance to exit test.\r\n");
WiredHome 75:ca78388cfd77 2850 display.SetKeyMap(myMap);
WiredHome 75:ca78388cfd77 2851 while (!pc.readable()) {
WiredHome 75:ca78388cfd77 2852 if (display.readable()) {
WiredHome 75:ca78388cfd77 2853 int key = display.getc();
WiredHome 75:ca78388cfd77 2854 bool longPress = key & 0x80;
WiredHome 75:ca78388cfd77 2855 display.SetTextCursor(0, 120);
WiredHome 75:ca78388cfd77 2856 display.printf("Long Press: %d\r\n", longPress);
WiredHome 75:ca78388cfd77 2857 display.printf(" Remapped: %c %02X\r\n", (key) ? key & 0x7F : ' ', key);
WiredHome 75:ca78388cfd77 2858 }
WiredHome 75:ca78388cfd77 2859 }
WiredHome 75:ca78388cfd77 2860 (void)pc.getc();
WiredHome 75:ca78388cfd77 2861 display.SetKeyMap();
WiredHome 75:ca78388cfd77 2862 pc.printf("\r\n");
WiredHome 75:ca78388cfd77 2863 }
WiredHome 75:ca78388cfd77 2864
WiredHome 23:a50ded45dbaf 2865 void TextCursorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2866 {
WiredHome 75:ca78388cfd77 2867 const char * iCursor = "The I-Beam cursor should be visible for this text.\r\n";
WiredHome 75:ca78388cfd77 2868 const char * uCursor = "The Underscore cursor should be visible for this text.\r\n";
WiredHome 75:ca78388cfd77 2869 const char * bCursor = "The Block cursor should be visible for this text.\r\n";
WiredHome 37:f19b7e7449dc 2870 const char * bbCursor = "The Blinking Block cursor should be visible for this text.\r\n";
WiredHome 23:a50ded45dbaf 2871 const char * p;
WiredHome 100:0b084475d5a9 2872 int delay = 60;
WiredHome 73:f22a18707b5e 2873
WiredHome 41:2956a0a221e5 2874 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2875 pc.printf("Text Cursor Test\r\n");
WiredHome 73:f22a18707b5e 2876 else
WiredHome 41:2956a0a221e5 2877 delay = 0;
WiredHome 23:a50ded45dbaf 2878 display.background(Black);
WiredHome 23:a50ded45dbaf 2879 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2880 display.cls();
WiredHome 25:9556a3a9b7cc 2881 display.Backlight_u8(255);
WiredHome 100:0b084475d5a9 2882 display.puts("Text Cursor Test.");
WiredHome 73:f22a18707b5e 2883
WiredHome 23:a50ded45dbaf 2884 // visible, non-blinking
WiredHome 24:8ca861acf12d 2885 display.SetTextCursor(0,20);
WiredHome 53:86d24b9480b9 2886 display.SetTextCursorControl(RA8875::IBEAM, false);
WiredHome 24:8ca861acf12d 2887 p = iCursor;
WiredHome 23:a50ded45dbaf 2888 while (*p) {
WiredHome 24:8ca861acf12d 2889 display._putc(*p++);
WiredHome 41:2956a0a221e5 2890 wait_ms(delay);
WiredHome 24:8ca861acf12d 2891 }
WiredHome 24:8ca861acf12d 2892
WiredHome 53:86d24b9480b9 2893 display.SetTextCursorControl(RA8875::UNDER, false);
WiredHome 24:8ca861acf12d 2894 p = uCursor;
WiredHome 24:8ca861acf12d 2895 while (*p) {
WiredHome 24:8ca861acf12d 2896 display._putc(*p++);
WiredHome 41:2956a0a221e5 2897 wait_ms(delay);
WiredHome 23:a50ded45dbaf 2898 }
WiredHome 73:f22a18707b5e 2899
WiredHome 53:86d24b9480b9 2900 display.SetTextCursorControl(RA8875::BLOCK, false);
WiredHome 24:8ca861acf12d 2901 p = bCursor;
WiredHome 24:8ca861acf12d 2902 while (*p) {
WiredHome 24:8ca861acf12d 2903 display._putc(*p++);
WiredHome 41:2956a0a221e5 2904 wait_ms(delay);
WiredHome 24:8ca861acf12d 2905 }
WiredHome 24:8ca861acf12d 2906
WiredHome 53:86d24b9480b9 2907 display.SetTextCursorControl(RA8875::BLOCK, true);
WiredHome 24:8ca861acf12d 2908 p = bbCursor;
WiredHome 24:8ca861acf12d 2909 while (*p) {
WiredHome 24:8ca861acf12d 2910 display._putc(*p++);
WiredHome 41:2956a0a221e5 2911 wait_ms(delay);
WiredHome 24:8ca861acf12d 2912 }
WiredHome 41:2956a0a221e5 2913 wait_ms(delay * 20);
WiredHome 53:86d24b9480b9 2914 display.SetTextCursorControl(RA8875::NOCURSOR, false);
WiredHome 23:a50ded45dbaf 2915 }
WiredHome 23:a50ded45dbaf 2916
WiredHome 44:207594dece70 2917
WiredHome 23:a50ded45dbaf 2918 void BacklightTest(RA8875 & display, Serial & pc, float ramptime)
WiredHome 23:a50ded45dbaf 2919 {
WiredHome 29:422616aa04bd 2920 char buf[60];
WiredHome 41:2956a0a221e5 2921 unsigned int w = (ramptime * 1000)/ 256;
WiredHome 41:2956a0a221e5 2922 int delay = 200;
WiredHome 41:2956a0a221e5 2923
WiredHome 41:2956a0a221e5 2924 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2925 pc.printf("Backlight Test - ramp over %f sec.\r\n", ramptime);
WiredHome 41:2956a0a221e5 2926 else {
WiredHome 41:2956a0a221e5 2927 delay = 0;
WiredHome 41:2956a0a221e5 2928 w = 0;
WiredHome 41:2956a0a221e5 2929 }
WiredHome 23:a50ded45dbaf 2930 display.Backlight_u8(0);
WiredHome 29:422616aa04bd 2931 display.background(White);
WiredHome 23:a50ded45dbaf 2932 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2933 display.cls();
WiredHome 100:0b084475d5a9 2934 display.puts("RA8875 Backlight Test - Ramp up.");
WiredHome 41:2956a0a221e5 2935 wait_ms(delay);
WiredHome 38:38d503b4fad6 2936 for (int i=0; i <= 255; i++) {
WiredHome 141:2ec78a50dc98 2937 snprintf(buf, sizeof(buf), "%3d, %4d", i, w);
WiredHome 37:f19b7e7449dc 2938 display.puts(100,100,buf);
WiredHome 23:a50ded45dbaf 2939 display.Backlight_u8(i);
WiredHome 29:422616aa04bd 2940 wait_ms(w);
WiredHome 23:a50ded45dbaf 2941 }
WiredHome 23:a50ded45dbaf 2942 }
WiredHome 23:a50ded45dbaf 2943
WiredHome 44:207594dece70 2944
WiredHome 23:a50ded45dbaf 2945 void BacklightTest2(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2946 {
WiredHome 41:2956a0a221e5 2947 int delay = 20;
WiredHome 41:2956a0a221e5 2948
WiredHome 41:2956a0a221e5 2949 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2950 pc.printf("Backlight Test 2\r\n");
WiredHome 41:2956a0a221e5 2951 else
WiredHome 41:2956a0a221e5 2952 delay = 0;
WiredHome 41:2956a0a221e5 2953
WiredHome 23:a50ded45dbaf 2954 // Dim it out at the end of the tests.
WiredHome 37:f19b7e7449dc 2955 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2956 display.puts(0,0, "Ramp Backlight down.");
WiredHome 23:a50ded45dbaf 2957 // Ramp it off
WiredHome 23:a50ded45dbaf 2958 for (int i=255; i != 0; i--) {
WiredHome 23:a50ded45dbaf 2959 display.Backlight_u8(i);
WiredHome 41:2956a0a221e5 2960 wait_ms(delay);
WiredHome 23:a50ded45dbaf 2961 }
WiredHome 23:a50ded45dbaf 2962 display.Backlight_u8(0);
WiredHome 23:a50ded45dbaf 2963 }
WiredHome 23:a50ded45dbaf 2964
WiredHome 44:207594dece70 2965
WiredHome 23:a50ded45dbaf 2966 void ExternalFontTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2967 {
WiredHome 41:2956a0a221e5 2968 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2969 pc.printf("External Font 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("External Font Test.");
WiredHome 23:a50ded45dbaf 2974 display.Backlight(1);
WiredHome 37:f19b7e7449dc 2975
WiredHome 98:ecebed9b80b2 2976 display.SelectUserFont(BPG_Arial08x08);
WiredHome 73:f22a18707b5e 2977 display.puts(0,30, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 37:f19b7e7449dc 2978
WiredHome 98:ecebed9b80b2 2979 display.SelectUserFont(BPG_Arial20x20);
WiredHome 37:f19b7e7449dc 2980 display.puts("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 98:ecebed9b80b2 2981
WiredHome 98:ecebed9b80b2 2982 display.SelectUserFont();
WiredHome 73:f22a18707b5e 2983
WiredHome 37:f19b7e7449dc 2984 display.puts("Normal font again.");
WiredHome 37:f19b7e7449dc 2985 //display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 2986 }
WiredHome 23:a50ded45dbaf 2987
WiredHome 44:207594dece70 2988
WiredHome 23:a50ded45dbaf 2989 void DOSColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2990 {
WiredHome 41:2956a0a221e5 2991 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2992 pc.printf("DOS Color Test\r\n");
WiredHome 23:a50ded45dbaf 2993 display.background(Black);
WiredHome 23:a50ded45dbaf 2994 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2995 display.cls();
WiredHome 100:0b084475d5a9 2996 display.puts("DOS Colors - Fore");
WiredHome 23:a50ded45dbaf 2997 display.puts(280,0, "Back");
WiredHome 23:a50ded45dbaf 2998 display.background(Gray);
WiredHome 23:a50ded45dbaf 2999 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3000 display.foreground(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3001 display.puts(160, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 3002 display.background(Black);
WiredHome 23:a50ded45dbaf 3003 }
WiredHome 23:a50ded45dbaf 3004 display.foreground(White);
WiredHome 23:a50ded45dbaf 3005 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3006 display.background(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3007 display.puts(360, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 3008 display.foreground(White);
WiredHome 23:a50ded45dbaf 3009 }
WiredHome 23:a50ded45dbaf 3010 }
WiredHome 23:a50ded45dbaf 3011
WiredHome 44:207594dece70 3012
WiredHome 23:a50ded45dbaf 3013 void WebColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 3014 {
WiredHome 41:2956a0a221e5 3015 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3016 pc.printf("Web Color Test\r\n");
WiredHome 23:a50ded45dbaf 3017 display.background(Black);
WiredHome 23:a50ded45dbaf 3018 display.foreground(Blue);
WiredHome 32:0e4f2ae512e2 3019 display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 3020 display.cls();
WiredHome 59:fb40aad4efd4 3021 display.SetTextFontSize(1,1);
WiredHome 59:fb40aad4efd4 3022 display.puts(200,0, "Web Color Test");
WiredHome 59:fb40aad4efd4 3023 display.SetTextCursor(0,0);
WiredHome 59:fb40aad4efd4 3024 display.puts(" ");
WiredHome 59:fb40aad4efd4 3025 for (int i=0; i<16; i++)
WiredHome 59:fb40aad4efd4 3026 display.printf("%X", i&0xF);
WiredHome 59:fb40aad4efd4 3027 display.puts("\r\n0 ");
WiredHome 23:a50ded45dbaf 3028 for (int i=0; i<sizeof(WebColors)/sizeof(WebColors[0]); i++) {
WiredHome 23:a50ded45dbaf 3029 display.background(WebColors[i]);
WiredHome 23:a50ded45dbaf 3030 display.puts(" ");
WiredHome 59:fb40aad4efd4 3031 if (i % 16 == 15 && i < 255) {
WiredHome 59:fb40aad4efd4 3032 display.printf("\r\n%X ", ((i+1)/16));
WiredHome 59:fb40aad4efd4 3033 }
WiredHome 23:a50ded45dbaf 3034 }
WiredHome 23:a50ded45dbaf 3035 display.SetTextFontSize(1,1);
WiredHome 23:a50ded45dbaf 3036 }
WiredHome 23:a50ded45dbaf 3037
WiredHome 44:207594dece70 3038
WiredHome 37:f19b7e7449dc 3039 void PixelTest(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 3040 {
WiredHome 37:f19b7e7449dc 3041 int i, c, x, y;
WiredHome 37:f19b7e7449dc 3042
WiredHome 41:2956a0a221e5 3043 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3044 pc.printf("Pixel Test\r\n");
WiredHome 37:f19b7e7449dc 3045 display.background(Black);
WiredHome 37:f19b7e7449dc 3046 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 3047 display.cls();
WiredHome 100:0b084475d5a9 3048 display.puts("Pixel Test");
WiredHome 37:f19b7e7449dc 3049 for (i=0; i<1000; i++) {
WiredHome 37:f19b7e7449dc 3050 x = rand() % 480;
WiredHome 37:f19b7e7449dc 3051 y = 16 + rand() % (272-16);
WiredHome 37:f19b7e7449dc 3052 c = rand() % 16;
WiredHome 37:f19b7e7449dc 3053 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 37:f19b7e7449dc 3054 display.pixel(x,y, display.DOSColor(c));
WiredHome 37:f19b7e7449dc 3055 }
WiredHome 37:f19b7e7449dc 3056 }
WiredHome 37:f19b7e7449dc 3057
WiredHome 44:207594dece70 3058
WiredHome 23:a50ded45dbaf 3059 void LineTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 3060 {
WiredHome 23:a50ded45dbaf 3061 int i, x, y, x2, y2;
WiredHome 23:a50ded45dbaf 3062
WiredHome 41:2956a0a221e5 3063 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3064 pc.printf("Line Test\r\n");
WiredHome 23:a50ded45dbaf 3065 display.background(Black);
WiredHome 23:a50ded45dbaf 3066 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 3067 display.cls();
WiredHome 100:0b084475d5a9 3068 display.puts("Line Test");
WiredHome 23:a50ded45dbaf 3069 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3070 // Lines
WiredHome 23:a50ded45dbaf 3071 x = rand() % 480;
WiredHome 23:a50ded45dbaf 3072 y = rand() % 272;
WiredHome 23:a50ded45dbaf 3073 x2 = rand() % 480;
WiredHome 23:a50ded45dbaf 3074 y2 = rand() % 272;
WiredHome 23:a50ded45dbaf 3075 display.line(x,y, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3076 }
WiredHome 62:ba5d33438fda 3077 display.foreground(BrightRed);
WiredHome 62:ba5d33438fda 3078 display.foreground(BrightGreen);
WiredHome 62:ba5d33438fda 3079 display.foreground(BrightBlue);
WiredHome 62:ba5d33438fda 3080 display.line(55,50, 79,74, BrightRed);
WiredHome 62:ba5d33438fda 3081 display.line(57,50, 81,74, BrightGreen);
WiredHome 62:ba5d33438fda 3082 display.line(59,50, 83,74, BrightBlue);
WiredHome 62:ba5d33438fda 3083 // horz
WiredHome 62:ba5d33438fda 3084 display.line(30,40, 32,40, BrightRed);
WiredHome 62:ba5d33438fda 3085 display.line(30,42, 32,42, BrightGreen);
WiredHome 62:ba5d33438fda 3086 display.line(30,44, 32,44, BrightBlue);
WiredHome 62:ba5d33438fda 3087 // vert
WiredHome 62:ba5d33438fda 3088 display.line(20,40, 20,42, BrightRed);
WiredHome 62:ba5d33438fda 3089 display.line(22,40, 22,42, BrightGreen);
WiredHome 62:ba5d33438fda 3090 display.line(24,40, 24,42, BrightBlue);
WiredHome 62:ba5d33438fda 3091 // compare point to line-point
WiredHome 62:ba5d33438fda 3092 display.pixel(20,50, BrightRed);
WiredHome 62:ba5d33438fda 3093 display.pixel(22,50, BrightGreen);
WiredHome 62:ba5d33438fda 3094 display.pixel(24,50, BrightBlue);
WiredHome 62:ba5d33438fda 3095 display.line(20,52, 20,52, BrightRed);
WiredHome 62:ba5d33438fda 3096 display.line(22,52, 22,52, BrightGreen);
WiredHome 62:ba5d33438fda 3097 display.line(24,52, 24,52, BrightBlue);
WiredHome 73:f22a18707b5e 3098
WiredHome 62:ba5d33438fda 3099 // point
WiredHome 62:ba5d33438fda 3100 display.line(50,50, 50,50, Red);
WiredHome 62:ba5d33438fda 3101 display.line(52,52, 52,52, Green);
WiredHome 62:ba5d33438fda 3102 display.line(54,54, 54,54, Blue);
WiredHome 62:ba5d33438fda 3103 display.line(60,60, 60,60, BrightRed);
WiredHome 62:ba5d33438fda 3104 display.line(62,62, 62,62, BrightGreen);
WiredHome 62:ba5d33438fda 3105 display.line(64,64, 64,64, BrightBlue);
WiredHome 62:ba5d33438fda 3106 display.line(70,70, 70,70, DarkRed);
WiredHome 62:ba5d33438fda 3107 display.line(72,72, 72,72, DarkGreen);
WiredHome 62:ba5d33438fda 3108 display.line(74,74, 74,74, DarkBlue);
WiredHome 23:a50ded45dbaf 3109 }
WiredHome 23:a50ded45dbaf 3110
WiredHome 44:207594dece70 3111
WiredHome 23:a50ded45dbaf 3112 void RectangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 3113 {
WiredHome 23:a50ded45dbaf 3114 int i, x1,y1, x2,y2;
WiredHome 23:a50ded45dbaf 3115
WiredHome 41:2956a0a221e5 3116 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3117 pc.printf("Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 3118 display.background(Black);
WiredHome 23:a50ded45dbaf 3119 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 3120 display.cls();
WiredHome 100:0b084475d5a9 3121 display.puts("Rectangle Test");
WiredHome 23:a50ded45dbaf 3122 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3123 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 3124 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3125 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 3126 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3127 display.rect(x1,y1, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3128
WiredHome 23:a50ded45dbaf 3129 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 3130 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3131 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 3132 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3133 display.rect(x1,y1, x2,y2, FILL);
WiredHome 23:a50ded45dbaf 3134 }
WiredHome 23:a50ded45dbaf 3135 }
WiredHome 23:a50ded45dbaf 3136
WiredHome 44:207594dece70 3137
WiredHome 44:207594dece70 3138 void LayerTest(RA8875 & display, Serial & pc)
WiredHome 44:207594dece70 3139 {
WiredHome 44:207594dece70 3140 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 44:207594dece70 3141
WiredHome 44:207594dece70 3142 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 3143 pc.printf("Layer Test\r\n");
WiredHome 44:207594dece70 3144
WiredHome 50:2c4f474a2453 3145 display.SelectDrawingLayer(0);
WiredHome 44:207594dece70 3146 display.background(Black);
WiredHome 44:207594dece70 3147 display.foreground(Blue);
WiredHome 44:207594dece70 3148 display.cls();
WiredHome 100:0b084475d5a9 3149 display.puts("Layer 0");
WiredHome 44:207594dece70 3150 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 3151 x1 = rand() % 240;
WiredHome 44:207594dece70 3152 y1 = 50 + rand() % 200;
WiredHome 44:207594dece70 3153 x2 = x1 + rand() % 100;
WiredHome 44:207594dece70 3154 y2 = y1 + rand() % 100;
WiredHome 44:207594dece70 3155 r1 = rand() % (x2 - x1)/2;
WiredHome 44:207594dece70 3156 r2 = rand() % (y2 - y1)/2;
WiredHome 44:207594dece70 3157 display.roundrect(x1,y1, x2,y2, r1,r2, display.DOSColor(i));
WiredHome 44:207594dece70 3158 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 3159 wait_ms(20);
WiredHome 44:207594dece70 3160 }
WiredHome 44:207594dece70 3161 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 3162 wait_ms(1000);
WiredHome 44:207594dece70 3163
WiredHome 50:2c4f474a2453 3164 display.SelectDrawingLayer(1);
WiredHome 44:207594dece70 3165 display.background(Black);
WiredHome 44:207594dece70 3166 display.foreground(Yellow);
WiredHome 44:207594dece70 3167 display.cls();
WiredHome 44:207594dece70 3168 display.puts(240,0, "Layer 1");
WiredHome 44:207594dece70 3169 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 3170 x1 = 300 + rand() % 100;
WiredHome 44:207594dece70 3171 y1 = 70 + rand() % 200;
WiredHome 44:207594dece70 3172 r1 = rand() % min(y1 - 20, 100);
WiredHome 44:207594dece70 3173 display.circle(x1,y1,r1, display.DOSColor(i));
WiredHome 44:207594dece70 3174 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 3175 wait_ms(20);
WiredHome 44:207594dece70 3176 }
WiredHome 56:7a85d226ad0d 3177 display.SetLayerMode(RA8875::ShowLayer1); // Show it after the build-up
WiredHome 44:207594dece70 3178 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 3179 wait_ms(2000);
WiredHome 44:207594dece70 3180
WiredHome 50:2c4f474a2453 3181 display.SelectDrawingLayer(0);
WiredHome 56:7a85d226ad0d 3182 display.SetLayerMode(RA8875::ShowLayer0); // Show Layer 0 again
WiredHome 44:207594dece70 3183 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 3184 wait_ms(1000);
WiredHome 53:86d24b9480b9 3185 display.SetLayerMode(RA8875::TransparentMode); // Transparent mode
WiredHome 44:207594dece70 3186 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 3187 wait_ms(1000);
WiredHome 44:207594dece70 3188 for (i=0; i<=8; i++) {
WiredHome 44:207594dece70 3189 display.SetLayerTransparency(i, 8-i);
WiredHome 44:207594dece70 3190 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 3191 wait_ms(200);
WiredHome 44:207594dece70 3192 }
WiredHome 73:f22a18707b5e 3193
WiredHome 44:207594dece70 3194 // Restore before we exit
WiredHome 44:207594dece70 3195 display.SetLayerTransparency(0, 0);
WiredHome 56:7a85d226ad0d 3196 display.SetLayerMode(RA8875::ShowLayer0); // Restore to layer 0
WiredHome 44:207594dece70 3197 }
WiredHome 44:207594dece70 3198
WiredHome 44:207594dece70 3199
WiredHome 23:a50ded45dbaf 3200 void RoundRectTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 3201 {
WiredHome 37:f19b7e7449dc 3202 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 23:a50ded45dbaf 3203
WiredHome 41:2956a0a221e5 3204 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3205 pc.printf("Round Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 3206 display.background(Black);
WiredHome 23:a50ded45dbaf 3207 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 3208 display.cls();
WiredHome 100:0b084475d5a9 3209 display.puts("Rounded Rectangle Test");
WiredHome 73:f22a18707b5e 3210
WiredHome 23:a50ded45dbaf 3211 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3212 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 3213 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3214 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 3215 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 3216 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 3217 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 3218 display.roundrect(x1,y1, x2,y2, 5,8, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3219
WiredHome 23:a50ded45dbaf 3220 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 3221 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3222 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 3223 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 3224 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 3225 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 3226 display.roundrect(x1,y1, x2,y2, r1,r2, FILL);
WiredHome 23:a50ded45dbaf 3227 }
WiredHome 23:a50ded45dbaf 3228 }
WiredHome 23:a50ded45dbaf 3229
WiredHome 44:207594dece70 3230
WiredHome 23:a50ded45dbaf 3231 void TriangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 3232 {
WiredHome 23:a50ded45dbaf 3233 int i, x1, y1, x2, y2, x3, y3;
WiredHome 23:a50ded45dbaf 3234
WiredHome 41:2956a0a221e5 3235 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3236 pc.printf("Triangle Test\r\n");
WiredHome 23:a50ded45dbaf 3237 display.background(Black);
WiredHome 23:a50ded45dbaf 3238 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 3239 display.cls();
WiredHome 23:a50ded45dbaf 3240 display.puts(0,0, "Triangle Test");
WiredHome 23:a50ded45dbaf 3241
WiredHome 23:a50ded45dbaf 3242 x1 = 150;
WiredHome 23:a50ded45dbaf 3243 y1 = 2;
WiredHome 23:a50ded45dbaf 3244 x2 = 190;
WiredHome 23:a50ded45dbaf 3245 y2 = 7;
WiredHome 23:a50ded45dbaf 3246 x3 = 170;
WiredHome 23:a50ded45dbaf 3247 y3 = 16;
WiredHome 23:a50ded45dbaf 3248 display.triangle(x1,y1, x2,y2, x3,y3);
WiredHome 23:a50ded45dbaf 3249
WiredHome 23:a50ded45dbaf 3250 x1 = 200;
WiredHome 23:a50ded45dbaf 3251 y1 = 2;
WiredHome 23:a50ded45dbaf 3252 x2 = 240;
WiredHome 23:a50ded45dbaf 3253 y2 = 7;
WiredHome 23:a50ded45dbaf 3254 x3 = 220;
WiredHome 23:a50ded45dbaf 3255 y3 = 16;
WiredHome 23:a50ded45dbaf 3256 display.filltriangle(x1,y1, x2,y2, x3,y3, BrightRed);
WiredHome 23:a50ded45dbaf 3257
WiredHome 23:a50ded45dbaf 3258 x1 = 300;
WiredHome 23:a50ded45dbaf 3259 y1 = 2;
WiredHome 23:a50ded45dbaf 3260 x2 = 340;
WiredHome 23:a50ded45dbaf 3261 y2 = 7;
WiredHome 23:a50ded45dbaf 3262 x3 = 320;
WiredHome 23:a50ded45dbaf 3263 y3 = 16;
WiredHome 23:a50ded45dbaf 3264 display.triangle(x1,y1, x2,y2, x3,y3, NOFILL);
WiredHome 23:a50ded45dbaf 3265
WiredHome 23:a50ded45dbaf 3266 x1 = 400;
WiredHome 23:a50ded45dbaf 3267 y1 = 2;
WiredHome 23:a50ded45dbaf 3268 x2 = 440;
WiredHome 23:a50ded45dbaf 3269 y2 = 7;
WiredHome 23:a50ded45dbaf 3270 x3 = 420;
WiredHome 23:a50ded45dbaf 3271 y3 = 16;
WiredHome 23:a50ded45dbaf 3272 display.triangle(x1,y1, x2,y2, x3,y3, Blue);
WiredHome 23:a50ded45dbaf 3273
WiredHome 23:a50ded45dbaf 3274 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3275 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 3276 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3277 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 3278 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3279 x3 = rand() % 240;
WiredHome 23:a50ded45dbaf 3280 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3281 display.triangle(x1,y1, x2,y2, x3,y3, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3282 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 3283 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3284 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 3285 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3286 x3 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 3287 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 3288 display.triangle(x1,y1, x2,y2, x3,y3, FILL);
WiredHome 23:a50ded45dbaf 3289 }
WiredHome 23:a50ded45dbaf 3290 }
WiredHome 23:a50ded45dbaf 3291
WiredHome 44:207594dece70 3292
WiredHome 23:a50ded45dbaf 3293 void CircleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 3294 {
WiredHome 23:a50ded45dbaf 3295 int i, x, y, r1;
WiredHome 23:a50ded45dbaf 3296
WiredHome 41:2956a0a221e5 3297 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3298 pc.printf("Circle Test\r\n");
WiredHome 23:a50ded45dbaf 3299 display.background(Black);
WiredHome 23:a50ded45dbaf 3300 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 3301 display.cls();
WiredHome 100:0b084475d5a9 3302 display.puts("Circle Test");
WiredHome 23:a50ded45dbaf 3303 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3304 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 3305 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 3306 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3307 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 3308 display.circle(x,y,r1, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3309
WiredHome 23:a50ded45dbaf 3310 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 3311 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 3312 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3313 //pc.printf(" (%d,%d) - %d FILL\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 3314 display.circle(x,y,r1, display.DOSColor(i), FILL);
WiredHome 23:a50ded45dbaf 3315 }
WiredHome 23:a50ded45dbaf 3316 }
WiredHome 23:a50ded45dbaf 3317
WiredHome 44:207594dece70 3318
WiredHome 23:a50ded45dbaf 3319 void EllipseTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 3320 {
WiredHome 23:a50ded45dbaf 3321 int i,x,y,r1,r2;
WiredHome 23:a50ded45dbaf 3322
WiredHome 41:2956a0a221e5 3323 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 3324 pc.printf("Ellipse Test\r\n");
WiredHome 23:a50ded45dbaf 3325 display.background(Black);
WiredHome 23:a50ded45dbaf 3326 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 3327 display.cls();
WiredHome 100:0b084475d5a9 3328 display.puts("Ellipse Test");
WiredHome 23:a50ded45dbaf 3329 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 3330 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 3331 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 3332 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3333 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3334 display.ellipse(x,y,r1,r2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 3335
WiredHome 23:a50ded45dbaf 3336 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 3337 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 3338 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3339 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 3340 display.ellipse(x,y,r1,r2, FILL);
WiredHome 23:a50ded45dbaf 3341 }
WiredHome 23:a50ded45dbaf 3342 }
WiredHome 23:a50ded45dbaf 3343
WiredHome 44:207594dece70 3344
WiredHome 37:f19b7e7449dc 3345 void TestGraphicsBitmap(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 3346 {
WiredHome 37:f19b7e7449dc 3347 LocalFileSystem local("local");
WiredHome 41:2956a0a221e5 3348 if (!SuppressSlowStuff)
WiredHome 73:f22a18707b5e 3349 pc.printf("Bitmap File Load\r\n");
WiredHome 37:f19b7e7449dc 3350 display.background(Black);
WiredHome 37:f19b7e7449dc 3351 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 3352 display.cls();
WiredHome 100:0b084475d5a9 3353 display.puts("Graphics Test, loading /local/TestPat.bmp");
WiredHome 37:f19b7e7449dc 3354 wait(3);
WiredHome 37:f19b7e7449dc 3355
WiredHome 37:f19b7e7449dc 3356 int r = display.RenderBitmapFile(0,0, "/local/TestPat.bmp");
WiredHome 59:fb40aad4efd4 3357 if (!SuppressSlowStuff)
WiredHome 59:fb40aad4efd4 3358 pc.printf(" returned %d\r\n", r);
WiredHome 37:f19b7e7449dc 3359 }
WiredHome 37:f19b7e7449dc 3360
WiredHome 44:207594dece70 3361
WiredHome 77:9206c13aa527 3362 void TouchPanelTest(RA8875 & display, Serial & pc)
WiredHome 77:9206c13aa527 3363 {
WiredHome 77:9206c13aa527 3364 Timer t;
WiredHome 98:ecebed9b80b2 3365 int x, y;
WiredHome 78:faf49c381591 3366 tpMatrix_t calmatrix;
WiredHome 78:faf49c381591 3367
WiredHome 77:9206c13aa527 3368 display.background(Black);
WiredHome 77:9206c13aa527 3369 display.foreground(Blue);
WiredHome 77:9206c13aa527 3370 display.cls();
WiredHome 100:0b084475d5a9 3371 display.puts("Touch Panel Test\r\n");
WiredHome 78:faf49c381591 3372 pc.printf("Touch Panel Test\r\n");
WiredHome 77:9206c13aa527 3373 display.TouchPanelInit();
WiredHome 78:faf49c381591 3374 pc.printf(" TP: c - calibrate, r - restore, t - test\r\n");
WiredHome 78:faf49c381591 3375 int c = pc.getc();
WiredHome 78:faf49c381591 3376 if (c == 'c') {
WiredHome 78:faf49c381591 3377 point_t pTest[3] =
WiredHome 78:faf49c381591 3378 { { 50, 50 }, {450, 150}, {225,250} };
WiredHome 78:faf49c381591 3379 point_t pSample[3];
WiredHome 78:faf49c381591 3380 for (int i=0; i<3; i++) {
WiredHome 78:faf49c381591 3381 display.foreground(Blue);
WiredHome 78:faf49c381591 3382 display.printf(" (%3d,%3d) => ", pTest[i].x, pTest[i].y);
WiredHome 78:faf49c381591 3383 display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, White);
WiredHome 78:faf49c381591 3384 display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, White);
WiredHome 79:544eb4964795 3385 while (!display.TouchPanelA2DFiltered(&x, &y))
WiredHome 78:faf49c381591 3386 wait_ms(20);
WiredHome 78:faf49c381591 3387 pSample[i].x = x;
WiredHome 78:faf49c381591 3388 pSample[i].y = y;
WiredHome 78:faf49c381591 3389 display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, Black);
WiredHome 78:faf49c381591 3390 display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, Black);
WiredHome 78:faf49c381591 3391 display.foreground(Blue);
WiredHome 78:faf49c381591 3392 display.printf(" (%4d,%4d)\r\n", x,y);
WiredHome 79:544eb4964795 3393 while (display.TouchPanelA2DFiltered(&x, &y))
WiredHome 78:faf49c381591 3394 wait_ms(20);
WiredHome 78:faf49c381591 3395 wait(2);
WiredHome 78:faf49c381591 3396 }
WiredHome 81:01da2e34283d 3397 display.TouchPanelComputeCalibration(pTest, pSample, &calmatrix);
WiredHome 78:faf49c381591 3398 display.printf(" Writing calibration to tpcal.cfg\r\n");
WiredHome 78:faf49c381591 3399 FILE * fh = fopen("/local/tpcal.cfg", "wb");
WiredHome 78:faf49c381591 3400 if (fh) {
WiredHome 78:faf49c381591 3401 fwrite(&calmatrix, sizeof(calmatrix), 1, fh);
WiredHome 78:faf49c381591 3402 fclose(fh);
WiredHome 78:faf49c381591 3403 }
WiredHome 78:faf49c381591 3404 display.printf(" Calibration is complete.");
WiredHome 78:faf49c381591 3405 } else if (c == 'r') {
WiredHome 78:faf49c381591 3406 display.printf(" Reading calibration from tpcal.cfg\r\n");
WiredHome 78:faf49c381591 3407 FILE * fh = fopen("/local/tpcal.cfg", "rb");
WiredHome 78:faf49c381591 3408 if (fh) {
WiredHome 78:faf49c381591 3409 fread(&calmatrix, sizeof(calmatrix), 1, fh);
WiredHome 78:faf49c381591 3410 fclose(fh);
WiredHome 78:faf49c381591 3411 }
WiredHome 78:faf49c381591 3412 display.printf(" Calibration is complete.");
WiredHome 78:faf49c381591 3413 display.TouchPanelSetMatrix(&calmatrix);
WiredHome 77:9206c13aa527 3414 }
WiredHome 77:9206c13aa527 3415 t.start();
WiredHome 77:9206c13aa527 3416 do {
WiredHome 77:9206c13aa527 3417 point_t point = {0, 0};
WiredHome 79:544eb4964795 3418 if (display.TouchPanelReadable(&point)) {
WiredHome 77:9206c13aa527 3419 display.pixel(point.x, point.y, Red);
WiredHome 77:9206c13aa527 3420 }
WiredHome 77:9206c13aa527 3421 } while (t.read_ms() < 30000);
WiredHome 77:9206c13aa527 3422 pc.printf(">");
WiredHome 77:9206c13aa527 3423 }
WiredHome 77:9206c13aa527 3424
WiredHome 77:9206c13aa527 3425
WiredHome 41:2956a0a221e5 3426 void SpeedTest(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 3427 {
WiredHome 41:2956a0a221e5 3428 Timer t;
WiredHome 41:2956a0a221e5 3429 SuppressSlowStuff = true;
WiredHome 41:2956a0a221e5 3430 pc.printf("\r\nSpeedTest disables delays, runs tests, reports overall time.\r\n");
WiredHome 41:2956a0a221e5 3431 t.start();
WiredHome 41:2956a0a221e5 3432 // do stuff fast
WiredHome 41:2956a0a221e5 3433 TextCursorTest(display, pc);
WiredHome 49:c5182231d1b9 3434 TextWrapTest(display, pc);
WiredHome 41:2956a0a221e5 3435 BacklightTest(display, pc, 0);
WiredHome 41:2956a0a221e5 3436 BacklightTest2(display, pc);
WiredHome 41:2956a0a221e5 3437 ExternalFontTest(display, pc);
WiredHome 41:2956a0a221e5 3438 DOSColorTest(display, pc);
WiredHome 41:2956a0a221e5 3439 WebColorTest(display, pc);
WiredHome 41:2956a0a221e5 3440 PixelTest(display, pc);
WiredHome 41:2956a0a221e5 3441 LineTest(display, pc);
WiredHome 41:2956a0a221e5 3442 RectangleTest(display, pc);
WiredHome 41:2956a0a221e5 3443 RoundRectTest(display, pc);
WiredHome 41:2956a0a221e5 3444 TriangleTest(display, pc);
WiredHome 41:2956a0a221e5 3445 CircleTest(display, pc);
WiredHome 41:2956a0a221e5 3446 EllipseTest(display, pc);
WiredHome 44:207594dece70 3447 LayerTest(display, pc);
WiredHome 41:2956a0a221e5 3448 //TestGraphicsBitmap(display, pc);
WiredHome 41:2956a0a221e5 3449 pc.printf("SpeedTest completed in %d msec\r\n", t.read_ms());
WiredHome 73:f22a18707b5e 3450 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 3451 display.ReportPerformance(pc);
WiredHome 73:f22a18707b5e 3452 #endif
WiredHome 41:2956a0a221e5 3453 SuppressSlowStuff = false;
WiredHome 41:2956a0a221e5 3454 }
WiredHome 41:2956a0a221e5 3455
WiredHome 44:207594dece70 3456
WiredHome 41:2956a0a221e5 3457 void PrintScreen(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 3458 {
WiredHome 41:2956a0a221e5 3459 if (!SuppressSlowStuff)
WiredHome 73:f22a18707b5e 3460 pc.printf("PrintScreen\r\n");
WiredHome 41:2956a0a221e5 3461 display.PrintScreen( 0,0, 480,272, "/local/Capture.bmp");
WiredHome 41:2956a0a221e5 3462 }
WiredHome 41:2956a0a221e5 3463
WiredHome 44:207594dece70 3464
WiredHome 23:a50ded45dbaf 3465 void RunTestSet(RA8875 & lcd, Serial & pc)
WiredHome 23:a50ded45dbaf 3466 {
WiredHome 23:a50ded45dbaf 3467 int q = 0;
WiredHome 23:a50ded45dbaf 3468 int automode = 0;
WiredHome 49:c5182231d1b9 3469 const unsigned char modelist[] = "BDWtGLlFROTPCEbw"; // auto-test in this order.
WiredHome 23:a50ded45dbaf 3470
WiredHome 23:a50ded45dbaf 3471 while(1) {
WiredHome 23:a50ded45dbaf 3472 pc.printf("\r\n"
WiredHome 41:2956a0a221e5 3473 "B - Backlight up b - backlight dim\r\n"
WiredHome 41:2956a0a221e5 3474 "D - DOS Colors W - Web Colors\r\n"
WiredHome 41:2956a0a221e5 3475 "t - text cursor G - Graphics Bitmap\r\n"
WiredHome 41:2956a0a221e5 3476 "L - Lines F - external Font\r\n"
WiredHome 41:2956a0a221e5 3477 "R - Rectangles O - rOund rectangles\r\n"
WiredHome 41:2956a0a221e5 3478 "T - Triangles P - Pixels \r\n"
WiredHome 41:2956a0a221e5 3479 "C - Circles E - Ellipses\r\n"
WiredHome 41:2956a0a221e5 3480 "A - Auto Test mode S - Speed Test\r\n"
WiredHome 77:9206c13aa527 3481 "K - Keypad Test s - touch screen test\r\n"
WiredHome 41:2956a0a221e5 3482 "p - print screen r - reset \r\n"
WiredHome 49:c5182231d1b9 3483 "l - layer test w - wrapping text \r\n"
WiredHome 73:f22a18707b5e 3484 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 3485 "0 - clear performance 1 - report performance\r\n"
WiredHome 73:f22a18707b5e 3486 #endif
WiredHome 23:a50ded45dbaf 3487 "> ");
WiredHome 23:a50ded45dbaf 3488 if (automode == -1 || pc.readable()) {
WiredHome 23:a50ded45dbaf 3489 automode = -1;
WiredHome 37:f19b7e7449dc 3490 q = pc.getc();
WiredHome 37:f19b7e7449dc 3491 while (pc.readable())
WiredHome 37:f19b7e7449dc 3492 pc.getc();
WiredHome 23:a50ded45dbaf 3493 } else if (automode >= 0) {
WiredHome 23:a50ded45dbaf 3494 q = modelist[automode];
WiredHome 23:a50ded45dbaf 3495 }
WiredHome 23:a50ded45dbaf 3496 switch(q) {
WiredHome 73:f22a18707b5e 3497 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 3498 case '0':
WiredHome 41:2956a0a221e5 3499 lcd.ClearPerformance();
WiredHome 41:2956a0a221e5 3500 break;
WiredHome 41:2956a0a221e5 3501 case '1':
WiredHome 41:2956a0a221e5 3502 lcd.ReportPerformance(pc);
WiredHome 41:2956a0a221e5 3503 break;
WiredHome 73:f22a18707b5e 3504 #endif
WiredHome 23:a50ded45dbaf 3505 case 'A':
WiredHome 23:a50ded45dbaf 3506 automode = 0;
WiredHome 23:a50ded45dbaf 3507 break;
WiredHome 23:a50ded45dbaf 3508 case 'B':
WiredHome 41:2956a0a221e5 3509 BacklightTest(lcd, pc, 2);
WiredHome 23:a50ded45dbaf 3510 break;
WiredHome 23:a50ded45dbaf 3511 case 'b':
WiredHome 23:a50ded45dbaf 3512 BacklightTest2(lcd, pc);
WiredHome 23:a50ded45dbaf 3513 break;
WiredHome 23:a50ded45dbaf 3514 case 'D':
WiredHome 23:a50ded45dbaf 3515 DOSColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3516 break;
WiredHome 75:ca78388cfd77 3517 case 'K':
WiredHome 75:ca78388cfd77 3518 KeyPadTest(lcd, pc);
WiredHome 75:ca78388cfd77 3519 break;
WiredHome 23:a50ded45dbaf 3520 case 'W':
WiredHome 23:a50ded45dbaf 3521 WebColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3522 break;
WiredHome 23:a50ded45dbaf 3523 case 't':
WiredHome 23:a50ded45dbaf 3524 TextCursorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3525 break;
WiredHome 49:c5182231d1b9 3526 case 'w':
WiredHome 49:c5182231d1b9 3527 TextWrapTest(lcd, pc);
WiredHome 49:c5182231d1b9 3528 break;
WiredHome 23:a50ded45dbaf 3529 case 'F':
WiredHome 23:a50ded45dbaf 3530 ExternalFontTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3531 break;
WiredHome 23:a50ded45dbaf 3532 case 'L':
WiredHome 23:a50ded45dbaf 3533 LineTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3534 break;
WiredHome 44:207594dece70 3535 case 'l':
WiredHome 44:207594dece70 3536 LayerTest(lcd, pc);
WiredHome 44:207594dece70 3537 break;
WiredHome 23:a50ded45dbaf 3538 case 'R':
WiredHome 23:a50ded45dbaf 3539 RectangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3540 break;
WiredHome 23:a50ded45dbaf 3541 case 'O':
WiredHome 23:a50ded45dbaf 3542 RoundRectTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3543 break;
WiredHome 41:2956a0a221e5 3544 case 'p':
WiredHome 41:2956a0a221e5 3545 PrintScreen(lcd, pc);
WiredHome 41:2956a0a221e5 3546 break;
WiredHome 41:2956a0a221e5 3547 case 'S':
WiredHome 41:2956a0a221e5 3548 SpeedTest(lcd, pc);
WiredHome 41:2956a0a221e5 3549 break;
WiredHome 77:9206c13aa527 3550 case 's':
WiredHome 77:9206c13aa527 3551 TouchPanelTest(lcd, pc);
WiredHome 77:9206c13aa527 3552 break;
WiredHome 23:a50ded45dbaf 3553 case 'T':
WiredHome 23:a50ded45dbaf 3554 TriangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3555 break;
WiredHome 37:f19b7e7449dc 3556 case 'P':
WiredHome 37:f19b7e7449dc 3557 PixelTest(lcd, pc);
WiredHome 37:f19b7e7449dc 3558 break;
WiredHome 37:f19b7e7449dc 3559 case 'G':
WiredHome 37:f19b7e7449dc 3560 TestGraphicsBitmap(lcd, pc);
WiredHome 37:f19b7e7449dc 3561 break;
WiredHome 23:a50ded45dbaf 3562 case 'C':
WiredHome 23:a50ded45dbaf 3563 CircleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3564 break;
WiredHome 23:a50ded45dbaf 3565 case 'E':
WiredHome 23:a50ded45dbaf 3566 EllipseTest(lcd, pc);
WiredHome 23:a50ded45dbaf 3567 break;
WiredHome 23:a50ded45dbaf 3568 case 'r':
WiredHome 23:a50ded45dbaf 3569 pc.printf("Resetting ...\r\n");
WiredHome 23:a50ded45dbaf 3570 wait_ms(20);
WiredHome 23:a50ded45dbaf 3571 mbed_reset();
WiredHome 23:a50ded45dbaf 3572 break;
WiredHome 75:ca78388cfd77 3573 case ' ':
WiredHome 75:ca78388cfd77 3574 break;
WiredHome 23:a50ded45dbaf 3575 default:
WiredHome 23:a50ded45dbaf 3576 printf("huh?\n");
WiredHome 23:a50ded45dbaf 3577 break;
WiredHome 23:a50ded45dbaf 3578 }
WiredHome 23:a50ded45dbaf 3579 if (automode >= 0) {
WiredHome 23:a50ded45dbaf 3580 automode++;
WiredHome 23:a50ded45dbaf 3581 if (automode >= sizeof(modelist))
WiredHome 23:a50ded45dbaf 3582 automode = 0;
WiredHome 23:a50ded45dbaf 3583 wait_ms(2000);
WiredHome 23:a50ded45dbaf 3584 }
WiredHome 23:a50ded45dbaf 3585 wait_ms(200);
WiredHome 23:a50ded45dbaf 3586 }
WiredHome 23:a50ded45dbaf 3587 }
WiredHome 23:a50ded45dbaf 3588
WiredHome 79:544eb4964795 3589 #endif // TESTENABLE