配置LED流程:
1、修改设备树,增加led节点
2、查看gpio复用,将led对应的端口配置成gpio模式
3、添加led触发模式
MT7688 共47个IO, 分两组控制,gpio0[0-31],gpio1[32-46]
1、添加led节点
led-wifi:gpio42 对应 gpio1_10
led-usb:gpio41 对应 gpio1_9
(此处led-usb只是定义led的名字,可用于usb状态,也可用于其他,例如lan口状态)
leds {
compatible = "gpio-leds";
// led_wifi: wifi {
// label = "linkit-smart-7688:orange:wifi";
// gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
// };
// gpio42-gpio1_10
led_wifi: wifi {
label = "led-wifi";
gpios = <&gpio1 10 GPIO_ACTIVE_LOW>;
linux,default-trigger = "phy0tpt";
};
// gpio41-gpio1_9
led_usb: usb {
label = "led-usb";
gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
linux,default-trigger = "usbport";
};
};
2、修改gpio复用
查看build_dir/target-mipsel_24kc_musl/linux-ramips_mt76x8/linux-4.14.180/arch/mips/ralink/mt7620.c
从prom_soc_init中,可确定7688 用的是mt7628an_pinmux_data。不同的型号,用的pinmap不同。
if (is_mt76x8())
rt2880_pinmux_data = mt7628an_pinmux_data;
else
rt2880_pinmux_data = mt7620a_pinmux_data;
mt7628an_pinmux_data定义如下:
static struct rt2880_pmx_group mt7628an_pinmux_data[] = {
GRP_G("pwm1", pwm1_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_PWM1),
GRP_G("pwm0", pwm0_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_PWM0),
GRP_G("uart2", uart2_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_UART2),
GRP_G("uart1", uart1_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_UART1),
GRP_G("i2c", i2c_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_I2C),
GRP("refclk", refclk_grp_mt7628, 1, MT7628_GPIO_MODE_REFCLK),
GRP("perst", perst_grp_mt7628, 1, MT7628_GPIO_MODE_PERST),
GRP("wdt", wdt_grp_mt7628, 1, MT7628_GPIO_MODE_WDT),
GRP("spi", spi_grp_mt7628, 1, MT7628_GPIO_MODE_SPI),
GRP_G("sdmode", sd_mode_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_SDMODE),
GRP_G("uart0", uart0_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_UART0),
GRP_G("i2s", i2s_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_I2S),
GRP_G("spi cs1", spi_cs1_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_CS1),
GRP_G("spis", spis_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_SPIS),
GRP_G("gpio", gpio_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_GPIO),
GRP_G("wled_an", wled_an_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_WLED_AN),
GRP_G("p0led_an", p0led_an_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_P0LED_AN),
GRP_G("p1led_an", p1led_an_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_P1LED_AN),
GRP_G("p2led_an", p2led_an_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_P2LED_AN),
GRP_G("p3led_an", p3led_an_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_P3LED_AN),
GRP_G("p4led_an", p4led_an_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_P4LED_AN),
GRP_G("wled_kn", wled_kn_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_WLED_KN),
GRP_G("p0led_kn", p0led_kn_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_P0LED_KN),
GRP_G("p1led_kn", p1led_kn_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_P1LED_KN),
GRP_G("p2led_kn", p2led_kn_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_P2LED_KN),
GRP_G("p3led_kn", p3led_kn_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_P3LED_KN),
GRP_G("p4led_kn", p4led_kn_grp_mt7628, MT7628_GPIO_MODE_MASK,
1, MT7628_GPIO_MODE_P4LED_KN),
{
0 }
};
gpio41,gpio42 分别对应以上p1led_an、p2led_an
设备树中,将这两组gpio,设置为gpio模式
state_default: pinctrl0 {
gpio {
// eric++ p0led_an as gpio
ralink,group = "gpio","p0led_an","p1led_an","p2led_an","p3led_an","p4led_an";
ralink,function = "gpio";
};
};
3、menuconfig,打开对应led驱动模块
.config - OpenWrt Configuration
> Kernel modules > LED modules ───────────────────────────────────────────────────────────────
┌────────────────────────────────────── LED modules ──────────────────────────────────────┐
│ Arrow keys navigate the menu. <Enter> selects submenus ---> (or empty submenus ----). │
│ Highlighted letters are hotkeys. Pressing <Y> includes, <N> excludes, <M> modularizes │
│ features. Press <Esc><Esc> to exit, <?> for Help, </> for Search. Legend: [*] │
│ built-in [ ] excluded <M> module < > module capable │
│ ┌─────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ <*> kmod-leds-gpio.......................................... GPIO LED support │ │
│ │ < > kmod-leds-pca963x.................................... PCA963x LED support │ │
│ │ <*> kmod-ledtrig-default-on........................... LED Default ON Trigger │ │
│ │ <*> kmod-ledtrig-gpio....................................... LED GPIO Trigger │ │
│ │ <*> kmod-ledtrig-heartbeat............................. LED Heartbeat Trigger │ │
│ │ <*> kmod-ledtrig-netdev................................... LED NETDEV Trigger │ │
│ │ <*> kmod-ledtrig-oneshot................................ LED One-Shot Trigger │ │
│ │ <*> kmod-ledtrig-timer..................................... LED Timer Trigger │ │
│ └───────v(+)──────────────────────────────────────────────────────────────────────────┘ │
├─────────────────────────────────────────────────────────────────────────────────────────┤
│ <Select> < Exit > < Help > < Save > < Load > │
└─────────────────────────────────────────────────────────────────────────────────────────┘
4、编译,查看设备节点
root@OpenWrt:/sys/devices/platform/leds/leds# ls
led-usb led-wifi
5、测试led控制
1、关闭触发方式,echo none > trigger
2、打开led,echo 1 > brightness
3、关闭led,echo 0 > brightness
root@OpenWrt:/sys/devices/platform/leds/leds/led-usb# ls
brightness interval rx tx
device link subsystem uevent
device_name max_brightness trigger
root@OpenWrt:/sys/devices/platform/leds/leds/led-usb# cat trigger
none switch0 timer default-on [netdev] gpio heartbeat oneshot usbport phy0rx phy0tx phy0assoc phy0radio phy0tpt
root@OpenWrt:/sys/devices/platform/leds/leds/led-usb#
root@OpenWrt:/sys/devices/platform/leds/leds/led-usb#
root@OpenWrt:/sys/devices/platform/leds/leds/led-usb# echo none > trigger
root@OpenWrt:/sys/devices/platform/leds/leds/led-usb# echo 1 > brightness
root@OpenWrt:/sys/devices/platform/leds/leds/led-usb# echo 0 > brightness
6、配置led自动触发
target/linux/ramips/base-files/etc/board.d/01_leds
配置led-wifi,wifi数据传输闪烁
配置led-usb,在lan口数据传输闪烁
linkits7688)
# ucidef_set_led_wlan "wifi" "wifi" "linkit-smart-7688:orange:wifi" "phy0tpt"
# eric++
ucidef_set_led_wlan "wifi" "wifi" "led-wifi" "phy0tpt"
ucidef_set_led_netdev "lan" "lan" "led-usb" "eth0"
;;
7、按键配置
详情参考https://openwrt.org/docs/guide-user/hardware/hardware.button?s[]=rc&s[]=button
如发现系统启动过程中,出现以下log
kernel: [ 3.590000] Error: Driver 'gpio-keys-polled' is already registered, aborting...
需要关掉冲突的配置,只保留kmod-input-gpio-keys-polled
CONFIG_PACKAGE_kmod-input-gpio-*
CONFIG_PACKAGE_kmod-button-hotplug
8、修改设备树,添加对应按键描述
keys {
compatible = "gpio-keys-polled";
poll-interval = <20>;
// gpio38----gpio1_6
// wps {
// label = "wps";
// gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
// linux,code = <KEY_WPS_BUTTON>;
// };
// reboot {
// label = "reboot";
// gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
// linux,code = <KEY_POWER2>;
// };
reset {
label = "reset";
gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
linux,code = <KEY_RESTART>;
};
};
9、进入系统中查看gpio状态
root@OpenWrt:/sys/kernel/debug# cat gpio
gpiochip0: GPIOs 0-31, parent: platform/10000600.gpio, 10000600.gpio:
gpiochip1: GPIOs 32-63, parent: platform/10000600.gpio, 10000600.gpio:
gpio-38 ( |reboot ) in hi
gpio-41 ( |led-usb ) out lo
gpio-42 ( |led-wifi ) out lo
gpiochip2: GPIOs 64-95, parent: platform/10000600.gpio, 10000600.gpio:
10、具体按键执行动作可查看文件
package/base-files/files/etc/rc.button/reboot
package/base-files/files/etc/rc.button/reset
…
仅此记录