KSM edits to RA8875

Dependents:   Liz_Test_Code

Committer:
WiredHome
Date:
Sun Aug 31 14:37:37 2014 +0000
Revision:
66:468a11f05580
Parent:
62:ba5d33438fda
Child:
67:9f834f0ff97d
Increase the SPI clock rate by splitting the write from the read to better match the RA8875 display capabilities.

Who changed what in which revision?

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