Skip to content

Commit da54c87

Browse files
author
rogerclarkmelbourne
committed
Added Adafruit_SSD1306 and OLED_I2C libs ported by @madias
1 parent e069959 commit da54c87

45 files changed

Lines changed: 6189 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

STM32F1/libraries/Adafruit_SSD1306/Adafruit_SSD1306_STM32.cpp

Lines changed: 777 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*********************************************************************
2+
This is a library for our Monochrome OLEDs based on SSD1306 drivers
3+
4+
Pick one up today in the adafruit shop!
5+
------> http://www.adafruit.com/category/63_98
6+
7+
These displays use SPI to communicate, 4 or 5 pins are required to
8+
interface
9+
10+
Adafruit invests time and resources providing this open source code,
11+
please support Adafruit and open-source hardware by purchasing
12+
products from Adafruit!
13+
14+
Written by Limor Fried/Ladyada for Adafruit Industries.
15+
BSD license, check license.txt for more information
16+
All text above, and the splash screen must be included in any redistribution
17+
*********************************************************************/
18+
19+
#if ARDUINO >= 100
20+
#include "Arduino.h"
21+
#define WIRE_WRITE HWIRE.write
22+
#else
23+
#include "WProgram.h"
24+
#define WIRE_WRITE HWIRE.send
25+
#endif
26+
/*
27+
#ifdef __SAM3X8E__
28+
typedef volatile RwReg PortReg;
29+
typedef uint32_t PortMask;
30+
#else
31+
typedef volatile uint8_t PortReg;
32+
typedef uint8_t PortMask;
33+
#endif
34+
*/
35+
//typedef volatile RwReg PortReg;
36+
// typedef uint32_t PortMask;
37+
#include <SPI.h>
38+
#include <Adafruit_GFX.h>
39+
40+
#define BLACK 0
41+
#define WHITE 1
42+
#define INVERSE 2
43+
44+
#define SSD1306_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x3C or 0x3D
45+
// Address for 128x32 is 0x3C
46+
// Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded)
47+
48+
/*=========================================================================
49+
SSD1306 Displays
50+
-----------------------------------------------------------------------
51+
The driver is used in multiple displays (128x64, 128x32, etc.).
52+
Select the appropriate display below to create an appropriately
53+
sized framebuffer, etc.
54+
55+
SSD1306_128_64 128x64 pixel display
56+
57+
SSD1306_128_32 128x32 pixel display
58+
59+
SSD1306_96_16
60+
61+
-----------------------------------------------------------------------*/
62+
#define SSD1306_128_64
63+
// #define SSD1306_128_32
64+
// #define SSD1306_96_16
65+
/*=========================================================================*/
66+
67+
#if defined SSD1306_128_64 && defined SSD1306_128_32
68+
#error "Only one SSD1306 display can be specified at once in SSD1306.h"
69+
#endif
70+
#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16
71+
#error "At least one SSD1306 display must be specified in SSD1306.h"
72+
#endif
73+
74+
#if defined SSD1306_128_64
75+
#define SSD1306_LCDWIDTH 128
76+
#define SSD1306_LCDHEIGHT 64
77+
#endif
78+
#if defined SSD1306_128_32
79+
#define SSD1306_LCDWIDTH 128
80+
#define SSD1306_LCDHEIGHT 32
81+
#endif
82+
#if defined SSD1306_96_16
83+
#define SSD1306_LCDWIDTH 96
84+
#define SSD1306_LCDHEIGHT 16
85+
#endif
86+
87+
#define SSD1306_SETCONTRAST 0x81
88+
#define SSD1306_DISPLAYALLON_RESUME 0xA4
89+
#define SSD1306_DISPLAYALLON 0xA5
90+
#define SSD1306_NORMALDISPLAY 0xA6
91+
#define SSD1306_INVERTDISPLAY 0xA7
92+
#define SSD1306_DISPLAYOFF 0xAE
93+
#define SSD1306_DISPLAYON 0xAF
94+
95+
#define SSD1306_SETDISPLAYOFFSET 0xD3
96+
#define SSD1306_SETCOMPINS 0xDA
97+
98+
#define SSD1306_SETVCOMDETECT 0xDB
99+
100+
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
101+
#define SSD1306_SETPRECHARGE 0xD9
102+
103+
#define SSD1306_SETMULTIPLEX 0xA8
104+
105+
#define SSD1306_SETLOWCOLUMN 0x00
106+
#define SSD1306_SETHIGHCOLUMN 0x10
107+
108+
#define SSD1306_SETSTARTLINE 0x40
109+
110+
#define SSD1306_MEMORYMODE 0x20
111+
#define SSD1306_COLUMNADDR 0x21
112+
#define SSD1306_PAGEADDR 0x22
113+
114+
#define SSD1306_COMSCANINC 0xC0
115+
#define SSD1306_COMSCANDEC 0xC8
116+
117+
#define SSD1306_SEGREMAP 0xA0
118+
119+
#define SSD1306_CHARGEPUMP 0x8D
120+
121+
#define SSD1306_EXTERNALVCC 0x1
122+
#define SSD1306_SWITCHCAPVCC 0x2
123+
124+
// Scrolling #defines
125+
#define SSD1306_ACTIVATE_SCROLL 0x2F
126+
#define SSD1306_DEACTIVATE_SCROLL 0x2E
127+
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
128+
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
129+
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
130+
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
131+
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
132+
133+
class Adafruit_SSD1306 : public Adafruit_GFX {
134+
public:
135+
Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);
136+
Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS);
137+
Adafruit_SSD1306(int8_t RST);
138+
139+
void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS, bool reset=true);
140+
void ssd1306_command(uint8_t c);
141+
void ssd1306_data(uint8_t c);
142+
143+
void clearDisplay(void);
144+
void invertDisplay(uint8_t i);
145+
void display();
146+
147+
void startscrollright(uint8_t start, uint8_t stop);
148+
void startscrollleft(uint8_t start, uint8_t stop);
149+
150+
void startscrolldiagright(uint8_t start, uint8_t stop);
151+
void startscrolldiagleft(uint8_t start, uint8_t stop);
152+
void stopscroll(void);
153+
154+
void dim(boolean dim);
155+
156+
void drawPixel(int16_t x, int16_t y, uint16_t color);
157+
158+
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
159+
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
160+
161+
private:
162+
int8_t _i2caddr, _vccstate, sid, sclk, dc, rst, cs;
163+
void fastSPIwrite(uint8_t c);
164+
165+
boolean hwSPI;
166+
volatile uint32 *mosiport, *clkport, *csport, *dcport;
167+
uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
168+
169+
inline void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color) __attribute__((always_inline));
170+
inline void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) __attribute__((always_inline));
171+
172+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is a library for our Monochrome OLEDs based on SSD1306 drivers
2+
3+
Pick one up today in the adafruit shop!
4+
------> http://www.adafruit.com/category/63_98
5+
6+
These displays use SPI to communicate, 4 or 5 pins are required to
7+
interface
8+
9+
Adafruit invests time and resources providing this open source code,
10+
please support Adafruit and open-source hardware by purchasing
11+
products from Adafruit!
12+
13+
Written by Limor Fried/Ladyada for Adafruit Industries.
14+
Scrolling code contributed by Michael Gregg
15+
BSD license, check license.txt for more information
16+
All text above must be included in any redistribution
17+
18+
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_SSD1306. Check that the Adafruit_SSD1306 folder contains Adafruit_SSD1306.cpp and Adafruit_SSD1306.h
19+
20+
Place the Adafruit_SSD1306 library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
21+
22+
You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from
23+
https://github.com/adafruit/Adafruit-GFX-Library
24+
and download/install that library as well
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
STM32 adaption by Matthias Diro, 25.03.2015
2+
Things to know:
3+
This adaption uses hardware I2C (hardwire.h), Port: I2c2. SDA=0, SCL=1 on maple mini
4+
To change it to Port I2C1:
5+
//HardWire HWIRE(1,I2C_FAST_MODE); // I2c1
6+
HardWire HWIRE(2,I2C_FAST_MODE); // I2c2

0 commit comments

Comments
 (0)