summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/avr.mk7
-rw-r--r--tmk_core/chibios.mk120
-rw-r--r--tmk_core/common.mk33
-rw-r--r--tmk_core/common/action.h2
-rw-r--r--tmk_core/common/action_layer.h13
-rw-r--r--tmk_core/common/bootmagic.c2
-rw-r--r--tmk_core/common/chibios/bootloader.c74
-rw-r--r--tmk_core/common/chibios/suspend.c16
-rw-r--r--tmk_core/common/command.c2
-rw-r--r--tmk_core/common/keyboard.c7
-rw-r--r--tmk_core/common/magic.c3
-rw-r--r--tmk_core/common/mousekey.c91
-rw-r--r--tmk_core/common/progmem.h1
-rw-r--r--tmk_core/common/report.h20
-rw-r--r--tmk_core/protocol/chibios/main.c1
-rw-r--r--tmk_core/protocol/chibios/usb_main.c85
-rw-r--r--tmk_core/protocol/iwrap.mk32
-rw-r--r--tmk_core/protocol/iwrap/iWRAP4.txt376
-rw-r--r--tmk_core/protocol/iwrap/iWRAP5.txt356
-rw-r--r--tmk_core/protocol/iwrap/iwrap.c420
-rw-r--r--tmk_core/protocol/iwrap/iwrap.h47
-rw-r--r--tmk_core/protocol/iwrap/main.c412
-rw-r--r--tmk_core/protocol/iwrap/mux_exit.rb7
-rw-r--r--tmk_core/protocol/iwrap/suart.S156
-rw-r--r--tmk_core/protocol/iwrap/suart.h8
-rw-r--r--tmk_core/protocol/iwrap/wd.h161
-rw-r--r--tmk_core/protocol/lufa.mk25
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.cpp4
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.h27
-rw-r--r--tmk_core/protocol/lufa/bluetooth.c38
-rw-r--r--tmk_core/protocol/lufa/bluetooth.h48
-rw-r--r--tmk_core/protocol/lufa/lufa.c314
-rw-r--r--tmk_core/protocol/lufa/lufa.h4
-rw-r--r--tmk_core/protocol/lufa/outputselect.c14
-rw-r--r--tmk_core/protocol/lufa/outputselect.h6
-rw-r--r--tmk_core/protocol/serial.h5
-rw-r--r--tmk_core/protocol/usb_descriptor.c121
-rw-r--r--tmk_core/protocol/usb_descriptor.h20
-rw-r--r--tmk_core/protocol/vusb.mk7
-rw-r--r--tmk_core/protocol/vusb/main.c37
-rw-r--r--tmk_core/protocol/vusb/sendchar_usart.c19
-rw-r--r--tmk_core/protocol/vusb/usbconfig.h20
-rw-r--r--tmk_core/protocol/vusb/vusb.c144
-rw-r--r--tmk_core/readme.md5
-rw-r--r--tmk_core/rules.mk8
45 files changed, 823 insertions, 2495 deletions
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk
index 04ae162246..336a83e9d3 100644
--- a/tmk_core/avr.mk
+++ b/tmk_core/avr.mk
@@ -120,15 +120,16 @@ define EXEC_DFU
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) erase --force; \
if [ "$(1)" ]; then \
- $(DFU_PROGRAMMER) $(MCU) flash --eeprom $(QUANTUM_PATH)/split_common/$(1);\
+ $(DFU_PROGRAMMER) $(MCU) flash --force --eeprom $(QUANTUM_PATH)/split_common/$(1);\
fi; \
+ $(DFU_PROGRAMMER) $(MCU) flash --force $(BUILD_DIR)/$(TARGET).hex;\
else \
$(DFU_PROGRAMMER) $(MCU) erase; \
if [ "$(1)" ]; then \
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(QUANTUM_PATH)/split_common/$(1);\
fi; \
+ $(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex;\
fi; \
- $(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex;\
$(DFU_PROGRAMMER) $(MCU) reset
endef
@@ -141,7 +142,7 @@ dfu-start:
dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
- $(DFU_PROGRAMMER) $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep;\
+ $(DFU_PROGRAMMER) $(MCU) flash --force --eeprom $(BUILD_DIR)/$(TARGET).eep;\
else\
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep;\
fi
diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk
index 09aaddeef0..2bd53f0dc8 100644
--- a/tmk_core/chibios.mk
+++ b/tmk_core/chibios.mk
@@ -50,11 +50,42 @@ PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLAT
endif
include $(PLATFORM_MK)
+BOARD_MK :=
+
+ifneq ("$(wildcard $(KEYBOARD_PATH_5)/boards/$(BOARD)/board.mk)","")
+ BOARD_PATH = $(KEYBOARD_PATH_5)
+ BOARD_MK += $(KEYBOARD_PATH_5)/boards/$(BOARD)/board.mk
+else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/boards/$(BOARD)/board.mk)","")
+ BOARD_PATH = $(KEYBOARD_PATH_4)
+ BOARD_MK += $(KEYBOARD_PATH_4)/boards/$(BOARD)/board.mk
+else ifneq ("$(wildcard $(KEYBOARD_PATH_3)/boards/$(BOARD)/board.mk)","")
+ BOARD_PATH = $(KEYBOARD_PATH_3)
+ BOARD_MK += $(KEYBOARD_PATH_3)/boards/$(BOARD)/board.mk
+else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/boards/$(BOARD)/board.mk)","")
+ BOARD_PATH = $(KEYBOARD_PATH_2)
+ BOARD_MK += $(KEYBOARD_PATH_2)/boards/$(BOARD)/board.mk
+else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/boards/$(BOARD)/board.mk)","")
+ BOARD_PATH = $(KEYBOARD_PATH_1)
+ BOARD_MK += $(KEYBOARD_PATH_1)/boards/$(BOARD)/board.mk
+else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/$(BOARD)/board/board.mk)","")
+ BOARD_PATH = $(TOP_DIR)/platforms/chibios/$(BOARD)
+ BOARD_MK += $(TOP_DIR)/platforms/chibios/$(BOARD)/board/board.mk
+ KEYBOARD_PATHS += $(BOARD_PATH)/configs
+endif
+
+ifeq ("$(wildcard $(BOARD_MK))","")
+ BOARD_MK = $(CHIBIOS)/os/hal/boards/$(BOARD)/board.mk
+ ifeq ("$(wildcard $(BOARD_MK))","")
+ BOARD_MK = $(CHIBIOS_CONTRIB)/os/hal/boards/$(BOARD)/board.mk
+ endif
+endif
+
# Bootloader address
ifdef STM32_BOOTLOADER_ADDRESS
OPT_DEFS += -DSTM32_BOOTLOADER_ADDRESS=$(STM32_BOOTLOADER_ADDRESS)
endif
+# Work out if we need to set up the include for the bootloader definitions
ifneq ("$(wildcard $(KEYBOARD_PATH_5)/bootloader_defs.h)","")
OPT_DEFS += -include $(KEYBOARD_PATH_5)/bootloader_defs.h
else ifneq ("$(wildcard $(KEYBOARD_PATH_5)/boards/$(BOARD)/bootloader_defs.h)","")
@@ -75,38 +106,52 @@ else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/bootloader_defs.h)","")
OPT_DEFS += -include $(KEYBOARD_PATH_1)/bootloader_defs.h
else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/boards/$(BOARD)/bootloader_defs.h)","")
OPT_DEFS += -include $(KEYBOARD_PATH_1)/boards/$(BOARD)/bootloader_defs.h
-else ifneq ("$(wildcard $(TOP_DIR)/drivers/boards/$(BOARD)/bootloader_defs.h)","")
- OPT_DEFS += -include $(TOP_DIR)/drivers/boards/$(BOARD)/bootloader_defs.h
+else ifneq ("$(wildcard $(BOARD_PATH)/configs/bootloader_defs.h)","")
+ OPT_DEFS += -include $(BOARD_PATH)/configs/bootloader_defs.h
endif
-BOARD_MK :=
+# Work out the config file directories
+ifneq ("$(wildcard $(KEYBOARD_PATH_5)/chconf.h)","")
+ CHCONFDIR = $(KEYBOARD_PATH_5)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/chconf.h)","")
+ CHCONFDIR = $(KEYBOARD_PATH_4)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_3)/chconf.h)","")
+ CHCONFDIR = $(KEYBOARD_PATH_3)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/chconf.h)","")
+ CHCONFDIR = $(KEYBOARD_PATH_2)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/chconf.h)","")
+ CHCONFDIR = $(KEYBOARD_PATH_1)
+else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/$(BOARD)/configs/chconf.h)","")
+ CHCONFDIR = $(TOP_DIR)/platforms/chibios/$(BOARD)/configs
+endif
-ifneq ("$(wildcard $(KEYBOARD_PATH_5)/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(KEYBOARD_PATH_5)
- BOARD_MK += $(KEYBOARD_PATH_5)/boards/$(BOARD)/board.mk
-else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(KEYBOARD_PATH_4)
- BOARD_MK += $(KEYBOARD_PATH_4)/boards/$(BOARD)/board.mk
-else ifneq ("$(wildcard $(KEYBOARD_PATH_3)/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(KEYBOARD_PATH_3)
- BOARD_MK += $(KEYBOARD_PATH_3)/boards/$(BOARD)/board.mk
-else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(KEYBOARD_PATH_2)
- BOARD_MK += $(KEYBOARD_PATH_2)/boards/$(BOARD)/board.mk
-else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(KEYBOARD_PATH_1)
- BOARD_MK += $(KEYBOARD_PATH_1)/boards/$(BOARD)/board.mk
-else ifneq ("$(wildcard $(TOP_DIR)/drivers/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(TOP_DIR)/drivers
- BOARD_MK += $(TOP_DIR)/drivers/boards/$(BOARD)/board.mk
+ifneq ("$(wildcard $(KEYBOARD_PATH_5)/halconf.h)","")
+ HALCONFDIR = $(KEYBOARD_PATH_5)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/halconf.h)","")
+ HALCONFDIR = $(KEYBOARD_PATH_4)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_3)/halconf.h)","")
+ HALCONFDIR = $(KEYBOARD_PATH_3)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/halconf.h)","")
+ HALCONFDIR = $(KEYBOARD_PATH_2)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/halconf.h)","")
+ HALCONFDIR = $(KEYBOARD_PATH_1)
+else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/$(BOARD)/configs/halconf.h)","")
+ HALCONFDIR = $(TOP_DIR)/platforms/chibios/$(BOARD)/configs
endif
-ifeq ("$(wildcard $(BOARD_MK))","")
- BOARD_MK = $(CHIBIOS)/os/hal/boards/$(BOARD)/board.mk
- ifeq ("$(wildcard $(BOARD_MK))","")
- BOARD_MK = $(CHIBIOS_CONTRIB)/os/hal/boards/$(BOARD)/board.mk
- endif
+# HAL-OSAL files (optional).
+include $(CHIBIOS)/os/hal/hal.mk
+
+ifeq ("$(PLATFORM_NAME)","")
+ PLATFORM_NAME = platform
+endif
+
+PLATFORM_MK = $(CHIBIOS)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk
+ifeq ("$(wildcard $(PLATFORM_MK))","")
+PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk
endif
+include $(PLATFORM_MK)
+
include $(BOARD_MK)
-include $(CHIBIOS)/os/hal/osal/rt/osal.mk # ChibiOS <= 19.x
@@ -138,8 +183,8 @@ else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/ld/$(MCU_LDSCRIPT).ld)","")
LDSCRIPT = $(KEYBOARD_PATH_2)/ld/$(MCU_LDSCRIPT).ld
else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/ld/$(MCU_LDSCRIPT).ld)","")
LDSCRIPT = $(KEYBOARD_PATH_1)/ld/$(MCU_LDSCRIPT).ld
-else ifneq ("$(wildcard $(TOP_DIR)/drivers/boards/ld/$(MCU_LDSCRIPT).ld)","")
- LDSCRIPT = $(TOP_DIR)/drivers/boards/ld/$(MCU_LDSCRIPT).ld
+else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/ld/$(MCU_LDSCRIPT).ld)","")
+ LDSCRIPT = $(TOP_DIR)/platforms/chibios/ld/$(MCU_LDSCRIPT).ld
else ifneq ("$(wildcard $(STARTUPLD_CONTRIB)/$(MCU_LDSCRIPT).ld)","")
LDSCRIPT = $(STARTUPLD_CONTRIB)/$(MCU_LDSCRIPT).ld
USE_CHIBIOS_CONTRIB = yes
@@ -163,6 +208,7 @@ QUANTUM_LIB_SRC += $(STARTUPASM) $(PORTASM) $(OSALASM)
CHIBISRC := $(patsubst $(TOP_DIR)/%,%,$(CHIBISRC))
EXTRAINCDIRS += $(CHIBIOS)/os/license $(CHIBIOS)/os/oslib/include \
+ $(TOP_DIR)/platforms/chibios/$(BOARD)/configs \
$(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(STREAMSINC) $(CHIBIOS)/os/various $(COMMON_VPATH)
@@ -182,6 +228,8 @@ else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/halconf_community.h)","")
USE_CHIBIOS_CONTRIB = yes
else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/halconf_community.h)","")
USE_CHIBIOS_CONTRIB = yes
+else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/$(BOARD)/configs/halconf_community.h)","")
+ USE_CHIBIOS_CONTRIB = yes
endif
ifeq ($(strip $(USE_CHIBIOS_CONTRIB)),yes)
@@ -194,6 +242,15 @@ endif
# Project, sources and paths
##############################################################################
+##############################################################################
+# Injected configs
+#
+ifneq ("$(wildcard $(BOARD_PATH)/configs/config.h)","")
+ CONFIG_H += $(BOARD_PATH)/configs/config.h
+endif
+ifneq ("$(wildcard $(BOARD_PATH)/configs/post_config.h)","")
+ POST_CONFIG_H += $(BOARD_PATH)/configs/post_config.h
+endif
##############################################################################
# Compiler settings
@@ -261,12 +318,14 @@ ifneq ("$(SERIAL)","")
endif
ST_LINK_ARGS ?=
+ST_FLASH_ARGS ?=
# List any extra directories to look for libraries here.
EXTRALIBDIRS = $(RULESPATH)/ld
DFU_UTIL ?= dfu-util
ST_LINK_CLI ?= st-link_cli
+ST_FLASH ?= st-flash
define EXEC_DFU_UTIL
until $(DFU_UTIL) -l | grep -q "Found DFU"; do\
@@ -300,6 +359,9 @@ dfu-util-split-right: dfu-util
st-link-cli: $(BUILD_DIR)/$(TARGET).hex sizeafter
$(ST_LINK_CLI) $(ST_LINK_ARGS) -q -c SWD -p $(BUILD_DIR)/$(TARGET).hex -Rst
+st-flash: $(BUILD_DIR)/$(TARGET).hex sizeafter
+ $(ST_FLASH) $(ST_FLASH_ARGS) --reset --format ihex write $(BUILD_DIR)/$(TARGET).hex
+
# Autodetect teensy loader
ifndef TEENSY_LOADER_CLI
@@ -324,7 +386,7 @@ bin: $(BUILD_DIR)/$(TARGET).bin sizeafter
flash: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
ifneq ($(strip $(PROGRAM_CMD)),)
$(PROGRAM_CMD)
-else ifeq ($(strip $(BOOTLOADER)),dfu)
+else ifeq ($(strip $(BOOTLOADER)),kiibohd)
$(call EXEC_DFU_UTIL)
else ifeq ($(strip $(MCU_FAMILY)),KINETIS)
$(call EXEC_TEENSY)
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 63de7c7ede..fdf2aa0972 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -99,8 +99,16 @@ ifeq ($(strip $(COMMAND_ENABLE)), yes)
endif
ifeq ($(strip $(NKRO_ENABLE)), yes)
- TMK_COMMON_DEFS += -DNKRO_ENABLE
- SHARED_EP_ENABLE = yes
+ ifeq ($(PROTOCOL), VUSB)
+ $(info NKRO is not currently supported on V-USB, and has been disabled.)
+ else ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)
+ $(info NKRO is not currently supported with Bluetooth, and has been disabled.)
+ else ifneq ($(BLUETOOTH),)
+ $(info NKRO is not currently supported with Bluetooth, and has been disabled.)
+ else
+ TMK_COMMON_DEFS += -DNKRO_ENABLE
+ SHARED_EP_ENABLE = yes
+ endif
endif
ifeq ($(strip $(USB_6KRO_ENABLE)), yes)
@@ -113,10 +121,6 @@ ifeq ($(strip $(SLEEP_LED_ENABLE)), yes)
TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
endif
-ifeq ($(strip $(NO_UART)), yes)
- TMK_COMMON_DEFS += -DNO_UART
-endif
-
ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes)
TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
endif
@@ -132,12 +136,6 @@ ifeq ($(strip $(BLUETOOTH)), AdafruitBLE)
TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK
endif
-ifeq ($(strip $(BLUETOOTH)), AdafruitEZKey)
- TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE
- TMK_COMMON_DEFS += -DMODULE_ADAFRUIT_EZKEY
- TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK
-endif
-
ifeq ($(strip $(BLUETOOTH)), RN42)
TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE
TMK_COMMON_DEFS += -DMODULE_RN42
@@ -160,16 +158,15 @@ ifeq ($(strip $(SHARED_EP_ENABLE)), yes)
endif
ifeq ($(strip $(LTO_ENABLE)), yes)
- LINK_TIME_OPTIMIZATION_ENABLE = yes
-endif
-
-ifeq ($(strip $(LINK_TIME_OPTIMIZATION_ENABLE)), yes)
ifeq ($(PLATFORM),CHIBIOS)
$(info Enabling LTO on ChibiOS-targeting boards is known to have a high likelihood of failure.)
- $(info If unsure, set LINK_TIME_OPTIMIZATION_ENABLE = no.)
+ $(info If unsure, set LTO_ENABLE = no.)
endif
EXTRAFLAGS += -flto
- TMK_COMMON_DEFS += -DLINK_TIME_OPTIMIZATION_ENABLE
+ TMK_COMMON_DEFS += -DLTO_ENABLE
+ TMK_COMMON_DEFS += -DLINK_TIME_OPTIMIZATON_ENABLE
+else ifdef LINK_TIME_OPTIMIZATION_ENABLE
+ $(error The LINK_TIME_OPTIMIZATION_ENABLE flag has been renamed to LTO_ENABLE.)
endif
# Search Path
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h
index c82c9c81be..345c030c94 100644
--- a/tmk_core/common/action.h
+++ b/tmk_core/common/action.h
@@ -29,7 +29,7 @@ extern "C" {
#endif
/* Disable macro and function features when LTO is enabled, since they break */
-#ifdef LINK_TIME_OPTIMIZATION_ENABLE
+#ifdef LTO_ENABLE
# ifndef NO_ACTION_MACRO
# define NO_ACTION_MACRO
# endif
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h
index 16922c1ff9..f9f6861120 100644
--- a/tmk_core/common/action_layer.h
+++ b/tmk_core/common/action_layer.h
@@ -82,9 +82,11 @@ void layer_on(uint8_t layer);
void layer_off(uint8_t layer);
void layer_invert(uint8_t layer);
/* bitwise operation */
-void layer_or(layer_state_t state);
-void layer_and(layer_state_t state);
-void layer_xor(layer_state_t state);
+void layer_or(layer_state_t state);
+void layer_and(layer_state_t state);
+void layer_xor(layer_state_t state);
+layer_state_t layer_state_set_user(layer_state_t state);
+layer_state_t layer_state_set_kb(layer_state_t state);
#else
# define layer_state 0
@@ -101,11 +103,10 @@ void layer_xor(layer_state_t state);
# define layer_or(state) (void)state
# define layer_and(state) (void)state
# define layer_xor(state) (void)state
+# define layer_state_set_kb(state) (void)state
+# define layer_state_set_user(state) (void)state
#endif
-layer_state_t layer_state_set_user(layer_state_t state);
-layer_state_t layer_state_set_kb(layer_state_t state);
-
/* pressed actions cache */
#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
index bb2aa0db8c..c1b3adf94d 100644
--- a/tmk_core/common/bootmagic.c
+++ b/tmk_core/common/bootmagic.c
@@ -122,6 +122,8 @@ void bootmagic(void) {
default_layer = eeconfig_read_default_layer();
default_layer_set((layer_state_t)default_layer);
}
+ /* Also initialize layer state to trigger callback functions for layer_state */
+ layer_state_set_kb((layer_state_t)layer_state);
/* EE_HANDS handedness */
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) {
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c
index 4cf5dae7e6..7b2cf5c435 100644
--- a/tmk_core/common/chibios/bootloader.c
+++ b/tmk_core/common/chibios/bootloader.c
@@ -2,29 +2,67 @@
#include "ch.h"
#include "hal.h"
-
-#ifdef STM32_BOOTLOADER_ADDRESS
-/* STM32 */
+#include "wait.h"
/* This code should be checked whether it runs correctly on platforms */
-# define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
+#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
+#define BOOTLOADER_MAGIC 0xDEADBEEF
+#define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
+
+#ifndef STM32_BOOTLOADER_DUAL_BANK
+# define STM32_BOOTLOADER_DUAL_BANK FALSE
+#endif
+
+#if STM32_BOOTLOADER_DUAL_BANK
+
+// Need pin definitions
+# include "config_common.h"
+
+# ifndef STM32_BOOTLOADER_DUAL_BANK_GPIO
+# error "No STM32_BOOTLOADER_DUAL_BANK_GPIO defined, don't know which pin to toggle"
+# endif
+
+# ifndef STM32_BOOTLOADER_DUAL_BANK_POLARITY
+# define STM32_BOOTLOADER_DUAL_BANK_POLARITY 0
+# endif
+
+# ifndef STM32_BOOTLOADER_DUAL_BANK_DELAY
+# define STM32_BOOTLOADER_DUAL_BANK_DELAY 100000
+# endif
+
+extern uint32_t __ram0_end__;
+
+void bootloader_jump(void) {
+ // For STM32 MCUs with dual-bank flash, and we're incapable of jumping to the bootloader. The first valid flash
+ // bank is executed unconditionally after a reset, so it doesn't enter DFU unless BOOT0 is high. Instead, we do
+ // it with hardware...in this case, we pull a GPIO high/low depending on the configuration, connects 3.3V to
+ // BOOT0's RC charging circuit, lets it charge the capacitor, and issue a system reset. See the QMK discord
+ // #hardware channel pins for an example circuit.
+ palSetPadMode(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_MODE_OUTPUT_PUSHPULL);
+# if STM32_BOOTLOADER_DUAL_BANK_POLARITY
+ palSetPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
+# else
+ palClearPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
+# endif
+
+ // Wait for a while for the capacitor to charge
+ wait_ms(100);
+
+ // Issue a system reset to get the ROM bootloader to execute, with BOOT0 high
+ NVIC_SystemReset();
+}
+
+void enter_bootloader_mode_if_requested(void) {} // not needed at all, but if anybody attempts to invoke it....
+
+#elif defined(STM32_BOOTLOADER_ADDRESS) // STM32_BOOTLOADER_DUAL_BANK
+
extern uint32_t __ram0_end__;
-# define BOOTLOADER_MAGIC 0xDEADBEEF
-# define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
-/** \brief Jump to the bootloader
- *
- * FIXME: needs doc
- */
void bootloader_jump(void) {
*MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader
NVIC_SystemReset();
}
-/** \brief Enter bootloader mode if requested
- *
- * FIXME: needs doc
- */
void enter_bootloader_mode_if_requested(void) {
unsigned long *check = MAGIC_ADDR;
if (*check == BOOTLOADER_MAGIC) {
@@ -41,10 +79,10 @@ void enter_bootloader_mode_if_requested(void) {
}
}
-#elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */
+#elif defined(KL2x) || defined(K20x) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS
/* Kinetis */
-# if defined(KIIBOHD_BOOTLOADER)
+# if defined(BOOTLOADER_KIIBOHD)
/* Kiibohd Bootloader (MCHCK and Infinity KB) */
# define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
@@ -54,14 +92,14 @@ void bootloader_jump(void) {
SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
}
-# else /* defined(KIIBOHD_BOOTLOADER) */
+# else /* defined(BOOTLOADER_KIIBOHD) */
/* Default for Kinetis - expecting an ARM Teensy */
# include "wait.h"
void bootloader_jump(void) {
wait_ms(100);
__BKPT(0);
}
-# endif /* defined(KIIBOHD_BOOTLOADER) */
+# endif /* defined(BOOTLOADER_KIIBOHD) */
#else /* neither STM32 nor KINETIS */
__attribute__((weak)) void bootloader_jump(void) {}
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index 8c071e7a08..64dfc05abc 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -9,6 +9,7 @@
#include "mousekey.h"
#include "host.h"
#include "suspend.h"
+#include "led.h"
#include "wait.h"
#ifdef BACKLIGHT_ENABLE
@@ -47,6 +48,20 @@ __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user
* FIXME: needs doc
*/
void suspend_power_down(void) {
+#ifdef BACKLIGHT_ENABLE
+ backlight_set(0);
+#endif
+
+ // 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);
+
// TODO: figure out what to power down and how
// shouldn't power down TPM/FTM if we want a breathing LED
// also shouldn't power down USB
@@ -119,6 +134,7 @@ void suspend_wakeup_init(void) {
#ifdef BACKLIGHT_ENABLE
backlight_init();
#endif /* BACKLIGHT_ENABLE */
+ led_set(host_keyboard_leds());
#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
is_suspended = false;
if (rgblight_enabled) {
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index ef6a39c0fe..feeb2202e2 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -180,7 +180,7 @@ static void print_version(void) {
#ifdef NKRO_ENABLE
" NKRO"
#endif
-#ifdef LINK_TIME_OPTIMIZATION_ENABLE
+#ifdef LTO_ENABLE
" LTO"
#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 714c3d048f..a45af56dfd 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -74,6 +74,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef MIDI_ENABLE
# include "process_midi.h"
#endif
+#ifdef JOYSTICK_ENABLE
+# include "process_joystick.h"
+#endif
#ifdef HD44780_ENABLE
# include "hd44780.h"
#endif
@@ -420,6 +423,10 @@ MATRIX_LOOP_END:
}
#endif
+#ifdef JOYSTICK_ENABLE
+ joystick_task();
+#endif
+
// update LED
if (led_status != host_keyboard_leds()) {
led_status = host_keyboard_leds();
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c
index d8ab525735..e14994164e 100644
--- a/tmk_core/common/magic.c
+++ b/tmk_core/common/magic.c
@@ -33,4 +33,7 @@ void magic(void) {
uint8_t default_layer = 0;
default_layer = eeconfig_read_default_layer();
default_layer_set((layer_state_t)default_layer);
+
+ /* Also initialize layer state to trigger callback functions for layer_state */
+ layer_state_set_kb((layer_state_t)layer_state);
}
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
index 42bf231f4c..ef18bcf1a8 100644
--- a/tmk_core/common/mousekey.c
+++ b/tmk_core/common/mousekey.c
@@ -33,9 +33,9 @@ inline int8_t times_inv_sqrt2(int8_t x) {
static report_mouse_t mouse_report = {0};
static void mousekey_debug(void);
-static uint8_t mousekey_accel = 0;
-static uint8_t mousekey_repeat = 0;
-static uint16_t last_timer = 0;
+static uint8_t mousekey_accel = 0;
+static uint8_t mousekey_repeat = 0;
+static uint8_t mousekey_wheel_repeat = 0;
#ifndef MK_3_SPEED
@@ -94,12 +94,12 @@ static uint8_t wheel_unit(void) {
unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
} else if (mousekey_accel & (1 << 2)) {
unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
- } else if (mousekey_repeat == 0) {
+ } else if (mousekey_wheel_repeat == 0) {
unit = MOUSEKEY_WHEEL_DELTA;
- } else if (mousekey_repeat >= mk_wheel_time_to_max) {
+ } else if (mousekey_wheel_repeat >= mk_wheel_time_to_max) {
unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
} else {
- unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max;
+ unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_wheel_repeat) / mk_wheel_time_to_max;
}
return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
}
@@ -147,14 +147,17 @@ static uint8_t wheel_unit(void) {
void mousekey_task(void) {
// report cursor and scroll movement independently
report_mouse_t const tmpmr = mouse_report;
- if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
+
+ mouse_report.x = 0;
+ mouse_report.y = 0;
+ mouse_report.v = 0;
+ mouse_report.h = 0;
+
+ if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
- mouse_report.v = 0;
- mouse_report.h = 0;
- if (mouse_report.x > 0) mouse_report.x = move_unit();
- if (mouse_report.x < 0) mouse_report.x = move_unit() * -1;
- if (mouse_report.y > 0) mouse_report.y = move_unit();
- if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
+ if (tmpmr.x != 0) mouse_report.x = move_unit() * ((tmpmr.x > 0) ? 1 : -1);
+ if (tmpmr.y != 0) mouse_report.y = move_unit() * ((tmpmr.y > 0) ? 1 : -1);
+
/* diagonal move [1/sqrt(2)] */
if (mouse_report.x && mouse_report.y) {
mouse_report.x = times_inv_sqrt2(mouse_report.x);
@@ -166,18 +169,12 @@ void mousekey_task(void) {
mouse_report.y = 1;
}
}
- mousekey_send();
- last_timer_c = last_timer;
- mouse_report = tmpmr;
}
- if ((mouse_report.v || mouse_report.h) && timer_elapsed(last_timer_w) > (mousekey_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) {
- if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
- mouse_report.x = 0;
- mouse_report.y = 0;
- if (mouse_report.v > 0) mouse_report.v = wheel_unit();
- if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1;
- if (mouse_report.h > 0) mouse_report.h = wheel_unit();
- if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1;
+ if ((tmpmr.v || tmpmr.h) && timer_elapsed(last_timer_w) > (mousekey_wheel_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) {
+ if (mousekey_wheel_repeat != UINT8_MAX) mousekey_wheel_repeat++;
+ if (tmpmr.v != 0) mouse_report.v = wheel_unit() * ((tmpmr.v > 0) ? 1 : -1);
+ if (tmpmr.h != 0) mouse_report.h = wheel_unit() * ((tmpmr.h > 0) ? 1 : -1);
+
/* diagonal move [1/sqrt(2)] */
if (mouse_report.v && mouse_report.h) {
mouse_report.v = times_inv_sqrt2(mouse_report.v);
@@ -189,10 +186,10 @@ void mousekey_task(void) {
mouse_report.h = 1;
}
}
- mousekey_send();
- last_timer_w = last_timer;
- mouse_report = tmpmr;
}
+
+ if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
+ mouse_report = tmpmr;
}
void mousekey_on(uint8_t code) {
@@ -263,7 +260,8 @@ void mousekey_off(uint8_t code) {
mousekey_accel &= ~(1 << 1);
else if (code == KC_MS_ACCEL2)
mousekey_accel &= ~(1 << 2);
- if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) mousekey_repeat = 0;
+ if (mouse_report.x == 0 && mouse_report.y == 0) mousekey_repeat = 0;
+ if (mouse_report.v == 0 && mouse_report.h == 0) mousekey_wheel_repeat = 0;
}
#else /* #ifndef MK_3_SPEED */
@@ -285,20 +283,22 @@ uint16_t w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0
void mousekey_task(void) {
// report cursor and scroll movement independently
report_mouse_t const tmpmr = mouse_report;
- if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
- mouse_report.h = 0;
- mouse_report.v = 0;
- mousekey_send();
- last_timer_c = last_timer;
- mouse_report = tmpmr;
+ mouse_report.x = 0;
+ mouse_report.y = 0;
+ mouse_report.v = 0;
+ mouse_report.h = 0;
+
+ if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
+ mouse_report.x = tmpmr.x;
+ mouse_report.y = tmpmr.y;
}
- if ((mouse_report.h || mouse_report.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) {
- mouse_report.x = 0;
- mouse_report.y = 0;
- mousekey_send();
- last_timer_w = last_timer;
- mouse_report = tmpmr;
+ if ((tmpmr.h || tmpmr.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) {
+ mouse_report.v = tmpmr.v;
+ mouse_report.h = tmpmr.h;
}
+
+ if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
+ mouse_report = tmpmr;
}
void adjust_speed(void) {
@@ -413,14 +413,17 @@ void mousekey_off(uint8_t code) {
void mousekey_send(void) {
mousekey_debug();
+ uint16_t time = timer_read();
+ if (mouse_report.x || mouse_report.y) last_timer_c = time;
+ if (mouse_report.v || mouse_report.h) last_timer_w = time;
host_mouse_send(&mouse_report);
- last_timer = timer_read();
}
void mousekey_clear(void) {
- mouse_report = (report_mouse_t){};
- mousekey_repeat = 0;
- mousekey_accel = 0;
+ mouse_report = (report_mouse_t){};
+ mousekey_repeat = 0;
+ mousekey_wheel_repeat = 0;
+ mousekey_accel = 0;
}
static void mousekey_debug(void) {
diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h
index 39a918fe98..c8863d3ad2 100644
--- a/tmk_core/common/progmem.h
+++ b/tmk_core/common/progmem.h
@@ -4,6 +4,7 @@
# include <avr/pgmspace.h>
#else
# define PROGMEM
+# define PGM_P const char*
# define memcpy_P(dest, src, n) memcpy(dest, src, n)
# define pgm_read_byte(address_short) *((uint8_t*)(address_short))
# define pgm_read_word(address_short) *((uint16_t*)(address_short))
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index c2b1b7c710..1aa33c998d 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -29,7 +29,8 @@ enum hid_report_ids {
REPORT_ID_MOUSE,
REPORT_ID_SYSTEM,
REPORT_ID_CONSUMER,
- REPORT_ID_NKRO
+ REPORT_ID_NKRO,
+ REPORT_ID_JOYSTICK
};
/* Mouse buttons */
@@ -46,8 +47,9 @@ enum mouse_buttons {
* See https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=75
*/
enum consumer_usages {
- // 15.5 Display Controls (https://www.usb.org/sites/default/files/hutrr41_0.pdf)
- BRIGHTNESS_UP = 0x06F,
+ // 15.5 Display Controls
+ SNAPSHOT = 0x065,
+ BRIGHTNESS_UP = 0x06F, // https://www.usb.org/sites/default/files/hutrr41_0.pdf
BRIGHTNESS_DOWN = 0x070,
// 15.7 Transport Controls
TRANSPORT_RECORD = 0x0B2,
@@ -57,6 +59,7 @@ enum consumer_usages {
TRANSPORT_PREV_TRACK = 0x0B6,
TRANSPORT_STOP = 0x0B7,
TRANSPORT_EJECT = 0x0B8,
+ TRANSPORT_RANDOM_PLAY = 0x0B9,
TRANSPORT_STOP_EJECT = 0x0CC,
TRANSPORT_PLAY_PAUSE = 0x0CD,
// 15.9.1 Audio Controls - Volume
@@ -71,6 +74,7 @@ enum consumer_usages {
AL_LOCK = 0x19E,
AL_CONTROL_PANEL = 0x19F,
AL_ASSISTANT = 0x1CB,
+ AL_KEYBOARD_LAYOUT = 0x1AE,
// 15.16 Generic GUI Application Controls
AC_MINIMIZE = 0x206,
AC_SEARCH = 0x221,
@@ -186,6 +190,16 @@ typedef struct {
int8_t h;
} __attribute__((packed)) report_mouse_t;
+typedef struct {
+#if JOYSTICK_AXES_COUNT > 0
+ int8_t axes[JOYSTICK_AXES_COUNT];
+#endif
+
+#if JOYSTICK_BUTTON_COUNT > 0
+ uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1];
+#endif
+} __attribute__((packed)) joystick_report_t;
+
/* keycode to system usage */
static inline uint16_t KEYCODE2SYSTEM(uint8_t key) {
switch (key) {
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c
index 7d32c16ed8..a0d28f9afc 100644
--- a/tmk_core/protocol/chibios/main.c
+++ b/tmk_core/protocol/chibios/main.c
@@ -35,6 +35,7 @@
#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
// Change this to be TRUE once we've migrated keyboards to the new init system
+// Remember to change docs/platformdev_chibios_earlyinit.md as well.
# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE
#endif
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 65bd291bec..ae33e86a70 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -47,6 +47,10 @@
extern keymap_config_t keymap_config;
#endif
+#ifdef JOYSTICK_ENABLE
+# include "joystick.h"
+#endif
+
/* ---------------------------------------------------------
* Global interface variables and declarations
* ---------------------------------------------------------
@@ -62,7 +66,7 @@ extern keymap_config_t keymap_config;
uint8_t keyboard_idle __attribute__((aligned(2))) = 0;
uint8_t keyboard_protocol __attribute__((aligned(2))) = 1;
-uint8_t keyboard_led_stats = 0;
+uint8_t keyboard_led_state = 0;
volatile uint16_t keyboard_idle_count = 0;
static virtual_timer_t keyboard_idle_timer;
static void keyboard_idle_timer_cb(void *arg);
@@ -247,6 +251,9 @@ typedef struct {
#ifdef VIRTSER_ENABLE
usb_driver_config_t serial_driver;
#endif
+#ifdef JOYSTICK_ENABLE
+ usb_driver_config_t joystick_driver;
+#endif
};
usb_driver_config_t array[0];
};
@@ -283,6 +290,14 @@ static usb_driver_configs_t drivers = {
# define CDC_OUT_MODE USB_EP_MODE_TYPE_BULK
.serial_driver = QMK_USB_DRIVER_CONFIG(CDC, CDC_NOTIFICATION_EPNUM, false),
#endif
+
+#ifdef JOYSTICK_ENABLE
+# define JOYSTICK_IN_CAPACITY 4
+# define JOYSTICK_OUT_CAPACITY 4
+# define JOYSTICK_IN_MODE USB_EP_MODE_TYPE_BULK
+# define JOYSTICK_OUT_MODE USB_EP_MODE_TYPE_BULK
+ .joystick_driver = QMK_USB_DRIVER_CONFIG(JOYSTICK, 0, false),
+#endif
};
#define NUM_USB_DRIVERS (sizeof(drivers) / sizeof(usb_driver_config_t))
@@ -386,10 +401,10 @@ static void set_led_transfer_cb(USBDriver *usbp) {
if (usbp->setup[6] == 2) { /* LSB(wLength) */
uint8_t report_id = set_report_buf[0];
if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_NKRO)) {
- keyboard_led_stats = set_report_buf[1];
+ keyboard_led_state = set_report_buf[1];
}
} else {
- keyboard_led_stats = set_report_buf[0];
+ keyboard_led_state = set_report_buf[0];
}
}
@@ -610,7 +625,7 @@ static void keyboard_idle_timer_cb(void *arg) {
}
/* LED status */
-uint8_t keyboard_leds(void) { return keyboard_led_stats; }
+uint8_t keyboard_leds(void) { return keyboard_led_state; }
/* prepare and start sending a report IN
* not callable from ISR or locked state */
@@ -796,9 +811,7 @@ int8_t sendchar(uint8_t c) {
}
#endif /* CONSOLE_ENABLE */
-void _putchar(char character) {
- sendchar(character);
-}
+void _putchar(char character) { sendchar(character); }
#ifdef RAW_ENABLE
void raw_hid_send(uint8_t *data, uint8_t length) {
@@ -869,3 +882,61 @@ void virtser_task(void) {
}
#endif
+
+#ifdef JOYSTICK_ENABLE
+
+void send_joystick_packet(joystick_t *joystick) {
+ joystick_report_t rep = {
+# if JOYSTICK_AXES_COUNT > 0
+ .axes =
+ {
+ joystick->axes[0],
+
+# if JOYSTICK_AXES_COUNT >= 2
+ joystick->axes[1],
+# endif
+# if JOYSTICK_AXES_COUNT >= 3
+ joystick->axes[2],
+# endif
+# if JOYSTICK_AXES_COUNT >= 4
+ joystick->axes[3],
+# endif
+# if JOYSTICK_AXES_COUNT >= 5
+ joystick->axes[4],
+# endif
+# if JOYSTICK_AXES_COUNT >= 6
+ joystick->axes[5],
+# endif
+ },
+# endif // JOYSTICK_AXES_COUNT>0
+
+# if JOYSTICK_BUTTON_COUNT > 0
+ .buttons =
+ {
+ joystick->buttons[0],
+
+# if JOYSTICK_BUTTON_COUNT > 8
+ joystick->buttons[1],
+# endif
+# if JOYSTICK_BUTTON_COUNT > 16
+ joystick->buttons[2],
+# endif
+# if JOYSTICK_BUTTON_COUNT > 24
+ joystick->buttons[3],
+# endif
+ }
+# endif // JOYSTICK_BUTTON_COUNT>0
+ };
+
+ // chnWrite(&drivers.joystick_driver.driver, (uint8_t *)&rep, sizeof(rep));
+ osalSysLock();
+ if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
+ osalSysUnlock();
+ return;
+ }
+
+ usbStartTransmitI(&USB_DRIVER, JOYSTICK_IN_EPNUM, (uint8_t *)&rep, sizeof(joystick_report_t));
+ osalSysUnlock();
+}
+
+#endif
diff --git a/tmk_core/protocol/iwrap.mk b/tmk_core/protocol/iwrap.mk
deleted file mode 100644
index 934235bd81..0000000000
--- a/tmk_core/protocol/iwrap.mk
+++ /dev/null
@@ -1,32 +0,0 @@
-IWRAP_DIR = protocol/iwrap
-
-OPT_DEFS += -DPROTOCOL_IWRAP
-
-SRC += $(IWRAP_DIR)/main.c \
- $(IWRAP_DIR)/iwrap.c \
- $(IWRAP_DIR)/suart.S \
- $(COMMON_DIR)/sendchar_uart.c \
- $(COMMON_DIR)/uart.c
-
-# Search Path
-VPATH += $(TMK_DIR)/protocol/iwrap
-
-
-# TODO: compatible with LUFA and PJRC
-# V-USB
-#
-VUSB_DIR = protocol/vusb
-
-# Path to the V-USB library
-VUSB_PATH = $(LIB_PATH)/vusb
-
-SRC += $(VUSB_DIR)/vusb.c \
- $(VUSB_PATH)/usbdrv/usbdrv.c \
- $(VUSB_PATH)/usbdrv/usbdrvasm.S \
- $(VUSB_PATH)/usbdrv/oddebug.c
-
-# Search Path
-VPATH += $(TMK_PATH)/$(VUSB_DIR)
-VPATH += $(VUSB_PATH)
-
-OPT_DEFS += -DPROTOCOL_VUSB
diff --git a/tmk_core/protocol/iwrap/iWRAP4.txt b/tmk_core/protocol/iwrap/iWRAP4.txt
deleted file mode 100644
index 2a062d9d98..0000000000
--- a/tmk_core/protocol/iwrap/iWRAP4.txt
+++ /dev/null
@@ -1,376 +0,0 @@
-Bulegiga WT12
-=============
-WT12 is a bluetooth module from Bluegiga. http://www.bluegiga.com/
-
-iWRAP
- higher layer interface for bluetooth firmware
- communicate with UART
-
-iWRAP HID
-default setting
- 115200 8bit/n/1/n
-
-
-TODO
-----
-KiCAD circuit/PCB design
-power saving
- AVR sleep(15ms by watch dog timer)
- WT12 sleep
- measuring current consumption
- measuring battery life of normal usage/idle/intensive usage
-software reset/bootloarder
-LED indicator(chaging/paring/connecting)
-license confirmation of suart.c
-consumer page is not working
-authenticate method/SSP
-SPP keyboard support
-SPP debug console support
-mouse wheel feature request to Bluegiga
-
-
-Problems
---------
-power consumption
-no consumer page support(bug?)
-no mouse wheel support
-no paring management
-no interactive auth method
-
-
-UART hardware flow control
---------------------------
-(iWRAP4 User Guide 9.5)
-Hardware flow control is enabled by default and it should not be disabled unless mandatory, because without the hardware flow control the data transmission may not be reliable.
-If the hardware flow control is enabled from PS-keys, but no flow control is used, the following steps should be implemented in the hardware design:
-- CTS pin must be grounded
-- RTS pin must be left floating
-
-
-Power Saving
-------------
-power consume
- without opimization: 4hr to shutdown(310mAh)
- 2011/08/25: 9hr(310mAh) SNIFF MASTER sleep/WDTO_120MS
-
-measure current consumption
- HHKB keyswitch matrix board
- idle
- scanning
- Bluegiga WT12 module
- SLEEP command
- deep sleep on/off in config bits
-
-HHKB keyswich
- how to power off
- I/O pin configuration when sleeping
- FET switch for 5V regulator
-
-Bluetooth module
- power off when in USB mode
- power off by FET switch
-
-AVR configuration
- unused pins
- ADC
-
-
-
-SET CONTROL CONFIG
-------------------
- SET CONTROL CONFIG 4810
- SET CONTROL CONFIG LIST
- SET CONTROL CONFIG 0000 0000 4910 DEEP_SLEEP KLUDGE INTERACTIVE_PIN UART_LATENCY
-
- Bit14 UART low latency
- Bit11 Interactive pairing mode
- Bit04 Deep sleep
-
-
-Reconnection
-------------
-SET CONTROL AUTOCALL 1124 5000 HID
- 1124 HID service class
- 5000 interval ms
-
-HID profile
------------
-This is needed to configure only once.
- SET PROFILE HID ON
- RESET
-
-HID class
----------
- SET BT CLASS 005C0 // keyboard/mouse combined devie
-
-Pairing Security
-----------------
-Secure Simple Pairing(SSP)
- SET BT SSP 2 0 // Enables SSP for keyboard and Man-in-the-middle protection
- SET BT SSP 3 0 // Enables SSP just works mode
-
-for keyboard with SSP
- SET BT AUTH * 0000
- SET BT SSP 2 0
- SET CONTROL CONFIG 800
- RESET
-
-for keyboard without SSP
- SET BT AUTH * 0000
- SET CONTROL CONFIG 800
- RESET
-
-AUTH
- AUTH xx:xx:xx:xx:xx:xx? // Pairing request event
- AUTH xx:xx:xx:xx:xx:xx 0000
-
- SSP PASSKEY 78:dd:08:b7:e4:a2 ?
- SSP PASSKEY 78:dd:08:b7:e4:a2 xxxxx
- (SSP COMPLETE 78:dd:08:b7:e4:a2 HCI_ERROR_AUTH_FAIL // failed)
- RING 0 78:dd:08:b7:e4:a2 11 HID
-
-Connecton
- RING xx:xx:xx:xx:xx:xx xx HID // connection event
-
- KILL xx:xx:xx:xx:xx:xx
-
-Mode
-----
-Command mode
-Data mode
- Raw mode
- (Simple mode not for a real keyboard)
-
-Raw mode
- Keyboard:
- 0x9f, length(10), 0xa1, 0x01, mods, 0x00, key1, key2, key3, key4, key5, key6
-
- Mouse:
- 0x9f, length(5), 0xa1, 0x02, buttons, X, Y
-
- Consumer page:
- 0x9f, length(5), 0xa1, 0x03, bitfield1, bitfield2, bitfield3
-
- consumer page suage
- Bitfield 1:
- 0x01 Volume Increment
- 0x02 Volume Decrement
- 0x04 Mute
- 0x08 Play/Pause
- 0x10 Scan Next Track
- 0x20 Scan Previous Track
- 0x40 Stop
- 0x80 Eject
- Bitfield 2:
- 0x01 Email Reader
- 0x02 Application Control Search
- 0x04 AC Bookmarks
- 0x08 AC Home
- 0x10 AC Back
- 0x20 AC Forward
- 0x40 AC Stop
- 0x80 AC Refresh
- Bitfield 3:
- 0x01 Application Launch Generic Consumer Control
- 0x02 AL Internet Browser
- 0x04 AL Calculator
- 0x08 AL Terminal Lock / Screensaver
- 0x10 AL Local Machine Browser
- 0x20 AC Minimize
- 0x40 Record
- 0x80 Rewind
-
-
-
-
-
-2011/07/13
-set
-SET BT BDADDR 00:07:80:47:22:14
-SET BT NAME HHKB pro BT
-SET BT CLASS 0005c0
-SET BT AUTH * 0000
-SET BT IDENT BT:47 f000 4.1.0 Bluegiga iWRAP
-SET BT LAP 9e8b33
-SET BT PAGEMODE 4 2000 1
-SET BT PAIR 78:dd:08:b7:e4:a2 a191189cd7e51030ad6a07848ce879bb
-SET BT POWER 3 3 3
-SET BT ROLE 0 f 7d00
-SET BT SNIFF 0 20 1 8
-SET BT SSP 2 1
-SET BT MTU 667
-SET CONTROL AUTOCALL 1124 3000 HID
-SET CONTROL BAUD 38400,8n1
-SET CONTROL CD 00 0
-SET CONTROL ECHO 7
-SET CONTROL ESCAPE 43 00 1
-SET CONTROL GAIN 0 5
-SET CONTROL INIT SET CONTROL MUX 0
-SET CONTROL MSC DTE 00 00 00 00 00 00
-SET CONTROL MUX 1
-SET CONTROL PIO 00 00
-SET CONTROL READY 00
-SET PROFILE HID f HID
-SET
-
-info config
-
-!!! THIS IS BETA RELEASE AND MAY BE USED FOR EVALUATION PURPOSES ONLY !!!
-
-WRAP THOR AI (4.1.0 build 435)
-Copyright (c) 2003-2011 Bluegiga Technologies Inc.
-Compiled on Jun 28 2011 17:19:51, running on WT12-A module, psr v31
- AVRCP BGIO FTP HFP HFP_AG HID HID_CONSUMER_PAGE HSP LEDS MAP OTA PBAP PIO=0x00fc SSP SUBRATE TEST VOLUME
- - BOCK3 version 435 (Jun 28 2011 17:19:37) (max acl/sco 7/1)
- - Bluetooth version 2.1, Power class 2
- - Loader 4279, firmware 6297 (56-bit encryption), native execution mode
- - up 0 days, 06:23, 2 connections (pool 2)
- - User configuration:
-&028a = 0001 0000 0000 0011 0024 0000 0000 0010 0000 0080 0000 0000 0080 005f 009b 0034 00fb 0006
-&028b = 0000 0bb8
-&028d = 0001
-&0295 = 0000 0005 000b 0000 0003 0000 0000 0000 0000 0000 0000
-&0298 = a006
-&0299 = 0000 0000
-&02a3 = 0030 0030 0030 0030
-&02a4 = 009d 0000
-&02a5 = 0053 0045 0054 0020 0043 004f 004e 0054 0052 004f 004c 0020 004d 0055 0058 0020 0030
-&02a7 = 0000 05c0
-&02a8 = 4910 0000 0000
-&02aa = 0004 2000 0001 0033 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-&02ac = 0000 0000 002b 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0010 0000 0000 0000 0000 029b 0000 0000 0000 0000
-&02ad = 4848 424b 7020 6f72 4220 0054
-&02b3 = 0005 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003
-&02b7 = 000f 4948 0044
-&02bb = 8000
-READY.
-
-
-
-
-2011/07/07 settings:
-set
-SET BT BDADDR 00:07:80:47:22:14
-SET BT NAME HHKB Pro BT
-SET BT CLASS 0005c0
-SET BT AUTH * 000
-SET BT IDENT BT:47 f000 4.0.0 Bluegiga iWRAP
-SET BT LAP 9e8b33
-SET BT PAGEMODE 4 2000 1
-SET BT PAIR 78:dd:08:b7:e4:a2 9e54d0aabb1b4d73cfccddb1ea4ef2d6
-SET BT POWER 3 3 3
-SET BT ROLE 0 f 7d00
-SET BT SNIFF 0 20 1 8
-SET BT SSP 3 0
-SET BT MTU 667
-SET CONTROL BAUD 38400,8n1
-SET CONTROL CD 00 0
-SET CONTROL ECHO 7
-SET CONTROL ESCAPE 255 00 1
-SET CONTROL GAIN 0 5
-SET CONTROL INIT set control mux 0
-SET CONTROL MSC DTE 00 00 00 00 00 00
-SET CONTROL PREAMP 1 1
-SET CONTROL READY 00
-SET PROFILE HID HID
-SET PROFILE SPP Bluetooth Serial Port
-SET
-
-info config
-WRAP THOR AI (4.0.0 build 317)
-Copyright (c) 2003-2010 Bluegiga Technologies Inc.
-Compiled on Apr 20 2010 16:44:28, running on WT12-A module, psr v31
- AVRCP FTP PBAP PIO=0x00fc SSP SUBRATE VOLUME
- - BOCK3 version 317 (Apr 20 2010 16:44:21) (max acl/sco 7/1)
- - Bluetooth version 2.1, Power class 2
- - Loader 4279, firmware 6297 (56-bit encryption), native execution mode
- - up 0 days, 00:00, 0 connections (pool 1)
- - User configuration:
-&028c = 0001 0020 0000 0001 0008 0000
-&028d = 0000
-&0296 = 0047 0001 f000 0400 6c42 6575 6967 6167 6920 5257 5041
-&0298 = c006
-&02a3 = 0030 0030 0030
-&02a4 = 009d 0000
-&02a5 = 0073 0065 0074 0020 0063 006f 006e 0074 0072 006f 006c 0020 006d 0075 0078 0020 0030
-&02a7 = 0000 05c0
-&02a8 = 0800 0000 0000
-&02ac = 0000 0000 00ff 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0010 0000 0000 0000 0000 029b 0000 0000 0000 0000
-&02ad = 4848 424b 5020 6f72 4220 0054
-&02b3 = 0004 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003
-&02b7 = 0000
-&02bb = 6c42 6575 6f74 746f 2068 6553 6972 6c61 5020 726f 0074
-READY.
-
-
-
-2011/08/23:
-SET BT BDADDR 00:07:80:47:22:14
-SET BT NAME HHKB pro BT
-SET BT CLASS 0005c0
-SET BT AUTH * 0000
-SET BT IDENT BT:47 f000 4.1.0 Bluegiga iWRAP
-SET BT LAP 9e8b33
-SET BT PAGEMODE 4 2000 1
-SET BT PAIRCOUNT 4
-SET BT POWER 3 3 3
-SET BT ROLE 1 f 12c0
-SET BT SNIFF 10 2 1 8
-SET BT SSP 3 0
-SET BT MTU 667
-SET CONTROL BAUD 38400,8n1
-SET CONTROL CD 00 0
-SET CONTROL ECHO 7
-SET CONTROL ESCAPE 43 00 1
-SET CONTROL GAIN 0 5
-SET CONTROL INIT SET CONTROL MUX 0
-SET CONTROL MSC DTE 00 00 00 00 00 00
-SET CONTROL MUX 1
-SET CONTROL PIO 00 00
-SET CONTROL READY 00
-SET PROFILE HID 7 HIDKeyboardMouse
-SET
-
-SET CONTROL CONFIG 0000 0004 481e CLOCK_CACHE INTERLACED_INQ INTERLACED_PAGE DEEP_SLEEP INTERACTIVE_PIN UART_LATENCY 23D_NOKLUDGE
-
-
-
-2011/08/25:
-SET BT BDADDR 00:07:80:47:22:14
-SET BT NAME HHKB pro BT
-SET BT CLASS 0005c0
-
-SET BT IDENT BT:47 f000 4.1.0 Bluegiga iWRAP
-SET BT LAP 9e8b33
-SET BT PAGEMODE 4 2000 1
-SET BT PAIRCOUNT 4
-SET BT PAIR 78:dd:08:b7:e4:a2 0be83335a03fed8ededae42e99554e28
-SET BT POWER 3 3 3
-SET BT ROLE 1 f 12c0
-SET BT SNIFF 100 20 1 8
-SET BT SSP 3 0
-SET BT MTU 667
-SET CONTROL BAUD 38400,8n1
-SET CONTROL CD 00 0
-SET CONTROL ECHO 7
-SET CONTROL ESCAPE - 20 1
-SET CONTROL GAIN 0 5
-SET CONTROL INIT SET CONTROL MUX 0
-SET CONTROL MSC DTE 00 00 00 00 00 00
-SET CONTROL MUX 1
-SET CONTROL PIO 00 00
-SET CONTROL READY 00
-SET PROFILE HID f HIDKeyboardMouse
-SET
-
-
-SET CONTROL CONFIG 0000 0000 490e CLOCK_CACHE INTERLACED_INQ INTERLACED_PAGE KLUDGE INTERACTIVE_PIN UART_LATENCY
-
-
-2011/09/08:
-SET CONTROL CONFIG 0000 0000 410e CLOCK_CACHE INTERLACED_INQ INTERLACED_PAGE KLUDGE UART_LATENCY
-
- Removed INTERACTIVE_PIN to avoid interactive auth and use SET BT AUTH pin(0000).
-
-
-EOF
diff --git a/tmk_core/protocol/iwrap/iWRAP5.txt b/tmk_core/protocol/iwrap/iWRAP5.txt
deleted file mode 100644
index ce3310f1bf..0000000000
--- a/tmk_core/protocol/iwrap/iWRAP5.txt
+++ /dev/null
@@ -1,356 +0,0 @@
-Terminology
-===========
-PSM
-HIDP HID Protocol
-L2CAP Logical Link Control Adaptation Protocol
-MTU Maximum Transmission Unit
-
-
-
-HID Protocol
-============
-3 of HID_SPEC_V11.pdf
-
-Channel
--------
-Control channel PSM=0x0011
-Interrupt channel PSM=0x0013
-
-Message
--------
-HANDSHAKE(0)
-HID_CONTROL(1)
-
-GET_REPORT(4)
- Host requests report(DATA payload on Control channel) from Device
- Size Desc
- ------------------------------------------------------------------------------
- HIDP-Hdr 1 7..4: HIDP Message TYpe(4: GET_REPORT)
- 3: Size(1:2-octed buffer size, 0:size of the report)
- 2: 0
- 1..0: Report Type(1:input, 2:output, 3: feature)
- ReportID 1 Optional
- BufferSize 2 Optional(specified when Size=1)
-
-SET_REPORT(5)
-GET_PROTOCOL(6)
-SET_PROTOCOL(7)
-
-DATA(A)
- Input/Output Report: All DATA payloads flow on Interrupt channel.
- Other: flows on Control channel.
- Size Desc
- ------------------------------------------------------------------------------
- HIDP-Hdr 1 7..4 0xA
- 3..2 Reserved(0)
- 1..0 Report Type(0:Other, 1:Input, 2:Output, 3:Feature)
- Payload N Data
-
-
-
-
-Boot Protocol
-=============
-3.3.2
-No report descriptor, fixed report descriptors defined.
-
-Device ReportID Size
----------------------------------
-Reserved 0
-Keyboard 1 9octets
-Mouse 2 4octets
-Reserved 3-255
-
-Report descriptor
------------------
-Report ID is added to USB HID boot protocol descriptor.
-Boot Protocol device doesn't need to supply descriptors. and can send extra data on end of boot report this data will be ignored unless host supports report descriptor.
-
-Report Protocol devices can have specific descriptors. Using Boot protocol descriptor followed by extra data may be useful for compatibility to Boot protocol only supported host.
-
-NOTE:
-Bluegiga HID sample say report ID of mouse is 1 but 2?
-Bluegiga HID sample say report ID of consumer page is 2 but 3?
-** mouse.desc and consumer.desc were fixed.
- size
-keyboard.desc 67 0x43
-mouse.desc 60 0x3c
-consumer.desc 82 0x52
-combo.desc 209 0xd1
-
-
-
-SDP
-===
-attributes(3.3.2)
-----------
-HIDDeviceSubclass
- which type is supported in Boot Protocol Mode
- 7 6
- ---
- 0 1 Keyboard
- 1 0 Pointing device
- 1 1 Combo keyboard/pointing device
-
-HIDBootDevice
- TRUE
-HIDReconnectInitiate
- TRUE
-
-
-Class of Device/Service
-=======================
-http://phys.sci.hokudai.ac.jp/LABS/yts/pic/GB002/Bluetooth_assigned_numbers_baseband.pdf
-
-0x0005C0 Keyboard and Pointing deivce(combo)
-
-
- 23 16 15 8 7 0
- ---------------------------------
- Service |Major |Minor |Format
-
- Format type
- 1 0
- ---
- 0 0
-
- Minor Device Class of Peripheral Major
- 7 6
- ---
- 0 1 Keyboard
- 1 0 Pointing device
- 1 1 Combo keyboard/pointing device
-
-
- Major device classes
- 12 11 10 9 8
- --------------
- 0 0 0 0 0 Miscellaneous
- 0 0 0 0 1 Computer
- 0 0 0 1 0 Phone
- 0 0 0 1 1 LAN /Network Access point
- 0 0 1 0 0 Audio/Video (headset,speaker,stereo, video display, vcr.....
- 0 0 1 0 1 *Peripheral (mouse, joystick, keyboards, ..... )
- 0 0 1 1 0 Imaging (printing, scanner, camera, display, ...)
- 1 1 1 1 1 Uncategorized, specific device code not specified
- X X X X X All other values reserved
-
-
- Major service classes
- bit
- --------------------------------------
- 13 Limited Discoverable Mode [Ref #1]
- 14 (reserved)
- 15 (reserved)
- 16 Positioning (Location identification)
- 17 Networking (LAN, Ad hoc, ...)
- 18 Rendering (Printing, Speaker, ...)
- 19 Capturing (Scanner, Microphone, ...)
- 20 Object Transfer (v-Inbox, v-Folder, ...)
- 21 Audio (Speaker, Microphone, Headset service, ...)
- 22 Telephony (Cordless telephony, Modem, Headset service, ...)
- 23 Information (WEB-server, WAP-server, ...)
-
-
-
-
-Authentication SSP
--------------------
-SET BT SSP 2 0 PASS KEY entering
-SET BT SSP 3 0 NO PASS KEY entering
-SET BT SSP <capabilities> <mitm>
- <capabilities>: 0:display only 1:display+yes/no button 2:keyboard only 3:none
-SET BT SSP 2 1 # 2:keyboard only 1:Man-in-the-middle protection is needed
-SET BT SSP 2 0 # 2:keyboard only 0:Man-in-the-middle protection is not needed
-
-
-SET BT SSP 2 1
- bond only if MITM protection is supported by host
-SET BT SSP 2 0
- bond even if MITM protection is not supported by host
-
-On Windows 'Add device' causes SSP PASSKEY event on iWRAP
- SSP PASSKEY 78:dd:08:b7:e4:a2 ?
-
-If device has display(0 or 1) this event occurs. User should be shown this code on the device.
- SSP CONFIRM 78:dd:08:b7:e4:a2 517572
-
-
-SET BT SSP 3 0
- No input/output, No MITM protection.
- Without procedure of authentication the divice is bond to host.
-
-
-Connect
-=======
-CALL 78:dd:08:b7:e4:a2 11 HID
-
-
-Setting
-========
-Following settings need to be done before wiring into keyboard.
-- UART speed: 38400bps(115200bps didn't work with software serial)
-- No SSP procedure(without MITM protection)
-- No Power Saving
-
-# clear pairing record and set default
-SET BT PAIR *
-SET RESET
-
-SET CONTROL INIT SET CONTROL MUX 0
-SET CONTROL BAUD 38400,8n1
-SET BT NAME TMK Blootooth WT12
-SET BT CLASS 0005c0
-SET BT AUTH * 0000
-SET BT SSP 3 0
-SET CONTROL CONFIG 4800
-SET PROFILE HID 0f c0 0100 00 en 0409 TMK Bluetooth keyboard(WT12)
-SET PROFILE SPP
-
-# power saving?
-SET BT SNIFF 100 20 1 8
-
-
-# Report Descriptor
-# combo keyboard + mouse + consumer
-HID SET d2 05010906a1010507850119e029e715002501750195088102950175088101950575010508850119012905910295017503910395067508150025650507190029658100c005010902a1010901a1008502050919012908150025017501950881020501093009311581257f750895028106093895018106050c0a380295018106c0c0050c0901a1018503050c1500250109e909ea09e209cd19b529b87501950881020a8a010a21020a2a021a23022a27027501950881020a83010a96010a92010a9e010a94010a060209b209b4750195088102c0
-
-
-
-SET PROFILE HID
----------------
- SET PROFILE HID 0d c0 100 0 en 0409 HHKB pro Bluetooth keyboard
- {function bit} uint8
- {subclass} uint8
- {version} uint16
- {country} uint8
- {BTlang} char[2]
- {USBlang} uint16
- {name} string
-
-
-SET BT CLASS
-------------
- See Class of Device
- composite device: keyboard and mouse
- SET BT CLASS 005c0
-
-
-
-
-
-
-----------
-after setting
-----------
-set
-SET BT BDADDR 00:07:80:47:22:14
-SET BT NAME TMK Blootooth WT12
-SET BT CLASS 0005c0
-SET BT AUTH * 0000
-SET BT IDENT BT:47 f000 5.0.1 Bluegiga iWRAP
-SET BT LAP 9e8b33
-SET BT PAGEMODE 4 2000 1
-SET BT PAIR 78:dd:08:b7:e4:a2 9e3d85c91bcae73fef8cc10bec18b42f
-SET BT POWER 3 3 3
-SET BT ROLE 0 f 7d00
-SET BT SNIFF 0 20 1 8
-SET BT SSP 3 0
-SET BT MTU 667
-SET CONTROL BAUD 38400,8n1
-SET CONTROL CD 00 0
-SET CONTROL ECHO 7
-SET CONTROL ESCAPE 43 00 1
-SET CONTROL GAIN 0 5
-SET CONTROL INIT SET CONTROL MUX 0
-SET CONTROL MSC DTE 00 00 00 00 00 00
-SET CONTROL MUX 1
-SET CONTROL PIO 00 00
-SET CONTROL READY 00
-SET PROFILE HID 0f c0 0100 00 en 0409 TMK Bluetooth keyboard(WT12)
-SET
-
-set control config list
-SET CONTROL CONFIG 0000 0000 0000 4900 KLUDGE INTERACTIVE_PIN UART_LATENCY
-
-
-info config
-WRAP THOR AI (5.0.1 build 620)
-Copyright (c) 2003-2012 Bluegiga Technologies Inc.
-Compiled on Oct 1 2012 10:56:21, running on WT12-A module, psr v31
- BGIO FTP HFP HFP_AG HID HID_CONSUMER_PAGE HSP MAP MDP OTA PBAP PIO=0x00fc SSP SUBRATE TEST VOLUME
- - BOCK4 version 620 (Oct 1 2012 10:56:03) (max acl/sco 7/1)
- - Bluetooth version 3.0, Power class 2
- - Loader 8615, firmware 8825 (56-bit encryption), native execution mode
- - up 0 days, 01:50, 2 connections (pool 2)
- - User configuration:
-&028d = 0001
-&0295 = 0000 0005 000b 0000 0003 0000 0000 0000 0000 0000 0000
-&0298 = c053
-&0299 = 0000 0000
-&02a3 = 0030 0030 0030 0030
-&02a4 = 009d 0000
-&02a5 = 0053 0045 0054 0020 0043 004f 004e 0054 0052 004f 004c 0020 004d 0055 0058 0020 0030
-&02a7 = 0000 05c0
-&02a8 = 0800 0000 0000 0000
-&02aa = 0004 2000 0001 0033 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-&02ac = 0000 0000 002b 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0010 0000 0000 0000 0000 029b 0000 0000 0000 0000
-&02ad = 4d54 204b 6c42 6f6f 6f74 746f 2068 5457 3231
-&02b0 = fa65 b0aa 934a 077b a600 d1cc fe58 8dd5
-&02b3 = 0004 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0005 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0005
-&02b7 = 000f 00c0 0100 0000 0065 006e 0409 4d54 204b 6c42 6575 6f74 746f &02bb = 8000
-READY.
-----------
-
-
-
------
-After 5.0.1 Firmware update
-Firmware: ai-5.0.1-620-25b.bc4.dfu
-PSR: wt12-a.ai-5.0.1-620-25b.psrf
------
-info config
-WRAP THOR AI (5.0.1 build 620)
-Copyright (c) 2003-2012 Bluegiga Technologies Inc.
-Compiled on Oct 1 2012 10:56:21, running on WT12-A module, psr v31
- BGIO FTP HFP HFP_AG HID HID_CONSUMER_PAGE HSP MAP MDP OTA PBAP PIO=0x00fc SSP SUBRATE TEST VOLUME
- - BOCK4 version 620 (Oct 1 2012 10:56:03) (max acl/sco 7/1)
- - Bluetooth version 3.0, Power class 2
- - Loader 8615, firmware 8825 (56-bit encryption), native execution mode
- - up 0 days, 00:03, 0 connections (pool 1)
- - User configuration:
-&0295 = 0000 0005 000b 0000 0003 0000 0000 0000 0000 0000 0000
-&0299 = 0000 0000
-&02aa = 0004 2000 0001 0033 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-&02ac = 0000 0000 002b 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0010 0000 0000 0000 0000 029b 0000 0000 0000 0000
-&02ad = 5457 3231 412d
-&02b0 = fa65 b0aa 934a 077b a600 d1cc fe58 8dd5
-READY.
-
-set
-SET BT BDADDR 00:07:80:47:22:14
-SET BT NAME WT12-A
-SET BT CLASS 001f00
-SET BT IDENT BT:47 f000 5.0.1 Bluegiga iWRAP
-SET BT LAP 9e8b33
-SET BT PAGEMODE 4 2000 1
-SET BT PAIR 78:dd:08:b7:e4:a2 af18f81faa107e6dd068762ef921f48b
-SET BT POWER 3 3 3
-SET BT ROLE 0 f 7d00
-SET BT SNIFF 0 20 1 8
-SET BT SSP 3 0
-SET BT MTU 667
-SET CONTROL BAUD 115200,8n1
-SET CONTROL CD 00 0
-SET CONTROL ECHO 7
-SET CONTROL ESCAPE 43 00 1
-SET CONTROL GAIN 0 5
-SET CONTROL MSC DTE 00 00 00 00 00 00
-SET CONTROL PIO 00 00
-SET CONTROL READY 00
-SET PROFILE SPP Bluetooth Serial Port
-SET
-
-set control config list
-SET CONTROL CONFIG 0000 0000 0000 0100 KLUDGE
----------
diff --git a/tmk_core/protocol/iwrap/iwrap.c b/tmk_core/protocol/iwrap/iwrap.c
deleted file mode 100644
index 4d0ca5756b..0000000000
--- a/tmk_core/protocol/iwrap/iwrap.c
+++ /dev/null
@@ -1,420 +0,0 @@
-/*
-Copyright 2011 Jun Wako <wakojun@gmail.com>
-
-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
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* host driver for Bulegiga iWRAP */
-/* Bluegiga BT12
- * Connections
- * Hardware UART Software UART BlueTooth
- * PC=====UART=======AVR=====SUART====iWRAP(BT12)-----------PC
- *
- * - Hardware UART for Debug Console to communicate iWRAP
- * - Software UART for iWRAP control to send keyboard/mouse data
- */
-
-#include <stdint.h>
-#include <string.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include "keycode.h"
-#include "suart.h"
-#include "uart.h"
-#include "report.h"
-#include "host_driver.h"
-#include "iwrap.h"
-#include "print.h"
-
-/* iWRAP MUX mode utils. 3.10 HID raw mode(iWRAP_HID_Application_Note.pdf) */
-#define MUX_HEADER(LINK, LENGTH) \
- do { \
- xmit(0xbf); /* SOF */ \
- xmit(LINK); /* Link */ \
- xmit(0x00); /* Flags */ \
- xmit(LENGTH); /* Length */ \
- } while (0)
-#define MUX_FOOTER(LINK) xmit(LINK ^ 0xff)
-
-static uint8_t connected = 0;
-// static uint8_t channel = 1;
-
-/* iWRAP buffer */
-#define MUX_BUF_SIZE 64
-static char buf[MUX_BUF_SIZE];
-static uint8_t snd_pos = 0;
-
-#define MUX_RCV_BUF_SIZE 256
-static char rcv_buf[MUX_RCV_BUF_SIZE];
-static uint8_t rcv_head = 0;
-static uint8_t rcv_tail = 0;
-
-/* receive buffer */
-static void rcv_enq(char c) {
- uint8_t next = (rcv_head + 1) % MUX_RCV_BUF_SIZE;
- if (next != rcv_tail) {
- rcv_buf[rcv_head] = c;
- rcv_head = next;
- }
-}
-
-static char rcv_deq(void) {
- char c = 0;
- if (rcv_head != rcv_tail) {
- c = rcv_buf[rcv_tail++];
- rcv_tail %= MUX_RCV_BUF_SIZE;
- }
- return c;
-}
-
-/*
-static char rcv_peek(void)
-{
- if (rcv_head == rcv_tail)
- return 0;
- return rcv_buf[rcv_tail];
-}
-*/
-
-static void rcv_clear(void) { rcv_tail = rcv_head = 0; }
-
-/* iWRAP response */
-ISR(PCINT1_vect, ISR_BLOCK) // recv() runs away in case of ISR_NOBLOCK
-{
- if ((SUART_IN_PIN & (1 << SUART_IN_BIT))) return;
-
- static volatile uint8_t mux_state = 0xff;
- static volatile uint8_t mux_link = 0xff;
- uint8_t c = recv();
- switch (mux_state) {
- case 0xff: // SOF
- if (c == 0xbf) mux_state--;
- break;
- case 0xfe: // Link
- mux_state--;
- mux_link = c;
- break;
- case 0xfd: // Flags
- mux_state--;
- break;
- case 0xfc: // Length
- mux_state = c;
- break;
- case 0x00:
- mux_state = 0xff;
- mux_link = 0xff;
- break;
- default:
- if (mux_state--) {
- uart_putchar(c);
- rcv_enq(c);
- }
- }
-}
-
-/*------------------------------------------------------------------*
- * iWRAP communication
- *------------------------------------------------------------------*/
-void iwrap_init(void) {
- // reset iWRAP if in already MUX mode after AVR software-reset
- iwrap_send("RESET");
- iwrap_mux_send("RESET");
- _delay_ms(3000);
- iwrap_send("\r\nSET CONTROL MUX 1\r\n");
- _delay_ms(500);
- iwrap_check_connection();
-}
-
-void iwrap_mux_send(const char *s) {
- rcv_clear();
- MUX_HEADER(0xff, strlen((char *)s));
- iwrap_send(s);
- MUX_FOOTER(0xff);
-}
-
-void iwrap_send(const char *s) {
- while (*s) xmit(*s++);
-}
-
-/* send buffer */
-void iwrap_buf_add(uint8_t c) {
- // need space for '\0'
- if (snd_pos < MUX_BUF_SIZE - 1) buf[snd_pos++] = c;
-}
-
-void iwrap_buf_del(void) {
- if (snd_pos) snd_pos--;
-}
-
-void iwrap_buf_send(void) {
- buf[snd_pos] = '\0';
- snd_pos = 0;
- iwrap_mux_send(buf);
-}
-
-void iwrap_call(void) {
- char *p;
-
- iwrap_mux_send("SET BT PAIR");
- _delay_ms(500);
-
- p = rcv_buf + rcv_tail;
- while (!strncmp(p, "SET BT PAIR", 11)) {
- p += 7;
- strncpy(p, "CALL", 4);
- strncpy(p + 22, " 11 HID\n\0", 9);
- print_S(p);
- iwrap_mux_send(p);
- // TODO: skip to next line
- p += 57;
-
- DEBUG_LED_CONFIG;
- DEBUG_LED_ON;
- _delay_ms(500);
- DEBUG_LED_OFF;
- _delay_ms(500);
- DEBUG_LED_ON;
- _delay_ms(500);
- DEBUG_LED_OFF;
- _delay_ms(500);
- DEBUG_LED_ON;
- _delay_ms(500);
- DEBUG_LED_OFF;
- _delay_ms(500);
- DEBUG_LED_ON;
- _delay_ms(500);
- DEBUG_LED_OFF;
- _delay_ms(500);
- DEBUG_LED_ON;
- _delay_ms(500);
- DEBUG_LED_OFF;
- _delay_ms(500);
- }
- iwrap_check_connection();
-}
-
-void iwrap_kill(void) {
- char c;
- iwrap_mux_send("LIST");
- _delay_ms(500);
-
- while ((c = rcv_deq()) && c != '\n')
- ;
- if (strncmp(rcv_buf + rcv_tail, "LIST ", 5)) {
- print("no connection to kill.\n");
- return;
- }
- // skip 10 'space' chars
- for (uint8_t i = 10; i; i--)
- while ((c = rcv_deq()) && c != ' ')
- ;
-
- char *p = rcv_buf + rcv_tail - 5;
- strncpy(p, "KILL ", 5);
- strncpy(p + 22, "\n\0", 2);
- print_S(p);
- iwrap_mux_send(p);
- _delay_ms(500);
-
- iwrap_check_connection();
-}
-
-void iwrap_unpair(void) {
- iwrap_mux_send("SET BT PAIR");
- _delay_ms(500);
-
- char *p = rcv_buf + rcv_tail;
- if (!strncmp(p, "SET BT PAIR", 11)) {
- strncpy(p + 29, "\n\0", 2);
- print_S(p);
- iwrap_mux_send(p);
- }
-}
-
-void iwrap_sleep(void) { iwrap_mux_send("SLEEP"); }
-
-void iwrap_sniff(void) {}
-
-void iwrap_subrate(void) {}
-
-bool iwrap_failed(void) {
- if (strncmp(rcv_buf, "SYNTAX ERROR", 12))
- return true;
- else
- return false;
-}
-
-uint8_t iwrap_connected(void) { return connected; }
-
-uint8_t iwrap_check_connection(void) {
- iwrap_mux_send("LIST");
- _delay_ms(100);
-
- if (strncmp(rcv_buf, "LIST ", 5) || !strncmp(rcv_buf, "LIST 0", 6))
- connected = 0;
- else
- connected = 1;
- return connected;
-}
-
-/*------------------------------------------------------------------*
- * Host driver
- *------------------------------------------------------------------*/
-static uint8_t keyboard_leds(void);
-static void send_keyboard(report_keyboard_t *report);
-static void send_mouse(report_mouse_t *report);
-static void send_system(uint16_t data);
-static void send_consumer(uint16_t data);
-
-static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
-
-host_driver_t *iwrap_driver(void) { return &driver; }
-
-static uint8_t keyboard_leds(void) { return 0; }
-
-static void send_keyboard(report_keyboard_t *report) {
- if (!iwrap_connected() && !iwrap_check_connection()) return;
- MUX_HEADER(0x01, 0x0c);
- // HID raw mode header
- xmit(0x9f);
- xmit(0x0a); // Length
- xmit(0xa1); // DATA(Input)
- xmit(0x01); // Report ID
- xmit(report->mods);
- xmit(0x00); // reserved byte(always 0)
- xmit(report->keys[0]);
- xmit(report->keys[1]);
- xmit(report->keys[2]);
- xmit(report->keys[3]);
- xmit(report->keys[4]);
- xmit(report->keys[5]);
- MUX_FOOTER(0x01);
-}
-
-static void send_mouse(report_mouse_t *report) {
-#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
- if (!iwrap_connected() && !iwrap_check_connection()) return;
- MUX_HEADER(0x01, 0x09);
- // HID raw mode header
- xmit(0x9f);
- xmit(0x07); // Length
- xmit(0xa1); // DATA(Input)
- xmit(0x02); // Report ID
- xmit(report->buttons);
- xmit(report->x);
- xmit(report->y);
- xmit(report->v);
- xmit(report->h);
- MUX_FOOTER(0x01);
-#endif
-}
-
-static void send_system(uint16_t data) { /* not supported */
-}
-
-static void send_consumer(uint16_t data) {
-#ifdef EXTRAKEY_ENABLE
- static uint16_t last_data = 0;
- uint8_t bits1 = 0;
- uint8_t bits2 = 0;
- uint8_t bits3 = 0;
-
- if (!iwrap_connected() && !iwrap_check_connection()) return;
- if (data == last_data) return;
- last_data = data;
-
- // 3.10 HID raw mode(iWRAP_HID_Application_Note.pdf)
- switch (data) {
- case AUDIO_VOL_UP:
- bits1 = 0x01;
- break;
- case AUDIO_VOL_DOWN:
- bits1 = 0x02;
- break;
- case AUDIO_MUTE:
- bits1 = 0x04;
- break;
- case TRANSPORT_PLAY_PAUSE:
- bits1 = 0x08;
- break;
- case TRANSPORT_NEXT_TRACK:
- bits1 = 0x10;
- break;
- case TRANSPORT_PREV_TRACK:
- bits1 = 0x20;
- break;
- case TRANSPORT_STOP:
- bits1 = 0x40;
- break;
- case TRANSPORT_EJECT:
- bits1 = 0x80;
- break;
- case AL_EMAIL:
- bits2 = 0x01;
- break;
- case AC_SEARCH:
- bits2 = 0x02;
- break;
- case AC_BOOKMARKS:
- bits2 = 0x04;
- break;
- case AC_HOME:
- bits2 = 0x08;
- break;
- case AC_BACK:
- bits2 = 0x10;
- break;
- case AC_FORWARD:
- bits2 = 0x20;
- break;
- case AC_STOP:
- bits2 = 0x40;
- break;
- case AC_REFRESH:
- bits2 = 0x80;
- break;
- case AL_CC_CONFIG:
- bits3 = 0x01;
- break;
- case AL_CALCULATOR:
- bits3 = 0x04;
- break;
- case AL_LOCK:
- bits3 = 0x08;
- break;
- case AL_LOCAL_BROWSER:
- bits3 = 0x10;
- break;
- case AC_MINIMIZE:
- bits3 = 0x20;
- break;
- case TRANSPORT_RECORD:
- bits3 = 0x40;
- break;
- case TRANSPORT_REWIND:
- bits3 = 0x80;
- break;
- }
-
- MUX_HEADER(0x01, 0x07);
- xmit(0x9f);
- xmit(0x05); // Length
- xmit(0xa1); // DATA(Input)
- xmit(0x03); // Report ID
- xmit(bits1);
- xmit(bits2);
- xmit(bits3);
- MUX_FOOTER(0x01);
-#endif
-}
diff --git a/tmk_core/protocol/iwrap/iwrap.h b/tmk_core/protocol/iwrap/iwrap.h
deleted file mode 100644
index 51f2b5670b..0000000000
--- a/tmk_core/protocol/iwrap/iwrap.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-Copyright 2011 Jun Wako <wakojun@gmail.com>
-
-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
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-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 IWRAP_H
-#define IWRAP_H
-
-#include <stdint.h>
-#include <stdbool.h>
-#include "host_driver.h"
-
-/* enable iWRAP MUX mode */
-#define MUX_MODE
-
-host_driver_t *iwrap_driver(void);
-
-void iwrap_init(void);
-void iwrap_send(const char *s);
-void iwrap_mux_send(const char *s);
-void iwrap_buf_send(void);
-void iwrap_buf_add(uint8_t c);
-void iwrap_buf_del(void);
-
-void iwrap_call(void);
-void iwrap_kill(void);
-void iwrap_unpair(void);
-void iwrap_sleep(void);
-void iwrap_sniff(void);
-void iwrap_subrate(void);
-bool iwrap_failed(void);
-uint8_t iwrap_connected(void);
-uint8_t iwrap_check_connection(void);
-
-#endif
diff --git a/tmk_core/protocol/iwrap/main.c b/tmk_core/protocol/iwrap/main.c
deleted file mode 100644
index 4048a9791d..0000000000
--- a/tmk_core/protocol/iwrap/main.c
+++ /dev/null
@@ -1,412 +0,0 @@
-/*
-Copyright 2011 Jun Wako <wakojun@gmail.com>
-
-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
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-#include <stdint.h>
-#include <avr/interrupt.h>
-#include <avr/io.h>
-//#include <avr/wdt.h>
-#include "wd.h" // in order to use watchdog in interrupt mode
-#include <avr/sleep.h>
-#include <util/delay.h>
-#include <avr/power.h>
-#include "keyboard.h"
-#include "matrix.h"
-#include "host.h"
-#include "action.h"
-#include "iwrap.h"
-#ifdef PROTOCOL_VUSB
-# include "vusb.h"
-# include <usbdrv/usbdrv.h>
-#endif
-#include "uart.h"
-#include "suart.h"
-#include "timer.h"
-#include "debug.h"
-#include "keycode.h"
-#include "command.h"
-
-static void sleep(uint8_t term);
-static bool console(void);
-static bool console_command(uint8_t c);
-static uint8_t key2asc(uint8_t key);
-
-/*
-static void set_prr(void)
-{
- power_adc_disable();
- power_spi_disable();
- power_twi_disable();
-#ifndef TIMER_H
- //power_timer0_disable(); // used in timer.c
-#endif
- power_timer1_disable();
- power_timer2_disable();
-}
-*/
-
-/*
-static void pullup_pins(void)
-{
- // DDRs are set to 0(input) by default.
-#ifdef PORTA
- PORTA = 0xFF;
-#endif
- PORTB = 0xFF;
- PORTC = 0xFF;
- PORTD = 0xFF;
-#ifdef PORTE
- PORTE = 0xFF;
-#endif
-#ifdef PORTE
- PORTF = 0xFF;
-#endif
-}
-*/
-
-#ifdef PROTOCOL_VUSB
-static void disable_vusb(void) {
- // disable interrupt & disconnect to prevent host from enumerating
- USB_INTR_ENABLE &= ~(1 << USB_INTR_ENABLE_BIT);
- usbDeviceDisconnect();
-}
-
-static void enable_vusb(void) {
- USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
- usbDeviceConnect();
-}
-
-static void init_vusb(void) {
- uint8_t i = 0;
-
- usbInit();
- disable_vusb();
- /* fake USB disconnect for > 250 ms */
- while (--i) {
- _delay_ms(1);
- }
- enable_vusb();
-}
-#endif
-
-void change_driver(host_driver_t *driver) {
- /*
- host_clear_keyboard_report();
- host_swap_keyboard_report();
- host_clear_keyboard_report();
- host_send_keyboard_report();
- */
- clear_keyboard();
- _delay_ms(1000);
- host_set_driver(driver);
-}
-
-static bool sleeping = false;
-static bool insomniac = false; // TODO: should be false for power saving
-static uint16_t last_timer = 0;
-
-int main(void) {
- MCUSR = 0;
- clock_prescale_set(clock_div_1);
- WD_SET(WD_OFF);
-
- // power saving: the result is worse than nothing... why?
- // pullup_pins();
- // set_prr();
-
-#ifdef PROTOCOL_VUSB
- disable_vusb();
-#endif
- uart_init(115200);
- keyboard_init();
- print("\nSend BREAK for UART Console Commands.\n");
-
- // TODO: move to iWRAP/suart file
- print("suart init\n");
- // suart init
- // PC4: Tx Output IDLE(Hi)
- PORTC |= (1 << 4);
- DDRC |= (1 << 4);
- // PC5: Rx Input(pull-up)
- PORTC |= (1 << 5);
- DDRC &= ~(1 << 5);
- // suart receive interrut(PC5/PCINT13)
- PCMSK1 = 0b00100000;
- PCICR = 0b00000010;
-
- host_set_driver(iwrap_driver());
-
- print("iwrap_init()\n");
- iwrap_init();
- iwrap_call();
-
- last_timer = timer_read();
- while (true) {
-#ifdef PROTOCOL_VUSB
- if (host_get_driver() == vusb_driver()) usbPoll();
-#endif
- keyboard_task();
-#ifdef PROTOCOL_VUSB
- if (host_get_driver() == vusb_driver()) vusb_transfer_keyboard();
-#endif
- // TODO: depricated
- if (matrix_is_modified() || console()) {
- last_timer = timer_read();
- sleeping = false;
- } else if (!sleeping && timer_elapsed(last_timer) > 4000) {
- sleeping = true;
- iwrap_check_connection();
- }
-
- // TODO: suspend.h
- if (host_get_driver() == iwrap_driver()) {
- if (sleeping && !insomniac) {
- _delay_ms(1); // wait for UART to send
- iwrap_sleep();
- sleep(WDTO_60MS);
- }
- }
- }
-}
-
-static void sleep(uint8_t term) {
- WD_SET(WD_IRQ, term);
-
- cli();
- set_sleep_mode(SLEEP_MODE_PWR_DOWN);
- sleep_enable();
- sleep_bod_disable();
- sei();
- sleep_cpu();
- sleep_disable();
-
- WD_SET(WD_OFF);
-}
-
-static bool console(void) {
- // Send to Bluetoot module WT12
- static bool breaked = false;
- if (!uart_available())
- return false;
- else {
- uint8_t c;
- c = uart_getchar();
- uart_putchar(c);
- switch (c) {
- case 0x00: // BREAK signal
- if (!breaked) {
- print("break(? for help): ");
- breaked = true;
- }
- break;
- case '\r':
- uart_putchar('\n');
- iwrap_buf_send();
- break;
- case '\b':
- iwrap_buf_del();
- break;
- default:
- if (breaked) {
- print("\n");
- console_command(c);
- breaked = false;
- } else {
- iwrap_buf_add(c);
- }
- break;
- }
- return true;
- }
-}
-
-bool command_extra(uint8_t code) { return console_command(key2asc(code)); }
-
-static bool console_command(uint8_t c) {
- switch (c) {
- case 'h':
- case '?':
- print("\nCommands for Bluetooth(WT12/iWRAP):\n");
- print("r: reset. software reset by watchdog\n");
- print("i: insomniac. prevent KB from sleeping\n");
- print("c: iwrap_call. CALL for BT connection.\n");
-#ifdef PROTOCOL_VUSB
- print("u: USB mode. switch to USB.\n");
- print("w: BT mode. switch to Bluetooth.\n");
-#endif
- print("k: kill first connection.\n");
- print("Del: unpair first pairing.\n");
- print("\n");
- return 0;
- case 'r':
- print("reset\n");
- WD_AVR_RESET();
- return 1;
- case 'i':
- insomniac = !insomniac;
- if (insomniac)
- print("insomniac\n");
- else
- print("not insomniac\n");
- return 1;
- case 'c':
- print("iwrap_call()\n");
- iwrap_call();
- return 1;
-#ifdef PROTOCOL_VUSB
- case 'u':
- print("USB mode\n");
- init_vusb();
- change_driver(vusb_driver());
- // iwrap_kill();
- // iwrap_sleep();
- // disable suart receive interrut(PC5/PCINT13)
- PCMSK1 &= ~(0b00100000);
- PCICR &= ~(0b00000010);
- return 1;
- case 'w':
- print("iWRAP mode\n");
- change_driver(iwrap_driver());
- disable_vusb();
- // enable suart receive interrut(PC5/PCINT13)
- PCMSK1 |= 0b00100000;
- PCICR |= 0b00000010;
- return 1;
-#endif
- case 'k':
- print("kill\n");
- iwrap_kill();
- return 1;
- case 0x7F: // DELETE
- print("unpair\n");
- iwrap_unpair();
- return 1;
- }
- return 0;
-}
-
-// convert keycode into ascii charactor
-static uint8_t key2asc(uint8_t key) {
- switch (key) {
- case KC_A:
- return 'a';
- case KC_B:
- return 'b';
- case KC_C:
- return 'c';
- case KC_D:
- return 'd';
- case KC_E:
- return 'e';
- case KC_F:
- return 'f';
- case KC_G:
- return 'g';
- case KC_H:
- return 'h';
- case KC_I:
- return 'i';
- case KC_J:
- return 'j';
- case KC_K:
- return 'k';
- case KC_L:
- return 'l';
- case KC_M:
- return 'm';
- case KC_N:
- return 'n';
- case KC_O:
- return 'o';
- case KC_P:
- return 'p';
- case KC_Q:
- return 'q';
- case KC_R:
- return 'r';
- case KC_S:
- return 's';
- case KC_T:
- return 't';
- case KC_U:
- return 'u';
- case KC_V:
- return 'v';
- case KC_W:
- return 'w';
- case KC_X:
- return 'x';
- case KC_Y:
- return 'y';
- case KC_Z:
- return 'z';
- case KC_1:
- return '1';
- case KC_2:
- return '2';
- case KC_3:
- return '3';
- case KC_4:
- return '4';
- case KC_5:
- return '5';
- case KC_6:
- return '6';
- case KC_7:
- return '7';
- case KC_8:
- return '8';
- case KC_9:
- return '9';
- case KC_0:
- return '0';
- case KC_ENTER:
- return '\n';
- case KC_ESCAPE:
- return 0x1B;
- case KC_BSPACE:
- return '\b';
- case KC_TAB:
- return '\t';
- case KC_SPACE:
- return ' ';
- case KC_MINUS:
- return '-';
- case KC_EQUAL:
- return '=';
- case KC_LBRACKET:
- return '[';
- case KC_RBRACKET:
- return ']';
- case KC_BSLASH:
- return '\\';
- case KC_NONUS_HASH:
- return '#';
- case KC_SCOLON:
- return ';';
- case KC_QUOTE:
- return '\'';
- case KC_GRAVE:
- return '`';
- case KC_COMMA:
- return ',';
- case KC_DOT:
- return '.';
- case KC_SLASH:
- return '/';
- default:
- return 0x00;
- }
-}
diff --git a/tmk_core/protocol/iwrap/mux_exit.rb b/tmk_core/protocol/iwrap/mux_exit.rb
deleted file mode 100644
index 1f6be48afd..0000000000
--- a/tmk_core/protocol/iwrap/mux_exit.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-#
-# Rescue from Bluegiga iWRAP MUX mode
-# 6.75 of iWRAP5_User_Guid.pdf
-#
-[0xBF, 0xFF, 0x00, 0x11, 0x53, 0x45, 0x54, 0x20, 0x43, 0x4f, 0x4e, 0x54, 0x52, 0x4f, 0x4c, 0x20, 0x4d, 0x55, 0x58, 0x20, 0x30, 0x00].each do |x|
- print x.chr
-end
diff --git a/tmk_core/protocol/iwrap/suart.S b/tmk_core/protocol/iwrap/suart.S
deleted file mode 100644
index a873515e10..0000000000
--- a/tmk_core/protocol/iwrap/suart.S
+++ /dev/null
@@ -1,156 +0,0 @@
-;---------------------------------------------------------------------------;
-; Software implemented UART module ;
-; (C)ChaN, 2005 (http://elm-chan.org/) ;
-;---------------------------------------------------------------------------;
-; Bit rate settings:
-;
-; 1MHz 2MHz 4MHz 6MHz 8MHz 10MHz 12MHz 16MHz 20MHz
-; 2.4kbps 138 - - - - - - - -
-; 4.8kbps 68 138 - - - - - - -
-; 9.6kbps 33 68 138 208 - - - - -
-; 19.2kbps - 33 68 102 138 173 208 - -
-; 38.4kbps - - 33 50 68 85 102 138 172
-; 57.6kbps - - 21 33 44 56 68 91 114
-; 115.2kbps - - - - 21 27 33 44 56
-
-.nolist
-#include <avr/io.h>
-.list
-
-#define BPS 102 /* Bit delay. (see above table) */
-#define BIDIR 0 /* 0:Separated Tx/Rx, 1:Shared Tx/Rx */
-
-#define OUT_1 sbi _SFR_IO_ADDR(SUART_OUT_PORT), SUART_OUT_BIT /* Output 1 */
-#define OUT_0 cbi _SFR_IO_ADDR(SUART_OUT_PORT), SUART_OUT_BIT /* Output 0 */
-#define SKIP_IN_1 sbis _SFR_IO_ADDR(SUART_IN_PIN), SUART_IN_BIT /* Skip if 1 */
-#define SKIP_IN_0 sbic _SFR_IO_ADDR(SUART_IN_PIN), SUART_IN_BIT /* Skip if 0 */
-
-
-
-#ifdef SPM_PAGESIZE
-.macro _LPMI reg
- lpm \reg, Z+
-.endm
-.macro _MOVW dh,dl, sh,sl
- movw \dl, \sl
-.endm
-#else
-.macro _LPMI reg
- lpm
- mov \reg, r0
- adiw ZL, 1
-.endm
-.macro _MOVW dh,dl, sh,sl
- mov \dl, \sl
- mov \dh, \sh
-.endm
-#endif
-
-
-
-;---------------------------------------------------------------------------;
-; Transmit a byte in serial format of N81
-;
-;Prototype: void xmit (uint8_t data);
-;Size: 16 words
-
-.global xmit
-.func xmit
-xmit:
-#if BIDIR
- ldi r23, BPS-1 ;Pre-idle time for bidirectional data line
-5: dec r23 ;
- brne 5b ;/
-#endif
- in r0, _SFR_IO_ADDR(SREG) ;Save flags
-
- com r24 ;C = start bit
- ldi r25, 10 ;Bit counter
- cli ;Start critical section
-
-1: ldi r23, BPS-1 ;----- Bit transferring loop
-2: dec r23 ;Wait for a bit time
- brne 2b ;/
- brcs 3f ;MISO = bit to be sent
- OUT_1 ;
-3: brcc 4f ;
- OUT_0 ;/
-4: lsr r24 ;Get next bit into C
- dec r25 ;All bits sent?
- brne 1b ; no, coutinue
-
- out _SFR_IO_ADDR(SREG), r0 ;End of critical section
- ret
-.endfunc
-
-
-
-;---------------------------------------------------------------------------;
-; Receive a byte
-;
-;Prototype: uint8_t rcvr (void);
-;Size: 19 words
-
-.global rcvr
-.func rcvr
-rcvr:
- in r0, _SFR_IO_ADDR(SREG) ;Save flags
-
- ldi r24, 0x80 ;Receiving shift reg
- cli ;Start critical section
-
-1: SKIP_IN_1 ;Wait for idle
- rjmp 1b
-2: SKIP_IN_0 ;Wait for start bit
- rjmp 2b
- ldi r25, BPS/2 ;Wait for half bit time
-3: dec r25
- brne 3b
-
-4: ldi r25, BPS ;----- Bit receiving loop
-5: dec r25 ;Wait for a bit time
- brne 5b ;/
- lsr r24 ;Next bit
- SKIP_IN_0 ;Get a data bit into r24.7
- ori r24, 0x80
- brcc 4b ;All bits received? no, continue
-
- out _SFR_IO_ADDR(SREG), r0 ;End of critical section
- ret
-.endfunc
-
-
-; Not wait for start bit. This should be called after detecting start bit.
-.global recv
-.func recv
-recv:
- in r0, _SFR_IO_ADDR(SREG) ;Save flags
-
- ldi r24, 0x80 ;Receiving shift reg
- cli ;Start critical section
-
-;1: SKIP_IN_1 ;Wait for idle
-; rjmp 1b
-;2: SKIP_IN_0 ;Wait for start bit
-; rjmp 2b
- ldi r25, BPS/2 ;Wait for half bit time
-3: dec r25
- brne 3b
-
-4: ldi r25, BPS ;----- Bit receiving loop
-5: dec r25 ;Wait for a bit time
- brne 5b ;/
- lsr r24 ;Next bit
- SKIP_IN_0 ;Get a data bit into r24.7
- ori r24, 0x80
- brcc 4b ;All bits received? no, continue
-
- ldi r25, BPS/2 ;Wait for half bit time
-6: dec r25
- brne 6b
-7: SKIP_IN_1 ;Wait for stop bit
- rjmp 7b
-
- out _SFR_IO_ADDR(SREG), r0 ;End of critical section
- ret
-.endfunc
diff --git a/tmk_core/protocol/iwrap/suart.h b/tmk_core/protocol/iwrap/suart.h
deleted file mode 100644
index c634bbc2f4..0000000000
--- a/tmk_core/protocol/iwrap/suart.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef SUART
-#define SUART
-
-void xmit(uint8_t);
-uint8_t rcvr(void);
-uint8_t recv(void);
-
-#endif /* SUART */
diff --git a/tmk_core/protocol/iwrap/wd.h b/tmk_core/protocol/iwrap/wd.h
deleted file mode 100644
index 083d6d44d6..0000000000
--- a/tmk_core/protocol/iwrap/wd.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/* This is from http://www.mtcnet.net/~henryvm/wdt/ */
-#ifndef _AVR_WD_H_
-#define _AVR_WD_H_
-
-#include <avr/io.h>
-
-/*
-Copyright (c) 2009, Curt Van Maanen
-
-Permission to use, copy, modify, and/or distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-
-include usage-
- #include "wd.h" //if in same directory as project
- #include <avr/wd.h> //if wd.h is in avr directory
-
-set watchdog modes and prescale
-
-usage-
- WD_SET(mode,[timeout]); //prescale always set
-
-modes-
- WD_OFF disabled
- WD_RST normal reset mode
- WD_IRQ interrupt only mode (if supported)
- WD_RST_IRQ interrupt+reset mode (if supported)
-
-timeout-
- WDTO_15MS default if no timeout provided
- WDTO_30MS
- WDTO_60MS
- WDTO_120MS
- WDTO_250MS
- WDTO_500MS
- WDTO_1S
- WDTO_2S
- WDTO_4S (if supported)
- WDTO_8S (if supported)
-
-examples-
- WD_SET(WD_RST,WDTO_1S); //reset mode, 1s timeout
- WD_SET(WD_OFF); //watchdog disabled (if not fused on)
- WD_SET(WD_RST); //reset mode, 15ms (default timeout)
- WD_SET(WD_IRQ,WDTO_120MS); //interrupt only mode, 120ms timeout
- WD_SET(WD_RST_IRQ,WDTO_2S); //interrupt+reset mode, 2S timeout
-
-
-for enhanced watchdogs, if the watchdog is not being used WDRF should be
-cleared on every power up or reset, along with disabling the watchdog-
- WD_DISABLE(); //clear WDRF, then turn off watchdog
-
-*/
-
-// reset registers to the same name (MCUCSR)
-#if !defined(MCUCSR)
-# define MCUCSR MCUSR
-#endif
-
-// watchdog registers to the same name (WDTCSR)
-#if !defined(WDTCSR)
-# define WDTCSR WDTCR
-#endif
-
-// if enhanced watchdog, define irq values, create disable macro
-#if defined(WDIF)
-# define WD_IRQ 0xC0
-# define WD_RST_IRQ 0xC8
-# define WD_DISABLE() \
- do { \
- MCUCSR &= ~(1 << WDRF); \
- WD_SET(WD_OFF); \
- } while (0)
-#endif
-
-// all watchdogs
-#define WD_RST 8
-#define WD_OFF 0
-
-// prescale values
-#define WDTO_15MS 0
-#define WDTO_30MS 1
-#define WDTO_60MS 2
-#define WDTO_120MS 3
-#define WDTO_250MS 4
-#define WDTO_500MS 5
-#define WDTO_1S 6
-#define WDTO_2S 7
-
-// prescale values for avrs with WDP3
-#if defined(WDP3)
-# define WDTO_4S 0x20
-# define WDTO_8S 0x21
-#endif
-
-// watchdog reset
-#define WDR() __asm__ __volatile__("wdr")
-
-// avr reset using watchdog
-#define WD_AVR_RESET() \
- do { \
- __asm__ __volatile__("cli"); \
- WD_SET_UNSAFE(WD_RST); \
- while (1) \
- ; \
- } while (0)
-
-/*set the watchdog-
-1. save SREG
-2. turn off irq's
-3. reset watchdog timer
-4. enable watchdog change
-5. write watchdog value
-6. restore SREG (restoring irq status)
-*/
-#define WD_SET(val, ...) \
- __asm__ __volatile__("in __tmp_reg__,__SREG__" \
- "\n\t" \
- "cli" \
- "\n\t" \
- "wdr" \
- "\n\t" \
- "sts %[wdreg],%[wden]" \
- "\n\t" \
- "sts %[wdreg],%[wdval]" \
- "\n\t" \
- "out __SREG__,__tmp_reg__" \
- "\n\t" \
- : \
- : [ wdreg ] "M"(&WDTCSR), [ wden ] "r"((uint8_t)(0x18)), [ wdval ] "r"((uint8_t)(val | (__VA_ARGS__ + 0))) \
- : "r0")
-
-/*set the watchdog when I bit in SREG known to be clear-
-1. reset watchdog timer
-2. enable watchdog change
-5. write watchdog value
-*/
-#define WD_SET_UNSAFE(val, ...) \
- __asm__ __volatile__("wdr" \
- "\n\t" \
- "sts %[wdreg],%[wden]" \
- "\n\t" \
- "sts %[wdreg],%[wdval]" \
- "\n\t" \
- : \
- : [ wdreg ] "M"(&WDTCSR), [ wden ] "r"((uint8_t)(0x18)), [ wdval ] "r"((uint8_t)(val | (__VA_ARGS__ + 0))))
-
-// for compatibility with avr/wdt.h
-#define wdt_enable(val) WD_SET(WD_RST, val)
-#define wdt_disable() WD_SET(WD_OFF)
-
-#endif /* _AVR_WD_H_ */
diff --git a/tmk_core/protocol/lufa.mk b/tmk_core/protocol/lufa.mk
index d87802992e..1cc1fa04e5 100644
--- a/tmk_core/protocol/lufa.mk
+++ b/tmk_core/protocol/lufa.mk
@@ -15,33 +15,28 @@ else
endif
LUFA_SRC = lufa.c \
- usb_descriptor.c \
- outputselect.c \
- $(LUFA_SRC_USB)
+ usb_descriptor.c \
+ $(LUFA_SRC_USB)
ifeq ($(strip $(MIDI_ENABLE)), yes)
include $(TMK_PATH)/protocol/midi.mk
endif
ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)
- LUFA_SRC += $(LUFA_DIR)/bluetooth.c \
- $(TMK_DIR)/protocol/serial_uart.c
+ LUFA_SRC += outputselect.c \
+ $(TMK_DIR)/protocol/serial_uart.c
endif
ifeq ($(strip $(BLUETOOTH)), AdafruitBLE)
- LUFA_SRC += spi_master.c
- LUFA_SRC += analog.c
- LUFA_SRC += $(LUFA_DIR)/adafruit_ble.cpp
-endif
-
-ifeq ($(strip $(BLUETOOTH)), AdafruitEZKey)
- LUFA_SRC += $(LUFA_DIR)/bluetooth.c \
- $(TMK_DIR)/protocol/serial_uart.c
+ LUFA_SRC += spi_master.c \
+ analog.c \
+ outputselect.c \
+ $(LUFA_DIR)/adafruit_ble.cpp
endif
ifeq ($(strip $(BLUETOOTH)), RN42)
- LUFA_SRC += $(LUFA_DIR)/bluetooth.c \
- $(TMK_DIR)/protocol/serial_uart.c
+ LUFA_SRC += outputselect.c \
+ $(TMK_DIR)/protocol/serial_uart.c
endif
ifeq ($(strip $(VIRTSER_ENABLE)), yes)
diff --git a/tmk_core/protocol/lufa/adafruit_ble.cpp b/tmk_core/protocol/lufa/adafruit_ble.cpp
index b07407f387..79b35fca31 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.cpp
+++ b/tmk_core/protocol/lufa/adafruit_ble.cpp
@@ -38,7 +38,7 @@
#ifdef SAMPLE_BATTERY
# ifndef BATTERY_LEVEL_PIN
-# define BATTERY_LEVEL_PIN 7
+# define BATTERY_LEVEL_PIN B5
# endif
#endif
@@ -556,7 +556,7 @@ void adafruit_ble_task(void) {
if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) {
state.last_battery_update = timer_read();
- state.vbat = analogRead(BATTERY_LEVEL_PIN);
+ state.vbat = analogReadPin(BATTERY_LEVEL_PIN);
}
#endif
}
diff --git a/tmk_core/protocol/lufa/adafruit_ble.h b/tmk_core/protocol/lufa/adafruit_ble.h
index cef46fe9f7..9dfc9b4355 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.h
+++ b/tmk_core/protocol/lufa/adafruit_ble.h
@@ -2,18 +2,19 @@
* Author: Wez Furlong, 2016
* Supports the Adafruit BLE board built around the nRF51822 chip.
*/
+
#pragma once
-#ifdef MODULE_ADAFRUIT_BLE
-# include <stdbool.h>
-# include <stdint.h>
-# include <string.h>
-# include "config_common.h"
-# include "progmem.h"
+#include <stdbool.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "config_common.h"
+#include "progmem.h"
-# ifdef __cplusplus
+#ifdef __cplusplus
extern "C" {
-# endif
+#endif
/* Instruct the module to enable HID keyboard support and reset */
extern bool adafruit_ble_enable_keyboard(void);
@@ -40,12 +41,12 @@ extern bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uin
* (milliseconds) */
extern bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration);
-# ifdef MOUSE_ENABLE
+#ifdef MOUSE_ENABLE
/* Send a mouse/wheel movement report.
* The parameters are signed and indicate positive of negative direction
* change. */
extern bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons);
-# endif
+#endif
/* Compute battery voltage by reading an analog pin.
* Returns the integer number of millivolts */
@@ -54,8 +55,6 @@ extern uint32_t adafruit_ble_read_battery_voltage(void);
extern bool adafruit_ble_set_mode_leds(bool on);
extern bool adafruit_ble_set_power_level(int8_t level);
-# ifdef __cplusplus
+#ifdef __cplusplus
}
-# endif
-
-#endif // MODULE_ADAFRUIT_BLE
+#endif
diff --git a/tmk_core/protocol/lufa/bluetooth.c b/tmk_core/protocol/lufa/bluetooth.c
deleted file mode 100644
index 5eb52860b1..0000000000
--- a/tmk_core/protocol/lufa/bluetooth.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-Bluefruit Protocol for TMK firmware
-Author: Benjamin Gould, 2013
- Jack Humbert, 2015
-Based on code Copyright 2011 Jun Wako <wakojun@gmail.com>
-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
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <stdint.h>
-#include "report.h"
-#include "print.h"
-#include "debug.h"
-#include "bluetooth.h"
-
-void bluefruit_keyboard_print_report(report_keyboard_t *report) {
- if (!debug_keyboard) return;
- dprintf("keys: ");
- for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
- debug_hex8(report->keys[i]);
- dprintf(" ");
- }
- dprintf(" mods: ");
- debug_hex8(report->mods);
- dprintf(" reserved: ");
- debug_hex8(report->reserved);
- dprintf("\n");
-}
-
-void bluefruit_serial_send(uint8_t data) { serial_send(data); } \ No newline at end of file
diff --git a/tmk_core/protocol/lufa/bluetooth.h b/tmk_core/protocol/lufa/bluetooth.h
deleted file mode 100644
index 081271a4e6..0000000000
--- a/tmk_core/protocol/lufa/bluetooth.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
-Bluefruit Protocol for TMK firmware
-Author: Benjamin Gould, 2013
- Jack Humbert, 2015
-Based on code Copyright 2011 Jun Wako <wakojun@gmail.com>
-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
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-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 BLUETOOTH_H
-#define BLUETOOTH_H
-
-#include "../serial.h"
-
-void bluefruit_serial_send(uint8_t data);
-
-/*
-+-----------------+-------------------+-------+
-| Consumer Key | Bit Map | Hex |
-+-----------------+-------------------+-------+
-| Home | 00000001 00000000 | 01 00 |
-| KeyboardLayout | 00000010 00000000 | 02 00 |
-| Search | 00000100 00000000 | 04 00 |
-| Snapshot | 00001000 00000000 | 08 00 |
-| VolumeUp | 00010000 00000000 | 10 00 |
-| VolumeDown | 00100000 00000000 | 20 00 |
-| Play/Pause | 01000000 00000000 | 40 00 |
-| Fast Forward | 10000000 00000000 | 80 00 |
-| Rewind | 00000000 00000001 | 00 01 |
-| Scan Next Track | 00000000 00000010 | 00 02 |
-| Scan Prev Track | 00000000 00000100 | 00 04 |
-| Random Play | 00000000 00001000 | 00 08 |
-| Stop | 00000000 00010000 | 00 10 |
-+-------------------------------------+-------+
-*/
-#define CONSUMER2BLUEFRUIT(usage) (usage == AUDIO_MUTE ? 0x0000 : (usage == AUDIO_VOL_UP ? 0x1000 : (usage == AUDIO_VOL_DOWN ? 0x2000 : (usage == TRANSPORT_NEXT_TRACK ? 0x0002 : (usage == TRANSPORT_PREV_TRACK ? 0x0004 : (usage == TRANSPORT_STOP ? 0x0010 : (usage == TRANSPORT_STOP_EJECT ? 0x0000 : (usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : (usage == AL_CC_CONFIG ? 0x0000 : (usage == AL_EMAIL ? 0x0000 : (usage == AL_CALCULATOR ? 0x0000 : (usage == AL_LOCAL_BROWSER ? 0x0000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : (usage == AC_BACK ? 0x0000 : (usage == AC_FORWARD ? 0x0000 : (usage == AC_STOP ? 0x0000 : (usage == AC_REFRESH ? 0x0000 : (usage == AC_BOOKMARKS ? 0x0000 : 0)))))))))))))))))))
-
-#define CONSUMER2RN42(usage) (usage == AUDIO_MUTE ? 0x0040 : (usage == AUDIO_VOL_UP ? 0x0010 : (usage == AUDIO_VOL_DOWN ? 0x0020 : (usage == TRANSPORT_NEXT_TRACK ? 0x0100 : (usage == TRANSPORT_PREV_TRACK ? 0x0200 : (usage == TRANSPORT_STOP ? 0x0400 : (usage == TRANSPORT_STOP_EJECT ? 0x0800 : (usage == TRANSPORT_PLAY_PAUSE ? 0x0080 : (usage == AL_EMAIL ? 0x0200 : (usage == AL_LOCAL_BROWSER ? 0x8000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : 0))))))))))))
-
-#endif
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 374add20f9..cec0044026 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -53,7 +53,6 @@
#include "lufa.h"
#include "quantum.h"
#include <util/atomic.h>
-#include "outputselect.h"
#ifdef NKRO_ENABLE
# include "keycode_config.h"
@@ -66,10 +65,11 @@ extern keymap_config_t keymap_config;
#endif
#ifdef BLUETOOTH_ENABLE
+# include "outputselect.h"
# ifdef MODULE_ADAFRUIT_BLE
# include "adafruit_ble.h"
# else
-# include "bluetooth.h"
+# include "../serial.h"
# endif
#endif
@@ -85,10 +85,54 @@ extern keymap_config_t keymap_config;
# include "raw_hid.h"
#endif
+#ifdef JOYSTICK_ENABLE
+# include "joystick.h"
+#endif
+
+// https://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf#G7.663734
+static inline uint16_t CONSUMER2RN42(uint16_t usage) {
+ switch (usage) {
+ case AC_HOME:
+ return 0x0001;
+ case AL_EMAIL:
+ return 0x0002;
+ case AC_SEARCH:
+ return 0x0004;
+ case AL_KEYBOARD_LAYOUT:
+ return 0x0008;
+ case AUDIO_VOL_UP:
+ return 0x0010;
+ case AUDIO_VOL_DOWN:
+ return 0x0020;
+ case AUDIO_MUTE:
+ return 0x0040;
+ case TRANSPORT_PLAY_PAUSE:
+ return 0x0080;
+ case TRANSPORT_NEXT_TRACK:
+ return 0x0100;
+ case TRANSPORT_PREV_TRACK:
+ return 0x0200;
+ case TRANSPORT_STOP:
+ return 0x0400;
+ case TRANSPORT_EJECT:
+ return 0x0800;
+ case TRANSPORT_FAST_FORWARD:
+ return 0x1000;
+ case TRANSPORT_REWIND:
+ return 0x2000;
+ case TRANSPORT_STOP_EJECT:
+ return 0x4000;
+ case AL_LOCAL_BROWSER:
+ return 0x8000;
+ default:
+ return 0;
+ }
+}
+
uint8_t keyboard_idle = 0;
/* 0: Boot Protocol, 1: Report Protocol(default) */
uint8_t keyboard_protocol = 1;
-static uint8_t keyboard_led_stats = 0;
+static uint8_t keyboard_led_state = 0;
static report_keyboard_t keyboard_report_sent;
@@ -103,30 +147,30 @@ host_driver_t lufa_driver = {
};
#ifdef VIRTSER_ENABLE
+// clang-format off
+
USB_ClassInfo_CDC_Device_t cdc_device = {
- .Config =
- {
- .ControlInterfaceNumber = CCI_INTERFACE,
- .DataINEndpoint =
- {
- .Address = CDC_IN_EPADDR,
- .Size = CDC_EPSIZE,
- .Banks = 1,
- },
- .DataOUTEndpoint =
- {
- .Address = CDC_OUT_EPADDR,
- .Size = CDC_EPSIZE,
- .Banks = 1,
- },
- .NotificationEndpoint =
- {
- .Address = CDC_NOTIFICATION_EPADDR,
- .Size = CDC_NOTIFICATION_EPSIZE,
- .Banks = 1,
- },
+ .Config = {
+ .ControlInterfaceNumber = CCI_INTERFACE,
+ .DataINEndpoint = {
+ .Address = (CDC_IN_EPNUM | ENDPOINT_DIR_IN),
+ .Size = CDC_EPSIZE,
+ .Banks = 1
},
+ .DataOUTEndpoint = {
+ .Address = (CDC_OUT_EPNUM | ENDPOINT_DIR_OUT),
+ .Size = CDC_EPSIZE,
+ .Banks = 1
+ },
+ .NotificationEndpoint = {
+ .Address = (CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN),
+ .Size = CDC_NOTIFICATION_EPSIZE,
+ .Banks = 1
+ }
+ }
};
+
+// clang-format on
#endif
#ifdef RAW_ENABLE
@@ -254,7 +298,7 @@ static void Console_Task(void) {
// fill empty bank
while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0);
- // flash senchar packet
+ // flush sendchar packet
if (Endpoint_IsINReady()) {
Endpoint_ClearIN();
}
@@ -264,6 +308,70 @@ static void Console_Task(void) {
#endif
/*******************************************************************************
+ * Joystick
+ ******************************************************************************/
+#ifdef JOYSTICK_ENABLE
+void send_joystick_packet(joystick_t *joystick) {
+ uint8_t timeout = 255;
+
+ joystick_report_t r = {
+# if JOYSTICK_AXES_COUNT > 0
+ .axes =
+ {
+ joystick->axes[0],
+
+# if JOYSTICK_AXES_COUNT >= 2
+ joystick->axes[1],
+# endif
+# if JOYSTICK_AXES_COUNT >= 3
+ joystick->axes[2],
+# endif
+# if JOYSTICK_AXES_COUNT >= 4
+ joystick->axes[3],
+# endif
+# if JOYSTICK_AXES_COUNT >= 5
+ joystick->axes[4],
+# endif
+# if JOYSTICK_AXES_COUNT >= 6
+ joystick->axes[5],
+# endif
+ },
+# endif // JOYSTICK_AXES_COUNT>0
+
+# if JOYSTICK_BUTTON_COUNT > 0
+ .buttons =
+ {
+ joystick->buttons[0],
+
+# if JOYSTICK_BUTTON_COUNT > 8
+ joystick->buttons[1],
+# endif
+# if JOYSTICK_BUTTON_COUNT > 16
+ joystick->buttons[2],
+# endif
+# if JOYSTICK_BUTTON_COUNT > 24
+ joystick->buttons[3],
+# endif
+ }
+# endif // JOYSTICK_BUTTON_COUNT>0
+ };
+
+ /* Select the Joystick Report Endpoint */
+ Endpoint_SelectEndpoint(JOYSTICK_IN_EPNUM);
+
+ /* Check if write ready for a polling interval around 10ms */
+ while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
+ if (!Endpoint_IsReadWriteAllowed()) return;
+
+ /* Write Joystick Report Data */
+ Endpoint_Write_Stream_LE(&r, sizeof(joystick_report_t), NULL);
+
+ /* Finalize the stream transfer to send the last packet */
+ Endpoint_ClearIN();
+}
+#endif
+
+/*******************************************************************************
* USB Events
******************************************************************************/
/*
@@ -370,45 +478,51 @@ void EVENT_USB_Device_StartOfFrame(void) {
void EVENT_USB_Device_ConfigurationChanged(void) {
bool ConfigSuccess = true;
- /* Setup Keyboard HID Report Endpoints */
#ifndef KEYBOARD_SHARED_EP
- ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup keyboard report endpoint */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((KEYBOARD_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, KEYBOARD_EPSIZE, 1);
#endif
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
- /* Setup Mouse HID Report Endpoint */
- ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup mouse report endpoint */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((MOUSE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, MOUSE_EPSIZE, 1);
#endif
#ifdef SHARED_EP_ENABLE
- /* Setup Shared HID Report Endpoint */
- ConfigSuccess &= ENDPOINT_CONFIG(SHARED_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, SHARED_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup shared report endpoint */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((SHARED_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, SHARED_EPSIZE, 1);
#endif
#ifdef RAW_ENABLE
- /* Setup Raw HID Report Endpoints */
- ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
- ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup raw HID endpoints */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1);
#endif
#ifdef CONSOLE_ENABLE
- /* Setup Console HID Report Endpoints */
- ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup console endpoint */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
# if 0
- ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
- CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
# endif
#endif
#ifdef MIDI_ENABLE
- ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
- ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup MIDI stream endpoints */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1);
#endif
#ifdef VIRTSER_ENABLE
- ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE);
- ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_OUT_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE);
- ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_IN_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup virtual serial endpoints */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, 1);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_BULK, CDC_EPSIZE, 1);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, CDC_EPSIZE, 1);
+#endif
+
+#ifdef JOYSTICK_ENABLE
+ /* Setup joystick endpoint */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((JOYSTICK_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, 1);
#endif
}
@@ -472,10 +586,10 @@ void EVENT_USB_Device_ControlRequest(void) {
uint8_t report_id = Endpoint_Read_8();
if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) {
- keyboard_led_stats = Endpoint_Read_8();
+ keyboard_led_state = Endpoint_Read_8();
}
} else {
- keyboard_led_stats = Endpoint_Read_8();
+ keyboard_led_state = Endpoint_Read_8();
}
Endpoint_ClearOUT();
@@ -545,7 +659,7 @@ void EVENT_USB_Device_ControlRequest(void) {
*
* FIXME: Needs doc
*/
-static uint8_t keyboard_leds(void) { return keyboard_led_stats; }
+static uint8_t keyboard_leds(void) { return keyboard_led_state; }
/** \brief Send Keyboard
*
@@ -553,35 +667,29 @@ static uint8_t keyboard_leds(void) { return keyboard_led_stats; }
*/
static void send_keyboard(report_keyboard_t *report) {
uint8_t timeout = 255;
- uint8_t where = where_to_send();
#ifdef BLUETOOTH_ENABLE
+ uint8_t where = where_to_send();
+
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
# ifdef MODULE_ADAFRUIT_BLE
adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys));
# elif MODULE_RN42
- bluefruit_serial_send(0xFD);
- bluefruit_serial_send(0x09);
- bluefruit_serial_send(0x01);
- bluefruit_serial_send(report->mods);
- bluefruit_serial_send(report->reserved);
- for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
- bluefruit_serial_send(report->keys[i]);
- }
-# else
- bluefruit_serial_send(0xFD);
- bluefruit_serial_send(report->mods);
- bluefruit_serial_send(report->reserved);
+ serial_send(0xFD);
+ serial_send(0x09);
+ serial_send(0x01);
+ serial_send(report->mods);
+ serial_send(report->reserved);
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
- bluefruit_serial_send(report->keys[i]);
+ serial_send(report->keys[i]);
}
# endif
}
-#endif
if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
return;
}
+#endif
/* Select the Keyboard Report Endpoint */
uint8_t ep = KEYBOARD_IN_EPNUM;
@@ -617,30 +725,31 @@ static void send_keyboard(report_keyboard_t *report) {
static void send_mouse(report_mouse_t *report) {
#ifdef MOUSE_ENABLE
uint8_t timeout = 255;
- uint8_t where = where_to_send();
# ifdef BLUETOOTH_ENABLE
+ uint8_t where = where_to_send();
+
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
# ifdef MODULE_ADAFRUIT_BLE
// FIXME: mouse buttons
adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons);
# else
- bluefruit_serial_send(0xFD);
- bluefruit_serial_send(0x00);
- bluefruit_serial_send(0x03);
- bluefruit_serial_send(report->buttons);
- bluefruit_serial_send(report->x);
- bluefruit_serial_send(report->y);
- bluefruit_serial_send(report->v); // should try sending the wheel v here
- bluefruit_serial_send(report->h); // should try sending the wheel h here
- bluefruit_serial_send(0x00);
+ serial_send(0xFD);
+ serial_send(0x00);
+ serial_send(0x03);
+ serial_send(report->buttons);
+ serial_send(report->x);
+ serial_send(report->y);
+ serial_send(report->v); // should try sending the wheel v here
+ serial_send(report->h); // should try sending the wheel h here
+ serial_send(0x00);
# endif
}
-# endif
if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
return;
}
+# endif
/* Select the Mouse Report Endpoint */
Endpoint_SelectEndpoint(MOUSE_IN_EPNUM);
@@ -695,9 +804,9 @@ static void send_system(uint16_t data) {
*/
static void send_consumer(uint16_t data) {
#ifdef EXTRAKEY_ENABLE
+# ifdef BLUETOOTH_ENABLE
uint8_t where = where_to_send();
-# ifdef BLUETOOTH_ENABLE
if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
# ifdef MODULE_ADAFRUIT_BLE
adafruit_ble_send_consumer_key(data, 0);
@@ -706,32 +815,18 @@ static void send_consumer(uint16_t data) {
if (data == last_data) return;
last_data = data;
uint16_t bitmap = CONSUMER2RN42(data);
- bluefruit_serial_send(0xFD);
- bluefruit_serial_send(0x03);
- bluefruit_serial_send(0x03);
- bluefruit_serial_send(bitmap & 0xFF);
- bluefruit_serial_send((bitmap >> 8) & 0xFF);
-# else
- static uint16_t last_data = 0;
- if (data == last_data) return;
- last_data = data;
- uint16_t bitmap = CONSUMER2BLUEFRUIT(data);
- bluefruit_serial_send(0xFD);
- bluefruit_serial_send(0x00);
- bluefruit_serial_send(0x02);
- bluefruit_serial_send((bitmap >> 8) & 0xFF);
- bluefruit_serial_send(bitmap & 0xFF);
- bluefruit_serial_send(0x00);
- bluefruit_serial_send(0x00);
- bluefruit_serial_send(0x00);
- bluefruit_serial_send(0x00);
+ serial_send(0xFD);
+ serial_send(0x03);
+ serial_send(0x03);
+ serial_send(bitmap & 0xFF);
+ serial_send((bitmap >> 8) & 0xFF);
# endif
}
-# endif
if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
return;
}
+# endif
send_extra(REPORT_ID_CONSUMER, data);
#endif
@@ -808,25 +903,26 @@ ERROR_EXIT:
******************************************************************************/
#ifdef MIDI_ENABLE
+// clang-format off
+
USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = {
- .Config =
- {
- .StreamingInterfaceNumber = AS_INTERFACE,
- .DataINEndpoint =
- {
- .Address = MIDI_STREAM_IN_EPADDR,
- .Size = MIDI_STREAM_EPSIZE,
- .Banks = 1,
- },
- .DataOUTEndpoint =
- {
- .Address = MIDI_STREAM_OUT_EPADDR,
- .Size = MIDI_STREAM_EPSIZE,
- .Banks = 1,
- },
+ .Config = {
+ .StreamingInterfaceNumber = AS_INTERFACE,
+ .DataINEndpoint = {
+ .Address = (MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN),
+ .Size = MIDI_STREAM_EPSIZE,
+ .Banks = 1
},
+ .DataOUTEndpoint = {
+ .Address = (MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_OUT),
+ .Size = MIDI_STREAM_EPSIZE,
+ .Banks = 1
+ }
+ }
};
+// clang-format on
+
void send_midi_packet(MIDI_EventPacket_t *event) { MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event); }
bool recv_midi_packet(MIDI_EventPacket_t *const event) { return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event); }
@@ -945,7 +1041,7 @@ int main(void) {
setup_usb();
sei();
-#if defined(MODULE_ADAFRUIT_EZKEY) || defined(MODULE_RN42)
+#if defined(MODULE_RN42)
serial_init();
#endif
diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h
index 82a5f8e05f..71fd7aad85 100644
--- a/tmk_core/protocol/lufa/lufa.h
+++ b/tmk_core/protocol/lufa/lufa.h
@@ -69,8 +69,4 @@ extern host_driver_t lufa_driver;
# define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
#endif
-#define ENDPOINT_BANK_SINGLE 1
-#define ENDPOINT_BANK_DOUBLE 2
-#define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum), eptype, epsize, epbank)
-
#endif
diff --git a/tmk_core/protocol/lufa/outputselect.c b/tmk_core/protocol/lufa/outputselect.c
index b115ea9691..f758c65280 100644
--- a/tmk_core/protocol/lufa/outputselect.c
+++ b/tmk_core/protocol/lufa/outputselect.c
@@ -12,8 +12,12 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "lufa.h"
#include "outputselect.h"
+
+#if defined(PROTOCOL_LUFA)
+# include "lufa.h"
+#endif
+
#ifdef MODULE_ADAFRUIT_BLE
# include "adafruit_ble.h"
#endif
@@ -35,12 +39,18 @@ void set_output(uint8_t output) {
*/
__attribute__((weak)) void set_output_user(uint8_t output) {}
+static bool is_usb_configured(void) {
+#if defined(PROTOCOL_LUFA)
+ return USB_DeviceState == DEVICE_STATE_Configured;
+#endif
+}
+
/** \brief Auto Detect Output
*
* FIXME: Needs doc
*/
uint8_t auto_detect_output(void) {
- if (USB_DeviceState == DEVICE_STATE_Configured) {
+ if (is_usb_configured()) {
return OUTPUT_USB;
}
diff --git a/tmk_core/protocol/lufa/outputselect.h b/tmk_core/protocol/lufa/outputselect.h
index 24fe4daa24..7f7ed00b95 100644
--- a/tmk_core/protocol/lufa/outputselect.h
+++ b/tmk_core/protocol/lufa/outputselect.h
@@ -12,6 +12,10 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#pragma once
+
+#include <stdint.h>
+
enum outputs {
OUTPUT_AUTO,
@@ -37,4 +41,4 @@ enum outputs {
void set_output(uint8_t output);
void set_output_user(uint8_t output);
uint8_t auto_detect_output(void);
-uint8_t where_to_send(void); \ No newline at end of file
+uint8_t where_to_send(void);
diff --git a/tmk_core/protocol/serial.h b/tmk_core/protocol/serial.h
index 93ac998983..b70d117d7c 100644
--- a/tmk_core/protocol/serial.h
+++ b/tmk_core/protocol/serial.h
@@ -35,13 +35,10 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef SERIAL_H
-#define SERIAL_H
+#pragma once
/* host role */
void serial_init(void);
uint8_t serial_recv(void);
int16_t serial_recv2(void);
void serial_send(uint8_t data);
-
-#endif
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index 8c71dd1dda..f5d32445de 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -279,6 +279,63 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
};
#endif
+#ifdef JOYSTICK_ENABLE
+# if JOYSTICK_AXES_COUNT == 0 && JOYSTICK_BUTTON_COUNT == 0
+# error Need at least one axis or button for joystick
+# endif
+const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = {
+ HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
+ HID_RI_USAGE(8, 0x04), // Joystick
+ HID_RI_COLLECTION(8, 0x01), // Application
+ HID_RI_COLLECTION(8, 0x00), // Physical
+ HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
+# if JOYSTICK_AXES_COUNT >= 1
+ HID_RI_USAGE(8, 0x30), // X
+# endif
+# if JOYSTICK_AXES_COUNT >= 2
+ HID_RI_USAGE(8, 0x31), // Y
+# endif
+# if JOYSTICK_AXES_COUNT >= 3
+ HID_RI_USAGE(8, 0x32), // Z
+# endif
+# if JOYSTICK_AXES_COUNT >= 4
+ HID_RI_USAGE(8, 0x33), // Rx
+# endif
+# if JOYSTICK_AXES_COUNT >= 5
+ HID_RI_USAGE(8, 0x34), // Ry
+# endif
+# if JOYSTICK_AXES_COUNT >= 6
+ HID_RI_USAGE(8, 0x35), // Rz
+# endif
+# if JOYSTICK_AXES_COUNT >= 1
+ HID_RI_LOGICAL_MINIMUM(8, -127),
+ HID_RI_LOGICAL_MAXIMUM(8, 127),
+ HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT),
+ HID_RI_REPORT_SIZE(8, 0x08),
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+# endif
+
+# if JOYSTICK_BUTTON_COUNT >= 1
+ HID_RI_USAGE_PAGE(8, 0x09), // Button
+ HID_RI_USAGE_MINIMUM(8, 0x01),
+ HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT),
+ HID_RI_LOGICAL_MINIMUM(8, 0x00),
+ HID_RI_LOGICAL_MAXIMUM(8, 0x01),
+ HID_RI_REPORT_COUNT(8, JOYSTICK_BUTTON_COUNT),
+ HID_RI_REPORT_SIZE(8, 0x01),
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+
+# if (JOYSTICK_BUTTON_COUNT % 8) != 0
+ HID_RI_REPORT_COUNT(8, 8 - (JOYSTICK_BUTTON_COUNT % 8)),
+ HID_RI_REPORT_SIZE(8, 0x01),
+ HID_RI_INPUT(8, HID_IOF_CONSTANT),
+# endif
+# endif
+ HID_RI_END_COLLECTION(0),
+ HID_RI_END_COLLECTION(0)
+};
+#endif
+
/*
* Device descriptor
*/
@@ -288,7 +345,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
.Type = DTYPE_Device
},
.USBSpecification = VERSION_BCD(1, 1, 0),
-
+
#if VIRTSER_ENABLE
.Class = USB_CSCP_IADDeviceClass,
.SubClass = USB_CSCP_IADDeviceSubclass,
@@ -673,7 +730,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t),
.Type = DTYPE_Endpoint
},
- .EndpointAddress = MIDI_STREAM_OUT_EPADDR,
+ .EndpointAddress = (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = MIDI_STREAM_EPSIZE,
.PollingIntervalMS = 0x05
@@ -696,7 +753,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t),
.Type = DTYPE_Endpoint
},
- .EndpointAddress = MIDI_STREAM_IN_EPADDR,
+ .EndpointAddress = (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = MIDI_STREAM_EPSIZE,
.PollingIntervalMS = 0x05
@@ -774,7 +831,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.Size = sizeof(USB_Descriptor_Endpoint_t),
.Type = DTYPE_Endpoint
},
- .EndpointAddress = CDC_NOTIFICATION_EPADDR,
+ .EndpointAddress = (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_NOTIFICATION_EPSIZE,
.PollingIntervalMS = 0xFF
@@ -797,7 +854,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.Size = sizeof(USB_Descriptor_Endpoint_t),
.Type = DTYPE_Endpoint
},
- .EndpointAddress = CDC_OUT_EPADDR,
+ .EndpointAddress = (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_EPSIZE,
.PollingIntervalMS = 0x05
@@ -807,12 +864,52 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.Size = sizeof(USB_Descriptor_Endpoint_t),
.Type = DTYPE_Endpoint
},
- .EndpointAddress = CDC_IN_EPADDR,
+ .EndpointAddress = (ENDPOINT_DIR_IN | CDC_IN_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_EPSIZE,
.PollingIntervalMS = 0x05
},
#endif
+
+ /*
+ * Joystick
+ */
+#ifdef JOYSTICK_ENABLE
+ .Joystick_Interface = {
+ .Header = {
+ .Size = sizeof(USB_Descriptor_Interface_t),
+ .Type = DTYPE_Interface
+ },
+ .InterfaceNumber = JOYSTICK_INTERFACE,
+ .AlternateSetting = 0x00,
+ .TotalEndpoints = 1,
+ .Class = HID_CSCP_HIDClass,
+ .SubClass = HID_CSCP_NonBootSubclass,
+ .Protocol = HID_CSCP_NonBootProtocol,
+ .InterfaceStrIndex = NO_DESCRIPTOR
+ },
+ .Joystick_HID = {
+ .Header = {
+ .Size = sizeof(USB_HID_Descriptor_HID_t),
+ .Type = HID_DTYPE_HID
+ },
+ .HIDSpec = VERSION_BCD(1, 1, 1),
+ .CountryCode = 0x00,
+ .TotalReportDescriptors = 1,
+ .HIDReportType = HID_DTYPE_Report,
+ .HIDReportLength = sizeof(JoystickReport)
+ },
+ .Joystick_INEndpoint = {
+ .Header = {
+ .Size = sizeof(USB_Descriptor_Endpoint_t),
+ .Type = DTYPE_Endpoint
+ },
+ .EndpointAddress = (ENDPOINT_DIR_IN | JOYSTICK_IN_EPNUM),
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = JOYSTICK_EPSIZE,
+ .PollingIntervalMS = USB_POLLING_INTERVAL_MS
+ }
+#endif
};
/*
@@ -945,6 +1042,12 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
break;
#endif
+#ifdef JOYSTICK_ENABLE
+ case JOYSTICK_INTERFACE:
+ Address = &ConfigurationDescriptor.Joystick_HID;
+ Size = sizeof(USB_HID_Descriptor_HID_t);
+ break;
+#endif
}
break;
@@ -989,6 +1092,12 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
break;
#endif
+#ifdef JOYSTICK_ENABLE
+ case JOYSTICK_INTERFACE:
+ Address = &JoystickReport;
+ Size = sizeof(JoystickReport);
+ break;
+#endif
}
break;
diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h
index b2423fa7e6..79dd87014f 100644
--- a/tmk_core/protocol/usb_descriptor.h
+++ b/tmk_core/protocol/usb_descriptor.h
@@ -123,6 +123,13 @@ typedef struct {
USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
#endif
+
+#ifdef JOYSTICK_ENABLE
+ // Joystick HID Interface
+ USB_Descriptor_Interface_t Joystick_Interface;
+ USB_HID_Descriptor_HID_t Joystick_HID;
+ USB_Descriptor_Endpoint_t Joystick_INEndpoint;
+#endif
} USB_Descriptor_Configuration_t;
/*
@@ -164,6 +171,9 @@ enum usb_interfaces {
CDI_INTERFACE,
#endif
+#if defined(JOYSTICK_ENABLE)
+ JOYSTICK_INTERFACE,
+#endif
TOTAL_INTERFACES
};
@@ -212,17 +222,16 @@ enum usb_endpoints {
#ifdef MIDI_ENABLE
MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
-# define MIDI_STREAM_IN_EPADDR (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
-# define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
#endif
#ifdef VIRTSER_ENABLE
CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
CDC_IN_EPNUM = NEXT_EPNUM,
CDC_OUT_EPNUM = NEXT_EPNUM,
-# define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM)
-# define CDC_IN_EPADDR (ENDPOINT_DIR_IN | CDC_IN_EPNUM)
-# define CDC_OUT_EPADDR (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM)
+#endif
+#ifdef JOYSTICK_ENABLE
+ JOYSTICK_IN_EPNUM = NEXT_EPNUM,
+ JOYSTICK_OUT_EPNUM = NEXT_EPNUM,
#endif
};
@@ -248,6 +257,7 @@ enum usb_endpoints {
#define MIDI_STREAM_EPSIZE 64
#define CDC_NOTIFICATION_EPSIZE 8
#define CDC_EPSIZE 16
+#define JOYSTICK_EPSIZE 8
uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const void** const DescriptorAddress);
#endif
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk
index 5e564f7480..1de6003089 100644
--- a/tmk_core/protocol/vusb.mk
+++ b/tmk_core/protocol/vusb.mk
@@ -9,13 +9,6 @@ SRC += $(VUSB_DIR)/main.c \
$(VUSB_PATH)/usbdrv/usbdrvasm.S \
$(VUSB_PATH)/usbdrv/oddebug.c
-ifneq ($(strip $(CONSOLE_ENABLE)), yes)
-ifndef NO_UART
-SRC += $(COMMON_DIR)/sendchar_uart.c \
- $(COMMON_DIR)/uart.c
-endif
-endif
-
# Search Path
VPATH += $(TMK_PATH)/$(VUSB_DIR)
VPATH += $(VUSB_PATH)
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c
index b4063273da..a57df5ce06 100644
--- a/tmk_core/protocol/vusb/main.c
+++ b/tmk_core/protocol/vusb/main.c
@@ -7,19 +7,22 @@
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
* This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
*/
+
#include <stdint.h>
+
#include <avr/interrupt.h>
+#include <avr/power.h>
#include <avr/wdt.h>
#include <avr/sleep.h>
-#include <util/delay.h>
+
#include <usbdrv/usbdrv.h>
-#include <usbdrv/oddebug.h>
+
#include "vusb.h"
+
#include "keyboard.h"
#include "host.h"
#include "timer.h"
-#include "uart.h"
-#include "debug.h"
+#include "print.h"
#include "suspend.h"
#include "wait.h"
#include "sendchar.h"
@@ -28,8 +31,6 @@
# include "sleep_led.h"
#endif
-#define UART_BAUD_RATE 115200
-
#ifdef CONSOLE_ENABLE
void console_task(void);
#endif
@@ -47,7 +48,7 @@ static void initForUsbConnectivity(void) {
usbDeviceDisconnect(); /* do this while interrupts are disabled */
while (--i) { /* fake USB disconnect for > 250 ms */
wdt_reset();
- _delay_ms(1);
+ wait_ms(1);
}
usbDeviceConnect();
}
@@ -60,7 +61,7 @@ static void usb_remote_wakeup(void) {
USBDDR = ddr_orig | USBMASK;
USBOUT ^= USBMASK;
- _delay_ms(25);
+ wait_ms(25);
USBOUT ^= USBMASK;
USBDDR = ddr_orig;
@@ -74,7 +75,6 @@ static void usb_remote_wakeup(void) {
* FIXME: Needs doc
*/
static void setup_usb(void) {
- // debug("initForUsbConnectivity()\n");
initForUsbConnectivity();
// for Console_Task
@@ -95,10 +95,7 @@ int main(void) {
#ifdef CLKPR
// avoid unintentional changes of clock frequency in devices that have a
// clock prescaler
- CLKPR = 0x80, CLKPR = 0;
-#endif
-#ifndef NO_UART
- uart_init(UART_BAUD_RATE);
+ clock_prescale_set(clock_div_1);
#endif
keyboard_setup();
@@ -113,7 +110,6 @@ int main(void) {
sleep_led_init();
#endif
- debug("main loop\n");
while (1) {
#if USB_COUNT_SOF
if (usbSofCount != 0) {
@@ -130,19 +126,6 @@ int main(void) {
# ifdef SLEEP_LED_ENABLE
sleep_led_enable();
# endif
- /*
- uart_putchar('S');
- _delay_ms(1);
- cli();
- set_sleep_mode(SLEEP_MODE_PWR_DOWN);
- sleep_enable();
- sleep_bod_disable();
- sei();
- sleep_cpu();
- sleep_disable();
- _delay_ms(10);
- uart_putchar('W');
- */
}
}
#endif
diff --git a/tmk_core/protocol/vusb/sendchar_usart.c b/tmk_core/protocol/vusb/sendchar_usart.c
deleted file mode 100644
index a920a9a536..0000000000
--- a/tmk_core/protocol/vusb/sendchar_usart.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
- */
-#include <stdint.h>
-#include <usbdrv/oddebug.h>
-#include "sendchar.h"
-
-#if DEBUG_LEVEL > 0
-/* from oddebug.c */
-int8_t sendchar(uint8_t c) {
- while (!(ODDBG_USR & (1 << ODDBG_UDRE)))
- ; /* wait for data register empty */
- ODDBG_UDR = c;
- return 1;
-}
-#else
-int8_t sendchar(uint8_t c) { return 1; }
-#endif
diff --git a/tmk_core/protocol/vusb/usbconfig.h b/tmk_core/protocol/vusb/usbconfig.h
index dcef7584c4..041f7bd095 100644
--- a/tmk_core/protocol/vusb/usbconfig.h
+++ b/tmk_core/protocol/vusb/usbconfig.h
@@ -85,9 +85,19 @@ section at the end of this file).
/* If the so-called endpoint 3 is used, it can now be configured to any other
* endpoint number (except 0) with this macro. Default if undefined is 3.
*/
+#define USB_CFG_HAVE_INTRIN_ENDPOINT4 1
+/* Define this to 1 if you want to compile a version with three endpoints: The
+ * default control endpoint 0, an interrupt-in endpoint 4 (or the number
+ * configured below) and a catch-all default interrupt-in endpoint as above.
+ * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
+ */
+#define USB_CFG_EP4_NUMBER 4
+/* If the so-called endpoint 4 is used, it can now be configured to any other
+ * endpoint number (except 0) with this macro. Default if undefined is 4.
+ */
/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */
/* The above macro defines the startup condition for data toggling on the
- * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1.
+ * interrupt/bulk endpoints 1, 3 and 4. Defaults to USBPID_DATA1.
* Since the token is toggled BEFORE sending any data, the first packet is
* sent with the oposite value of this configuration!
*/
@@ -100,10 +110,10 @@ section at the end of this file).
#define USB_CFG_SUPPRESS_INTR_CODE 0
/* Define this to 1 if you want to declare interrupt-in endpoints, but don't
* want to send any data over them. If this macro is defined to 1, functions
- * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
- * you need the interrupt-in endpoints in order to comply to an interface
- * (e.g. HID), but never want to send any data. This option saves a couple
- * of bytes in flash memory and the transmit buffers in RAM.
+ * usbSetInterrupt(), usbSetInterrupt3() and usbSetInterrupt4() are omitted.
+ * This is useful if you need the interrupt-in endpoints in order to comply
+ * to an interface (e.g. HID), but never want to send any data. This option
+ * saves a couple of bytes in flash memory and the transmit buffers in RAM.
*/
#define USB_CFG_IS_SELF_POWERED 0
/* Define this to 1 if the device has its own power supply. Set it to 0 if the
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 5feff889a1..77bbbd7bd4 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -15,10 +15,12 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <avr/wdt.h>
-#include <util/delay.h>
#include <stdint.h>
+
+#include <avr/wdt.h>
+
#include <usbdrv/usbdrv.h>
+
#include "usbconfig.h"
#include "host.h"
#include "report.h"
@@ -26,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "vusb.h"
#include "print.h"
#include "debug.h"
+#include "wait.h"
#include "usb_descriptor_common.h"
#ifdef RAW_ENABLE
@@ -56,16 +59,20 @@ enum usb_interfaces {
#ifdef CONSOLE_ENABLE
CONSOLE_INTERFACE = NEXT_INTERFACE,
#endif
- TOTAL_INTERFACES = NEXT_INTERFACE,
+ TOTAL_INTERFACES = NEXT_INTERFACE
};
-#define MAX_INTERFACES 2
+#define MAX_INTERFACES 3
#if (NEXT_INTERFACE - 1) > MAX_INTERFACES
# error There are not enough available interfaces to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Raw HID, Console
#endif
-static uint8_t vusb_keyboard_leds = 0;
+#if (defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)) && CONSOLE_ENABLE
+# error Mouse/Extra Keys share an endpoint with Console. Please disable one of the two.
+#endif
+
+static uint8_t keyboard_led_state = 0;
static uint8_t vusb_idle_rate = 0;
/* Keyboard report send buffer */
@@ -74,13 +81,7 @@ static report_keyboard_t kbuf[KBUF_SIZE];
static uint8_t kbuf_head = 0;
static uint8_t kbuf_tail = 0;
-typedef struct {
- uint8_t modifier;
- uint8_t reserved;
- uint8_t keycode[6];
-} keyboard_report_t;
-
-static keyboard_report_t keyboard_report; // sent to PC
+static report_keyboard_t keyboard_report_sent;
#define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10
@@ -92,19 +93,13 @@ void vusb_transfer_keyboard(void) {
usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
if (debug_keyboard) {
- print("V-USB: kbuf[");
- pdec(kbuf_tail);
- print("->");
- pdec(kbuf_head);
- print("](");
- phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
- print(")\n");
+ dprintf("V-USB: kbuf[%d->%d](%02X)\n", kbuf_tail, kbuf_head, (kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
}
}
break;
}
usbPoll();
- _delay_ms(1);
+ wait_ms(1);
}
}
@@ -125,16 +120,16 @@ void raw_hid_send(uint8_t *data, uint8_t length) {
uint8_t *temp = data;
for (uint8_t i = 0; i < 4; i++) {
- while (!usbInterruptIsReady3()) {
+ while (!usbInterruptIsReady4()) {
usbPoll();
}
- usbSetInterrupt3(temp, 8);
+ usbSetInterrupt4(temp, 8);
temp += 8;
}
- while (!usbInterruptIsReady3()) {
+ while (!usbInterruptIsReady4()) {
usbPoll();
}
- usbSetInterrupt3(0, 0);
+ usbSetInterrupt4(0, 0);
}
__attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) {
@@ -218,7 +213,7 @@ static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_sy
host_driver_t *vusb_driver(void) { return &driver; }
-static uint8_t keyboard_leds(void) { return vusb_keyboard_leds; }
+static uint8_t keyboard_leds(void) { return keyboard_led_state; }
static void send_keyboard(report_keyboard_t *report) {
uint8_t next = (kbuf_head + 1) % KBUF_SIZE;
@@ -226,12 +221,13 @@ static void send_keyboard(report_keyboard_t *report) {
kbuf[kbuf_head] = *report;
kbuf_head = next;
} else {
- debug("kbuf: full\n");
+ dprint("kbuf: full\n");
}
// NOTE: send key strokes of Macro
usbPoll();
vusb_transfer_keyboard();
+ keyboard_report_sent = *report;
}
typedef struct {
@@ -288,36 +284,35 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */
if (rq->bRequest == USBRQ_HID_GET_REPORT) {
- debug("GET_REPORT:");
- /* we only have one report type, so don't look at wValue */
- usbMsgPtr = (usbMsgPtr_t)&keyboard_report;
- return sizeof(keyboard_report);
+ dprint("GET_REPORT:");
+ if (rq->wIndex.word == KEYBOARD_INTERFACE) {
+ usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent;
+ return sizeof(keyboard_report_sent);
+ }
} else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
- debug("GET_IDLE: ");
- // debug_hex(vusb_idle_rate);
+ dprint("GET_IDLE:");
usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate;
return 1;
} else if (rq->bRequest == USBRQ_HID_SET_IDLE) {
vusb_idle_rate = rq->wValue.bytes[1];
- debug("SET_IDLE: ");
- debug_hex(vusb_idle_rate);
+ dprintf("SET_IDLE: %02X", vusb_idle_rate);
} else if (rq->bRequest == USBRQ_HID_SET_REPORT) {
- debug("SET_REPORT: ");
+ dprint("SET_REPORT:");
// Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard)
- if (rq->wValue.word == 0x0200 && rq->wIndex.word == 0) {
- debug("SET_LED: ");
+ if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) {
+ dprint("SET_LED:");
last_req.kind = SET_LED;
last_req.len = rq->wLength.word;
}
return USB_NO_MSG; // to get data in usbFunctionWrite
} else {
- debug("UNKNOWN:");
+ dprint("UNKNOWN:");
}
} else {
- debug("VENDOR:");
+ dprint("VENDOR:");
/* no vendor specific requests implemented */
}
- debug("\n");
+ dprint("\n");
return 0; /* default for not implemented requests: return no data back to host */
}
@@ -327,10 +322,8 @@ uchar usbFunctionWrite(uchar *data, uchar len) {
}
switch (last_req.kind) {
case SET_LED:
- debug("SET_LED: ");
- debug_hex(data[0]);
- debug("\n");
- vusb_keyboard_leds = data[0];
+ dprintf("SET_LED: %02X\n", data[0]);
+ keyboard_led_state = data[0];
last_req.len = 0;
return 1;
break;
@@ -346,13 +339,13 @@ void usbFunctionWriteOut(uchar *data, uchar len) {
#ifdef RAW_ENABLE
// Data from host must be divided every 8bytes
if (len != 8) {
- debug("RAW: invalid length");
+ dprint("RAW: invalid length\n");
raw_output_received_bytes = 0;
return;
}
if (raw_output_received_bytes + len > RAW_BUFFER_SIZE) {
- debug("RAW: buffer full");
+ dprint("RAW: buffer full\n");
raw_output_received_bytes = 0;
} else {
for (uint8_t i = 0; i < 8; i++) {
@@ -408,29 +401,6 @@ const PROGMEM uchar keyboard_hid_report[] = {
0xC0 // End Collection
};
-#ifdef RAW_ENABLE
-const PROGMEM uchar raw_hid_report[] = {
- 0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined)
- 0x09, RAW_USAGE_ID, // Usage (Vendor Defined)
- 0xA1, 0x01, // Collection (Application)
- // Data to host
- 0x09, 0x62, // Usage (Vendor Defined)
- 0x15, 0x00, // Logical Minimum (0)
- 0x26, 0xFF, 0x00, // Logical Maximum (255)
- 0x95, RAW_BUFFER_SIZE, // Report Count
- 0x75, 0x08, // Report Size (8)
- 0x81, 0x02, // Input (Data, Variable, Absolute)
- // Data from host
- 0x09, 0x63, // Usage (Vendor Defined)
- 0x15, 0x00, // Logical Minimum (0)
- 0x26, 0xFF, 0x00, // Logical Maximum (255)
- 0x95, RAW_BUFFER_SIZE, // Report Count
- 0x75, 0x08, // Report Size (8)
- 0x91, 0x02, // Output (Data, Variable, Absolute)
- 0xC0 // End Collection
-};
-#endif
-
#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
const PROGMEM uchar mouse_extra_hid_report[] = {
# ifdef MOUSE_ENABLE
@@ -515,6 +485,29 @@ const PROGMEM uchar mouse_extra_hid_report[] = {
};
#endif
+#ifdef RAW_ENABLE
+const PROGMEM uchar raw_hid_report[] = {
+ 0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined)
+ 0x09, RAW_USAGE_ID, // Usage (Vendor Defined)
+ 0xA1, 0x01, // Collection (Application)
+ // Data to host
+ 0x09, 0x62, // Usage (Vendor Defined)
+ 0x15, 0x00, // Logical Minimum (0)
+ 0x26, 0xFF, 0x00, // Logical Maximum (255)
+ 0x95, RAW_BUFFER_SIZE, // Report Count
+ 0x75, 0x08, // Report Size (8)
+ 0x81, 0x02, // Input (Data, Variable, Absolute)
+ // Data from host
+ 0x09, 0x63, // Usage (Vendor Defined)
+ 0x15, 0x00, // Logical Minimum (0)
+ 0x26, 0xFF, 0x00, // Logical Maximum (255)
+ 0x95, RAW_BUFFER_SIZE, // Report Count
+ 0x75, 0x08, // Report Size (8)
+ 0x91, 0x02, // Output (Data, Variable, Absolute)
+ 0xC0 // End Collection
+};
+#endif
+
#if defined(CONSOLE_ENABLE)
const PROGMEM uchar console_hid_report[] = {
0x06, 0x31, 0xFF, // Usage Page (Vendor Defined - PJRC Teensy compatible)
@@ -694,7 +687,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
.bLength = sizeof(usbEndpointDescriptor_t),
.bDescriptorType = USBDESCR_ENDPOINT
},
- .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP3_NUMBER),
+ .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP4_NUMBER),
.bmAttributes = 0x03,
.wMaxPacketSize = RAW_EPSIZE,
.bInterval = USB_POLLING_INTERVAL_MS
@@ -704,7 +697,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
.bLength = sizeof(usbEndpointDescriptor_t),
.bDescriptorType = USBDESCR_ENDPOINT
},
- .bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP3_NUMBER),
+ .bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP4_NUMBER),
.bmAttributes = 0x03,
.wMaxPacketSize = RAW_EPSIZE,
.bInterval = USB_POLLING_INTERVAL_MS
@@ -805,14 +798,6 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
usbMsgLen_t len = 0;
- /*
- debug("usbFunctionDescriptor: ");
- debug_hex(rq->bmRequestType); debug(" ");
- debug_hex(rq->bRequest); debug(" ");
- debug_hex16(rq->wValue.word); debug(" ");
- debug_hex16(rq->wIndex.word); debug(" ");
- debug_hex16(rq->wLength.word); debug("\n");
- */
switch (rq->wValue.bytes[1]) {
case USBDESCR_DEVICE:
usbMsgPtr = (usbMsgPtr_t)&usbDeviceDescriptor;
@@ -896,6 +881,5 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
}
break;
}
- // debug("desc len: "); debug_hex(len); debug("\n");
return len;
}
diff --git a/tmk_core/readme.md b/tmk_core/readme.md
index 5b719bca5d..a754cfee42 100644
--- a/tmk_core/readme.md
+++ b/tmk_core/readme.md
@@ -84,8 +84,8 @@ Architecture
/ /| Keys/Mouse | Protocol |d| | Action | | | Protocol |
/__________/ |<-----------| LUFA |r| | Layer, Tap | | | Matrix |
|.--------.| | LED | V-USB |i| |-------------| | | PS/2,IBM | __________________
- || || |----------->| iWRAP(BT)|v| | Keymap | | | ADB,M0110| Keys / /_/_/_/_/_/_/_/ /|
- || Host || | Console | UART |e| | Mousekey | | | SUN/NEWS |<----------/ /_/_/_/_/_/_/_/ / /
+ || || |----------->| UART |v| | Keymap | | | ADB,M0110| Keys / /_/_/_/_/_/_/_/ /|
+ || Host || | Console | |e| | Mousekey | | | SUN/NEWS |<----------/ /_/_/_/_/_/_/_/ / /
||________||/.<-----------| |r| | Report | | | X68K/PC98| Control / /_/_/_/_/_/_/_/ / /
`_========_'/| |---------------------------------------------|-------->/___ /_______/ ___/ /
|_o______o_|/ | Sendchar, Print, Debug, Command, ... | |_________________|/
@@ -133,7 +133,6 @@ Files and Directories
### Keyboard Protocols
* lufa/ - LUFA USB stack
* vusb/ - Objective Development V-USB
-* iwrap/ - Bluetooth HID for Bluegiga iWRAP
* ps2.c - PS/2 protocol
* adb.c - Apple Desktop Bus protocol
* m0110.c - Macintosh 128K/512K/Plus keyboard protocol
diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk
index 9bb341ecb1..a7053d185c 100644
--- a/tmk_core/rules.mk
+++ b/tmk_core/rules.mk
@@ -396,6 +396,12 @@ show_path:
@echo SRC=$(SRC)
@echo OBJ=$(OBJ)
+dump_vars: ERROR_IF_EMPTY=""
+dump_vars: ERROR_IF_NONBOOL=""
+dump_vars: ERROR_IF_UNSET=""
+dump_vars:
+ @$(foreach V,$(sort $(.VARIABLES)),$(if $(filter-out environment% default automatic,$(origin $V)),$(info $V=$($V))))
+
objs-size:
for i in $(OBJ); do echo $$i; done | sort | xargs $(SIZE)
@@ -436,7 +442,7 @@ $(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir -p $(OUTPUT) 2>/dev/null)))
# Listing of phony targets.
-.PHONY : all finish sizebefore sizeafter qmkversion \
+.PHONY : all dump_vars finish sizebefore sizeafter qmkversion \
gccversion build elf hex eep lss sym coff extcoff \
clean clean_list debug gdb-config show_path \
program teensy dfu dfu-ee dfu-start \