SPI based library for the ST7735 LCD controller.
Dependents: RayCastingEngine RETRO_LCD_PerformanceTest RETRO_loop_test RETRO_RickGame ... more
Diff: LCD_ST7735.cpp
- Revision:
- 9:7ecd74dcb8ef
- Parent:
- 8:12f16befa7e1
- Child:
- 12:146a55dccb22
diff -r 12f16befa7e1 -r 7ecd74dcb8ef LCD_ST7735.cpp --- a/LCD_ST7735.cpp Sat Oct 25 04:10:47 2014 +0000 +++ b/LCD_ST7735.cpp Sat Oct 25 04:15:30 2014 +0000 @@ -93,7 +93,9 @@ void LCD_ST7735::setPixel(int x, int y, uint16_t color) { - setPixelFast(x, y, color); + write(CMD_CASET, (uint8_t[]){0, x, 0, x}, 4); + write(CMD_RASET, (uint8_t[]){0, y, 0, y}, 4); + write(CMD_RAMWR, color); } void LCD_ST7735::drawLine(int x1, int y1, int x2, int y2, uint16_t color) @@ -117,7 +119,7 @@ int err = dx - dy; while(x1 != x2 || y1 != y2) { - setPixelFast(x1, y1, color); + setPixel(x1, y1, color); int e2 = err << 1; if (e2 > -dy) { @@ -130,7 +132,7 @@ y1 += sy; } } - setPixelFast(x2, y2, color); + setPixel(x2, y2, color); } void LCD_ST7735::swap(int &a, int &b) @@ -159,14 +161,14 @@ while(ix >= iy) { - setPixelFast(x + ix, y + iy, color); - setPixelFast(x + iy, y + ix, color); - setPixelFast(x - ix, y + iy, color); - setPixelFast(x - iy, y + ix, color); - setPixelFast(x - ix, y - iy, color); - setPixelFast(x - iy, y - ix, color); - setPixelFast(x + ix, y - iy, color); - setPixelFast(x + iy, y - ix, color); + setPixel(x + ix, y + iy, color); + setPixel(x + iy, y + ix, color); + setPixel(x - ix, y + iy, color); + setPixel(x - iy, y + ix, color); + setPixel(x - ix, y - iy, color); + setPixel(x - iy, y - ix, color); + setPixel(x + ix, y - iy, color); + setPixel(x + iy, y - ix, color); iy++; if (err < 0) { @@ -190,10 +192,10 @@ int ix, iy, sigma; for (ix = 0, iy = ry, sigma = 2 * b2 + a2 * (1 - 2 * ry); b2 * ix <= a2 * iy; ix++) { - setPixelFast(x + ix, y + iy, color); - setPixelFast(x - ix, y + iy, color); - setPixelFast(x + ix, y - iy, color); - setPixelFast(x - ix, y - iy, color); + 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); @@ -204,10 +206,10 @@ for (ix = rx, iy = 0, sigma = 2 * a2 + b2 * (1 - 2 * rx); a2 * iy <= b2 * ix; iy++) { - setPixelFast(x + ix, y + iy, color); - setPixelFast(x - ix, y + iy, color); - setPixelFast(x + ix, y - iy, color); - setPixelFast(x - ix, y - iy, color); + 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); @@ -256,20 +258,20 @@ while(ix >= iy) { - setPixelFast(x - ix, y + iy, borderColor); - setPixelFast(x + ix, y + iy, borderColor); + setPixel(x - ix, y + iy, borderColor); + setPixel(x + ix, y + iy, borderColor); drawHorizLine(x - ix + 1, y + iy, x + ix - 1, fillColor); - setPixelFast(x - iy, y + ix, borderColor); - setPixelFast(x + iy, y + ix, borderColor); + setPixel(x - iy, y + ix, borderColor); + setPixel(x + iy, y + ix, borderColor); drawHorizLine(x - iy + 1, y + ix, x + iy - 1, fillColor); - setPixelFast(x - ix, y - iy, borderColor); - setPixelFast(x + ix, y - iy, borderColor); + setPixel(x - ix, y - iy, borderColor); + setPixel(x + ix, y - iy, borderColor); drawHorizLine(x - ix + 1, y - iy, x + ix - 1, fillColor); - setPixelFast(x - iy, y - ix, borderColor); - setPixelFast(x + iy, y - ix, borderColor); + setPixel(x - iy, y - ix, borderColor); + setPixel(x + iy, y - ix, borderColor); drawHorizLine(x - iy + 1, y - ix, x + iy - 1, fillColor); iy++; if (err < 0) @@ -294,12 +296,12 @@ int ix, iy, sigma; for (ix = 0, iy = ry, sigma = 2 * b2 + a2 * (1 - 2 * ry); b2 * ix <= a2 * iy; ix++) { - setPixelFast(x + ix, y + iy, borderColor); - setPixelFast(x - ix, y + iy, borderColor); + setPixel(x + ix, y + iy, borderColor); + setPixel(x - ix, y + iy, borderColor); drawHorizLine(x - ix + 1, y + iy, x + ix - 1, fillColor); - setPixelFast(x + ix, y - iy, borderColor); - setPixelFast(x - ix, y - iy, borderColor); + 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) @@ -312,12 +314,12 @@ for (ix = rx, iy = 0, sigma = 2 * a2 + b2 * (1 - 2 * rx); a2 * iy <= b2 * ix; iy++) { - setPixelFast(x + ix, y + iy, borderColor); - setPixelFast(x - ix, y + iy, borderColor); + setPixel(x + ix, y + iy, borderColor); + setPixel(x - ix, y + iy, borderColor); drawHorizLine(x - ix + 1, y + iy, x + ix - 1, fillColor); - setPixelFast(x + ix, y - iy, borderColor); - setPixelFast(x - ix, y - iy, borderColor); + 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) { @@ -389,13 +391,6 @@ _spi.prepareFastSPI(); } -void LCD_ST7735::setPixelFast(int x, int y, uint16_t color) -{ - write(CMD_CASET, (uint8_t[]){0, x, 0, x}, 4); - write(CMD_RASET, (uint8_t[]){0, y, 0, y}, 4); - write(CMD_RAMWR, color); -} - void LCD_ST7735::drawVertLine(int x1, int y1, int y2, uint16_t color) { clipRect(x1, y1, x1, y2);