Rectangle helper fixed

This commit is contained in:
KTOWN 2013-10-08 18:20:21 +02:00
parent cb9b045f07
commit b12ba062e4
2 changed files with 64 additions and 47 deletions

View File

@ -194,58 +194,19 @@ void Adafruit_RA8875::drawPixel(int16_t x, int16_t y, uint16_t color)
digitalWrite(_cs, HIGH);
}
void Adafruit_RA8875::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
{
rectHelper(x, y, x+w, y+h, color, false);
}
void Adafruit_RA8875::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
{
/* Set X */
writeCommand(0x91);
writeData(x);
writeCommand(0x92);
writeData(x >> 8);
/* Set Y */
writeCommand(0x93);
writeData(y);
writeCommand(0x94);
writeData(y >> 8);
/* Set X1 */
writeCommand(0x95);
writeData(x+w);
writeCommand(0x96);
writeData((x+w) >> 8);
/* Set Y1 */
writeCommand(0x97);
writeData(y+h);
writeCommand(0x98);
writeData((y+h) >> 8);
/* Set Color */
writeCommand(0x63);
writeData((color & 0xf800) >> 11);
writeCommand(0x64);
writeData((color & 0x07e0) >> 5);
writeCommand(0x65);
writeData((color & 0x001f));
/* Draw! */
writeCommand(RA8875_DCR);
/* Square, Filled */
writeData(0xB0);
/* Wait for the command to finish */
bool finished = false;
while (!finished)
{
uint8_t temp = readReg(RA8875_DCR);
if (!(temp & RA8875_DCR_LINESQUTRI_STATUS))
finished = true;
}
rectHelper(x, y, x+w, y+h, color, true);
}
void Adafruit_RA8875::fillScreen(uint16_t color)
{
fillRect(0, 0, _width-1, _height-1, color);
rectHelper(0, 0, _width-1, _height-1, color, true);
}
void Adafruit_RA8875::circleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t color, bool filled)
@ -295,6 +256,61 @@ void Adafruit_RA8875::circleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t c
}
}
void Adafruit_RA8875::rectHelper(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, bool filled)
{
/* Set X */
writeCommand(0x91);
writeData(x);
writeCommand(0x92);
writeData(x >> 8);
/* Set Y */
writeCommand(0x93);
writeData(y);
writeCommand(0x94);
writeData(y >> 8);
/* Set X1 */
writeCommand(0x95);
writeData(w);
writeCommand(0x96);
writeData((w) >> 8);
/* Set Y1 */
writeCommand(0x97);
writeData(h);
writeCommand(0x98);
writeData((h) >> 8);
/* Set Color */
writeCommand(0x63);
writeData((color & 0xf800) >> 11);
writeCommand(0x64);
writeData((color & 0x07e0) >> 5);
writeCommand(0x65);
writeData((color & 0x001f));
/* Draw! */
writeCommand(RA8875_DCR);
if (filled)
{
writeData(0xB0);
}
else
{
writeData(0x90);
}
/* Wait for the command to finish */
bool finished = false;
while (!finished)
{
uint8_t temp = readReg(RA8875_DCR);
if (!(temp & RA8875_DCR_LINESQUTRI_STATUS))
finished = true;
}
}
void Adafruit_RA8875::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
{
circleHelper(x0, y0, r, color, false);

View File

@ -33,7 +33,7 @@ class Adafruit_RA8875 : public Adafruit_GFX {
//void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
//void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
//void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
//void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void fillScreen(uint16_t color);
@ -70,6 +70,7 @@ class Adafruit_RA8875 : public Adafruit_GFX {
/* GFX Helper Functions */
void circleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t color, bool filled);
void rectHelper (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, bool filled);
uint8_t _cs, _rst;
uint16_t _width, _height;