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",
|
||||
"compare": "c",
|
||||
"type_traits": "c",
|
||||
"gpio.h": "c"
|
||||
"gpio.h": "c",
|
||||
"stdint.h": "c",
|
||||
"time.h": "c"
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
#include "ui.h"
|
||||
#include "keypad.h"
|
||||
#include "global.h"
|
||||
#include "time.h"
|
||||
|
||||
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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user