基于已有的gpio驱动,增加对板载蜂鸣器的控制,附上源码供参考。刚开始以为蜂鸣器是电平控制,后来经过多次测试才发现是PWM控制。
测试命令执行效果如下:
在drv_gpio.c文件中增加如下代码:
蜂鸣器的控制脚是ls2k 的GPIO 39.
void buzzer_test(int argc, char *argv[])
{
int dlyh,dlyl,cnt;
if(argc<3){
rt_kprintf("Usage:buzzer_test pwmH pwmL test_cnt\n");
return;
}
dlyh = atoi(argv[1]);
dlyl = atoi(argv[2]);
cnt = atoi(argv[3]);
rt_kprintf("buzzer test!\n");
rt_pin_mode(39, 0);
do{
rt_pin_write(39, 1);
rt_thread_mdelay(dlyh);
rt_pin_write(39, 0);
rt_thread_mdelay(dlyl);
}while(cnt--);
rt_kprintf("buzzer test ok!\n");
}
MSH_CMD_EXPORT(buzzer_test,LS2K PWM buzzer_test);
drivers.zip
(105.51 KB)
|