Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Sun Nov 09 18:52:46 2014 +0000
Revision:
73:f22a18707b5e
Parent:
72:ecffe56af969
Child:
74:686faa218914
Improved PrintScreen function automatically senses some of the modes of operation.

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 19:3f82c1161fd2 72
WiredHome 19:3f82c1161fd2 73 RA8875::RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, const char *name)
WiredHome 58:26658a56112a 74 : GraphicsDisplay(name)
WiredHome 58:26658a56112a 75 , spi(mosi, miso, sclk)
WiredHome 19:3f82c1161fd2 76 , cs(csel)
WiredHome 19:3f82c1161fd2 77 , res(reset)
WiredHome 19:3f82c1161fd2 78 {
WiredHome 19:3f82c1161fd2 79 font = NULL; // no external font, use internal.
WiredHome 19:3f82c1161fd2 80 select(false); // deselect the display
WiredHome 19:3f82c1161fd2 81 frequency(RA8875_DEFAULT_SPI_FREQ); // data rate
WiredHome 28:ed102fc442c4 82 Reset();
WiredHome 28:ed102fc442c4 83 Power(true);
WiredHome 28:ed102fc442c4 84 Backlight_u8(255);
WiredHome 19:3f82c1161fd2 85 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 86 performance.start();
WiredHome 19:3f82c1161fd2 87 ClearPerformance();
WiredHome 19:3f82c1161fd2 88 #endif
WiredHome 19:3f82c1161fd2 89 }
WiredHome 19:3f82c1161fd2 90
WiredHome 43:3becae133285 91
WiredHome 19:3f82c1161fd2 92 //RA8875::~RA8875()
WiredHome 19:3f82c1161fd2 93 //{
WiredHome 19:3f82c1161fd2 94 //}
WiredHome 19:3f82c1161fd2 95
WiredHome 61:8f3153bf0baa 96 uint16_t RA8875::GetDrawingLayer(void)
WiredHome 61:8f3153bf0baa 97 {
WiredHome 61:8f3153bf0baa 98 return (ReadCommand(0x41) & 0x01);
WiredHome 61:8f3153bf0baa 99 }
WiredHome 43:3becae133285 100
WiredHome 50:2c4f474a2453 101 RetCode_t RA8875::SelectDrawingLayer(uint16_t layer)
WiredHome 43:3becae133285 102 {
WiredHome 43:3becae133285 103 unsigned char mwcr1 = ReadCommand(0x41) & ~0x01; // retain all but the currently selected layer
WiredHome 43:3becae133285 104
WiredHome 43:3becae133285 105 if (width() >= 800 && height() >= 480 && color_bpp() == 8) {
WiredHome 43:3becae133285 106 return bad_parameter;
WiredHome 43:3becae133285 107 } else if (layer > 1) {
WiredHome 43:3becae133285 108 return bad_parameter;
WiredHome 43:3becae133285 109 } else { // layer == 0 ro 1
WiredHome 72:ecffe56af969 110 return WriteCommand(0x41, mwcr1 | layer);
WiredHome 43:3becae133285 111 }
WiredHome 43:3becae133285 112 }
WiredHome 43:3becae133285 113
WiredHome 44:207594dece70 114
WiredHome 53:86d24b9480b9 115 RetCode_t RA8875::SetLayerMode(LayerMode_T mode)
WiredHome 44:207594dece70 116 {
WiredHome 53:86d24b9480b9 117 unsigned char ltpr0 = ReadCommand(0x52) & ~0x7; // retain all but the display layer mode
WiredHome 53:86d24b9480b9 118 if (mode <= (LayerMode_T)6) {
WiredHome 53:86d24b9480b9 119 WriteCommand(0x52, ltpr0 | (mode & 0x7));
WiredHome 53:86d24b9480b9 120 return noerror;
WiredHome 53:86d24b9480b9 121 } else {
WiredHome 53:86d24b9480b9 122 return bad_parameter;
WiredHome 53:86d24b9480b9 123 }
WiredHome 44:207594dece70 124 }
WiredHome 44:207594dece70 125
WiredHome 44:207594dece70 126
WiredHome 44:207594dece70 127 RetCode_t RA8875::SetLayerTransparency(uint8_t layer1, uint8_t layer2)
WiredHome 44:207594dece70 128 {
WiredHome 44:207594dece70 129 if (layer1 > 8)
WiredHome 44:207594dece70 130 layer1 = 8;
WiredHome 44:207594dece70 131 if (layer2 > 8)
WiredHome 44:207594dece70 132 layer2 = 8;
WiredHome 44:207594dece70 133 WriteCommand(0x53, ((layer2 & 0xF) << 4) | (layer1 & 0xF));
WiredHome 44:207594dece70 134 return noerror;
WiredHome 44:207594dece70 135 }
WiredHome 44:207594dece70 136
WiredHome 44:207594dece70 137
WiredHome 53:86d24b9480b9 138 RetCode_t RA8875::SetBackgroundTransparencyColor(color_t color)
WiredHome 53:86d24b9480b9 139 {
WiredHome 53:86d24b9480b9 140 WriteCommand(0x67, (color >> 11) & 0x1F);
WiredHome 53:86d24b9480b9 141 WriteCommand(0x68, (color >> 5) & 0x3F);
WiredHome 53:86d24b9480b9 142 WriteCommand(0x69, (color & 0x1F));
WiredHome 53:86d24b9480b9 143 return noerror;
WiredHome 53:86d24b9480b9 144 }
WiredHome 53:86d24b9480b9 145
WiredHome 73:f22a18707b5e 146 color_t RA8875::GetBackgroundTransparencyColor(void)
WiredHome 73:f22a18707b5e 147 {
WiredHome 73:f22a18707b5e 148 RGBQUAD q;
WiredHome 73:f22a18707b5e 149 q.rgbRed = ReadCommand(0x67);
WiredHome 73:f22a18707b5e 150 q.rgbGreen = ReadCommand(0x68);
WiredHome 73:f22a18707b5e 151 q.rgbBlue = ReadCommand(0x69);
WiredHome 73:f22a18707b5e 152 return RGBQuadToRGB16(&q, 0);
WiredHome 73:f22a18707b5e 153 }
WiredHome 73:f22a18707b5e 154
hexley 54:e117ad10fba6 155 // ### Touch Panel support code additions begin here
hexley 54:e117ad10fba6 156
hexley 54:e117ad10fba6 157 RetCode_t RA8875::TouchPanelInit(void)
WiredHome 73:f22a18707b5e 158 {
hexley 54:e117ad10fba6 159 //TPCR0: Set enable bit, default sample time, wakeup, and ADC clock
hexley 54:e117ad10fba6 160 WriteCommand(TPCR0, TP_ENABLE | TP_ADC_SAMPLE_DEFAULT_CLKS | TP_ADC_CLKDIV_DEFAULT);
hexley 54:e117ad10fba6 161 // TPCR1: Set auto/manual, Ref voltage, debounce, manual mode params
WiredHome 73:f22a18707b5e 162 WriteCommand(TPCR1, TP_MODE_DEFAULT | TP_DEBOUNCE_DEFAULT);
hexley 54:e117ad10fba6 163 WriteCommand(INTC1, ReadCommand(INTC1) | RA8875_INT_TP); // reg INTC1: Enable Touch Panel Interrupts (D2 = 1)
hexley 54:e117ad10fba6 164 WriteCommand(INTC2, RA8875_INT_TP); // reg INTC2: Clear any TP interrupt flag
hexley 54:e117ad10fba6 165 return noerror;
hexley 54:e117ad10fba6 166 }
hexley 54:e117ad10fba6 167
hexley 54:e117ad10fba6 168 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 169 {
hexley 54:e117ad10fba6 170 // Parameter bounds check
hexley 54:e117ad10fba6 171 if( \
WiredHome 73:f22a18707b5e 172 !(bTpEnable == TP_ENABLE || bTpEnable == TP_ENABLE) || \
WiredHome 73:f22a18707b5e 173 !(bTpAutoManual == TP_MODE_AUTO || bTpAutoManual == TP_MODE_MANUAL) || \
WiredHome 73:f22a18707b5e 174 !(bTpDebounce == TP_DEBOUNCE_OFF || bTpDebounce == TP_DEBOUNCE_ON) || \
WiredHome 73:f22a18707b5e 175 !(bTpManualMode <= TP_MANUAL_LATCH_Y) || \
WiredHome 73:f22a18707b5e 176 !(bTpAdcClkDiv <= TP_ADC_CLKDIV_128) || \
WiredHome 73:f22a18707b5e 177 !(bTpAdcSampleTime <= TP_ADC_SAMPLE_65536_CLKS) \
WiredHome 73:f22a18707b5e 178 ) return bad_parameter;
hexley 54:e117ad10fba6 179 // Construct the config byte for TPCR0 and write them
hexley 54:e117ad10fba6 180 WriteCommand(TPCR0, bTpEnable | bTpAdcClkDiv | bTpAdcSampleTime); // Note: Wakeup is never enabled
hexley 54:e117ad10fba6 181 // Construct the config byte for TPCR1 and write them
hexley 54:e117ad10fba6 182 WriteCommand(TPCR1, bTpManualMode | bTpDebounce | bTpManualMode); // Note: Always uses internal Vref.
hexley 54:e117ad10fba6 183 // Set up the interrupt flag and enable bits
hexley 54:e117ad10fba6 184 WriteCommand(INTC1, ReadCommand(INTC1) | RA8875_INT_TP); // reg INTC1: Enable Touch Panel Interrupts (D2 = 1)
hexley 54:e117ad10fba6 185 WriteCommand(INTC2, RA8875_INT_TP); // reg INTC2: Clear any TP interrupt flag
WiredHome 73:f22a18707b5e 186 return noerror;
hexley 54:e117ad10fba6 187 }
hexley 54:e117ad10fba6 188
hexley 54:e117ad10fba6 189 unsigned char RA8875::TouchPanelRead(loc_t *x, loc_t *y)
hexley 54:e117ad10fba6 190 {
hexley 54:e117ad10fba6 191 unsigned char touchready;
hexley 54:e117ad10fba6 192 static int xbuf[TPBUFSIZE], ybuf[TPBUFSIZE], sample = 0;
hexley 54:e117ad10fba6 193 int i, j, temp;
hexley 54:e117ad10fba6 194
WiredHome 73:f22a18707b5e 195 if( (ReadCommand(INTC2) & RA8875_INT_TP) ) { // Test for TP Interrupt pending in register INTC2
hexley 54:e117ad10fba6 196 // Get the next data samples
hexley 54:e117ad10fba6 197 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 198 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 199 // Check for a complete set
hexley 54:e117ad10fba6 200 if(++sample == TPBUFSIZE) {
WiredHome 73:f22a18707b5e 201 // Buffers are full, so process them using Finn's method described in Analog Dialogue No. 44, Feb 2010
WiredHome 73:f22a18707b5e 202 // This requires sorting the samples in order of size, then discarding the top 25% and
WiredHome 73:f22a18707b5e 203 // bottom 25% as noise spikes. Finally, the middle 50% of the values are averaged to
WiredHome 73:f22a18707b5e 204 // reduce Gaussian noise.
WiredHome 73:f22a18707b5e 205
WiredHome 73:f22a18707b5e 206 // Sort the Y buffer using an Insertion Sort
hexley 54:e117ad10fba6 207 for(i = 1; i <= TPBUFSIZE; i++) {
hexley 54:e117ad10fba6 208 temp = ybuf[i];
hexley 54:e117ad10fba6 209 j = i;
hexley 54:e117ad10fba6 210 while( j && (ybuf[j-1] > temp) ) {
hexley 54:e117ad10fba6 211 ybuf[j] = ybuf[j-1];
WiredHome 73:f22a18707b5e 212 j = j-1;
hexley 54:e117ad10fba6 213 }
WiredHome 73:f22a18707b5e 214 ybuf[j] = temp;
hexley 54:e117ad10fba6 215 } // End of Y sort
hexley 54:e117ad10fba6 216 // Sort the X buffer the same way
hexley 54:e117ad10fba6 217 for(i = 1; i <= TPBUFSIZE; i++) {
hexley 54:e117ad10fba6 218 temp = xbuf[i];
hexley 54:e117ad10fba6 219 j = i;
hexley 54:e117ad10fba6 220 while( j && (xbuf[j-1] > temp) ) {
hexley 54:e117ad10fba6 221 xbuf[j] = xbuf[j-1];
WiredHome 73:f22a18707b5e 222 j = j-1;
hexley 54:e117ad10fba6 223 }
WiredHome 73:f22a18707b5e 224 xbuf[j] = temp;
hexley 54:e117ad10fba6 225 } // End of X sort
hexley 54:e117ad10fba6 226 // Average the middle half of the Y values and report them
hexley 54:e117ad10fba6 227 j = 0;
hexley 54:e117ad10fba6 228 for(i = (TPBUFSIZE/4) - 1; i < TPBUFSIZE - TPBUFSIZE/4; i++ ) {
WiredHome 73:f22a18707b5e 229 j += ybuf[i];
hexley 54:e117ad10fba6 230 }
hexley 54:e117ad10fba6 231 *y = j * (float)2/TPBUFSIZE; // This is the average
hexley 54:e117ad10fba6 232 // Average the middle half of the X values and report them
hexley 54:e117ad10fba6 233 j = 0;
hexley 54:e117ad10fba6 234 for(i = (TPBUFSIZE/4) - 1; i < TPBUFSIZE - TPBUFSIZE/4; i++ ) {
WiredHome 73:f22a18707b5e 235 j += xbuf[i];
hexley 54:e117ad10fba6 236 }
WiredHome 73:f22a18707b5e 237 *x = j * (float)2/TPBUFSIZE; // This is the average
WiredHome 73:f22a18707b5e 238 // Tidy up and return
hexley 54:e117ad10fba6 239 touchready = 1;
hexley 54:e117ad10fba6 240 sample = 0; // Ready to start on the next set of data samples
WiredHome 73:f22a18707b5e 241 } else {
hexley 54:e117ad10fba6 242 // Buffer not yet full, so do not return any results yet
hexley 54:e117ad10fba6 243 touchready = 0;
hexley 54:e117ad10fba6 244 }
WiredHome 73:f22a18707b5e 245 WriteCommand(INTC2, RA8875_INT_TP); // reg INTC2: Clear that TP interrupt flag
hexley 54:e117ad10fba6 246 } // End of initial if -- data has been read and processed
hexley 54:e117ad10fba6 247 else
hexley 54:e117ad10fba6 248 touchready = 0; // Touch Panel "Int" was not set
hexley 54:e117ad10fba6 249 return touchready;
hexley 54:e117ad10fba6 250 }
hexley 54:e117ad10fba6 251
hexley 54:e117ad10fba6 252 unsigned char RA8875::TouchPanelReadRaw(loc_t *x, loc_t *y)
hexley 54:e117ad10fba6 253 {
hexley 54:e117ad10fba6 254 unsigned char touchready;
hexley 54:e117ad10fba6 255
WiredHome 73:f22a18707b5e 256 if( (ReadCommand(INTC2) & RA8875_INT_TP) ) { // Test for TP Interrupt pending in register INTC2
hexley 54:e117ad10fba6 257 *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 258 *x = ReadCommand(TPXH) << 2 | ( (ReadCommand(TPXYL) & 0x3) ); // D[9:2] from reg TPXH, D[1:0] from reg TPXYL[1:0]
WiredHome 73:f22a18707b5e 259 WriteCommand(INTC2, RA8875_INT_TP); // reg INTC2: Clear that TP interrupt flag
hexley 54:e117ad10fba6 260 touchready = 1;
WiredHome 73:f22a18707b5e 261 } else
WiredHome 73:f22a18707b5e 262 touchready = 0;
hexley 54:e117ad10fba6 263 return touchready;
hexley 54:e117ad10fba6 264 }
hexley 54:e117ad10fba6 265 // #### end of touch panel code additions
WiredHome 53:86d24b9480b9 266
WiredHome 71:dcac8efd842d 267
WiredHome 73:f22a18707b5e 268 RetCode_t RA8875::KeypadInit(bool scanEnable, bool longDetect, uint8_t sampleTime, uint8_t scanFrequency,
WiredHome 73:f22a18707b5e 269 uint8_t longTimeAdjustment, bool interruptEnable, bool wakeupEnable)
WiredHome 71:dcac8efd842d 270 {
WiredHome 71:dcac8efd842d 271 uint8_t value = 0;
WiredHome 73:f22a18707b5e 272
WiredHome 71:dcac8efd842d 273 if (sampleTime > 3 || scanFrequency > 7 || longTimeAdjustment > 3)
WiredHome 71:dcac8efd842d 274 return bad_parameter;
WiredHome 71:dcac8efd842d 275 value |= (scanEnable) ? 0x80 : 0x00;
WiredHome 71:dcac8efd842d 276 value |= (longDetect) ? 0x40 : 0x00;
WiredHome 71:dcac8efd842d 277 value |= (sampleTime & 0x03) << 4;
WiredHome 71:dcac8efd842d 278 value |= (scanFrequency & 0x07);
WiredHome 71:dcac8efd842d 279 WriteCommand(0xC0, value); // Enable Key Scan (and ignore possibility of an error)
WiredHome 73:f22a18707b5e 280
WiredHome 71:dcac8efd842d 281 value = 0;
WiredHome 71:dcac8efd842d 282 value |= (wakeupEnable) ? 0x80 : 0x00;
WiredHome 71:dcac8efd842d 283 value |= (longTimeAdjustment & 0x03) << 2;
WiredHome 71:dcac8efd842d 284 WriteCommand(0xC1, value); // (and ignore possibility of an error)
WiredHome 73:f22a18707b5e 285
WiredHome 71:dcac8efd842d 286 value = ReadCommand(0xF0); // (and ignore possibility of an error)
WiredHome 71:dcac8efd842d 287 value &= ~0x10;
WiredHome 71:dcac8efd842d 288 value |= (interruptEnable) ? 0x10 : 0x00;
WiredHome 71:dcac8efd842d 289 return WriteCommand(0xF0, value);
WiredHome 71:dcac8efd842d 290 }
WiredHome 71:dcac8efd842d 291
WiredHome 71:dcac8efd842d 292 bool RA8875::_kbhit(void)
WiredHome 71:dcac8efd842d 293 {
WiredHome 71:dcac8efd842d 294 return (ReadCommand(0xF1) & 0x10); // check KS status - true if kbhit
WiredHome 71:dcac8efd842d 295 }
WiredHome 71:dcac8efd842d 296
WiredHome 71:dcac8efd842d 297 uint8_t RA8875::_getch(void)
WiredHome 71:dcac8efd842d 298 {
WiredHome 71:dcac8efd842d 299 while (!_kbhit()) {
WiredHome 71:dcac8efd842d 300 wait_us(POLLWAITuSec);
WiredHome 71:dcac8efd842d 301 COUNTIDLETIME(POLLWAITuSec);
WiredHome 71:dcac8efd842d 302 }
WiredHome 71:dcac8efd842d 303
WiredHome 71:dcac8efd842d 304 // read the key press number
WiredHome 71:dcac8efd842d 305 uint8_t keyNumReg = ReadCommand(0xC1) & 0x03;
WiredHome 71:dcac8efd842d 306 // read the key code
WiredHome 71:dcac8efd842d 307 uint8_t keyCode = ReadCommand(0xC2 + keyNumReg);
WiredHome 71:dcac8efd842d 308 // Clear KS status
WiredHome 71:dcac8efd842d 309 WriteCommand(0xF1, 0x10);
WiredHome 71:dcac8efd842d 310 return keyCode;
WiredHome 71:dcac8efd842d 311 }
WiredHome 71:dcac8efd842d 312
WiredHome 19:3f82c1161fd2 313 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 314 void RA8875::ClearPerformance()
WiredHome 19:3f82c1161fd2 315 {
WiredHome 19:3f82c1161fd2 316 for (int i=0; i<METRICCOUNT; i++)
WiredHome 19:3f82c1161fd2 317 metrics[i] = 0;
WiredHome 66:468a11f05580 318 idlecounter = 0;
WiredHome 19:3f82c1161fd2 319 }
WiredHome 19:3f82c1161fd2 320
WiredHome 19:3f82c1161fd2 321 void RA8875::RegisterPerformance(method_e method)
WiredHome 19:3f82c1161fd2 322 {
WiredHome 19:3f82c1161fd2 323 unsigned long elapsed = performance.read_us();
WiredHome 73:f22a18707b5e 324
WiredHome 19:3f82c1161fd2 325 if (method < METRICCOUNT && elapsed > metrics[method])
WiredHome 19:3f82c1161fd2 326 metrics[method] = elapsed;
WiredHome 19:3f82c1161fd2 327 }
WiredHome 19:3f82c1161fd2 328
WiredHome 66:468a11f05580 329 void RA8875::CountIdleTime(uint32_t t)
WiredHome 66:468a11f05580 330 {
WiredHome 66:468a11f05580 331 idlecounter += t;
WiredHome 66:468a11f05580 332 }
WiredHome 44:207594dece70 333
WiredHome 41:2956a0a221e5 334 void RA8875::ReportPerformance(Serial & pc)
WiredHome 19:3f82c1161fd2 335 {
WiredHome 41:2956a0a221e5 336 pc.printf("\r\nPerformance Metrics\r\n");
WiredHome 19:3f82c1161fd2 337 for (int i=0; i<METRICCOUNT; i++) {
WiredHome 41:2956a0a221e5 338 pc.printf("%10d uS %s\r\n", metrics[i], metricsName[i]);
WiredHome 66:468a11f05580 339 }
WiredHome 68:ab08efabfc88 340 pc.printf("%10d uS Idle time polling display for ready.\r\n", idlecounter);
WiredHome 19:3f82c1161fd2 341 }
WiredHome 19:3f82c1161fd2 342 #endif
WiredHome 19:3f82c1161fd2 343
WiredHome 44:207594dece70 344
WiredHome 38:38d503b4fad6 345 RetCode_t RA8875::WriteCommandW(uint8_t command, uint16_t data)
WiredHome 38:38d503b4fad6 346 {
WiredHome 73:f22a18707b5e 347 #if 1
WiredHome 38:38d503b4fad6 348 WriteCommand(command, data & 0xFF);
WiredHome 38:38d503b4fad6 349 WriteCommand(command+1, data >> 8);
WiredHome 73:f22a18707b5e 350 #else
WiredHome 41:2956a0a221e5 351 // This should be a little faster, but doesn't work...
WiredHome 38:38d503b4fad6 352 INFO("WriteCommandW(%02X, %04X)", command, data);
WiredHome 38:38d503b4fad6 353 select(true);
WiredHome 38:38d503b4fad6 354 spiwrite(0x80);
WiredHome 38:38d503b4fad6 355 spiwrite(command);
WiredHome 41:2956a0a221e5 356 //spiwrite(0x00); // dummy
WiredHome 38:38d503b4fad6 357 spiwrite(data & 0xFF);
WiredHome 38:38d503b4fad6 358 spiwrite(data >> 8);
WiredHome 38:38d503b4fad6 359 select(false);
WiredHome 73:f22a18707b5e 360 #endif
WiredHome 38:38d503b4fad6 361 return noerror;
WiredHome 38:38d503b4fad6 362 }
WiredHome 38:38d503b4fad6 363
WiredHome 44:207594dece70 364
WiredHome 19:3f82c1161fd2 365 RetCode_t RA8875::WriteCommand(unsigned char command, unsigned int data)
WiredHome 19:3f82c1161fd2 366 {
WiredHome 19:3f82c1161fd2 367 select(true);
WiredHome 41:2956a0a221e5 368 spiwrite(0x80); // cmd: write command
WiredHome 19:3f82c1161fd2 369 spiwrite(command);
WiredHome 19:3f82c1161fd2 370 if (data <= 0xFF) { // only if in the valid range
WiredHome 19:3f82c1161fd2 371 spiwrite(0x00);
WiredHome 19:3f82c1161fd2 372 spiwrite(data);
WiredHome 19:3f82c1161fd2 373 }
WiredHome 19:3f82c1161fd2 374 select(false);
WiredHome 19:3f82c1161fd2 375 return noerror;
WiredHome 19:3f82c1161fd2 376 }
WiredHome 19:3f82c1161fd2 377
WiredHome 44:207594dece70 378
WiredHome 38:38d503b4fad6 379 RetCode_t RA8875::WriteDataW(uint16_t data)
WiredHome 38:38d503b4fad6 380 {
WiredHome 38:38d503b4fad6 381 select(true);
WiredHome 41:2956a0a221e5 382 spiwrite(0x00); // cmd: write data
WiredHome 38:38d503b4fad6 383 spiwrite(data & 0xFF);
WiredHome 38:38d503b4fad6 384 spiwrite(data >> 8);
WiredHome 38:38d503b4fad6 385 select(false);
WiredHome 38:38d503b4fad6 386 return noerror;
WiredHome 38:38d503b4fad6 387 }
WiredHome 38:38d503b4fad6 388
WiredHome 44:207594dece70 389
WiredHome 19:3f82c1161fd2 390 RetCode_t RA8875::WriteData(unsigned char data)
WiredHome 19:3f82c1161fd2 391 {
WiredHome 19:3f82c1161fd2 392 select(true);
WiredHome 19:3f82c1161fd2 393 spiwrite(0x00);
WiredHome 19:3f82c1161fd2 394 spiwrite(data);
WiredHome 19:3f82c1161fd2 395 select(false);
WiredHome 19:3f82c1161fd2 396 return noerror;
WiredHome 19:3f82c1161fd2 397 }
WiredHome 19:3f82c1161fd2 398
WiredHome 44:207594dece70 399
WiredHome 19:3f82c1161fd2 400 unsigned char RA8875::ReadCommand(unsigned char command)
WiredHome 19:3f82c1161fd2 401 {
WiredHome 19:3f82c1161fd2 402 WriteCommand(command);
WiredHome 19:3f82c1161fd2 403 return ReadData();
WiredHome 19:3f82c1161fd2 404 }
WiredHome 19:3f82c1161fd2 405
WiredHome 44:207594dece70 406
WiredHome 19:3f82c1161fd2 407 unsigned char RA8875::ReadData(void)
WiredHome 19:3f82c1161fd2 408 {
WiredHome 19:3f82c1161fd2 409 unsigned char data;
WiredHome 73:f22a18707b5e 410
WiredHome 19:3f82c1161fd2 411 select(true);
WiredHome 19:3f82c1161fd2 412 spiwrite(0x40);
WiredHome 19:3f82c1161fd2 413 data = spiread();
WiredHome 19:3f82c1161fd2 414 select(false);
WiredHome 19:3f82c1161fd2 415 return data;
WiredHome 19:3f82c1161fd2 416 }
WiredHome 19:3f82c1161fd2 417
WiredHome 44:207594dece70 418
WiredHome 41:2956a0a221e5 419 uint16_t RA8875::ReadDataW(void)
WiredHome 41:2956a0a221e5 420 {
WiredHome 41:2956a0a221e5 421 uint16_t data;
WiredHome 73:f22a18707b5e 422
WiredHome 41:2956a0a221e5 423 select(true);
WiredHome 41:2956a0a221e5 424 spiwrite(0x40);
WiredHome 41:2956a0a221e5 425 data = spiread();
WiredHome 41:2956a0a221e5 426 data |= (spiread() << 8);
WiredHome 41:2956a0a221e5 427 select(false);
WiredHome 41:2956a0a221e5 428 return data;
WiredHome 41:2956a0a221e5 429 }
WiredHome 41:2956a0a221e5 430
WiredHome 44:207594dece70 431
WiredHome 19:3f82c1161fd2 432 unsigned char RA8875::ReadStatus(void)
WiredHome 19:3f82c1161fd2 433 {
WiredHome 19:3f82c1161fd2 434 unsigned char data;
WiredHome 73:f22a18707b5e 435
WiredHome 19:3f82c1161fd2 436 select(true);
WiredHome 66:468a11f05580 437 spiwrite(0xC0); // These two bits are for the special "Status Read" [STSR]
WiredHome 19:3f82c1161fd2 438 data = spiread();
WiredHome 19:3f82c1161fd2 439 select(false);
WiredHome 19:3f82c1161fd2 440 return data;
WiredHome 19:3f82c1161fd2 441 }
WiredHome 19:3f82c1161fd2 442
WiredHome 66:468a11f05580 443 /// @todo add a timeout and return false, but how long
WiredHome 66:468a11f05580 444 /// to wait since some operations can be very long.
WiredHome 66:468a11f05580 445 bool RA8875::_WaitWhileBusy(uint8_t mask)
WiredHome 66:468a11f05580 446 {
WiredHome 66:468a11f05580 447 int i = 20000/POLLWAITuSec; // 20 msec max
WiredHome 66:468a11f05580 448
WiredHome 67:9f834f0ff97d 449 while (i-- && ReadStatus() & mask) {
WiredHome 66:468a11f05580 450 wait_us(POLLWAITuSec);
WiredHome 68:ab08efabfc88 451 COUNTIDLETIME(POLLWAITuSec);
WiredHome 67:9f834f0ff97d 452 }
WiredHome 66:468a11f05580 453 if (i)
WiredHome 66:468a11f05580 454 return true;
WiredHome 66:468a11f05580 455 else
WiredHome 66:468a11f05580 456 return false;
WiredHome 66:468a11f05580 457 }
WiredHome 66:468a11f05580 458
WiredHome 66:468a11f05580 459 /// @todo add a timeout and return false, but how long
WiredHome 66:468a11f05580 460 /// to wait since some operations can be very long.
WiredHome 66:468a11f05580 461 bool RA8875::_WaitWhileReg(uint8_t reg, uint8_t mask)
WiredHome 66:468a11f05580 462 {
WiredHome 66:468a11f05580 463 int i = 20000/POLLWAITuSec; // 20 msec max
WiredHome 66:468a11f05580 464
WiredHome 67:9f834f0ff97d 465 while (i-- && ReadCommand(reg) & mask) {
WiredHome 66:468a11f05580 466 wait_us(POLLWAITuSec);
WiredHome 68:ab08efabfc88 467 COUNTIDLETIME(POLLWAITuSec);
WiredHome 67:9f834f0ff97d 468 }
WiredHome 66:468a11f05580 469 if (i)
WiredHome 66:468a11f05580 470 return true;
WiredHome 66:468a11f05580 471 else
WiredHome 66:468a11f05580 472 return false;
WiredHome 66:468a11f05580 473 }
WiredHome 66:468a11f05580 474
WiredHome 66:468a11f05580 475
WiredHome 44:207594dece70 476
WiredHome 37:f19b7e7449dc 477 dim_t RA8875::fontwidth(void)
WiredHome 19:3f82c1161fd2 478 {
WiredHome 19:3f82c1161fd2 479 if (font == NULL)
WiredHome 55:dfbabef7003e 480 return (((ReadCommand(0x22) >> 2) & 0x3) + 1) * 8;
WiredHome 19:3f82c1161fd2 481 else
WiredHome 29:422616aa04bd 482 return font[1];
WiredHome 19:3f82c1161fd2 483 }
WiredHome 19:3f82c1161fd2 484
WiredHome 44:207594dece70 485
WiredHome 37:f19b7e7449dc 486 dim_t RA8875::fontheight(void)
WiredHome 19:3f82c1161fd2 487 {
WiredHome 19:3f82c1161fd2 488 if (font == NULL)
WiredHome 23:a50ded45dbaf 489 return (((ReadCommand(0x22) >> 0) & 0x3) + 1) * 16;
WiredHome 19:3f82c1161fd2 490 else
WiredHome 29:422616aa04bd 491 return font[2];
WiredHome 19:3f82c1161fd2 492 }
WiredHome 19:3f82c1161fd2 493
WiredHome 44:207594dece70 494
WiredHome 37:f19b7e7449dc 495 RetCode_t RA8875::locate(textloc_t column, textloc_t row)
WiredHome 19:3f82c1161fd2 496 {
WiredHome 32:0e4f2ae512e2 497 return SetTextCursor(column * fontwidth(), row * fontheight());
WiredHome 19:3f82c1161fd2 498 }
WiredHome 19:3f82c1161fd2 499
WiredHome 44:207594dece70 500
WiredHome 19:3f82c1161fd2 501 int RA8875::columns(void)
WiredHome 19:3f82c1161fd2 502 {
WiredHome 19:3f82c1161fd2 503 return width() / fontwidth();
WiredHome 19:3f82c1161fd2 504 }
WiredHome 19:3f82c1161fd2 505
WiredHome 44:207594dece70 506
WiredHome 19:3f82c1161fd2 507 int RA8875::rows(void)
WiredHome 19:3f82c1161fd2 508 {
WiredHome 19:3f82c1161fd2 509 return height() / fontheight();
WiredHome 19:3f82c1161fd2 510 }
WiredHome 19:3f82c1161fd2 511
WiredHome 44:207594dece70 512
WiredHome 38:38d503b4fad6 513 dim_t RA8875::width(void)
WiredHome 19:3f82c1161fd2 514 {
WiredHome 29:422616aa04bd 515 return (ReadCommand(0x14) + 1) * 8;
WiredHome 19:3f82c1161fd2 516 }
WiredHome 19:3f82c1161fd2 517
WiredHome 44:207594dece70 518
WiredHome 38:38d503b4fad6 519 dim_t RA8875::height(void)
WiredHome 19:3f82c1161fd2 520 {
WiredHome 29:422616aa04bd 521 return (ReadCommand(0x19) | (ReadCommand(0x1A) << 8)) + 1;
WiredHome 19:3f82c1161fd2 522 }
WiredHome 19:3f82c1161fd2 523
WiredHome 44:207594dece70 524
WiredHome 43:3becae133285 525 dim_t RA8875::color_bpp(void)
WiredHome 43:3becae133285 526 {
WiredHome 43:3becae133285 527 if ((ReadCommand(0x10) & 0x0C) == 0x04)
WiredHome 43:3becae133285 528 return 16;
WiredHome 43:3becae133285 529 else
WiredHome 43:3becae133285 530 return 8;
WiredHome 43:3becae133285 531 }
WiredHome 43:3becae133285 532
WiredHome 44:207594dece70 533
WiredHome 37:f19b7e7449dc 534 RetCode_t RA8875::SetTextCursor(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 535 {
WiredHome 73:f22a18707b5e 536 cursor_x = x;
WiredHome 73:f22a18707b5e 537 cursor_y = y; // for non-internal fonts
WiredHome 38:38d503b4fad6 538 WriteCommandW(0x2A, x);
WiredHome 38:38d503b4fad6 539 WriteCommandW(0x2C, y);
WiredHome 19:3f82c1161fd2 540 return noerror;
WiredHome 19:3f82c1161fd2 541 }
WiredHome 19:3f82c1161fd2 542
WiredHome 44:207594dece70 543
WiredHome 37:f19b7e7449dc 544 loc_t RA8875::GetTextCursor_Y(void)
WiredHome 29:422616aa04bd 545 {
WiredHome 29:422616aa04bd 546 if (font == NULL)
WiredHome 29:422616aa04bd 547 return ReadCommand(0x2C) | (ReadCommand(0x2D) << 8);
WiredHome 29:422616aa04bd 548 else
WiredHome 29:422616aa04bd 549 return cursor_y;
WiredHome 29:422616aa04bd 550 }
WiredHome 29:422616aa04bd 551
WiredHome 44:207594dece70 552
WiredHome 37:f19b7e7449dc 553 loc_t RA8875::GetTextCursor_X(void)
WiredHome 29:422616aa04bd 554 {
WiredHome 29:422616aa04bd 555 if (font == NULL)
WiredHome 29:422616aa04bd 556 return ReadCommand(0x2A) | (ReadCommand(0x2B) << 8);
WiredHome 29:422616aa04bd 557 else
WiredHome 29:422616aa04bd 558 return cursor_x;
WiredHome 29:422616aa04bd 559 }
WiredHome 29:422616aa04bd 560
WiredHome 44:207594dece70 561
WiredHome 24:8ca861acf12d 562 RetCode_t RA8875::SetTextCursorControl(cursor_t cursor, bool blink)
WiredHome 23:a50ded45dbaf 563 {
WiredHome 23:a50ded45dbaf 564 unsigned char mwcr0 = ReadCommand(0x40) & 0x0F; // retain direction, auto-increase
WiredHome 43:3becae133285 565 unsigned char mwcr1 = ReadCommand(0x41) & 0x01; // retain currently selected layer
WiredHome 24:8ca861acf12d 566 unsigned char horz = 0;
WiredHome 24:8ca861acf12d 567 unsigned char vert = 0;
WiredHome 73:f22a18707b5e 568
WiredHome 24:8ca861acf12d 569 mwcr0 |= 0x80; // text mode
WiredHome 24:8ca861acf12d 570 if (cursor != NOCURSOR)
WiredHome 24:8ca861acf12d 571 mwcr0 |= 0x40; // visible
WiredHome 23:a50ded45dbaf 572 if (blink)
WiredHome 24:8ca861acf12d 573 mwcr0 |= 0x20; // blink
WiredHome 23:a50ded45dbaf 574 WriteCommand(0x40, mwcr0); // configure the cursor
WiredHome 43:3becae133285 575 WriteCommand(0x41, mwcr1); // close the graphics cursor
WiredHome 24:8ca861acf12d 576 WriteCommand(0x44, 0x1f); // The cursor flashing cycle
WiredHome 24:8ca861acf12d 577 switch (cursor) {
WiredHome 24:8ca861acf12d 578 case IBEAM:
WiredHome 24:8ca861acf12d 579 horz = 0x01;
WiredHome 24:8ca861acf12d 580 vert = 0x1F;
WiredHome 24:8ca861acf12d 581 break;
WiredHome 24:8ca861acf12d 582 case UNDER:
WiredHome 24:8ca861acf12d 583 horz = 0x07;
WiredHome 24:8ca861acf12d 584 vert = 0x01;
WiredHome 24:8ca861acf12d 585 break;
WiredHome 24:8ca861acf12d 586 case BLOCK:
WiredHome 24:8ca861acf12d 587 horz = 0x07;
WiredHome 24:8ca861acf12d 588 vert = 0x1F;
WiredHome 24:8ca861acf12d 589 break;
WiredHome 24:8ca861acf12d 590 case NOCURSOR:
WiredHome 24:8ca861acf12d 591 default:
WiredHome 24:8ca861acf12d 592 break;
WiredHome 24:8ca861acf12d 593 }
WiredHome 24:8ca861acf12d 594 WriteCommand(0x4e, horz); // The cursor size horz
WiredHome 24:8ca861acf12d 595 WriteCommand(0x4f, vert); // The cursor size vert
WiredHome 23:a50ded45dbaf 596 return noerror;
WiredHome 23:a50ded45dbaf 597 }
WiredHome 23:a50ded45dbaf 598
WiredHome 44:207594dece70 599
WiredHome 19:3f82c1161fd2 600 RetCode_t RA8875::SetTextFont(RA8875::font_t font)
WiredHome 19:3f82c1161fd2 601 {
WiredHome 19:3f82c1161fd2 602 if (/*font >= RA8875::ISO8859_1 && */ font <= RA8875::ISO8859_4) {
WiredHome 19:3f82c1161fd2 603 WriteCommand(0x21, (unsigned int)(font));
WiredHome 19:3f82c1161fd2 604 return noerror;
WiredHome 19:3f82c1161fd2 605 } else {
WiredHome 19:3f82c1161fd2 606 return bad_parameter;
WiredHome 19:3f82c1161fd2 607 }
WiredHome 19:3f82c1161fd2 608 }
WiredHome 19:3f82c1161fd2 609
WiredHome 44:207594dece70 610
WiredHome 19:3f82c1161fd2 611 RetCode_t RA8875::SetTextFontControl(fill_t fillit,
WiredHome 73:f22a18707b5e 612 RA8875::font_angle_t angle,
WiredHome 73:f22a18707b5e 613 RA8875::HorizontalScale hScale,
WiredHome 73:f22a18707b5e 614 RA8875::VerticalScale vScale,
WiredHome 73:f22a18707b5e 615 RA8875::alignment_t alignment)
WiredHome 19:3f82c1161fd2 616 {
WiredHome 73:f22a18707b5e 617 if (hScale >= 1 && hScale <= 4 &&
WiredHome 73:f22a18707b5e 618 vScale >= 1 && vScale <= 4) {
WiredHome 19:3f82c1161fd2 619 unsigned char x = 0;
WiredHome 73:f22a18707b5e 620
WiredHome 19:3f82c1161fd2 621 if (alignment == align_full)
WiredHome 19:3f82c1161fd2 622 x |= 0x80;
WiredHome 19:3f82c1161fd2 623 if (fillit == NOFILL)
WiredHome 19:3f82c1161fd2 624 x |= 0x40;
WiredHome 19:3f82c1161fd2 625 if (angle == rotated)
WiredHome 19:3f82c1161fd2 626 x |= 0x10;
WiredHome 19:3f82c1161fd2 627 x |= ((hScale - 1) << 2);
WiredHome 19:3f82c1161fd2 628 x |= ((vScale - 1) << 0);
WiredHome 19:3f82c1161fd2 629 WriteCommand(0x22, x);
WiredHome 19:3f82c1161fd2 630 return noerror;
WiredHome 19:3f82c1161fd2 631 } else {
WiredHome 19:3f82c1161fd2 632 return bad_parameter;
WiredHome 19:3f82c1161fd2 633 }
WiredHome 19:3f82c1161fd2 634 }
WiredHome 19:3f82c1161fd2 635
WiredHome 44:207594dece70 636
WiredHome 19:3f82c1161fd2 637 RetCode_t RA8875::SetTextFontSize(RA8875::HorizontalScale hScale, RA8875::VerticalScale vScale)
WiredHome 19:3f82c1161fd2 638 {
WiredHome 19:3f82c1161fd2 639 unsigned char reg = ReadCommand(0x22);
WiredHome 73:f22a18707b5e 640
WiredHome 40:04aa280dfa39 641 if (vScale == -1)
WiredHome 40:04aa280dfa39 642 vScale = hScale;
WiredHome 19:3f82c1161fd2 643 if (hScale >= 1 && hScale <= 4 && vScale >= 1 && vScale <= 4) {
WiredHome 19:3f82c1161fd2 644 reg &= 0xF0; // keep the high nibble as is.
WiredHome 19:3f82c1161fd2 645 reg |= ((hScale - 1) << 2);
WiredHome 19:3f82c1161fd2 646 reg |= ((vScale - 1) << 0);
WiredHome 19:3f82c1161fd2 647 WriteCommand(0x22, reg);
WiredHome 19:3f82c1161fd2 648 return noerror;
WiredHome 19:3f82c1161fd2 649 } else {
WiredHome 19:3f82c1161fd2 650 return bad_parameter;
WiredHome 19:3f82c1161fd2 651 }
WiredHome 19:3f82c1161fd2 652 }
WiredHome 19:3f82c1161fd2 653
WiredHome 44:207594dece70 654
WiredHome 19:3f82c1161fd2 655 int RA8875::_putc(int c)
WiredHome 19:3f82c1161fd2 656 {
WiredHome 29:422616aa04bd 657 if (font == NULL) {
WiredHome 29:422616aa04bd 658 return _internal_putc(c);
WiredHome 29:422616aa04bd 659 } else {
WiredHome 29:422616aa04bd 660 return _external_putc(c);
WiredHome 29:422616aa04bd 661 }
WiredHome 29:422616aa04bd 662 }
WiredHome 29:422616aa04bd 663
WiredHome 44:207594dece70 664
WiredHome 29:422616aa04bd 665 int RA8875::_external_putc(int c)
WiredHome 29:422616aa04bd 666 {
WiredHome 19:3f82c1161fd2 667 if (c) {
WiredHome 19:3f82c1161fd2 668 if (c == '\r') {
WiredHome 29:422616aa04bd 669 cursor_x = 0;
WiredHome 29:422616aa04bd 670 } else if (c == '\n') {
WiredHome 29:422616aa04bd 671 cursor_y += font[2];
WiredHome 29:422616aa04bd 672 } else {
WiredHome 29:422616aa04bd 673 int advance = character(cursor_x, cursor_y, c); // advance tells us how many pixels we advanced
WiredHome 37:f19b7e7449dc 674 //INFO("x,y,advance %d,%d,%d", cursor_x, cursor_y, advance);
WiredHome 29:422616aa04bd 675 if (advance) {
WiredHome 29:422616aa04bd 676 cursor_x += advance;
WiredHome 29:422616aa04bd 677 if (cursor_x >= width()) {
WiredHome 29:422616aa04bd 678 cursor_x = 0;
WiredHome 29:422616aa04bd 679 cursor_y += font[2];
WiredHome 29:422616aa04bd 680 if (cursor_y >= height()) {
WiredHome 29:422616aa04bd 681 cursor_y = 0; // @todo Should it scroll?
WiredHome 29:422616aa04bd 682 }
WiredHome 29:422616aa04bd 683 }
WiredHome 29:422616aa04bd 684 }
WiredHome 29:422616aa04bd 685 }
WiredHome 29:422616aa04bd 686 }
WiredHome 29:422616aa04bd 687 return c;
WiredHome 29:422616aa04bd 688 }
WiredHome 29:422616aa04bd 689
WiredHome 44:207594dece70 690
WiredHome 29:422616aa04bd 691 int RA8875::_internal_putc(int c)
WiredHome 29:422616aa04bd 692 {
WiredHome 29:422616aa04bd 693 if (c) {
WiredHome 29:422616aa04bd 694 unsigned char mwcr0;
WiredHome 73:f22a18707b5e 695
WiredHome 29:422616aa04bd 696 mwcr0 = ReadCommand(0x40);
WiredHome 29:422616aa04bd 697 if ((mwcr0 & 0x80) == 0x00) {
WiredHome 29:422616aa04bd 698 WriteCommand(0x40, 0x80 | mwcr0); // Put in Text mode if not already
WiredHome 29:422616aa04bd 699 }
WiredHome 29:422616aa04bd 700 if (c == '\r') {
WiredHome 37:f19b7e7449dc 701 loc_t x;
WiredHome 19:3f82c1161fd2 702 x = ReadCommand(0x30) | (ReadCommand(0x31) << 8); // Left edge of active window
WiredHome 38:38d503b4fad6 703 WriteCommandW(0x2A, x);
WiredHome 19:3f82c1161fd2 704 } else if (c == '\n') {
WiredHome 37:f19b7e7449dc 705 loc_t y;
WiredHome 19:3f82c1161fd2 706 y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); // current y location
WiredHome 19:3f82c1161fd2 707 y += fontheight();
WiredHome 47:d96a09269f91 708 if (y >= height()) // @TODO after bottom of active window, then scroll window?
WiredHome 19:3f82c1161fd2 709 y = 0;
WiredHome 38:38d503b4fad6 710 WriteCommandW(0x2C, y);
WiredHome 19:3f82c1161fd2 711 } else {
WiredHome 29:422616aa04bd 712 WriteCommand(0x02); // RA8875 Internal Fonts
WiredHome 29:422616aa04bd 713 select(true);
WiredHome 29:422616aa04bd 714 WriteData(c);
WiredHome 66:468a11f05580 715 _WaitWhileBusy(0x80);
WiredHome 29:422616aa04bd 716 select(false);
WiredHome 19:3f82c1161fd2 717 }
WiredHome 19:3f82c1161fd2 718 }
WiredHome 19:3f82c1161fd2 719 return c;
WiredHome 19:3f82c1161fd2 720 }
WiredHome 19:3f82c1161fd2 721
WiredHome 44:207594dece70 722
WiredHome 32:0e4f2ae512e2 723 RetCode_t RA8875::_StartGraphicsStream(void)
WiredHome 32:0e4f2ae512e2 724 {
WiredHome 32:0e4f2ae512e2 725 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 32:0e4f2ae512e2 726 WriteCommand(0x02); // Prepare for streaming data
WiredHome 32:0e4f2ae512e2 727 return noerror;
WiredHome 32:0e4f2ae512e2 728 }
WiredHome 32:0e4f2ae512e2 729
WiredHome 44:207594dece70 730
WiredHome 32:0e4f2ae512e2 731 RetCode_t RA8875::_EndGraphicsStream(void)
WiredHome 32:0e4f2ae512e2 732 {
WiredHome 32:0e4f2ae512e2 733 return noerror;
WiredHome 32:0e4f2ae512e2 734 }
WiredHome 32:0e4f2ae512e2 735
WiredHome 44:207594dece70 736
WiredHome 55:dfbabef7003e 737 RetCode_t RA8875::_putp(color_t pixel)
WiredHome 32:0e4f2ae512e2 738 {
WiredHome 38:38d503b4fad6 739 WriteDataW((pixel>>8) | (pixel<<8));
WiredHome 73:f22a18707b5e 740 return noerror;
WiredHome 32:0e4f2ae512e2 741 }
WiredHome 29:422616aa04bd 742
WiredHome 44:207594dece70 743
WiredHome 37:f19b7e7449dc 744 void RA8875::puts(loc_t x, loc_t y, const char * string)
WiredHome 19:3f82c1161fd2 745 {
WiredHome 19:3f82c1161fd2 746 SetTextCursor(x,y);
WiredHome 19:3f82c1161fd2 747 puts(string);
WiredHome 19:3f82c1161fd2 748 }
WiredHome 19:3f82c1161fd2 749
WiredHome 44:207594dece70 750
WiredHome 19:3f82c1161fd2 751 void RA8875::puts(const char * string)
WiredHome 19:3f82c1161fd2 752 {
WiredHome 29:422616aa04bd 753 unsigned char mwcr0 = ReadCommand(0x40);
WiredHome 73:f22a18707b5e 754
WiredHome 37:f19b7e7449dc 755 if (font == NULL) {
WiredHome 37:f19b7e7449dc 756 if ((mwcr0 & 0x80) == 0x00)
WiredHome 37:f19b7e7449dc 757 WriteCommand(0x40,0x80); // Put in Text mode if not already
WiredHome 37:f19b7e7449dc 758 } else {
WiredHome 37:f19b7e7449dc 759 _StartGraphicsStream();
WiredHome 37:f19b7e7449dc 760 }
WiredHome 19:3f82c1161fd2 761 if (*string != '\0') {
WiredHome 73:f22a18707b5e 762 #if 1
WiredHome 29:422616aa04bd 763 while (*string) { // @TODO calling individual _putc is slower... optimizations?
WiredHome 19:3f82c1161fd2 764 _putc(*string++);
WiredHome 19:3f82c1161fd2 765 }
WiredHome 73:f22a18707b5e 766 #else
WiredHome 19:3f82c1161fd2 767 WriteCommand(0x02);
WiredHome 19:3f82c1161fd2 768 select(true);
WiredHome 19:3f82c1161fd2 769 while (*string != '\0') {
WiredHome 19:3f82c1161fd2 770 WriteData(*string);
WiredHome 19:3f82c1161fd2 771 ++string;
WiredHome 66:468a11f05580 772 _WaitWhileBusy(0x80);
WiredHome 19:3f82c1161fd2 773 }
WiredHome 19:3f82c1161fd2 774 select(false);
WiredHome 73:f22a18707b5e 775 #endif
WiredHome 19:3f82c1161fd2 776 }
WiredHome 37:f19b7e7449dc 777 if (font)
WiredHome 37:f19b7e7449dc 778 _EndGraphicsStream();
WiredHome 19:3f82c1161fd2 779 }
WiredHome 19:3f82c1161fd2 780
WiredHome 44:207594dece70 781
WiredHome 37:f19b7e7449dc 782 RetCode_t RA8875::SetGraphicsCursor(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 783 {
WiredHome 38:38d503b4fad6 784 WriteCommandW(0x46, x);
WiredHome 38:38d503b4fad6 785 WriteCommandW(0x48, y);
WiredHome 19:3f82c1161fd2 786 return noerror;
WiredHome 19:3f82c1161fd2 787 }
WiredHome 19:3f82c1161fd2 788
WiredHome 44:207594dece70 789
WiredHome 41:2956a0a221e5 790 RetCode_t RA8875::SetGraphicsCursorRead(loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 791 {
WiredHome 41:2956a0a221e5 792 //WriteCommand(0x40, 0); // Graphics mode
WiredHome 41:2956a0a221e5 793 //WriteCommand(0x45, 0); // left->right, top->bottom
WiredHome 41:2956a0a221e5 794 WriteCommandW(0x4A, x);
WiredHome 41:2956a0a221e5 795 WriteCommandW(0x4C, y);
WiredHome 41:2956a0a221e5 796 return noerror;
WiredHome 41:2956a0a221e5 797 }
WiredHome 41:2956a0a221e5 798
WiredHome 44:207594dece70 799
WiredHome 37:f19b7e7449dc 800 RetCode_t RA8875::window(loc_t x, loc_t y, dim_t width, dim_t height)
WiredHome 19:3f82c1161fd2 801 {
WiredHome 37:f19b7e7449dc 802 GraphicsDisplay::window(x,y, width,height);
WiredHome 38:38d503b4fad6 803 WriteCommandW(0x30, x);
WiredHome 38:38d503b4fad6 804 WriteCommandW(0x32, y);
WiredHome 38:38d503b4fad6 805 WriteCommandW(0x34, (x+width-1));
WiredHome 38:38d503b4fad6 806 WriteCommandW(0x36, (y+height-1));
WiredHome 37:f19b7e7449dc 807 SetGraphicsCursor(x,y);
WiredHome 19:3f82c1161fd2 808 return noerror;
WiredHome 19:3f82c1161fd2 809 }
WiredHome 19:3f82c1161fd2 810
WiredHome 44:207594dece70 811
WiredHome 61:8f3153bf0baa 812 RetCode_t RA8875::cls(uint16_t layers)
WiredHome 19:3f82c1161fd2 813 {
WiredHome 61:8f3153bf0baa 814 RetCode_t ret;
WiredHome 73:f22a18707b5e 815
WiredHome 19:3f82c1161fd2 816 PERFORMANCE_RESET;
WiredHome 61:8f3153bf0baa 817 if (layers == 0) {
WiredHome 61:8f3153bf0baa 818 ret = clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 819 ret = SetTextCursor(0,0);
WiredHome 61:8f3153bf0baa 820 } else if (layers > 3) {
WiredHome 61:8f3153bf0baa 821 ret = bad_parameter;
WiredHome 61:8f3153bf0baa 822 } else {
WiredHome 61:8f3153bf0baa 823 uint16_t prevLayer = GetDrawingLayer();
WiredHome 61:8f3153bf0baa 824 if (layers & 1) {
WiredHome 61:8f3153bf0baa 825 SelectDrawingLayer(0);
WiredHome 61:8f3153bf0baa 826 clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 827 }
WiredHome 61:8f3153bf0baa 828 if (layers & 2) {
WiredHome 61:8f3153bf0baa 829 SelectDrawingLayer(1);
WiredHome 61:8f3153bf0baa 830 clsw(FULLWINDOW);
WiredHome 61:8f3153bf0baa 831 }
WiredHome 61:8f3153bf0baa 832 ret = SelectDrawingLayer(prevLayer);
WiredHome 61:8f3153bf0baa 833 }
WiredHome 19:3f82c1161fd2 834 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 61:8f3153bf0baa 835 return ret;
WiredHome 19:3f82c1161fd2 836 }
WiredHome 19:3f82c1161fd2 837
WiredHome 44:207594dece70 838
WiredHome 19:3f82c1161fd2 839 RetCode_t RA8875::clsw(RA8875::Region_t region)
WiredHome 19:3f82c1161fd2 840 {
WiredHome 19:3f82c1161fd2 841 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 842 WriteCommand(0x8E, (region == ACTIVEWINDOW) ? 0xC0 : 0x80);
WiredHome 66:468a11f05580 843 _WaitWhileReg(0x8E, 0x80);
WiredHome 19:3f82c1161fd2 844 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 19:3f82c1161fd2 845 return noerror;
WiredHome 19:3f82c1161fd2 846 }
WiredHome 19:3f82c1161fd2 847
WiredHome 44:207594dece70 848
WiredHome 37:f19b7e7449dc 849 RetCode_t RA8875::pixel(loc_t x, loc_t y, color_t color)
WiredHome 19:3f82c1161fd2 850 {
WiredHome 62:ba5d33438fda 851 RetCode_t ret;
WiredHome 73:f22a18707b5e 852
WiredHome 62:ba5d33438fda 853 PERFORMANCE_RESET;
WiredHome 73:f22a18707b5e 854 #if 1
WiredHome 62:ba5d33438fda 855 ret = pixelStream(&color, 1, x,y);
WiredHome 73:f22a18707b5e 856 #else
WiredHome 19:3f82c1161fd2 857 foreground(color);
WiredHome 62:ba5d33438fda 858 ret = pixel(x,y);
WiredHome 73:f22a18707b5e 859 #endif
WiredHome 62:ba5d33438fda 860 REGISTERPERFORMANCE(PRF_DRAWPIXEL);
WiredHome 62:ba5d33438fda 861 return ret;
WiredHome 19:3f82c1161fd2 862 }
WiredHome 19:3f82c1161fd2 863
WiredHome 44:207594dece70 864
WiredHome 37:f19b7e7449dc 865 RetCode_t RA8875::pixel(loc_t x, loc_t y)
WiredHome 19:3f82c1161fd2 866 {
WiredHome 19:3f82c1161fd2 867 RetCode_t ret;
WiredHome 73:f22a18707b5e 868
WiredHome 19:3f82c1161fd2 869 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 870 color_t color = GetForeColor();
WiredHome 73:f22a18707b5e 871 #if 1
WiredHome 62:ba5d33438fda 872 ret = pixelStream(&color, 1, x, y);
WiredHome 73:f22a18707b5e 873 #else
WiredHome 19:3f82c1161fd2 874 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 32:0e4f2ae512e2 875 SetGraphicsCursor(x, y);
WiredHome 38:38d503b4fad6 876 WriteCommand(0x02);
WiredHome 38:38d503b4fad6 877 WriteDataW(color);
WiredHome 19:3f82c1161fd2 878 ret = noerror;
WiredHome 73:f22a18707b5e 879 #endif
WiredHome 41:2956a0a221e5 880 REGISTERPERFORMANCE(PRF_DRAWPIXEL);
WiredHome 19:3f82c1161fd2 881 return ret;
WiredHome 19:3f82c1161fd2 882 }
WiredHome 19:3f82c1161fd2 883
WiredHome 44:207594dece70 884
WiredHome 41:2956a0a221e5 885 RetCode_t RA8875::pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 886 {
WiredHome 41:2956a0a221e5 887 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 888 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 41:2956a0a221e5 889 SetGraphicsCursor(x, y);
WiredHome 41:2956a0a221e5 890 WriteCommand(0x02);
WiredHome 41:2956a0a221e5 891 select(true);
WiredHome 41:2956a0a221e5 892 spiwrite(0x00); // Cmd: write data
WiredHome 41:2956a0a221e5 893 while (count--) {
WiredHome 41:2956a0a221e5 894 spiwrite(*p >> 8);
WiredHome 41:2956a0a221e5 895 spiwrite(*p & 0xFF);
WiredHome 41:2956a0a221e5 896 p++;
WiredHome 41:2956a0a221e5 897 }
WiredHome 41:2956a0a221e5 898 select(false);
WiredHome 41:2956a0a221e5 899 REGISTERPERFORMANCE(PRF_PIXELSTREAM);
WiredHome 41:2956a0a221e5 900 return(noerror);
WiredHome 41:2956a0a221e5 901 }
WiredHome 41:2956a0a221e5 902
WiredHome 44:207594dece70 903
WiredHome 41:2956a0a221e5 904 color_t RA8875::getPixel(loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 905 {
WiredHome 41:2956a0a221e5 906 color_t pixel;
WiredHome 73:f22a18707b5e 907
WiredHome 41:2956a0a221e5 908 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 909 //WriteCommand(0x45,0x00); // read left->right, top->bottom
WiredHome 41:2956a0a221e5 910 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 41:2956a0a221e5 911 SetGraphicsCursorRead(x, y);
WiredHome 41:2956a0a221e5 912 WriteCommand(0x02);
WiredHome 41:2956a0a221e5 913 select(true);
WiredHome 41:2956a0a221e5 914 spiwrite(0x40); // Cmd: read data
WiredHome 41:2956a0a221e5 915 spiwrite(0x00); // dummy read
WiredHome 41:2956a0a221e5 916 pixel = spiread();
WiredHome 41:2956a0a221e5 917 pixel |= (spiread() << 8);
WiredHome 41:2956a0a221e5 918 select(false);
WiredHome 41:2956a0a221e5 919 REGISTERPERFORMANCE(PRF_READPIXEL);
WiredHome 41:2956a0a221e5 920 return pixel;
WiredHome 41:2956a0a221e5 921 }
WiredHome 41:2956a0a221e5 922
WiredHome 44:207594dece70 923
WiredHome 41:2956a0a221e5 924 RetCode_t RA8875::getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y)
WiredHome 41:2956a0a221e5 925 {
WiredHome 41:2956a0a221e5 926 color_t pixel;
WiredHome 73:f22a18707b5e 927
WiredHome 41:2956a0a221e5 928 PERFORMANCE_RESET;
WiredHome 41:2956a0a221e5 929 //WriteCommand(0x45,0x00); // read left->right, top->bottom
WiredHome 41:2956a0a221e5 930 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 41:2956a0a221e5 931 SetGraphicsCursorRead(x, y);
WiredHome 41:2956a0a221e5 932 WriteCommand(0x02);
WiredHome 41:2956a0a221e5 933 select(true);
WiredHome 41:2956a0a221e5 934 spiwrite(0x40); // Cmd: read data
WiredHome 41:2956a0a221e5 935 spiwrite(0x00); // dummy read
WiredHome 41:2956a0a221e5 936 while (count--) {
WiredHome 41:2956a0a221e5 937 pixel = spiread();
WiredHome 41:2956a0a221e5 938 pixel |= (spiread() << 8);
WiredHome 41:2956a0a221e5 939 *p++ = pixel;
WiredHome 41:2956a0a221e5 940 }
WiredHome 41:2956a0a221e5 941 select(false);
WiredHome 41:2956a0a221e5 942 REGISTERPERFORMANCE(PRF_READPIXELSTREAM);
WiredHome 41:2956a0a221e5 943 return noerror;
WiredHome 41:2956a0a221e5 944 }
WiredHome 41:2956a0a221e5 945
WiredHome 44:207594dece70 946
WiredHome 37:f19b7e7449dc 947 RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color)
WiredHome 19:3f82c1161fd2 948 {
WiredHome 19:3f82c1161fd2 949 foreground(color);
WiredHome 19:3f82c1161fd2 950 return line(x1,y1,x2,y2);
WiredHome 19:3f82c1161fd2 951 }
WiredHome 19:3f82c1161fd2 952
WiredHome 44:207594dece70 953
WiredHome 37:f19b7e7449dc 954 RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2)
WiredHome 19:3f82c1161fd2 955 {
WiredHome 19:3f82c1161fd2 956 PERFORMANCE_RESET;
WiredHome 62:ba5d33438fda 957 if (x1 == x2 && y1 == y2) {
WiredHome 60:2dfd574f63bd 958 pixel(x1, y1);
WiredHome 62:ba5d33438fda 959 } else {
WiredHome 60:2dfd574f63bd 960 WriteCommandW(0x91, x1);
WiredHome 60:2dfd574f63bd 961 WriteCommandW(0x93, y1);
WiredHome 60:2dfd574f63bd 962 WriteCommandW(0x95, x2);
WiredHome 60:2dfd574f63bd 963 WriteCommandW(0x97, y2);
WiredHome 60:2dfd574f63bd 964 unsigned char drawCmd = 0x00; // Line
WiredHome 60:2dfd574f63bd 965 WriteCommand(0x90, drawCmd);
WiredHome 60:2dfd574f63bd 966 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 967 _WaitWhileReg(0x90, 0x80);
WiredHome 60:2dfd574f63bd 968 }
WiredHome 19:3f82c1161fd2 969 REGISTERPERFORMANCE(PRF_DRAWLINE);
WiredHome 19:3f82c1161fd2 970 return noerror;
WiredHome 19:3f82c1161fd2 971 }
WiredHome 19:3f82c1161fd2 972
WiredHome 44:207594dece70 973
WiredHome 73:f22a18707b5e 974 RetCode_t RA8875::fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 975 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 976 {
WiredHome 19:3f82c1161fd2 977 return rect(x1,y1,x2,y2,color,fillit);
WiredHome 19:3f82c1161fd2 978 }
WiredHome 19:3f82c1161fd2 979
WiredHome 44:207594dece70 980
WiredHome 73:f22a18707b5e 981 RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 982 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 983 {
WiredHome 19:3f82c1161fd2 984 foreground(color);
WiredHome 19:3f82c1161fd2 985 return rect(x1,y1,x2,y2,fillit);
WiredHome 19:3f82c1161fd2 986 }
WiredHome 19:3f82c1161fd2 987
WiredHome 44:207594dece70 988
WiredHome 73:f22a18707b5e 989 RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 990 fill_t fillit)
WiredHome 19:3f82c1161fd2 991 {
WiredHome 19:3f82c1161fd2 992 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 993 if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 994 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 995 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 996 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 997 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 998 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 999 } else {
WiredHome 38:38d503b4fad6 1000 WriteCommandW(0x91, x1);
WiredHome 38:38d503b4fad6 1001 WriteCommandW(0x93, y1);
WiredHome 38:38d503b4fad6 1002 WriteCommandW(0x95, x2);
WiredHome 38:38d503b4fad6 1003 WriteCommandW(0x97, y2);
WiredHome 19:3f82c1161fd2 1004 unsigned char drawCmd = 0x10; // Rectangle
WiredHome 19:3f82c1161fd2 1005 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1006 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 1007 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 1008 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1009 _WaitWhileReg(0x90, 0x80);
WiredHome 19:3f82c1161fd2 1010 }
WiredHome 19:3f82c1161fd2 1011 REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
WiredHome 19:3f82c1161fd2 1012 return noerror;
WiredHome 19:3f82c1161fd2 1013 }
WiredHome 19:3f82c1161fd2 1014
WiredHome 44:207594dece70 1015
WiredHome 73:f22a18707b5e 1016 RetCode_t RA8875::fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1017 dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1018 {
WiredHome 19:3f82c1161fd2 1019 foreground(color);
WiredHome 19:3f82c1161fd2 1020 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1021 }
WiredHome 19:3f82c1161fd2 1022
WiredHome 44:207594dece70 1023
WiredHome 73:f22a18707b5e 1024 RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1025 dim_t radius1, dim_t radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1026 {
WiredHome 19:3f82c1161fd2 1027 foreground(color);
WiredHome 19:3f82c1161fd2 1028 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1029 }
WiredHome 19:3f82c1161fd2 1030
WiredHome 44:207594dece70 1031
WiredHome 73:f22a18707b5e 1032 RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1033 dim_t radius1, dim_t radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 1034 {
WiredHome 19:3f82c1161fd2 1035 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1036
WiredHome 19:3f82c1161fd2 1037 PERFORMANCE_RESET;
WiredHome 21:3c1efb192927 1038 if (x1 > x2 || y1 > y2 || (radius1 > (x2-x1)/2) || (radius2 > (y2-y1)/2) ) {
WiredHome 21:3c1efb192927 1039 ret = bad_parameter;
WiredHome 21:3c1efb192927 1040 } else if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 1041 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1042 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 1043 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1044 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 1045 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 1046 } else {
WiredHome 38:38d503b4fad6 1047 WriteCommandW(0x91, x1);
WiredHome 38:38d503b4fad6 1048 WriteCommandW(0x93, y1);
WiredHome 38:38d503b4fad6 1049 WriteCommandW(0x95, x2);
WiredHome 38:38d503b4fad6 1050 WriteCommandW(0x97, y2);
WiredHome 38:38d503b4fad6 1051 WriteCommandW(0xA1, radius1);
WiredHome 38:38d503b4fad6 1052 WriteCommandW(0xA3, radius2);
WiredHome 21:3c1efb192927 1053 // Should not need this...
WiredHome 38:38d503b4fad6 1054 WriteCommandW(0xA5, 0);
WiredHome 38:38d503b4fad6 1055 WriteCommandW(0xA7, 0);
WiredHome 19:3f82c1161fd2 1056 unsigned char drawCmd = 0x20; // Rounded Rectangle
WiredHome 19:3f82c1161fd2 1057 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1058 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 1059 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 1060 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1061 _WaitWhileReg(0xA0, 0x80);
WiredHome 19:3f82c1161fd2 1062 }
WiredHome 19:3f82c1161fd2 1063 REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
WiredHome 19:3f82c1161fd2 1064 return ret;
WiredHome 19:3f82c1161fd2 1065 }
WiredHome 19:3f82c1161fd2 1066
WiredHome 44:207594dece70 1067
WiredHome 73:f22a18707b5e 1068 RetCode_t RA8875::triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1069 loc_t x3, loc_t y3, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1070 {
WiredHome 20:6e2e4a8372eb 1071 RetCode_t ret;
WiredHome 20:6e2e4a8372eb 1072
WiredHome 19:3f82c1161fd2 1073 foreground(color);
WiredHome 20:6e2e4a8372eb 1074 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 20:6e2e4a8372eb 1075 return ret;
WiredHome 19:3f82c1161fd2 1076 }
WiredHome 19:3f82c1161fd2 1077
WiredHome 44:207594dece70 1078
WiredHome 73:f22a18707b5e 1079 RetCode_t RA8875::filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1080 loc_t x3, loc_t y3, color_t color, fill_t fillit)
WiredHome 73:f22a18707b5e 1081 {
WiredHome 73:f22a18707b5e 1082 RetCode_t ret;
WiredHome 73:f22a18707b5e 1083
WiredHome 73:f22a18707b5e 1084 foreground(color);
WiredHome 73:f22a18707b5e 1085 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 73:f22a18707b5e 1086 return ret;
WiredHome 73:f22a18707b5e 1087 }
WiredHome 73:f22a18707b5e 1088
WiredHome 73:f22a18707b5e 1089
WiredHome 73:f22a18707b5e 1090 RetCode_t RA8875::triangle(loc_t x1, loc_t y1 ,loc_t x2, loc_t y2,
WiredHome 73:f22a18707b5e 1091 loc_t x3, loc_t y3, fill_t fillit)
WiredHome 19:3f82c1161fd2 1092 {
WiredHome 19:3f82c1161fd2 1093 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1094
WiredHome 19:3f82c1161fd2 1095 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1096 if (x1 == x2 && y1 == y2 && x1 == x3 && y1 == y3) {
WiredHome 19:3f82c1161fd2 1097 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 1098 } else {
WiredHome 38:38d503b4fad6 1099 WriteCommandW(0x91, x1);
WiredHome 38:38d503b4fad6 1100 WriteCommandW(0x93, y1);
WiredHome 38:38d503b4fad6 1101 WriteCommandW(0x95, x2);
WiredHome 38:38d503b4fad6 1102 WriteCommandW(0x97, y2);
WiredHome 38:38d503b4fad6 1103 WriteCommandW(0xA9, x3);
WiredHome 38:38d503b4fad6 1104 WriteCommandW(0xAB, y3);
WiredHome 19:3f82c1161fd2 1105 unsigned char drawCmd = 0x01; // Triangle
WiredHome 19:3f82c1161fd2 1106 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1107 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 1108 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 1109 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1110 _WaitWhileReg(0x90, 0x80);
WiredHome 19:3f82c1161fd2 1111 }
WiredHome 19:3f82c1161fd2 1112 REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
WiredHome 19:3f82c1161fd2 1113 return ret;
WiredHome 19:3f82c1161fd2 1114 }
WiredHome 19:3f82c1161fd2 1115
WiredHome 73:f22a18707b5e 1116 RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius,
WiredHome 73:f22a18707b5e 1117 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1118 {
WiredHome 19:3f82c1161fd2 1119 foreground(color);
WiredHome 19:3f82c1161fd2 1120 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 1121 }
WiredHome 19:3f82c1161fd2 1122
WiredHome 44:207594dece70 1123
WiredHome 73:f22a18707b5e 1124 RetCode_t RA8875::fillcircle(loc_t x, loc_t y, dim_t radius,
WiredHome 73:f22a18707b5e 1125 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 1126 {
WiredHome 19:3f82c1161fd2 1127 foreground(color);
WiredHome 19:3f82c1161fd2 1128 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 1129 }
WiredHome 19:3f82c1161fd2 1130
WiredHome 44:207594dece70 1131
WiredHome 37:f19b7e7449dc 1132 RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius, fill_t fillit)
WiredHome 19:3f82c1161fd2 1133 {
WiredHome 19:3f82c1161fd2 1134 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1135
WiredHome 19:3f82c1161fd2 1136 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 1137 if (radius <= 0) {
WiredHome 19:3f82c1161fd2 1138 ret = bad_parameter;
WiredHome 19:3f82c1161fd2 1139 } else if (radius == 1) {
WiredHome 19:3f82c1161fd2 1140 pixel(x,y);
WiredHome 19:3f82c1161fd2 1141 } else {
WiredHome 38:38d503b4fad6 1142 WriteCommandW(0x99, x);
WiredHome 38:38d503b4fad6 1143 WriteCommandW(0x9B, y);
WiredHome 19:3f82c1161fd2 1144 WriteCommand(0x9d, radius & 0xFF);
WiredHome 19:3f82c1161fd2 1145 unsigned char drawCmd = 0x00; // Circle
WiredHome 19:3f82c1161fd2 1146 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1147 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 1148 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 1149 WriteCommand(0x90, 0x40 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1150 _WaitWhileReg(0x90, 0x40);
WiredHome 19:3f82c1161fd2 1151 }
WiredHome 19:3f82c1161fd2 1152 REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
WiredHome 19:3f82c1161fd2 1153 return ret;
WiredHome 19:3f82c1161fd2 1154 }
WiredHome 19:3f82c1161fd2 1155
WiredHome 44:207594dece70 1156
WiredHome 37:f19b7e7449dc 1157 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 1158 {
WiredHome 19:3f82c1161fd2 1159 foreground(color);
WiredHome 25:9556a3a9b7cc 1160 return ellipse(x,y,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 1161 }
WiredHome 19:3f82c1161fd2 1162
WiredHome 44:207594dece70 1163
WiredHome 37:f19b7e7449dc 1164 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 1165 {
WiredHome 25:9556a3a9b7cc 1166 foreground(color);
WiredHome 25:9556a3a9b7cc 1167 return ellipse(x,y,radius1,radius2,fillit);
WiredHome 25:9556a3a9b7cc 1168 }
WiredHome 44:207594dece70 1169
WiredHome 73:f22a18707b5e 1170
WiredHome 37:f19b7e7449dc 1171 RetCode_t RA8875::ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 1172 {
WiredHome 19:3f82c1161fd2 1173 RetCode_t ret = noerror;
WiredHome 73:f22a18707b5e 1174
WiredHome 19:3f82c1161fd2 1175 PERFORMANCE_RESET;
WiredHome 25:9556a3a9b7cc 1176 if (radius1 <= 0 || radius2 <= 0) {
WiredHome 19:3f82c1161fd2 1177 ; // do nothing
WiredHome 25:9556a3a9b7cc 1178 } else if (radius1 == 1 && radius2 == 1) {
WiredHome 19:3f82c1161fd2 1179 pixel(x, y);
WiredHome 19:3f82c1161fd2 1180 } else {
WiredHome 38:38d503b4fad6 1181 WriteCommandW(0xA5, x);
WiredHome 38:38d503b4fad6 1182 WriteCommandW(0xA7, y);
WiredHome 38:38d503b4fad6 1183 WriteCommandW(0xA1, radius1);
WiredHome 38:38d503b4fad6 1184 WriteCommandW(0xA3, radius2);
WiredHome 19:3f82c1161fd2 1185 unsigned char drawCmd = 0x00; // Ellipse
WiredHome 19:3f82c1161fd2 1186 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 1187 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 1188 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 1189 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 66:468a11f05580 1190 _WaitWhileReg(0xA0, 0x80);
WiredHome 19:3f82c1161fd2 1191 }
WiredHome 19:3f82c1161fd2 1192 REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
WiredHome 19:3f82c1161fd2 1193 return ret;
WiredHome 19:3f82c1161fd2 1194 }
WiredHome 19:3f82c1161fd2 1195
WiredHome 44:207594dece70 1196
WiredHome 68:ab08efabfc88 1197 RetCode_t RA8875::frequency(unsigned long Hz, unsigned long Hz2)
WiredHome 19:3f82c1161fd2 1198 {
WiredHome 66:468a11f05580 1199 spiwritefreq = Hz;
WiredHome 68:ab08efabfc88 1200 if (Hz2 != 0)
WiredHome 68:ab08efabfc88 1201 spireadfreq = Hz2;
WiredHome 68:ab08efabfc88 1202 else
WiredHome 68:ab08efabfc88 1203 spireadfreq = Hz/2;
WiredHome 68:ab08efabfc88 1204 _setWriteSpeed(true);
WiredHome 19:3f82c1161fd2 1205 // __ ___
WiredHome 19:3f82c1161fd2 1206 // Clock ___A Rising edge latched
WiredHome 19:3f82c1161fd2 1207 // ___ ____
WiredHome 19:3f82c1161fd2 1208 // Data ___X____
WiredHome 19:3f82c1161fd2 1209 spi.format(8, 3); // 8 bits and clock to data phase 0
WiredHome 19:3f82c1161fd2 1210 return noerror;
WiredHome 19:3f82c1161fd2 1211 }
WiredHome 19:3f82c1161fd2 1212
WiredHome 68:ab08efabfc88 1213 void RA8875::_setWriteSpeed(bool writeSpeed)
WiredHome 68:ab08efabfc88 1214 {
WiredHome 68:ab08efabfc88 1215 if (writeSpeed) {
WiredHome 68:ab08efabfc88 1216 spi.frequency(spiwritefreq);
WiredHome 68:ab08efabfc88 1217 spiWriteSpeed = true;
WiredHome 68:ab08efabfc88 1218 } else {
WiredHome 68:ab08efabfc88 1219 spi.frequency(spireadfreq);
WiredHome 68:ab08efabfc88 1220 spiWriteSpeed = false;
WiredHome 68:ab08efabfc88 1221 }
WiredHome 68:ab08efabfc88 1222 }
WiredHome 44:207594dece70 1223
WiredHome 19:3f82c1161fd2 1224 RetCode_t RA8875::Power(bool on)
WiredHome 19:3f82c1161fd2 1225 {
WiredHome 19:3f82c1161fd2 1226 WriteCommand(0x01, (on) ? 0x80 : 0x00);
WiredHome 19:3f82c1161fd2 1227 return noerror;
WiredHome 19:3f82c1161fd2 1228 }
WiredHome 19:3f82c1161fd2 1229
WiredHome 44:207594dece70 1230
WiredHome 19:3f82c1161fd2 1231 RetCode_t RA8875::Reset(void)
WiredHome 19:3f82c1161fd2 1232 {
WiredHome 19:3f82c1161fd2 1233 WriteCommand(0x01, 0x01); // Apply Display Off, Reset
WiredHome 19:3f82c1161fd2 1234 wait_ms(2); // no idea if I need to wait, or how long
WiredHome 19:3f82c1161fd2 1235 WriteCommand(0x01, 0x00); // Display off, Remove reset
WiredHome 73:f22a18707b5e 1236 wait_ms(2); // no idea if I need to wait, or how long
WiredHome 43:3becae133285 1237 init(RA8875_DISPLAY_WIDTH, RA8875_DISPLAY_HEIGHT, RA8875_COLORDEPTH_BPP);
WiredHome 19:3f82c1161fd2 1238 return noerror;
WiredHome 19:3f82c1161fd2 1239 }
WiredHome 19:3f82c1161fd2 1240
WiredHome 19:3f82c1161fd2 1241
WiredHome 19:3f82c1161fd2 1242 RetCode_t RA8875::Backlight_u8(unsigned char brightness)
WiredHome 19:3f82c1161fd2 1243 {
WiredHome 19:3f82c1161fd2 1244 static bool is_enabled = false;
WiredHome 19:3f82c1161fd2 1245 if (brightness == 0) {
WiredHome 19:3f82c1161fd2 1246 WriteCommand(0x8a); // Disable the PWM
WiredHome 19:3f82c1161fd2 1247 WriteData(0x00);
WiredHome 19:3f82c1161fd2 1248 is_enabled = false;
WiredHome 19:3f82c1161fd2 1249 } else if (!is_enabled) {
WiredHome 19:3f82c1161fd2 1250 WriteCommand(0x8a); // Enable the PWM
WiredHome 19:3f82c1161fd2 1251 WriteData(0x80);
WiredHome 19:3f82c1161fd2 1252 WriteCommand(0x8a); // Not sure why this is needed, but following the pattern
WiredHome 19:3f82c1161fd2 1253 WriteData(0x81); // open PWM (SYS_CLK / 2 as best I can tell)
WiredHome 19:3f82c1161fd2 1254 is_enabled = true;
WiredHome 19:3f82c1161fd2 1255 }
WiredHome 19:3f82c1161fd2 1256 WriteCommand(0x8b, brightness); // Brightness parameter 0xff-0x00
WiredHome 19:3f82c1161fd2 1257 return noerror;
WiredHome 19:3f82c1161fd2 1258 }
WiredHome 19:3f82c1161fd2 1259
WiredHome 44:207594dece70 1260
WiredHome 19:3f82c1161fd2 1261 RetCode_t RA8875::Backlight(float brightness)
WiredHome 19:3f82c1161fd2 1262 {
WiredHome 19:3f82c1161fd2 1263 unsigned char b;
WiredHome 73:f22a18707b5e 1264
WiredHome 29:422616aa04bd 1265 if (brightness >= 1.0)
WiredHome 19:3f82c1161fd2 1266 b = 255;
WiredHome 29:422616aa04bd 1267 else if (brightness <= 0.0)
WiredHome 19:3f82c1161fd2 1268 b = 0;
WiredHome 19:3f82c1161fd2 1269 else
WiredHome 19:3f82c1161fd2 1270 b = (unsigned char)(brightness * 255);
WiredHome 19:3f82c1161fd2 1271 return Backlight_u8(b);
WiredHome 19:3f82c1161fd2 1272 }
WiredHome 19:3f82c1161fd2 1273
WiredHome 44:207594dece70 1274
WiredHome 19:3f82c1161fd2 1275 RetCode_t RA8875::set_font(const unsigned char * _font)
WiredHome 19:3f82c1161fd2 1276 {
WiredHome 37:f19b7e7449dc 1277 if (font && ! _font) {
WiredHome 37:f19b7e7449dc 1278 SetTextCursor(cursor_x, cursor_y); // soft-font cursor -> hw cursor
WiredHome 37:f19b7e7449dc 1279 }
WiredHome 19:3f82c1161fd2 1280 font = _font;
WiredHome 29:422616aa04bd 1281 GraphicsDisplay::set_font(_font);
WiredHome 29:422616aa04bd 1282 return noerror; // trusting them, but it might be good to put some checks in here...
WiredHome 19:3f82c1161fd2 1283 }
WiredHome 19:3f82c1161fd2 1284
WiredHome 44:207594dece70 1285
WiredHome 19:3f82c1161fd2 1286 RetCode_t RA8875::background(color_t color)
WiredHome 19:3f82c1161fd2 1287 {
WiredHome 37:f19b7e7449dc 1288 GraphicsDisplay::background(color);
WiredHome 19:3f82c1161fd2 1289 WriteCommand(0x60, (color>>11)); // BGCR0
WiredHome 19:3f82c1161fd2 1290 WriteCommand(0x61, (unsigned char)(color>>5)); // BGCR0
WiredHome 19:3f82c1161fd2 1291 WriteCommand(0x62, (unsigned char)(color)); // BGCR0
WiredHome 19:3f82c1161fd2 1292 return noerror;
WiredHome 19:3f82c1161fd2 1293 }
WiredHome 19:3f82c1161fd2 1294
WiredHome 44:207594dece70 1295
WiredHome 19:3f82c1161fd2 1296 RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 1297 {
WiredHome 37:f19b7e7449dc 1298 background(RGB(r,g,b));
WiredHome 37:f19b7e7449dc 1299 // WriteCommand(0x60, r);
WiredHome 37:f19b7e7449dc 1300 // WriteCommand(0x61, g);
WiredHome 37:f19b7e7449dc 1301 // WriteCommand(0x62, b);
WiredHome 19:3f82c1161fd2 1302 return noerror;
WiredHome 19:3f82c1161fd2 1303 }
WiredHome 19:3f82c1161fd2 1304
WiredHome 44:207594dece70 1305
WiredHome 19:3f82c1161fd2 1306 RetCode_t RA8875::foreground(color_t color)
WiredHome 19:3f82c1161fd2 1307 {
WiredHome 37:f19b7e7449dc 1308 GraphicsDisplay::foreground(color);
WiredHome 19:3f82c1161fd2 1309 WriteCommand(0x63, (unsigned char)(color>>11));
WiredHome 19:3f82c1161fd2 1310 WriteCommand(0x64, (unsigned char)(color>>5));
WiredHome 19:3f82c1161fd2 1311 WriteCommand(0x65, (unsigned char)(color));
WiredHome 19:3f82c1161fd2 1312 return noerror;
WiredHome 19:3f82c1161fd2 1313 }
WiredHome 19:3f82c1161fd2 1314
WiredHome 44:207594dece70 1315
WiredHome 37:f19b7e7449dc 1316 RetCode_t RA8875::foreground(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 1317 {
WiredHome 37:f19b7e7449dc 1318 foreground(RGB(r,g,b));
WiredHome 37:f19b7e7449dc 1319 // WriteCommand(0x63, r);
WiredHome 37:f19b7e7449dc 1320 // WriteCommand(0x64, g);
WiredHome 37:f19b7e7449dc 1321 // WriteCommand(0x65, b);
WiredHome 19:3f82c1161fd2 1322 return noerror;
WiredHome 19:3f82c1161fd2 1323 }
WiredHome 19:3f82c1161fd2 1324
WiredHome 44:207594dece70 1325
WiredHome 37:f19b7e7449dc 1326 color_t RA8875::GetForeColor(void)
WiredHome 19:3f82c1161fd2 1327 {
WiredHome 19:3f82c1161fd2 1328 color_t color;
WiredHome 73:f22a18707b5e 1329
WiredHome 19:3f82c1161fd2 1330 color = (ReadCommand(0x63) & 0x1F) << 11;
WiredHome 19:3f82c1161fd2 1331 color |= (ReadCommand(0x64) & 0x3F) << 5;
WiredHome 19:3f82c1161fd2 1332 color |= (ReadCommand(0x65) & 0x1F);
WiredHome 19:3f82c1161fd2 1333 return color;
WiredHome 19:3f82c1161fd2 1334 }
WiredHome 19:3f82c1161fd2 1335
WiredHome 44:207594dece70 1336
WiredHome 19:3f82c1161fd2 1337 color_t RA8875::DOSColor(int i)
WiredHome 73:f22a18707b5e 1338 {
WiredHome 73:f22a18707b5e 1339 const color_t colors[16] = {
WiredHome 19:3f82c1161fd2 1340 Black, Blue, Green, Cyan,
WiredHome 19:3f82c1161fd2 1341 Red, Magenta, Brown, Gray,
WiredHome 19:3f82c1161fd2 1342 Charcoal, BrightBlue, BrightGreen, BrightCyan,
WiredHome 19:3f82c1161fd2 1343 Orange, Pink, Yellow, White
WiredHome 73:f22a18707b5e 1344 };
WiredHome 19:3f82c1161fd2 1345 if (i < 16)
WiredHome 19:3f82c1161fd2 1346 return colors[i];
WiredHome 19:3f82c1161fd2 1347 else
WiredHome 19:3f82c1161fd2 1348 return 0;
WiredHome 73:f22a18707b5e 1349 }
WiredHome 19:3f82c1161fd2 1350
WiredHome 44:207594dece70 1351
WiredHome 73:f22a18707b5e 1352 const char * RA8875::DOSColorNames(int i)
WiredHome 73:f22a18707b5e 1353 {
WiredHome 73:f22a18707b5e 1354 const char * names[16] = {
WiredHome 19:3f82c1161fd2 1355 "Black", "Blue", "Green", "Cyan",
WiredHome 19:3f82c1161fd2 1356 "Red", "Magenta", "Brown", "Gray",
WiredHome 19:3f82c1161fd2 1357 "Charcoal", "BrightBlue", "BrightGreen", "BrightCyan",
WiredHome 19:3f82c1161fd2 1358 "Orange", "Pink", "Yellow", "White"
WiredHome 73:f22a18707b5e 1359 };
WiredHome 19:3f82c1161fd2 1360 if (i < 16)
WiredHome 19:3f82c1161fd2 1361 return names[i];
WiredHome 19:3f82c1161fd2 1362 else
WiredHome 19:3f82c1161fd2 1363 return NULL;
WiredHome 73:f22a18707b5e 1364 }
WiredHome 19:3f82c1161fd2 1365
WiredHome 19:3f82c1161fd2 1366
WiredHome 19:3f82c1161fd2 1367 ///////////////////////////////////////////////////////////////
WiredHome 19:3f82c1161fd2 1368 // Private functions
WiredHome 19:3f82c1161fd2 1369
WiredHome 19:3f82c1161fd2 1370 unsigned char RA8875::spiwrite(unsigned char data)
WiredHome 19:3f82c1161fd2 1371 {
WiredHome 19:3f82c1161fd2 1372 unsigned char retval;
WiredHome 73:f22a18707b5e 1373
WiredHome 68:ab08efabfc88 1374 if (!spiWriteSpeed)
WiredHome 68:ab08efabfc88 1375 _setWriteSpeed(true);
WiredHome 19:3f82c1161fd2 1376 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 1377 return retval;
WiredHome 19:3f82c1161fd2 1378 }
WiredHome 19:3f82c1161fd2 1379
WiredHome 44:207594dece70 1380
WiredHome 19:3f82c1161fd2 1381 unsigned char RA8875::spiread(void)
WiredHome 19:3f82c1161fd2 1382 {
WiredHome 19:3f82c1161fd2 1383 unsigned char retval;
WiredHome 19:3f82c1161fd2 1384 unsigned char data = 0;
WiredHome 73:f22a18707b5e 1385
WiredHome 68:ab08efabfc88 1386 if (spiWriteSpeed)
WiredHome 68:ab08efabfc88 1387 _setWriteSpeed(false);
WiredHome 19:3f82c1161fd2 1388 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 1389 return retval;
WiredHome 19:3f82c1161fd2 1390 }
WiredHome 19:3f82c1161fd2 1391
WiredHome 44:207594dece70 1392
WiredHome 19:3f82c1161fd2 1393 RetCode_t RA8875::select(bool chipsel)
WiredHome 19:3f82c1161fd2 1394 {
WiredHome 19:3f82c1161fd2 1395 cs = (chipsel == true) ? 0 : 1;
WiredHome 19:3f82c1161fd2 1396 return noerror;
WiredHome 19:3f82c1161fd2 1397 }
WiredHome 19:3f82c1161fd2 1398
WiredHome 44:207594dece70 1399
WiredHome 43:3becae133285 1400 RetCode_t RA8875::init(int width, int height, int color_bpp)
WiredHome 19:3f82c1161fd2 1401 {
WiredHome 19:3f82c1161fd2 1402 Backlight_u8(0);
WiredHome 66:468a11f05580 1403 WriteCommand(0x88, 0x0B); // PLLC1 - Phase Lock Loop registers
WiredHome 19:3f82c1161fd2 1404 wait_ms(1);
WiredHome 19:3f82c1161fd2 1405 WriteCommand(0x89, 0x02);
WiredHome 19:3f82c1161fd2 1406 wait_ms(1);
WiredHome 73:f22a18707b5e 1407
WiredHome 23:a50ded45dbaf 1408 // System Config Register (SYSR)
WiredHome 43:3becae133285 1409 if (color_bpp == 16) {
WiredHome 43:3becae133285 1410 WriteCommand(0x10, 0x0C); // 16-bpp (65K colors) color depth, 8-bit interface
WiredHome 43:3becae133285 1411 } else { // color_bpp == 8
WiredHome 43:3becae133285 1412 WriteCommand(0x10, 0x00); // 8-bpp (256 colors)
WiredHome 43:3becae133285 1413 }
WiredHome 23:a50ded45dbaf 1414 // Pixel Clock Setting Register (PCSR)
WiredHome 37:f19b7e7449dc 1415 WriteCommand(0x04, 0x82); // PDAT on PCLK falling edge, PCLK = 4 x System Clock
WiredHome 19:3f82c1161fd2 1416 wait_ms(1);
WiredHome 19:3f82c1161fd2 1417
WiredHome 19:3f82c1161fd2 1418 // Horizontal Settings
WiredHome 43:3becae133285 1419 WriteCommand(0x14, width/8 - 1); //HDWR//Horizontal Display Width Setting Bit[6:0]
WiredHome 43:3becae133285 1420 WriteCommand(0x15, 0x02); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
WiredHome 43:3becae133285 1421 WriteCommand(0x16, 0x03); //HNDR//Horizontal Non-Display Period Bit[4:0]
WiredHome 43:3becae133285 1422 WriteCommand(0x17, 0x01); //HSTR//HSYNC Start Position[4:0]
WiredHome 43:3becae133285 1423 WriteCommand(0x18, 0x03); //HPWR//HSYNC Polarity ,The period width of HSYNC.
WiredHome 19:3f82c1161fd2 1424
WiredHome 19:3f82c1161fd2 1425 // Vertical Settings
WiredHome 43:3becae133285 1426 WriteCommand(0x19, (height-1)&0xFF); //VDHR0 //Vertical Display Height Bit [7:0]
WiredHome 43:3becae133285 1427 WriteCommand(0x1a, (height-1)>>8); //VDHR1 //Vertical Display Height Bit [8]
WiredHome 43:3becae133285 1428 WriteCommand(0x1b, 0x0F); //VNDR0 //Vertical Non-Display Period Bit [7:0]
WiredHome 43:3becae133285 1429 WriteCommand(0x1c, 0x00); //VNDR1 //Vertical Non-Display Period Bit [8]
WiredHome 43:3becae133285 1430 WriteCommand(0x1d, 0x0e); //VSTR0 //VSYNC Start Position[7:0]
WiredHome 43:3becae133285 1431 WriteCommand(0x1e, 0x06); //VSTR1 //VSYNC Start Position[8]
WiredHome 43:3becae133285 1432 WriteCommand(0x1f, 0x01); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
WiredHome 19:3f82c1161fd2 1433
WiredHome 43:3becae133285 1434 if (width >= 800 && height >= 480 && color_bpp > 8) {
WiredHome 43:3becae133285 1435 WriteCommand(0x20, 0x00); // DPCR - 1-layer mode when the resolution is too high
WiredHome 43:3becae133285 1436 } else {
WiredHome 43:3becae133285 1437 WriteCommand(0x20, 0x80); // DPCR - 2-layer mode
WiredHome 43:3becae133285 1438 }
WiredHome 73:f22a18707b5e 1439
WiredHome 50:2c4f474a2453 1440 // Set display image to Blue on Black as default
WiredHome 43:3becae133285 1441 window(0,0, width, height); // Initialize to full screen
WiredHome 24:8ca861acf12d 1442 SetTextCursorControl();
WiredHome 28:ed102fc442c4 1443 foreground(Blue);
WiredHome 19:3f82c1161fd2 1444 background(Black);
WiredHome 50:2c4f474a2453 1445 SelectDrawingLayer(1);
WiredHome 50:2c4f474a2453 1446 cls();
WiredHome 50:2c4f474a2453 1447 SelectDrawingLayer(0);
WiredHome 19:3f82c1161fd2 1448 cls();
WiredHome 19:3f82c1161fd2 1449 return noerror;
WiredHome 19:3f82c1161fd2 1450 }
WiredHome 19:3f82c1161fd2 1451
WiredHome 72:ecffe56af969 1452 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 1453 {
WiredHome 72:ecffe56af969 1454 uint16_t curLayer = GetDrawingLayer();
WiredHome 72:ecffe56af969 1455 RetCode_t ret = SelectDrawingLayer(layer);
WiredHome 72:ecffe56af969 1456 if (ret == noerror) {
WiredHome 72:ecffe56af969 1457 ret = PrintScreen(x, y, w, h, Name_BMP);
WiredHome 72:ecffe56af969 1458 }
WiredHome 72:ecffe56af969 1459 SelectDrawingLayer(curLayer);
WiredHome 72:ecffe56af969 1460 return ret;
WiredHome 72:ecffe56af969 1461 }
WiredHome 72:ecffe56af969 1462
WiredHome 72:ecffe56af969 1463 RetCode_t RA8875::PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP)
WiredHome 72:ecffe56af969 1464 {
WiredHome 72:ecffe56af969 1465 BITMAPFILEHEADER BMP_Header;
WiredHome 72:ecffe56af969 1466 BITMAPINFOHEADER BMP_Info;
WiredHome 73:f22a18707b5e 1467
WiredHome 72:ecffe56af969 1468 INFO("(%d,%d) - (%d,%d) %s", x,y,w,h,Name_BMP);
WiredHome 72:ecffe56af969 1469 if (x >= 0 && x < width()
WiredHome 73:f22a18707b5e 1470 && y >= 0 && y < height()
WiredHome 73:f22a18707b5e 1471 && w > 0 && x + w <= width()
WiredHome 73:f22a18707b5e 1472 && h > 0 && y + h <= height()) {
WiredHome 72:ecffe56af969 1473
WiredHome 72:ecffe56af969 1474 BMP_Header.bfType = BF_TYPE;
WiredHome 72:ecffe56af969 1475 BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Header);
WiredHome 72:ecffe56af969 1476 BMP_Header.bfReserved1 = 0;
WiredHome 72:ecffe56af969 1477 BMP_Header.bfReserved2 = 0;
WiredHome 72:ecffe56af969 1478 BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Header);
WiredHome 73:f22a18707b5e 1479
WiredHome 72:ecffe56af969 1480 BMP_Info.biSize = sizeof(BMP_Info);
WiredHome 72:ecffe56af969 1481 BMP_Info.biWidth = w;
WiredHome 72:ecffe56af969 1482 BMP_Info.biHeight = h;
WiredHome 72:ecffe56af969 1483 BMP_Info.biPlanes = 1;
WiredHome 72:ecffe56af969 1484 BMP_Info.biBitCount = 24;
WiredHome 72:ecffe56af969 1485 BMP_Info.biCompression = BI_RGB;
WiredHome 72:ecffe56af969 1486 BMP_Info.biSizeImage = 0;
WiredHome 72:ecffe56af969 1487 BMP_Info.biXPelsPerMeter = 0;
WiredHome 72:ecffe56af969 1488 BMP_Info.biYPelsPerMeter = 0;
WiredHome 72:ecffe56af969 1489 BMP_Info.biClrUsed = 0;
WiredHome 72:ecffe56af969 1490 BMP_Info.biClrImportant = 0;
WiredHome 72:ecffe56af969 1491
WiredHome 72:ecffe56af969 1492 INFO("Writing {%s}", Name_BMP);
WiredHome 72:ecffe56af969 1493 FILE *Image = fopen(Name_BMP, "wb");
WiredHome 72:ecffe56af969 1494 if (!Image) {
WiredHome 72:ecffe56af969 1495 ERR("File not found");
WiredHome 72:ecffe56af969 1496 return(file_not_found);
WiredHome 72:ecffe56af969 1497 }
WiredHome 72:ecffe56af969 1498
WiredHome 72:ecffe56af969 1499 // Be optimistic - don't check for errors.
WiredHome 72:ecffe56af969 1500 //HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 72:ecffe56af969 1501 fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image);
WiredHome 72:ecffe56af969 1502 //INFO("fwrite returned %d", r);
WiredHome 73:f22a18707b5e 1503
WiredHome 72:ecffe56af969 1504 //HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 72:ecffe56af969 1505 fwrite(&BMP_Info, sizeof(char), sizeof(BMP_Info), Image);
WiredHome 72:ecffe56af969 1506 //INFO("fwrite returned %d", r);
WiredHome 73:f22a18707b5e 1507
WiredHome 72:ecffe56af969 1508 int lineBufSize = ((24 * w + 7)/8);
WiredHome 72:ecffe56af969 1509 uint8_t * lineBuffer = (uint8_t *)malloc(lineBufSize);
WiredHome 72:ecffe56af969 1510 if (lineBuffer == NULL) {
WiredHome 72:ecffe56af969 1511 fclose(Image);
WiredHome 72:ecffe56af969 1512 ERR("Not enough RAM for lineBuffer");
WiredHome 72:ecffe56af969 1513 return(not_enough_ram);
WiredHome 72:ecffe56af969 1514 }
WiredHome 72:ecffe56af969 1515 color_t * pixelBuffer = (color_t *)malloc(w * sizeof(color_t));
WiredHome 73:f22a18707b5e 1516 color_t * pixelBuffer2 = (color_t *)malloc(w * sizeof(color_t));
WiredHome 73:f22a18707b5e 1517 color_t transparency = GetBackgroundTransparencyColor();
WiredHome 73:f22a18707b5e 1518 unsigned char ltpr0 = ReadCommand(0x52) & 0x7;
WiredHome 73:f22a18707b5e 1519
WiredHome 73:f22a18707b5e 1520 if (pixelBuffer == NULL || pixelBuffer2 == NULL) {
WiredHome 72:ecffe56af969 1521 fclose(Image);
WiredHome 72:ecffe56af969 1522 free(lineBuffer);
WiredHome 72:ecffe56af969 1523 ERR("Not enough RAM for pixelBuffer");
WiredHome 73:f22a18707b5e 1524 if (pixelBuffer)
WiredHome 73:f22a18707b5e 1525 free(pixelBuffer);
WiredHome 72:ecffe56af969 1526 return(not_enough_ram);
WiredHome 72:ecffe56af969 1527 }
WiredHome 73:f22a18707b5e 1528
WiredHome 73:f22a18707b5e 1529 uint16_t prevLayer = GetDrawingLayer();
WiredHome 73:f22a18707b5e 1530 // If only one of the layers is visible, select that layer
WiredHome 73:f22a18707b5e 1531 switch(ltpr0) {
WiredHome 73:f22a18707b5e 1532 case 0:
WiredHome 73:f22a18707b5e 1533 SelectDrawingLayer(0);
WiredHome 73:f22a18707b5e 1534 break;
WiredHome 73:f22a18707b5e 1535 case 1:
WiredHome 73:f22a18707b5e 1536 SelectDrawingLayer(1);
WiredHome 73:f22a18707b5e 1537 break;
WiredHome 73:f22a18707b5e 1538 default:
WiredHome 73:f22a18707b5e 1539 break;
WiredHome 73:f22a18707b5e 1540 }
WiredHome 73:f22a18707b5e 1541
WiredHome 72:ecffe56af969 1542 // Read the display from the last line toward the top
WiredHome 72:ecffe56af969 1543 // so we can write the file in one pass.
WiredHome 72:ecffe56af969 1544 for (int j = h - 1; j >= 0; j--) {
WiredHome 73:f22a18707b5e 1545 if (ltpr0 >= 2) // Need to combine the layers...
WiredHome 73:f22a18707b5e 1546 SelectDrawingLayer(0); // so read layer 0 first
WiredHome 72:ecffe56af969 1547 // Read one line of pixels to a local buffer
WiredHome 72:ecffe56af969 1548 if (getPixelStream(pixelBuffer, w, x,y+j) != noerror) {
WiredHome 72:ecffe56af969 1549 ERR("getPixelStream error, and no recovery handler...");
WiredHome 72:ecffe56af969 1550 }
WiredHome 73:f22a18707b5e 1551 if (ltpr0 >= 2) { // Need to combine the layers...
WiredHome 73:f22a18707b5e 1552 SelectDrawingLayer(1); // so read layer 0 first
WiredHome 73:f22a18707b5e 1553 if (getPixelStream(pixelBuffer2, w, x,y+j) != noerror) {
WiredHome 73:f22a18707b5e 1554 ERR("getPixelStream error, and no recovery handler...");
WiredHome 73:f22a18707b5e 1555 }
WiredHome 73:f22a18707b5e 1556 }
WiredHome 72:ecffe56af969 1557 // Convert the local buffer to RGBQUAD format
WiredHome 72:ecffe56af969 1558 int lb = 0;
WiredHome 72:ecffe56af969 1559 for (int i=0; i<w; i++) {
WiredHome 73:f22a18707b5e 1560 RGBQUAD q0 = RGB16ToRGBQuad(pixelBuffer[x+i]); // Scale to 24-bits
WiredHome 73:f22a18707b5e 1561 RGBQUAD q1 = RGB16ToRGBQuad(pixelBuffer2[x+i]); // Scale to 24-bits
WiredHome 73:f22a18707b5e 1562 switch (ltpr0) {
WiredHome 73:f22a18707b5e 1563 case 0:
WiredHome 73:f22a18707b5e 1564 case 1:
WiredHome 73:f22a18707b5e 1565 case 2: // lighten-overlay (@TODO Not supported yet)
WiredHome 73:f22a18707b5e 1566 case 6: // Floating Windows (@TODO not sure how to support)
WiredHome 73:f22a18707b5e 1567 default: // Reserved...
WiredHome 73:f22a18707b5e 1568 lineBuffer[lb++] = q0.rgbBlue;
WiredHome 73:f22a18707b5e 1569 lineBuffer[lb++] = q0.rgbGreen;
WiredHome 73:f22a18707b5e 1570 lineBuffer[lb++] = q0.rgbRed;
WiredHome 73:f22a18707b5e 1571 break;
WiredHome 73:f22a18707b5e 1572 case 3: // transparent mode (@TODO Read the background color register for transparent)
WiredHome 73:f22a18707b5e 1573 case 4: // boolean or
WiredHome 73:f22a18707b5e 1574 lineBuffer[lb++] = q0.rgbBlue | q1.rgbBlue;
WiredHome 73:f22a18707b5e 1575 lineBuffer[lb++] = q0.rgbGreen | q1.rgbGreen;
WiredHome 73:f22a18707b5e 1576 lineBuffer[lb++] = q0.rgbRed | q1.rgbRed;
WiredHome 73:f22a18707b5e 1577 break;
WiredHome 73:f22a18707b5e 1578 case 5: // boolean AND
WiredHome 73:f22a18707b5e 1579 lineBuffer[lb++] = q0.rgbBlue & q1.rgbBlue;
WiredHome 73:f22a18707b5e 1580 lineBuffer[lb++] = q0.rgbGreen & q1.rgbGreen;
WiredHome 73:f22a18707b5e 1581 lineBuffer[lb++] = q0.rgbRed & q1.rgbRed;
WiredHome 73:f22a18707b5e 1582 break;
WiredHome 73:f22a18707b5e 1583 }
WiredHome 72:ecffe56af969 1584 }
WiredHome 73:f22a18707b5e 1585 if (j == h - 1)
WiredHome 73:f22a18707b5e 1586 HexDump("Line", lineBuffer, lineBufSize);
WiredHome 72:ecffe56af969 1587 // Write to disk
WiredHome 72:ecffe56af969 1588 fwrite(lineBuffer, sizeof(char), lb, Image);
WiredHome 72:ecffe56af969 1589 }
WiredHome 73:f22a18707b5e 1590 SelectDrawingLayer(prevLayer);
WiredHome 72:ecffe56af969 1591 fclose(Image);
WiredHome 73:f22a18707b5e 1592 free(pixelBuffer2); // don't leak memory.
WiredHome 73:f22a18707b5e 1593 free(pixelBuffer);
WiredHome 72:ecffe56af969 1594 free(lineBuffer);
WiredHome 73:f22a18707b5e 1595 INFO("Image closed");
WiredHome 72:ecffe56af969 1596 return noerror;
WiredHome 72:ecffe56af969 1597 } else {
WiredHome 72:ecffe56af969 1598 return bad_parameter;
WiredHome 72:ecffe56af969 1599 }
WiredHome 72:ecffe56af969 1600 }
WiredHome 72:ecffe56af969 1601
WiredHome 72:ecffe56af969 1602
WiredHome 72:ecffe56af969 1603 // ##########################################################################
WiredHome 72:ecffe56af969 1604 // ##########################################################################
WiredHome 72:ecffe56af969 1605 // ##########################################################################
WiredHome 72:ecffe56af969 1606
WiredHome 23:a50ded45dbaf 1607 #ifdef TESTENABLE
WiredHome 23:a50ded45dbaf 1608
WiredHome 37:f19b7e7449dc 1609 #include "Arial12x12.h"
WiredHome 37:f19b7e7449dc 1610 #include "Small_6.h"
WiredHome 37:f19b7e7449dc 1611
WiredHome 23:a50ded45dbaf 1612 // ______________ ______________ ______________ _______________
WiredHome 23:a50ded45dbaf 1613 // /_____ _____/ / ___________/ / ___________/ /_____ ______/
WiredHome 23:a50ded45dbaf 1614 // / / / / / / / /
WiredHome 23:a50ded45dbaf 1615 // / / / /___ / /__________ / /
WiredHome 23:a50ded45dbaf 1616 // / / / ____/ /__________ / / /
WiredHome 23:a50ded45dbaf 1617 // / / / / / / / /
WiredHome 23:a50ded45dbaf 1618 // / / / /__________ ___________/ / / /
WiredHome 23:a50ded45dbaf 1619 // /__/ /_____________/ /_____________/ /__/
WiredHome 23:a50ded45dbaf 1620 //
WiredHome 23:a50ded45dbaf 1621 // Everything from here down is test code.
WiredHome 41:2956a0a221e5 1622 bool SuppressSlowStuff = false;
WiredHome 23:a50ded45dbaf 1623
WiredHome 44:207594dece70 1624
WiredHome 49:c5182231d1b9 1625 void TextWrapTest(RA8875 & display, Serial & pc)
WiredHome 49:c5182231d1b9 1626 {
WiredHome 49:c5182231d1b9 1627 if (!SuppressSlowStuff)
WiredHome 49:c5182231d1b9 1628 pc.printf("Text Wrap Test\r\n");
WiredHome 49:c5182231d1b9 1629 display.background(Black);
WiredHome 49:c5182231d1b9 1630 display.foreground(Blue);
WiredHome 49:c5182231d1b9 1631 display.cls();
WiredHome 49:c5182231d1b9 1632 display.Backlight_u8(255);
WiredHome 49:c5182231d1b9 1633 display.puts(0,0, "Text Wrap Test.\r\n");
WiredHome 52:e6039a823420 1634 for (int i=1; i<60; i++) {
WiredHome 52:e6039a823420 1635 display.printf("L%2d\n", i % 17);
WiredHome 49:c5182231d1b9 1636 if (!SuppressSlowStuff)
WiredHome 52:e6039a823420 1637 wait_ms(100);
WiredHome 49:c5182231d1b9 1638 }
WiredHome 49:c5182231d1b9 1639 if (!SuppressSlowStuff)
WiredHome 49:c5182231d1b9 1640 wait_ms(3000);
WiredHome 49:c5182231d1b9 1641 }
WiredHome 49:c5182231d1b9 1642
WiredHome 23:a50ded45dbaf 1643 void TextCursorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1644 {
WiredHome 37:f19b7e7449dc 1645 const char * iCursor = "The I-Beam cursor should be visible for this text.\r\n";
WiredHome 37:f19b7e7449dc 1646 const char * uCursor = "The Underscore cursor should be visible for this text.\r\n";
WiredHome 37:f19b7e7449dc 1647 const char * bCursor = "The Block cursor should be visible for this text.\r\n";
WiredHome 37:f19b7e7449dc 1648 const char * bbCursor = "The Blinking Block cursor should be visible for this text.\r\n";
WiredHome 23:a50ded45dbaf 1649 const char * p;
WiredHome 41:2956a0a221e5 1650 int delay = 100;
WiredHome 73:f22a18707b5e 1651
WiredHome 41:2956a0a221e5 1652 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1653 pc.printf("Text Cursor Test\r\n");
WiredHome 73:f22a18707b5e 1654 else
WiredHome 41:2956a0a221e5 1655 delay = 0;
WiredHome 23:a50ded45dbaf 1656 display.background(Black);
WiredHome 23:a50ded45dbaf 1657 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1658 display.cls();
WiredHome 25:9556a3a9b7cc 1659 display.Backlight_u8(255);
WiredHome 23:a50ded45dbaf 1660 display.puts(0,0, "Text Cursor Test.");
WiredHome 73:f22a18707b5e 1661
WiredHome 23:a50ded45dbaf 1662 // visible, non-blinking
WiredHome 24:8ca861acf12d 1663 display.SetTextCursor(0,20);
WiredHome 53:86d24b9480b9 1664 display.SetTextCursorControl(RA8875::IBEAM, false);
WiredHome 24:8ca861acf12d 1665 p = iCursor;
WiredHome 23:a50ded45dbaf 1666 while (*p) {
WiredHome 24:8ca861acf12d 1667 display._putc(*p++);
WiredHome 41:2956a0a221e5 1668 wait_ms(delay);
WiredHome 24:8ca861acf12d 1669 }
WiredHome 24:8ca861acf12d 1670
WiredHome 53:86d24b9480b9 1671 display.SetTextCursorControl(RA8875::UNDER, false);
WiredHome 24:8ca861acf12d 1672 p = uCursor;
WiredHome 24:8ca861acf12d 1673 while (*p) {
WiredHome 24:8ca861acf12d 1674 display._putc(*p++);
WiredHome 41:2956a0a221e5 1675 wait_ms(delay);
WiredHome 23:a50ded45dbaf 1676 }
WiredHome 73:f22a18707b5e 1677
WiredHome 53:86d24b9480b9 1678 display.SetTextCursorControl(RA8875::BLOCK, false);
WiredHome 24:8ca861acf12d 1679 p = bCursor;
WiredHome 24:8ca861acf12d 1680 while (*p) {
WiredHome 24:8ca861acf12d 1681 display._putc(*p++);
WiredHome 41:2956a0a221e5 1682 wait_ms(delay);
WiredHome 24:8ca861acf12d 1683 }
WiredHome 24:8ca861acf12d 1684
WiredHome 53:86d24b9480b9 1685 display.SetTextCursorControl(RA8875::BLOCK, true);
WiredHome 24:8ca861acf12d 1686 p = bbCursor;
WiredHome 24:8ca861acf12d 1687 while (*p) {
WiredHome 24:8ca861acf12d 1688 display._putc(*p++);
WiredHome 41:2956a0a221e5 1689 wait_ms(delay);
WiredHome 24:8ca861acf12d 1690 }
WiredHome 41:2956a0a221e5 1691 wait_ms(delay * 20);
WiredHome 53:86d24b9480b9 1692 display.SetTextCursorControl(RA8875::NOCURSOR, false);
WiredHome 23:a50ded45dbaf 1693 }
WiredHome 23:a50ded45dbaf 1694
WiredHome 44:207594dece70 1695
WiredHome 23:a50ded45dbaf 1696 void BacklightTest(RA8875 & display, Serial & pc, float ramptime)
WiredHome 23:a50ded45dbaf 1697 {
WiredHome 29:422616aa04bd 1698 char buf[60];
WiredHome 41:2956a0a221e5 1699 unsigned int w = (ramptime * 1000)/ 256;
WiredHome 41:2956a0a221e5 1700 int delay = 200;
WiredHome 41:2956a0a221e5 1701
WiredHome 41:2956a0a221e5 1702 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1703 pc.printf("Backlight Test - ramp over %f sec.\r\n", ramptime);
WiredHome 41:2956a0a221e5 1704 else {
WiredHome 41:2956a0a221e5 1705 delay = 0;
WiredHome 41:2956a0a221e5 1706 w = 0;
WiredHome 41:2956a0a221e5 1707 }
WiredHome 23:a50ded45dbaf 1708 display.Backlight_u8(0);
WiredHome 29:422616aa04bd 1709 display.background(White);
WiredHome 23:a50ded45dbaf 1710 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1711 display.cls();
WiredHome 41:2956a0a221e5 1712 wait_ms(delay);
WiredHome 23:a50ded45dbaf 1713 display.puts(0,0, "RA8875 Backlight Test - Ramp up.");
WiredHome 38:38d503b4fad6 1714 for (int i=0; i <= 255; i++) {
WiredHome 29:422616aa04bd 1715 sprintf(buf, "%3d, %4d", i, w);
WiredHome 37:f19b7e7449dc 1716 display.puts(100,100,buf);
WiredHome 23:a50ded45dbaf 1717 display.Backlight_u8(i);
WiredHome 29:422616aa04bd 1718 wait_ms(w);
WiredHome 23:a50ded45dbaf 1719 }
WiredHome 23:a50ded45dbaf 1720 }
WiredHome 23:a50ded45dbaf 1721
WiredHome 44:207594dece70 1722
WiredHome 23:a50ded45dbaf 1723 void BacklightTest2(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1724 {
WiredHome 41:2956a0a221e5 1725 int delay = 20;
WiredHome 41:2956a0a221e5 1726
WiredHome 41:2956a0a221e5 1727 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1728 pc.printf("Backlight Test 2\r\n");
WiredHome 41:2956a0a221e5 1729 else
WiredHome 41:2956a0a221e5 1730 delay = 0;
WiredHome 41:2956a0a221e5 1731
WiredHome 23:a50ded45dbaf 1732 // Dim it out at the end of the tests.
WiredHome 37:f19b7e7449dc 1733 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1734 display.puts(0,0, "Ramp Backlight down.");
WiredHome 23:a50ded45dbaf 1735 // Ramp it off
WiredHome 23:a50ded45dbaf 1736 for (int i=255; i != 0; i--) {
WiredHome 23:a50ded45dbaf 1737 display.Backlight_u8(i);
WiredHome 41:2956a0a221e5 1738 wait_ms(delay);
WiredHome 23:a50ded45dbaf 1739 }
WiredHome 23:a50ded45dbaf 1740 display.Backlight_u8(0);
WiredHome 23:a50ded45dbaf 1741 }
WiredHome 23:a50ded45dbaf 1742
WiredHome 44:207594dece70 1743
WiredHome 23:a50ded45dbaf 1744 void ExternalFontTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1745 {
WiredHome 41:2956a0a221e5 1746 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1747 pc.printf("External Font Test\r\n");
WiredHome 23:a50ded45dbaf 1748 display.background(Black);
WiredHome 23:a50ded45dbaf 1749 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1750 display.cls();
WiredHome 23:a50ded45dbaf 1751 display.Backlight(1);
WiredHome 37:f19b7e7449dc 1752 display.puts(0,0, "External Font Test.");
WiredHome 37:f19b7e7449dc 1753
WiredHome 37:f19b7e7449dc 1754 display.set_font(Small_6);
WiredHome 73:f22a18707b5e 1755 display.puts(0,30, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 37:f19b7e7449dc 1756
WiredHome 23:a50ded45dbaf 1757 display.set_font(Arial12x12);
WiredHome 37:f19b7e7449dc 1758 display.puts("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 37:f19b7e7449dc 1759 display.set_font(); // restore to internal
WiredHome 73:f22a18707b5e 1760
WiredHome 37:f19b7e7449dc 1761 display.puts("Normal font again.");
WiredHome 37:f19b7e7449dc 1762 //display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 1763 }
WiredHome 23:a50ded45dbaf 1764
WiredHome 44:207594dece70 1765
WiredHome 23:a50ded45dbaf 1766 void DOSColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1767 {
WiredHome 41:2956a0a221e5 1768 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1769 pc.printf("DOS Color Test\r\n");
WiredHome 23:a50ded45dbaf 1770 display.background(Black);
WiredHome 23:a50ded45dbaf 1771 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1772 display.cls();
WiredHome 23:a50ded45dbaf 1773 display.puts(0,0, "DOS Colors - Fore");
WiredHome 23:a50ded45dbaf 1774 display.puts(280,0, "Back");
WiredHome 23:a50ded45dbaf 1775 display.background(Gray);
WiredHome 23:a50ded45dbaf 1776 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1777 display.foreground(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1778 display.puts(160, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 1779 display.background(Black);
WiredHome 23:a50ded45dbaf 1780 }
WiredHome 23:a50ded45dbaf 1781 display.foreground(White);
WiredHome 23:a50ded45dbaf 1782 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1783 display.background(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1784 display.puts(360, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 1785 display.foreground(White);
WiredHome 23:a50ded45dbaf 1786 }
WiredHome 23:a50ded45dbaf 1787 }
WiredHome 23:a50ded45dbaf 1788
WiredHome 44:207594dece70 1789
WiredHome 23:a50ded45dbaf 1790 void WebColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1791 {
WiredHome 41:2956a0a221e5 1792 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1793 pc.printf("Web Color Test\r\n");
WiredHome 23:a50ded45dbaf 1794 display.background(Black);
WiredHome 23:a50ded45dbaf 1795 display.foreground(Blue);
WiredHome 32:0e4f2ae512e2 1796 display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 1797 display.cls();
WiredHome 59:fb40aad4efd4 1798 display.SetTextFontSize(1,1);
WiredHome 59:fb40aad4efd4 1799 display.puts(200,0, "Web Color Test");
WiredHome 59:fb40aad4efd4 1800 display.SetTextCursor(0,0);
WiredHome 59:fb40aad4efd4 1801 display.puts(" ");
WiredHome 59:fb40aad4efd4 1802 for (int i=0; i<16; i++)
WiredHome 59:fb40aad4efd4 1803 display.printf("%X", i&0xF);
WiredHome 59:fb40aad4efd4 1804 display.puts("\r\n0 ");
WiredHome 23:a50ded45dbaf 1805 for (int i=0; i<sizeof(WebColors)/sizeof(WebColors[0]); i++) {
WiredHome 23:a50ded45dbaf 1806 display.background(WebColors[i]);
WiredHome 23:a50ded45dbaf 1807 display.puts(" ");
WiredHome 59:fb40aad4efd4 1808 if (i % 16 == 15 && i < 255) {
WiredHome 59:fb40aad4efd4 1809 display.printf("\r\n%X ", ((i+1)/16));
WiredHome 59:fb40aad4efd4 1810 }
WiredHome 23:a50ded45dbaf 1811 }
WiredHome 23:a50ded45dbaf 1812 display.SetTextFontSize(1,1);
WiredHome 23:a50ded45dbaf 1813 }
WiredHome 23:a50ded45dbaf 1814
WiredHome 44:207594dece70 1815
WiredHome 37:f19b7e7449dc 1816 void PixelTest(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 1817 {
WiredHome 37:f19b7e7449dc 1818 int i, c, x, y;
WiredHome 37:f19b7e7449dc 1819
WiredHome 41:2956a0a221e5 1820 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1821 pc.printf("Pixel Test\r\n");
WiredHome 37:f19b7e7449dc 1822 display.background(Black);
WiredHome 37:f19b7e7449dc 1823 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 1824 display.cls();
WiredHome 37:f19b7e7449dc 1825 display.puts(0,0, "Pixel Test");
WiredHome 37:f19b7e7449dc 1826 for (i=0; i<1000; i++) {
WiredHome 37:f19b7e7449dc 1827 x = rand() % 480;
WiredHome 37:f19b7e7449dc 1828 y = 16 + rand() % (272-16);
WiredHome 37:f19b7e7449dc 1829 c = rand() % 16;
WiredHome 37:f19b7e7449dc 1830 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 37:f19b7e7449dc 1831 display.pixel(x,y, display.DOSColor(c));
WiredHome 37:f19b7e7449dc 1832 }
WiredHome 37:f19b7e7449dc 1833 }
WiredHome 37:f19b7e7449dc 1834
WiredHome 44:207594dece70 1835
WiredHome 23:a50ded45dbaf 1836 void LineTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1837 {
WiredHome 23:a50ded45dbaf 1838 int i, x, y, x2, y2;
WiredHome 23:a50ded45dbaf 1839
WiredHome 41:2956a0a221e5 1840 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1841 pc.printf("Line Test\r\n");
WiredHome 23:a50ded45dbaf 1842 display.background(Black);
WiredHome 23:a50ded45dbaf 1843 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1844 display.cls();
WiredHome 23:a50ded45dbaf 1845 display.puts(0,0, "Line Test");
WiredHome 23:a50ded45dbaf 1846 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1847 // Lines
WiredHome 23:a50ded45dbaf 1848 x = rand() % 480;
WiredHome 23:a50ded45dbaf 1849 y = rand() % 272;
WiredHome 23:a50ded45dbaf 1850 x2 = rand() % 480;
WiredHome 23:a50ded45dbaf 1851 y2 = rand() % 272;
WiredHome 23:a50ded45dbaf 1852 display.line(x,y, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1853 }
WiredHome 62:ba5d33438fda 1854 display.foreground(BrightRed);
WiredHome 62:ba5d33438fda 1855 display.foreground(BrightGreen);
WiredHome 62:ba5d33438fda 1856 display.foreground(BrightBlue);
WiredHome 62:ba5d33438fda 1857 display.line(55,50, 79,74, BrightRed);
WiredHome 62:ba5d33438fda 1858 display.line(57,50, 81,74, BrightGreen);
WiredHome 62:ba5d33438fda 1859 display.line(59,50, 83,74, BrightBlue);
WiredHome 62:ba5d33438fda 1860 // horz
WiredHome 62:ba5d33438fda 1861 display.line(30,40, 32,40, BrightRed);
WiredHome 62:ba5d33438fda 1862 display.line(30,42, 32,42, BrightGreen);
WiredHome 62:ba5d33438fda 1863 display.line(30,44, 32,44, BrightBlue);
WiredHome 62:ba5d33438fda 1864 // vert
WiredHome 62:ba5d33438fda 1865 display.line(20,40, 20,42, BrightRed);
WiredHome 62:ba5d33438fda 1866 display.line(22,40, 22,42, BrightGreen);
WiredHome 62:ba5d33438fda 1867 display.line(24,40, 24,42, BrightBlue);
WiredHome 62:ba5d33438fda 1868 // compare point to line-point
WiredHome 62:ba5d33438fda 1869 display.pixel(20,50, BrightRed);
WiredHome 62:ba5d33438fda 1870 display.pixel(22,50, BrightGreen);
WiredHome 62:ba5d33438fda 1871 display.pixel(24,50, BrightBlue);
WiredHome 62:ba5d33438fda 1872 display.line(20,52, 20,52, BrightRed);
WiredHome 62:ba5d33438fda 1873 display.line(22,52, 22,52, BrightGreen);
WiredHome 62:ba5d33438fda 1874 display.line(24,52, 24,52, BrightBlue);
WiredHome 73:f22a18707b5e 1875
WiredHome 62:ba5d33438fda 1876 // point
WiredHome 62:ba5d33438fda 1877 display.line(50,50, 50,50, Red);
WiredHome 62:ba5d33438fda 1878 display.line(52,52, 52,52, Green);
WiredHome 62:ba5d33438fda 1879 display.line(54,54, 54,54, Blue);
WiredHome 62:ba5d33438fda 1880 display.line(60,60, 60,60, BrightRed);
WiredHome 62:ba5d33438fda 1881 display.line(62,62, 62,62, BrightGreen);
WiredHome 62:ba5d33438fda 1882 display.line(64,64, 64,64, BrightBlue);
WiredHome 62:ba5d33438fda 1883 display.line(70,70, 70,70, DarkRed);
WiredHome 62:ba5d33438fda 1884 display.line(72,72, 72,72, DarkGreen);
WiredHome 62:ba5d33438fda 1885 display.line(74,74, 74,74, DarkBlue);
WiredHome 23:a50ded45dbaf 1886 }
WiredHome 23:a50ded45dbaf 1887
WiredHome 44:207594dece70 1888
WiredHome 23:a50ded45dbaf 1889 void RectangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1890 {
WiredHome 23:a50ded45dbaf 1891 int i, x1,y1, x2,y2;
WiredHome 23:a50ded45dbaf 1892
WiredHome 41:2956a0a221e5 1893 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1894 pc.printf("Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 1895 display.background(Black);
WiredHome 23:a50ded45dbaf 1896 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1897 display.cls();
WiredHome 23:a50ded45dbaf 1898 display.puts(0,0, "Rectangle Test");
WiredHome 23:a50ded45dbaf 1899 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1900 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 1901 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1902 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 1903 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1904 display.rect(x1,y1, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1905
WiredHome 23:a50ded45dbaf 1906 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1907 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1908 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1909 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1910 display.rect(x1,y1, x2,y2, FILL);
WiredHome 23:a50ded45dbaf 1911 }
WiredHome 23:a50ded45dbaf 1912 }
WiredHome 23:a50ded45dbaf 1913
WiredHome 44:207594dece70 1914
WiredHome 44:207594dece70 1915 void LayerTest(RA8875 & display, Serial & pc)
WiredHome 44:207594dece70 1916 {
WiredHome 44:207594dece70 1917 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 44:207594dece70 1918
WiredHome 44:207594dece70 1919 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1920 pc.printf("Layer Test\r\n");
WiredHome 44:207594dece70 1921
WiredHome 50:2c4f474a2453 1922 display.SelectDrawingLayer(0);
WiredHome 44:207594dece70 1923 display.background(Black);
WiredHome 44:207594dece70 1924 display.foreground(Blue);
WiredHome 44:207594dece70 1925 display.cls();
WiredHome 44:207594dece70 1926 display.puts(0,0, "Layer 0");
WiredHome 44:207594dece70 1927 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 1928 x1 = rand() % 240;
WiredHome 44:207594dece70 1929 y1 = 50 + rand() % 200;
WiredHome 44:207594dece70 1930 x2 = x1 + rand() % 100;
WiredHome 44:207594dece70 1931 y2 = y1 + rand() % 100;
WiredHome 44:207594dece70 1932 r1 = rand() % (x2 - x1)/2;
WiredHome 44:207594dece70 1933 r2 = rand() % (y2 - y1)/2;
WiredHome 44:207594dece70 1934 display.roundrect(x1,y1, x2,y2, r1,r2, display.DOSColor(i));
WiredHome 44:207594dece70 1935 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1936 wait_ms(20);
WiredHome 44:207594dece70 1937 }
WiredHome 44:207594dece70 1938 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1939 wait_ms(1000);
WiredHome 44:207594dece70 1940
WiredHome 50:2c4f474a2453 1941 display.SelectDrawingLayer(1);
WiredHome 44:207594dece70 1942 display.background(Black);
WiredHome 44:207594dece70 1943 display.foreground(Yellow);
WiredHome 44:207594dece70 1944 display.cls();
WiredHome 44:207594dece70 1945 display.puts(240,0, "Layer 1");
WiredHome 44:207594dece70 1946 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 1947 x1 = 300 + rand() % 100;
WiredHome 44:207594dece70 1948 y1 = 70 + rand() % 200;
WiredHome 44:207594dece70 1949 r1 = rand() % min(y1 - 20, 100);
WiredHome 44:207594dece70 1950 display.circle(x1,y1,r1, display.DOSColor(i));
WiredHome 44:207594dece70 1951 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1952 wait_ms(20);
WiredHome 44:207594dece70 1953 }
WiredHome 56:7a85d226ad0d 1954 display.SetLayerMode(RA8875::ShowLayer1); // Show it after the build-up
WiredHome 44:207594dece70 1955 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1956 wait_ms(2000);
WiredHome 44:207594dece70 1957
WiredHome 50:2c4f474a2453 1958 display.SelectDrawingLayer(0);
WiredHome 56:7a85d226ad0d 1959 display.SetLayerMode(RA8875::ShowLayer0); // Show Layer 0 again
WiredHome 44:207594dece70 1960 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1961 wait_ms(1000);
WiredHome 53:86d24b9480b9 1962 display.SetLayerMode(RA8875::TransparentMode); // Transparent mode
WiredHome 44:207594dece70 1963 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1964 wait_ms(1000);
WiredHome 44:207594dece70 1965 for (i=0; i<=8; i++) {
WiredHome 44:207594dece70 1966 display.SetLayerTransparency(i, 8-i);
WiredHome 44:207594dece70 1967 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1968 wait_ms(200);
WiredHome 44:207594dece70 1969 }
WiredHome 73:f22a18707b5e 1970
WiredHome 44:207594dece70 1971 // Restore before we exit
WiredHome 44:207594dece70 1972 display.SetLayerTransparency(0, 0);
WiredHome 56:7a85d226ad0d 1973 display.SetLayerMode(RA8875::ShowLayer0); // Restore to layer 0
WiredHome 44:207594dece70 1974 }
WiredHome 44:207594dece70 1975
WiredHome 44:207594dece70 1976
WiredHome 23:a50ded45dbaf 1977 void RoundRectTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1978 {
WiredHome 37:f19b7e7449dc 1979 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 23:a50ded45dbaf 1980
WiredHome 41:2956a0a221e5 1981 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1982 pc.printf("Round Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 1983 display.background(Black);
WiredHome 23:a50ded45dbaf 1984 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1985 display.cls();
WiredHome 23:a50ded45dbaf 1986 display.puts(0,0, "Rounded Rectangle Test");
WiredHome 73:f22a18707b5e 1987
WiredHome 23:a50ded45dbaf 1988 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1989 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 1990 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1991 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 1992 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 1993 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 1994 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 1995 display.roundrect(x1,y1, x2,y2, 5,8, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1996
WiredHome 23:a50ded45dbaf 1997 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1998 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1999 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 2000 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 2001 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 2002 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 2003 display.roundrect(x1,y1, x2,y2, r1,r2, FILL);
WiredHome 23:a50ded45dbaf 2004 }
WiredHome 23:a50ded45dbaf 2005 }
WiredHome 23:a50ded45dbaf 2006
WiredHome 44:207594dece70 2007
WiredHome 23:a50ded45dbaf 2008 void TriangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2009 {
WiredHome 23:a50ded45dbaf 2010 int i, x1, y1, x2, y2, x3, y3;
WiredHome 23:a50ded45dbaf 2011
WiredHome 41:2956a0a221e5 2012 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2013 pc.printf("Triangle Test\r\n");
WiredHome 23:a50ded45dbaf 2014 display.background(Black);
WiredHome 23:a50ded45dbaf 2015 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2016 display.cls();
WiredHome 23:a50ded45dbaf 2017 display.puts(0,0, "Triangle Test");
WiredHome 23:a50ded45dbaf 2018
WiredHome 23:a50ded45dbaf 2019 x1 = 150;
WiredHome 23:a50ded45dbaf 2020 y1 = 2;
WiredHome 23:a50ded45dbaf 2021 x2 = 190;
WiredHome 23:a50ded45dbaf 2022 y2 = 7;
WiredHome 23:a50ded45dbaf 2023 x3 = 170;
WiredHome 23:a50ded45dbaf 2024 y3 = 16;
WiredHome 23:a50ded45dbaf 2025 display.triangle(x1,y1, x2,y2, x3,y3);
WiredHome 23:a50ded45dbaf 2026
WiredHome 23:a50ded45dbaf 2027 x1 = 200;
WiredHome 23:a50ded45dbaf 2028 y1 = 2;
WiredHome 23:a50ded45dbaf 2029 x2 = 240;
WiredHome 23:a50ded45dbaf 2030 y2 = 7;
WiredHome 23:a50ded45dbaf 2031 x3 = 220;
WiredHome 23:a50ded45dbaf 2032 y3 = 16;
WiredHome 23:a50ded45dbaf 2033 display.filltriangle(x1,y1, x2,y2, x3,y3, BrightRed);
WiredHome 23:a50ded45dbaf 2034
WiredHome 23:a50ded45dbaf 2035 x1 = 300;
WiredHome 23:a50ded45dbaf 2036 y1 = 2;
WiredHome 23:a50ded45dbaf 2037 x2 = 340;
WiredHome 23:a50ded45dbaf 2038 y2 = 7;
WiredHome 23:a50ded45dbaf 2039 x3 = 320;
WiredHome 23:a50ded45dbaf 2040 y3 = 16;
WiredHome 23:a50ded45dbaf 2041 display.triangle(x1,y1, x2,y2, x3,y3, NOFILL);
WiredHome 23:a50ded45dbaf 2042
WiredHome 23:a50ded45dbaf 2043 x1 = 400;
WiredHome 23:a50ded45dbaf 2044 y1 = 2;
WiredHome 23:a50ded45dbaf 2045 x2 = 440;
WiredHome 23:a50ded45dbaf 2046 y2 = 7;
WiredHome 23:a50ded45dbaf 2047 x3 = 420;
WiredHome 23:a50ded45dbaf 2048 y3 = 16;
WiredHome 23:a50ded45dbaf 2049 display.triangle(x1,y1, x2,y2, x3,y3, Blue);
WiredHome 23:a50ded45dbaf 2050
WiredHome 23:a50ded45dbaf 2051 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2052 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 2053 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2054 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 2055 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2056 x3 = rand() % 240;
WiredHome 23:a50ded45dbaf 2057 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2058 display.triangle(x1,y1, x2,y2, x3,y3, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2059 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2060 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2061 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2062 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2063 x3 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 2064 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 2065 display.triangle(x1,y1, x2,y2, x3,y3, FILL);
WiredHome 23:a50ded45dbaf 2066 }
WiredHome 23:a50ded45dbaf 2067 }
WiredHome 23:a50ded45dbaf 2068
WiredHome 44:207594dece70 2069
WiredHome 23:a50ded45dbaf 2070 void CircleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2071 {
WiredHome 23:a50ded45dbaf 2072 int i, x, y, r1;
WiredHome 23:a50ded45dbaf 2073
WiredHome 41:2956a0a221e5 2074 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2075 pc.printf("Circle Test\r\n");
WiredHome 23:a50ded45dbaf 2076 display.background(Black);
WiredHome 23:a50ded45dbaf 2077 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2078 display.cls();
WiredHome 23:a50ded45dbaf 2079 display.puts(0,0, "Circle Test");
WiredHome 23:a50ded45dbaf 2080 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2081 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 2082 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2083 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2084 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 2085 display.circle(x,y,r1, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2086
WiredHome 23:a50ded45dbaf 2087 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 2088 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2089 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2090 //pc.printf(" (%d,%d) - %d FILL\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 2091 display.circle(x,y,r1, display.DOSColor(i), FILL);
WiredHome 23:a50ded45dbaf 2092 }
WiredHome 23:a50ded45dbaf 2093 }
WiredHome 23:a50ded45dbaf 2094
WiredHome 44:207594dece70 2095
WiredHome 23:a50ded45dbaf 2096 void EllipseTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 2097 {
WiredHome 23:a50ded45dbaf 2098 int i,x,y,r1,r2;
WiredHome 23:a50ded45dbaf 2099
WiredHome 41:2956a0a221e5 2100 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 2101 pc.printf("Ellipse Test\r\n");
WiredHome 23:a50ded45dbaf 2102 display.background(Black);
WiredHome 23:a50ded45dbaf 2103 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 2104 display.cls();
WiredHome 23:a50ded45dbaf 2105 display.puts(0,0, "Ellipse Test");
WiredHome 23:a50ded45dbaf 2106 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 2107 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 2108 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2109 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2110 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2111 display.ellipse(x,y,r1,r2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 2112
WiredHome 23:a50ded45dbaf 2113 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 2114 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 2115 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2116 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 2117 display.ellipse(x,y,r1,r2, FILL);
WiredHome 23:a50ded45dbaf 2118 }
WiredHome 23:a50ded45dbaf 2119 }
WiredHome 23:a50ded45dbaf 2120
WiredHome 44:207594dece70 2121
WiredHome 37:f19b7e7449dc 2122 void TestGraphicsBitmap(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 2123 {
WiredHome 37:f19b7e7449dc 2124 LocalFileSystem local("local");
WiredHome 41:2956a0a221e5 2125 if (!SuppressSlowStuff)
WiredHome 73:f22a18707b5e 2126 pc.printf("Bitmap File Load\r\n");
WiredHome 37:f19b7e7449dc 2127 display.background(Black);
WiredHome 37:f19b7e7449dc 2128 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 2129 display.cls();
WiredHome 37:f19b7e7449dc 2130 display.puts(0,0, "Graphics Test, loading /local/TestPat.bmp");
WiredHome 37:f19b7e7449dc 2131 wait(3);
WiredHome 37:f19b7e7449dc 2132
WiredHome 37:f19b7e7449dc 2133 int r = display.RenderBitmapFile(0,0, "/local/TestPat.bmp");
WiredHome 59:fb40aad4efd4 2134 if (!SuppressSlowStuff)
WiredHome 59:fb40aad4efd4 2135 pc.printf(" returned %d\r\n", r);
WiredHome 37:f19b7e7449dc 2136 }
WiredHome 37:f19b7e7449dc 2137
WiredHome 44:207594dece70 2138
WiredHome 41:2956a0a221e5 2139 void SpeedTest(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 2140 {
WiredHome 41:2956a0a221e5 2141 Timer t;
WiredHome 41:2956a0a221e5 2142 SuppressSlowStuff = true;
WiredHome 41:2956a0a221e5 2143 pc.printf("\r\nSpeedTest disables delays, runs tests, reports overall time.\r\n");
WiredHome 41:2956a0a221e5 2144 t.start();
WiredHome 41:2956a0a221e5 2145 // do stuff fast
WiredHome 41:2956a0a221e5 2146 TextCursorTest(display, pc);
WiredHome 49:c5182231d1b9 2147 TextWrapTest(display, pc);
WiredHome 41:2956a0a221e5 2148 BacklightTest(display, pc, 0);
WiredHome 41:2956a0a221e5 2149 BacklightTest2(display, pc);
WiredHome 41:2956a0a221e5 2150 ExternalFontTest(display, pc);
WiredHome 41:2956a0a221e5 2151 DOSColorTest(display, pc);
WiredHome 41:2956a0a221e5 2152 WebColorTest(display, pc);
WiredHome 41:2956a0a221e5 2153 PixelTest(display, pc);
WiredHome 41:2956a0a221e5 2154 LineTest(display, pc);
WiredHome 41:2956a0a221e5 2155 RectangleTest(display, pc);
WiredHome 41:2956a0a221e5 2156 RoundRectTest(display, pc);
WiredHome 41:2956a0a221e5 2157 TriangleTest(display, pc);
WiredHome 41:2956a0a221e5 2158 CircleTest(display, pc);
WiredHome 41:2956a0a221e5 2159 EllipseTest(display, pc);
WiredHome 44:207594dece70 2160 LayerTest(display, pc);
WiredHome 41:2956a0a221e5 2161 //TestGraphicsBitmap(display, pc);
WiredHome 41:2956a0a221e5 2162 pc.printf("SpeedTest completed in %d msec\r\n", t.read_ms());
WiredHome 73:f22a18707b5e 2163 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 2164 display.ReportPerformance(pc);
WiredHome 73:f22a18707b5e 2165 #endif
WiredHome 41:2956a0a221e5 2166 SuppressSlowStuff = false;
WiredHome 41:2956a0a221e5 2167 }
WiredHome 41:2956a0a221e5 2168
WiredHome 44:207594dece70 2169
WiredHome 41:2956a0a221e5 2170 void PrintScreen(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 2171 {
WiredHome 41:2956a0a221e5 2172 LocalFileSystem local("local");
WiredHome 41:2956a0a221e5 2173 if (!SuppressSlowStuff)
WiredHome 73:f22a18707b5e 2174 pc.printf("PrintScreen\r\n");
WiredHome 41:2956a0a221e5 2175 display.PrintScreen( 0,0, 480,272, "/local/Capture.bmp");
WiredHome 41:2956a0a221e5 2176 }
WiredHome 41:2956a0a221e5 2177
WiredHome 44:207594dece70 2178
WiredHome 23:a50ded45dbaf 2179 void RunTestSet(RA8875 & lcd, Serial & pc)
WiredHome 23:a50ded45dbaf 2180 {
WiredHome 23:a50ded45dbaf 2181 int q = 0;
WiredHome 23:a50ded45dbaf 2182 int automode = 0;
WiredHome 49:c5182231d1b9 2183 const unsigned char modelist[] = "BDWtGLlFROTPCEbw"; // auto-test in this order.
WiredHome 23:a50ded45dbaf 2184
WiredHome 23:a50ded45dbaf 2185 while(1) {
WiredHome 23:a50ded45dbaf 2186 pc.printf("\r\n"
WiredHome 41:2956a0a221e5 2187 "B - Backlight up b - backlight dim\r\n"
WiredHome 41:2956a0a221e5 2188 "D - DOS Colors W - Web Colors\r\n"
WiredHome 41:2956a0a221e5 2189 "t - text cursor G - Graphics Bitmap\r\n"
WiredHome 41:2956a0a221e5 2190 "L - Lines F - external Font\r\n"
WiredHome 41:2956a0a221e5 2191 "R - Rectangles O - rOund rectangles\r\n"
WiredHome 41:2956a0a221e5 2192 "T - Triangles P - Pixels \r\n"
WiredHome 41:2956a0a221e5 2193 "C - Circles E - Ellipses\r\n"
WiredHome 41:2956a0a221e5 2194 "A - Auto Test mode S - Speed Test\r\n"
WiredHome 41:2956a0a221e5 2195 "p - print screen r - reset \r\n"
WiredHome 49:c5182231d1b9 2196 "l - layer test w - wrapping text \r\n"
WiredHome 73:f22a18707b5e 2197 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 2198 "0 - clear performance 1 - report performance\r\n"
WiredHome 73:f22a18707b5e 2199 #endif
WiredHome 23:a50ded45dbaf 2200 "> ");
WiredHome 23:a50ded45dbaf 2201 if (automode == -1 || pc.readable()) {
WiredHome 23:a50ded45dbaf 2202 automode = -1;
WiredHome 37:f19b7e7449dc 2203 q = pc.getc();
WiredHome 37:f19b7e7449dc 2204 while (pc.readable())
WiredHome 37:f19b7e7449dc 2205 pc.getc();
WiredHome 23:a50ded45dbaf 2206 } else if (automode >= 0) {
WiredHome 23:a50ded45dbaf 2207 q = modelist[automode];
WiredHome 23:a50ded45dbaf 2208 }
WiredHome 23:a50ded45dbaf 2209 switch(q) {
WiredHome 73:f22a18707b5e 2210 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 2211 case '0':
WiredHome 41:2956a0a221e5 2212 lcd.ClearPerformance();
WiredHome 41:2956a0a221e5 2213 break;
WiredHome 41:2956a0a221e5 2214 case '1':
WiredHome 41:2956a0a221e5 2215 lcd.ReportPerformance(pc);
WiredHome 41:2956a0a221e5 2216 break;
WiredHome 73:f22a18707b5e 2217 #endif
WiredHome 23:a50ded45dbaf 2218 case 'A':
WiredHome 23:a50ded45dbaf 2219 automode = 0;
WiredHome 23:a50ded45dbaf 2220 break;
WiredHome 23:a50ded45dbaf 2221 case 'B':
WiredHome 41:2956a0a221e5 2222 BacklightTest(lcd, pc, 2);
WiredHome 23:a50ded45dbaf 2223 break;
WiredHome 23:a50ded45dbaf 2224 case 'b':
WiredHome 23:a50ded45dbaf 2225 BacklightTest2(lcd, pc);
WiredHome 23:a50ded45dbaf 2226 break;
WiredHome 23:a50ded45dbaf 2227 case 'D':
WiredHome 23:a50ded45dbaf 2228 DOSColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2229 break;
WiredHome 23:a50ded45dbaf 2230 case 'W':
WiredHome 23:a50ded45dbaf 2231 WebColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2232 break;
WiredHome 23:a50ded45dbaf 2233 case 't':
WiredHome 23:a50ded45dbaf 2234 TextCursorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2235 break;
WiredHome 49:c5182231d1b9 2236 case 'w':
WiredHome 49:c5182231d1b9 2237 TextWrapTest(lcd, pc);
WiredHome 49:c5182231d1b9 2238 break;
WiredHome 23:a50ded45dbaf 2239 case 'F':
WiredHome 23:a50ded45dbaf 2240 ExternalFontTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2241 break;
WiredHome 23:a50ded45dbaf 2242 case 'L':
WiredHome 23:a50ded45dbaf 2243 LineTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2244 break;
WiredHome 44:207594dece70 2245 case 'l':
WiredHome 44:207594dece70 2246 LayerTest(lcd, pc);
WiredHome 44:207594dece70 2247 break;
WiredHome 23:a50ded45dbaf 2248 case 'R':
WiredHome 23:a50ded45dbaf 2249 RectangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2250 break;
WiredHome 23:a50ded45dbaf 2251 case 'O':
WiredHome 23:a50ded45dbaf 2252 RoundRectTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2253 break;
WiredHome 41:2956a0a221e5 2254 case 'p':
WiredHome 41:2956a0a221e5 2255 PrintScreen(lcd, pc);
WiredHome 41:2956a0a221e5 2256 break;
WiredHome 41:2956a0a221e5 2257 case 'S':
WiredHome 41:2956a0a221e5 2258 SpeedTest(lcd, pc);
WiredHome 41:2956a0a221e5 2259 break;
WiredHome 23:a50ded45dbaf 2260 case 'T':
WiredHome 23:a50ded45dbaf 2261 TriangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2262 break;
WiredHome 37:f19b7e7449dc 2263 case 'P':
WiredHome 37:f19b7e7449dc 2264 PixelTest(lcd, pc);
WiredHome 37:f19b7e7449dc 2265 break;
WiredHome 37:f19b7e7449dc 2266 case 'G':
WiredHome 37:f19b7e7449dc 2267 TestGraphicsBitmap(lcd, pc);
WiredHome 37:f19b7e7449dc 2268 break;
WiredHome 23:a50ded45dbaf 2269 case 'C':
WiredHome 23:a50ded45dbaf 2270 CircleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2271 break;
WiredHome 23:a50ded45dbaf 2272 case 'E':
WiredHome 23:a50ded45dbaf 2273 EllipseTest(lcd, pc);
WiredHome 23:a50ded45dbaf 2274 break;
WiredHome 23:a50ded45dbaf 2275 case 'r':
WiredHome 23:a50ded45dbaf 2276 pc.printf("Resetting ...\r\n");
WiredHome 23:a50ded45dbaf 2277 wait_ms(20);
WiredHome 23:a50ded45dbaf 2278 mbed_reset();
WiredHome 23:a50ded45dbaf 2279 break;
WiredHome 23:a50ded45dbaf 2280 default:
WiredHome 23:a50ded45dbaf 2281 printf("huh?\n");
WiredHome 23:a50ded45dbaf 2282 break;
WiredHome 23:a50ded45dbaf 2283 }
WiredHome 23:a50ded45dbaf 2284 if (automode >= 0) {
WiredHome 23:a50ded45dbaf 2285 automode++;
WiredHome 23:a50ded45dbaf 2286 if (automode >= sizeof(modelist))
WiredHome 23:a50ded45dbaf 2287 automode = 0;
WiredHome 23:a50ded45dbaf 2288 wait_ms(2000);
WiredHome 23:a50ded45dbaf 2289 }
WiredHome 23:a50ded45dbaf 2290 wait_ms(200);
WiredHome 23:a50ded45dbaf 2291 }
WiredHome 23:a50ded45dbaf 2292 }
WiredHome 23:a50ded45dbaf 2293
WiredHome 23:a50ded45dbaf 2294 #endif // TESTENABLE