Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
121 Kevin 1
#include "maindefs.h"
2
#include "oled_ssd1306.h"
3
#include "spi.h"
4
#include "string.h"
129 Kevin 5
#include "glcdfont.c"
121 Kevin 6
#include <delays.h>
129 Kevin 7
#include <string.h>
8
#include <stdio.h>
121 Kevin 9
 
129 Kevin 10
static SSD1306_DATA ssd1306_data;
11
static SSD1306_DATA *ssd1306_data_p = &ssd1306_data;
12
 
13
#pragma idata LCD_BUFFER
121 Kevin 14
// 512 (128x32) or 1024 (128x64) bytes allocated for LCD buffer
15
// See linker file for details
16
static unsigned char LCD_Buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {
17
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
18
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
19
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
21
    0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
22
    0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
26
    0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00,
27
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
28
    0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF,
29
    0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
30
    0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80,
31
    0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8,
32
    0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33
    0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80,
34
    0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
35
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01,
36
    0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF,
37
    0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00,
38
    0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF,
39
    0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF,
40
    0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41
    0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F,
42
    0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC,
43
    0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03,
44
    0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01,
45
    0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00,
46
    0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
47
    0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03,
48
    0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49
#if (SSD1306_LCDHEIGHT == 64)
50
    0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F,
51
    0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF,
52
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00,
53
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54
    0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00,
56
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00,
57
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58
    0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F,
59
    0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0,
60
    0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00,
61
    0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E,
62
    0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC,
63
    0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06,
64
    0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8,
65
    0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80,
66
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67
    0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03,
68
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00,
69
    0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C,
70
    0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F,
71
    0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00,
72
    0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07,
73
    0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07,
74
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
75
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
82
#endif
83
};
129 Kevin 84
#pragma idata
121 Kevin 85
 
129 Kevin 86
int SSD1306_Abs(int i) {
87
    if (i < 0)
88
        return -i;
89
    else
90
        return i;
91
}
92
 
93
void SSD1306_Swap(int *a, int *b) {
94
    int tmp = *a;
95
    *a = *b;
96
    *b = tmp;
97
}
98
 
121 Kevin 99
void SSD1306_Init() {
129 Kevin 100
    ssd1306_data_p->_width = ssd1306_data_p->WIDTH = SSD1306_LCDWIDTH;
101
    ssd1306_data_p->_height = ssd1306_data_p->HEIGHT = SSD1306_LCDHEIGHT;
102
    ssd1306_data_p->rotation = 0;
103
    ssd1306_data_p->cursor_x = ssd1306_data_p->cursor_y = 0;
104
    ssd1306_data_p->textsize = 1;
105
    ssd1306_data_p->textcolor = SSD1306_WHITE;
106
    ssd1306_data_p->textbgcolor = SSD1306_BLACK;
107
    ssd1306_data_p->wrap = 1;
121 Kevin 108
}
109
 
