Turning Display Backlight On and Off Print

 

This application note explains how to enable the display backlight on and off, in those hardware design where the backlight is controlled by a GPIO and, therefore, can have one of the two states: off and on.

Note the display backlight can be controlled independently of any display software. That is, the backlight may be turned on and off regardless of whether or not your BSP configuration has a display device driver (and an upper-layer GUI stack) enabled.

Understanding Implementation

Control of the LCD backlight is managed by the standard Linux driver gpio_backlight.c residing in the linux/drivers/video/backlight directory in the kernel tree. The driver is enabled at the build time by the CONFIG_BACKLIGHT_GPIO kernel config option.

For the run-time configuration of the kernel, the LCD backlight is configured in the kernel dts file. For instance, in the i.MX RT1050 BSP refer to rootfs.dts.IMXRT105X_NXPEVK in the projects/rootfs directory. Note that the backlight is turned on by default:

backlight { compatible = "gpio-backlight"; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_backlight>; gpios = <&gpio2 31 GPIO_ACTIVE_HIGH>; default-on; };

Controlling Backlight

To turn the LCD backlight off, run the following command:

/ # echo 0 > /sys/class/backlight/backlight/brightness

To turn the LCD backlight on, run the following command:

/ # echo 1 > /sys/class/backlight/backlight/brightness