Fork of David Smart's RA8875 library

Fork of RA8875 by David Smart

Committer:
WiredHome
Date:
Sat Jan 25 19:47:33 2014 +0000
Revision:
37:f19b7e7449dc
Parent:
32:0e4f2ae512e2
Child:
38:38d503b4fad6
major API tweak to use typedef's for pixel locations, dimensions, and text locations.

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