void hook_usb_suspend_entry(void) { //dprintf("huse\n"); // Turn LED off to save power // Set 0 with putting aside status before suspend and restore // it after wakeup, then LED is updated at keyboard_task() in main loop _led_stats = keyboard_led_stats; keyboard_led_stats = 0; led_set(keyboard_led_stats); matrix_clear(); clear_keyboard(); send_sleep_to_other_side(true); mcpu_hardware_shutdown(true); #ifdef BACKLIGHT_ENABLE suspend_animation(); backlight_enableShutdown(true); #endif #ifdef SLEEP_LED_ENABLE sleep_led_enable(); #endif }
/* Handles the USB driver global events * TODO: maybe disable some things when connection is lost? */ static void usb_event_cb(USBDriver *usbp, usbevent_t event) { switch(event) { case USB_EVENT_ADDRESS: return; case USB_EVENT_CONFIGURED: osalSysLockFromISR(); /* Enable the endpoints specified into the configuration. */ usbInitEndpointI(usbp, KEYBOARD_IN_EPNUM, &kbd_ep_config); #ifdef MOUSE_ENABLE usbInitEndpointI(usbp, MOUSE_IN_EPNUM, &mouse_ep_config); #endif /* MOUSE_ENABLE */ #ifdef EXTRAKEY_ENABLE usbInitEndpointI(usbp, EXTRAKEY_IN_EPNUM, &extra_ep_config); #endif /* EXTRAKEY_ENABLE */ #ifdef NKRO_ENABLE usbInitEndpointI(usbp, NKRO_IN_EPNUM, &nkro_ep_config); #endif /* NKRO_ENABLE */ for (int i=0;i<NUM_USB_DRIVERS;i++) { usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].in_ep_config); usbInitEndpointI(usbp, drivers.array[i].config.bulk_out, &drivers.array[i].out_ep_config); if (drivers.array[i].config.int_in) { usbInitEndpointI(usbp, drivers.array[i].config.int_in, &drivers.array[i].int_ep_config); } qmkusbConfigureHookI(&drivers.array[i].driver); } osalSysUnlockFromISR(); return; case USB_EVENT_SUSPEND: #ifdef SLEEP_LED_ENABLE sleep_led_enable(); #endif /* SLEEP_LED_ENABLE */ /* Falls into.*/ case USB_EVENT_UNCONFIGURED: /* Falls into.*/ case USB_EVENT_RESET: for (int i=0;i<NUM_USB_DRIVERS;i++) { chSysLockFromISR(); /* Disconnection event on suspend.*/ qmkusbSuspendHookI(&drivers.array[i].driver); chSysUnlockFromISR(); } return; case USB_EVENT_WAKEUP: //TODO: from ISR! print("[W]"); for (int i=0;i<NUM_USB_DRIVERS;i++) { chSysLockFromISR(); /* Disconnection event on suspend.*/ qmkusbWakeupHookI(&drivers.array[i].driver); chSysUnlockFromISR(); } suspend_wakeup_init(); #ifdef SLEEP_LED_ENABLE sleep_led_disable(); // NOTE: converters may not accept this led_set(host_keyboard_leds()); #endif /* SLEEP_LED_ENABLE */ return; case USB_EVENT_STALLED: return; } }
static bool command_common(uint8_t code) { #ifdef KEYBOARD_LOCK_ENABLE static host_driver_t *host_driver = 0; #endif #ifdef SLEEP_LED_ENABLE static bool sleep_led_test = false; #endif switch (code) { #ifdef SLEEP_LED_ENABLE case KC_Z: // test breathing sleep LED print("Sleep LED test\n"); if (sleep_led_test) { sleep_led_disable(); led_set(host_keyboard_leds()); } else { sleep_led_enable(); } sleep_led_test = !sleep_led_test; break; #endif #ifdef BOOTMAGIC_ENABLE case KC_E: print("eeconfig:\n"); print_eeconfig(); break; #endif #ifdef KEYBOARD_LOCK_ENABLE case KC_CAPSLOCK: if (host_get_driver()) { host_driver = host_get_driver(); clear_keyboard(); host_set_driver(0); print("Locked.\n"); } else { host_set_driver(host_driver); print("Unlocked.\n"); } break; #endif case KC_H: case KC_SLASH: /* ? */ command_common_help(); break; case KC_C: debug_matrix = false; debug_keyboard = false; debug_mouse = false; debug_enable = false; command_console_help(); print("C> "); command_state = CONSOLE; break; case KC_PAUSE: clear_keyboard(); print("\n\nbootloader... "); wait_ms(1000); bootloader_jump(); // not return break; case KC_D: if (debug_enable) { print("\ndebug: off\n"); debug_matrix = false; debug_keyboard = false; debug_mouse = false; debug_enable = false; } else { print("\ndebug: on\n"); debug_enable = true; } break; case KC_X: // debug matrix toggle debug_matrix = !debug_matrix; if (debug_matrix) { print("\nmatrix: on\n"); debug_enable = true; } else { print("\nmatrix: off\n"); } break; case KC_K: // debug keyboard toggle debug_keyboard = !debug_keyboard; if (debug_keyboard) { print("\nkeyboard: on\n"); debug_enable = true; } else { print("\nkeyboard: off\n"); } break; case KC_M: // debug mouse toggle debug_mouse = !debug_mouse; if (debug_mouse) { print("\nmouse: on\n"); debug_enable = true; } else { print("\nmouse: off\n"); } break; case KC_V: // print version & information print("\n\t- Version -\n"); print("DESC: " STR(DESCRIPTION) "\n"); print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " "VER: " STR(DEVICE_VER) "\n"); print("BUILD: " STR(VERSION) " (" __TIME__ " " __DATE__ ")\n"); /* build options */ print("OPTIONS:" #ifdef PROTOCOL_PJRC " PJRC" #endif #ifdef PROTOCOL_LUFA " LUFA" #endif #ifdef PROTOCOL_VUSB " VUSB" #endif #ifdef PROTOCOL_CHIBIOS " CHIBIOS" #endif #ifdef BOOTMAGIC_ENABLE " BOOTMAGIC" #endif #ifdef MOUSEKEY_ENABLE " MOUSEKEY" #endif #ifdef EXTRAKEY_ENABLE " EXTRAKEY" #endif #ifdef CONSOLE_ENABLE " CONSOLE" #endif #ifdef COMMAND_ENABLE " COMMAND" #endif #ifdef NKRO_ENABLE " NKRO" #endif #ifdef KEYMAP_SECTION_ENABLE " KEYMAP_SECTION" #endif " " STR(BOOTLOADER_SIZE) "\n"); print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) #if defined(__AVR__) " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ " AVR_ARCH: avr" STR(__AVR_ARCH__) "\n"); #elif defined(__arm__) // TODO ); #endif break; case KC_S: print("\n\t- Status -\n"); print_val_hex8(host_keyboard_leds()); print_val_hex8(keyboard_protocol); print_val_hex8(keyboard_idle); #ifdef NKRO_ENABLE print_val_hex8(keyboard_nkro); #endif print_val_hex32(timer_read32()); #ifdef PROTOCOL_PJRC print_val_hex8(UDCON); print_val_hex8(UDIEN); print_val_hex8(UDINT); print_val_hex8(usb_keyboard_leds); print_val_hex8(usb_keyboard_idle_count); #endif #ifdef PROTOCOL_PJRC # if USB_COUNT_SOF print_val_hex8(usbSofCount); # endif #endif break; #ifdef NKRO_ENABLE case KC_N: clear_keyboard(); //Prevents stuck keys. keyboard_nkro = !keyboard_nkro; if (keyboard_nkro) { print("NKRO: on\n"); } else { print("NKRO: off\n"); } break; #endif case KC_ESC: case KC_GRV: case KC_0: case KC_F10: switch_default_layer(0); break; case KC_1 ... KC_9: switch_default_layer((code - KC_1) + 1); break; case KC_F1 ... KC_F9: switch_default_layer((code - KC_F1) + 1); break; default: print("?"); return false; }