add 7-segment display

This commit is contained in:
King Kévin 2020-02-17 18:10:40 +01:00
parent f1168608c7
commit ddaa619e97
1 changed files with 13 additions and 9 deletions

View File

@ -47,6 +47,7 @@
#include "usb_cdcacm.h" // USB CDC ACM utilities
#include "terminal.h" // handle the terminal interface
#include "menu.h" // menu utilities
#include "led_tm1637.h" // 7-segment display
/** watchdog period in ms */
#define WATCHDOG_PERIOD 10000
@ -341,7 +342,7 @@ void main(void)
uart_setup(); // setup USART (for printing)
#endif
usb_cdcacm_setup(); // setup USB CDC ACM (for printing)
puts("\nwelcome to the CuVoodoo STM32F1 example application\n"); // print welcome message
puts("\nwelcome to the CuVoodoo sound lever meter display\n"); // print welcome message
#if DEBUG
// show reset cause
@ -394,6 +395,14 @@ void main(void)
time_start = rtc_get_counter_val(); // get start time from internal RTC
puts("OK\n");
// setup display
printf("setup 7-segment display: ");
led_tm1637_setup();
led_tm1637_brightness(LED_TM1637_14DIV16);
led_tm1637_time(88, 88);
led_tm1637_on();
printf("OK\n");
// setup terminal
terminal_prefix = ""; // set default prefix
terminal_process = &process_command; // set central function to process commands
@ -410,18 +419,13 @@ void main(void)
char c = user_input_get(); // store receive character
terminal_send(c); // send received character to terminal
}
if (button_flag) { // user pressed button
action = true; // action has been performed
puts("button pressed\n");
led_toggle(); // toggle LED
sleep_ms(100); // wait a bit to remove noise and double trigger
button_flag = false; // reset flag
}
if (rtc_internal_tick_flag) { // the internal RTC ticked
rtc_internal_tick_flag = false; // reset flag
action = true; // action has been performed
if (0 == (rtc_get_counter_val() % RTC_TICKS_SECOND)) { // one seond has passed
if (0 == (rtc_get_counter_val() % RTC_TICKS_SECOND)) { // one second has passed
led_toggle(); // toggle LED (good to indicate if main function is stuck)
uint32_t seconds = rtc_get_counter_val() / RTC_TICKS_SECOND; // get number of seconds
led_tm1637_time(seconds / 60, seconds % 60); // display time
}
}
if (action) { // go to sleep if nothing had to be done, else recheck for activity