Hotboards MX / Hotboards_SpiLcd

Dependents:   Hotboards_SpiLcd-Hello_World Hotboards_SpiLcd-Writing_In_Diferent_Rows Hotboards_SpiLcd_Scrolling_Text Hotboards_SpiLcd_AutoScroll ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Hotboards_SpiLcd.h Source File

Hotboards_SpiLcd.h

00001 /*
00002   Hotboards_SpiLcd.cpp - Library to control and write an lcd with spi interface and ST7032 controller.
00003   base on Arduino's Liquid Cristal library
00004   Library ported by diego from Hotboards January 16, 2016. 
00005   and originally cretaed by
00006   by David A. Mellis
00007   library modified 5 Jul 2009
00008   by Limor Fried (http://www.ladyada.net)
00009   example added 9 Jul 2009
00010   by Tom Igoe
00011   modified 22 Nov 2010
00012   by Tom Igoe
00013   Released into the public domain.
00014 */
00015 
00016 #ifndef Hotboards_SpiLcd_h
00017 #define Hotboards_SpiLcd_h
00018 
00019 #include "mbed.h"
00020 
00021 // commands
00022 #define HT_SPILCD_CLEARDISPLAY          0x01
00023 #define HT_SPILCD_RETURNHOME            0x02
00024 #define HT_SPILCD_ENTRYMODESET          0x04
00025 #define HT_SPILCD_DISPLAYCONTROL        0x08
00026 #define HT_SPILCD_CURSORSHIFT           0x10
00027 #define HT_SPILCD_FUNCTIONSET           0x20
00028 #define HT_SPILCD_SETCGRAMADDR          0x40
00029 #define HT_SPILCD_SETDDRAMADDR          0x80
00030 
00031 // flags for display entry mode
00032 #define HT_SPILCD_ENTRYRIGHT            0x00
00033 #define HT_SPILCD_ENTRYLEFT             0x02
00034 #define HT_SPILCD_ENTRYSHIFTINCREMENT   0x01
00035 #define HT_SPILCD_ENTRYSHIFTDECREMENT   0x00
00036 
00037 // flags for display on/off control
00038 #define HT_SPILCD_DISPLAYON             0x04
00039 #define HT_SPILCD_DISPLAYOFF            0x00
00040 #define HT_SPILCD_CURSORON              0x02
00041 #define HT_SPILCD_CURSOROFF             0x00
00042 #define HT_SPILCD_BLINKON               0x01
00043 #define HT_SPILCD_BLINKOFF              0x00
00044 
00045 // flags for display/cursor shift
00046 #define HT_SPILCD_DISPLAYMOVE           0x08
00047 #define HT_SPILCD_CURSORMOVE            0x00
00048 #define HT_SPILCD_MOVERIGHT             0x04
00049 #define HT_SPILCD_MOVELEFT              0x00
00050 
00051 // flags for function set
00052 #define HT_SPILCD_8BITMODE              0x10
00053 #define HT_SPILCD_4BITMODE              0x00
00054 #define HT_SPILCD_2LINE                 0x08
00055 #define HT_SPILCD_1LINE                 0x00
00056 #define HT_SPILCD_5x16DOTS              0x04
00057 #define HT_SPILCD_5x8DOTS               0x00
00058 #define HT_SPILCD_EXTINST               0x01
00059 #define HT_SPILCD_NORMINST              0x00
00060 
00061 
00062 /** Hotboards_SpiLcd class.
00063  *  Used to control lcd with spi serial interface
00064  *
00065  * Example:
00066  * @code
00067  * #include "mbed.h"
00068  * #include "Hotboards_SpiLcd.h"
00069  *
00070  * SPI device( PB_5, NC, PB_3 ); // mosi, miso, sclk
00071  * Hotboards_SpiLcd lcd( device, PC_0, PC_1, PC_2 ); //spi, cs, rs, rst
00072  * 
00073  * int main( void ) 
00074  * {
00075  *     lcd.init( ); 
00076  *     lcd.printf( "Hola mundo" );
00077  * }
00078  * @endcode
00079  */
00080 class Hotboards_SpiLcd : public Stream
00081 {
00082   public:
00083   
00084     /** Create Hotboards_SpiLcd instance
00085       * @param spi spi peripheral to be use to control the lcd
00086       * @param cs pin to control the chip select signal
00087       * @param rs pin to control the data/command signal
00088       * @param rst pin to control the reset signal
00089       *
00090       * Example:
00091       * @code
00092       *   // we need to init an spi peripheral first
00093       *   SPI device( PB_5, NC, PB_3 ); // mosi, miso, sclk
00094       *   // then we can create the instance
00095       *   Hotboards_SpiLcd lcd( device, PC_0, PC_1, PC_2 ); //spi, cs, rs, rst
00096       * @endcode
00097       */     
00098     Hotboards_SpiLcd( SPI &spi, PinName cs, PinName rs, PinName rst );
00099 
00100     /** Send commands to initialize internal lcd controller
00101       *
00102       * Example:
00103       * @code
00104       *   // After create the instance we init
00105       *   lcd.begin();
00106       * @endcode
00107       */
00108     void init( void );
00109 
00110     /** Clears the LCD screen and positions the cursor in the upper-left corner. 
00111       *
00112       * Example:
00113       * @code
00114       *   lcd.clear();
00115       * @endcode
00116       */
00117     void clear( void );
00118 
00119     /** Positions the cursor in the upper-left of the LCD. That is, use that location 
00120       * in outputting subsequent text to the display. To also clear the display, use 
00121       * the clear() function instead
00122       *
00123       * Example:
00124       * @code
00125       *   lcd.home();
00126       * @endcode
00127       */
00128     void home( void );
00129 
00130     /** Turns off the LCD display, without losing the text currently shown on it.
00131       *
00132       * Example:
00133       * @code
00134       *   lcd.noDisplay();
00135       * @endcode
00136       */
00137     void noDisplay( void );
00138 
00139     /** Turns on the LCD display, after it's been turned off with noDisplay(). 
00140       * This will restore the text (and cursor) that was on the display. 
00141       *
00142       * Example:
00143       * @code
00144       *   lcd.display();
00145       * @endcode
00146       */
00147     void display( void );
00148 
00149     /** Turns off the blinking LCD cursor. 
00150       *
00151       * Example:
00152       * @code
00153       *   lcd.noBlink();
00154       * @endcode
00155       */
00156     void noBlink( void );
00157 
00158     /** Display the blinking LCD cursor. If used in combination with the cursor() function, 
00159       * the result will depend on the particular display. 
00160       *
00161       * Example:
00162       * @code
00163       *   lcd.blink();
00164       * @endcode
00165       */
00166     void blink( void );
00167 
00168     /** Hides the LCD cursor.
00169       *
00170       * Example:
00171       * @code
00172       *   lcd.noCursor();
00173       * @endcode
00174       */
00175     void noCursor( void );
00176 
00177     /** Display the LCD cursor: an underscore (line) at the position to which the 
00178       * next character will be written. 
00179       *
00180       * Example:
00181       * @code
00182       *   lcd.cursor();
00183       * @endcode
00184       */
00185     void cursor( void );
00186 
00187     /** Scrolls the contents of the display (text and cursor) one space to the left. 
00188       *
00189       * Example:
00190       * @code
00191       *   lcd.scrollDisplayLeft();
00192       * @endcode
00193       */
00194     void scrollDisplayLeft( void );
00195 
00196     /** Scrolls the contents of the display (text and cursor) one space to the right. 
00197       *
00198       * Example:
00199       * @code
00200       *   lcd.scrollDisplayRight();
00201       * @endcode
00202       */
00203     void scrollDisplayRight( void );
00204 
00205     /** Set the direction for text written to the LCD to left-to-right, the default. 
00206       * This means that subsequent characters written to the display will go from left to right, 
00207       * but does not affect previously-output text. 
00208       *
00209       * Example:
00210       * @code
00211       *   lcd.leftToRight();
00212       * @endcode
00213       */
00214     void leftToRight( void );
00215 
00216     /** Set the direction for text written to the LCD to right-to-left (the default is left-to-right). 
00217       * This means that subsequent characters written to the display will go from right to left, 
00218       * but does not affect previously-output text. 
00219       *
00220       * Example:
00221       * @code
00222       *   lcd.rightToLeft();
00223       * @endcode
00224       */
00225     void rightToLeft( void );
00226 
00227     /** Turns on automatic scrolling of the LCD. This causes each character 
00228       * output to the display to push previous characters over by one space. 
00229       * If the current text direction is left-to-right (the default), 
00230       * the display scrolls to the left; if the current direction is right-to-left, 
00231       * the display scrolls to the right. This has the effect of outputting 
00232       * each new character to the same location on the LCD. 
00233       *
00234       * Example:
00235       * @code
00236       *   lcd.autoscroll();
00237       * @endcode
00238       */
00239     void autoscroll( void );
00240 
00241     /** Turns off automatic scrolling of the LCD.
00242       *
00243       * Example:
00244       * @code
00245       *   lcd.noAutoscroll();
00246       * @endcode
00247       */
00248     void noAutoscroll( void );
00249 
00250     //void setRowOffsets( int row1, int row2 );
00251 
00252     //void createChar( uint8_t, uint8_t[] );
00253 
00254     /** Position the LCD cursor; that is, set the location at which subsequent 
00255       * text written to the LCD will be displayed.
00256       * @param col: the column at which to position the cursor (with 0 being the first column)
00257       * @param row: the row at which to position the cursor (with 0 being the first row) 
00258       *
00259       * Example:
00260       * @code
00261       *   lcd.setCursor( 3, 1 );
00262       * @endcode
00263       */
00264     void setCursor( uint8_t col, uint8_t row );
00265     
00266     /** Send a command to the LCD.
00267       * @data: cmd command to send
00268       *
00269       * Example:
00270       * @code
00271       *   // clear screen command
00272       *   lcd.command( 0x30 );
00273       * @endcode
00274       */ 
00275     void command( uint8_t );
00276     #if DOXYGEN_ONLY
00277        /** Write a character to the LCD.
00278          * @param c: character to display
00279          *
00280          * Example:
00281          * @code
00282          *   lcd.putc();
00283          * @endcode
00284          */
00285         int putc(int c);
00286         
00287         /** Write a formatted string of characters to the LCD.
00288           * @param format: formatted string
00289           *
00290           * Example:
00291           * @code
00292           *   lcd.printf( "number %d: ", 34 );
00293           * @endcode
00294           */     
00295         int printf(const char* format, ...);
00296     #endif
00297     
00298   
00299   protected:
00300 
00301     void send( uint8_t, uint8_t );
00302     
00303     // redirection for the printf and putc functions
00304     virtual int _putc( int value );
00305     virtual int _getc( void );
00306             
00307     // internal objects
00308     SPI _spi;
00309             
00310     DigitalOut _cs_pin;
00311     DigitalOut _rs_pin;
00312     DigitalOut _rst_pin;
00313 
00314     uint8_t _displayfunction;
00315     uint8_t _displaycontrol;
00316     uint8_t _displaymode;
00317 };
00318 
00319 #endif /* Hotboards_SpiLcd_h */