zoukankan      html  css  js  c++  java
  • openwrt的led configuration

    一、led配置

    1、界面说明

     如上图可在led configuration界面添加对于led灯的控制。

    通过add按钮添加led闪烁的触发事件。

    Name:配置led名字。

    LED Name:设置红灯和绿灯。  (目前用的测试板红灯和绿灯都显示绿灯)

    Default state:选中时灯亮度为255,不选时为0.

    Trigger:触发器,设置led的触发方式。在led modules中可以安装触发器module.

    添加后,trigger可选项如下:

    trigger驱动文件目录:openwrtuild_dir arget-arm_cortex-a7+neon-vfpv4_musl_eabilinux-sunxi_cortexa7linux-4.14.25driversleds rigger

    2、Led triggers      参考博客:LEDE/OpenWRT控制gpio-led

          Now we explain in detail what each trigger does.

    (1)None

    The LED is always in default state. Unlisted LED are default OFF, so this is only useful to declare a LED to be always ON.

    (2)Timer

    The LED blinks with the configured on/off frequency.

     (5)Default-on

      The LED is ON. Deprecated, use default=1 trigger=none instead. 

     (6)Heartbeat

      The LED flashes to simulate actual heart beat thump-thump-pause. The frequency is in direct proportion to 1-minute average CPU load. 

     (7)Flash Writes

    The LED flashes as data is written to flash memory.

     (8)Network Activity

    The LED flashes with link status and/or send and receive activity on the configured interface.

     (9)WiFi Activity triggers

      The LED flashes on events triggered in physical interface, rather than in software network interface. Besides phy triggers have more events, it also provides possibility of static LED setup in case you want to monitor your 2.4 GHz radio (phy0 usually) and 5 GHz radio (phy1 usually) separately. netdev can’t guarantee this distinguishing since wlan0 may be referring to 2.4 GHz or 5 GHz radio based on current network setup.

    • phy0rx - flashes on reception.
    • phy0tx - flashes on transmission.
    • phy0assoc - flashes on client association.
    • phy0radio - (unknown, this option did nothing on my tl-wr1043nd)
    • phy0tpt - flashes slowly and steadily on network activity.in comparison to energetic flashes of tx and rx modes
    (10)USB Device

      The LED turns ON if USB device is connected.

     To find out device name use logread to search for it or list /sys/bus/usb/devices (for this example, there would be /sys/bus/usb/devices/1-1 device).

    (11)Morse Code

      The LED signals a message using Morse code. 

     (12)GPIO

      Allows LEDs to be controlled by gpio events. 

    二、led脚本介绍

    脚本中的config_get、config_load、config_foreach的处理方式可查看https://www.cnblogs.com/yuanqiangfei/p/14751882.html

    config_get<variable> <section> <option> [<default>]会获取led配置(etc/config/system文件中关于led section)的参数,如果没有配置相关参数会取默认值

    	config_get sysfs $1 sysfs
    	config_get name $1 name "$sysfs"
    	config_get trigger $1 trigger "none"
    	config_get dev $1 dev
    	config_get ports $1 port
    	config_get mode $1 mode "link"  //link为默认值
    	config_get_bool default $1 default "nil"  
    	config_get delayon $1 delayon
    	config_get delayoff $1 delayoff
    	config_get interval $1 interval "50"
    	config_get port_state $1 port_state
    	config_get delay $1 delay "150"
    	config_get message $1 message ""
    	config_get gpio $1 gpio "0"
    	config_get inverted $1 inverted "0"

     /etc/init.d/led脚本对于这几种触发器类型led状态做处理。

    case "$trigger" in
    		"netdev")
    			[ -n "$dev" ] && {
    				echo $dev > /sys/class/leds/${sysfs}/device_name
    				echo $mode > /sys/class/leds/${sysfs}/mode
    				echo $interval > /sys/class/leds/${sysfs}/interval
    			}
    			;;
    
    		"timer"|"oneshot")
    			[ -n "$delayon" ] && 
    				echo $delayon > /sys/class/leds/${sysfs}/delay_on
    			[ -n "$delayoff" ] && 
    				echo $delayoff > /sys/class/leds/${sysfs}/delay_off
    			;;
    
    		"usbport")
    			local p
    
    			for p in $ports; do
    				echo 1 > /sys/class/leds/${sysfs}/ports/$p
    			done
    			;;
    
    		"port_state")
    			[ -n "$port_state" ] && 
    				echo $port_state > /sys/class/leds/${sysfs}/port_state
    			;;
    
    		"gpio")
    			echo $gpio > /sys/class/leds/${sysfs}/gpio
    			echo $inverted > /sys/class/leds/${sysfs}/inverted
    			;;  

    配置好状态后会将led配置写到/etc/config/system配置文件中:

     然后 /etc/init.d/led脚本会获取/etc/config/system文件中每个option的值写到/sys/class/led/目录下的文件中去。

    三、查看led灯的gpio

     target Profile选择的是Hangzhou vidtoo model A,可通过修改500-ARM-dts-support-vidtoo-model-A.patch文件来修改gpio,打完patch后生成dts文件。 

     openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-sunxi_cortexa7/linux-4.14.25/arch/arm/boot/dts/sun8i-h2-plus-vidtoo-model-A.dts

    dts文件中会有对led灯gpio的配置

    科普
    在OpenWrt/Linux里面,对GPIO的操作都是通过寄存器操作的,详细可以看每个板子的DTSI文件,在DTSI文件里描述了板子寄存器的地址。
    GPIO按组划分,以MT7620A为例,GPIO一共有72个,一共分了四组,组号为0~3。
    0组拥有24个GPIO,GPIO号为0~23;
    1组拥有16个GPIO,GPIO号为24-39;
    2组拥有32个GPIO,GPIO号为40-71;
    3组仅拥有一个GPIO72。
    因此,GPIO号=GPIO组号基址+GPIO组内编号。
    以ZTE Q7路由器为例,GPIO定义在../target/linux/ramips/dts/mt7620n.dtsi文件中定义

    gpio定义的方式是:组号+组内编号

    	leds {
     		compatible = "gpio-leds";
     
     		pwr_led {
     			label = "green:pwr";
     			gpios = <&r_pio 0 10 GPIO_ACTIVE_HIGH>;     //绿灯是第0组的第10个GPIO10默认为高电平
     			default-state = "on";
     		};
     
     		status_led {
     			label = "red:status";
     			gpios = <&pio 0 15 GPIO_ACTIVE_HIGH>;    //红灯是第0组的第15个,GPIO15默认为高电平
                  default-state = "on"; }; };

    如果要修改led的gpio,直接修改openwrt/target/linux/sunxi/patch-4.14/500-ARM_dts-support-vidtoo-model-A.patch文件,不要直接修改dts文件,因为在编译过程中会删除dts文件重新打patch,会覆盖掉修改。 

    可以在500-ARM_dts-support-vidtoo-model-A.patch文件中增加默认trigger 

      

  • 相关阅读:
    ubuntu环境下快速搭建开发环境
    Ubuntu安装mysql及设置远程访问方法
    lua 获取指定目录下指定后缀文件名
    DLL远程注入及卸载实现
    c字符检测函数
    数据库bcp导入导出批处理工具
    Schtasks命令详解(计划任务DOS批处理)
    lmathlib文件
    Github常用命令【转】
    Github上传代码菜鸟超详细教程【转】
  • 原文地址:https://www.cnblogs.com/yuanqiangfei/p/14752782.html
Copyright © 2011-2022 走看看