PX30驱动input子系统实现pwm及gpio控制
1、修改设备树
在SDK/kernel/arch/arm64/boot/dts/rockchip/px30-evb-ddr3-v10-linux.dts中,在‘/’目录下添加节点(以峰鸣器控制为例)。
gpio:
beeper {
compatible = "gpio-beeper";
status = "okay";
gpios =<&gpio2 RK_PB5 GPIO_ACTIVE_HIGH>; //buzeer连接在gpio2_PB5高电平有效
};
pwm:
beeper {
compatible = "pwm-beeper";
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pwm2_pin>;
};
pwm2 {
pwm2_pin: pwm2-pin {
rockchip,pins =
<2 RK_PB5 RK_FUNC_1 &pcfg_pull_none>; //复用为pwm
};
};
设备树匹配分别在SDK/kernel/drivers/input/misc/pwm-beeper.c和SDK/kernel/drivers/input/misc/gpio-beeper.c
gpio:
pwm:
2、将驱动编译进内核
在SDK/kernel/drivers/input/misc目录下找到Kconfig以及Makefile文件,添加修改
(1)Kconfig文件使能模块
gpio:
pwm:
(2)Makefile添加编译
编译启动生成input/event节点
3、根据驱动及input系统属性编写应用测试
#include<stdint.h>
#include<string.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdio.h>
#include<linux/input.h>
#include<unistd.h>
int main(int argc, char **argv)
{
struct input_event beep_evn;
int fd;
char *file_name=argv[1];
fd = open(file_name,O_RDWR);
if(fd<0)
{
printf("%s filed\n",argv[1]);
return 0;
}
beep_evn.type = EV_SND;//gpio控制模式
beep_evn.code = SND_BELL;//gpio控制模式
beep_evn.type = EV_SND; //pwm控制模式
beep_evn.code = SND_TONE;//pwm控制模式
beep_evn.value = 2000; //pwm频率
while(1)
{
beep_evn.value =1; //gpio控制模式
write(fd,&beep_evn,sizeof(struct input_event));
printf("beep_evn.value = %d\n",beep_evn.value);
sleep(2);
beep_evn.value = 0;
write(fd,&beep_evn,sizeof(struct input_event));
printf("beep_evn.value = %d\n",beep_evn.value);
sleep(3);
}
close(fd);
return 0;
}