KSM edits to RA8875

Dependents:   Liz_Test_Code

Committer:
WiredHome
Date:
Sun Mar 09 23:45:23 2014 +0000
Revision:
43:3becae133285
Parent:
41:2956a0a221e5
Child:
44:207594dece70
Initial support (not yet complete) for more screen resolutions and for display layers.

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