This commit is contained in:
Sheikah 2023-01-27 17:55:15 +08:00
parent 7cca8f153a
commit 423e3f3571
5 changed files with 27 additions and 1 deletions

View File

@ -5,6 +5,8 @@
"tim.h": "c", "tim.h": "c",
"compare": "c", "compare": "c",
"type_traits": "c", "type_traits": "c",
"gpio.h": "c" "gpio.h": "c",
"stdint.h": "c",
"time.h": "c"
} }
} }

View File

@ -3,6 +3,7 @@
#include "ui.h" #include "ui.h"
#include "keypad.h" #include "keypad.h"
#include "global.h" #include "global.h"
#include "time.h"
void app_init() { void app_init() {
// 程序开始时执行一次 // 程序开始时执行一次

6
Core/Inc/time.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#include <stdint.h>
int32_t ticks_ms();
int32_t ticks_add(int32_t t1, int32_t delta);
int32_t ticks_diff(int32_t t1, int32_t t2);

16
Core/Src/time.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdint.h>
#include "time.h"
#include "main.h"
int32_t ticks_ms() {
return HAL_GetTick() & INT32_MAX;
}
int32_t ticks_add(int32_t t1, int32_t delta) {
return (t1 + delta) & INT32_MAX;
}
int32_t ticks_diff(int32_t t1, int32_t t2) {
int32_t half = (INT32_MAX / 2) + 1;
return ((t1 - t2 + half) & INT32_MAX) - half;
}

View File

@ -68,6 +68,7 @@ Core/Src/gpio.c \
Core/Src/usart.c \ Core/Src/usart.c \
Core/Src/spi.c \ Core/Src/spi.c \
Core/Src/system_stm32g0xx.c \ Core/Src/system_stm32g0xx.c \
Core/Src/time.c \
Core/App/app.c \ Core/App/app.c \
Core/App/global.c \ Core/App/global.c \
Core/Hardware/RotaryCoder/RotaryCoder.c \ Core/Hardware/RotaryCoder/RotaryCoder.c \