-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssd1306.h
246 lines (203 loc) · 9 KB
/
ssd1306.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef SSD1306_H
#define SSD1306_H
#include "font.h"
/* I2C address */
#ifndef SSD1306_I2C_ADDR
#define SSD1306_I2C_ADDR 0x3c
#endif
/* SSD1306 settings */
/* SSD1306 width in pixels */
#ifndef SSD1306_WIDTH
#define SSD1306_WIDTH 132
#endif
/* SSD1306 LCD height in pixels */
#ifndef SSD1306_HEIGHT
#define SSD1306_HEIGHT 72
#endif
/**
* @brief SSD1306 color enumeration
*/
typedef enum {
SSD1306_COLOR_BLACK = 0x00, /*!< Black color, no pixel */
SSD1306_COLOR_WHITE = 0x01 /*!< Pixel is set. Color depends on LCD */
} SSD1306_COLOR_t;
/**
* @brief Initializes SSD1306 LCD
* @param None
* @retval Initialization status:
* - 0: LCD was not detected on I2C port
* - > 0: LCD initialized OK and ready to use
*/
uint8_t SSD1306_Init(void);
/**
* @brief Updates buffer from internal RAM to LCD
* @note This function must be called each time you do some changes to LCD, to update buffer from RAM to LCD
* @param None
* @retval None
*/
void SSD1306_UpdateScreen(void);
/**
* @brief Toggles pixels invertion inside internal RAM
* @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
* @param None
* @retval None
*/
void SSD1306_ToggleInvert(void);
/**
* @brief Fills entire LCD with desired color
* @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
* @param Color: Color to be used for screen fill. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval None
*/
void SSD1306_Fill(SSD1306_COLOR_t Color);
/**
* @brief Draws pixel at desired location
* @note @ref SSD1306_UpdateScreen() must called after that in order to see updated LCD screen
* @param x: X location. This parameter can be a value between 0 and SSD1306_WIDTH - 1
* @param y: Y location. This parameter can be a value between 0 and SSD1306_HEIGHT - 1
* @param color: Color to be used for screen fill. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval None
*/
void SSD1306_DrawPixel(uint16_t x, uint16_t y, SSD1306_COLOR_t color);
/**
* @brief Sets cursor pointer to desired location for strings
* @param x: X location. This parameter can be a value between 0 and SSD1306_WIDTH - 1
* @param y: Y location. This parameter can be a value between 0 and SSD1306_HEIGHT - 1
* @retval None
*/
void SSD1306_GotoXY(uint16_t x, uint16_t y);
/**
* @brief Puts character to internal RAM
* @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
* @param ch: Character to be written
* @param *Font: Pointer to @ref FontDef_t structure with used font
* @param color: Color used for drawing. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval Character written
*/
char SSD1306_Putc(char ch, FontDef_t* Font, SSD1306_COLOR_t color);
/**
* @brief Puts string to internal RAM
* @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
* @param *str: String to be written
* @param *Font: Pointer to @ref FontDef_t structure with used font
* @param color: Color used for drawing. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval Zero on success or character value when function failed
*/
char SSD1306_Puts(char* str, FontDef_t* Font, SSD1306_COLOR_t color);
/**
* @brief Draws line on LCD
* @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
* @param x0: Line X start point. Valid input is 0 to SSD1306_WIDTH - 1
* @param y0: Line Y start point. Valid input is 0 to SSD1306_HEIGHT - 1
* @param x1: Line X end point. Valid input is 0 to SSD1306_WIDTH - 1
* @param y1: Line Y end point. Valid input is 0 to SSD1306_HEIGHT - 1
* @param c: Color to be used. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval None
*/
void SSD1306_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, SSD1306_COLOR_t c);
/**
* @brief Draws rectangle on LCD
* @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
* @param x: Top left X start point. Valid input is 0 to SSD1306_WIDTH - 1
* @param y: Top left Y start point. Valid input is 0 to SSD1306_HEIGHT - 1
* @param w: Rectangle width in units of pixels
* @param h: Rectangle height in units of pixels
* @param c: Color to be used. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval None
*/
void SSD1306_DrawRectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, SSD1306_COLOR_t c);
/**
* @brief Draws filled rectangle on LCD
* @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
* @param x: Top left X start point. Valid input is 0 to SSD1306_WIDTH - 1
* @param y: Top left Y start point. Valid input is 0 to SSD1306_HEIGHT - 1
* @param w: Rectangle width in units of pixels
* @param h: Rectangle height in units of pixels
* @param c: Color to be used. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval None
*/
void SSD1306_DrawFilledRectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, SSD1306_COLOR_t c);
/**
* @brief Draws triangle on LCD
* @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
* @param x1: First coordinate X location. Valid input is 0 to SSD1306_WIDTH - 1
* @param y1: First coordinate Y location. Valid input is 0 to SSD1306_HEIGHT - 1
* @param x2: Second coordinate X location. Valid input is 0 to SSD1306_WIDTH - 1
* @param y2: Second coordinate Y location. Valid input is 0 to SSD1306_HEIGHT - 1
* @param x3: Third coordinate X location. Valid input is 0 to SSD1306_WIDTH - 1
* @param y3: Third coordinate Y location. Valid input is 0 to SSD1306_HEIGHT - 1
* @param c: Color to be used. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval None
*/
void SSD1306_DrawTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, SSD1306_COLOR_t color);
/**
* @brief Draws circle to STM buffer
* @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
* @param x: X location for center of circle. Valid input is 0 to SSD1306_WIDTH - 1
* @param y: Y location for center of circle. Valid input is 0 to SSD1306_HEIGHT - 1
* @param r: Circle radius in units of pixels
* @param c: Color to be used. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval None
*/
void SSD1306_DrawCircle(int16_t x0, int16_t y0, int16_t r, SSD1306_COLOR_t c);
/**
* @brief Draws filled circle to STM buffer
* @note @ref SSD1306_UpdateScreen() must be called after that in order to see updated LCD screen
* @param x: X location for center of circle. Valid input is 0 to SSD1306_WIDTH - 1
* @param y: Y location for center of circle. Valid input is 0 to SSD1306_HEIGHT - 1
* @param r: Circle radius in units of pixels
* @param c: Color to be used. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval None
*/
void SSD1306_DrawFilledCircle(int16_t x0, int16_t y0, int16_t r, SSD1306_COLOR_t c);
#ifndef ssd1306_I2C_TIMEOUT
#define ssd1306_I2C_TIMEOUT 20000
#endif
/**
* @brief Initializes SSD1306 LCD
* @param None
* @retval Initialization status:
* - 0: LCD was not detected on I2C port
* - > 0: LCD initialized OK and ready to use
*/
void ssd1306_I2C_Init();
/**
* @brief Writes single byte to slave
* @param *I2Cx: I2C used
* @param address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
* @param reg: register to write to
* @param data: data to be written
* @retval None
*/
void ssd1306_I2C_Write(uint8_t address, uint8_t reg, uint8_t data);
/**
* @brief Writes multi bytes to slave
* @param *I2Cx: I2C used
* @param address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
* @param reg: register to write to
* @param *data: pointer to data array to write it to slave
* @param count: how many bytes will be written
* @retval None
*/
void ssd1306_I2C_WriteMulti(uint8_t address, uint8_t reg, uint8_t *data, uint16_t count);
/**
* @brief Draws the Bitmap
* @param X: X location to start the Drawing
* @param Y: Y location to start the Drawing
* @param *bitmap : Pointer to the bitmap
* @param W : width of the image
* @param H : Height of the image
* @param color : 1-> white/blue, 0-> black
*/
void SSD1306_DrawBitmap(int16_t x, int16_t y, const unsigned char* bitmap, int16_t w, int16_t h, uint16_t color);
// scroll the screen for fixed rows
void SSD1306_ScrollRight(uint8_t start_row, uint8_t end_row);
void SSD1306_ScrollLeft(uint8_t start_row, uint8_t end_row);
void SSD1306_Scrolldiagright(uint8_t start_row, uint8_t end_row);
void SSD1306_Scrolldiagleft(uint8_t start_row, uint8_t end_row);
void SSD1306_Stopscroll(void);
// inverts the display i = 1->inverted, i = 0->normal
void SSD1306_InvertDisplay (int i);
// clear the display
void SSD1306_Clear (void);
#endif