110
void SSD1306_Begin(unsigned char vccstate) {
111
    // Toggle reset pin
129 Kevin 112
    SPI_RESET_LAT = 0;
121 Kevin 113
    Delay10KTCYx(1);
129 Kevin 114
    SPI_RESET_LAT = 1;
121 Kevin 115
 
116
#if defined SSD1306_128_32
117
    // Init sequence for 128x32 OLED module
118
    SSD1306_Command(SSD1306_DISPLAYOFF); // 0xAE
119
    SSD1306_Command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
120
    SSD1306_Command(0x80); // The suggested ratio 0x80
121
    SSD1306_Command(SSD1306_SETMULTIPLEX); // 0xA8
122
    SSD1306_Command(0x1F);
123
    SSD1306_Command(SSD1306_SETDISPLAYOFFSET); // 0xD3
124
    SSD1306_Command(0x0); // No offset
125
    SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // Line #0
126
    SSD1306_Command(SSD1306_CHARGEPUMP); // 0x8D
127
    if (vccstate == SSD1306_EXTERNALVCC) {
128
        SSD1306_Command(0x10);
129
    } else {
130
        SSD1306_Command(0x14);
131
    }
132
    SSD1306_Command(SSD1306_MEMORYMODE); // 0x20
133
    SSD1306_Command(0x00); // 0x0 act like ks0108
134
    SSD1306_Command(SSD1306_SEGREMAP | 0x1);
135
    SSD1306_Command(SSD1306_COMSCANDEC);
136
    SSD1306_Command(SSD1306_SETCOMPINS); // 0xDA
137
    SSD1306_Command(0x02);
138
    SSD1306_Command(SSD1306_SETCONTRAST); // 0x81
139
    SSD1306_Command(0x8F);
140
    SSD1306_Command(SSD1306_SETPRECHARGE); // 0xd9
141
    if (vccstate == SSD1306_EXTERNALVCC) {
142
        SSD1306_Command(0x22);
143
    } else {
144
        SSD1306_Command(0xF1);
145
    }
146
    SSD1306_Command(SSD1306_SETVCOMDETECT); // 0xDB
147
    SSD1306_Command(0x40);
148
    SSD1306_Command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
149
    SSD1306_Command(SSD1306_NORMALDISPLAY); // 0xA6
150
#endif
151
 
152
#if defined SSD1306_128_64
153
    // Init sequence for 128x64 OLED module
154
    SSD1306_Command(SSD1306_DISPLAYOFF); // 0xAE
155
    SSD1306_Command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
156
    SSD1306_Command(0x80); // The suggested ratio 0x80
157
    SSD1306_Command(SSD1306_SETMULTIPLEX); // 0xA8
158
    SSD1306_Command(0x3F);
159
    SSD1306_Command(SSD1306_SETDISPLAYOFFSET); // 0xD3
160
    SSD1306_Command(0x0); // No offset
161
    SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // Line #0
162
    SSD1306_Command(SSD1306_CHARGEPUMP); // 0x8D
163
    if (vccstate == SSD1306_EXTERNALVCC) {
164
        SSD1306_Command(0x10);
165
    } else {
166
        SSD1306_Command(0x14);
167
    }
168
    SSD1306_Command(SSD1306_MEMORYMODE); // 0x20
169
    SSD1306_Command(0x00); // 0x0 act like ks0108
170
    SSD1306_Command(SSD1306_SEGREMAP | 0x1);
171
    SSD1306_Command(SSD1306_COMSCANDEC);
172
    SSD1306_Command(SSD1306_SETCOMPINS); // 0xDA
173
    SSD1306_Command(0x12);
174
    SSD1306_Command(SSD1306_SETCONTRAST); // 0x81
175
    if (vccstate == SSD1306_EXTERNALVCC) {
176
        SSD1306_Command(0x9F);
177
    } else {
178
        SSD1306_Command(0xCF);
179
    }
180
    SSD1306_Command(SSD1306_SETPRECHARGE); // 0xd9
181
    if (vccstate == SSD1306_EXTERNALVCC) {
182
        SSD1306_Command(0x22);
183
    } else {
184
        SSD1306_Command(0xF1);
185
    }
186
    SSD1306_Command(SSD1306_SETVCOMDETECT); // 0xDB
187
    SSD1306_Command(0x40);
188
    SSD1306_Command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
189
    SSD1306_Command(SSD1306_NORMALDISPLAY); // 0xA6
190
#endif
191
 
192
    SSD1306_Command(SSD1306_DISPLAYON); // Turn on OLED panel
193
}
194
 
195
void SSD1306_Command(unsigned char cmd) {
196
    unsigned char c = cmd;
129 Kevin 197
    SPI_DC_SELECT_LAT = 0; // D/C low (cmd)
121 Kevin 198
    SPI2_Write(&c, 1);
199
}
200
 
201
void SSD1306_Data(unsigned char data) {
202
    unsigned char c = data;
129 Kevin 203
    SPI_DC_SELECT_LAT = 1; // D/C high (data)
121 Kevin 204
    SPI2_Write(&c, 1);
205
}
206
 
207
void SSD1306_Clear_Display() {
208
    memset(LCD_Buffer, 0, (SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8));
209
}
210
 
211
void SSD1306_Invert_Display(unsigned char c) {
212
    if (c) {
213
        SSD1306_Command(SSD1306_INVERTDISPLAY);
214
    } else {
215
        SSD1306_Command((SSD1306_NORMALDISPLAY));
216
    }
217
}
218
 
219
void SSD1306_Display() {
220
    unsigned int i;
221
    unsigned char c = 0;
222
 
223
    SSD1306_Command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0
224
    SSD1306_Command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0
225
    SSD1306_Command(SSD1306_SETSTARTLINE | 0x0); // line #0
226
 
129 Kevin 227
    SPI_DC_SELECT_LAT = 1; // D/C high (data)
121 Kevin 228
    SPI2_Write(LCD_Buffer, SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8);
229
 
230
//    if (SSD1306_LCDHEIGHT == 32) {
231
//        SPI2_Write_Repeat(0, SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8);
232
//    }
233
}
234
 
