Changed CurrentTime to a static variable and added function for getting the current time instead

Global variables are really bad practice and should be avoided
This commit is contained in:
Kristian Sloth Lauszus
2018-03-11 17:59:23 +01:00
parent 8f4fc1da8e
commit 6e2eca7829
5 changed files with 10 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
#include "fsl_pit.h" #include "fsl_pit.h"
#include "timer.h" #include "timer.h"
volatile uint32_t CurrentTime; static volatile uint32_t CurrentTime;
void PIT_TIMER_HANDLER(void) void PIT_TIMER_HANDLER(void)
{ {
@@ -24,6 +24,10 @@ void Timer_Init(void)
PIT_StartTimer(PIT, PIT_TIMER_CHANNEL); PIT_StartTimer(PIT, PIT_TIMER_CHANNEL);
} }
uint32_t Timer_GetCurrentTime() {
return CurrentTime;
}
void Timer_SetCurrentTime(uint32_t *time) void Timer_SetCurrentTime(uint32_t *time)
{ {
*time = CurrentTime; *time = CurrentTime;

View File

@@ -9,13 +9,10 @@
#define TIMER_INTERVAL_MSEC 1 #define TIMER_INTERVAL_MSEC 1
// Variables:
extern volatile uint32_t CurrentTime;
// Functions: // Functions:
void Timer_Init(void); void Timer_Init(void);
uint32_t Timer_GetCurrentTime();
void Timer_SetCurrentTime(uint32_t *time); void Timer_SetCurrentTime(uint32_t *time);
uint32_t Timer_GetElapsedTime(uint32_t *time); uint32_t Timer_GetElapsedTime(uint32_t *time);
uint32_t Timer_GetElapsedTimeAndSetCurrent(uint32_t *time); uint32_t Timer_GetElapsedTimeAndSetCurrent(uint32_t *time);

View File

@@ -22,7 +22,7 @@ void UsbCommand_GetDebugBuffer(void)
SetDebugBufferUint32(13, I2cWatchdog_RecoveryCounter); SetDebugBufferUint32(13, I2cWatchdog_RecoveryCounter);
SetDebugBufferUint32(17, KeyScannerCounter); SetDebugBufferUint32(17, KeyScannerCounter);
SetDebugBufferUint32(21, UsbReportUpdateCounter); SetDebugBufferUint32(21, UsbReportUpdateCounter);
SetDebugBufferUint32(25, CurrentTime); SetDebugBufferUint32(25, Timer_GetCurrentTime());
SetDebugBufferUint32(29, UsbGenericHidActionCounter); SetDebugBufferUint32(29, UsbGenericHidActionCounter);
SetDebugBufferUint32(33, UsbBasicKeyboardActionCounter); SetDebugBufferUint32(33, UsbBasicKeyboardActionCounter);
SetDebugBufferUint32(37, UsbMediaKeyboardActionCounter); SetDebugBufferUint32(37, UsbMediaKeyboardActionCounter);

View File

@@ -69,7 +69,7 @@ void UsbCommand_GetDeviceProperty(void)
SetUsbTxBufferUint32(6, I2cMainBusActualBaudRateBps); SetUsbTxBufferUint32(6, I2cMainBusActualBaudRateBps);
break; break;
case DevicePropertyId_Uptime: case DevicePropertyId_Uptime:
SetUsbTxBufferUint32(1, CurrentTime); SetUsbTxBufferUint32(1, Timer_GetCurrentTime());
break; break;
default: default:
SetUsbTxBufferUint8(0, UsbStatusCode_GetDeviceProperty_InvalidProperty); SetUsbTxBufferUint8(0, UsbStatusCode_GetDeviceProperty_InvalidProperty);

View File

@@ -245,11 +245,11 @@ static void applyKeyAction(key_state_t *keyState, key_action_t *action)
if (!keyState->previous && previousLayer == LayerId_Base && action->switchLayer.mode == SwitchLayerMode_HoldAndDoubleTapToggle) { if (!keyState->previous && previousLayer == LayerId_Base && action->switchLayer.mode == SwitchLayerMode_HoldAndDoubleTapToggle) {
if (doubleTapSwitchLayerKey && Timer_GetElapsedTimeAndSetCurrent(&doubleTapSwitchLayerStartTime) < DoubleTapSwitchLayerTimeout) { if (doubleTapSwitchLayerKey && Timer_GetElapsedTimeAndSetCurrent(&doubleTapSwitchLayerStartTime) < DoubleTapSwitchLayerTimeout) {
ToggledLayer = action->switchLayer.layer; ToggledLayer = action->switchLayer.layer;
doubleTapSwitchLayerTriggerTime = CurrentTime; doubleTapSwitchLayerTriggerTime = Timer_GetCurrentTime();
} else { } else {
doubleTapSwitchLayerKey = keyState; doubleTapSwitchLayerKey = keyState;
} }
doubleTapSwitchLayerStartTime = CurrentTime; doubleTapSwitchLayerStartTime = Timer_GetCurrentTime();
} }
break; break;
case KeyActionType_SwitchKeymap: case KeyActionType_SwitchKeymap: