mirror of
https://github.com/geekammo/MicroView-Arduino-Library.git
synced 2026-03-03 00:34:06 +01:00
added multiple fonts support
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
/*
|
||||
Screen memory buffer 64 x 48 divided by 8 = 384 bytes
|
||||
Screen memory buffer is required because in SPI mode, the host cannot read the GDRAM of the controller. This buffer serves as a scratch RAM for graphical functions.
|
||||
Screen memory buffer is required because in SPI mode, the host cannot read the SSD1306's GDRAM of the controller. This buffer serves as a scratch RAM for graphical functions.
|
||||
*/
|
||||
static uint8_t screenmemory [] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
@@ -34,7 +34,15 @@ static uint8_t screenmemory [] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
#define TOTALFONTS 2
|
||||
|
||||
const unsigned char *MICROVIEW::fontsPointer[]={font,font};
|
||||
|
||||
void MICROVIEW::begin() {
|
||||
|
||||
// default 5x7 font
|
||||
fontType=0;
|
||||
|
||||
// Setting up SPI pins
|
||||
pinMode(MOSI, OUTPUT);
|
||||
pinMode(SCK, OUTPUT);
|
||||
@@ -333,14 +341,37 @@ void MICROVIEW::circleFill(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color, uin
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::getFontWidth(void) {
|
||||
return pgm_read_byte(fontsPointer[fontType]+1);
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::getFontHeight(void) {
|
||||
return pgm_read_byte(fontsPointer[fontType]+2);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void MICROVIEW::drawChar(uint8_t x, uint8_t line, uint8_t c, uint8_t mode) {
|
||||
// TODO - char must be able to be drawn anywhere, not limited by line
|
||||
if ((line >= LCDHEIGHT/8) || (x >= (LCDWIDTH - 6)))
|
||||
return;
|
||||
for (uint8_t i =0; i<5; i++ ) {
|
||||
screenmemory[x + (line*64) ] = pgm_read_byte(font+(c*5)+i);
|
||||
x++;
|
||||
}
|
||||
if ((line >= LCDHEIGHT/8) || (x >= (LCDWIDTH - 6)))
|
||||
return;
|
||||
for (uint8_t i =0; i<5; i++ ) {
|
||||
screenmemory[x + (line*LCDWIDTH) ] = pgm_read_byte(fontsPointer[fontType]+3+(c*5)+i);
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
void MICROVIEW::stopScroll(void){
|
||||
|
||||
76
MicroView.h
76
MicroView.h
@@ -2,9 +2,9 @@
|
||||
#define MICROVIEW_H
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define swap(a, b) { uint8_t t = a; a = b; b = t; }
|
||||
@@ -61,40 +61,46 @@
|
||||
#define VERTICALLEFTHORIZONTALSCROLL 0x2A
|
||||
|
||||
class MICROVIEW {
|
||||
public:
|
||||
MICROVIEW(void) {};
|
||||
void begin(void);
|
||||
void command(uint8_t c);
|
||||
void data(uint8_t c);
|
||||
void clear(uint8_t mode);
|
||||
void invert(uint8_t i);
|
||||
void display(void);
|
||||
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);
|
||||
void lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode);
|
||||
void rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode);
|
||||
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 drawBitmap(void);
|
||||
|
||||
|
||||
void setColumnAddress(uint8_t add);
|
||||
void setPageAddress(uint8_t add);
|
||||
|
||||
public:
|
||||
MICROVIEW(void) {};
|
||||
void begin(void);
|
||||
void command(uint8_t c);
|
||||
void data(uint8_t c);
|
||||
void clear(uint8_t mode);
|
||||
void invert(uint8_t i);
|
||||
void display(void);
|
||||
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);
|
||||
void lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode);
|
||||
void rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode);
|
||||
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 drawBitmap(void);
|
||||
|
||||
void scrollRight(uint8_t start, uint8_t stop);
|
||||
void scrollLeft(uint8_t start, uint8_t stop);
|
||||
void scrollVertRight(uint8_t start, uint8_t stop);
|
||||
void scrollVertLeft(uint8_t start, uint8_t stop);
|
||||
void stopScroll(void);
|
||||
|
||||
uint8_t getFontWidth(void);
|
||||
uint8_t getFontHeight(void);
|
||||
uint8_t getTotalFonts(void);
|
||||
uint8_t getFontType(void);
|
||||
uint8_t setFontType(uint8_t type);
|
||||
|
||||
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;
|
||||
void setColumnAddress(uint8_t add);
|
||||
void setPageAddress(uint8_t add);
|
||||
|
||||
void scrollRight(uint8_t start, uint8_t stop);
|
||||
void scrollLeft(uint8_t start, uint8_t stop);
|
||||
void scrollVertRight(uint8_t start, uint8_t stop);
|
||||
void scrollVertLeft(uint8_t start, uint8_t stop);
|
||||
void stopScroll(void);
|
||||
|
||||
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;
|
||||
//unsigned char *fontsPointer[TOTALFONTS];
|
||||
static const unsigned char *fontsPointer[];
|
||||
};
|
||||
#endif
|
||||
@@ -1,11 +1,12 @@
|
||||
#ifndef FONT5X7_H
|
||||
#define FONT5X7_H
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
// Standard ASCII 5x7 font
|
||||
static const unsigned char font[] PROGMEM = {
|
||||
// first row FONTTYPE, FONTWIDTH, FONTHEIGHT
|
||||
0,5,7,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
|
||||
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
|
||||
|
||||
Reference in New Issue
Block a user