Added ability to use printf directly

Fork of LCD_DISCO_F429ZI by ST

Revision:
1:45d79100d676
Parent:
0:dc55a068bc1a
--- a/LCD_DISCO_F429ZI.h	Thu Dec 17 10:26:56 2015 +0000
+++ b/LCD_DISCO_F429ZI.h	Fri Feb 05 09:17:26 2016 +0000
@@ -45,7 +45,7 @@
       }
   }
 */
-class LCD_DISCO_F429ZI
+class LCD_DISCO_F429ZI : public Stream //use Stream base class
 {
   
 public:
@@ -217,6 +217,14 @@
   void DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii);
 
   /**
+    * @brief  Moves cursor.
+    * @param  Xpos: start column address
+    * @param  Ypos: the Line where to display the character shape
+    * @retval None
+    */
+  void Cursor(uint16_t Xpos, uint16_t Ypos);
+
+  /**
     * @brief  Displays a maximum of 60 char on the LCD.
     * @param  X: pointer to x position (in pixel);
     * @param  Y: pointer to y position (in pixel);    
@@ -385,7 +393,29 @@
   void DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code);
 
 private:
+    uint16_t cursorX;
+    uint16_t cursorY;
 
+protected:
+    //used by printf
+    virtual int _putc(int c) {
+        if( COLUMN(cursorX+1) >= BSP_LCD_GetXSize() ) {
+            cursorX = 0;
+            cursorY++;
+        }
+        if( c > 31 && c <127 ) {
+            BSP_LCD_DisplayChar(COLUMN(cursorX), LINE(cursorY), c);
+            cursorX++;
+        }
+        // TODO: Handle wraparound based on font size
+        if( c == '\n' ) cursorX = 0;
+        if( c == '\r' ) cursorY++;
+        return 0;
+    };
+//assuming no reads from LCD
+    virtual int _getc() {
+        return -1;
+    }
 };
 
 #else