From 355e81ba44ab0a364aa30ba1b6e4681b766d3475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 24 May 2020 23:35:17 +0200 Subject: [PATCH] Add multitone support for loudspeaker --- stm-firmware/digio.c | 70 ++++++++++++++++--- .../include/reflow-controller/digio.h | 5 +- stm-firmware/main.c | 2 +- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/stm-firmware/digio.c b/stm-firmware/digio.c index 7ec5b9e..4c8f86b 100644 --- a/stm-firmware/digio.c +++ b/stm-firmware/digio.c @@ -27,6 +27,7 @@ static const uint8_t digio_pins[] = {DIGIO_PINS}; static const uint8_t digio_default_io[] = {DIGIO_INOUT_DEFAULT}; static const uint8_t digio_default_altfunc[] = {DIGIO_ALTFUNC_DEFAULT}; +static uint16_t loudspeaker_val; static void digio_setup_pin_int(uint8_t bit_no, uint8_t in_out, uint8_t alt_func) { @@ -118,6 +119,19 @@ int led_get(uint8_t num) return ((LED_PORT->ODR & (1<APB1ENR, BITMASK_TO_BITNO(RCC_APB1ENR_TIM7EN)); + TIM7->CR1 = 0UL; + TIM7->CR2 = 0UL; + TIM7->PSC = 1000; + TIM7->DIER = TIM_DIER_UIE; + NVIC_EnableIRQ(TIM7_IRQn); +#endif +} + void loudspeaker_setup() { rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(LOUDSPEAKER_RCC_MASK)); @@ -125,16 +139,56 @@ void loudspeaker_setup() LOUDSPEAKER_PORT->MODER &= MODER_DELETE(LOUDSPEAKER_PIN); LOUDSPEAKER_PORT->MODER |= OUTPUT(LOUDSPEAKER_PIN); - loudspeaker_set(0); + loudspeaker_freq_timer_init(); + loudspeaker_set(0U); } -void loudspeaker_set(int val) + +static void loudspeaker_start_beep(uint16_t val) { - if (val) - LOUDSPEAKER_PORT->ODR |= (1<ODR &= ~(1<ARR = val; + TIM7->CNT = 0UL; + TIM7->CR1 |= TIM_CR1_CEN; +#else + (void)val; + LOUDSPEAKER_PORT->ODR |= (1<ODR & (1<CR1 &= ~TIM_CR1_CEN; + __DSB(); + TIM7->SR = 0UL; + __DSB(); + LOUDSPEAKER_PORT->ODR &= ~(1<ODR &= ~(1<SR = 0UL; + __DSB(); + LOUDSPEAKER_PORT->ODR ^= (1<