You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

49 lines
1.3 KiB
C

#include "p_tcc.h"
#include "lvgl/lvgl.h"
static struct timer_task TIMER_0_task1, TIMER_0_task2;
struct timer_descriptor p_tcc_inst;
#define P_MAX_TIME_STR (64)
static volatile uint32_t sys_time = 0;
static char sys_time_str[64];
static void TIMER_0_task1_cb(const struct timer_task *const timer_task)
{
sys_time++;
lv_tick_inc(1);
}
void p_time_init(void)
{
delay_init(SysTick);
hri_mclk_set_APBAMASK_TC0_bit(MCLK);
hri_gclk_write_PCHCTRL_reg(GCLK, TC0_GCLK_ID, CONF_GCLK_TC0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
timer_init(&p_tcc_inst, TC0, _tc_get_timer());
TIMER_0_task1.interval = 1;
TIMER_0_task1.cb = TIMER_0_task1_cb;
TIMER_0_task1.mode = TIMER_TASK_REPEAT;
timer_add_task(&p_tcc_inst, &TIMER_0_task1);
timer_start(&p_tcc_inst);
}
uint32_t p_get_time(void)
{
return sys_time;
}
const char* p_get_time_str(void)
{
uint16_t millis = sys_time % 1000;
// remove millis portion
uint32_t current_time = sys_time / 1000;
uint8_t hour = ((current_time % 86400UL) / 3600); // 86400 seconds per day
uint8_t minute = ((current_time % 3600) / 60);
uint8_t _sec = (current_time % 60);
memset(sys_time_str, '\0', P_MAX_TIME_STR);
snprintf(sys_time_str, P_MAX_TIME_STR, "%02u:%02u:%02u:%03u", hour, minute, _sec, millis);
return sys_time_str;
}