Modified to support Wemos mini shiled OLED 64x48

This commit is contained in:
Dirk Jahnke 2018-01-22 13:02:30 +01:00
parent 21dd4f7cde
commit 57308b3a8e
11 changed files with 88 additions and 32 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
lib
build
deps
*.a
*.bak

View File

@ -1 +1,2 @@
# Arduino Adafruit SSD1306 library for Mongoose OS
# Arduino Adafruit SSD1306 library for Mongoose OS and Wemos ESP8266 D1 mini OLED board (64x48)
# Origin: https://github.com/mongoose-os-libs/arduino-adafruit-ssd1306

View File

@ -1,5 +1,5 @@
// Arduino Adafruit_SSD1306 library API. Source C API is defined at:
// [mgos_arduino_ssd1306.h](https://github.com/mongoose-os-libs/arduino-adafruit-ssd1306/blob/master/src/mgos_arduino_ssd1306.h)
// [mgos_arduino_ssd1306dj.h](https://github.com/mongoose-os-libs/arduino-adafruit-ssd1306/blob/master/src/mgos_arduino_ssd1306.h)
let Adafruit_SSD1306 = {
_ci2c: ffi('void *mgos_ssd1306_create_i2c(int, int)'),
@ -44,6 +44,7 @@ let Adafruit_SSD1306 = {
RES_96_16: 0,
RES_128_32: 1,
RES_128_64: 2,
RES_64_48: 3,
EXTERNALVCC: 1,
SWITCHCAPVCC: 2,
@ -212,7 +213,7 @@ let Adafruit_SSD1306 = {
// Initialize Adafruit_SSD1306 library for I2C.
// Return value: handle opaque pointer.
// We set the reset pin and
// Resolution: 0 - RES_96_16, 1 - RES_128_32, 2 - RES_128_64.
// Resolution: 0 - RES_96_16, 1 - RES_128_32, 2 - RES_128_64, 3 - RES_64_48.
obj.ssd = Adafruit_SSD1306._ci2c(rst, res);
return obj;
},
@ -223,7 +224,7 @@ let Adafruit_SSD1306 = {
// Initialize Adafruit_SSD1306 library for SPI.
// Return value: handle opaque pointer.
// We set DataCommand, ChipSelect, Reset and
// Resolution: 0 - RES_96_16, 1 - RES_128_32, 2 - RES_128_64.
// Resolution: 0 - RES_96_16, 1 - RES_128_32, 2 - RES_128_6, 3 - RES_64_484.
obj.ssd = Adafruit_SSD1306._cspi(dc, rst, cs, res);
return obj;
},

View File

@ -1,5 +1,5 @@
author: mongoose-os
description: Arduino Adafruit SSD1306 library
author: Dirk Jahnke
description: Arduino Adafruit SSD1306 library modified for Wemos OLED 64x48
type: lib
version: 1.0
@ -16,5 +16,3 @@ tags:
- c
- js
- hw
skeleton_version: 2017-05-18

View File

@ -33,9 +33,35 @@ All text above, and the splash screen below must be included in any redistributi
#include <Wire.h>
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"
#include "Adafruit_SSD1306dj.h"
static const uint8_t logo_buffer[] = {
#if defined SSD1306_64_48
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, 0xC0,
0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0, 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, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8,
0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xFC, 0xFF, 0xFF,
0xFF, 0xFF, 0x7F, 0x3F, 0x7F, 0xFF, 0xFF, 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, 0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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
#else
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,
@ -102,6 +128,7 @@ static const uint8_t logo_buffer[] = {
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
#endif
};
#define ssd1306_swap(a, b) { int16_t t = a; a = b; b = t; }
@ -114,6 +141,8 @@ int Adafruit_SSD1306::getW(Adafruit_SSD1306::Resolution res) {
return 128;
case RES_96_16:
return 96;
case RES_64_48:
return 64;
}
return 0;
}
@ -127,6 +156,8 @@ int Adafruit_SSD1306::getH(Adafruit_SSD1306::Resolution res) {
return 64;
case RES_96_16:
return 16;
case RES_64_48:
return 48;
}
return 0;
}
@ -301,6 +332,12 @@ void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) {
else
{ ssd1306_command(0xAF); }
break;
case RES_64_48:
ssd1306_command(SSD1306_SETCOMPINS); // 0xDA
ssd1306_command(0x12);
ssd1306_command(SSD1306_SETCONTRAST); // 0x81
ssd1306_command(0xCF);
}
ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9
@ -448,9 +485,15 @@ void Adafruit_SSD1306::dim(boolean dim) {
}
void Adafruit_SSD1306::display(void) {
ssd1306_command(SSD1306_COLUMNADDR);
ssd1306_command(0); // Column start address (0 = reset)
ssd1306_command(WIDTH-1); // Column end address (127 = reset)
if (WIDTH == 64 && HEIGHT == 48) {
ssd1306_command(SSD1306_COLUMNADDR);
ssd1306_command(0x20); // Column start address (0 = reset)
ssd1306_command(0x20 + WIDTH-1); // Column end address (127 = reset)
} else {
ssd1306_command(SSD1306_COLUMNADDR);
ssd1306_command(0); // Column start address (0 = reset)
ssd1306_command(WIDTH-1); // Column end address (127 = reset)
}
ssd1306_command(SSD1306_PAGEADDR);
ssd1306_command(0); // Page start address (0 = reset)
@ -458,6 +501,9 @@ void Adafruit_SSD1306::display(void) {
case 64:
ssd1306_command(7); // Page end address
break;
case 48:
ssd1306_command(5); // Page end address
break;
case 32:
ssd1306_command(3); // Page end address
break;

View File

@ -1,4 +1,5 @@
/*********************************************************************
DJ: Added RES_64_48
This is a library for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
@ -15,8 +16,8 @@ Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#ifndef _Adafruit_SSD1306_H_
#define _Adafruit_SSD1306_H_
#ifndef _Adafruit_SSD1306dj_H_
#define _Adafruit_SSD1306dj_H_
#if ARDUINO >= 100
#include "Arduino.h"
@ -71,14 +72,15 @@ All text above, and the splash screen must be included in any redistribution
-----------------------------------------------------------------------*/
// #define SSD1306_128_64
#define SSD1306_128_32
#define SSD1306_64_48
// #define SSD1306_128_32
// #define SSD1306_96_16
/*=========================================================================*/
#if defined SSD1306_128_64 && defined SSD1306_128_32
#error "Only one SSD1306 display can be specified at once in SSD1306.h"
#endif
#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16
#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16 && !defined SSD1306_64_48
#error "At least one SSD1306 display must be specified in SSD1306.h"
#endif
@ -88,6 +90,8 @@ All text above, and the splash screen must be included in any redistribution
#define SSD1306_DEFAULT_RES Adafruit_SSD1306::RES_128_32
#elif defined SSD1306_96_16
#define SSD1306_DEFAULT_RES Adafruit_SSD1306::RES_96_16
#elif defined SSD1306_64_48
#define SSD1306_DEFAULT_RES Adafruit_SSD1306::RES_64_48
#endif
#define SSD1306_SETCONTRAST 0x81
@ -138,7 +142,7 @@ All text above, and the splash screen must be included in any redistribution
class Adafruit_SSD1306 : public Adafruit_GFX {
public:
enum Resolution { RES_96_16, RES_128_32, RES_128_64 };
enum Resolution { RES_96_16, RES_128_32, RES_128_64, RES_64_48 };
Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, Resolution res = SSD1306_DEFAULT_RES);
Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS, Resolution res = SSD1306_DEFAULT_RES);
@ -186,4 +190,4 @@ class Adafruit_SSD1306 : public Adafruit_GFX {
};
#endif /* _Adafruit_SSD1306_H_ */
#endif /* _Adafruit_SSD1306dj_H_ */

View File

@ -1,9 +1,9 @@
name=Adafruit SSD1306
name=Adafruit SSD1306dj
version=1.1.2
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=SSD1306 oled driver library for 'monochrome' 128x64 and 128x32 OLEDs!
paragraph=SSD1306 oled driver library for 'monochrome' 128x64 and 128x32 OLEDs!
author=Adafruit / Dirk Jahnke (mods 64x48)
maintainer=Dirk Jahnke <dirk.jahnke@mailbox.org>
sentence=SSD1306 oled driver library for 'monochrome' 128x64 and 128x32 and 64x48 OLEDs!
paragraph=SSD1306 oled driver library for 'monochrome' 128x64 and 128x32 and 64x48 OLEDs!
category=Display
url=https://github.com/adafruit/Adafruit_SSD1306
architectures=*

View File

@ -1,5 +0,0 @@
#include <stdbool.h>
bool mgos_arduino_adafruit_ssd1306_init(void) {
return true;
}

View File

@ -5,7 +5,7 @@
* Arduino Adafruit_SSD1306 library API wrapper
*/
#include "mgos_arduino_ssd1306.h"
#include "mgos_ssd1306dj.h"
static Adafruit_SSD1306::Resolution mgos_ssd1306_get_res(int res) {
Adafruit_SSD1306::Resolution r;
@ -13,6 +13,7 @@ static Adafruit_SSD1306::Resolution mgos_ssd1306_get_res(int res) {
case 0: r = Adafruit_SSD1306::RES_96_16; break;
case 1: r = Adafruit_SSD1306::RES_128_32; break;
case 2: r = Adafruit_SSD1306::RES_128_64; break;
case 3: r = Adafruit_SSD1306::RES_64_48; break;
default: r = SSD1306_DEFAULT_RES;
}
return r;

View File

@ -8,7 +8,7 @@
#ifndef CS_MOS_LIBS_ARDUINO_ADAFRUIT_SSD1306_SRC_MGOS_ARDUINO_SSD1306_H_
#define CS_MOS_LIBS_ARDUINO_ADAFRUIT_SSD1306_SRC_MGOS_ARDUINO_SSD1306_H_
#include "Adafruit_SSD1306.h"
#include "Adafruit_SSD1306dj.h"
#ifdef __cplusplus
extern "C" {
@ -17,12 +17,12 @@ extern "C" {
// Initialize Adafruit_SSD1306 library for I2C.
// Return value: handle opaque pointer.
// We set the reset pin and
// Resolution: 0 - RES_96_16, 1 - RES_128_32, 2 - RES_128_64.
// Resolution: 0 - RES_96_16, 1 - RES_128_32, 2 - RES_128_64, 3 - RES_64_48.
Adafruit_SSD1306 *mgos_ssd1306_create_i2c(int rst, int res);
// Initialize Adafruit_SSD1306 library for SPI.
// Return value: handle opaque pointer.
// We set DataCommand, ChipSelect, Reset and
// Resolution: 0 - RES_96_16, 1 - RES_128_32, 2 - RES_128_64.
// Resolution: 0 - RES_96_16, 1 - RES_128_32, 2 - RES_128_64, 3 - RES_64_48.
Adafruit_SSD1306 *mgos_ssd1306_create_spi(int dc, int rst, int cs, int res);
// Close Adafruit_SSD1306 handle. Return value: none.
void mgos_ssd1306_close(Adafruit_SSD1306 *ssd);

5
src/mgos_ssd1306dj_c.c Normal file
View File

@ -0,0 +1,5 @@
#include <stdbool.h>
bool mgos_ssd1306dj_init(void) {
return true;
}