Turn LEDs, backlight and display off when sleeping

Fixes #83
This commit is contained in:
Kristian Sloth Lauszus
2018-03-11 05:26:51 +01:00
parent 1742437f8b
commit 5de0e5ac60
4 changed files with 53 additions and 3 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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