feat: better microsecond timer (#4112)

This commit is contained in:
Raphael Coeffic
2023-09-26 18:30:55 +02:00
committed by GitHub
parent 6f40ea44ad
commit 6abd4263a4
22 changed files with 135 additions and 195 deletions
+4 -4
View File
@@ -23,7 +23,7 @@
#include "sbus.h"
#include "timers_driver.h"
#define SBUS_FRAME_GAP_DELAY 1000 // 500uS
#define SBUS_FRAME_GAP_DELAY_US 500
#define SBUS_START_BYTE 0x0F
#define SBUS_END_BYTE 0x00
@@ -99,7 +99,7 @@ void processSbusInput()
// TODO: place this outside of the function
static uint8_t SbusIndex = 0;
static uint16_t SbusTimer;
static uint32_t SbusTimer;
static uint8_t SbusFrame[SBUS_FRAME_SIZE];
uint32_t active = 0;
@@ -117,13 +117,13 @@ void processSbusInput()
// Data has been received
if (active) {
SbusTimer = getTmr2MHz();
SbusTimer = timersGetUsTick();
return;
}
// Check if end-of-frame is detected
if (SbusIndex) {
if ((uint16_t)(getTmr2MHz() - SbusTimer) > SBUS_FRAME_GAP_DELAY) {
if ((uint32_t)(timersGetUsTick() - SbusTimer) > SBUS_FRAME_GAP_DELAY_US) {
processSbusFrame(SbusFrame, trainerInput, SbusIndex);
SbusIndex = 0;
}