Backlight control aspects on Toradex modules
On Windows CE, the backlight can be controlled independently from the display driver. But there is one exception to take note of, if the registry settings for backlight GPIO and display GPIO are identical, a change of the backlight will also change the state of the Display driver accordingly. Please refer to display driver registry settings for details. It is important to note that this is applicable only for Colibri PXA Modules.
The backlight is turned off by default after a timeout that starts whenever there is no user activity on the system. Similarly, it is automatically turned on as soon as there is any user activity detected.
The backlight timeout can be controlled manually from the control panel:
Control Panel -> Display
These settings are stored in the registry at key name:
[HKCU\ControlPanel\Backlight] ACTimeout =dword:0x00000258 ;Time[seconds] before Backlight is turned off when on external power BatteryTimeout=dword:0x00000258 ;Time[seconds] before Backlight is turned off when on battery power
In order to completely avoid the backlight from turning off, the following registry settings need to be added:
; never turn off backlight [HKCU\ControlPanel\Backlight] UseExt =dword:0x00000000 ; 0: don't switch off backlight when on external power UseBattery =dword:0x00000000 ; 0: don't switch off backlight when on battery power
It is to be noted that you can use the ExtEscape() function to control the backlight from your application, thereby, overriding the automatic user activity / timeout detection. The code below shows the basic structure of a call to ExtEscape(). The function sets the backlight status to the value new_backlight, and returns the backlight status before applying the change in old_backlight.
DWORD old_backlight; DWORD new_backlight=0; ExtEscape(GetDC(NULL), BACKLIGHT, 4, (char*)&new_backlight, 4, (char*)&old_backlight);
The following values for new_backlight are supported:
- (NULL) Read the current backlight status
- 0 Turn the backlight off before the timer expires
- 255 Turn the backlight on and reset the timer, without any user activity
- 256 Force the backlight off, then ignore timers and user activity
- 511 Force the backlight on, then ignore timers and user activity
The code snipplet below shows how to use the ExtEscape() function:
#define ESCAPECODEBASE 100000 #define MOUSECURSOR (ESCAPECODEBASE + 20) #define BACKLIGHT (ESCAPECODEBASE + 21) #define BACKLIGHT_FORCE_STATE 256 DWORD old_backlight; DWORD new_backlight=0; //Get Backlight Status ExtEscape(GetDC(NULL), BACKLIGHT, 0, NULL, 4, (char*)&old_backlight); //Disable Backlight until user activity new_backlight=0; ExtEscape(GetDC(NULL), BACKLIGHT, 4, (char*)&new_backlight, 4, (char*)&old_backlight); //Enable Backlight until timeout new_backlight=255; ExtEscape(GetDC(NULL), BACKLIGHT, 4, (char*)&new_backlight, 4, (char*)&old_backlight); //Force Backlight OFF new_backlight=0|BACKLIGHT_FORCE_STATE ; ExtEscape(GetDC(NULL), BACKLIGHT, 4, (char*)&new_backlight, 4, (char*)&old_backlight); //Force Backlight ON new_backlight=255|BACKLIGHT_FORCE_STATE ; ExtEscape(GetDC(NULL), BACKLIGHT, 4, (char*)&new_backlight, 4, (char*)&old_backlight);
The following lists the pair of manual-reset events that are signaled to indicate if the display is on or off:
The WaitForSingleObject() API function can be used to request the status or wait for these events.
On our carrier boards, PWM<A> is used for adjusting LCD brightness.
The PWM backlight brightness can be adjusted via sysfs as follows (1 being brightest and 255 being darkest):
root@colibri_t20:~# cat /sys/class/backlight/pwm-backlight/bl_power 0 root@colibri_t20:~# echo 1 > /sys/class/backlight/pwm-backlight/bl_power root@colibri_t20:~# echo 0 > /sys/class/backlight/pwm-backlight/bl_power root@colibri_t20:~# cat /sys/class/backlight/pwm-backlight/brightness 224 root@colibri_t20:~# echo 1 > /sys/class/backlight/pwm-backlight/brightness
Please note that for the Ampire 5.7" LED VGA Touch TFT connected to the MECS Tellurium the brightness behaves inverse (e.g. 255 being brightest and 1 being darkest).
To automatically set the back light to the desired level on one can create a systemd service. First create the file /etc/systemd/system/backlight.service.
Note: On Vybrid the PWM backlight has an instance number appended (i.e. /sys/class/backlight/pwm-backlight.0)
[Unit] Description=Backlight brightness service, set and store display brightness setting After=multi-user.target [Service] Type=oneshot RemainAfterExit=true ExecStart=/bin/sh -c 'cat /etc/brightness > /sys/class/backlight/pwm-backlight/brightness' ExecStop=/bin/sh -c 'cat /sys/class/backlight/pwm-backlight/brightness > /etc/brightness' [Install] WantedBy=multi-user.target
Reload and enable the service.
$ systemctl --system daemon-reload $ systemctl enable backlight
New Release:TorizonCore 5.5.0 Quarterly Release
New Release:TorizonCore 5.4.0 Quarterly Release