add time
This commit is contained in:
parent
7cca8f153a
commit
423e3f3571
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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
6
Core/Inc/time.h
Normal 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
16
Core/Src/time.c
Normal 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;
|
||||||
|
}
|
1
Makefile
1
Makefile
@ -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 \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user