diff --git a/lcd.c b/lcd.c
index 5919952..766d521 100644
--- a/lcd.c
+++ b/lcd.c
@@ -1,11 +1,11 @@
/*
- * This file is part of lcd library for ssd1306/sh1106 oled-display.
+ * This file is part of lcd library for ssd1306/ssd1309/sh1106 oled-display.
*
- * lcd library for ssd1306/sh1106 oled-display is free software: you can redistribute it and/or modify
+ * lcd library for ssd1306/ssd1309/sh1106 oled-display is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
*
- * lcd library for ssd1306/sh1106 oled-display is distributed in the hope that it will be useful,
+ * lcd library for ssd1306/ssd1309/sh1106 oled-display is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
@@ -13,14 +13,14 @@
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see .
*
- * Diese Datei ist Teil von lcd library for ssd1306/sh1106 oled-display.
+ * Diese Datei ist Teil von lcd library for ssd1306/ssd1309/sh1106 oled-display.
*
- * lcd library for ssd1306/sh1106 oled-display ist Freie Software: Sie können es unter den Bedingungen
+ * lcd library for ssd1306/ssd1309/sh1106 oled-display ist Freie Software: Sie können es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder jeder späteren
* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
*
- * lcd library for ssd1306/sh1106 oled-display wird in der Hoffnung, dass es nützlich sein wird, aber
+ * lcd library for ssd1306/ssd1309/sh1106 oled-display wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
@@ -33,7 +33,7 @@
* Created by Michael Köhler on 22.12.16.
* Copyright 2016 Skie-Systems. All rights reserved.
*
- * lib for OLED-Display with ssd1306/sh1106-Controller
+ * lib for OLED-Display with ssd1306/ssd1309/sh1106-Controller
* first dev-version only for I2C-Connection
* at ATMega328P like Arduino Uno
*
@@ -48,10 +48,15 @@
#include "font.h"
#include
+#if defined SPI
+#include
+#endif
+
static struct {
uint8_t x;
uint8_t y;
} cursorPosition;
+
static uint8_t charMode = NORMALSIZE;
#if defined GRAPHICMODE
#include
@@ -91,25 +96,56 @@ const uint8_t init_sequence [] PROGMEM = { // Initialization Sequence
};
#pragma mark LCD COMMUNICATION
void lcd_command(uint8_t cmd[], uint8_t size) {
+#if defined I2C
i2c_start((LCD_I2C_ADR << 1) | 0);
i2c_byte(0x00); // 0x00 for command, 0x40 for data
for (uint8_t i=0; i> 4 ), 0x7f};
@@ -151,7 +187,6 @@ void lcd_home(void){
lcd_gotoxy(0, 0);
}
void lcd_invert(uint8_t invert){
- i2c_start((LCD_I2C_ADR << 1) | 0);
uint8_t commandSequence[1];
if (invert != YES) {
commandSequence[0] = 0xA6;
@@ -161,7 +196,6 @@ void lcd_invert(uint8_t invert){
lcd_command(commandSequence, 1);
}
void lcd_sleep(uint8_t sleep){
- i2c_start((LCD_I2C_ADR << 1) | 0);
uint8_t commandSequence[1];
if (sleep != YES) {
commandSequence[0] = 0xAF;
@@ -221,6 +255,7 @@ void lcd_putc(char c){
if (charMode == DOUBLESIZE) {
uint16_t doubleChar[sizeof(FONT[0])];
uint8_t dChar;
+ if ((cursorPosition.x+2*sizeof(FONT[0]))>DISPLAY_WIDTH) break;
for (uint8_t i=0; i < sizeof(FONT[0]); i++) {
doubleChar[i] = 0;
@@ -242,6 +277,8 @@ void lcd_putc(char c){
}
cursorPosition.x += sizeof(FONT[0])*2;
} else {
+ if ((cursorPosition.x+sizeof(FONT[0]))>DISPLAY_WIDTH) break;
+
for (uint8_t i = 0; i < sizeof(FONT[0]); i++)
{
// load bit-pattern from flash
@@ -253,6 +290,7 @@ void lcd_putc(char c){
if (charMode == DOUBLESIZE) {
uint16_t doubleChar[sizeof(FONT[0])];
uint8_t dChar;
+ if ((cursorPosition.x+2*sizeof(FONT[0]))>DISPLAY_WIDTH) break;
for (uint8_t i=0; i < sizeof(FONT[0]); i++) {
doubleChar[i] = 0;
@@ -273,7 +311,7 @@ void lcd_putc(char c){
}
lcd_data(data, sizeof(FONT[0])*2);
-#if defined SSD1306
+#if defined (SSD1306) || (SSD1309)
uint8_t commandSequence[] = {0xb0+cursorPosition.y+1,
0x21,
cursorPosition.x,
@@ -296,7 +334,7 @@ void lcd_putc(char c){
lcd_data(data, sizeof(FONT[0])*2);
commandSequence[0] = 0xb0+cursorPosition.y;
-#if defined SSD1306
+#if defined (SSD1306) || (SSD1309)
commandSequence[2] = cursorPosition.x+(2*sizeof(FONT[0]));
#elif defined SH1106
commandSequence[2] = 0x00+((2+cursorPosition.x+(2*sizeof(FONT[0]))) & (0x0f));
@@ -306,6 +344,8 @@ void lcd_putc(char c){
cursorPosition.x += sizeof(FONT[0])*2;
} else {
uint8_t data[sizeof(FONT[0])];
+ if ((cursorPosition.x+sizeof(FONT[0]))>DISPLAY_WIDTH) break;
+
for (uint8_t i = 0; i < sizeof(FONT[0]); i++)
{
// print font to ram, print 6 columns
@@ -438,7 +478,7 @@ void lcd_drawBitmap(uint8_t x, uint8_t y, const uint8_t *picture, uint8_t width,
}
}
void lcd_display() {
-#if defined SSD1306
+#if defined (SSD1306) || (SSD1309)
lcd_gotoxy(0,0);
lcd_data(&displayBuffer[0][0], DISPLAY_WIDTH*DISPLAY_HEIGHT/8);
#elif defined SH1106