diff options
author | Andreas Regel <andreas.regel@gmx.de> | 2015-04-24 21:51:29 +0200 |
---|---|---|
committer | Andreas Regel <andreas.regel@gmx.de> | 2016-04-01 23:47:51 +0200 |
commit | 110dc03d98ecbb873d399c75e221a8b0e27f060a (patch) | |
tree | eb49cb5e143802e95559eeb4d2f1b900b1f0099e | |
parent | 0dab8701003ba9b91924ee776658a58075cc6530 (diff) | |
download | graphlcd-base-110dc03d98ecbb873d399c75e221a8b0e27f060a.tar.gz graphlcd-base-110dc03d98ecbb873d399c75e221a8b0e27f060a.tar.bz2 |
ili9341: Use the PWM for the backlight brightness.
-rw-r--r-- | glcddrivers/ili9341.c | 31 |
1 files changed, 30 insertions, 1 deletions
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() |