235
void SSD1306_Draw_Pixel(int x, int y, unsigned int color) {
129 Kevin 236
    if ((x < 0) || (x >= ssd1306_data_p->_width) || (y < 0) || (y >= ssd1306_data_p->_height))
121 Kevin 237
        return;
238
 
239
    // check rotation, move pixel around if necessary
129 Kevin 240
    switch (ssd1306_data_p->rotation) {
121 Kevin 241
        case 1:
129 Kevin 242
            SSD1306_Swap(&x, &y);
121 Kevin 243
            x = SSD1306_LCDWIDTH - x - 1;
244
            break;
245
        case 2:
246
            x = SSD1306_LCDWIDTH - x - 1;
247
            y = SSD1306_LCDHEIGHT - y - 1;
248
            break;
249
        case 3:
129 Kevin 250
            SSD1306_Swap(&x, &y);
121 Kevin 251
            y = SSD1306_LCDHEIGHT - y - 1;
252
            break;
253
    }
254
 
255
    // x is which column
256
    if (color == SSD1306_WHITE)
257
        LCD_Buffer[x + (y / 8) * SSD1306_LCDWIDTH] |= 1<<(y % 8);
258
    else
259
        LCD_Buffer[x + (y / 8) * SSD1306_LCDWIDTH] &= ~(1<<(y % 8));
260
}
261
 
129 Kevin 262
void SSD1306_Draw_Line(int x0, int y0, int x1, int y1, unsigned int color) {
263
    int dx, dy, err, ystep;
264
    int steep = SSD1306_Abs(y1 - y0) > SSD1306_Abs(x1 - x0);
265
    if (steep) {
266
        SSD1306_Swap(&x0, &y0);
267
        SSD1306_Swap(&x1, &y1);
268
    }
269
 
270
    if (x0 > x1) {
271
        SSD1306_Swap(&x0, &x1);
272
        SSD1306_Swap(&y0, &y1);
273
    }
274
 
275
    dx = x1 - x0;
276
    dy = SSD1306_Abs(y1 - y0);
277
 
278
    err = dx / 2;
279
 
280
    if (y0 < y1) {
281
        ystep = 1;
282
    } else {
283
        ystep = -1;
284
    }
285
 
286
    for (; x0 <= x1; x0++) {
287
 
288
        if (steep) {
289
            SSD1306_Draw_Pixel(y0, x0, color);
290
        } else {
291
            SSD1306_Draw_Pixel(x0, y0, color);
292
        }
293
        err -= dy;
294
        if (err < 0) {
295
            y0 += ystep;
296
            err += dx;
297
        }
298
    }
299
}
300
 
301
void SSD1306_Draw_Fast_VLine(int x, int y, int h, unsigned int color) {
302
    SSD1306_Draw_Line(x, y, x, y + h - 1, color);
303
}
304
 
305
void SSD1306_Draw_Fast_HLine(int x, int y, int w, unsigned int color) {
306
    SSD1306_Draw_Line(x, y, x + w - 1, y, color);
307
}
308
 
309
void SSD1306_Draw_Rect(int x, int y, int w, int h, unsigned int color) {
310
    SSD1306_Draw_Fast_HLine(x, y, w, color);
311
    SSD1306_Draw_Fast_HLine(x, y + h, w, color);
312
    SSD1306_Draw_Fast_VLine(x, y, h, color);
313
    SSD1306_Draw_Fast_VLine(x + w, y, h, color);
314
}
315
 
316
void SSD1306_Fill_Rect(int x, int y, int w, int h, unsigned int color) {
317
    int i;
318
    for (i = x; i < x + w; i++) {
319
        SSD1306_Draw_Fast_VLine(i, y, h, color);
320
    }
321
}
322
 
323
void SSD1306_Draw_Circle(int x0, int y0, int r, unsigned int color) {
324
    int f = 1 - r;
325
    int ddF_x = 1;
326
    int ddF_y = -2 * r;
327
    int x = 0;
328
    int y = r;
329
 
330
    SSD1306_Draw_Pixel(x0, y0 + r, color);
331
    SSD1306_Draw_Pixel(x0, y0 - r, color);
332
    SSD1306_Draw_Pixel(x0 + r, y0, color);
333
    SSD1306_Draw_Pixel(x0 - r, y0, color);
334
 
335
    while (x < y) {
336
        if (f >= 0) {
337
            y--;
338
            ddF_y += 2;
339
            f += ddF_y;
340
        }
341
        x++;
342
        ddF_x += 2;
343
        f += ddF_x;
344
 
345
        SSD1306_Draw_Pixel(x0 + x, y0 + y, color);
346
        SSD1306_Draw_Pixel(x0 - x, y0 + y, color);
347
        SSD1306_Draw_Pixel(x0 + x, y0 - y, color);
348
        SSD1306_Draw_Pixel(x0 - x, y0 - y, color);
349
        SSD1306_Draw_Pixel(x0 + y, y0 + x, color);
350
        SSD1306_Draw_Pixel(x0 - y, y0 + x, color);
351
        SSD1306_Draw_Pixel(x0 + y, y0 - x, color);
352
        SSD1306_Draw_Pixel(x0 - y, y0 - x, color);
353
    }
354
}
355
 
