Merge branch 'MLXXXp-master'

This commit is contained in:
JP
2014-08-03 15:48:14 +10:00
3 changed files with 260 additions and 180 deletions

View File

@@ -60,18 +60,18 @@ Page buffer is required because in SPI mode, the host cannot read the SSD1306's
static uint8_t screenmemory [] = { static uint8_t screenmemory [] = {
// LCD Memory organised in 64 horizontal pixel and 6 rows of byte // LCD Memory organised in 64 horizontal pixel and 6 rows of byte
// B B .............B ----- // B B .............B -----
// y y .............y \ // y y .............y |
// t t .............t \ // t t .............t |
// e e .............e \ // e e .............e |
// 0 1 .............63 \ // 0 1 .............63 |
// \ // |
// D0 D0.............D0 \ // D0 D0.............D0 | ROW 0
// D1 D1.............D1 / ROW 0 // D1 D1.............D1 |
// D2 D2.............D2 / // D2 D2.............D2 |
// D3 D3.............D3 / // D3 D3.............D3 |
// D4 D4.............D4 / // D4 D4.............D4 |
// D5 D5.............D5 / // D5 D5.............D5 |
// D6 D6.............D6 / // D6 D6.............D6 |
// D7 D7.............D7 ---- // D7 D7.............D7 ----
//SparkFun Electronics LOGO //SparkFun Electronics LOGO
@@ -123,119 +123,116 @@ void MicroView::begin() {
setColor(WHITE); setColor(WHITE);
setDrawMode(NORM); setDrawMode(NORM);
setCursor(0,0); setCursor(0,0);
RESETLOW;
// Enable 3.3V power to the display
pinMode(OLEDPWR, OUTPUT); pinMode(OLEDPWR, OUTPUT);
digitalWrite(OLEDPWR,HIGH); digitalWrite(OLEDPWR, HIGH);
// Setting up SPI pins
pinMode(MOSI, OUTPUT); // Give some time for power to stabilise
pinMode(SCK, OUTPUT); delay(10);
//pinMode(DC, OUTPUT); RESETHIGH;
pinMode(RESET, OUTPUT);
pinMode(SS, INPUT);
digitalWrite(SS, HIGH);
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
delay(5); delay(5);
// bring reset low RESETLOW;
digitalWrite(RESET, LOW);
// Setup SPI frequency // Setup SPI frequency
MVSPI.setClockDivider(SPI_CLOCK_DIV2); MVSPI.setClockDivider(SPI_CLOCK_DIV2);
// Initialise SPI
MVSPI.begin(); MVSPI.begin();
// wait 10ms delay(5);
delay(10);
// bring out of reset // bring out of reset
pinMode(RESET,INPUT_PULLUP); RESETHIGH;
//digitalWrite(RESET, HIGH);
delay(10);
// Init sequence for 64x48 OLED module // Init sequence for 64x48 OLED module
command(DISPLAYOFF); // 0xAE // command(DISPLAYOFF); // 0xAE
// command(SETDISPLAYCLOCKDIV, 0x80); // 0xD5 / the suggested ratio 0x80
command(SETDISPLAYCLOCKDIV); // 0xD5 command(SETMULTIPLEX, 0x2F); // 0xA8
command(0x80); // the suggested ratio 0x80 // command(SETDISPLAYOFFSET, 0x0); // 0xD3 / no offset
// command(SETSTARTLINE | 0x0); // 0x40 / line #0
command(SETMULTIPLEX); // 0xA8 command(CHARGEPUMP, 0x14); // 0x8D / enable charge pump
command(0x2F); // command(NORMALDISPLAY); // 0xA6
// command(DISPLAYALLONRESUME); // 0xA4
command(SETDISPLAYOFFSET); // 0xD3
command(0x0); // no offset
command(SETSTARTLINE | 0x0); // line #0
command(CHARGEPUMP); // enable charge pump
command(0x14);
command(NORMALDISPLAY); // 0xA6
command(DISPLAYALLONRESUME); // 0xA4
command(SEGREMAP | 0x1); command(SEGREMAP | 0x1);
command(COMSCANDEC); command(COMSCANDEC);
// command(SETCOMPINS, 0x12); // 0xDA
command(SETCONTRAST, 0x8F); // 0x81
command(SETPRECHARGE, 0xF1); // 0xD9
command(SETVCOMDESELECT, 0x40); // 0xDB
command(DISPLAYON); //--turn on oled panel
command(SETCOMPINS); // 0xDA clear(ALL); // Erase hardware memory inside the OLED controller to avoid random data in memory.
command(0x12);
command(SETCONTRAST); // 0x81
command(0x8F);
command(SETPRECHARGE); // 0xd9
command(0xF1);
command(SETVCOMDESELECT); // 0xDB
command(0x40);
command(DISPLAYON); //--turn on oled panel
clear(ALL); // Erase hardware memory inside the OLED controller to avoid random data in memory.
Serial.begin(115200); Serial.begin(115200);
} }
/** \brief SPI command. /** \brief Power off the OLED display.
Setup DC and SS pins, then send command via SPI to SSD1306 controller. Reset display control signals and
prepare the SSD1306 controller for power off,
then power off the 3.3V regulator.
*/
void MicroView::end() {
DCLOW; // Just in case
command(DISPLAYOFF);
command(CHARGEPUMP, 0x10); // Disable the charge pump
delay(150); // Wait for charge pump off
RESETLOW;
SSLOW;
MVSPI.end(); // Disable SPI mode
digitalWrite(OLEDPWR, LOW); // Power off the 3.3V regulator
}
/** \brief Send 1 command byte.
Send 1 command byte via SPI to SSD1306 controller.
*/ */
void MicroView::command(uint8_t c) { void MicroView::command(uint8_t c) {
// Hardware SPI MVSPI.packetBegin();
*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); MVSPI.transfer(c);
MVSPI.packetEnd();
}
*ssport |= sspinmask; // SS HIGH /** \brief Send 2 command bytes.
*ssreg &= ~sspinmask; // Set SS pin to INPUT
Send 2 command bytes via SPI to SSD1306 controller.
*dcreg &= ~dcpinmask; // Set DC to INPUT to avoid high voltage over driving the OLED logic */
void MicroView::command(uint8_t c1, uint8_t c2) {
MVSPI.packetBegin();
MVSPI.transfer(c1);
MVSPI.wait();
MVSPI.transfer(c2);
MVSPI.packetEnd();
}
/** \brief Send 3 command bytes.
Send 3 command bytes via SPI to SSD1306 controller.
*/
void MicroView::command(uint8_t c1, uint8_t c2, uint8_t c3) {
MVSPI.packetBegin();
MVSPI.transfer(c1);
MVSPI.wait();
MVSPI.transfer(c2);
MVSPI.wait();
MVSPI.transfer(c3);
MVSPI.packetEnd();
} }
/** \brief SPI data. /** \brief SPI data.
Setup DC and SS pins, then send data via SPI to SSD1306 controller. Send 1 data byte via SPI to SSD1306 controller.
*/ */
void MicroView::data(uint8_t c) { void MicroView::data(uint8_t c) {
// Hardware SPI MVSPI.packetBegin();
*dcport |= dcpinmask; // DC HIGH DCHIGH;
*ssreg |= sspinmask; // Set SS pin to OUTPUT
*ssport &= ~sspinmask; // SS LOW
MVSPI.transfer(c); MVSPI.transfer(c);
MVSPI.packetEnd();
*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
} }
/** \brief Set SSD1306 page address. /** \brief Set SSD1306 page address.
@@ -243,8 +240,7 @@ void MicroView::data(uint8_t c) {
Send page address command and address to the SSD1306 OLED controller. Send page address command and address to the SSD1306 OLED controller.
*/ */
void MicroView::setPageAddress(uint8_t add) { void MicroView::setPageAddress(uint8_t add) {
add=0xb0|add; command(SETPAGE|add);
command(add);
return; return;
} }
@@ -253,8 +249,7 @@ void MicroView::setPageAddress(uint8_t add) {
Send column address command and address to the SSD1306 OLED controller. Send column address command and address to the SSD1306 OLED controller.
*/ */
void MicroView::setColumnAddress(uint8_t add) { void MicroView::setColumnAddress(uint8_t add) {
command((0x10|(add>>4))+0x02); command((SETHIGHCOLUMN|(add>>4))+0x02, SETLOWCOLUMN|(0x0f&add));
command((0x0f&add));
return; return;
} }
@@ -263,19 +258,25 @@ void MicroView::setColumnAddress(uint8_t add) {
To clear GDRAM inside the LCD controller, pass in the variable mode = ALL and to clear screen page buffer pass in the variable mode = PAGE. To clear GDRAM inside the LCD controller, pass in the variable mode = ALL and to clear screen page buffer pass in the variable mode = PAGE.
*/ */
void MicroView::clear(uint8_t mode) { void MicroView::clear(uint8_t mode) {
// uint8_t page=6, col=0x40;
if (mode==ALL) { if (mode==ALL) {
for (int i=0;i<8; i++) { command(SETADDRESSMODE, 0); // Set horizontal addressing mode
setPageAddress(i); command(SETCOLUMNBOUNDS, 0, LCDTOTALWIDTH - 1); // Set width
setColumnAddress(0); command(SETPAGEBOUNDS, 0, LCDTOTALPAGES - 1); // Set height
for (int j=0; j<0x80; j++) {
data(0); MVSPI.packetBegin();
} DCHIGH;
MVSPI.transfer(0);
for (int i = 1; i < LCDTOTALWIDTH * LCDTOTALPAGES; i++) {
MVSPI.wait();
MVSPI.transfer(0);
} }
MVSPI.packetEnd();
command(SETADDRESSMODE, 2); // Return display to page addressing mode
} }
else else
{ {
memset(screenmemory,0,384); // (64 x 48) / 8 = 384 memset(screenmemory, 0, LCDWIDTH * LCDPAGES);
//display(); //display();
} }
} }
@@ -285,19 +286,25 @@ void MicroView::clear(uint8_t mode) {
To clear GDRAM inside the LCD controller, pass in the variable mode = ALL with c character and to clear screen page buffer, pass in the variable mode = PAGE with c character. To clear GDRAM inside the LCD controller, pass in the variable mode = ALL with c character and to clear screen page buffer, pass in the variable mode = PAGE with c character.
*/ */
void MicroView::clear(uint8_t mode, uint8_t c) { void MicroView::clear(uint8_t mode, uint8_t c) {
//uint8_t page=6, col=0x40;
if (mode==ALL) { if (mode==ALL) {
for (int i=0;i<8; i++) { command(SETADDRESSMODE, 0); // Set horizontal addressing mode
setPageAddress(i); command(SETCOLUMNBOUNDS, 0, LCDTOTALWIDTH - 1); // Set width
setColumnAddress(0); command(SETPAGEBOUNDS, 0, LCDTOTALPAGES - 1); // Set height
for (int j=0; j<0x80; j++) {
data(c); MVSPI.packetBegin();
} DCHIGH;
MVSPI.transfer(c);
for (int i = 1; i < LCDTOTALWIDTH * LCDTOTALPAGES; i++) {
MVSPI.wait();
MVSPI.transfer(c);
} }
MVSPI.packetEnd();
command(SETADDRESSMODE, 2); // Return display to page addressing mode
} }
else else
{ {
memset(screenmemory,c,384); // (64 x 48) / 8 = 384 memset(screenmemory, c, LCDWIDTH * LCDPAGES);
display(); display();
} }
} }
@@ -315,11 +322,10 @@ void MicroView::invert(boolean inv) {
/** \brief Set contrast. /** \brief Set contrast.
OLED contract value from 0 to 255. Note: Contrast level is not very obvious. OLED contrast value from 0 to 255. Note: Contrast level is not very obvious.
*/ */
void MicroView::contrast(uint8_t contrast) { void MicroView::contrast(uint8_t contrast) {
command(SETCONTRAST); // 0x81 command(SETCONTRAST, contrast); // 0x81
command(contrast);
} }
/** \brief Transfer display memory. /** \brief Transfer display memory.
@@ -327,15 +333,22 @@ void MicroView::contrast(uint8_t contrast) {
Bulk move the screen buffer to the SSD1306 controller's memory so that images/graphics drawn on the screen buffer will be displayed on the OLED. Bulk move the screen buffer to the SSD1306 controller's memory so that images/graphics drawn on the screen buffer will be displayed on the OLED.
*/ */
void MicroView::display(void) { void MicroView::display(void) {
uint8_t i, j; command(SETADDRESSMODE, 0); // Set horizontal addressing mode
command(SETCOLUMNBOUNDS,
for (i=0; i<6; i++) { LCDCOLUMNOFFSET,
setPageAddress(i); LCDCOLUMNOFFSET + LCDWIDTH - 1); // Set width
setColumnAddress(0); command(SETPAGEBOUNDS, 0, LCDPAGES - 1); // Set height
for (j=0;j<0x40;j++) {
data(screenmemory[i*0x40+j]); MVSPI.packetBegin();
} DCHIGH;
MVSPI.transfer(screenmemory[0]);
for (int i = 1; i < LCDWIDTH * LCDPAGES; i++) {
MVSPI.wait();
MVSPI.transfer(screenmemory[i]);
} }
MVSPI.packetEnd();
command(SETADDRESSMODE, 2); // Restore to page addressing mode
} }
//#if ARDUINO >= 100 //#if ARDUINO >= 100
@@ -847,14 +860,9 @@ size_t MicroView::write(uint8_t c) {
if (stop<start) // stop must be larger or equal to start if (stop<start) // stop must be larger or equal to start
return; return;
scrollStop(); // need to disable scrolling before starting to avoid memory corrupt scrollStop(); // need to disable scrolling before starting to avoid memory corrupt
command(RIGHTHORIZONTALSCROLL); command(RIGHTHORIZONTALSCROLL, 0);
command(0x00); command(start, 0x7, stop); // scroll speed frames , TODO
command(start); command(0x00, 0xFF, ACTIVATESCROLL);
command(0x7); // scroll speed frames , TODO
command(stop);
command(0x00);
command(0xFF);
command(ACTIVATESCROLL);
} }
/** \brief Vertical flip. /** \brief Vertical flip.
@@ -955,7 +963,7 @@ size_t MicroView::write(uint8_t c) {
Serial.println(serCmd[2]); Serial.println(serCmd[2]);
pixel(serCmd[1],serCmd[2]); pixel(serCmd[1],serCmd[2]);
display(); display();
} else if (cmdCount=4) { } else if (cmdCount==4) {
Serial.print("pixel "); Serial.print("pixel ");
Serial.print(serCmd[1]); Serial.print(serCmd[1]);
Serial.print(" "); Serial.print(" ");
@@ -1269,7 +1277,7 @@ size_t MicroView::write(uint8_t c) {
temp=atoi(result); temp=atoi(result);
serCmd[index]=(uint8_t)temp & 0xff; // we only need 8 bit number serCmd[index]=(uint8_t)temp & 0xff; // we only need 8 bit number
index++; index++;
for (uint8_t i;i<recvLEN;i++) { for (uint8_t i=0;i<recvLEN;i++) {
result=strtok(NULL,","); result=strtok(NULL,",");
if (result != NULL) { if (result != NULL) {
@@ -1554,10 +1562,10 @@ size_t MicroView::write(uint8_t c) {
/** \brief Draw widget face. /** \brief Draw widget face.
Draw image/diagram represengint the widget's face. Draw image/diagram representing the widget's face.
*/ */
void MicroViewGauge::drawFace() { void MicroViewGauge::drawFace() {
uint8_t offsetX, offsetY, majorLine; uint8_t offsetX, offsetY;
float degreeSec, fromSecX, fromSecY, toSecX, toSecY; float degreeSec, fromSecX, fromSecY, toSecX, toSecY;
offsetX=getX(); offsetX=getX();
offsetY=getY(); offsetY=getY();
@@ -1591,8 +1599,7 @@ size_t MicroView::write(uint8_t c) {
*/ */
void MicroViewGauge::draw() { void MicroViewGauge::draw() {
uint8_t offsetX, offsetY; uint8_t offsetX, offsetY;
uint8_t tickPosition=0; float degreeSec, toSecX, toSecY;
float degreeSec, fromSecX, fromSecY, toSecX, toSecY;
char strBuffer[5]; char strBuffer[5];
offsetX=getX(); offsetX=getX();
@@ -1640,39 +1647,69 @@ size_t MicroView::write(uint8_t c) {
/** \brief SPI Initialisation. /** \brief SPI Initialisation.
Setup SCK, MOSI pins for SPI transmission. Setup SCK, MOSI, SS and DC pins for SPI transmission.
*/ */
void MVSPIClass::begin() { void MVSPIClass::begin() {
// Set SS to high so a connected chip will be "deselected" by default // Set SS to high so the display will be "deselected" by default
digitalWrite(SS, HIGH); SSHIGH;
// When the SS pin is set as OUTPUT, it can be used as
// a general purpose output port (it doesn't influence
// SPI operations).
pinMode(SS, OUTPUT);
// Warning: if the SS pin ever becomes a LOW INPUT then SPI // Warning: if the SS pin ever becomes a LOW INPUT then SPI
// automatically switches to Slave, so the data direction of // automatically switches to Slave.
// the SS pin MUST be kept as OUTPUT. // This should not occur with the MicroView as nothing can drive the pin.
SPCR |= _BV(MSTR);
SPCR |= _BV(SPE);
// Set direction register for SCK and MOSI pin. // Set DC low for command mode, where it should always default to unless
// MISO pin automatically overrides to INPUT. // data is being transmitted.
// By doing this AFTER enabling SPI, we avoid accidentally DCLOW;
// clocking in a single bit since the lines go directly
// from "input" to SPI control. // Set SCK and MOSI to be outputs and low when SPI is disabled.
// http://code.google.com/p/arduino/issues/detail?id=888 digitalWrite(SCK, LOW);
digitalWrite(MOSI, LOW);
pinMode(SCK, OUTPUT); pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT); pinMode(MOSI, OUTPUT);
// Set SPI master mode. Don't enable SPI at this time.
SPCR |= _BV(MSTR);
} }
/** \brief End SPI. */ /** \brief End SPI. */
void MVSPIClass::end() { void MVSPIClass::end() {
SPCR &= ~_BV(SPE); SPCR &= ~_BV(SPE);
// SCK and MOSI should already be low but set them again, to be sure.
digitalWrite(SCK, LOW);
digitalWrite(MOSI, LOW);
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
} }
/** \brief Set SPI bit order. /** \brief Set up SPI for transmitting
Pepare the SPI interface for transmitting on or more bytes of
commands and/or data.
*/
void MVSPIClass::packetBegin() {
// Enable SPI mode
SPCR |= _BV(SPE);
// Set SS low
SSLOW;
}
/** \brief End a SPI packet transmission
End a SPI packet transmission:
- Wait for the last byte to finish being transmitted.
- Set DC to command mode (even if already set that way, just in case).
- Set SS high.
- Disable SPI mode (causing SCK and MOSI to go low).
*/
void MVSPIClass::packetEnd() {
while (!(SPSR & _BV(SPIF)))
;
DCLOW;
SSHIGH;
SPCR &= ~_BV(SPE);
}
/** \brief Set SPI bit order.
Set SPI port bit order with LSBFIRST or MSBFIRST. Set SPI port bit order with LSBFIRST or MSBFIRST.
*/ */
@@ -1687,7 +1724,7 @@ size_t MicroView::write(uint8_t c) {
/** \brief Set SPI data mode. /** \brief Set SPI data mode.
Set the SPI daa mode: clock polarity and phase. mode - SPI_MODE0, SPI_MODE1, SPI_MODE2, SPI_MODE3. Set the SPI data mode: clock polarity and phase. mode - SPI_MODE0, SPI_MODE1, SPI_MODE2, SPI_MODE3.
*/ */
void MVSPIClass::setDataMode(uint8_t mode) void MVSPIClass::setDataMode(uint8_t mode)
{ {

View File

@@ -24,13 +24,35 @@
#define swap(a, b) { uint8_t t = a; a = b; b = t; } #define swap(a, b) { uint8_t t = a; a = b; b = t; }
#define DC 8 #define OLEDPWR 4 // 3.3V regulator enable
#define RESET 7
#define OLEDPWR 4
// SS, SCK, MOSI already defined by original pins_arduino.h // Port and bit mappings for DC, RESET, SS
//#define CS 10 // ** These are CPU dependent **
//#define SCK 13 #define DCPORT PORTB
#define DCDDR DDRB
#define DCBIT 0
#define RESETPORT PORTD
#define RESETDDR DDRD
#define RESETBIT 7
#define SSPORT PORTB
#define SSDDR DDRB
#define SSBIT 2
// Macros to quickly set DC, RESET, SS
// A HIGH sets the signal to input mode with the internal pullup enabled
#define DCHIGH ((DCPORT |= _BV(DCBIT)), (DCDDR &= ~_BV(DCBIT)))
#define DCLOW ((DCPORT &= ~_BV(DCBIT)), (DCDDR |= _BV(DCBIT)))
#define RESETHIGH ((RESETPORT |= _BV(RESETBIT)), (RESETDDR &= ~_BV(RESETBIT)))
#define RESETLOW ((RESETPORT &= ~_BV(RESETBIT)), (RESETDDR |= _BV(RESETBIT)))
#define SSHIGH ((SSPORT |= _BV(SSBIT)), (SSDDR &= ~_BV(SSBIT)))
#define SSLOW ((SSPORT &= ~_BV(SSBIT)), (SSDDR |= _BV(SSBIT)))
// SCK, MOSI already defined by original pins_arduino.h
//#define SCK 13
//#define MOSI 11 //#define MOSI 11
#define BLACK 0 #define BLACK 0
@@ -38,6 +60,13 @@
#define LCDWIDTH 64 #define LCDWIDTH 64
#define LCDHEIGHT 48 #define LCDHEIGHT 48
#define LCDPAGES (LCDHEIGHT / 8)
#define LCDCOLUMNOFFSET 32 // Visible start column within SSD1306 controller memory
#define LCDTOTALWIDTH 128 // Full width of SSD1306 controller memory
#define LCDTOTALHEIGHT 64 // Full height of SSD1306 controller memory
#define LCDTOTALPAGES (LCDTOTALHEIGHT / 8)
#define FONTHEADERSIZE 6 #define FONTHEADERSIZE 6
#define NORM 0 #define NORM 0
@@ -65,6 +94,10 @@
#define SETMULTIPLEX 0xA8 #define SETMULTIPLEX 0xA8
#define SETLOWCOLUMN 0x00 #define SETLOWCOLUMN 0x00
#define SETHIGHCOLUMN 0x10 #define SETHIGHCOLUMN 0x10
#define SETPAGE 0xB0
#define SETADDRESSMODE 0x20
#define SETCOLUMNBOUNDS 0x21
#define SETPAGEBOUNDS 0x22
#define SETSTARTLINE 0x40 #define SETSTARTLINE 0x40
#define MEMORYMODE 0x20 #define MEMORYMODE 0x20
#define COMSCANINC 0xC0 #define COMSCANINC 0xC0
@@ -109,6 +142,7 @@ class MicroView : public Print{
public: public:
MicroView(void) {}; MicroView(void) {};
void begin(void); void begin(void);
void end(void);
//#if ARDUINO >= 100 //#if ARDUINO >= 100
@@ -120,6 +154,8 @@ public:
// RAW LCD functions // RAW LCD functions
void command(uint8_t c); void command(uint8_t c);
void command(uint8_t c1, uint8_t c2);
void command(uint8_t c1, uint8_t c2, uint8_t c3);
void data(uint8_t c); void data(uint8_t c);
void setColumnAddress(uint8_t add); void setColumnAddress(uint8_t add);
void setPageAddress(uint8_t add); void setPageAddress(uint8_t add);
@@ -178,10 +214,6 @@ public:
void doCmd(uint8_t index); void doCmd(uint8_t index);
private: private:
//uint8_t cs;
//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; uint8_t foreColor,drawMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY;
uint16_t fontMapWidth; uint16_t fontMapWidth;
//unsigned char *fontsPointer[TOTALFONTS]; //unsigned char *fontsPointer[TOTALFONTS];
@@ -261,8 +293,17 @@ private:
class MVSPIClass { class MVSPIClass {
public: public:
/** \brief Wait for SPI serial transfer complete. */
inline static void wait();
/** \brief Transfer data byte via SPI port. */ /** \brief Transfer data byte via SPI port. */
inline static byte transfer(byte _data); inline static void transfer(byte _data);
/** \brief Set up to begin a SPI packet transmit */
static void packetBegin();
/** \brief End a SPI packet transmit */
static void packetEnd();
// SPI Configuration methods // SPI Configuration methods
@@ -279,11 +320,13 @@ public:
extern MVSPIClass MVSPI; extern MVSPIClass MVSPI;
byte MVSPIClass::transfer(byte _data) { void MVSPIClass::wait() {
SPDR = _data;
while (!(SPSR & _BV(SPIF))) while (!(SPSR & _BV(SPIF)))
; ;
return SPDR; }
void MVSPIClass::transfer(byte _data) {
SPDR = _data;
} }
void MVSPIClass::attachInterrupt() { void MVSPIClass::attachInterrupt() {

View File

@@ -373,7 +373,7 @@ void loop() {
uView.print(6); uView.print(6);
uView.setCursor(0,uView.getLCDHeight() /2-(uView.getFontHeight()/2)); uView.setCursor(0,uView.getLCDHeight() /2-(uView.getFontHeight()/2));
uView.print(9); uView.print(9);
uView.setCursor(uView.getLCDWidth()-uView.getFontWidth(),uView.getLCDWidth()/2-(uView.getFontHeight()/2)); uView.setCursor(uView.getLCDWidth()-uView.getFontWidth(),uView.getLCDHeight()/2-(uView.getFontHeight()/2));
uView.print(3); uView.print(3);
uView.display(); // display the memory buffer drawn uView.display(); // display the memory buffer drawn
@@ -618,4 +618,4 @@ void loop() {
uView.clear(PAGE); uView.clear(PAGE);
} }