Use the builtin RTC and display it

Its roughly %15 fast, and initializes to zero, but the display
currently shows HH:MM:SS AM/PM.
This commit is contained in:
2019-03-11 22:56:08 -07:00
parent dedcb5af71
commit d5bfecedb2
10 changed files with 285 additions and 8 deletions

39
test.c
View File

@@ -26,15 +26,16 @@
#include "stm32l0xx.h"
#include "macros.h"
#include "rtc.h"
#include "spi.h"
#include "display.h"
#include "font-notomono-10.h"
/* TODO: Start cleaning up code and adding bounds checking! */
extern uint32_t system_clk_freq;
void SystemInit()
{
/**
* Use the MSI for the system clock, and disable all other clocks.
*/
@@ -51,6 +52,9 @@ void SystemInit()
RCC_ICSCR_MSIRANGE,
RCC_ICSCR_MSIRANGE_6);
/*!< Set internal representation of clock frequency to 4MHz */
system_clk_freq = 4u << 22;
/*!< Reset
* SW[1:0] (use MSI oscillator as system clock),
* HPRE[3:0] (do not divide AHB clock in prescaler) ,
@@ -168,6 +172,14 @@ void init_lptim_toggler()
CLR(GPIOA->PUPDR, GPIO_PUPDR_PUPD7);
}
static char get_char_for_digit(uint8_t bcd_digit)
{
return bcd_digit + '0';
}
struct time_bcd time;
char time_str[11] = { 0 };
int main()
{
/** Enable Port A,B clock */
@@ -185,15 +197,34 @@ int main()
init_lptim_toggler();
display_init(&display, SPI1);
rtc_init();
int x = 0;
while (1) {
rtc_get_time_bcd(&time);
time_str[0] = get_char_for_digit(time.hour_tens);
time_str[1] = get_char_for_digit(time.hour_ones);
time_str[2] = ':';
time_str[3] = get_char_for_digit(time.minute_tens);
time_str[4] = get_char_for_digit(time.minute_ones);
time_str[5] = ':';
time_str[6] = get_char_for_digit(time.second_tens);
time_str[7] = get_char_for_digit(time.second_ones);
time_str[8] = time.pm ? 'P' : 'A';
time_str[9] = 'M';
time_str[10] = '\0';
FLIP(GPIOB->ODR, GPIO_ODR_OD3);
// for (int i = 0; i < 10000; i++);
display_clear(&display);
display_string_at(&display, 0, font_notomono_10.height * 0, "> Option 1", &font_notomono_10);
display_string_at(&display, 0, font_notomono_10.height * 1, " Option 2", &font_notomono_10);
display_string_at(&display, 0, font_notomono_10.height * 2, " Option 3", &font_notomono_10);
display_string_at(&display, 32, font_notomono_10.height * 0, time_str, &font_notomono_10);
display_string_at(&display, 0, font_notomono_10.height * 2, "> Option 1", &font_notomono_10);
display_string_at(&display, 0, font_notomono_10.height * 3, " Option 2", &font_notomono_10);
display_string_at(&display, 0, font_notomono_10.height * 4, " Option 3", &font_notomono_10);
display_refresh(&display);
x++;
if (x == DISPLAY_WIDTH) {