Fork of David Smart's RA8875 library for the purpose of adding touch screen support

Fork of RA8875 by David Smart

Committer:
WiredHome
Date:
Sun Jan 12 21:11:15 2014 +0000
Revision:
21:3c1efb192927
Parent:
20:6e2e4a8372eb
Child:
23:a50ded45dbaf
Rounded rectangle now working.

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 /// @TODO what is the size?
WiredHome 19:3f82c1161fd2 34 /// If we're using the built-in font, read it from the chip.
WiredHome 19:3f82c1161fd2 35 /// If we're using a custom font, get it from the font metrics.
WiredHome 19:3f82c1161fd2 36 const int size_x = 16;
WiredHome 19:3f82c1161fd2 37 const int size_y = 16;
WiredHome 19:3f82c1161fd2 38
WiredHome 19:3f82c1161fd2 39
WiredHome 19:3f82c1161fd2 40 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 41 #define PERFORMANCE_RESET performance.reset()
WiredHome 19:3f82c1161fd2 42 #define REGISTERPERFORMANCE(a) RegisterPerformance(a)
WiredHome 19:3f82c1161fd2 43 static const char *metricsName[] =
WiredHome 19:3f82c1161fd2 44 {
WiredHome 19:3f82c1161fd2 45 "Point", "Line", "Rectangle", "Rounded Rectangle", "Triangle", "Circle", "Ellipse"
WiredHome 19:3f82c1161fd2 46 };
WiredHome 19:3f82c1161fd2 47 #else
WiredHome 19:3f82c1161fd2 48 #define PERFORMANCE_RESET
WiredHome 19:3f82c1161fd2 49 #define REGISTERPERFORMANCE(a)
WiredHome 19:3f82c1161fd2 50 #endif
WiredHome 19:3f82c1161fd2 51
WiredHome 19:3f82c1161fd2 52 // When it is going to poll a register for completion, how many
WiredHome 19:3f82c1161fd2 53 // uSec should it wait between each polling activity.
WiredHome 19:3f82c1161fd2 54 #define POLLWAITuSec 10
WiredHome 19:3f82c1161fd2 55
WiredHome 19:3f82c1161fd2 56
WiredHome 19:3f82c1161fd2 57 RA8875::RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, const char *name)
WiredHome 19:3f82c1161fd2 58 : spi(mosi, miso, sclk)
WiredHome 19:3f82c1161fd2 59 , cs(csel)
WiredHome 19:3f82c1161fd2 60 , res(reset)
WiredHome 19:3f82c1161fd2 61 , GraphicsDisplay(name)
WiredHome 19:3f82c1161fd2 62 {
WiredHome 19:3f82c1161fd2 63 font = NULL; // no external font, use internal.
WiredHome 19:3f82c1161fd2 64 select(false); // deselect the display
WiredHome 19:3f82c1161fd2 65 frequency(RA8875_DEFAULT_SPI_FREQ); // data rate
WiredHome 19:3f82c1161fd2 66 init();
WiredHome 19:3f82c1161fd2 67 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 68 performance.start();
WiredHome 19:3f82c1161fd2 69 ClearPerformance();
WiredHome 19:3f82c1161fd2 70 #endif
WiredHome 19:3f82c1161fd2 71 }
WiredHome 19:3f82c1161fd2 72
WiredHome 19:3f82c1161fd2 73 //RA8875::~RA8875()
WiredHome 19:3f82c1161fd2 74 //{
WiredHome 19:3f82c1161fd2 75 //}
WiredHome 19:3f82c1161fd2 76
WiredHome 19:3f82c1161fd2 77 #ifdef PERF_METRICS
WiredHome 19:3f82c1161fd2 78 void RA8875::ClearPerformance()
WiredHome 19:3f82c1161fd2 79 {
WiredHome 19:3f82c1161fd2 80 for (int i=0; i<METRICCOUNT; i++)
WiredHome 19:3f82c1161fd2 81 metrics[i] = 0;
WiredHome 19:3f82c1161fd2 82 }
WiredHome 19:3f82c1161fd2 83
WiredHome 19:3f82c1161fd2 84 void RA8875::RegisterPerformance(method_e method)
WiredHome 19:3f82c1161fd2 85 {
WiredHome 19:3f82c1161fd2 86 unsigned long elapsed = performance.read_us();
WiredHome 19:3f82c1161fd2 87
WiredHome 19:3f82c1161fd2 88 if (method < METRICCOUNT && elapsed > metrics[method])
WiredHome 19:3f82c1161fd2 89 metrics[method] = elapsed;
WiredHome 19:3f82c1161fd2 90 }
WiredHome 19:3f82c1161fd2 91
WiredHome 19:3f82c1161fd2 92 void RA8875::ReportPerformance()
WiredHome 19:3f82c1161fd2 93 {
WiredHome 19:3f82c1161fd2 94 for (int i=0; i<METRICCOUNT; i++) {
WiredHome 19:3f82c1161fd2 95 printf("%10d uS %s\r\n", metrics[i], metricsName[i]);
WiredHome 19:3f82c1161fd2 96 }
WiredHome 19:3f82c1161fd2 97 }
WiredHome 19:3f82c1161fd2 98 #endif
WiredHome 19:3f82c1161fd2 99
WiredHome 19:3f82c1161fd2 100 RetCode_t RA8875::WriteCommand(unsigned char command, unsigned int data)
WiredHome 19:3f82c1161fd2 101 {
WiredHome 19:3f82c1161fd2 102 select(true);
WiredHome 19:3f82c1161fd2 103 spiwrite(0x80);
WiredHome 19:3f82c1161fd2 104 spiwrite(command);
WiredHome 19:3f82c1161fd2 105 if (data <= 0xFF) { // only if in the valid range
WiredHome 19:3f82c1161fd2 106 spiwrite(0x00);
WiredHome 19:3f82c1161fd2 107 spiwrite(data);
WiredHome 19:3f82c1161fd2 108 }
WiredHome 19:3f82c1161fd2 109 select(false);
WiredHome 19:3f82c1161fd2 110 return noerror;
WiredHome 19:3f82c1161fd2 111 }
WiredHome 19:3f82c1161fd2 112
WiredHome 19:3f82c1161fd2 113 RetCode_t RA8875::WriteData(unsigned char data)
WiredHome 19:3f82c1161fd2 114 {
WiredHome 19:3f82c1161fd2 115 select(true);
WiredHome 19:3f82c1161fd2 116 spiwrite(0x00);
WiredHome 19:3f82c1161fd2 117 spiwrite(data);
WiredHome 19:3f82c1161fd2 118 select(false);
WiredHome 19:3f82c1161fd2 119 return noerror;
WiredHome 19:3f82c1161fd2 120 }
WiredHome 19:3f82c1161fd2 121
WiredHome 19:3f82c1161fd2 122 unsigned char RA8875::ReadCommand(unsigned char command)
WiredHome 19:3f82c1161fd2 123 {
WiredHome 19:3f82c1161fd2 124 WriteCommand(command);
WiredHome 19:3f82c1161fd2 125 return ReadData();
WiredHome 19:3f82c1161fd2 126 }
WiredHome 19:3f82c1161fd2 127
WiredHome 19:3f82c1161fd2 128 unsigned char RA8875::ReadData(void)
WiredHome 19:3f82c1161fd2 129 {
WiredHome 19:3f82c1161fd2 130 unsigned char data;
WiredHome 19:3f82c1161fd2 131
WiredHome 19:3f82c1161fd2 132 select(true);
WiredHome 19:3f82c1161fd2 133 spiwrite(0x40);
WiredHome 19:3f82c1161fd2 134 data = spiread();
WiredHome 19:3f82c1161fd2 135 select(false);
WiredHome 19:3f82c1161fd2 136 return data;
WiredHome 19:3f82c1161fd2 137 }
WiredHome 19:3f82c1161fd2 138
WiredHome 19:3f82c1161fd2 139 unsigned char RA8875::ReadStatus(void)
WiredHome 19:3f82c1161fd2 140 {
WiredHome 19:3f82c1161fd2 141 unsigned char data;
WiredHome 19:3f82c1161fd2 142
WiredHome 19:3f82c1161fd2 143 select(true);
WiredHome 19:3f82c1161fd2 144 spiwrite(0xC0);
WiredHome 19:3f82c1161fd2 145 data = spiread();
WiredHome 19:3f82c1161fd2 146 select(false);
WiredHome 19:3f82c1161fd2 147 return data;
WiredHome 19:3f82c1161fd2 148 }
WiredHome 19:3f82c1161fd2 149
WiredHome 19:3f82c1161fd2 150 unsigned int RA8875::fontwidth(void)
WiredHome 19:3f82c1161fd2 151 {
WiredHome 19:3f82c1161fd2 152 if (font == NULL)
WiredHome 19:3f82c1161fd2 153 return size_x;
WiredHome 19:3f82c1161fd2 154 else
WiredHome 19:3f82c1161fd2 155 return width() / font[1];
WiredHome 19:3f82c1161fd2 156 }
WiredHome 19:3f82c1161fd2 157
WiredHome 19:3f82c1161fd2 158 unsigned int RA8875::fontheight(void)
WiredHome 19:3f82c1161fd2 159 {
WiredHome 19:3f82c1161fd2 160 if (font == NULL)
WiredHome 19:3f82c1161fd2 161 return size_y;
WiredHome 19:3f82c1161fd2 162 else
WiredHome 19:3f82c1161fd2 163 return height() / font[2];
WiredHome 19:3f82c1161fd2 164 }
WiredHome 19:3f82c1161fd2 165
WiredHome 19:3f82c1161fd2 166 RetCode_t RA8875::locate(unsigned int x, unsigned int y)
WiredHome 19:3f82c1161fd2 167 {
WiredHome 19:3f82c1161fd2 168 return SetTextCursor(x * fontwidth(), y * fontheight());
WiredHome 19:3f82c1161fd2 169 }
WiredHome 19:3f82c1161fd2 170
WiredHome 19:3f82c1161fd2 171 int RA8875::columns(void)
WiredHome 19:3f82c1161fd2 172 {
WiredHome 19:3f82c1161fd2 173 return width() / fontwidth();
WiredHome 19:3f82c1161fd2 174 }
WiredHome 19:3f82c1161fd2 175
WiredHome 19:3f82c1161fd2 176 int RA8875::rows(void)
WiredHome 19:3f82c1161fd2 177 {
WiredHome 19:3f82c1161fd2 178 return height() / fontheight();
WiredHome 19:3f82c1161fd2 179 }
WiredHome 19:3f82c1161fd2 180
WiredHome 19:3f82c1161fd2 181 int RA8875::width(void)
WiredHome 19:3f82c1161fd2 182 {
WiredHome 19:3f82c1161fd2 183 return RA8875_DISPLAY_WIDTH;
WiredHome 19:3f82c1161fd2 184 }
WiredHome 19:3f82c1161fd2 185
WiredHome 19:3f82c1161fd2 186 int RA8875::height(void)
WiredHome 19:3f82c1161fd2 187 {
WiredHome 19:3f82c1161fd2 188 return RA8875_DISPLAY_HEIGHT;
WiredHome 19:3f82c1161fd2 189 }
WiredHome 19:3f82c1161fd2 190
WiredHome 19:3f82c1161fd2 191 RetCode_t RA8875::SetTextCursor(unsigned int x, unsigned int y)
WiredHome 19:3f82c1161fd2 192 {
WiredHome 19:3f82c1161fd2 193 WriteCommand(0x2A, x & 0xFF);
WiredHome 19:3f82c1161fd2 194 WriteCommand(0x2B, x >> 8);
WiredHome 19:3f82c1161fd2 195 WriteCommand(0x2C, y & 0xFF);
WiredHome 19:3f82c1161fd2 196 WriteCommand(0x2D, y >> 8);
WiredHome 19:3f82c1161fd2 197 INFO("SetTextCursor(%d,%d)", x,y);
WiredHome 19:3f82c1161fd2 198 return noerror;
WiredHome 19:3f82c1161fd2 199 }
WiredHome 19:3f82c1161fd2 200
WiredHome 19:3f82c1161fd2 201 RetCode_t RA8875::SetTextFont(RA8875::font_t font)
WiredHome 19:3f82c1161fd2 202 {
WiredHome 19:3f82c1161fd2 203 if (/*font >= RA8875::ISO8859_1 && */ font <= RA8875::ISO8859_4) {
WiredHome 19:3f82c1161fd2 204 WriteCommand(0x21, (unsigned int)(font));
WiredHome 19:3f82c1161fd2 205 return noerror;
WiredHome 19:3f82c1161fd2 206 } else {
WiredHome 19:3f82c1161fd2 207 return bad_parameter;
WiredHome 19:3f82c1161fd2 208 }
WiredHome 19:3f82c1161fd2 209 }
WiredHome 19:3f82c1161fd2 210
WiredHome 19:3f82c1161fd2 211 RetCode_t RA8875::SetTextFontControl(fill_t fillit,
WiredHome 19:3f82c1161fd2 212 RA8875::font_angle_t angle,
WiredHome 19:3f82c1161fd2 213 RA8875::HorizontalScale hScale,
WiredHome 19:3f82c1161fd2 214 RA8875::VerticalScale vScale,
WiredHome 19:3f82c1161fd2 215 RA8875::alignment_t alignment)
WiredHome 19:3f82c1161fd2 216 {
WiredHome 19:3f82c1161fd2 217 if (hScale >= 1 && hScale <= 4 &&
WiredHome 19:3f82c1161fd2 218 vScale >= 1 && vScale <= 4) {
WiredHome 19:3f82c1161fd2 219 unsigned char x = 0;
WiredHome 19:3f82c1161fd2 220
WiredHome 19:3f82c1161fd2 221 if (alignment == align_full)
WiredHome 19:3f82c1161fd2 222 x |= 0x80;
WiredHome 19:3f82c1161fd2 223 if (fillit == NOFILL)
WiredHome 19:3f82c1161fd2 224 x |= 0x40;
WiredHome 19:3f82c1161fd2 225 if (angle == rotated)
WiredHome 19:3f82c1161fd2 226 x |= 0x10;
WiredHome 19:3f82c1161fd2 227 x |= ((hScale - 1) << 2);
WiredHome 19:3f82c1161fd2 228 x |= ((vScale - 1) << 0);
WiredHome 19:3f82c1161fd2 229 WriteCommand(0x22, x);
WiredHome 19:3f82c1161fd2 230 return noerror;
WiredHome 19:3f82c1161fd2 231 } else {
WiredHome 19:3f82c1161fd2 232 return bad_parameter;
WiredHome 19:3f82c1161fd2 233 }
WiredHome 19:3f82c1161fd2 234 }
WiredHome 19:3f82c1161fd2 235
WiredHome 19:3f82c1161fd2 236 RetCode_t RA8875::SetTextFontSize(RA8875::HorizontalScale hScale, RA8875::VerticalScale vScale)
WiredHome 19:3f82c1161fd2 237 {
WiredHome 19:3f82c1161fd2 238 unsigned char reg = ReadCommand(0x22);
WiredHome 19:3f82c1161fd2 239
WiredHome 19:3f82c1161fd2 240 if (hScale >= 1 && hScale <= 4 && vScale >= 1 && vScale <= 4) {
WiredHome 19:3f82c1161fd2 241 reg &= 0xF0; // keep the high nibble as is.
WiredHome 19:3f82c1161fd2 242 reg |= ((hScale - 1) << 2);
WiredHome 19:3f82c1161fd2 243 reg |= ((vScale - 1) << 0);
WiredHome 19:3f82c1161fd2 244 WriteCommand(0x22, reg);
WiredHome 19:3f82c1161fd2 245 return noerror;
WiredHome 19:3f82c1161fd2 246 } else {
WiredHome 19:3f82c1161fd2 247 return bad_parameter;
WiredHome 19:3f82c1161fd2 248 }
WiredHome 19:3f82c1161fd2 249 }
WiredHome 19:3f82c1161fd2 250
WiredHome 19:3f82c1161fd2 251 int RA8875::_putc(int c)
WiredHome 19:3f82c1161fd2 252 {
WiredHome 19:3f82c1161fd2 253 if (c) {
WiredHome 19:3f82c1161fd2 254 if (c == '\r') {
WiredHome 19:3f82c1161fd2 255 unsigned int x;
WiredHome 19:3f82c1161fd2 256 x = ReadCommand(0x30) | (ReadCommand(0x31) << 8); // Left edge of active window
WiredHome 19:3f82c1161fd2 257 WriteCommand(0x2A, x & 0xFF);
WiredHome 19:3f82c1161fd2 258 WriteCommand(0x2B, x >> 8);
WiredHome 19:3f82c1161fd2 259 } else if (c == '\n') {
WiredHome 19:3f82c1161fd2 260 unsigned int y;
WiredHome 19:3f82c1161fd2 261 y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); // current y location
WiredHome 19:3f82c1161fd2 262 y += fontheight();
WiredHome 19:3f82c1161fd2 263 if (y > height()) // @TODO > active window, then scroll?
WiredHome 19:3f82c1161fd2 264 y = 0;
WiredHome 19:3f82c1161fd2 265 WriteCommand(0x2C, y & 0xFF);
WiredHome 19:3f82c1161fd2 266 WriteCommand(0x2D, y >> 8);
WiredHome 19:3f82c1161fd2 267 } else {
WiredHome 19:3f82c1161fd2 268 if (font == NULL) {
WiredHome 19:3f82c1161fd2 269 WriteCommand(0x40,0x80);
WiredHome 19:3f82c1161fd2 270 WriteCommand(0x02);
WiredHome 19:3f82c1161fd2 271 select(true);
WiredHome 19:3f82c1161fd2 272 WriteData(c);
WiredHome 19:3f82c1161fd2 273 while (ReadStatus() & 0x80)
WiredHome 19:3f82c1161fd2 274 wait_us(POLLWAITuSec); // Chk_Busy();
WiredHome 19:3f82c1161fd2 275 select(false);
WiredHome 19:3f82c1161fd2 276 } else {
WiredHome 19:3f82c1161fd2 277 unsigned int x = (ReadCommand(0x2A) | (ReadCommand(0x2B) << 8)) / fontwidth();
WiredHome 19:3f82c1161fd2 278 unsigned int y = (ReadCommand(0x2C) | (ReadCommand(0x2D) << 8)) / fontheight();
WiredHome 19:3f82c1161fd2 279 character(x,y,c);
WiredHome 19:3f82c1161fd2 280 }
WiredHome 19:3f82c1161fd2 281 // @TODO right of active window, then wrap?
WiredHome 19:3f82c1161fd2 282 }
WiredHome 19:3f82c1161fd2 283 }
WiredHome 19:3f82c1161fd2 284 return c;
WiredHome 19:3f82c1161fd2 285 }
WiredHome 19:3f82c1161fd2 286
WiredHome 19:3f82c1161fd2 287 void RA8875::puts(unsigned int x, unsigned int y, const char * string)
WiredHome 19:3f82c1161fd2 288 {
WiredHome 19:3f82c1161fd2 289 SetTextCursor(x,y);
WiredHome 19:3f82c1161fd2 290 puts(string);
WiredHome 19:3f82c1161fd2 291 }
WiredHome 19:3f82c1161fd2 292
WiredHome 19:3f82c1161fd2 293 void RA8875::puts(const char * string)
WiredHome 19:3f82c1161fd2 294 {
WiredHome 19:3f82c1161fd2 295 if (*string != '\0') {
WiredHome 19:3f82c1161fd2 296 INFO("puts(%s)", string);
WiredHome 19:3f82c1161fd2 297 #if 1
WiredHome 19:3f82c1161fd2 298 while (*string) { // @TODO calling individual _putc is slower... anything to do?
WiredHome 19:3f82c1161fd2 299 _putc(*string++);
WiredHome 19:3f82c1161fd2 300 }
WiredHome 19:3f82c1161fd2 301 #else
WiredHome 19:3f82c1161fd2 302 WriteCommand(0x40,0x80); // Put display into text mode
WiredHome 19:3f82c1161fd2 303 WriteCommand(0x02);
WiredHome 19:3f82c1161fd2 304 select(true);
WiredHome 19:3f82c1161fd2 305 while (*string != '\0') {
WiredHome 19:3f82c1161fd2 306 WriteData(*string);
WiredHome 19:3f82c1161fd2 307 ++string;
WiredHome 19:3f82c1161fd2 308 while (ReadStatus() & 0x80)
WiredHome 19:3f82c1161fd2 309 wait_us(POLLWAITuSec); // Chk_Busy();
WiredHome 19:3f82c1161fd2 310 }
WiredHome 19:3f82c1161fd2 311 select(false);
WiredHome 19:3f82c1161fd2 312 #endif
WiredHome 19:3f82c1161fd2 313 }
WiredHome 19:3f82c1161fd2 314 }
WiredHome 19:3f82c1161fd2 315
WiredHome 19:3f82c1161fd2 316 RetCode_t RA8875::SetMemoryCursor(unsigned int x, unsigned int y)
WiredHome 19:3f82c1161fd2 317
WiredHome 19:3f82c1161fd2 318 {
WiredHome 19:3f82c1161fd2 319 WriteCommand(0x46, x & 0xFF);
WiredHome 19:3f82c1161fd2 320 WriteCommand(0x47, x >> 8);
WiredHome 19:3f82c1161fd2 321 WriteCommand(0x48, y & 0xFF);
WiredHome 19:3f82c1161fd2 322 WriteCommand(0x49, y >> 8);
WiredHome 19:3f82c1161fd2 323 return noerror;
WiredHome 19:3f82c1161fd2 324 }
WiredHome 19:3f82c1161fd2 325
WiredHome 19:3f82c1161fd2 326 RetCode_t RA8875::SetWindow(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
WiredHome 19:3f82c1161fd2 327 {
WiredHome 19:3f82c1161fd2 328 WriteCommand(0x30, x & 0xFF); // HSAW0
WiredHome 19:3f82c1161fd2 329 WriteCommand(0x31, x >> 8); // HSAW1
WiredHome 19:3f82c1161fd2 330 WriteCommand(0x32, y & 0xFF); // VSAW0
WiredHome 19:3f82c1161fd2 331 WriteCommand(0x33, y >> 8); // VSAW1
WiredHome 19:3f82c1161fd2 332 WriteCommand(0x34, (x+width-1) & 0xFF); // HEAW0
WiredHome 19:3f82c1161fd2 333 WriteCommand(0x35, (x+width-1) >> 8); // HEAW1
WiredHome 19:3f82c1161fd2 334 WriteCommand(0x36, (y+height-1) & 0xFF); // VEAW0
WiredHome 19:3f82c1161fd2 335 WriteCommand(0x37, (y+height-1) >> 8); // VEAW1
WiredHome 19:3f82c1161fd2 336 return noerror;
WiredHome 19:3f82c1161fd2 337 }
WiredHome 19:3f82c1161fd2 338
WiredHome 19:3f82c1161fd2 339 RetCode_t RA8875::cls(void)
WiredHome 19:3f82c1161fd2 340 {
WiredHome 19:3f82c1161fd2 341 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 342 clsw(FULLWINDOW);
WiredHome 19:3f82c1161fd2 343 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 19:3f82c1161fd2 344 return noerror;
WiredHome 19:3f82c1161fd2 345 }
WiredHome 19:3f82c1161fd2 346
WiredHome 19:3f82c1161fd2 347 RetCode_t RA8875::clsw(RA8875::Region_t region)
WiredHome 19:3f82c1161fd2 348 {
WiredHome 19:3f82c1161fd2 349 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 350 WriteCommand(0x8E, (region == ACTIVEWINDOW) ? 0xC0 : 0x80);
WiredHome 19:3f82c1161fd2 351 while (ReadCommand(0x8E) & 0x80)
WiredHome 19:3f82c1161fd2 352 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 353 REGISTERPERFORMANCE(PRF_CLS);
WiredHome 19:3f82c1161fd2 354 return noerror;
WiredHome 19:3f82c1161fd2 355 }
WiredHome 19:3f82c1161fd2 356
WiredHome 19:3f82c1161fd2 357 RetCode_t RA8875::pixel(unsigned int x, unsigned int y, color_t color)
WiredHome 19:3f82c1161fd2 358 {
WiredHome 19:3f82c1161fd2 359 foreground(color);
WiredHome 19:3f82c1161fd2 360 return pixel(x,y);
WiredHome 19:3f82c1161fd2 361 }
WiredHome 19:3f82c1161fd2 362
WiredHome 19:3f82c1161fd2 363 RetCode_t RA8875::pixel(unsigned int x, unsigned int y)
WiredHome 19:3f82c1161fd2 364 {
WiredHome 19:3f82c1161fd2 365 RetCode_t ret;
WiredHome 19:3f82c1161fd2 366
WiredHome 19:3f82c1161fd2 367 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 368 #if 1
WiredHome 19:3f82c1161fd2 369 color_t color = GetForeColor();
WiredHome 19:3f82c1161fd2 370 WriteCommand(0x40,0x00); // Graphics write mode
WiredHome 19:3f82c1161fd2 371 SetMemoryCursor(x, y);
WiredHome 19:3f82c1161fd2 372 WriteCommand(0x02); //start data write
WiredHome 19:3f82c1161fd2 373 WriteData(color & 0xFF);
WiredHome 19:3f82c1161fd2 374 WriteData(color >> 8);
WiredHome 19:3f82c1161fd2 375 ret = noerror;
WiredHome 19:3f82c1161fd2 376 #else
WiredHome 19:3f82c1161fd2 377 // There isn't actually a set pixel function that I found
WiredHome 19:3f82c1161fd2 378 // so we'll emulate it as we can.
WiredHome 19:3f82c1161fd2 379 ret = line(x,y, x,y);
WiredHome 19:3f82c1161fd2 380 #endif
WiredHome 19:3f82c1161fd2 381 REGISTERPERFORMANCE(PRF_DRAWPOINT);
WiredHome 19:3f82c1161fd2 382 return ret;
WiredHome 19:3f82c1161fd2 383 }
WiredHome 19:3f82c1161fd2 384
WiredHome 19:3f82c1161fd2 385 RetCode_t RA8875::line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, color_t color)
WiredHome 19:3f82c1161fd2 386 {
WiredHome 19:3f82c1161fd2 387 foreground(color);
WiredHome 19:3f82c1161fd2 388 return line(x1,y1,x2,y2);
WiredHome 19:3f82c1161fd2 389 }
WiredHome 19:3f82c1161fd2 390
WiredHome 19:3f82c1161fd2 391 RetCode_t RA8875::line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
WiredHome 19:3f82c1161fd2 392 {
WiredHome 19:3f82c1161fd2 393 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 394 WriteCommand(0x91, x1 & 0xFF);
WiredHome 19:3f82c1161fd2 395 WriteCommand(0x92, x1 >> 8);
WiredHome 19:3f82c1161fd2 396 WriteCommand(0x93, y1 & 0xFF);
WiredHome 19:3f82c1161fd2 397 WriteCommand(0x94, y1 >> 8);
WiredHome 19:3f82c1161fd2 398 WriteCommand(0x95, x2 & 0xFF);
WiredHome 19:3f82c1161fd2 399 WriteCommand(0x96, x2 >> 8);
WiredHome 19:3f82c1161fd2 400 WriteCommand(0x97, y2 & 0xFF);
WiredHome 19:3f82c1161fd2 401 WriteCommand(0x98, y2 >> 8);
WiredHome 19:3f82c1161fd2 402
WiredHome 19:3f82c1161fd2 403 unsigned char drawCmd = 0x00; // Line
WiredHome 19:3f82c1161fd2 404 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 405 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 406 while (ReadCommand(0x90) & 0x80) // await completion.
WiredHome 19:3f82c1161fd2 407 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 408 REGISTERPERFORMANCE(PRF_DRAWLINE);
WiredHome 19:3f82c1161fd2 409 return noerror;
WiredHome 19:3f82c1161fd2 410 }
WiredHome 19:3f82c1161fd2 411
WiredHome 19:3f82c1161fd2 412 RetCode_t RA8875::fillrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 413 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 414 {
WiredHome 19:3f82c1161fd2 415 return rect(x1,y1,x2,y2,color,fillit);
WiredHome 19:3f82c1161fd2 416 }
WiredHome 19:3f82c1161fd2 417
WiredHome 19:3f82c1161fd2 418 RetCode_t RA8875::rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 419 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 420 {
WiredHome 19:3f82c1161fd2 421 foreground(color);
WiredHome 19:3f82c1161fd2 422 return rect(x1,y1,x2,y2,fillit);
WiredHome 19:3f82c1161fd2 423 }
WiredHome 19:3f82c1161fd2 424
WiredHome 19:3f82c1161fd2 425 RetCode_t RA8875::rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 426 fill_t fillit)
WiredHome 19:3f82c1161fd2 427 {
WiredHome 19:3f82c1161fd2 428 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 429 if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 430 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 431 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 432 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 433 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 434 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 435 } else {
WiredHome 19:3f82c1161fd2 436 WriteCommand(0x91, x1 & 0xFF);
WiredHome 19:3f82c1161fd2 437 WriteCommand(0x92, x1 >> 8);
WiredHome 19:3f82c1161fd2 438 WriteCommand(0x93, y1 & 0xFF);
WiredHome 19:3f82c1161fd2 439 WriteCommand(0x94, y1 >> 8);
WiredHome 19:3f82c1161fd2 440 WriteCommand(0x95, x2 & 0xFF);
WiredHome 19:3f82c1161fd2 441 WriteCommand(0x96, x2 >> 8);
WiredHome 19:3f82c1161fd2 442 WriteCommand(0x97, y2 & 0xFF);
WiredHome 19:3f82c1161fd2 443 WriteCommand(0x98, y2 >> 8);
WiredHome 19:3f82c1161fd2 444
WiredHome 19:3f82c1161fd2 445 unsigned char drawCmd = 0x10; // Rectangle
WiredHome 19:3f82c1161fd2 446 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 447 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 448 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 449 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 450 while (ReadCommand(0x90) & 0x80) // await completion.
WiredHome 19:3f82c1161fd2 451 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 452 }
WiredHome 19:3f82c1161fd2 453 REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
WiredHome 19:3f82c1161fd2 454 return noerror;
WiredHome 19:3f82c1161fd2 455 }
WiredHome 19:3f82c1161fd2 456
WiredHome 19:3f82c1161fd2 457 RetCode_t RA8875::fillroundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 458 unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 459 {
WiredHome 19:3f82c1161fd2 460 foreground(color);
WiredHome 19:3f82c1161fd2 461 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 462 }
WiredHome 19:3f82c1161fd2 463
WiredHome 19:3f82c1161fd2 464 RetCode_t RA8875::roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 465 unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 466 {
WiredHome 19:3f82c1161fd2 467 foreground(color);
WiredHome 19:3f82c1161fd2 468 return roundrect(x1,y1,x2,y2,radius1,radius2,fillit);
WiredHome 19:3f82c1161fd2 469 }
WiredHome 19:3f82c1161fd2 470
WiredHome 21:3c1efb192927 471 RetCode_t RA8875::roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 472 unsigned int radius1, unsigned int radius2, fill_t fillit)
WiredHome 19:3f82c1161fd2 473 {
WiredHome 19:3f82c1161fd2 474 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 475
WiredHome 19:3f82c1161fd2 476 PERFORMANCE_RESET;
WiredHome 21:3c1efb192927 477 if (x1 > x2 || y1 > y2 || (radius1 > (x2-x1)/2) || (radius2 > (y2-y1)/2) ) {
WiredHome 21:3c1efb192927 478 ret = bad_parameter;
WiredHome 21:3c1efb192927 479 } else if (x1 == x2 && y1 == y2) {
WiredHome 19:3f82c1161fd2 480 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 481 } else if (x1 == x2) {
WiredHome 19:3f82c1161fd2 482 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 483 } else if (y1 == y2) {
WiredHome 19:3f82c1161fd2 484 line(x1, y1, x2, y2);
WiredHome 19:3f82c1161fd2 485 } else {
WiredHome 19:3f82c1161fd2 486 WriteCommand(0x91, x1 & 0xFF);
WiredHome 19:3f82c1161fd2 487 WriteCommand(0x92, x1 >> 8);
WiredHome 19:3f82c1161fd2 488 WriteCommand(0x93, y1 & 0xFF);
WiredHome 19:3f82c1161fd2 489 WriteCommand(0x94, y1 >> 8);
WiredHome 19:3f82c1161fd2 490 WriteCommand(0x95, x2 & 0xFF);
WiredHome 19:3f82c1161fd2 491 WriteCommand(0x96, x2 >> 8);
WiredHome 19:3f82c1161fd2 492 WriteCommand(0x97, y2 & 0xFF);
WiredHome 19:3f82c1161fd2 493 WriteCommand(0x98, y2 >> 8);
WiredHome 19:3f82c1161fd2 494
WiredHome 19:3f82c1161fd2 495 WriteCommand(0xA1, radius1 & 0xFF);
WiredHome 19:3f82c1161fd2 496 WriteCommand(0xA2, radius1 >> 8);
WiredHome 19:3f82c1161fd2 497 WriteCommand(0xA3, radius2 & 0xFF);
WiredHome 19:3f82c1161fd2 498 WriteCommand(0xA4, radius2 >> 8);
WiredHome 21:3c1efb192927 499
WiredHome 21:3c1efb192927 500 // Should not need this...
WiredHome 21:3c1efb192927 501 WriteCommand(0xA5, 0 & 0xFF);
WiredHome 21:3c1efb192927 502 WriteCommand(0xA6, 0 >> 8);
WiredHome 21:3c1efb192927 503 WriteCommand(0xA7, 0 & 0xFF);
WiredHome 21:3c1efb192927 504 WriteCommand(0xA8, 0 >> 8);
WiredHome 19:3f82c1161fd2 505
WiredHome 19:3f82c1161fd2 506 unsigned char drawCmd = 0x20; // Rounded Rectangle
WiredHome 19:3f82c1161fd2 507 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 508 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 509 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 510 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 511 while (ReadCommand(0xA0) & 0x80) { // await completion.
WiredHome 19:3f82c1161fd2 512 wait_us(POLLWAITuSec);
WiredHome 21:3c1efb192927 513 }
WiredHome 19:3f82c1161fd2 514 }
WiredHome 19:3f82c1161fd2 515 REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
WiredHome 19:3f82c1161fd2 516 return ret;
WiredHome 19:3f82c1161fd2 517 }
WiredHome 19:3f82c1161fd2 518
WiredHome 19:3f82c1161fd2 519 RetCode_t RA8875::triangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 520 unsigned int x3, unsigned int y3, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 521 {
WiredHome 20:6e2e4a8372eb 522 RetCode_t ret;
WiredHome 20:6e2e4a8372eb 523
WiredHome 19:3f82c1161fd2 524 foreground(color);
WiredHome 20:6e2e4a8372eb 525 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 20:6e2e4a8372eb 526 return ret;
WiredHome 19:3f82c1161fd2 527 }
WiredHome 19:3f82c1161fd2 528
WiredHome 19:3f82c1161fd2 529 RetCode_t RA8875::filltriangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 530 unsigned int x3, unsigned int y3, color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 531 {
WiredHome 20:6e2e4a8372eb 532 RetCode_t ret;
WiredHome 20:6e2e4a8372eb 533
WiredHome 19:3f82c1161fd2 534 foreground(color);
WiredHome 20:6e2e4a8372eb 535 ret = triangle(x1,y1,x2,y2,x3,y3,fillit);
WiredHome 20:6e2e4a8372eb 536 return ret;
WiredHome 19:3f82c1161fd2 537 }
WiredHome 19:3f82c1161fd2 538
WiredHome 19:3f82c1161fd2 539 RetCode_t RA8875::triangle(unsigned int x1, unsigned int y1 ,unsigned int x2, unsigned int y2,
WiredHome 19:3f82c1161fd2 540 unsigned int x3, unsigned int y3, fill_t fillit)
WiredHome 19:3f82c1161fd2 541 {
WiredHome 19:3f82c1161fd2 542 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 543
WiredHome 19:3f82c1161fd2 544 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 545 if (x1 == x2 && y1 == y2 && x1 == x3 && y1 == y3) {
WiredHome 19:3f82c1161fd2 546 pixel(x1, y1);
WiredHome 19:3f82c1161fd2 547 } else {
WiredHome 19:3f82c1161fd2 548 WriteCommand(0x91, x1 & 0xFF);
WiredHome 19:3f82c1161fd2 549 WriteCommand(0x92, x1 >> 8);
WiredHome 19:3f82c1161fd2 550 WriteCommand(0x93, y1 & 0xFF);
WiredHome 19:3f82c1161fd2 551 WriteCommand(0x94, y1 >> 8);
WiredHome 19:3f82c1161fd2 552
WiredHome 19:3f82c1161fd2 553 WriteCommand(0x95, x2 & 0xFF);
WiredHome 19:3f82c1161fd2 554 WriteCommand(0x96, x2 >> 8);
WiredHome 19:3f82c1161fd2 555 WriteCommand(0x97, y2 & 0xFF);
WiredHome 19:3f82c1161fd2 556 WriteCommand(0x98, y2 >> 8);
WiredHome 19:3f82c1161fd2 557
WiredHome 19:3f82c1161fd2 558 WriteCommand(0xA9, x3 & 0xFF);
WiredHome 19:3f82c1161fd2 559 WriteCommand(0xAA, x3 >> 8);
WiredHome 19:3f82c1161fd2 560 WriteCommand(0xAB, y3 & 0xFF);
WiredHome 19:3f82c1161fd2 561 WriteCommand(0xAC, y3 >> 8);
WiredHome 19:3f82c1161fd2 562
WiredHome 19:3f82c1161fd2 563 unsigned char drawCmd = 0x01; // Triangle
WiredHome 19:3f82c1161fd2 564 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 565 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 566 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 567 WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 568 while (ReadCommand(0x90) & 0x80) // await completion.
WiredHome 19:3f82c1161fd2 569 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 570 }
WiredHome 19:3f82c1161fd2 571 REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
WiredHome 19:3f82c1161fd2 572 return ret;
WiredHome 19:3f82c1161fd2 573 }
WiredHome 19:3f82c1161fd2 574
WiredHome 19:3f82c1161fd2 575 RetCode_t RA8875::circle(unsigned int x, unsigned int y, unsigned int radius,
WiredHome 19:3f82c1161fd2 576 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 577 {
WiredHome 19:3f82c1161fd2 578 foreground(color);
WiredHome 19:3f82c1161fd2 579 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 580 }
WiredHome 19:3f82c1161fd2 581
WiredHome 19:3f82c1161fd2 582 RetCode_t RA8875::fillcircle(unsigned int x, unsigned int y, unsigned int radius,
WiredHome 19:3f82c1161fd2 583 color_t color, fill_t fillit)
WiredHome 19:3f82c1161fd2 584 {
WiredHome 19:3f82c1161fd2 585 foreground(color);
WiredHome 19:3f82c1161fd2 586 return circle(x,y,radius,fillit);
WiredHome 19:3f82c1161fd2 587 }
WiredHome 19:3f82c1161fd2 588
WiredHome 19:3f82c1161fd2 589 RetCode_t RA8875::circle(unsigned int x, unsigned int y, unsigned int radius, fill_t fillit)
WiredHome 19:3f82c1161fd2 590 {
WiredHome 19:3f82c1161fd2 591 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 592
WiredHome 19:3f82c1161fd2 593 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 594 if (radius <= 0) {
WiredHome 19:3f82c1161fd2 595 ret = bad_parameter;
WiredHome 19:3f82c1161fd2 596 } else if (radius == 1) {
WiredHome 19:3f82c1161fd2 597 pixel(x,y);
WiredHome 19:3f82c1161fd2 598 } else {
WiredHome 19:3f82c1161fd2 599 WriteCommand(0x99, x & 0xFF);
WiredHome 19:3f82c1161fd2 600 WriteCommand(0x9a, x >> 8);
WiredHome 19:3f82c1161fd2 601 WriteCommand(0x9b, y & 0xFF);
WiredHome 19:3f82c1161fd2 602 WriteCommand(0x9c, y >> 8);
WiredHome 19:3f82c1161fd2 603 WriteCommand(0x9d, radius & 0xFF);
WiredHome 19:3f82c1161fd2 604
WiredHome 19:3f82c1161fd2 605 unsigned char drawCmd = 0x00; // Circle
WiredHome 19:3f82c1161fd2 606 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 607 drawCmd |= 0x20;
WiredHome 19:3f82c1161fd2 608 WriteCommand(0x90, drawCmd);
WiredHome 19:3f82c1161fd2 609 WriteCommand(0x90, 0x40 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 610 while (ReadCommand(0x90) & 0x40) // await completion.
WiredHome 19:3f82c1161fd2 611 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 612 }
WiredHome 19:3f82c1161fd2 613 REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
WiredHome 19:3f82c1161fd2 614 return ret;
WiredHome 19:3f82c1161fd2 615 }
WiredHome 19:3f82c1161fd2 616
WiredHome 19:3f82c1161fd2 617 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 618 {
WiredHome 19:3f82c1161fd2 619 foreground(color);
WiredHome 19:3f82c1161fd2 620 return ellipse(x,y,R1,R2,fillit);
WiredHome 19:3f82c1161fd2 621 }
WiredHome 19:3f82c1161fd2 622
WiredHome 19:3f82c1161fd2 623 RetCode_t RA8875::ellipse(unsigned int x, unsigned int y, unsigned int R1, unsigned int R2, fill_t fillit)
WiredHome 19:3f82c1161fd2 624 {
WiredHome 19:3f82c1161fd2 625 RetCode_t ret = noerror;
WiredHome 19:3f82c1161fd2 626
WiredHome 19:3f82c1161fd2 627 PERFORMANCE_RESET;
WiredHome 19:3f82c1161fd2 628 if (R1 <= 0 || R2 <= 0) {
WiredHome 19:3f82c1161fd2 629 ; // do nothing
WiredHome 19:3f82c1161fd2 630 } else if (R1 == 1 && R2 == 1) {
WiredHome 19:3f82c1161fd2 631 pixel(x, y);
WiredHome 19:3f82c1161fd2 632 } else {
WiredHome 19:3f82c1161fd2 633 WriteCommand(0xA5, x & 0xFF);
WiredHome 19:3f82c1161fd2 634 WriteCommand(0xA6, x >> 8);
WiredHome 19:3f82c1161fd2 635 WriteCommand(0xA7, y & 0xFF);
WiredHome 19:3f82c1161fd2 636 WriteCommand(0xA8, y >> 8);
WiredHome 19:3f82c1161fd2 637 WriteCommand(0xA1, R1 & 0xFF);
WiredHome 19:3f82c1161fd2 638 WriteCommand(0xA2, R1 >> 8);
WiredHome 19:3f82c1161fd2 639 WriteCommand(0xA3, R2 & 0xFF);
WiredHome 19:3f82c1161fd2 640 WriteCommand(0xA4, R2 >> 8);
WiredHome 19:3f82c1161fd2 641
WiredHome 19:3f82c1161fd2 642 unsigned char drawCmd = 0x00; // Ellipse
WiredHome 19:3f82c1161fd2 643 if (fillit == FILL)
WiredHome 19:3f82c1161fd2 644 drawCmd |= 0x40;
WiredHome 19:3f82c1161fd2 645 WriteCommand(0xA0, drawCmd);
WiredHome 19:3f82c1161fd2 646 WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
WiredHome 19:3f82c1161fd2 647 while (ReadCommand(0xA0) & 0x80) // await completion.
WiredHome 19:3f82c1161fd2 648 wait_us(POLLWAITuSec);
WiredHome 19:3f82c1161fd2 649 }
WiredHome 19:3f82c1161fd2 650 REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
WiredHome 19:3f82c1161fd2 651 return ret;
WiredHome 19:3f82c1161fd2 652 }
WiredHome 19:3f82c1161fd2 653
WiredHome 19:3f82c1161fd2 654
WiredHome 19:3f82c1161fd2 655 RetCode_t RA8875::frequency(unsigned long Hz)
WiredHome 19:3f82c1161fd2 656 {
WiredHome 19:3f82c1161fd2 657 spi.frequency(Hz);
WiredHome 19:3f82c1161fd2 658 // __ ___
WiredHome 19:3f82c1161fd2 659 // Clock ___A Rising edge latched
WiredHome 19:3f82c1161fd2 660 // ___ ____
WiredHome 19:3f82c1161fd2 661 // Data ___X____
WiredHome 19:3f82c1161fd2 662 spi.format(8, 3); // 8 bits and clock to data phase 0
WiredHome 19:3f82c1161fd2 663 init();
WiredHome 19:3f82c1161fd2 664 return noerror;
WiredHome 19:3f82c1161fd2 665 }
WiredHome 19:3f82c1161fd2 666
WiredHome 19:3f82c1161fd2 667 RetCode_t RA8875::Power(bool on)
WiredHome 19:3f82c1161fd2 668 {
WiredHome 19:3f82c1161fd2 669 WriteCommand(0x01, (on) ? 0x80 : 0x00);
WiredHome 19:3f82c1161fd2 670 return noerror;
WiredHome 19:3f82c1161fd2 671 }
WiredHome 19:3f82c1161fd2 672
WiredHome 19:3f82c1161fd2 673 RetCode_t RA8875::Reset(void)
WiredHome 19:3f82c1161fd2 674 {
WiredHome 19:3f82c1161fd2 675 WriteCommand(0x01, 0x01); // Apply Display Off, Reset
WiredHome 19:3f82c1161fd2 676 wait_ms(2); // no idea if I need to wait, or how long
WiredHome 19:3f82c1161fd2 677 WriteCommand(0x01, 0x00); // Display off, Remove reset
WiredHome 19:3f82c1161fd2 678 wait_ms(2); // no idea if I need to wait, or how long
WiredHome 19:3f82c1161fd2 679 init();
WiredHome 19:3f82c1161fd2 680 return noerror;
WiredHome 19:3f82c1161fd2 681 }
WiredHome 19:3f82c1161fd2 682
WiredHome 19:3f82c1161fd2 683
WiredHome 19:3f82c1161fd2 684 RetCode_t RA8875::Backlight_u8(unsigned char brightness)
WiredHome 19:3f82c1161fd2 685 {
WiredHome 19:3f82c1161fd2 686 static bool is_enabled = false;
WiredHome 19:3f82c1161fd2 687 if (brightness == 0) {
WiredHome 19:3f82c1161fd2 688 WriteCommand(0x8a); // Disable the PWM
WiredHome 19:3f82c1161fd2 689 WriteData(0x00);
WiredHome 19:3f82c1161fd2 690 is_enabled = false;
WiredHome 19:3f82c1161fd2 691 } else if (!is_enabled) {
WiredHome 19:3f82c1161fd2 692 WriteCommand(0x8a); // Enable the PWM
WiredHome 19:3f82c1161fd2 693 WriteData(0x80);
WiredHome 19:3f82c1161fd2 694 WriteCommand(0x8a); // Not sure why this is needed, but following the pattern
WiredHome 19:3f82c1161fd2 695 WriteData(0x81); // open PWM (SYS_CLK / 2 as best I can tell)
WiredHome 19:3f82c1161fd2 696 is_enabled = true;
WiredHome 19:3f82c1161fd2 697 }
WiredHome 19:3f82c1161fd2 698 WriteCommand(0x8b, brightness); // Brightness parameter 0xff-0x00
WiredHome 19:3f82c1161fd2 699 return noerror;
WiredHome 19:3f82c1161fd2 700 }
WiredHome 19:3f82c1161fd2 701
WiredHome 19:3f82c1161fd2 702 RetCode_t RA8875::Backlight(float brightness)
WiredHome 19:3f82c1161fd2 703 {
WiredHome 19:3f82c1161fd2 704 unsigned char b;
WiredHome 19:3f82c1161fd2 705
WiredHome 19:3f82c1161fd2 706 if (brightness > 1.0)
WiredHome 19:3f82c1161fd2 707 b = 255;
WiredHome 19:3f82c1161fd2 708 else if (brightness < 0)
WiredHome 19:3f82c1161fd2 709 b = 0;
WiredHome 19:3f82c1161fd2 710 else
WiredHome 19:3f82c1161fd2 711 b = (unsigned char)(brightness * 255);
WiredHome 19:3f82c1161fd2 712 return Backlight_u8(b);
WiredHome 19:3f82c1161fd2 713 }
WiredHome 19:3f82c1161fd2 714
WiredHome 19:3f82c1161fd2 715
WiredHome 19:3f82c1161fd2 716 RetCode_t RA8875::set_font(const unsigned char * _font)
WiredHome 19:3f82c1161fd2 717 {
WiredHome 19:3f82c1161fd2 718 font = _font;
WiredHome 19:3f82c1161fd2 719 return noerror; // trusting them, but we could put some checks in here...
WiredHome 19:3f82c1161fd2 720 }
WiredHome 19:3f82c1161fd2 721
WiredHome 19:3f82c1161fd2 722 RetCode_t RA8875::background(color_t color)
WiredHome 19:3f82c1161fd2 723 {
WiredHome 19:3f82c1161fd2 724 WriteCommand(0x60, (color>>11)); // BGCR0
WiredHome 19:3f82c1161fd2 725 WriteCommand(0x61, (unsigned char)(color>>5)); // BGCR0
WiredHome 19:3f82c1161fd2 726 WriteCommand(0x62, (unsigned char)(color)); // BGCR0
WiredHome 19:3f82c1161fd2 727 return noerror;
WiredHome 19:3f82c1161fd2 728 }
WiredHome 19:3f82c1161fd2 729
WiredHome 19:3f82c1161fd2 730 RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b)
WiredHome 19:3f82c1161fd2 731 {
WiredHome 19:3f82c1161fd2 732 WriteCommand(0x60, r);
WiredHome 19:3f82c1161fd2 733 WriteCommand(0x61, g);
WiredHome 19:3f82c1161fd2 734 WriteCommand(0x62, b);
WiredHome 19:3f82c1161fd2 735 return noerror;
WiredHome 19:3f82c1161fd2 736 }
WiredHome 19:3f82c1161fd2 737
WiredHome 19:3f82c1161fd2 738 RetCode_t RA8875::foreground(color_t color)
WiredHome 19:3f82c1161fd2 739 {
WiredHome 19:3f82c1161fd2 740 WriteCommand(0x63, (unsigned char)(color>>11));
WiredHome 19:3f82c1161fd2 741 WriteCommand(0x64, (unsigned char)(color>>5));
WiredHome 19:3f82c1161fd2 742 WriteCommand(0x65, (unsigned char)(color));
WiredHome 19:3f82c1161fd2 743 return noerror;
WiredHome 19:3f82c1161fd2 744 }
WiredHome 19:3f82c1161fd2 745
WiredHome 19:3f82c1161fd2 746 RetCode_t RA8875::foreground(unsigned char setR, unsigned char setG, unsigned char setB)
WiredHome 19:3f82c1161fd2 747 {
WiredHome 19:3f82c1161fd2 748 WriteCommand(0x63, setR);
WiredHome 19:3f82c1161fd2 749 WriteCommand(0x64, setG);
WiredHome 19:3f82c1161fd2 750 WriteCommand(0x65, setB);
WiredHome 19:3f82c1161fd2 751 return noerror;
WiredHome 19:3f82c1161fd2 752 }
WiredHome 19:3f82c1161fd2 753
WiredHome 19:3f82c1161fd2 754 unsigned int RA8875::GetForeColor(void)
WiredHome 19:3f82c1161fd2 755 {
WiredHome 19:3f82c1161fd2 756 color_t color;
WiredHome 19:3f82c1161fd2 757
WiredHome 19:3f82c1161fd2 758 color = (ReadCommand(0x63) & 0x1F) << 11;
WiredHome 19:3f82c1161fd2 759 color |= (ReadCommand(0x64) & 0x3F) << 5;
WiredHome 19:3f82c1161fd2 760 color |= (ReadCommand(0x65) & 0x1F);
WiredHome 19:3f82c1161fd2 761 return color;
WiredHome 19:3f82c1161fd2 762 }
WiredHome 19:3f82c1161fd2 763
WiredHome 19:3f82c1161fd2 764 color_t RA8875::DOSColor(int i)
WiredHome 19:3f82c1161fd2 765 {
WiredHome 19:3f82c1161fd2 766 const color_t colors[16] =
WiredHome 19:3f82c1161fd2 767 {
WiredHome 19:3f82c1161fd2 768 Black, Blue, Green, Cyan,
WiredHome 19:3f82c1161fd2 769 Red, Magenta, Brown, Gray,
WiredHome 19:3f82c1161fd2 770 Charcoal, BrightBlue, BrightGreen, BrightCyan,
WiredHome 19:3f82c1161fd2 771 Orange, Pink, Yellow, White
WiredHome 19:3f82c1161fd2 772 };
WiredHome 19:3f82c1161fd2 773 if (i < 16)
WiredHome 19:3f82c1161fd2 774 return colors[i];
WiredHome 19:3f82c1161fd2 775 else
WiredHome 19:3f82c1161fd2 776 return 0;
WiredHome 19:3f82c1161fd2 777 }
WiredHome 19:3f82c1161fd2 778
WiredHome 19:3f82c1161fd2 779 const char * RA8875::DOSColorNames(int i)
WiredHome 19:3f82c1161fd2 780 {
WiredHome 19:3f82c1161fd2 781 const char * names[16] =
WiredHome 19:3f82c1161fd2 782 {
WiredHome 19:3f82c1161fd2 783 "Black", "Blue", "Green", "Cyan",
WiredHome 19:3f82c1161fd2 784 "Red", "Magenta", "Brown", "Gray",
WiredHome 19:3f82c1161fd2 785 "Charcoal", "BrightBlue", "BrightGreen", "BrightCyan",
WiredHome 19:3f82c1161fd2 786 "Orange", "Pink", "Yellow", "White"
WiredHome 19:3f82c1161fd2 787 };
WiredHome 19:3f82c1161fd2 788 if (i < 16)
WiredHome 19:3f82c1161fd2 789 return names[i];
WiredHome 19:3f82c1161fd2 790 else
WiredHome 19:3f82c1161fd2 791 return NULL;
WiredHome 19:3f82c1161fd2 792 }
WiredHome 19:3f82c1161fd2 793
WiredHome 19:3f82c1161fd2 794
WiredHome 19:3f82c1161fd2 795 ///////////////////////////////////////////////////////////////
WiredHome 19:3f82c1161fd2 796 // Private functions
WiredHome 19:3f82c1161fd2 797
WiredHome 19:3f82c1161fd2 798 unsigned char RA8875::spiwrite(unsigned char data)
WiredHome 19:3f82c1161fd2 799 {
WiredHome 19:3f82c1161fd2 800 unsigned char retval;
WiredHome 19:3f82c1161fd2 801
WiredHome 19:3f82c1161fd2 802 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 803 return retval;
WiredHome 19:3f82c1161fd2 804 }
WiredHome 19:3f82c1161fd2 805
WiredHome 19:3f82c1161fd2 806 unsigned char RA8875::spiread(void)
WiredHome 19:3f82c1161fd2 807 {
WiredHome 19:3f82c1161fd2 808 unsigned char retval;
WiredHome 19:3f82c1161fd2 809 unsigned char data = 0;
WiredHome 19:3f82c1161fd2 810
WiredHome 19:3f82c1161fd2 811 retval = spi.write(data);
WiredHome 19:3f82c1161fd2 812 return retval;
WiredHome 19:3f82c1161fd2 813 }
WiredHome 19:3f82c1161fd2 814
WiredHome 19:3f82c1161fd2 815 RetCode_t RA8875::select(bool chipsel)
WiredHome 19:3f82c1161fd2 816 {
WiredHome 19:3f82c1161fd2 817 cs = (chipsel == true) ? 0 : 1;
WiredHome 19:3f82c1161fd2 818 return noerror;
WiredHome 19:3f82c1161fd2 819 }
WiredHome 19:3f82c1161fd2 820
WiredHome 19:3f82c1161fd2 821 RetCode_t RA8875::init(void)
WiredHome 19:3f82c1161fd2 822 {
WiredHome 19:3f82c1161fd2 823 Backlight_u8(0);
WiredHome 19:3f82c1161fd2 824 WriteCommand(0x88, 0x0a); // PLLC1 - Phase Lock Loop registers
WiredHome 19:3f82c1161fd2 825 wait_ms(1);
WiredHome 19:3f82c1161fd2 826 WriteCommand(0x89, 0x02);
WiredHome 19:3f82c1161fd2 827 wait_ms(1);
WiredHome 19:3f82c1161fd2 828
WiredHome 19:3f82c1161fd2 829 //?
WiredHome 19:3f82c1161fd2 830 WriteCommand(0x10, 0x0C); //SYSR bit[4:3]=00 256 color bit[2:1]= 00 8bit MPU interface, 1x 64k color 1x 16bit
WiredHome 19:3f82c1161fd2 831
WiredHome 19:3f82c1161fd2 832 //?
WiredHome 19:3f82c1161fd2 833 WriteCommand(0x04, 0x82); //PCLK
WiredHome 19:3f82c1161fd2 834 wait_ms(1);
WiredHome 19:3f82c1161fd2 835
WiredHome 19:3f82c1161fd2 836 // Horizontal Settings
WiredHome 19:3f82c1161fd2 837 WriteCommand(0x14, RA8875_DISPLAY_WIDTH/8 - 1); //HDWR//Horizontal Display Width Setting Bit[6:0]
WiredHome 19:3f82c1161fd2 838 WriteCommand(0x15, 0x02); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
WiredHome 19:3f82c1161fd2 839 WriteCommand(0x16, 0x03); //HNDR//Horizontal Non-Display Period Bit[4:0]
WiredHome 19:3f82c1161fd2 840 WriteCommand(0x17, 0x01); //HSTR//HSYNC Start Position[4:0]
WiredHome 19:3f82c1161fd2 841 WriteCommand(0x18, 0x03); //HPWR//HSYNC Polarity ,The period width of HSYNC.
WiredHome 19:3f82c1161fd2 842
WiredHome 19:3f82c1161fd2 843 // Vertical Settings
WiredHome 19:3f82c1161fd2 844 WriteCommand(0x19, (RA8875_DISPLAY_HEIGHT-1)&0xFF); //VDHR0 //Vertical Display Height Bit [7:0]
WiredHome 19:3f82c1161fd2 845 WriteCommand(0x1a, (RA8875_DISPLAY_HEIGHT-1)>>8); //VDHR1 //Vertical Display Height Bit [8]
WiredHome 19:3f82c1161fd2 846 WriteCommand(0x1b, 0x0F); //VNDR0 //Vertical Non-Display Period Bit [7:0]
WiredHome 19:3f82c1161fd2 847 WriteCommand(0x1c, 0x00); //VNDR1 //Vertical Non-Display Period Bit [8]
WiredHome 19:3f82c1161fd2 848 WriteCommand(0x1d, 0x0e); //VSTR0 //VSYNC Start Position[7:0]
WiredHome 19:3f82c1161fd2 849 WriteCommand(0x1e, 0x06); //VSTR1 //VSYNC Start Position[8]
WiredHome 19:3f82c1161fd2 850 WriteCommand(0x1f, 0x01); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
WiredHome 19:3f82c1161fd2 851
WiredHome 19:3f82c1161fd2 852 // Clear ram image
WiredHome 19:3f82c1161fd2 853 SetWindow(0,0, width(), height()); // Initialize to full screen
WiredHome 19:3f82c1161fd2 854 foreground(Black);
WiredHome 19:3f82c1161fd2 855 background(Black);
WiredHome 19:3f82c1161fd2 856 cls();
WiredHome 19:3f82c1161fd2 857 return noerror;
WiredHome 19:3f82c1161fd2 858 }
WiredHome 19:3f82c1161fd2 859