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:
Sat Feb 08 17:35:45 2014 +0000
Revision:
41:2956a0a221e5
Parent:
40:04aa280dfa39
Child:
43:3becae133285
Added PrintScreen method, to capture the current image to a file system.; Improved performance of pixel streaming (rendering a bitmap and capturing a bitmap).; Ran performance checks, then disabled debug and the performance information.

Who changed what in which revision?

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