From 43d1cfd0d1458c2d4c333155902be28bfe17b6ee Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 27 Jan 2024 23:47:45 -0800 Subject: [PATCH] altos/stm32f1: Set beeper pin to 0 while off Make sure we don't let the timer leave it sitting high; the magnetic beepers probably don't do the right thing in that case. Signed-off-by: Keith Packard --- src/stm32f1/ao_beep_stm.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/stm32f1/ao_beep_stm.c b/src/stm32f1/ao_beep_stm.c index 3cabcfe8..02c8d91c 100644 --- a/src/stm32f1/ao_beep_stm.c +++ b/src/stm32f1/ao_beep_stm.c @@ -38,7 +38,13 @@ ao_beep(uint8_t beep) if (beep == 0) { stm_beeper.cr1 = 0; stm_rcc.apb1enr &= ~(1UL << RCC_BEEPER); + stm_gpio_conf(BEEPER_PORT, BEEPER_PIN, + STM_GPIO_CR_MODE_OUTPUT_2MHZ, + STM_GPIO_CR_CNF_OUTPUT_PUSH_PULL); } else { + stm_gpio_conf(BEEPER_PORT, BEEPER_PIN, + STM_GPIO_CR_MODE_OUTPUT_2MHZ, + STM_GPIO_CR_CNF_OUTPUT_AF_PUSH_PULL); stm_rcc.apb1enr |= (1UL << RCC_BEEPER); stm_beeper.cr2 = ((0 << STM_TIM234_CR2_TI1S) | @@ -155,7 +161,6 @@ ao_beep_for(uint8_t beep, AO_TICK_TYPE ticks) void ao_beep_init(void) { - ao_enable_port(BEEPER_PORT); #if BEEPER_TIMER == 2 if (BEEPER_PORT == &stm_gpioa) { switch (BEEPER_PIN) { @@ -217,9 +222,7 @@ ao_beep_init(void) #elif BEEPER_TIMER == 4 ao_panic(AO_PANIC_CRASH); #endif - stm_gpio_conf(BEEPER_PORT, BEEPER_PIN, - STM_GPIO_CR_MODE_OUTPUT_2MHZ, - STM_GPIO_CR_CNF_OUTPUT_AF_PUSH_PULL); + ao_enable_output(BEEPER_PORT, BEEPER_PIN, 0); /* Leave the timer off until requested */ stm_rcc.apb1enr &= ~(1UL << RCC_BEEPER); -- 2.30.2