ban4jp - / sharp_mlcd

Dependents:   Sharp_Memory_LCD_Test hello_GT20L16J1Y_FONT_mlcd

Fork of sharp_mlcd by Masato YAMANISHI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sharp_mlcd.h Source File

sharp_mlcd.h

00001 /*
00002  * mbed library for the Sharp memory LCD LS027BDH01 / LS013B4DN04
00003  * derived from C12832_lcd
00004  * Copyright (c) 2014 Masato YAMANISHI
00005  * Released under the MIT License: http://mbed.org/license/mit
00006  */
00007 
00008 /* mbed library for the mbed Lab Board  128*32 pixel LCD
00009  * use C12832 controller
00010  * Copyright (c) 2012 Peter Drescher - DC2PD
00011  * Released under the MIT License: http://mbed.org/license/mit
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00014  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00015  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00016  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00017  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00018  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00019  * THE SOFTWARE.
00020  */
00021 
00022 #ifndef SHARP_MLCD_H
00023 #define SHARP_MLCD_H
00024 
00025 #include "mbed.h"
00026 #include "GraphicsDisplay.h"
00027 
00028 /** optional Defines :
00029  * #define debug_lcd  1  enable infos to PC_USB
00030  */
00031   
00032 #define BPP    1       // Bits per pixel
00033 #define WIDTH  400 // 96
00034 #define HEIGHT 240 // 96
00035 #define PAGES (HEIGHT/8) // 6
00036 #define BUFFER_SIZE (WIDTH*HEIGHT/8)
00037 
00038 
00039 /** Draw mode
00040  * NORMAl
00041  * XOR set pixel by xor the screen
00042  */
00043 enum {NORMAL,XOR};
00044 
00045 /** Bitmap
00046  */
00047 struct Bitmap{
00048   int xSize;
00049   int ySize;
00050   int Byte_in_Line;
00051   char* data;
00052 };
00053 
00054 class sharp_mlcd : public GraphicsDisplay
00055 {
00056  public:
00057   /** Create a aqm1248a object connected to SPI1
00058    *
00059    */
00060 
00061   sharp_mlcd(const char* name = "LCD");
00062 
00063   sharp_mlcd(PinName mosi, PinName sclk, PinName scs, PinName extcomin, PinName disp, const char* name = "LCD");
00064 
00065   /** Get the width of the screen in pixel
00066    *
00067    * @param
00068    * @returns width of screen in pixel
00069    *
00070    */
00071   virtual int width();
00072 
00073   /** Get the height of the screen in pixel
00074    *
00075    * @returns height of screen in pixel
00076    *
00077    */
00078   virtual int height();
00079 
00080   /** Draw a pixel at x,y black or white
00081    *
00082    * @param x horizontal position
00083    * @param y vertical position
00084    * @param colour ,1 set pixel ,0 erase pixel
00085    */
00086   virtual void pixel(int x, int y,int colour);
00087 
00088   /** draw a circle
00089    *
00090    * @param x0,y0 center
00091    * @param r radius
00092    * @param colour ,1 set pixel ,0 erase pixel
00093    *
00094    */
00095   void circle(int x, int y, int r, int colour);
00096 
00097   /** draw a filled circle
00098    *
00099    * @param x0,y0 center
00100    * @param r radius
00101    * @param color ,1 set pixel ,0 erase pixel
00102    *
00103    * use circle with different radius,
00104    * can miss some pixel
00105    */
00106   void fillcircle(int x, int y, int r, int colour);
00107 
00108   /** draw a 1 pixel line
00109    *
00110    * @param x0,y0 start point
00111    * @param x1,y1 stop point
00112    * @param color ,1 set pixel ,0 erase pixel
00113    *
00114    */
00115   void line(int x0, int y0, int x1, int y1, int colour);
00116 
00117   /** draw a rect
00118    *
00119    * @param x0,y0 top left corner
00120    * @param x1,y1 down right corner
00121    * @param color 1 set pixel ,0 erase pixel
00122    *                                                   *
00123    */
00124   void rect(int x0, int y0, int x1, int y1, int colour);
00125 
00126   /** draw a filled rect
00127    *
00128    * @param x0,y0 top left corner
00129    * @param x1,y1 down right corner
00130    * @param color 1 set pixel ,0 erase pixel
00131    *
00132    */
00133   void fillrect(int x0, int y0, int x1, int y1, int colour);
00134 
00135   /** copy display buffer to lcd
00136    *
00137    */
00138 
00139   void copy_to_lcd(int start = 0);
00140 
00141   /** clear the screen
00142    *
00143    */
00144   virtual void cls(void);
00145 
00146   /** set the drawing mode
00147    *
00148    * @param mode NORMAl or XOR
00149    */
00150 
00151   void setmode(int mode);
00152 
00153   virtual int columns(void);
00154 
00155   /** calculate the max number of columns
00156    *
00157    * @returns max column
00158    * depends on actual font size
00159    *
00160    */
00161   virtual int rows(void);
00162 
00163   /** put a char on the screen
00164    *
00165    * @param value char to print
00166    * @returns printed char
00167    *
00168    */
00169   virtual int _putc(int value);
00170 
00171   /** draw a character on given position out of the active font to the LCD
00172    *
00173    * @param x x-position of char (top left)
00174    * @param y y-position
00175    * @param c char to print
00176    *
00177    */
00178   virtual void character(int x, int y, int c);
00179 
00180   /** setup cursor position
00181    *
00182    * @param x x-position (top left)
00183    * @param y y-position
00184    */
00185   virtual void locate(int x, int y);
00186     
00187   /** setup auto update of screen 
00188    *
00189    * @param up 1 = on , 0 = off
00190    * if switched off the program has to call copy_to_lcd() 
00191    * to update screen from framebuffer
00192    */
00193   void set_auto_up(unsigned int up);
00194 
00195   /** get status of the auto update function
00196    *
00197    *  @returns if auto update is on
00198    */
00199   unsigned int get_auto_up(void);
00200 
00201   /** Vars     */
00202   SPI _spi;
00203   // DigitalOut _reset;
00204   // DigitalOut _A0;
00205   DigitalOut _EXTCOM;
00206   DigitalOut _DISP;
00207   DigitalOut _CS;
00208   unsigned char* font;
00209   unsigned int draw_mode;
00210 
00211   // Ticker timer;
00212 
00213   /** select the font to use
00214    *
00215    * @param f pointer to font array
00216    *
00217    *   font array can created with GLCD Font Creator from http://www.mikroe.com
00218    *   you have to add 4 parameter at the beginning of the font array to use:
00219    *   - the number of byte / char
00220    *   - the vertial size in pixel
00221    *   - the horizontal size in pixel
00222    *   - the number of byte per vertical line
00223    *   you also have to change the array to char[]
00224    *
00225    */
00226   void set_font(unsigned char* f);
00227     
00228   /** print bitmap to buffer
00229    *
00230    * @param bm Bitmap in flash
00231    * @param x  x start
00232    * @param y  y start 
00233    *
00234    */
00235 
00236   void print_bm(Bitmap bm, int x, int y, int color);
00237   void attime();
00238   void set_reverse_mode(unsigned int r);
00239 
00240  protected:
00241 
00242   /** draw a horizontal line
00243    *
00244    * @param x0 horizontal start
00245    * @param x1 horizontal stop
00246    * @param y vertical position
00247    * @param ,1 set pixel ,0 erase pixel
00248    *
00249    */
00250   void hline(int x0, int x1, int y, int colour);
00251 
00252   /** draw a vertical line
00253    *
00254    * @param x horizontal position
00255    * @param y0 vertical start
00256    * @param y1 vertical stop
00257    * @param ,1 set pixel ,0 erase pixel
00258    */
00259   void vline(int y0, int y1, int x, int colour);
00260 
00261   /** Init the C12832 LCD controller
00262    *
00263    */
00264   void lcd_reset();
00265 
00266   /** Write data to the LCD controller
00267    *
00268    * @param dat data written to LCD controller
00269    *
00270    */
00271   void wr_dat(unsigned char value);
00272 
00273   /** Write a command the LCD controller
00274    *
00275    * @param cmd: command to be written
00276    *
00277    */
00278   void wr_cmd(unsigned char value);
00279 
00280   void wr_cnt(unsigned char cmd);
00281 
00282   // unsigned int orientation;
00283   unsigned int char_x;
00284   unsigned int char_y;
00285   unsigned char buffer[BUFFER_SIZE];
00286   unsigned int reverse;
00287   unsigned int auto_up;
00288 
00289   unsigned int flip;
00290 
00291   unsigned char bit_reverse(unsigned char c);
00292 };
00293 
00294 #endif