MatrixMiniR4 1.1.4
Matrix Mini R4 Arduino Library API Documentation
Loading...
Searching...
No Matches
MiniR4OLED.h
Go to the documentation of this file.
1/*
2The MIT License (MIT)
3
4Copyright (c) 2017 Adafruit Industries
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
54#ifndef _Adafruit_SSD1306_H_
55#define _Adafruit_SSD1306_H_
56
57// ONE of the following three lines must be #defined:
58// #define SSD1306_128_64 ///< DEPRECTAED: old way to specify 128x64 screen
59#define SSD1306_128_32
60// #define SSD1306_96_16 ///< DEPRECATED: old way to specify 96x16 screen
61// This establishes the screen dimensions in old Adafruit_SSD1306 sketches
62// (NEW CODE SHOULD IGNORE THIS, USE THE CONSTRUCTORS THAT ACCEPT WIDTH
63// AND HEIGHT ARGUMENTS).
64
65// Uncomment to disable Adafruit splash logo
66// #define SSD1306_NO_SPLASH
67
68#if defined(ARDUINO_STM32_FEATHER)
69typedef class HardwareSPI SPIClass;
70#endif
71
72#include "MiniR4_GFX.h"
73#include <SPI.h>
74#include <Wire.h>
75
76#if defined(__AVR__)
77typedef volatile uint8_t PortReg;
78typedef uint8_t PortMask;
79# define HAVE_PORTREG
80#elif defined(__SAM3X8E__)
81typedef volatile RwReg PortReg;
82typedef uint32_t PortMask;
83# define HAVE_PORTREG
84#elif (defined(__arm__) || defined(ARDUINO_FEATHER52)) && !defined(ARDUINO_ARCH_MBED) && \
85 !defined(ARDUINO_ARCH_RP2040)
86typedef volatile uint32_t PortReg;
87typedef uint32_t PortMask;
88# define HAVE_PORTREG
89#endif
90
95#ifndef NO_ADAFRUIT_SSD1306_COLOR_COMPATIBILITY
96# define BLACK SSD1306_BLACK
97# define WHITE SSD1306_WHITE
98# define INVERSE SSD1306_INVERSE
99#endif
101#define SSD1306_BLACK 0
102#define SSD1306_WHITE 1
103#define SSD1306_INVERSE 2
104
105#define SSD1306_MEMORYMODE 0x20
106#define SSD1306_COLUMNADDR 0x21
107#define SSD1306_PAGEADDR 0x22
108#define SSD1306_SETCONTRAST 0x81
109#define SSD1306_CHARGEPUMP 0x8D
110#define SSD1306_SEGREMAP 0xA0
111#define SSD1306_DISPLAYALLON_RESUME 0xA4
112#define SSD1306_DISPLAYALLON 0xA5
113#define SSD1306_NORMALDISPLAY 0xA6
114#define SSD1306_INVERTDISPLAY 0xA7
115#define SSD1306_SETMULTIPLEX 0xA8
116#define SSD1306_DISPLAYOFF 0xAE
117#define SSD1306_DISPLAYON 0xAF
118#define SSD1306_COMSCANINC 0xC0
119#define SSD1306_COMSCANDEC 0xC8
120#define SSD1306_SETDISPLAYOFFSET 0xD3
121#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
122#define SSD1306_SETPRECHARGE 0xD9
123#define SSD1306_SETCOMPINS 0xDA
124#define SSD1306_SETVCOMDETECT 0xDB
125
126#define SSD1306_SETLOWCOLUMN 0x00
127#define SSD1306_SETHIGHCOLUMN 0x10
128#define SSD1306_SETSTARTLINE 0x40
129
130#define SSD1306_EXTERNALVCC 0x01
131#define SSD1306_SWITCHCAPVCC 0x02
132
133#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
134#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
135#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
136#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
137#define SSD1306_DEACTIVATE_SCROLL 0x2E
138#define SSD1306_ACTIVATE_SCROLL 0x2F
139#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
140
141// Deprecated size stuff for backwards compatibility with old sketches
142#if defined SSD1306_128_64
143# define SSD1306_LCDWIDTH 128
144# define SSD1306_LCDHEIGHT 64
145#endif
146#if defined SSD1306_128_32
147# define SSD1306_LCDWIDTH 128
148# define SSD1306_LCDHEIGHT 32
149#endif
150#if defined SSD1306_96_16
151# define SSD1306_LCDWIDTH 96
152# define SSD1306_LCDHEIGHT 16
153#endif
154
160{
161public:
162 // NEW CONSTRUCTORS -- recommended for new projects
164 uint8_t w, uint8_t h, TwoWire* twi = &Wire, int8_t rst_pin = -1,
165 uint32_t clkDuring = 400000UL, uint32_t clkAfter = 100000UL);
167 uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin,
168 int8_t cs_pin);
170 uint8_t w, uint8_t h, SPIClass* spi, int8_t dc_pin, int8_t rst_pin, int8_t cs_pin,
171 uint32_t bitrate = 8000000UL);
172
173 // DEPRECATED CONSTRUCTORS - for back compatibility, avoid in new projects
175 int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
176 Adafruit_SSD1306(int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
177 Adafruit_SSD1306(int8_t rst_pin = -1);
178
179 ~Adafruit_SSD1306(void);
180
181 bool begin(
182 uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = 0, bool reset = true,
183 bool periphBegin = true);
184 void display(void);
185 void clearDisplay(void);
186 void invertDisplay(bool i);
187 void dim(bool dim);
188 void drawPixel(int16_t x, int16_t y, uint16_t color);
189 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
190 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
191 void startscrollright(uint8_t start, uint8_t stop);
192 void startscrollleft(uint8_t start, uint8_t stop);
193 void startscrolldiagright(uint8_t start, uint8_t stop);
194 void startscrolldiagleft(uint8_t start, uint8_t stop);
195 void stopscroll(void);
196 void ssd1306_command(uint8_t c);
197 bool getPixel(int16_t x, int16_t y);
198 uint8_t* getBuffer(void);
199
200protected:
201 inline void SPIwrite(uint8_t d) __attribute__((always_inline));
202 void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color);
203 void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color);
204 void ssd1306_command1(uint8_t c);
205 void ssd1306_commandList(const uint8_t* c, uint8_t n);
206
207 SPIClass* spi;
209 TwoWire* wire;
211 uint8_t* buffer;
213 int8_t i2caddr;
214 int8_t vccstate;
215 int8_t page_end;
216 int8_t mosiPin;
218 int8_t clkPin;
219 int8_t dcPin;
220 int8_t csPin;
221 int8_t rstPin;
222
223#ifdef HAVE_PORTREG
224 PortReg *mosiPort, *clkPort, *dcPort, *csPort;
225 PortMask mosiPinMask, clkPinMask, dcPinMask, csPinMask;
226#endif
227#if ARDUINO >= 157
228 uint32_t wireClk;
229 uint32_t restoreClk;
230#endif
231 uint8_t contrast;
232#if defined(SPI_HAS_TRANSACTION)
233protected:
234 // Allow sub-class to change
235 SPISettings spiSettings;
236#endif
237};
238
239#endif // _Adafruit_SSD1306_H_
Adafruit SSD1306 dependency code.
@ x
@ y
#define SSD1306_SWITCHCAPVCC
Gen. display voltage from 3.3V.
Definition MiniR4OLED.h:131
A generic graphics superclass that can handle all sorts of drawing. At a.
Definition MiniR4_GFX.h:51
Class that stores state and functions for interacting with SSD1306 OLED displays.
Definition MiniR4OLED.h:160
int8_t i2caddr
I2C address initialized when begin method is called.
Definition MiniR4OLED.h:213
void ssd1306_command1(uint8_t c)
Issue single command to SSD1306, using I2C or hard/soft SPI as needed. Because command calls are ofte...
uint8_t * buffer
Definition MiniR4OLED.h:211
void display(void)
Push data currently in RAM to SSD1306 display.
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Draw a vertical line. This is also invoked by the Adafruit_GFX library in generating many higher-leve...
uint8_t * getBuffer(void)
Get base address of display buffer for direct reading or writing.
void dim(bool dim)
Dim the display.
SPIClass * spi
Definition MiniR4OLED.h:207
int8_t dcPin
(Data Pin) set when using SPI set during construction.
Definition MiniR4OLED.h:219
void invertDisplay(bool i)
Enable or disable display invert mode (white-on-black vs black-on-white).
void startscrollleft(uint8_t start, uint8_t stop)
Activate a left-handed scroll for all or part of the display.
~Adafruit_SSD1306(void)
Destructor for Adafruit_SSD1306 object.
Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi=&Wire, int8_t rst_pin=-1, uint32_t clkDuring=400000UL, uint32_t clkAfter=100000UL)
Constructor for I2C-interfaced SSD1306 displays.
void startscrollright(uint8_t start, uint8_t stop)
Activate a right-handed scroll for all or part of the display.
int8_t rstPin
Display reset pin assignment. Set during construction.
Definition MiniR4OLED.h:221
int8_t csPin
(Chip Select Pin) set when using SPI set during construction.
Definition MiniR4OLED.h:220
void ssd1306_commandList(const uint8_t *c, uint8_t n)
Issue list of commands to SSD1306, same rules as above re: transactions. This is a protected function...
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Draw a horizontal line. This is also invoked by the Adafruit_GFX library in generating many higher-le...
bool getPixel(int16_t x, int16_t y)
Return color of a single pixel in display buffer.
void startscrolldiagleft(uint8_t start, uint8_t stop)
Activate alternate diagonal scroll for all or part of the display.
void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color)
Draw a vertical line with a width and color. Used by public method drawFastHLine,drawFastVLine.
void ssd1306_command(uint8_t c)
Issue a single low-level command directly to the SSD1306 display, bypassing the library.
bool begin(uint8_t switchvcc=SSD1306_SWITCHCAPVCC, uint8_t i2caddr=0, bool reset=true, bool periphBegin=true)
Allocate RAM for image buffer, initialize peripherals and pins.
void stopscroll(void)
Cease a previously-begun scrolling action.
void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color)
Draw a horizontal line with a width and color. Used by public methods drawFastHLine,...
int8_t page_end
not used
Definition MiniR4OLED.h:215
int8_t clkPin
(Clock Pin) set when using SPI set during construction.
Definition MiniR4OLED.h:218
void startscrolldiagright(uint8_t start, uint8_t stop)
Activate a diagonal scroll for all or part of the display.
int8_t vccstate
VCC selection, set by begin method.
Definition MiniR4OLED.h:214
void drawPixel(int16_t x, int16_t y, uint16_t color)
Set/clear/invert a single pixel. This is also invoked by the Adafruit_GFX library in generating many ...
uint8_t contrast
normal contrast setting for this device
Definition MiniR4OLED.h:231
void SPIwrite(uint8_t d) __attribute__((always_inline))
Write a single byte to the SPI port.
void clearDisplay(void)
Clear contents of display buffer (set all pixels to off).