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

Committer:
WiredHome
Date:
Fri Oct 11 20:53:08 2019 +0000
Revision:
191:0fad2e45e196
Parent:
190:3132b7dfad82
Child:
194:53c18f0e7922
Added a method to get the screen orientation.

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