Fork of David Smart's RA8875 library for the purpose of adding touch screen support

Fork of RA8875 by David Smart

Committer:
WiredHome
Date:
Sat Mar 15 17:35:51 2014 +0000
Revision:
50:2c4f474a2453
Parent:
44:207594dece70
Child:
51:aa1f57b81da1
API name change from SelectLayer to SelectDrawingLayer.

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 50:2c4f474a2453 75 RetCode_t RA8875::SelectDrawingLayer(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 29:422616aa04bd 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 50:2c4f474a2453 1159 // Set display image to Blue on Black as default
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 50:2c4f474a2453 1164 SelectDrawingLayer(1);
WiredHome 50:2c4f474a2453 1165 cls();
WiredHome 50:2c4f474a2453 1166 SelectDrawingLayer(0);
WiredHome 19:3f82c1161fd2 1167 cls();
WiredHome 19:3f82c1161fd2 1168 return noerror;
WiredHome 19:3f82c1161fd2 1169 }
WiredHome 19:3f82c1161fd2 1170
WiredHome 23:a50ded45dbaf 1171 #ifdef TESTENABLE
WiredHome 23:a50ded45dbaf 1172
WiredHome 37:f19b7e7449dc 1173 #include "Arial12x12.h"
WiredHome 37:f19b7e7449dc 1174 #include "Small_6.h"
WiredHome 37:f19b7e7449dc 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 // / / / /__________ ___________/ / / /
WiredHome 23:a50ded45dbaf 1183 // /__/ /_____________/ /_____________/ /__/
WiredHome 23:a50ded45dbaf 1184 //
WiredHome 23:a50ded45dbaf 1185 // Everything from here down is test code.
WiredHome 41:2956a0a221e5 1186 bool SuppressSlowStuff = false;
WiredHome 23:a50ded45dbaf 1187
WiredHome 44:207594dece70 1188
WiredHome 23:a50ded45dbaf 1189 void TextCursorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1190 {
WiredHome 37:f19b7e7449dc 1191 const char * iCursor = "The I-Beam cursor should be visible for this text.\r\n";
WiredHome 37:f19b7e7449dc 1192 const char * uCursor = "The Underscore cursor should be visible for this text.\r\n";
WiredHome 37:f19b7e7449dc 1193 const char * bCursor = "The Block cursor should be visible for this text.\r\n";
WiredHome 37:f19b7e7449dc 1194 const char * bbCursor = "The Blinking Block cursor should be visible for this text.\r\n";
WiredHome 23:a50ded45dbaf 1195 const char * p;
WiredHome 41:2956a0a221e5 1196 int delay = 100;
WiredHome 23:a50ded45dbaf 1197
WiredHome 41:2956a0a221e5 1198 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1199 pc.printf("Text Cursor Test\r\n");
WiredHome 41:2956a0a221e5 1200 else
WiredHome 41:2956a0a221e5 1201 delay = 0;
WiredHome 23:a50ded45dbaf 1202 display.background(Black);
WiredHome 23:a50ded45dbaf 1203 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1204 display.cls();
WiredHome 25:9556a3a9b7cc 1205 display.Backlight_u8(255);
WiredHome 23:a50ded45dbaf 1206 display.puts(0,0, "Text Cursor Test.");
WiredHome 23:a50ded45dbaf 1207
WiredHome 23:a50ded45dbaf 1208 // visible, non-blinking
WiredHome 24:8ca861acf12d 1209 display.SetTextCursor(0,20);
WiredHome 24:8ca861acf12d 1210 display.SetTextCursorControl(IBEAM, false);
WiredHome 24:8ca861acf12d 1211 p = iCursor;
WiredHome 23:a50ded45dbaf 1212 while (*p) {
WiredHome 24:8ca861acf12d 1213 display._putc(*p++);
WiredHome 41:2956a0a221e5 1214 wait_ms(delay);
WiredHome 24:8ca861acf12d 1215 }
WiredHome 24:8ca861acf12d 1216
WiredHome 24:8ca861acf12d 1217 display.SetTextCursorControl(UNDER, false);
WiredHome 24:8ca861acf12d 1218 p = uCursor;
WiredHome 24:8ca861acf12d 1219 while (*p) {
WiredHome 24:8ca861acf12d 1220 display._putc(*p++);
WiredHome 41:2956a0a221e5 1221 wait_ms(delay);
WiredHome 23:a50ded45dbaf 1222 }
WiredHome 24:8ca861acf12d 1223
WiredHome 24:8ca861acf12d 1224 display.SetTextCursorControl(BLOCK, false);
WiredHome 24:8ca861acf12d 1225 p = bCursor;
WiredHome 24:8ca861acf12d 1226 while (*p) {
WiredHome 24:8ca861acf12d 1227 display._putc(*p++);
WiredHome 41:2956a0a221e5 1228 wait_ms(delay);
WiredHome 24:8ca861acf12d 1229 }
WiredHome 24:8ca861acf12d 1230
WiredHome 24:8ca861acf12d 1231 display.SetTextCursorControl(BLOCK, true);
WiredHome 24:8ca861acf12d 1232 p = bbCursor;
WiredHome 24:8ca861acf12d 1233 while (*p) {
WiredHome 24:8ca861acf12d 1234 display._putc(*p++);
WiredHome 41:2956a0a221e5 1235 wait_ms(delay);
WiredHome 24:8ca861acf12d 1236 }
WiredHome 41:2956a0a221e5 1237 wait_ms(delay * 20);
WiredHome 24:8ca861acf12d 1238 display.SetTextCursorControl(NOCURSOR, false);
WiredHome 23:a50ded45dbaf 1239 }
WiredHome 23:a50ded45dbaf 1240
WiredHome 44:207594dece70 1241
WiredHome 23:a50ded45dbaf 1242 void BacklightTest(RA8875 & display, Serial & pc, float ramptime)
WiredHome 23:a50ded45dbaf 1243 {
WiredHome 29:422616aa04bd 1244 char buf[60];
WiredHome 41:2956a0a221e5 1245 unsigned int w = (ramptime * 1000)/ 256;
WiredHome 41:2956a0a221e5 1246 int delay = 200;
WiredHome 41:2956a0a221e5 1247
WiredHome 41:2956a0a221e5 1248 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1249 pc.printf("Backlight Test - ramp over %f sec.\r\n", ramptime);
WiredHome 41:2956a0a221e5 1250 else {
WiredHome 41:2956a0a221e5 1251 delay = 0;
WiredHome 41:2956a0a221e5 1252 w = 0;
WiredHome 41:2956a0a221e5 1253 }
WiredHome 23:a50ded45dbaf 1254 display.Backlight_u8(0);
WiredHome 29:422616aa04bd 1255 display.background(White);
WiredHome 23:a50ded45dbaf 1256 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1257 display.cls();
WiredHome 41:2956a0a221e5 1258 wait_ms(delay);
WiredHome 23:a50ded45dbaf 1259 display.puts(0,0, "RA8875 Backlight Test - Ramp up.");
WiredHome 38:38d503b4fad6 1260 for (int i=0; i <= 255; i++) {
WiredHome 29:422616aa04bd 1261 sprintf(buf, "%3d, %4d", i, w);
WiredHome 37:f19b7e7449dc 1262 display.puts(100,100,buf);
WiredHome 23:a50ded45dbaf 1263 display.Backlight_u8(i);
WiredHome 29:422616aa04bd 1264 wait_ms(w);
WiredHome 23:a50ded45dbaf 1265 }
WiredHome 23:a50ded45dbaf 1266 }
WiredHome 23:a50ded45dbaf 1267
WiredHome 44:207594dece70 1268
WiredHome 23:a50ded45dbaf 1269 void BacklightTest2(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1270 {
WiredHome 41:2956a0a221e5 1271 int delay = 20;
WiredHome 41:2956a0a221e5 1272
WiredHome 41:2956a0a221e5 1273 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1274 pc.printf("Backlight Test 2\r\n");
WiredHome 41:2956a0a221e5 1275 else
WiredHome 41:2956a0a221e5 1276 delay = 0;
WiredHome 41:2956a0a221e5 1277
WiredHome 23:a50ded45dbaf 1278 // Dim it out at the end of the tests.
WiredHome 37:f19b7e7449dc 1279 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1280 display.puts(0,0, "Ramp Backlight down.");
WiredHome 23:a50ded45dbaf 1281 // Ramp it off
WiredHome 23:a50ded45dbaf 1282 for (int i=255; i != 0; i--) {
WiredHome 23:a50ded45dbaf 1283 display.Backlight_u8(i);
WiredHome 41:2956a0a221e5 1284 wait_ms(delay);
WiredHome 23:a50ded45dbaf 1285 }
WiredHome 23:a50ded45dbaf 1286 display.Backlight_u8(0);
WiredHome 23:a50ded45dbaf 1287 }
WiredHome 23:a50ded45dbaf 1288
WiredHome 44:207594dece70 1289
WiredHome 23:a50ded45dbaf 1290 void ExternalFontTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1291 {
WiredHome 41:2956a0a221e5 1292 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1293 pc.printf("External Font Test\r\n");
WiredHome 23:a50ded45dbaf 1294 display.background(Black);
WiredHome 23:a50ded45dbaf 1295 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1296 display.cls();
WiredHome 23:a50ded45dbaf 1297 display.Backlight(1);
WiredHome 37:f19b7e7449dc 1298 display.puts(0,0, "External Font Test.");
WiredHome 37:f19b7e7449dc 1299
WiredHome 37:f19b7e7449dc 1300 display.set_font(Small_6);
WiredHome 37:f19b7e7449dc 1301 display.puts(0,30, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 37:f19b7e7449dc 1302
WiredHome 23:a50ded45dbaf 1303 display.set_font(Arial12x12);
WiredHome 37:f19b7e7449dc 1304 display.puts("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 37:f19b7e7449dc 1305 display.set_font(); // restore to internal
WiredHome 37:f19b7e7449dc 1306
WiredHome 37:f19b7e7449dc 1307 display.puts("Normal font again.");
WiredHome 37:f19b7e7449dc 1308 //display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 1309 }
WiredHome 23:a50ded45dbaf 1310
WiredHome 44:207594dece70 1311
WiredHome 23:a50ded45dbaf 1312 void DOSColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1313 {
WiredHome 41:2956a0a221e5 1314 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1315 pc.printf("DOS Color Test\r\n");
WiredHome 23:a50ded45dbaf 1316 display.background(Black);
WiredHome 23:a50ded45dbaf 1317 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1318 display.cls();
WiredHome 23:a50ded45dbaf 1319 display.puts(0,0, "DOS Colors - Fore");
WiredHome 23:a50ded45dbaf 1320 display.puts(280,0, "Back");
WiredHome 23:a50ded45dbaf 1321 display.background(Gray);
WiredHome 23:a50ded45dbaf 1322 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1323 display.foreground(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1324 display.puts(160, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 1325 display.background(Black);
WiredHome 23:a50ded45dbaf 1326 }
WiredHome 23:a50ded45dbaf 1327 display.foreground(White);
WiredHome 23:a50ded45dbaf 1328 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1329 display.background(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1330 display.puts(360, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 1331 display.foreground(White);
WiredHome 23:a50ded45dbaf 1332 }
WiredHome 23:a50ded45dbaf 1333 }
WiredHome 23:a50ded45dbaf 1334
WiredHome 44:207594dece70 1335
WiredHome 23:a50ded45dbaf 1336 void WebColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1337 {
WiredHome 41:2956a0a221e5 1338 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1339 pc.printf("Web Color Test\r\n");
WiredHome 23:a50ded45dbaf 1340 display.background(Black);
WiredHome 23:a50ded45dbaf 1341 display.foreground(Blue);
WiredHome 32:0e4f2ae512e2 1342 display.window(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 1343 display.cls();
WiredHome 23:a50ded45dbaf 1344 display.puts(0,0, "Web Color Test\r\n");
WiredHome 23:a50ded45dbaf 1345 display.SetTextFontSize(1,2);
WiredHome 23:a50ded45dbaf 1346 for (int i=0; i<sizeof(WebColors)/sizeof(WebColors[0]); i++) {
WiredHome 23:a50ded45dbaf 1347 display.background(WebColors[i]);
WiredHome 23:a50ded45dbaf 1348 display.puts(" ");
WiredHome 23:a50ded45dbaf 1349 if (i % 36 == 35)
WiredHome 23:a50ded45dbaf 1350 display.puts("\r\n");
WiredHome 23:a50ded45dbaf 1351 }
WiredHome 23:a50ded45dbaf 1352 display.SetTextFontSize(1,1);
WiredHome 23:a50ded45dbaf 1353 }
WiredHome 23:a50ded45dbaf 1354
WiredHome 44:207594dece70 1355
WiredHome 37:f19b7e7449dc 1356 void PixelTest(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 1357 {
WiredHome 37:f19b7e7449dc 1358 int i, c, x, y;
WiredHome 37:f19b7e7449dc 1359
WiredHome 41:2956a0a221e5 1360 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1361 pc.printf("Pixel Test\r\n");
WiredHome 37:f19b7e7449dc 1362 display.background(Black);
WiredHome 37:f19b7e7449dc 1363 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 1364 display.cls();
WiredHome 37:f19b7e7449dc 1365 display.puts(0,0, "Pixel Test");
WiredHome 37:f19b7e7449dc 1366 for (i=0; i<1000; i++) {
WiredHome 37:f19b7e7449dc 1367 x = rand() % 480;
WiredHome 37:f19b7e7449dc 1368 y = 16 + rand() % (272-16);
WiredHome 37:f19b7e7449dc 1369 c = rand() % 16;
WiredHome 37:f19b7e7449dc 1370 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 37:f19b7e7449dc 1371 display.pixel(x,y, display.DOSColor(c));
WiredHome 37:f19b7e7449dc 1372 }
WiredHome 37:f19b7e7449dc 1373 }
WiredHome 37:f19b7e7449dc 1374
WiredHome 44:207594dece70 1375
WiredHome 23:a50ded45dbaf 1376 void LineTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1377 {
WiredHome 23:a50ded45dbaf 1378 int i, x, y, x2, y2;
WiredHome 23:a50ded45dbaf 1379
WiredHome 41:2956a0a221e5 1380 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1381 pc.printf("Line Test\r\n");
WiredHome 23:a50ded45dbaf 1382 display.background(Black);
WiredHome 23:a50ded45dbaf 1383 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1384 display.cls();
WiredHome 23:a50ded45dbaf 1385 display.puts(0,0, "Line Test");
WiredHome 23:a50ded45dbaf 1386 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1387 // Lines
WiredHome 23:a50ded45dbaf 1388 x = rand() % 480;
WiredHome 23:a50ded45dbaf 1389 y = rand() % 272;
WiredHome 23:a50ded45dbaf 1390 x2 = rand() % 480;
WiredHome 23:a50ded45dbaf 1391 y2 = rand() % 272;
WiredHome 23:a50ded45dbaf 1392 display.line(x,y, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1393 }
WiredHome 23:a50ded45dbaf 1394 }
WiredHome 23:a50ded45dbaf 1395
WiredHome 44:207594dece70 1396
WiredHome 23:a50ded45dbaf 1397 void RectangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1398 {
WiredHome 23:a50ded45dbaf 1399 int i, x1,y1, x2,y2;
WiredHome 23:a50ded45dbaf 1400
WiredHome 41:2956a0a221e5 1401 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1402 pc.printf("Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 1403 display.background(Black);
WiredHome 23:a50ded45dbaf 1404 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1405 display.cls();
WiredHome 23:a50ded45dbaf 1406 display.puts(0,0, "Rectangle Test");
WiredHome 23:a50ded45dbaf 1407 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1408 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 1409 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1410 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 1411 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1412 display.rect(x1,y1, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1413
WiredHome 23:a50ded45dbaf 1414 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1415 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1416 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1417 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1418 display.rect(x1,y1, x2,y2, FILL);
WiredHome 23:a50ded45dbaf 1419 }
WiredHome 23:a50ded45dbaf 1420 }
WiredHome 23:a50ded45dbaf 1421
WiredHome 44:207594dece70 1422
WiredHome 44:207594dece70 1423 void LayerTest(RA8875 & display, Serial & pc)
WiredHome 44:207594dece70 1424 {
WiredHome 44:207594dece70 1425 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 44:207594dece70 1426
WiredHome 44:207594dece70 1427 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1428 pc.printf("Layer Test\r\n");
WiredHome 44:207594dece70 1429
WiredHome 50:2c4f474a2453 1430 display.SelectDrawingLayer(0);
WiredHome 44:207594dece70 1431 display.background(Black);
WiredHome 44:207594dece70 1432 display.foreground(Blue);
WiredHome 44:207594dece70 1433 display.cls();
WiredHome 44:207594dece70 1434 display.puts(0,0, "Layer 0");
WiredHome 44:207594dece70 1435 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 1436 x1 = rand() % 240;
WiredHome 44:207594dece70 1437 y1 = 50 + rand() % 200;
WiredHome 44:207594dece70 1438 x2 = x1 + rand() % 100;
WiredHome 44:207594dece70 1439 y2 = y1 + rand() % 100;
WiredHome 44:207594dece70 1440 r1 = rand() % (x2 - x1)/2;
WiredHome 44:207594dece70 1441 r2 = rand() % (y2 - y1)/2;
WiredHome 44:207594dece70 1442 display.roundrect(x1,y1, x2,y2, r1,r2, display.DOSColor(i));
WiredHome 44:207594dece70 1443 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1444 wait_ms(20);
WiredHome 44:207594dece70 1445 }
WiredHome 44:207594dece70 1446 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1447 wait_ms(1000);
WiredHome 44:207594dece70 1448
WiredHome 50:2c4f474a2453 1449 display.SelectDrawingLayer(1);
WiredHome 44:207594dece70 1450 display.background(Black);
WiredHome 44:207594dece70 1451 display.foreground(Yellow);
WiredHome 44:207594dece70 1452 display.cls();
WiredHome 44:207594dece70 1453 display.puts(240,0, "Layer 1");
WiredHome 44:207594dece70 1454 for (i=0; i<16; i++) {
WiredHome 44:207594dece70 1455 x1 = 300 + rand() % 100;
WiredHome 44:207594dece70 1456 y1 = 70 + rand() % 200;
WiredHome 44:207594dece70 1457 r1 = rand() % min(y1 - 20, 100);
WiredHome 44:207594dece70 1458 display.circle(x1,y1,r1, display.DOSColor(i));
WiredHome 44:207594dece70 1459 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1460 wait_ms(20);
WiredHome 44:207594dece70 1461 }
WiredHome 44:207594dece70 1462 display.SetLayerMode(1); // Show it after the build-up
WiredHome 44:207594dece70 1463 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1464 wait_ms(2000);
WiredHome 44:207594dece70 1465
WiredHome 50:2c4f474a2453 1466 display.SelectDrawingLayer(0);
WiredHome 44:207594dece70 1467 display.SetLayerMode(0); // Show Layer 0 again
WiredHome 44:207594dece70 1468 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1469 wait_ms(1000);
WiredHome 44:207594dece70 1470 display.SetLayerMode(3); // Transparent mode
WiredHome 44:207594dece70 1471 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1472 wait_ms(1000);
WiredHome 44:207594dece70 1473 for (i=0; i<=8; i++) {
WiredHome 44:207594dece70 1474 display.SetLayerTransparency(i, 8-i);
WiredHome 44:207594dece70 1475 if (!SuppressSlowStuff)
WiredHome 44:207594dece70 1476 wait_ms(200);
WiredHome 44:207594dece70 1477 }
WiredHome 44:207594dece70 1478
WiredHome 44:207594dece70 1479 // Restore before we exit
WiredHome 44:207594dece70 1480 display.SetLayerTransparency(0, 0);
WiredHome 44:207594dece70 1481 display.SetLayerMode(0); // Restore to layer 0
WiredHome 44:207594dece70 1482 }
WiredHome 44:207594dece70 1483
WiredHome 44:207594dece70 1484
WiredHome 23:a50ded45dbaf 1485 void RoundRectTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1486 {
WiredHome 37:f19b7e7449dc 1487 loc_t i, x1,y1, x2,y2, r1,r2;
WiredHome 23:a50ded45dbaf 1488
WiredHome 41:2956a0a221e5 1489 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1490 pc.printf("Round Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 1491 display.background(Black);
WiredHome 23:a50ded45dbaf 1492 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1493 display.cls();
WiredHome 23:a50ded45dbaf 1494 display.puts(0,0, "Rounded Rectangle Test");
WiredHome 23:a50ded45dbaf 1495
WiredHome 23:a50ded45dbaf 1496 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1497 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 1498 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1499 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 1500 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 1501 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 1502 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 1503 display.roundrect(x1,y1, x2,y2, 5,8, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1504
WiredHome 23:a50ded45dbaf 1505 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1506 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1507 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 1508 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 1509 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 1510 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 1511 display.roundrect(x1,y1, x2,y2, r1,r2, FILL);
WiredHome 23:a50ded45dbaf 1512 }
WiredHome 23:a50ded45dbaf 1513 }
WiredHome 23:a50ded45dbaf 1514
WiredHome 44:207594dece70 1515
WiredHome 23:a50ded45dbaf 1516 void TriangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1517 {
WiredHome 23:a50ded45dbaf 1518 int i, x1, y1, x2, y2, x3, y3;
WiredHome 23:a50ded45dbaf 1519
WiredHome 41:2956a0a221e5 1520 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1521 pc.printf("Triangle Test\r\n");
WiredHome 23:a50ded45dbaf 1522 display.background(Black);
WiredHome 23:a50ded45dbaf 1523 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1524 display.cls();
WiredHome 23:a50ded45dbaf 1525 display.puts(0,0, "Triangle Test");
WiredHome 23:a50ded45dbaf 1526
WiredHome 23:a50ded45dbaf 1527 x1 = 150;
WiredHome 23:a50ded45dbaf 1528 y1 = 2;
WiredHome 23:a50ded45dbaf 1529 x2 = 190;
WiredHome 23:a50ded45dbaf 1530 y2 = 7;
WiredHome 23:a50ded45dbaf 1531 x3 = 170;
WiredHome 23:a50ded45dbaf 1532 y3 = 16;
WiredHome 23:a50ded45dbaf 1533 display.triangle(x1,y1, x2,y2, x3,y3);
WiredHome 23:a50ded45dbaf 1534
WiredHome 23:a50ded45dbaf 1535 x1 = 200;
WiredHome 23:a50ded45dbaf 1536 y1 = 2;
WiredHome 23:a50ded45dbaf 1537 x2 = 240;
WiredHome 23:a50ded45dbaf 1538 y2 = 7;
WiredHome 23:a50ded45dbaf 1539 x3 = 220;
WiredHome 23:a50ded45dbaf 1540 y3 = 16;
WiredHome 23:a50ded45dbaf 1541 display.filltriangle(x1,y1, x2,y2, x3,y3, BrightRed);
WiredHome 23:a50ded45dbaf 1542
WiredHome 23:a50ded45dbaf 1543 x1 = 300;
WiredHome 23:a50ded45dbaf 1544 y1 = 2;
WiredHome 23:a50ded45dbaf 1545 x2 = 340;
WiredHome 23:a50ded45dbaf 1546 y2 = 7;
WiredHome 23:a50ded45dbaf 1547 x3 = 320;
WiredHome 23:a50ded45dbaf 1548 y3 = 16;
WiredHome 23:a50ded45dbaf 1549 display.triangle(x1,y1, x2,y2, x3,y3, NOFILL);
WiredHome 23:a50ded45dbaf 1550
WiredHome 23:a50ded45dbaf 1551 x1 = 400;
WiredHome 23:a50ded45dbaf 1552 y1 = 2;
WiredHome 23:a50ded45dbaf 1553 x2 = 440;
WiredHome 23:a50ded45dbaf 1554 y2 = 7;
WiredHome 23:a50ded45dbaf 1555 x3 = 420;
WiredHome 23:a50ded45dbaf 1556 y3 = 16;
WiredHome 23:a50ded45dbaf 1557 display.triangle(x1,y1, x2,y2, x3,y3, Blue);
WiredHome 23:a50ded45dbaf 1558
WiredHome 23:a50ded45dbaf 1559 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1560 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 1561 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1562 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 1563 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1564 x3 = rand() % 240;
WiredHome 23:a50ded45dbaf 1565 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1566 display.triangle(x1,y1, x2,y2, x3,y3, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1567 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1568 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1569 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1570 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1571 x3 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1572 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1573 display.triangle(x1,y1, x2,y2, x3,y3, FILL);
WiredHome 23:a50ded45dbaf 1574 }
WiredHome 23:a50ded45dbaf 1575 }
WiredHome 23:a50ded45dbaf 1576
WiredHome 44:207594dece70 1577
WiredHome 23:a50ded45dbaf 1578 void CircleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1579 {
WiredHome 23:a50ded45dbaf 1580 int i, x, y, r1;
WiredHome 23:a50ded45dbaf 1581
WiredHome 41:2956a0a221e5 1582 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1583 pc.printf("Circle Test\r\n");
WiredHome 23:a50ded45dbaf 1584 display.background(Black);
WiredHome 23:a50ded45dbaf 1585 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1586 display.cls();
WiredHome 23:a50ded45dbaf 1587 display.puts(0,0, "Circle Test");
WiredHome 23:a50ded45dbaf 1588 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1589 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 1590 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 1591 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1592 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 1593 display.circle(x,y,r1, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1594
WiredHome 23:a50ded45dbaf 1595 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 1596 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 1597 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1598 //pc.printf(" (%d,%d) - %d FILL\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 1599 display.circle(x,y,r1, display.DOSColor(i), FILL);
WiredHome 23:a50ded45dbaf 1600 }
WiredHome 23:a50ded45dbaf 1601 }
WiredHome 23:a50ded45dbaf 1602
WiredHome 44:207594dece70 1603
WiredHome 23:a50ded45dbaf 1604 void EllipseTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1605 {
WiredHome 23:a50ded45dbaf 1606 int i,x,y,r1,r2;
WiredHome 23:a50ded45dbaf 1607
WiredHome 41:2956a0a221e5 1608 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1609 pc.printf("Ellipse Test\r\n");
WiredHome 23:a50ded45dbaf 1610 display.background(Black);
WiredHome 23:a50ded45dbaf 1611 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1612 display.cls();
WiredHome 23:a50ded45dbaf 1613 display.puts(0,0, "Ellipse Test");
WiredHome 23:a50ded45dbaf 1614 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1615 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 1616 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 1617 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1618 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1619 display.ellipse(x,y,r1,r2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1620
WiredHome 23:a50ded45dbaf 1621 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 1622 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 1623 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1624 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1625 display.ellipse(x,y,r1,r2, FILL);
WiredHome 23:a50ded45dbaf 1626 }
WiredHome 23:a50ded45dbaf 1627 }
WiredHome 23:a50ded45dbaf 1628
WiredHome 44:207594dece70 1629
WiredHome 37:f19b7e7449dc 1630 void TestGraphicsBitmap(RA8875 & display, Serial & pc)
WiredHome 37:f19b7e7449dc 1631 {
WiredHome 37:f19b7e7449dc 1632 LocalFileSystem local("local");
WiredHome 41:2956a0a221e5 1633 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1634 pc.printf("Bitmap File Load\r\n");
WiredHome 37:f19b7e7449dc 1635 display.background(Black);
WiredHome 37:f19b7e7449dc 1636 display.foreground(Blue);
WiredHome 37:f19b7e7449dc 1637 display.cls();
WiredHome 37:f19b7e7449dc 1638 display.puts(0,0, "Graphics Test, loading /local/TestPat.bmp");
WiredHome 37:f19b7e7449dc 1639 wait(3);
WiredHome 37:f19b7e7449dc 1640
WiredHome 37:f19b7e7449dc 1641 int r = display.RenderBitmapFile(0,0, "/local/TestPat.bmp");
WiredHome 37:f19b7e7449dc 1642 }
WiredHome 37:f19b7e7449dc 1643
WiredHome 44:207594dece70 1644
WiredHome 41:2956a0a221e5 1645 void SpeedTest(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 1646 {
WiredHome 41:2956a0a221e5 1647 Timer t;
WiredHome 41:2956a0a221e5 1648 SuppressSlowStuff = true;
WiredHome 41:2956a0a221e5 1649 pc.printf("\r\nSpeedTest disables delays, runs tests, reports overall time.\r\n");
WiredHome 41:2956a0a221e5 1650 t.start();
WiredHome 41:2956a0a221e5 1651 // do stuff fast
WiredHome 41:2956a0a221e5 1652 TextCursorTest(display, pc);
WiredHome 41:2956a0a221e5 1653 BacklightTest(display, pc, 0);
WiredHome 41:2956a0a221e5 1654 BacklightTest2(display, pc);
WiredHome 41:2956a0a221e5 1655 ExternalFontTest(display, pc);
WiredHome 41:2956a0a221e5 1656 DOSColorTest(display, pc);
WiredHome 41:2956a0a221e5 1657 WebColorTest(display, pc);
WiredHome 41:2956a0a221e5 1658 PixelTest(display, pc);
WiredHome 41:2956a0a221e5 1659 LineTest(display, pc);
WiredHome 41:2956a0a221e5 1660 RectangleTest(display, pc);
WiredHome 41:2956a0a221e5 1661 RoundRectTest(display, pc);
WiredHome 41:2956a0a221e5 1662 TriangleTest(display, pc);
WiredHome 41:2956a0a221e5 1663 CircleTest(display, pc);
WiredHome 41:2956a0a221e5 1664 EllipseTest(display, pc);
WiredHome 44:207594dece70 1665 LayerTest(display, pc);
WiredHome 41:2956a0a221e5 1666 //TestGraphicsBitmap(display, pc);
WiredHome 41:2956a0a221e5 1667 pc.printf("SpeedTest completed in %d msec\r\n", t.read_ms());
WiredHome 44:207594dece70 1668 #ifdef PERF_METRICS
WiredHome 41:2956a0a221e5 1669 display.ReportPerformance(pc);
WiredHome 41:2956a0a221e5 1670 #endif
WiredHome 41:2956a0a221e5 1671 SuppressSlowStuff = false;
WiredHome 41:2956a0a221e5 1672 }
WiredHome 41:2956a0a221e5 1673
WiredHome 44:207594dece70 1674
WiredHome 41:2956a0a221e5 1675 void PrintScreen(RA8875 & display, Serial & pc)
WiredHome 41:2956a0a221e5 1676 {
WiredHome 41:2956a0a221e5 1677 LocalFileSystem local("local");
WiredHome 41:2956a0a221e5 1678 if (!SuppressSlowStuff)
WiredHome 41:2956a0a221e5 1679 pc.printf("PrintScreen\r\n");
WiredHome 41:2956a0a221e5 1680 display.PrintScreen( 0,0, 480,272, "/local/Capture.bmp");
WiredHome 41:2956a0a221e5 1681 }
WiredHome 41:2956a0a221e5 1682
WiredHome 44:207594dece70 1683
WiredHome 23:a50ded45dbaf 1684 void RunTestSet(RA8875 & lcd, Serial & pc)
WiredHome 23:a50ded45dbaf 1685 {
WiredHome 23:a50ded45dbaf 1686 int q = 0;
WiredHome 23:a50ded45dbaf 1687 int automode = 0;
WiredHome 44:207594dece70 1688 const unsigned char modelist[] = "BDWtGLlFROTPCEb"; // auto-test in this order.
WiredHome 23:a50ded45dbaf 1689
WiredHome 23:a50ded45dbaf 1690 while(1) {
WiredHome 23:a50ded45dbaf 1691 pc.printf("\r\n"
WiredHome 41:2956a0a221e5 1692 "B - Backlight up b - backlight dim\r\n"
WiredHome 41:2956a0a221e5 1693 "D - DOS Colors W - Web Colors\r\n"
WiredHome 41:2956a0a221e5 1694 "t - text cursor G - Graphics Bitmap\r\n"
WiredHome 41:2956a0a221e5 1695 "L - Lines F - external Font\r\n"
WiredHome 41:2956a0a221e5 1696 "R - Rectangles O - rOund rectangles\r\n"
WiredHome 41:2956a0a221e5 1697 "T - Triangles P - Pixels \r\n"
WiredHome 41:2956a0a221e5 1698 "C - Circles E - Ellipses\r\n"
WiredHome 41:2956a0a221e5 1699 "A - Auto Test mode S - Speed Test\r\n"
WiredHome 41:2956a0a221e5 1700 "p - print screen r - reset \r\n"
WiredHome 44:207594dece70 1701 "l - layer test \r\n"
WiredHome 41:2956a0a221e5 1702 #ifdef DEBUG
WiredHome 41:2956a0a221e5 1703 "0 - clear performance 1 - report performance\r\n"
WiredHome 41:2956a0a221e5 1704 #endif
WiredHome 23:a50ded45dbaf 1705 "> ");
WiredHome 23:a50ded45dbaf 1706 if (automode == -1 || pc.readable()) {
WiredHome 23:a50ded45dbaf 1707 automode = -1;
WiredHome 37:f19b7e7449dc 1708 q = pc.getc();
WiredHome 37:f19b7e7449dc 1709 while (pc.readable())
WiredHome 37:f19b7e7449dc 1710 pc.getc();
WiredHome 23:a50ded45dbaf 1711 } else if (automode >= 0) {
WiredHome 23:a50ded45dbaf 1712 q = modelist[automode];
WiredHome 23:a50ded45dbaf 1713 }
WiredHome 23:a50ded45dbaf 1714 switch(q) {
WiredHome 41:2956a0a221e5 1715 #ifdef DEBUG
WiredHome 41:2956a0a221e5 1716 case '0':
WiredHome 41:2956a0a221e5 1717 lcd.ClearPerformance();
WiredHome 41:2956a0a221e5 1718 break;
WiredHome 41:2956a0a221e5 1719 case '1':
WiredHome 41:2956a0a221e5 1720 lcd.ReportPerformance(pc);
WiredHome 41:2956a0a221e5 1721 break;
WiredHome 41:2956a0a221e5 1722 #endif
WiredHome 23:a50ded45dbaf 1723 case 'A':
WiredHome 23:a50ded45dbaf 1724 automode = 0;
WiredHome 23:a50ded45dbaf 1725 break;
WiredHome 23:a50ded45dbaf 1726 case 'B':
WiredHome 41:2956a0a221e5 1727 BacklightTest(lcd, pc, 2);
WiredHome 23:a50ded45dbaf 1728 break;
WiredHome 23:a50ded45dbaf 1729 case 'b':
WiredHome 23:a50ded45dbaf 1730 BacklightTest2(lcd, pc);
WiredHome 23:a50ded45dbaf 1731 break;
WiredHome 23:a50ded45dbaf 1732 case 'D':
WiredHome 23:a50ded45dbaf 1733 DOSColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1734 break;
WiredHome 23:a50ded45dbaf 1735 case 'W':
WiredHome 23:a50ded45dbaf 1736 WebColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1737 break;
WiredHome 23:a50ded45dbaf 1738 case 't':
WiredHome 23:a50ded45dbaf 1739 TextCursorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1740 break;
WiredHome 23:a50ded45dbaf 1741 case 'F':
WiredHome 23:a50ded45dbaf 1742 ExternalFontTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1743 break;
WiredHome 23:a50ded45dbaf 1744 case 'L':
WiredHome 23:a50ded45dbaf 1745 LineTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1746 break;
WiredHome 44:207594dece70 1747 case 'l':
WiredHome 44:207594dece70 1748 LayerTest(lcd, pc);
WiredHome 44:207594dece70 1749 break;
WiredHome 23:a50ded45dbaf 1750 case 'R':
WiredHome 23:a50ded45dbaf 1751 RectangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1752 break;
WiredHome 23:a50ded45dbaf 1753 case 'O':
WiredHome 23:a50ded45dbaf 1754 RoundRectTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1755 break;
WiredHome 41:2956a0a221e5 1756 case 'p':
WiredHome 41:2956a0a221e5 1757 PrintScreen(lcd, pc);
WiredHome 41:2956a0a221e5 1758 break;
WiredHome 41:2956a0a221e5 1759 case 'S':
WiredHome 41:2956a0a221e5 1760 SpeedTest(lcd, pc);
WiredHome 41:2956a0a221e5 1761 break;
WiredHome 23:a50ded45dbaf 1762 case 'T':
WiredHome 23:a50ded45dbaf 1763 TriangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1764 break;
WiredHome 37:f19b7e7449dc 1765 case 'P':
WiredHome 37:f19b7e7449dc 1766 PixelTest(lcd, pc);
WiredHome 37:f19b7e7449dc 1767 break;
WiredHome 37:f19b7e7449dc 1768 case 'G':
WiredHome 37:f19b7e7449dc 1769 TestGraphicsBitmap(lcd, pc);
WiredHome 37:f19b7e7449dc 1770 break;
WiredHome 23:a50ded45dbaf 1771 case 'C':
WiredHome 23:a50ded45dbaf 1772 CircleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1773 break;
WiredHome 23:a50ded45dbaf 1774 case 'E':
WiredHome 23:a50ded45dbaf 1775 EllipseTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1776 break;
WiredHome 23:a50ded45dbaf 1777 case 'r':
WiredHome 23:a50ded45dbaf 1778 pc.printf("Resetting ...\r\n");
WiredHome 23:a50ded45dbaf 1779 wait_ms(20);
WiredHome 23:a50ded45dbaf 1780 mbed_reset();
WiredHome 23:a50ded45dbaf 1781 break;
WiredHome 23:a50ded45dbaf 1782 default:
WiredHome 23:a50ded45dbaf 1783 printf("huh?\n");
WiredHome 23:a50ded45dbaf 1784 break;
WiredHome 23:a50ded45dbaf 1785 }
WiredHome 23:a50ded45dbaf 1786 if (automode >= 0) {
WiredHome 23:a50ded45dbaf 1787 automode++;
WiredHome 23:a50ded45dbaf 1788 if (automode >= sizeof(modelist))
WiredHome 23:a50ded45dbaf 1789 automode = 0;
WiredHome 23:a50ded45dbaf 1790 wait_ms(2000);
WiredHome 23:a50ded45dbaf 1791 }
WiredHome 23:a50ded45dbaf 1792 wait_ms(200);
WiredHome 23:a50ded45dbaf 1793 }
WiredHome 23:a50ded45dbaf 1794 }
WiredHome 23:a50ded45dbaf 1795
WiredHome 23:a50ded45dbaf 1796 #endif // TESTENABLE