mirror of
https://github.com/adafruit/Adafruit_SSD1306.git
synced 2026-07-27 20:05:50 +00:00
Sweep of various things. ESP32 I2C clock, add getPixel(), etc.
This commit is contained in:
+68
-31
@@ -44,8 +44,10 @@
|
||||
#define WIRE_WRITE wire->send
|
||||
#endif
|
||||
|
||||
#if defined(__AVR__) || defined(ESP32)
|
||||
#if defined(__AVR__)
|
||||
#define WIRECLK 400000L
|
||||
#elif defined(ESP32)
|
||||
#define WIRECLK 800000L
|
||||
#else
|
||||
#define WIRECLK 1000000L
|
||||
#endif
|
||||
@@ -74,52 +76,58 @@
|
||||
#define SPI_TRANSACTION_END SSD1306_DESELECT
|
||||
#endif
|
||||
|
||||
#define TRANSACTION_START \
|
||||
#if ARDUINO >= 157
|
||||
#define TRANSACTION_START \
|
||||
if(wire) wire->setClock(WIRECLK); \
|
||||
else { SPI_TRANSACTION_START }
|
||||
|
||||
#define TRANSACTION_END \
|
||||
#define TRANSACTION_END \
|
||||
if(wire) wire->setClock(restoreClk); \
|
||||
else { SPI_TRANSACTION_END }
|
||||
#else
|
||||
#define TRANSACTION_START if(spi) { SPI_TRANSACTION_START }
|
||||
#define TRANSACTION_END if(spi) { SPI_TRANSACTION_END }
|
||||
#endif
|
||||
|
||||
// CONSTRUCTORS, DESTRUCTOR ------------------------------------------------
|
||||
|
||||
// New constructor for 'soft' SPI
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(uint8_t w, uint8_t h,
|
||||
int8_t MOSI, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS) :
|
||||
Adafruit_GFX(w, h), mosiPin(MOSI), clkPin(SCLK), dcPin(DC),
|
||||
rstPin(RST), csPin(CS), spi(NULL), wire(NULL), buffer(NULL) {
|
||||
int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin,
|
||||
int8_t cs_pin) : Adafruit_GFX(w, h), mosiPin(mosi_pin), clkPin(sclk_pin),
|
||||
dcPin(dc_pin), rstPin(rst_pin), csPin(cs_pin), spi(NULL), wire(NULL),
|
||||
buffer(NULL) {
|
||||
}
|
||||
|
||||
// New constructor for hardware SPI
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(uint8_t w, uint8_t h,
|
||||
SPIClass *spi, int8_t DC, int8_t RST, int8_t CS, uint32_t bitrate) :
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(uint8_t w, uint8_t h, SPIClass *spi,
|
||||
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin, uint32_t bitrate) :
|
||||
Adafruit_GFX(w, h), spi(spi ? spi : &SPI), wire(NULL),
|
||||
mosiPin(-1), clkPin(-1), dcPin(DC), rstPin(RST), csPin(CS), buffer(NULL) {
|
||||
mosiPin(-1), clkPin(-1), dcPin(dc_pin), rstPin(rst_pin), csPin(cs_pin),
|
||||
buffer(NULL) {
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
spiSettings = SPISettings(bitrate, MSBFIRST, SPI_MODE0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// New constructor for I2C
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(
|
||||
uint8_t w, uint8_t h, TwoWire *twi, int8_t RST, uint32_t res) :
|
||||
Adafruit_GFX(w, h), wire(twi ? twi : &Wire), restoreClk(res), spi(NULL),
|
||||
rstPin(RST), mosiPin(-1), clkPin(-1), dcPin(-1), csPin(-1), buffer(NULL) {
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi,
|
||||
int8_t rst_pin, uint32_t res) : Adafruit_GFX(w, h),
|
||||
wire(twi ? twi : &Wire), restoreClk(res), spi(NULL), rstPin(rst_pin),
|
||||
mosiPin(-1), clkPin(-1), dcPin(-1), csPin(-1), buffer(NULL) {
|
||||
}
|
||||
|
||||
// Old constructor for 'soft' SPI (deprecated)
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(
|
||||
int8_t MOSI, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS) :
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(int8_t mosi_pin, int8_t sclk_pin,
|
||||
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin) :
|
||||
Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT),
|
||||
mosiPin(MOSI), clkPin(SCLK), dcPin(DC), rstPin(RST), csPin(CS),
|
||||
spi(NULL), wire(NULL), buffer(NULL) {
|
||||
mosiPin(mosi_pin), clkPin(sclk_pin), dcPin(dc_pin), rstPin(rst_pin),
|
||||
csPin(cs_pin), spi(NULL), wire(NULL), buffer(NULL) {
|
||||
}
|
||||
|
||||
// Old constructor for hardware SPI (deprecated)
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS) :
|
||||
Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT),
|
||||
mosiPin(-1), clkPin(-1), dcPin(DC), rstPin(RST), csPin(CS),
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(int8_t dc_pin, int8_t rst_pin,
|
||||
int8_t cs_pin) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT),
|
||||
mosiPin(-1), clkPin(-1), dcPin(dc_pin), rstPin(rst_pin), csPin(cs_pin),
|
||||
spi(&SPI), wire(NULL), buffer(NULL) {
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
spiSettings = SPISettings(8000000, MSBFIRST, SPI_MODE0);
|
||||
@@ -127,9 +135,9 @@ Adafruit_SSD1306::Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS) :
|
||||
}
|
||||
|
||||
// Old constructor for I2C (deprecated)
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(int8_t RST) :
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(int8_t rst_pin) :
|
||||
Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT),
|
||||
rstPin(RST), mosiPin(-1), clkPin(-1), dcPin(-1), csPin(-1),
|
||||
rstPin(rst_pin), mosiPin(-1), clkPin(-1), dcPin(-1), csPin(-1),
|
||||
spi(NULL), wire(&Wire), buffer(NULL) {
|
||||
}
|
||||
|
||||
@@ -203,7 +211,7 @@ void Adafruit_SSD1306::ssd1306_commandList(const uint8_t *c, uint8_t n) {
|
||||
|
||||
// ALLOCATE & INIT DISPLAY -------------------------------------------------
|
||||
|
||||
bool Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, bool reset) {
|
||||
boolean Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, boolean reset) {
|
||||
|
||||
if((!buffer) && !(buffer = (uint8_t *)malloc(WIDTH * ((HEIGHT + 7) / 8))))
|
||||
return false;
|
||||
@@ -418,7 +426,7 @@ void Adafruit_SSD1306::drawFastHLineInternal(
|
||||
|
||||
void Adafruit_SSD1306::drawFastVLine(
|
||||
int16_t x, int16_t y, int16_t h, uint16_t color) {
|
||||
bool bSwap = false;
|
||||
boolean bSwap = false;
|
||||
switch(rotation) {
|
||||
case 1:
|
||||
// 90 degree rotation, swap x & y for rotation,
|
||||
@@ -530,6 +538,32 @@ void Adafruit_SSD1306::drawFastVLineInternal(
|
||||
} // endif x in bounds
|
||||
}
|
||||
|
||||
boolean Adafruit_SSD1306::getPixel(int16_t x, int16_t y) {
|
||||
if((x >= 0) && (x < width()) && (y >= 0) && (y < height())) {
|
||||
// Pixel is in-bounds. Rotate coordinates if needed.
|
||||
switch(getRotation()) {
|
||||
case 1:
|
||||
ssd1306_swap(x, y);
|
||||
x = WIDTH - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
case 3:
|
||||
ssd1306_swap(x, y);
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
}
|
||||
return (buffer[x + (y / 8) * WIDTH] & (1 << (y & 7)));
|
||||
}
|
||||
return false; // Pixel out of bounds
|
||||
}
|
||||
|
||||
uint8_t *Adafruit_SSD1306::getBuffer(void) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// REFRESH DISPLAY ---------------------------------------------------------
|
||||
|
||||
// Push data currently in RAM to SSD1306 display
|
||||
@@ -544,6 +578,9 @@ void Adafruit_SSD1306::display(void) {
|
||||
ssd1306_commandList(dlist1, sizeof(dlist1));
|
||||
ssd1306_command(WIDTH - 1); // Column end address
|
||||
|
||||
#if defined(ESP8266)
|
||||
yield();
|
||||
#endif
|
||||
uint16_t count = WIDTH * ((HEIGHT + 7) / 8);
|
||||
uint8_t *ptr = buffer;
|
||||
if(wire) { // I2C
|
||||
@@ -573,7 +610,7 @@ void Adafruit_SSD1306::display(void) {
|
||||
// startscrollright
|
||||
// Activate a right handed scroll for rows start through stop
|
||||
// Hint, the display is 16 rows tall. To scroll the whole display, run:
|
||||
// display.scrollright(0x00, 0x0F)
|
||||
// display.startscrollright(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrollright(uint8_t start, uint8_t stop){
|
||||
TRANSACTION_START
|
||||
static const uint8_t PROGMEM scrollList1a[] = {
|
||||
@@ -592,9 +629,9 @@ void Adafruit_SSD1306::startscrollright(uint8_t start, uint8_t stop){
|
||||
}
|
||||
|
||||
// startscrollleft
|
||||
// Activate a right handed scroll for rows start through stop
|
||||
// Activate a left handed scroll for rows start through stop
|
||||
// Hint, the display is 16 rows tall. To scroll the whole display, run:
|
||||
// display.scrollright(0x00, 0x0F)
|
||||
// display.startscrollleft(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrollleft(uint8_t start, uint8_t stop){
|
||||
TRANSACTION_START
|
||||
static const uint8_t PROGMEM scrollList2a[] = {
|
||||
@@ -615,7 +652,7 @@ void Adafruit_SSD1306::startscrollleft(uint8_t start, uint8_t stop){
|
||||
// startscrolldiagright
|
||||
// Activate a diagonal scroll for rows start through stop
|
||||
// Hint, the display is 16 rows tall. To scroll the whole display, run:
|
||||
// display.scrollright(0x00, 0x0F)
|
||||
// display.startscrolldiagright(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrolldiagright(uint8_t start, uint8_t stop){
|
||||
TRANSACTION_START
|
||||
static const uint8_t PROGMEM scrollList3a[] = {
|
||||
@@ -640,7 +677,7 @@ void Adafruit_SSD1306::startscrolldiagright(uint8_t start, uint8_t stop){
|
||||
// startscrolldiagleft
|
||||
// Activate a diagonal scroll for rows start through stop
|
||||
// Hint, the display is 16 rows tall. To scroll the whole display, run:
|
||||
// display.scrollright(0x00, 0x0F)
|
||||
// display.startscrolldiagleft(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrolldiagleft(uint8_t start, uint8_t stop){
|
||||
TRANSACTION_START
|
||||
static const uint8_t PROGMEM scrollList4a[] = {
|
||||
@@ -670,7 +707,7 @@ void Adafruit_SSD1306::stopscroll(void){
|
||||
|
||||
// OTHER HARDWARE SETTINGS -------------------------------------------------
|
||||
|
||||
void Adafruit_SSD1306::invertDisplay(bool i) {
|
||||
void Adafruit_SSD1306::invertDisplay(boolean i) {
|
||||
TRANSACTION_START
|
||||
ssd1306_command(i ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY);
|
||||
TRANSACTION_END
|
||||
|
||||
+17
-11
@@ -104,25 +104,26 @@
|
||||
class Adafruit_SSD1306 : public Adafruit_GFX {
|
||||
public:
|
||||
// NEW CONSTRUCTORS -- recommended for new projects
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h,
|
||||
int8_t MOSI, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin,
|
||||
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h, SPIClass *spi,
|
||||
int8_t DC, int8_t RST, int8_t CS, uint32_t bitrate=8000000UL);
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi=&Wire, int8_t RST=-1,
|
||||
uint32_t res=100000L);
|
||||
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin, uint32_t bitrate=8000000UL);
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi=&Wire,
|
||||
int8_t rst_pin=-1, uint32_t res=100000L);
|
||||
|
||||
// DEPRECATED CONSTRUCTORS - for back compatibility, avoid in new projects
|
||||
Adafruit_SSD1306(int8_t MOSI, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);
|
||||
Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS);
|
||||
Adafruit_SSD1306(int8_t RST = -1);
|
||||
Adafruit_SSD1306(int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin,
|
||||
int8_t rst_pin, int8_t cs_pin);
|
||||
Adafruit_SSD1306(int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
|
||||
Adafruit_SSD1306(int8_t rst_pin = -1);
|
||||
|
||||
~Adafruit_SSD1306(void);
|
||||
|
||||
bool begin(uint8_t switchvcc=SSD1306_SWITCHCAPVCC,
|
||||
uint8_t i2caddr=0, bool reset=true);
|
||||
boolean begin(uint8_t switchvcc=SSD1306_SWITCHCAPVCC,
|
||||
uint8_t i2caddr=0, boolean reset=true);
|
||||
void display(void);
|
||||
void clearDisplay(void);
|
||||
void invertDisplay(bool i);
|
||||
void invertDisplay(boolean i);
|
||||
void dim(boolean dim);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
@@ -134,6 +135,9 @@ class Adafruit_SSD1306 : public Adafruit_GFX {
|
||||
void stopscroll(void);
|
||||
void ssd1306_command(uint8_t c);
|
||||
void ssd1306_commandList(const uint8_t *c, uint8_t n);
|
||||
boolean getPixel(int16_t x, int16_t y);
|
||||
uint8_t *getBuffer(void);
|
||||
|
||||
|
||||
private:
|
||||
inline void SPIwrite(uint8_t d) __attribute__((always_inline));
|
||||
@@ -154,7 +158,9 @@ class Adafruit_SSD1306 : public Adafruit_GFX {
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPISettings spiSettings;
|
||||
#endif
|
||||
#if ARDUINO >= 157
|
||||
uint32_t restoreClk; // Wire speed following SSD1306 transfers
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _Adafruit_SSD1306_H_
|
||||
|
||||
@@ -34,10 +34,10 @@ ESP8266 | X | | | change OLED_RESET to
|
||||
ESP32 | X | | |
|
||||
ATSAM3X8E | X | | |
|
||||
ATSAM21D | X | | |
|
||||
Intel Curie @ 32MHz| X | | |
|
||||
ATtiny85 @ 16MHz | | X | |
|
||||
ATtiny85 @ 8MHz | | X | |
|
||||
WICED | | X | |
|
||||
Intel Curie @ 32MHz| | | X |
|
||||
STM32F2 | | | X |
|
||||
|
||||
* ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name=Adafruit SSD1306
|
||||
version=1.2.3
|
||||
version=1.2.4
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=SSD1306 oled driver library for monochrome 128x64 and 128x32 displays
|
||||
|
||||
Reference in New Issue
Block a user