Set up the timer properly and introduce CurrentTime.
This commit is contained in:
@@ -77,7 +77,8 @@ void InitI2cMainBus(void)
|
|||||||
I2C_MasterGetDefaultConfig(&masterConfig);
|
I2C_MasterGetDefaultConfig(&masterConfig);
|
||||||
masterConfig.baudRate_Bps = I2C_MAIN_BUS_BAUD_RATE;
|
masterConfig.baudRate_Bps = I2C_MAIN_BUS_BAUD_RATE;
|
||||||
uint32_t sourceClock = CLOCK_GetFreq(I2C_MASTER_BUS_CLK_SRC);
|
uint32_t sourceClock = CLOCK_GetFreq(I2C_MASTER_BUS_CLK_SRC);
|
||||||
I2C_MasterInit(I2C_MAIN_BUS_BASEADDR, &masterConfig, sourceClock);}
|
I2C_MasterInit(I2C_MAIN_BUS_BASEADDR, &masterConfig, sourceClock);
|
||||||
|
}
|
||||||
|
|
||||||
void initI2cEepromBus(void)
|
void initI2cEepromBus(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,18 +1,28 @@
|
|||||||
#include "fsl_pit.h"
|
#include "fsl_pit.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
|
uint32_t CurrentTime = 1;
|
||||||
|
|
||||||
|
void PIT_TIMER_HANDLER(void)
|
||||||
|
{
|
||||||
|
CurrentTime++;
|
||||||
|
PIT_ClearStatusFlags(PIT, PIT_TIMER_CHANNEL, PIT_TFLG_TIF_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
void Timer_Init(void)
|
void Timer_Init(void)
|
||||||
{
|
{
|
||||||
pit_config_t pitConfig;
|
pit_config_t pitConfig;
|
||||||
PIT_GetDefaultConfig(&pitConfig);
|
PIT_GetDefaultConfig(&pitConfig);
|
||||||
PIT_Init(PIT, &pitConfig);
|
PIT_Init(PIT, &pitConfig);
|
||||||
PIT_SetTimerPeriod(PIT, PIT_TIMER_CHANNEL, USEC_TO_COUNT(TIMER_INTERVAL_USEC, PIT_SOURCE_CLOCK));
|
PIT_SetTimerPeriod(PIT, PIT_TIMER_CHANNEL, MSEC_TO_COUNT(TIMER_INTERVAL_MSEC, PIT_SOURCE_CLOCK));
|
||||||
PIT_EnableInterrupts(PIT, PIT_TIMER_CHANNEL, kPIT_TimerInterruptEnable);
|
PIT_EnableInterrupts(PIT, PIT_TIMER_CHANNEL, kPIT_TimerInterruptEnable);
|
||||||
// EnableIRQ(PIT_TIMER_IRQ_ID);
|
EnableIRQ(PIT_TIMER_IRQ_ID);
|
||||||
PIT_StartTimer(PIT, PIT_TIMER_CHANNEL);
|
PIT_StartTimer(PIT, PIT_TIMER_CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Timer_GetTime(void)
|
uint32_t Timer_GetElapsedTime(uint32_t *time)
|
||||||
{
|
{
|
||||||
return PIT_GetCurrentTimerCount(PIT, PIT_TIMER_CHANNEL);
|
uint32_t elapsedTime = CurrentTime - *time;
|
||||||
|
*time = CurrentTime;
|
||||||
|
return elapsedTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,15 @@
|
|||||||
|
|
||||||
// Macros:
|
// Macros:
|
||||||
|
|
||||||
#define TIMER_INTERVAL_USEC 1000
|
#define TIMER_INTERVAL_MSEC 1
|
||||||
|
|
||||||
|
// Variables:
|
||||||
|
|
||||||
|
extern uint32_t CurrentTime;
|
||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
void Timer_Init(void);
|
void Timer_Init(void);
|
||||||
uint32_t Timer_GetTime(void);
|
uint32_t Timer_GetElapsedTime(uint32_t *time);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ void UsbCommand_GetDebugBuffer(void)
|
|||||||
SetDebugBufferUint32(5, I2cSlaveScheduler_Counter);
|
SetDebugBufferUint32(5, I2cSlaveScheduler_Counter);
|
||||||
SetDebugBufferUint32(9, I2cWatchdog_WatchCounter);
|
SetDebugBufferUint32(9, I2cWatchdog_WatchCounter);
|
||||||
SetDebugBufferUint32(13, I2cWatchdog_RecoveryCounter);
|
SetDebugBufferUint32(13, I2cWatchdog_RecoveryCounter);
|
||||||
SetDebugBufferUint32(40, Timer_GetTime());
|
SetDebugBufferUint32(40, CurrentTime);
|
||||||
|
|
||||||
memcpy(GenericHidOutBuffer, DebugBuffer, USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
memcpy(GenericHidOutBuffer, DebugBuffer, USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||||
|
|
||||||
|
|||||||
@@ -11,15 +11,20 @@
|
|||||||
#include "right_key_matrix.h"
|
#include "right_key_matrix.h"
|
||||||
#include "layer.h"
|
#include "layer.h"
|
||||||
#include "usb_report_updater.h"
|
#include "usb_report_updater.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
|
uint32_t UsbReportUpdateTime = 0;
|
||||||
|
|
||||||
static uint8_t mouseWheelDivisorCounter = 0;
|
static uint8_t mouseWheelDivisorCounter = 0;
|
||||||
static uint8_t mouseSpeedAccelDivisorCounter = 0;
|
static uint8_t mouseSpeedAccelDivisorCounter = 0;
|
||||||
static uint8_t mouseSpeed = 3;
|
static uint8_t mouseSpeed = 10;
|
||||||
static bool wasPreviousMouseActionWheelAction = false;
|
static bool wasPreviousMouseActionWheelAction = false;
|
||||||
|
static uint32_t elapsedTime;
|
||||||
|
|
||||||
void processMouseAction(key_action_t *action)
|
void processMouseAction(key_action_t *action)
|
||||||
{
|
{
|
||||||
bool isWheelAction = action->mouse.scrollActions && !action->mouse.moveActions && !action->mouse.buttonActions;
|
bool isWheelAction = action->mouse.scrollActions && !action->mouse.moveActions && !action->mouse.buttonActions;
|
||||||
|
uint16_t distance = mouseSpeed * elapsedTime / 25;
|
||||||
|
|
||||||
if (isWheelAction && wasPreviousMouseActionWheelAction) {
|
if (isWheelAction && wasPreviousMouseActionWheelAction) {
|
||||||
mouseWheelDivisorCounter++;
|
mouseWheelDivisorCounter++;
|
||||||
@@ -56,16 +61,16 @@ void processMouseAction(key_action_t *action)
|
|||||||
}
|
}
|
||||||
} else if (action->mouse.moveActions) {
|
} else if (action->mouse.moveActions) {
|
||||||
if (action->mouse.moveActions & MouseMove_Left) {
|
if (action->mouse.moveActions & MouseMove_Left) {
|
||||||
ActiveUsbMouseReport->x = -mouseSpeed;
|
ActiveUsbMouseReport->x = -distance;
|
||||||
}
|
}
|
||||||
if (action->mouse.moveActions & MouseMove_Right) {
|
if (action->mouse.moveActions & MouseMove_Right) {
|
||||||
ActiveUsbMouseReport->x = mouseSpeed;
|
ActiveUsbMouseReport->x = distance;
|
||||||
}
|
}
|
||||||
if (action->mouse.moveActions & MouseMove_Up) {
|
if (action->mouse.moveActions & MouseMove_Up) {
|
||||||
ActiveUsbMouseReport->y = -mouseSpeed;
|
ActiveUsbMouseReport->y = -distance;
|
||||||
}
|
}
|
||||||
if (action->mouse.moveActions & MouseMove_Down) {
|
if (action->mouse.moveActions & MouseMove_Down) {
|
||||||
ActiveUsbMouseReport->y = mouseSpeed;
|
ActiveUsbMouseReport->y = distance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +134,8 @@ static secondary_role_t secondaryRole;
|
|||||||
void UpdateActiveUsbReports(void)
|
void UpdateActiveUsbReports(void)
|
||||||
{
|
{
|
||||||
static uint8_t previousModifiers = 0;
|
static uint8_t previousModifiers = 0;
|
||||||
|
elapsedTime = Timer_GetElapsedTime(&UsbReportUpdateTime);
|
||||||
|
|
||||||
basicScancodeIndex = 0;
|
basicScancodeIndex = 0;
|
||||||
mediaScancodeIndex = 0;
|
mediaScancodeIndex = 0;
|
||||||
systemScancodeIndex = 0;
|
systemScancodeIndex = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user