mirror of
https://github.com/geekammo/MicroView-Arduino-Library.git
synced 2026-02-20 11:31:24 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ee0b95cf8 | ||
|
|
fb8b9c4a43 |
252
MicroView.cpp
252
MicroView.cpp
@@ -1,12 +1,12 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#include <SPI.h>
|
||||
//#include <SPI.h>
|
||||
#include <MicroView.h>
|
||||
|
||||
// This fixed ugly GCC warning "only initialized variables can be placed into program memory area"
|
||||
#undef PROGMEM
|
||||
#define PROGMEM __attribute__((section(".progmem.data")))
|
||||
|
||||
// Add header of the fonts here. Remove as many as possible to get conserve FLASH memory.
|
||||
// Add header of the fonts here. Remove as many as possible to conserve FLASH memory.
|
||||
#include <font5x7.h>
|
||||
#include <font8x16.h>
|
||||
#include <fontlargenumber.h>
|
||||
@@ -15,6 +15,8 @@
|
||||
#include <space02.h>
|
||||
#include <space03.h>
|
||||
|
||||
|
||||
|
||||
// Change the total fonts included
|
||||
#define TOTALFONTS 7
|
||||
#define recvLEN 100
|
||||
@@ -93,19 +95,19 @@ void MicroView::begin() {
|
||||
// Setting up SPI pins
|
||||
pinMode(MOSI, OUTPUT);
|
||||
pinMode(SCK, OUTPUT);
|
||||
pinMode(DC, OUTPUT);
|
||||
|
||||
//pinMode(DC, OUTPUT);
|
||||
pinMode(RESET, OUTPUT);
|
||||
pinMode(SS, OUTPUT);
|
||||
pinMode(SS, INPUT);
|
||||
digitalWrite(SS, HIGH);
|
||||
|
||||
sckport = portOutputRegister(digitalPinToPort(SCK));
|
||||
sckpinmask = digitalPinToBitMask(SCK);
|
||||
mosiport = portOutputRegister(digitalPinToPort(MOSI));
|
||||
mosipinmask = digitalPinToBitMask(MOSI);
|
||||
ssport = portOutputRegister(digitalPinToPort(SS));
|
||||
sspinmask = digitalPinToBitMask(SS);
|
||||
dcport = portOutputRegister(digitalPinToPort(DC));
|
||||
dcpinmask = digitalPinToBitMask(DC);
|
||||
ssport = portOutputRegister(digitalPinToPort(SS));
|
||||
sspinmask = digitalPinToBitMask(SS);
|
||||
ssreg = portModeRegister(digitalPinToPort(SS));
|
||||
|
||||
dcport = portOutputRegister(digitalPinToPort(DC));
|
||||
dcpinmask = digitalPinToBitMask(DC);
|
||||
dcreg = portModeRegister(digitalPinToPort(DC));
|
||||
|
||||
digitalWrite(RESET, HIGH);
|
||||
// VDD (3.3V) goes high at start, lets just chill for 5 ms
|
||||
@@ -120,7 +122,8 @@ void MicroView::begin() {
|
||||
// wait 10ms
|
||||
delay(10);
|
||||
// bring out of reset
|
||||
digitalWrite(RESET, HIGH);
|
||||
pinMode(RESET,INPUT_PULLUP);
|
||||
//digitalWrite(RESET, HIGH);
|
||||
|
||||
// Init sequence for 64x48 OLED module
|
||||
command(DISPLAYOFF); // 0xAE
|
||||
@@ -164,20 +167,33 @@ void MicroView::begin() {
|
||||
|
||||
void MicroView::command(uint8_t c) {
|
||||
// Hardware SPI
|
||||
*ssport |= sspinmask; // SS HIGH
|
||||
*dcport &= ~dcpinmask; // DC LOW
|
||||
*ssport &= ~sspinmask; // SS LOW
|
||||
*dcreg |= dcpinmask; // Set DC pin to OUTPUT
|
||||
*dcport &= ~dcpinmask; // DC pin LOW
|
||||
|
||||
*ssreg |= sspinmask; // Set SS pin to OUTPUT
|
||||
*ssport &= ~sspinmask; // SS LOW
|
||||
|
||||
MVSPI.transfer(c);
|
||||
|
||||
*ssport |= sspinmask; // SS HIGH
|
||||
*ssreg &= ~sspinmask; // Set SS pin to INPUT
|
||||
|
||||
*dcreg &= ~dcpinmask; // Set DC to INPUT to avoid high voltage over driving the OLED logic
|
||||
}
|
||||
|
||||
void MicroView::data(uint8_t c) {
|
||||
// Hardware SPI
|
||||
*ssport |= sspinmask; // SS HIGH
|
||||
*dcport |= dcpinmask; // DC HIGH
|
||||
|
||||
*ssreg |= sspinmask; // Set SS pin to OUTPUT
|
||||
*ssport &= ~sspinmask; // SS LOW
|
||||
|
||||
MVSPI.transfer(c);
|
||||
|
||||
*ssport |= sspinmask; // SS HIGH
|
||||
*ssreg &= ~sspinmask; // Set SS pin to INPUT
|
||||
|
||||
*dcreg &= ~dcpinmask; // Set DC to INPUT to avoid high voltage over driving the OLED logic
|
||||
}
|
||||
|
||||
void MicroView::setPageAddress(uint8_t add) {
|
||||
@@ -688,53 +704,80 @@ void MicroView::doCmd(uint8_t cmdCount) {
|
||||
// decode command
|
||||
switch (serCmd[0]) {
|
||||
case CMD_CLEAR: {
|
||||
Serial.println("clear");
|
||||
if (cmdCount==1) {
|
||||
Serial.print("clear ");
|
||||
Serial.println(serCmd[1]);
|
||||
clear(serCmd[1]);
|
||||
} else if (cmdCount==2) {
|
||||
Serial.print("clear ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[2]);
|
||||
clear(serCmd[1], serCmd[2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_INVERT: {
|
||||
Serial.println("invert");
|
||||
|
||||
if (cmdCount==1) {
|
||||
Serial.print("invert ");
|
||||
Serial.println(serCmd[1]);
|
||||
invert(serCmd[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_CONTRAST: {
|
||||
Serial.println("contrast");
|
||||
|
||||
if (cmdCount==1) {
|
||||
Serial.print("contrast ");
|
||||
Serial.println(serCmd[1]);
|
||||
contrast(serCmd[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_DISPLAY: {
|
||||
Serial.println("display");
|
||||
|
||||
if (cmdCount==0) {
|
||||
Serial.println("display");
|
||||
display();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_SETCURSOR: {
|
||||
Serial.println("setCursor");
|
||||
|
||||
if (cmdCount==2) {
|
||||
Serial.print("setCursor ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[2]);
|
||||
setCursor(serCmd[1], serCmd[2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_PIXEL: {
|
||||
Serial.println("pixel");
|
||||
|
||||
if (cmdCount==2) {
|
||||
Serial.print("pixel ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[2]);
|
||||
pixel(serCmd[1],serCmd[2]);
|
||||
display();
|
||||
} else if (cmdCount=4) {
|
||||
Serial.print("pixel ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[4]);
|
||||
|
||||
pixel(serCmd[1],serCmd[2],serCmd[3],serCmd[4]);
|
||||
display();
|
||||
}
|
||||
@@ -742,11 +785,32 @@ void MicroView::doCmd(uint8_t cmdCount) {
|
||||
}
|
||||
|
||||
case CMD_LINE: {
|
||||
Serial.println("line");
|
||||
if (cmdCount==4) {
|
||||
Serial.print("line ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[4]);
|
||||
|
||||
line(serCmd[1],serCmd[2],serCmd[3],serCmd[4]);
|
||||
display();
|
||||
} else if (cmdCount==6) {
|
||||
Serial.print("line ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[4]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[5]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[6]);
|
||||
|
||||
line(serCmd[1],serCmd[2],serCmd[3],serCmd[4],serCmd[5],serCmd[6]);
|
||||
display();
|
||||
}
|
||||
@@ -754,11 +818,28 @@ void MicroView::doCmd(uint8_t cmdCount) {
|
||||
}
|
||||
|
||||
case CMD_LINEH: {
|
||||
Serial.println("lineH");
|
||||
if (cmdCount==3) {
|
||||
Serial.print("lineH ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[3]);
|
||||
|
||||
lineH(serCmd[1], serCmd[2], serCmd[3]);
|
||||
display();
|
||||
} else if (cmdCount==5) {
|
||||
Serial.print("lineH ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[4]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[5]);
|
||||
|
||||
lineH(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5]);
|
||||
display();
|
||||
}
|
||||
@@ -766,11 +847,27 @@ void MicroView::doCmd(uint8_t cmdCount) {
|
||||
}
|
||||
|
||||
case CMD_LINEV: {
|
||||
Serial.println("lineV");
|
||||
if (cmdCount==3) {
|
||||
Serial.print("lineH ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[3]);
|
||||
|
||||
lineV(serCmd[1], serCmd[2], serCmd[3]);
|
||||
display();
|
||||
} else if (cmdCount==5) {
|
||||
Serial.print("lineH ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[4]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[5]);
|
||||
lineV(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5]);
|
||||
display();
|
||||
}
|
||||
@@ -778,11 +875,30 @@ void MicroView::doCmd(uint8_t cmdCount) {
|
||||
}
|
||||
|
||||
case CMD_RECT: {
|
||||
Serial.println("rect");
|
||||
if (cmdCount==4) {
|
||||
Serial.print("rect ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[4]);
|
||||
rect(serCmd[1], serCmd[2], serCmd[3], serCmd[4]);
|
||||
display();
|
||||
} else if (cmdCount==6) {
|
||||
Serial.print("rect ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[4]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[5]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[6]);
|
||||
rect(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5], serCmd[6]);
|
||||
display();
|
||||
}
|
||||
@@ -790,11 +906,30 @@ void MicroView::doCmd(uint8_t cmdCount) {
|
||||
}
|
||||
|
||||
case CMD_RECTFILL: {
|
||||
Serial.println("rectFill");
|
||||
if (cmdCount==4) {
|
||||
Serial.print("rectFill ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[4]);
|
||||
rectFill(serCmd[1], serCmd[2], serCmd[3], serCmd[4]);
|
||||
display();
|
||||
} else if (cmdCount==6) {
|
||||
Serial.print("rectFill ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[4]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[5]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[6]);
|
||||
rectFill(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5], serCmd[6]);
|
||||
display();
|
||||
}
|
||||
@@ -803,11 +938,26 @@ void MicroView::doCmd(uint8_t cmdCount) {
|
||||
}
|
||||
|
||||
case CMD_CIRCLE: {
|
||||
Serial.println("circle");
|
||||
if (cmdCount==3) {
|
||||
Serial.print("circle ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[3]);
|
||||
circle(serCmd[1], serCmd[2], serCmd[3]);
|
||||
display();
|
||||
} else if (cmdCount==5) {
|
||||
Serial.print("circle ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[4]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[5]);
|
||||
circle(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5]);
|
||||
display();
|
||||
}
|
||||
@@ -815,12 +965,27 @@ void MicroView::doCmd(uint8_t cmdCount) {
|
||||
}
|
||||
|
||||
case CMD_CIRCLEFILL: {
|
||||
Serial.println("circleFill");
|
||||
|
||||
if (cmdCount==3) {
|
||||
Serial.print("circle ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[3]);
|
||||
circleFill(serCmd[1], serCmd[2], serCmd[3]);
|
||||
display();
|
||||
} else if (cmdCount==5) {
|
||||
Serial.print("circle ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[4]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[5]);
|
||||
circleFill(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5]);
|
||||
display();
|
||||
}
|
||||
@@ -828,11 +993,26 @@ void MicroView::doCmd(uint8_t cmdCount) {
|
||||
}
|
||||
|
||||
case CMD_DRAWCHAR: {
|
||||
Serial.println("drawChar");
|
||||
if (cmdCount==3) {
|
||||
Serial.print("drawChar ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[3]);
|
||||
drawChar(serCmd[1], serCmd[2], serCmd[3]);
|
||||
display();
|
||||
} else if (cmdCount==5) {
|
||||
Serial.print("drawChar ");
|
||||
Serial.print(serCmd[1]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[2]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[3]);
|
||||
Serial.print(" ");
|
||||
Serial.print(serCmd[4]);
|
||||
Serial.print(" ");
|
||||
Serial.println(serCmd[5]);
|
||||
drawChar(serCmd[1], serCmd[2], serCmd[3], serCmd[4], serCmd[5]);
|
||||
display();
|
||||
}
|
||||
@@ -846,33 +1026,35 @@ void MicroView::doCmd(uint8_t cmdCount) {
|
||||
}
|
||||
|
||||
case CMD_GETLCDWIDTH: {
|
||||
Serial.println("getLCDWidth");
|
||||
|
||||
if (cmdCount==0) {
|
||||
Serial.print("LCDWidth=");
|
||||
Serial.println(getLCDWidth());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_GETLCDHEIGHT: {
|
||||
Serial.println("getLCDHeight");
|
||||
if (cmdCount==0) {
|
||||
Serial.print("LCDHeight=");
|
||||
Serial.println(getLCDHeight());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_SETCOLOR: {
|
||||
Serial.println("setColor");
|
||||
if (cmdCount==1) {
|
||||
Serial.print("setColor ");
|
||||
Serial.println(serCmd[1]);
|
||||
setColor(serCmd[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CMD_SETDRAWMODE: {
|
||||
Serial.println("drawMode");
|
||||
if (cmdCount==1) {
|
||||
Serial.print("drawMode ");
|
||||
Serial.println(serCmd[1]);
|
||||
setDrawMode(serCmd[1]);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
|
||||
#define DC 8
|
||||
#define RESET 12
|
||||
// SS, SCK, MOSI already defined by original SPI.h
|
||||
|
||||
// SS, SCK, MOSI already defined by original pins_arduino.h
|
||||
//#define CS 10
|
||||
//#define SCK 13
|
||||
//#define MOSI 11
|
||||
@@ -158,7 +159,8 @@ public:
|
||||
|
||||
private:
|
||||
//uint8_t cs;
|
||||
volatile uint8_t *mosiport, *sckport, *ssport, *dcport; // use volatile because these are fixed location port address
|
||||
//volatile uint8_t *mosiport, *sckport;
|
||||
volatile uint8_t *ssport, *dcport, *ssreg, *dcreg; // use volatile because these are fixed location port address
|
||||
uint8_t mosipinmask, sckpinmask, sspinmask, dcpinmask;
|
||||
uint8_t foreColor,drawMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY;
|
||||
uint16_t fontMapWidth;
|
||||
|
||||
18
README.md
18
README.md
@@ -12,9 +12,13 @@ Arduino library for MicroView.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Extract / Check out to Arduino's libraries folder.
|
||||
2. Start Arduino IDE.
|
||||
3. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo
|
||||
1. Change directory to Arduino's main directory
|
||||
2. cd libraries
|
||||
3. mkdir MicroView
|
||||
4. cd MicroView
|
||||
5. git clone git@github.com:geekammo/microview.git .
|
||||
6. Start Arduino IDE.
|
||||
7. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo
|
||||
|
||||
### Example 1 - Hello World!
|
||||
<pre><code>
|
||||
@@ -87,10 +91,16 @@ void loop() {
|
||||
</code></pre>
|
||||
|
||||
## History
|
||||
**v1.10b: 22th April 2014 by JP Liew**
|
||||
* changed SS, RESET, DC pins to use weak internal pull-up resistors
|
||||
|
||||
**v1.09b: 17th April 2014 by JP Liew**
|
||||
* changed verticalFlip() to flipVertical() and horizontalFlip() to flipHorizontal() for consistency
|
||||
* added debug messages for doCmd()
|
||||
|
||||
**v1.08b: 18th February 2014 by JP Liew**
|
||||
* added verticalFlip(), horizontalFlip()
|
||||
|
||||
|
||||
**v1.07b: 15th February 2014 by JP Liew**
|
||||
* changed function name stopScroll to scrollStop for consistency
|
||||
* added contrast function
|
||||
|
||||
Reference in New Issue
Block a user