C12832 by dreschpe modified to work with the DOGL128-6 LCD Display (ST7565R based)

Dependents:   DOGL128Test

Fork of C12832_lcd by Peter Drescher

DOGL128.h

Committer:
Sateg
Date:
2016-07-28
Revision:
19:23a26a1668cf
Parent:
18:672450caf175

File content as of revision 19:23a26a1668cf:

/* mbed library DOGL128-6 128*64 pixel LCD
 * Copyright (c) 2012 Peter Drescher - DC2PD,
 * Copyright (c) 2016 Łukasz Godziejewski
 * 
 * MIT License
 */

#ifndef DOGL128_H
#define DOGL128_H

#include "mbed.h"
#include "GraphicsDisplay.h"


/** optional Defines :
  * #define debug_lcd  1  enable infos to PC_USB
  */


/** Draw mode
  * NORMAl
  * XOR set pixel by xor the screen
  */
enum {NORMAL,XOR};

/** Bitmap
 */
struct Bitmap{
    int xSize;
    int ySize;
    int Byte_in_Line;
    char* data;
    };

/** DOGL128-6 (ST7565) handling library.
Initializes on spi defined in constructor. Works on an internal buffer and writes buffer
content to driver ram.
*/
class DOGL128 : public GraphicsDisplay
{
public:

    /** Create a DOGL128 object connected to SPI1
      *
      */
    DOGL128(PinName mosi, PinName clk, PinName cs, PinName a0, const char* name = "LCD");

    /** Get the width of the screen in pixel
      *
      * @param
      * @returns width of screen in pixel
      *
      */
    virtual int width();

    /** Get the height of the screen in pixel
     *
     * @returns height of screen in pixel
     *
     */
    virtual int height();

    /** Draw a pixel at x,y black or white
     *
     * @param x horizontal position
     * @param y vertical position
     * @param colour ,1 set pixel ,0 erase pixel
     */
    virtual void pixel(int x, int y,int colour);

    /** draw a circle
      *
      * @param x0,y0 center
      * @param r radius
      * @param colour ,1 set pixel ,0 erase pixel
      *
      */
    void circle(int x, int y, int r, int colour);

    /** draw a filled circle
     *
     * @param x0,y0 center
     * @param r radius
     * @param color ,1 set pixel ,0 erase pixel
     *
     * use circle with different radius,
     * can miss some pixel
     */
    void fillcircle(int x, int y, int r, int colour);

    /** draw a 1 pixel line
      *
      * @param x0,y0 start point
      * @param x1,y1 stop point
      * @param color ,1 set pixel ,0 erase pixel
      *
      */
    void line(int x0, int y0, int x1, int y1, int colour);

    /** draw a rect
    *
    * @param x0,y0 top left corner
    * @param x1,y1 down right corner
    * @param color 1 set pixel ,0 erase pixel
    *                                                   *
    */
    void rect(int x0, int y0, int x1, int y1, int colour);

    /** draw a filled rect
      *
      * @param x0,y0 top left corner
      * @param x1,y1 down right corner
      * @param color 1 set pixel ,0 erase pixel
      *
      */
    void fillrect(int x0, int y0, int x1, int y1, int colour);

    /** copy display buffer to lcd
      *
      */
    void copy_to_lcd(void);

    /** set the orienation of the screen
      *
      */

    //void set_orientation(unsigned int o);

    /** set the contrast of the screen
      *
      * @param o contrast 0-63
      */
    void set_contrast(unsigned int o);

    /** read the contrast level
      *
      */
    unsigned int get_contrast(void);



    /** invert the screen
      *
      * @param o = 0 normal, 1 invert
      */
    void invert(unsigned int o);

    /** clear the screen
       *
       */
    virtual void cls(void);

    /** set the drawing mode
      *
      * @param mode NORMAl or XOR
      */
    void setmode(int mode);

    virtual int columns(void);

    /** calculate the max number of columns
     *
     * @returns max column
     * depends on actual font size
     *
     */
    virtual int rows(void);

    /** put a char on the screen
     *
     * @param value char to print
     * @returns printed char
     *
     */
    virtual int _putc(int value);

