Forked para SNOCC
Fork of RA8875 by
Diff: RA8875.cpp
- Revision:
- 68:ab08efabfc88
- Parent:
- 67:9f834f0ff97d
- Child:
- 71:dcac8efd842d
--- a/RA8875.cpp Sun Aug 31 14:47:59 2014 +0000 +++ b/RA8875.cpp Sun Aug 31 15:52:39 2014 +0000 @@ -1,11 +1,10 @@ /// RA8875 Display Controller Library. /// -/// This is being created for a specific display from buydisplay.com, -/// which is 480 x 272. It has other attributes (like display controller -/// managed backlight brightness. So, there are expectations and some -/// defined constants based on that specific display. Some initial work -/// was done to support other display resolutions (e.g. 800 x 480), but -/// this has not been tested. +/// This is being created for a Raio RA8875-based display from buydisplay.com, +/// which is 480 x 272 using a 4-wire SPI interface. +/// This display controller is used in other display resolutions, up to 800x600. +/// While this driver has not been tested with these variants, nothing was done +/// to prevent easily supporting them. /// #include "RA8875.h" @@ -31,16 +30,19 @@ #ifdef PERF_METRICS #define PERFORMANCE_RESET performance.reset() #define REGISTERPERFORMANCE(a) RegisterPerformance(a) +#define COUNTIDLETIME(a) CountIdleTime(a) static const char *metricsName[] = { "Cls", "Pixel", "Pixel Stream", "Read Pixel", "Read Pixel Stream", "Line", - "Rectangle", "Rounded Rectangle", "Triangle", "Circle", "Ellipse" + "Rectangle", "Rounded Rectangle", + "Triangle", "Circle", "Ellipse" }; #else #define PERFORMANCE_RESET #define REGISTERPERFORMANCE(a) +#define COUNTIDLETIME(a) #endif // When it is going to poll a register for completion, how many @@ -263,7 +265,7 @@ for (int i=0; i<METRICCOUNT; i++) { pc.printf("%10d uS %s\r\n", metrics[i], metricsName[i]); } - pc.printf("Idle Counter: %u\r\n", idlecounter); + pc.printf("%10d uS Idle time polling display for ready.\r\n", idlecounter); } #endif @@ -374,7 +376,7 @@ while (i-- && ReadStatus() & mask) { wait_us(POLLWAITuSec); - CountIdleTime(POLLWAITuSec); + COUNTIDLETIME(POLLWAITuSec); } if (i) return true; @@ -390,7 +392,7 @@ while (i-- && ReadCommand(reg) & mask) { wait_us(POLLWAITuSec); - CountIdleTime(POLLWAITuSec); + COUNTIDLETIME(POLLWAITuSec); } if (i) return true; @@ -1119,11 +1121,14 @@ } -RetCode_t RA8875::frequency(unsigned long Hz) +RetCode_t RA8875::frequency(unsigned long Hz, unsigned long Hz2) { spiwritefreq = Hz; - spireadfreq = Hz/2; - spi.frequency(Hz); + if (Hz2 != 0) + spireadfreq = Hz2; + else + spireadfreq = Hz/2; + _setWriteSpeed(true); // __ ___ // Clock ___A Rising edge latched // ___ ____ @@ -1132,6 +1137,16 @@ return noerror; } +void RA8875::_setWriteSpeed(bool writeSpeed) +{ + if (writeSpeed) { + spi.frequency(spiwritefreq); + spiWriteSpeed = true; + } else { + spi.frequency(spireadfreq); + spiWriteSpeed = false; + } +} RetCode_t RA8875::Power(bool on) { @@ -1285,6 +1300,8 @@ { unsigned char retval; + if (!spiWriteSpeed) + _setWriteSpeed(true); retval = spi.write(data); return retval; } @@ -1295,9 +1312,9 @@ unsigned char retval; unsigned char data = 0; - spi.frequency(spireadfreq); + if (spiWriteSpeed) + _setWriteSpeed(false); retval = spi.write(data); - spi.frequency(spiwritefreq); return retval; } @@ -1609,11 +1626,8 @@ display.line(x,y, x2,y2, display.DOSColor(i)); } display.foreground(BrightRed); - pc.printf("fg %08X %08X %08X\r\n", RGB(255,0,0), BrightRed, display.GetForeColor()); display.foreground(BrightGreen); - pc.printf("fg %08X %08X %08X\r\n", RGB(0,255,0), BrightGreen, display.GetForeColor()); display.foreground(BrightBlue); - pc.printf("fg %08X %08X %08X\r\n", RGB(0,0,255), BrightBlue, display.GetForeColor()); display.line(55,50, 79,74, BrightRed); display.line(57,50, 81,74, BrightGreen); display.line(59,50, 83,74, BrightBlue);