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

Dependents:   FRDM_RA8875_mPaint RA8875_Demo RA8875_KeyPadDemo SignalGenerator ... more

Fork of SPI_TFT by Peter Drescher

See Components - RA8875 Based Display

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

Offline Help Manual (Windows chm)

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

Committer:
WiredHome
Date:
Sun Aug 31 15:52:39 2014 +0000
Revision:
68:ab08efabfc88
Parent:
67:9f834f0ff97d
Child:
71:dcac8efd842d
Performance tuning - speeding up transactions with RA8875 via SPI.

Who changed what in which revision?

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