Text console library for ST7565 graphics LCD controller over SPI interface.

Dependents:   TextLCD_ST7565SPI_Test OpPanel_Offline OpPanel_Offline_cmake_gcc_arm_NUCLEO_F303RENew

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TextLCD_ST7565SPI.h Source File

TextLCD_ST7565SPI.h

00001 // ==================================================== Mar 03 2015, kayeks ==
00002 // TextLCD_ST7565SPI.h
00003 // ===========================================================================
00004 // Text console library for ST7565 graphics LCD controller over SPI interface.
00005 
00006 #ifndef TEXTLCD_ST7565SPI_H_
00007 #define TEXTLCD_ST7565SPI_H_
00008 
00009 #include "mbed.h"
00010 
00011 /** Text console library for ST7565 graphics LCD controller over SPI interface. */
00012 class TextLCD_ST7565SPI : public Stream {
00013 public:
00014     /** Bias select: 1/7 or 1/9. */
00015     enum Bias {
00016         Bias1_7    /** 1/7 bias */
00017         , Bias1_9  /** 1/9 bias */
00018     };
00019     
00020     const static uint8_t V0_INTERNAL_R_0     = 0x20;
00021     const static uint8_t V0_INTERNAL_R_1     = 0x21;
00022     const static uint8_t V0_INTERNAL_R_2     = 0x22;
00023     const static uint8_t V0_INTERNAL_R_3     = 0x23;
00024     const static uint8_t V0_INTERNAL_R_4     = 0x24;
00025     const static uint8_t V0_INTERNAL_R_5     = 0x25;
00026     const static uint8_t V0_INTERNAL_R_6     = 0x26;
00027     const static uint8_t V0_INTERNAL_R_7     = 0x27;
00028     const static uint8_t PCTRL_VFOLLOWER_ON  = 0x29;
00029     const static uint8_t PCTRL_VFOLLOWER_OFF = 0x28;
00030     const static uint8_t PCTRL_REGULATOR_ON  = 0x2a;
00031     const static uint8_t PCTRL_REGULATOR_OFF = 0x28;
00032     const static uint8_t PCTRL_BOOSTER_ON    = 0x2c;
00033     const static uint8_t PCTRL_BOOSTER_OFF   = 0x28;
00034     const static uint8_t COMMON_OFFSET       = 0x40;
00035     const static uint8_t ELECTRONIC_VOL_MODE = 0x81;
00036     const static uint8_t ELECTRONIC_VOL_1    = 0x01;
00037     const static uint8_t ELECTRONIC_VOL_2    = 0x02;
00038     const static uint8_t ELECTRONIC_VOL_3    = 0x03;
00039     const static uint8_t ELECTRONIC_VOL_4    = 0x04;
00040     const static uint8_t ELECTRONIC_VOL_5    = 0x05;
00041     const static uint8_t ELECTRONIC_VOL_6    = 0x06;
00042     const static uint8_t ELECTRONIC_VOL_7    = 0x07;
00043     const static uint8_t ELECTRONIC_VOL_8    = 0x08;
00044     const static uint8_t ELECTRONIC_VOL_9    = 0x09;
00045     const static uint8_t ELECTRONIC_VOL_10   = 0x0a;
00046     const static uint8_t ELECTRONIC_VOL_11   = 0x0b;
00047     const static uint8_t ELECTRONIC_VOL_12   = 0x0c;
00048     const static uint8_t ELECTRONIC_VOL_13   = 0x0d;
00049     const static uint8_t ELECTRONIC_VOL_14   = 0x0e;
00050     const static uint8_t ELECTRONIC_VOL_15   = 0x0f;
00051     const static uint8_t ELECTRONIC_VOL_16   = 0x10;
00052     const static uint8_t ELECTRONIC_VOL_17   = 0x11;
00053     const static uint8_t ELECTRONIC_VOL_18   = 0x12;
00054     const static uint8_t ELECTRONIC_VOL_19   = 0x13;
00055     const static uint8_t ELECTRONIC_VOL_20   = 0x14;
00056     const static uint8_t ELECTRONIC_VOL_21   = 0x15;
00057     const static uint8_t ELECTRONIC_VOL_22   = 0x16;
00058     const static uint8_t ELECTRONIC_VOL_23   = 0x17;
00059     const static uint8_t ELECTRONIC_VOL_24   = 0x18;
00060     const static uint8_t ELECTRONIC_VOL_25   = 0x19;
00061     const static uint8_t ELECTRONIC_VOL_26   = 0x1a;
00062     const static uint8_t ELECTRONIC_VOL_27   = 0x1b;
00063     const static uint8_t ELECTRONIC_VOL_28   = 0x1c;
00064     const static uint8_t ELECTRONIC_VOL_29   = 0x1d;
00065     const static uint8_t ELECTRONIC_VOL_30   = 0x1e;
00066     const static uint8_t ELECTRONIC_VOL_31   = 0x1f;
00067     const static uint8_t ELECTRONIC_VOL_32   = 0x20;
00068     const static uint8_t ELECTRONIC_VOL_33   = 0x21;
00069     const static uint8_t ELECTRONIC_VOL_34   = 0x22;
00070     const static uint8_t ELECTRONIC_VOL_35   = 0x23;
00071     const static uint8_t ELECTRONIC_VOL_36   = 0x24;
00072     const static uint8_t ELECTRONIC_VOL_37   = 0x25;
00073     const static uint8_t ELECTRONIC_VOL_38   = 0x26;
00074     const static uint8_t ELECTRONIC_VOL_39   = 0x27;
00075     const static uint8_t ELECTRONIC_VOL_40   = 0x28;
00076     const static uint8_t ELECTRONIC_VOL_41   = 0x29;
00077     const static uint8_t ELECTRONIC_VOL_42   = 0x2a;
00078     const static uint8_t ELECTRONIC_VOL_43   = 0x2b;
00079     const static uint8_t ELECTRONIC_VOL_44   = 0x2c;
00080     const static uint8_t ELECTRONIC_VOL_45   = 0x2d;
00081     const static uint8_t ELECTRONIC_VOL_46   = 0x2e;
00082     const static uint8_t ELECTRONIC_VOL_47   = 0x2f;
00083     const static uint8_t ELECTRONIC_VOL_48   = 0x30;
00084     const static uint8_t ELECTRONIC_VOL_49   = 0x31;
00085     const static uint8_t ELECTRONIC_VOL_50   = 0x32;
00086     const static uint8_t ELECTRONIC_VOL_51   = 0x33;
00087     const static uint8_t ELECTRONIC_VOL_52   = 0x34;
00088     const static uint8_t ELECTRONIC_VOL_53   = 0x35;
00089     const static uint8_t ELECTRONIC_VOL_54   = 0x36;
00090     const static uint8_t ELECTRONIC_VOL_55   = 0x37;
00091     const static uint8_t ELECTRONIC_VOL_56   = 0x38;
00092     const static uint8_t ELECTRONIC_VOL_57   = 0x39;
00093     const static uint8_t ELECTRONIC_VOL_58   = 0x3a;
00094     const static uint8_t ELECTRONIC_VOL_59   = 0x3b;
00095     const static uint8_t ELECTRONIC_VOL_60   = 0x3c;
00096     const static uint8_t ELECTRONIC_VOL_61   = 0x3d;
00097     const static uint8_t ELECTRONIC_VOL_62   = 0x3e;
00098     const static uint8_t ELECTRONIC_VOL_63   = 0x3f;
00099     const static uint8_t SEGMENT_ASCENDING   = 0xa0;
00100     const static uint8_t SEGMENT_DESCENDING  = 0xa1;
00101     const static uint8_t BIAS_1_9            = 0xa2;
00102     const static uint8_t BIAS_1_7            = 0xa3;
00103     const static uint8_t ENTIRE_DISPLAY_OFF  = 0xa4;
00104     const static uint8_t ENTIRE_DISPLAY_ON   = 0xa5;
00105     const static uint8_t INVERT_DISPLAY_OFF  = 0xa6;
00106     const static uint8_t INVERT_DISPLAY_ON   = 0xa7;
00107     const static uint8_t DISPLAY_OFF         = 0xae;
00108     const static uint8_t DISPLAY_ON          = 0xaf;
00109     const static uint8_t COMMON_ASCENDING    = 0xc0;
00110     const static uint8_t COMMON_DESCENDING   = 0xc8;
00111     const static uint8_t MODIFY_WRITE_ON     = 0xe0;
00112     const static uint8_t INTERNAL_RESET      = 0xe2;
00113     const static uint8_t MODIFY_WRITE_OFF    = 0xee;
00114     
00115     const static uint8_t FONT_5X7[128][5];
00116     
00117 private:
00118     uint8_t**  _lineBuffer;
00119     uint8_t    _column, _row;
00120     uint8_t    _columns, _rows;
00121     DigitalOut _rs;
00122     DigitalOut _rst;
00123     SPI        _spi;
00124     DigitalOut _cs;
00125 
00126 public:
00127     /** Constructor of class TextLCD_ST7565SPI.
00128      * @param mosi     SPI data output (MOSI) pin.
00129      * @param sck      SPI clock output (SCK) pin.
00130      * @param cs       SPI Chip select (CS) pin.
00131      * @param rs       Register select (RS or A0) pin.
00132      * @param rst      Hardware reset (RST) pin.
00133      * @param columns  Number of characters in a row.
00134      * @param rows     Number of rows. 
00135      */
00136     TextLCD_ST7565SPI(PinName mosi, PinName sck, PinName cs,
00137                       PinName rs, PinName rst,
00138                       uint8_t columns, uint8_t rows);
00139     
00140     /** Destructor of class TextLCD_ST7565SPI. */
00141     virtual ~TextLCD_ST7565SPI();
00142     
00143     /** Hit hardware reset pin. */
00144     void reset();
00145     
00146     /** Initialize controller.
00147      * @param v0        Internal V0 setting (0..7).
00148      * @param contrast  Contrast setting (0..63).
00149      * @param bias      Bias configuration for your LCD.
00150      */
00151     void init(uint8_t v0, uint8_t contrast, Bias bias);
00152 
00153     /** Clear display and set cursor to home. */    
00154     void cls();
00155     
00156     /** Set cursor position for next character.
00157      * @param column  Column position indexed from 0.
00158      * @param row     Row position indexed from 0.
00159      */
00160     void locate(uint8_t column, uint8_t row);
00161     
00162 private:
00163     /** Implementation of putc from Stream class. */
00164     virtual int _putc(int c);
00165     
00166     /** Implementation of getc from Stream class. */
00167     virtual int _getc();
00168 
00169     /** Shift up the lower line for scrolling. */
00170     void shiftUp();
00171 
00172     /** Clear entire display. */
00173     void clear();
00174 
00175     /** Set page position for next data.
00176      * @param page  Page position indexed from 0 to 7.
00177      */ 
00178     void setPage(uint8_t page);
00179     
00180     /** Set column position for next data.
00181      * @param column  Column position indexed from 0.
00182      */
00183     void setColumn(uint8_t column);
00184     
00185     /** Write a command byte for LCD controller.
00186      * @param c  The command byte.
00187      */
00188     void command(uint8_t c);
00189 
00190     /** Write a data byte for LCD controller.
00191      * @param d  The data byte.
00192      */
00193     void data(uint8_t d);
00194 };
00195 
00196 #endif