356
void SSD1306_Draw_Circle_Helper(int x0, int y0, int r, unsigned char cornername, unsigned int color) {
357
    int f = 1 - r;
358
    int ddF_x = 1;
359
    int ddF_y = -2 * r;
360
    int x = 0;
361
    int y = r;
362
 
363
    while (x < y) {
364
        if (f >= 0) {
365
            y--;
366
            ddF_y += 2;
367
            f += ddF_y;
368
        }
369
        x++;
370
        ddF_x += 2;
371
        f += ddF_x;
372
        if (cornername & 0x4) {
373
            SSD1306_Draw_Pixel(x0 + x, y0 + y, color);
374
            SSD1306_Draw_Pixel(x0 + y, y0 + x, color);
375
        }
376
        if (cornername & 0x2) {
377
            SSD1306_Draw_Pixel(x0 + x, y0 - y, color);
378
            SSD1306_Draw_Pixel(x0 + y, y0 - x, color);
379
        }
380
        if (cornername & 0x8) {
381
            SSD1306_Draw_Pixel(x0 - y, y0 + x, color);
382
            SSD1306_Draw_Pixel(x0 - x, y0 + y, color);
383
        }
384
        if (cornername & 0x1) {
385
            SSD1306_Draw_Pixel(x0 - y, y0 - x, color);
386
            SSD1306_Draw_Pixel(x0 - x, y0 - y, color);
387
        }
388
    }
389
}
390
 
391
void SSD1306_Fill_Circle(int x0, int y0, int r, unsigned int color) {
392
    SSD1306_Draw_Fast_VLine(x0, y0 - r, 2 * r + 1, color);
393
    SSD1306_Fill_Circle_Helper(x0, y0, r, 3, 0, color);
394
}
395
 
396
void SSD1306_Fill_Circle_Helper(int x0, int y0, int r, unsigned char cornername, int delta, unsigned int color) {
397
    int f = 1 - r;
398
    int ddF_x = 1;
399
    int ddF_y = -2 * r;
400
    int x = 0;
401
    int y = r;
402
 
403
    while (x < y) {
404
        if (f >= 0) {
405
            y--;
406
            ddF_y += 2;
407
            f += ddF_y;
408
        }
409
        x++;
410
        ddF_x += 2;
411
        f += ddF_x;
412
 
413
        if (cornername & 0x1) {
414
            SSD1306_Draw_Fast_VLine(x0 + x, y0 - y, 2 * y + 1 + delta, color);
415
            SSD1306_Draw_Fast_VLine(x0 + y, y0 - x, 2 * x + 1 + delta, color);
416
        }
417
        if (cornername & 0x2) {
418
            SSD1306_Draw_Fast_VLine(x0 - x, y0 - y, 2 * y + 1 + delta, color);
419
            SSD1306_Draw_Fast_VLine(x0 - y, y0 - x, 2 * x + 1 + delta, color);
420
        }
421
    }
422
}
423
 
424
void SSD1306_Draw_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color) {
425
    SSD1306_Draw_Line(x0, y0, x1, y1, color);
426
    SSD1306_Draw_Line(x1, y1, x2, y2, color);
427
    SSD1306_Draw_Line(x2, y2, x0, y0, color);
428
}
429
 
430
void SSD1306_Fill_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int color) {
431
    int a, b, y, last;
432
    int dx01 = x1 - x0;
433
    int dy01 = y1 - y0;
434
    int dx02 = x2 - x0;
435
    int dy02 = y2 - y0;
436
    int dx12 = x2 - x1;
437
    int dy12 = y2 - y1;
438
    int sa = 0;
439
    int sb = 0;
440
 
441
    // Sort coordinates by Y order (y2 >= y1 >= y0)
442
    if (y0 > y1) {
443
        SSD1306_Swap(&y0, &y1);
444
        SSD1306_Swap(&x0, &x1);
445
    }
446
    if (y1 > y2) {
447
        SSD1306_Swap(&y2, &y1);
448
        SSD1306_Swap(&x2, &x1);
449
    }
450
    if (y0 > y1) {
451
        SSD1306_Swap(&y0, &y1);
452
        SSD1306_Swap(&x0, &x1);
453
    }
454
 
455
    if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
456
        a = b = x0;
457
        if (x1 < a) a = x1;
458
        else if (x1 > b) b = x1;
459
        if (x2 < a) a = x2;
460
        else if (x2 > b) b = x2;
461
        SSD1306_Draw_Fast_HLine(a, y0, b - a + 1, color);
462
        return;
463
    }
