fixed library.
Dependents: Sharp_Memory_LCD_Test hello_GT20L16J1Y_FONT_mlcd
Fork of sharp_mlcd by
sharp_mlcd.h@1:f8ba3b236d12, 2014-05-11 (annotated)
- Committer:
- masato
- Date:
- Sun May 11 14:03:39 2014 +0000
- Revision:
- 1:f8ba3b236d12
- Parent:
- 0:c99dda90f834
- Child:
- 2:c36cdd3ad7ba
RC1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
masato | 0:c99dda90f834 | 1 | /* |
masato | 0:c99dda90f834 | 2 | * mbed library for the Sharp memory LCD LS027BDH01 / LS013B4DN04 |
masato | 0:c99dda90f834 | 3 | * derived from C12832_lcd |
masato | 0:c99dda90f834 | 4 | * Copyright (c) 2014 Masato YAMANISHI |
masato | 0:c99dda90f834 | 5 | * Released under the MIT License: http://mbed.org/license/mit |
masato | 0:c99dda90f834 | 6 | */ |
masato | 0:c99dda90f834 | 7 | |
masato | 0:c99dda90f834 | 8 | /* mbed library for the mbed Lab Board 128*32 pixel LCD |
masato | 0:c99dda90f834 | 9 | * use C12832 controller |
masato | 0:c99dda90f834 | 10 | * Copyright (c) 2012 Peter Drescher - DC2PD |
masato | 0:c99dda90f834 | 11 | * Released under the MIT License: http://mbed.org/license/mit |
masato | 0:c99dda90f834 | 12 | * |
masato | 0:c99dda90f834 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
masato | 0:c99dda90f834 | 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
masato | 0:c99dda90f834 | 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
masato | 0:c99dda90f834 | 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
masato | 0:c99dda90f834 | 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
masato | 0:c99dda90f834 | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
masato | 0:c99dda90f834 | 19 | * THE SOFTWARE. |
masato | 0:c99dda90f834 | 20 | */ |
masato | 0:c99dda90f834 | 21 | |
masato | 0:c99dda90f834 | 22 | #ifndef SHARP_MLCD_H |
masato | 0:c99dda90f834 | 23 | #define SHARP_MLCD_H |
masato | 0:c99dda90f834 | 24 | |
masato | 0:c99dda90f834 | 25 | #include "mbed.h" |
masato | 0:c99dda90f834 | 26 | #include "GraphicsDisplay.h" |
masato | 0:c99dda90f834 | 27 | |
masato | 0:c99dda90f834 | 28 | /** optional Defines : |
masato | 0:c99dda90f834 | 29 | * #define debug_lcd 1 enable infos to PC_USB |
masato | 0:c99dda90f834 | 30 | */ |
masato | 0:c99dda90f834 | 31 | |
masato | 0:c99dda90f834 | 32 | #define BPP 1 // Bits per pixel |
masato | 0:c99dda90f834 | 33 | #define WIDTH 400 // 96 |
masato | 0:c99dda90f834 | 34 | #define HEIGHT 240 // 96 |
masato | 0:c99dda90f834 | 35 | #define PAGES (HEIGHT/8) // 6 |
masato | 0:c99dda90f834 | 36 | #define BUFFER_SIZE (WIDTH*HEIGHT/8) |
masato | 0:c99dda90f834 | 37 | |
masato | 0:c99dda90f834 | 38 | |
masato | 0:c99dda90f834 | 39 | /** Draw mode |
masato | 0:c99dda90f834 | 40 | * NORMAl |
masato | 0:c99dda90f834 | 41 | * XOR set pixel by xor the screen |
masato | 0:c99dda90f834 | 42 | */ |
masato | 0:c99dda90f834 | 43 | enum {NORMAL,XOR}; |
masato | 0:c99dda90f834 | 44 | |
masato | 0:c99dda90f834 | 45 | /** Bitmap |
masato | 0:c99dda90f834 | 46 | */ |
masato | 0:c99dda90f834 | 47 | struct Bitmap{ |
masato | 0:c99dda90f834 | 48 | int xSize; |
masato | 0:c99dda90f834 | 49 | int ySize; |
masato | 0:c99dda90f834 | 50 | int Byte_in_Line; |
masato | 0:c99dda90f834 | 51 | char* data; |
masato | 0:c99dda90f834 | 52 | }; |
masato | 0:c99dda90f834 | 53 | |
masato | 0:c99dda90f834 | 54 | class sharp_mlcd : public GraphicsDisplay |
masato | 0:c99dda90f834 | 55 | { |
masato | 0:c99dda90f834 | 56 | public: |
masato | 0:c99dda90f834 | 57 | /** Create a aqm1248a object connected to SPI1 |
masato | 0:c99dda90f834 | 58 | * |
masato | 0:c99dda90f834 | 59 | */ |
masato | 0:c99dda90f834 | 60 | |
masato | 0:c99dda90f834 | 61 | sharp_mlcd(const char* name = "LCD"); |
masato | 0:c99dda90f834 | 62 | |
masato | 0:c99dda90f834 | 63 | /** Get the width of the screen in pixel |
masato | 0:c99dda90f834 | 64 | * |
masato | 0:c99dda90f834 | 65 | * @param |
masato | 0:c99dda90f834 | 66 | * @returns width of screen in pixel |
masato | 0:c99dda90f834 | 67 | * |
masato | 0:c99dda90f834 | 68 | */ |
masato | 0:c99dda90f834 | 69 | virtual int width(); |
masato | 0:c99dda90f834 | 70 | |
masato | 0:c99dda90f834 | 71 | /** Get the height of the screen in pixel |
masato | 0:c99dda90f834 | 72 | * |
masato | 0:c99dda90f834 | 73 | * @returns height of screen in pixel |
masato | 0:c99dda90f834 | 74 | * |
masato | 0:c99dda90f834 | 75 | */ |
masato | 0:c99dda90f834 | 76 | virtual int height(); |
masato | 0:c99dda90f834 | 77 | |
masato | 0:c99dda90f834 | 78 | /** Draw a pixel at x,y black or white |
masato | 0:c99dda90f834 | 79 | * |
masato | 0:c99dda90f834 | 80 | * @param x horizontal position |
masato | 0:c99dda90f834 | 81 | * @param y vertical position |
masato | 0:c99dda90f834 | 82 | * @param colour ,1 set pixel ,0 erase pixel |
masato | 0:c99dda90f834 | 83 | */ |
masato | 0:c99dda90f834 | 84 | virtual void pixel(int x, int y,int colour); |
masato | 0:c99dda90f834 | 85 | |
masato | 0:c99dda90f834 | 86 | /** draw a circle |
masato | 0:c99dda90f834 | 87 | * |
masato | 0:c99dda90f834 | 88 | * @param x0,y0 center |
masato | 0:c99dda90f834 | 89 | * @param r radius |
masato | 0:c99dda90f834 | 90 | * @param colour ,1 set pixel ,0 erase pixel |
masato | 0:c99dda90f834 | 91 | * |
masato | 0:c99dda90f834 | 92 | */ |
masato | 0:c99dda90f834 | 93 | void circle(int x, int y, int r, int colour); |
masato | 0:c99dda90f834 | 94 | |
masato | 0:c99dda90f834 | 95 | /** draw a filled circle |
masato | 0:c99dda90f834 | 96 | * |
masato | 0:c99dda90f834 | 97 | * @param x0,y0 center |
masato | 0:c99dda90f834 | 98 | * @param r radius |
masato | 0:c99dda90f834 | 99 | * @param color ,1 set pixel ,0 erase pixel |
masato | 0:c99dda90f834 | 100 | * |
masato | 0:c99dda90f834 | 101 | * use circle with different radius, |
masato | 0:c99dda90f834 | 102 | * can miss some pixel |
masato | 0:c99dda90f834 | 103 | */ |
masato | 0:c99dda90f834 | 104 | void fillcircle(int x, int y, int r, int colour); |
masato | 0:c99dda90f834 | 105 | |
masato | 0:c99dda90f834 | 106 | /** draw a 1 pixel line |
masato | 0:c99dda90f834 | 107 | * |
masato | 0:c99dda90f834 | 108 | * @param x0,y0 start point |
masato | 0:c99dda90f834 | 109 | * @param x1,y1 stop point |
masato | 0:c99dda90f834 | 110 | * @param color ,1 set pixel ,0 erase pixel |
masato | 0:c99dda90f834 | 111 | * |
masato | 0:c99dda90f834 | 112 | */ |
masato | 0:c99dda90f834 | 113 | void line(int x0, int y0, int x1, int y1, int colour); |
masato | 0:c99dda90f834 | 114 | |
masato | 0:c99dda90f834 | 115 | /** draw a rect |
masato | 0:c99dda90f834 | 116 | * |
masato | 0:c99dda90f834 | 117 | * @param x0,y0 top left corner |
masato | 0:c99dda90f834 | 118 | * @param x1,y1 down right corner |
masato | 0:c99dda90f834 | 119 | * @param color 1 set pixel ,0 erase pixel |
masato | 0:c99dda90f834 | 120 | * * |
masato | 0:c99dda90f834 | 121 | */ |
masato | 0:c99dda90f834 | 122 | void rect(int x0, int y0, int x1, int y1, int colour); |
masato | 0:c99dda90f834 | 123 | |
masato | 0:c99dda90f834 | 124 | /** draw a filled rect |
masato | 0:c99dda90f834 | 125 | * |
masato | 0:c99dda90f834 | 126 | * @param x0,y0 top left corner |
masato | 0:c99dda90f834 | 127 | * @param x1,y1 down right corner |
masato | 0:c99dda90f834 | 128 | * @param color 1 set pixel ,0 erase pixel |
masato | 0:c99dda90f834 | 129 | * |
masato | 0:c99dda90f834 | 130 | */ |
masato | 0:c99dda90f834 | 131 | void fillrect(int x0, int y0, int x1, int y1, int colour); |
masato | 0:c99dda90f834 | 132 | |
masato | 0:c99dda90f834 | 133 | /** copy display buffer to lcd |
masato | 0:c99dda90f834 | 134 | * |
masato | 0:c99dda90f834 | 135 | */ |
masato | 0:c99dda90f834 | 136 | |
masato | 0:c99dda90f834 | 137 | void copy_to_lcd(void); |
masato | 0:c99dda90f834 | 138 | |
masato | 0:c99dda90f834 | 139 | /** clear the screen |
masato | 0:c99dda90f834 | 140 | * |
masato | 0:c99dda90f834 | 141 | */ |
masato | 0:c99dda90f834 | 142 | virtual void cls(void); |
masato | 0:c99dda90f834 | 143 | |
masato | 0:c99dda90f834 | 144 | /** set the drawing mode |
masato | 0:c99dda90f834 | 145 | * |
masato | 0:c99dda90f834 | 146 | * @param mode NORMAl or XOR |
masato | 0:c99dda90f834 | 147 | */ |
masato | 0:c99dda90f834 | 148 | |
masato | 0:c99dda90f834 | 149 | void setmode(int mode); |
masato | 0:c99dda90f834 | 150 | |
masato | 0:c99dda90f834 | 151 | virtual int columns(void); |
masato | 0:c99dda90f834 | 152 | |
masato | 0:c99dda90f834 | 153 | /** calculate the max number of columns |
masato | 0:c99dda90f834 | 154 | * |
masato | 0:c99dda90f834 | 155 | * @returns max column |
masato | 0:c99dda90f834 | 156 | * depends on actual font size |
masato | 0:c99dda90f834 | 157 | * |
masato | 0:c99dda90f834 | 158 | */ |
masato | 0:c99dda90f834 | 159 | virtual int rows(void); |
masato | 0:c99dda90f834 | 160 | |
masato | 0:c99dda90f834 | 161 | /** put a char on the screen |
masato | 0:c99dda90f834 | 162 | * |
masato | 0:c99dda90f834 | 163 | * @param value char to print |
masato | 0:c99dda90f834 | 164 | * @returns printed char |
masato | 0:c99dda90f834 | 165 | * |
masato | 0:c99dda90f834 | 166 | */ |
masato | 0:c99dda90f834 | 167 | virtual int _putc(int value); |
masato | 0:c99dda90f834 | 168 | |
masato | 0:c99dda90f834 | 169 | /** draw a character on given position out of the active font to the LCD |
masato | 0:c99dda90f834 | 170 | * |
masato | 0:c99dda90f834 | 171 | * @param x x-position of char (top left) |
masato | 0:c99dda90f834 | 172 | * @param y y-position |
masato | 0:c99dda90f834 | 173 | * @param c char to print |
masato | 0:c99dda90f834 | 174 | * |
masato | 0:c99dda90f834 | 175 | */ |
masato | 0:c99dda90f834 | 176 | virtual void character(int x, int y, int c); |
masato | 0:c99dda90f834 | 177 | |
masato | 0:c99dda90f834 | 178 | /** setup cursor position |
masato | 0:c99dda90f834 | 179 | * |
masato | 0:c99dda90f834 | 180 | * @param x x-position (top left) |
masato | 0:c99dda90f834 | 181 | * @param y y-position |
masato | 0:c99dda90f834 | 182 | */ |
masato | 0:c99dda90f834 | 183 | virtual void locate(int x, int y); |
masato | 0:c99dda90f834 | 184 | |
masato | 0:c99dda90f834 | 185 | /** setup auto update of screen |
masato | 0:c99dda90f834 | 186 | * |
masato | 0:c99dda90f834 | 187 | * @param up 1 = on , 0 = off |
masato | 0:c99dda90f834 | 188 | * if switched off the program has to call copy_to_lcd() |
masato | 0:c99dda90f834 | 189 | * to update screen from framebuffer |
masato | 0:c99dda90f834 | 190 | */ |
masato | 0:c99dda90f834 | 191 | void set_auto_up(unsigned int up); |
masato | 0:c99dda90f834 | 192 | |
masato | 0:c99dda90f834 | 193 | /** get status of the auto update function |
masato | 0:c99dda90f834 | 194 | * |
masato | 0:c99dda90f834 | 195 | * @returns if auto update is on |
masato | 0:c99dda90f834 | 196 | */ |
masato | 0:c99dda90f834 | 197 | unsigned int get_auto_up(void); |
masato | 0:c99dda90f834 | 198 | |
masato | 0:c99dda90f834 | 199 | /** Vars */ |
masato | 0:c99dda90f834 | 200 | SPI _spi; |
masato | 0:c99dda90f834 | 201 | // DigitalOut _reset; |
masato | 0:c99dda90f834 | 202 | // DigitalOut _A0; |
masato | 0:c99dda90f834 | 203 | DigitalOut _EXTCOM; |
masato | 0:c99dda90f834 | 204 | DigitalOut _DISP; |
masato | 0:c99dda90f834 | 205 | DigitalOut _CS; |
masato | 0:c99dda90f834 | 206 | unsigned char* font; |
masato | 0:c99dda90f834 | 207 | unsigned int draw_mode; |
masato | 0:c99dda90f834 | 208 | |
masato | 0:c99dda90f834 | 209 | // Ticker timer; |
masato | 0:c99dda90f834 | 210 | |
masato | 0:c99dda90f834 | 211 | /** select the font to use |
masato | 0:c99dda90f834 | 212 | * |
masato | 0:c99dda90f834 | 213 | * @param f pointer to font array |
masato | 0:c99dda90f834 | 214 | * |
masato | 0:c99dda90f834 | 215 | * font array can created with GLCD Font Creator from http://www.mikroe.com |
masato | 0:c99dda90f834 | 216 | * you have to add 4 parameter at the beginning of the font array to use: |
masato | 0:c99dda90f834 | 217 | * - the number of byte / char |
masato | 0:c99dda90f834 | 218 | * - the vertial size in pixel |
masato | 0:c99dda90f834 | 219 | * - the horizontal size in pixel |
masato | 0:c99dda90f834 | 220 | * - the number of byte per vertical line |
masato | 0:c99dda90f834 | 221 | * you also have to change the array to char[] |
masato | 0:c99dda90f834 | 222 | * |
masato | 0:c99dda90f834 | 223 | */ |
masato | 0:c99dda90f834 | 224 | void set_font(unsigned char* f); |
masato | 0:c99dda90f834 | 225 | |
masato | 0:c99dda90f834 | 226 | /** print bitmap to buffer |
masato | 0:c99dda90f834 | 227 | * |
masato | 0:c99dda90f834 | 228 | * @param bm Bitmap in flash |
masato | 0:c99dda90f834 | 229 | * @param x x start |
masato | 0:c99dda90f834 | 230 | * @param y y start |
masato | 0:c99dda90f834 | 231 | * |
masato | 0:c99dda90f834 | 232 | */ |
masato | 0:c99dda90f834 | 233 | |
masato | 1:f8ba3b236d12 | 234 | void print_bm(Bitmap bm, int x, int y, int color); |
masato | 0:c99dda90f834 | 235 | void attime(); |
masato | 1:f8ba3b236d12 | 236 | void set_reverse_mode(unsigned int r); |
masato | 0:c99dda90f834 | 237 | |
masato | 0:c99dda90f834 | 238 | protected: |
masato | 0:c99dda90f834 | 239 | |
masato | 0:c99dda90f834 | 240 | /** draw a horizontal line |
masato | 0:c99dda90f834 | 241 | * |
masato | 0:c99dda90f834 | 242 | * @param x0 horizontal start |
masato | 0:c99dda90f834 | 243 | * @param x1 horizontal stop |
masato | 0:c99dda90f834 | 244 | * @param y vertical position |
masato | 0:c99dda90f834 | 245 | * @param ,1 set pixel ,0 erase pixel |
masato | 0:c99dda90f834 | 246 | * |
masato | 0:c99dda90f834 | 247 | */ |
masato | 0:c99dda90f834 | 248 | void hline(int x0, int x1, int y, int colour); |
masato | 0:c99dda90f834 | 249 | |
masato | 0:c99dda90f834 | 250 | /** draw a vertical line |
masato | 0:c99dda90f834 | 251 | * |
masato | 0:c99dda90f834 | 252 | * @param x horizontal position |
masato | 0:c99dda90f834 | 253 | * @param y0 vertical start |
masato | 0:c99dda90f834 | 254 | * @param y1 vertical stop |
masato | 0:c99dda90f834 | 255 | * @param ,1 set pixel ,0 erase pixel |
masato | 0:c99dda90f834 | 256 | */ |
masato | 0:c99dda90f834 | 257 | void vline(int y0, int y1, int x, int colour); |
masato | 0:c99dda90f834 | 258 | |
masato | 0:c99dda90f834 | 259 | /** Init the C12832 LCD controller |
masato | 0:c99dda90f834 | 260 | * |
masato | 0:c99dda90f834 | 261 | */ |
masato | 0:c99dda90f834 | 262 | void lcd_reset(); |
masato | 0:c99dda90f834 | 263 | |
masato | 0:c99dda90f834 | 264 | /** Write data to the LCD controller |
masato | 0:c99dda90f834 | 265 | * |
masato | 0:c99dda90f834 | 266 | * @param dat data written to LCD controller |
masato | 0:c99dda90f834 | 267 | * |
masato | 0:c99dda90f834 | 268 | */ |
masato | 0:c99dda90f834 | 269 | void wr_dat(unsigned char value); |
masato | 0:c99dda90f834 | 270 | |
masato | 0:c99dda90f834 | 271 | /** Write a command the LCD controller |
masato | 0:c99dda90f834 | 272 | * |
masato | 0:c99dda90f834 | 273 | * @param cmd: command to be written |
masato | 0:c99dda90f834 | 274 | * |
masato | 0:c99dda90f834 | 275 | */ |
masato | 0:c99dda90f834 | 276 | void wr_cmd(unsigned char value); |
masato | 0:c99dda90f834 | 277 | |
masato | 0:c99dda90f834 | 278 | void wr_cnt(unsigned char cmd); |
masato | 0:c99dda90f834 | 279 | |
masato | 0:c99dda90f834 | 280 | // unsigned int orientation; |
masato | 0:c99dda90f834 | 281 | unsigned int char_x; |
masato | 0:c99dda90f834 | 282 | unsigned int char_y; |
masato | 0:c99dda90f834 | 283 | unsigned char buffer[BUFFER_SIZE]; |
masato | 1:f8ba3b236d12 | 284 | unsigned int reverse; |
masato | 0:c99dda90f834 | 285 | unsigned int auto_up; |
masato | 0:c99dda90f834 | 286 | |
masato | 0:c99dda90f834 | 287 | unsigned int flip; |
masato | 0:c99dda90f834 | 288 | |
masato | 0:c99dda90f834 | 289 | unsigned char bit_reverse(unsigned char c); |
masato | 0:c99dda90f834 | 290 | }; |
masato | 0:c99dda90f834 | 291 | |
masato | 0:c99dda90f834 | 292 | #endif |