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

Committer:
lamell
Date:
Sun May 03 10:16:02 2020 -0400
Revision:
201:1119f1e9f4e4
Parent:
197:853d08e2fb53
Slight modifications to the library. Mainly to make the speed faster and also changing some parameters from private to public.

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