| 155 |
Kevin |
1 |
#ifndef OLED_SSD1306_H
|
|
|
2 |
#define OLED_SSD1306_H
|
|
|
3 |
|
|
|
4 |
/*=========================================================================
|
|
|
5 |
SSD1306 Displays
|
|
|
6 |
-----------------------------------------------------------------------
|
|
|
7 |
The driver is used in multiple displays (128x64, 128x32, etc.).
|
|
|
8 |
Select the appropriate display below to create an appropriately
|
|
|
9 |
sized framebuffer, etc.
|
|
|
10 |
|
|
|
11 |
SSD1306_128_64 128x64 pixel display
|
|
|
12 |
|
|
|
13 |
SSD1306_128_32 128x32 pixel display
|
|
|
14 |
|
|
|
15 |
You also need to set the LCDWIDTH and LCDHEIGHT defines to an
|
|
|
16 |
appropriate size
|
|
|
17 |
|
|
|
18 |
-----------------------------------------------------------------------*/
|
|
|
19 |
#define SSD1306_128_64
|
|
|
20 |
// #define SSD1306_128_32
|
|
|
21 |
/*=========================================================================*/
|
|
|
22 |
|
|
|
23 |
#if defined SSD1306_128_64
|
|
|
24 |
#define SSD1306_LCDWIDTH 128
|
|
|
25 |
#define SSD1306_LCDHEIGHT 64
|
|
|
26 |
#endif
|
|
|
27 |
#if defined SSD1306_128_32
|
|
|
28 |
#define SSD1306_LCDWIDTH 128
|
|
|
29 |
#define SSD1306_LCDHEIGHT 32
|
|
|
30 |
#endif
|
|
|
31 |
|
|
|
32 |
//#define SSD1306_STRING_BUFFER_SIZE 32
|
|
|
33 |
|
|
|
34 |
#define SSD1306_BLACK 0
|
|
|
35 |
#define SSD1306_WHITE 1
|
|
|
36 |
|
|
|
37 |
#define SSD1306_I2C_ADDRESS 0x3D // 011110+SA0+RW
|
|
|
38 |
|
|
|
39 |
#define SSD1306_SETCONTRAST 0x81
|
|
|
40 |
#define SSD1306_DISPLAYALLON_RESUME 0xA4
|
|
|
41 |
#define SSD1306_DISPLAYALLON 0xA5
|
|
|
42 |
#define SSD1306_NORMALDISPLAY 0xA6
|
|
|
43 |
#define SSD1306_INVERTDISPLAY 0xA7
|
|
|
44 |
#define SSD1306_DISPLAYOFF 0xAE
|
|
|
45 |
#define SSD1306_DISPLAYON 0xAF
|
|
|
46 |
#define SSD1306_SETDISPLAYOFFSET 0xD3
|
|
|
47 |
#define SSD1306_SETCOMPINS 0xDA
|
|
|
48 |
#define SSD1306_SETVCOMDETECT 0xDB
|
|
|
49 |
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
|
|
|
50 |
#define SSD1306_SETPRECHARGE 0xD9
|
|
|
51 |
#define SSD1306_SETMULTIPLEX 0xA8
|
|
|
52 |
#define SSD1306_SETLOWCOLUMN 0x00
|
|
|
53 |
#define SSD1306_SETHIGHCOLUMN 0x10
|
|
|
54 |
#define SSD1306_SETSTARTLINE 0x40
|
|
|
55 |
#define SSD1306_MEMORYMODE 0x20
|
|
|
56 |
#define SSD1306_COMSCANINC 0xC0
|
|
|
57 |
#define SSD1306_COMSCANDEC 0xC8
|
|
|
58 |
#define SSD1306_SEGREMAP 0xA0
|
|
|
59 |
#define SSD1306_CHARGEPUMP 0x8D
|
|
|
60 |
#define SSD1306_EXTERNALVCC 0x1
|
|
|
61 |
#define SSD1306_SWITCHCAPVCC 0x2
|
|
|
62 |
|
|
|
63 |
typedef struct {
|
|
|
64 |
int WIDTH, HEIGHT; // raw display size
|
|
|
65 |
int _width, _height; // size depending on rotation
|
|
|
66 |
int cursor_x, cursor_y;
|
|
|
67 |
unsigned int textcolor, textbgcolor;
|
|
|
68 |
char textsize;
|
|
|
69 |
char rotation;
|
|
|
70 |
char wrap; // If set, wrap text at right side
|
|
|
71 |
} SSD1306_DATA;
|
|
|
72 |
|
|
|
73 |
// Misc functions
|
|
|
74 |
int SSD1306_Abs(int i);
|
|
|
75 |
void SSD1306_Swap(int *a, int *b);
|
|
|
76 |
|
|
|
77 |
// Core functions
|
|
|
78 |
void SSD1306_Init(SSD1306_DATA *data);
|
|
|
79 |
void SSD1306_Begin(char vcc);
|
|
|
80 |
void SSD1306_Command(char cmd);
|
|
|
81 |
void SSD1306_Data(char data);
|
|
|
82 |
|
|
|
83 |
void SSD1306_Clear_Display(void);
|
|
|
84 |
void SSD1306_Invert_Display(char);
|
|
|
85 |
void SSD1306_Display(void);
|
|
|
86 |
|
|
|
87 |
// Drawing functions
|
|
|
88 |
void SSD1306_Draw_Pixel(int x, int y, unsigned int color);
|
|
|
89 |
void SSD1306_Draw_Line(int x0, int y0, int x1, int y1, unsigned int color);
|
|
|
90 |
void SSD1306_Draw_Fast_VLine(int x, int y, int h, unsigned int color);
|
|
|
91 |
void SSD1306_Draw_Fast_HLine(int x, int y, int w, unsigned int color);
|
|
|
92 |
void SSD1306_Draw_Rect(int x, int y, int w, int h, unsigned int color);
|
|
|
93 |
void SSD1306_Fill_Rect(int x, int y, int w, int h, unsigned int color);
|
|
|
94 |
|
|
|
95 |
void SSD1306_Draw_Circle(int x0, int y0, int r, unsigned int color);
|
|
|
96 |
void SSD1306_Draw_Circle_Helper(int x0, int y0, int r, char cornername, unsigned int color);
|
|
|
97 |
void SSD1306_Fill_Circle(int x0, int y0, int r, unsigned int color);
|
|
|
98 |
void SSD1306_Fill_Circle_Helper(int x0, int y0, int r, char cornername, int delta, unsigned int color);
|
|
|
99 |
|
|
|
100 |
void SSD1306_Draw_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
|
|
|
101 |
void SSD1306_Fill_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color);
|
|
|
102 |
void SSD1306_Draw_Round_Rect(int x0, int y0, int w, int h, int radius, unsigned int color);
|
|
|
103 |
void SSD1306_Fill_Round_Rect(int x0, int y0, int w, int h, int radius, unsigned int color);
|
|
|
104 |
|
|
|
105 |
void SSD1306_Draw_Bitmap(int x, int y, const char *bitmap, int w, int h, unsigned int color);
|
|
|
106 |
void SSD1306_Draw_Char(int x, int y, char c, unsigned int color, unsigned int bg, char size);
|
|
|
107 |
|
|
|
108 |
void SSD1306_Write(char c);
|
|
|
109 |
void SSD1306_Write_String(char *msg, char length);
|
|
|
110 |
//void SSD1306_Write_String(const rom char *fmt, ...);
|
|
|
111 |
//void SSD1306_Append_String(const rom char *fmt, ...);
|
|
|
112 |
|
|
|
113 |
void SSD1306_Set_Cursor(int x, int y);
|
|
|
114 |
void SSD1306_Set_Text_Color(unsigned int c);
|
|
|
115 |
void SSD1306_Set_Text_Color_BG(unsigned int c, unsigned int bg);
|
|
|
116 |
void SSD1306_Set_Text_Size(char s);
|
|
|
117 |
void SSD1306_Set_Text_Wrap(char w);
|
|
|
118 |
void SSD1306_Set_Rotation(char r);
|
|
|
119 |
|
|
|
120 |
// Test functions
|
|
|
121 |
void SSD1306_Test_DrawChar(void);
|
|
|
122 |
void SSD1306_Test_DrawCircle(void);
|
|
|
123 |
void SSD1306_Test_DrawRect(void);
|
|
|
124 |
void SSD1306_Test_FillRect(void);
|
|
|
125 |
void SSD1306_Test_DrawTriangle(void);
|
|
|
126 |
void SSD1306_Test_FillTriangle(void);
|
|
|
127 |
void SSD1306_Test_DrawRoundRect(void);
|
|
|
128 |
void SSD1306_Test_FillRoundRect(void);
|
|
|
129 |
void SSD1306_Test_DrawLine(void);
|
|
|
130 |
|
|
|
131 |
#endif /* OLED_SSD1306_H */
|
|
|
132 |
|