Sequence to reboot keyboard


(Shriramana Sharma) #1

Hello. I’m wondering if there exists or can be made a key sequence (like Ctrl+Alt+Del for computer in olden days) to reboot the keyboard without physically plugging out and in the cable (causing wear and tear) or rebooting the computer (too much)?

Use cases I can think of: recent problem with one shot conflicting with key repeat.


(John T. Johnson) #2

You can create a reset function, then call it in your code.
I haven’t called a custom function based on a keystroke, so I can’t help you there. There is probably code in the basic firmware that would help you.

void(* resetFunc) (void) = 0;//declare reset function at address 0
...
resetFunc(); //call reset 

ref


(Gergely Nagy) #3

There is no ready-made Kaleidoscope.resetKeyboard() or anything like that, mostly because this is such a corner case, something you normally wouldn’t need. Nevertheless, it is fairly easy to reboot the keyboard: there’s a built-in watchdog, that will reset the keyboard if it gets stuck. It is disabled by default, but if we enable it, and enter an infinite loop, that just so happens to trigger it, and gets the device rebooted.

For this, you only need two lines (ok, three with the #include):

#include <avr/wdt.h>

wdt_enable(WDTO_120MS);
while (1) {}

You can put this in a macro, or a magic combo, or something like that, and voila.


#4

I was not able to get the watchdog timer method to work. I think I found the answer here. That worked for me, and I think it is exactly what you want to do. Here’s the code:

void softReset(){
Serial1.println(“resetting”);
USBCON&= ~(1<<USBE);
delay(5);
asm volatile(" jmp 0");
}

I assume you won’t need the Serial1.println() statement so you can edit that out. My understanding is that for this low-level code: The USBCON flags the usb as “not connected” and the jump 0 resets in a “usb just reconnected” state.