fixed library.

Dependents:   Sharp_Memory_LCD_Test hello_GT20L16J1Y_FONT_mlcd

Fork of sharp_mlcd by Masato YAMANISHI

Committer:
ban4jp
Date:
Sun Sep 21 08:05:33 2014 +0000
Revision:
3:d2aed1df064c
Parent:
2:c36cdd3ad7ba
Fix multi connection spi device issue.

Who changed what in which revision?

UserRevisionLine numberNew 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
ban4jp 2:c36cdd3ad7ba 63 sharp_mlcd(PinName mosi, PinName sclk, PinName scs, PinName extcomin, PinName disp, const char* name = "LCD");
ban4jp 2:c36cdd3ad7ba 64
masato 0:c99dda90f834 65 /** Get the width of the screen in pixel
masato 0:c99dda90f834 66 *
masato 0:c99dda90f834 67 * @param
masato 0:c99dda90f834 68 * @returns width of screen in pixel
masato 0:c99dda90f834 69 *
masato 0:c99dda90f834 70 */
masato 0:c99dda90f834 71 virtual int width();
masato 0:c99dda90f834 72
masato 0:c99dda90f834 73 /** Get the height of the screen in pixel
masato 0:c99dda90f834 74 *
masato 0:c99dda90f834 75 * @returns height of screen in pixel
masato 0:c99dda90f834 76 *
masato 0:c99dda90f834 77 */
masato 0:c99dda90f834 78 virtual int height();
masato 0:c99dda90f834 79
masato 0:c99dda90f834 80 /** Draw a pixel at x,y black or white
masato 0:c99dda90f834 81 *
masato 0:c99dda90f834 82 * @param x horizontal position
masato 0:c99dda90f834 83 * @param y vertical position
masato 0:c99dda90f834 84 * @param colour ,1 set pixel ,0 erase pixel
masato 0:c99dda90f834 85 */
masato 0:c99dda90f834 86 virtual void pixel(int x, int y,int colour);
masato 0:c99dda90f834 87
masato 0:c99dda90f834 88 /** draw a circle
masato 0:c99dda90f834 89 *
masato 0:c99dda90f834 90 * @param x0,y0 center
masato 0:c99dda90f834 91 * @param r radius
masato 0:c99dda90f834 92 * @param colour ,1 set pixel ,0 erase pixel
masato 0:c99dda90f834 93 *
masato 0:c99dda90f834 94 */
masato 0:c99dda90f834 95 void circle(int x, int y, int r, int colour);
masato 0:c99dda90f834 96
masato 0:c99dda90f834 97 /** draw a filled circle
masato 0:c99dda90f834 98 *
masato 0:c99dda90f834 99 * @param x0,y0 center
masato 0:c99dda90f834 100 * @param r radius
masato 0:c99dda90f834 101 * @param color ,1 set pixel ,0 erase pixel
masato 0:c99dda90f834 102 *
masato 0:c99dda90f834 103 * use circle with different radius,
masato 0:c99dda90f834 104 * can miss some pixel
masato 0:c99dda90f834 105 */
masato 0:c99dda90f834 106 void fillcircle(int x, int y, int r, int colour);
masato 0:c99dda90f834 107
masato 0:c99dda90f834 108 /** draw a 1 pixel line
masato 0:c99dda90f834 109 *
masato 0:c99dda90f834 110 * @param x0,y0 start point
masato 0:c99dda90f834 111 * @param x1,y1 stop point
masato 0:c99dda90f834 112 * @param color ,1 set pixel ,0 erase pixel
masato 0:c99dda90f834 113 *
masato 0:c99dda90f834 114 */
masato 0:c99dda90f834 115 void line(int x0, int y0, int x1, int y1, int colour);
masato 0:c99dda90f834 116
masato 0:c99dda90f834 117 /** draw a rect
masato 0:c99dda90f834 118 *
masato 0:c99dda90f834 119 * @param x0,y0 top left corner
masato 0:c99dda90f834 120 * @param x1,y1 down right corner
masato 0:c99dda90f834 121 * @param color 1 set pixel ,0 erase pixel
masato 0:c99dda90f834 122 * *
masato 0:c99dda90f834 123 */
masato 0:c99dda90f834 124 void rect(int x0, int y0, int x1, int y1, int colour);
masato 0:c99dda90f834 125
masato 0:c99dda90f834 126 /** draw a filled rect
masato 0:c99dda90f834 127 *
masato 0:c99dda90f834 128 * @param x0,y0 top left corner
masato 0:c99dda90f834 129 * @param x1,y1 down right corner
masato 0:c99dda90f834 130 * @param color 1 set pixel ,0 erase pixel
masato 0:c99dda90f834 131 *
masato 0:c99dda90f834 132 */
masato 0:c99dda90f834 133 void fillrect(int x0, int y0, int x1, int y1, int colour);
masato 0:c99dda90f834 134
masato 0:c99dda90f834 135 /** copy display buffer to lcd
masato 0:c99dda90f834 136 *
masato 0:c99dda90f834 137 */
masato 0:c99dda90f834 138
ban4jp 2:c36cdd3ad7ba 139 void copy_to_lcd(int start = 0);
masato 0:c99dda90f834 140
masato 0:c99dda90f834 141 /** clear the screen
masato 0:c99dda90f834 142 *
masato 0:c99dda90f834 143 */
masato 0:c99dda90f834 144 virtual void cls(void);
masato 0:c99dda90f834 145
masato 0:c99dda90f834 146 /** set the drawing mode
masato 0:c99dda90f834 147 *
masato 0:c99dda90f834 148 * @param mode NORMAl or XOR
masato 0:c99dda90f834 149 */
masato 0:c99dda90f834 150
masato 0:c99dda90f834 151 void setmode(int mode);
masato 0:c99dda90f834 152
masato 0:c99dda90f834 153 virtual int columns(void);
masato 0:c99dda90f834 154
masato 0:c99dda90f834 155 /** calculate the max number of columns
masato 0:c99dda90f834 156 *
masato 0:c99dda90f834 157 * @returns max column
masato 0:c99dda90f834 158 * depends on actual font size
masato 0:c99dda90f834 159 *
masato 0:c99dda90f834 160 */
masato 0:c99dda90f834 161 virtual int rows(void);
masato 0:c99dda90f834 162
masato 0:c99dda90f834 163 /** put a char on the screen
masato 0:c99dda90f834 164 *
masato 0:c99dda90f834 165 * @param value char to print
masato 0:c99dda90f834 166 * @returns printed char
masato 0:c99dda90f834 167 *
masato 0:c99dda90f834 168 */
masato 0:c99dda90f834 169 virtual int _putc(int value);
masato 0:c99dda90f834 170
masato 0:c99dda90f834 171 /** draw a character on given position out of the active font to the LCD
masato 0:c99dda90f834 172 *
masato 0:c99dda90f834 173 * @param x x-position of char (top left)
masato 0:c99dda90f834 174 * @param y y-position
masato 0:c99dda90f834 175 * @param c char to print
masato 0:c99dda90f834 176 *
masato 0:c99dda90f834 177 */
masato 0:c99dda90f834 178 virtual void character(int x, int y, int c);
masato 0:c99dda90f834 179
masato 0:c99dda90f834 180 /** setup cursor position
masato 0:c99dda90f834 181 *
masato 0:c99dda90f834 182 * @param x x-position (top left)
masato 0:c99dda90f834 183 * @param y y-position
masato 0:c99dda90f834 184 */
masato 0:c99dda90f834 185 virtual void locate(int x, int y);
masato 0:c99dda90f834 186
masato 0:c99dda90f834 187 /** setup auto update of screen
masato 0:c99dda90f834 188 *
masato 0:c99dda90f834 189 * @param up 1 = on , 0 = off
masato 0:c99dda90f834 190 * if switched off the program has to call copy_to_lcd()
masato 0:c99dda90f834 191 * to update screen from framebuffer
masato 0:c99dda90f834 192 */
masato 0:c99dda90f834 193 void set_auto_up(unsigned int up);
masato 0:c99dda90f834 194
masato 0:c99dda90f834 195 /** get status of the auto update function
masato 0:c99dda90f834 196 *
masato 0:c99dda90f834 197 * @returns if auto update is on
masato 0:c99dda90f834 198 */
masato 0:c99dda90f834 199 unsigned int get_auto_up(void);
masato 0:c99dda90f834 200
masato 0:c99dda90f834 201 /** Vars */
masato 0:c99dda90f834 202 SPI _spi;
masato 0:c99dda90f834 203 // DigitalOut _reset;
masato 0:c99dda90f834 204 // DigitalOut _A0;
masato 0:c99dda90f834 205 DigitalOut _EXTCOM;
masato 0:c99dda90f834 206 DigitalOut _DISP;
masato 0:c99dda90f834 207 DigitalOut _CS;
masato 0:c99dda90f834 208 unsigned char* font;
masato 0:c99dda90f834 209 unsigned int draw_mode;
masato 0:c99dda90f834 210
masato 0:c99dda90f834 211 // Ticker timer;
masato 0:c99dda90f834 212
masato 0:c99dda90f834 213 /** select the font to use
masato 0:c99dda90f834 214 *
masato 0:c99dda90f834 215 * @param f pointer to font array
masato 0:c99dda90f834 216 *
masato 0:c99dda90f834 217 * font array can created with GLCD Font Creator from http://www.mikroe.com
masato 0:c99dda90f834 218 * you have to add 4 parameter at the beginning of the font array to use:
masato 0:c99dda90f834 219 * - the number of byte / char
masato 0:c99dda90f834 220 * - the vertial size in pixel
masato 0:c99dda90f834 221 * - the horizontal size in pixel
masato 0:c99dda90f834 222 * - the number of byte per vertical line
masato 0:c99dda90f834 223 * you also have to change the array to char[]
masato 0:c99dda90f834 224 *
masato 0:c99dda90f834 225 */
masato 0:c99dda90f834 226 void set_font(unsigned char* f);
masato 0:c99dda90f834 227
masato 0:c99dda90f834 228 /** print bitmap to buffer
masato 0:c99dda90f834 229 *
masato 0:c99dda90f834 230 * @param bm Bitmap in flash
masato 0:c99dda90f834 231 * @param x x start
masato 0:c99dda90f834 232 * @param y y start
masato 0:c99dda90f834 233 *
masato 0:c99dda90f834 234 */
masato 0:c99dda90f834 235
masato 1:f8ba3b236d12 236 void print_bm(Bitmap bm, int x, int y, int color);
masato 0:c99dda90f834 237 void attime();
masato 1:f8ba3b236d12 238 void set_reverse_mode(unsigned int r);
masato 0:c99dda90f834 239
masato 0:c99dda90f834 240 protected:
masato 0:c99dda90f834 241
masato 0:c99dda90f834 242 /** draw a horizontal line
masato 0:c99dda90f834 243 *
masato 0:c99dda90f834 244 * @param x0 horizontal start
masato 0:c99dda90f834 245 * @param x1 horizontal stop
masato 0:c99dda90f834 246 * @param y vertical position
masato 0:c99dda90f834 247 * @param ,1 set pixel ,0 erase pixel
masato 0:c99dda90f834 248 *
masato 0:c99dda90f834 249 */
masato 0:c99dda90f834 250 void hline(int x0, int x1, int y, int colour);
masato 0:c99dda90f834 251
masato 0:c99dda90f834 252 /** draw a vertical line
masato 0:c99dda90f834 253 *
masato 0:c99dda90f834 254 * @param x horizontal position
masato 0:c99dda90f834 255 * @param y0 vertical start
masato 0:c99dda90f834 256 * @param y1 vertical stop
masato 0:c99dda90f834 257 * @param ,1 set pixel ,0 erase pixel
masato 0:c99dda90f834 258 */
masato 0:c99dda90f834 259 void vline(int y0, int y1, int x, int colour);
masato 0:c99dda90f834 260
masato 0:c99dda90f834 261 /** Init the C12832 LCD controller
masato 0:c99dda90f834 262 *
masato 0:c99dda90f834 263 */
masato 0:c99dda90f834 264 void lcd_reset();
masato 0:c99dda90f834 265
masato 0:c99dda90f834 266 /** Write data to the LCD controller
masato 0:c99dda90f834 267 *
masato 0:c99dda90f834 268 * @param dat data written to LCD controller
masato 0:c99dda90f834 269 *
masato 0:c99dda90f834 270 */
masato 0:c99dda90f834 271 void wr_dat(unsigned char value);
masato 0:c99dda90f834 272
masato 0:c99dda90f834 273 /** Write a command the LCD controller
masato 0:c99dda90f834 274 *
masato 0:c99dda90f834 275 * @param cmd: command to be written
masato 0:c99dda90f834 276 *
masato 0:c99dda90f834 277 */
masato 0:c99dda90f834 278 void wr_cmd(unsigned char value);
masato 0:c99dda90f834 279
masato 0:c99dda90f834 280 void wr_cnt(unsigned char cmd);
masato 0:c99dda90f834 281
masato 0:c99dda90f834 282 // unsigned int orientation;
masato 0:c99dda90f834 283 unsigned int char_x;
masato 0:c99dda90f834 284 unsigned int char_y;
masato 0:c99dda90f834 285 unsigned char buffer[BUFFER_SIZE];
masato 1:f8ba3b236d12 286 unsigned int reverse;
masato 0:c99dda90f834 287 unsigned int auto_up;
masato 0:c99dda90f834 288
masato 0:c99dda90f834 289 unsigned int flip;
masato 0:c99dda90f834 290
masato 0:c99dda90f834 291 unsigned char bit_reverse(unsigned char c);
masato 0:c99dda90f834 292 };
masato 0:c99dda90f834 293
masato 0:c99dda90f834 294 #endif