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