464
 
465
    // For upper part of triangle, find scanline crossings for segments
466
    // 0-1 and 0-2.  If y1=y2 (flat-bottomed triangle), the scanline y1
467
    // is included here (and second loop will be skipped, avoiding a /0
468
    // error there), otherwise scanline y1 is skipped here and handled
469
    // in the second loop...which also avoids a /0 error here if y0=y1
470
    // (flat-topped triangle).
471
    if (y1 == y2) last = y1; // Include y1 scanline
472
    else last = y1 - 1; // Skip it
473
 
474
    for (y = y0; y <= last; y++) {
475
        a = x0 + sa / dy01;
476
        b = x0 + sb / dy02;
477
        sa += dx01;
478
        sb += dx02;
479
        /* longhand:
480
        a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
481
        b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
482
         */
483
        if (a > b) SSD1306_Swap(&a, &b);
484
        SSD1306_Draw_Fast_HLine(a, y, b - a + 1, color);
485
    }
486
 
487
    // For lower part of triangle, find scanline crossings for segments
488
    // 0-2 and 1-2.  This loop is skipped if y1=y2.
489
    sa = dx12 * (y - y1);
490
    sb = dx02 * (y - y0);
491
    for (; y <= y2; y++) {
492
        a = x1 + sa / dy12;
493
        b = x0 + sb / dy02;
494
        sa += dx12;
495
        sb += dx02;
496
        /* longhand:
497
        a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
498
        b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
499
         */
500
        if (a > b) SSD1306_Swap(&a, &b);
501
        SSD1306_Draw_Fast_HLine(a, y, b - a + 1, color);
502
    }
503
}
504
 
505
void SSD1306_Draw_Round_Rect(int x, int y, int w, int h, int r, unsigned int color) {
506
    // smarter version
507
    SSD1306_Draw_Fast_HLine(x + r, y, w - 2 * r, color); // Top
508
    SSD1306_Draw_Fast_HLine(x + r, y + h - 1, w - 2 * r, color); // Bottom
509
    SSD1306_Draw_Fast_VLine(x, y + r, h - 2 * r, color); // Left
510
    SSD1306_Draw_Fast_VLine(x + w - 1, y + r, h - 2 * r, color); // Right
511
 
512
    // draw four corners
513
    SSD1306_Draw_Circle_Helper(x + r, y + r, r, 1, color);
514
    SSD1306_Draw_Circle_Helper(x + w - r - 1, y + r, r, 2, color);
515
    SSD1306_Draw_Circle_Helper(x + w - r - 1, y + h - r - 1, r, 4, color);
516
    SSD1306_Draw_Circle_Helper(x + r, y + h - r - 1, r, 8, color);
517
}
518
 
519
void SSD1306_Fill_Round_Rect(int x, int y, int w, int h, int r, unsigned int color) {
520
    // smarter version
521
    SSD1306_Fill_Rect(x + r, y, w - 2 * r, h, color);
522
 
523
    // draw four corners
524
    SSD1306_Fill_Circle_Helper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1, color);
525
    SSD1306_Fill_Circle_Helper(x + r, y + r, r, 2, h - 2 * r - 1, color);
526
}
527
 
528
void SSD1306_Draw_Bitmap(int x, int y, const unsigned char* bitmap, int w, int h, unsigned int color) {
529
    int i, j;
530
    for (j = 0; j < h; j++) {
531
        for (i = 0; i < w; i++) {
532
            if (bitmap[i + (j / 8) * w] & (j % 8)) {
533
                SSD1306_Draw_Pixel(x + i, y + j, color);
534
            }
535
        }
536
    }
537
}
538
 
