1.44 tft lcd display
Dependencies: TFT_fonts mbed-os
Fork of newTFTLCD by
Diff: lcd_base.cpp
- Revision:
- 22:4c169297f374
- Parent:
- 21:e5c1e8ffada1
- Child:
- 28:6ac2fa56f82c
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;