|
|
@@ -17,7 +17,7 @@
|
|
|
#include <rtthread.h>
|
|
|
#include <rtdevice.h>
|
|
|
|
|
|
-/* 引脚编号,通过查看drv_gpio.c确定 */
|
|
|
+/* 引脚编号,通过查看驱动文件drv_gpio.c确定 */
|
|
|
#ifndef BEEP_PIN_NUM
|
|
|
#define BEEP_PIN_NUM 37 /* PB2 */
|
|
|
#endif
|
|
|
@@ -44,6 +44,11 @@ void beep_off(void *args)
|
|
|
|
|
|
static void pin_beep_sample(void)
|
|
|
{
|
|
|
+ /* 蜂鸣器引脚为输出模式 */
|
|
|
+ rt_pin_mode(BEEP_PIN_NUM, PIN_MODE_OUTPUT);
|
|
|
+ /* 默认低电平 */
|
|
|
+ rt_pin_write(BEEP_PIN_NUM, PIN_LOW);
|
|
|
+
|
|
|
/* 按键0引脚为输入模式 */
|
|
|
rt_pin_mode(KEY0_PIN_NUM, PIN_MODE_INPUT_PULLUP);
|
|
|
/* 绑定中断,上升沿模式,回调函数名为beep_on */
|
|
|
@@ -57,9 +62,6 @@ static void pin_beep_sample(void)
|
|
|
rt_pin_attach_irq(KEY1_PIN_NUM, PIN_IRQ_MODE_FALLING, beep_off, RT_NULL);
|
|
|
/* 使能中断 */
|
|
|
rt_pin_irq_enable(KEY1_PIN_NUM, PIN_IRQ_ENABLE);
|
|
|
- /* 蜂鸣器引脚为输出模式 */
|
|
|
- rt_pin_mode(BEEP_PIN_NUM, PIN_MODE_OUTPUT);
|
|
|
-
|
|
|
}
|
|
|
/* 导出到 msh 命令列表中 */
|
|
|
MSH_CMD_EXPORT(pin_beep_sample, pin beep sample);
|