539
void SSD1306_Draw_Char(int x, int y, unsigned char c, unsigned int color, unsigned int bg, unsigned char size) {
540
    int i, j;
541
    unsigned int line;
542
 
543
    if ((x >= ssd1306_data_p->_width) || // Clip right
544
            (y >= ssd1306_data_p->_height) || // Clip bottom
545
            ((x + 5 * size - 1) < 0) || // Clip left
546
            ((y + 8 * size - 1) < 0)) // Clip top
547
        return;
548
 
549
    for (i = 0; i < 6; i++) {
550
        if (i == 5)
551
            line = 0x0;
552
        else
553
            line = font[(c * 5) + i];
554
        for (j = 0; j < 8; j++) {
555
            if (line & 0x1) {
556
                if (size == 1) {// default size
557
                    SSD1306_Draw_Pixel(x + i, y + j, color);
558
                } else { // big size
559
                    SSD1306_Fill_Rect(x + (i * size), y + (j * size), size, size, color);
560
                }
561
            } else if (bg != color) {
562
                if (size == 1) { // default size
563
                    SSD1306_Draw_Pixel(x + i, y + j, bg);
564
                } else { // big size
565
                    SSD1306_Fill_Rect(x + i*size, y + j*size, size, size, bg);
566
                }
567
            }
568
            line >>= 1;
569
        }
570
    }
571
}
572
 
573
void SSD1306_Write(unsigned char c) {
574
    if (c == '\n' || c == '\r') {
575
        ssd1306_data_p->cursor_y += ssd1306_data_p->textsize * 8;
576
        ssd1306_data_p->cursor_x = 0;
577
        //    } else if (c == '\r') {
578
        //        // skip em
579
    } else {
580
        SSD1306_Draw_Char(ssd1306_data_p->cursor_x, ssd1306_data_p->cursor_y, c, ssd1306_data_p->textcolor, ssd1306_data_p->textbgcolor, ssd1306_data_p->textsize);
581
        ssd1306_data_p->cursor_x += ssd1306_data_p->textsize * 6;
582
        if (ssd1306_data_p->wrap && (ssd1306_data_p->cursor_x > (ssd1306_data_p->_width - ssd1306_data_p->textsize * 6))) {
583
            ssd1306_data_p->cursor_y += ssd1306_data_p->textsize * 8;
584
            ssd1306_data_p->cursor_x = 0;
585
        }
586
    }
587
}
588
 
589
void SSD1306_Write_String(const rom char *fmt, ...) {
590
    unsigned char i, len;
591
    unsigned char buffer[SSD1306_STRING_BUFFER_SIZE];
592
 
593
    // Parse and create string
594
    va_list args;
595
    va_start(args, fmt);
596
    vsprintf((char *) buffer, fmt, args);
597
    va_end(args);
598
    len = strlen((char *) buffer);
599
 
600
    // Make sure string to insert fits in buffer, truncate if necessary
601
    if (len > SSD1306_STRING_BUFFER_SIZE)
602
        len = SSD1306_STRING_BUFFER_SIZE;
603
 
604
    // Print buffer to string
605
    for (i = 0; i < len; i++) {
606
        SSD1306_Write(buffer[i]);
607
    }
608
}
609
 
610
//void SSD1306_Append_String(const rom char *fmt, ...) {
611
//    unsigned char i, len;
612
//    unsigned char buffer[SSD1306_STRING_BUFFER_SIZE];
613
//
614
//    // Parse and create string
615
//    va_list args;
616
//    va_start(args, fmt);
617
//    vsprintf((char *) buffer, fmt, args);
618
//    va_end(args);
619
//
620
//    // Make sure string to insert fits in buffer, truncate if necessary
621
//    len = strlen((char *) buffer);
622
//
623
//    if (len == 1) {  // This will only occur on "\n"
624
//        // Do nothing?
625
//        return;
626
//    }
627
//
628
//    if (len > SSD1306_STRING_BUFFER_SIZE)
629
//        len = SSD1306_STRING_BUFFER_SIZE;
630
//
631
//    // Omit the newline if string fill entire line
632
//    if (((len - 1)%(ssd1306_data_p->_width / 6)) == 0) { // 16 or 10
633
//        len -= 1;
634
//    }
635
//
636
//    // Shift everything right and insert string at beginning
637
//    for (i = 127; i > len - 1; i--) {
638
//        ssd1306_data_p->lcd_buffer[i] = ssd1306_data_p->lcd_buffer[i - len];
639
//    }
640
//    memcpy((char *)ssd1306_data_p->lcd_buffer, (const char *) buffer, len);
641
//
642
//    // Print full buffer to screen
643
//    SSD1306_Clear_Display();
644
//    SSD1306_Display();
645
//
646
//    SSD1306_Set_Cursor(0,0);
647
//    for (i = 0; i < SSD1306_LCD_BUFFER_SIZE-1; i++) {
648
//        SSD1306_Write(ssd1306_data_p->lcd_buffer[i]);
649
//    }
650
//}
651
 
