Increased SPI frequency from 5Mhz to 10MHz
Fork of RA8875 by
Diff: RA8875.cpp
- Revision:
- 133:e36dcfc2d756
- Parent:
- 131:5bd6ba2ee4a1
- Child:
- 134:f028ed71a0af
--- a/RA8875.cpp Sun Sep 04 16:54:34 2016 +0000 +++ b/RA8875.cpp Mon Oct 17 00:42:47 2016 +0000 @@ -4,9 +4,8 @@ /// which is 480 x 272 using a 4-wire SPI interface. Support is provided for /// both a keypad and a resistive touch-screen. /// -/// 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. +/// This dirver has been fully tested with an 800 x 480 variant (also using +/// 4-wire SPI). /// #include "RA8875.h" @@ -183,7 +182,7 @@ WriteCommand(0x1f, 0x01); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0] portraitmode = false; - + if (width >= 800 && height >= 480 && color_bpp > 8) { WriteCommand(0x20, 0x00); // DPCR - 1-layer mode when the resolution is too high } else { @@ -295,10 +294,7 @@ RetCode_t RA8875::SetBackgroundTransparencyColor(color_t color) { - WriteCommand(0x67, (color >> 11) & 0x1F); - WriteCommand(0x68, (color >> 5) & 0x3F); - WriteCommand(0x69, (color & 0x1F)); - return noerror; + return _writeColorTrio(0x67, color); } @@ -667,6 +663,54 @@ return c16; } +RetCode_t RA8875::_writeColorTrio(uint8_t regAddr, color_t color) +{ + RetCode_t rt = noerror; + + if (screenbpp == 16) { + WriteCommand(regAddr+0, (color>>11)); // BGCR0 + WriteCommand(regAddr+1, (unsigned char)(color>>5)); // BGCR1 + rt = WriteCommand(regAddr+2, (unsigned char)(color)); // BGCR2 + } else { + uint8_t r, g, b; + + // RRRR RGGG GGGB BBBB RGB + // RRR GGG B B + r = (uint8_t)((color) >> 13); + g = (uint8_t)((color) >> 8); + b = (uint8_t)((color) >> 3); + WriteCommand(regAddr+0, r); // BGCR0 + WriteCommand(regAddr+1, g); // BGCR1 + rt = WriteCommand(regAddr+2, b); // BGCR2 + } + return rt; +} + +color_t RA8875::_readColorTrio(uint8_t regAddr) +{ + color_t color; + uint8_t r, g, b; + + r = ReadCommand(regAddr+0); + g = ReadCommand(regAddr+1); + b = ReadCommand(regAddr+2); + if (screenbpp == 16) { + // 000R RRRR 00GG GGGG 000B BBBB + // RRRR RGGG GGGB BBBB + color = (r & 0x1F) << 11; + color |= (g & 0x3F) << 5; + color |= (b & 0x1F); + } else { + // RRRG GGBB + // RRRR RGGG GGGB BBBB + color = (r & 0x07) << 13; + color |= (g & 0x07) << 8; + color |= (b & 0x03) << 3; + } + return color; +} + + dim_t RA8875::fontwidth(void) { if (font == NULL) @@ -1219,7 +1263,6 @@ color_t pixel; PERFORMANCE_RESET; - //WriteCommand(0x45,0x00); // read left->right, top->bottom WriteCommand(0x40,0x00); // Graphics write mode SetGraphicsCursorRead(x, y); WriteCommand(0x02); @@ -1749,10 +1792,7 @@ RetCode_t RA8875::background(color_t color) { GraphicsDisplay::background(color); - WriteCommand(0x60, (color>>11)); // BGCR0 - WriteCommand(0x61, (unsigned char)(color>>5)); // BGCR0 - WriteCommand(0x62, (unsigned char)(color)); // BGCR0 - return noerror; + return _writeColorTrio(0x60, color); } @@ -1766,10 +1806,7 @@ RetCode_t RA8875::foreground(color_t color) { GraphicsDisplay::foreground(color); - WriteCommand(0x63, (unsigned char)(color>>11)); - WriteCommand(0x64, (unsigned char)(color>>5)); - WriteCommand(0x65, (unsigned char)(color)); - return noerror; + return _writeColorTrio(0x63, color); } @@ -1782,12 +1819,7 @@ color_t RA8875::GetForeColor(void) { - color_t color; - - color = (ReadCommand(0x63) & 0x1F) << 11; - color |= (ReadCommand(0x64) & 0x3F) << 5; - color |= (ReadCommand(0x65) & 0x1F); - return color; + return _readColorTrio(0x63); }