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

Dependents:   FRDM_RA8875_mPaint RA8875_Demo RA8875_KeyPadDemo SignalGenerator ... more

Fork of SPI_TFT by Peter Drescher

See Components - RA8875 Based Display

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

Offline Help Manual (Windows chm)

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

Committer:
WiredHome
Date:
Thu Mar 13 23:17:10 2014 +0000
Revision:
49:c5182231d1b9
Parent:
47:d96a09269f91
Child:
51:aa1f57b81da1
Create a simple test for the vertical line wrapping.

Who changed what in which revision?

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