diff --git a/common/bootmagic.c b/common/bootmagic.c index 036d4904..311a02f2 100644 --- a/common/bootmagic.c +++ b/common/bootmagic.c @@ -30,6 +30,7 @@ void bootmagic(void) /* eeconfig clear */ if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) { + eeconfig_disable(); eeconfig_init(); } diff --git a/common/eeconfig.c b/common/eeconfig.c index 5bd47dc6..5aadf1c5 100644 --- a/common/eeconfig.c +++ b/common/eeconfig.c @@ -2,6 +2,7 @@ #include #include #include "eeconfig.h" +#include "keymap_ex.h" void eeconfig_init(void) { @@ -13,6 +14,9 @@ void eeconfig_init(void) #ifdef BACKLIGHT_ENABLE eeprom_write_byte(EECONFIG_BACKLIGHT, 0); #endif +#ifdef KEYMAP_EX_ENABLE + keymap_ex_init(); +#endif } void eeconfig_enable(void) @@ -22,6 +26,9 @@ void eeconfig_enable(void) void eeconfig_disable(void) { +#ifdef KEYMAP_EX_ENABLE + keymap_ex_disable(); +#endif eeprom_write_word(EECONFIG_MAGIC, 0xFFFF); } diff --git a/common/keyboard.c b/common/keyboard.c index c5de65ef..933eb780 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -68,7 +68,9 @@ void keyboard_init(void) #endif #ifdef PS2_MOUSE_ENABLE - ps2_mouse_init(); + if (ps2_enabled()) { + ps2_mouse_init(); + } #endif #ifdef BOOTMAGIC_ENABLE @@ -80,7 +82,7 @@ void keyboard_init(void) #endif #ifdef KEYMAP_EX_ENABLE - keymap_init(); + keymap_ex_init(); #endif } @@ -133,7 +135,9 @@ MATRIX_LOOP_END: #endif #ifdef PS2_MOUSE_ENABLE - ps2_mouse_task(); + if (ps2_enabled()) { + ps2_mouse_task(); + } #endif // update LED diff --git a/common/keymap_ex.c b/common/keymap_ex.c index 0c01f707..99859c06 100644 --- a/common/keymap_ex.c +++ b/common/keymap_ex.c @@ -23,12 +23,16 @@ along with this program. If not, see . #ifdef KEYMAP_EX_ENABLE -void keymap_init(void) { +void keymap_ex_init(void) { if (!check_keymap_in_eeprom()) { write_keymap_to_eeprom(); } } +void keymap_ex_disable(void) { + eeprom_write_word((void*)EECONFIG_KEYMAP_CHECKSUM, eeprom_read_word((void*)EECONFIG_KEYMAP_CHECKSUM) + 1); +} + bool check_keymap_in_eeprom(void) { uint16_t checksum_in_eeprom = eeprom_read_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum); uint16_t checksum = EECONFIG_MAGIC_NUMBER; diff --git a/common/keymap_ex.h b/common/keymap_ex.h index e64bace6..ee6ff8c6 100644 --- a/common/keymap_ex.h +++ b/common/keymap_ex.h @@ -47,7 +47,8 @@ typedef struct { #define FN_ACTION_OFFSET(index) (sizeof(uint16_t) * index) #define KEY_OFFSET(layer, row, col) (sizeof(uint8_t) * (layer * MATRIX_ROWS * MATRIX_COLS + row * MATRIX_COLS + col)) -void keymap_init(void); +void keymap_ex_init(void); +void keymap_ex_disable(void); bool check_keymap_in_eeprom(void); void write_keymap_to_eeprom(void); uint8_t eeconfig_read_keymap_key(uint8_t layer, uint8_t row, uint8_t col); diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index f535bd73..d8374676 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -134,12 +134,12 @@ COMMAND_ENABLE = yes # Commands for debug and configuration #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +#PS2_USE_BUSYWAIT = yes BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_EX_ENABLE = yes # External keymap in eeprom KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor LED_MATRIX_ENABLE = yes - # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax @@ -148,5 +148,6 @@ VPATH += $(TARGET_DIR) VPATH += $(TOP_DIR) include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/protocol.mk include $(TOP_DIR)/common.mk include $(TOP_DIR)/rules.mk diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index 25fbc833..91b38c11 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -72,14 +72,43 @@ void backlight_set(uint8_t level) } } #else +static const uint8_t backlight_table[] PROGMEM = { + 0, 16, 128, 255 +}; + void backlight_set(uint8_t level) { if (level > 0) { - DDRF |= (1<. #define DEBOUNCE 5 /* number of backlight levels */ -#if defined(GH60_REV_CHN) -# define BACKLIGHT_LEVELS 3 -#elif defined(GH60_REV_CNY) -# define BACKLIGHT_LEVELS 3 -#else -# define BACKLIGHT_LEVELS 1 -#endif +#define BACKLIGHT_LEVELS 3 #ifdef GH60_REV_CNY # define LED_MATRIX_ROWS 6 @@ -66,7 +60,18 @@ along with this program. If not, see . keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ ) +/* PS2 mouse support */ +#ifdef PS2_MOUSE_ENABLE +#define PS2_CLOCK_PORT PORTF +#define PS2_CLOCK_PIN PINF +#define PS2_CLOCK_DDR DDRF +#define PS2_CLOCK_BIT PF7 +#define PS2_DATA_PORT PORTF +#define PS2_DATA_PIN PINF +#define PS2_DATA_DDR DDRF +#define PS2_DATA_BIT PF6 +#endif /* * Feature disable options diff --git a/keyboard/gh60/led_matrix.c b/keyboard/gh60/led_matrix.c index 2d3e544f..33eaf95f 100644 --- a/keyboard/gh60/led_matrix.c +++ b/keyboard/gh60/led_matrix.c @@ -18,6 +18,7 @@ along with this program. If not, see . #include #include "led_matrix.h" +#ifdef LED_MATRIX_ENABLE #if defined(GH60_REV_CNY) /* LED Column pin configuration @@ -94,3 +95,4 @@ void led_matrix_select_row(uint8_t row) } #endif +#endif diff --git a/keyboard/gh60/matrix.c b/keyboard/gh60/matrix.c index bb61f6ed..94cab02b 100644 --- a/keyboard/gh60/matrix.c +++ b/keyboard/gh60/matrix.c @@ -26,6 +26,9 @@ along with this program. If not, see . #include "debug.h" #include "util.h" #include "matrix.h" +#ifdef PS2_MOUSE_ENABLE +#include "ps2.h" +#endif #ifndef DEBOUNCE @@ -42,6 +45,14 @@ static void init_cols(void); static void unselect_rows(void); static void select_row(uint8_t row); +#ifdef PS2_MOUSE_ENABLE +static uint8_t ps2_mouse_detected; + +uint8_t ps2_enabled(void) +{ + return ps2_mouse_detected; +} +#endif inline uint8_t matrix_rows(void) @@ -61,6 +72,19 @@ void matrix_init(void) MCUCR = (1< +Copyright 2013,2014 Kai Ryu This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,30 +17,66 @@ along with this program. If not, see . #include #include +#include #include "backlight.h" +static const uint8_t backlight_table[] PROGMEM = { + 0, 16, 128, 255 +}; + +uint8_t softpwm_ocr = 0; + /* Backlight pin configuration - * PF7 PF6 PF5 + * PWM: PB5 (RevRS) + * GPIO: PF7 PF6 PF5 */ void backlight_set(uint8_t level) { - switch (level) { - case 0: - DDRF &= ~(1< 0) { + // Turn on PWM + cli(); + // Hard PWM + DDRB |= (1<. #define LOCKING_RESYNC_ENABLE /* key combination for command */ +#ifndef __ASSEMBLER__ +#include "matrix.h" #define IS_COMMAND() ( \ - keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ + matrix_is_on(0, 0) && matrix_is_on(0, MATRIX_COLS - 1) \ ) +#endif - +/* boot magic key */ +#define BOOTMAGIC_KEY_SALT KC_FN0 /* * Feature disable options diff --git a/keyboard/ghpad/keymap_4x6_backlight.c b/keyboard/ghpad/keymap_4x6_backlight.c new file mode 100644 index 00000000..e2359034 --- /dev/null +++ b/keyboard/ghpad/keymap_4x6_backlight.c @@ -0,0 +1,54 @@ +#include "keymap_common.h" + +// 4x6 Keypad +#ifdef KEYMAP_SECTION_ENABLE +const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { +#else +const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { +#endif + /* Keymap 0: Default Layer + * ,---------------. + * |Esc|Fn0|Fn1|Fn2| + * |---+---+---+---| + * |Num|/ |* |- | + * |---+---+---+---| + * |7 |8 |9 |+ | + * |---+---+---| | + * |4 |5 |6 | | + * |---+---+---+---| + * |1 |2 |3 |Ent| + * |---+---+---| | + * |0 |. | | + * `---------------' + */ + [0] = KEYMAP( + ESC, FN0, FN1, FN2, \ + NLCK,PSLS,PAST,PMNS, \ + P7, P8, P9, PPLS, \ + P4, P5, P6, PENT, \ + P1, P2, P3, PENT, \ + P0, NO, PDOT,NO) +}; + +/* + * Fn action definition + */ +#ifdef KEYMAP_SECTION_ENABLE +const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn_actions"))) = { +#else +const uint16_t fn_actions[] PROGMEM = { +#endif + [0] = ACTION_BACKLIGHT_TOGGLE(), + [1] = ACTION_BACKLIGHT_DECREASE(), + [2] = ACTION_BACKLIGHT_INCREASE() +}; + +#ifdef KEYMAP_EX_ENABLE +uint16_t keys_count(void) { + return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; +} + +uint16_t fn_actions_count(void) { + return sizeof(fn_actions) / sizeof(fn_actions[0]); +} +#endif diff --git a/keyboard/ghpad/led.c b/keyboard/ghpad/led.c index eac65559..04104fb7 100644 --- a/keyboard/ghpad/led.c +++ b/keyboard/ghpad/led.c @@ -24,11 +24,11 @@ void led_set(uint8_t usb_led) { if (usb_led & (1< +Copyright 2013,2014 Kai Ryu This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/protocol/ps2.h b/protocol/ps2.h index 483eea72..703e0c27 100644 --- a/protocol/ps2.h +++ b/protocol/ps2.h @@ -90,6 +90,7 @@ uint8_t ps2_host_send(uint8_t data); uint8_t ps2_host_recv_response(void); uint8_t ps2_host_recv(void); void ps2_host_set_led(uint8_t usb_led); +uint8_t ps2_enabled(void); /* Check port settings for clock and data line */