From 39763abbb50107d77fa970603ad587bdf99e3b52 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 18 May 2018 17:38:14 +0200 Subject: [PATCH] Implement ErgoDox.resetDevice() Can be used to reset the device, and put it into programmable mode, from within the firmware. Signed-off-by: Gergely Nagy --- src/kaleidoscope/hardware/ErgoDox.cpp | 33 +++++++++++++++++++++++++++ src/kaleidoscope/hardware/ErgoDox.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/src/kaleidoscope/hardware/ErgoDox.cpp b/src/kaleidoscope/hardware/ErgoDox.cpp index 63c064aa..6f99f899 100644 --- a/src/kaleidoscope/hardware/ErgoDox.cpp +++ b/src/kaleidoscope/hardware/ErgoDox.cpp @@ -125,6 +125,39 @@ void ErgoDox::setStatusLEDBrightness(uint8_t led, uint8_t brightness) { (OCR1C = brightness); } +void ErgoDox::resetDevice() { + cli(); + UDCON = 1; + USBCON = (1 << FRZCLK); + UCSR1B = 0; + _delay_ms(5); + + EIMSK = 0; + PCICR = 0; + SPCR = 0; + ACSR = 0; + EECR = 0; + ADCSRA = 0; + TIMSK0 = 0; + TIMSK1 = 0; + TIMSK3 = 0; + TIMSK4 = 0; + UCSR1B = 0; + TWCR = 0; + DDRB = 0; + DDRC = 0; + DDRD = 0; + DDRE = 0; + DDRF = 0; + TWCR = 0; + PORTB = 0; + PORTC = 0; + PORTD = 0; + PORTE = 0; + PORTF = 0; + asm volatile("jmp 0x7E00"); +} + } } diff --git a/src/kaleidoscope/hardware/ErgoDox.h b/src/kaleidoscope/hardware/ErgoDox.h index 553205f1..6b7500ed 100644 --- a/src/kaleidoscope/hardware/ErgoDox.h +++ b/src/kaleidoscope/hardware/ErgoDox.h @@ -73,6 +73,8 @@ class ErgoDox { void setStatusLED(uint8_t led, bool state = true); void setStatusLEDBrightness(uint8_t led, uint8_t brightness); + void resetDevice(); + private: static ErgoDoxScanner scanner_; static uint8_t previousKeyState_[ROWS];