KSM edits to RA8875

Dependents:   Liz_Test_Code

Committer:
WiredHome
Date:
Fri Dec 26 21:34:28 2014 +0000
Revision:
77:9206c13aa527
Parent:
75:ca78388cfd77
Child:
78:faf49c381591
Functioning touch panel updates - added method for calibration and a new API to get the touch in the "display" coordinate system.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 19:3f82c1161fd2 1 /// RA8875 Display Controller Library.
WiredHome 73:f22a18707b5e 2 ///
WiredHome 68:ab08efabfc88 3 /// This is being created for a Raio RA8875-based display from buydisplay.com,
WiredHome 73:f22a18707b5e 4 /// which is 480 x 272 using a 4-wire SPI interface.
WiredHome 68:ab08efabfc88 5 /// This display controller is used in other display resolutions, up to 800x600.
WiredHome 68:ab08efabfc88 6 /// While this driver has not been tested with these variants, nothing was done
WiredHome 68:ab08efabfc88 7 /// to prevent easily supporting them.
WiredHome 19:3f82c1161fd2 8 ///
WiredHome 19:3f82c1161fd2 9 #include "RA8875.h"
WiredHome 19:3f82c1161fd2 10
WiredHome 41:2956a0a221e5 11 //#define DEBUG "RAIO"
WiredHome 19:3f82c1161fd2 12 // ...
WiredHome 19:3f82c1161fd2 13 // INFO("Stuff to show %d", var); // new-line is automatically appended
WiredHome 19:3f82c1161fd2 14 //
WiredHome 19:3f82c1161fd2 15 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
WiredHome 19:3f82c1161fd2 16 #define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 19:3f82c1161fd2 17 #define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 19:3f82c1161fd2 18 #define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 73:f22a18707b5e 19 static void HexDump(char * title, uint8_t * p, int count)
WiredHome 73:f22a18707b5e 20 {
WiredHome 73:f22a18707b5e 21 int i;
WiredHome 73:f22a18707b5e 22 char buf[100] = "0000: ";
WiredHome 73:f22a18707b5e 23
WiredHome 73:f22a18707b5e 24 if (*title)
WiredHome 73:f22a18707b5e 25 INFO("%s", title);
WiredHome 73:f22a18707b5e 26 for (i=0; i<count; ) {
WiredHome 73:f22a18707b5e 27 sprintf(buf + strlen(buf), "%02X ", *(p+i));
WiredHome 73:f22a18707b5e 28 if ((++i & 0x0F) == 0x00) {
WiredHome 73:f22a18707b5e 29 INFO("%s", buf);
WiredHome 73:f22a18707b5e 30 if (i < count)
WiredHome 73:f22a18707b5e 31 sprintf(buf, "%04X: ", i);
WiredHome 73:f22a18707b5e 32 else
WiredHome 73:f22a18707b5e 33 buf[0] = '\0';
WiredHome 73:f22a18707b5e 34 }
WiredHome 73:f22a18707b5e 35 }
WiredHome 73:f22a18707b5e 36 if (strlen(buf))
WiredHome 73:f22a18707b5e 37 INFO("%s", buf);
WiredHome 73:f22a18707b5e 38 }
WiredHome 19:3f82c1161fd2 39 #else
WiredHome 19:3f82c1161fd2 40 #define INFO(x, ...)
WiredHome 19:3f82c1161fd2 41 #define WARN(x, ...)
WiredHome 19:3f82c1161fd2 42 #define ERR(x, ...)
WiredHome 73:f22a18707b5e 43 #define HexDump(a, b, c)
WiredHome 19:3f82c1161fd2 44 #endif
WiredHome 19:3f82c1161fd2 45
WiredHome 19:3f82c1161fd2 46
WiredHome 19:3f82c1161fd2 47 #define RA8875_DISPLAY_WIDTH 480
WiredHome 19:3f82c1161fd2 48 #define RA8875_DISPLAY_HEIGHT 272
WiredHome 43:3becae133285 49 #define RA8875_COLORDEPTH_BPP 16 /* Not an API */
WiredHome 19:3f82c1161fd2 50
WiredHome 19:3f82c1161fd2 51 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 52 #define PERFORMANCE_RESET performance.reset()
WiredHome 19:3f82c1161fd2 53 #define REGISTERPERFORMANCE(a) RegisterPerformance(a)
WiredHome 68:ab08efabfc88 54 #define COUNTIDLETIME(a) CountIdleTime(a)
WiredHome 73:f22a18707b5e 55 static const char *metricsName[] = {
WiredHome 73:f22a18707b5e 56 "Cls", "Pixel", "Pixel Stream",
WiredHome 41:2956a0a221e5 57 "Read Pixel", "Read Pixel Stream",
WiredHome 73:f22a18707b5e 58 "Line",
WiredHome 73:f22a18707b5e 59 "Rectangle", "Rounded Rectangle",
WiredHome 68:ab08efabfc88 60 "Triangle", "Circle", "Ellipse"
WiredHome 19:3f82c1161fd2 61 };
WiredHome 19:3f82c1161fd2 62 #else
WiredHome 19:3f82c1161fd2 63 #define PERFORMANCE_RESET
WiredHome 19:3f82c1161fd2 64 #define REGISTERPERFORMANCE(a)
WiredHome 68:ab08efabfc88 65 #define COUNTIDLETIME(a)
WiredHome 19:3f82c1161fd2 66 #endif
WiredHome 19:3f82c1161fd2 67
WiredHome 73:f22a18707b5e 68 // When it is going to poll a register for completion, how many
WiredHome 19:3f82c1161fd2 69 // uSec should it wait between each polling activity.
WiredHome 19:3f82c1161fd2 70 #define POLLWAITuSec 10
WiredHome 19:3f82c1161fd2 71
WiredHome 75:ca78388cfd77 72 // Private RawKeyMap for the Keyboard interface
WiredHome 77:9206c13aa527 73 static const uint8_t KeyMap[22] = {
WiredHome 77:9206c13aa527 74 0,
WiredHome 77:9206c13aa527 75 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
WiredHome 75:ca78388cfd77 76 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
WiredHome 75:ca78388cfd77 77 255
WiredHome 77:9206c13aa527 78 };
WiredHome 75:ca78388cfd77 79
WiredHome 19:3f82c1161fd2 80
WiredHome 19:3f82c1161fd2 81 RA8875::RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, const char *name)
WiredHome 58:26658a56112a 82 : GraphicsDisplay(name)
WiredHome 58:26658a56112a 83 , spi(mosi, miso, sclk)
WiredHome 19:3f82c1161fd2 84 , cs(csel)
WiredHome 19:3f82c1161fd2 85 , res(reset)
WiredHome 19:3f82c1161fd2 86 {
WiredHome 19:3f82c1161fd2 87 font = NULL; // no external font, use internal.
WiredHome 19:3f82c1161fd2 88 select(false); // deselect the display
WiredHome 19:3f82c1161fd2 89 frequency(RA8875_DEFAULT_SPI_FREQ); // data rate
WiredHome 28:ed102fc442c4 90 Reset();
WiredHome 28:ed102fc442c4 91 Power(true);
WiredHome 28:ed102fc442c4 92 Backlight_u8(255);
WiredHome 75:ca78388cfd77 93 pKeyMap = KeyMap;
WiredHome 19:3f82c1161fd2 94 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 95 performance.start();
WiredHome 19:3f82c1161fd2 96 ClearPerformance();
WiredHome 19:3f82c1161fd2 97 #endif
WiredHome 19:3f82c1161fd2 98 }
WiredHome 19:3f82c1161fd2 99
WiredHome 43:3becae133285 100
WiredHome 19:3f82c1161fd2 101 //RA8875::~RA8875()
WiredHome 19:3f82c1161fd2 102 //{
WiredHome 19:3f82c1161fd2 103 //}
WiredHome 19:3f82c1161fd2 104
WiredHome 61:8f3153bf0baa 105 uint16_t RA8875::GetDrawingLayer(void)
WiredHome 61:8f3153bf0baa 106 {
WiredHome 61:8f3153bf0baa 107 return (ReadCommand(0x41) & 0x01);
WiredHome 61:8f3153bf0baa 108 }
WiredHome 43:3becae133285 109
WiredHome 50:2c4f474a2453 110 RetCode_t RA8875::SelectDrawingLayer(uint16_t layer)
WiredHome 43:3becae133285 111 {
WiredHome 43:3becae133285 112 unsigned char mwcr1 = ReadCommand(0x41) & ~0x01; // retain all but the currently selected layer
WiredHome 43:3becae133285 113
WiredHome 43:3becae133285 114 if (width() >= 800 && height() >= 480 && color_bpp() == 8) {
WiredHome 43:3becae133285 115 return bad_parameter;
WiredHome 43:3becae133285 116 } else if (layer > 1) {
WiredHome 43:3becae133285 117 return bad_parameter;
WiredHome 43:3becae133285 118 } else { // layer == 0 ro 1
WiredHome 72:ecffe56af969 119 return WriteCommand(0x41, mwcr1 | layer);
WiredHome 43:3becae133285 120 }
WiredHome 43:3becae133285 121 }
WiredHome 43:3becae133285 122
WiredHome 44:207594dece70 123
WiredHome 53:86d24b9480b9 124 RetCode_t RA8875::SetLayerMode(LayerMode_T mode)
WiredHome 44:207594dece70 125 {
WiredHome 53:86d24b9480b9 126 unsigned char ltpr0 = ReadCommand(0x52) & ~0x7; // retain all but the display layer mode
WiredHome 53:86d24b9480b9 127 if (mode <= (LayerMode_T)6) {
WiredHome 53:86d24b9480b9 128 WriteCommand(0x52, ltpr0 | (mode & 0x7));
WiredHome 53:86d24b9480b9 129 return noerror;
WiredHome 53:86d24b9480b9 130 } else {
WiredHome 53:86d24b9480b9 131 return bad_parameter;
WiredHome 53:86d24b9480b9 132 }
WiredHome 44:207594dece70 133 }
WiredHome 44:207594dece70 134
WiredHome 44:207594dece70 135
WiredHome 44:207594dece70 136 RetCode_t RA8875::SetLayerTransparency(uint8_t layer1, uint8_t layer2)
WiredHome 44:207594dece70 137 {
WiredHome 44:207594dece70 138 if (layer1 > 8)
WiredHome 44:207594dece70 139 layer1 = 8;
WiredHome 44:207594dece70 140 if (layer2 > 8)
WiredHome 44:207594dece70 141 layer2 = 8;
WiredHome 44:207594dece70 142 WriteCommand(0x53, ((layer2 & 0xF) << 4) | (layer1 & 0xF));
WiredHome 44:207594dece70 143 return noerror;
WiredHome 44:207594dece70 144 }
WiredHome 44:207594dece70 145
WiredHome 44:207594dece70 146
WiredHome 53:86d24b9480b9 147 RetCode_t RA8875::SetBackgroundTransparencyColor(color_t color)
WiredHome 53:86d24b9480b9 148 {
WiredHome 53:86d24b9480b9 149 WriteCommand(0x67, (color >> 11) & 0x1F);
WiredHome 53:86d24b9480b9 150 WriteCommand(0x68, (color >> 5) & 0x3F);
WiredHome 53:86d24b9480b9 151 WriteCommand(0x69, (color & 0x1F));
WiredHome 53:86d24b9480b9 152 return noerror;
WiredHome 53:86d24b9480b9 153 }
WiredHome 53:86d24b9480b9 154
WiredHome 73:f22a18707b5e 155 color_t RA8875::GetBackgroundTransparencyColor(void)
WiredHome 73:f22a18707b5e 156 {
WiredHome 73:f22a18707b5e 157 RGBQUAD q;
WiredHome 73:f22a18707b5e 158 q.rgbRed = ReadCommand(0x67);
WiredHome 73:f22a18707b5e 159 q.rgbGreen = ReadCommand(0x68);
WiredHome 73:f22a18707b5e 160 q.rgbBlue = ReadCommand(0x69);
WiredHome 73:f22a18707b5e 161 return RGBQuadToRGB16(&q, 0);
WiredHome 73:f22a18707b5e 162 }
WiredHome 73:f22a18707b5e 163
hexley 54:e117ad10fba6 164 // ### Touch Panel support code additions begin here
hexley 54:e117ad10fba6 165
hexley 54:e117ad10fba6 166 RetCode_t RA8875::TouchPanelInit(void)
WiredHome 73:f22a18707b5e 167 {
hexley 54:e117ad10fba6 168 //TPCR0: Set enable bit, default sample time, wakeup, and ADC clock
hexley 54:e117ad10fba6 169 WriteCommand(TPCR0, TP_ENABLE | TP_ADC_SAMPLE_DEFAULT_CLKS | TP_ADC_CLKDIV_DEFAULT);
hexley 54:e117ad10fba6 170 // TPCR1: Set auto/manual, Ref voltage, debounce, manual mode params
WiredHome 73:f22a18707b5e 171 WriteCommand(TPCR1, TP_MODE_DEFAULT | TP_DEBOUNCE_DEFAULT);
hexley 54:e117ad10fba6 172 WriteCommand(INTC1, ReadCommand(INTC1) | RA8875_INT_TP); // reg INTC1: Enable Touch Panel Interrupts (D2 = 1)
hexley 54:e117ad10fba6 173 WriteCommand(INTC2, RA8875_INT_TP); // reg INTC2: Clear any TP interrupt flag
hexley 54:e117ad10fba6 174 return noerror;
hexley 54:e117ad10fba6 175 }
hexley 54:e117ad10fba6 176
hexley 54:e117ad10fba6 177 RetCode_t RA8875::TouchPanelInit(uint8_t bTpEnable, uint8_t bTpAutoManual, uint8_t bTpDebounce, uint8_t bTpManualMode, uint8_t bTpAdcClkDiv, uint8_t bTpAdcSampleTime)
hexley 54:e117ad10fba6 178 {
hexley 54:e117ad10fba6 179 // Parameter bounds check
hexley 54:e117ad10fba6 180 if( \
WiredHome 73:f22a18707b5e 181 !(bTpEnable == TP_ENABLE || bTpEnable == TP_ENABLE) || \
WiredHome 73:f22a18707b5e 182 !(bTpAutoManual == TP_MODE_AUTO || bTpAutoManual == TP_MODE_MANUAL) || \
WiredHome 73:f22a18707b5e 183 !(bTpDebounce == TP_DEBOUNCE_OFF || bTpDebounce == TP_DEBOUNCE_ON) || \
WiredHome 73:f22a18707b5e 184 !(bTpManualMode <= TP_MANUAL_LATCH_Y) || \
WiredHome 73:f22a18707b5e 185 !(bTpAdcClkDiv <= TP_ADC_CLKDIV_128) || \
WiredHome 73:f22a18707b5e 186 !(bTpAdcSampleTime <= TP_ADC_SAMPLE_65536_CLKS) \
WiredHome 73:f22a18707b5e 187 ) return bad_parameter;
hexley 54:e117ad10fba6 188 // Construct the config byte for TPCR0 and write them
hexley 54:e117ad10fba6 189 WriteCommand(TPCR0, bTpEnable | bTpAdcClkDiv | bTpAdcSampleTime); // Note: Wakeup is never enabled
hexley 54:e117ad10fba6 190 // Construct the config byte for TPCR1 and write them
hexley 54:e117ad10fba6 191 WriteCommand(TPCR1, bTpManualMode | bTpDebounce | bTpManualMode); // Note: Always uses internal Vref.
hexley 54:e117ad10fba6 192 // Set up the interrupt flag and enable bits
hexley 54:e117ad10fba6 193 WriteCommand(INTC1, ReadCommand(INTC1) | RA8875_INT_TP); // reg INTC1: Enable Touch Panel Interrupts (D2 = 1)
hexley 54:e117ad10fba6 194 WriteCommand(INTC2, RA8875_INT_TP); // reg INTC2: Clear any TP interrupt flag
WiredHome 73:f22a18707b5e 195 return noerror;
hexley 54:e117ad10fba6 196 }
hexley 54:e117ad10fba6 197
hexley 54:e117ad10fba6 198 unsigned char RA8875::TouchPanelRead(loc_t *x, loc_t *y)
hexley 54:e117ad10fba6 199 {
hexley 54:e117ad10fba6 200 unsigned char touchready;
hexley 54:e117ad10fba6 201 static int xbuf[TPBUFSIZE], ybuf[TPBUFSIZE], sample = 0;
hexley 54:e117ad10fba6 202 int i, j, temp;
hexley 54:e117ad10fba6 203
WiredHome 73:f22a18707b5e 204 if( (ReadCommand(INTC2) & RA8875_INT_TP) ) { // Test for TP Interrupt pending in register INTC2
hexley 54:e117ad10fba6 205 // Get the next data samples
hexley 54:e117ad10fba6 206 ybuf[sample] = ReadCommand(TPYH) << 2 | ( (ReadCommand(TPXYL) & 0xC) >> 2 ); // D[9:2] from reg TPYH, D[1:0] from reg TPXYL[3:2]
hexley 54:e117ad10fba6 207 xbuf[sample] = ReadCommand(TPXH) << 2 | ( (ReadCommand(TPXYL) & 0x3) ); // D[9:2] from reg TPXH, D[1:0] from reg TPXYL[1:0]
hexley 54:e117ad10fba6 208 // Check for a complete set
hexley 54:e117ad10fba6 209 if(++sample == TPBUFSIZE) {
WiredHome 73:f22a18707b5e 210 // Buffers are full, so process them using Finn's method described in Analog Dialogue No. 44, Feb 2010
WiredHome 73:f22a18707b5e 211 // This requires sorting the samples in order of size, then discarding the top 25% and
WiredHome 73:f22a18707b5e 212 // bottom 25% as noise spikes. Finally, the middle 50% of the values are averaged to
WiredHome 73:f22a18707b5e 213 // reduce Gaussian noise.
WiredHome 73:f22a18707b5e 214
WiredHome 73:f22a18707b5e 215 // Sort the Y buffer using an Insertion Sort
hexley 54:e117ad10fba6 216 for(i = 1; i <= TPBUFSIZE; i++) {
hexley 54:e117ad10fba6 217 temp = ybuf[i];
hexley 54:e117ad10fba6 218 j = i;
hexley 54:e117ad10fba6 219 while( j && (ybuf[j-1] > temp) ) {
hexley 54:e117ad10fba6 220 ybuf[j] = ybuf[j-1];
WiredHome 73:f22a18707b5e 221 j = j-1;
hexley 54:e117ad10fba6 222 }
WiredHome 73:f22a18707b5e 223 ybuf[j] = temp;
hexley 54:e117ad10fba6 224 } // End of Y sort
hexley 54:e117ad10fba6 225 // Sort the X buffer the same way
hexley 54:e117ad10fba6 226 for(i = 1; i <= TPBUFSIZE; i++) {
hexley 54:e117ad10fba6 227 temp = xbuf[i];
hexley 54:e117ad10fba6 228 j = i;
hexley 54:e117ad10fba6 229 while( j && (xbuf[j-1] > temp) ) {
hexley 54:e117ad10fba6 230 xbuf[j] = xbuf[j-1];
WiredHome 73:f22a18707b5e 231 j = j-1;
hexley 54:e117ad10fba6 232 }
WiredHome 73:f22a18707b5e 233 xbuf[j] = temp;
hexley 54:e117ad10fba6 234 } // End of X sort
hexley 54:e117ad10fba6 235 // Average the middle half of the Y values and report them
hexley 54:e117ad10fba6 236 j = 0;
hexley 54:e117ad10fba6 237 for(i = (TPBUFSIZE/4) - 1; i < TPBUFSIZE - TPBUFSIZE/4; i++ ) {
WiredHome 73:f22a18707b5e 238 j += ybuf[i];
hexley 54:e117ad10fba6 239 }
hexley 54:e117ad10fba6 240 *y = j * (float)2/TPBUFSIZE; // This is the average
hexley 54:e117ad10fba6 241 // Average the middle half of the X values and report them
hexley 54:e117ad10fba6 242 j = 0;
hexley 54:e117ad10fba6 243 for(i = (TPBUFSIZE/4) - 1; i < TPBUFSIZE - TPBUFSIZE/4; i++ ) {
WiredHome 73:f22a18707b5e 244 j += xbuf[i];
hexley 54:e117ad10fba6 245 }
WiredHome 73:f22a18707b5e 246 *x = j * (float)2/TPBUFSIZE; // This is the average
WiredHome 73:f22a18707b5e 247 // Tidy up and return
hexley 54:e117ad10fba6 248 touchready = 1;
hexley 54:e117ad10fba6 249 sample = 0; // Ready to start on the next set of data samples
WiredHome 73:f22a18707b5e 250 } else {
hexley 54:e117ad10fba6 251 // Buffer not yet full, so do not return any results yet
hexley 54:e117ad10fba6 252 touchready = 0;
hexley 54:e117ad10fba6 253 }
WiredHome 73:f22a18707b5e 254 WriteCommand(INTC2, RA8875_INT_TP); // reg INTC2: Clear that TP interrupt flag
hexley 54:e117ad10fba6 255 } // End of initial if -- data has been read and processed
hexley 54:e117ad10fba6 256 else
hexley 54:e117ad10fba6 257 touchready = 0; // Touch Panel "Int" was not set
hexley 54:e117ad10fba6 258 return touchready;
hexley 54:e117ad10fba6 259 }
hexley 54:e117ad10fba6 260
hexley 54:e117ad10fba6 261 unsigned char RA8875::TouchPanelReadRaw(loc_t *x, loc_t *y)
hexley 54:e117ad10fba6 262 {
hexley 54:e117ad10fba6 263 unsigned char touchready;
hexley 54:e117ad10fba6 264
WiredHome 73:f22a18707b5e 265 if( (ReadCommand(INTC2) & RA8875_INT_TP) ) { // Test for TP Interrupt pending in register INTC2
hexley 54:e117ad10fba6 266 *y = ReadCommand(TPYH) << 2 | ( (ReadCommand(TPXYL) & 0xC) >> 2 ); // D[9:2] from reg TPYH, D[1:0] from reg TPXYL[3:2]
hexley 54:e117ad10fba6 267 *x = ReadCommand(TPXH) << 2 | ( (ReadCommand(TPXYL) & 0x3) ); // D[9:2] from reg TPXH, D[1:0] from reg TPXYL[1:0]
WiredHome 73:f22a18707b5e 268 WriteCommand(INTC2, RA8875_INT_TP); // reg INTC2: Clear that TP interrupt flag
hexley 54:e117ad10fba6 269 touchready = 1;
WiredHome 73:f22a18707b5e 270 } else
WiredHome 73:f22a18707b5e 271 touchready = 0;
hexley 54:e117ad10fba6 272 return touchready;
hexley 54:e117ad10fba6 273 }
WiredHome 77:9206c13aa527 274
WiredHome 77:9206c13aa527 275 /* The following section is derived from Carlos E. Vidales.
WiredHome 77:9206c13aa527 276 *
WiredHome 77:9206c13aa527 277 * Copyright (c) 2001, Carlos E. Vidales. All rights reserved.
WiredHome 77:9206c13aa527 278 *
WiredHome 77:9206c13aa527 279 * This sample program was written and put in the public domain
WiredHome 77:9206c13aa527 280 * by Carlos E. Vidales. The program is provided "as is"
WiredHome 77:9206c13aa527 281 * without warranty of any kind, either expressed or implied.
WiredHome 77:9206c13aa527 282 * If you choose to use the program within your own products
WiredHome 77:9206c13aa527 283 * you do so at your own risk, and assume the responsibility
WiredHome 77:9206c13aa527 284 * for servicing, repairing or correcting the program should
WiredHome 77:9206c13aa527 285 * it prove defective in any manner.
WiredHome 77:9206c13aa527 286 * You may copy and distribute the program's source code in any
WiredHome 77:9206c13aa527 287 * medium, provided that you also include in each copy an
WiredHome 77:9206c13aa527 288 * appropriate copyright notice and disclaimer of warranty.
WiredHome 77:9206c13aa527 289 * You may also modify this program and distribute copies of
WiredHome 77:9206c13aa527 290 * it provided that you include prominent notices stating
WiredHome 77:9206c13aa527 291 * that you changed the file(s) and the date of any change,
WiredHome 77:9206c13aa527 292 * and that you do not charge any royalties or licenses for
WiredHome 77:9206c13aa527 293 * its use.
WiredHome 77:9206c13aa527 294 *
WiredHome 77:9206c13aa527 295 * This file contains functions that implement calculations
WiredHome 77:9206c13aa527 296 * necessary to obtain calibration factors for a touch screen
WiredHome 77:9206c13aa527 297 * that suffers from multiple distortion effects: namely,
WiredHome 77:9206c13aa527 298 * translation, scaling and rotation.
WiredHome 77:9206c13aa527 299 *
WiredHome 77:9206c13aa527 300 * The following set of equations represent a valid display
WiredHome 77:9206c13aa527 301 * point given a corresponding set of touch screen points:
WiredHome 77:9206c13aa527 302 *
WiredHome 77:9206c13aa527 303 * /- -\
WiredHome 77:9206c13aa527 304 * /- -\ /- -\ | |
WiredHome 77:9206c13aa527 305 * | | | | | Xs |
WiredHome 77:9206c13aa527 306 * | Xd | | A B C | | |
WiredHome 77:9206c13aa527 307 * | | = | | * | Ys |
WiredHome 77:9206c13aa527 308 * | Yd | | D E F | | |
WiredHome 77:9206c13aa527 309 * | | | | | 1 |
WiredHome 77:9206c13aa527 310 * \- -/ \- -/ | |
WiredHome 77:9206c13aa527 311 * \- -/
WiredHome 77:9206c13aa527 312 * where:
WiredHome 77:9206c13aa527 313 * (Xd,Yd) represents the desired display point
WiredHome 77:9206c13aa527 314 * coordinates,
WiredHome 77:9206c13aa527 315 * (Xs,Ys) represents the available touch screen
WiredHome 77:9206c13aa527 316 * coordinates, and the matrix
WiredHome 77:9206c13aa527 317 * /- -\
WiredHome 77:9206c13aa527 318 * |A,B,C|
WiredHome 77:9206c13aa527 319 * |D,E,F| represents the factors used to translate
WiredHome 77:9206c13aa527 320 * \- -/ the available touch screen point values
WiredHome 77:9206c13aa527 321 * into the corresponding display
WiredHome 77:9206c13aa527 322 * coordinates.
WiredHome 77:9206c13aa527 323 * Note that for practical considerations, the utilities
WiredHome 77:9206c13aa527 324 * within this file do not use the matrix coefficients as
WiredHome 77:9206c13aa527 325 * defined above, but instead use the following
WiredHome 77:9206c13aa527 326 * equivalents, since floating point math is not used:
WiredHome 77:9206c13aa527 327 * A = An/Divider
WiredHome 77:9206c13aa527 328 * B = Bn/Divider
WiredHome 77:9206c13aa527 329 * C = Cn/Divider
WiredHome 77:9206c13aa527 330 * D = Dn/Divider
WiredHome 77:9206c13aa527 331 * E = En/Divider
WiredHome 77:9206c13aa527 332 * F = Fn/Divider
WiredHome 77:9206c13aa527 333 * The functions provided within this file are:
WiredHome 77:9206c13aa527 334 * setCalibrationMatrix() - calculates the set of factors
WiredHome 77:9206c13aa527 335 * in the above equation, given
WiredHome 77:9206c13aa527 336 * three sets of test points.
WiredHome 77:9206c13aa527 337 * getDisplayPoint() - returns the actual display
WiredHome 77:9206c13aa527 338 * coordinates, given a set of
WiredHome 77:9206c13aa527 339 * touch screen coordinates.
WiredHome 77:9206c13aa527 340 * translateRawScreenCoordinates() - helper function to transform
WiredHome 77:9206c13aa527 341 * raw screen points into values
WiredHome 77:9206c13aa527 342 * scaled to the desired display
WiredHome 77:9206c13aa527 343 * resolution.
WiredHome 77:9206c13aa527 344 */
WiredHome 77:9206c13aa527 345
WiredHome 77:9206c13aa527 346 /**********************************************************************
WiredHome 77:9206c13aa527 347 *
WiredHome 77:9206c13aa527 348 * Function: setCalibrationMatrix()
WiredHome 77:9206c13aa527 349 *
WiredHome 77:9206c13aa527 350 * Description: Calling this function with valid input data
WiredHome 77:9206c13aa527 351 * in the display and screen input arguments
WiredHome 77:9206c13aa527 352 * causes the calibration factors between the
WiredHome 77:9206c13aa527 353 * screen and display points to be calculated,
WiredHome 77:9206c13aa527 354 * and the output argument - matrixPtr - to be
WiredHome 77:9206c13aa527 355 * populated.
WiredHome 77:9206c13aa527 356 *
WiredHome 77:9206c13aa527 357 * This function needs to be called only when new
WiredHome 77:9206c13aa527 358 * calibration factors are desired.
WiredHome 77:9206c13aa527 359 *
WiredHome 77:9206c13aa527 360 *
WiredHome 77:9206c13aa527 361 * Argument(s): displayPtr (input) - Pointer to an array of three
WiredHome 77:9206c13aa527 362 * sample, reference points.
WiredHome 77:9206c13aa527 363 * screenPtr (input) - Pointer to the array of touch
WiredHome 77:9206c13aa527 364 * screen points corresponding
WiredHome 77:9206c13aa527 365 * to the reference display points.
WiredHome 77:9206c13aa527 366 * matrixPtr (output) - Pointer to the calibration
WiredHome 77:9206c13aa527 367 * matrix computed for the set
WiredHome 77:9206c13aa527 368 * of points being provided.
WiredHome 77:9206c13aa527 369 *
WiredHome 77:9206c13aa527 370 *
WiredHome 77:9206c13aa527 371 * From the article text, recall that the matrix coefficients are
WiredHome 77:9206c13aa527 372 * resolved to be the following:
WiredHome 77:9206c13aa527 373 *
WiredHome 77:9206c13aa527 374 *
WiredHome 77:9206c13aa527 375 * Divider = (Xs0 - Xs2)*(Ys1 - Ys2) - (Xs1 - Xs2)*(Ys0 - Ys2)
WiredHome 77:9206c13aa527 376 *
WiredHome 77:9206c13aa527 377 *
WiredHome 77:9206c13aa527 378 *
WiredHome 77:9206c13aa527 379 * (Xd0 - Xd2)*(Ys1 - Ys2) - (Xd1 - Xd2)*(Ys0 - Ys2)
WiredHome 77:9206c13aa527 380 * A = ---------------------------------------------------
WiredHome 77:9206c13aa527 381 * Divider
WiredHome 77:9206c13aa527 382 *
WiredHome 77:9206c13aa527 383 *
WiredHome 77:9206c13aa527 384 * (Xs0 - Xs2)*(Xd1 - Xd2) - (Xd0 - Xd2)*(Xs1 - Xs2)
WiredHome 77:9206c13aa527 385 * B = ---------------------------------------------------
WiredHome 77:9206c13aa527 386 * Divider
WiredHome 77:9206c13aa527 387 *
WiredHome 77:9206c13aa527 388 *
WiredHome 77:9206c13aa527 389 * Ys0*(Xs2*Xd1 - Xs1*Xd2) +
WiredHome 77:9206c13aa527 390 * Ys1*(Xs0*Xd2 - Xs2*Xd0) +
WiredHome 77:9206c13aa527 391 * Ys2*(Xs1*Xd0 - Xs0*Xd1)
WiredHome 77:9206c13aa527 392 * C = ---------------------------------------------------
WiredHome 77:9206c13aa527 393 * Divider
WiredHome 77:9206c13aa527 394 *
WiredHome 77:9206c13aa527 395 *
WiredHome 77:9206c13aa527 396 * (Yd0 - Yd2)*(Ys1 - Ys2) - (Yd1 - Yd2)*(Ys0 - Ys2)
WiredHome 77:9206c13aa527 397 * D = ---------------------------------------------------
WiredHome 77:9206c13aa527 398 * Divider
WiredHome 77:9206c13aa527 399 *
WiredHome 77:9206c13aa527 400 *
WiredHome 77:9206c13aa527 401 * (Xs0 - Xs2)*(Yd1 - Yd2) - (Yd0 - Yd2)*(Xs1 - Xs2)
WiredHome 77:9206c13aa527 402 * E = ---------------------------------------------------
WiredHome 77:9206c13aa527 403 * Divider
WiredHome 77:9206c13aa527 404 *
WiredHome 77:9206c13aa527 405 *
WiredHome 77:9206c13aa527 406 * Ys0*(Xs2*Yd1 - Xs1*Yd2) +
WiredHome 77:9206c13aa527 407 * Ys1*(Xs0*Yd2 - Xs2*Yd0) +
WiredHome 77:9206c13aa527 408 * Ys2*(Xs1*Yd0 - Xs0*Yd1)
WiredHome 77:9206c13aa527 409 * F = ---------------------------------------------------
WiredHome 77:9206c13aa527 410 * Divider
WiredHome 77:9206c13aa527 411 *
WiredHome 77:9206c13aa527 412 *
WiredHome 77:9206c13aa527 413 * Return: OK - the calibration matrix was correctly
WiredHome 77:9206c13aa527 414 * calculated and its value is in the
WiredHome 77:9206c13aa527 415 * output argument.
WiredHome 77:9206c13aa527 416 * NOT_OK - an error was detected and the
WiredHome 77:9206c13aa527 417 * function failed to return a valid
WiredHome 77:9206c13aa527 418 * set of matrix values.
WiredHome 77:9206c13aa527 419 * The only time this sample code returns
WiredHome 77:9206c13aa527 420 * NOT_OK is when Divider == 0
WiredHome 77:9206c13aa527 421 *
WiredHome 77:9206c13aa527 422 *
WiredHome 77:9206c13aa527 423 *
WiredHome 77:9206c13aa527 424 * NOTE! NOTE! NOTE!
WiredHome 77:9206c13aa527 425 *
WiredHome 77:9206c13aa527 426 * setCalibrationMatrix() and getDisplayPoint() will do fine
WiredHome 77:9206c13aa527 427 * for you as they are, provided that your digitizer
WiredHome 77:9206c13aa527 428 * resolution does not exceed 10 bits (1024 values). Higher
WiredHome 77:9206c13aa527 429 * resolutions may cause the integer operations to overflow
WiredHome 77:9206c13aa527 430 * and return incorrect values. If you wish to use these
WiredHome 77:9206c13aa527 431 * functions with digitizer resolutions of 12 bits (4096
WiredHome 77:9206c13aa527 432 * values) you will either have to a) use 64-bit signed
WiredHome 77:9206c13aa527 433 * integer variables and math, or b) judiciously modify the
WiredHome 77:9206c13aa527 434 * operations to scale results by a factor of 2 or even 4.
WiredHome 77:9206c13aa527 435 *
WiredHome 77:9206c13aa527 436 */
WiredHome 77:9206c13aa527 437 RetCode_t RA8875::TouchPanelCalibrate(point_t * displayPtr, point_t * screenPtr, tpMatrix_t * matrixPtr)
WiredHome 77:9206c13aa527 438 {
WiredHome 77:9206c13aa527 439 RetCode_t retValue = noerror;
WiredHome 77:9206c13aa527 440
WiredHome 77:9206c13aa527 441 tpMatrix.Divider = ((screenPtr[0].x - screenPtr[2].x) * (screenPtr[1].y - screenPtr[2].y)) -
WiredHome 77:9206c13aa527 442 ((screenPtr[1].x - screenPtr[2].x) * (screenPtr[0].y - screenPtr[2].y)) ;
WiredHome 77:9206c13aa527 443
WiredHome 77:9206c13aa527 444 if( tpMatrix.Divider == 0 ) {
WiredHome 77:9206c13aa527 445 retValue = bad_parameter;
WiredHome 77:9206c13aa527 446 } else {
WiredHome 77:9206c13aa527 447 tpMatrix.An = ((displayPtr[0].x - displayPtr[2].x) * (screenPtr[1].y - screenPtr[2].y)) -
WiredHome 77:9206c13aa527 448 ((displayPtr[1].x - displayPtr[2].x) * (screenPtr[0].y - screenPtr[2].y)) ;
WiredHome 77:9206c13aa527 449
WiredHome 77:9206c13aa527 450 tpMatrix.Bn = ((screenPtr[0].x - screenPtr[2].x) * (displayPtr[1].x - displayPtr[2].x)) -
WiredHome 77:9206c13aa527 451 ((displayPtr[0].x - displayPtr[2].x) * (screenPtr[1].x - screenPtr[2].x)) ;
WiredHome 77:9206c13aa527 452
WiredHome 77:9206c13aa527 453 tpMatrix.Cn = (screenPtr[2].x * displayPtr[1].x - screenPtr[1].x * displayPtr[2].x) * screenPtr[0].y +
WiredHome 77:9206c13aa527 454 (screenPtr[0].x * displayPtr[2].x - screenPtr[2].x * displayPtr[0].x) * screenPtr[1].y +
WiredHome 77:9206c13aa527 455 (screenPtr[1].x * displayPtr[0].x - screenPtr[0].x * displayPtr[1].x) * screenPtr[2].y ;
WiredHome 77:9206c13aa527 456
WiredHome 77:9206c13aa527 457 tpMatrix.Dn = ((displayPtr[0].y - displayPtr[2].y) * (screenPtr[1].y - screenPtr[2].y)) -
WiredHome 77:9206c13aa527 458 ((displayPtr[1].y - displayPtr[2].y) * (screenPtr[0].y - screenPtr[2].y)) ;
WiredHome 77:9206c13aa527 459
WiredHome 77:9206c13aa527 460 tpMatrix.En = ((screenPtr[0].x - screenPtr[2].x) * (displayPtr[1].y - displayPtr[2].y)) -
WiredHome 77:9206c13aa527 461 ((displayPtr[0].y - displayPtr[2].y) * (screenPtr[1].x - screenPtr[2].x)) ;
WiredHome 77:9206c13aa527 462
WiredHome 77:9206c13aa527 463 tpMatrix.Fn = (screenPtr[2].x * displayPtr[1].y - screenPtr[1].x * displayPtr[2].y) * screenPtr[0].y +
WiredHome 77:9206c13aa527 464 (screenPtr[0].x * displayPtr[2].y - screenPtr[2].x * displayPtr[0].y) * screenPtr[1].y +
WiredHome 77:9206c13aa527 465 (screenPtr[1].x * displayPtr[0].y - screenPtr[0].x * displayPtr[1].y) * screenPtr[2].y ;
WiredHome 77:9206c13aa527 466 if (matrixPtr)
WiredHome 77:9206c13aa527 467 memcpy(matrixPtr, &tpMatrix, sizeof(tpMatrix_t));
WiredHome 77:9206c13aa527 468 }
WiredHome 77:9206c13aa527 469 return( retValue ) ;
WiredHome 77:9206c13aa527 470 }
WiredHome 77:9206c13aa527 471
WiredHome 77:9206c13aa527 472 /**********************************************************************
WiredHome 77:9206c13aa527 473 *
WiredHome 77:9206c13aa527 474 * Function: getDisplayPoint()
WiredHome 77:9206c13aa527 475 *
WiredHome 77:9206c13aa527 476 * Description: Given a valid set of calibration factors and a point
WiredHome 77:9206c13aa527 477 * value reported by the touch screen, this function
WiredHome 77:9206c13aa527 478 * calculates and returns the true (or closest to true)
WiredHome 77:9206c13aa527 479 * display point below the spot where the touch screen
WiredHome 77:9206c13aa527 480 * was touched.
WiredHome 77:9206c13aa527 481 *
WiredHome 77:9206c13aa527 482 *
WiredHome 77:9206c13aa527 483 *
WiredHome 77:9206c13aa527 484 * Argument(s): displayPtr (output) - Pointer to the calculated
WiredHome 77:9206c13aa527 485 * (true) display point.
WiredHome 77:9206c13aa527 486 * screenPtr (input) - Pointer to the reported touch
WiredHome 77:9206c13aa527 487 * screen point.
WiredHome 77:9206c13aa527 488 * matrixPtr (input) - Pointer to calibration factors
WiredHome 77:9206c13aa527 489 * matrix previously calculated
WiredHome 77:9206c13aa527 490 * from a call to
WiredHome 77:9206c13aa527 491 * setCalibrationMatrix()
WiredHome 77:9206c13aa527 492 *
WiredHome 77:9206c13aa527 493 *
WiredHome 77:9206c13aa527 494 * The function simply solves for Xd and Yd by implementing the
WiredHome 77:9206c13aa527 495 * computations required by the translation matrix.
WiredHome 77:9206c13aa527 496 *
WiredHome 77:9206c13aa527 497 * /- -\
WiredHome 77:9206c13aa527 498 * /- -\ /- -\ | |
WiredHome 77:9206c13aa527 499 * | | | | | Xs |
WiredHome 77:9206c13aa527 500 * | Xd | | A B C | | |
WiredHome 77:9206c13aa527 501 * | | = | | * | Ys |
WiredHome 77:9206c13aa527 502 * | Yd | | D E F | | |
WiredHome 77:9206c13aa527 503 * | | | | | 1 |
WiredHome 77:9206c13aa527 504 * \- -/ \- -/ | |
WiredHome 77:9206c13aa527 505 * \- -/
WiredHome 77:9206c13aa527 506 *
WiredHome 77:9206c13aa527 507 * It must be kept brief to avoid consuming CPU cycles.
WiredHome 77:9206c13aa527 508 *
WiredHome 77:9206c13aa527 509 *
WiredHome 77:9206c13aa527 510 * Return: OK - the display point was correctly calculated
WiredHome 77:9206c13aa527 511 * and its value is in the output argument.
WiredHome 77:9206c13aa527 512 * NOT_OK - an error was detected and the function
WiredHome 77:9206c13aa527 513 * failed to return a valid point.
WiredHome 77:9206c13aa527 514 *
WiredHome 77:9206c13aa527 515 *
WiredHome 77:9206c13aa527 516 *
WiredHome 77:9206c13aa527 517 * NOTE! NOTE! NOTE!
WiredHome 77:9206c13aa527 518 *
WiredHome 77:9206c13aa527 519 * setCalibrationMatrix() and getDisplayPoint() will do fine
WiredHome 77:9206c13aa527 520 * for you as they are, provided that your digitizer
WiredHome 77:9206c13aa527 521 * resolution does not exceed 10 bits (1024 values). Higher
WiredHome 77:9206c13aa527 522 * resolutions may cause the integer operations to overflow
WiredHome 77:9206c13aa527 523 * and return incorrect values. If you wish to use these
WiredHome 77:9206c13aa527 524 * functions with digitizer resolutions of 12 bits (4096
WiredHome 77:9206c13aa527 525 * values) you will either have to a) use 64-bit signed
WiredHome 77:9206c13aa527 526 * integer variables and math, or b) judiciously modify the
WiredHome 77:9206c13aa527 527 * operations to scale results by a factor of 2 or even 4.
WiredHome 77:9206c13aa527 528 *
WiredHome 77:9206c13aa527 529 */
WiredHome 77:9206c13aa527 530 RetCode_t RA8875::TouchPanelPoint(point_t * TouchPoint)
WiredHome 77:9206c13aa527 531 {
WiredHome 77:9206c13aa527 532 RetCode_t retValue = no_touch;
WiredHome 77:9206c13aa527 533 point_t screenpoint = {0, 0};
WiredHome 77:9206c13aa527 534
WiredHome 77:9206c13aa527 535 if (TouchPanelReadRaw(&screenpoint.x, &screenpoint.y)) {
WiredHome 77:9206c13aa527 536 retValue = touch;
WiredHome 77:9206c13aa527 537 if (tpMatrix.Divider != 0 ) {
WiredHome 77:9206c13aa527 538 /* Operation order is important since we are doing integer */
WiredHome 77:9206c13aa527 539 /* math. Make sure you add all terms together before */
WiredHome 77:9206c13aa527 540 /* dividing, so that the remainder is not rounded off */
WiredHome 77:9206c13aa527 541 /* prematurely. */
WiredHome 77:9206c13aa527 542 TouchPoint->x = ( (tpMatrix.An * screenpoint.x) +
WiredHome 77:9206c13aa527 543 (tpMatrix.Bn * screenpoint.y) +
WiredHome 77:9206c13aa527 544 tpMatrix.Cn
WiredHome 77:9206c13aa527 545 ) / tpMatrix.Divider ;
WiredHome 77:9206c13aa527 546
WiredHome 77:9206c13aa527 547 TouchPoint->y = ( (tpMatrix.Dn * screenpoint.x) +
WiredHome 77:9206c13aa527 548 (tpMatrix.En * screenpoint.y) +
WiredHome 77:9206c13aa527 549 tpMatrix.Fn
WiredHome 77:9206c13aa527 550 ) / tpMatrix.Divider ;
WiredHome 77:9206c13aa527 551 } else {
WiredHome 77:9206c13aa527 552 retValue = bad_parameter ;
WiredHome 77:9206c13aa527 553 }
WiredHome 77:9206c13aa527 554 }
WiredHome 77:9206c13aa527 555 return( retValue );
WiredHome 77:9206c13aa527 556 }
WiredHome 77:9206c13aa527 557
WiredHome 77:9206c13aa527 558
WiredHome 77:9206c13aa527 559 RetCode_t RA8875::TouchPanelSetMatrix(tpMatrix_t * matrixPtr)
WiredHome 77:9206c13aa527 560 {
WiredHome 77:9206c13aa527 561 if (matrixPtr == NULL || matrixPtr->Divider == 0)
WiredHome 77:9206c13aa527 562 return bad_parameter;
WiredHome 77:9206c13aa527 563 memcpy(&tpMatrix, matrixPtr, sizeof(tpMatrix_t));
WiredHome 77:9206c13aa527 564 return noerror;
WiredHome 77:9206c13aa527 565 }
WiredHome 77:9206c13aa527 566
hexley 54:e117ad10fba6 567 // #### end of touch panel code additions
WiredHome 53:86d24b9480b9 568
WiredHome 71:dcac8efd842d 569
WiredHome 77:9206c13aa527 570 RetCode_t RA8875::KeypadInit(bool scanEnable, bool longDetect, uint8_t sampleTime, uint8_t scanFrequency,
WiredHome 77:9206c13aa527 571 uint8_t longTimeAdjustment, bool interruptEnable, bool wakeupEnable)
WiredHome 71:dcac8efd842d 572 {
WiredHome 71:dcac8efd842d 573 uint8_t value = 0;
WiredHome 77:9206c13aa527 574
WiredHome 71:dcac8efd842d 575 if (sampleTime > 3 || scanFrequency > 7 || longTimeAdjustment > 3)
WiredHome 71:dcac8efd842d 576 return bad_parameter;
WiredHome 71:dcac8efd842d 577 value |= (scanEnable) ? 0x80 : 0x00;
WiredHome 71:dcac8efd842d 578 value |= (longDetect) ? 0x40 : 0x00;
WiredHome 71:dcac8efd842d 579 value |= (sampleTime & 0x03) << 4;
WiredHome 71:dcac8efd842d 580 value |= (scanFrequency & 0x07);
WiredHome 75:ca78388cfd77 581 WriteCommand(0xC0, value); // KSCR1 - Enable Key Scan (and ignore possibility of an error)
WiredHome 77:9206c13aa527 582
WiredHome 71:dcac8efd842d 583 value = 0;
WiredHome 71:dcac8efd842d 584 value |= (wakeupEnable) ? 0x80 : 0x00;
WiredHome 71:dcac8efd842d 585 value |= (longTimeAdjustment & 0x03) << 2;
WiredHome 75:ca78388cfd77 586 WriteCommand(0xC1, value); // KSCR2 - (and ignore possibility of an error)
WiredHome 77:9206c13aa527 587
WiredHome 75:ca78388cfd77 588 value = ReadCommand(0xF0); // (and ignore possibility of an error)
WiredHome 71:dcac8efd842d 589 value &= ~0x10;
WiredHome 71:dcac8efd842d 590 value |= (interruptEnable) ? 0x10 : 0x00;
WiredHome 75:ca78388cfd77 591 return WriteCommand(0xF0, value); // INT
WiredHome 71:dcac8efd842d 592 }
WiredHome 71:dcac8efd842d 593
WiredHome 75:ca78388cfd77 594 RetCode_t RA8875::SetKeyMap(const uint8_t * CodeList)
WiredHome 75:ca78388cfd77 595 {
WiredHome 75:ca78388cfd77 596 pKeyMap = CodeList;
WiredHome 75:ca78388cfd77 597 return noerror;
WiredHome 75:ca78388cfd77 598 }
WiredHome 75:ca78388cfd77 599
WiredHome 75:ca78388cfd77 600 bool RA8875::readable(void)
WiredHome 71:dcac8efd842d 601 {
WiredHome 71:dcac8efd842d 602 return (ReadCommand(0xF1) & 0x10); // check KS status - true if kbhit
WiredHome 71:dcac8efd842d 603 }
WiredHome 71:dcac8efd842d 604
WiredHome 75:ca78388cfd77 605 uint8_t RA8875::getc(void)
WiredHome 71:dcac8efd842d 606 {
WiredHome 75:ca78388cfd77 607 //#define GETC_DEV
WiredHome 77:9206c13aa527 608 #ifdef GETC_DEV
WiredHome 75:ca78388cfd77 609 uint8_t keyCode1, keyCode2;
WiredHome 77:9206c13aa527 610 #endif
WiredHome 75:ca78388cfd77 611 uint8_t keyCode3;
WiredHome 75:ca78388cfd77 612 static uint8_t count = 0;
WiredHome 75:ca78388cfd77 613 uint8_t col, row;
WiredHome 75:ca78388cfd77 614 uint8_t key;
WiredHome 77:9206c13aa527 615
WiredHome 75:ca78388cfd77 616 while (!readable()) {
WiredHome 71:dcac8efd842d 617 wait_us(POLLWAITuSec);
WiredHome 75:ca78388cfd77 618 // COUNTIDLETIME(POLLWAITuSec); // As it is voluntary to call the getc and pend. Don't tally it.
WiredHome 71:dcac8efd842d 619 }
WiredHome 71:dcac8efd842d 620 // read the key press number
WiredHome 71:dcac8efd842d 621 uint8_t keyNumReg = ReadCommand(0xC1) & 0x03;
WiredHome 75:ca78388cfd77 622 count++;
WiredHome 75:ca78388cfd77 623 switch (keyNumReg) {
WiredHome 75:ca78388cfd77 624 case 0x01: // one key
WiredHome 75:ca78388cfd77 625 keyCode3 = ReadCommand(0xC2);
WiredHome 77:9206c13aa527 626 #ifdef GETC_DEV
WiredHome 75:ca78388cfd77 627 keyCode2 = 0;
WiredHome 75:ca78388cfd77 628 keyCode1 = 0;
WiredHome 77:9206c13aa527 629 #endif
WiredHome 75:ca78388cfd77 630 break;
WiredHome 75:ca78388cfd77 631 case 0x02: // two keys
WiredHome 75:ca78388cfd77 632 keyCode3 = ReadCommand(0xC3);
WiredHome 77:9206c13aa527 633 #ifdef GETC_DEV
WiredHome 75:ca78388cfd77 634 keyCode2 = ReadCommand(0xC2);
WiredHome 75:ca78388cfd77 635 keyCode1 = 0;
WiredHome 77:9206c13aa527 636 #endif
WiredHome 75:ca78388cfd77 637 break;
WiredHome 75:ca78388cfd77 638 case 0x03: // three keys
WiredHome 75:ca78388cfd77 639 keyCode3 = ReadCommand(0xC4);
WiredHome 77:9206c13aa527 640 #ifdef GETC_DEV
WiredHome 75:ca78388cfd77 641 keyCode2 = ReadCommand(0xC3);
WiredHome 75:ca78388cfd77 642 keyCode1 = ReadCommand(0xC2);
WiredHome 77:9206c13aa527 643 #endif
WiredHome 75:ca78388cfd77 644 break;
WiredHome 75:ca78388cfd77 645 default: // no keys (key released)
WiredHome 75:ca78388cfd77 646 keyCode3 = 0xFF;
WiredHome 77:9206c13aa527 647 #ifdef GETC_DEV
WiredHome 75:ca78388cfd77 648 keyCode2 = 0;
WiredHome 75:ca78388cfd77 649 keyCode1 = 0;
WiredHome 77:9206c13aa527 650 #endif
WiredHome 75:ca78388cfd77 651 break;
WiredHome 75:ca78388cfd77 652 }
WiredHome 75:ca78388cfd77 653 if (keyCode3 == 0xFF)
WiredHome 75:ca78388cfd77 654 key = pKeyMap[0]; // Key value 0
WiredHome 75:ca78388cfd77 655 else {
WiredHome 75:ca78388cfd77 656 row = (keyCode3 >> 4) & 0x03;
WiredHome 75:ca78388cfd77 657 col = (keyCode3 & 7);
WiredHome 75:ca78388cfd77 658 key = row * 5 + col + 1; // Keys value 1 - 20
WiredHome 75:ca78388cfd77 659 if (key > 21) {
WiredHome 75:ca78388cfd77 660 key = 21;
WiredHome 75:ca78388cfd77 661 }
WiredHome 75:ca78388cfd77 662 key = pKeyMap[key];
WiredHome 75:ca78388cfd77 663 key |= (keyCode3 & 0x80); // combine the key held flag
WiredHome 75:ca78388cfd77 664 }
WiredHome 77:9206c13aa527 665 #if GETC_DEV // for Development only
WiredHome 75:ca78388cfd77 666 SetTextCursor(0, 20);
WiredHome 75:ca78388cfd77 667 printf(" Reg: %02x\r\n", keyNumReg);
WiredHome 75:ca78388cfd77 668 printf(" key1: %02x\r\n", keyCode1);
WiredHome 75:ca78388cfd77 669 printf(" key2: %02x\r\n", keyCode2);
WiredHome 75:ca78388cfd77 670 printf(" key3: %02x\r\n", keyCode3);
WiredHome 75:ca78388cfd77 671 printf(" count: %02X\r\n", count);
WiredHome 75:ca78388cfd77 672 printf(" key: %02X\r\n", key);
WiredHome 77:9206c13aa527 673 #endif
WiredHome 75:ca78388cfd77 674 WriteCommand(0xF1, 0x10); // Clear KS status
WiredHome 75:ca78388cfd77 675 return key;
WiredHome 71:dcac8efd842d 676 }
WiredHome 71:dcac8efd842d 677
WiredHome 19:3f82c1161fd2 678 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 679 void RA8875::ClearPerformance()
WiredHome 19:3f82c1161fd2 680 {
WiredHome 19:3f82c1161fd2 681 for (int i=0; i<METRICCOUNT; i++)
WiredHome 19:3f82c1161fd2 682 metrics[i] = 0;
WiredHome 75:ca78388cfd77 683 idletime_usec = 0;
WiredHome 19:3f82c1161fd2 684 }
WiredHome 19:3f82c1161fd2 685
WiredHome 19:3f82c1161fd2 686 void RA8875::RegisterPerformance(method_e method)
WiredHome 19:3f82c1161fd2 687 {
WiredHome 19:3f82c1161fd2 688 unsigned long elapsed = performance.read_us();
WiredHome 73:f22a18707b5e 689
WiredHome 19:3f82c1161fd2 690 if (method < METRICCOUNT && elapsed > metrics[method])
WiredHome 19:3f82c1161fd2 691 metrics[method] = elapsed;
WiredHome 19:3f82c1161fd2 692 }
WiredHome 19:3f82c1161fd2 693
WiredHome 66:468a11f05580 694 void RA8875::CountIdleTime(uint32_t t)
WiredHome 66:468a11f05580 695 {
WiredHome 75:ca78388cfd77 696 idletime_usec += t;
WiredHome 66:468a11f05580 697 }
WiredHome 44:207594dece70 698
WiredHome 41:2956a0a221e5 699 void RA8875::ReportPerformance(Serial & pc)
WiredHome 19:3f82c1161fd2 700 {
WiredHome 41:2956a0a221e5 701 pc.printf("\r\nPerformance Metrics\r\n");
WiredHome 19:3f82c1161fd2 702 for (int i=0; i<METRICCOUNT; i++) {
WiredHome 41:2956a0a221e5 703 pc.printf("%10d uS %s\r\n", metrics[i], metricsName[i]);
WiredHome 66:468a11f05580 704 }
WiredHome 75:ca78388cfd77 705 pc.printf("%10d uS Idle time polling display for ready.\r\n", idletime_usec);
WiredHome 19:3f82c1161fd2 706 }
WiredHome 19:3f82c1161fd2 707 #endif
WiredHome 19:3f82c1161fd2 708
WiredHome 44:207594dece70 709
WiredHome 38:38d503b4fad6 710 RetCode_t RA8875::WriteCommandW(uint8_t command, uint16_t data)
WiredHome 38:38d503b4fad6 711 {
WiredHome 73:f22a18707b5e 712 #if 1
WiredHome 38:38d503b4fad6 713 WriteCommand(command, data & 0xFF);
WiredHome 38:38d503b4fad6 714 WriteCommand(command+1, data >> 8);
WiredHome 73:f22a18707b5e 715 #else
WiredHome 41:2956a0a221e5 716 // This should be a little faster, but doesn't work...
WiredHome 38:38d503b4fad6 717 INFO("WriteCommandW(%02X, %04X)", command, data);
WiredHome 38:38d503b4fad6 718 select(true);
WiredHome 38:38d503b4fad6 719 spiwrite(0x80);
WiredHome 38:38d503b4fad6 720 spiwrite(command);
WiredHome 41:2956a0a221e5 721 //spiwrite(0x00); // dummy
WiredHome 38:38d503b4fad6 722 spiwrite(data & 0xFF);
WiredHome 38:38d503b4fad6 723 spiwrite(data >> 8);
WiredHome 38:38d503b4fad6 724 select(false);
WiredHome 73:f22a18707b5e 725 #endif
WiredHome 38:38d503b4fad6 726 return noerror;
WiredHome 38:38d503b4fad6 727 }
WiredHome 38:38d503b4fad6 728
WiredHome 44:207594dece70 729
WiredHome 19:3f82c1161fd2 730 RetCode_t RA8875::WriteCommand(unsigned char command, unsigned int data)
WiredHome 19:3f82c1161fd2 731 {
WiredHome 19:3f82c1161fd2 732 select(true);
WiredHome 41:2956a0a221e5 733 spiwrite(0x80); // cmd: write command
WiredHome 19:3f82c1161fd2 734 spiwrite(command);
WiredHome 19:3f82c1161fd2 735 if (data <= 0xFF) { // only if in the valid range
WiredHome 19:3f82c1161fd2 736 spiwrite(0x00);
WiredHome 19:3f82c1161fd2 737 spiwrite(data);
WiredHome 19:3f82c1161fd2 738 }
WiredHome 19:3f82c1161fd2 739 select(false);
WiredHome 19:3f82c1161fd2 740 return noerror;
WiredHome 19:3f82c1161fd2 741 }
WiredHome 19:3f82c1161fd2 742
WiredHome 44:207594dece70 743
WiredHome 38:38d503b4fad6 744 RetCode_t RA8875::WriteDataW(uint16_t data)
WiredHome 38:38d503b4fad6 745 {
WiredHome 38:38d503b4fad6 746 select(true);
WiredHome 41:2956a0a221e5 747 spiwrite(0x00); // cmd: write data
WiredHome 38:38d503b4fad6 748 spiwrite(data & 0xFF);
WiredHome 38:38d503b4fad6 749 spiwrite(data >> 8);
WiredHome 38:38d503b4fad6 750 select(false);
WiredHome 38:38d503b4fad6 751 return noerror;
WiredHome 38:38d503b4fad6 752 }
WiredHome 38:38d503b4fad6 753
WiredHome 44:207594dece70 754
WiredHome 19:3f82c1161fd2 755 RetCode_t RA8875::WriteData(unsigned char data)
WiredHome 19:3f82c1161fd2 756 {
WiredHome 19:3f82c1161fd2 757 select(true);
WiredHome 19:3f82c1161fd2 758 spiwrite(0x00);
WiredHome 19:3f82c1161fd2 759 spiwrite(data);
WiredHome 19:3f82c1161fd2 760 select(false);
WiredHome 19:3f82c1161fd2 761 return noerror;
WiredHome 19:3f82c1161fd2 762 }
WiredHome 19:3f82c1161fd2 763
WiredHome 44:207594dece70 764
WiredHome 19:3f82c1161fd2 765 unsigned char RA8875::ReadCommand(unsigned char command)
WiredHome 19:3f82c1161fd2 766 {
WiredHome 19:3f82c1161fd2 767 WriteCommand(command);
WiredHome 19:3f82c1161fd2 768 return ReadData();
WiredHome 19:3f82c1161fd2 769 }
WiredHome 19:3f82c1161fd2 770
WiredHome 44:207594dece70 771
WiredHome 19:3f82c1161fd2 772 unsigned char RA8875::ReadData(void)
WiredHome 19:3f82c1161fd2 773 {
WiredHome 19:3f82c1161fd2 774 unsigned char data;
WiredHome 73:f22a18707b5e 775
WiredHome 19:3f82c1161fd2 776 select(true);
WiredHome 19:3f82c1161fd2 777 spiwrite(0x40);
WiredHome 19:3f82c1161fd2 778 data = spiread();
WiredHome 19:3f82c1161fd2 779 select(false);
WiredHome 19:3f82c1161fd2 780 return data;
WiredHome 19:3f82c1161fd2 781 }
WiredHome 19:3f82c1161fd2 782
WiredHome 44:207594dece70 783
WiredHome 41:2956a0a221e5 784 uint16_t RA8875::ReadDataW(void)
WiredHome 41:2956a0a221e5 785 {
WiredHome 41:2956a0a221e5 786 uint16_t data;
WiredHome 73:f22a18707b5e 787
WiredHome 41:2956a0a221e5 788 select(true);
WiredHome 41:2956a0a221e5 789 spiwrite(0x40);
WiredHome 41:2956a0a221e5 790 data = spiread();
WiredHome 41:2956a0a221e5 791 data |= (spiread() << 8);
WiredHome 41:2956a0a221e5 792 select(false);
WiredHome 41:2956a0a221e5 793 return data;
WiredHome 41:2956a0a221e5 794 }
WiredHome 41:2956a0a221e5 795
WiredHome 44:207594dece70 796
WiredHome 19:3f82c1161fd2 797 unsigned char RA8875::ReadStatus(void)
WiredHome 19:3f82c1161fd2 798 {
WiredHome 19:3f82c1161fd2 799 unsigned char data;
WiredHome 73:f22a18707b5e 800
WiredHome 19:3f82c1161fd2 801 select(true);
WiredHome 66:468a11f05580 802 spiwrite(0xC0); // These two bits are for the special "Status Read" [STSR]
WiredHome 19:3f82c1161fd2 803 data = spiread();
WiredHome 19:3f82c1161fd2 804 select(false);
WiredHome 19:3f82c1161fd2 805 return data;
WiredHome 19:3f82c1161fd2 806 }
WiredHome 19:3f82c1161fd2 807
WiredHome 66:468a11f05580 808 /// @todo add a timeout and return false, but how long
WiredHome 66:468a11f05580 809 /// to wait since some operations can be very long.
WiredHome 66:468a11f05580 810 bool RA8875::_WaitWhileBusy(uint8_t mask)
WiredHome 66:468a11f05580 811 {
WiredHome 66:468a11f05580 812 int i = 20000/POLLWAITuSec; // 20 msec max
WiredHome 66:468a11f05580 813
WiredHome 67:9f834f0ff97d 814 while (i-- && ReadStatus() & mask) {
WiredHome 66:468a11f05580 815 wait_us(POLLWAITuSec);
WiredHome 68:ab08efabfc88 816 COUNTIDLETIME(POLLWAITuSec);
WiredHome 67:9f834f0ff97d 817 }
WiredHome 66:468a11f05580 818 if (i)
WiredHome 66:468a11f05580 819 return true;
WiredHome 66:468a11f05580 820 else
WiredHome 66:468a11f05580 821 return false;
WiredHome 66:468a11f05580 822 }
WiredHome 66:468a11f05580 823
WiredHome 66:468a11f05580 824 /// @todo add a timeout and return false, but how long
WiredHome 66:468a11f05580 825 /// to wait since some operations can be very long.
WiredHome 66:468a11f05580 826 bool RA8875::_WaitWhileReg(uint8_t reg, uint8_t mask)
WiredHome 66:468a11f05580 827 {
WiredHome 66:468a11f05580 828 int i = 20000/POLLWAITuSec; // 20 msec max
WiredHome 66:468a11f05580 829
WiredHome 67:9f834f0ff97d 830 while (i-- && ReadCommand(reg) & mask) {
WiredHome 66:468a11f05580 831 wait_us(POLLWAITuSec);
WiredHome 68:ab08efabfc88 832 COUNTIDLETIME(POLLWAITuSec);
WiredHome 67:9f834f0ff97d 833 }
WiredHome 66:468a11f05580 834 if (i)
WiredHome 66:468a11f05580 835 return true;
WiredHome 66:468a11f05580 836 else
WiredHome 66:468a11f05580 837 return false;
WiredHome 66:468a11f05580 838 }
WiredHome 66:468a11f05580 839
WiredHome 66:468a11f05580 840
WiredHome 44:207594dece70 841
WiredHome 37:f19b7e7449dc 842 dim_t RA8875::fontwidth(void)
WiredHome 19:3f82c1161fd2 843 {
WiredHome 19:3f82c1161fd2 844 if (font == NULL)
WiredHome 55:dfbabef7003e 845 return (((ReadCommand(0x22) >> 2) & 0x3) + 1) * 8;
WiredHome 19:3f82c1161fd2 846 else
WiredHome 29:422616aa04bd 847 return font[1];
WiredHome 19:3f82c1161fd2 848 }
WiredHome 19:3f82c1161fd2 849
WiredHome 44:207594dece70 850
WiredHome 37:f19b7e7449dc 851 dim_t RA8875::fontheight(void)
WiredHome 19:3f82c1161fd2 852 {
WiredHome 19:3f82c1161fd2 853 if (font == NULL)
WiredHome 23:a50ded45dbaf 854 return (((ReadCommand(0x22) >> 0) & 0x3) + 1) * 16;
WiredHome 19:3f82c1161fd2 855 else
WiredHome 29:422616aa04bd 856 return font[2];
WiredHome 19:3f82c1161fd2 857 }
WiredHome 19:3f82c1161fd2 858
WiredHome 44:207594dece70 859
WiredHome 37:f19b7e7449dc 860 RetCode_t RA8875::locate(textloc_t column, textloc_t row)
WiredHome 19:3f82c1161fd2 861 {
WiredHome 32:0e4f2ae512e2 862 return SetTextCursor(column * fontwidth(), row * fontheight());
WiredHome 19:3f82c1161fd2 863 }
WiredHome 19:3f82c1161fd2 864
WiredHome 44:207594dece70 865
WiredHome 19:3f82c1161fd2 866 int RA8875::columns(void)
WiredHome 19:3f82c1161fd2 867 {
WiredHome 19:3f82c1161fd2 868 return width() / fontwidth();
WiredHome 19:3f82c1161fd2 869 }
WiredHome 19:3f82c1161fd2 870
WiredHome 44:207594dece70 871
WiredHome 19:3f82c1161fd2 872 int RA8875::rows(void)
WiredHome 19:3f82c1161fd2 873 {
WiredHome 19:3f82c1161fd2 874 return height() / fontheight();
WiredHome 19:3f82c1161fd2 875 }
WiredHome 19:3f82c1161fd2 876
WiredHome 44:207594dece70 877
WiredHome 38:38d503b4fad6 878 dim_t RA8875::width(void)
WiredHome 19:3f82c1161fd2 879 {
WiredHome 29:422616aa04bd 880 return (ReadCommand(0x14) + 1) * 8;
WiredHome 19:3f82c1161fd2 881 }
WiredHome 19:3f82c1161fd2 882
WiredHome 44:207594dece70 883
WiredHome 38:38d503b4fad6 884 dim_t RA8875::height(void)
WiredHome 19:3f82c1161fd2 885 {
WiredHome 29:422616aa04bd 886 return (ReadCommand(0x19) | (ReadCommand(0x1A) << 8)) + 1;
WiredHome 19:3f82c1161fd2 887 }
WiredHome 19:3f82c1161fd2 888
WiredHome 44:207594dece70 889
WiredHome 43:3becae133285 890 dim_t RA8875::color_bpp(void)
WiredHome 43:3becae133285 891 {
WiredHome 43:3becae133285 892 if ((ReadCommand(0x10) & 0x0C) == 0x04)
WiredHome 43:3becae133285 893 return 16;
WiredHome 43:3becae133285 894 else
WiredHome 43:3becae133285 895 return 8;
WiredHome 43:3becae133285 896 }
WiredHome 43:3becae133285 897
WiredHome 44:207594dece70 898
WiredHome 37:f19b7e7449dc 899 RetCode_t RA8875::SetTextCursor(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 900 {
WiredHome 75:ca78388cfd77 901 cursor_x = x; // set these values for non-internal fonts
WiredHome 75:ca78388cfd77 902 cursor_y = y;
WiredHome 38:38d503b4fad6 903 WriteCommandW(0x2A, x);
WiredHome 38:38d503b4fad6 904 WriteCommandW(0x2C, y);
WiredHome 19:3f82c1161fd2 905 return noerror;
WiredHome 19:3f82c1161fd2 906 }
WiredHome 19:3f82c1161fd2 907
WiredHome 44:207594dece70 908
WiredHome 37:f19b7e7449dc 909 loc_t RA8875::GetTextCursor_Y(void)
WiredHome 29:422616aa04bd 910 {
WiredHome 29:422616aa04bd 911 if (font == NULL)
WiredHome 29:422616aa04bd 912 return ReadCommand(0x2C) | (ReadCommand(0x2D) << 8);
WiredHome 29:422616aa04bd 913 else
WiredHome 29:422616aa04bd 914 return cursor_y;
WiredHome 29:422616aa04bd 915 }
WiredHome 29:422616aa04bd 916
WiredHome 44:207594dece70 917
WiredHome 37:f19b7e7449dc 918 loc_t RA8875::GetTextCursor_X(void)
WiredHome 29:422616aa04bd 919 {
WiredHome 29:422616aa04bd 920 if (font == NULL)
WiredHome 29:422616aa04bd 921 return ReadCommand(0x2A) | (ReadCommand(0x2B) << 8);
WiredHome 29:422616aa04bd 922 else
WiredHome 29:422616aa04bd 923 return cursor_x;
WiredHome 29:422616aa04bd 924 }
WiredHome 29:422616aa04bd 925
WiredHome 44:207594dece70 926
WiredHome 24:8ca861acf12d 927 RetCode_t RA8875::SetTextCursorControl(cursor_t cursor, bool blink)
WiredHome 23:a50ded45dbaf 928 {
WiredHome 23:a50ded45dbaf 929 unsigned char mwcr0 = ReadCommand(0x40) & 0x0F; // retain direction, auto-increase
WiredHome 43:3becae133285 930 unsigned char mwcr1 = ReadCommand(0x41) & 0x01; // retain currently selected layer
WiredHome 24:8ca861acf12d 931 unsigned char horz = 0;
WiredHome 24:8ca861acf12d 932 unsigned char vert = 0;
WiredHome 73:f22a18707b5e 933
WiredHome 24:8ca861acf12d 934 mwcr0 |= 0x80; // text mode
WiredHome 24:8ca861acf12d 935 if (cursor != NOCURSOR)
WiredHome 24:8ca861acf12d 936 mwcr0 |= 0x40; // visible
WiredHome 23:a50ded45dbaf 937 if (blink)
WiredHome 24:8ca861acf12d 938 mwcr0 |= 0x20; // blink
WiredHome 23:a50ded45dbaf 939 WriteCommand(0x40, mwcr0); // configure the cursor
WiredHome 43:3becae133285 940 WriteCommand(0x41, mwcr1); // close the graphics cursor
WiredHome 24:8ca861acf12d 941 WriteCommand(0x44, 0x1f); // The cursor flashing cycle
WiredHome 24:8ca861acf12d 942 switch (cursor) {
WiredHome 24:8ca861acf12d 943 case IBEAM:
WiredHome 24:8ca861acf12d 944 horz = 0x01;
WiredHome 24:8ca861acf12d 945 vert = 0x1F;
WiredHome 24:8ca861acf12d 946 break;
WiredHome 24:8ca861acf12d 947 case UNDER:
WiredHome 24:8ca861acf12d 948 horz = 0x07;
WiredHome 24:8ca861acf12d 949 vert = 0x01;
WiredHome 24:8ca861acf12d 950 break;
WiredHome 24:8ca861acf12d 951 case BLOCK:
WiredHome 24:8ca861acf12d 952 horz = 0x07;
WiredHome 24:8ca861acf12d 953 vert = 0x1F;
WiredHome 24:8ca861acf12d 954 break;
WiredHome 24:8ca861acf12d 955 case NOCURSOR:
WiredHome 24:8ca861acf12d 956 default:
WiredHome 24:8ca861acf12d 957 break;
WiredHome 24:8ca861acf12d 958 }
WiredHome 24:8ca861acf12d 959 WriteCommand(0x4e, horz); // The cursor size horz
WiredHome 24:8ca861acf12d 960 WriteCommand(0x4f, vert); // The cursor size vert
WiredHome 23:a50ded45dbaf 961 return noerror;
WiredHome 23:a50ded45dbaf 962 }
WiredHome 23:a50ded45dbaf 963
WiredHome 44:207594dece70 964
WiredHome 19:3f82c1161fd2 965 RetCode_t RA8875::SetTextFont(RA8875::font_t font)
WiredHome 19:3f82c1161fd2 966 {
WiredHome 19:3f82c1161fd2 967 if (/*font >= RA8875::ISO8859_1 && */ font <= RA8875::ISO8859_4) {
WiredHome 19:3f82c1161fd2 968 WriteCommand(0x21, (unsigned int)(font));
WiredHome 19:3f82c1161fd2 969 return noerror;
WiredHome 19:3f82c1161fd2 970 } else {
WiredHome 19:3f82c1161fd2 971 return bad_parameter;
WiredHome 19:3f82c1161fd2 972 }
WiredHome 19:3f82c1161fd2 973 }
WiredHome 19:3f82c1161fd2 974
WiredHome 44:207594dece70 975
WiredHome 19:3f82c1161fd2 976 RetCode_t RA8875::SetTextFontControl(fill_t fillit,
WiredHome 73:f22a18707b5e 977 RA8875::font_angle_t angle,
WiredHome 73:f22a18707b5e 978 RA8875::HorizontalScale hScale,
WiredHome 73:f22a18707b5e 979 RA8875::VerticalScale vScale,
WiredHome 73:f22a18707b5e 980 RA8875::alignment_t alignment)
WiredHome 19:3f82c1161fd2 981 {
WiredHome 73:f22a18707b5e 982 if (hScale >= 1 && hScale <= 4 &&
WiredHome 73:f22a18707b5e 983 vScale >= 1 && vScale <= 4) {
WiredHome 19:3f82c1161fd2 984 unsigned char x = 0;
WiredHome 73:f22a18707b5e 985
WiredHome 19:3f82c1161fd2 986 if (alignment == align_full)
WiredHome 19:3f82c1161fd2 987 x |= 0x80;
WiredHome 19:3f82c1161fd2 988 if (fillit == NOFILL)
WiredHome 19:3f82c1161fd2 989 x |= 0x40;
WiredHome 19:3f82c1161fd2 990 if (angle == rotated)
WiredHome 19:3f82c1161fd2 991 x |= 0x10;
WiredHome 19:3f82c1161fd2 992 x |= ((hScale - 1) << 2);
WiredHome 19:3f82c1161fd2 993 x |= ((vScale - 1) << 0);
WiredHome 19:3f82c1161fd2 994 WriteCommand(0x22, x);
WiredHome 19:3f82c1161fd2 995 return noerror;
WiredHome 19:3f82c1161fd2 996 } else {
WiredHome 19:3f82c1161fd2 997 return bad_parameter;
WiredHome 19:3f82c1161fd2 998 }
WiredHome 19:3f82c1161fd2 999 }
WiredHome 19:3f82c1161fd2 1000
WiredHome 44:207594dece70 1001
WiredHome 19:3f82c1161fd2 1002 RetCode_t RA8875::SetTextFontSize(RA8875::HorizontalScale hScale, RA8875::VerticalScale vScale)
WiredHome 19:3f82c1161fd2 1003 {
WiredHome 19:3f82c1161fd2 1004 unsigned char reg = ReadCommand(0x22);
WiredHome 73:f22a18707b5e 1005
WiredHome 40:04aa280dfa39 1006 if (vScale == -1)
WiredHome 40:04aa280dfa39 1007 vScale = hScale;
WiredHome 19:3f82c1161fd2 1008 if (hScale >= 1 && hScale <= 4 && vScale >= 1 && vScale <= 4) {
WiredHome 19:3f82c1161fd2 1009 reg &= 0xF0; // keep the high nibble as is.
WiredHome 19:3f82c1161fd2 1010 reg |= ((hScale - 1) << 2);
WiredHome 19:3f82c1161fd2 1011 reg |= ((vScale - 1) << 0);
WiredHome 19:3f82c1161fd2 1012 WriteCommand(0x22, reg);
WiredHome 19:3f82c1161fd2 1013 return noerror;
WiredHome 19:3f82c1161fd2 1014 } else {
WiredHome 19:3f82c1161fd2 1015 return bad_parameter;
WiredHome 19:3f82c1161fd2 1016 }
WiredHome 19:3f82c1161fd2 1017 }
WiredHome 19:3f82c1161fd2 1018
WiredHome 44:207594dece70 1019
WiredHome 19:3f82c1161fd2 1020 int RA8875::_putc(int c)
WiredHome 19:3f82c1161fd2 1021 {
WiredHome 29:422616aa04bd 1022 if (font == NULL) {
WiredHome 29:422616aa04bd 1023 return _internal_putc(c);
WiredHome 29:422616aa04bd 1024 } else {
WiredHome 29:422616aa04bd 1025 return _external_putc(c);
WiredHome 29:422616aa04bd 1026 }
WiredHome 29:422616aa04bd 1027 }
WiredHome 29:422616aa04bd 1028
WiredHome 44:207594dece70 1029
WiredHome 29:422616aa04bd 1030 int RA8875::_external_putc(int c)
WiredHome 29:422616aa04bd 1031 {
WiredHome 19:3f82c1161fd2 1032 if (c) {
WiredHome 19:3f82c1161fd2 1033 if (c == '\r') {
WiredHome 29:422616aa04bd 1034 cursor_x = 0;
WiredHome 29:422616aa04bd 1035 } else if (c == '\n') {
WiredHome 29:422616aa04bd 1036 cursor_y += font[2];
WiredHome 29:422616aa04bd 1037 } else {
WiredHome 29:422616aa04bd 1038 int advance = character(cursor_x, cursor_y, c); // advance tells us how many pixels we advanced
WiredHome 37:f19b7e7449dc 1039 //INFO("x,y,advance %d,%d,%d", cursor_x, cursor_y, advance);
WiredHome 29:422616aa04bd 1040 if (advance) {
WiredHome 29:422616aa04bd 1041 cursor_x += advance;
WiredHome 29:422616aa04bd 1042 if (cursor_x >= width()) {
WiredHome 29:422616aa04bd 1043 cursor_x = 0;
WiredHome 29:422616aa04bd 1044 cursor_y += font[2];
WiredHome 29:422616aa04bd 1045 if (cursor_y >= height()) {
WiredHome 29:422616aa04bd 1046 cursor_y = 0; // @todo Should it scroll?
WiredHome 29:422616aa04bd 1047 }
WiredHome 29:422616aa04bd 1048 }
WiredHome 29:422616aa04bd 1049 }
WiredHome 29:422616aa04bd 1050 }
WiredHome 29:422616aa04bd 1051 }
WiredHome 29:422616aa04bd 1052 return c;
WiredHome 29:422616aa04bd 1053 }
WiredHome 29:422616aa04bd 1054
WiredHome 44:207594dece70 1055
WiredHome 29:422616aa04bd 1056 int RA8875::_internal_putc(int c)
WiredHome 29:422616aa04bd 1057 {
WiredHome 29:422616aa04bd 1058 if (c) {
WiredHome 29:422616aa04bd 1059 unsigned char mwcr0;
WiredHome 73:f22a18707b5e 1060
WiredHome 29:422616aa04bd 1061 mwcr0 = ReadCommand(0x40);
WiredHome 29:422616aa04bd 1062 if ((mwcr0 & 0x80) == 0x00) {
WiredHome 29:422616aa04bd 1063 WriteCommand(0x40, 0x80 | mwcr0); // Put in Text mode if not already
WiredHome 29:422616aa04bd 1064 }
WiredHome 29:422616aa04bd 1065 if (c == '\r') {
WiredHome 37:f19b7e7449dc 1066 loc_t x;
WiredHome 19:3f82c1161fd2 1067 x = ReadCommand(0x30) | (ReadCommand(0x31) << 8); // Left edge of active window
WiredHome 38:38d503b4fad6 1068 WriteCommandW(0x2A, x);
WiredHome 19:3f82c1161fd2 1069 } else if (c == '\n') {
WiredHome 37:f19b7e7449dc 1070 loc_t y;
WiredHome 19:3f82c1161fd2 1071 y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); // current y location
WiredHome 19:3f82c1161fd2 1072 y += fontheight();
WiredHome 47:d96a09269f91 1073 if (y >= height()) // @TODO after bottom of active window, then scroll window?
WiredHome 19:3f82c1161fd2 1074 y = 0;
WiredHome 38:38d503b4fad6 1075 WriteCommandW(0x2C, y);
WiredHome 19:3f82c1161fd2 1076 } else {
WiredHome 29:422616aa04bd 1077 WriteCommand(0x02); // RA8875 Internal Fonts
WiredHome 29:422616aa04bd 1078 select(true);
WiredHome 29:422616aa04bd 1079 WriteData(c);
WiredHome 66:468a11f05580 1080 _WaitWhileBusy(0x80);
WiredHome 29:422616aa04bd 1081 select(false);
WiredHome 19:3f82c1161fd2 1082 }
WiredHome 19:3f82c1161fd2 1083 }
WiredHome 19:3f82c1161fd2 1084 return c;
WiredHome 19:3f82c1161fd2 1085 }
WiredHome 19:3f82c1161fd2 1086
WiredHome 44:207594dece70 1087
WiredHome 32:0e4f2ae512e2 1088 RetCode_t RA8875::_StartGraphicsStream(void)
WiredHome 32:0e4f2ae512e2 1089 {
WiredHome 32:0e4f2ae512e2 1090 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 32:0e4f2ae512e2 1091 WriteCommand(0x02); // Prepare for streaming data
WiredHome 32:0e4f2ae512e2 1092 return noerror;
WiredHome 32:0e4f2ae512e2 1093 }
WiredHome 32:0e4f2ae512e2 1094
WiredHome 44:207594dece70 1095
WiredHome 32:0e4f2ae512e2 1096 RetCode_t RA8875::_EndGraphicsStream(void)
WiredHome 32:0e4f2ae512e2 1097 {
WiredHome 32:0e4f2ae512e2 1098 return noerror;
WiredHome 32:0e4f2ae512e2 1099 }
WiredHome 32:0e4f2ae512e2 1100
WiredHome 44:207594dece70 1101
WiredHome 55:dfbabef7003e 1102 RetCode_t RA8875::_putp(color_t pixel)
WiredHome 32:0e4f2ae512e2 1103 {
WiredHome 38:38d503b4fad6 1104 WriteDataW((pixel>>8) | (pixel<<8));
WiredHome 73:f22a18707b5e 1105 return noerror;
WiredHome 32:0e4f2ae512e2 1106 }
WiredHome 29:422616aa04bd 1107
WiredHome 44:207594dece70 1108
WiredHome 37:f19b7e7449dc 1109 void RA8875::puts(loc_t x, loc_t y, const char * string)
WiredHome 19:3f82c1161fd2 1110 {
WiredHome 19:3f82c1161fd2 1111 SetTextCursor(x,y);
WiredHome 19:3f82c1161fd2 1112 puts(string);
WiredHome 19:3f82c1161fd2 1113 }
WiredHome 19:3f82c1161fd2 1114
WiredHome 44:207594dece70 1115
WiredHome 19:3f82c1161fd2 1116 void RA8875::puts(const char * string)
WiredHome 19:3f82c1161fd2 1117 {
WiredHome 29:422616aa04bd 1118 unsigned char mwcr0 = ReadCommand(0x40);
WiredHome 73:f22a18707b5e 1119
WiredHome 37:f19b7e7449dc 1120 if (font == NULL) {
WiredHome 37:f19b7e7449dc 1121 if ((mwcr0 & 0x80) == 0x00)
WiredHome 37:f19b7e7449dc 1122 WriteCommand(0x40,0x80); // Put in Text mode if not already
WiredHome 37:f19b7e7449dc 1123 } else {
WiredHome 37:f19b7e7449dc 1124 _StartGraphicsStream();
WiredHome 37:f19b7e7449dc 1125 }
WiredHome 19:3f82c1161fd2 1126 if (*string != '\0') {
WiredHome 73:f22a18707b5e 1127 #if 1
WiredHome 29:422616aa04bd 1128 while (*string) { // @TODO calling individual _putc is slower... optimizations?
WiredHome 19:3f82c1161fd2 1129 _putc(*string++);
WiredHome 19:3f82c1161fd2 1130 }
WiredHome 73:f22a18707b5e 1131 #else
WiredHome 19:3f82c1161fd2 1132 WriteCommand(0x02);
WiredHome 19:3f82c1161fd2 1133 select(true);
WiredHome 19:3f82c1161fd2 1134 while (*string != '\0') {
WiredHome 19:3f82c1161fd2 1135 WriteData(*string);
WiredHome 19:3f82c1161fd2 1136 ++string;
WiredHome 66:468a11f05580 1137 _WaitWhileBusy(0x80);
WiredHome 19:3f82c1161fd2 1138 }
WiredHome 19:3f82c1161fd2 1139 select(false);
WiredHome 73:f22a18707b5e 1140 #endif
WiredHome 19:3f82c1161fd2 1141 }
WiredHome 37:f19b7e7449dc 1142 if (font)
WiredHome 37:f19b7e7449dc 1143 _EndGraphicsStream();
WiredHome 19:3f82c1161fd2 1144 }
WiredHome 19:3f82c1161fd2 1145
WiredHome 44:207594dece70 1146
WiredHome 37:f19b7e7449dc 1147 RetCode_t RA8875::SetGraphicsCursor(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 1148 {
WiredHome 38:38d503b4fad6 1149 WriteCommandW(0x46, x);
WiredHome 38:38d503b4fad6 1150 WriteCommandW(0x48, y);
WiredHome 19:3f82c1161fd2 1151 return noerror;
WiredHome 19:3f82c1161fd2 1152 }
WiredHome 19:3f82c1161fd2 1153
WiredHome 44:207594dece70 1154
WiredHome 41:2956a0a221e5 1155 RetCode_t RA8875::SetGraphicsCursorRead(loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1156 {
WiredHome 41:2956a0a221e5 1157 //WriteCommand(0x40, 0); // Graphics mode
WiredHome 41:2956a0a221e5 1158 //WriteCommand(0x45, 0); // left->right, top->bottom
WiredHome 41:2956a0a221e5 1159 WriteCommandW(0x4A, x);
WiredHome 41:2956a0a221e5 1160 WriteCommandW(0x4C, y);
WiredHome 41:2956a0a221e5 1161 return noerror;
WiredHome 41:2956a0a221e5 1162 }
WiredHome 41:2956a0a221e5 1163
WiredHome 44:207594dece70 1164
WiredHome 37:f19b7e7449dc 1165 RetCode_t RA8875::window(loc_t x, loc_t y, dim_t width, dim_t height)
WiredHome 19:3f82c1161fd2 1166 {
WiredHome 37:f19b7e7449dc 1167 GraphicsDisplay::window(x,y, width,height);
WiredHome 38:38d503b4fad6 1168 WriteCommandW(0x30, x);
WiredHome 38:38d503b4fad6 1169 WriteCommandW(0x32, y);
WiredHome 38:38d503b4fad6 1170 WriteCommandW(0x34, (x+width-1));
WiredHome 38:38d503b4fad6 1171 WriteCommandW(0x36, (y+height-1));
WiredHome 37:f19b7e7449dc 1172 SetGraphicsCursor(x,y);
WiredHome 19:3f82c1161fd2 1173 return noerror;
WiredHome 19:3f82c1161fd2 1174 }
WiredHome 19:3f82c1161fd2 1175
WiredHome 44:207594dece70 1176
WiredHome 61:8f3153bf0baa 1177 RetCode_t RA8875::cls(uint16_t layers)
WiredHome 19:3f82c1161fd2 1178 {
WiredHome 61:8f3153bf0baa 1179 RetCode_t ret;
WiredHome 73:f22a18707b5e 1180
WiredHome 19:3f82c1161fd2 1181 PERFORMANCE_RESET;
WiredHome 61:8f3153bf0baa 1182 if (layers == 0) {
WiredHome 61:8f3153bf0baa 1183 ret = clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1184 ret = SetTextCursor(0,0);
WiredHome 61:8f3153bf0baa 1185 } else if (layers > 3) {
WiredHome 61:8f3153bf0baa 1186 ret = bad_parameter;
WiredHome 61:8f3153bf0baa 1187 } else {
WiredHome 61:8f3153bf0baa 1188 uint16_t prevLayer = GetDrawingLayer();
WiredHome 61:8f3153bf0baa 1189 if (layers & 1) {
WiredHome 61:8f3153bf0baa 1190 SelectDrawingLayer(0);
WiredHome 61:8f3153bf0baa 1191 clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1192 }
WiredHome 61:8f3153bf0baa 1193 if (layers & 2) {
WiredHome 61:8f3153bf0baa 1194 SelectDrawingLayer(1);
WiredHome 61:8f3153bf0baa 1195 clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 1196 }
WiredHome 61:8f3153bf0baa 1197 ret = SelectDrawingLayer(prevLayer);
WiredHome 61:8f3153bf0baa 1198 }
WiredHome 19:3f82c1161fd2 1199 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 61:8f3153bf0baa 1200 return ret;
WiredHome 19:3f82c1161fd2 1201 }
WiredHome 19:3f82c1161fd2 1202
WiredHome 44:207594dece70 1203
WiredHome 19:3f82c1161fd2 1204 RetCode_t RA8875::clsw(RA8875::Region_t region)
WiredHome 19:3f82c1161fd2 1205 {
WiredHome 19:3f82c1161fd2 1206 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1207 WriteCommand(0x8E, (region == ACTIVEWINDOW) ? 0xC0 : 0x80);
WiredHome 66:468a11f05580 1208 _WaitWhileReg(0x8E, 0x80);
WiredHome 19:3f82c1161fd2 1209 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 19:3f82c1161fd2 1210 return noerror;
WiredHome 19:3f82c1161fd2 1211 }
WiredHome 19:3f82c1161fd2 1212
WiredHome 44:207594dece70 1213
WiredHome 37:f19b7e7449dc 1214 RetCode_t RA8875::pixel(loc_t x, loc_t y, color_t color)
WiredHome 19:3f82c1161fd2 1215 {
WiredHome 62:ba5d33438fda 1216 RetCode_t ret;
WiredHome 73:f22a18707b5e 1217
WiredHome 62:ba5d33438fda 1218 PERFORMANCE_RESET;
WiredHome 73:f22a18707b5e 1219 #if 1
WiredHome 62:ba5d33438fda 1220 ret = pixelStream(&color, 1, x,y);
WiredHome 73:f22a18707b5e 1221 #else
WiredHome 19:3f82c1161fd2 1222 foreground(color);
WiredHome 62:ba5d33438fda 1223 ret = pixel(x,y);
WiredHome 73:f22a18707b5e 1224 #endif
WiredHome 62:ba5d33438fda 1225 REGISTERPERFORMANCE(PRF_DRAWPIXEL);
WiredHome 62:ba5d33438fda 1226 return ret;
WiredHome 19:3f82c1161fd2 1227 }
WiredHome 19:3f82c1161fd2 1228
WiredHome 44:207594dece70 1229
WiredHome 37:f19b7e7449dc 1230 RetCode_t RA8875::pixel(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 1231 {
WiredHome 19:3f82c1161fd2 1232 RetCode_t ret;
WiredHome 73:f22a18707b5e 1233
WiredHome 19:3f82c1161fd2 1234 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1235 color_t color = GetForeColor();
WiredHome 73:f22a18707b5e 1236 #if 1
WiredHome 62:ba5d33438fda 1237 ret = pixelStream(&color, 1, x, y);
WiredHome 73:f22a18707b5e 1238 #else
WiredHome 19:3f82c1161fd2 1239 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 32:0e4f2ae512e2 1240 SetGraphicsCursor(x, y);
WiredHome 38:38d503b4fad6 1241 WriteCommand(0x02);
WiredHome 38:38d503b4fad6 1242 WriteDataW(color);
WiredHome 19:3f82c1161fd2 1243 ret = noerror;
WiredHome 73:f22a18707b5e 1244 #endif
WiredHome 41:2956a0a221e5 1245 REGISTERPERFORMANCE(PRF_DRAWPIXEL);
WiredHome 19:3f82c1161fd2 1246 return ret;
WiredHome 19:3f82c1161fd2 1247 }
WiredHome 19:3f82c1161fd2 1248
WiredHome 44:207594dece70 1249
WiredHome 41:2956a0a221e5 1250 RetCode_t RA8875::pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1251 {
WiredHome 41:2956a0a221e5 1252 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 1253 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 41:2956a0a221e5 1254 SetGraphicsCursor(x, y);
WiredHome 41:2956a0a221e5 1255 WriteCommand(0x02);
WiredHome 41:2956a0a221e5 1256 select(true);
WiredHome 41:2956a0a221e5 1257 spiwrite(0x00); // Cmd: write data
WiredHome 41:2956a0a221e5 1258 while (count--) {
WiredHome 41:2956a0a221e5 1259 spiwrite(*p >> 8);
WiredHome 41:2956a0a221e5 1260 spiwrite(*p & 0xFF);
WiredHome 41:2956a0a221e5 1261 p++;
WiredHome 41:2956a0a221e5 1262 }
WiredHome 41:2956a0a221e5 1263 select(false);
WiredHome 41:2956a0a221e5 1264 REGISTERPERFORMANCE(PRF_PIXELSTREAM);
WiredHome 41:2956a0a221e5 1265 return(noerror);
WiredHome 41:2956a0a221e5 1266 }
WiredHome 41:2956a0a221e5 1267
WiredHome 44:207594dece70 1268
WiredHome 41:2956a0a221e5 1269 color_t RA8875::getPixel(loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1270 {
WiredHome 41:2956a0a221e5 1271 color_t pixel;
WiredHome 73:f22a18707b5e 1272
WiredHome 41:2956a0a221e5 1273 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 1274 //WriteCommand(0x45,0x00); // read left->right, top->bottom
WiredHome 41:2956a0a221e5 1275 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 41:2956a0a221e5 1276 SetGraphicsCursorRead(x, y);
WiredHome 41:2956a0a221e5 1277 WriteCommand(0x02);
WiredHome 41:2956a0a221e5 1278 select(true);
WiredHome 41:2956a0a221e5 1279 spiwrite(0x40); // Cmd: read data
WiredHome 41:2956a0a221e5 1280 spiwrite(0x00); // dummy read
WiredHome 41:2956a0a221e5 1281 pixel = spiread();
WiredHome 41:2956a0a221e5 1282 pixel |= (spiread() << 8);
WiredHome 41:2956a0a221e5 1283 select(false);
WiredHome 41:2956a0a221e5 1284 REGISTERPERFORMANCE(PRF_READPIXEL);
WiredHome 41:2956a0a221e5 1285 return pixel;
WiredHome 41:2956a0a221e5 1286 }
WiredHome 41:2956a0a221e5 1287
WiredHome 44:207594dece70 1288
WiredHome 41:2956a0a221e5 1289 RetCode_t RA8875::getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 1290 {
WiredHome 41:2956a0a221e5 1291 color_t pixel;
WiredHome 73:f22a18707b5e 1292
WiredHome 41:2956a0a221e5 1293 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 1294 //WriteCommand(0x45,0x00); // read left->right, top->bottom
WiredHome 41:2956a0a221e5 1295 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 41:2956a0a221e5 1296 SetGraphicsCursorRead(x, y);
WiredHome 41:2956a0a221e5 1297 WriteCommand(0x02);
WiredHome 41:2956a0a221e5 1298 select(true);
WiredHome 41:2956a0a221e5 1299 spiwrite(0x40); // Cmd: read data
WiredHome 41:2956a0a221e5 1300 spiwrite(0x00); // dummy read
WiredHome 41:2956a0a221e5 1301 while (count--) {
WiredHome 41:2956a0a221e5 1302 pixel = spiread();
WiredHome 41:2956a0a221e5 1303 pixel |= (spiread() << 8);
WiredHome 41:2956a0a221e5 1304 *p++ = pixel;
WiredHome 41:2956a0a221e5 1305 }
WiredHome 41:2956a0a221e5 1306 select(false);
WiredHome 41:2956a0a221e5 1307 REGISTERPERFORMANCE(PRF_READPIXELSTREAM);
WiredHome 41:2956a0a221e5 1308 return noerror;
WiredHome 41:2956a0a221e5 1309 }
WiredHome 41:2956a0a221e5 1310
WiredHome 44:207594dece70 1311
WiredHome 37:f19b7e7449dc 1312 RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color)
WiredHome 19:3f82c1161fd2 1313 {
WiredHome 19:3f82c1161fd2 1314 foreground(color);
WiredHome 19:3f82c1161fd2 1315 return line(x1,y1,x2,y2);
WiredHome 19:3f82c1161fd2 1316 }
WiredHome 19:3f82c1161fd2 1317
WiredHome 44:207594dece70 1318
WiredHome 37:f19b7e7449dc 1319 RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2)
WiredHome 19:3f82c1161fd2 1320 {
WiredHome 19:3f82c1161fd2 1321 PERFORMANCE_RESET;
WiredHome 62:ba5d33438fda 1322 if (x1 == x2 && y1 == y2) {
WiredHome 60:2dfd574f63bd 1323 pixel(x1, y1);
WiredHome 62:ba5d33438fda 1324 } else {
WiredHome 60:2dfd574f63bd 1325 WriteCommandW(0x91, x1);
WiredHome 60:2dfd574f63bd 1326 WriteCommandW(0x93, y1);
WiredHome 60:2dfd574f63bd 1327 WriteCommandW(0x95, x2);
WiredHome 60:2dfd574f63bd 1328 WriteCommandW(0x97, y2);
WiredHome 60:2dfd574f63bd 1329 unsigned char drawCmd = 0x00; // Line
WiredHome 60:2dfd574f63bd 1330 WriteCommand(0x90, drawCmd);
WiredHome 60:2dfd574f63bd 1331 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1332 _WaitWhileReg(0x90, 0x80);
WiredHome 60:2dfd574f63bd 1333 }
WiredHome 19:3f82c1161fd2 1334 REGISTERPERFORMANCE(PRF_DRAWLINE);
WiredHome 19:3f82c1161fd2 1335 return noerror;
WiredHome 19:3f82c1161fd2 1336 }
WiredHome 19:3f82c1161fd2 1337
WiredHome 44:207594dece70 1338
WiredHome 73:f22a18707b5e 1339 RetCode_t RA8875::fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1340 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1341 {
WiredHome 19:3f82c1161fd2 1342 return rect(x1,y1,x2,y2,color,fillit);
WiredHome 19:3f82c1161fd2 1343 }
WiredHome 19:3f82c1161fd2 1344
WiredHome 44:207594dece70 1345
WiredHome 73:f22a18707b5e 1346 RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1347 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1348 {
WiredHome 19:3f82c1161fd2 1349 foreground(color);
WiredHome 19:3f82c1161fd2 1350 return rect(x1,y1,x2,y2,fillit);
WiredHome 19:3f82c1161fd2 1351 }
WiredHome 19:3f82c1161fd2 1352
WiredHome 44:207594dece70 1353
WiredHome 73:f22a18707b5e 1354 RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1355 fill_t fillit)
WiredHome 19:3f82c1161fd2 1356 {
WiredHome 19:3f82c1161fd2 1357 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1358 if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 1359 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1360 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 1361 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1362 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 1363 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1364 } else {
WiredHome 38:38d503b4fad6 1365 WriteCommandW(0x91, x1);
WiredHome 38:38d503b4fad6 1366 WriteCommandW(0x93, y1);
WiredHome 38:38d503b4fad6 1367 WriteCommandW(0x95, x2);
WiredHome 38:38d503b4fad6 1368 WriteCommandW(0x97, y2);
WiredHome 19:3f82c1161fd2 1369 unsigned char drawCmd = 0x10; // Rectangle
WiredHome 19:3f82c1161fd2 1370 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1371 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 1372 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 1373 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1374 _WaitWhileReg(0x90, 0x80);
WiredHome 19:3f82c1161fd2 1375 }
WiredHome 19:3f82c1161fd2 1376 REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
WiredHome 19:3f82c1161fd2 1377 return noerror;
WiredHome 19:3f82c1161fd2 1378 }
WiredHome 19:3f82c1161fd2 1379
WiredHome 44:207594dece70 1380
WiredHome 73:f22a18707b5e 1381 RetCode_t RA8875::fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1382 dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1383 {
WiredHome 19:3f82c1161fd2 1384 foreground(color);
WiredHome 19:3f82c1161fd2 1385 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1386 }
WiredHome 19:3f82c1161fd2 1387
WiredHome 44:207594dece70 1388
WiredHome 73:f22a18707b5e 1389 RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1390 dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1391 {
WiredHome 19:3f82c1161fd2 1392 foreground(color);
WiredHome 19:3f82c1161fd2 1393 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1394 }
WiredHome 19:3f82c1161fd2 1395
WiredHome 44:207594dece70 1396
WiredHome 73:f22a18707b5e 1397 RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1398 dim_t radius1, dim_t radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 1399 {
WiredHome 19:3f82c1161fd2 1400 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1401
WiredHome 19:3f82c1161fd2 1402 PERFORMANCE_RESET;
WiredHome 21:3c1efb192927 1403 if (x1 > x2 || y1 > y2 || (radius1 > (x2-x1)/2) || (radius2 > (y2-y1)/2) ) {
WiredHome 21:3c1efb192927 1404 ret = bad_parameter;
WiredHome 21:3c1efb192927 1405 } else if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 1406 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1407 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 1408 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1409 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 1410 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1411 } else {
WiredHome 38:38d503b4fad6 1412 WriteCommandW(0x91, x1);
WiredHome 38:38d503b4fad6 1413 WriteCommandW(0x93, y1);
WiredHome 38:38d503b4fad6 1414 WriteCommandW(0x95, x2);
WiredHome 38:38d503b4fad6 1415 WriteCommandW(0x97, y2);
WiredHome 38:38d503b4fad6 1416 WriteCommandW(0xA1, radius1);
WiredHome 38:38d503b4fad6 1417 WriteCommandW(0xA3, radius2);
WiredHome 21:3c1efb192927 1418 // Should not need this...
WiredHome 38:38d503b4fad6 1419 WriteCommandW(0xA5, 0);
WiredHome 38:38d503b4fad6 1420 WriteCommandW(0xA7, 0);
WiredHome 19:3f82c1161fd2 1421 unsigned char drawCmd = 0x20; // Rounded Rectangle
WiredHome 19:3f82c1161fd2 1422 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1423 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 1424 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 1425 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1426 _WaitWhileReg(0xA0, 0x80);
WiredHome 19:3f82c1161fd2 1427 }
WiredHome 19:3f82c1161fd2 1428 REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
WiredHome 19:3f82c1161fd2 1429 return ret;
WiredHome 19:3f82c1161fd2 1430 }
WiredHome 19:3f82c1161fd2 1431
WiredHome 44:207594dece70 1432
WiredHome 73:f22a18707b5e 1433 RetCode_t RA8875::triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1434 loc_t x3, loc_t y3, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1435 {
WiredHome 20:6e2e4a8372eb 1436 RetCode_t ret;
WiredHome 20:6e2e4a8372eb 1437
WiredHome 19:3f82c1161fd2 1438 foreground(color);
WiredHome 20:6e2e4a8372eb 1439 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 20:6e2e4a8372eb 1440 return ret;
WiredHome 19:3f82c1161fd2 1441 }
WiredHome 19:3f82c1161fd2 1442
WiredHome 44:207594dece70 1443
WiredHome 73:f22a18707b5e 1444 RetCode_t RA8875::filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1445 loc_t x3, loc_t y3, color_t color, fill_t fillit)
WiredHome 73:f22a18707b5e 1446 {
WiredHome 73:f22a18707b5e 1447 RetCode_t ret;
WiredHome 73:f22a18707b5e 1448
WiredHome 73:f22a18707b5e 1449 foreground(color);
WiredHome 73:f22a18707b5e 1450 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 73:f22a18707b5e 1451 return ret;
WiredHome 73:f22a18707b5e 1452 }
WiredHome 73:f22a18707b5e 1453
WiredHome 73:f22a18707b5e 1454
WiredHome 73:f22a18707b5e 1455 RetCode_t RA8875::triangle(loc_t x1, loc_t y1 ,loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1456 loc_t x3, loc_t y3, fill_t fillit)
WiredHome 19:3f82c1161fd2 1457 {
WiredHome 19:3f82c1161fd2 1458 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1459
WiredHome 19:3f82c1161fd2 1460 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1461 if (x1 == x2 && y1 == y2 && x1 == x3 && y1 == y3) {
WiredHome 19:3f82c1161fd2 1462 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1463 } else {
WiredHome 38:38d503b4fad6 1464 WriteCommandW(0x91, x1);
WiredHome 38:38d503b4fad6 1465 WriteCommandW(0x93, y1);
WiredHome 38:38d503b4fad6 1466 WriteCommandW(0x95, x2);
WiredHome 38:38d503b4fad6 1467 WriteCommandW(0x97, y2);
WiredHome 38:38d503b4fad6 1468 WriteCommandW(0xA9, x3);
WiredHome 38:38d503b4fad6 1469 WriteCommandW(0xAB, y3);
WiredHome 19:3f82c1161fd2 1470 unsigned char drawCmd = 0x01; // Triangle
WiredHome 19:3f82c1161fd2 1471 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1472 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 1473 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 1474 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1475 _WaitWhileReg(0x90, 0x80);
WiredHome 19:3f82c1161fd2 1476 }
WiredHome 19:3f82c1161fd2 1477 REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
WiredHome 19:3f82c1161fd2 1478 return ret;
WiredHome 19:3f82c1161fd2 1479 }
WiredHome 19:3f82c1161fd2 1480
WiredHome 73:f22a18707b5e 1481 RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius,
WiredHome 73:f22a18707b5e 1482 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1483 {
WiredHome 19:3f82c1161fd2 1484 foreground(color);
WiredHome 19:3f82c1161fd2 1485 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 1486 }
WiredHome 19:3f82c1161fd2 1487
WiredHome 44:207594dece70 1488
WiredHome 73:f22a18707b5e 1489 RetCode_t RA8875::fillcircle(loc_t x, loc_t y, dim_t radius,
WiredHome 73:f22a18707b5e 1490 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1491 {
WiredHome 19:3f82c1161fd2 1492 foreground(color);
WiredHome 19:3f82c1161fd2 1493 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 1494 }
WiredHome 19:3f82c1161fd2 1495
WiredHome 44:207594dece70 1496
WiredHome 37:f19b7e7449dc 1497 RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius, fill_t fillit)
WiredHome 19:3f82c1161fd2 1498 {
WiredHome 19:3f82c1161fd2 1499 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1500
WiredHome 19:3f82c1161fd2 1501 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1502 if (radius <= 0) {
WiredHome 19:3f82c1161fd2 1503 ret = bad_parameter;
WiredHome 19:3f82c1161fd2 1504 } else if (radius == 1) {
WiredHome 19:3f82c1161fd2 1505 pixel(x,y);
WiredHome 19:3f82c1161fd2 1506 } else {
WiredHome 38:38d503b4fad6 1507 WriteCommandW(0x99, x);
WiredHome 38:38d503b4fad6 1508 WriteCommandW(0x9B, y);
WiredHome 19:3f82c1161fd2 1509 WriteCommand(0x9d, radius & 0xFF);
WiredHome 19:3f82c1161fd2 1510 unsigned char drawCmd = 0x00; // Circle
WiredHome 19:3f82c1161fd2 1511 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1512 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 1513 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 1514 WriteCommand(0x90, 0x40 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1515 _WaitWhileReg(0x90, 0x40);
WiredHome 19:3f82c1161fd2 1516 }
WiredHome 19:3f82c1161fd2 1517 REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
WiredHome 19:3f82c1161fd2 1518 return ret;
WiredHome 19:3f82c1161fd2 1519 }
WiredHome 19:3f82c1161fd2 1520
WiredHome 44:207594dece70 1521
WiredHome 37:f19b7e7449dc 1522 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 1523 {
WiredHome 19:3f82c1161fd2 1524 foreground(color);
WiredHome 25:9556a3a9b7cc 1525 return ellipse(x,y,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1526 }
WiredHome 19:3f82c1161fd2 1527
WiredHome 44:207594dece70 1528
WiredHome 37:f19b7e7449dc 1529 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 1530 {
WiredHome 25:9556a3a9b7cc 1531 foreground(color);
WiredHome 25:9556a3a9b7cc 1532 return ellipse(x,y,radius1,radius2,fillit);
WiredHome 25:9556a3a9b7cc 1533 }
WiredHome 44:207594dece70 1534
WiredHome 73:f22a18707b5e 1535
WiredHome 37:f19b7e7449dc 1536 RetCode_t RA8875::ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 1537 {
WiredHome 19:3f82c1161fd2 1538 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1539
WiredHome 19:3f82c1161fd2 1540 PERFORMANCE_RESET;
WiredHome 25:9556a3a9b7cc 1541 if (radius1 <= 0 || radius2 <= 0) {
WiredHome 19:3f82c1161fd2 1542 ; // do nothing
WiredHome 25:9556a3a9b7cc 1543 } else if (radius1 == 1 && radius2 == 1) {
WiredHome 19:3f82c1161fd2 1544 pixel(x, y);
WiredHome 19:3f82c1161fd2 1545 } else {
WiredHome 38:38d503b4fad6 1546 WriteCommandW(0xA5, x);
WiredHome 38:38d503b4fad6 1547 WriteCommandW(0xA7, y);
WiredHome 38:38d503b4fad6 1548 WriteCommandW(0xA1, radius1);
WiredHome 38:38d503b4fad6 1549 WriteCommandW(0xA3, radius2);
WiredHome 19:3f82c1161fd2 1550 unsigned char drawCmd = 0x00; // Ellipse
WiredHome 19:3f82c1161fd2 1551 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1552 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 1553 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 1554 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1555 _WaitWhileReg(0xA0, 0x80);
WiredHome 19:3f82c1161fd2 1556 }
WiredHome 19:3f82c1161fd2 1557 REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
WiredHome 19:3f82c1161fd2 1558 return ret;
WiredHome 19:3f82c1161fd2 1559 }
WiredHome 19:3f82c1161fd2 1560
WiredHome 44:207594dece70 1561
WiredHome 68:ab08efabfc88 1562 RetCode_t RA8875::frequency(unsigned long Hz, unsigned long Hz2)
WiredHome 19:3f82c1161fd2 1563 {
WiredHome 66:468a11f05580 1564 spiwritefreq = Hz;
WiredHome 68:ab08efabfc88 1565 if (Hz2 != 0)
WiredHome 68:ab08efabfc88 1566 spireadfreq = Hz2;
WiredHome 68:ab08efabfc88 1567 else
WiredHome 68:ab08efabfc88 1568 spireadfreq = Hz/2;
WiredHome 68:ab08efabfc88 1569 _setWriteSpeed(true);
WiredHome 19:3f82c1161fd2 1570 // __ ___
WiredHome 19:3f82c1161fd2 1571 // Clock ___A Rising edge latched
WiredHome 19:3f82c1161fd2 1572 // ___ ____
WiredHome 19:3f82c1161fd2 1573 // Data ___X____
WiredHome 19:3f82c1161fd2 1574 spi.format(8, 3); // 8 bits and clock to data phase 0
WiredHome 19:3f82c1161fd2 1575 return noerror;
WiredHome 19:3f82c1161fd2 1576 }
WiredHome 19:3f82c1161fd2 1577
WiredHome 68:ab08efabfc88 1578 void RA8875::_setWriteSpeed(bool writeSpeed)
WiredHome 68:ab08efabfc88 1579 {
WiredHome 68:ab08efabfc88 1580 if (writeSpeed) {
WiredHome 68:ab08efabfc88 1581 spi.frequency(spiwritefreq);
WiredHome 68:ab08efabfc88 1582 spiWriteSpeed = true;
WiredHome 68:ab08efabfc88 1583 } else {
WiredHome 68:ab08efabfc88 1584 spi.frequency(spireadfreq);
WiredHome 68:ab08efabfc88 1585 spiWriteSpeed = false;
WiredHome 68:ab08efabfc88 1586 }
WiredHome 68:ab08efabfc88 1587 }
WiredHome 44:207594dece70 1588
WiredHome 19:3f82c1161fd2 1589 RetCode_t RA8875::Power(bool on)
WiredHome 19:3f82c1161fd2 1590 {
WiredHome 19:3f82c1161fd2 1591 WriteCommand(0x01, (on) ? 0x80 : 0x00);
WiredHome 19:3f82c1161fd2 1592 return noerror;
WiredHome 19:3f82c1161fd2 1593 }
WiredHome 19:3f82c1161fd2 1594
WiredHome 44:207594dece70 1595
WiredHome 19:3f82c1161fd2 1596 RetCode_t RA8875::Reset(void)
WiredHome 19:3f82c1161fd2 1597 {
WiredHome 19:3f82c1161fd2 1598 WriteCommand(0x01, 0x01); // Apply Display Off, Reset
WiredHome 19:3f82c1161fd2 1599 wait_ms(2); // no idea if I need to wait, or how long
WiredHome 19:3f82c1161fd2 1600 WriteCommand(0x01, 0x00); // Display off, Remove reset
WiredHome 73:f22a18707b5e 1601 wait_ms(2); // no idea if I need to wait, or how long
WiredHome 43:3becae133285 1602 init(RA8875_DISPLAY_WIDTH, RA8875_DISPLAY_HEIGHT, RA8875_COLORDEPTH_BPP);
WiredHome 19:3f82c1161fd2 1603 return noerror;
WiredHome 19:3f82c1161fd2 1604 }
WiredHome 19:3f82c1161fd2 1605
WiredHome 19:3f82c1161fd2 1606
WiredHome 19:3f82c1161fd2 1607 RetCode_t RA8875::Backlight_u8(unsigned char brightness)
WiredHome 19:3f82c1161fd2 1608 {
WiredHome 19:3f82c1161fd2 1609 static bool is_enabled = false;
WiredHome 19:3f82c1161fd2 1610 if (brightness == 0) {
WiredHome 19:3f82c1161fd2 1611 WriteCommand(0x8a); // Disable the PWM
WiredHome 19:3f82c1161fd2 1612 WriteData(0x00);
WiredHome 19:3f82c1161fd2 1613 is_enabled = false;
WiredHome 19:3f82c1161fd2 1614 } else if (!is_enabled) {
WiredHome 19:3f82c1161fd2 1615 WriteCommand(0x8a); // Enable the PWM
WiredHome 19:3f82c1161fd2 1616 WriteData(0x80);
WiredHome 19:3f82c1161fd2 1617 WriteCommand(0x8a); // Not sure why this is needed, but following the pattern
WiredHome 19:3f82c1161fd2 1618 WriteData(0x81); // open PWM (SYS_CLK / 2 as best I can tell)
WiredHome 19:3f82c1161fd2 1619 is_enabled = true;
WiredHome 19:3f82c1161fd2 1620 }
WiredHome 19:3f82c1161fd2 1621 WriteCommand(0x8b, brightness); // Brightness parameter 0xff-0x00
WiredHome 19:3f82c1161fd2 1622 return noerror;
WiredHome 19:3f82c1161fd2 1623 }
WiredHome 19:3f82c1161fd2 1624
WiredHome 44:207594dece70 1625
WiredHome 19:3f82c1161fd2 1626 RetCode_t RA8875::Backlight(float brightness)
WiredHome 19:3f82c1161fd2 1627 {
WiredHome 19:3f82c1161fd2 1628 unsigned char b;
WiredHome 73:f22a18707b5e 1629
WiredHome 29:422616aa04bd 1630 if (brightness >= 1.0)
WiredHome 19:3f82c1161fd2 1631 b = 255;
WiredHome 29:422616aa04bd 1632 else if (brightness <= 0.0)
WiredHome 19:3f82c1161fd2 1633 b = 0;
WiredHome 19:3f82c1161fd2 1634 else
WiredHome 19:3f82c1161fd2 1635 b = (unsigned char)(brightness * 255);
WiredHome 19:3f82c1161fd2 1636 return Backlight_u8(b);
WiredHome 19:3f82c1161fd2 1637 }
WiredHome 19:3f82c1161fd2 1638
WiredHome 44:207594dece70 1639
WiredHome 19:3f82c1161fd2 1640 RetCode_t RA8875::set_font(const unsigned char * _font)
WiredHome 19:3f82c1161fd2 1641 {
WiredHome 37:f19b7e7449dc 1642 if (font && ! _font) {
WiredHome 37:f19b7e7449dc 1643 SetTextCursor(cursor_x, cursor_y); // soft-font cursor -> hw cursor
WiredHome 37:f19b7e7449dc 1644 }
WiredHome 19:3f82c1161fd2 1645 font = _font;
WiredHome 29:422616aa04bd 1646 GraphicsDisplay::set_font(_font);
WiredHome 29:422616aa04bd 1647 return noerror; // trusting them, but it might be good to put some checks in here...
WiredHome 19:3f82c1161fd2 1648 }
WiredHome 19:3f82c1161fd2 1649
WiredHome 44:207594dece70 1650
WiredHome 19:3f82c1161fd2 1651 RetCode_t RA8875::background(color_t color)
WiredHome 19:3f82c1161fd2 1652 {
WiredHome 37:f19b7e7449dc 1653 GraphicsDisplay::background(color);
WiredHome 19:3f82c1161fd2 1654 WriteCommand(0x60, (color>>11)); // BGCR0
WiredHome 19:3f82c1161fd2 1655 WriteCommand(0x61, (unsigned char)(color>>5)); // BGCR0
WiredHome 19:3f82c1161fd2 1656 WriteCommand(0x62, (unsigned char)(color)); // BGCR0
WiredHome 19:3f82c1161fd2 1657 return noerror;
WiredHome 19:3f82c1161fd2 1658 }
WiredHome 19:3f82c1161fd2 1659
WiredHome 44:207594dece70 1660
WiredHome 19:3f82c1161fd2 1661 RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 1662 {
WiredHome 37:f19b7e7449dc 1663 background(RGB(r,g,b));
WiredHome 37:f19b7e7449dc 1664 // WriteCommand(0x60, r);
WiredHome 37:f19b7e7449dc 1665 // WriteCommand(0x61, g);
WiredHome 37:f19b7e7449dc 1666 // WriteCommand(0x62, b);
WiredHome 19:3f82c1161fd2 1667 return noerror;
WiredHome 19:3f82c1161fd2 1668 }
WiredHome 19:3f82c1161fd2 1669
WiredHome 44:207594dece70 1670
WiredHome 19:3f82c1161fd2 1671 RetCode_t RA8875::foreground(color_t color)
WiredHome 19:3f82c1161fd2 1672 {
WiredHome 37:f19b7e7449dc 1673 GraphicsDisplay::foreground(color);
WiredHome 19:3f82c1161fd2 1674 WriteCommand(0x63, (unsigned char)(color>>11));
WiredHome 19:3f82c1161fd2 1675 WriteCommand(0x64, (unsigned char)(color>>5));
WiredHome 19:3f82c1161fd2 1676 WriteCommand(0x65, (unsigned char)(color));
WiredHome 19:3f82c1161fd2 1677 return noerror;
WiredHome 19:3f82c1161fd2 1678 }
WiredHome 19:3f82c1161fd2 1679
WiredHome 44:207594dece70 1680
WiredHome 37:f19b7e7449dc 1681 RetCode_t RA8875::foreground(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 1682 {
WiredHome 37:f19b7e7449dc 1683 foreground(RGB(r,g,b));
WiredHome 37:f19b7e7449dc 1684 // WriteCommand(0x63, r);
WiredHome 37:f19b7e7449dc 1685 // WriteCommand(0x64, g);
WiredHome 37:f19b7e7449dc 1686 // WriteCommand(0x65, b);
WiredHome 19:3f82c1161fd2 1687 return noerror;
WiredHome 19:3f82c1161fd2 1688 }
WiredHome 19:3f82c1161fd2 1689
WiredHome 44:207594dece70 1690
WiredHome 37:f19b7e7449dc 1691 color_t RA8875::GetForeColor(void)
WiredHome 19:3f82c1161fd2 1692 {
WiredHome 19:3f82c1161fd2 1693 color_t color;
WiredHome 73:f22a18707b5e 1694
WiredHome 19:3f82c1161fd2 1695 color = (ReadCommand(0x63) & 0x1F) << 11;
WiredHome 19:3f82c1161fd2 1696 color |= (ReadCommand(0x64) & 0x3F) << 5;
WiredHome 19:3f82c1161fd2 1697 color |= (ReadCommand(0x65) & 0x1F);
WiredHome 19:3f82c1161fd2 1698 return color;
WiredHome 19:3f82c1161fd2 1699 }
WiredHome 19:3f82c1161fd2 1700
WiredHome 44:207594dece70 1701
WiredHome 19:3f82c1161fd2 1702 color_t RA8875::DOSColor(int i)
WiredHome 73:f22a18707b5e 1703 {
WiredHome 73:f22a18707b5e 1704 const color_t colors[16] = {
WiredHome 19:3f82c1161fd2 1705 Black, Blue, Green, Cyan,
WiredHome 19:3f82c1161fd2 1706 Red, Magenta, Brown, Gray,
WiredHome 19:3f82c1161fd2 1707 Charcoal, BrightBlue, BrightGreen, BrightCyan,
WiredHome 19:3f82c1161fd2 1708 Orange, Pink, Yellow, White
WiredHome 73:f22a18707b5e 1709 };
WiredHome 19:3f82c1161fd2 1710 if (i < 16)
WiredHome 19:3f82c1161fd2 1711 return colors[i];
WiredHome 19:3f82c1161fd2 1712 else
WiredHome 19:3f82c1161fd2 1713 return 0;
WiredHome 73:f22a18707b5e 1714 }
WiredHome 19:3f82c1161fd2 1715
WiredHome 44:207594dece70 1716
WiredHome 73:f22a18707b5e 1717 const char * RA8875::DOSColorNames(int i)
WiredHome 73:f22a18707b5e 1718 {
WiredHome 73:f22a18707b5e 1719 const char * names[16] = {
WiredHome 19:3f82c1161fd2 1720 "Black", "Blue", "Green", "Cyan",
WiredHome 19:3f82c1161fd2 1721 "Red", "Magenta", "Brown", "Gray",
WiredHome 19:3f82c1161fd2 1722 "Charcoal", "BrightBlue", "BrightGreen", "BrightCyan",
WiredHome 19:3f82c1161fd2 1723 "Orange", "Pink", "Yellow", "White"
WiredHome 73:f22a18707b5e 1724 };
WiredHome 19:3f82c1161fd2 1725 if (i < 16)
WiredHome 19:3f82c1161fd2 1726 return names[i];
WiredHome 19:3f82c1161fd2 1727 else
WiredHome 19:3f82c1161fd2 1728 return NULL;
WiredHome 73:f22a18707b5e 1729 }
WiredHome 19:3f82c1161fd2 1730
WiredHome 19:3f82c1161fd2 1731
WiredHome 19:3f82c1161fd2 1732 ///////////////////////////////////////////////////////////////
WiredHome 19:3f82c1161fd2 1733 // Private functions
WiredHome 19:3f82c1161fd2 1734
WiredHome 19:3f82c1161fd2 1735 unsigned char RA8875::spiwrite(unsigned char data)
WiredHome 19:3f82c1161fd2 1736 {
WiredHome 19:3f82c1161fd2 1737 unsigned char retval;
WiredHome 73:f22a18707b5e 1738
WiredHome 68:ab08efabfc88 1739 if (!spiWriteSpeed)
WiredHome 68:ab08efabfc88 1740 _setWriteSpeed(true);
WiredHome 19:3f82c1161fd2 1741 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 1742 return retval;
WiredHome 19:3f82c1161fd2 1743 }
WiredHome 19:3f82c1161fd2 1744
WiredHome 44:207594dece70 1745
WiredHome 19:3f82c1161fd2 1746 unsigned char RA8875::spiread(void)
WiredHome 19:3f82c1161fd2 1747 {
WiredHome 19:3f82c1161fd2 1748 unsigned char retval;
WiredHome 19:3f82c1161fd2 1749 unsigned char data = 0;
WiredHome 73:f22a18707b5e 1750
WiredHome 68:ab08efabfc88 1751 if (spiWriteSpeed)
WiredHome 68:ab08efabfc88 1752 _setWriteSpeed(false);
WiredHome 19:3f82c1161fd2 1753 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 1754 return retval;
WiredHome 19:3f82c1161fd2 1755 }
WiredHome 19:3f82c1161fd2 1756
WiredHome 44:207594dece70 1757
WiredHome 19:3f82c1161fd2 1758 RetCode_t RA8875::select(bool chipsel)
WiredHome 19:3f82c1161fd2 1759 {
WiredHome 19:3f82c1161fd2 1760 cs = (chipsel == true) ? 0 : 1;
WiredHome 19:3f82c1161fd2 1761 return noerror;
WiredHome 19:3f82c1161fd2 1762 }
WiredHome 19:3f82c1161fd2 1763
WiredHome 44:207594dece70 1764
WiredHome 43:3becae133285 1765 RetCode_t RA8875::init(int width, int height, int color_bpp)
WiredHome 19:3f82c1161fd2 1766 {
WiredHome 19:3f82c1161fd2 1767 Backlight_u8(0);
WiredHome 66:468a11f05580 1768 WriteCommand(0x88, 0x0B); // PLLC1 - Phase Lock Loop registers
WiredHome 19:3f82c1161fd2 1769 wait_ms(1);
WiredHome 19:3f82c1161fd2 1770 WriteCommand(0x89, 0x02);
WiredHome 19:3f82c1161fd2 1771 wait_ms(1);
WiredHome 73:f22a18707b5e 1772
WiredHome 23:a50ded45dbaf 1773 // System Config Register (SYSR)
WiredHome 43:3becae133285 1774 if (color_bpp == 16) {
WiredHome 43:3becae133285 1775 WriteCommand(0x10, 0x0C); // 16-bpp (65K colors) color depth, 8-bit interface
WiredHome 43:3becae133285 1776 } else { // color_bpp == 8
WiredHome 43:3becae133285 1777 WriteCommand(0x10, 0x00); // 8-bpp (256 colors)
WiredHome 43:3becae133285 1778 }
WiredHome 23:a50ded45dbaf 1779 // Pixel Clock Setting Register (PCSR)
WiredHome 37:f19b7e7449dc 1780 WriteCommand(0x04, 0x82); // PDAT on PCLK falling edge, PCLK = 4 x System Clock
WiredHome 19:3f82c1161fd2 1781 wait_ms(1);
WiredHome 19:3f82c1161fd2 1782
WiredHome 19:3f82c1161fd2 1783 // Horizontal Settings
WiredHome 43:3becae133285 1784 WriteCommand(0x14, width/8 - 1); //HDWR//Horizontal Display Width Setting Bit[6:0]
WiredHome 43:3becae133285 1785 WriteCommand(0x15, 0x02); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
WiredHome 43:3becae133285 1786 WriteCommand(0x16, 0x03); //HNDR//Horizontal Non-Display Period Bit[4:0]
WiredHome 43:3becae133285 1787 WriteCommand(0x17, 0x01); //HSTR//HSYNC Start Position[4:0]
WiredHome 43:3becae133285 1788 WriteCommand(0x18, 0x03); //HPWR//HSYNC Polarity ,The period width of HSYNC.
WiredHome 19:3f82c1161fd2 1789
WiredHome 19:3f82c1161fd2 1790 // Vertical Settings
WiredHome 43:3becae133285 1791 WriteCommand(0x19, (height-1)&0xFF); //VDHR0 //Vertical Display Height Bit [7:0]
WiredHome 43:3becae133285 1792 WriteCommand(0x1a, (height-1)>>8); //VDHR1 //Vertical Display Height Bit [8]
WiredHome 43:3becae133285 1793 WriteCommand(0x1b, 0x0F); //VNDR0 //Vertical Non-Display Period Bit [7:0]
WiredHome 43:3becae133285 1794 WriteCommand(0x1c, 0x00); //VNDR1 //Vertical Non-Display Period Bit [8]
WiredHome 43:3becae133285 1795 WriteCommand(0x1d, 0x0e); //VSTR0 //VSYNC Start Position[7:0]
WiredHome 43:3becae133285 1796 WriteCommand(0x1e, 0x06); //VSTR1 //VSYNC Start Position[8]
WiredHome 43:3becae133285 1797 WriteCommand(0x1f, 0x01); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
WiredHome 19:3f82c1161fd2 1798
WiredHome 43:3becae133285 1799 if (width >= 800 && height >= 480 && color_bpp > 8) {
WiredHome 43:3becae133285 1800 WriteCommand(0x20, 0x00); // DPCR - 1-layer mode when the resolution is too high
WiredHome 43:3becae133285 1801 } else {
WiredHome 43:3becae133285 1802 WriteCommand(0x20, 0x80); // DPCR - 2-layer mode
WiredHome 43:3becae133285 1803 }
WiredHome 73:f22a18707b5e 1804
WiredHome 50:2c4f474a2453 1805 // Set display image to Blue on Black as default
WiredHome 43:3becae133285 1806 window(0,0, width, height); // Initialize to full screen
WiredHome 24:8ca861acf12d 1807 SetTextCursorControl();
WiredHome 28:ed102fc442c4 1808 foreground(Blue);
WiredHome 19:3f82c1161fd2 1809 background(Black);
WiredHome 50:2c4f474a2453 1810 SelectDrawingLayer(1);
WiredHome 50:2c4f474a2453 1811 cls();
WiredHome 50:2c4f474a2453 1812 SelectDrawingLayer(0);
WiredHome 19:3f82c1161fd2 1813 cls();
WiredHome 19:3f82c1161fd2 1814 return noerror;
WiredHome 19:3f82c1161fd2 1815 }
WiredHome 19:3f82c1161fd2 1816
WiredHome 72:ecffe56af969 1817 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 1818 {
WiredHome 77:9206c13aa527 1819 #if 1
WiredHome 74:686faa218914 1820 (void)layer;
WiredHome 74:686faa218914 1821 return PrintScreen(x, y, w, h, Name_BMP);
WiredHome 77:9206c13aa527 1822 #else
WiredHome 74:686faa218914 1823 // This is the deprecated interface and with the changes it is no longer implemented correctly.
WiredHome 72:ecffe56af969 1824 uint16_t curLayer = GetDrawingLayer();
WiredHome 72:ecffe56af969 1825 RetCode_t ret = SelectDrawingLayer(layer);
WiredHome 72:ecffe56af969 1826 if (ret == noerror) {
WiredHome 72:ecffe56af969 1827 ret = PrintScreen(x, y, w, h, Name_BMP);
WiredHome 72:ecffe56af969 1828 }
WiredHome 72:ecffe56af969 1829 SelectDrawingLayer(curLayer);
WiredHome 72:ecffe56af969 1830 return ret;
WiredHome 77:9206c13aa527 1831 #endif
WiredHome 72:ecffe56af969 1832 }
WiredHome 72:ecffe56af969 1833
WiredHome 72:ecffe56af969 1834 RetCode_t RA8875::PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP)
WiredHome 72:ecffe56af969 1835 {
WiredHome 72:ecffe56af969 1836 BITMAPFILEHEADER BMP_Header;
WiredHome 72:ecffe56af969 1837 BITMAPINFOHEADER BMP_Info;
WiredHome 73:f22a18707b5e 1838
WiredHome 72:ecffe56af969 1839 INFO("(%d,%d) - (%d,%d) %s", x,y,w,h,Name_BMP);
WiredHome 72:ecffe56af969 1840 if (x >= 0 && x < width()
WiredHome 73:f22a18707b5e 1841 && y >= 0 && y < height()
WiredHome 73:f22a18707b5e 1842 && w > 0 && x + w <= width()
WiredHome 73:f22a18707b5e 1843 && h > 0 && y + h <= height()) {
WiredHome 72:ecffe56af969 1844
WiredHome 72:ecffe56af969 1845 BMP_Header.bfType = BF_TYPE;
WiredHome 72:ecffe56af969 1846 BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Header);
WiredHome 72:ecffe56af969 1847 BMP_Header.bfReserved1 = 0;
WiredHome 72:ecffe56af969 1848 BMP_Header.bfReserved2 = 0;
WiredHome 72:ecffe56af969 1849 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Header);
WiredHome 73:f22a18707b5e 1850
WiredHome 72:ecffe56af969 1851 BMP_Info.biSize = sizeof(BMP_Info);
WiredHome 72:ecffe56af969 1852 BMP_Info.biWidth = w;
WiredHome 72:ecffe56af969 1853 BMP_Info.biHeight = h;
WiredHome 72:ecffe56af969 1854 BMP_Info.biPlanes = 1;
WiredHome 72:ecffe56af969 1855 BMP_Info.biBitCount = 24;
WiredHome 72:ecffe56af969 1856 BMP_Info.biCompression = BI_RGB;
WiredHome 72:ecffe56af969 1857 BMP_Info.biSizeImage = 0;
WiredHome 72:ecffe56af969 1858 BMP_Info.biXPelsPerMeter = 0;
WiredHome 72:ecffe56af969 1859 BMP_Info.biYPelsPerMeter = 0;
WiredHome 72:ecffe56af969 1860 BMP_Info.biClrUsed = 0;
WiredHome 72:ecffe56af969 1861 BMP_Info.biClrImportant = 0;
WiredHome 72:ecffe56af969 1862
WiredHome 72:ecffe56af969 1863 INFO("Writing {%s}", Name_BMP);
WiredHome 72:ecffe56af969 1864 FILE *Image = fopen(Name_BMP, "wb");
WiredHome 72:ecffe56af969 1865 if (!Image) {
WiredHome 72:ecffe56af969 1866 ERR("File not found");
WiredHome 72:ecffe56af969 1867 return(file_not_found);
WiredHome 72:ecffe56af969 1868 }
WiredHome 72:ecffe56af969 1869
WiredHome 72:ecffe56af969 1870 // Be optimistic - don't check for errors.
WiredHome 72:ecffe56af969 1871 //HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 72:ecffe56af969 1872 fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image);
WiredHome 72:ecffe56af969 1873 //INFO("fwrite returned %d", r);
WiredHome 73:f22a18707b5e 1874
WiredHome 72:ecffe56af969 1875 //HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 72:ecffe56af969 1876 fwrite(&BMP_Info, sizeof(char), sizeof(BMP_Info), Image);
WiredHome 72:ecffe56af969 1877 //INFO("fwrite returned %d", r);
WiredHome 73:f22a18707b5e 1878
WiredHome 72:ecffe56af969 1879 int lineBufSize = ((24 * w + 7)/8);
WiredHome 72:ecffe56af969 1880 uint8_t * lineBuffer = (uint8_t *)malloc(lineBufSize);
WiredHome 72:ecffe56af969 1881 if (lineBuffer == NULL) {
WiredHome 72:ecffe56af969 1882 fclose(Image);
WiredHome 72:ecffe56af969 1883 ERR("Not enough RAM for lineBuffer");
WiredHome 72:ecffe56af969 1884 return(not_enough_ram);
WiredHome 72:ecffe56af969 1885 }
WiredHome 72:ecffe56af969 1886 color_t * pixelBuffer = (color_t *)malloc(w * sizeof(color_t));
WiredHome 73:f22a18707b5e 1887 color_t * pixelBuffer2 = (color_t *)malloc(w * sizeof(color_t));
WiredHome 73:f22a18707b5e 1888 color_t transparency = GetBackgroundTransparencyColor();
WiredHome 73:f22a18707b5e 1889 unsigned char ltpr0 = ReadCommand(0x52) & 0x7;
WiredHome 73:f22a18707b5e 1890
WiredHome 73:f22a18707b5e 1891 if (pixelBuffer == NULL || pixelBuffer2 == NULL) {
WiredHome 72:ecffe56af969 1892 fclose(Image);
WiredHome 72:ecffe56af969 1893 free(lineBuffer);
WiredHome 72:ecffe56af969 1894 ERR("Not enough RAM for pixelBuffer");
WiredHome 73:f22a18707b5e 1895 if (pixelBuffer)
WiredHome 73:f22a18707b5e 1896 free(pixelBuffer);
WiredHome 72:ecffe56af969 1897 return(not_enough_ram);
WiredHome 72:ecffe56af969 1898 }
WiredHome 73:f22a18707b5e 1899
WiredHome 73:f22a18707b5e 1900 uint16_t prevLayer = GetDrawingLayer();
WiredHome 73:f22a18707b5e 1901 // If only one of the layers is visible, select that layer
WiredHome 73:f22a18707b5e 1902 switch(ltpr0) {
WiredHome 73:f22a18707b5e 1903 case 0:
WiredHome 73:f22a18707b5e 1904 SelectDrawingLayer(0);
WiredHome 73:f22a18707b5e 1905 break;
WiredHome 73:f22a18707b5e 1906 case 1:
WiredHome 73:f22a18707b5e 1907 SelectDrawingLayer(1);
WiredHome 73:f22a18707b5e 1908 break;
WiredHome 73:f22a18707b5e 1909 default:
WiredHome 73:f22a18707b5e 1910 break;
WiredHome 73:f22a18707b5e 1911 }
WiredHome 73:f22a18707b5e 1912
WiredHome 72:ecffe56af969 1913 // Read the display from the last line toward the top
WiredHome 72:ecffe56af969 1914 // so we can write the file in one pass.
WiredHome 72:ecffe56af969 1915 for (int j = h - 1; j >= 0; j--) {
WiredHome 73:f22a18707b5e 1916 if (ltpr0 >= 2) // Need to combine the layers...
WiredHome 73:f22a18707b5e 1917 SelectDrawingLayer(0); // so read layer 0 first
WiredHome 72:ecffe56af969 1918 // Read one line of pixels to a local buffer
WiredHome 72:ecffe56af969 1919 if (getPixelStream(pixelBuffer, w, x,y+j) != noerror) {
WiredHome 72:ecffe56af969 1920 ERR("getPixelStream error, and no recovery handler...");
WiredHome 72:ecffe56af969 1921 }
WiredHome 73:f22a18707b5e 1922 if (ltpr0 >= 2) { // Need to combine the layers...
WiredHome 73:f22a18707b5e 1923 SelectDrawingLayer(1); // so read layer 0 first
WiredHome 73:f22a18707b5e 1924 if (getPixelStream(pixelBuffer2, w, x,y+j) != noerror) {
WiredHome 73:f22a18707b5e 1925 ERR("getPixelStream error, and no recovery handler...");
WiredHome 73:f22a18707b5e 1926 }
WiredHome 73:f22a18707b5e 1927 }
WiredHome 72:ecffe56af969 1928 // Convert the local buffer to RGBQUAD format
WiredHome 72:ecffe56af969 1929 int lb = 0;
WiredHome 72:ecffe56af969 1930 for (int i=0; i<w; i++) {
WiredHome 73:f22a18707b5e 1931 RGBQUAD q0 = RGB16ToRGBQuad(pixelBuffer[x+i]); // Scale to 24-bits
WiredHome 73:f22a18707b5e 1932 RGBQUAD q1 = RGB16ToRGBQuad(pixelBuffer2[x+i]); // Scale to 24-bits
WiredHome 73:f22a18707b5e 1933 switch (ltpr0) {
WiredHome 73:f22a18707b5e 1934 case 0:
WiredHome 73:f22a18707b5e 1935 case 1:
WiredHome 73:f22a18707b5e 1936 case 2: // lighten-overlay (@TODO Not supported yet)
WiredHome 73:f22a18707b5e 1937 case 6: // Floating Windows (@TODO not sure how to support)
WiredHome 73:f22a18707b5e 1938 default: // Reserved...
WiredHome 73:f22a18707b5e 1939 lineBuffer[lb++] = q0.rgbBlue;
WiredHome 73:f22a18707b5e 1940 lineBuffer[lb++] = q0.rgbGreen;
WiredHome 73:f22a18707b5e 1941 lineBuffer[lb++] = q0.rgbRed;
WiredHome 73:f22a18707b5e 1942 break;
WiredHome 73:f22a18707b5e 1943 case 3: // transparent mode (@TODO Read the background color register for transparent)
WiredHome 73:f22a18707b5e 1944 case 4: // boolean or
WiredHome 73:f22a18707b5e 1945 lineBuffer[lb++] = q0.rgbBlue | q1.rgbBlue;
WiredHome 73:f22a18707b5e 1946 lineBuffer[lb++] = q0.rgbGreen | q1.rgbGreen;
WiredHome 73:f22a18707b5e 1947 lineBuffer[lb++] = q0.rgbRed | q1.rgbRed;
WiredHome 73:f22a18707b5e 1948 break;
WiredHome 73:f22a18707b5e 1949 case 5: // boolean AND
WiredHome 73:f22a18707b5e 1950 lineBuffer[lb++] = q0.rgbBlue & q1.rgbBlue;
WiredHome 73:f22a18707b5e 1951 lineBuffer[lb++] = q0.rgbGreen & q1.rgbGreen;
WiredHome 73:f22a18707b5e 1952 lineBuffer[lb++] = q0.rgbRed & q1.rgbRed;
WiredHome 73:f22a18707b5e 1953 break;
WiredHome 73:f22a18707b5e 1954 }
WiredHome 72:ecffe56af969 1955 }
WiredHome 73:f22a18707b5e 1956 if (j == h - 1)
WiredHome 73:f22a18707b5e 1957 HexDump("Line", lineBuffer, lineBufSize);
WiredHome 72:ecffe56af969 1958 // Write to disk
WiredHome 72:ecffe56af969 1959 fwrite(lineBuffer, sizeof(char), lb, Image);
WiredHome 72:ecffe56af969 1960 }
WiredHome 73:f22a18707b5e 1961 SelectDrawingLayer(prevLayer);
WiredHome 72:ecffe56af969 1962 fclose(Image);
WiredHome 73:f22a18707b5e 1963 free(pixelBuffer2); // don't leak memory.
WiredHome 73:f22a18707b5e 1964 free(pixelBuffer);
WiredHome 72:ecffe56af969 1965 free(lineBuffer);
WiredHome 73:f22a18707b5e 1966 INFO("Image closed");
WiredHome 72:ecffe56af969 1967 return noerror;
WiredHome 72:ecffe56af969 1968 } else {
WiredHome 72:ecffe56af969 1969 return bad_parameter;
WiredHome 72:ecffe56af969 1970 }
WiredHome 72:ecffe56af969 1971 }
WiredHome 72:ecffe56af969 1972
WiredHome 72:ecffe56af969 1973
WiredHome 72:ecffe56af969 1974 // ##########################################################################
WiredHome 72:ecffe56af969 1975 // ##########################################################################
WiredHome 72:ecffe56af969 1976 // ##########################################################################
WiredHome 72:ecffe56af969 1977
WiredHome 23:a50ded45dbaf 1978 #ifdef TESTENABLE
WiredHome 23:a50ded45dbaf 1979
WiredHome 37:f19b7e7449dc 1980 #include "Arial12x12.h"
WiredHome 37:f19b7e7449dc 1981 #include "Small_6.h"
WiredHome 37:f19b7e7449dc 1982
WiredHome 23:a50ded45dbaf 1983 // ______________ ______________ ______________ _______________
WiredHome 23:a50ded45dbaf 1984 // /_____ _____/ / ___________/ / ___________/ /_____ ______/
WiredHome 23:a50ded45dbaf 1985 // / / / / / / / /
WiredHome 23:a50ded45dbaf 1986 // / / / /___ / /__________ / /
WiredHome 23:a50ded45dbaf 1987 // / / / ____/ /__________ / / /
WiredHome 23:a50ded45dbaf 1988 // / / / / / / / /
WiredHome 23:a50ded45dbaf 1989 // / / / /__________ ___________/ / / /
WiredHome 23:a50ded45dbaf 1990 // /__/ /_____________/ /_____________/ /__/
WiredHome 23:a50ded45dbaf 1991 //
WiredHome 23:a50ded45dbaf 1992 // Everything from here down is test code.
WiredHome 75:ca78388cfd77 1993 //
WiredHome 41:2956a0a221e5 1994 bool SuppressSlowStuff = false;
WiredHome 23:a50ded45dbaf 1995
WiredHome 49:c5182231d1b9 1996 void TextWrapTest(RA8875 & display, Serial & pc)
WiredHome 49:c5182231d1b9 1997 {
WiredHome 49:c5182231d1b9 1998 if (!SuppressSlowStuff)
WiredHome 49:c5182231d1b9 1999 pc.printf("Text Wrap Test\r\n");
WiredHome 49:c5182231d1b9 2000 display.background(Black);
WiredHome 49:c5182231d1b9 2001 display.foreground(Blue);
WiredHome 49:c5182231d1b9 2002 display.cls();
WiredHome 49:c5182231d1b9 2003 display.Backlight_u8(255);
WiredHome 49:c5182231d1b9 2004 display.puts(0,0, "Text Wrap Test.\r\n");
WiredHome 52:e6039a823420 2005 for (int i=1; i<60; i++) {
WiredHome 52:e6039a823420 2006 display.printf("L%2d\n", i % 17);
WiredHome 49:c5182231d1b9 2007 if (!SuppressSlowStuff)
WiredHome 52:e6039a823420 2008 wait_ms(100);
WiredHome 49:c5182231d1b9 2009 }
WiredHome 49:c5182231d1b9 2010 if (!SuppressSlowStuff)
WiredHome 49:c5182231d1b9 2011 wait_ms(3000);
WiredHome 49:c5182231d1b9 2012 }
WiredHome 49:c5182231d1b9 2013
WiredHome 75:ca78388cfd77 2014
WiredHome 75:ca78388cfd77 2015 void ShowKey(RA8875 & display, int key)
WiredHome 75:ca78388cfd77 2016 {
WiredHome 75:ca78388cfd77 2017 loc_t col, row;
WiredHome 75:ca78388cfd77 2018 dim_t r1 = 25;
WiredHome 75:ca78388cfd77 2019 color_t color = (key & 0x80) ? Red : Green;
WiredHome 75:ca78388cfd77 2020
WiredHome 75:ca78388cfd77 2021 key &= 0x7F; // remove the long-press flag
WiredHome 75:ca78388cfd77 2022 row = (key - 1) / 5;
WiredHome 75:ca78388cfd77 2023 col = (key - 1) % 5;
WiredHome 75:ca78388cfd77 2024 if (col > 5) col = 5;
WiredHome 75:ca78388cfd77 2025 if (row > 4) row = 4;
WiredHome 75:ca78388cfd77 2026 display.circle(450 - + (2 * r1) * col, 200 - (2 * r1) * row, r1-2, color, FILL);
WiredHome 75:ca78388cfd77 2027 }
WiredHome 75:ca78388cfd77 2028
WiredHome 75:ca78388cfd77 2029 void HideKey(RA8875 & display, int key)
WiredHome 75:ca78388cfd77 2030 {
WiredHome 75:ca78388cfd77 2031 loc_t col, row;
WiredHome 75:ca78388cfd77 2032 dim_t r1 = 25;
WiredHome 75:ca78388cfd77 2033
WiredHome 75:ca78388cfd77 2034 row = (key - 1) / 5;
WiredHome 75:ca78388cfd77 2035 col = (key - 1) % 5;
WiredHome 75:ca78388cfd77 2036 if (col > 5) col = 5;
WiredHome 75:ca78388cfd77 2037 if (row > 4) row = 4;
WiredHome 75:ca78388cfd77 2038 display.background(Black);
WiredHome 75:ca78388cfd77 2039 display.circle(450 - (2 * r1) * col, 200 - (2 * r1) * row, r1-2, Black, FILL);
WiredHome 75:ca78388cfd77 2040 display.circle(450 - (2 * r1) * col, 200 - (2 * r1) * row, r1-2, Blue);
WiredHome 75:ca78388cfd77 2041 }
WiredHome 75:ca78388cfd77 2042
WiredHome 75:ca78388cfd77 2043 void KeyPadTest(RA8875 & display, Serial & pc)
WiredHome 75:ca78388cfd77 2044 {
WiredHome 75:ca78388cfd77 2045 const uint8_t myMap[22] = {
WiredHome 77:9206c13aa527 2046 0,
WiredHome 75:ca78388cfd77 2047 'a', 'b', 'c', 'd', 'e',
WiredHome 75:ca78388cfd77 2048 'f', 'g', 'h', 'i', 'j',
WiredHome 75:ca78388cfd77 2049 'k', 'l', 'm', 'n', 'o',
WiredHome 75:ca78388cfd77 2050 'p', 'q', 'r', 's', 't',
WiredHome 75:ca78388cfd77 2051 'x'
WiredHome 75:ca78388cfd77 2052 };
WiredHome 77:9206c13aa527 2053
WiredHome 75:ca78388cfd77 2054 display.background(Black);
WiredHome 75:ca78388cfd77 2055 display.foreground(Blue);
WiredHome 75:ca78388cfd77 2056 display.cls();
WiredHome 75:ca78388cfd77 2057 display.Backlight_u8(255);
WiredHome 75:ca78388cfd77 2058 display.puts(0,0, "KeyPad Test. Touch the keypad...");
WiredHome 75:ca78388cfd77 2059 pc.printf("\r\n"
WiredHome 75:ca78388cfd77 2060 "Raw KeyPad Test. Keypad returns the key-number.\r\n"
WiredHome 75:ca78388cfd77 2061 "Press [most] any PC keyboard key to advance to next test.\r\n");
WiredHome 75:ca78388cfd77 2062 RetCode_t ret = display.KeypadInit(true, true, 3, 7, 3);
WiredHome 75:ca78388cfd77 2063 if (ret != noerror)
WiredHome 75:ca78388cfd77 2064 pc.printf("returncode from KeypadInit is %d\r\n", ret);
WiredHome 75:ca78388cfd77 2065 int lastKey = 0;
WiredHome 75:ca78388cfd77 2066 while (!pc.readable()) {
WiredHome 75:ca78388cfd77 2067 if (display.readable()) {
WiredHome 75:ca78388cfd77 2068 int key = display.getc();
WiredHome 75:ca78388cfd77 2069 if (key) {
WiredHome 75:ca78388cfd77 2070 if (((key & 0x7F) != lastKey) && (lastKey != 0))
WiredHome 75:ca78388cfd77 2071 HideKey(display, lastKey);
WiredHome 75:ca78388cfd77 2072 ShowKey(display, key);
WiredHome 75:ca78388cfd77 2073 lastKey = key & 0x7F;
WiredHome 75:ca78388cfd77 2074 } else {
WiredHome 75:ca78388cfd77 2075 // erase the last one
WiredHome 75:ca78388cfd77 2076 if (lastKey)
WiredHome 75:ca78388cfd77 2077 HideKey(display, lastKey);
WiredHome 75:ca78388cfd77 2078 }
WiredHome 75:ca78388cfd77 2079 }
WiredHome 75:ca78388cfd77 2080 }
WiredHome 75:ca78388cfd77 2081 (void)pc.getc();
WiredHome 75:ca78388cfd77 2082 pc.printf("\r\n"
WiredHome 75:ca78388cfd77 2083 "Map KeyPad Test. Keypad returns the remapped key 'a' - 't'.\r\n"
WiredHome 75:ca78388cfd77 2084 "Press [most] any PC keyboard key to advance to exit test.\r\n");
WiredHome 75:ca78388cfd77 2085 display.SetKeyMap(myMap);
WiredHome 75:ca78388cfd77 2086 while (!pc.readable()) {
WiredHome 75:ca78388cfd77 2087 if (display.readable()) {
WiredHome 75:ca78388cfd77 2088 int key = display.getc();
WiredHome 75:ca78388cfd77 2089 bool longPress = key & 0x80;
WiredHome 75:ca78388cfd77 2090 display.SetTextCursor(0, 120);
WiredHome 75:ca78388cfd77 2091 display.printf("Long Press: %d\r\n", longPress);
WiredHome 75:ca78388cfd77 2092 display.printf(" Remapped: %c %02X\r\n", (key) ? key & 0x7F : ' ', key);
WiredHome 75:ca78388cfd77 2093 }
WiredHome 75:ca78388cfd77 2094 }
WiredHome 75:ca78388cfd77 2095 (void)pc.getc();
WiredHome 75:ca78388cfd77 2096 display.SetKeyMap();
WiredHome 75:ca78388cfd77 2097 pc.printf("\r\n");
WiredHome 75:ca78388cfd77 2098 }
WiredHome 75:ca78388cfd77 2099
WiredHome 23:a50ded45dbaf 2100 void TextCursorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2101 {
WiredHome 75:ca78388cfd77 2102 const char * iCursor = "The I-Beam cursor should be visible for this text.\r\n";
WiredHome 75:ca78388cfd77 2103 const char * uCursor = "The Underscore cursor should be visible for this text.\r\n";
WiredHome 75:ca78388cfd77 2104 const char * bCursor = "The Block cursor should be visible for this text.\r\n";
WiredHome 37:f19b7e7449dc 2105 const char * bbCursor = "The Blinking Block cursor should be visible for this text.\r\n";
WiredHome 23:a50ded45dbaf 2106 const char * p;
WiredHome 41:2956a0a221e5 2107 int delay = 100;
WiredHome 73:f22a18707b5e 2108
WiredHome 41:2956a0a221e5 2109 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2110 pc.printf("Text Cursor Test\r\n");
WiredHome 73:f22a18707b5e 2111 else
WiredHome 41:2956a0a221e5 2112 delay = 0;
WiredHome 23:a50ded45dbaf 2113 display.background(Black);
WiredHome 23:a50ded45dbaf 2114 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2115 display.cls();
WiredHome 25:9556a3a9b7cc 2116 display.Backlight_u8(255);
WiredHome 23:a50ded45dbaf 2117 display.puts(0,0, "Text Cursor Test.");
WiredHome 73:f22a18707b5e 2118
WiredHome 23:a50ded45dbaf 2119 // visible, non-blinking
WiredHome 24:8ca861acf12d 2120 display.SetTextCursor(0,20);
WiredHome 53:86d24b9480b9 2121 display.SetTextCursorControl(RA8875::IBEAM, false);
WiredHome 24:8ca861acf12d 2122 p = iCursor;
WiredHome 23:a50ded45dbaf 2123 while (*p) {
WiredHome 24:8ca861acf12d 2124 display._putc(*p++);
WiredHome 41:2956a0a221e5 2125 wait_ms(delay);
WiredHome 24:8ca861acf12d 2126 }
WiredHome 24:8ca861acf12d 2127
WiredHome 53:86d24b9480b9 2128 display.SetTextCursorControl(RA8875::UNDER, false);
WiredHome 24:8ca861acf12d 2129 p = uCursor;
WiredHome 24:8ca861acf12d 2130 while (*p) {
WiredHome 24:8ca861acf12d 2131 display._putc(*p++);
WiredHome 41:2956a0a221e5 2132 wait_ms(delay);
WiredHome 23:a50ded45dbaf 2133 }
WiredHome 73:f22a18707b5e 2134
WiredHome 53:86d24b9480b9 2135 display.SetTextCursorControl(RA8875::BLOCK, false);
WiredHome 24:8ca861acf12d 2136 p = bCursor;
WiredHome 24:8ca861acf12d 2137 while (*p) {
WiredHome 24:8ca861acf12d 2138 display._putc(*p++);
WiredHome 41:2956a0a221e5 2139 wait_ms(delay);
WiredHome 24:8ca861acf12d 2140 }
WiredHome 24:8ca861acf12d 2141
WiredHome 53:86d24b9480b9 2142 display.SetTextCursorControl(RA8875::BLOCK, true);
WiredHome 24:8ca861acf12d 2143 p = bbCursor;
WiredHome 24:8ca861acf12d 2144 while (*p) {
WiredHome 24:8ca861acf12d 2145 display._putc(*p++);
WiredHome 41:2956a0a221e5 2146 wait_ms(delay);
WiredHome 24:8ca861acf12d 2147 }
WiredHome 41:2956a0a221e5 2148 wait_ms(delay * 20);
WiredHome 53:86d24b9480b9 2149 display.SetTextCursorControl(RA8875::NOCURSOR, false);
WiredHome 23:a50ded45dbaf 2150 }
WiredHome 23:a50ded45dbaf 2151
WiredHome 44:207594dece70 2152
WiredHome 23:a50ded45dbaf 2153 void BacklightTest(RA8875 & display, Serial & pc, float ramptime)
WiredHome 23:a50ded45dbaf 2154 {
WiredHome 29:422616aa04bd 2155 char buf[60];
WiredHome 41:2956a0a221e5 2156 unsigned int w = (ramptime * 1000)/ 256;
WiredHome 41:2956a0a221e5 2157 int delay = 200;
WiredHome 41:2956a0a221e5 2158
WiredHome 41:2956a0a221e5 2159 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2160 pc.printf("Backlight Test - ramp over %f sec.\r\n", ramptime);
WiredHome 41:2956a0a221e5 2161 else {
WiredHome 41:2956a0a221e5 2162 delay = 0;
WiredHome 41:2956a0a221e5 2163 w = 0;
WiredHome 41:2956a0a221e5 2164 }
WiredHome 23:a50ded45dbaf 2165 display.Backlight_u8(0);
WiredHome 29:422616aa04bd 2166 display.background(White);
WiredHome 23:a50ded45dbaf 2167 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2168 display.cls();
WiredHome 41:2956a0a221e5 2169 wait_ms(delay);
WiredHome 23:a50ded45dbaf 2170 display.puts(0,0, "RA8875 Backlight Test - Ramp up.");
WiredHome 38:38d503b4fad6 2171 for (int i=0; i <= 255; i++) {
WiredHome 29:422616aa04bd 2172 sprintf(buf, "%3d, %4d", i, w);
WiredHome 37:f19b7e7449dc 2173 display.puts(100,100,buf);
WiredHome 23:a50ded45dbaf 2174 display.Backlight_u8(i);
WiredHome 29:422616aa04bd 2175 wait_ms(w);
WiredHome 23:a50ded45dbaf 2176 }
WiredHome 23:a50ded45dbaf 2177 }
WiredHome 23:a50ded45dbaf 2178
WiredHome 44:207594dece70 2179
WiredHome 23:a50ded45dbaf 2180 void BacklightTest2(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2181 {
WiredHome 41:2956a0a221e5 2182 int delay = 20;
WiredHome 41:2956a0a221e5 2183
WiredHome 41:2956a0a221e5 2184 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2185 pc.printf("Backlight Test 2\r\n");
WiredHome 41:2956a0a221e5 2186 else
WiredHome 41:2956a0a221e5 2187 delay = 0;
WiredHome 41:2956a0a221e5 2188
WiredHome 23:a50ded45dbaf 2189 // Dim it out at the end of the tests.
WiredHome 37:f19b7e7449dc 2190 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2191 display.puts(0,0, "Ramp Backlight down.");
WiredHome 23:a50ded45dbaf 2192 // Ramp it off
WiredHome 23:a50ded45dbaf 2193 for (int i=255; i != 0; i--) {
WiredHome 23:a50ded45dbaf 2194 display.Backlight_u8(i);
WiredHome 41:2956a0a221e5 2195 wait_ms(delay);
WiredHome 23:a50ded45dbaf 2196 }
WiredHome 23:a50ded45dbaf 2197 display.Backlight_u8(0);
WiredHome 23:a50ded45dbaf 2198 }
WiredHome 23:a50ded45dbaf 2199
WiredHome 44:207594dece70 2200
WiredHome 23:a50ded45dbaf 2201 void ExternalFontTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2202 {
WiredHome 41:2956a0a221e5 2203 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2204 pc.printf("External Font Test\r\n");
WiredHome 23:a50ded45dbaf 2205 display.background(Black);
WiredHome 23:a50ded45dbaf 2206 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2207 display.cls();
WiredHome 23:a50ded45dbaf 2208 display.Backlight(1);
WiredHome 37:f19b7e7449dc 2209 display.puts(0,0, "External Font Test.");
WiredHome 37:f19b7e7449dc 2210
WiredHome 37:f19b7e7449dc 2211 display.set_font(Small_6);
WiredHome 73:f22a18707b5e 2212 display.puts(0,30, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 37:f19b7e7449dc 2213
WiredHome 23:a50ded45dbaf 2214 display.set_font(Arial12x12);
WiredHome 37:f19b7e7449dc 2215 display.puts("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 37:f19b7e7449dc 2216 display.set_font(); // restore to internal
WiredHome 73:f22a18707b5e 2217
WiredHome 37:f19b7e7449dc 2218 display.puts("Normal font again.");
WiredHome 37:f19b7e7449dc 2219 //display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 2220 }
WiredHome 23:a50ded45dbaf 2221
WiredHome 44:207594dece70 2222
WiredHome 23:a50ded45dbaf 2223 void DOSColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2224 {
WiredHome 41:2956a0a221e5 2225 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2226 pc.printf("DOS Color Test\r\n");
WiredHome 23:a50ded45dbaf 2227 display.background(Black);
WiredHome 23:a50ded45dbaf 2228 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2229 display.cls();
WiredHome 23:a50ded45dbaf 2230 display.puts(0,0, "DOS Colors - Fore");
WiredHome 23:a50ded45dbaf 2231 display.puts(280,0, "Back");
WiredHome 23:a50ded45dbaf 2232 display.background(Gray);
WiredHome 23:a50ded45dbaf 2233 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2234 display.foreground(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2235 display.puts(160, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 2236 display.background(Black);
WiredHome 23:a50ded45dbaf 2237 }
WiredHome 23:a50ded45dbaf 2238 display.foreground(White);
WiredHome 23:a50ded45dbaf 2239 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2240 display.background(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2241 display.puts(360, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 2242 display.foreground(White);
WiredHome 23:a50ded45dbaf 2243 }
WiredHome 23:a50ded45dbaf 2244 }
WiredHome 23:a50ded45dbaf 2245
WiredHome 44:207594dece70 2246
WiredHome 23:a50ded45dbaf 2247 void WebColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2248 {
WiredHome 41:2956a0a221e5 2249 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2250 pc.printf("Web Color Test\r\n");
WiredHome 23:a50ded45dbaf 2251 display.background(Black);
WiredHome 23:a50ded45dbaf 2252 display.foreground(Blue);
WiredHome 32:0e4f2ae512e2 2253 display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 2254 display.cls();
WiredHome 59:fb40aad4efd4 2255 display.SetTextFontSize(1,1);
WiredHome 59:fb40aad4efd4 2256 display.puts(200,0, "Web Color Test");
WiredHome 59:fb40aad4efd4 2257 display.SetTextCursor(0,0);
WiredHome 59:fb40aad4efd4 2258 display.puts(" ");
WiredHome 59:fb40aad4efd4 2259 for (int i=0; i<16; i++)
WiredHome 59:fb40aad4efd4 2260 display.printf("%X", i&0xF);
WiredHome 59:fb40aad4efd4 2261 display.puts("\r\n0 ");
WiredHome 23:a50ded45dbaf 2262 for (int i=0; i<sizeof(WebColors)/sizeof(WebColors[0]); i++) {
WiredHome 23:a50ded45dbaf 2263 display.background(WebColors[i]);
WiredHome 23:a50ded45dbaf 2264 display.puts(" ");
WiredHome 59:fb40aad4efd4 2265 if (i % 16 == 15 && i < 255) {
WiredHome 59:fb40aad4efd4 2266 display.printf("\r\n%X ", ((i+1)/16));
WiredHome 59:fb40aad4efd4 2267 }
WiredHome 23:a50ded45dbaf 2268 }
WiredHome 23:a50ded45dbaf 2269 display.SetTextFontSize(1,1);
WiredHome 23:a50ded45dbaf 2270 }
WiredHome 23:a50ded45dbaf 2271
WiredHome 44:207594dece70 2272
WiredHome 37:f19b7e7449dc 2273 void PixelTest(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 2274 {
WiredHome 37:f19b7e7449dc 2275 int i, c, x, y;
WiredHome 37:f19b7e7449dc 2276
WiredHome 41:2956a0a221e5 2277 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2278 pc.printf("Pixel Test\r\n");
WiredHome 37:f19b7e7449dc 2279 display.background(Black);
WiredHome 37:f19b7e7449dc 2280 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 2281 display.cls();
WiredHome 37:f19b7e7449dc 2282 display.puts(0,0, "Pixel Test");
WiredHome 37:f19b7e7449dc 2283 for (i=0; i<1000; i++) {
WiredHome 37:f19b7e7449dc 2284 x = rand() % 480;
WiredHome 37:f19b7e7449dc 2285 y = 16 + rand() % (272-16);
WiredHome 37:f19b7e7449dc 2286 c = rand() % 16;
WiredHome 37:f19b7e7449dc 2287 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 37:f19b7e7449dc 2288 display.pixel(x,y, display.DOSColor(c));
WiredHome 37:f19b7e7449dc 2289 }
WiredHome 37:f19b7e7449dc 2290 }
WiredHome 37:f19b7e7449dc 2291
WiredHome 44:207594dece70 2292
WiredHome 23:a50ded45dbaf 2293 void LineTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2294 {
WiredHome 23:a50ded45dbaf 2295 int i, x, y, x2, y2;
WiredHome 23:a50ded45dbaf 2296
WiredHome 41:2956a0a221e5 2297 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2298 pc.printf("Line Test\r\n");
WiredHome 23:a50ded45dbaf 2299 display.background(Black);
WiredHome 23:a50ded45dbaf 2300 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2301 display.cls();
WiredHome 23:a50ded45dbaf 2302 display.puts(0,0, "Line Test");
WiredHome 23:a50ded45dbaf 2303 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2304 // Lines
WiredHome 23:a50ded45dbaf 2305 x = rand() % 480;
WiredHome 23:a50ded45dbaf 2306 y = rand() % 272;
WiredHome 23:a50ded45dbaf 2307 x2 = rand() % 480;
WiredHome 23:a50ded45dbaf 2308 y2 = rand() % 272;
WiredHome 23:a50ded45dbaf 2309 display.line(x,y, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2310 }
WiredHome 62:ba5d33438fda 2311 display.foreground(BrightRed);
WiredHome 62:ba5d33438fda 2312 display.foreground(BrightGreen);
WiredHome 62:ba5d33438fda 2313 display.foreground(BrightBlue);
WiredHome 62:ba5d33438fda 2314 display.line(55,50, 79,74, BrightRed);
WiredHome 62:ba5d33438fda 2315 display.line(57,50, 81,74, BrightGreen);
WiredHome 62:ba5d33438fda 2316 display.line(59,50, 83,74, BrightBlue);
WiredHome 62:ba5d33438fda 2317 // horz
WiredHome 62:ba5d33438fda 2318 display.line(30,40, 32,40, BrightRed);
WiredHome 62:ba5d33438fda 2319 display.line(30,42, 32,42, BrightGreen);
WiredHome 62:ba5d33438fda 2320 display.line(30,44, 32,44, BrightBlue);
WiredHome 62:ba5d33438fda 2321 // vert
WiredHome 62:ba5d33438fda 2322 display.line(20,40, 20,42, BrightRed);
WiredHome 62:ba5d33438fda 2323 display.line(22,40, 22,42, BrightGreen);
WiredHome 62:ba5d33438fda 2324 display.line(24,40, 24,42, BrightBlue);
WiredHome 62:ba5d33438fda 2325 // compare point to line-point
WiredHome 62:ba5d33438fda 2326 display.pixel(20,50, BrightRed);
WiredHome 62:ba5d33438fda 2327 display.pixel(22,50, BrightGreen);
WiredHome 62:ba5d33438fda 2328 display.pixel(24,50, BrightBlue);
WiredHome 62:ba5d33438fda 2329 display.line(20,52, 20,52, BrightRed);
WiredHome 62:ba5d33438fda 2330 display.line(22,52, 22,52, BrightGreen);
WiredHome 62:ba5d33438fda 2331 display.line(24,52, 24,52, BrightBlue);
WiredHome 73:f22a18707b5e 2332
WiredHome 62:ba5d33438fda 2333 // point
WiredHome 62:ba5d33438fda 2334 display.line(50,50, 50,50, Red);
WiredHome 62:ba5d33438fda 2335 display.line(52,52, 52,52, Green);
WiredHome 62:ba5d33438fda 2336 display.line(54,54, 54,54, Blue);
WiredHome 62:ba5d33438fda 2337 display.line(60,60, 60,60, BrightRed);
WiredHome 62:ba5d33438fda 2338 display.line(62,62, 62,62, BrightGreen);
WiredHome 62:ba5d33438fda 2339 display.line(64,64, 64,64, BrightBlue);
WiredHome 62:ba5d33438fda 2340 display.line(70,70, 70,70, DarkRed);
WiredHome 62:ba5d33438fda 2341 display.line(72,72, 72,72, DarkGreen);
WiredHome 62:ba5d33438fda 2342 display.line(74,74, 74,74, DarkBlue);
WiredHome 23:a50ded45dbaf 2343 }
WiredHome 23:a50ded45dbaf 2344
WiredHome 44:207594dece70 2345
WiredHome 23:a50ded45dbaf 2346 void RectangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2347 {
WiredHome 23:a50ded45dbaf 2348 int i, x1,y1, x2,y2;
WiredHome 23:a50ded45dbaf 2349
WiredHome 41:2956a0a221e5 2350 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2351 pc.printf("Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 2352 display.background(Black);
WiredHome 23:a50ded45dbaf 2353 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2354 display.cls();
WiredHome 23:a50ded45dbaf 2355 display.puts(0,0, "Rectangle Test");
WiredHome 23:a50ded45dbaf 2356 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2357 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 2358 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2359 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 2360 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2361 display.rect(x1,y1, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2362
WiredHome 23:a50ded45dbaf 2363 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2364 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2365 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2366 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2367 display.rect(x1,y1, x2,y2, FILL);
WiredHome 23:a50ded45dbaf 2368 }
WiredHome 23:a50ded45dbaf 2369 }
WiredHome 23:a50ded45dbaf 2370
WiredHome 44:207594dece70 2371
WiredHome 44:207594dece70 2372 void LayerTest(RA8875 & display, Serial & pc)
WiredHome 44:207594dece70 2373 {
WiredHome 44:207594dece70 2374 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 44:207594dece70 2375
WiredHome 44:207594dece70 2376 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2377 pc.printf("Layer Test\r\n");
WiredHome 44:207594dece70 2378
WiredHome 50:2c4f474a2453 2379 display.SelectDrawingLayer(0);
WiredHome 44:207594dece70 2380 display.background(Black);
WiredHome 44:207594dece70 2381 display.foreground(Blue);
WiredHome 44:207594dece70 2382 display.cls();
WiredHome 44:207594dece70 2383 display.puts(0,0, "Layer 0");
WiredHome 44:207594dece70 2384 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 2385 x1 = rand() % 240;
WiredHome 44:207594dece70 2386 y1 = 50 + rand() % 200;
WiredHome 44:207594dece70 2387 x2 = x1 + rand() % 100;
WiredHome 44:207594dece70 2388 y2 = y1 + rand() % 100;
WiredHome 44:207594dece70 2389 r1 = rand() % (x2 - x1)/2;
WiredHome 44:207594dece70 2390 r2 = rand() % (y2 - y1)/2;
WiredHome 44:207594dece70 2391 display.roundrect(x1,y1, x2,y2, r1,r2, display.DOSColor(i));
WiredHome 44:207594dece70 2392 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2393 wait_ms(20);
WiredHome 44:207594dece70 2394 }
WiredHome 44:207594dece70 2395 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2396 wait_ms(1000);
WiredHome 44:207594dece70 2397
WiredHome 50:2c4f474a2453 2398 display.SelectDrawingLayer(1);
WiredHome 44:207594dece70 2399 display.background(Black);
WiredHome 44:207594dece70 2400 display.foreground(Yellow);
WiredHome 44:207594dece70 2401 display.cls();
WiredHome 44:207594dece70 2402 display.puts(240,0, "Layer 1");
WiredHome 44:207594dece70 2403 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 2404 x1 = 300 + rand() % 100;
WiredHome 44:207594dece70 2405 y1 = 70 + rand() % 200;
WiredHome 44:207594dece70 2406 r1 = rand() % min(y1 - 20, 100);
WiredHome 44:207594dece70 2407 display.circle(x1,y1,r1, display.DOSColor(i));
WiredHome 44:207594dece70 2408 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2409 wait_ms(20);
WiredHome 44:207594dece70 2410 }
WiredHome 56:7a85d226ad0d 2411 display.SetLayerMode(RA8875::ShowLayer1); // Show it after the build-up
WiredHome 44:207594dece70 2412 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2413 wait_ms(2000);
WiredHome 44:207594dece70 2414
WiredHome 50:2c4f474a2453 2415 display.SelectDrawingLayer(0);
WiredHome 56:7a85d226ad0d 2416 display.SetLayerMode(RA8875::ShowLayer0); // Show Layer 0 again
WiredHome 44:207594dece70 2417 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2418 wait_ms(1000);
WiredHome 53:86d24b9480b9 2419 display.SetLayerMode(RA8875::TransparentMode); // Transparent mode
WiredHome 44:207594dece70 2420 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2421 wait_ms(1000);
WiredHome 44:207594dece70 2422 for (i=0; i<=8; i++) {
WiredHome 44:207594dece70 2423 display.SetLayerTransparency(i, 8-i);
WiredHome 44:207594dece70 2424 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 2425 wait_ms(200);
WiredHome 44:207594dece70 2426 }
WiredHome 73:f22a18707b5e 2427
WiredHome 44:207594dece70 2428 // Restore before we exit
WiredHome 44:207594dece70 2429 display.SetLayerTransparency(0, 0);
WiredHome 56:7a85d226ad0d 2430 display.SetLayerMode(RA8875::ShowLayer0); // Restore to layer 0
WiredHome 44:207594dece70 2431 }
WiredHome 44:207594dece70 2432
WiredHome 44:207594dece70 2433
WiredHome 23:a50ded45dbaf 2434 void RoundRectTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2435 {
WiredHome 37:f19b7e7449dc 2436 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 23:a50ded45dbaf 2437
WiredHome 41:2956a0a221e5 2438 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2439 pc.printf("Round Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 2440 display.background(Black);
WiredHome 23:a50ded45dbaf 2441 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2442 display.cls();
WiredHome 23:a50ded45dbaf 2443 display.puts(0,0, "Rounded Rectangle Test");
WiredHome 73:f22a18707b5e 2444
WiredHome 23:a50ded45dbaf 2445 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2446 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 2447 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2448 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 2449 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 2450 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 2451 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 2452 display.roundrect(x1,y1, x2,y2, 5,8, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2453
WiredHome 23:a50ded45dbaf 2454 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2455 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2456 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 2457 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 2458 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 2459 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 2460 display.roundrect(x1,y1, x2,y2, r1,r2, FILL);
WiredHome 23:a50ded45dbaf 2461 }
WiredHome 23:a50ded45dbaf 2462 }
WiredHome 23:a50ded45dbaf 2463
WiredHome 44:207594dece70 2464
WiredHome 23:a50ded45dbaf 2465 void TriangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2466 {
WiredHome 23:a50ded45dbaf 2467 int i, x1, y1, x2, y2, x3, y3;
WiredHome 23:a50ded45dbaf 2468
WiredHome 41:2956a0a221e5 2469 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2470 pc.printf("Triangle Test\r\n");
WiredHome 23:a50ded45dbaf 2471 display.background(Black);
WiredHome 23:a50ded45dbaf 2472 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2473 display.cls();
WiredHome 23:a50ded45dbaf 2474 display.puts(0,0, "Triangle Test");
WiredHome 23:a50ded45dbaf 2475
WiredHome 23:a50ded45dbaf 2476 x1 = 150;
WiredHome 23:a50ded45dbaf 2477 y1 = 2;
WiredHome 23:a50ded45dbaf 2478 x2 = 190;
WiredHome 23:a50ded45dbaf 2479 y2 = 7;
WiredHome 23:a50ded45dbaf 2480 x3 = 170;
WiredHome 23:a50ded45dbaf 2481 y3 = 16;
WiredHome 23:a50ded45dbaf 2482 display.triangle(x1,y1, x2,y2, x3,y3);
WiredHome 23:a50ded45dbaf 2483
WiredHome 23:a50ded45dbaf 2484 x1 = 200;
WiredHome 23:a50ded45dbaf 2485 y1 = 2;
WiredHome 23:a50ded45dbaf 2486 x2 = 240;
WiredHome 23:a50ded45dbaf 2487 y2 = 7;
WiredHome 23:a50ded45dbaf 2488 x3 = 220;
WiredHome 23:a50ded45dbaf 2489 y3 = 16;
WiredHome 23:a50ded45dbaf 2490 display.filltriangle(x1,y1, x2,y2, x3,y3, BrightRed);
WiredHome 23:a50ded45dbaf 2491
WiredHome 23:a50ded45dbaf 2492 x1 = 300;
WiredHome 23:a50ded45dbaf 2493 y1 = 2;
WiredHome 23:a50ded45dbaf 2494 x2 = 340;
WiredHome 23:a50ded45dbaf 2495 y2 = 7;
WiredHome 23:a50ded45dbaf 2496 x3 = 320;
WiredHome 23:a50ded45dbaf 2497 y3 = 16;
WiredHome 23:a50ded45dbaf 2498 display.triangle(x1,y1, x2,y2, x3,y3, NOFILL);
WiredHome 23:a50ded45dbaf 2499
WiredHome 23:a50ded45dbaf 2500 x1 = 400;
WiredHome 23:a50ded45dbaf 2501 y1 = 2;
WiredHome 23:a50ded45dbaf 2502 x2 = 440;
WiredHome 23:a50ded45dbaf 2503 y2 = 7;
WiredHome 23:a50ded45dbaf 2504 x3 = 420;
WiredHome 23:a50ded45dbaf 2505 y3 = 16;
WiredHome 23:a50ded45dbaf 2506 display.triangle(x1,y1, x2,y2, x3,y3, Blue);
WiredHome 23:a50ded45dbaf 2507
WiredHome 23:a50ded45dbaf 2508 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2509 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 2510 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2511 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 2512 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2513 x3 = rand() % 240;
WiredHome 23:a50ded45dbaf 2514 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2515 display.triangle(x1,y1, x2,y2, x3,y3, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2516 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2517 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2518 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2519 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2520 x3 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2521 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2522 display.triangle(x1,y1, x2,y2, x3,y3, FILL);
WiredHome 23:a50ded45dbaf 2523 }
WiredHome 23:a50ded45dbaf 2524 }
WiredHome 23:a50ded45dbaf 2525
WiredHome 44:207594dece70 2526
WiredHome 23:a50ded45dbaf 2527 void CircleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2528 {
WiredHome 23:a50ded45dbaf 2529 int i, x, y, r1;
WiredHome 23:a50ded45dbaf 2530
WiredHome 41:2956a0a221e5 2531 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2532 pc.printf("Circle Test\r\n");
WiredHome 23:a50ded45dbaf 2533 display.background(Black);
WiredHome 23:a50ded45dbaf 2534 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2535 display.cls();
WiredHome 23:a50ded45dbaf 2536 display.puts(0,0, "Circle Test");
WiredHome 23:a50ded45dbaf 2537 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2538 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 2539 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2540 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2541 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 2542 display.circle(x,y,r1, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2543
WiredHome 23:a50ded45dbaf 2544 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 2545 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2546 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2547 //pc.printf(" (%d,%d) - %d FILL\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 2548 display.circle(x,y,r1, display.DOSColor(i), FILL);
WiredHome 23:a50ded45dbaf 2549 }
WiredHome 23:a50ded45dbaf 2550 }
WiredHome 23:a50ded45dbaf 2551
WiredHome 44:207594dece70 2552
WiredHome 23:a50ded45dbaf 2553 void EllipseTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2554 {
WiredHome 23:a50ded45dbaf 2555 int i,x,y,r1,r2;
WiredHome 23:a50ded45dbaf 2556
WiredHome 41:2956a0a221e5 2557 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2558 pc.printf("Ellipse Test\r\n");
WiredHome 23:a50ded45dbaf 2559 display.background(Black);
WiredHome 23:a50ded45dbaf 2560 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2561 display.cls();
WiredHome 23:a50ded45dbaf 2562 display.puts(0,0, "Ellipse Test");
WiredHome 23:a50ded45dbaf 2563 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2564 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 2565 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2566 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2567 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2568 display.ellipse(x,y,r1,r2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2569
WiredHome 23:a50ded45dbaf 2570 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 2571 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2572 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2573 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2574 display.ellipse(x,y,r1,r2, FILL);
WiredHome 23:a50ded45dbaf 2575 }
WiredHome 23:a50ded45dbaf 2576 }
WiredHome 23:a50ded45dbaf 2577
WiredHome 44:207594dece70 2578
WiredHome 37:f19b7e7449dc 2579 void TestGraphicsBitmap(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 2580 {
WiredHome 37:f19b7e7449dc 2581 LocalFileSystem local("local");
WiredHome 41:2956a0a221e5 2582 if (!SuppressSlowStuff)
WiredHome 73:f22a18707b5e 2583 pc.printf("Bitmap File Load\r\n");
WiredHome 37:f19b7e7449dc 2584 display.background(Black);
WiredHome 37:f19b7e7449dc 2585 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 2586 display.cls();
WiredHome 37:f19b7e7449dc 2587 display.puts(0,0, "Graphics Test, loading /local/TestPat.bmp");
WiredHome 37:f19b7e7449dc 2588 wait(3);
WiredHome 37:f19b7e7449dc 2589
WiredHome 37:f19b7e7449dc 2590 int r = display.RenderBitmapFile(0,0, "/local/TestPat.bmp");
WiredHome 59:fb40aad4efd4 2591 if (!SuppressSlowStuff)
WiredHome 59:fb40aad4efd4 2592 pc.printf(" returned %d\r\n", r);
WiredHome 37:f19b7e7449dc 2593 }
WiredHome 37:f19b7e7449dc 2594
WiredHome 44:207594dece70 2595
WiredHome 77:9206c13aa527 2596 void TouchPanelTest(RA8875 & display, Serial & pc)
WiredHome 77:9206c13aa527 2597 {
WiredHome 77:9206c13aa527 2598 Timer t;
WiredHome 77:9206c13aa527 2599 loc_t x, y;
WiredHome 77:9206c13aa527 2600
WiredHome 77:9206c13aa527 2601 display.background(Black);
WiredHome 77:9206c13aa527 2602 display.foreground(Blue);
WiredHome 77:9206c13aa527 2603 display.cls();
WiredHome 77:9206c13aa527 2604 display.puts(0,0, "Touch Panel Test\r\n");
WiredHome 77:9206c13aa527 2605 pc.printf("Touch Panel Test");
WiredHome 77:9206c13aa527 2606 display.TouchPanelInit();
WiredHome 77:9206c13aa527 2607 point_t pTest[3] =
WiredHome 77:9206c13aa527 2608 { { 50, 50 }, {450, 50}, {450,250} };
WiredHome 77:9206c13aa527 2609 point_t pSample[3];
WiredHome 77:9206c13aa527 2610 for (int i=0; i<3; i++) {
WiredHome 77:9206c13aa527 2611 display.foreground(Blue);
WiredHome 77:9206c13aa527 2612 display.printf("(%3d,%3d) => ", pTest[i].x, pTest[i].y);
WiredHome 77:9206c13aa527 2613 display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, White);
WiredHome 77:9206c13aa527 2614 display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, White);
WiredHome 77:9206c13aa527 2615 while (!display.TouchPanelReadRaw(&x, &y))
WiredHome 77:9206c13aa527 2616 wait_ms(20);
WiredHome 77:9206c13aa527 2617 pSample[i].x = x;
WiredHome 77:9206c13aa527 2618 pSample[i].y = y;
WiredHome 77:9206c13aa527 2619 display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, Black);
WiredHome 77:9206c13aa527 2620 display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, Black);
WiredHome 77:9206c13aa527 2621 display.foreground(Blue);
WiredHome 77:9206c13aa527 2622 display.printf(" (%4d,%4d)\r\n", x,y);
WiredHome 77:9206c13aa527 2623 while (display.TouchPanelReadRaw(&x, &y))
WiredHome 77:9206c13aa527 2624 wait_ms(20);
WiredHome 77:9206c13aa527 2625 wait(2);
WiredHome 77:9206c13aa527 2626 }
WiredHome 77:9206c13aa527 2627 display.TouchPanelCalibrate(pTest, pSample, NULL);
WiredHome 77:9206c13aa527 2628 display.printf(" Calibration is complete.");
WiredHome 77:9206c13aa527 2629 t.start();
WiredHome 77:9206c13aa527 2630 do {
WiredHome 77:9206c13aa527 2631 point_t point = {0, 0};
WiredHome 77:9206c13aa527 2632 if (display.TouchPanelPoint(&point)) {
WiredHome 77:9206c13aa527 2633 display.pixel(point.x, point.y, Red);
WiredHome 77:9206c13aa527 2634 }
WiredHome 77:9206c13aa527 2635 } while (t.read_ms() < 30000);
WiredHome 77:9206c13aa527 2636 pc.printf(">");
WiredHome 77:9206c13aa527 2637 }
WiredHome 77:9206c13aa527 2638
WiredHome 77:9206c13aa527 2639
WiredHome 41:2956a0a221e5 2640 void SpeedTest(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 2641 {
WiredHome 41:2956a0a221e5 2642 Timer t;
WiredHome 41:2956a0a221e5 2643 SuppressSlowStuff = true;
WiredHome 41:2956a0a221e5 2644 pc.printf("\r\nSpeedTest disables delays, runs tests, reports overall time.\r\n");
WiredHome 41:2956a0a221e5 2645 t.start();
WiredHome 41:2956a0a221e5 2646 // do stuff fast
WiredHome 41:2956a0a221e5 2647 TextCursorTest(display, pc);
WiredHome 49:c5182231d1b9 2648 TextWrapTest(display, pc);
WiredHome 41:2956a0a221e5 2649 BacklightTest(display, pc, 0);
WiredHome 41:2956a0a221e5 2650 BacklightTest2(display, pc);
WiredHome 41:2956a0a221e5 2651 ExternalFontTest(display, pc);
WiredHome 41:2956a0a221e5 2652 DOSColorTest(display, pc);
WiredHome 41:2956a0a221e5 2653 WebColorTest(display, pc);
WiredHome 41:2956a0a221e5 2654 PixelTest(display, pc);
WiredHome 41:2956a0a221e5 2655 LineTest(display, pc);
WiredHome 41:2956a0a221e5 2656 RectangleTest(display, pc);
WiredHome 41:2956a0a221e5 2657 RoundRectTest(display, pc);
WiredHome 41:2956a0a221e5 2658 TriangleTest(display, pc);
WiredHome 41:2956a0a221e5 2659 CircleTest(display, pc);
WiredHome 41:2956a0a221e5 2660 EllipseTest(display, pc);
WiredHome 44:207594dece70 2661 LayerTest(display, pc);
WiredHome 41:2956a0a221e5 2662 //TestGraphicsBitmap(display, pc);
WiredHome 41:2956a0a221e5 2663 pc.printf("SpeedTest completed in %d msec\r\n", t.read_ms());
WiredHome 73:f22a18707b5e 2664 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 2665 display.ReportPerformance(pc);
WiredHome 73:f22a18707b5e 2666 #endif
WiredHome 41:2956a0a221e5 2667 SuppressSlowStuff = false;
WiredHome 41:2956a0a221e5 2668 }
WiredHome 41:2956a0a221e5 2669
WiredHome 44:207594dece70 2670
WiredHome 41:2956a0a221e5 2671 void PrintScreen(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 2672 {
WiredHome 41:2956a0a221e5 2673 LocalFileSystem local("local");
WiredHome 41:2956a0a221e5 2674 if (!SuppressSlowStuff)
WiredHome 73:f22a18707b5e 2675 pc.printf("PrintScreen\r\n");
WiredHome 41:2956a0a221e5 2676 display.PrintScreen( 0,0, 480,272, "/local/Capture.bmp");
WiredHome 41:2956a0a221e5 2677 }
WiredHome 41:2956a0a221e5 2678
WiredHome 44:207594dece70 2679
WiredHome 23:a50ded45dbaf 2680 void RunTestSet(RA8875 & lcd, Serial & pc)
WiredHome 23:a50ded45dbaf 2681 {
WiredHome 23:a50ded45dbaf 2682 int q = 0;
WiredHome 23:a50ded45dbaf 2683 int automode = 0;
WiredHome 49:c5182231d1b9 2684 const unsigned char modelist[] = "BDWtGLlFROTPCEbw"; // auto-test in this order.
WiredHome 23:a50ded45dbaf 2685
WiredHome 23:a50ded45dbaf 2686 while(1) {
WiredHome 23:a50ded45dbaf 2687 pc.printf("\r\n"
WiredHome 41:2956a0a221e5 2688 "B - Backlight up b - backlight dim\r\n"
WiredHome 41:2956a0a221e5 2689 "D - DOS Colors W - Web Colors\r\n"
WiredHome 41:2956a0a221e5 2690 "t - text cursor G - Graphics Bitmap\r\n"
WiredHome 41:2956a0a221e5 2691 "L - Lines F - external Font\r\n"
WiredHome 41:2956a0a221e5 2692 "R - Rectangles O - rOund rectangles\r\n"
WiredHome 41:2956a0a221e5 2693 "T - Triangles P - Pixels \r\n"
WiredHome 41:2956a0a221e5 2694 "C - Circles E - Ellipses\r\n"
WiredHome 41:2956a0a221e5 2695 "A - Auto Test mode S - Speed Test\r\n"
WiredHome 77:9206c13aa527 2696 "K - Keypad Test s - touch screen test\r\n"
WiredHome 41:2956a0a221e5 2697 "p - print screen r - reset \r\n"
WiredHome 49:c5182231d1b9 2698 "l - layer test w - wrapping text \r\n"
WiredHome 73:f22a18707b5e 2699 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 2700 "0 - clear performance 1 - report performance\r\n"
WiredHome 73:f22a18707b5e 2701 #endif
WiredHome 23:a50ded45dbaf 2702 "> ");
WiredHome 23:a50ded45dbaf 2703 if (automode == -1 || pc.readable()) {
WiredHome 23:a50ded45dbaf 2704 automode = -1;
WiredHome 37:f19b7e7449dc 2705 q = pc.getc();
WiredHome 37:f19b7e7449dc 2706 while (pc.readable())
WiredHome 37:f19b7e7449dc 2707 pc.getc();
WiredHome 23:a50ded45dbaf 2708 } else if (automode >= 0) {
WiredHome 23:a50ded45dbaf 2709 q = modelist[automode];
WiredHome 23:a50ded45dbaf 2710 }
WiredHome 23:a50ded45dbaf 2711 switch(q) {
WiredHome 73:f22a18707b5e 2712 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 2713 case '0':
WiredHome 41:2956a0a221e5 2714 lcd.ClearPerformance();
WiredHome 41:2956a0a221e5 2715 break;
WiredHome 41:2956a0a221e5 2716 case '1':
WiredHome 41:2956a0a221e5 2717 lcd.ReportPerformance(pc);
WiredHome 41:2956a0a221e5 2718 break;
WiredHome 73:f22a18707b5e 2719 #endif
WiredHome 23:a50ded45dbaf 2720 case 'A':
WiredHome 23:a50ded45dbaf 2721 automode = 0;
WiredHome 23:a50ded45dbaf 2722 break;
WiredHome 23:a50ded45dbaf 2723 case 'B':
WiredHome 41:2956a0a221e5 2724 BacklightTest(lcd, pc, 2);
WiredHome 23:a50ded45dbaf 2725 break;
WiredHome 23:a50ded45dbaf 2726 case 'b':
WiredHome 23:a50ded45dbaf 2727 BacklightTest2(lcd, pc);
WiredHome 23:a50ded45dbaf 2728 break;
WiredHome 23:a50ded45dbaf 2729 case 'D':
WiredHome 23:a50ded45dbaf 2730 DOSColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2731 break;
WiredHome 75:ca78388cfd77 2732 case 'K':
WiredHome 75:ca78388cfd77 2733 KeyPadTest(lcd, pc);
WiredHome 75:ca78388cfd77 2734 break;
WiredHome 23:a50ded45dbaf 2735 case 'W':
WiredHome 23:a50ded45dbaf 2736 WebColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2737 break;
WiredHome 23:a50ded45dbaf 2738 case 't':
WiredHome 23:a50ded45dbaf 2739 TextCursorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2740 break;
WiredHome 49:c5182231d1b9 2741 case 'w':
WiredHome 49:c5182231d1b9 2742 TextWrapTest(lcd, pc);
WiredHome 49:c5182231d1b9 2743 break;
WiredHome 23:a50ded45dbaf 2744 case 'F':
WiredHome 23:a50ded45dbaf 2745 ExternalFontTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2746 break;
WiredHome 23:a50ded45dbaf 2747 case 'L':
WiredHome 23:a50ded45dbaf 2748 LineTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2749 break;
WiredHome 44:207594dece70 2750 case 'l':
WiredHome 44:207594dece70 2751 LayerTest(lcd, pc);
WiredHome 44:207594dece70 2752 break;
WiredHome 23:a50ded45dbaf 2753 case 'R':
WiredHome 23:a50ded45dbaf 2754 RectangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2755 break;
WiredHome 23:a50ded45dbaf 2756 case 'O':
WiredHome 23:a50ded45dbaf 2757 RoundRectTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2758 break;
WiredHome 41:2956a0a221e5 2759 case 'p':
WiredHome 41:2956a0a221e5 2760 PrintScreen(lcd, pc);
WiredHome 41:2956a0a221e5 2761 break;
WiredHome 41:2956a0a221e5 2762 case 'S':
WiredHome 41:2956a0a221e5 2763 SpeedTest(lcd, pc);
WiredHome 41:2956a0a221e5 2764 break;
WiredHome 77:9206c13aa527 2765 case 's':
WiredHome 77:9206c13aa527 2766 TouchPanelTest(lcd, pc);
WiredHome 77:9206c13aa527 2767 break;
WiredHome 23:a50ded45dbaf 2768 case 'T':
WiredHome 23:a50ded45dbaf 2769 TriangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2770 break;
WiredHome 37:f19b7e7449dc 2771 case 'P':
WiredHome 37:f19b7e7449dc 2772 PixelTest(lcd, pc);
WiredHome 37:f19b7e7449dc 2773 break;
WiredHome 37:f19b7e7449dc 2774 case 'G':
WiredHome 37:f19b7e7449dc 2775 TestGraphicsBitmap(lcd, pc);
WiredHome 37:f19b7e7449dc 2776 break;
WiredHome 23:a50ded45dbaf 2777 case 'C':
WiredHome 23:a50ded45dbaf 2778 CircleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2779 break;
WiredHome 23:a50ded45dbaf 2780 case 'E':
WiredHome 23:a50ded45dbaf 2781 EllipseTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2782 break;
WiredHome 23:a50ded45dbaf 2783 case 'r':
WiredHome 23:a50ded45dbaf 2784 pc.printf("Resetting ...\r\n");
WiredHome 23:a50ded45dbaf 2785 wait_ms(20);
WiredHome 23:a50ded45dbaf 2786 mbed_reset();
WiredHome 23:a50ded45dbaf 2787 break;
WiredHome 75:ca78388cfd77 2788 case ' ':
WiredHome 75:ca78388cfd77 2789 break;
WiredHome 23:a50ded45dbaf 2790 default:
WiredHome 23:a50ded45dbaf 2791 printf("huh?\n");
WiredHome 23:a50ded45dbaf 2792 break;
WiredHome 23:a50ded45dbaf 2793 }
WiredHome 23:a50ded45dbaf 2794 if (automode >= 0) {
WiredHome 23:a50ded45dbaf 2795 automode++;
WiredHome 23:a50ded45dbaf 2796 if (automode >= sizeof(modelist))
WiredHome 23:a50ded45dbaf 2797 automode = 0;
WiredHome 23:a50ded45dbaf 2798 wait_ms(2000);
WiredHome 23:a50ded45dbaf 2799 }
WiredHome 23:a50ded45dbaf 2800 wait_ms(200);
WiredHome 23:a50ded45dbaf 2801 }
WiredHome 23:a50ded45dbaf 2802 }
WiredHome 23:a50ded45dbaf 2803
WiredHome 23:a50ded45dbaf 2804 #endif // TESTENABLE