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