diff options
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/common.mk | 5 | ||||
-rw-r--r-- | tmk_core/common/action.c | 2 | ||||
-rw-r--r-- | tmk_core/common/action_layer.c | 4 | ||||
-rw-r--r-- | tmk_core/common/action_layer.h | 2 | ||||
-rw-r--r-- | tmk_core/common/action_util.c | 88 | ||||
-rw-r--r-- | tmk_core/common/action_util.h | 11 | ||||
-rw-r--r-- | tmk_core/common/avr/suspend.c | 76 | ||||
-rwxr-xr-x | tmk_core/common/chibios/eeprom_stm32.c | 29 | ||||
-rwxr-xr-x | tmk_core/common/chibios/eeprom_stm32.h | 6 | ||||
-rwxr-xr-x | tmk_core/common/chibios/flash_stm32.c | 5 | ||||
-rw-r--r-- | tmk_core/common/command.h | 3 | ||||
-rw-r--r-- | tmk_core/common/keyboard.c | 36 | ||||
-rw-r--r-- | tmk_core/common/keyboard.h | 5 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/adc.c | 6 | ||||
-rw-r--r-- | tmk_core/protocol/bluefruit/main.c | 15 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/main.c | 2 | ||||
-rw-r--r-- | tmk_core/protocol/usb_hid/test/config.h | 12 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/main.c | 1 | ||||
-rw-r--r-- | tmk_core/rules.mk | 13 |
19 files changed, 225 insertions, 96 deletions
diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 063115acb1..94f3c2380d 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -41,6 +41,11 @@ ifeq ($(PLATFORM),CHIBIOS) TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c TMK_COMMON_DEFS += -DEEPROM_EMU_STM32F103xB TMK_COMMON_DEFS += -DSTM32_EEPROM_ENABLE + else ifeq ($(MCU_SERIES)_$(MCU_LDSCRIPT), STM32F0xx_STM32F072xB) + TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c + TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c + TMK_COMMON_DEFS += -DEEPROM_EMU_STM32F072xB + TMK_COMMON_DEFS += -DSTM32_EEPROM_ENABLE else TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/eeprom_teensy.c endif diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index ec8d6ed7b9..d4d4ac28da 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -537,7 +537,7 @@ void process_action(keyrecord_t *record, action_t action) action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); break; #endif -#ifdef BACKLIGHT_ENABLE +#if defined(BACKLIGHT_ENABLE) | defined(LED_MATRIX_ENABLE) case ACT_BACKLIGHT: if (!event.pressed) { switch (action.backlight.opt) { diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index 6ff8c5549b..47cad996a3 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -296,7 +296,7 @@ action_t store_or_get_action(bool pressed, keypos_t key) { * * Gets the layer based on key info */ -int8_t layer_switch_get_layer(keypos_t key) { +uint8_t layer_switch_get_layer(keypos_t key) { #ifndef NO_ACTION_LAYER action_t action; action.code = ACTION_TRANSPARENT; @@ -304,7 +304,7 @@ int8_t layer_switch_get_layer(keypos_t key) { uint32_t layers = layer_state | default_layer_state; /* check top layer first */ for (int8_t i = 31; i >= 0; i--) { - if (layers & (1UL<<i)) { + if (layers & (1UL << i)) { action = action_for_key(i, key); if (action.code != ACTION_TRANSPARENT) { return i; diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index f1551d2519..6e2f35d90d 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h @@ -97,7 +97,7 @@ uint8_t read_source_layers_cache(keypos_t key); action_t store_or_get_action(bool pressed, keypos_t key); /* return the topmost non-transparent layer currently associated with key */ -int8_t layer_switch_get_layer(keypos_t key); +uint8_t layer_switch_get_layer(keypos_t key); /* return action depending on current layer status */ action_t layer_switch_get_action(keypos_t key); diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index 58401ace55..365ed6a1dd 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c @@ -48,11 +48,21 @@ extern inline void del_key(uint8_t key); extern inline void clear_keys(void); #ifndef NO_ACTION_ONESHOT -static int8_t oneshot_mods = 0; -static int8_t oneshot_locked_mods = 0; -int8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } -void set_oneshot_locked_mods(int8_t mods) { oneshot_locked_mods = mods; } -void clear_oneshot_locked_mods(void) { oneshot_locked_mods = 0; } +static uint8_t oneshot_mods = 0; +static uint8_t oneshot_locked_mods = 0; +uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } +void set_oneshot_locked_mods(uint8_t mods) { + if (mods != oneshot_locked_mods) { + oneshot_locked_mods = mods; + oneshot_locked_mods_changed_kb(oneshot_locked_mods); + } +} +void clear_oneshot_locked_mods(void) { + if (oneshot_locked_mods) { + oneshot_locked_mods = 0; + oneshot_locked_mods_changed_kb(oneshot_locked_mods); + } +} #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) static uint16_t oneshot_time = 0; bool has_oneshot_mods_timed_out(void) { @@ -97,6 +107,7 @@ void set_oneshot_layer(uint8_t layer, uint8_t state) #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) oneshot_layer_time = timer_read(); #endif + oneshot_layer_changed_kb(get_oneshot_layer()); } /** \brief Reset oneshot layer * @@ -107,6 +118,7 @@ void reset_oneshot_layer(void) { #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) oneshot_layer_time = 0; #endif + oneshot_layer_changed_kb(get_oneshot_layer()); } /** \brief Clear oneshot layer * @@ -118,9 +130,7 @@ void clear_oneshot_layer_state(oneshot_fullfillment_t state) oneshot_layer_data &= ~state; if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) { layer_off(get_oneshot_layer()); -#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) - oneshot_layer_time = 0; -#endif + reset_oneshot_layer(); } } /** \brief Is oneshot layer active @@ -243,23 +253,27 @@ void clear_macro_mods(void) { macro_mods = 0; } * * FIXME: needs doc */ -void set_oneshot_mods(uint8_t mods) -{ - oneshot_mods = mods; +void set_oneshot_mods(uint8_t mods) { + if (oneshot_mods != mods) { #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) oneshot_time = timer_read(); #endif + oneshot_mods = mods; + oneshot_mods_changed_kb(mods); + } } /** \brief clear oneshot mods * * FIXME: needs doc */ -void clear_oneshot_mods(void) -{ +void clear_oneshot_mods(void) { + if (oneshot_mods) { oneshot_mods = 0; #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) oneshot_time = 0; #endif + oneshot_mods_changed_kb(oneshot_mods); + } } /** \brief get oneshot mods * @@ -271,6 +285,54 @@ uint8_t get_oneshot_mods(void) } #endif +/** \brief Called when the one shot modifiers have been changed. + * + * \param mods Contains the active modifiers active after the change. + */ +__attribute__((weak)) +void oneshot_locked_mods_changed_user(uint8_t mods) { } + +/** \brief Called when the locked one shot modifiers have been changed. + * + * \param mods Contains the active modifiers active after the change. + */ +__attribute__((weak)) +void oneshot_locked_mods_changed_kb(uint8_t mods) { + oneshot_locked_mods_changed_user(mods); +} + +/** \brief Called when the one shot modifiers have been changed. + * + * \param mods Contains the active modifiers active after the change. + */ +__attribute__((weak)) +void oneshot_mods_changed_user(uint8_t mods) { } + +/** \brief Called when the one shot modifiers have been changed. + * + * \param mods Contains the active modifiers active after the change. + */ +__attribute__((weak)) +void oneshot_mods_changed_kb(uint8_t mods) { + oneshot_mods_changed_user(mods); +} + +/** \brief Called when the one shot layers have been changed. + * + * \param layer Contains the layer that is toggled on, or zero when toggled off. + */ +__attribute__((weak)) +void oneshot_layer_changed_user(uint8_t layer) { } + +/** \brief Called when the one shot layers have been changed. + * + * \param layer Contains the layer that is toggled on, or zero when toggled off. + */ +__attribute__((weak)) +void oneshot_layer_changed_kb(uint8_t layer) { + oneshot_layer_changed_user(layer); +} + /** \brief inspect keyboard state * * FIXME: needs doc diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h index 3458931514..d03f5682a3 100644 --- a/tmk_core/common/action_util.h +++ b/tmk_core/common/action_util.h @@ -71,8 +71,8 @@ void oneshot_enable(void); void oneshot_disable(void); bool has_oneshot_mods_timed_out(void); -int8_t get_oneshot_locked_mods(void); -void set_oneshot_locked_mods(int8_t mods); +uint8_t get_oneshot_locked_mods(void); +void set_oneshot_locked_mods(uint8_t mods); void clear_oneshot_locked_mods(void); typedef enum { @@ -89,6 +89,13 @@ bool is_oneshot_layer_active(void); uint8_t get_oneshot_layer_state(void); bool has_oneshot_layer_timed_out(void); +void oneshot_locked_mods_changed_user(uint8_t mods); +void oneshot_locked_mods_changed_kb(uint8_t mods); +void oneshot_mods_changed_user(uint8_t mods); +void oneshot_mods_changed_kb(uint8_t mods); +void oneshot_layer_changed_user(uint8_t layer); +void oneshot_layer_changed_kb(uint8_t layer); + /* inspect */ uint8_t has_anymod(void); diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 5bca646854..b29447ac4e 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c @@ -11,6 +11,9 @@ #include "led.h" #include "host.h" #include "rgblight_reconfig.h" +#ifdef SPLIT_KEYBOARD + #include "split_flags.h" +#endif #ifdef PROTOCOL_LUFA #include "lufa.h" @@ -22,6 +25,9 @@ #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) #include "rgblight.h" + extern rgblight_config_t rgblight_config; + static bool rgblight_enabled; + static bool is_suspended; #endif @@ -46,8 +52,7 @@ __asm__ __volatile__ ( \ * * FIXME: needs doc */ -void suspend_idle(uint8_t time) -{ +void suspend_idle(uint8_t time) { cli(); set_sleep_mode(SLEEP_MODE_IDLE); sleep_enable(); @@ -95,32 +100,45 @@ static uint8_t wdt_timeout = 0; * * FIXME: needs doc */ -static void power_down(uint8_t wdto) -{ +static void power_down(uint8_t wdto) { #ifdef PROTOCOL_LUFA - if (USB_DeviceState == DEVICE_STATE_Configured) return; + if (USB_DeviceState == DEVICE_STATE_Configured) return; #endif - wdt_timeout = wdto; + wdt_timeout = wdto; - // Watchdog Interrupt Mode - wdt_intr_enable(wdto); + // Watchdog Interrupt Mode + wdt_intr_enable(wdto); #ifdef BACKLIGHT_ENABLE - backlight_set(0); + backlight_set(0); #endif - // Turn off LED indicators - led_set(0); + // Turn off LED indicators + uint8_t leds_off = 0; +#if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) + if (is_backlight_enabled()) { + // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off + leds_off |= (1<<USB_LED_CAPS_LOCK); + } +#endif + led_set(leds_off); - #ifdef AUDIO_ENABLE - // This sometimes disables the start-up noise, so it's been disabled - // stop_all_notes(); - #endif /* AUDIO_ENABLE */ +#ifdef AUDIO_ENABLE + // This sometimes disables the start-up noise, so it's been disabled + // stop_all_notes(); +#endif /* AUDIO_ENABLE */ #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_disable(); #endif - rgblight_disable_noeeprom(); + if (!is_suspended) { + is_suspended = true; + rgblight_enabled = rgblight_config.enable; + rgblight_disable_noeeprom(); + #ifdef SPLIT_KEYBOARD + RGB_DIRTY = true; + #endif + } #endif suspend_power_down_kb(); @@ -145,8 +163,7 @@ static void power_down(uint8_t wdto) * * FIXME: needs doc */ -void suspend_power_down(void) -{ +void suspend_power_down(void) { suspend_power_down_kb(); #ifndef NO_SUSPEND_POWER_DOWN @@ -156,8 +173,7 @@ void suspend_power_down(void) __attribute__ ((weak)) void matrix_power_up(void) {} __attribute__ ((weak)) void matrix_power_down(void) {} -bool suspend_wakeup_condition(void) -{ +bool suspend_wakeup_condition(void) { matrix_power_up(); matrix_scan(); matrix_power_down(); @@ -186,8 +202,7 @@ void suspend_wakeup_init_kb(void) { * * FIXME: needs doc */ -void suspend_wakeup_init(void) -{ +void suspend_wakeup_init(void) { // clear keyboard state clear_keyboard(); #ifdef BACKLIGHT_ENABLE @@ -195,10 +210,16 @@ void suspend_wakeup_init(void) #endif led_set(host_keyboard_leds()); #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) -#ifdef BOOTLOADER_TEENSY - wait_ms(10); -#endif - rgblight_enable_noeeprom(); + is_suspended = false; + if (rgblight_enabled) { + #ifdef BOOTLOADER_TEENSY + wait_ms(10); + #endif + rgblight_enable_noeeprom(); + #ifdef SPLIT_KEYBOARD + RGB_DIRTY = true; + #endif + } #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_enable(); #endif @@ -208,8 +229,7 @@ void suspend_wakeup_init(void) #ifndef NO_SUSPEND_POWER_DOWN /* watchdog timeout */ -ISR(WDT_vect) -{ +ISR(WDT_vect) { // compensate timer for sleep switch (wdt_timeout) { case WDTO_15MS: diff --git a/tmk_core/common/chibios/eeprom_stm32.c b/tmk_core/common/chibios/eeprom_stm32.c index a15430d676..4b1abc968d 100755 --- a/tmk_core/common/chibios/eeprom_stm32.c +++ b/tmk_core/common/chibios/eeprom_stm32.c @@ -75,17 +75,13 @@ uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) { } // calculate which page is affected (Pagenum1/Pagenum2...PagenumN) - page = (FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address)) & 0x00000FFF; - - if (page % FEE_PAGE_SIZE) page = page + FEE_PAGE_SIZE; - page = (page / FEE_PAGE_SIZE) - 1; + page = FEE_ADDR_OFFSET(Address) / FEE_PAGE_SIZE; // if current data is 0xFF, the byte is empty, just overwrite with the new one if ((*(__IO uint16_t*)(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address))) == FEE_EMPTY_WORD) { FlashStatus = FLASH_ProgramHalfWord(FEE_PAGE_BASE_ADDRESS + FEE_ADDR_OFFSET(Address), (uint16_t)(0x00FF & DataByte)); - } - else { + } else { // Copy Page to a buffer memcpy(DataBuf, (uint8_t*)FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE), FEE_PAGE_SIZE); // !!! Calculate base address for the desired page @@ -96,18 +92,17 @@ uint16_t EEPROM_WriteDataByte (uint16_t Address, uint8_t DataByte) { } // manipulate desired data byte in temp data array if new byte is differ to the current - DataBuf[FEE_ADDR_OFFSET(Address)] = DataByte; + DataBuf[FEE_ADDR_OFFSET(Address) % FEE_PAGE_SIZE] = DataByte; //Erase Page - FlashStatus = FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + page); + FlashStatus = FLASH_ErasePage(FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE)); - // Write new data (whole page) to flash if data has beed changed + // Write new data (whole page) to flash if data has been changed for(i = 0; i < (FEE_PAGE_SIZE / 2); i++) { if ((__IO uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)]) != 0xFFFF) { FlashStatus = FLASH_ProgramHalfWord((FEE_PAGE_BASE_ADDRESS + (page * FEE_PAGE_SIZE)) + (i * 2), (uint16_t)(0xFF00 | DataBuf[FEE_ADDR_OFFSET(i)])); } } - } return FlashStatus; } @@ -168,7 +163,7 @@ void eeprom_update_word (uint16_t *Address, uint16_t Value) uint32_t eeprom_read_dword (const uint32_t *Address) { const uint16_t p = (const uint32_t) Address; - return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8) + return EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8) | (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24); } @@ -184,10 +179,14 @@ void eeprom_write_dword (uint32_t *Address, uint32_t Value) void eeprom_update_dword (uint32_t *Address, uint32_t Value) { uint16_t p = (const uint32_t) Address; - EEPROM_WriteDataByte(p, (uint8_t) Value); - EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8)); - EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16)); - EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24)); + uint32_t existingValue = EEPROM_ReadDataByte(p) | (EEPROM_ReadDataByte(p+1) << 8) + | (EEPROM_ReadDataByte(p+2) << 16) | (EEPROM_ReadDataByte(p+3) << 24); + if(Value != existingValue){ + EEPROM_WriteDataByte(p, (uint8_t) Value); + EEPROM_WriteDataByte(p+1, (uint8_t) (Value >> 8)); + EEPROM_WriteDataByte(p+2, (uint8_t) (Value >> 16)); + EEPROM_WriteDataByte(p+3, (uint8_t) (Value >> 24)); + } } void eeprom_read_block(void *buf, const void *addr, uint32_t len) { diff --git a/tmk_core/common/chibios/eeprom_stm32.h b/tmk_core/common/chibios/eeprom_stm32.h index 892e417b7e..083eb16ee6 100755 --- a/tmk_core/common/chibios/eeprom_stm32.h +++ b/tmk_core/common/chibios/eeprom_stm32.h @@ -34,6 +34,8 @@ #define MCU_STM32F303CC #elif defined(EEPROM_EMU_STM32F103xB) #define MCU_STM32F103RB +#elif defined(EEPROM_EMU_STM32F072xB) + #define MCU_STM32F072CB #else #error "not implemented." #endif @@ -42,7 +44,7 @@ #if defined (MCU_STM32F103RB) #define FEE_PAGE_SIZE (uint16_t)0x400 // Page size = 1KByte #define FEE_DENSITY_PAGES 2 // How many pages are used - #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) || defined (MCU_STM32F103RD) || defined (MCU_STM32F303CC) + #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) || defined (MCU_STM32F103RD) || defined (MCU_STM32F303CC) || defined(MCU_STM32F072CB) #define FEE_PAGE_SIZE (uint16_t)0x800 // Page size = 2KByte #define FEE_DENSITY_PAGES 4 // How many pages are used #else @@ -51,7 +53,7 @@ #endif #ifndef EEPROM_START_ADDRESS - #if defined (MCU_STM32F103RB) + #if defined (MCU_STM32F103RB) || defined(MCU_STM32F072CB) #define FEE_MCU_FLASH_SIZE 128 // Size in Kb #elif defined (MCU_STM32F103ZE) || defined (MCU_STM32F103RE) #define FEE_MCU_FLASH_SIZE 512 // Size in Kb diff --git a/tmk_core/common/chibios/flash_stm32.c b/tmk_core/common/chibios/flash_stm32.c index 164654a15e..832bf3908f 100755 --- a/tmk_core/common/chibios/flash_stm32.c +++ b/tmk_core/common/chibios/flash_stm32.c @@ -22,6 +22,9 @@ #elif defined(EEPROM_EMU_STM32F103xB) #define STM32F103xB #include "stm32f1xx.h" +#elif defined(EEPROM_EMU_STM32F072xB) + #define STM32F072xB + #include "stm32f0xx.h" #else #error "not implemented." #endif @@ -193,7 +196,7 @@ void FLASH_Lock(void) * This parameter can be any combination of the following values: * @arg FLASH_FLAG_PGERR: FLASH Programming error flag flag * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag - * @arg FLASH_FLAG_EOP: FLASH End of Programming flag + * @arg FLASH_FLAG_EOP: FLASH End of Programming flag * @retval None */ void FLASH_ClearFlag(uint32_t FLASH_FLAG) diff --git a/tmk_core/common/command.h b/tmk_core/common/command.h index c38f2b9e80..052e251843 100644 --- a/tmk_core/common/command.h +++ b/tmk_core/common/command.h @@ -34,6 +34,9 @@ bool command_proc(uint8_t code); #define command_proc(code) false #endif +#ifndef IS_COMMAND +#define IS_COMMAND() (get_mods() == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) +#endif #ifndef MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS #define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS true diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 25be28d02a..849d74aa1b 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -139,6 +139,40 @@ __attribute__ ((weak)) void matrix_setup(void) { } +/** \brief keyboard_pre_init_user + * + * FIXME: needs doc + */ +__attribute__ ((weak)) +void keyboard_pre_init_user(void) { } + +/** \brief keyboard_pre_init_kb + * + * FIXME: needs doc + */ +__attribute__ ((weak)) +void keyboard_pre_init_kb(void) { + keyboard_pre_init_user(); +} + +/** \brief keyboard_post_init_user + * + * FIXME: needs doc + */ + +__attribute__ ((weak)) +void keyboard_post_init_user() {} + +/** \brief keyboard_post_init_kb + * + * FIXME: needs doc + */ + +__attribute__ ((weak)) +void keyboard_post_init_kb(void) { + keyboard_post_init_user(); +} + /** \brief keyboard_setup * * FIXME: needs doc @@ -146,6 +180,7 @@ void matrix_setup(void) { void keyboard_setup(void) { disable_jtag(); matrix_setup(); + keyboard_pre_init_kb(); } /** \brief is_keyboard_master @@ -199,6 +234,7 @@ void keyboard_init(void) { #if defined(NKRO_ENABLE) && defined(FORCE_NKRO) keymap_config.nkro = 1; #endif + keyboard_post_init_kb(); /* Always keep this last */ } /** \brief Keyboard task: Do keyboard routine jobs diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h index ea2f336e9d..bf8b71fb78 100644 --- a/tmk_core/common/keyboard.h +++ b/tmk_core/common/keyboard.h @@ -70,6 +70,11 @@ void keyboard_set_leds(uint8_t leds); /* it runs whenever code has to behave differently on a slave */ bool is_keyboard_master(void); +void keyboard_pre_init_kb(void); +void keyboard_pre_init_user(void); +void keyboard_post_init_kb(void); +void keyboard_post_init_user(void); + #ifdef __cplusplus } #endif diff --git a/tmk_core/protocol/arm_atsam/adc.c b/tmk_core/protocol/arm_atsam/adc.c index ab77f92402..cb5c349b73 100644 --- a/tmk_core/protocol/arm_atsam/adc.c +++ b/tmk_core/protocol/arm_atsam/adc.c @@ -74,9 +74,9 @@ void ADC0_init(void) while (ADC0->SYNCBUSY.bit.SAMPCTRL) { DBGC(DC_ADC0_SAMPCTRL_SYNCING_1); } //Load factory calibration data - ADC0->CALIB.bit.BIASCOMP = (ADC0_FUSES_BIASCOMP_ADDR >> ADC0_FUSES_BIASCOMP_Pos) & ADC0_FUSES_BIASCOMP_Msk; - ADC0->CALIB.bit.BIASR2R = (ADC0_FUSES_BIASR2R_ADDR >> ADC0_FUSES_BIASR2R_Pos) & ADC0_FUSES_BIASR2R_Msk; - ADC0->CALIB.bit.BIASREFBUF = (ADC0_FUSES_BIASREFBUF_ADDR >> ADC0_FUSES_BIASREFBUF_Pos) & ADC0_FUSES_BIASREFBUF_Msk; + ADC0->CALIB.bit.BIASCOMP = ((*(uint32_t *)ADC0_FUSES_BIASCOMP_ADDR) & ADC0_FUSES_BIASCOMP_Msk) >> ADC0_FUSES_BIASCOMP_Pos; + ADC0->CALIB.bit.BIASR2R = ((*(uint32_t *)ADC0_FUSES_BIASR2R_ADDR) & ADC0_FUSES_BIASR2R_Msk) >> ADC0_FUSES_BIASR2R_Pos; + ADC0->CALIB.bit.BIASREFBUF = ((*(uint32_t *)ADC0_FUSES_BIASREFBUF_ADDR) & ADC0_FUSES_BIASREFBUF_Msk) >> ADC0_FUSES_BIASREFBUF_Pos; //Enable ADC0->CTRLA.bit.ENABLE = 1; diff --git a/tmk_core/protocol/bluefruit/main.c b/tmk_core/protocol/bluefruit/main.c index 0dbb637e2c..8a6386b4eb 100644 --- a/tmk_core/protocol/bluefruit/main.c +++ b/tmk_core/protocol/bluefruit/main.c @@ -42,13 +42,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. int main(void) -{ +{ CPU_PRESCALE(0); // DDRD = _BV(PD5); // DDRB = _BV(PB0); - + // PORTD = _BV(PD5); // PORTB = _BV(PB0); @@ -59,22 +59,23 @@ int main(void) // while (!usb_configured()) /* wait */ + keyboard_setup(); dprintf("Initializing keyboard...\n"); keyboard_init(); - + // This implementation is pretty simplistic... if the USB connection // is not configured, choose the Bluefruit, otherwise use USB // Definitely would prefer to have this driven by an input pin and make // it switch dynamically - BCG // if (!usb_configured()) { - + // // Send power to Bluefruit... Adafruit says it takes 27 mA, I think - // // the pins should provide 40 mA, but just in case I switch the + // // the pins should provide 40 mA, but just in case I switch the // // Bluefruit using a transistor - BCG // DDRB = _BV(PB6); // PORTB |= _BV(PB6); - + dprintf("Setting host driver to bluefruit...\n"); host_set_driver(bluefruit_driver()); @@ -131,7 +132,7 @@ int main(void) // usb_remote_wakeup(); // } // } -// keyboard_task(); +// keyboard_task(); // } // } diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c index 5436d49090..8de55bfe3f 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/main.c @@ -119,6 +119,8 @@ int main(void) { // TESTING // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); + keyboard_setup(); + /* Init USB */ init_usb_driver(&USB_DRIVER); diff --git a/tmk_core/protocol/usb_hid/test/config.h b/tmk_core/protocol/usb_hid/test/config.h index c2230fb570..71a6814fd1 100644 --- a/tmk_core/protocol/usb_hid/test/config.h +++ b/tmk_core/protocol/usb_hid/test/config.h @@ -15,9 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef CONFIG_H -#define CONFIG_H - +#pragma once #define VENDOR_ID 0xFEED #define PRODUCT_ID 0xCAFE @@ -25,16 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MANUFACTURER t.m.k. #define PRODUCT USB to USB keyboard converter - #define DESCRIPTION Product from t.m.k. keyboard firmware project - /* matrix size */ #define MATRIX_ROWS 32 #define MATRIX_COLS 8 - - -/* key combination for command */ -#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT))) - -#endif diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c index f6a0c7e9a4..86c2188c87 100644 --- a/tmk_core/protocol/vusb/main.c +++ b/tmk_core/protocol/vusb/main.c @@ -56,6 +56,7 @@ int main(void) #ifndef NO_UART uart_init(UART_BAUD_RATE); #endif + keyboard_setup(); keyboard_init(); host_set_driver(vusb_driver()); diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index 2e419dd667..c43f14292a 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -48,9 +48,6 @@ FORMAT = ihex # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) OPT = s -AUTOGEN ?= false - - # Compiler flag to set the C Standard level. # c89 = "ANSI" C # gnu89 = c89 plus GCC extensions @@ -142,7 +139,7 @@ CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) # files -- see avr-libc docs [FIXME: not yet described there] # -listing-cont-lines: Sets the maximum number of continuation lines of hex # dump that will be displayed for a given single line of source input. -ASFLAGS += $(ADEFS) +ASFLAGS += $(ADEFS) ifndef SKIP_DEBUG_INFO ASFLAGS += -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 else @@ -260,10 +257,6 @@ gccversion : @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD) $(eval CMD=$(HEX) $< $@) @$(BUILD_CMD) - @if $(AUTOGEN); then \ - $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(TARGET).hex\n"; \ - $(COPY) $@ $(KEYMAP_PATH)/$(TARGET).hex; \ - fi %.eep: %.elf @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD) @@ -297,7 +290,7 @@ BEGIN = gccversion sizebefore @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) $(eval CMD=$(CC) $(ALL_CFLAGS) $(filter-out %.txt,$^) --output $@ $(LDFLAGS)) @$(BUILD_CMD) - + define GEN_OBJRULE $1_INCFLAGS := $$(patsubst %,-I%,$$($1_INC)) @@ -371,7 +364,7 @@ DEPS = $(patsubst %.o,%.d,$(patsubst %.a,%.o,$(OBJ))) .PRECIOUS: $(DEPS) # Empty rule to force recompilation if the .d file is missing $(DEPS): - + $(foreach OUTPUT,$(OUTPUTS),$(eval $(call GEN_OBJRULE,$(OUTPUT)))) |