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