Display_Lib_RPI 2.6.0
A C++ Library to connect electronic displays to Linux single board computers.
Loading...
Searching...
No Matches
SSD1306_OLED_RDL.hpp
Go to the documentation of this file.
1
9#pragma once
10
11// Library includes
12
13#include <cstdio>
14#include <cstdint>
15#include <cstdbool>
16#include <lgpio.h>
18
19
24 public:
26 ~SSD1306_RDL(){};
27
29 enum class OLED_Controller_e {
30 SSD1306,
31 SSD1315
32 };
33
34 virtual void drawPixel(int16_t x, int16_t y, uint8_t color) override;
35
39 void OLEDBufferScreen(int16_t x, int16_t y, uint8_t w, uint8_t h, std::span<uint8_t> data);
40
43
45 void OLEDinit(void);
46 void OLEDPowerDown(void);
47
48 void OLEDEnable(uint8_t on);
50 void OLEDInvert(bool on);
51
56 void OLEDStopScroll(void) ;
57
60 int OLEDCheckConnection(void);
61 int OLEDI2CErrorGet(void);
66
67 static constexpr uint8_t SSD1306_ADDR = 0x3C;
68 static constexpr uint8_t SSD1315_ADDR = 0x3C;
70 private:
71
73 // === SSD1306 Command Set ===
74 // Fundamental Commands
75 static constexpr uint8_t SSD1306_SET_CONTRAST_CONTROL = 0x81;
76 static constexpr uint8_t SSD1306_DISPLAY_ALL_ON_RESUME = 0xA4;
77 static constexpr uint8_t SSD1306_DISPLAY_ALL_ON = 0xA5;
78 static constexpr uint8_t SSD1306_NORMAL_DISPLAY = 0xA6;
79 static constexpr uint8_t SSD1306_INVERT_DISPLAY = 0xA7;
80 static constexpr uint8_t SSD1306_DISPLAY_OFF = 0xAE;
81 static constexpr uint8_t SSD1306_DISPLAY_ON = 0xAF;
82 static constexpr uint8_t SSD1306_NOP = 0xE3;
84 // Scrolling Commands
85 static constexpr uint8_t SSD1306_RIGHT_HORIZONTAL_SCROLL = 0x26;
86 static constexpr uint8_t SSD1306_LEFT_HORIZONTAL_SCROLL = 0x27;
89 static constexpr uint8_t SSD1306_DEACTIVATE_SCROLL = 0x2E;
90 static constexpr uint8_t SSD1306_ACTIVATE_SCROLL = 0x2F;
91 static constexpr uint8_t SSD1306_SET_VERTICAL_SCROLL_AREA = 0xA3;
94 // Addressing Setting Commands
95 static constexpr uint8_t SSD1306_SET_LOWER_COLUMN = 0x00;
96 static constexpr uint8_t SSD1306_SET_HIGHER_COLUMN = 0x10;
97 static constexpr uint8_t SSD1306_MEMORY_ADDR_MODE = 0x20;
98 static constexpr uint8_t SSD1306_SET_COLUMN_ADDR = 0x21;
99 static constexpr uint8_t SSD1306_SET_PAGE_ADDR = 0x22;
101 // Hardware Configuration Commands
102 static constexpr uint8_t SSD1306_SET_START_LINE = 0x40;
103 static constexpr uint8_t SSD1306_SET_SEGMENT_REMAP = 0xA0;
104 static constexpr uint8_t SSD1306_SET_MULTIPLEX_RATIO = 0xA8;
105 static constexpr uint8_t SSD1306_COM_SCAN_DIR_INC = 0xC0;
106 static constexpr uint8_t SSD1306_COM_SCAN_DIR_DEC = 0xC8;
107 static constexpr uint8_t SSD1306_SET_DISPLAY_OFFSET = 0xD3;
108 static constexpr uint8_t SSD1306_SET_COM_PINS = 0xDA;
109 static constexpr uint8_t SSD1306_CHARGE_PUMP = 0x8D;
111 // Timing & Driving Scheme Setting Commands
113 static constexpr uint8_t SSD1306_SET_PRECHARGE_PERIOD = 0xD9;
114 static constexpr uint8_t SSD1306_SET_VCOM_DESELECT = 0xDB;
116 // I2C related
117 static constexpr uint8_t SSD1306_COMMAND = 0x00;
118 static constexpr uint8_t SSD1306_DATA = 0xC0;
119 static constexpr uint8_t SSD1306_DATA_CONTINUE = 0x40;
120 // === SSD1306 Command Set END ===
121
122 // I2C
135 std::span<uint8_t> _OLEDbuffer;
139};
Graphics based functions for bicolor display.
static constexpr int defaultFormat()
Called from vector & string template , Get the default format for a given type.
Definition print_data_RDL.hpp:206
class to control OLED and define buffer
Definition SSD1306_OLED_RDL.hpp:23
OLED_Controller_e
Enum to control controller type.
Definition SSD1306_OLED_RDL.hpp:29
int OLEDCheckConnection(void)
checks if OLED on I2C bus
Definition SSD1306_OLED_RDL.cpp:529
static constexpr uint8_t SSD1306_INVERT_DISPLAY
Definition SSD1306_OLED_RDL.hpp:79
OLED_Controller_e _eController
Definition SSD1306_OLED_RDL.hpp:136
static constexpr uint8_t SSD1306_SET_DISPLAY_CLOCK_DIV_RATIO
Definition SSD1306_OLED_RDL.hpp:112
static constexpr uint8_t SSD1306_DISPLAY_ALL_ON
Definition SSD1306_OLED_RDL.hpp:77
static constexpr uint8_t SSD1306_DATA
Definition SSD1306_OLED_RDL.hpp:118
static constexpr uint8_t SSD1306_SET_START_LINE
Definition SSD1306_OLED_RDL.hpp:102
static constexpr uint8_t SSD1306_DISPLAY_ALL_ON_RESUME
Definition SSD1306_OLED_RDL.hpp:76
static constexpr uint8_t SSD1306_NOP
Definition SSD1306_OLED_RDL.hpp:82
rdlib::Return_Codes_e OLEDupdate(void)
updates the buffer i.e. writes it to the screen
Definition SSD1306_OLED_RDL.cpp:283
uint8_t OLEDI2CErrorRetryNumGet(void)
Gets the I2C error retry attempts, used in the event of an I2C write error.
Definition SSD1306_OLED_RDL.cpp:512
static constexpr uint8_t SSD1306_SET_DISPLAY_OFFSET
Definition SSD1306_OLED_RDL.hpp:107
static constexpr uint8_t SSD1306_SET_COLUMN_ADDR
Definition SSD1306_OLED_RDL.hpp:98
uint8_t _OLED_PAGE_NUM
Definition SSD1306_OLED_RDL.hpp:133
static constexpr uint8_t SSD1306_COM_SCAN_DIR_DEC
Definition SSD1306_OLED_RDL.hpp:106
static constexpr uint8_t SSD1306_MEMORY_ADDR_MODE
Definition SSD1306_OLED_RDL.hpp:97
static constexpr uint8_t SSD1306_SET_SEGMENT_REMAP
Definition SSD1306_OLED_RDL.hpp:103
static constexpr uint8_t SSD1306_SET_HIGHER_COLUMN
Definition SSD1306_OLED_RDL.hpp:96
rdlib::Return_Codes_e OLEDSetBufferPtr(uint8_t width, uint8_t height, std::span< uint8_t > buffer)
sets the buffer pointer to the users screen data buffer
Definition SSD1306_OLED_RDL.cpp:43
uint8_t _OLED_HEIGHT
Definition SSD1306_OLED_RDL.hpp:132
void OLEDFillScreen(uint8_t pixel, uint8_t mircodelay)
Fill the screen NOT the buffer with a datapattern.
Definition SSD1306_OLED_RDL.cpp:212
static constexpr uint8_t SSD1306_CHARGE_PUMP
Definition SSD1306_OLED_RDL.hpp:109
virtual void drawPixel(int16_t x, int16_t y, uint8_t color) override
Draws a Pixel to the screen overrides the graphics lib.
Definition SSD1306_OLED_RDL.cpp:365
void OLEDbegin(OLED_Controller_e controller=OLED_Controller_e::SSD1306)
begin Method, initialise OLED
Definition SSD1306_OLED_RDL.cpp:27
int _OLEDI2CHandle
Definition SSD1306_OLED_RDL.hpp:126
static constexpr uint8_t SSD1315_ADDR
Definition SSD1306_OLED_RDL.hpp:68
static constexpr uint8_t SSD1306_SET_LOWER_COLUMN
Definition SSD1306_OLED_RDL.hpp:95
std::span< uint8_t > _OLEDbuffer
Definition SSD1306_OLED_RDL.hpp:135
rdlib::Return_Codes_e OLED_I2C_ON(int I2C_device, int I2C_addr, int I2C_flags)
Start I2C operations.
Definition SSD1306_OLED_RDL.cpp:68
static constexpr uint8_t SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL
Definition SSD1306_OLED_RDL.hpp:87
void OLEDStartScrollLeft(uint8_t start, uint8_t stop)
Scroll OLED data to the left.
Definition SSD1306_OLED_RDL.cpp:421
rdlib::Return_Codes_e OLEDclearBuffer(void)
clears the buffer memory i.e. does NOT write to the screen
Definition SSD1306_OLED_RDL.cpp:304
static constexpr uint8_t SSD1306_COMMAND
Definition SSD1306_OLED_RDL.hpp:117
int _OLEDI2CFlags
Definition SSD1306_OLED_RDL.hpp:125
void OLEDEnable(uint8_t on)
Turns On Display.
Definition SSD1306_OLED_RDL.cpp:183
static constexpr uint8_t SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL
Definition SSD1306_OLED_RDL.hpp:88
void OLEDPowerDown(void)
Disables OLED Call when powering down.
Definition SSD1306_OLED_RDL.cpp:111
void OLEDStartScrollDiagLeft(uint8_t start, uint8_t stop)
Scroll OLED data diagonally to the left.
Definition SSD1306_OLED_RDL.cpp:459
static constexpr uint8_t SSD1306_COM_SCAN_DIR_INC
Definition SSD1306_OLED_RDL.hpp:105
int _I2C_ErrorFlag
Definition SSD1306_OLED_RDL.hpp:129
static constexpr uint8_t SSD1306_SET_MULTIPLEX_RATIO
Definition SSD1306_OLED_RDL.hpp:104
void OLEDInvert(bool on)
invert the display
Definition SSD1306_OLED_RDL.cpp:202
int _OLEDI2CAddress
Definition SSD1306_OLED_RDL.hpp:123
uint8_t _OLED_WIDTH
Definition SSD1306_OLED_RDL.hpp:131
static constexpr uint8_t SSD1306_ACTIVATE_SCROLL
Definition SSD1306_OLED_RDL.hpp:90
static constexpr uint8_t SSD1306_SET_COM_PINS
Definition SSD1306_OLED_RDL.hpp:108
void OLEDI2CErrorTimeoutSet(uint16_t)
Sets the I2C timeout, in the event of an I2C write error.
Definition SSD1306_OLED_RDL.cpp:495
void OLEDStartScrollDiagRight(uint8_t start, uint8_t stop)
Scroll OLED data diagonally to the right.
Definition SSD1306_OLED_RDL.cpp:439
static constexpr uint8_t SSD1306_DISPLAY_OFF
Definition SSD1306_OLED_RDL.hpp:80
static constexpr uint8_t SSD1306_DEACTIVATE_SCROLL
Definition SSD1306_OLED_RDL.hpp:89
static constexpr uint8_t SSD1306_ADDR
Definition SSD1306_OLED_RDL.hpp:67
uint16_t _I2C_ErrorDelay
Definition SSD1306_OLED_RDL.hpp:127
int _OLEDI2CDevice
Definition SSD1306_OLED_RDL.hpp:124
static constexpr uint8_t SSD1306_NORMAL_DISPLAY
Definition SSD1306_OLED_RDL.hpp:78
static constexpr uint8_t SSD1306_DATA_CONTINUE
Definition SSD1306_OLED_RDL.hpp:119
static constexpr uint8_t SSD1306_RIGHT_HORIZONTAL_SCROLL
Definition SSD1306_OLED_RDL.hpp:85
static constexpr uint8_t SSD1306_SET_VERTICAL_SCROLL_AREA
Definition SSD1306_OLED_RDL.hpp:91
uint16_t OLEDI2CErrorTimeoutGet(void)
Gets the I2C timeout, used in the event of an I2C write error.
Definition SSD1306_OLED_RDL.cpp:505
rdlib::Return_Codes_e OLED_I2C_OFF(void)
End I2C operations. This closes the I2C device.
Definition SSD1306_OLED_RDL.cpp:96
void OLEDStartScrollRight(uint8_t start, uint8_t stop)
Scroll OLED data to the right.
Definition SSD1306_OLED_RDL.cpp:403
static constexpr uint8_t SSD1306_DISPLAY_ON
Definition SSD1306_OLED_RDL.hpp:81
void OLEDinit(void)
Called from OLEDbegin carries out Power on sequence and register init.
Definition SSD1306_OLED_RDL.cpp:120
void OLEDFillPage(uint8_t page_num, uint8_t pixels, uint8_t delay)
Fill the chosen page(1-8) with a datapattern.
Definition SSD1306_OLED_RDL.cpp:233
static constexpr uint8_t SSD1306_SET_PAGE_ADDR
Definition SSD1306_OLED_RDL.hpp:99
void OLEDContrast(uint8_t OLEDcontrast)
Adjusts contrast.
Definition SSD1306_OLED_RDL.cpp:192
void OLEDI2CErrorRetryNumSet(uint8_t)
Sets the I2C error retry attempts used in the event of an I2C write error.
Definition SSD1306_OLED_RDL.cpp:519
int OLEDI2CErrorGet(void)
get I2C error Flag
Definition SSD1306_OLED_RDL.cpp:488
static constexpr uint8_t SSD1306_SET_PRECHARGE_PERIOD
Definition SSD1306_OLED_RDL.hpp:113
void OLEDStopScroll(void)
Stop scroll mode.
Definition SSD1306_OLED_RDL.cpp:477
static constexpr uint8_t SSD1306_LEFT_HORIZONTAL_SCROLL
Definition SSD1306_OLED_RDL.hpp:86
static constexpr uint8_t SSD1306_SET_VCOM_DESELECT
Definition SSD1306_OLED_RDL.hpp:114
static constexpr uint8_t SSD1306_SET_CONTRAST_CONTROL
Definition SSD1306_OLED_RDL.hpp:75
uint8_t _I2C_ErrorRetryNum
Definition SSD1306_OLED_RDL.hpp:128
void I2CWriteByte(uint8_t value=0x00, uint8_t DataOrCmd=SSD1306_COMMAND)
Writes a byte to I2C address,command or data, used internally.
Definition SSD1306_OLED_RDL.cpp:253
void OLEDBufferScreen(int16_t x, int16_t y, uint8_t w, uint8_t h, std::span< uint8_t > data)
Draw the buffer directly to the screen.
Definition SSD1306_OLED_RDL.cpp:325
Graphics class to hold graphic related functions for 1-bit displays.
Definition bicolor_graphics_RDL.hpp:21
int16_t width(void) const
Gets the width of the display (per current _rotation)
Definition bicolor_graphics_RDL.cpp:617
int16_t height(void) const
Gets the height of the display (per current _rotation)
Definition bicolor_graphics_RDL.cpp:623
Return_Codes_e
Definition common_data_RDL.hpp:22