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

Committer:
WiredHome
Date:
Tue Feb 11 15:35:02 2020 +0000
Revision:
194:53c18f0e7922
Parent:
191:0fad2e45e196
Child:
195:17e176dbd6eb
Don't alter the Memory write direction when changing between text and graphics modes.

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