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:
Fri Jan 17 02:10:18 2014 +0000
Revision:
24:8ca861acf12d
Parent:
23:a50ded45dbaf
Child:
25:9556a3a9b7cc
Cursor control is working - none, i-beam, underscore, block.

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 20:6e2e4a8372eb 10 DigitalOut zz1(LED1);
WiredHome 20:6e2e4a8372eb 11 DigitalOut zz2(LED2);
WiredHome 20:6e2e4a8372eb 12 DigitalOut zz3(LED3);
WiredHome 20:6e2e4a8372eb 13 DigitalOut zz4(LED4);
WiredHome 20:6e2e4a8372eb 14
WiredHome 19:3f82c1161fd2 15 //#define DEBUG "RAIO"
WiredHome 19:3f82c1161fd2 16 // ...
WiredHome 19:3f82c1161fd2 17 // INFO("Stuff to show %d", var); // new-line is automatically appended
WiredHome 19:3f82c1161fd2 18 //
WiredHome 19:3f82c1161fd2 19 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
WiredHome 19:3f82c1161fd2 20 #define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 19:3f82c1161fd2 21 #define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 19:3f82c1161fd2 22 #define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 19:3f82c1161fd2 23 #else
WiredHome 19:3f82c1161fd2 24 #define INFO(x, ...)
WiredHome 19:3f82c1161fd2 25 #define WARN(x, ...)
WiredHome 19:3f82c1161fd2 26 #define ERR(x, ...)
WiredHome 19:3f82c1161fd2 27 #endif
WiredHome 19:3f82c1161fd2 28
WiredHome 19:3f82c1161fd2 29
WiredHome 19:3f82c1161fd2 30 #define RA8875_DISPLAY_WIDTH 480
WiredHome 19:3f82c1161fd2 31 #define RA8875_DISPLAY_HEIGHT 272
WiredHome 19:3f82c1161fd2 32
WiredHome 19:3f82c1161fd2 33
WiredHome 19:3f82c1161fd2 34 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 35 #define PERFORMANCE_RESET performance.reset()
WiredHome 19:3f82c1161fd2 36 #define REGISTERPERFORMANCE(a) RegisterPerformance(a)
WiredHome 19:3f82c1161fd2 37 static const char *metricsName[] =
WiredHome 19:3f82c1161fd2 38 {
WiredHome 19:3f82c1161fd2 39 "Point", "Line", "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 19:3f82c1161fd2 60 init();
WiredHome 19:3f82c1161fd2 61 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 62 performance.start();
WiredHome 19:3f82c1161fd2 63 ClearPerformance();
WiredHome 19:3f82c1161fd2 64 #endif
WiredHome 19:3f82c1161fd2 65 }
WiredHome 19:3f82c1161fd2 66
WiredHome 19:3f82c1161fd2 67 //RA8875::~RA8875()
WiredHome 19:3f82c1161fd2 68 //{
WiredHome 19:3f82c1161fd2 69 //}
WiredHome 19:3f82c1161fd2 70
WiredHome 19:3f82c1161fd2 71 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 72 void RA8875::ClearPerformance()
WiredHome 19:3f82c1161fd2 73 {
WiredHome 19:3f82c1161fd2 74 for (int i=0; i<METRICCOUNT; i++)
WiredHome 19:3f82c1161fd2 75 metrics[i] = 0;
WiredHome 19:3f82c1161fd2 76 }
WiredHome 19:3f82c1161fd2 77
WiredHome 19:3f82c1161fd2 78 void RA8875::RegisterPerformance(method_e method)
WiredHome 19:3f82c1161fd2 79 {
WiredHome 19:3f82c1161fd2 80 unsigned long elapsed = performance.read_us();
WiredHome 19:3f82c1161fd2 81
WiredHome 19:3f82c1161fd2 82 if (method < METRICCOUNT && elapsed > metrics[method])
WiredHome 19:3f82c1161fd2 83 metrics[method] = elapsed;
WiredHome 19:3f82c1161fd2 84 }
WiredHome 19:3f82c1161fd2 85
WiredHome 19:3f82c1161fd2 86 void RA8875::ReportPerformance()
WiredHome 19:3f82c1161fd2 87 {
WiredHome 19:3f82c1161fd2 88 for (int i=0; i<METRICCOUNT; i++) {
WiredHome 19:3f82c1161fd2 89 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 19:3f82c1161fd2 94 RetCode_t RA8875::WriteCommand(unsigned char command, unsigned int data)
WiredHome 19:3f82c1161fd2 95 {
WiredHome 19:3f82c1161fd2 96 select(true);
WiredHome 19:3f82c1161fd2 97 spiwrite(0x80);
WiredHome 19:3f82c1161fd2 98 spiwrite(command);
WiredHome 19:3f82c1161fd2 99 if (data <= 0xFF) { // only if in the valid range
WiredHome 19:3f82c1161fd2 100 spiwrite(0x00);
WiredHome 19:3f82c1161fd2 101 spiwrite(data);
WiredHome 19:3f82c1161fd2 102 }
WiredHome 19:3f82c1161fd2 103 select(false);
WiredHome 19:3f82c1161fd2 104 return noerror;
WiredHome 19:3f82c1161fd2 105 }
WiredHome 19:3f82c1161fd2 106
WiredHome 19:3f82c1161fd2 107 RetCode_t RA8875::WriteData(unsigned char data)
WiredHome 19:3f82c1161fd2 108 {
WiredHome 19:3f82c1161fd2 109 select(true);
WiredHome 19:3f82c1161fd2 110 spiwrite(0x00);
WiredHome 19:3f82c1161fd2 111 spiwrite(data);
WiredHome 19:3f82c1161fd2 112 select(false);
WiredHome 19:3f82c1161fd2 113 return noerror;
WiredHome 19:3f82c1161fd2 114 }
WiredHome 19:3f82c1161fd2 115
WiredHome 19:3f82c1161fd2 116 unsigned char RA8875::ReadCommand(unsigned char command)
WiredHome 19:3f82c1161fd2 117 {
WiredHome 19:3f82c1161fd2 118 WriteCommand(command);
WiredHome 19:3f82c1161fd2 119 return ReadData();
WiredHome 19:3f82c1161fd2 120 }
WiredHome 19:3f82c1161fd2 121
WiredHome 19:3f82c1161fd2 122 unsigned char RA8875::ReadData(void)
WiredHome 19:3f82c1161fd2 123 {
WiredHome 19:3f82c1161fd2 124 unsigned char data;
WiredHome 19:3f82c1161fd2 125
WiredHome 19:3f82c1161fd2 126 select(true);
WiredHome 19:3f82c1161fd2 127 spiwrite(0x40);
WiredHome 19:3f82c1161fd2 128 data = spiread();
WiredHome 19:3f82c1161fd2 129 select(false);
WiredHome 19:3f82c1161fd2 130 return data;
WiredHome 19:3f82c1161fd2 131 }
WiredHome 19:3f82c1161fd2 132
WiredHome 19:3f82c1161fd2 133 unsigned char RA8875::ReadStatus(void)
WiredHome 19:3f82c1161fd2 134 {
WiredHome 19:3f82c1161fd2 135 unsigned char data;
WiredHome 19:3f82c1161fd2 136
WiredHome 19:3f82c1161fd2 137 select(true);
WiredHome 19:3f82c1161fd2 138 spiwrite(0xC0);
WiredHome 19:3f82c1161fd2 139 data = spiread();
WiredHome 19:3f82c1161fd2 140 select(false);
WiredHome 19:3f82c1161fd2 141 return data;
WiredHome 19:3f82c1161fd2 142 }
WiredHome 19:3f82c1161fd2 143
WiredHome 19:3f82c1161fd2 144 unsigned int RA8875::fontwidth(void)
WiredHome 19:3f82c1161fd2 145 {
WiredHome 19:3f82c1161fd2 146 if (font == NULL)
WiredHome 23:a50ded45dbaf 147 return (((ReadCommand(0x22) >> 2) & 0x3) + 1) * 16;
WiredHome 19:3f82c1161fd2 148 else
WiredHome 19:3f82c1161fd2 149 return width() / font[1];
WiredHome 19:3f82c1161fd2 150 }
WiredHome 19:3f82c1161fd2 151
WiredHome 19:3f82c1161fd2 152 unsigned int RA8875::fontheight(void)
WiredHome 19:3f82c1161fd2 153 {
WiredHome 19:3f82c1161fd2 154 if (font == NULL)
WiredHome 23:a50ded45dbaf 155 return (((ReadCommand(0x22) >> 0) & 0x3) + 1) * 16;
WiredHome 19:3f82c1161fd2 156 else
WiredHome 19:3f82c1161fd2 157 return height() / font[2];
WiredHome 19:3f82c1161fd2 158 }
WiredHome 19:3f82c1161fd2 159
WiredHome 19:3f82c1161fd2 160 RetCode_t RA8875::locate(unsigned int x, unsigned int y)
WiredHome 19:3f82c1161fd2 161 {
WiredHome 19:3f82c1161fd2 162 return SetTextCursor(x * fontwidth(), y * fontheight());
WiredHome 19:3f82c1161fd2 163 }
WiredHome 19:3f82c1161fd2 164
WiredHome 19:3f82c1161fd2 165 int RA8875::columns(void)
WiredHome 19:3f82c1161fd2 166 {
WiredHome 19:3f82c1161fd2 167 return width() / fontwidth();
WiredHome 19:3f82c1161fd2 168 }
WiredHome 19:3f82c1161fd2 169
WiredHome 19:3f82c1161fd2 170 int RA8875::rows(void)
WiredHome 19:3f82c1161fd2 171 {
WiredHome 19:3f82c1161fd2 172 return height() / fontheight();
WiredHome 19:3f82c1161fd2 173 }
WiredHome 19:3f82c1161fd2 174
WiredHome 19:3f82c1161fd2 175 int RA8875::width(void)
WiredHome 19:3f82c1161fd2 176 {
WiredHome 19:3f82c1161fd2 177 return RA8875_DISPLAY_WIDTH;
WiredHome 19:3f82c1161fd2 178 }
WiredHome 19:3f82c1161fd2 179
WiredHome 19:3f82c1161fd2 180 int RA8875::height(void)
WiredHome 19:3f82c1161fd2 181 {
WiredHome 19:3f82c1161fd2 182 return RA8875_DISPLAY_HEIGHT;
WiredHome 19:3f82c1161fd2 183 }
WiredHome 19:3f82c1161fd2 184
WiredHome 19:3f82c1161fd2 185 RetCode_t RA8875::SetTextCursor(unsigned int x, unsigned int y)
WiredHome 19:3f82c1161fd2 186 {
WiredHome 19:3f82c1161fd2 187 WriteCommand(0x2A, x & 0xFF);
WiredHome 19:3f82c1161fd2 188 WriteCommand(0x2B, x >> 8);
WiredHome 19:3f82c1161fd2 189 WriteCommand(0x2C, y & 0xFF);
WiredHome 19:3f82c1161fd2 190 WriteCommand(0x2D, y >> 8);
WiredHome 19:3f82c1161fd2 191 INFO("SetTextCursor(%d,%d)", x,y);
WiredHome 19:3f82c1161fd2 192 return noerror;
WiredHome 19:3f82c1161fd2 193 }
WiredHome 19:3f82c1161fd2 194
WiredHome 24:8ca861acf12d 195 RetCode_t RA8875::SetTextCursorControl(cursor_t cursor, bool blink)
WiredHome 23:a50ded45dbaf 196 {
WiredHome 23:a50ded45dbaf 197 unsigned char mwcr0 = ReadCommand(0x40) & 0x0F; // retain direction, auto-increase
WiredHome 24:8ca861acf12d 198 unsigned char horz = 0;
WiredHome 24:8ca861acf12d 199 unsigned char vert = 0;
WiredHome 23:a50ded45dbaf 200
WiredHome 24:8ca861acf12d 201 mwcr0 |= 0x80; // text mode
WiredHome 24:8ca861acf12d 202 if (cursor != NOCURSOR)
WiredHome 24:8ca861acf12d 203 mwcr0 |= 0x40; // visible
WiredHome 23:a50ded45dbaf 204 if (blink)
WiredHome 24:8ca861acf12d 205 mwcr0 |= 0x20; // blink
WiredHome 23:a50ded45dbaf 206 WriteCommand(0x40, mwcr0); // configure the cursor
WiredHome 23:a50ded45dbaf 207 WriteCommand(0x41, 0x00); // close the graphics cursor
WiredHome 24:8ca861acf12d 208 WriteCommand(0x44, 0x1f); // The cursor flashing cycle
WiredHome 24:8ca861acf12d 209 switch (cursor) {
WiredHome 24:8ca861acf12d 210 case IBEAM:
WiredHome 24:8ca861acf12d 211 horz = 0x01;
WiredHome 24:8ca861acf12d 212 vert = 0x1F;
WiredHome 24:8ca861acf12d 213 break;
WiredHome 24:8ca861acf12d 214 case UNDER:
WiredHome 24:8ca861acf12d 215 horz = 0x07;
WiredHome 24:8ca861acf12d 216 vert = 0x01;
WiredHome 24:8ca861acf12d 217 break;
WiredHome 24:8ca861acf12d 218 case BLOCK:
WiredHome 24:8ca861acf12d 219 horz = 0x07;
WiredHome 24:8ca861acf12d 220 vert = 0x1F;
WiredHome 24:8ca861acf12d 221 break;
WiredHome 24:8ca861acf12d 222 case NOCURSOR:
WiredHome 24:8ca861acf12d 223 default:
WiredHome 24:8ca861acf12d 224 break;
WiredHome 24:8ca861acf12d 225 }
WiredHome 24:8ca861acf12d 226 WriteCommand(0x4e, horz); // The cursor size horz
WiredHome 24:8ca861acf12d 227 WriteCommand(0x4f, vert); // The cursor size vert
WiredHome 23:a50ded45dbaf 228 return noerror;
WiredHome 23:a50ded45dbaf 229 }
WiredHome 23:a50ded45dbaf 230
WiredHome 19:3f82c1161fd2 231 RetCode_t RA8875::SetTextFont(RA8875::font_t font)
WiredHome 19:3f82c1161fd2 232 {
WiredHome 19:3f82c1161fd2 233 if (/*font >= RA8875::ISO8859_1 && */ font <= RA8875::ISO8859_4) {
WiredHome 19:3f82c1161fd2 234 WriteCommand(0x21, (unsigned int)(font));
WiredHome 19:3f82c1161fd2 235 return noerror;
WiredHome 19:3f82c1161fd2 236 } else {
WiredHome 19:3f82c1161fd2 237 return bad_parameter;
WiredHome 19:3f82c1161fd2 238 }
WiredHome 19:3f82c1161fd2 239 }
WiredHome 19:3f82c1161fd2 240
WiredHome 19:3f82c1161fd2 241 RetCode_t RA8875::SetTextFontControl(fill_t fillit,
WiredHome 19:3f82c1161fd2 242 RA8875::font_angle_t angle,
WiredHome 19:3f82c1161fd2 243 RA8875::HorizontalScale hScale,
WiredHome 19:3f82c1161fd2 244 RA8875::VerticalScale vScale,
WiredHome 19:3f82c1161fd2 245 RA8875::alignment_t alignment)
WiredHome 19:3f82c1161fd2 246 {
WiredHome 19:3f82c1161fd2 247 if (hScale >= 1 && hScale <= 4 &&
WiredHome 19:3f82c1161fd2 248 vScale >= 1 && vScale <= 4) {
WiredHome 19:3f82c1161fd2 249 unsigned char x = 0;
WiredHome 19:3f82c1161fd2 250
WiredHome 19:3f82c1161fd2 251 if (alignment == align_full)
WiredHome 19:3f82c1161fd2 252 x |= 0x80;
WiredHome 19:3f82c1161fd2 253 if (fillit == NOFILL)
WiredHome 19:3f82c1161fd2 254 x |= 0x40;
WiredHome 19:3f82c1161fd2 255 if (angle == rotated)
WiredHome 19:3f82c1161fd2 256 x |= 0x10;
WiredHome 19:3f82c1161fd2 257 x |= ((hScale - 1) << 2);
WiredHome 19:3f82c1161fd2 258 x |= ((vScale - 1) << 0);
WiredHome 19:3f82c1161fd2 259 WriteCommand(0x22, x);
WiredHome 19:3f82c1161fd2 260 return noerror;
WiredHome 19:3f82c1161fd2 261 } else {
WiredHome 19:3f82c1161fd2 262 return bad_parameter;
WiredHome 19:3f82c1161fd2 263 }
WiredHome 19:3f82c1161fd2 264 }
WiredHome 19:3f82c1161fd2 265
WiredHome 19:3f82c1161fd2 266 RetCode_t RA8875::SetTextFontSize(RA8875::HorizontalScale hScale, RA8875::VerticalScale vScale)
WiredHome 19:3f82c1161fd2 267 {
WiredHome 19:3f82c1161fd2 268 unsigned char reg = ReadCommand(0x22);
WiredHome 19:3f82c1161fd2 269
WiredHome 19:3f82c1161fd2 270 if (hScale >= 1 && hScale <= 4 && vScale >= 1 && vScale <= 4) {
WiredHome 19:3f82c1161fd2 271 reg &= 0xF0; // keep the high nibble as is.
WiredHome 19:3f82c1161fd2 272 reg |= ((hScale - 1) << 2);
WiredHome 19:3f82c1161fd2 273 reg |= ((vScale - 1) << 0);
WiredHome 19:3f82c1161fd2 274 WriteCommand(0x22, reg);
WiredHome 19:3f82c1161fd2 275 return noerror;
WiredHome 19:3f82c1161fd2 276 } else {
WiredHome 19:3f82c1161fd2 277 return bad_parameter;
WiredHome 19:3f82c1161fd2 278 }
WiredHome 19:3f82c1161fd2 279 }
WiredHome 19:3f82c1161fd2 280
WiredHome 19:3f82c1161fd2 281 int RA8875::_putc(int c)
WiredHome 19:3f82c1161fd2 282 {
WiredHome 19:3f82c1161fd2 283 if (c) {
WiredHome 19:3f82c1161fd2 284 if (c == '\r') {
WiredHome 19:3f82c1161fd2 285 unsigned int x;
WiredHome 19:3f82c1161fd2 286 x = ReadCommand(0x30) | (ReadCommand(0x31) << 8); // Left edge of active window
WiredHome 19:3f82c1161fd2 287 WriteCommand(0x2A, x & 0xFF);
WiredHome 19:3f82c1161fd2 288 WriteCommand(0x2B, x >> 8);
WiredHome 19:3f82c1161fd2 289 } else if (c == '\n') {
WiredHome 19:3f82c1161fd2 290 unsigned int y;
WiredHome 19:3f82c1161fd2 291 y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); // current y location
WiredHome 19:3f82c1161fd2 292 y += fontheight();
WiredHome 19:3f82c1161fd2 293 if (y > height()) // @TODO > active window, then scroll?
WiredHome 19:3f82c1161fd2 294 y = 0;
WiredHome 19:3f82c1161fd2 295 WriteCommand(0x2C, y & 0xFF);
WiredHome 19:3f82c1161fd2 296 WriteCommand(0x2D, y >> 8);
WiredHome 19:3f82c1161fd2 297 } else {
WiredHome 19:3f82c1161fd2 298 if (font == NULL) {
WiredHome 24:8ca861acf12d 299 unsigned char mwcr0 = ReadCommand(0x40);
WiredHome 24:8ca861acf12d 300
WiredHome 24:8ca861acf12d 301 if (mwcr0 & 0x80 == 0x00)
WiredHome 24:8ca861acf12d 302 WriteCommand(0x40,0x80);
WiredHome 19:3f82c1161fd2 303 WriteCommand(0x02);
WiredHome 19:3f82c1161fd2 304 select(true);
WiredHome 19:3f82c1161fd2 305 WriteData(c);
WiredHome 19:3f82c1161fd2 306 while (ReadStatus() & 0x80)
WiredHome 19:3f82c1161fd2 307 wait_us(POLLWAITuSec); // Chk_Busy();
WiredHome 19:3f82c1161fd2 308 select(false);
WiredHome 19:3f82c1161fd2 309 } else {
WiredHome 19:3f82c1161fd2 310 unsigned int x = (ReadCommand(0x2A) | (ReadCommand(0x2B) << 8)) / fontwidth();
WiredHome 19:3f82c1161fd2 311 unsigned int y = (ReadCommand(0x2C) | (ReadCommand(0x2D) << 8)) / fontheight();
WiredHome 19:3f82c1161fd2 312 character(x,y,c);
WiredHome 19:3f82c1161fd2 313 }
WiredHome 19:3f82c1161fd2 314 // @TODO right of active window, then wrap?
WiredHome 19:3f82c1161fd2 315 }
WiredHome 19:3f82c1161fd2 316 }
WiredHome 19:3f82c1161fd2 317 return c;
WiredHome 19:3f82c1161fd2 318 }
WiredHome 19:3f82c1161fd2 319
WiredHome 19:3f82c1161fd2 320 void RA8875::puts(unsigned int x, unsigned int y, const char * string)
WiredHome 19:3f82c1161fd2 321 {
WiredHome 19:3f82c1161fd2 322 SetTextCursor(x,y);
WiredHome 19:3f82c1161fd2 323 puts(string);
WiredHome 19:3f82c1161fd2 324 }
WiredHome 19:3f82c1161fd2 325
WiredHome 19:3f82c1161fd2 326 void RA8875::puts(const char * string)
WiredHome 19:3f82c1161fd2 327 {
WiredHome 19:3f82c1161fd2 328 if (*string != '\0') {
WiredHome 19:3f82c1161fd2 329 INFO("puts(%s)", string);
WiredHome 19:3f82c1161fd2 330 #if 1
WiredHome 19:3f82c1161fd2 331 while (*string) { // @TODO calling individual _putc is slower... anything to do?
WiredHome 19:3f82c1161fd2 332 _putc(*string++);
WiredHome 19:3f82c1161fd2 333 }
WiredHome 19:3f82c1161fd2 334 #else
WiredHome 19:3f82c1161fd2 335 WriteCommand(0x40,0x80); // Put display into text mode
WiredHome 19:3f82c1161fd2 336 WriteCommand(0x02);
WiredHome 19:3f82c1161fd2 337 select(true);
WiredHome 19:3f82c1161fd2 338 while (*string != '\0') {
WiredHome 19:3f82c1161fd2 339 WriteData(*string);
WiredHome 19:3f82c1161fd2 340 ++string;
WiredHome 19:3f82c1161fd2 341 while (ReadStatus() & 0x80)
WiredHome 19:3f82c1161fd2 342 wait_us(POLLWAITuSec); // Chk_Busy();
WiredHome 19:3f82c1161fd2 343 }
WiredHome 19:3f82c1161fd2 344 select(false);
WiredHome 19:3f82c1161fd2 345 #endif
WiredHome 19:3f82c1161fd2 346 }
WiredHome 19:3f82c1161fd2 347 }
WiredHome 19:3f82c1161fd2 348
WiredHome 19:3f82c1161fd2 349 RetCode_t RA8875::SetMemoryCursor(unsigned int x, unsigned int y)
WiredHome 19:3f82c1161fd2 350
WiredHome 19:3f82c1161fd2 351 {
WiredHome 19:3f82c1161fd2 352 WriteCommand(0x46, x & 0xFF);
WiredHome 19:3f82c1161fd2 353 WriteCommand(0x47, x >> 8);
WiredHome 19:3f82c1161fd2 354 WriteCommand(0x48, y & 0xFF);
WiredHome 19:3f82c1161fd2 355 WriteCommand(0x49, y >> 8);
WiredHome 19:3f82c1161fd2 356 return noerror;
WiredHome 19:3f82c1161fd2 357 }
WiredHome 19:3f82c1161fd2 358
WiredHome 19:3f82c1161fd2 359 RetCode_t RA8875::SetWindow(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
WiredHome 19:3f82c1161fd2 360 {
WiredHome 19:3f82c1161fd2 361 WriteCommand(0x30, x & 0xFF); // HSAW0
WiredHome 19:3f82c1161fd2 362 WriteCommand(0x31, x >> 8); // HSAW1
WiredHome 19:3f82c1161fd2 363 WriteCommand(0x32, y & 0xFF); // VSAW0
WiredHome 19:3f82c1161fd2 364 WriteCommand(0x33, y >> 8); // VSAW1
WiredHome 19:3f82c1161fd2 365 WriteCommand(0x34, (x+width-1) & 0xFF); // HEAW0
WiredHome 19:3f82c1161fd2 366 WriteCommand(0x35, (x+width-1) >> 8); // HEAW1
WiredHome 19:3f82c1161fd2 367 WriteCommand(0x36, (y+height-1) & 0xFF); // VEAW0
WiredHome 19:3f82c1161fd2 368 WriteCommand(0x37, (y+height-1) >> 8); // VEAW1
WiredHome 19:3f82c1161fd2 369 return noerror;
WiredHome 19:3f82c1161fd2 370 }
WiredHome 19:3f82c1161fd2 371
WiredHome 19:3f82c1161fd2 372 RetCode_t RA8875::cls(void)
WiredHome 19:3f82c1161fd2 373 {
WiredHome 19:3f82c1161fd2 374 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 375 clsw(FULLWINDOW);
WiredHome 19:3f82c1161fd2 376 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 19:3f82c1161fd2 377 return noerror;
WiredHome 19:3f82c1161fd2 378 }
WiredHome 19:3f82c1161fd2 379
WiredHome 19:3f82c1161fd2 380 RetCode_t RA8875::clsw(RA8875::Region_t region)
WiredHome 19:3f82c1161fd2 381 {
WiredHome 19:3f82c1161fd2 382 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 383 WriteCommand(0x8E, (region == ACTIVEWINDOW) ? 0xC0 : 0x80);
WiredHome 19:3f82c1161fd2 384 while (ReadCommand(0x8E) & 0x80)
WiredHome 19:3f82c1161fd2 385 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 386 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 19:3f82c1161fd2 387 return noerror;
WiredHome 19:3f82c1161fd2 388 }
WiredHome 19:3f82c1161fd2 389
WiredHome 19:3f82c1161fd2 390 RetCode_t RA8875::pixel(unsigned int x, unsigned int y, color_t color)
WiredHome 19:3f82c1161fd2 391 {
WiredHome 19:3f82c1161fd2 392 foreground(color);
WiredHome 19:3f82c1161fd2 393 return pixel(x,y);
WiredHome 19:3f82c1161fd2 394 }
WiredHome 19:3f82c1161fd2 395
WiredHome 19:3f82c1161fd2 396 RetCode_t RA8875::pixel(unsigned int x, unsigned int y)
WiredHome 19:3f82c1161fd2 397 {
WiredHome 19:3f82c1161fd2 398 RetCode_t ret;
WiredHome 19:3f82c1161fd2 399
WiredHome 19:3f82c1161fd2 400 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 401 #if 1
WiredHome 19:3f82c1161fd2 402 color_t color = GetForeColor();
WiredHome 19:3f82c1161fd2 403 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 19:3f82c1161fd2 404 SetMemoryCursor(x, y);
WiredHome 19:3f82c1161fd2 405 WriteCommand(0x02); //start data write
WiredHome 19:3f82c1161fd2 406 WriteData(color & 0xFF);
WiredHome 19:3f82c1161fd2 407 WriteData(color >> 8);
WiredHome 19:3f82c1161fd2 408 ret = noerror;
WiredHome 19:3f82c1161fd2 409 #else
WiredHome 19:3f82c1161fd2 410 // There isn't actually a set pixel function that I found
WiredHome 19:3f82c1161fd2 411 // so we'll emulate it as we can.
WiredHome 19:3f82c1161fd2 412 ret = line(x,y, x,y);
WiredHome 19:3f82c1161fd2 413 #endif
WiredHome 19:3f82c1161fd2 414 REGISTERPERFORMANCE(PRF_DRAWPOINT);
WiredHome 19:3f82c1161fd2 415 return ret;
WiredHome 19:3f82c1161fd2 416 }
WiredHome 19:3f82c1161fd2 417
WiredHome 19:3f82c1161fd2 418 RetCode_t RA8875::line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, color_t color)
WiredHome 19:3f82c1161fd2 419 {
WiredHome 19:3f82c1161fd2 420 foreground(color);
WiredHome 19:3f82c1161fd2 421 return line(x1,y1,x2,y2);
WiredHome 19:3f82c1161fd2 422 }
WiredHome 19:3f82c1161fd2 423
WiredHome 19:3f82c1161fd2 424 RetCode_t RA8875::line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
WiredHome 19:3f82c1161fd2 425 {
WiredHome 19:3f82c1161fd2 426 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 427 WriteCommand(0x91, x1 & 0xFF);
WiredHome 19:3f82c1161fd2 428 WriteCommand(0x92, x1 >> 8);
WiredHome 19:3f82c1161fd2 429 WriteCommand(0x93, y1 & 0xFF);
WiredHome 19:3f82c1161fd2 430 WriteCommand(0x94, y1 >> 8);
WiredHome 19:3f82c1161fd2 431 WriteCommand(0x95, x2 & 0xFF);
WiredHome 19:3f82c1161fd2 432 WriteCommand(0x96, x2 >> 8);
WiredHome 19:3f82c1161fd2 433 WriteCommand(0x97, y2 & 0xFF);
WiredHome 19:3f82c1161fd2 434 WriteCommand(0x98, y2 >> 8);
WiredHome 19:3f82c1161fd2 435
WiredHome 19:3f82c1161fd2 436 unsigned char drawCmd = 0x00; // Line
WiredHome 19:3f82c1161fd2 437 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 438 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 439 while (ReadCommand(0x90) & 0x80) // await completion.
WiredHome 19:3f82c1161fd2 440 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 441 REGISTERPERFORMANCE(PRF_DRAWLINE);
WiredHome 19:3f82c1161fd2 442 return noerror;
WiredHome 19:3f82c1161fd2 443 }
WiredHome 19:3f82c1161fd2 444
WiredHome 19:3f82c1161fd2 445 RetCode_t RA8875::fillrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 446 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 447 {
WiredHome 19:3f82c1161fd2 448 return rect(x1,y1,x2,y2,color,fillit);
WiredHome 19:3f82c1161fd2 449 }
WiredHome 19:3f82c1161fd2 450
WiredHome 19:3f82c1161fd2 451 RetCode_t RA8875::rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 452 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 453 {
WiredHome 19:3f82c1161fd2 454 foreground(color);
WiredHome 19:3f82c1161fd2 455 return rect(x1,y1,x2,y2,fillit);
WiredHome 19:3f82c1161fd2 456 }
WiredHome 19:3f82c1161fd2 457
WiredHome 19:3f82c1161fd2 458 RetCode_t RA8875::rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 459 fill_t fillit)
WiredHome 19:3f82c1161fd2 460 {
WiredHome 19:3f82c1161fd2 461 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 462 if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 463 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 464 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 465 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 466 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 467 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 468 } else {
WiredHome 19:3f82c1161fd2 469 WriteCommand(0x91, x1 & 0xFF);
WiredHome 19:3f82c1161fd2 470 WriteCommand(0x92, x1 >> 8);
WiredHome 19:3f82c1161fd2 471 WriteCommand(0x93, y1 & 0xFF);
WiredHome 19:3f82c1161fd2 472 WriteCommand(0x94, y1 >> 8);
WiredHome 19:3f82c1161fd2 473 WriteCommand(0x95, x2 & 0xFF);
WiredHome 19:3f82c1161fd2 474 WriteCommand(0x96, x2 >> 8);
WiredHome 19:3f82c1161fd2 475 WriteCommand(0x97, y2 & 0xFF);
WiredHome 19:3f82c1161fd2 476 WriteCommand(0x98, y2 >> 8);
WiredHome 19:3f82c1161fd2 477
WiredHome 19:3f82c1161fd2 478 unsigned char drawCmd = 0x10; // Rectangle
WiredHome 19:3f82c1161fd2 479 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 480 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 481 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 482 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 483 while (ReadCommand(0x90) & 0x80) // await completion.
WiredHome 19:3f82c1161fd2 484 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 485 }
WiredHome 19:3f82c1161fd2 486 REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
WiredHome 19:3f82c1161fd2 487 return noerror;
WiredHome 19:3f82c1161fd2 488 }
WiredHome 19:3f82c1161fd2 489
WiredHome 19:3f82c1161fd2 490 RetCode_t RA8875::fillroundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 491 unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 492 {
WiredHome 19:3f82c1161fd2 493 foreground(color);
WiredHome 19:3f82c1161fd2 494 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 495 }
WiredHome 19:3f82c1161fd2 496
WiredHome 19:3f82c1161fd2 497 RetCode_t RA8875::roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 498 unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 499 {
WiredHome 19:3f82c1161fd2 500 foreground(color);
WiredHome 19:3f82c1161fd2 501 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 502 }
WiredHome 19:3f82c1161fd2 503
WiredHome 21:3c1efb192927 504 RetCode_t RA8875::roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 505 unsigned int radius1, unsigned int radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 506 {
WiredHome 19:3f82c1161fd2 507 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 508
WiredHome 19:3f82c1161fd2 509 PERFORMANCE_RESET;
WiredHome 21:3c1efb192927 510 if (x1 > x2 || y1 > y2 || (radius1 > (x2-x1)/2) || (radius2 > (y2-y1)/2) ) {
WiredHome 21:3c1efb192927 511 ret = bad_parameter;
WiredHome 21:3c1efb192927 512 } else if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 513 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 514 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 515 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 516 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 517 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 518 } else {
WiredHome 19:3f82c1161fd2 519 WriteCommand(0x91, x1 & 0xFF);
WiredHome 19:3f82c1161fd2 520 WriteCommand(0x92, x1 >> 8);
WiredHome 19:3f82c1161fd2 521 WriteCommand(0x93, y1 & 0xFF);
WiredHome 19:3f82c1161fd2 522 WriteCommand(0x94, y1 >> 8);
WiredHome 19:3f82c1161fd2 523 WriteCommand(0x95, x2 & 0xFF);
WiredHome 19:3f82c1161fd2 524 WriteCommand(0x96, x2 >> 8);
WiredHome 19:3f82c1161fd2 525 WriteCommand(0x97, y2 & 0xFF);
WiredHome 19:3f82c1161fd2 526 WriteCommand(0x98, y2 >> 8);
WiredHome 19:3f82c1161fd2 527
WiredHome 19:3f82c1161fd2 528 WriteCommand(0xA1, radius1 & 0xFF);
WiredHome 19:3f82c1161fd2 529 WriteCommand(0xA2, radius1 >> 8);
WiredHome 19:3f82c1161fd2 530 WriteCommand(0xA3, radius2 & 0xFF);
WiredHome 19:3f82c1161fd2 531 WriteCommand(0xA4, radius2 >> 8);
WiredHome 21:3c1efb192927 532
WiredHome 21:3c1efb192927 533 // Should not need this...
WiredHome 21:3c1efb192927 534 WriteCommand(0xA5, 0 & 0xFF);
WiredHome 21:3c1efb192927 535 WriteCommand(0xA6, 0 >> 8);
WiredHome 21:3c1efb192927 536 WriteCommand(0xA7, 0 & 0xFF);
WiredHome 21:3c1efb192927 537 WriteCommand(0xA8, 0 >> 8);
WiredHome 19:3f82c1161fd2 538
WiredHome 19:3f82c1161fd2 539 unsigned char drawCmd = 0x20; // Rounded Rectangle
WiredHome 19:3f82c1161fd2 540 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 541 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 542 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 543 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 544 while (ReadCommand(0xA0) & 0x80) { // await completion.
WiredHome 19:3f82c1161fd2 545 wait_us(POLLWAITuSec);
WiredHome 21:3c1efb192927 546 }
WiredHome 19:3f82c1161fd2 547 }
WiredHome 19:3f82c1161fd2 548 REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
WiredHome 19:3f82c1161fd2 549 return ret;
WiredHome 19:3f82c1161fd2 550 }
WiredHome 19:3f82c1161fd2 551
WiredHome 19:3f82c1161fd2 552 RetCode_t RA8875::triangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 553 unsigned int x3, unsigned int y3, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 554 {
WiredHome 20:6e2e4a8372eb 555 RetCode_t ret;
WiredHome 20:6e2e4a8372eb 556
WiredHome 19:3f82c1161fd2 557 foreground(color);
WiredHome 20:6e2e4a8372eb 558 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 20:6e2e4a8372eb 559 return ret;
WiredHome 19:3f82c1161fd2 560 }
WiredHome 19:3f82c1161fd2 561
WiredHome 19:3f82c1161fd2 562 RetCode_t RA8875::filltriangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 563 unsigned int x3, unsigned int y3, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 564 {
WiredHome 20:6e2e4a8372eb 565 RetCode_t ret;
WiredHome 20:6e2e4a8372eb 566
WiredHome 19:3f82c1161fd2 567 foreground(color);
WiredHome 20:6e2e4a8372eb 568 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 20:6e2e4a8372eb 569 return ret;
WiredHome 19:3f82c1161fd2 570 }
WiredHome 19:3f82c1161fd2 571
WiredHome 19:3f82c1161fd2 572 RetCode_t RA8875::triangle(unsigned int x1, unsigned int y1 ,unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 573 unsigned int x3, unsigned int y3, fill_t fillit)
WiredHome 19:3f82c1161fd2 574 {
WiredHome 19:3f82c1161fd2 575 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 576
WiredHome 19:3f82c1161fd2 577 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 578 if (x1 == x2 && y1 == y2 && x1 == x3 && y1 == y3) {
WiredHome 19:3f82c1161fd2 579 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 580 } else {
WiredHome 19:3f82c1161fd2 581 WriteCommand(0x91, x1 & 0xFF);
WiredHome 19:3f82c1161fd2 582 WriteCommand(0x92, x1 >> 8);
WiredHome 19:3f82c1161fd2 583 WriteCommand(0x93, y1 & 0xFF);
WiredHome 19:3f82c1161fd2 584 WriteCommand(0x94, y1 >> 8);
WiredHome 19:3f82c1161fd2 585
WiredHome 19:3f82c1161fd2 586 WriteCommand(0x95, x2 & 0xFF);
WiredHome 19:3f82c1161fd2 587 WriteCommand(0x96, x2 >> 8);
WiredHome 19:3f82c1161fd2 588 WriteCommand(0x97, y2 & 0xFF);
WiredHome 19:3f82c1161fd2 589 WriteCommand(0x98, y2 >> 8);
WiredHome 19:3f82c1161fd2 590
WiredHome 19:3f82c1161fd2 591 WriteCommand(0xA9, x3 & 0xFF);
WiredHome 19:3f82c1161fd2 592 WriteCommand(0xAA, x3 >> 8);
WiredHome 19:3f82c1161fd2 593 WriteCommand(0xAB, y3 & 0xFF);
WiredHome 19:3f82c1161fd2 594 WriteCommand(0xAC, y3 >> 8);
WiredHome 19:3f82c1161fd2 595
WiredHome 19:3f82c1161fd2 596 unsigned char drawCmd = 0x01; // Triangle
WiredHome 19:3f82c1161fd2 597 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 598 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 599 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 600 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 601 while (ReadCommand(0x90) & 0x80) // await completion.
WiredHome 19:3f82c1161fd2 602 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 603 }
WiredHome 19:3f82c1161fd2 604 REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
WiredHome 19:3f82c1161fd2 605 return ret;
WiredHome 19:3f82c1161fd2 606 }
WiredHome 19:3f82c1161fd2 607
WiredHome 19:3f82c1161fd2 608 RetCode_t RA8875::circle(unsigned int x, unsigned int y, unsigned int radius,
WiredHome 19:3f82c1161fd2 609 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 610 {
WiredHome 19:3f82c1161fd2 611 foreground(color);
WiredHome 19:3f82c1161fd2 612 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 613 }
WiredHome 19:3f82c1161fd2 614
WiredHome 19:3f82c1161fd2 615 RetCode_t RA8875::fillcircle(unsigned int x, unsigned int y, unsigned int radius,
WiredHome 19:3f82c1161fd2 616 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 617 {
WiredHome 19:3f82c1161fd2 618 foreground(color);
WiredHome 19:3f82c1161fd2 619 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 620 }
WiredHome 19:3f82c1161fd2 621
WiredHome 19:3f82c1161fd2 622 RetCode_t RA8875::circle(unsigned int x, unsigned int y, unsigned int radius, fill_t fillit)
WiredHome 19:3f82c1161fd2 623 {
WiredHome 19:3f82c1161fd2 624 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 625
WiredHome 19:3f82c1161fd2 626 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 627 if (radius <= 0) {
WiredHome 19:3f82c1161fd2 628 ret = bad_parameter;
WiredHome 19:3f82c1161fd2 629 } else if (radius == 1) {
WiredHome 19:3f82c1161fd2 630 pixel(x,y);
WiredHome 19:3f82c1161fd2 631 } else {
WiredHome 19:3f82c1161fd2 632 WriteCommand(0x99, x & 0xFF);
WiredHome 19:3f82c1161fd2 633 WriteCommand(0x9a, x >> 8);
WiredHome 19:3f82c1161fd2 634 WriteCommand(0x9b, y & 0xFF);
WiredHome 19:3f82c1161fd2 635 WriteCommand(0x9c, y >> 8);
WiredHome 19:3f82c1161fd2 636 WriteCommand(0x9d, radius & 0xFF);
WiredHome 19:3f82c1161fd2 637
WiredHome 19:3f82c1161fd2 638 unsigned char drawCmd = 0x00; // Circle
WiredHome 19:3f82c1161fd2 639 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 640 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 641 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 642 WriteCommand(0x90, 0x40 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 643 while (ReadCommand(0x90) & 0x40) // await completion.
WiredHome 19:3f82c1161fd2 644 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 645 }
WiredHome 19:3f82c1161fd2 646 REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
WiredHome 19:3f82c1161fd2 647 return ret;
WiredHome 19:3f82c1161fd2 648 }
WiredHome 19:3f82c1161fd2 649
WiredHome 19:3f82c1161fd2 650 RetCode_t RA8875::ellipse(unsigned int x, unsigned int y, unsigned int R1, unsigned int R2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 651 {
WiredHome 19:3f82c1161fd2 652 foreground(color);
WiredHome 19:3f82c1161fd2 653 return ellipse(x,y,R1,R2,fillit);
WiredHome 19:3f82c1161fd2 654 }
WiredHome 19:3f82c1161fd2 655
WiredHome 19:3f82c1161fd2 656 RetCode_t RA8875::ellipse(unsigned int x, unsigned int y, unsigned int R1, unsigned int R2, fill_t fillit)
WiredHome 19:3f82c1161fd2 657 {
WiredHome 19:3f82c1161fd2 658 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 659
WiredHome 19:3f82c1161fd2 660 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 661 if (R1 <= 0 || R2 <= 0) {
WiredHome 19:3f82c1161fd2 662 ; // do nothing
WiredHome 19:3f82c1161fd2 663 } else if (R1 == 1 && R2 == 1) {
WiredHome 19:3f82c1161fd2 664 pixel(x, y);
WiredHome 19:3f82c1161fd2 665 } else {
WiredHome 19:3f82c1161fd2 666 WriteCommand(0xA5, x & 0xFF);
WiredHome 19:3f82c1161fd2 667 WriteCommand(0xA6, x >> 8);
WiredHome 19:3f82c1161fd2 668 WriteCommand(0xA7, y & 0xFF);
WiredHome 19:3f82c1161fd2 669 WriteCommand(0xA8, y >> 8);
WiredHome 19:3f82c1161fd2 670 WriteCommand(0xA1, R1 & 0xFF);
WiredHome 19:3f82c1161fd2 671 WriteCommand(0xA2, R1 >> 8);
WiredHome 19:3f82c1161fd2 672 WriteCommand(0xA3, R2 & 0xFF);
WiredHome 19:3f82c1161fd2 673 WriteCommand(0xA4, R2 >> 8);
WiredHome 19:3f82c1161fd2 674
WiredHome 19:3f82c1161fd2 675 unsigned char drawCmd = 0x00; // Ellipse
WiredHome 19:3f82c1161fd2 676 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 677 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 678 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 679 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 680 while (ReadCommand(0xA0) & 0x80) // await completion.
WiredHome 19:3f82c1161fd2 681 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 682 }
WiredHome 19:3f82c1161fd2 683 REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
WiredHome 19:3f82c1161fd2 684 return ret;
WiredHome 19:3f82c1161fd2 685 }
WiredHome 19:3f82c1161fd2 686
WiredHome 19:3f82c1161fd2 687
WiredHome 19:3f82c1161fd2 688 RetCode_t RA8875::frequency(unsigned long Hz)
WiredHome 19:3f82c1161fd2 689 {
WiredHome 19:3f82c1161fd2 690 spi.frequency(Hz);
WiredHome 19:3f82c1161fd2 691 // __ ___
WiredHome 19:3f82c1161fd2 692 // Clock ___A Rising edge latched
WiredHome 19:3f82c1161fd2 693 // ___ ____
WiredHome 19:3f82c1161fd2 694 // Data ___X____
WiredHome 19:3f82c1161fd2 695 spi.format(8, 3); // 8 bits and clock to data phase 0
WiredHome 19:3f82c1161fd2 696 init();
WiredHome 19:3f82c1161fd2 697 return noerror;
WiredHome 19:3f82c1161fd2 698 }
WiredHome 19:3f82c1161fd2 699
WiredHome 19:3f82c1161fd2 700 RetCode_t RA8875::Power(bool on)
WiredHome 19:3f82c1161fd2 701 {
WiredHome 19:3f82c1161fd2 702 WriteCommand(0x01, (on) ? 0x80 : 0x00);
WiredHome 19:3f82c1161fd2 703 return noerror;
WiredHome 19:3f82c1161fd2 704 }
WiredHome 19:3f82c1161fd2 705
WiredHome 19:3f82c1161fd2 706 RetCode_t RA8875::Reset(void)
WiredHome 19:3f82c1161fd2 707 {
WiredHome 19:3f82c1161fd2 708 WriteCommand(0x01, 0x01); // Apply Display Off, Reset
WiredHome 19:3f82c1161fd2 709 wait_ms(2); // no idea if I need to wait, or how long
WiredHome 19:3f82c1161fd2 710 WriteCommand(0x01, 0x00); // Display off, Remove reset
WiredHome 19:3f82c1161fd2 711 wait_ms(2); // no idea if I need to wait, or how long
WiredHome 19:3f82c1161fd2 712 init();
WiredHome 19:3f82c1161fd2 713 return noerror;
WiredHome 19:3f82c1161fd2 714 }
WiredHome 19:3f82c1161fd2 715
WiredHome 19:3f82c1161fd2 716
WiredHome 19:3f82c1161fd2 717 RetCode_t RA8875::Backlight_u8(unsigned char brightness)
WiredHome 19:3f82c1161fd2 718 {
WiredHome 19:3f82c1161fd2 719 static bool is_enabled = false;
WiredHome 19:3f82c1161fd2 720 if (brightness == 0) {
WiredHome 19:3f82c1161fd2 721 WriteCommand(0x8a); // Disable the PWM
WiredHome 19:3f82c1161fd2 722 WriteData(0x00);
WiredHome 19:3f82c1161fd2 723 is_enabled = false;
WiredHome 19:3f82c1161fd2 724 } else if (!is_enabled) {
WiredHome 19:3f82c1161fd2 725 WriteCommand(0x8a); // Enable the PWM
WiredHome 19:3f82c1161fd2 726 WriteData(0x80);
WiredHome 19:3f82c1161fd2 727 WriteCommand(0x8a); // Not sure why this is needed, but following the pattern
WiredHome 19:3f82c1161fd2 728 WriteData(0x81); // open PWM (SYS_CLK / 2 as best I can tell)
WiredHome 19:3f82c1161fd2 729 is_enabled = true;
WiredHome 19:3f82c1161fd2 730 }
WiredHome 19:3f82c1161fd2 731 WriteCommand(0x8b, brightness); // Brightness parameter 0xff-0x00
WiredHome 19:3f82c1161fd2 732 return noerror;
WiredHome 19:3f82c1161fd2 733 }
WiredHome 19:3f82c1161fd2 734
WiredHome 19:3f82c1161fd2 735 RetCode_t RA8875::Backlight(float brightness)
WiredHome 19:3f82c1161fd2 736 {
WiredHome 19:3f82c1161fd2 737 unsigned char b;
WiredHome 19:3f82c1161fd2 738
WiredHome 19:3f82c1161fd2 739 if (brightness > 1.0)
WiredHome 19:3f82c1161fd2 740 b = 255;
WiredHome 19:3f82c1161fd2 741 else if (brightness < 0)
WiredHome 19:3f82c1161fd2 742 b = 0;
WiredHome 19:3f82c1161fd2 743 else
WiredHome 19:3f82c1161fd2 744 b = (unsigned char)(brightness * 255);
WiredHome 19:3f82c1161fd2 745 return Backlight_u8(b);
WiredHome 19:3f82c1161fd2 746 }
WiredHome 19:3f82c1161fd2 747
WiredHome 19:3f82c1161fd2 748
WiredHome 19:3f82c1161fd2 749 RetCode_t RA8875::set_font(const unsigned char * _font)
WiredHome 19:3f82c1161fd2 750 {
WiredHome 19:3f82c1161fd2 751 font = _font;
WiredHome 19:3f82c1161fd2 752 return noerror; // trusting them, but we could put some checks in here...
WiredHome 19:3f82c1161fd2 753 }
WiredHome 19:3f82c1161fd2 754
WiredHome 19:3f82c1161fd2 755 RetCode_t RA8875::background(color_t color)
WiredHome 19:3f82c1161fd2 756 {
WiredHome 19:3f82c1161fd2 757 WriteCommand(0x60, (color>>11)); // BGCR0
WiredHome 19:3f82c1161fd2 758 WriteCommand(0x61, (unsigned char)(color>>5)); // BGCR0
WiredHome 19:3f82c1161fd2 759 WriteCommand(0x62, (unsigned char)(color)); // BGCR0
WiredHome 19:3f82c1161fd2 760 return noerror;
WiredHome 19:3f82c1161fd2 761 }
WiredHome 19:3f82c1161fd2 762
WiredHome 19:3f82c1161fd2 763 RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 764 {
WiredHome 19:3f82c1161fd2 765 WriteCommand(0x60, r);
WiredHome 19:3f82c1161fd2 766 WriteCommand(0x61, g);
WiredHome 19:3f82c1161fd2 767 WriteCommand(0x62, b);
WiredHome 19:3f82c1161fd2 768 return noerror;
WiredHome 19:3f82c1161fd2 769 }
WiredHome 19:3f82c1161fd2 770
WiredHome 19:3f82c1161fd2 771 RetCode_t RA8875::foreground(color_t color)
WiredHome 19:3f82c1161fd2 772 {
WiredHome 19:3f82c1161fd2 773 WriteCommand(0x63, (unsigned char)(color>>11));
WiredHome 19:3f82c1161fd2 774 WriteCommand(0x64, (unsigned char)(color>>5));
WiredHome 19:3f82c1161fd2 775 WriteCommand(0x65, (unsigned char)(color));
WiredHome 19:3f82c1161fd2 776 return noerror;
WiredHome 19:3f82c1161fd2 777 }
WiredHome 19:3f82c1161fd2 778
WiredHome 19:3f82c1161fd2 779 RetCode_t RA8875::foreground(unsigned char setR, unsigned char setG, unsigned char setB)
WiredHome 19:3f82c1161fd2 780 {
WiredHome 19:3f82c1161fd2 781 WriteCommand(0x63, setR);
WiredHome 19:3f82c1161fd2 782 WriteCommand(0x64, setG);
WiredHome 19:3f82c1161fd2 783 WriteCommand(0x65, setB);
WiredHome 19:3f82c1161fd2 784 return noerror;
WiredHome 19:3f82c1161fd2 785 }
WiredHome 19:3f82c1161fd2 786
WiredHome 19:3f82c1161fd2 787 unsigned int RA8875::GetForeColor(void)
WiredHome 19:3f82c1161fd2 788 {
WiredHome 19:3f82c1161fd2 789 color_t color;
WiredHome 19:3f82c1161fd2 790
WiredHome 19:3f82c1161fd2 791 color = (ReadCommand(0x63) & 0x1F) << 11;
WiredHome 19:3f82c1161fd2 792 color |= (ReadCommand(0x64) & 0x3F) << 5;
WiredHome 19:3f82c1161fd2 793 color |= (ReadCommand(0x65) & 0x1F);
WiredHome 19:3f82c1161fd2 794 return color;
WiredHome 19:3f82c1161fd2 795 }
WiredHome 19:3f82c1161fd2 796
WiredHome 19:3f82c1161fd2 797 color_t RA8875::DOSColor(int i)
WiredHome 19:3f82c1161fd2 798 {
WiredHome 19:3f82c1161fd2 799 const color_t colors[16] =
WiredHome 19:3f82c1161fd2 800 {
WiredHome 19:3f82c1161fd2 801 Black, Blue, Green, Cyan,
WiredHome 19:3f82c1161fd2 802 Red, Magenta, Brown, Gray,
WiredHome 19:3f82c1161fd2 803 Charcoal, BrightBlue, BrightGreen, BrightCyan,
WiredHome 19:3f82c1161fd2 804 Orange, Pink, Yellow, White
WiredHome 19:3f82c1161fd2 805 };
WiredHome 19:3f82c1161fd2 806 if (i < 16)
WiredHome 19:3f82c1161fd2 807 return colors[i];
WiredHome 19:3f82c1161fd2 808 else
WiredHome 19:3f82c1161fd2 809 return 0;
WiredHome 19:3f82c1161fd2 810 }
WiredHome 19:3f82c1161fd2 811
WiredHome 19:3f82c1161fd2 812 const char * RA8875::DOSColorNames(int i)
WiredHome 19:3f82c1161fd2 813 {
WiredHome 19:3f82c1161fd2 814 const char * names[16] =
WiredHome 19:3f82c1161fd2 815 {
WiredHome 19:3f82c1161fd2 816 "Black", "Blue", "Green", "Cyan",
WiredHome 19:3f82c1161fd2 817 "Red", "Magenta", "Brown", "Gray",
WiredHome 19:3f82c1161fd2 818 "Charcoal", "BrightBlue", "BrightGreen", "BrightCyan",
WiredHome 19:3f82c1161fd2 819 "Orange", "Pink", "Yellow", "White"
WiredHome 19:3f82c1161fd2 820 };
WiredHome 19:3f82c1161fd2 821 if (i < 16)
WiredHome 19:3f82c1161fd2 822 return names[i];
WiredHome 19:3f82c1161fd2 823 else
WiredHome 19:3f82c1161fd2 824 return NULL;
WiredHome 19:3f82c1161fd2 825 }
WiredHome 19:3f82c1161fd2 826
WiredHome 19:3f82c1161fd2 827
WiredHome 19:3f82c1161fd2 828 ///////////////////////////////////////////////////////////////
WiredHome 19:3f82c1161fd2 829 // Private functions
WiredHome 19:3f82c1161fd2 830
WiredHome 19:3f82c1161fd2 831 unsigned char RA8875::spiwrite(unsigned char data)
WiredHome 19:3f82c1161fd2 832 {
WiredHome 19:3f82c1161fd2 833 unsigned char retval;
WiredHome 19:3f82c1161fd2 834
WiredHome 19:3f82c1161fd2 835 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 836 return retval;
WiredHome 19:3f82c1161fd2 837 }
WiredHome 19:3f82c1161fd2 838
WiredHome 19:3f82c1161fd2 839 unsigned char RA8875::spiread(void)
WiredHome 19:3f82c1161fd2 840 {
WiredHome 19:3f82c1161fd2 841 unsigned char retval;
WiredHome 19:3f82c1161fd2 842 unsigned char data = 0;
WiredHome 19:3f82c1161fd2 843
WiredHome 19:3f82c1161fd2 844 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 845 return retval;
WiredHome 19:3f82c1161fd2 846 }
WiredHome 19:3f82c1161fd2 847
WiredHome 19:3f82c1161fd2 848 RetCode_t RA8875::select(bool chipsel)
WiredHome 19:3f82c1161fd2 849 {
WiredHome 19:3f82c1161fd2 850 cs = (chipsel == true) ? 0 : 1;
WiredHome 19:3f82c1161fd2 851 return noerror;
WiredHome 19:3f82c1161fd2 852 }
WiredHome 19:3f82c1161fd2 853
WiredHome 19:3f82c1161fd2 854 RetCode_t RA8875::init(void)
WiredHome 19:3f82c1161fd2 855 {
WiredHome 19:3f82c1161fd2 856 Backlight_u8(0);
WiredHome 19:3f82c1161fd2 857 WriteCommand(0x88, 0x0a); // PLLC1 - Phase Lock Loop registers
WiredHome 19:3f82c1161fd2 858 wait_ms(1);
WiredHome 19:3f82c1161fd2 859 WriteCommand(0x89, 0x02);
WiredHome 19:3f82c1161fd2 860 wait_ms(1);
WiredHome 19:3f82c1161fd2 861
WiredHome 23:a50ded45dbaf 862 // System Config Register (SYSR)
WiredHome 23:a50ded45dbaf 863 WriteCommand(0x10, 0x0C); // 16-bpp (65K colors) color depth, 8-bit interface
WiredHome 23:a50ded45dbaf 864 // Pixel Clock Setting Register (PCSR)
WiredHome 23:a50ded45dbaf 865 WriteCommand(0x04, 0x82); // PDAT on PCLK falling edge, PCLK = 4 x System Clock
WiredHome 19:3f82c1161fd2 866 wait_ms(1);
WiredHome 19:3f82c1161fd2 867
WiredHome 19:3f82c1161fd2 868 // Horizontal Settings
WiredHome 23:a50ded45dbaf 869 WriteCommand(0x14, RA8875_DISPLAY_WIDTH/8 - 1); //HDWR//Horizontal Display Width Setting Bit[6:0]
WiredHome 19:3f82c1161fd2 870 WriteCommand(0x15, 0x02); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
WiredHome 19:3f82c1161fd2 871 WriteCommand(0x16, 0x03); //HNDR//Horizontal Non-Display Period Bit[4:0]
WiredHome 19:3f82c1161fd2 872 WriteCommand(0x17, 0x01); //HSTR//HSYNC Start Position[4:0]
WiredHome 19:3f82c1161fd2 873 WriteCommand(0x18, 0x03); //HPWR//HSYNC Polarity ,The period width of HSYNC.
WiredHome 19:3f82c1161fd2 874
WiredHome 19:3f82c1161fd2 875 // Vertical Settings
WiredHome 23:a50ded45dbaf 876 WriteCommand(0x19, (RA8875_DISPLAY_HEIGHT-1)&0xFF); //VDHR0 //Vertical Display Height Bit [7:0]
WiredHome 23:a50ded45dbaf 877 WriteCommand(0x1a, (RA8875_DISPLAY_HEIGHT-1)>>8); //VDHR1 //Vertical Display Height Bit [8]
WiredHome 19:3f82c1161fd2 878 WriteCommand(0x1b, 0x0F); //VNDR0 //Vertical Non-Display Period Bit [7:0]
WiredHome 19:3f82c1161fd2 879 WriteCommand(0x1c, 0x00); //VNDR1 //Vertical Non-Display Period Bit [8]
WiredHome 19:3f82c1161fd2 880 WriteCommand(0x1d, 0x0e); //VSTR0 //VSYNC Start Position[7:0]
WiredHome 19:3f82c1161fd2 881 WriteCommand(0x1e, 0x06); //VSTR1 //VSYNC Start Position[8]
WiredHome 19:3f82c1161fd2 882 WriteCommand(0x1f, 0x01); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
WiredHome 19:3f82c1161fd2 883
WiredHome 19:3f82c1161fd2 884 // Clear ram image
WiredHome 19:3f82c1161fd2 885 SetWindow(0,0, width(), height()); // Initialize to full screen
WiredHome 24:8ca861acf12d 886 SetTextCursorControl();
WiredHome 19:3f82c1161fd2 887 foreground(Black);
WiredHome 19:3f82c1161fd2 888 background(Black);
WiredHome 19:3f82c1161fd2 889 cls();
WiredHome 19:3f82c1161fd2 890 return noerror;
WiredHome 19:3f82c1161fd2 891 }
WiredHome 19:3f82c1161fd2 892
WiredHome 23:a50ded45dbaf 893 #ifdef TESTENABLE
WiredHome 23:a50ded45dbaf 894
WiredHome 23:a50ded45dbaf 895 // ______________ ______________ ______________ _______________
WiredHome 23:a50ded45dbaf 896 // /_____ _____/ / ___________/ / ___________/ /_____ ______/
WiredHome 23:a50ded45dbaf 897 // / / / / / / / /
WiredHome 23:a50ded45dbaf 898 // / / / /___ / /__________ / /
WiredHome 23:a50ded45dbaf 899 // / / / ____/ /__________ / / /
WiredHome 23:a50ded45dbaf 900 // / / / / / / / /
WiredHome 23:a50ded45dbaf 901 // / / / /__________ ___________/ / / /
WiredHome 23:a50ded45dbaf 902 // /__/ /_____________/ /_____________/ /__/
WiredHome 23:a50ded45dbaf 903 //
WiredHome 23:a50ded45dbaf 904 // Everything from here down is test code.
WiredHome 23:a50ded45dbaf 905
WiredHome 23:a50ded45dbaf 906 void ValentineMessage(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 907 {
WiredHome 23:a50ded45dbaf 908 pc.printf("Write Sample text\r\n");
WiredHome 23:a50ded45dbaf 909 display.background(BrightRed);
WiredHome 23:a50ded45dbaf 910 display.foreground(White);
WiredHome 23:a50ded45dbaf 911 display.cls();
WiredHome 23:a50ded45dbaf 912 display.SetTextFontControl(NOFILL);
WiredHome 23:a50ded45dbaf 913 for (int i=0; i<20 ; i++) {
WiredHome 23:a50ded45dbaf 914 int sz = rand() & 1 + 1;
WiredHome 23:a50ded45dbaf 915 int rx = rand() % 360 + 0;
WiredHome 23:a50ded45dbaf 916 int ry = rand() % 250 + 0;
WiredHome 23:a50ded45dbaf 917 if (sz == 1)
WiredHome 23:a50ded45dbaf 918 rx /= 2;
WiredHome 23:a50ded45dbaf 919 display.SetTextCursor(rx, ry);
WiredHome 23:a50ded45dbaf 920 display.SetTextFontSize(sz, sz);
WiredHome 23:a50ded45dbaf 921 display.puts("David loves Louize");
WiredHome 23:a50ded45dbaf 922 wait_ms(50);
WiredHome 23:a50ded45dbaf 923 }
WiredHome 23:a50ded45dbaf 924 display.SetTextFontSize(2,2);
WiredHome 23:a50ded45dbaf 925 wait_ms(1000);
WiredHome 23:a50ded45dbaf 926 // Make a heart shape
WiredHome 23:a50ded45dbaf 927 display.ellipse(300, 120, 40, 50, FILL);
WiredHome 23:a50ded45dbaf 928 display.ellipse(370, 120, 40, 50, FILL);
WiredHome 23:a50ded45dbaf 929 display.triangle(265,145, 405,145, 335,230, FILL);
WiredHome 23:a50ded45dbaf 930 wait_ms(2500);
WiredHome 23:a50ded45dbaf 931 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 932 display.puts(300,90, "Be My");
WiredHome 23:a50ded45dbaf 933 wait_ms(500);
WiredHome 23:a50ded45dbaf 934 display.puts(262,118, "Valentine");
WiredHome 23:a50ded45dbaf 935 // put a few things back the way they were
WiredHome 23:a50ded45dbaf 936 display.SetTextFontControl(FILL);
WiredHome 23:a50ded45dbaf 937 display.SetTextFontSize(1,1);
WiredHome 23:a50ded45dbaf 938 display.background(Black);
WiredHome 23:a50ded45dbaf 939 }
WiredHome 23:a50ded45dbaf 940
WiredHome 23:a50ded45dbaf 941
WiredHome 23:a50ded45dbaf 942 void TextCursorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 943 {
WiredHome 24:8ca861acf12d 944 const char * iCursor = "The I-Beam cursor should be visible for this text, but it should not be blinking while writing this text.\r\n";
WiredHome 24:8ca861acf12d 945 const char * uCursor = "The Underscore cursor should be visible for this text, but it should not be blinking while writing this text.\r\n";
WiredHome 24:8ca861acf12d 946 const char * bCursor = "The Block cursor should be visible for this text, but it should not be blinking while writing this text.\r\n";
WiredHome 24:8ca861acf12d 947 const char * bbCursor = "The Blinking Block cursor should be visible for this text, and it should be blinking while writing this text.\r\n";
WiredHome 23:a50ded45dbaf 948 const char * p;
WiredHome 23:a50ded45dbaf 949
WiredHome 23:a50ded45dbaf 950 pc.printf("Text Cursor Test\r\n");
WiredHome 23:a50ded45dbaf 951 display.Backlight_u8(255);
WiredHome 23:a50ded45dbaf 952 display.background(Black);
WiredHome 23:a50ded45dbaf 953 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 954 display.cls();
WiredHome 23:a50ded45dbaf 955 display.puts(0,0, "Text Cursor Test.");
WiredHome 23:a50ded45dbaf 956
WiredHome 23:a50ded45dbaf 957 // visible, non-blinking
WiredHome 24:8ca861acf12d 958 display.SetTextCursor(0,20);
WiredHome 24:8ca861acf12d 959 display.SetTextCursorControl(IBEAM, false);
WiredHome 24:8ca861acf12d 960 p = iCursor;
WiredHome 23:a50ded45dbaf 961 while (*p) {
WiredHome 24:8ca861acf12d 962 display._putc(*p++);
WiredHome 24:8ca861acf12d 963 wait_ms(100);
WiredHome 24:8ca861acf12d 964 }
WiredHome 24:8ca861acf12d 965
WiredHome 24:8ca861acf12d 966 display.SetTextCursorControl(UNDER, false);
WiredHome 24:8ca861acf12d 967 p = uCursor;
WiredHome 24:8ca861acf12d 968 while (*p) {
WiredHome 24:8ca861acf12d 969 display._putc(*p++);
WiredHome 23:a50ded45dbaf 970 wait_ms(100);
WiredHome 23:a50ded45dbaf 971 }
WiredHome 24:8ca861acf12d 972
WiredHome 24:8ca861acf12d 973 display.SetTextCursorControl(BLOCK, false);
WiredHome 24:8ca861acf12d 974 p = bCursor;
WiredHome 24:8ca861acf12d 975 while (*p) {
WiredHome 24:8ca861acf12d 976 display._putc(*p++);
WiredHome 24:8ca861acf12d 977 wait_ms(100);
WiredHome 24:8ca861acf12d 978 }
WiredHome 24:8ca861acf12d 979
WiredHome 24:8ca861acf12d 980 display.SetTextCursorControl(BLOCK, true);
WiredHome 24:8ca861acf12d 981 p = bbCursor;
WiredHome 24:8ca861acf12d 982 while (*p) {
WiredHome 24:8ca861acf12d 983 display._putc(*p++);
WiredHome 24:8ca861acf12d 984 wait_ms(100);
WiredHome 24:8ca861acf12d 985 }
WiredHome 24:8ca861acf12d 986 wait_ms(2000);
WiredHome 24:8ca861acf12d 987 display.SetTextCursorControl(NOCURSOR, false);
WiredHome 23:a50ded45dbaf 988 }
WiredHome 23:a50ded45dbaf 989
WiredHome 23:a50ded45dbaf 990 void BacklightTest(RA8875 & display, Serial & pc, float ramptime)
WiredHome 23:a50ded45dbaf 991 {
WiredHome 23:a50ded45dbaf 992 pc.printf("Backlight Test - ramp over %f sec.\r\n", ramptime);
WiredHome 23:a50ded45dbaf 993 display.Backlight_u8(0);
WiredHome 23:a50ded45dbaf 994 display.background(Black);
WiredHome 23:a50ded45dbaf 995 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 996 display.cls();
WiredHome 23:a50ded45dbaf 997 display.puts(0,0, "RA8875 Backlight Test - Ramp up.");
WiredHome 23:a50ded45dbaf 998 for (int i=0; i < 255; i++) {
WiredHome 23:a50ded45dbaf 999 display.Backlight_u8(i);
WiredHome 23:a50ded45dbaf 1000 wait_ms((ramptime * 1000)/ 256);
WiredHome 23:a50ded45dbaf 1001 }
WiredHome 23:a50ded45dbaf 1002 }
WiredHome 23:a50ded45dbaf 1003
WiredHome 23:a50ded45dbaf 1004 void BacklightTest2(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1005 {
WiredHome 23:a50ded45dbaf 1006 pc.printf("Backlight Test 2\r\n");
WiredHome 23:a50ded45dbaf 1007 // Dim it out at the end of the tests.
WiredHome 23:a50ded45dbaf 1008 display.foreground(Yellow);
WiredHome 23:a50ded45dbaf 1009 display.puts(0,0, "Ramp Backlight down.");
WiredHome 23:a50ded45dbaf 1010 // Ramp it off
WiredHome 23:a50ded45dbaf 1011 for (int i=255; i != 0; i--) {
WiredHome 23:a50ded45dbaf 1012 display.Backlight_u8(i);
WiredHome 23:a50ded45dbaf 1013 wait_ms(20);
WiredHome 23:a50ded45dbaf 1014 }
WiredHome 23:a50ded45dbaf 1015 display.Backlight_u8(0);
WiredHome 23:a50ded45dbaf 1016 }
WiredHome 23:a50ded45dbaf 1017
WiredHome 23:a50ded45dbaf 1018 void ExternalFontTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1019 {
WiredHome 23:a50ded45dbaf 1020 pc.printf("External Font Test\r\n");
WiredHome 23:a50ded45dbaf 1021 display.background(Black);
WiredHome 23:a50ded45dbaf 1022 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1023 display.cls();
WiredHome 23:a50ded45dbaf 1024 display.Backlight(1);
WiredHome 23:a50ded45dbaf 1025 display.set_font(Arial12x12);
WiredHome 23:a50ded45dbaf 1026 display.puts(0,0,"ABCDEFGHIJKLMNOPWRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
WiredHome 23:a50ded45dbaf 1027 }
WiredHome 23:a50ded45dbaf 1028
WiredHome 23:a50ded45dbaf 1029 void DOSColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1030 {
WiredHome 23:a50ded45dbaf 1031 pc.printf("DOS Color Test\r\n");
WiredHome 23:a50ded45dbaf 1032 display.background(Black);
WiredHome 23:a50ded45dbaf 1033 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1034 display.cls();
WiredHome 23:a50ded45dbaf 1035 display.puts(0,0, "DOS Colors - Fore");
WiredHome 23:a50ded45dbaf 1036 display.puts(280,0, "Back");
WiredHome 23:a50ded45dbaf 1037 display.background(Gray);
WiredHome 23:a50ded45dbaf 1038 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1039 display.foreground(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1040 display.puts(160, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 1041 display.background(Black);
WiredHome 23:a50ded45dbaf 1042 }
WiredHome 23:a50ded45dbaf 1043 display.foreground(White);
WiredHome 23:a50ded45dbaf 1044 for (int i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1045 display.background(display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1046 display.puts(360, i*16, display.DOSColorNames(i));
WiredHome 23:a50ded45dbaf 1047 display.foreground(White);
WiredHome 23:a50ded45dbaf 1048 }
WiredHome 23:a50ded45dbaf 1049 }
WiredHome 23:a50ded45dbaf 1050
WiredHome 23:a50ded45dbaf 1051 void WebColorTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1052 {
WiredHome 23:a50ded45dbaf 1053 pc.printf("Web Color Test\r\n");
WiredHome 23:a50ded45dbaf 1054 display.background(Black);
WiredHome 23:a50ded45dbaf 1055 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1056 display.SetWindow(0,0, display.width(), display.height());
WiredHome 23:a50ded45dbaf 1057 display.cls();
WiredHome 23:a50ded45dbaf 1058 display.puts(0,0, "Web Color Test\r\n");
WiredHome 23:a50ded45dbaf 1059 display.SetTextFontSize(1,2);
WiredHome 23:a50ded45dbaf 1060 for (int i=0; i<sizeof(WebColors)/sizeof(WebColors[0]); i++) {
WiredHome 23:a50ded45dbaf 1061 display.background(WebColors[i]);
WiredHome 23:a50ded45dbaf 1062 display.puts(" ");
WiredHome 23:a50ded45dbaf 1063 if (i % 36 == 35)
WiredHome 23:a50ded45dbaf 1064 display.puts("\r\n");
WiredHome 23:a50ded45dbaf 1065 }
WiredHome 23:a50ded45dbaf 1066 display.SetTextFontSize(1,1);
WiredHome 23:a50ded45dbaf 1067 }
WiredHome 23:a50ded45dbaf 1068
WiredHome 23:a50ded45dbaf 1069 void LineTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1070 {
WiredHome 23:a50ded45dbaf 1071 int i, x, y, x2, y2;
WiredHome 23:a50ded45dbaf 1072
WiredHome 23:a50ded45dbaf 1073 pc.printf("Line Test\r\n");
WiredHome 23:a50ded45dbaf 1074 display.background(Black);
WiredHome 23:a50ded45dbaf 1075 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1076 display.cls();
WiredHome 23:a50ded45dbaf 1077 display.puts(0,0, "Line Test");
WiredHome 23:a50ded45dbaf 1078 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1079 // Lines
WiredHome 23:a50ded45dbaf 1080 x = rand() % 480;
WiredHome 23:a50ded45dbaf 1081 y = rand() % 272;
WiredHome 23:a50ded45dbaf 1082 x2 = rand() % 480;
WiredHome 23:a50ded45dbaf 1083 y2 = rand() % 272;
WiredHome 23:a50ded45dbaf 1084 display.line(x,y, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1085 }
WiredHome 23:a50ded45dbaf 1086 }
WiredHome 23:a50ded45dbaf 1087
WiredHome 23:a50ded45dbaf 1088 void RectangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1089 {
WiredHome 23:a50ded45dbaf 1090 int i, x1,y1, x2,y2;
WiredHome 23:a50ded45dbaf 1091
WiredHome 23:a50ded45dbaf 1092 pc.printf("Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 1093 display.background(Black);
WiredHome 23:a50ded45dbaf 1094 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1095 display.cls();
WiredHome 23:a50ded45dbaf 1096 display.puts(0,0, "Rectangle Test");
WiredHome 23:a50ded45dbaf 1097 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1098 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 1099 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1100 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 1101 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1102 display.rect(x1,y1, x2,y2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1103
WiredHome 23:a50ded45dbaf 1104 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1105 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1106 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1107 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1108 display.rect(x1,y1, x2,y2, FILL);
WiredHome 23:a50ded45dbaf 1109 }
WiredHome 23:a50ded45dbaf 1110 }
WiredHome 23:a50ded45dbaf 1111
WiredHome 23:a50ded45dbaf 1112
WiredHome 23:a50ded45dbaf 1113 void RoundRectTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1114 {
WiredHome 23:a50ded45dbaf 1115 unsigned int i, x1,y1, x2,y2, r1,r2;
WiredHome 23:a50ded45dbaf 1116
WiredHome 23:a50ded45dbaf 1117 pc.printf("Round Rectangle Test\r\n");
WiredHome 23:a50ded45dbaf 1118 display.background(Black);
WiredHome 23:a50ded45dbaf 1119 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1120 display.cls();
WiredHome 23:a50ded45dbaf 1121 display.puts(0,0, "Rounded Rectangle Test");
WiredHome 23:a50ded45dbaf 1122
WiredHome 23:a50ded45dbaf 1123 #if 0
WiredHome 23:a50ded45dbaf 1124 i = 3;
WiredHome 23:a50ded45dbaf 1125 x1 = 30; y1 = 30;
WiredHome 23:a50ded45dbaf 1126 x2 = 200; y2 = 100;
WiredHome 23:a50ded45dbaf 1127 r1 = 10; r2 = 20;
WiredHome 23:a50ded45dbaf 1128 pc.printf(" (%3d,%3d), (%3d,%3d): (%2d,%2d) - %04X\r\n", x1,y1, x2,y2, r1,r2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1129 display.roundrect(x1,y1, x2,y2, r1,r2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1130
WiredHome 23:a50ded45dbaf 1131 x1 = 230; y1 = 30;
WiredHome 23:a50ded45dbaf 1132 x2 = 400; y2 = 100;
WiredHome 23:a50ded45dbaf 1133 r1 = 30; r2 = 34;
WiredHome 23:a50ded45dbaf 1134 pc.printf(" (%3d,%3d), (%3d,%3d): (%2d,%2d) - %04X\r\n", x1,y1, x2,y2, r1,r2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1135 display.roundrect(x1,y1, x2,y2, r1,r2, display.DOSColor(i), NOFILL);
WiredHome 23:a50ded45dbaf 1136 #endif
WiredHome 23:a50ded45dbaf 1137
WiredHome 23:a50ded45dbaf 1138 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1139 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 1140 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1141 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 1142 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 1143 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 1144 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 1145 display.roundrect(x1,y1, x2,y2, 5,8, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1146
WiredHome 23:a50ded45dbaf 1147 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1148 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1149 x2 = x1 + rand() % 100;
WiredHome 23:a50ded45dbaf 1150 y2 = y1 + rand() % 100;
WiredHome 23:a50ded45dbaf 1151 r1 = rand() % (x2 - x1)/2;
WiredHome 23:a50ded45dbaf 1152 r2 = rand() % (y2 - y1)/2;
WiredHome 23:a50ded45dbaf 1153 display.roundrect(x1,y1, x2,y2, r1,r2, FILL);
WiredHome 23:a50ded45dbaf 1154 }
WiredHome 23:a50ded45dbaf 1155 }
WiredHome 23:a50ded45dbaf 1156
WiredHome 23:a50ded45dbaf 1157 void TriangleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1158 {
WiredHome 23:a50ded45dbaf 1159 int i, x1, y1, x2, y2, x3, y3;
WiredHome 23:a50ded45dbaf 1160
WiredHome 23:a50ded45dbaf 1161 pc.printf("Triangle Test\r\n");
WiredHome 23:a50ded45dbaf 1162 display.background(Black);
WiredHome 23:a50ded45dbaf 1163 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1164 display.cls();
WiredHome 23:a50ded45dbaf 1165 display.puts(0,0, "Triangle Test");
WiredHome 23:a50ded45dbaf 1166
WiredHome 23:a50ded45dbaf 1167 x1 = 150;
WiredHome 23:a50ded45dbaf 1168 y1 = 2;
WiredHome 23:a50ded45dbaf 1169 x2 = 190;
WiredHome 23:a50ded45dbaf 1170 y2 = 7;
WiredHome 23:a50ded45dbaf 1171 x3 = 170;
WiredHome 23:a50ded45dbaf 1172 y3 = 16;
WiredHome 23:a50ded45dbaf 1173 display.triangle(x1,y1, x2,y2, x3,y3);
WiredHome 23:a50ded45dbaf 1174
WiredHome 23:a50ded45dbaf 1175 x1 = 200;
WiredHome 23:a50ded45dbaf 1176 y1 = 2;
WiredHome 23:a50ded45dbaf 1177 x2 = 240;
WiredHome 23:a50ded45dbaf 1178 y2 = 7;
WiredHome 23:a50ded45dbaf 1179 x3 = 220;
WiredHome 23:a50ded45dbaf 1180 y3 = 16;
WiredHome 23:a50ded45dbaf 1181 display.filltriangle(x1,y1, x2,y2, x3,y3, BrightRed);
WiredHome 23:a50ded45dbaf 1182
WiredHome 23:a50ded45dbaf 1183 x1 = 300;
WiredHome 23:a50ded45dbaf 1184 y1 = 2;
WiredHome 23:a50ded45dbaf 1185 x2 = 340;
WiredHome 23:a50ded45dbaf 1186 y2 = 7;
WiredHome 23:a50ded45dbaf 1187 x3 = 320;
WiredHome 23:a50ded45dbaf 1188 y3 = 16;
WiredHome 23:a50ded45dbaf 1189 display.triangle(x1,y1, x2,y2, x3,y3, NOFILL);
WiredHome 23:a50ded45dbaf 1190
WiredHome 23:a50ded45dbaf 1191 x1 = 400;
WiredHome 23:a50ded45dbaf 1192 y1 = 2;
WiredHome 23:a50ded45dbaf 1193 x2 = 440;
WiredHome 23:a50ded45dbaf 1194 y2 = 7;
WiredHome 23:a50ded45dbaf 1195 x3 = 420;
WiredHome 23:a50ded45dbaf 1196 y3 = 16;
WiredHome 23:a50ded45dbaf 1197 display.triangle(x1,y1, x2,y2, x3,y3, Blue);
WiredHome 23:a50ded45dbaf 1198
WiredHome 23:a50ded45dbaf 1199 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1200 x1 = rand() % 240;
WiredHome 23:a50ded45dbaf 1201 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1202 x2 = rand() % 240;
WiredHome 23:a50ded45dbaf 1203 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1204 x3 = rand() % 240;
WiredHome 23:a50ded45dbaf 1205 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1206 display.triangle(x1,y1, x2,y2, x3,y3, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1207 x1 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1208 y1 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1209 x2 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1210 y2 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1211 x3 = 240 + rand() % 240;
WiredHome 23:a50ded45dbaf 1212 y3 = 50 + rand() % 200;
WiredHome 23:a50ded45dbaf 1213 display.triangle(x1,y1, x2,y2, x3,y3, FILL);
WiredHome 23:a50ded45dbaf 1214 }
WiredHome 23:a50ded45dbaf 1215 }
WiredHome 23:a50ded45dbaf 1216
WiredHome 23:a50ded45dbaf 1217 void CircleTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1218 {
WiredHome 23:a50ded45dbaf 1219 int i, x, y, r1;
WiredHome 23:a50ded45dbaf 1220
WiredHome 23:a50ded45dbaf 1221 pc.printf("Circle Test\r\n");
WiredHome 23:a50ded45dbaf 1222 display.background(Black);
WiredHome 23:a50ded45dbaf 1223 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1224 display.cls();
WiredHome 23:a50ded45dbaf 1225 display.puts(0,0, "Circle Test");
WiredHome 23:a50ded45dbaf 1226 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1227 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 1228 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 1229 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1230 //pc.printf(" (%d,%d) - %d\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 1231 display.circle(x,y,r1, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1232
WiredHome 23:a50ded45dbaf 1233 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 1234 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 1235 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1236 //pc.printf(" (%d,%d) - %d FILL\r\n", x,y,r1);
WiredHome 23:a50ded45dbaf 1237 display.circle(x,y,r1, display.DOSColor(i), FILL);
WiredHome 23:a50ded45dbaf 1238 }
WiredHome 23:a50ded45dbaf 1239 }
WiredHome 23:a50ded45dbaf 1240
WiredHome 23:a50ded45dbaf 1241 void EllipseTest(RA8875 & display, Serial & pc)
WiredHome 23:a50ded45dbaf 1242 {
WiredHome 23:a50ded45dbaf 1243 int i,x,y,r1,r2;
WiredHome 23:a50ded45dbaf 1244
WiredHome 23:a50ded45dbaf 1245 pc.printf("Ellipse Test\r\n");
WiredHome 23:a50ded45dbaf 1246 display.background(Black);
WiredHome 23:a50ded45dbaf 1247 display.foreground(Blue);
WiredHome 23:a50ded45dbaf 1248 display.cls();
WiredHome 23:a50ded45dbaf 1249 display.puts(0,0, "Ellipse Test");
WiredHome 23:a50ded45dbaf 1250 for (i=0; i<16; i++) {
WiredHome 23:a50ded45dbaf 1251 x = 100 + rand() % 100;
WiredHome 23:a50ded45dbaf 1252 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 1253 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1254 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1255 display.ellipse(x,y,r1,r2, display.DOSColor(i));
WiredHome 23:a50ded45dbaf 1256
WiredHome 23:a50ded45dbaf 1257 x = 300 + rand() % 100;
WiredHome 23:a50ded45dbaf 1258 y = 70 + rand() % 200;
WiredHome 23:a50ded45dbaf 1259 r1 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1260 r2 = rand() % min(y - 20, 100);
WiredHome 23:a50ded45dbaf 1261 display.ellipse(x,y,r1,r2, FILL);
WiredHome 23:a50ded45dbaf 1262 }
WiredHome 23:a50ded45dbaf 1263 }
WiredHome 23:a50ded45dbaf 1264
WiredHome 23:a50ded45dbaf 1265 void RunTestSet(RA8875 & lcd, Serial & pc)
WiredHome 23:a50ded45dbaf 1266 {
WiredHome 23:a50ded45dbaf 1267 int q = 0;
WiredHome 23:a50ded45dbaf 1268 int automode = 0;
WiredHome 23:a50ded45dbaf 1269 const unsigned char modelist[] = "BDWLROTCEbt"; // auto-test in this order.
WiredHome 23:a50ded45dbaf 1270
WiredHome 23:a50ded45dbaf 1271 while(1) {
WiredHome 23:a50ded45dbaf 1272 pc.printf("\r\n"
WiredHome 23:a50ded45dbaf 1273 "B - Backlight up b - backlight dim\r\n"
WiredHome 23:a50ded45dbaf 1274 "D - DOS Colors W - Web Colors\r\n"
WiredHome 23:a50ded45dbaf 1275 "t - text cursor \r\n"
WiredHome 23:a50ded45dbaf 1276 "L - Lines F - external Font\r\n"
WiredHome 23:a50ded45dbaf 1277 "R - Rectangles O - rOund rectangles\r\n"
WiredHome 23:a50ded45dbaf 1278 "T - Triangles \r\n"
WiredHome 23:a50ded45dbaf 1279 "C - Circles E - Ellipses\r\n"
WiredHome 23:a50ded45dbaf 1280 "V - Valentine r - reset \r\n"
WiredHome 23:a50ded45dbaf 1281 "A - Auto Test mode \r\n"
WiredHome 23:a50ded45dbaf 1282 "> ");
WiredHome 23:a50ded45dbaf 1283 if (automode == -1 || pc.readable()) {
WiredHome 23:a50ded45dbaf 1284 automode = -1;
WiredHome 23:a50ded45dbaf 1285 q = getchar();
WiredHome 23:a50ded45dbaf 1286 } else if (automode >= 0) {
WiredHome 23:a50ded45dbaf 1287 q = modelist[automode];
WiredHome 23:a50ded45dbaf 1288 }
WiredHome 23:a50ded45dbaf 1289 switch(q) {
WiredHome 23:a50ded45dbaf 1290 case 'A':
WiredHome 23:a50ded45dbaf 1291 automode = 0;
WiredHome 23:a50ded45dbaf 1292 break;
WiredHome 23:a50ded45dbaf 1293 case 'B':
WiredHome 23:a50ded45dbaf 1294 BacklightTest(lcd, pc, 2);
WiredHome 23:a50ded45dbaf 1295 break;
WiredHome 23:a50ded45dbaf 1296 case 'b':
WiredHome 23:a50ded45dbaf 1297 BacklightTest2(lcd, pc);
WiredHome 23:a50ded45dbaf 1298 break;
WiredHome 23:a50ded45dbaf 1299 case 'D':
WiredHome 23:a50ded45dbaf 1300 DOSColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1301 break;
WiredHome 23:a50ded45dbaf 1302 case 'W':
WiredHome 23:a50ded45dbaf 1303 WebColorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1304 break;
WiredHome 23:a50ded45dbaf 1305 case 't':
WiredHome 23:a50ded45dbaf 1306 TextCursorTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1307 break;
WiredHome 23:a50ded45dbaf 1308 case 'F':
WiredHome 23:a50ded45dbaf 1309 ExternalFontTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1310 break;
WiredHome 23:a50ded45dbaf 1311 case 'L':
WiredHome 23:a50ded45dbaf 1312 LineTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1313 break;
WiredHome 23:a50ded45dbaf 1314 case 'R':
WiredHome 23:a50ded45dbaf 1315 RectangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1316 break;
WiredHome 23:a50ded45dbaf 1317 case 'O':
WiredHome 23:a50ded45dbaf 1318 RoundRectTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1319 break;
WiredHome 23:a50ded45dbaf 1320 case 'T':
WiredHome 23:a50ded45dbaf 1321 TriangleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1322 break;
WiredHome 23:a50ded45dbaf 1323 case 'C':
WiredHome 23:a50ded45dbaf 1324 CircleTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1325 break;
WiredHome 23:a50ded45dbaf 1326 case 'E':
WiredHome 23:a50ded45dbaf 1327 EllipseTest(lcd, pc);
WiredHome 23:a50ded45dbaf 1328 break;
WiredHome 23:a50ded45dbaf 1329 case 'V':
WiredHome 23:a50ded45dbaf 1330 ValentineMessage(lcd, pc);
WiredHome 23:a50ded45dbaf 1331 break;
WiredHome 23:a50ded45dbaf 1332 case 'r':
WiredHome 23:a50ded45dbaf 1333 pc.printf("Resetting ...\r\n");
WiredHome 23:a50ded45dbaf 1334 wait_ms(20);
WiredHome 23:a50ded45dbaf 1335 mbed_reset();
WiredHome 23:a50ded45dbaf 1336 break;
WiredHome 23:a50ded45dbaf 1337 default:
WiredHome 23:a50ded45dbaf 1338 printf("huh?\n");
WiredHome 23:a50ded45dbaf 1339 break;
WiredHome 23:a50ded45dbaf 1340 }
WiredHome 23:a50ded45dbaf 1341 if (automode >= 0) {
WiredHome 23:a50ded45dbaf 1342 automode++;
WiredHome 23:a50ded45dbaf 1343 if (automode >= sizeof(modelist))
WiredHome 23:a50ded45dbaf 1344 automode = 0;
WiredHome 23:a50ded45dbaf 1345 wait_ms(2000);
WiredHome 23:a50ded45dbaf 1346 }
WiredHome 23:a50ded45dbaf 1347 wait_ms(200);
WiredHome 23:a50ded45dbaf 1348 }
WiredHome 23:a50ded45dbaf 1349 }
WiredHome 23:a50ded45dbaf 1350
WiredHome 23:a50ded45dbaf 1351 #endif // TESTENABLE