aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/main.c b/main.c
index 94c7445..1ed013a 100644
--- a/main.c
+++ b/main.c
@@ -15,7 +15,7 @@
/** CuVoodoo clapperboard firmware (for STM32F103Cx micro-controller)
* @file main.c
* @author King Kévin <kingkevin@cuvoodoo.info>
- * @date 2016-2017
+ * @date 2016-2018
*/
/* standard libraries */
@@ -593,7 +593,12 @@ void main(void)
timer_enable_oc_output(TIM(BUZZER_TIMER), TIM_OC1); // enable output to generate PWM
timer_enable_oc_output(TIM(BUZZER_TIMER), TIM_OC1N); // enable output to generate PWM (complementary to be louder)
timer_enable_break_main_output(TIM(BUZZER_TIMER)); // enable master output
- timer_generate_event(TIM(BUZZER_TIMER), TIM_EGR_UG); // generate update event to reload registers and reset counter
+ timer_generate_event(TIM(BUZZER_TIMER), TIM_EGR_UG); // generate update event to reload registers and reset counter
+ // switch buzzer off by removing the output from the PWM
+ gpio_clear(GPIO(BUZZER_1_PORT), GPIO(BUZZER_1_PIN));
+ gpio_set_mode(GPIO(BUZZER_1_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_1_PIN));
+ gpio_clear(GPIO(BUZZER_2_PORT), GPIO(BUZZER_2_PIN));
+ gpio_set_mode(GPIO(BUZZER_2_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_2_PIN));
printf("OK\n");
// setup GPIO for reading buttons
@@ -628,12 +633,14 @@ void main(void)
action = true; // action has been performed
led_toggle(); // toggle LED to show activity
c = usart_getchar(); // store receive character
+ standby_timer = 0; // restart standby timer
char_flag = true; // notify character has been received
}
while (cdcacm_received) { // data received over USB
action = true; // action has been performed
led_toggle(); // toggle LED to show activity
c = cdcacm_getchar(); // store receive character
+ standby_timer = 0; // restart standby timer
char_flag = true; // notify character has been received
}
while (char_flag) { // user data received
@@ -684,7 +691,15 @@ void main(void)
if (morse[morse_i]) { // skip empty codes
if (morse_i%2) { // switch buzzer on for odd code
timer_disable_counter(TIM(BUZZER_TIMER)); // stop buzzing
+ // switch buzzer off by removing the output from the PWM
+ gpio_clear(GPIO(BUZZER_1_PORT), GPIO(BUZZER_1_PIN));
+ gpio_set_mode(GPIO(BUZZER_1_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_1_PIN));
+ gpio_clear(GPIO(BUZZER_2_PORT), GPIO(BUZZER_2_PIN));
+ gpio_set_mode(GPIO(BUZZER_2_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_2_PIN));
} else {
+ // allow PWM to control the output
+ gpio_set_mode(GPIO(BUZZER_1_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO(BUZZER_1_PIN));
+ gpio_set_mode(GPIO(BUZZER_2_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO(BUZZER_2_PIN));
timer_enable_counter(TIM(BUZZER_TIMER)); // start buzzing
}
morse[morse_i]--; // decrement remaining buzzing time
@@ -695,8 +710,11 @@ void main(void)
}
if (morse_i>=LENGTH(morse)) { // all codes done
morse_delay = -2; // Morse completed
- gpio_clear(GPIO(BUZZER_1_PORT), GPIO(BUZZER_1_PIN)); // ensure it's not beeping
- gpio_clear(GPIO(BUZZER_2_PORT), GPIO(BUZZER_2_PIN)); // ensure it's not beeping
+ // switch buzzer off by removing the output from the PWM
+ gpio_clear(GPIO(BUZZER_1_PORT), GPIO(BUZZER_1_PIN));
+ gpio_set_mode(GPIO(BUZZER_1_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_1_PIN));
+ gpio_clear(GPIO(BUZZER_2_PORT), GPIO(BUZZER_2_PIN));
+ gpio_set_mode(GPIO(BUZZER_2_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUZZER_2_PIN));
}
}
@@ -741,7 +759,7 @@ void main(void)
uint16_t buttons_diff = buttons^buttons_new; // get difference
buttons = buttons_new; // save new state
if (buttons_diff) { // only do something if there is a change
- //printf("button pressed: %016b\n", buttons);
+ printf("button pressed: %016b\n", buttons);
for (uint8_t number=0; number<LENGTH(numbers); number++) { // check buttons for every number
if (buttons_diff&(1<<numbers[number].up) || buttons_diff&(1<<numbers[number].down)) { // a button for the number has been pressed
if (buttons&(1<<numbers[number].up) && buttons&(1<<numbers[number].down)) { // both buttons are pressed
@@ -823,6 +841,7 @@ void main(void)
}
}
}
+ standby_timer = 0; // restart standby timer
}
}