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.
Fork of TFTLCD by
Diff: lcd_base.cpp
- Revision:
- 22:4c169297f374
- Parent:
- 21:e5c1e8ffada1
diff -r e5c1e8ffada1 -r 4c169297f374 lcd_base.cpp --- a/lcd_base.cpp Sat Jan 26 02:55:46 2013 +0000 +++ b/lcd_base.cpp Sat Jan 26 04:36:46 2013 +0000 @@ -22,12 +22,54 @@ #include "lcd_base.h" #include "helpers.h" -LCD::LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS, PinName RESET ) - : _disp_width( width ), _disp_height( height ), _lcd_pin_cs( CS ), _lcd_pin_rs( RS ), _lcd_pin_reset( RESET ) +LCD::LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS, PinName RESET, PinName BL, backlight_t blType, float defaultBacklight ) + : _disp_width( width ), _disp_height( height ), _lcd_pin_cs( CS ), _lcd_pin_rs( RS ), _lcd_pin_reset( RESET ), _bl_type( blType ) { SetForeground(); SetBackground(); _font = &TerminusFont; + if ( defaultBacklight < 0 ) _bl_pwm_default = 0; + else if ( defaultBacklight > 1.0 ) _bl_pwm_default = 1.0; + else _bl_pwm_default = defaultBacklight; + if ( BL != NC ) + { + if ( blType == Constant ) + { + _bl_pwm = 0; + _lcd_pin_bl = new DigitalOut( BL ); + } + else + { + _lcd_pin_bl = 0; + _bl_pwm = new PwmOut( BL ); + _bl_pwm->period_ms( 8.33 ); // 120 Hz + _bl_pwm_current = _bl_pwm_default; + // initially off + *_bl_pwm = 0; + } + + } + else + { + _lcd_pin_bl = 0; + _bl_pwm = 0; + } +} + +void LCD::Sleep( void ) +{ + if ( _lcd_pin_bl != 0 ) + *_lcd_pin_bl = LOW; + else if ( _bl_pwm != 0 ) + *_bl_pwm = 0; +} + +void LCD::WakeUp( void ) +{ + if ( _lcd_pin_bl != 0 ) + *_lcd_pin_bl = HIGH; + else if ( _bl_pwm != 0 ) + *_bl_pwm = _bl_pwm_current; } inline @@ -75,6 +117,26 @@ return 0; } +void LCD::SetBacklightLevel( float level ) +{ + switch ( _bl_type ) + { + case Direct: + if ( _bl_pwm != 0 ) + { + *_bl_pwm = level; + _bl_pwm_current = level; + } + break; + + case Indirect: + break; + case Constant: + default: + break; + } +} + void LCD::FillScreen( int color ) { unsigned int rgb = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;