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

Dependents:   FRDM_RA8875_mPaint RA8875_Demo RA8875_KeyPadDemo SignalGenerator ... more

Fork of SPI_TFT by Peter Drescher

See Components - RA8875 Based Display

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

Offline Help Manual (Windows chm)

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

Committer:
WiredHome
Date:
Mon Mar 17 11:29:40 2014 +0000
Revision:
53:86d24b9480b9
Parent:
52:e6039a823420
Child:
54:e117ad10fba6
Child:
63:ed787f5fcdc4
Moved cursor definitions into the class.; Added support for setting the background color register for transparency.

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