Display_Lib_RPI 2.3.0
A C++ Library to connect electronic displays to Linux single board computers.
Loading...
Searching...
No Matches
ERM1_CH1115_OLED_RDL.hpp
Go to the documentation of this file.
1
9#pragma once
10
11// ** INCLUDES **
12#include <lgpio.h>
13#include <cstdio>
14#include <cstdint>
15#include <cstdbool>
16#include <cstring>
18
19
20// CLASS SECTION
21
24
25 private:
26
27 /* CH1115 Command Set*/
28 // Fundamental Commands
29 static constexpr uint8_t ERMCH1115_ENTIRE_DISPLAY_ON = 0xA4;
30 static constexpr uint8_t ERMCH1115_ENTIRE_DISPLAY_OFF = 0xA5;
31 static constexpr uint8_t ERMCH1115_DISPLAY_ON = 0xAF;
32 static constexpr uint8_t ERMCH1115_DISPLAY_OFF = 0xAE;
33 static constexpr uint8_t ERMCH1115_DISPLAY_NORMAL = 0xA6;
34 static constexpr uint8_t ERMCH1115_DISPLAY_INVERT = 0xA7;
35 static constexpr uint8_t ERMCH1115_CONTRAST_CONTROL = 0x81;
36 static constexpr uint8_t ERMCH1115_CONTRAST_DATA_DEFAULT = 0x80;
38 // Addressing Setting Commands
39 static constexpr uint8_t ERMCH1115_SET_PAGEADD = 0xB0;
40 static constexpr uint8_t ERMCH1115_SET_COLADD_LSB = 0x00;
41 static constexpr uint8_t ERMCH1115_SET_COLADD_MSB = 0x10;
42 static constexpr uint8_t ERMCH1115_SET_DISPLAY_START_LINE = 0x40;
44 // Hardware Configuration Commands
45 static constexpr uint8_t ERMCH1115_SET_PUMP_REG = 0x30;
46 static constexpr uint8_t ERMCH1115_SET_PUMP_SET = 0x01;
47 static constexpr uint8_t ERMCH1115_IREF_REG = 0x82;
48 static constexpr uint8_t ERMCH1115_IREF_SET = 0x00;
49 static constexpr uint8_t ERMCH1115_SEG_SET_REMAP = 0xA0;
50 static constexpr uint8_t ERMCH1115_SEG_SET_PADS = 0xA2;
51 static constexpr uint8_t ERMCH1115_MULTIPLEX_MODE_SET = 0xA8;
52 static constexpr uint8_t ERMCH1115_MULTIPLEX_DATA_SET = 0x3F;
53 static constexpr uint8_t ERMCH1115_DC_MODE_SET = 0xAD;
54 static constexpr uint8_t ERMCH1115_DC_ONOFF_SET = 0x8B;
55 static constexpr uint8_t ERMCH1115_COMMON_SCAN_DIR = 0xC0;
56 static constexpr uint8_t ERMCH1115_OFFSET_MODE_SET = 0xD3;
57 static constexpr uint8_t ERMCH1115_OFFSET_DATA_SET = 0x00;
58 static constexpr uint8_t ERMCH1115_BREATHEFFECT_SET = 0x23;
59 static constexpr uint8_t ERMCH1115_BREATHEFFECT_DATA = 0x81;
61 // Timing & Driving Scheme Setting Commands
62 static constexpr uint8_t ERMCH1115_OSC_FREQ_MODE_SET = 0xD5;
63 static constexpr uint8_t ERMCH1115_OSC_FREQ_DATA_SET = 0xA0;
64 static constexpr uint8_t ERMCH1115_PRECHARGE_MODE_SET = 0xD9;
65 static constexpr uint8_t ERMCH1115_PRECHARGE_DATA_SET = 0x22;
66 static constexpr uint8_t ERMCH1115_COM_LEVEL_MODE_SET = 0xDB;
67 static constexpr uint8_t ERMCH1115_COM_LEVEL_DATA_SET = 0x40;
69 // HORIZONTAL Scrolling Commands
70 static constexpr uint8_t ERMCH1115_HORIZONTAL_A_SCROLL_SETUP = 0x24;
71 static constexpr uint8_t ERMCH1115_HORIZONTAL_A_SCROLL_SET_SCOL = 0x00;
72 static constexpr uint8_t ERMCH1115_HORIZONTAL_A_SCROLL_SET_ECOL = 0x7F;
73 static constexpr uint8_t ERMCH1115_SCROLL_SETUP = 0x26;
74 static constexpr uint8_t ERMCH1115_SPAGE_ADR_SET = 0x00;
75 static constexpr uint8_t ERMCH1115_TIME_SET = 0x00;
76 static constexpr uint8_t ERMCH1115_EPAGE_ADR_SET = 0x07;
77 static constexpr uint8_t ERMCH1115_SET_SCROLL_MODE = 0x28;
78 static constexpr uint8_t ERMCH1115_DEACTIVATE_SCROLL = 0x2E;
79 static constexpr uint8_t ERMCH1115_ACTIVATE_SCROLL = 0x2F;
81 // Delays
84 {
85 static constexpr uint16_t INITDELAY = 100;
86 static constexpr uint16_t RST_DELAY1 = 10;
87 static constexpr uint16_t RST_DELAY2 = 100;
88 };
89
90 // GPIO related
91 int8_t _Display_CS;
92 int8_t _Display_DC;
93 int8_t _Display_RST;
97 int _GpioHandle = 0;
99 // SPI related
100 int _spiHandle = 0;
101 int _spiDev = 0;
102 int _spiChan = 0;
103 int _spiBaud = 50000;
104 int _spiFlags = 0;
105 uint16_t _OLEDHighFreqDelay = 0;
106 int8_t _OLED_mode = 2;
108 // Display
109 uint8_t _OLED_WIDTH = 128;
110 uint8_t _OLED_HEIGHT = 64;
112 std::span<uint8_t> _OLEDbuffer;
113 bool _sleep = true;
116 // methods
117 void send_data(uint8_t data);
118 void send_command(uint8_t command, uint8_t value);
119 int8_t GetCommMode(void);
120 void SoftwareSPIShiftOut(uint8_t val);
121
122 protected:
123
124 public:
125
126 // Contructor 1 Software SPI with explicit SCLK and SDIN and DC/cd
127 ERMCH1115(int16_t oledwidth, int16_t oledheight , int8_t rst, int8_t dc, int8_t cs, int8_t sclk, int8_t din);
128 // Constructor 2 Hardware SPI
129 ERMCH1115(int16_t oledwidth, int16_t oledheight , int8_t rst, int8_t dc);
130 ~ERMCH1115(){};
131
132 virtual void drawPixel(int16_t x, int16_t y, uint8_t colour) override;
133
134 rdlib::Return_Codes_e OLEDSetBufferPtr(uint8_t width, uint8_t height , std::span<uint8_t> buffer);
137 void OLEDBufferScreen(int16_t x, int16_t y, uint8_t w, uint8_t h, std::span<uint8_t> data);
138
139 void OLEDFillScreen(uint8_t pixel);
140 void OLEDFillPage(uint8_t page_num, uint8_t pixels);
141 void OLEDBitmap(int16_t x, int16_t y, uint8_t w, uint8_t h, const std::span<const uint8_t> data);
142
143 rdlib::Return_Codes_e OLEDbegin(uint8_t contrast, int gpioDev);
144 rdlib::Return_Codes_e OLEDbegin(uint8_t contrast, int device, int channel, int speed, int flags, int gpioDev );
145 void OLEDinit(void);
146 void OLEDReset(void);
147
148 void OLEDEnable(uint8_t on);
149 void OLEDInvert(uint8_t on);
150 void OLEDFlip(uint8_t on);
151 void OLEDContrast(uint8_t contrast = ERMCH1115_CONTRAST_DATA_DEFAULT);
152 void OLEDscroll(uint8_t bits) ;
153 void OLEDscrollSetup(uint8_t Timeinterval= ERMCH1115_TIME_SET, uint8_t Direction=ERMCH1115_SCROLL_SETUP, uint8_t mode=ERMCH1115_SET_SCROLL_MODE) ;
154 void OLEDfadeEffect(uint8_t bits = ERMCH1115_BREATHEFFECT_DATA);
155 bool OLEDIsSleeping(void);
156
158 void OLEDPowerDown(void);
159 uint16_t OLEDHighFreqDelayGet(void);
160 void OLEDHighFreqDelaySet(uint16_t);
161
162}; // end of class
163
164
165
Graphics based functions for bicolor display.
class to drive the ERMCh1115 OLED
Definition ERM1_CH1115_OLED_RDL.hpp:23
static constexpr uint8_t ERMCH1115_PRECHARGE_DATA_SET
Definition ERM1_CH1115_OLED_RDL.hpp:65
static constexpr uint8_t ERMCH1115_ENTIRE_DISPLAY_OFF
Definition ERM1_CH1115_OLED_RDL.hpp:30
int _spiFlags
Definition ERM1_CH1115_OLED_RDL.hpp:104
void OLEDscrollSetup(uint8_t Timeinterval=ERMCH1115_TIME_SET, uint8_t Direction=ERMCH1115_SCROLL_SETUP, uint8_t mode=ERMCH1115_SET_SCROLL_MODE)
Sets up Horizontal Scroll.
Definition ERM1_CH1115_OLED_RDL.cpp:458
static constexpr uint8_t ERMCH1115_PRECHARGE_MODE_SET
Definition ERM1_CH1115_OLED_RDL.hpp:64
static constexpr uint8_t ERMCH1115_ACTIVATE_SCROLL
Definition ERM1_CH1115_OLED_RDL.hpp:79
static constexpr uint8_t ERMCH1115_DC_MODE_SET
Definition ERM1_CH1115_OLED_RDL.hpp:53
void SoftwareSPIShiftOut(uint8_t val)
used in software SPI mode to shift out data
Definition ERM1_CH1115_OLED_RDL.cpp:322
int _spiBaud
Definition ERM1_CH1115_OLED_RDL.hpp:103
static constexpr uint8_t ERMCH1115_TIME_SET
Definition ERM1_CH1115_OLED_RDL.hpp:75
bool _sleep
Definition ERM1_CH1115_OLED_RDL.hpp:113
void OLEDinit(void)
Called from OLEDbegin carries out Power on sequence and register init.
Definition ERM1_CH1115_OLED_RDL.cpp:340
static constexpr uint8_t ERMCH1115_SEG_SET_REMAP
Definition ERM1_CH1115_OLED_RDL.hpp:49
static constexpr uint8_t ERMCH1115_OSC_FREQ_DATA_SET
Definition ERM1_CH1115_OLED_RDL.hpp:63
int8_t _Display_RST
Definition ERM1_CH1115_OLED_RDL.hpp:93
uint16_t _OLEDHighFreqDelay
Definition ERM1_CH1115_OLED_RDL.hpp:105
static constexpr uint8_t ERMCH1115_COM_LEVEL_MODE_SET
Definition ERM1_CH1115_OLED_RDL.hpp:66
rdlib::Return_Codes_e OLEDupdate(void)
updates the OLED i.e. writes buffer to the screen
Definition ERM1_CH1115_OLED_RDL.cpp:674
int _spiDev
Definition ERM1_CH1115_OLED_RDL.hpp:101
static constexpr uint8_t ERMCH1115_SET_DISPLAY_START_LINE
Definition ERM1_CH1115_OLED_RDL.hpp:42
static constexpr uint8_t ERMCH1115_CONTRAST_CONTROL
Definition ERM1_CH1115_OLED_RDL.hpp:35
static constexpr uint8_t ERMCH1115_IREF_REG
Definition ERM1_CH1115_OLED_RDL.hpp:47
static constexpr uint8_t ERMCH1115_SET_COLADD_LSB
Definition ERM1_CH1115_OLED_RDL.hpp:40
static constexpr uint8_t ERMCH1115_SPAGE_ADR_SET
Definition ERM1_CH1115_OLED_RDL.hpp:74
void OLEDFillPage(uint8_t page_num, uint8_t pixels)
Fill the chosen page(0-7) with a datapattern.
Definition ERM1_CH1115_OLED_RDL.cpp:576
static constexpr uint8_t ERMCH1115_SET_PAGEADD
Definition ERM1_CH1115_OLED_RDL.hpp:39
uint16_t OLEDHighFreqDelayGet(void)
Freq delay used in SW SPI getter, uS delay used in SW SPI method.
Definition ERM1_CH1115_OLED_RDL.cpp:791
std::span< uint8_t > _OLEDbuffer
Definition ERM1_CH1115_OLED_RDL.hpp:112
static constexpr uint8_t ERMCH1115_SET_COLADD_MSB
Definition ERM1_CH1115_OLED_RDL.hpp:41
static constexpr uint8_t ERMCH1115_COM_LEVEL_DATA_SET
Definition ERM1_CH1115_OLED_RDL.hpp:67
void OLEDHighFreqDelaySet(uint16_t)
Freq delay used in SW SPI setter, uS delay used in SW SPI method.
Definition ERM1_CH1115_OLED_RDL.cpp:797
static constexpr uint8_t ERMCH1115_HORIZONTAL_A_SCROLL_SETUP
Definition ERM1_CH1115_OLED_RDL.hpp:70
void OLEDfadeEffect(uint8_t bits=ERMCH1115_BREATHEFFECT_DATA)
Turns on fade effect.
Definition ERM1_CH1115_OLED_RDL.cpp:532
static constexpr uint8_t ERMCH1115_DISPLAY_ON
Definition ERM1_CH1115_OLED_RDL.hpp:31
static constexpr uint8_t ERMCH1115_OFFSET_DATA_SET
Definition ERM1_CH1115_OLED_RDL.hpp:57
static constexpr uint8_t ERMCH1115_BREATHEFFECT_SET
Definition ERM1_CH1115_OLED_RDL.hpp:58
uint8_t _OLED_PAGE_NUM
Definition ERM1_CH1115_OLED_RDL.hpp:111
void OLEDscroll(uint8_t bits)
Turns on Horizontal scroll.
Definition ERM1_CH1115_OLED_RDL.cpp:481
static constexpr uint8_t ERMCH1115_OFFSET_MODE_SET
Definition ERM1_CH1115_OLED_RDL.hpp:56
int8_t _Display_DC
Definition ERM1_CH1115_OLED_RDL.hpp:92
int _GpioHandle
Definition ERM1_CH1115_OLED_RDL.hpp:97
static constexpr uint8_t ERMCH1115_HORIZONTAL_A_SCROLL_SET_ECOL
Definition ERM1_CH1115_OLED_RDL.hpp:72
int8_t _Display_SCLK
Definition ERM1_CH1115_OLED_RDL.hpp:94
int _spiHandle
Definition ERM1_CH1115_OLED_RDL.hpp:100
void OLEDEnable(uint8_t on)
Turns On Display.
Definition ERM1_CH1115_OLED_RDL.cpp:427
static constexpr uint8_t ERMCH1115_COMMON_SCAN_DIR
Definition ERM1_CH1115_OLED_RDL.hpp:55
static constexpr uint8_t ERMCH1115_CONTRAST_DATA_DEFAULT
Definition ERM1_CH1115_OLED_RDL.hpp:36
static constexpr uint8_t ERMCH1115_DISPLAY_NORMAL
Definition ERM1_CH1115_OLED_RDL.hpp:33
void OLEDBufferScreen(int16_t x, int16_t y, uint8_t w, uint8_t h, std::span< uint8_t > data)
Draw a bitmap to the screen.
Definition ERM1_CH1115_OLED_RDL.cpp:716
bool OLEDIsSleeping(void)
getting for _sleep member . is OLED in sleep mode
Definition ERM1_CH1115_OLED_RDL.cpp:450
static constexpr uint8_t ERMCH1115_HORIZONTAL_A_SCROLL_SET_SCOL
Definition ERM1_CH1115_OLED_RDL.hpp:71
int8_t _Display_CS
Definition ERM1_CH1115_OLED_RDL.hpp:91
static constexpr uint8_t ERMCH1115_SET_SCROLL_MODE
Definition ERM1_CH1115_OLED_RDL.hpp:77
static constexpr uint8_t ERMCH1115_SET_PUMP_REG
Definition ERM1_CH1115_OLED_RDL.hpp:45
uint8_t _OLEDcontrast
Definition ERM1_CH1115_OLED_RDL.hpp:114
static constexpr uint8_t ERMCH1115_DISPLAY_OFF
Definition ERM1_CH1115_OLED_RDL.hpp:32
static constexpr uint8_t ERMCH1115_DC_ONOFF_SET
Definition ERM1_CH1115_OLED_RDL.hpp:54
int8_t _OLED_mode
Definition ERM1_CH1115_OLED_RDL.hpp:106
void OLEDReset(void)
Resets OLED in a four wire setup called at start.
Definition ERM1_CH1115_OLED_RDL.cpp:413
static constexpr uint8_t ERMCH1115_DEACTIVATE_SCROLL
Definition ERM1_CH1115_OLED_RDL.hpp:78
static constexpr uint8_t ERMCH1115_EPAGE_ADR_SET
Definition ERM1_CH1115_OLED_RDL.hpp:76
static constexpr uint8_t ERMCH1115_SEG_SET_PADS
Definition ERM1_CH1115_OLED_RDL.hpp:50
void send_data(uint8_t data)
Send data byte with SPI to ERMCH1115.
Definition ERM1_CH1115_OLED_RDL.cpp:649
uint8_t _OLED_WIDTH
Definition ERM1_CH1115_OLED_RDL.hpp:109
static constexpr uint8_t ERMCH1115_MULTIPLEX_DATA_SET
Definition ERM1_CH1115_OLED_RDL.hpp:52
static constexpr uint8_t ERMCH1115_SET_PUMP_SET
Definition ERM1_CH1115_OLED_RDL.hpp:46
void OLEDInvert(uint8_t on)
invert the display
Definition ERM1_CH1115_OLED_RDL.cpp:548
rdlib::Return_Codes_e OLEDbegin(uint8_t contrast, int gpioDev)
begin Method initialise OLED for software SPI
Definition ERM1_CH1115_OLED_RDL.cpp:131
void OLEDFillScreen(uint8_t pixel)
Fill the screen NOT the buffer with a datapattern.
Definition ERM1_CH1115_OLED_RDL.cpp:563
void OLEDPowerDown(void)
Power down function.
Definition ERM1_CH1115_OLED_RDL.cpp:296
uint8_t _OLED_HEIGHT
Definition ERM1_CH1115_OLED_RDL.hpp:110
void OLEDBitmap(int16_t x, int16_t y, uint8_t w, uint8_t h, const std::span< const uint8_t > data)
Draw a bitmap to the screen.
Definition ERM1_CH1115_OLED_RDL.cpp:617
virtual void drawPixel(int16_t x, int16_t y, uint8_t colour) override
Draws a Pixel to the screen , overides the graphics library.
Definition ERM1_CH1115_OLED_RDL.cpp:754
static constexpr uint8_t ERMCH1115_DISPLAY_INVERT
Definition ERM1_CH1115_OLED_RDL.hpp:34
int _DeviceNumGpioChip
Definition ERM1_CH1115_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 ERM1_CH1115_OLED_RDL.cpp:192
void OLEDContrast(uint8_t contrast=ERMCH1115_CONTRAST_DATA_DEFAULT)
Adjusts contrast.
Definition ERM1_CH1115_OLED_RDL.cpp:496
rdlib::Return_Codes_e OLEDSPIoff(void)
stops HW spi operations
Definition ERM1_CH1115_OLED_RDL.cpp:218
void OLEDFlip(uint8_t on)
Rotates the display vertically, A 180 degree 'flip'.
Definition ERM1_CH1115_OLED_RDL.cpp:511
void send_command(uint8_t command, uint8_t value)
Sends a command to the display.
Definition ERM1_CH1115_OLED_RDL.cpp:403
int8_t _Display_SDATA
Definition ERM1_CH1115_OLED_RDL.hpp:95
rdlib::Return_Codes_e OLEDclearBuffer(void)
clears the buffer memory i.e. does NOT write to the screen
Definition ERM1_CH1115_OLED_RDL.cpp:695
static constexpr uint8_t ERMCH1115_IREF_SET
Definition ERM1_CH1115_OLED_RDL.hpp:48
static constexpr uint8_t ERMCH1115_MULTIPLEX_MODE_SET
Definition ERM1_CH1115_OLED_RDL.hpp:51
int8_t GetCommMode(void)
Checks if software SPI is on.
Definition ERM1_CH1115_OLED_RDL.cpp:314
static constexpr uint8_t ERMCH1115_OSC_FREQ_MODE_SET
Definition ERM1_CH1115_OLED_RDL.hpp:62
int _spiChan
Definition ERM1_CH1115_OLED_RDL.hpp:102
static constexpr uint8_t ERMCH1115_BREATHEFFECT_DATA
Definition ERM1_CH1115_OLED_RDL.hpp:59
static constexpr uint8_t ERMCH1115_SCROLL_SETUP
Definition ERM1_CH1115_OLED_RDL.hpp:73
static constexpr uint8_t ERMCH1115_ENTIRE_DISPLAY_ON
Definition ERM1_CH1115_OLED_RDL.hpp:29
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:560
int16_t height(void) const
Gets the height of the display (per current _rotation)
Definition bicolor_graphics_RDL.cpp:566
Return_Codes_e
Definition common_data_RDL.hpp:22
Struct to hold delay values used in driver.
Definition ERM1_CH1115_OLED_RDL.hpp:84
static constexpr uint16_t RST_DELAY1
Definition ERM1_CH1115_OLED_RDL.hpp:86
static constexpr uint16_t INITDELAY
Definition ERM1_CH1115_OLED_RDL.hpp:85
static constexpr uint16_t RST_DELAY2
Definition ERM1_CH1115_OLED_RDL.hpp:87