Library to control a Graphics TFT connected to 4-wire SPI - revised for the Raio RA8875 Display Controller.

Dependents:   FRDM_RA8875_mPaint RA8875_Demo RA8875_KeyPadDemo SignalGenerator ... more

Fork of SPI_TFT by Peter Drescher

See Components - RA8875 Based Display

Enhanced touch-screen support - where it previous supported both the Resistive Touch and Capacitive Touch based on the FT5206 Touch Controller, now it also has support for the GSL1680 Touch Controller.

Offline Help Manual (Windows chm)

/media/uploads/WiredHome/ra8875.zip.bin (download, rename to .zip and unzip)

Committer:
WiredHome
Date:
Tue Feb 11 18:33:44 2020 +0000
Revision:
195:17e176dbd6eb
Parent:
194:53c18f0e7922
Child:
196:56820026701b
Working on orientation.

Who changed what in which revision?

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