From c15355793392e1dea6aade9187dbaa0b1fa840ec Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sun, 22 Jan 2017 10:31:37 -0500 Subject: [PATCH 1/3] Added watchdog timer. Unless scan_matrix is run at least every 250ms the WDT will reset the device. --- keyboards/lfk78/keymaps/default/Makefile | 9 +++++++-- keyboards/lfk78/lfk78.c | 10 ++++++++++ keyboards/lfk78/lighting.c | 7 +++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/keyboards/lfk78/keymaps/default/Makefile b/keyboards/lfk78/keymaps/default/Makefile index cd0f49ad4e79..99ca7d38d259 100644 --- a/keyboards/lfk78/keymaps/default/Makefile +++ b/keyboards/lfk78/keymaps/default/Makefile @@ -16,10 +16,11 @@ UNICODE_ENABLE = no # Unicode BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend +TAP_DANCE_ENABLE = no -ISSI_ENABLE = yes +ISSI_ENABLE = yes # If the I2C pullup resistors aren't install this must be disabled +WATCHDOG_ENABLE = yes # Resets keyboard if matrix_scan isn't run every 250ms -TAP_DANCE_ENABLE = no ifndef QUANTUM_DIR include ../../../../Makefile @@ -29,6 +30,10 @@ ifeq ($(strip $(ISSI_ENABLE)), yes) TMK_COMMON_DEFS += -DISSI_ENABLE endif +ifeq ($(strip $(WATCHDOG_ENABLE)), yes) + TMK_COMMON_DEFS += -WATCHDOG_ENABLE +endif + # # Set the LFK78 hardware version. This is defined in rules.mk, but can be overidden here if desired # # diff --git a/keyboards/lfk78/lfk78.c b/keyboards/lfk78/lfk78.c index 98798175f18e..75928f3ee229 100644 --- a/keyboards/lfk78/lfk78.c +++ b/keyboards/lfk78/lfk78.c @@ -1,5 +1,6 @@ #include #include +#include #include "lfk78.h" #include "issi.h" #include "TWIlib.h" @@ -37,6 +38,12 @@ void matrix_init_kb(void) // Set as output DDRB |= 0b11100000; +#ifdef WATCHDOG_ENABLE + // This is done after turning the layer LED red, if we're caught in a loop + // we should get a red (flashing?) light + wdt_enable(WDTO_250MS); +#endif + #ifdef AUDIO_ENABLE audio_init(); #else @@ -52,6 +59,9 @@ void matrix_init_kb(void) void matrix_scan_kb(void) { +#ifdef WATCHDOG_ENABLE + wdt_reset(); +#endif #ifdef ISSI_ENABLE // switch/underglow lighting update static uint32_t issi_device = 0; diff --git a/keyboards/lfk78/lighting.c b/keyboards/lfk78/lighting.c index 9244e86053a7..4eb88f2d972e 100644 --- a/keyboards/lfk78/lighting.c +++ b/keyboards/lfk78/lighting.c @@ -184,6 +184,10 @@ void force_issi_refresh(){ } void led_test(){ +#ifdef WATCHDOG_ENABLE + // This test take a long time to run, disable the WTD until its complete + wdt_disable(); +#endif backlight_set(0); set_underglow(0, 0, 0); force_issi_refresh(); @@ -201,6 +205,9 @@ void led_test(){ set_rgb(rgb_sequence[x], 0, 0, 0); force_issi_refresh(); } +#ifdef WATCHDOG_ENABLE + wdt_enable(WDTO_250MS); +#endif } void backlight_init_ports(void){ From 24b82c4b17ad0ad50b6842c836d37578d19d10f5 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sun, 22 Jan 2017 10:39:27 -0500 Subject: [PATCH 2/3] Fix compile flag and includes --- keyboards/lfk78/keymaps/default/Makefile | 2 +- keyboards/lfk78/lighting.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/keyboards/lfk78/keymaps/default/Makefile b/keyboards/lfk78/keymaps/default/Makefile index 99ca7d38d259..6b547d0cb457 100644 --- a/keyboards/lfk78/keymaps/default/Makefile +++ b/keyboards/lfk78/keymaps/default/Makefile @@ -31,7 +31,7 @@ ifeq ($(strip $(ISSI_ENABLE)), yes) endif ifeq ($(strip $(WATCHDOG_ENABLE)), yes) - TMK_COMMON_DEFS += -WATCHDOG_ENABLE + TMK_COMMON_DEFS += -DWATCHDOG_ENABLE endif diff --git a/keyboards/lfk78/lighting.c b/keyboards/lfk78/lighting.c index 4eb88f2d972e..9dfbaf245f2e 100644 --- a/keyboards/lfk78/lighting.c +++ b/keyboards/lfk78/lighting.c @@ -1,13 +1,17 @@ #ifdef ISSI_ENABLE + +#include +#include +#include #include "lfk78.h" #include "issi.h" -#include -#include "audio/audio.h" #include "TWIlib.h" -#include "avr/timer_avr.h" #include "lighting.h" +#include "debug.h" #include "rgblight.h" +#include "audio/audio.h" + extern rgblight_config_t rgblight_config; // Declared in rgblight.c From 45b839704471a0dc51c030aa445c88befad2feea Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sat, 28 Jan 2017 15:18:47 -0500 Subject: [PATCH 3/3] Fixed bootloader size in rules.mk --- keyboards/lfk78/keymaps/default/Makefile | 6 +++--- keyboards/lfk78/lfk78.c | 22 ++++++++++++++-------- keyboards/lfk78/lighting.c | 20 +++++++++++++------- keyboards/lfk78/rules.mk | 4 +++- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/keyboards/lfk78/keymaps/default/Makefile b/keyboards/lfk78/keymaps/default/Makefile index 6b547d0cb457..b999a9afbc58 100644 --- a/keyboards/lfk78/keymaps/default/Makefile +++ b/keyboards/lfk78/keymaps/default/Makefile @@ -6,15 +6,15 @@ BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) MOUSEKEY_ENABLE = no # Mouse keys(+4700) EXTRAKEY_ENABLE = yes # Audio control and System control(+450) -CONSOLE_ENABLE = yes # Console for debug(+400) -COMMAND_ENABLE = yes # Commands for debug and configuration +CONSOLE_ENABLE = no # Console for debug(+400) +COMMAND_ENABLE = no # Commands for debug and configuration NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality MIDI_ENABLE = no # MIDI controls AUDIO_ENABLE = no # Audio output on port C6 UNICODE_ENABLE = no # Unicode BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID -RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. +RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend TAP_DANCE_ENABLE = no diff --git a/keyboards/lfk78/lfk78.c b/keyboards/lfk78/lfk78.c index 75928f3ee229..06bde356b7d7 100644 --- a/keyboards/lfk78/lfk78.c +++ b/keyboards/lfk78/lfk78.c @@ -38,12 +38,6 @@ void matrix_init_kb(void) // Set as output DDRB |= 0b11100000; -#ifdef WATCHDOG_ENABLE - // This is done after turning the layer LED red, if we're caught in a loop - // we should get a red (flashing?) light - wdt_enable(WDTO_250MS); -#endif - #ifdef AUDIO_ENABLE audio_init(); #else @@ -55,10 +49,17 @@ void matrix_init_kb(void) #ifdef ISSI_ENABLE issi_init(); #endif +#ifdef WATCHDOG_ENABLE + // This is done after turning the layer LED red, if we're caught in a loop + // we should get a flashing red light + wdt_enable(WDTO_500MS); +#endif + } void matrix_scan_kb(void) { + debug_enable = true; #ifdef WATCHDOG_ENABLE wdt_reset(); #endif @@ -76,7 +77,7 @@ void matrix_scan_kb(void) if(isTWIReady()){ twi_last_ready = 0; // If the i2c bus is available, kick off the issi update, alternate between devices - update_issi(issi_device, 0); + update_issi(issi_device, issi_device); if(issi_device){ issi_device = 0; }else{ @@ -124,7 +125,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { // Test code that turns on the switch led for the key that is pressed // dprintf("event: %d %d\n", record->event.key.col, record->event.key.row); - set_backlight_by_keymap(record->event.key.col, record->event.key.row); + // set_backlight_by_keymap(record->event.key.col, record->event.key.row); if (click_toggle && record->event.pressed){ click(click_hz, click_time); } @@ -202,6 +203,11 @@ void action_function(keyrecord_t *event, uint8_t id, uint8_t opt) } void reset_keyboard_kb(){ +#ifdef WATCHDOG_ENABLE + MCUSR = 0; + wdt_disable(); + wdt_reset(); +#endif dprintf("programming!\n"); OCR1A = 0x0000; // B5 - Red OCR1B = 0x0FFF; // B6 - Green diff --git a/keyboards/lfk78/lighting.c b/keyboards/lfk78/lighting.c index 9dfbaf245f2e..f26333f26388 100644 --- a/keyboards/lfk78/lighting.c +++ b/keyboards/lfk78/lighting.c @@ -100,9 +100,7 @@ const uint8_t rgb_leds[][3][2] = { #endif void set_rgb(uint8_t rgb_led, uint8_t red, uint8_t green, uint8_t blue){ - if(rgb_led == 24){ - return; - } +#ifdef RGBLIGHT_ENABLE uint8_t matrix = rgb_matrices[0]; if(rgb_led >= 17){ matrix = rgb_matrices[1]; @@ -117,14 +115,15 @@ void set_rgb(uint8_t rgb_led, uint8_t red, uint8_t green, uint8_t blue){ if(rgb_leds[rgb_led][2][1] != 0){ activateLED(matrix, rgb_leds[rgb_led][2][0], rgb_leds[rgb_led][2][1], blue); } +#endif } void backlight_set(uint8_t level){ - if(!(issi_devices[0] && issi_devices[3])){ - // if either of the issi devices failed to init, try again - issi_init(); - } +#ifdef BACKLIGHT_ENABLE uint8_t pwm_value = 0; + if(level >= BACKLIGHT_LEVELS){ + level = BACKLIGHT_LEVELS; + } if(level > 0){ pwm_value = backlight_pwm_map[level-1]; } @@ -136,16 +135,20 @@ void backlight_set(uint8_t level){ activateLED(switch_matrices[1], x, y, pwm_value); } } +#endif } void set_underglow(uint8_t red, uint8_t green, uint8_t blue){ +#ifdef RGBLIGHT_ENABLE for(uint8_t x = 1; x <= 32; x++){ set_rgb(x, red, green, blue); } +#endif } void rgblight_set(void) { +#ifdef RGBLIGHT_ENABLE for(uint8_t i = 0; (i < sizeof(rgb_sequence)) && (i < RGBLED_NUM); i++){ if(rgblight_config.enable){ set_rgb(rgb_sequence[i], led[i].r, led[i].g, led[i].b); @@ -153,9 +156,11 @@ void rgblight_set(void) { set_rgb(rgb_sequence[i], 0, 0, 0); } } +#endif } void set_backlight_by_keymap(uint8_t col, uint8_t row){ +#ifdef RGBLIGHT_ENABLE dprintf("event: %d %d\n", col, row); uint8_t lookup_value = switch_leds[row][col]; uint8_t matrix = switch_matrices[0]; @@ -178,6 +183,7 @@ void set_backlight_by_keymap(uint8_t col, uint8_t row){ #endif dprintf("LED: %02X, %d %d %d\n", lookup_value, matrix, led_col, led_row); activateLED(matrix, led_col, led_row, 255); +#endif } void force_issi_refresh(){ diff --git a/keyboards/lfk78/rules.mk b/keyboards/lfk78/rules.mk index 280c88d25acc..faf620bd3626 100644 --- a/keyboards/lfk78/rules.mk +++ b/keyboards/lfk78/rules.mk @@ -10,8 +10,10 @@ LFK_REV = D ifeq ($(LFK_REV), B) MCU = atmega32u4 + OPT_DEFS += -DBOOTLOADER_SIZE=4096 else MCU = at90usb1286 + OPT_DEFS += -DBOOTLOADER_SIZE=8192 endif OPT_DEFS += -DLFK_REV_$(LFK_REV) OPT_DEFS += -DUSB_PRODUCT=\"LFK_Rev$(LFK_REV)\" @@ -60,7 +62,7 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # Atmel DFU loader 4096 # LUFA bootloader 4096 # USBaspLoader 2048 -OPT_DEFS += -DBOOTLOADER_SIZE=4096 +# OPT_DEFS += -DBOOTLOADER_SIZE=4096 ifndef QUANTUM_DIR include ../../Makefile