【f1c200s/f1c100s】屏幕背光驱动适配

屏幕背光启驱动适配

前言

目前大部分嵌入式设备还是采用PWM调光的方式,当然我的mangopi也是采用这种方式进行背光调节的。linux是自带背光控制驱动程序的,要使用背光控制接口首先得调通PWM得驱动,可以参考上一篇博客PWM驱动适配
既然都有了PWM驱动了,其实就可以控制屏幕背光了,还去调专用的背光控制接口也仅仅是为了简化控制方法吧。

设备树修改

PWM驱动调试成功以后,还需要在设备树根节点中添加backlight节点,如下所示:

backlight: backlight {
    
    
		compatible = "pwm-backlight"; //适配内核pwm-backlight驱动
		pwms = <&pwm 1 500000 0>; //引用PWM1 也就是PWM驱动
		pwm-names = "backlight";
		brightness-levels = <0 4 8 16 32 64 128 255>;
		default-brightness-level = <7>;
		status = "okay";
	};

其中关于节点中的各属性含义可参考内核绑定文档Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt。引用如下:

equired properties:
  - compatible: "pwm-backlight"
  - pwms: OF device-tree PWM specification (see PWM binding[0])
  - power-supply: regulator for supply voltage

Optional properties:
  - pwm-names: a list of names for the PWM devices specified in the
               "pwms" property (see PWM binding[0])
  - enable-gpios: contains a single GPIO specifier for the GPIO which enables
                  and disables the backlight (see GPIO binding[1])
  - post-pwm-on-delay-ms: Delay in ms between setting an initial (non-zero) PWM
                          and enabling the backlight using GPIO.
  - pwm-off-delay-ms: Delay in ms between disabling the backlight using GPIO
                      and setting PWM value to 0.
  - brightness-levels: Array of distinct brightness levels. Typically these
                       are in the range from 0 to 255, but any range starting at
                       0 will do. The actual brightness level (PWM duty cycle)
                       will be interpolated from these values. 0 means a 0% duty
                       cycle (darkest/off), while the last value in the array
                       represents a 100% duty cycle (brightest).
  - default-brightness-level: The default brightness level (index into the
                              array defined by the "brightness-levels" property).
  - num-interpolated-steps: Number of interpolated steps between each value
                            of brightness-levels table. This way a high
                            resolution pwm duty cycle can be used without
                            having to list out every possible value in the
                            brightness-level array.

其中brightness-levels意思就是:
这是一个描述亮度等级的数组,一般是从0到255,0代表亮度为0,255代表亮度为最亮。中间的亮度通过插值进行确定。
在这里brightness-levels = <0 4 8 16 32 64 128 255>,一共分为了8个等级(从0到7)。
default-brightness-level:默认的亮度等级,这里设置为最高亮度等级7。

内核配置

在menuconfig中打开以下选项以使能PWM背光控制:
在这里插入图片描述

结果

启动系统后,在目录/sys/class/backlight/backlight中可以看到和背光相关的目录:

root@mangopi:/sys/class/backlight/backlight# ls
actual_brightness  brightness  max_brightness  subsystem  uevent
bl_power           device      power           type

通过修改brightness即可修改屏幕亮度:

echo 7 > brightness
echo 6 > brightness

猜你喜欢

转载自blog.csdn.net/qq_27350133/article/details/124800980
今日推荐