Mon, 11 Mar 2024 15:35:36 +0100
Add links to sr.ht repos and add an image in the README file
5 | 1 | /* mbed UniGraphic library - Device specific class |
2 | * Copyright (c) 2015 Peter Drescher | |
3 | * Released under the MIT License: http://mbed.org/license/mit | |
4 | */ | |
26 | 5 | |
5 | 6 | #include "platform.h" |
7 | #include "SSD1322.h" | |
8 | ||
9 | ////////////////////////////////////////////////////////////////////////////////// | |
10 | // display settings /////////////////////////////////////////////////////// | |
11 | ///////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #define IC_X_SEGS 480 // SSD1322 SEG has range 0-479 (479-0 if MX=1), check your datasheet, important for the orientation | |
14 | #define IC_Y_COMS 128 // SSD1322 COM has range 0-127 (127-0 if MY=1), check your datasheet, important for the orientation | |
15 | #define BPP 4 // SSD1322 has 16 gray levels | |
16 | ||
17 | #define SSD1322_CMD_ENABLE_GRAY_SCALE_TABLE 0x00 | |
18 | #define SSD1322_CMD_SET_COLUMN_ADDR 0x15 | |
19 | #define SSD1322_CMD_WRITE_RAM 0x5C | |
20 | #define SSD1322_CMD_READ_RAM 0x5D | |
21 | #define SSD1322_CMD_SET_ROW_ADDR 0x75 | |
22 | #define SSD1322_CMD_SET_REMAP 0xA0 | |
23 | #define SSD1322_CMD_SET_DISPLAY_START_LINE 0xA1 | |
24 | #define SSD1322_CMD_SET_DISPLAY_OFFSET 0xA2 | |
25 | #define SSD1322_CMD_SET_DISPLAY_MODE_OFF 0xA4 | |
26 | #define SSD1322_CMD_SET_DISPLAY_MODE_ON 0xA5 | |
27 | #define SSD1322_CMD_SET_DISPLAY_MODE_NORMAL 0xA6 | |
28 | #define SSD1322_CMD_SET_DISPLAY_MODE_INVERSE 0xA7 | |
29 | #define SSD1322_CMD_ENABLE_PARTIAL_DISPLAY 0xA8 | |
30 | #define SSD1322_CMD_EXIT_PARTIAL_DISPLAY 0xA9 | |
31 | #define SSD1322_CMD_SET_FUNCTION_SELECTION 0xAB | |
32 | #define SSD1322_CMD_SET_DISPLAY_OFF 0xAE | |
33 | #define SSD1322_CMD_SET_DISPLAY_ON 0xAF | |
34 | #define SSD1322_CMD_SET_PHASE_LENGTH 0xB1 | |
35 | #define SSD1322_CMD_SET_CLOCK_DIVIDER 0xB3 | |
36 | #define SSD1322_CMD_DISPLAY_ENHANCEMENT 0xB4 | |
37 | #define SSD1322_CMD_SET_GPIO 0xB5 | |
38 | #define SSD1322_CMD_SET_SECOND_PRECHARGE_PERIOD 0xB6 | |
39 | #define SSD1322_CMD_SET_GRAY_SCALE_TABLE 0xB8 | |
40 | #define SSD1322_CMD_SET_DEFAULT_LINEAR_GRAY_SCALE_TABLE 0xB9 | |
41 | #define SSD1322_CMD_SET_PRECHARGE_VOLTAGE 0xBB | |
42 | #define SSD1322_CMD_SET_VCOMH_VOLTAGE 0xBE | |
43 | #define SSD1322_CMD_SET_CONTRAST_CURRENT 0xC1 | |
44 | #define SSD1322_CMD_MASTER_CURRENT_CONTROL 0xC7 | |
45 | #define SSD1322_CMD_SET_MULTIPLEX_RATIO 0xCA | |
46 | #define SSD1322_CMD_DISPLAY_ENHANCEMENT_B 0xD1 | |
47 | #define SSD1322_CMD_SET_COMMAND_LOCK 0xFD | |
48 | ||
26 | 49 | // set for some OLED displays |
5 | 50 | //#define ALTERNATE_OLED_VERSION |
51 | ||
52 | ||
53 | static const uint8_t oledInit[] = { | |
54 | SSD1322_CMD_SET_COMMAND_LOCK, 1, 0x12, /* Unlock OLED driver IC*/ | |
55 | SSD1322_CMD_SET_DISPLAY_OFF, 0, | |
17
162fe523c37d
almost working... before killing the 87C51...
David Douard <david.douard@logilab.fr>
parents:
8
diff
changeset
|
56 | SSD1322_CMD_SET_CLOCK_DIVIDER, 1, 0x91,//0xF0, //max freq, was 0x91, |
5 | 57 | SSD1322_CMD_SET_MULTIPLEX_RATIO, 1, 0x3F, /*duty = 1/64*,64 COMS are enabled*/ |
58 | SSD1322_CMD_SET_DISPLAY_OFFSET, 1, 0x00, | |
59 | SSD1322_CMD_SET_DISPLAY_START_LINE, 1, 0x00, /*set start line position*/ | |
60 | SSD1322_CMD_SET_REMAP, 2, 0x14, // Horizontal address increment, | |
61 | // Disable Column Address Re-map, | |
62 | // Enable Nibble Re-map,Scan from COM[N-1] to COM0, | |
63 | // Disable COM Split Odd Even | |
64 | 0x11, // Enable Dual COM mode | |
65 | SSD1322_CMD_SET_GPIO, 1, 0x00, | |
66 | SSD1322_CMD_SET_FUNCTION_SELECTION, 1, 0x01, /* selection external VDD */ | |
67 | SSD1322_CMD_DISPLAY_ENHANCEMENT, 2, 0xA0, /* enables the external VSL*/ | |
68 | 0xfd, /* 0xfd,Enhanced low GS display quality;default is 0xb5(normal),*/ | |
69 | SSD1322_CMD_SET_CONTRAST_CURRENT, 1, 0xff, /* default is 0x7f*/ | |
70 | SSD1322_CMD_MASTER_CURRENT_CONTROL, 1, 0x0f, | |
71 | /* writeCommand(0xB9); GRAY TABLE,linear Gray Scale*/ | |
72 | SSD1322_CMD_SET_PHASE_LENGTH, 1, 0xE2, /*default is 0x74*/ | |
73 | SSD1322_CMD_DISPLAY_ENHANCEMENT_B, 2, 0x82, 0x20, | |
74 | #ifdef ALTERNATE_OLED_VERSION | |
75 | SSD1322_CMD_SET_PRECHARGE_VOLTAGE, 1, 0x08, /* 0.3xVcc */ | |
76 | SSD1322_CMD_SET_SECOND_PRECHARGE_PERIOD, 1, 0x0F, /* 15 clocks */ | |
77 | #else | |
78 | SSD1322_CMD_SET_PRECHARGE_VOLTAGE, 1, 0x1F, /* 0.6xVcc */ | |
79 | SSD1322_CMD_SET_SECOND_PRECHARGE_PERIOD, 1, 0x08, /* default */ | |
80 | #endif | |
81 | SSD1322_CMD_SET_VCOMH_VOLTAGE, 1, 0x07, /*0.86xVcc;default is 0x04*/ | |
82 | SSD1322_CMD_SET_DISPLAY_MODE_NORMAL, 0, | |
83 | SSD1322_CMD_SET_DISPLAY_ON, 0 | |
84 | }; | |
85 | ||
86 | ||
87 | //////////////////////////////////////////////////////////////////////////////////////// | |
88 | //////////////////////////////////////////////////////////////////////////////////////// | |
89 | //////////////////////////////////////////////////////////////////////////////////////// | |
90 | ||
91 | ||
92 | //#include "mbed_debug.h" | |
93 | ||
94 | #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; } | |
95 | ||
96 | ||
8 | 97 | SSD1322::SSD1322(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, |
26 | 98 | const char *name) |
5 | 99 | : GraphicsDisplay(name), |
8 | 100 | screensize_X(DISPLAY_WIDTH), screensize_Y(DISPLAY_HEIGHT), |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
101 | _PAGES(DISPLAY_HEIGHT/8*BPP), _BPP(BPP), |
8 | 102 | _IC_X_SEGS(IC_X_SEGS), _IC_Y_COMS(IC_Y_COMS), _IC_PAGES(IC_Y_COMS/8*BPP), |
103 | _spi(mosi, miso, sclk), | |
104 | _DC(DC), _CS(CS), _RST(reset) | |
5 | 105 | { |
8 | 106 | _RST = 1; |
107 | _DC = 1; | |
108 | _CS = 1; | |
109 | _spi.format(8, 0); // 8 bit spi mode 0 | |
110 | _spi.frequency(Hz); | |
5 | 111 | set_auto_up(false); |
112 | foreground(0xFFFF); | |
113 | background(0x0000); | |
114 | hw_reset(); | |
115 | init(); | |
116 | set_orientation(1); | |
117 | cls(); | |
118 | locate(0,0); | |
8 | 119 | //_internalEventCallback.attach(this, &SSD1322::_cbHandler); |
5 | 120 | } |
121 | ||
122 | void SSD1322::wr_cmd8(unsigned char cmd) | |
123 | { | |
8 | 124 | _CS = 0; |
125 | _DC.write(0); // 0=cmd | |
126 | _spi.write(cmd); // write 8bit | |
127 | _DC.write(1); // 1=data next | |
128 | _CS = 1; | |
5 | 129 | } |
130 | ||
131 | void SSD1322::wr_data8(unsigned char data) | |
132 | { | |
8 | 133 | _CS = 0; |
134 | _spi.write(data); // write 8bit | |
135 | _CS = 1; | |
5 | 136 | |
137 | } | |
138 | ||
139 | void SSD1322::hw_reset() | |
140 | { | |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
141 | ThisThread::sleep_for(15ms); |
8 | 142 | _DC = 1; |
143 | _CS = 1; | |
144 | _RST = 0; // display reset | |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
145 | ThisThread::sleep_for(2ms); |
8 | 146 | _RST = 1; // end reset |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
147 | ThisThread::sleep_for(100ms); |
5 | 148 | } |
149 | ||
150 | void SSD1322::bus_enable(bool enable) | |
151 | { | |
8 | 152 | _CS = enable ? 0:1; |
5 | 153 | } |
154 | ||
155 | ||
156 | // monochrome SSD1322 driver ICs does not have ram rotate in hw (swap raw<->columns) like TFT displays | |
157 | // for portrait views, XY swap will be done in sw in pixel() function | |
158 | void SSD1322::set_orientation(int o) | |
159 | { | |
160 | orientation = o; | |
161 | if (o & 0x01) { | |
162 | set_width(screensize_X); | |
163 | set_height(screensize_Y); | |
164 | } else { | |
165 | set_width(screensize_Y); | |
166 | set_height(screensize_X); | |
26 | 167 | } |
5 | 168 | switch (o) { |
169 | case (0):// portrait view -90° | |
170 | mirrorXY(Y); | |
171 | break; | |
172 | case (1): // default, landscape view 0° | |
173 | mirrorXY(NONE); | |
174 | break; | |
175 | case (2):// portrait view +90° | |
176 | mirrorXY(X); | |
177 | break; | |
178 | case (3):// landscape view +180° | |
179 | mirrorXY(XY); | |
180 | break; | |
181 | } | |
182 | } | |
183 | ||
184 | void SSD1322::mirrorXY(mirror_t mode) | |
185 | { | |
186 | // Horizontal address increment, | |
187 | // Disable Column Address Re-map, | |
188 | // Enable Nibble Re-map,Scan from COM[N-1] to COM0, | |
189 | // Disable COM Split Odd Even | |
190 | // Enable Dual COM mode | |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
191 | unsigned char d = 0; |
5 | 192 | switch (mode) |
193 | { | |
194 | case(NONE): | |
195 | d = 0x14; | |
196 | break; | |
197 | case(X): | |
198 | d = 0x10; | |
199 | break; | |
200 | case(Y): | |
201 | d = 0x16; | |
202 | break; | |
203 | case(XY): | |
204 | d = 0x12; | |
26 | 205 | break; |
5 | 206 | } |
26 | 207 | wr_cmd8(SSD1322_CMD_SET_REMAP); |
5 | 208 | wr_data8(d); |
26 | 209 | wr_data8(0x11); |
5 | 210 | } |
211 | ||
212 | void SSD1322::invert(unsigned char o) | |
213 | { | |
8 | 214 | if(o == 0) wr_cmd8(SSD1322_CMD_SET_DISPLAY_MODE_NORMAL); |
215 | else wr_cmd8(SSD1322_CMD_SET_DISPLAY_MODE_INVERSE); | |
5 | 216 | } |
217 | ||
218 | void SSD1322::set_contrast(int o) | |
219 | { | |
220 | contrast = o; | |
221 | ||
222 | wr_cmd8(SSD1322_CMD_SET_CONTRAST_CURRENT); | |
223 | wr_data8(o&0xFF); | |
224 | } | |
225 | ||
226 | int SSD1322::get_contrast(void) | |
227 | { | |
228 | return(contrast); | |
229 | } | |
230 | void SSD1322::window(int x, int y, int w, int h) { | |
231 | // current pixel location | |
232 | cur_x = x; | |
233 | cur_y = y; | |
234 | // window settings | |
235 | win_x1 = x; | |
236 | win_x2 = x + w - 1; | |
237 | win_y1 = y; | |
238 | win_y2 = y + h - 1; | |
239 | } | |
240 | void SSD1322::window_pushpixel(unsigned short color) { | |
8 | 241 | pixel(cur_x, cur_y, color); |
242 | cur_x++; | |
243 | if(cur_x > win_x2) { | |
244 | cur_x = win_x1; | |
245 | cur_y++; | |
246 | if(cur_y > win_y2) { | |
247 | cur_y = win_y1; | |
5 | 248 | } |
8 | 249 | } |
5 | 250 | } |
251 | void SSD1322::window_pushpixel(unsigned short color, unsigned int count) { | |
8 | 252 | while(count) |
5 | 253 | { |
8 | 254 | pixel(cur_x, cur_y, color); |
255 | cur_x++; | |
256 | if(cur_x > win_x2) | |
5 | 257 | { |
8 | 258 | cur_x = win_x1; |
259 | cur_y++; | |
260 | if(cur_y > win_y2) | |
5 | 261 | { |
8 | 262 | cur_y = win_y1; |
5 | 263 | } |
264 | } | |
8 | 265 | count--; |
5 | 266 | } |
267 | } | |
26 | 268 | |
5 | 269 | void SSD1322::window_pushpixelbuf(unsigned short* color, unsigned int lenght) { |
8 | 270 | while(lenght) |
5 | 271 | { |
8 | 272 | pixel(cur_x, cur_y, *color++); |
273 | cur_x++; | |
274 | if(cur_x > win_x2) | |
5 | 275 | { |
8 | 276 | cur_x = win_x1; |
277 | cur_y++; | |
278 | if(cur_y > win_y2) | |
5 | 279 | { |
8 | 280 | cur_y = win_y1; |
5 | 281 | } |
282 | } | |
8 | 283 | lenght--; |
5 | 284 | } |
285 | } | |
286 | ||
287 | unsigned short SSD1322::pixelpos(int x, int y) | |
288 | { | |
289 | if(!(orientation&1)) SWAP(x,y); | |
290 | // first check parameter | |
291 | if((x >= screensize_X) || (y >= screensize_Y)) return 0; | |
292 | ||
293 | unsigned short page = y * _BPP / 8; | |
294 | return (x + page*screensize_X); | |
295 | } | |
296 | ||
297 | void SSD1322::pixel(int x, int y, unsigned short color) | |
298 | { | |
299 | if(!(orientation&1)) SWAP(x,y); | |
300 | // first check parameter | |
301 | if((x >= screensize_X) || (y >= screensize_Y)) return; | |
302 | ||
303 | /* | |
304 | unsigned short page = y * _BPP / 8; | |
305 | unsigned char pos = y & ((8 / _BPP) - 1); // position in page | |
306 | unsigned char mask = (( 1 << _BPP) - 1); | |
307 | ||
308 | buffer[(x + page*screensize_X)] = (buffer[(x + page*screensize_X)] & ~(mask<<(pos*_BPP))) | ((color&mask)<<(pos*_BPP)); | |
309 | */ | |
310 | ||
8 | 311 | unsigned char cval = _pixelBuffer[(y*128) + x/2]; |
5 | 312 | if (x&1) { |
313 | cval = (cval & 0xF0) | (color & 0x0F); | |
314 | } else { | |
315 | cval = (cval & 0x0F) | (color & 0x0F)<<4; | |
316 | } | |
8 | 317 | _pixelBuffer[(y*128) + x/2] = cval; |
5 | 318 | } |
319 | ||
320 | unsigned short SSD1322::pixelread(int x, int y) | |
321 | { | |
322 | if(!(orientation&1)) SWAP(x,y); | |
323 | // first check parameter | |
324 | if((x >= screensize_X) || (y >= screensize_Y)) return 0; | |
325 | ||
326 | unsigned short page = y * _BPP / 8; | |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
327 | /* to be used in correct implementation... |
5 | 328 | unsigned char pos = y & ((8 / _BPP) - 1); // position in page |
329 | unsigned char mask = (( 1 << _BPP) - 1); | |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
330 | */ |
5 | 331 | //FAUX |
8 | 332 | return (_pixelBuffer[(x + page*screensize_X)]); // = (_pixelBuffer[(x + page*screensize_X)] & ~(mask<<(pos*_BPP))) | ((color&mask)<<(pos*_BPP)); |
5 | 333 | } |
334 | ||
335 | ||
336 | ||
6
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
337 | // Set row address 0~64 |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
338 | void SSD1322::set_row_address(unsigned char start_row, unsigned char end_row) |
5 | 339 | { |
340 | wr_cmd8(SSD1322_CMD_SET_ROW_ADDR); | |
6
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
341 | start_row &= 0x3F; |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
342 | wr_data8(start_row); |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
343 | end_row &= 0x3F; |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
344 | wr_data8(end_row); |
5 | 345 | } |
346 | ||
347 | // Set col address 0~64 for Gray mode) | |
6
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
348 | void SSD1322::set_column_address(unsigned char start_col, unsigned char end_col) |
5 | 349 | { |
350 | wr_cmd8(SSD1322_CMD_SET_COLUMN_ADDR); | |
6
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
351 | start_col = (start_col & 0x3F) + 0x1C; |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
352 | wr_data8(start_col); // where does this 0x1C (28) comes from??? |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
353 | end_col = (end_col & 0x3F) + 0x1C; |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
354 | wr_data8(end_col); |
5 | 355 | } |
356 | ||
357 | void SSD1322::copy_to_lcd(void) | |
358 | { | |
45 | 359 | pixel_buffer_mutex.lock(); |
8 | 360 | memcpy((void*)_trBuffer, |
26 | 361 | (const void*)_pixelBuffer, |
362 | DISPLAY_BUFFER_ELEMENTS * sizeof(DISPLAY_BUFFER_TYPE)); | |
45 | 363 | pixel_buffer_mutex.unlock(); |
26 | 364 | |
45 | 365 | set_row_address(0); |
366 | set_column_address(0); | |
8 | 367 | wr_cmd8(SSD1322_CMD_WRITE_RAM); |
368 | ||
17
162fe523c37d
almost working... before killing the 87C51...
David Douard <david.douard@logilab.fr>
parents:
8
diff
changeset
|
369 | #ifdef DEVICE_SPI_ASYNCH |
162fe523c37d
almost working... before killing the 87C51...
David Douard <david.douard@logilab.fr>
parents:
8
diff
changeset
|
370 | _CS = 0; |
162fe523c37d
almost working... before killing the 87C51...
David Douard <david.douard@logilab.fr>
parents:
8
diff
changeset
|
371 | _spi.transfer((uint8_t*) _trBuffer, 64*128, (uint8_t*) NULL, 0, _spiEventCb); |
162fe523c37d
almost working... before killing the 87C51...
David Douard <david.douard@logilab.fr>
parents:
8
diff
changeset
|
372 | #else |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
373 | unsigned int x, y; |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
374 | unsigned int i; |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
375 | |
5 | 376 | i = 0; |
26 | 377 | for(y=0; y<64; y++) |
378 | for(x=0; x<128; x++) | |
8 | 379 | wr_data8(_trBuffer[i++]); |
17
162fe523c37d
almost working... before killing the 87C51...
David Douard <david.douard@logilab.fr>
parents:
8
diff
changeset
|
380 | #endif |
5 | 381 | } |
382 | ||
6
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
383 | void SSD1322::copy_to_lcd(unsigned char from_col, unsigned char to_col, |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
384 | unsigned char from_row, unsigned char to_row) |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
385 | { |
8 | 386 | unsigned int x, y; |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
6
diff
changeset
|
387 | if (to_col>0x3F) |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
6
diff
changeset
|
388 | to_col = 0x3F; |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
6
diff
changeset
|
389 | if (to_row>0x3F) |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
6
diff
changeset
|
390 | to_row = 0x3F; |
8 | 391 | |
392 | memcpy((void*)_trBuffer, | |
26 | 393 | (const void*)_pixelBuffer, |
394 | DISPLAY_BUFFER_ELEMENTS * sizeof(DISPLAY_BUFFER_TYPE)); | |
395 | ||
6
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
396 | set_row_address(from_row, to_row); |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
397 | set_column_address(from_col, to_col); |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
398 | |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
399 | wr_cmd8(SSD1322_CMD_WRITE_RAM); |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
400 | for(y=from_row; y<=to_row; y++) { |
26 | 401 | for(x=from_col; x<=to_col; x++) { |
8 | 402 | wr_data8(_trBuffer[y*128 + 2*x]); |
403 | wr_data8(_trBuffer[y*128 + 2*x + 1]); | |
6
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
404 | } |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
405 | } |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
406 | } |
8cb67d7afd79
[SSD1322] add a copy_to_lcd method that accepts an area
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
407 | |
5 | 408 | unsigned long SSD1322::buffaddr(unsigned int i) |
409 | { | |
8 | 410 | return (unsigned long) &(_pixelBuffer[i]); |
5 | 411 | } |
412 | ||
413 | void SSD1322::clrbuff(const unsigned char value) | |
414 | { | |
8 | 415 | memset((void*)_pixelBuffer, value, screensize_X*_PAGES); |
5 | 416 | } |
417 | ||
418 | void SSD1322::fills(const unsigned char value) | |
419 | { | |
8 | 420 | clrbuff(value); |
421 | copy_to_lcd(); | |
5 | 422 | } |
423 | ||
424 | void SSD1322::cls(void) | |
425 | { | |
8 | 426 | clrbuff(); |
427 | copy_to_lcd(); | |
5 | 428 | } |
429 | ||
430 | ||
431 | // reset and init the lcd controller | |
432 | void SSD1322::init() | |
433 | { | |
40
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
434 | /* Start Initial Sequence ----------------------------------------------------*/ |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
435 | for (uint16_t ind=0; ind < sizeof(oledInit); ) { |
5 | 436 | wr_cmd8(oledInit[ind++]); |
437 | uint8_t dataSize = oledInit[ind++]; | |
438 | while (dataSize--) { | |
439 | wr_data8(oledInit[ind++]); | |
440 | } | |
40
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
441 | } |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
442 | } |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
443 | |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
444 | void SSD1322::power_off() |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
445 | { |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
446 | wr_cmd8(SSD1322_CMD_SET_DISPLAY_OFF); |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
447 | } |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
448 | |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
449 | void SSD1322::power_on() |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
450 | { |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
451 | wr_cmd8(SSD1322_CMD_SET_DISPLAY_ON); |
069bbd5ee3e4
SSD1322: add power off/on methods
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
452 | } |