-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathHCuOLED.h
210 lines (175 loc) · 6.52 KB
/
HCuOLED.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* FILE: HCuOLED.h
DATE: 14/01/22
VERSION: 0.9
AUTHOR: Andrew Davies
16/04/15 version 0.1: Original version
06/12/16 version 0.2: Added compatibility with ESP8266
Added support for uOLED displays in I2C mode
Added support for WeMos D1 mini OLED shield (see item HCWEMO0007)
Made speed improvement to erase function (thanks to vladyslav-savchenko)
22/05/17 version 0.3: Added support for 128x32 OLED display (see items HCMODU0118 & HCMODU0119)
02/11/18 version 0.4: Fixed issue which cause the integer value of 0 not to be printed.
06/01/19 version 0.5: Change unsigned int to uint16_t in font.h file to fix error when compiling for Wemos boards
18/05/19 version 0.6: Added Brightness() function to allow adjustment of displays brightness level
Removed initialisation code from Reset() and added a new Init() function to allow multiple displays to be reset from the same pin
Added command to pull CS pin high in the Init() function.
24/02/21 version 0.7: Add 2 additonal tiny fonts: sharpsharp_5pt & sharpsharp_6pt thanks to Chris Sharp for creating the fonts.
Also added different font spacing for each font.
22/03/21 version 0.8: Added GetPixel() function to get the current state of a pixel at a specified coordinate.
Updated font description in Fonts.h file from 'const unsigned int' to 'const short unsigned int' to remove compile error when compiling for WeMos D1
11/01/22 version 0.9: Updated Bitmap() and Cursor() functions to allow bitmaps and text to be printed partially off screen
14/01/22 version 1.0: Fixed bug that caused the Flip_H() & Flip_V() functions to not work.
Library header for SSD1307 and SH1106 based OLED displays. In particular this
library has been written for the following displays:
Hobby Components 0.96" uOLED displays (HCMODU0050 & HCMODU0052)
Hobby Components 1.3" uOLED displays (HCMODU0058 & HCMODU0059)
You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/
#ifndef HCuOLED_h
#define HCuOLED_h
#include "SPI.h"
#include <Wire.h>
#include "Arduino.h"
#if !defined (ESP8266)
#include <avr/pgmspace.h>
#endif
extern const PROGMEM byte Terminal_8pt[];
extern const PROGMEM byte MedProp_11pt[];
extern const PROGMEM byte LCDLarge_24pt[];
extern const PROGMEM byte sharpsharp_6pt[];
extern const PROGMEM byte sharpsharp_5pt[];
/* Supported displays */
#define SSD1307 0
#define SSD1306 0
#define SH1106 1
#define WEMOS_D1_MINI_OLED 2
#define SSD1306_128_32 3
/* Display settings */
#define SSD1306_RES_X 128
#define SSD1306_RES_Y 64
#define SSD1306_GRAM_COL_START 0x00
#define SSD1306_GRAM_COL_END 0x7F
#define SSD1306_GRAM_PAGE_START 0
#define SSD1306_GRAM_PAGE_END 7
#define SH1106_RES_X 128
#define SH1106_RES_Y 64
#define SH1106_GRAM_COL_START 0x02
#define SH1106_GRAM_COL_END 0x7F
#define SH1106_GRAM_PAGE_START 0
#define SH1106_GRAM_PAGE_END 7
#define WEMOS_RES_X 64
#define WEMOS_RES_Y 48
#define WEMOS_GRAM_COL_START 0x20
#define WEMOS_GRAM_COL_END 0x5F
#define WEMOS_GRAM_PAGE_START 2
#define WEMOS_GRAM_PAGE_END 7
#define SSD1306_128_32_RES_X 128
#define SSD1306_128_32_RES_Y 32
#define SSD1306_128_32_GRAM_COL_START 0x00
#define SSD1306_128_32_GRAM_COL_END 0x7F
#define SSD1306_128_32_GRAM_PAGE_START 0
#define SSD1306_128_32_GRAM_PAGE_END 7
/* Display resolution */
#define BUFFERCOLSIZE 128
#define BUFFERROWSIZE 8
/* Display command register addresses */
#define COLLOWADD 0x00
#define COLHIGHADD 0x10
#define MEMORYADDRESSMODE 0x20
#define SETCOLADDRESS 0x21
#define SETPAGEADDRESS 0x22
#define SETCONTRAST 0x81
#define CHARGEPUMP 0x8D
#define SETMUXRATIO 0xA8
#define DISPLAYONADD 0xAE
#define PAGEADD 0xB0
#define STARTLINEADD 0x40
#define SCANDIRECTIONADD 0xC0
#define SEGMENTMAPADD 0xA0
/* Command register parameters */
#define SCANDIRNORMAL 0x00
#define SCANDIRREVERSE 0x08
#define SEGMENTMAPNORMAL 0
#define SEGMENTMAPREVERSE 1
#define ENABLECHARGEPUMP 0x14
#define HORIZONTALADDRESSMODE 0x00
/* Hardware interface type */
#define INT_SPI 0
#define INT_I2C 1
/* I2C control byte command / data modes */
#define I2C_COMMAND 0b00000000
#define I2C_DATA 0b01000000
/* Various draw modes */
enum HCuOLEDDrawModes
{
NORMAL = 1,
INVERT = 2,
CLEAR = 3,
OUTLINE = 4,
SOLID = 5
};
class HCuOLED
{
public:
HCuOLED(byte DisplayType, byte SS_DIO, byte DC_DIO, byte RST_DIO);
HCuOLED(byte DisplayType, byte I2C_Add, byte RST_DIO = 0xFF);
void Reset(void);
void Init(void);
void Refresh(void);
static void ClearBuffer(void);
//void ClearDisplayRam(void);
void Flip_H(void);
void Flip_V(void);
void Brightness(uint8_t Level);
static void Bitmap(uint8_t Cols, uint8_t ByteRows, const uint8_t BitmapData[]);
static void Cursor(int X, int Y);
static void Print(char TextString[]);
static void Print(long Value);
static void Print(int long Value, byte DecimalPlaces);
static void Print(float value, byte digits, byte DecimalPlaces);
static void SetFont(const byte *Font);
static void Plot(uint8_t X, uint8_t Y);
static boolean GetPixel(uint8_t X, uint8_t Y);
static void Line(uint8_t X1, uint8_t Y1, uint8_t X2, uint8_t Y2);
static void Rect(uint8_t X1, uint8_t Y1, uint8_t X2, uint8_t Y2, uint8_t FillMode);
static void Erase(uint8_t X1, uint8_t Y1, uint8_t X2, uint8_t Y2);
static void DrawMode(byte DrawMode);
private:
void _CommandMode(void);
void _DisplayMode(void);
static void _WriteChar(char character);
void _Send_Command(byte Data);
byte _SS;
byte _DC;
byte _RST;
byte _I2C_Add;
boolean _Interface;
boolean _V_Ori;
boolean _H_Ori;
static int _XPos;
static int _YPos;
static const byte *_FontType;
static const uint16_t *_FontDescriptor;
static byte _FontHight;
static byte _FontSpacing;
//byte _DisplayRAMColSize;
static byte _DrawMode;
byte _Res_Max_X;
byte _Res_Max_Y;
byte _GRAM_Col_Start;
byte _GRAM_Col_End;
byte _GRAM_Page_Start;
byte _GRAM_Page_End;
byte _RAM_Pages;
byte _DisplayType;
};
#endif