This is a port of Henning Kralsen's UTFT library for Arduino/chipKIT to mbed, refactored to make full use of C inheritance and access control, in order to reduce work when implementing new drivers and at the same time make the code more readable and easier to maintain. As of now supported are SSD1289 (16-bit interface), HX8340-B (serial interface) and ST7735 (serial interface). Drivers for other controllers will be added as time and resources to acquire the displays to test the code permit.

Dependents:   UTFT_SSD1289

Fork of TFTLCD by Todor Todorov

Revision:
22:4c169297f374
Parent:
21:e5c1e8ffada1
--- a/lcd_base.h	Sat Jan 26 02:55:46 2013 +0000
+++ b/lcd_base.h	Sat Jan 26 04:36:46 2013 +0000
@@ -158,6 +158,34 @@
  */
 typedef struct Bitmap_struct bitmap_t;
 
+/** \struct BacklightPwmCtrl_enum
+ *  \brief Type of backlight control for the LCD.
+ *
+ * When the selected type is \c Constant, the pin is simply on or off - there is no gradation in the intensity of the display.
+ * In this case any free pin can be used to control the backlight.  On the other hand, when PWM is used to control brightness,
+ * take care to use only PWM-able mbed pins (p21, p22, p23, p24, p25, and p26), any other pins won't work.  It is assumed that
+ * you know what you are doing, so no check is done to prevent using a non-PWM pin as assigned control pin, when either \c Direct
+ * or \c Indirect option is used.
+ *
+ * \version 0.1
+ * \remark When choosing PWM to control the backlight, you have the option to choose the pin to either source (\c Direct) or sink
+ *         (\c Indirect) the current for LCD brightness control.  Be aware that the mbed pins can source (and probably sink when
+ *         configured as inputs) only 4 mA @+3V3 VDD.  So if you are intending to use a bigger LCD, whith more LEDs in its backlight
+ *         implementation, you probably want to interface it through a small signal transistor or a small MOSFET, in order to be able
+ *         to handle a higher current without damaging your mbed.
+ * \remark As of version 0.1 (2013-01-25) the Indirect method of PWM has not been implemented yet.
+ */
+enum BacklightPwmCtrl_enum
+{
+    Constant, /**< When the pin is a simple on/off switch. */
+    Direct, /**< Control the brightness with PWM, as the control pin is sourcing the current to drive the backlight LEDs. */
+    Indirect, /**< Control the brightness with PWM, as the control pin is sinking the current which drives the backlight LEDs. */
+};
+/** \typedef backlight_t
+ *  \brief Convenience shortcut for the backlight control type.
+ */
+typedef BacklightPwmCtrl_enum backlight_t;
+
 
 /** Base class for LCD implementations.
  *
@@ -202,7 +230,7 @@
      * \remarks This function is controller-specific and needs to be
      *          implemented separately for each available display.
      */
-    virtual void Sleep( void ) = 0;
+    virtual void Sleep( void );
     
     /** Wakes up the display from sleep mode.
      *
@@ -212,7 +240,7 @@
      * \remarks This function is controller-specific and needs to be
      *          implemented separately for each available display.
      */
-    virtual void WakeUp( void ) = 0;
+    virtual void WakeUp( void );
     
     /** Set the foreground color for painting.
      *
@@ -271,6 +299,11 @@
      */
     virtual void FillScreen( int color = -1 );
     
+    /** Sets the backlight intensity in percent as a float value in the range [0.0,1.0].
+     *  \param level The backligh intensity in percent, where 0.0 is off and 1.0 is full brightness.
+     */
+    virtual void SetBacklightLevel( float level );
+    
     /** Clears the screen.
      *
      * This is the same as calling #FillScreen() or #FillScreen( -1 ) to use the background color.
@@ -408,8 +441,11 @@
      * \param CS Pin connected to the CS input of the display.
      * \param RS Pin connected to the RS input of the display.
      * \param RESET Pin connected to the RESET input of the display.
+     * \param BL Pin connected to the circuit controlling the LCD's backlight.
+     * \param blType The type of backlight to be used.
+     * \param defaultBacklight The standard backlight intensity (if using PWM control), expressed in percent as float value from 0.0 to 1.0
      */
-    LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS, PinName RESET );
+    LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS, PinName RESET, PinName BL, backlight_t blType, float defaultBacklight );
     
     /** Activates the display for command/data transfer.
      *
@@ -539,6 +575,10 @@
     colordepth_t    _colorDepth;
     unsigned int    _foreground, _background;
     const font_t*   _font;
+    DigitalOut*     _lcd_pin_bl;
+    PwmOut*         _bl_pwm;
+    backlight_t     _bl_type;
+    float           _bl_pwm_default, _bl_pwm_current;
 };
 
 #ifdef __cplusplus