Hotboards_SpiLcd.cpp - Library for write and control and lcd with spi interfaces and the ST7032 controller. Base on Arduino's Liquid Cristal library

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

Committer:
Hotboards
Date:
Sat Feb 27 20:02:57 2016 +0000
Revision:
2:9673849ef2e9
Parent:
1:b777b6147d99
Child:
3:e16488b64ef7
added mbed documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Hotboards 0:1d03652e9f7a 1 /*
Hotboards 1:b777b6147d99 2 Hotboards_SpiLcd.cpp - Library to control and write an lcd with spi interface and ST7032 controller.
Hotboards 0:1d03652e9f7a 3 base on Arduino's Liquid Cristal library
Hotboards 0:1d03652e9f7a 4 Library ported by diego from Hotboards January 16, 2016.
Hotboards 0:1d03652e9f7a 5 and originally cretaed by
Hotboards 0:1d03652e9f7a 6 by David A. Mellis
Hotboards 0:1d03652e9f7a 7 library modified 5 Jul 2009
Hotboards 0:1d03652e9f7a 8 by Limor Fried (http://www.ladyada.net)
Hotboards 0:1d03652e9f7a 9 example added 9 Jul 2009
Hotboards 0:1d03652e9f7a 10 by Tom Igoe
Hotboards 0:1d03652e9f7a 11 modified 22 Nov 2010
Hotboards 0:1d03652e9f7a 12 by Tom Igoe
Hotboards 0:1d03652e9f7a 13 Released into the public domain.
Hotboards 0:1d03652e9f7a 14 */
Hotboards 0:1d03652e9f7a 15
Hotboards 0:1d03652e9f7a 16 #ifndef Hotboards_SpiLcd_h
Hotboards 0:1d03652e9f7a 17 #define Hotboards_SpiLcd_h
Hotboards 0:1d03652e9f7a 18
Hotboards 0:1d03652e9f7a 19 #include "mbed.h"
Hotboards 0:1d03652e9f7a 20
Hotboards 0:1d03652e9f7a 21 // commands
Hotboards 0:1d03652e9f7a 22 #define HT_SPILCD_CLEARDISPLAY 0x01
Hotboards 0:1d03652e9f7a 23 #define HT_SPILCD_RETURNHOME 0x02
Hotboards 0:1d03652e9f7a 24 #define HT_SPILCD_ENTRYMODESET 0x04
Hotboards 0:1d03652e9f7a 25 #define HT_SPILCD_DISPLAYCONTROL 0x08
Hotboards 0:1d03652e9f7a 26 #define HT_SPILCD_CURSORSHIFT 0x10
Hotboards 0:1d03652e9f7a 27 #define HT_SPILCD_FUNCTIONSET 0x20
Hotboards 0:1d03652e9f7a 28 #define HT_SPILCD_SETCGRAMADDR 0x40
Hotboards 0:1d03652e9f7a 29 #define HT_SPILCD_SETDDRAMADDR 0x80
Hotboards 0:1d03652e9f7a 30
Hotboards 0:1d03652e9f7a 31 // flags for display entry mode
Hotboards 0:1d03652e9f7a 32 #define HT_SPILCD_ENTRYRIGHT 0x00
Hotboards 0:1d03652e9f7a 33 #define HT_SPILCD_ENTRYLEFT 0x02
Hotboards 0:1d03652e9f7a 34 #define HT_SPILCD_ENTRYSHIFTINCREMENT 0x01
Hotboards 0:1d03652e9f7a 35 #define HT_SPILCD_ENTRYSHIFTDECREMENT 0x00
Hotboards 0:1d03652e9f7a 36
Hotboards 0:1d03652e9f7a 37 // flags for display on/off control
Hotboards 0:1d03652e9f7a 38 #define HT_SPILCD_DISPLAYON 0x04
Hotboards 0:1d03652e9f7a 39 #define HT_SPILCD_DISPLAYOFF 0x00
Hotboards 0:1d03652e9f7a 40 #define HT_SPILCD_CURSORON 0x02
Hotboards 0:1d03652e9f7a 41 #define HT_SPILCD_CURSOROFF 0x00
Hotboards 0:1d03652e9f7a 42 #define HT_SPILCD_BLINKON 0x01
Hotboards 0:1d03652e9f7a 43 #define HT_SPILCD_BLINKOFF 0x00
Hotboards 0:1d03652e9f7a 44
Hotboards 0:1d03652e9f7a 45 // flags for display/cursor shift
Hotboards 0:1d03652e9f7a 46 #define HT_SPILCD_DISPLAYMOVE 0x08
Hotboards 0:1d03652e9f7a 47 #define HT_SPILCD_CURSORMOVE 0x00
Hotboards 0:1d03652e9f7a 48 #define HT_SPILCD_MOVERIGHT 0x04
Hotboards 0:1d03652e9f7a 49 #define HT_SPILCD_MOVELEFT 0x00
Hotboards 0:1d03652e9f7a 50
Hotboards 0:1d03652e9f7a 51 // flags for function set
Hotboards 0:1d03652e9f7a 52 #define HT_SPILCD_8BITMODE 0x10
Hotboards 0:1d03652e9f7a 53 #define HT_SPILCD_4BITMODE 0x00
Hotboards 0:1d03652e9f7a 54 #define HT_SPILCD_2LINE 0x08
Hotboards 0:1d03652e9f7a 55 #define HT_SPILCD_1LINE 0x00
Hotboards 0:1d03652e9f7a 56 #define HT_SPILCD_5x16DOTS 0x04
Hotboards 0:1d03652e9f7a 57 #define HT_SPILCD_5x8DOTS 0x00
Hotboards 0:1d03652e9f7a 58 #define HT_SPILCD_EXTINST 0x01
Hotboards 0:1d03652e9f7a 59 #define HT_SPILCD_NORMINST 0x00
Hotboards 0:1d03652e9f7a 60
Hotboards 0:1d03652e9f7a 61
Hotboards 2:9673849ef2e9 62 /** Hotboards_SpiLcd class.
Hotboards 2:9673849ef2e9 63 * Used to control lcd with spi serial interface
Hotboards 2:9673849ef2e9 64 *
Hotboards 2:9673849ef2e9 65 * Example:
Hotboards 2:9673849ef2e9 66 * @code
Hotboards 2:9673849ef2e9 67 * #include "mbed.h"
Hotboards 2:9673849ef2e9 68 * #include "Hotboards_SpiLcd.h"
Hotboards 2:9673849ef2e9 69 *
Hotboards 2:9673849ef2e9 70 * Hotboards_SpiLcd lcd( PB_5, NC, PB_3 ); // mosi, miso, sclk
Hotboards 2:9673849ef2e9 71 *
Hotboards 2:9673849ef2e9 72 * int main( void )
Hotboards 2:9673849ef2e9 73 * {
Hotboards 2:9673849ef2e9 74 * lcd.init( );
Hotboards 2:9673849ef2e9 75 * lcd.printf( "Hola mundo" );
Hotboards 2:9673849ef2e9 76 * }
Hotboards 2:9673849ef2e9 77 * @endcode
Hotboards 2:9673849ef2e9 78 */
Hotboards 0:1d03652e9f7a 79 class Hotboards_SpiLcd : public Stream
Hotboards 0:1d03652e9f7a 80 {
Hotboards 0:1d03652e9f7a 81 public:
Hotboards 0:1d03652e9f7a 82
Hotboards 2:9673849ef2e9 83 /** Create Hotboards_SpiLcd instance
Hotboards 2:9673849ef2e9 84 */
Hotboards 0:1d03652e9f7a 85 Hotboards_SpiLcd( SPI &spi, PinName cs, PinName rs, PinName rst );
Hotboards 2:9673849ef2e9 86
Hotboards 2:9673849ef2e9 87 /** send commands to initialize internal lcd controller
Hotboards 2:9673849ef2e9 88 */
Hotboards 0:1d03652e9f7a 89 void init( void );
Hotboards 2:9673849ef2e9 90
Hotboards 2:9673849ef2e9 91 /** Clears the LCD screen and positions the cursor in the upper-left corner.
Hotboards 2:9673849ef2e9 92 */
Hotboards 0:1d03652e9f7a 93 void clear( void );
Hotboards 2:9673849ef2e9 94
Hotboards 2:9673849ef2e9 95 /** Positions the cursor in the upper-left of the LCD. That is, use that location
Hotboards 2:9673849ef2e9 96 * in outputting subsequent text to the display. To also clear the display, use
Hotboards 2:9673849ef2e9 97 * the clear() function instead
Hotboards 2:9673849ef2e9 98 */
Hotboards 0:1d03652e9f7a 99 void home( void );
Hotboards 0:1d03652e9f7a 100
Hotboards 2:9673849ef2e9 101 /** Turns off the LCD display, without losing the text currently shown on it.
Hotboards 2:9673849ef2e9 102 */
Hotboards 0:1d03652e9f7a 103 void noDisplay( void );
Hotboards 2:9673849ef2e9 104
Hotboards 2:9673849ef2e9 105 /** Turns on the LCD display, after it's been turned off with noDisplay().
Hotboards 2:9673849ef2e9 106 * This will restore the text (and cursor) that was on the display.
Hotboards 2:9673849ef2e9 107 */
Hotboards 0:1d03652e9f7a 108 void display( void );
Hotboards 2:9673849ef2e9 109
Hotboards 2:9673849ef2e9 110 /** Turns off the blinking LCD cursor.
Hotboards 2:9673849ef2e9 111 */
Hotboards 0:1d03652e9f7a 112 void noBlink( void );
Hotboards 2:9673849ef2e9 113
Hotboards 2:9673849ef2e9 114 /** Display the blinking LCD cursor. If used in combination with the cursor() function,
Hotboards 2:9673849ef2e9 115 * the result will depend on the particular display.
Hotboards 2:9673849ef2e9 116 */
Hotboards 0:1d03652e9f7a 117 void blink( void );
Hotboards 2:9673849ef2e9 118
Hotboards 2:9673849ef2e9 119 /** Hides the LCD cursor.
Hotboards 2:9673849ef2e9 120 */
Hotboards 0:1d03652e9f7a 121 void noCursor( void );
Hotboards 2:9673849ef2e9 122
Hotboards 2:9673849ef2e9 123 /** Display the LCD cursor: an underscore (line) at the position to which the
Hotboards 2:9673849ef2e9 124 * next character will be written.
Hotboards 2:9673849ef2e9 125 */
Hotboards 0:1d03652e9f7a 126 void cursor( void );
Hotboards 2:9673849ef2e9 127
Hotboards 2:9673849ef2e9 128 /** Scrolls the contents of the display (text and cursor) one space to the left.
Hotboards 2:9673849ef2e9 129 */
Hotboards 0:1d03652e9f7a 130 void scrollDisplayLeft( void );
Hotboards 2:9673849ef2e9 131
Hotboards 2:9673849ef2e9 132 /** Scrolls the contents of the display (text and cursor) one space to the right.
Hotboards 2:9673849ef2e9 133 */
Hotboards 0:1d03652e9f7a 134 void scrollDisplayRight( void );
Hotboards 2:9673849ef2e9 135
Hotboards 2:9673849ef2e9 136 /** Set the direction for text written to the LCD to left-to-right, the default.
Hotboards 2:9673849ef2e9 137 * This means that subsequent characters written to the display will go from left to right,
Hotboards 2:9673849ef2e9 138 * but does not affect previously-output text.
Hotboards 2:9673849ef2e9 139 */
Hotboards 0:1d03652e9f7a 140 void leftToRight( void );
Hotboards 2:9673849ef2e9 141
Hotboards 2:9673849ef2e9 142 /** Set the direction for text written to the LCD to right-to-left (the default is left-to-right).
Hotboards 2:9673849ef2e9 143 * This means that subsequent characters written to the display will go from right to left,
Hotboards 2:9673849ef2e9 144 * but does not affect previously-output text.
Hotboards 2:9673849ef2e9 145 */
Hotboards 0:1d03652e9f7a 146 void rightToLeft( void );
Hotboards 2:9673849ef2e9 147
Hotboards 2:9673849ef2e9 148 /** Turns on automatic scrolling of the LCD. This causes each character
Hotboards 2:9673849ef2e9 149 * output to the display to push previous characters over by one space.
Hotboards 2:9673849ef2e9 150 * If the current text direction is left-to-right (the default),
Hotboards 2:9673849ef2e9 151 * the display scrolls to the left; if the current direction is right-to-left,
Hotboards 2:9673849ef2e9 152 * the display scrolls to the right. This has the effect of outputting
Hotboards 2:9673849ef2e9 153 * each new character to the same location on the LCD.
Hotboards 2:9673849ef2e9 154 */
Hotboards 0:1d03652e9f7a 155 void autoscroll( void );
Hotboards 2:9673849ef2e9 156
Hotboards 2:9673849ef2e9 157 /** Turns off automatic scrolling of the LCD.
Hotboards 2:9673849ef2e9 158 */
Hotboards 0:1d03652e9f7a 159 void noAutoscroll( void );
Hotboards 0:1d03652e9f7a 160
Hotboards 0:1d03652e9f7a 161 //void setRowOffsets( int row1, int row2 );
Hotboards 2:9673849ef2e9 162
Hotboards 0:1d03652e9f7a 163 //void createChar( uint8_t, uint8_t[] );
Hotboards 2:9673849ef2e9 164
Hotboards 2:9673849ef2e9 165 /** Position the LCD cursor; that is, set the location at which subsequent
Hotboards 2:9673849ef2e9 166 * text written to the LCD will be displayed.
Hotboards 2:9673849ef2e9 167 *
Hotboards 2:9673849ef2e9 168 * @param col: the column at which to position the cursor (with 0 being the first column)
Hotboards 2:9673849ef2e9 169 * @param row: the row at which to position the cursor (with 0 being the first row)
Hotboards 2:9673849ef2e9 170 */
Hotboards 2:9673849ef2e9 171 void setCursor( uint8_t col, uint8_t row );
Hotboards 2:9673849ef2e9 172
Hotboards 2:9673849ef2e9 173 /** Write a character to the LCD.
Hotboards 2:9673849ef2e9 174 * @data: the character to write to the display
Hotboards 2:9673849ef2e9 175 */
Hotboards 0:1d03652e9f7a 176 void command( uint8_t );
Hotboards 0:1d03652e9f7a 177 #if DOXYGEN_ONLY
Hotboards 2:9673849ef2e9 178 /** Write a character to the LCD.
Hotboards 2:9673849ef2e9 179 * @param c: character to display
Hotboards 2:9673849ef2e9 180 */
Hotboards 2:9673849ef2e9 181 int putc(int c);
Hotboards 2:9673849ef2e9 182
Hotboards 2:9673849ef2e9 183 /** Write a formatted string of characters to the LCD.
Hotboards 2:9673849ef2e9 184 * @param format: formatted string
Hotboards 2:9673849ef2e9 185 */
Hotboards 0:1d03652e9f7a 186 int printf(const char* format, ...);
Hotboards 0:1d03652e9f7a 187 #endif
Hotboards 0:1d03652e9f7a 188
Hotboards 0:1d03652e9f7a 189
Hotboards 0:1d03652e9f7a 190 protected:
Hotboards 0:1d03652e9f7a 191
Hotboards 0:1d03652e9f7a 192 void send( uint8_t, uint8_t );
Hotboards 0:1d03652e9f7a 193
Hotboards 0:1d03652e9f7a 194 // redirection for the printf and putc functions
Hotboards 0:1d03652e9f7a 195 virtual int _putc( int value );
Hotboards 0:1d03652e9f7a 196 virtual int _getc( void );
Hotboards 0:1d03652e9f7a 197
Hotboards 0:1d03652e9f7a 198 // internal objects
Hotboards 0:1d03652e9f7a 199 SPI _spi;
Hotboards 0:1d03652e9f7a 200
Hotboards 0:1d03652e9f7a 201 DigitalOut _cs_pin;
Hotboards 0:1d03652e9f7a 202 DigitalOut _rs_pin;
Hotboards 0:1d03652e9f7a 203 DigitalOut _rst_pin;
Hotboards 0:1d03652e9f7a 204
Hotboards 0:1d03652e9f7a 205 uint8_t _displayfunction;
Hotboards 0:1d03652e9f7a 206 uint8_t _displaycontrol;
Hotboards 0:1d03652e9f7a 207 uint8_t _displaymode;
Hotboards 0:1d03652e9f7a 208 };
Hotboards 0:1d03652e9f7a 209
Hotboards 0:1d03652e9f7a 210 #endif /* Hotboards_SpiLcd_h */