Merge commit 'b68c6bed184f5da12f00c173e23b07c4428be661' into dev
This commit is contained in:
@@ -6,10 +6,10 @@
|
|||||||
#include "config_parser/config_globals.h"
|
#include "config_parser/config_globals.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
||||||
bool IsEepromBusy;
|
volatile bool IsEepromBusy;
|
||||||
static eeprom_operation_t CurrentEepromOperation;
|
static eeprom_operation_t CurrentEepromOperation;
|
||||||
static config_buffer_id_t CurrentConfigBufferId;
|
static config_buffer_id_t CurrentConfigBufferId;
|
||||||
status_t LastEepromTransferStatus;
|
static status_t LastEepromTransferStatus;
|
||||||
void (*SuccessCallback)(void);
|
void (*SuccessCallback)(void);
|
||||||
|
|
||||||
static i2c_master_handle_t i2cHandle;
|
static i2c_master_handle_t i2cHandle;
|
||||||
|
|||||||
@@ -24,8 +24,7 @@
|
|||||||
|
|
||||||
// Variables:
|
// Variables:
|
||||||
|
|
||||||
extern bool IsEepromBusy;
|
extern volatile bool IsEepromBusy;
|
||||||
extern status_t EepromTransferStatus;
|
|
||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,10 @@
|
|||||||
#include "bootloader/wormhole.h"
|
#include "bootloader/wormhole.h"
|
||||||
|
|
||||||
bool IsBusPalOn;
|
bool IsBusPalOn;
|
||||||
uint32_t I2cMainBusRequestedBaudRateBps = I2C_MAIN_BUS_NORMAL_BAUD_RATE;
|
volatile uint32_t I2cMainBusRequestedBaudRateBps = I2C_MAIN_BUS_NORMAL_BAUD_RATE;
|
||||||
uint32_t I2cMainBusActualBaudRateBps;
|
volatile uint32_t I2cMainBusActualBaudRateBps;
|
||||||
|
|
||||||
void initBusPalState(void) {
|
static void initBusPalState(void) {
|
||||||
IsBusPalOn = Wormhole.magicNumber == WORMHOLE_MAGIC_NUMBER && Wormhole.enumerationMode == EnumerationMode_BusPal;
|
IsBusPalOn = Wormhole.magicNumber == WORMHOLE_MAGIC_NUMBER && Wormhole.enumerationMode == EnumerationMode_BusPal;
|
||||||
if (IsBusPalOn) {
|
if (IsBusPalOn) {
|
||||||
Wormhole.magicNumber = 0;
|
Wormhole.magicNumber = 0;
|
||||||
@@ -29,7 +29,7 @@ void initBusPalState(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initInterruptPriorities(void)
|
static void initInterruptPriorities(void)
|
||||||
{
|
{
|
||||||
NVIC_SetPriority(PIT_I2C_WATCHDOG_IRQ_ID, 1);
|
NVIC_SetPriority(PIT_I2C_WATCHDOG_IRQ_ID, 1);
|
||||||
NVIC_SetPriority(PIT_TIMER_IRQ_ID, 2);
|
NVIC_SetPriority(PIT_TIMER_IRQ_ID, 2);
|
||||||
@@ -40,12 +40,12 @@ void initInterruptPriorities(void)
|
|||||||
NVIC_SetPriority(USB_IRQ_ID, 3);
|
NVIC_SetPriority(USB_IRQ_ID, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delay(void)
|
static void delay(void)
|
||||||
{
|
{
|
||||||
for (volatile uint32_t i=0; i<62; i++);
|
for (volatile uint32_t i=0; i<62; i++);
|
||||||
}
|
}
|
||||||
|
|
||||||
void recoverI2c(void)
|
static void recoverI2c(void)
|
||||||
{
|
{
|
||||||
PORT_SetPinMux(I2C_MAIN_BUS_SDA_PORT, I2C_MAIN_BUS_SDA_PIN, kPORT_MuxAsGpio);
|
PORT_SetPinMux(I2C_MAIN_BUS_SDA_PORT, I2C_MAIN_BUS_SDA_PIN, kPORT_MuxAsGpio);
|
||||||
PORT_SetPinMux(I2C_MAIN_BUS_SCL_PORT, I2C_MAIN_BUS_SCL_PIN, kPORT_MuxAsGpio);
|
PORT_SetPinMux(I2C_MAIN_BUS_SCL_PORT, I2C_MAIN_BUS_SCL_PIN, kPORT_MuxAsGpio);
|
||||||
@@ -74,7 +74,7 @@ void recoverI2c(void)
|
|||||||
delay();
|
delay();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initI2cMainBus(void)
|
static void initI2cMainBus(void)
|
||||||
{
|
{
|
||||||
CLOCK_EnableClock(I2C_MAIN_BUS_SDA_CLOCK);
|
CLOCK_EnableClock(I2C_MAIN_BUS_SDA_CLOCK);
|
||||||
CLOCK_EnableClock(I2C_MAIN_BUS_SCL_CLOCK);
|
CLOCK_EnableClock(I2C_MAIN_BUS_SCL_CLOCK);
|
||||||
@@ -105,7 +105,7 @@ void ReinitI2cMainBus(void)
|
|||||||
InitSlaveScheduler();
|
InitSlaveScheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initI2cEepromBus(void)
|
static void initI2cEepromBus(void)
|
||||||
{
|
{
|
||||||
port_pin_config_t pinConfig = {
|
port_pin_config_t pinConfig = {
|
||||||
.pullSelect = kPORT_PullUp,
|
.pullSelect = kPORT_PullUp,
|
||||||
@@ -126,7 +126,7 @@ void initI2cEepromBus(void)
|
|||||||
I2C_MasterInit(I2C_EEPROM_BUS_BASEADDR, &masterConfig, sourceClock);
|
I2C_MasterInit(I2C_EEPROM_BUS_BASEADDR, &masterConfig, sourceClock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initI2c(void)
|
static void initI2c(void)
|
||||||
{
|
{
|
||||||
initI2cMainBus();
|
initI2cMainBus();
|
||||||
initI2cEepromBus();
|
initI2cEepromBus();
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
// Variables:
|
// Variables:
|
||||||
|
|
||||||
extern bool IsBusPalOn;
|
extern bool IsBusPalOn;
|
||||||
extern uint32_t I2cMainBusRequestedBaudRateBps;
|
extern volatile uint32_t I2cMainBusRequestedBaudRateBps;
|
||||||
extern uint32_t I2cMainBusActualBaudRateBps;
|
extern volatile uint32_t I2cMainBusActualBaudRateBps;
|
||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ void LedDisplay_SetCurrentKeymapText(void)
|
|||||||
LedDisplay_SetText(currentKeymap->abbreviationLen, currentKeymap->abbreviation);
|
LedDisplay_SetText(currentKeymap->abbreviationLen, currentKeymap->abbreviation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedDisplay_SetLayer(uint8_t layerId)
|
void LedDisplay_SetLayer(layer_id_t layerId)
|
||||||
{
|
{
|
||||||
for (uint8_t i = 13; i <= 45; i += 16) {
|
for (uint8_t i = 13; i <= 45; i += 16) {
|
||||||
LedDriverValues[LedDriverId_Left][i] = 0;
|
LedDriverValues[LedDriverId_Left][i] = 0;
|
||||||
@@ -101,6 +101,11 @@ void LedDisplay_SetLayer(uint8_t layerId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LedDisplay_GetIcon(led_display_icon_t icon)
|
||||||
|
{
|
||||||
|
return LedDriverValues[LedDriverId_Left][8 + icon];
|
||||||
|
}
|
||||||
|
|
||||||
void LedDisplay_SetIcon(led_display_icon_t icon, bool isEnabled)
|
void LedDisplay_SetIcon(led_display_icon_t icon, bool isEnabled)
|
||||||
{
|
{
|
||||||
LedDriverValues[LedDriverId_Left][8 + icon] = isEnabled ? IconsAndLayerTextsBrightness : 0;
|
LedDriverValues[LedDriverId_Left][8 + icon] = isEnabled ? IconsAndLayerTextsBrightness : 0;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "layer.h"
|
||||||
|
|
||||||
// Typedefs:
|
// Typedefs:
|
||||||
|
|
||||||
@@ -23,7 +24,9 @@
|
|||||||
|
|
||||||
void LedDisplay_SetText(uint8_t length, const char* text);
|
void LedDisplay_SetText(uint8_t length, const char* text);
|
||||||
void LedDisplay_SetCurrentKeymapText(void);
|
void LedDisplay_SetCurrentKeymapText(void);
|
||||||
void LedDisplay_SetLayer(uint8_t layerId);
|
void LedDisplay_SetLayer(layer_id_t layerId);
|
||||||
void LedDisplay_SetIcon(led_display_icon_t icon, bool isEnabled);
|
void LedDisplay_SetIcon(led_display_icon_t icon, bool isEnabled);
|
||||||
|
|
||||||
|
bool LedDisplay_GetIcon(led_display_icon_t icon);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -11,15 +11,15 @@
|
|||||||
#include "peripherals/reset_button.h"
|
#include "peripherals/reset_button.h"
|
||||||
#include "usb_report_updater.h"
|
#include "usb_report_updater.h"
|
||||||
|
|
||||||
bool IsEepromInitialized = false;
|
static bool IsEepromInitialized = false;
|
||||||
bool IsConfigInitialized = false;
|
static bool IsConfigInitialized = false;
|
||||||
|
|
||||||
void userConfigurationReadFinished(void)
|
static void userConfigurationReadFinished(void)
|
||||||
{
|
{
|
||||||
IsEepromInitialized = true;
|
IsEepromInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hardwareConfigurationReadFinished(void)
|
static void hardwareConfigurationReadFinished(void)
|
||||||
{
|
{
|
||||||
EEPROM_LaunchTransfer(EepromOperation_Read, ConfigBufferId_StagingUserConfig, userConfigurationReadFinished);
|
EEPROM_LaunchTransfer(EepromOperation_Read, ConfigBufferId_StagingUserConfig, userConfigurationReadFinished);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "fsl_port.h"
|
#include "fsl_port.h"
|
||||||
#include "peripherals/adc.h"
|
#include "peripherals/adc.h"
|
||||||
|
|
||||||
adc16_channel_config_t adc16ChannelConfigStruct;
|
static adc16_channel_config_t adc16ChannelConfigStruct;
|
||||||
|
|
||||||
void ADC_Init(void)
|
void ADC_Init(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "fsl_pit.h"
|
#include "fsl_pit.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
@@ -9,13 +9,10 @@
|
|||||||
|
|
||||||
#define TIMER_INTERVAL_MSEC 1
|
#define TIMER_INTERVAL_MSEC 1
|
||||||
|
|
||||||
// Variables:
|
|
||||||
|
|
||||||
extern 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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#include "config.h"
|
||||||
|
#include "led_display.h"
|
||||||
|
#include "slave_drivers/is31fl3731_driver.h"
|
||||||
#include "usb_device_config.h"
|
#include "usb_device_config.h"
|
||||||
#include "usb_composite_device.h"
|
#include "usb_composite_device.h"
|
||||||
#include "usb_descriptors/usb_descriptor_hid.h"
|
#include "usb_descriptors/usb_descriptor_hid.h"
|
||||||
@@ -160,21 +163,89 @@ static usb_device_class_config_list_struct_t UsbDeviceCompositeConfigList = {
|
|||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
static bool computerSleeping = false;
|
||||||
|
#ifdef LED_DRIVERS_ENABLED
|
||||||
|
static uint8_t oldKeyBacklightBrightness = 0xFF;
|
||||||
|
static bool capsLockOn = false, agentOn = false, adaptiveOn = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool IsComputerSleeping(void) {
|
||||||
|
return computerSleeping;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ComputerIsSleeping(void) {
|
||||||
|
computerSleeping = true;
|
||||||
|
#ifdef LED_DRIVERS_ENABLED
|
||||||
|
// Save the state of the icons
|
||||||
|
capsLockOn = LedDisplay_GetIcon(LedDisplayIcon_CapsLock);
|
||||||
|
agentOn = LedDisplay_GetIcon(LedDisplayIcon_Agent);
|
||||||
|
adaptiveOn = LedDisplay_GetIcon(LedDisplayIcon_Adaptive);
|
||||||
|
|
||||||
|
// Disable keyboard backlight
|
||||||
|
oldKeyBacklightBrightness = KeyBacklightBrightness;
|
||||||
|
KeyBacklightBrightness = 0;
|
||||||
|
LedSlaveDriver_Init(LedDriverId_Right);
|
||||||
|
LedSlaveDriver_Init(LedDriverId_Left);
|
||||||
|
|
||||||
|
// Turn layer LEDs off
|
||||||
|
LedDisplay_SetLayer(LayerId_Base);
|
||||||
|
|
||||||
|
// Clear the text
|
||||||
|
LedDisplay_SetText(0, NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void WakeupComputer(bool sendResume) {
|
||||||
|
if (sendResume) // The device should wake up the computer
|
||||||
|
USB_DeviceSetStatus(UsbCompositeDevice.deviceHandle, kUSB_DeviceStatusBus, NULL); // Send resume signal - this will call USB_DeviceKhciControl(khciHandle, kUSB_DeviceControlResume, NULL);
|
||||||
|
|
||||||
|
computerSleeping = false; // The computer is now awake
|
||||||
|
|
||||||
|
#ifdef LED_DRIVERS_ENABLED
|
||||||
|
// Restore keyboard backlight and text
|
||||||
|
KeyBacklightBrightness = oldKeyBacklightBrightness;
|
||||||
|
LedSlaveDriver_Init(LedDriverId_Right);
|
||||||
|
LedSlaveDriver_Init(LedDriverId_Left);
|
||||||
|
|
||||||
|
// Update the active layer
|
||||||
|
LedDisplay_SetLayer(GetActiveLayer());
|
||||||
|
|
||||||
|
// Restore icon states
|
||||||
|
LedDisplay_SetIcon(LedDisplayIcon_CapsLock, capsLockOn);
|
||||||
|
LedDisplay_SetIcon(LedDisplayIcon_Agent, agentOn);
|
||||||
|
LedDisplay_SetIcon(LedDisplayIcon_Adaptive, adaptiveOn);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static usb_status_t usbDeviceCallback(usb_device_handle handle, uint32_t event, void *param)
|
static usb_status_t usbDeviceCallback(usb_device_handle handle, uint32_t event, void *param)
|
||||||
{
|
{
|
||||||
usb_status_t status = kStatus_USB_Error;
|
usb_status_t status = kStatus_USB_Error;
|
||||||
uint16_t *temp16 = (uint16_t*)param;
|
uint16_t *temp16 = (uint16_t*)param;
|
||||||
uint8_t *temp8 = (uint8_t*)param;
|
uint8_t *temp8 = (uint8_t*)param;
|
||||||
|
|
||||||
if (!param && event != kUSB_DeviceEventBusReset && event != kUSB_DeviceEventSetInterface) {
|
if (!param && event != kUSB_DeviceEventBusReset && event != kUSB_DeviceEventSetInterface && event != kUSB_DeviceEventSuspend && event != kUSB_DeviceEventResume) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (computerSleeping)
|
||||||
|
WakeupComputer(false); // Wake up the keyboard if there is any activity on the bus
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case kUSB_DeviceEventBusReset:
|
case kUSB_DeviceEventBusReset:
|
||||||
UsbCompositeDevice.attach = 0;
|
UsbCompositeDevice.attach = 0;
|
||||||
status = kStatus_USB_Success;
|
status = kStatus_USB_Success;
|
||||||
break;
|
break;
|
||||||
|
case kUSB_DeviceEventSuspend:
|
||||||
|
if (UsbCompositeDevice.attach) {
|
||||||
|
ComputerIsSleeping(); // The computer sends this event when it goes to sleep, so turn off all the LEDs
|
||||||
|
status = kStatus_USB_Success;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case kUSB_DeviceEventResume:
|
||||||
|
// We will just wake up the computer if there is any activity on the bus
|
||||||
|
// The problem is that the computer won't send a resume event when it boots, so the lights will never come back on
|
||||||
|
status = kStatus_USB_Success;
|
||||||
|
break;
|
||||||
case kUSB_DeviceEventSetConfiguration:
|
case kUSB_DeviceEventSetConfiguration:
|
||||||
UsbCompositeDevice.attach = 1;
|
UsbCompositeDevice.attach = 1;
|
||||||
UsbCompositeDevice.currentConfiguration = *temp8;
|
UsbCompositeDevice.currentConfiguration = *temp8;
|
||||||
|
|||||||
@@ -33,5 +33,7 @@
|
|||||||
//Functions:
|
//Functions:
|
||||||
|
|
||||||
void InitUsb(void);
|
void InitUsb(void);
|
||||||
|
bool IsComputerSleeping(void);
|
||||||
|
void WakeupComputer(bool sendResume);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -23,10 +23,10 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Whether the device is self-powered: 1 supported, 0 not supported
|
// Whether the device is self-powered: 1 supported, 0 not supported
|
||||||
#define USB_DEVICE_CONFIG_SELF_POWER 1
|
#define USB_DEVICE_CONFIG_SELF_POWER 0
|
||||||
|
|
||||||
// Whether device remote wakeup supported: 1 supported, 0 not supported
|
// Whether device remote wakeup supported: 1 supported, 0 not supported
|
||||||
#define USB_DEVICE_CONFIG_REMOTE_WAKEUP 0
|
#define USB_DEVICE_CONFIG_REMOTE_WAKEUP 1
|
||||||
|
|
||||||
// The number of control endpoints, which is always 1
|
// The number of control endpoints, which is always 1
|
||||||
#define USB_CONTROL_ENDPOINT_COUNT 1
|
#define USB_CONTROL_ENDPOINT_COUNT 1
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
static usb_basic_keyboard_report_t usbBasicKeyboardReports[2];
|
static usb_basic_keyboard_report_t usbBasicKeyboardReports[2];
|
||||||
uint32_t UsbBasicKeyboardActionCounter;
|
uint32_t UsbBasicKeyboardActionCounter;
|
||||||
usb_basic_keyboard_report_t* ActiveUsbBasicKeyboardReport = usbBasicKeyboardReports;
|
usb_basic_keyboard_report_t* ActiveUsbBasicKeyboardReport = usbBasicKeyboardReports;
|
||||||
bool IsUsbBasicKeyboardReportSent = false;
|
volatile bool IsUsbBasicKeyboardReportSent = false;
|
||||||
static uint8_t usbBasicKeyboardInBuffer[USB_BASIC_KEYBOARD_REPORT_LENGTH];
|
static uint8_t usbBasicKeyboardInBuffer[USB_BASIC_KEYBOARD_REPORT_LENGTH];
|
||||||
|
|
||||||
usb_basic_keyboard_report_t* getInactiveUsbBasicKeyboardReport(void)
|
static usb_basic_keyboard_report_t* getInactiveUsbBasicKeyboardReport(void)
|
||||||
{
|
{
|
||||||
return ActiveUsbBasicKeyboardReport == usbBasicKeyboardReports ? usbBasicKeyboardReports+1 : usbBasicKeyboardReports;
|
return ActiveUsbBasicKeyboardReport == usbBasicKeyboardReports ? usbBasicKeyboardReports+1 : usbBasicKeyboardReports;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
// Variables:
|
// Variables:
|
||||||
|
|
||||||
extern bool IsUsbBasicKeyboardReportSent;
|
extern volatile bool IsUsbBasicKeyboardReportSent;
|
||||||
extern uint32_t UsbBasicKeyboardActionCounter;
|
extern uint32_t UsbBasicKeyboardActionCounter;
|
||||||
extern usb_basic_keyboard_report_t* ActiveUsbBasicKeyboardReport;
|
extern usb_basic_keyboard_report_t* ActiveUsbBasicKeyboardReport;
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
uint32_t UsbMediaKeyboardActionCounter;
|
uint32_t UsbMediaKeyboardActionCounter;
|
||||||
static usb_media_keyboard_report_t usbMediaKeyboardReports[2];
|
static usb_media_keyboard_report_t usbMediaKeyboardReports[2];
|
||||||
usb_media_keyboard_report_t* ActiveUsbMediaKeyboardReport = usbMediaKeyboardReports;
|
usb_media_keyboard_report_t* ActiveUsbMediaKeyboardReport = usbMediaKeyboardReports;
|
||||||
bool IsUsbMediaKeyboardReportSent = false;
|
volatile bool IsUsbMediaKeyboardReportSent = false;
|
||||||
|
|
||||||
usb_media_keyboard_report_t* getInactiveUsbMediaKeyboardReport(void)
|
static usb_media_keyboard_report_t* getInactiveUsbMediaKeyboardReport(void)
|
||||||
{
|
{
|
||||||
return ActiveUsbMediaKeyboardReport == usbMediaKeyboardReports ? usbMediaKeyboardReports+1 : usbMediaKeyboardReports;
|
return ActiveUsbMediaKeyboardReport == usbMediaKeyboardReports ? usbMediaKeyboardReports+1 : usbMediaKeyboardReports;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
// Variables:
|
// Variables:
|
||||||
|
|
||||||
extern bool IsUsbMediaKeyboardReportSent;
|
extern volatile bool IsUsbMediaKeyboardReportSent;
|
||||||
extern uint32_t UsbMediaKeyboardActionCounter;
|
extern uint32_t UsbMediaKeyboardActionCounter;
|
||||||
extern usb_media_keyboard_report_t* ActiveUsbMediaKeyboardReport;
|
extern usb_media_keyboard_report_t* ActiveUsbMediaKeyboardReport;
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
uint32_t UsbMouseActionCounter;
|
uint32_t UsbMouseActionCounter;
|
||||||
static usb_mouse_report_t usbMouseReports[2];
|
static usb_mouse_report_t usbMouseReports[2];
|
||||||
usb_mouse_report_t* ActiveUsbMouseReport = usbMouseReports;
|
usb_mouse_report_t* ActiveUsbMouseReport = usbMouseReports;
|
||||||
bool IsUsbMouseReportSent = false;
|
volatile bool IsUsbMouseReportSent = false;
|
||||||
|
|
||||||
usb_mouse_report_t* getInactiveUsbMouseReport(void)
|
static usb_mouse_report_t* getInactiveUsbMouseReport(void)
|
||||||
{
|
{
|
||||||
return ActiveUsbMouseReport == usbMouseReports ? usbMouseReports+1 : usbMouseReports;
|
return ActiveUsbMouseReport == usbMouseReports ? usbMouseReports+1 : usbMouseReports;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
// Variables:
|
// Variables:
|
||||||
|
|
||||||
extern bool IsUsbMouseReportSent;
|
extern volatile bool IsUsbMouseReportSent;
|
||||||
extern uint32_t UsbMouseActionCounter;
|
extern uint32_t UsbMouseActionCounter;
|
||||||
extern usb_mouse_report_t* ActiveUsbMouseReport;
|
extern usb_mouse_report_t* ActiveUsbMouseReport;
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
uint32_t UsbSystemKeyboardActionCounter;
|
uint32_t UsbSystemKeyboardActionCounter;
|
||||||
static usb_system_keyboard_report_t usbSystemKeyboardReports[2];
|
static usb_system_keyboard_report_t usbSystemKeyboardReports[2];
|
||||||
usb_system_keyboard_report_t* ActiveUsbSystemKeyboardReport = usbSystemKeyboardReports;
|
usb_system_keyboard_report_t* ActiveUsbSystemKeyboardReport = usbSystemKeyboardReports;
|
||||||
bool IsUsbSystemKeyboardReportSent = false;
|
volatile bool IsUsbSystemKeyboardReportSent = false;
|
||||||
|
|
||||||
usb_system_keyboard_report_t* getInactiveUsbSystemKeyboardReport()
|
static usb_system_keyboard_report_t* getInactiveUsbSystemKeyboardReport()
|
||||||
{
|
{
|
||||||
return ActiveUsbSystemKeyboardReport == usbSystemKeyboardReports ? usbSystemKeyboardReports+1 : usbSystemKeyboardReports;
|
return ActiveUsbSystemKeyboardReport == usbSystemKeyboardReports ? usbSystemKeyboardReports+1 : usbSystemKeyboardReports;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
// Variables:
|
// Variables:
|
||||||
|
|
||||||
extern bool IsUsbSystemKeyboardReportSent;
|
extern volatile bool IsUsbSystemKeyboardReportSent;
|
||||||
extern uint32_t UsbSystemKeyboardActionCounter;
|
extern uint32_t UsbSystemKeyboardActionCounter;
|
||||||
extern usb_system_keyboard_report_t* ActiveUsbSystemKeyboardReport;
|
extern usb_system_keyboard_report_t* ActiveUsbSystemKeyboardReport;
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,11 @@
|
|||||||
#include "config_parser/parse_keymap.h"
|
#include "config_parser/parse_keymap.h"
|
||||||
#include "usb_commands/usb_command_get_debug_buffer.h"
|
#include "usb_commands/usb_command_get_debug_buffer.h"
|
||||||
|
|
||||||
uint32_t UsbReportUpdateTime = 0;
|
static uint32_t UsbReportUpdateTime = 0;
|
||||||
static uint32_t elapsedTime;
|
static uint32_t elapsedTime;
|
||||||
|
|
||||||
uint16_t DoubleTapSwitchLayerTimeout = 150;
|
uint16_t DoubleTapSwitchLayerTimeout = 150;
|
||||||
uint16_t DoubleTapSwitchLayerReleaseTimeout = 100;
|
static uint16_t DoubleTapSwitchLayerReleaseTimeout = 100;
|
||||||
|
|
||||||
static bool activeMouseStates[ACTIVE_MOUSE_STATES_COUNT];
|
static bool activeMouseStates[ACTIVE_MOUSE_STATES_COUNT];
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ mouse_kinetic_state_t MouseScrollState = {
|
|||||||
.acceleratedSpeed = 50,
|
.acceleratedSpeed = 50,
|
||||||
};
|
};
|
||||||
|
|
||||||
void processMouseKineticState(mouse_kinetic_state_t *kineticState)
|
static void processMouseKineticState(mouse_kinetic_state_t *kineticState)
|
||||||
{
|
{
|
||||||
float initialSpeed = kineticState->intMultiplier * kineticState->initialSpeed;
|
float initialSpeed = kineticState->intMultiplier * kineticState->initialSpeed;
|
||||||
float acceleration = kineticState->intMultiplier * kineticState->acceleration;
|
float acceleration = kineticState->intMultiplier * kineticState->acceleration;
|
||||||
@@ -155,7 +155,7 @@ void processMouseKineticState(mouse_kinetic_state_t *kineticState)
|
|||||||
kineticState->wasMoveAction = isMoveAction;
|
kineticState->wasMoveAction = isMoveAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void processMouseActions()
|
static void processMouseActions()
|
||||||
{
|
{
|
||||||
processMouseKineticState(&MouseMoveState);
|
processMouseKineticState(&MouseMoveState);
|
||||||
ActiveUsbMouseReport->x = MouseMoveState.xOut;
|
ActiveUsbMouseReport->x = MouseMoveState.xOut;
|
||||||
@@ -193,7 +193,7 @@ static uint8_t basicScancodeIndex = 0;
|
|||||||
static uint8_t mediaScancodeIndex = 0;
|
static uint8_t mediaScancodeIndex = 0;
|
||||||
static uint8_t systemScancodeIndex = 0;
|
static uint8_t systemScancodeIndex = 0;
|
||||||
|
|
||||||
void applyKeyAction(key_state_t *keyState, key_action_t *action)
|
static void applyKeyAction(key_state_t *keyState, key_action_t *action)
|
||||||
{
|
{
|
||||||
static key_state_t *doubleTapSwitchLayerKey;
|
static key_state_t *doubleTapSwitchLayerKey;
|
||||||
static uint32_t doubleTapSwitchLayerStartTime;
|
static uint32_t doubleTapSwitchLayerStartTime;
|
||||||
@@ -245,11 +245,11 @@ 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:
|
||||||
@@ -265,7 +265,7 @@ static uint8_t secondaryRoleSlotId;
|
|||||||
static uint8_t secondaryRoleKeyId;
|
static uint8_t secondaryRoleKeyId;
|
||||||
static secondary_role_t secondaryRole;
|
static secondary_role_t secondaryRole;
|
||||||
|
|
||||||
void updateActiveUsbReports(void)
|
static void updateActiveUsbReports(void)
|
||||||
{
|
{
|
||||||
memset(activeMouseStates, 0, ACTIVE_MOUSE_STATES_COUNT);
|
memset(activeMouseStates, 0, ACTIVE_MOUSE_STATES_COUNT);
|
||||||
|
|
||||||
@@ -369,10 +369,10 @@ void updateActiveUsbReports(void)
|
|||||||
previousLayer = activeLayer;
|
previousLayer = activeLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UsbBasicKeyboardReportEverSent = false;
|
static bool UsbBasicKeyboardReportEverSent = false;
|
||||||
bool UsbMediaKeyboardReportEverSent = false;
|
static bool UsbMediaKeyboardReportEverSent = false;
|
||||||
bool UsbSystemKeyboardReportEverSent = false;
|
static bool UsbSystemKeyboardReportEverSent = false;
|
||||||
bool UsbMouseReportEverSentEverSent = false;
|
static bool UsbMouseReportEverSentEverSent = false;
|
||||||
|
|
||||||
uint32_t UsbReportUpdateCounter;
|
uint32_t UsbReportUpdateCounter;
|
||||||
static uint32_t lastUsbUpdateTime;
|
static uint32_t lastUsbUpdateTime;
|
||||||
@@ -425,15 +425,36 @@ void UpdateUsbReports(void)
|
|||||||
|
|
||||||
updateActiveUsbReports();
|
updateActiveUsbReports();
|
||||||
|
|
||||||
SwitchActiveUsbBasicKeyboardReport();
|
static usb_basic_keyboard_report_t last_basic_report = { .scancodes[0] = 0xFF };
|
||||||
SwitchActiveUsbMediaKeyboardReport();
|
if (memcmp(ActiveUsbBasicKeyboardReport, &last_basic_report, sizeof(usb_basic_keyboard_report_t)) != 0) {
|
||||||
SwitchActiveUsbSystemKeyboardReport();
|
last_basic_report = *ActiveUsbBasicKeyboardReport;
|
||||||
SwitchActiveUsbMouseReport();
|
SwitchActiveUsbBasicKeyboardReport();
|
||||||
|
IsUsbBasicKeyboardReportSent = false;
|
||||||
|
}
|
||||||
|
|
||||||
IsUsbBasicKeyboardReportSent = false;
|
static usb_media_keyboard_report_t last_media_report = { .scancodes[0] = 0xFF };
|
||||||
IsUsbMediaKeyboardReportSent = false;
|
if (memcmp(ActiveUsbMediaKeyboardReport, &last_media_report, sizeof(usb_media_keyboard_report_t)) != 0) {
|
||||||
IsUsbSystemKeyboardReportSent = false;
|
last_media_report = *ActiveUsbMediaKeyboardReport;
|
||||||
IsUsbMouseReportSent = false;
|
SwitchActiveUsbMediaKeyboardReport();
|
||||||
|
IsUsbMediaKeyboardReportSent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static usb_system_keyboard_report_t last_system_report = { .scancodes[0] = 0xFF };
|
||||||
|
if (memcmp(ActiveUsbSystemKeyboardReport, &last_system_report, sizeof(usb_system_keyboard_report_t)) != 0) {
|
||||||
|
last_system_report = *ActiveUsbSystemKeyboardReport;
|
||||||
|
SwitchActiveUsbSystemKeyboardReport();
|
||||||
|
IsUsbSystemKeyboardReportSent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static usb_mouse_report_t last_mouse_report = { .buttons = 0xFF };
|
||||||
|
if (memcmp(ActiveUsbMouseReport, &last_mouse_report, sizeof(usb_mouse_report_t)) != 0) {
|
||||||
|
last_mouse_report = *ActiveUsbMouseReport;
|
||||||
|
SwitchActiveUsbMouseReport();
|
||||||
|
IsUsbMouseReportSent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((previousLayer != LayerId_Base || !IsUsbBasicKeyboardReportSent || !IsUsbMediaKeyboardReportSent || !IsUsbSystemKeyboardReportSent || !IsUsbMouseReportSent) && IsComputerSleeping())
|
||||||
|
WakeupComputer(true); // Wake up the computer if any key is pressed and the computer is sleeping
|
||||||
|
|
||||||
Timer_SetCurrentTime(&lastUsbUpdateTime);
|
Timer_SetCurrentTime(&lastUsbUpdateTime);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user