minor cleanup
This commit is contained in:
parent
0fe1994cc9
commit
d674488e2a
31
main.c
31
main.c
|
@ -49,11 +49,10 @@ The time is read from a DS1307 RTC module.
|
||||||
volatile bool button_flag = false; /**< flag set if board user button has been pressed */
|
volatile bool button_flag = false; /**< flag set if board user button has been pressed */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/** the number of ticks in one second
|
#define TICKS_PER_SECOND 256 /**< the number of ticks in one second */
|
||||||
* @note the other values are derived from this value @ref main_ticks
|
#define SQUARE_WAVE_FREQUENCY 1 /**< square wave output frequency from the RTC IC */
|
||||||
*/
|
|
||||||
#define TICKS_PER_SECOND 255
|
|
||||||
/** @defgroup main_ticks ticks per time units
|
/** @defgroup main_ticks ticks per time units
|
||||||
|
* @note these are derived from TICKS_PER_SECOND
|
||||||
* @note I have to use type variables because defines would be stored in signed integers, leading to an overflow it later calculations
|
* @note I have to use type variables because defines would be stored in signed integers, leading to an overflow it later calculations
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
@ -91,18 +90,18 @@ int _write(int file, char *ptr, int len)
|
||||||
|
|
||||||
void led_on(void)
|
void led_on(void)
|
||||||
{
|
{
|
||||||
#ifdef SYSTEM_BOARD
|
#if defined(SYSTEM_BOARD) || defined(BLUE_PILL)
|
||||||
gpio_clear(LED_PORT, LED_PIN);
|
gpio_clear(LED_PORT, LED_PIN);
|
||||||
#elif MAPLE_MINI
|
#elif defined(MAPLE_MINI)
|
||||||
gpio_set(LED_PORT, LED_PIN);
|
gpio_set(LED_PORT, LED_PIN);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_off(void)
|
void led_off(void)
|
||||||
{
|
{
|
||||||
#ifdef SYSTEM_BOARD
|
#if defined(SYSTEM_BOARD) || defined(BLUE_PILL)
|
||||||
gpio_set(LED_PORT, LED_PIN);
|
gpio_set(LED_PORT, LED_PIN);
|
||||||
#elif MAPLE_MINI
|
#elif defined(MAPLE_MINI)
|
||||||
gpio_clear(LED_PORT, LED_PIN);
|
gpio_clear(LED_PORT, LED_PIN);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -288,7 +287,7 @@ int main(void)
|
||||||
|
|
||||||
// setup RTC module
|
// setup RTC module
|
||||||
rtc_setup(); // setup RTC module
|
rtc_setup(); // setup RTC module
|
||||||
rtc_write_square_wave(1); // set square wave output to 1 Hz
|
rtc_write_square_wave(SQUARE_WAVE_FREQUENCY); // set square wave output frequency
|
||||||
|
|
||||||
printf("welcome to the CuVoodoo LED clock\n"); // print welcome message
|
printf("welcome to the CuVoodoo LED clock\n"); // print welcome message
|
||||||
led_on(); // switch on LED to indicate setup completed
|
led_on(); // switch on LED to indicate setup completed
|
||||||
|
@ -311,31 +310,30 @@ int main(void)
|
||||||
button_flag = false; // reset button flag
|
button_flag = false; // reset button flag
|
||||||
char c = ' '; // to store received character
|
char c = ' '; // to store received character
|
||||||
bool char_flag = false; // a new character has been received
|
bool char_flag = false; // a new character has been received
|
||||||
/* toggle the LED with every transmitted character */
|
|
||||||
while (true) { // infinite loop
|
while (true) { // infinite loop
|
||||||
while (usart_received) { // echo every received character
|
while (usart_received) { // data received over UART
|
||||||
action = true; // action has been performed
|
action = true; // action has been performed
|
||||||
led_toggle(); // toggle LED
|
led_toggle(); // toggle LED
|
||||||
c = usart_getchar(); // store receive character
|
c = usart_getchar(); // store receive character
|
||||||
char_flag = true; // notify character has been received
|
char_flag = true; // notify character has been received
|
||||||
}
|
}
|
||||||
while (cdcacm_received) { // echo every received character
|
while (cdcacm_received) { // data received over USB
|
||||||
action = true; // action has been performed
|
action = true; // action has been performed
|
||||||
led_toggle(); // toggle LED
|
led_toggle(); // toggle LED
|
||||||
c = usart_getchar(); // store receive character
|
c = usart_getchar(); // store receive character
|
||||||
char_flag = true; // notify character has been received
|
char_flag = true; // notify character has been received
|
||||||
}
|
}
|
||||||
while (char_flag) {
|
while (char_flag) { // user data received
|
||||||
char_flag = false; // reset flag
|
char_flag = false; // reset flag
|
||||||
action = true; // action has been performed
|
action = true; // action has been performed
|
||||||
printf("%c",c); // echo receive character
|
printf("%c",c); // echo receive character
|
||||||
}
|
}
|
||||||
while (button_flag) {
|
while (button_flag) { // user pressed button
|
||||||
button_flag = false; // reset flag
|
button_flag = false; // reset flag
|
||||||
action = true; // action has been performed
|
action = true; // action has been performed
|
||||||
led_toggle(); // toggle LED
|
led_toggle(); // toggle LED
|
||||||
}
|
}
|
||||||
while (square_wave_flag) {
|
while (square_wave_flag) { // time passed
|
||||||
square_wave_flag = false; // reset flag
|
square_wave_flag = false; // reset flag
|
||||||
action = true; // action has been performed
|
action = true; // action has been performed
|
||||||
led_toggle();
|
led_toggle();
|
||||||
|
@ -344,8 +342,7 @@ int main(void)
|
||||||
clock_set_time(current_time); // set time
|
clock_set_time(current_time); // set time
|
||||||
printf("it is now %02lu:%02lu:%02lu\n", current_time/ticks_hour, (current_time%ticks_hour)/ticks_minute, (current_time%ticks_minute)/ticks_second); // display time
|
printf("it is now %02lu:%02lu:%02lu\n", current_time/ticks_hour, (current_time%ticks_hour)/ticks_minute, (current_time%ticks_minute)/ticks_second); // display time
|
||||||
}
|
}
|
||||||
// go to sleep if nothing had to be done, else recheck for activity
|
if (action) { // go to sleep if nothing had to be done, else recheck for activity
|
||||||
if (action) {
|
|
||||||
action = false;
|
action = false;
|
||||||
} else {
|
} else {
|
||||||
__WFI(); // go to sleep
|
__WFI(); // go to sleep
|
||||||
|
|
Loading…
Reference in New Issue