use internal RTC with our tick speed
This commit is contained in:
parent
28f2c1fbe5
commit
a07e287865
22
main.c
22
main.c
|
@ -39,6 +39,7 @@
|
|||
#include <libopencm3/stm32/exti.h> // external interrupt utilities
|
||||
#include <libopencm3/stm32/timer.h> // timer utilities
|
||||
#include <libopencm3/stm32/adc.h> // ADC utilities
|
||||
#include <libopencm3/stm32/rtc.h> // real time clock utilities
|
||||
|
||||
/* own libraries */
|
||||
#include "global.h" // board definitions
|
||||
|
@ -368,6 +369,11 @@ int main(void)
|
|||
nvic_enable_irq(BUTTON_IRQ); // enable interrupt
|
||||
#endif
|
||||
|
||||
// setup RTC
|
||||
rtc_auto_awake(RCC_LSE, 32768/TICKS_PER_SECOND-1); // ensure RTC is on, uses the 32.678 kHz LSE, and the prescale is set to our tick speed, else update backup registers accordingly
|
||||
rtc_interrupt_enable(RTC_SEC); // enable RTC interrupt on "seconds"
|
||||
nvic_enable_irq(NVIC_RTC_IRQ); // allow the RTC to interrupt
|
||||
|
||||
// generate gamma correction table (with fixed gamma value)
|
||||
for (uint16_t i=0; i<LENGTH(gamma_correction_lut); i++) {
|
||||
gamma_correction_lut[i] = powf((float)i / (float)LENGTH(gamma_correction_lut), 2.2)*LENGTH(gamma_correction_lut);
|
||||
|
@ -465,19 +471,18 @@ int main(void)
|
|||
time_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
if ((current_time%ticks_second)==0) { // one second passed
|
||||
//printf("%02lu:%02lu:%02lu\n", current_time/ticks_hour, (current_time%ticks_hour)/ticks_minute, (current_time%ticks_minute)/ticks_second); // display time
|
||||
led_toggle(); // LED activity to show we are not stuck
|
||||
}
|
||||
if ((current_time%ticks_minute)==0) { // one minute passed
|
||||
//current_time = rtc_time[2]*ticks_hour+rtc_time[1]*ticks_minute+rtc_time[0]*ticks_second; // sync current 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
|
||||
}
|
||||
if ((current_time%ticks_hour)==0) { // one hours passed
|
||||
clock_hours(); // show hour markers
|
||||
}
|
||||
if ((current_time%ticks_midday*2)==0) { // one day passed
|
||||
current_time = 0; // reset time counter
|
||||
}
|
||||
clock_set_time(current_time); // set time
|
||||
if ((current_time%ticks_second)==0) { // on second passed
|
||||
//printf("%02lu:%02lu:%02lu\n", current_time/ticks_hour, (current_time%ticks_hour)/ticks_minute, (current_time%ticks_minute)/ticks_second); // display time
|
||||
}
|
||||
}
|
||||
if (action) { // go to sleep if nothing had to be done, else recheck for activity
|
||||
action = false;
|
||||
|
@ -496,3 +501,10 @@ void BUTTON_ISR(void)
|
|||
button_flag = true; // perform button action
|
||||
}
|
||||
#endif
|
||||
|
||||
void rtc_isr(void)
|
||||
{
|
||||
rtc_clear_flag(RTC_SEC); // clear flag
|
||||
current_time++; // increment time
|
||||
time_flag = true; // notify to show new time
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue