RV1126 GPIO 控制:
1. 修改 dtsi 文件,BSP/kernel/arch/arm/boot/dts/rongpin/rv1126_1109_common.dtsi
rp_gpio {
status = "okay";
compatible = "rp_gpio";
vcc_led{
gpio_num = <&gpio4 RK_PA1 GPIO_ACTIVE_LOW>;
gpio_function = <0>;
};
wifi_led{
gpio_num = <&gpio2 RK_PD2 GPIO_ACTIVE_LOW>;
gpio_function = <0>;
};
}
----------------------------------------------------
LED_Y_PWM: GPIO0_C0 #16
LED_X_PWM: GPIO0_C3 #19
LED_W_PWM: GPIO0_C2 #18
LED_V_PWM: GPIO2_B3 控制一个灯 #75
LED_L_PWM: GPIO2_B2 控制四个灯 #74
VCC_LED: GPIO4_A1 打开24V电源(12V无法工作)
FANCTL1: GPIO2_D1
FANCTL2: GPIO2_D3
WIFI_LED: GPIO_D2
如何在 /sys/class/gpio 中控制 GPIO:
GPIO编号计算
GPIO编号 = BANK * 32 + GPIO_PIN
GPION_MP = N * 32 + 8 * (M -1) + P
示例:GPIO7_C2 = 7 X 32 + 8 X (3-1) + 2 = 242
GPIO2_A1 = 2 X 32 + 8 X (1-1) + 1 = 73
A对应1,B对应2,C对应3,以此类推
-------------------------------------------------------------
示例:设置GPIO2_D1为高电平
导出GPIO2_D1引脚
echo 89 > /sys/class/gpio/export
导出成功后,会生成/sys/class/gpio/gpio89目录
若没有生成,说明该引脚不可导出
设置GPIO2_D1引脚为输出模式
echo out > /sys/class/gpio/gpio89/direction
设置GPIO2_D1引脚高电平
echo 1 > /sys/class/gpio/gpio89/value
-----------------------------------------------------------
# GPIO0_C0 / LED_Y_PWM 白光控制
echo 16 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio16/direction
echo 1 > /sys/class/gpio/gpio16/value
echo 0 > /sys/class/gpio/gpio16/value
# GPIO_C2 / LED_W_PWM 白光控制
echo 18 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio18/direction
echo 1 > /sys/class/gpio/gpio18/value
echo 0 > /sys/class/gpio/gpio18/value
# GPIO_C3 / LED_X_PWM 白光控制
echo 19 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio19/direction
echo 1 > /sys/class/gpio/gpio19/value
echo 0 > /sys/class/gpio/gpio19/value
# GPIO2_B3 / LED_V_PWM 单颗紫外线
echo 75 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio75/direction
echo 1 > /sys/class/gpio/gpio75/value
echo 0 > /sys/class/gpio/gpio75/value
# GPIO2_B2 / LED_L_PWM 四颗紫外线
echo 74 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio74/direction
echo 1 > /sys/class/gpio/gpio74/value
echo 0 > /sys/class/gpio/gpio74/value
==============================
PWM 控制:
PWM 脚位的配置:
BSP/kernel/arch/arm/boot/dts/rv1126-pinctrl.dtsi
BSP/kernel/arch/arm/boot/dts/rongpin/rv1126_1109_common.dtsi
# 打 VCC LED (24V) 电源
echo 1 > /proc/rp_gpio/vcc_led
echo 0 > /proc/rp_gpio/vcc_led
PWM8 - GPIO2_B3 - PWM0M1 / pwmchip5 - ok
PWM1 - GPIO2_B2 - PWM1M1 / pwmchip1 - ok
PWM5 - GPIO0_C3 - PWM5M0 / pwmchip4 - ok
PWM4 - GPIO0_C2 - PWM4M0 / pwmchip3 - ok
PWM2 - GPIO0_C0 - PWM2M0 / pwmchip2 - ok
# PWM1 - GPIO2_B2 - PWM1M1 / pwmchip1 - ok
--------------------------------------------
echo 0 > /sys/class/pwm/pwmchip1/export
echo 1000000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 100000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
echo normal > /sys/class/pwm/pwmchip1/pwm0/polarity
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
# PWM2 - GPIO0_C0 - PWM2M0 / pwmchip2 - ok
# --------------------------------------------
echo 0 > /sys/class/pwm/pwmchip2/export
echo 1000000 > /sys/class/pwm/pwmchip2/pwm0/period
echo 100000 > /sys/class/pwm/pwmchip2/pwm0/duty_cycle
echo normal > /sys/class/pwm/pwmchip2/pwm0/polarity
echo 1 > /sys/class/pwm/pwmchip2/pwm0/enable
# PWM4 - GPIO0_C2 - PWM4M0 / pwmchip3 - ok
# --------------------------------------------
echo 0 > /sys/class/pwm/pwmchip3/export
echo 1000000 > /sys/class/pwm/pwmchip3/pwm0/period
echo 100000 > /sys/class/pwm/pwmchip3/pwm0/duty_cycle
echo normal > /sys/class/pwm/pwmchip3/pwm0/polarity
echo 1 > /sys/class/pwm/pwmchip3/pwm0/enable
# PWM5 - GPIO0_C3 - PWM5M0 / pwmchip4 - ok
# --------------------------------------------
echo 0 > /sys/class/pwm/pwmchip4/export
echo 1000000 > /sys/class/pwm/pwmchip4/pwm0/period
echo 100000 > /sys/class/pwm/pwmchip4/pwm0/duty_cycle
echo normal > /sys/class/pwm/pwmchip4/pwm0/polarity
echo 1 > /sys/class/pwm/pwmchip4/pwm0/enable
# PWM8 - GPIO2_B3 - PWM8M1 / pwmchip5 - ok
# --------------------------------------------
echo 0 > /sys/class/pwm/pwmchip5/export
echo 1000000 > /sys/class/pwm/pwmchip5/pwm0/period
echo 100000 > /sys/class/pwm/pwmchip5/pwm0/duty_cycle
echo normal > /sys/class/pwm/pwmchip5/pwm0/polarity
echo 1 > /sys/class/pwm/pwmchip5/pwm0/enable
阅读(5265) | 评论(0) | 转发(0) |