lib/unigraphic/SSD1322.cpp

Mon, 11 Mar 2024 15:35:36 +0100

author
David Douard <david.douard@sdf3.org>
date
Mon, 11 Mar 2024 15:35:36 +0100
changeset 71
d193c24a078a
parent 66
48f29a1d43d6
permissions
-rw-r--r--

Add links to sr.ht repos and add an image in the README file

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 */
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
5
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
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
49 // set for some OLED displays
5
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,
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
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,
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
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),
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
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 {
66
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 45
diff changeset
141 ThisThread::sleep_for(15ms);
8
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
66
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 45
diff changeset
145 ThisThread::sleep_for(2ms);
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
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
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);
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
167 }
5
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
66
48f29a1d43d6 Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents: 45
diff changeset
191 unsigned char d = 0;
5
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;
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
205 break;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
206 }
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
207 wr_cmd8(SSD1322_CMD_SET_REMAP);
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
208 wr_data8(d);
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
209 wr_data8(0x11);
5
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 }
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
268
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
269 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
270 while(lenght)
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
271 {
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
272 pixel(cur_x, cur_y, *color++);
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
273 cur_x++;
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
274 if(cur_x > win_x2)
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
275 {
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
276 cur_x = win_x1;
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
277 cur_y++;
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
278 if(cur_y > win_y2)
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
279 {
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
280 cur_y = win_y1;
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
281 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
282 }
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
283 lenght--;
5
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
287 unsigned short SSD1322::pixelpos(int x, int y)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
288 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
289 if(!(orientation&1)) SWAP(x,y);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
290 // first check parameter
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
291 if((x >= screensize_X) || (y >= screensize_Y)) return 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
292
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
293 unsigned short page = y * _BPP / 8;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
294 return (x + page*screensize_X);
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
297 void SSD1322::pixel(int x, int y, unsigned short color)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
298 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
299 if(!(orientation&1)) SWAP(x,y);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
300 // first check parameter
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
301 if((x >= screensize_X) || (y >= screensize_Y)) return;
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 /*
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
304 unsigned short page = y * _BPP / 8;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
305 unsigned char pos = y & ((8 / _BPP) - 1); // position in page
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
306 unsigned char mask = (( 1 << _BPP) - 1);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
307
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
308 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
309 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
310
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
311 unsigned char cval = _pixelBuffer[(y*128) + x/2];
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
312 if (x&1) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
313 cval = (cval & 0xF0) | (color & 0x0F);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
314 } else {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
315 cval = (cval & 0x0F) | (color & 0x0F)<<4;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
316 }
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
317 _pixelBuffer[(y*128) + x/2] = cval;
5
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
320 unsigned short SSD1322::pixelread(int x, int y)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
321 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
322 if(!(orientation&1)) SWAP(x,y);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
323 // first check parameter
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
324 if((x >= screensize_X) || (y >= screensize_Y)) return 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
325
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
328 unsigned char pos = y & ((8 / _BPP) - 1); // position in page
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
331 //FAUX
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
332 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
333 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
334
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
335
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
339 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
345 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
346
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
349 {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
355 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
356
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
357 void SSD1322::copy_to_lcd(void)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
358 {
45
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 40
diff changeset
359 pixel_buffer_mutex.lock();
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
360 memcpy((void*)_trBuffer,
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
361 (const void*)_pixelBuffer,
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
362 DISPLAY_BUFFER_ELEMENTS * sizeof(DISPLAY_BUFFER_TYPE));
45
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 40
diff changeset
363 pixel_buffer_mutex.unlock();
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
364
45
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 40
diff changeset
365 set_row_address(0);
2da50a3d4e9f Adjust font rendering
David Douard <david.douard@sdf3.org>
parents: 40
diff changeset
366 set_column_address(0);
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
367 wr_cmd8(SSD1322_CMD_WRITE_RAM);
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
376 i = 0;
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
377 for(y=0; y<64; y++)
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
378 for(x=0; x<128; x++)
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
381 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
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
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
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
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
391
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
392 memcpy((void*)_trBuffer,
26
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
393 (const void*)_pixelBuffer,
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
394 DISPLAY_BUFFER_ELEMENTS * sizeof(DISPLAY_BUFFER_TYPE));
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
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
86f099bda525 Several stuff
David Douard <david.douard@sdfa3.org>
parents: 17
diff changeset
401 for(x=from_col; x<=to_col; x++) {
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
402 wr_data8(_trBuffer[y*128 + 2*x]);
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
408 unsigned long SSD1322::buffaddr(unsigned int i)
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 return (unsigned long) &(_pixelBuffer[i]);
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
411 }
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 void SSD1322::clrbuff(const unsigned char value)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
414 {
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
415 memset((void*)_pixelBuffer, value, screensize_X*_PAGES);
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
416 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
417
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
418 void SSD1322::fills(const unsigned char value)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
419 {
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
420 clrbuff(value);
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
421 copy_to_lcd();
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
422 }
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 void SSD1322::cls(void)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
425 {
8
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
426 clrbuff();
55021f3f1929 pff so many stuff
David Douard <david.douard@logilab.fr>
parents: 7
diff changeset
427 copy_to_lcd();
5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
428 }
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
429
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 // reset and init the lcd controller
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
432 void SSD1322::init()
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
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
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
436 wr_cmd8(oledInit[ind++]);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
437 uint8_t dataSize = oledInit[ind++];
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
438 while (dataSize--) {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
439 wr_data8(oledInit[ind++]);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
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 }

mercurial