Addition Support for Arduino I2C based on PCF8574A

Fork of TextLCD by Wim Huiskamp

Files at this revision

API Documentation at this revision

Comitter:
Sissors
Date:
Sat May 10 13:50:25 2014 +0000
Parent:
23:d47f226efb24
Child:
25:6162b31128c9
Commit message:
Added ST7032 support + SPI mode

Changed in this revision

TextLCD.cpp Show annotated file Show diff for this revision Revisions of this file
TextLCD.h Show annotated file Show diff for this revision Revisions of this file
--- a/TextLCD.cpp	Wed Apr 02 18:16:37 2014 +0000
+++ b/TextLCD.cpp	Sat May 10 13:50:25 2014 +0000
@@ -111,7 +111,18 @@
           wait_ms(50);
         
           break;
-
+      case ST7032:
+          _writeByte( 0x1c );   //Internal OSC frequency adjustment 183HZ    bias will be 1/4 
+          wait_us(30);
+          _writeByte( 0x73 );    //Contrast control  low byte
+          wait_us(30);  
+          _writeByte( 0x57 );    //booster circuit is turn on.    /ICON display off. /Contrast control   high byte
+          wait_us(30);
+          _writeByte( 0x6c );  //Follower control
+          wait_us(50);   
+          _writeByte( 0x0c );    //DISPLAY ON
+          wait_us(30);
+          break;
       case WS0010:         
           // WS0010 OLED controller: Initialise DC/DC Voltage converter for LEDs
           // Note: supports 1 or 2 lines (and 16x100 graphics)
@@ -1107,6 +1118,77 @@
 //---------- End TextLCD_SPI ------------
 
 
+//--------- Start TextLCD_NativeSPI -----------
+
+ /** Create a TextLCD interface using an SPI 74595 portexpander
+   *
+   * @param spi             SPI Bus
+   * @param cs              chip select pin (active low)
+   * @param type            Sets the panel size/addressing mode (default = LCD16x2)
+   * @param ctrl            LCD controller (default = HD44780)      
+   */
+TextLCD_NativeSPI::TextLCD_NativeSPI(SPI *spi, PinName cs, PinName rs, LCDType type, PinName bl, LCDCtrl ctrl) :
+                         TextLCD_Base(type, ctrl), 
+                         _spi(spi),        
+                         _cs(cs),
+                         _rs(rs) {      
+        
+  // Setup the spi for 8 bit data, low steady state clock,
+  // rising edge capture, with a 500KHz or 1MHz clock rate  
+  _spi->format(8,0);
+  _spi->frequency(1000000);    
+  
+  // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access.
+  if (bl != NC) {
+    _bl = new DigitalOut(bl);   //Construct new pin 
+    _bl->write(0);              //Deactivate    
+  }
+  else {
+    // No Hardware Backlight pin       
+    _bl = NULL;                 //Construct dummy pin     
+  }  
+  
+  _writeByte( 0x39 );  //FUNCTION SET 8 bit,N=1 2-line display mode,5*7dot IS=1
+  wait_us(30);
+  _init();
+}
+
+TextLCD_NativeSPI::~TextLCD_NativeSPI() {
+   if (_bl != NULL) {delete _bl;}  // BL pin
+}
+
+// Not used in this mode
+void TextLCD_NativeSPI::_setEnable(bool value) {
+}    
+
+// Set RS pin
+// Used for mbed pins, I2C bus expander or SPI shiftregister
+void TextLCD_NativeSPI::_setRS(bool value) {
+    _rs = value;
+}    
+
+// Set BL pin
+void TextLCD_NativeSPI::_setBL(bool value) {
+    if (_bl)
+        _bl->write(value);   
+}    
+
+// Write a byte using SPI
+void TextLCD_NativeSPI::_writeByte(int value) {
+    _cs = 0;
+    wait_us(1);
+    _spi->write(value);
+    wait_us(1);
+    _cs = 1;
+}
+    
+
+// Not used in this mode
+void TextLCD_NativeSPI::_setData(int value) {
+}    
+
+
+//---------- End TextLCD_NativeSPI ------------
 
 
 
--- a/TextLCD.h	Wed Apr 02 18:16:37 2014 +0000
+++ b/TextLCD.h	Sat May 10 13:50:25 2014 +0000
@@ -191,7 +191,8 @@
     enum LCDCtrl {
         HD44780,    /**<  HD44780 (default)      */    
         WS0010,     /**<  WS0010 OLED Controller */    
-        ST7036      /**<  ST7036                 */    
+        ST7036,      /**<  ST7036                 */   
+        ST7032      /**<  ST7032                 */   
     };
 
 
@@ -335,7 +336,7 @@
 /** Low level write operations to LCD controller
   */
     void _writeNibble(int value);
-    void _writeByte(int value);
+    virtual void _writeByte(int value);
     void _writeCommand(int command);
     void _writeData(int data);
 
@@ -496,4 +497,42 @@
 
 //---------- End TextLCD_SPI ------------
 
+
+//--------- Start TextLCD_NativeSPI -----------
+
+
+/** Create a TextLCD interface with direct SPI access to the controller
+  *
+  */
+class TextLCD_NativeSPI : public TextLCD_Base {    
+public:
+    /** Create a TextLCD interface using an SPI 74595 portexpander
+     *
+     * @param spi             SPI Bus
+     * @param cs              chip select pin (active low)
+     * @param rs              Instruction/data control line
+     * @param type            Sets the panel size/addressing mode (default = LCD16x2)
+     * @param bl              Backlight control line (optional, default = NC)  
+     * @param ctrl            LCD controller (default = ST7032)                     
+     */
+    TextLCD_NativeSPI(SPI *spi, PinName cs, PinName rs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032);
+    virtual ~TextLCD_NativeSPI(void);
+
+private:
+    virtual void _setEnable(bool value);
+    virtual void _setRS(bool value);  
+    virtual void _setBL(bool value);
+    virtual void _setData(int value);
+    virtual void _writeByte(int value);
+   
+// SPI bus        
+    SPI *_spi;
+    DigitalOut _cs;    
+    DigitalOut _rs;
+    DigitalOut *_bl;
+
+};
+
+//---------- End TextLCD_NativeSPI ------------
+
 #endif