Skip to content

Commit e640b0c

Browse files
authored
Merge pull request #6 from misonyo/master
增加蜂鸣器初始化默认电平状态
2 parents f15414f + 0b1cf68 commit e640b0c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pin_beep_sample.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <rtthread.h>
1818
#include <rtdevice.h>
1919

20-
/* 引脚编号,通过查看drv_gpio.c确定 */
20+
/* 引脚编号,通过查看驱动文件drv_gpio.c确定 */
2121
#ifndef BEEP_PIN_NUM
2222
#define BEEP_PIN_NUM 37 /* PB2 */
2323
#endif
@@ -44,6 +44,11 @@ void beep_off(void *args)
4444

4545
static void pin_beep_sample(void)
4646
{
47+
/* 蜂鸣器引脚为输出模式 */
48+
rt_pin_mode(BEEP_PIN_NUM, PIN_MODE_OUTPUT);
49+
/* 默认低电平 */
50+
rt_pin_write(BEEP_PIN_NUM, PIN_LOW);
51+
4752
/* 按键0引脚为输入模式 */
4853
rt_pin_mode(KEY0_PIN_NUM, PIN_MODE_INPUT_PULLUP);
4954
/* 绑定中断,上升沿模式,回调函数名为beep_on */
@@ -57,9 +62,6 @@ static void pin_beep_sample(void)
5762
rt_pin_attach_irq(KEY1_PIN_NUM, PIN_IRQ_MODE_FALLING, beep_off, RT_NULL);
5863
/* 使能中断 */
5964
rt_pin_irq_enable(KEY1_PIN_NUM, PIN_IRQ_ENABLE);
60-
/* 蜂鸣器引脚为输出模式 */
61-
rt_pin_mode(BEEP_PIN_NUM, PIN_MODE_OUTPUT);
62-
6365
}
6466
/* 导出到 msh 命令列表中 */
6567
MSH_CMD_EXPORT(pin_beep_sample, pin beep sample);

0 commit comments

Comments
 (0)