SPI based library for the ST7735 LCD controller.
Dependents: RayCastingEngine RETRO_LCD_PerformanceTest RETRO_loop_test RETRO_RickGame ... more
Diff: LCD_ST7735.cpp
- Revision:
- 13:a559617cdf94
- Parent:
- 12:146a55dccb22
- Child:
- 14:c94d0a2c2ba0
--- a/LCD_ST7735.cpp Sun Jan 25 06:53:17 2015 +0000 +++ b/LCD_ST7735.cpp Sun Feb 01 05:09:49 2015 +0000 @@ -385,14 +385,35 @@ void LCD_ST7735::drawString(const uint8_t *pFont, int x, int y, const char *pString) { + uint8_t w = *pFont; + uint8_t h = *(pFont + 1); + uint8_t offset = *(pFont + 2); + uint8_t leftPad = *(pFont + 3); + uint8_t rightPad = *(pFont + 4); + uint8_t topPad = *(pFont + 5); + uint8_t bottomPad = *(pFont + 6); + char *p = (char*)pString; while(*p != 0) { - drawChar(pFont, x, y, *p++); - x += 8; + drawChar(pFont, x, y, *p++, w, h, offset, leftPad, rightPad, topPad, bottomPad); + x += (w + leftPad + rightPad); } } +void measureString(const uint8_t *pFont, const char *pString, uint8_t &width, uint8_t &height) +{ + uint8_t w = *pFont; + uint8_t h = *(pFont + 1); + uint8_t leftPad = *(pFont + 3); + uint8_t rightPad = *(pFont + 4); + uint8_t topPad = *(pFont + 5); + uint8_t bottomPad = *(pFont + 6); + + width = (w + leftPad + rightPad) * strlen(pString); + height = (h + topPad + bottomPad); +} + void LCD_ST7735::selectDevice() { _spi.prepareFastSPI(); @@ -426,16 +447,36 @@ endBatchCommand(); } -void LCD_ST7735::drawChar(const uint8_t *pFont, int x, int y, char c) +void LCD_ST7735::drawChar(const uint8_t *pFont, int x, int y, char c, uint8_t w, uint8_t h, uint8_t offset, uint8_t leftPad, uint8_t rightPad, uint8_t topPad, uint8_t bottomPad) { - const uint8_t *pChar = pFont + (c * 8); + const uint8_t *pChar = (pFont + 7) + ((c - offset) * h); + + clip(x, y, w + leftPad + rightPad, h + topPad + bottomPad); + + beginBatchCommand(CMD_RAMWR); - clip(x, y, 8, 8); - beginBatchCommand(CMD_RAMWR); - for(int r = 0; r < 8; ++r) + // Render top spacing + for (int r = 0; r < topPad; ++r) + { + for (int c = 0; c < w + leftPad + rightPad; ++c) + { + writeBatchData(_backgroundColorHigh); + writeBatchData(_backgroundColorLow); + } + } + + // Render character + for(int r = 0; r < h; ++r) { uint8_t b = pChar[r]; - for(int c = 0; c < 8; ++c) + + // Render left spacing + for (int c = 0; c < leftPad; ++c) + { + writeBatchData(_backgroundColorHigh); + writeBatchData(_backgroundColorLow); + } + for(int c = 0; c < w; ++c) { if (b & 0x80) { @@ -450,6 +491,22 @@ b <<= 1; } + + for (int c = 0; c < rightPad; ++c) + { + writeBatchData(_backgroundColorHigh); + writeBatchData(_backgroundColorLow); + } + } + + // Render bottom spacing + for (int r = 0; r < bottomPad; ++r) + { + for (int c = 0; c < w + leftPad + rightPad; ++c) + { + writeBatchData(_backgroundColorHigh); + writeBatchData(_backgroundColorLow); + } } endBatchCommand(); }