diff --git a/right/src/led_display.c b/right/src/led_display.c index cb3d8c9..d6fab2b 100644 --- a/right/src/led_display.c +++ b/right/src/led_display.c @@ -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) { LedDriverValues[LedDriverId_Left][8 + icon] = isEnabled ? IconsAndLayerTextsBrightness : 0; diff --git a/right/src/led_display.h b/right/src/led_display.h index 8e76c23..2d98423 100644 --- a/right/src/led_display.h +++ b/right/src/led_display.h @@ -26,4 +26,6 @@ void LedDisplay_SetLayer(uint8_t layerId); void LedDisplay_SetIcon(led_display_icon_t icon, bool isEnabled); + bool LedDisplay_GetIcon(led_display_icon_t icon); + #endif diff --git a/right/src/usb_composite_device.c b/right/src/usb_composite_device.c index a98b05c..048233d 100644 --- a/right/src/usb_composite_device.c +++ b/right/src/usb_composite_device.c @@ -1,3 +1,6 @@ +#include "config.h" +#include "led_display.h" +#include "slave_drivers/is31fl3731_driver.h" #include "usb_device_config.h" #include "usb_composite_device.h" #include "usb_descriptors/usb_descriptor_hid.h" @@ -162,11 +165,15 @@ static usb_device_class_config_list_struct_t UsbDeviceCompositeConfigList = { static usb_status_t usbDeviceCallback(usb_device_handle handle, uint32_t event, void *param) { +#ifdef LED_DRIVERS_ENABLED + static uint8_t oldKeyBacklightBrightness = 0xFF; + static bool capsLockOn = false, agentOn = false, adaptiveOn = false; +#endif usb_status_t status = kStatus_USB_Error; uint16_t *temp16 = (uint16_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; } @@ -175,6 +182,42 @@ static usb_status_t usbDeviceCallback(usb_device_handle handle, uint32_t event, UsbCompositeDevice.attach = 0; status = kStatus_USB_Success; break; + case kUSB_DeviceEventSuspend: + if (UsbCompositeDevice.attach) { +#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); + + // Clear the text + LedDisplay_SetText(0, NULL); +#endif + status = kStatus_USB_Success; + } + break; + case kUSB_DeviceEventResume: + if (UsbCompositeDevice.attach) { +#ifdef LED_DRIVERS_ENABLED + // Restore keyboard backlight and text + KeyBacklightBrightness = oldKeyBacklightBrightness; + LedSlaveDriver_Init(LedDriverId_Right); + LedSlaveDriver_Init(LedDriverId_Left); + + // Restore icon states + LedDisplay_SetIcon(LedDisplayIcon_CapsLock, capsLockOn); + LedDisplay_SetIcon(LedDisplayIcon_Agent, agentOn); + LedDisplay_SetIcon(LedDisplayIcon_Adaptive, adaptiveOn); +#endif + status = kStatus_USB_Success; + } + break; case kUSB_DeviceEventSetConfiguration: UsbCompositeDevice.attach = 1; UsbCompositeDevice.currentConfiguration = *temp8; diff --git a/right/src/usb_device_config.h b/right/src/usb_device_config.h index 1aa0013..e418b48 100644 --- a/right/src/usb_device_config.h +++ b/right/src/usb_device_config.h @@ -23,10 +23,10 @@ ) // 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 -#define USB_DEVICE_CONFIG_REMOTE_WAKEUP 0 +#define USB_DEVICE_CONFIG_REMOTE_WAKEUP 1 // The number of control endpoints, which is always 1 #define USB_CONTROL_ENDPOINT_COUNT 1