Added ability to use printf directly

Fork of LCD_DISCO_F429ZI by ST

Files at this revision

API Documentation at this revision

Comitter:
SomeRandomBloke
Date:
Fri Feb 05 09:17:26 2016 +0000
Parent:
0:dc55a068bc1a
Commit message:
Updates to use printf

Changed in this revision

LCD_DISCO_F429ZI.cpp Show annotated file Show diff for this revision Revisions of this file
LCD_DISCO_F429ZI.h Show annotated file Show diff for this revision Revisions of this file
diff -r dc55a068bc1a -r 45d79100d676 LCD_DISCO_F429ZI.cpp
--- a/LCD_DISCO_F429ZI.cpp	Thu Dec 17 10:26:56 2015 +0000
+++ b/LCD_DISCO_F429ZI.cpp	Fri Feb 05 09:17:26 2016 +0000
@@ -141,6 +141,8 @@
 void LCD_DISCO_F429ZI::Clear(uint32_t Color)
 {
   BSP_LCD_Clear(Color);
+  cursorX = 0;
+  cursorY = 0;
 }
 
 void LCD_DISCO_F429ZI::ClearStringLine(uint32_t Line)
@@ -153,6 +155,12 @@
   BSP_LCD_DisplayChar(Xpos, Ypos, Ascii);
 }
 
+void LCD_DISCO_F429ZI::Cursor(uint16_t Xpos, uint16_t Ypos)
+{
+  cursorX = Xpos;
+  cursorY = Ypos;
+}
+
 void LCD_DISCO_F429ZI::DisplayStringAt(uint16_t X, uint16_t Y, uint8_t *pText, Text_AlignModeTypdef mode)
 {
   BSP_LCD_DisplayStringAt(X, Y, pText, mode);
diff -r dc55a068bc1a -r 45d79100d676 LCD_DISCO_F429ZI.h
--- 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