1 #ifndef MBED_SSD1322_H |
1 #ifndef MBED_SSD1322_H |
2 #define MBED_SSD1322_H |
2 #define MBED_SSD1322_H |
3 |
3 |
4 #include "mbed.h" |
4 #include "mbed.h" |
5 |
|
6 #include "SPI8.h" |
|
7 |
|
8 #include "Protocols.h" |
|
9 #include "GraphicsDisplay.h" |
5 #include "GraphicsDisplay.h" |
10 |
6 |
|
7 //Display module specs |
|
8 #define DISPLAY_WIDTH (256) |
|
9 #define DISPLAY_HEIGHT (64) |
|
10 #define DISPLAY_BUFFER_TYPE uint8_t |
|
11 #define DISPLAY_BUFFER_TYPE_SIZE (2) // 2 pixel / byte |
|
12 #define DISPLAY_BUFFER_ELEMENTS 8192 // 256*64 / 2 (because 2 pixels/byte) |
|
13 |
|
14 |
11 /** Mirror mode */ |
15 /** Mirror mode */ |
12 enum mirror_t {X,Y,XY,NONE}; |
16 enum mirror_t {X, Y, XY, NONE}; |
|
17 |
|
18 typedef enum { |
|
19 IDLE, // No operation currently ongoing |
|
20 CLEARING, // In the process of clearing the display |
|
21 WRITING, // In the process of sending a display update |
|
22 WAIT_CLEAR, // Going to clear after CS pin timeout |
|
23 WAIT_WRITE, // Going to write after CS pin timeout |
|
24 TRANSFERS_DONE, // Last transfer in progress |
|
25 DONE, // Done with transmission, waiting for CS pin to become high |
|
26 } SSD1322_state_t; |
13 |
27 |
14 /** A common base class for monochrome Display |
28 /** A common base class for monochrome Display |
15 */ |
29 */ |
16 class SSD1322 : public GraphicsDisplay |
30 class SSD1322: public GraphicsDisplay |
17 { |
31 { |
18 |
32 |
19 public: |
33 public: |
20 |
34 |
21 |
35 |
22 /** Create a monochrome SSD1322 SPI interface |
36 /** Create a monochrome SSD1322 SPI interface |
23 * @param name The name used by the parent class to access the interface |
37 * @param name The name used by the parent class to access the interface |
24 */ |
38 */ |
25 SSD1322(proto_t displayproto, |
39 SSD1322(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, |
26 int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, |
40 const char* name); |
27 const char* name, |
|
28 const unsigned int lcdsize_x=128, const unsigned int lcdsize_y=64); |
|
29 |
41 |
30 /** Destructor |
42 /** Destructor |
31 * will free framebuffer |
43 * will free framebuffer |
32 */ |
44 */ |
33 virtual ~SSD1322(); |
45 virtual ~SSD1322() {}; |
34 |
46 |
35 |
47 |
36 |
48 |
37 /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// |
49 /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// |
38 /////// ----------------------------------------------------/////////////////////////////////////////////////// |
50 /////// ----------------------------------------------------/////////////////////////////////////////////////// |
127 virtual void bus_enable(bool enable); |
139 virtual void bus_enable(bool enable); |
128 |
140 |
129 /** get display X size in pixels (native, orientation independent) |
141 /** get display X size in pixels (native, orientation independent) |
130 * @returns X size in pixels |
142 * @returns X size in pixels |
131 */ |
143 */ |
132 int sizeX(); |
144 int sizeX() {return screensize_X;}; |
133 |
145 |
134 /** get display Y size in pixels (native, orientation independent) |
146 /** get display Y size in pixels (native, orientation independent) |
135 * @returns Y size in pixels |
147 * @returns Y size in pixels |
136 */ |
148 */ |
137 int sizeY(); |
149 int sizeY() {return screensize_Y;}; |
138 |
150 |
139 //////////////////////////////////////////////////////////////////////////////// |
151 //////////////////////////////////////////////////////////////////////////////// |
140 // not implemented yet |
152 // not implemented yet |
141 ////////////////////////////////////////////////////////////////// |
153 ////////////////////////////////////////////////////////////////// |
142 // virtual unsigned short pixelread(int x, int y){return 0;}; |
154 // virtual unsigned short pixelread(int x, int y){return 0;}; |
149 unsigned int buffsize() { return _PAGES*screensize_X;}; |
161 unsigned int buffsize() { return _PAGES*screensize_X;}; |
150 unsigned short pixelpos(int x, int y); |
162 unsigned short pixelpos(int x, int y); |
151 void clrbuff(const unsigned char value=0x00); |
163 void clrbuff(const unsigned char value=0x00); |
152 unsigned long buffaddr(unsigned int i); |
164 unsigned long buffaddr(unsigned int i); |
153 void fills(const unsigned char value=0xFF); |
165 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); |
166 |
155 void set_row_address(unsigned char start_row=0x00, unsigned char end_row=0x3F); |
167 void set_row_address(unsigned char start_row=0x00, unsigned char end_row=0x3F); |
156 void set_column_address(unsigned char start_col=0x00, unsigned char end_col=0x3F); |
168 void set_column_address(unsigned char start_col=0x00, unsigned char end_col=0x3F); |
157 |
|
158 void start_loop(float tick); |
|
159 void stop_loop(void); |
|
160 |
169 |
161 virtual void copy_to_lcd(unsigned char from_col, unsigned char to_col, |
170 virtual void copy_to_lcd(unsigned char from_col, unsigned char to_col, |
162 unsigned char from_row, unsigned char to_row); |
171 unsigned char from_row, unsigned char to_row); |
163 |
172 |
164 protected: |
173 protected: |
186 * |
195 * |
187 * @param data: byte to send |
196 * @param data: byte to send |
188 * |
197 * |
189 */ |
198 */ |
190 void wr_data8(unsigned char data); |
199 void wr_data8(unsigned char data); |
191 |
200 |
192 /** Send 16bit command to display controller |
|
193 * |
|
194 * @param cmd: halfword to send |
|
195 * |
|
196 */ |
|
197 void wr_cmd16(unsigned short cmd); |
|
198 |
|
199 /** Send same 16bit pixeldata to display controller multiple times |
|
200 * |
|
201 * @param data: halfword to send |
|
202 * @param count: how many |
|
203 * |
|
204 */ |
|
205 virtual void wr_gram(unsigned short data, unsigned int count); |
|
206 |
|
207 /** Send array of pixeldata shorts to display controller |
|
208 * |
|
209 * @param data: unsigned short pixeldata array |
|
210 * @param lenght: lenght (in shorts) |
|
211 * |
|
212 */ |
|
213 virtual void wr_grambuf(unsigned short* data, unsigned int lenght); |
|
214 |
|
215 /** HW reset sequence (without display init commands) |
201 /** HW reset sequence (without display init commands) |
216 */ |
202 */ |
217 void hw_reset(); |
203 void hw_reset(); |
218 |
204 |
219 int contrast; |
205 int contrast; |
220 void loop_event(void); |
|
221 |
206 |
222 protected: |
207 protected: |
223 |
208 |
224 Protocols* proto; |
209 mbed::SPI _spi; |
225 unsigned char *buffer; |
210 DigitalOut _CS; |
|
211 DigitalOut _RST; |
|
212 DigitalOut _DC; |
|
213 volatile DISPLAY_BUFFER_TYPE _pixelBuffer[DISPLAY_BUFFER_ELEMENTS]; // one full frame buffer |
|
214 DISPLAY_BUFFER_TYPE _trBuffer[DISPLAY_BUFFER_ELEMENTS]; // for sending |
|
215 |
226 const int screensize_X; |
216 const int screensize_X; |
227 const int screensize_Y; |
217 const int screensize_Y; |
228 const int _PAGES; |
218 const int _PAGES; |
229 const int _BPP; |
219 const int _BPP; |
230 const int _IC_X_SEGS; |
220 const int _IC_X_SEGS; |
231 const int _IC_Y_COMS; |
221 const int _IC_Y_COMS; |
232 const int _IC_PAGES; |
222 const int _IC_PAGES; |
233 |
223 |
234 Ticker bah; |
|
235 int loop_pos; |
|
236 // pixel location |
224 // pixel location |
237 int cur_x; |
225 int cur_x; |
238 int cur_y; |
226 int cur_y; |
239 // window location |
227 // window location |
240 int win_x1; |
228 int win_x1; |
241 int win_x2; |
229 int win_x2; |
242 int win_y1; |
230 int win_y1; |
243 int win_y2; |
231 int win_y2; |
244 int orientation; |
232 int orientation; |
|
233 |
|
234 SSD1322_state_t _state; |
|
235 |
245 }; |
236 }; |
246 |
237 |
247 #endif |
238 #endif |