Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

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