use RTC
This commit is contained in:
parent
5665f035c4
commit
60608dcaa5
21
main.c
21
main.c
@ -34,7 +34,6 @@
|
||||
#include <libopencmsis/core_cm3.h> // Cortex M3 utilities
|
||||
#include <libopencm3/cm3/nvic.h> // interrupt utilities
|
||||
#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
|
||||
|
||||
@ -43,6 +42,7 @@
|
||||
#include "usart.h" // USART utilities
|
||||
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
||||
#include "led_ws2812b.h" // WS2812b LEDs utilities
|
||||
#include "rtc_ds1307.h" // Real Time Clock DS1307 utilities
|
||||
|
||||
/** @defgroup main_flags flag set in interrupts to be processed in main task
|
||||
* @{
|
||||
@ -80,10 +80,10 @@ const uint32_t ticks_midday = 12*60*60*TICKS_PER_SECOND;
|
||||
/** @defgroup photoresistor_adc ADC used to ambient luminosity
|
||||
* @{
|
||||
*/
|
||||
#define PHOTORESISTOR_ADC_CHANNEL ADC_CHANNEL0 /**< ADC channel */
|
||||
#define PHOTORESISTOR_ADC_CHANNEL ADC_CHANNEL1 /**< ADC channel */
|
||||
#define PHOTORESISTOR_PORT GPIOA /**< port on which the battery is connected */
|
||||
#define PHOTORESISTOR_PORT_RCC RCC_GPIOA /**< timer port peripheral clock */
|
||||
#define PHOTORESISTOR_PIN GPIO0 /**< pin of the port on which the battery is connected */
|
||||
#define PHOTORESISTOR_PIN GPIO1 /**< pin of the port on which the battery is connected */
|
||||
/** @} */
|
||||
|
||||
|
||||
@ -377,11 +377,14 @@ int main(void)
|
||||
nvic_enable_irq(BUTTON_IRQ); // enable interrupt
|
||||
#endif
|
||||
|
||||
// setup RTC
|
||||
// setup internal RTC
|
||||
rtc_auto_awake(RCC_LSE, 32768/ticks_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 (power off the micro-controller for the change to take effect)
|
||||
rtc_interrupt_enable(RTC_SEC); // enable RTC interrupt on "seconds"
|
||||
nvic_enable_irq(NVIC_RTC_IRQ); // allow the RTC to interrupt
|
||||
|
||||
// setup external RTC
|
||||
rtc_setup(); // setup RTC module
|
||||
|
||||
// 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);
|
||||
@ -416,6 +419,11 @@ int main(void)
|
||||
printf("welcome to the CuVoodoo LED clock\n"); // print welcome message
|
||||
led_on(); // switch on LED to indicate setup completed
|
||||
|
||||
// verify is external RTC is running
|
||||
if (rtc_oscillator_disabled()) {
|
||||
printf("/!\\ RTC oscillator is disabled: the battery may be empty\n");
|
||||
}
|
||||
|
||||
// read internal reference 1.2V and RTC battery voltages
|
||||
uint8_t channels[] = {ADC_CHANNEL17, BATTERY_ADC_CHANNEL}; // voltages to convert
|
||||
adc_set_regular_sequence(ADC1, LENGTH(channels), channels); // set channels to convert
|
||||
@ -506,6 +514,11 @@ int main(void)
|
||||
}
|
||||
button_flag = false; // reset flag
|
||||
}
|
||||
while (rtc_tick_flag) { // the RTC tick four our counter passed
|
||||
rtc_tick_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
led_toggle();
|
||||
}
|
||||
while (time_flag) { // time passed
|
||||
time_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
|
Loading…
Reference in New Issue
Block a user