diff --git a/right/src/macros.c b/right/src/macros.c index 7dd797989..b30bad84e 100644 --- a/right/src/macros.c +++ b/right/src/macros.c @@ -286,7 +286,7 @@ bool processDelayAction(void) inDelay = false; } } else { - Timer_SetCurrentTime(&delayStart); + delayStart = CurrentTime; inDelay = true; } return inDelay; diff --git a/right/src/timer.c b/right/src/timer.c index 3ddf4b9e1..5256401f5 100644 --- a/right/src/timer.c +++ b/right/src/timer.c @@ -2,12 +2,13 @@ #include "timer.h" #include "peripherals/test_led.h" +volatile uint32_t CurrentTime; static uint32_t timerClockFrequency; -static volatile uint32_t currentTime, delayLength; +static volatile uint32_t delayLength; void PIT_TIMER_HANDLER(void) { - currentTime++; + CurrentTime++; if (delayLength) { --delayLength; } @@ -28,15 +29,11 @@ void Timer_Init(void) PIT_StartTimer(PIT, PIT_TIMER_CHANNEL); } -uint32_t Timer_GetCurrentTime() { - return currentTime; -} - uint32_t Timer_GetCurrentTimeMicros() { uint32_t primask, count, ms; primask = DisableGlobalIRQ(); // Make sure the read is atomic count = PIT_GetCurrentTimerCount(PIT, PIT_TIMER_CHANNEL); // Read the current timer count - ms = currentTime; // Read the overflow counter + ms = CurrentTime; // Read the overflow counter EnableGlobalIRQ(primask); // Enable interrupts again if they where enabled before - this should make it interrupt safe // Calculate the counter value in microseconds - note that the PIT timer is counting downward, so we need to subtract the count from the period value @@ -44,11 +41,6 @@ uint32_t Timer_GetCurrentTimeMicros() { return ms * 1000U * TIMER_INTERVAL_MSEC + us; } -void Timer_SetCurrentTime(uint32_t *time) -{ - *time = Timer_GetCurrentTime(); -} - void Timer_SetCurrentTimeMicros(uint32_t *time) { *time = Timer_GetCurrentTimeMicros(); @@ -56,20 +48,18 @@ void Timer_SetCurrentTimeMicros(uint32_t *time) uint32_t Timer_GetElapsedTime(uint32_t *time) { - uint32_t elapsedTime = Timer_GetCurrentTime() - *time; - return elapsedTime; + return CurrentTime - *time; } uint32_t Timer_GetElapsedTimeMicros(uint32_t *time) { - uint32_t elapsedTime = Timer_GetCurrentTimeMicros() - *time; - return elapsedTime; + return Timer_GetCurrentTimeMicros() - *time; } uint32_t Timer_GetElapsedTimeAndSetCurrent(uint32_t *time) { uint32_t elapsedTime = Timer_GetElapsedTime(time); - *time = Timer_GetCurrentTime(); + *time = CurrentTime; return elapsedTime; } diff --git a/right/src/timer.h b/right/src/timer.h index 810bfc15a..9d177d18f 100644 --- a/right/src/timer.h +++ b/right/src/timer.h @@ -9,12 +9,14 @@ #define TIMER_INTERVAL_MSEC 1 +// Variables: + + extern volatile uint32_t CurrentTime; + // Functions: void Timer_Init(void); - uint32_t Timer_GetCurrentTime(); uint32_t Timer_GetCurrentTimeMicros(); - void Timer_SetCurrentTime(uint32_t *time); void Timer_SetCurrentTimeMicros(uint32_t *time); uint32_t Timer_GetElapsedTime(uint32_t *time); uint32_t Timer_GetElapsedTimeMicros(uint32_t *time); diff --git a/right/src/usb_commands/usb_command_get_debug_buffer.c b/right/src/usb_commands/usb_command_get_debug_buffer.c index 23475948b..416cf479b 100644 --- a/right/src/usb_commands/usb_command_get_debug_buffer.c +++ b/right/src/usb_commands/usb_command_get_debug_buffer.c @@ -22,7 +22,7 @@ void UsbCommand_GetDebugBuffer(void) SetDebugBufferUint32(13, I2cWatchdog_RecoveryCounter); SetDebugBufferUint32(17, MatrixScanCounter); SetDebugBufferUint32(21, UsbReportUpdateCounter); - SetDebugBufferUint32(25, Timer_GetCurrentTime()); + SetDebugBufferUint32(25, CurrentTime); SetDebugBufferUint32(29, UsbGenericHidActionCounter); SetDebugBufferUint32(33, UsbBasicKeyboardActionCounter); SetDebugBufferUint32(37, UsbMediaKeyboardActionCounter); diff --git a/right/src/usb_commands/usb_command_get_device_property.c b/right/src/usb_commands/usb_command_get_device_property.c index 50d67c6a2..62c1e5a27 100644 --- a/right/src/usb_commands/usb_command_get_device_property.c +++ b/right/src/usb_commands/usb_command_get_device_property.c @@ -69,7 +69,7 @@ void UsbCommand_GetDeviceProperty(void) SetUsbTxBufferUint32(6, I2cMainBusActualBaudRateBps); break; case DevicePropertyId_Uptime: - SetUsbTxBufferUint32(1, Timer_GetCurrentTime()); + SetUsbTxBufferUint32(1, CurrentTime); break; default: SetUsbTxBufferUint8(0, UsbStatusCode_GetDeviceProperty_InvalidProperty); diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index c3d2b35e2..ef3b229da 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -227,11 +227,11 @@ static void handleSwitchLayerAction(key_state_t *keyState, key_action_t *action) if (doubleTapSwitchLayerKey && Timer_GetElapsedTimeAndSetCurrent(&doubleTapSwitchLayerStartTime) < DoubleTapSwitchLayerTimeout) { ToggledLayer = action->switchLayer.layer; isLayerDoubleTapToggled = true; - doubleTapSwitchLayerTriggerTime = Timer_GetCurrentTime(); + doubleTapSwitchLayerTriggerTime = CurrentTime; } else { doubleTapSwitchLayerKey = keyState; } - doubleTapSwitchLayerStartTime = Timer_GetCurrentTime(); + doubleTapSwitchLayerStartTime = CurrentTime; } } @@ -364,13 +364,13 @@ static void updateActiveUsbReports(void) key_action_t *action; if (keyState->debouncing) { - if ((uint8_t)(Timer_GetCurrentTime() - keyState->timestamp) > (keyState->previous ? DebounceTimePress : DebounceTimeRelease)) { + if ((uint8_t)(CurrentTime - keyState->timestamp) > (keyState->previous ? DebounceTimePress : DebounceTimeRelease)) { keyState->debouncing = false; } else { keyState->current = keyState->previous; } } else if (keyState->previous != keyState->current) { - keyState->timestamp = Timer_GetCurrentTime(); + keyState->timestamp = CurrentTime; keyState->debouncing = true; }