SPI based library for the ST7735 LCD controller.
Dependents: RayCastingEngine RETRO_LCD_PerformanceTest RETRO_loop_test RETRO_RickGame ... more
Diff: LCD_ST7735.cpp
- Revision:
- 1:33ff5fad4320
- Parent:
- 0:7b3fb3085867
- Child:
- 3:451148656b76
diff -r 7b3fb3085867 -r 33ff5fad4320 LCD_ST7735.cpp --- a/LCD_ST7735.cpp Fri Sep 19 02:43:29 2014 +0000 +++ b/LCD_ST7735.cpp Sat Sep 20 04:28:41 2014 +0000 @@ -16,7 +16,7 @@ _spi(mosiPin, misoPin, clkPin) { _spi.format(8, 3); - _spi.frequency(12000000); + _spi.frequency(15000000); initDisplay(); clearScreen(); @@ -131,6 +131,43 @@ } } +void LCD_ST7735::drawEllipse(int x, int y, int rx, int ry, uint16_t color) +{ + int a2 = rx * rx; + int b2 = ry * ry; + int fa2 = 4 * a2; + int fb2 = 4 * b2; + + int ix, iy, sigma; + for (ix = 0, iy = ry, sigma = 2 * b2 + a2 * (1 - 2 * ry); b2 * ix <= a2 * iy; ix++) + { + setPixel(x + ix, y + iy, color); + setPixel(x - ix, y + iy, color); + setPixel(x + ix, y - iy, color); + setPixel(x - ix, y - iy, color); + if (sigma >= 0) + { + sigma+= fa2 * (1 - iy); + iy--; + } + sigma += b2 * ((4 * ix) + 6); + } + + for (ix = rx, iy = 0, sigma = 2 * a2 + b2 * (1 - 2 * rx); a2 * iy <= b2 * ix; iy++) + { + setPixel(x + ix, y + iy, color); + setPixel(x - ix, y + iy, color); + setPixel(x + ix, y - iy, color); + setPixel(x - ix, y - iy, color); + if (sigma >= 0) + { + sigma+= fb2 * (1 - ix); + ix--; + } + sigma += a2 * ((4 * iy) + 6); + } +} + void LCD_ST7735::fillRect(int x1, int y1, int x2, int y2, uint16_t borderColor, uint16_t fillColor) { if (x1 > x2) swap(x1, x2); @@ -183,6 +220,50 @@ } } +void LCD_ST7735::fillEllipse(int x, int y, int rx, int ry, uint16_t borderColor, uint16_t fillColor) +{ + int a2 = rx * rx; + int b2 = ry * ry; + int fa2 = 4 * a2; + int fb2 = 4 * b2; + + int ix, iy, sigma; + for (ix = 0, iy = ry, sigma = 2 * b2 + a2 * (1 - 2 * ry); b2 * ix <= a2 * iy; ix++) + { + setPixel(x + ix, y + iy, borderColor); + setPixel(x - ix, y + iy, borderColor); + drawHorizLine(x - ix + 1, y + iy, x + ix - 1, fillColor); + + setPixel(x + ix, y - iy, borderColor); + setPixel(x - ix, y - iy, borderColor); + drawHorizLine(x - ix + 1, y - iy, x + ix - 1, fillColor); + + if (sigma >= 0) + { + sigma+= fa2 * (1 - iy); + iy--; + } + sigma += b2 * ((4 * ix) + 6); + } + + for (ix = rx, iy = 0, sigma = 2 * a2 + b2 * (1 - 2 * rx); a2 * iy <= b2 * ix; iy++) + { + setPixel(x + ix, y + iy, borderColor); + setPixel(x - ix, y + iy, borderColor); + drawHorizLine(x - ix + 1, y + iy, x + ix - 1, fillColor); + + setPixel(x + ix, y - iy, borderColor); + setPixel(x - ix, y - iy, borderColor); + drawHorizLine(x - ix + 1, y - iy, x + ix - 1, fillColor); + if (sigma >= 0) + { + sigma+= fb2 * (1 - ix); + ix--; + } + sigma += a2 * ((4 * iy) + 6); + } +} + void LCD_ST7735::drawBitmap(int x, int y, const uint16_t *pbmp) { int w = *pbmp++; @@ -198,6 +279,25 @@ endBatchCommand(); } +void LCD_ST7735::drawBitmap(int x, int y, const uint16_t *pbmp, int srcX, int srcY, int srcWidth, int srcHeight) +{ + int w = *pbmp++; + int h = *pbmp++; + + clip(x, y, srcWidth, srcHeight); + beginBatchCommand(CMD_RAMWR); + const uint16_t *p = pbmp + srcX + (srcY * w); + for(int iy = 0; iy < srcHeight; ++iy) + { + for(int ix = 0; ix < srcWidth; ++ix) + { + writeBatchData(*(p + ix)); + } + p += w; + } + endBatchCommand(); +} + void LCD_ST7735::setForegroundColor(uint16_t color) { _foregroundColor = color;