652
void SSD1306_Set_Cursor(int x, int y) {
653
    ssd1306_data_p->cursor_x = x;
654
    ssd1306_data_p->cursor_y = y;
655
}
656
 
657
void SSD1306_Set_Text_Color(unsigned int c) {
658
    // for 'transparent' background, we'll set the bg
659
    // to the same as fg instead of using a flag
660
    ssd1306_data_p->textcolor = c;
661
    ssd1306_data_p->textbgcolor = c;
662
}
663
 
664
void SSD1306_Set_Text_Color_BG(unsigned int c, unsigned int bg) {
665
    ssd1306_data_p->textcolor = c;
666
    ssd1306_data_p->textbgcolor = bg;
667
}
668
 
669
void SSD1306_Set_Text_Size(unsigned char s) {
670
    ssd1306_data_p->textsize = (s > 0) ? s : 1;
671
}
672
 
673
void SSD1306_Set_Text_Wrap(unsigned char w) {
674
    ssd1306_data_p->wrap = w;
675
}
676
 
677
void SSD1306_Set_Rotation(unsigned char x) {
678
    x %= 4; // cant be higher than 3
679
    ssd1306_data_p->rotation = x;
680
    switch (x) {
681
        case 0:
682
        case 2:
683
            ssd1306_data_p->_width = ssd1306_data_p->WIDTH;
684
            ssd1306_data_p->_height = ssd1306_data_p->HEIGHT;
685
            break;
686
        case 1:
687
        case 3:
688
            ssd1306_data_p->_width = ssd1306_data_p->HEIGHT;
689
            ssd1306_data_p->_height = ssd1306_data_p->WIDTH;
690
            break;
691
    }
692
}
693
 
694
 
695
 
121 Kevin 696
void SSD1306_Test_DrawChar() {
697
    unsigned char i;
129 Kevin 698
    SSD1306_Set_Text_Size(1);
699
    SSD1306_Set_Text_Color(SSD1306_WHITE);
700
    SSD1306_Set_Cursor(0, 0);
121 Kevin 701
 
702
    for (i = 0; i < 168; i++) {
703
        if (i == '\n') continue;
129 Kevin 704
        SSD1306_Write(i);
121 Kevin 705
//        if ((i > 0) && (i % 21 == 0))
129 Kevin 706
//            SSD1306_write('\n');
121 Kevin 707
    }
708
    SSD1306_Display();
709
}
710
 
711
void SSD1306_Test_DrawCircle() {
712
    int i;
129 Kevin 713
    for (i = 0; i < ssd1306_data_p->_height; i += 2) {
714
        SSD1306_Draw_Circle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2, i, SSD1306_WHITE);
121 Kevin 715
        SSD1306_Display();
716
    }
717
}
718
 
719
void SSD1306_Test_DrawRect(void) {
720
    int i;
129 Kevin 721
    for (i = 0; i < ssd1306_data_p->_height / 2; i += 2) {
722
        SSD1306_Draw_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, SSD1306_WHITE);
121 Kevin 723
        SSD1306_Display();
724
    }
725
}
726
 
727
void SSD1306_Test_FillRect(void) {
728
    unsigned char color = 1;
729
    int i;
129 Kevin 730
    for (i = 0; i < ssd1306_data_p->_height / 2; i += 3) {
121 Kevin 731
        // alternate colors
129 Kevin 732
        SSD1306_Fill_Rect(i, i, ssd1306_data_p->_width - i * 2, ssd1306_data_p->_height - i * 2, color % 2);
121 Kevin 733
        SSD1306_Display();
734
        color++;
735
    }
736
}
737
 
738
void SSD1306_Test_DrawTriangle(void) {
739
    int i;
129 Kevin 740
    int min = ssd1306_data_p->_width < ssd1306_data_p->_height ? ssd1306_data_p->_width : ssd1306_data_p->_height;
121 Kevin 741
    for (i = 0; i < min / 2; i += 5) {
129 Kevin 742
        SSD1306_Draw_Triangle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2 - i,
743
                ssd1306_data_p->_width / 2 - i, ssd1306_data_p->_height / 2 + i,
744
                ssd1306_data_p->_width / 2 + i, ssd1306_data_p->_height / 2 + i, SSD1306_WHITE);
121 Kevin 745
        SSD1306_Display();
746
    }
747
}
748
 
