summaryrefslogtreecommitdiff
path: root/firmware/target/arm/rk27xx/backlight-rk27xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/rk27xx/backlight-rk27xx.c')
-rw-r--r--firmware/target/arm/rk27xx/backlight-rk27xx.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/firmware/target/arm/rk27xx/backlight-rk27xx.c b/firmware/target/arm/rk27xx/backlight-rk27xx.c
index e759220dff..cb669aecff 100644
--- a/firmware/target/arm/rk27xx/backlight-rk27xx.c
+++ b/firmware/target/arm/rk27xx/backlight-rk27xx.c
@@ -26,11 +26,24 @@
26#include "system.h" 26#include "system.h"
27 27
28static int brightness = DEFAULT_BRIGHTNESS_SETTING; 28static int brightness = DEFAULT_BRIGHTNESS_SETTING;
29static const unsigned short log_brightness[] = { 29
30 0x2710, 0x27ac, 0x2849, 0x2983, 0x2abd, 0x2c93, 0x2e6a, 0x30dd, 30/* Based on http://www.poynton.com/PDFs/SMPTE93_Gamma.pdf
31 0x3351, 0x3661, 0x3971, 0x3d1f, 0x40cc, 0x4516, 0x4960, 0x4e47, 31 * CIE standarized function that relates physical luminance
32 0x532e, 0x58b1, 0x5e35, 0x6456, 0x6a76, 0x7134, 0x77f1, 0x7f4c, 32 * to perceived lightness
33 0x86a6, 0x8e9d, 0x9695, 0x9f29, 0xa7bd, 0xb0ee, 0xba1f, 0xc350 33 *
34 * L* = 116*(Y/Yn)^(1/3) - 16 (Y/Yn > 0 008856)
35 * where Yn is luminance of reference white
36 *
37 * Actual function is lightly tweaked to account for the fact
38 * that fill factor of the PWM below ~15% gives black.
39 * So the function used to calculate the values in the matrix was:
40 * f(x) = 42000 * ((100*x/31 + 16)/116)^3 + 8000
41 */
42static const unsigned short lin_brightness[] = {
43 8110, 8191, 8304, 8455, 8649, 8892, 9189, 9545,
44 9966, 10457, 11024, 11671, 12406, 13232, 14156, 15182,
45 16316, 17565, 18932, 20423, 22045, 23801, 25699, 27742,
46 29937, 32289, 34803, 37485, 40340, 43374, 46592, 50000
34}; 47};
35 48
36bool _backlight_init(void) 49bool _backlight_init(void)
@@ -50,7 +63,7 @@ bool _backlight_init(void)
50 /* set pwm frequency to 500Hz - my lcd panel can't cope more reliably */ 63 /* set pwm frequency to 500Hz - my lcd panel can't cope more reliably */
51 /* (apb_freq/pwm_freq)/pwm_div = (50 000 000/500)/2 */ 64 /* (apb_freq/pwm_freq)/pwm_div = (50 000 000/500)/2 */
52 PWMT0_LRC = 50000; 65 PWMT0_LRC = 50000;
53 PWMT0_HRC = log_brightness[brightness]; 66 PWMT0_HRC = lin_brightness[brightness];
54 67
55 /* reset counter */ 68 /* reset counter */
56 PWMT0_CNTR = 0x00; 69 PWMT0_CNTR = 0x00;
@@ -88,5 +101,5 @@ void _backlight_off(void)
88void _backlight_set_brightness(int val) 101void _backlight_set_brightness(int val)
89{ 102{
90 brightness = val & 0x1f; 103 brightness = val & 0x1f;
91 PWMT0_HRC = log_brightness[brightness]; 104 PWMT0_HRC = lin_brightness[brightness];
92} 105}