KSM edits to RA8875

Dependents:   Liz_Test_Code

Committer:
WiredHome
Date:
Sun Aug 31 14:47:59 2014 +0000
Revision:
67:9f834f0ff97d
Parent:
66:468a11f05580
Child:
68:ab08efabfc88
Count idle time to improve performance metrics.

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