    /** draw a character on given position out of the active font to the LCD
     *
     * @param x x-position of char (top left)
     * @param y y-position
     * @param c char to print
     *
     */
    virtual void character(int x, int y, int c);

    /** setup cursor position
     *
     * @param x x-position (top left)
     * @param y y-position
     */
    virtual void locate(int x, int y);
    
    /** setup auto update of screen 
      *
      * @param up 1 = on , 0 = off
      * if switched off the program has to call copy_to_lcd() 
      * to update screen from framebuffer
      */
    void set_auto_up(unsigned int up);

    /** get status of the auto update function
      *
      *  @returns if auto update is on
      */
    unsigned int get_auto_up(void);

    /** Vars     */
    SPI _spi;
    DigitalOut _reset;
    DigitalOut _A0;
    DigitalOut _CS;
    unsigned char* font;
    unsigned int draw_mode;


    /** select the font to use
      *
      * @param f pointer to font array
      *
      *   font array can created with GLCD Font Creator from http://www.mikroe.com
      *   you have to add 4 parameter at the beginning of the font array to use:
      *   - the number of byte / char
      *   - the vertial size in pixel
      *   - the horizontal size in pixel
      *   - the number of byte per vertical line
      *   you also have to change the array to char[]
      *
      */
    void set_font(unsigned char* f);
    
    /** print bitmap to buffer
      *
      * @param bm Bitmap in flash
      * @param x  x start
      * @param y  y start 
      *
      */
    void print_bm(Bitmap bm, int x, int y);
    
    /// Fill buffer with preset array
    void print_logo(const unsigned char* data);

protected:

    /** draw a horizontal line
      *
      * @param x0 horizontal start
      * @param x1 horizontal stop
      * @param y vertical position
      * @param ,1 set pixel ,0 erase pixel
      *
      */
    void hline(int x0, int x1, int y, int colour);

    /** draw a vertical line
     *
     * @param x horizontal position
     * @param y0 vertical start
     * @param y1 vertical stop
     * @param ,1 set pixel ,0 erase pixel
     */
    void vline(int y0, int y1, int x, int colour);

    /** Configure LCD registers.
    
    */
    void configure();

    /** Init the DOGL128 LCD controller
     *
     */
    void lcd_reset();

    /** Write data to the LCD controller
     *
     * @param dat data written to LCD controller
     *
     */
    void wr_dat(unsigned char value);

    /** Write a command the LCD controller
      *
      * @param cmd: command to be written
      *
      */
    void wr_cmd(unsigned char value);

    void wr_cnt(unsigned char cmd);
    
    /** Write buffer content to provided page.
    
        @param page_number Page to write to.
    */
    void write_to_page(uint8_t page_number);    
    
    /// clear the display buffer
    void clear_buffer();
    
    // commands values
    enum Display {
        kDisplayOn = 0xAF,
        kDisplayOff = 0xAE
    };
    enum ADCMode {
        kADCModeNormal = 0xA0,
        kADCModeReverse = 0xA1
    };
    enum DisplayMode {
        kDisplayModeNormal = 0xA6,
        kDisplayModeReverse = 0xA7
    };
    enum DisplayAllPoints {
        kDisplayAllPointsOff = 0xA4,
        kDisplayAllPointsOn = 0xA5
    };
    enum LCDBias {
        kLCDBiasOneNinth = 0xA2,
        kLCDBiasOneSeventh = 0xA3
    };
    enum CommonOutputMode {
        kCommonOutputModeNormal = 0xC0,
        kCommonOutputModeReverse = 0xC8
    };
    enum StaticIndicator {
        kStaticIndicatorOff = 0xAC,
        kStaticIndicatorOn = 0xAD
    };
    
    static const uint8_t kPageCount = 8;
    static const uint8_t kPageSize = 128;
    static const uint8_t kReset = 0xE2;
    static const uint8_t kSetContrast = 0x81;
    
    

    unsigned int orientation;
    unsigned int char_x;
    unsigned int char_y;
    unsigned char buffer[kPageSize * kPageCount];
    unsigned int contrast;
    unsigned int auto_up;
};

#endif /* DOGL128_H */