Forked para SNOCC

Dependencies:   GPS

Dependents:   SNOCC_V1 SNOCC_V2

Fork of RA8875 by SNOCC

Committer:
WiredHome
Date:
Fri Nov 28 22:37:53 2014 +0000
Revision:
75:ca78388cfd77
Parent:
74:686faa218914
Child:
77:9206c13aa527
Finalized the KeyPad support using the RA8875 built-in keyscan support.

Who changed what in which revision?

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