From 110dc03d98ecbb873d399c75e221a8b0e27f060a Mon Sep 17 00:00:00 2001 From: Andreas Regel Date: Fri, 24 Apr 2015 21:51:29 +0200 Subject: ili9341: Use the PWM for the backlight brightness. --- glcddrivers/ili9341.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/glcddrivers/ili9341.c b/glcddrivers/ili9341.c index 2756538..54627d4 100644 --- a/glcddrivers/ili9341.c +++ b/glcddrivers/ili9341.c @@ -30,6 +30,7 @@ const int kLcdHeight = 240; const int kSpiBus = 0; +const int kGpioPwm = 13; const int kGpioReset = 23; const int kGpioDC = 24; @@ -111,6 +112,9 @@ int cDriverILI9341::Init() pinMode(kGpioReset, OUTPUT); pinMode(kGpioDC, OUTPUT); + pinMode(kGpioPwm, PWM_OUTPUT); + SetBrightness(config->brightness); + digitalWrite(kGpioReset, HIGH); digitalWrite(kGpioDC, LOW); @@ -319,7 +323,32 @@ void cDriverILI9341::Refresh(bool refreshAll) void cDriverILI9341::SetBrightness(unsigned int percent) { - //WriteCommand(kCmdSetContrast, percent * 255 / 100); + uint32_t value; + + if (percent == 0) + value = 0; + else if (percent <= 10) + value = 4; + else if (percent <= 20) + value = 8; + else if (percent <= 30) + value = 16; + else if (percent <= 40) + value = 32; + else if (percent <= 50) + value = 64; + else if (percent <= 60) + value = 128; + else if (percent <= 70) + value = 192; + else if (percent <= 80) + value = 320; + else if (percent <= 90) + value = 512; + else + value = 1023; + + pwmWrite(kGpioPwm, value); } void cDriverILI9341::Reset() -- cgit v1.2.3