From 2fab8fe34a6b8a87a8914573a49077aa5b7137e6 Mon Sep 17 00:00:00 2001 From: JP Date: Thu, 16 Jan 2014 20:29:42 +1100 Subject: [PATCH] font plotting anywhere --- MicroView.cpp | 548 ++++++++++++++++++++++++++++++-------------------- MicroView.h | 27 ++- font5x7.h | 2 +- 3 files changed, 350 insertions(+), 227 deletions(-) diff --git a/MicroView.cpp b/MicroView.cpp index f56ed4e..b0d0b5a 100644 --- a/MicroView.cpp +++ b/MicroView.cpp @@ -31,12 +31,30 @@ static uint8_t screenmemory [] = { // D6 D6.............D6 / // D7 D7.............D7 ---- - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0x78, 0xF8, 0xBC, 0xFC, 0xDE, 0xDE, 0xCF, 0xCF, 0xC7, 0xC3, 0xC3, 0xC7, 0x87, 0x8F, 0x0F, 0x1E, 0x1E, 0x3C, 0x78, 0x78, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xEF, 0xE7, 0xC7, 0xC3, 0x83, 0x01, 0x01, 0x00, 0x0F, 0x1F, 0x3F, 0x71, 0x6E, 0xEE, 0xEF, 0xF3, 0xF7, 0xF6, 0xF9, 0xFD, 0xDD, 0xEB, 0x7F, 0x7E, 0xBC, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0xF1, 0x79, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x0F, 0x1F, 0x1E, 0xFC, 0xFD, 0xF9, 0x7B, 0xF3, 0xE7, 0xEF, 0xCF, 0xDE, 0x9E, 0xBC, 0x3C, 0x78, 0x78, 0xF0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC, 0xBC, 0xFE, 0xFE, 0xFF, 0xE7, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x1E, 0x3F, 0x3F, 0x3F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0x7F, 0x1F, 0x3F, 0x3F, 0x1F, 0x03, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x07, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, + 0xC0, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, + 0xE0, 0xE0, 0xF0, 0xF0, 0x78, 0x38, 0xDC, 0xDC, 0xFE, 0xFE, 0x6F, 0x6F, 0xE7, 0xE7, 0x63, 0x61, + 0xC1, 0xC1, 0xC3, 0x87, 0x87, 0x0F, 0x0F, 0x1E, 0x1E, 0x3C, 0x3C, 0x78, 0x78, 0xF0, 0xF0, 0xE0, + 0xE0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFE, 0x3F, 0x7F, 0x77, 0xF3, 0xE3, + 0xE1, 0xC1, 0xC0, 0x80, 0x80, 0x07, 0x0F, 0x1F, 0x38, 0x30, 0x36, 0x76, 0x61, 0x61, 0x60, 0x68, + 0x69, 0x66, 0x60, 0x61, 0xB1, 0xBF, 0xDE, 0xC0, 0xE0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC, 0xBC, 0xBF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x07, 0x0F, 0xFF, 0xFE, 0xFE, 0x3C, + 0x3D, 0x79, 0x7B, 0xF3, 0xF7, 0xE7, 0xCF, 0xCE, 0x9E, 0x9C, 0x3C, 0xF8, 0xF8, 0xF8, 0x7C, 0xFC, + 0xFE, 0xCE, 0xEF, 0xFF, 0xFF, 0xFB, 0xFB, 0x7F, 0xFF, 0xFE, 0xFE, 0x1F, 0x0F, 0xFF, 0xFF, 0xFF, + 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, + 0xFF, 0xFF, 0x03, 0x01, 0x7F, 0xFF, 0x7F, 0x00, 0x1F, 0x3F, 0x1F, 0x00, 0x00, 0x07, 0x0F, 0x07, + 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -50,8 +68,13 @@ void MICROVIEW::begin() { fontStartChar=pgm_read_byte(fontsPointer[fontType]+3); fontTotalChar=pgm_read_byte(fontsPointer[fontType]+4); */ + setFontType(0); - + setFontColor(WHITE); + setFontDrawMode(NORM); + setCursor(0,0); + + // Setting up SPI pins pinMode(MOSI, OUTPUT); pinMode(SCK, OUTPUT); @@ -189,222 +212,307 @@ void MICROVIEW::display(void) { } } -void MICROVIEW::pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode) { - if ((x<0) || (x>LCDWIDTH-1) || (y<0) || (y>LCDHEIGHT-1)) - return; - - if (mode==XOR) { - screenmemory[x+ (y/8)*LCDWIDTH] ^= _BV((y%8)); - } - else { - if (color==WHITE) - screenmemory[x+ (y/8)*LCDWIDTH] |= _BV((y%8)); - else - screenmemory[x+ (y/8)*LCDWIDTH] &= ~_BV((y%8)); - } - - //display(); -} - -// bresenham's algorithm -void MICROVIEW::line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode) { - uint8_t steep = abs(y1 - y0) > abs(x1 - x0); - if (steep) { - swap(x0, y0); - swap(x1, y1); - } - - if (x0 > x1) { - swap(x0, x1); - swap(y0, y1); - } - - uint8_t dx, dy; - dx = x1 - x0; - dy = abs(y1 - y0); - - int8_t err = dx / 2; - int8_t ystep; - - if (y0 < y1) { - ystep = 1; - } else { - ystep = -1;} - - for (; x0= 100 +size_t MICROVIEW::write(uint8_t c) { +#else + void MICROVIEW::write(uint8_t c) { +#endif + if (c == '\n') { + cursorY += fontHeight; + cursorX = 0; + } else if (c == '\r') { + // skip em } else { - pixel(x0, y0, color, mode); + drawChar(cursorX, cursorY, c, fontColor, fontMode); + cursorX += fontWidth+1; + if ((cursorX > (LCDWIDTH - fontWidth))) { + cursorY += fontHeight; + cursorX = 0; + } } - err -= dy; - if (err < 0) { - y0 += ystep; - err += dx; - } - } -} - -void MICROVIEW::lineH(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode) { - line(x,y,x+width,y,color,mode); -} - -void MICROVIEW::lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode) { - line(x,y,x,y+height,color,mode); -} - -void MICROVIEW::rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode) { - uint8_t tempHeight; - - lineH(x,y, width, color, mode); - lineH(x,y+height-1, width, color, mode); - - tempHeight=height-2; - - // skip drawing vertical lines to avoid overlapping of pixel that will - // affect XOR plot if no pixel in between horizontal lines - if (tempHeight<1) return; - - lineV(x,y+1, tempHeight, color, mode); - lineV(x+width-1, y+1, tempHeight, color, mode); -} - -void MICROVIEW::rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode) { - // TODO - need to optimise the memory map draw so that this function will not call pixel one by one - for (int i=x; i= 100 + return 1; +#endif } -} -void MICROVIEW::circle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t mode) { - - //TODO - find a way to check for no overlapping of pixels so that XOR draw mode will work perfectly - int8_t f = 1 - radius; - int8_t ddF_x = 1; - int8_t ddF_y = -2 * radius; - int8_t x = 0; - int8_t y = radius; + void MICROVIEW::setCursor(uint8_t x, uint8_t y) { + cursorX=x; + cursorY=y; + } - pixel(x0, y0+radius, color, mode); - pixel(x0, y0-radius, color, mode); - pixel(x0+radius, y0, color, mode); - pixel(x0-radius, y0, color, mode); - - while (x= 0) { - y--; - ddF_y += 2; - f += ddF_y; - } - x++; - ddF_x += 2; - f += ddF_x; - - pixel(x0 + x, y0 + y, color, mode); - pixel(x0 - x, y0 + y, color, mode); - pixel(x0 + x, y0 - y, color, mode); - pixel(x0 - x, y0 - y, color, mode); + void MICROVIEW::pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode) { + if ((x<0) || (x>=LCDWIDTH) || (y<0) || (y>=LCDHEIGHT)) + return; - pixel(x0 + y, y0 + x, color, mode); - pixel(x0 - y, y0 + x, color, mode); - pixel(x0 + y, y0 - x, color, mode); - pixel(x0 - y, y0 - x, color, mode); - - } -} - - -void MICROVIEW::circleFill(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color, uint8_t mode) { - // TODO - - find a way to check for no overlapping of pixels so that XOR draw mode will work perfectly - int8_t f = 1 - r; - int8_t ddF_x = 1; - int8_t ddF_y = -2 * r; - int8_t x = 0; - int8_t y = r; - - // Temporary disable fill circle for XOR mode. - if (mode==XOR) return; - - for (uint8_t i=y0-r; i<=y0+r; i++) { - pixel(x0, i, color, mode); - } - - while (x= 0) { - y--; - ddF_y += 2; - f += ddF_y; + if (mode==XOR) { + screenmemory[x+ (y/8)*LCDWIDTH] ^= _BV((y%8)); } - x++; - ddF_x += 2; - f += ddF_x; - - for (uint8_t i=y0-y; i<=y0+y; i++) { - pixel(x0+x, i, color, mode); - pixel(x0-x, i, color, mode); - } - for (uint8_t i=y0-x; i<=y0+x; i++) { - pixel(x0+y, i, color, mode); - pixel(x0-y, i, color, mode); - } + else { + if (color==WHITE) + screenmemory[x+ (y/8)*LCDWIDTH] |= _BV((y%8)); + else + screenmemory[x+ (y/8)*LCDWIDTH] &= ~_BV((y%8)); + } + + //display(); } -} -uint8_t MICROVIEW::getFontWidth(void) { - return fontWidth; -} + // bresenham's algorithm + void MICROVIEW::line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode) { + uint8_t steep = abs(y1 - y0) > abs(x1 - x0); + if (steep) { + swap(x0, y0); + swap(x1, y1); + } -uint8_t MICROVIEW::getFontHeight(void) { - return fontHeight; -} + if (x0 > x1) { + swap(x0, x1); + swap(y0, y1); + } -uint8_t MICROVIEW::getFontStartChar(void) { - return fontStartChar; -} + uint8_t dx, dy; + dx = x1 - x0; + dy = abs(y1 - y0); -uint8_t MICROVIEW::getFontTotalChar(void) { - return fontTotalChar; -} + int8_t err = dx / 2; + int8_t ystep; -uint8_t MICROVIEW::getTotalFonts(void) { - return TOTALFONTS; -} + if (y0 < y1) { + ystep = 1; + } else { + ystep = -1;} -uint8_t MICROVIEW::getFontType(void) { - return fontType; -} + for (; x0=TOTALFONTS) || (type<0)) - return -1; + void MICROVIEW::lineH(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode) { + line(x,y,x+width,y,color,mode); + } - fontType=type; - fontWidth=pgm_read_byte(fontsPointer[fontType]+1); - fontHeight=pgm_read_byte(fontsPointer[fontType]+2); - fontStartChar=pgm_read_byte(fontsPointer[fontType]+3); - fontTotalChar=pgm_read_byte(fontsPointer[fontType]+4); - fontMapWidth=(pgm_read_byte(fontsPointer[fontType]+5)*100)+pgm_read_byte(fontsPointer[fontType]+6); // two bytes values into integer 16 + void MICROVIEW::lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode) { + line(x,y,x,y+height,color,mode); + } -} + void MICROVIEW::rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode) { + uint8_t tempHeight; + + lineH(x,y, width, color, mode); + lineH(x,y+height-1, width, color, mode); + + tempHeight=height-2; + + // skip drawing vertical lines to avoid overlapping of pixel that will + // affect XOR plot if no pixel in between horizontal lines + if (tempHeight<1) return; -void MICROVIEW::drawChar(uint8_t x, uint8_t line, uint8_t c, uint8_t mode) { - uint8_t rowsToDraw,row; - uint8_t i,tempX; - uint16_t charPerBitmapRow,charColPositionOnBitmap,charRowPositionOnBitmap,charBitmapStartPosition; - // TODO - char must be able to be drawn anywhere, not limited by line - // TODO - char must be able to XOR on background - - if ((line >= LCDHEIGHT/fontHeight) || (x > (LCDWIDTH - fontWidth))) - return; - - // TODO - check if char is not in memory + lineV(x,y+1, tempHeight, color, mode); + lineV(x+width-1, y+1, tempHeight, color, mode); + } + + void MICROVIEW::rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode) { + // TODO - need to optimise the memory map draw so that this function will not call pixel one by one + for (int i=x; i= 0) { + y--; + ddF_y += 2; + f += ddF_y; + } + x++; + ddF_x += 2; + f += ddF_x; + + pixel(x0 + x, y0 + y, color, mode); + pixel(x0 - x, y0 + y, color, mode); + pixel(x0 + x, y0 - y, color, mode); + pixel(x0 - x, y0 - y, color, mode); + + pixel(x0 + y, y0 + x, color, mode); + pixel(x0 - y, y0 + x, color, mode); + pixel(x0 + y, y0 - x, color, mode); + pixel(x0 - y, y0 - x, color, mode); + + } + } - tempX=x; - // each row (in datasheet is call page) is 8 bits high, 16 bit high character will have 2 rows to be drawn - rowsToDraw=fontHeight/8; // 8 is LCD's page size, see SSD1306 datasheet - if (rowsToDraw<=1) rowsToDraw=1; + void MICROVIEW::circleFill(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color, uint8_t mode) { + // TODO - - find a way to check for no overlapping of pixels so that XOR draw mode will work perfectly + int8_t f = 1 - r; + int8_t ddF_x = 1; + int8_t ddF_y = -2 * r; + int8_t x = 0; + int8_t y = r; + // Temporary disable fill circle for XOR mode. + if (mode==XOR) return; + + for (uint8_t i=y0-r; i<=y0+r; i++) { + pixel(x0, i, color, mode); + } + + while (x= 0) { + y--; + ddF_y += 2; + f += ddF_y; + } + x++; + ddF_x += 2; + f += ddF_x; + + for (uint8_t i=y0-y; i<=y0+y; i++) { + pixel(x0+x, i, color, mode); + pixel(x0-x, i, color, mode); + } + for (uint8_t i=y0-x; i<=y0+x; i++) { + pixel(x0+y, i, color, mode); + pixel(x0-y, i, color, mode); + } + } + } + + uint8_t MICROVIEW::getFontWidth(void) { + return fontWidth; + } + + uint8_t MICROVIEW::getFontHeight(void) { + return fontHeight; + } + + uint8_t MICROVIEW::getFontStartChar(void) { + return fontStartChar; + } + + uint8_t MICROVIEW::getFontTotalChar(void) { + return fontTotalChar; + } + + uint8_t MICROVIEW::getTotalFonts(void) { + return TOTALFONTS; + } + + uint8_t MICROVIEW::getFontType(void) { + return fontType; + } + + uint8_t MICROVIEW::setFontType(uint8_t type) { + if ((type>=TOTALFONTS) || (type<0)) + return -1; + + fontType=type; + fontWidth=pgm_read_byte(fontsPointer[fontType]+1); + fontHeight=pgm_read_byte(fontsPointer[fontType]+2); + fontStartChar=pgm_read_byte(fontsPointer[fontType]+3); + fontTotalChar=pgm_read_byte(fontsPointer[fontType]+4); + fontMapWidth=(pgm_read_byte(fontsPointer[fontType]+5)*100)+pgm_read_byte(fontsPointer[fontType]+6); // two bytes values into integer 16 + + } + + void MICROVIEW::setFontColor(uint8_t color) { + fontColor=color; + } + + void MICROVIEW::setFontDrawMode(uint8_t mode) { + fontMode=mode; + } + + void MICROVIEW::drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode) { + //void MICROVIEW::drawChar(uint8_t x, uint8_t line, uint8_t c, uint8_t mode) { + uint8_t rowsToDraw,row; + uint8_t i,j,tempX; + uint16_t charPerBitmapRow,charColPositionOnBitmap,charRowPositionOnBitmap,charBitmapStartPosition; + // TODO - char must be able to be drawn anywhere, not limited by line + // TODO - char must be able to XOR on background + + //if ((line >= LCDHEIGHT/fontHeight) || (x > (LCDWIDTH - fontWidth))) + //return; + + tempX=x; + // each row (in datasheet is call page) is 8 bits high, 16 bit high character will have 2 rows to be drawn + rowsToDraw=fontHeight/8; // 8 is LCD's page size, see SSD1306 datasheet + if (rowsToDraw<=1) rowsToDraw=1; + + // can draw anywhere on the screen, but SLOW pixel by pixel draw + if (rowsToDraw==1) { + for (i=0;i>=1; + } + } + return; + } + + + // font height over 8 bit + // take character "0" ASCII 48 as example + charPerBitmapRow=fontMapWidth/fontWidth; // 256/8 =32 char per row + charColPositionOnBitmap=c % charPerBitmapRow; // =16 + charRowPositionOnBitmap=int(c/charPerBitmapRow); // =1 + charBitmapStartPosition=(charRowPositionOnBitmap * fontMapWidth * (fontHeight/8)) + (charColPositionOnBitmap * fontWidth) ; + + // each row on LCD is 8 bit height (see datasheet for explanation) + for(row=0;row>=1; + } + } + } + + + + + /* + fast direct memory draw but has a limitation to draw in ROWS // only 1 row to draw for font with 8 bit height if (rowsToDraw==1) { for (i=0; i= 100 #include "Arduino.h" +#include "Print.h" #else #include "WProgram.h" #endif @@ -64,21 +65,28 @@ #define VERTICALRIGHTHORIZONTALSCROLL 0x29 #define VERTICALLEFTHORIZONTALSCROLL 0x2A -class MICROVIEW { +class MICROVIEW : public Print{ public: MICROVIEW(void) {}; void begin(void); -// RAW LCD functions +#if ARDUINO >= 100 + virtual size_t write(uint8_t); +#else + virtual void write(uint8_t); +#endif + + // RAW LCD functions void command(uint8_t c); void data(uint8_t c); void setColumnAddress(uint8_t add); void setPageAddress(uint8_t add); -// LCD Draw functions + // LCD Draw functions void clear(uint8_t mode); void invert(uint8_t i); void display(void); + void setCursor(uint8_t x, uint8_t y); void pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode); void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode); void lineH(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode); @@ -87,10 +95,10 @@ public: void rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode); void circle(uint8_t x, uint8_t y, uint8_t radius, uint8_t color, uint8_t mode); void circleFill(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color, uint8_t mode); - void drawChar(uint8_t x, uint8_t line, uint8_t c, uint8_t mode); + void drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode); void drawBitmap(void); -// Font functions + // Font functions uint8_t getFontWidth(void); uint8_t getFontHeight(void); uint8_t getTotalFonts(void); @@ -99,7 +107,12 @@ public: uint8_t getFontStartChar(void); uint8_t getFontTotalChar(void); -// LCD Rotate Scroll functions + // applicable for PRINT function + void setFontColor(uint8_t color); + void setFontDrawMode(uint8_t mode); + + + // LCD Rotate Scroll functions void scrollRight(uint8_t start, uint8_t stop); void scrollLeft(uint8_t start, uint8_t stop); void scrollVertRight(uint8_t start, uint8_t stop); @@ -110,7 +123,7 @@ private: //uint8_t cs; volatile uint8_t *mosiport, *sckport, *csport, *dcport; // use volatile because these are fixed location port address uint8_t mosipinmask, sckpinmask, cspinmask, dcpinmask; - uint8_t fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar; + uint8_t fontColor,fontMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY; uint16_t fontMapWidth; //unsigned char *fontsPointer[TOTALFONTS]; static const unsigned char *fontsPointer[]; diff --git a/font5x7.h b/font5x7.h index 266a573..5760d21 100644 --- a/font5x7.h +++ b/font5x7.h @@ -6,7 +6,7 @@ // Standard ASCII 5x7 font static const unsigned char font5x7[] PROGMEM = { // first row FONTTYPE, FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH - 0,5,7,0,255,12,75, + 0,5,8,0,255,12,75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E,