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

Committer:
WiredHome
Date:
Sat Sep 21 17:30:00 2019 +0000
Revision:
190:3132b7dfad82
Parent:
186:910fc2335c45
Child:
191:0fad2e45e196
Fonts Add & mods; Add methods; - get dimensions of image file; - round or square cap for thicklines; - word-wrap for puts; - align one rect to another; - independently set the text font fill; - get the width of a character, or a string

Who changed what in which revision?

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