|
1 #ifndef MBED_SSD1322_H |
|
2 #define MBED_SSD1322_H |
|
3 |
|
4 #include "mbed.h" |
|
5 |
|
6 #include "SPI8.h" |
|
7 |
|
8 #include "Protocols.h" |
|
9 #include "GraphicsDisplay.h" |
|
10 |
|
11 /** Mirror mode */ |
|
12 enum mirror_t {X,Y,XY,NONE}; |
|
13 |
|
14 /** A common base class for monochrome Display |
|
15 */ |
|
16 class SSD1322 : public GraphicsDisplay |
|
17 { |
|
18 |
|
19 public: |
|
20 |
|
21 |
|
22 /** Create a monochrome SSD1322 SPI interface |
|
23 * @param name The name used by the parent class to access the interface |
|
24 */ |
|
25 SSD1322(proto_t displayproto, |
|
26 int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, |
|
27 const char* name, |
|
28 const unsigned int lcdsize_x=128, const unsigned int lcdsize_y=64); |
|
29 |
|
30 /** Destructor |
|
31 * will free framebuffer |
|
32 */ |
|
33 virtual ~SSD1322(); |
|
34 |
|
35 |
|
36 |
|
37 /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// |
|
38 /////// ----------------------------------------------------/////////////////////////////////////////////////// |
|
39 |
|
40 /** Draw a pixel in the specified color. |
|
41 * @param x is the horizontal offset to this pixel. |
|
42 * @param y is the vertical offset to this pixel. |
|
43 * @param color defines the color for the pixel. |
|
44 */ |
|
45 virtual void pixel(int x, int y, unsigned short color); |
|
46 |
|
47 /** Set the window, which controls where items are written to the screen. |
|
48 * When something hits the window width, it wraps back to the left side |
|
49 * and down a row. If the initial write is outside the window, it will |
|
50 * be captured into the window when it crosses a boundary. |
|
51 * @param x is the left edge in pixels. |
|
52 * @param y is the top edge in pixels. |
|
53 * @param w is the window width in pixels. |
|
54 * @param h is the window height in pixels. |
|
55 */ |
|
56 virtual void window(int x, int y, int w, int h); |
|
57 |
|
58 /** Read pixel color at location |
|
59 * @param x is the horizontal offset to this pixel. |
|
60 * @param y is the vertical offset to this pixel. |
|
61 * @returns 16bit color, 0000=Black(pixel set), FFFF=White(pixel clear). |
|
62 */ |
|
63 virtual unsigned short pixelread(int x, int y); |
|
64 |
|
65 /** Push a single pixel into the window and increment position. |
|
66 * You must first call window() then push pixels in loop. |
|
67 * @param color is the pixel color. |
|
68 */ |
|
69 virtual void window_pushpixel(unsigned short color); |
|
70 |
|
71 /** Push some pixels of the same color into the window and increment position. |
|
72 * You must first call window() then push pixels. |
|
73 * @param color is the pixel color. |
|
74 * @param count: how many |
|
75 */ |
|
76 virtual void window_pushpixel(unsigned short color, unsigned int count); |
|
77 |
|
78 /** Push array of pixel colors into the window and increment position. |
|
79 * You must first call window() then push pixels. |
|
80 * @param color is the pixel color. |
|
81 */ |
|
82 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght); |
|
83 |
|
84 /** Framebuffer is used, it needs to be sent to SSD1322 from time to time |
|
85 */ |
|
86 virtual void copy_to_lcd(); |
|
87 |
|
88 /** set the contrast of the screen |
|
89 * |
|
90 * @param o contrast 0-63 |
|
91 * @note may be overrided in case of not standard command |
|
92 */ |
|
93 virtual void set_contrast(int o); |
|
94 |
|
95 /** read the contrast level |
|
96 * |
|
97 */ |
|
98 int get_contrast(void); |
|
99 |
|
100 /** display inverted colors |
|
101 * |
|
102 * @param o = 0 normal, 1 invert |
|
103 */ |
|
104 void invert(unsigned char o); |
|
105 |
|
106 /** clear the entire screen |
|
107 * The inherited one sets windomax then fill with background color |
|
108 * We override it to speedup |
|
109 */ |
|
110 virtual void cls(); |
|
111 |
|
112 /** Set the orientation of the screen |
|
113 * x,y: 0,0 is always top left |
|
114 * |
|
115 * @param o direction to use the screen (0-3) |
|
116 * 0 = -90° |
|
117 * 1 = default 0° |
|
118 * 2 = +90° |
|
119 * 3 = +180° |
|
120 * |
|
121 */ |
|
122 void set_orientation(int o); |
|
123 |
|
124 /** Set ChipSelect high or low |
|
125 * @param enable 0/1 |
|
126 */ |
|
127 virtual void bus_enable(bool enable); |
|
128 |
|
129 /** get display X size in pixels (native, orientation independent) |
|
130 * @returns X size in pixels |
|
131 */ |
|
132 int sizeX(); |
|
133 |
|
134 /** get display Y size in pixels (native, orientation independent) |
|
135 * @returns Y size in pixels |
|
136 */ |
|
137 int sizeY(); |
|
138 |
|
139 //////////////////////////////////////////////////////////////////////////////// |
|
140 // not implemented yet |
|
141 ////////////////////////////////////////////////////////////////// |
|
142 // virtual unsigned short pixelread(int x, int y){return 0;}; |
|
143 virtual void window4read(int x, int y, int w, int h){}; |
|
144 void setscrollarea (int startY, int areasize){}; |
|
145 void scroll (int lines){}; |
|
146 void scrollreset(){}; |
|
147 void FastWindow(bool enable){}; |
|
148 |
|
149 unsigned int buffsize() { return _PAGES*screensize_X;}; |
|
150 unsigned short pixelpos(int x, int y); |
|
151 void clrbuff(const unsigned char value=0x00); |
|
152 unsigned long buffaddr(unsigned int i); |
|
153 void fills(const unsigned char value=0xFF); |
|
154 void ll_fill(const unsigned char value=0xFF, const unsigned char w=0x78, const unsigned char=0x80); |
|
155 void set_row_address(unsigned char add); |
|
156 void set_column_address(unsigned char add); |
|
157 |
|
158 void start_loop(float tick); |
|
159 void stop_loop(void); |
|
160 |
|
161 protected: |
|
162 /** Setup some stuff (malloc the buffer, etc) |
|
163 */ |
|
164 void init(); |
|
165 |
|
166 /** set mirror mode |
|
167 * @note may be overridden by specific display init class in case of not standard cmds or inverted wiring |
|
168 * @param mode NONE, X, Y, XY |
|
169 */ |
|
170 virtual void mirrorXY(mirror_t mode); |
|
171 |
|
172 ////// functions needed by parent class /////////////////////////////////////// |
|
173 ////// -------------------------------- /////////////////////////////////////// |
|
174 |
|
175 /** Send 8bit command to display controller |
|
176 * |
|
177 * @param cmd: byte to send |
|
178 * @note if protocol is SPI16, it will insert NOP cmd before, so if cmd is a 2byte cmd, the second cmd will be broken. Use wr_cmd16 for 2bytes cmds |
|
179 */ |
|
180 void wr_cmd8(unsigned char cmd); |
|
181 |
|
182 /** Send 8bit data to display controller |
|
183 * |
|
184 * @param data: byte to send |
|
185 * |
|
186 */ |
|
187 void wr_data8(unsigned char data); |
|
188 |
|
189 /** Send 16bit command to display controller |
|
190 * |
|
191 * @param cmd: halfword to send |
|
192 * |
|
193 */ |
|
194 void wr_cmd16(unsigned short cmd); |
|
195 |
|
196 /** Send same 16bit pixeldata to display controller multiple times |
|
197 * |
|
198 * @param data: halfword to send |
|
199 * @param count: how many |
|
200 * |
|
201 */ |
|
202 virtual void wr_gram(unsigned short data, unsigned int count); |
|
203 |
|
204 /** Send array of pixeldata shorts to display controller |
|
205 * |
|
206 * @param data: unsigned short pixeldata array |
|
207 * @param lenght: lenght (in shorts) |
|
208 * |
|
209 */ |
|
210 virtual void wr_grambuf(unsigned short* data, unsigned int lenght); |
|
211 |
|
212 /** HW reset sequence (without display init commands) |
|
213 */ |
|
214 void hw_reset(); |
|
215 |
|
216 int contrast; |
|
217 void loop_event(void); |
|
218 |
|
219 protected: |
|
220 |
|
221 Protocols* proto; |
|
222 unsigned char *buffer; |
|
223 const int screensize_X; |
|
224 const int screensize_Y; |
|
225 const int _PAGES; |
|
226 const int _BPP; |
|
227 const int _IC_X_SEGS; |
|
228 const int _IC_Y_COMS; |
|
229 const int _IC_PAGES; |
|
230 |
|
231 Ticker bah; |
|
232 int loop_pos; |
|
233 // pixel location |
|
234 int cur_x; |
|
235 int cur_y; |
|
236 // window location |
|
237 int win_x1; |
|
238 int win_x2; |
|
239 int win_y1; |
|
240 int win_y2; |
|
241 int orientation; |
|
242 }; |
|
243 |
|
244 #endif |