28 /** A common base class for monochrome Display |
28 /** A common base class for monochrome Display |
29 */ |
29 */ |
30 class SSD1322: public GraphicsDisplay |
30 class SSD1322: public GraphicsDisplay |
31 { |
31 { |
32 |
32 |
33 public: |
33 public: |
34 |
34 |
35 |
35 |
36 /** Create a monochrome SSD1322 SPI interface |
36 /** Create a monochrome SSD1322 SPI interface |
37 * @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 |
38 */ |
38 */ |
39 SSD1322(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, |
39 SSD1322(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, |
40 const char* name); |
40 const char* name); |
41 |
41 |
42 /** Destructor |
42 /** Destructor |
43 * will free framebuffer |
43 * will free framebuffer |
44 */ |
44 */ |
45 virtual ~SSD1322() {}; |
45 virtual ~SSD1322() {}; |
46 |
46 |
47 |
47 |
48 |
48 |
49 /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// |
49 /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// |
50 /////// ----------------------------------------------------/////////////////////////////////////////////////// |
50 /////// ----------------------------------------------------/////////////////////////////////////////////////// |
51 |
51 |
52 /** Draw a pixel in the specified color. |
52 /** Draw a pixel in the specified color. |
53 * @param x is the horizontal offset to this pixel. |
53 * @param x is the horizontal offset to this pixel. |
64 * @param y is the top edge in pixels. |
64 * @param y is the top edge in pixels. |
65 * @param w is the window width in pixels. |
65 * @param w is the window width in pixels. |
66 * @param h is the window height in pixels. |
66 * @param h is the window height in pixels. |
67 */ |
67 */ |
68 virtual void window(int x, int y, int w, int h); |
68 virtual void window(int x, int y, int w, int h); |
69 |
69 |
70 /** Read pixel color at location |
70 /** Read pixel color at location |
71 * @param x is the horizontal offset to this pixel. |
71 * @param x is the horizontal offset to this pixel. |
72 * @param y is the vertical offset to this pixel. |
72 * @param y is the vertical offset to this pixel. |
73 * @returns 16bit color, 0000=Black(pixel set), FFFF=White(pixel clear). |
73 * @returns 16bit color, 0000=Black(pixel set), FFFF=White(pixel clear). |
74 */ |
74 */ |
77 /** Push a single pixel into the window and increment position. |
77 /** Push a single pixel into the window and increment position. |
78 * You must first call window() then push pixels in loop. |
78 * You must first call window() then push pixels in loop. |
79 * @param color is the pixel color. |
79 * @param color is the pixel color. |
80 */ |
80 */ |
81 virtual void window_pushpixel(unsigned short color); |
81 virtual void window_pushpixel(unsigned short color); |
82 |
82 |
83 /** Push some pixels of the same color into the window and increment position. |
83 /** Push some pixels of the same color into the window and increment position. |
84 * You must first call window() then push pixels. |
84 * You must first call window() then push pixels. |
85 * @param color is the pixel color. |
85 * @param color is the pixel color. |
86 * @param count: how many |
86 * @param count: how many |
87 */ |
87 */ |
88 virtual void window_pushpixel(unsigned short color, unsigned int count); |
88 virtual void window_pushpixel(unsigned short color, unsigned int count); |
89 |
89 |
90 /** Push array of pixel colors into the window and increment position. |
90 /** Push array of pixel colors into the window and increment position. |
91 * You must first call window() then push pixels. |
91 * You must first call window() then push pixels. |
92 * @param color is the pixel color. |
92 * @param color is the pixel color. |
93 */ |
93 */ |
94 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght); |
94 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght); |
95 |
95 |
96 /** Framebuffer is used, it needs to be sent to SSD1322 from time to time |
96 /** Framebuffer is used, it needs to be sent to SSD1322 from time to time |
97 */ |
97 */ |
98 virtual void copy_to_lcd(); |
98 virtual void copy_to_lcd(); |
99 |
99 |
100 /** set the contrast of the screen |
100 /** set the contrast of the screen |
101 * |
101 * |
102 * @param o contrast 0-63 |
102 * @param o contrast 0-63 |
103 * @note may be overrided in case of not standard command |
103 * @note may be overrided in case of not standard command |
104 */ |
104 */ |
118 /** clear the entire screen |
118 /** clear the entire screen |
119 * The inherited one sets windomax then fill with background color |
119 * The inherited one sets windomax then fill with background color |
120 * We override it to speedup |
120 * We override it to speedup |
121 */ |
121 */ |
122 virtual void cls(); |
122 virtual void cls(); |
123 |
123 |
124 /** Set the orientation of the screen |
124 /** Set the orientation of the screen |
125 * x,y: 0,0 is always top left |
125 * x,y: 0,0 is always top left |
126 * |
126 * |
127 * @param o direction to use the screen (0-3) |
127 * @param o direction to use the screen (0-3) |
128 * 0 = -90° |
128 * 0 = -90° |
129 * 1 = default 0° |
129 * 1 = default 0° |
130 * 2 = +90° |
130 * 2 = +90° |
131 * 3 = +180° |
131 * 3 = +180° |
132 * |
132 * |
133 */ |
133 */ |
134 void set_orientation(int o); |
134 void set_orientation(int o); |
135 |
135 |
136 /** Set ChipSelect high or low |
136 /** Set ChipSelect high or low |
137 * @param enable 0/1 |
137 * @param enable 0/1 |
138 */ |
138 */ |
139 virtual void bus_enable(bool enable); |
139 virtual void bus_enable(bool enable); |
140 |
140 |
141 /** get display X size in pixels (native, orientation independent) |
141 /** get display X size in pixels (native, orientation independent) |
142 * @returns X size in pixels |
142 * @returns X size in pixels |
143 */ |
143 */ |
144 int sizeX() {return screensize_X;}; |
144 int sizeX() {return screensize_X;}; |
145 |
145 |
146 /** get display Y size in pixels (native, orientation independent) |
146 /** get display Y size in pixels (native, orientation independent) |
147 * @returns Y size in pixels |
147 * @returns Y size in pixels |
148 */ |
148 */ |
149 int sizeY() {return screensize_Y;}; |
149 int sizeY() {return screensize_Y;}; |
150 |
150 |
151 //////////////////////////////////////////////////////////////////////////////// |
151 //////////////////////////////////////////////////////////////////////////////// |
152 // not implemented yet |
152 // not implemented yet |
153 ////////////////////////////////////////////////////////////////// |
153 ////////////////////////////////////////////////////////////////// |
154 // virtual unsigned short pixelread(int x, int y){return 0;}; |
154 // virtual unsigned short pixelread(int x, int y){return 0;}; |
155 virtual void window4read(int x, int y, int w, int h){}; |
155 virtual void window4read(int x, int y, int w, int h){}; |
156 void setscrollarea (int startY, int areasize){}; |
156 void setscrollarea (int startY, int areasize){}; |
161 unsigned int buffsize() { return _PAGES*screensize_X;}; |
161 unsigned int buffsize() { return _PAGES*screensize_X;}; |
162 unsigned short pixelpos(int x, int y); |
162 unsigned short pixelpos(int x, int y); |
163 void clrbuff(const unsigned char value=0x00); |
163 void clrbuff(const unsigned char value=0x00); |
164 unsigned long buffaddr(unsigned int i); |
164 unsigned long buffaddr(unsigned int i); |
165 void fills(const unsigned char value=0xFF); |
165 void fills(const unsigned char value=0xFF); |
166 |
166 |
167 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); |
168 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); |
169 |
169 |
170 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, |
171 unsigned char from_row, unsigned char to_row); |
171 unsigned char from_row, unsigned char to_row); |
172 |
172 |
173 protected: |
173 protected: |
174 /** Setup some stuff (malloc the buffer, etc) |
174 /** Setup some stuff (malloc the buffer, etc) |
175 */ |
175 */ |
176 void init(); |
176 void init(); |
177 |
177 |
178 /** set mirror mode |
178 /** set mirror mode |
179 * @note may be overridden by specific display init class in case of not standard cmds or inverted wiring |
179 * @note may be overridden by specific display init class in case of not standard cmds or inverted wiring |
180 * @param mode NONE, X, Y, XY |
180 * @param mode NONE, X, Y, XY |
181 */ |
181 */ |
182 virtual void mirrorXY(mirror_t mode); |
182 virtual void mirrorXY(mirror_t mode); |
183 |
183 |
184 ////// functions needed by parent class /////////////////////////////////////// |
184 ////// functions needed by parent class /////////////////////////////////////// |
185 ////// -------------------------------- /////////////////////////////////////// |
185 ////// -------------------------------- /////////////////////////////////////// |
186 |
186 |
187 /** Send 8bit command to display controller |
187 /** Send 8bit command to display controller |
188 * |
188 * |
189 * @param cmd: byte to send |
189 * @param cmd: byte to send |
190 * @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 |
190 * @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 |
191 */ |
191 */ |
192 void wr_cmd8(unsigned char cmd); |
192 void wr_cmd8(unsigned char cmd); |
193 |
193 |
194 /** Send 8bit data to display controller |
194 /** Send 8bit data to display controller |
195 * |
195 * |
196 * @param data: byte to send |
196 * @param data: byte to send |
197 * |
197 * |
198 */ |
198 */ |
199 void wr_data8(unsigned char data); |
199 void wr_data8(unsigned char data); |
200 |
200 |
201 /** HW reset sequence (without display init commands) |
201 /** HW reset sequence (without display init commands) |
202 */ |
202 */ |
203 void hw_reset(); |
203 void hw_reset(); |
204 |
204 |
205 int contrast; |
205 int contrast; |
206 |
206 |
207 protected: |
207 protected: |
208 |
208 |
209 mbed::SPI _spi; |
209 mbed::SPI _spi; |
210 DigitalOut _CS; |
210 DigitalOut _CS; |
211 DigitalOut _RST; |
211 DigitalOut _RST; |
212 DigitalOut _DC; |
212 DigitalOut _DC; |
213 volatile DISPLAY_BUFFER_TYPE _pixelBuffer[DISPLAY_BUFFER_ELEMENTS]; // one full frame buffer |
213 volatile DISPLAY_BUFFER_TYPE _pixelBuffer[DISPLAY_BUFFER_ELEMENTS]; // one full frame buffer |
214 DISPLAY_BUFFER_TYPE _trBuffer[DISPLAY_BUFFER_ELEMENTS]; // for sending |
214 DISPLAY_BUFFER_TYPE _trBuffer[DISPLAY_BUFFER_ELEMENTS]; // for sending |
215 |
215 |
216 const int screensize_X; |
216 const int screensize_X; |
217 const int screensize_Y; |
217 const int screensize_Y; |
218 const int _PAGES; |
218 const int _PAGES; |
219 const int _BPP; |
219 const int _BPP; |
220 const int _IC_X_SEGS; |
220 const int _IC_X_SEGS; |