lib/unigraphic/SSD1322.cpp

Tue, 11 Oct 2016 00:46:18 +0200

author
David Douard <david.douard@logilab.fr>
date
Tue, 11 Oct 2016 00:46:18 +0200
changeset 9
e5254c6aa0c8
parent 8
55021f3f1929
child 17
162fe523c37d
permissions
-rw-r--r--

use only one USART

with a front "AND" gate to combine both serial lines

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

mercurial