Skip to content

Commit

Permalink
Merge pull request #3 from mechkeys/feature/WDT
Browse files Browse the repository at this point in the history
Feature/wdt
  • Loading branch information
scott-t-wilson authored Jan 28, 2017
2 parents 8c70e0f + 45b8397 commit fb238c3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 18 deletions.
15 changes: 10 additions & 5 deletions keyboards/lfk78/keymaps/default/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
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

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
Expand All @@ -29,6 +30,10 @@ ifeq ($(strip $(ISSI_ENABLE)), yes)
TMK_COMMON_DEFS += -DISSI_ENABLE
endif

ifeq ($(strip $(WATCHDOG_ENABLE)), yes)
TMK_COMMON_DEFS += -DWATCHDOG_ENABLE
endif


# # Set the LFK78 hardware version. This is defined in rules.mk, but can be overidden here if desired
# #
Expand Down
20 changes: 18 additions & 2 deletions keyboards/lfk78/lfk78.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <avr/sfr_defs.h>
#include <avr/timer_avr.h>
#include <avr/wdt.h>
#include "lfk78.h"
#include "issi.h"
#include "TWIlib.h"
Expand Down Expand Up @@ -48,10 +49,20 @@ 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
#ifdef ISSI_ENABLE
// switch/underglow lighting update
static uint32_t issi_device = 0;
Expand All @@ -66,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{
Expand Down Expand Up @@ -114,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);
}
Expand Down Expand Up @@ -192,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
Expand Down
37 changes: 27 additions & 10 deletions keyboards/lfk78/lighting.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#ifdef ISSI_ENABLE


#include <avr/sfr_defs.h>
#include <avr/timer_avr.h>
#include <avr/wdt.h>
#include "lfk78.h"
#include "issi.h"
#include <avr/sfr_defs.h>
#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

Expand Down Expand Up @@ -96,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];
Expand All @@ -113,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];
}
Expand All @@ -132,26 +135,32 @@ 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);
}else{
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];
Expand All @@ -174,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(){
Expand All @@ -184,6 +194,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();
Expand All @@ -201,6 +215,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){
Expand Down
4 changes: 3 additions & 1 deletion keyboards/lfk78/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)\"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb238c3

Please sign in to comment.