I may be the first person to do this but probably won’t be the last. Do I need to take the keyboard apart to reset the arduino or is there a less intrusive way?
The PROG
key is hardwired to reset the MCU into programmable mode. No matter what code you put on it, if it is held while flashing, it should work. If it does not, you can try holding the key and then re-plugging the keyboard. In other words, even if you put, say, Key_A
on PROG
, even if it does work as the A
key during normal use, if you reset the serial port (which is done prior to flashing, to signal the board to enter programmable mode) and hold the key, it will still work as PROG
. So you are free to remap it to anything, and it should still work.
If that still fails, if you take the enclosure off, there’s a small reset button somewhere. (On my prototype, its on the left side, beside the extension headers, but it may have moved somewhere else on the final hardware.)
I had used it for the dynamic macro record key which seemed to confuse things. Mashing the key a couple of times while flashing worked, thanks.
Can you explain your failure? I was intending to make this exact mapping in my next round of refinements, and if there’s an issue with it, I would like to understand.
This is a failsafe feature intended for situations like this - if you hold prog while plugging the keyboard, it doesn’t even attempt to boot the current firmware but stays in bootloader mode so you should be able to flash. Theoretically I think the idea is that this should eliminate the need for anyone to disassemble their keyboard to reset the Arduino - but of course that’s still an option. In the production units, the hardware reset button is accessible if you open the left-hand enclosure.
While there are potential security implications (related to malicious reprogramming) to using the Prog
key as part of your layout, all of the bootloader-related functionality tied to the Prog
key are in the Bootloader code, rather than the user program, so it should be impossible to brick your keyboard by assigning the Prog
key to something.
…sorta. What’s going on behind the scenes is this:
The “regular arduino” way to reset a device like the Model 01 into ‘bootloader’ (reprogramming) mode is for the computer to open up the keyboard’s virtual serial port (COM port on windows) at 1200 baud and immediately close it. This causes the keyboard to reboot.
When the keyboard reboots, it first jumps into the bootloader.
We’ve wired up a couple of pins on the main microcontroller (The ATMega32u4) to be able to detect keypresses on the Prog
key.
It would be possible for malicious firmware on the keyscanner chips to fake out the main microcontroller, so the first thing the bootloader does is to turn off the keyscanner chips, That way, they can’t fake it out when it checks to see if you actually want to reprogram the keyboard.
Then, the main microcontroller looks to see if Prog
is held down. If it is, the bootloader knows that you want to reprogram the keyboard. Then it lights up the red led under the Prog
key and waits for further instructions.
Next time I flash the keyboard I’ll record the exact sequence of events.
I’ve tried this again, here’s the sequence:
- make flash
- wait for prompt
- hold down prog and hit enter, seems to start recording for slot “enter”
- press enter again still holding prog, records the keystroke
- press enter a third time, flashing occurs
- tap the prog key again to stop recording
If you do this, does it erase your custom programming, or will unplugging and reconnecting the keyboard (without holding PROG
) load your custom firmware again?
Nope. Just tried it, and replugging the keyboard boots your custom firmware just like normal.
Indeed. Holding in the prog key just governs whether the keyboard jumps into the bootloader and won’t, itself, do anything to your code.