749
void SSD1306_Test_FillTriangle(void) {
750
    unsigned char color = SSD1306_WHITE;
751
    int i;
129 Kevin 752
    int min = ssd1306_data_p->_width < ssd1306_data_p->_height ? ssd1306_data_p->_width : ssd1306_data_p->_height;
121 Kevin 753
    for (i = min / 2; i > 0; i -= 5) {
129 Kevin 754
        SSD1306_Fill_Triangle(ssd1306_data_p->_width / 2, ssd1306_data_p->_height / 2 - i,
755
                ssd1306_data_p->_width / 2 - i, ssd1306_data_p->_height / 2 + i,
756
                ssd1306_data_p->_width / 2 + i, ssd1306_data_p->_height / 2 + i, SSD1306_WHITE);
121 Kevin 757
        if (color == SSD1306_WHITE) color = SSD1306_BLACK;
758
        else color = SSD1306_WHITE;
759
        SSD1306_Display();
760
    }
761
}
762
 
763
void SSD1306_Test_DrawRoundRect(void) {
764
    int i;
129 Kevin 765
    for (i = 0; i < ssd1306_data_p->_height / 2 - 2; i += 2) {
766
        SSD1306_Draw_Round_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, ssd1306_data_p->_height / 4, SSD1306_WHITE);
121 Kevin 767
        SSD1306_Display();
768
    }
769
}
770
 
771
void SSD1306_Test_FillRoundRect(void) {
772
    unsigned char color = SSD1306_WHITE;
773
    int i;
129 Kevin 774
    for (i = 0; i < ssd1306_data_p->_height / 2 - 2; i += 2) {
775
        SSD1306_Fill_Round_Rect(i, i, ssd1306_data_p->_width - 2 * i, ssd1306_data_p->_height - 2 * i, ssd1306_data_p->_height / 4, color);
121 Kevin 776
        if (color == SSD1306_WHITE) color = SSD1306_BLACK;
777
        else color = SSD1306_WHITE;
778
        SSD1306_Display();
779
    }
780
}
781
 
782
void SSD1306_Test_DrawLine(void) {
783
    int i;
129 Kevin 784
    for (i = 0; i < ssd1306_data_p->_width; i += 4) {
785
        SSD1306_Draw_Line(0, 0, i, ssd1306_data_p->_height - 1, SSD1306_WHITE);
121 Kevin 786
        SSD1306_Display();
787
    }
129 Kevin 788
    for (i = 0; i < ssd1306_data_p->_height; i += 4) {
789
        SSD1306_Draw_Line(0, 0, ssd1306_data_p->_width - 1, i, SSD1306_WHITE);
121 Kevin 790
        SSD1306_Display();
791
    }
792
    Delay10KTCYx(255);
793
 
794
    SSD1306_Clear_Display();
129 Kevin 795
    for (i = 0; i < ssd1306_data_p->_width; i += 4) {
796
        SSD1306_Draw_Line(0, ssd1306_data_p->_height - 1, i, 0, SSD1306_WHITE);
121 Kevin 797
        SSD1306_Display();
798
    }
129 Kevin 799
    for (i = ssd1306_data_p->_height - 1; i >= 0; i -= 4) {
800
        SSD1306_Draw_Line(0, ssd1306_data_p->_height - 1, ssd1306_data_p->_width - 1, i, SSD1306_WHITE);
121 Kevin 801
        SSD1306_Display();
802
    }
803
    Delay10KTCYx(255);
804
 
805
    SSD1306_Clear_Display();
129 Kevin 806
    for (i = ssd1306_data_p->_width - 1; i >= 0; i -= 4) {
807
        SSD1306_Draw_Line(ssd1306_data_p->_width - 1, ssd1306_data_p->_height - 1, i, 0, SSD1306_WHITE);
121 Kevin 808
        SSD1306_Display();
809
    }
129 Kevin 810
    for (i = ssd1306_data_p->_height - 1; i >= 0; i -= 4) {
811
        SSD1306_Draw_Line(ssd1306_data_p->_width - 1, ssd1306_data_p->_height - 1, 0, i, SSD1306_WHITE);
121 Kevin 812
        SSD1306_Display();
813
    }
814
    Delay10KTCYx(255);
815
 
816
    SSD1306_Clear_Display();
129 Kevin 817
    for (i = 0; i < ssd1306_data_p->_height; i += 4) {
818
        SSD1306_Draw_Line(ssd1306_data_p->_width - 1, 0, 0, i, SSD1306_WHITE);
121 Kevin 819
        SSD1306_Display();
820
    }
129 Kevin 821
    for (i = 0; i < ssd1306_data_p->_width; i += 4) {
822
        SSD1306_Draw_Line(ssd1306_data_p->_width - 1, 0, i, ssd1306_data_p->_height - 1, SSD1306_WHITE);
121 Kevin 823
        SSD1306_Display();
824
    }
825
    Delay10KTCYx(255);
826
}