aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/avr.mk13
-rw-r--r--tmk_core/chibios.mk1
-rw-r--r--tmk_core/common.mk1
-rw-r--r--tmk_core/common/action.c27
-rw-r--r--tmk_core/common/action_code.h2
-rw-r--r--tmk_core/common/action_layer.c2
-rw-r--r--tmk_core/common/action_layer.h15
-rw-r--r--tmk_core/common/action_util.c54
-rw-r--r--tmk_core/common/action_util.h8
-rw-r--r--tmk_core/common/keyboard.c9
-rw-r--r--tmk_core/common/report.h2
-rw-r--r--tmk_core/common/sendchar_null.c2
-rw-r--r--tmk_core/protocol/bluefruit.mk11
-rw-r--r--tmk_core/protocol/bluefruit/bluefruit.c168
-rw-r--r--tmk_core/protocol/bluefruit/bluefruit.h24
-rw-r--r--tmk_core/protocol/bluefruit/main.c87
-rw-r--r--tmk_core/protocol/ibm4704.c4
-rw-r--r--tmk_core/protocol/lufa/lufa.c2
-rw-r--r--tmk_core/protocol/vusb.mk7
-rw-r--r--tmk_core/protocol/vusb/main.c47
-rw-r--r--tmk_core/protocol/vusb/usbconfig.h16
-rw-r--r--tmk_core/protocol/vusb/vusb.c279
-rw-r--r--tmk_core/protocol/vusb/vusb.h23
-rw-r--r--tmk_core/ring_buffer.h13
24 files changed, 434 insertions, 383 deletions
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk
index f5c125771..04ae16224 100644
--- a/tmk_core/avr.mk
+++ b/tmk_core/avr.mk
@@ -156,17 +156,20 @@ dfu-split-right: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
define EXEC_AVRDUDE
USB= ;\
if $(GREP) -q -s Microsoft /proc/version; then \
- echo 'ERROR: AVR flashing cannot be automated within the Windows Subsystem for Linux (WSL) currently. Instead, take the .hex file generated and flash it using AVRDUDE, AVRDUDESS, or XLoader.'; \
+ echo 'ERROR: AVR flashing cannot be automated within the Windows Subsystem for Linux (WSL) currently. Instead, take the .hex file generated and flash it using QMK Toolbox, AVRDUDE, AVRDUDESS, or XLoader.'; \
else \
printf "Detecting USB port, reset your controller now."; \
- ls /dev/tty* > /tmp/1; \
+ TMP1=`mktemp`; \
+ TMP2=`mktemp`; \
+ ls /dev/tty* > $$TMP1; \
while [ -z $$USB ]; do \
sleep 0.5; \
printf "."; \
- ls /dev/tty* > /tmp/2; \
- USB=`comm -13 /tmp/1 /tmp/2 | $(GREP) -o '/dev/tty.*'`; \
- mv /tmp/2 /tmp/1; \
+ ls /dev/tty* > $$TMP2; \
+ USB=`comm -13 $$TMP1 $$TMP2 | $(GREP) -o '/dev/tty.*'`; \
+ mv $$TMP2 $$TMP1; \
done; \
+ rm $$TMP1; \
echo ""; \
echo "Device $$USB has appeared; assuming it is the controller."; \
if $(GREP) -q -s 'MINGW\|MSYS' /proc/version; then \
diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk
index 6bacabbbf..d0f1032ac 100644
--- a/tmk_core/chibios.mk
+++ b/tmk_core/chibios.mk
@@ -233,7 +233,6 @@ LDFLAGS += -mno-thumb-interwork -mthumb
LDSYMBOLS =,--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE)
LDSYMBOLS :=$(LDSYMBOLS),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE)
LDFLAGS += -Wl,--script=$(LDSCRIPT)$(LDSYMBOLS)
-LDFLAGS += --specs=nano.specs
OPT_DEFS += -DPROTOCOL_CHIBIOS
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 3d0b83a01..aa8a0eb7a 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -10,6 +10,7 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \
$(COMMON_DIR)/action_util.c \
$(COMMON_DIR)/print.c \
$(COMMON_DIR)/debug.c \
+ $(COMMON_DIR)/sendchar_null.c \
$(COMMON_DIR)/util.c \
$(COMMON_DIR)/eeconfig.c \
$(COMMON_DIR)/report.c \
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index e5e9e2705..3b1268dc9 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -98,6 +98,11 @@ void action_exec(keyevent_t event) {
if (has_oneshot_mods_timed_out()) {
clear_oneshot_mods();
}
+# ifdef SWAP_HANDS_ENABLE
+ if (has_oneshot_swaphands_timed_out()) {
+ clear_oneshot_swaphands();
+ }
+# endif
# endif
#endif
@@ -165,6 +170,8 @@ void process_record_tap_hint(keyrecord_t *record) {
# ifdef SWAP_HANDS_ENABLE
case ACT_SWAP_HANDS:
switch (action.swap.code) {
+ case OP_SH_ONESHOT:
+ break;
case OP_SH_TAP_TOGGLE:
default:
swap_hands = !swap_hands;
@@ -224,7 +231,11 @@ void process_action(keyrecord_t *record, action_t action) {
#ifndef NO_ACTION_ONESHOT
bool do_release_oneshot = false;
// notice we only clear the one shot layer if the pressed key is not a modifier.
- if (is_oneshot_layer_active() && event.pressed && !IS_MOD(action.key.code)) {
+ if (is_oneshot_layer_active() && event.pressed && !IS_MOD(action.key.code)
+# ifdef SWAP_HANDS_ENABLE
+ && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT)
+# endif
+ ) {
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
do_release_oneshot = !is_oneshot_layer_active();
}
@@ -593,6 +604,14 @@ void process_action(keyrecord_t *record, action_t action) {
swap_hands = false;
}
break;
+ case OP_SH_ONESHOT:
+ if (event.pressed) {
+ set_oneshot_swaphands();
+ } else {
+ release_oneshot_swaphands();
+ }
+ break;
+
# ifndef NO_ACTION_TAPPING
case OP_SH_TAP_TOGGLE:
/* tap toggle */
@@ -681,6 +700,12 @@ void process_action(keyrecord_t *record, action_t action) {
# endif
#endif
+#ifdef SWAP_HANDS_ENABLE
+ if (event.pressed && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT)) {
+ use_oneshot_swaphands();
+ }
+#endif
+
#ifndef NO_ACTION_ONESHOT
/* Because we switch layers after a oneshot event, we need to release the
* key before we leave the layer or no key up event will be generated.
diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h
index f80b7a782..eea554ff2 100644
--- a/tmk_core/common/action_code.h
+++ b/tmk_core/common/action_code.h
@@ -294,11 +294,13 @@ enum swap_hands_param_tap_op {
OP_SH_OFF_ON,
OP_SH_OFF,
OP_SH_ON,
+ OP_SH_ONESHOT,
};
#define ACTION_SWAP_HANDS() ACTION_SWAP_HANDS_ON_OFF()
#define ACTION_SWAP_HANDS_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TOGGLE)
#define ACTION_SWAP_HANDS_TAP_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TAP_TOGGLE)
+#define ACTION_SWAP_HANDS_ONESHOT() ACTION(ACT_SWAP_HANDS, OP_SH_ONESHOT)
#define ACTION_SWAP_HANDS_TAP_KEY(key) ACTION(ACT_SWAP_HANDS, key)
#define ACTION_SWAP_HANDS_ON_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_ON_OFF)
#define ACTION_SWAP_HANDS_OFF_ON() ACTION(ACT_SWAP_HANDS, OP_SH_OFF_ON)
diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c
index 81f86f0f3..af2d7d964 100644
--- a/tmk_core/common/action_layer.c
+++ b/tmk_core/common/action_layer.c
@@ -257,7 +257,7 @@ uint8_t layer_switch_get_layer(keypos_t key) {
layer_state_t layers = layer_state | default_layer_state;
/* check top layer first */
- for (int8_t i = sizeof(layer_state_t) * 8 - 1; i >= 0; i--) {
+ for (int8_t i = MAX_LAYER - 1; i >= 0; i--) {
if (layers & (1UL << i)) {
action = action_for_key(i, key);
if (action.code != ACTION_TRANSPARENT) {
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h
index c283d2623..16922c1ff 100644
--- a/tmk_core/common/action_layer.h
+++ b/tmk_core/common/action_layer.h
@@ -23,12 +23,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#if defined(LAYER_STATE_8BIT)
typedef uint8_t layer_state_t;
+# define MAX_LAYER_BITS 3
+# ifndef MAX_LAYER
+# define MAX_LAYER 8
+# endif
# define get_highest_layer(state) biton(state)
#elif defined(LAYER_STATE_16BIT)
typedef uint16_t layer_state_t;
+# define MAX_LAYER_BITS 4
+# ifndef MAX_LAYER
+# define MAX_LAYER 16
+# endif
# define get_highest_layer(state) biton16(state)
#else
typedef uint32_t layer_state_t;
+# define MAX_LAYER_BITS 5
+# ifndef MAX_LAYER
+# define MAX_LAYER 32
+# endif
# define get_highest_layer(state) biton32(state)
#endif
@@ -96,8 +108,7 @@ layer_state_t layer_state_set_kb(layer_state_t state);
/* pressed actions cache */
#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
-/* The number of bits needed to represent the layer number: log2(32). */
-# define MAX_LAYER_BITS 5
+
void update_source_layers_cache(keypos_t key, uint8_t layer);
uint8_t read_source_layers_cache(keypos_t key);
#endif
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c
index 335aa36e6..371acfa61 100644
--- a/tmk_core/common/action_util.c
+++ b/tmk_core/common/action_util.c
@@ -83,9 +83,63 @@ static int8_t oneshot_layer_data = 0;
inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; }
inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; }
+# ifdef SWAP_HANDS_ENABLE
+enum {
+ SHO_OFF,
+ SHO_ACTIVE, // Swap hands button was pressed, and we didn't send any swapped keys yet
+ SHO_PRESSED, // Swap hands button is currently pressed
+ SHO_USED, // Swap hands button is still pressed, and we already sent swapped keys
+} swap_hands_oneshot = SHO_OFF;
+# endif
+
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
static uint16_t oneshot_layer_time = 0;
inline bool has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); }
+# ifdef SWAP_HANDS_ENABLE
+static uint16_t oneshot_swaphands_time = 0;
+inline bool has_oneshot_swaphands_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_swaphands_time) >= ONESHOT_TIMEOUT && !(swap_hands_oneshot >= SHO_PRESSED); }
+# endif
+# endif
+
+# ifdef SWAP_HANDS_ENABLE
+
+void set_oneshot_swaphands(void) {
+ swap_hands_oneshot = SHO_PRESSED;
+ swap_hands = true;
+# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+ oneshot_swaphands_time = timer_read();
+ if (oneshot_layer_time != 0) {
+ oneshot_layer_time = oneshot_swaphands_time;
+ }
+# endif
+}
+
+void release_oneshot_swaphands(void) {
+ if (swap_hands_oneshot == SHO_PRESSED) {
+ swap_hands_oneshot = SHO_ACTIVE;
+ }
+ if (swap_hands_oneshot == SHO_USED) {
+ clear_oneshot_swaphands();
+ }
+}
+
+void use_oneshot_swaphands(void) {
+ if (swap_hands_oneshot == SHO_PRESSED) {
+ swap_hands_oneshot = SHO_USED;
+ }
+ if (swap_hands_oneshot == SHO_ACTIVE) {
+ clear_oneshot_swaphands();
+ }
+}
+
+void clear_oneshot_swaphands(void) {
+ swap_hands_oneshot = SHO_OFF;
+ swap_hands = false;
+# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
+ oneshot_swaphands_time = 0;
+# endif
+}
+
# endif
/** \brief Set oneshot layer
diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h
index 1ce03ed0e..5dd8393da 100644
--- a/tmk_core/common/action_util.h
+++ b/tmk_core/common/action_util.h
@@ -77,6 +77,7 @@ void reset_oneshot_layer(void);
bool is_oneshot_layer_active(void);
uint8_t get_oneshot_layer_state(void);
bool has_oneshot_layer_timed_out(void);
+bool has_oneshot_swaphands_timed_out(void);
void oneshot_locked_mods_changed_user(uint8_t mods);
void oneshot_locked_mods_changed_kb(uint8_t mods);
@@ -88,6 +89,13 @@ void oneshot_layer_changed_kb(uint8_t layer);
/* inspect */
uint8_t has_anymod(void);
+#ifdef SWAP_HANDS_ENABLE
+void set_oneshot_swaphands(void);
+void release_oneshot_swaphands(void);
+void use_oneshot_swaphands(void);
+void clear_oneshot_swaphands(void);
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index a767d9c87..53d08959e 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -213,6 +213,13 @@ void keyboard_setup(void) {
*/
__attribute__((weak)) bool is_keyboard_master(void) { return true; }
+/** \brief should_process_keypress
+ *
+ * Override this function if you have a condition where keypresses processing should change:
+ * - splits where the slave side needs to process for rgb/oled functionality
+ */
+__attribute__((weak)) bool should_process_keypress(void) { return is_keyboard_master(); }
+
/** \brief keyboard_init
*
* FIXME: needs doc
@@ -292,7 +299,7 @@ void keyboard_task(void) {
matrix_scan();
#endif
- if (is_keyboard_master()) {
+ if (should_process_keypress()) {
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
matrix_row = matrix_get_row(r);
matrix_change = matrix_row ^ matrix_prev[r];
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index 61ef6ea66..c2b1b7c71 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -69,6 +69,8 @@ enum consumer_usages {
AL_CALCULATOR = 0x192,
AL_LOCAL_BROWSER = 0x194,
AL_LOCK = 0x19E,
+ AL_CONTROL_PANEL = 0x19F,
+ AL_ASSISTANT = 0x1CB,
// 15.16 Generic GUI Application Controls
AC_MINIMIZE = 0x206,
AC_SEARCH = 0x221,
diff --git a/tmk_core/common/sendchar_null.c b/tmk_core/common/sendchar_null.c
index f6cab1b9d..fb67f7086 100644
--- a/tmk_core/common/sendchar_null.c
+++ b/tmk_core/common/sendchar_null.c
@@ -16,4 +16,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sendchar.h"
-int8_t sendchar(uint8_t c) { return 0; }
+__attribute__((weak)) int8_t sendchar(uint8_t c) { return 0; }
diff --git a/tmk_core/protocol/bluefruit.mk b/tmk_core/protocol/bluefruit.mk
deleted file mode 100644
index 13a0693c5..000000000
--- a/tmk_core/protocol/bluefruit.mk
+++ /dev/null
@@ -1,11 +0,0 @@
-BLUEFRUIT_DIR = protocol/bluefruit
-
-SRC += $(BLUEFRUIT_DIR)/main.c \
- $(BLUEFRUIT_DIR)/bluefruit.c \
- serial_uart.c
-
-# Search Path
-VPATH += $(TMK_DIR)/$(BLUEFRUIT_DIR)
-#VPATH += $(TMK_DIR)/$(BLUEFRUIT_DIR)/usb_debug_only
-
-OPT_DEFS += -DPROTOCOL_BLUEFRUIT
diff --git a/tmk_core/protocol/bluefruit/bluefruit.c b/tmk_core/protocol/bluefruit/bluefruit.c
deleted file mode 100644
index fb001855e..000000000
--- a/tmk_core/protocol/bluefruit/bluefruit.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
-Bluefruit Protocol for TMK firmware
-Author: Benjamin Gould, 2013
-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 "host.h"
-#include "report.h"
-#include "print.h"
-#include "debug.h"
-#include "host_driver.h"
-#include "serial.h"
-#include "bluefruit.h"
-
-#define BLUEFRUIT_TRACE_SERIAL 1
-
-static uint8_t bluefruit_keyboard_leds = 0;
-
-static void bluefruit_serial_send(uint8_t);
-
-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");
-}
-
-#ifdef BLUEFRUIT_TRACE_SERIAL
-static void bluefruit_trace_header() {
- dprintf("+------------------------------------+\n");
- dprintf("| HID report to Bluefruit via serial |\n");
- dprintf("+------------------------------------+\n|");
-}
-
-static void bluefruit_trace_footer() { dprintf("|\n+------------------------------------+\n\n"); }
-#endif
-
-static void bluefruit_serial_send(uint8_t data) {
-#ifdef BLUEFRUIT_TRACE_SERIAL
- dprintf(" ");
- debug_hex8(data);
- dprintf(" ");
-#endif
- serial_send(data);
-}
-
-/*------------------------------------------------------------------*
- * 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);
-
-void sendString(char string[], int length) {
- for (int i = 0; i < length; i++) {
- serial_send(string[i]);
- }
-}
-
-static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
-
-host_driver_t *bluefruit_driver(void) { return &driver; }
-
-static uint8_t keyboard_leds(void) { return bluefruit_keyboard_leds; }
-
-static void send_keyboard(report_keyboard_t *report) {
-#ifdef BLUEFRUIT_TRACE_SERIAL
- bluefruit_trace_header();
-#endif
- bluefruit_serial_send(0xFD);
- for (uint8_t i = 0; i < KEYBOARD_REPORT_SIZE; i++) {
- bluefruit_serial_send(report->raw[i]);
- }
-#ifdef BLUEFRUIT_TRACE_SERIAL
- bluefruit_trace_footer();
-#endif
-}
-
-static void send_mouse(report_mouse_t *report) {
-#ifdef BLUEFRUIT_TRACE_SERIAL
- bluefruit_trace_header();
-#endif
- 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);
-#ifdef BLUEFRUIT_TRACE_SERIAL
- bluefruit_trace_footer();
-#endif
-}
-
-static void send_system(uint16_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)))))))))))))))))))
-
-static void send_consumer(uint16_t data) {
- static uint16_t last_data = 0;
- if (data == last_data) return;
- last_data = data;
-
- uint16_t bitmap = CONSUMER2BLUEFRUIT(data);
-
-#ifdef BLUEFRUIT_TRACE_SERIAL
- dprintf("\nData: ");
- debug_hex16(data);
- dprintf("; bitmap: ");
- debug_hex16(bitmap);
- dprintf("\n");
- bluefruit_trace_header();
-#endif
- 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);
-#ifdef BLUEFRUIT_TRACE_SERIAL
- bluefruit_trace_footer();
-#endif
-} \ No newline at end of file
diff --git a/tmk_core/protocol/bluefruit/bluefruit.h b/tmk_core/protocol/bluefruit/bluefruit.h
deleted file mode 100644
index 7b636abb9..000000000
--- a/tmk_core/protocol/bluefruit/bluefruit.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
-Bluefruit Protocol for TMK firmware
-Author: Benjamin Gould, 2013
-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 VUSB_H
-#define VUSB_H
-
-#include "host_driver.h"
-
-host_driver_t *bluefruit_driver(void);
-
-#endif \ No newline at end of file
diff --git a/tmk_core/protocol/bluefruit/main.c b/tmk_core/protocol/bluefruit/main.c
deleted file mode 100644
index aca46206d..000000000
--- a/tmk_core/protocol/bluefruit/main.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
-Bluefruit Protocol for TMK firmware
-Author: Benjamin Gould, 2013
-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 <avr/interrupt.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <util/delay.h>
-#include "../serial.h"
-#include "keyboard.h"
-#include "host.h"
-#include "timer.h"
-#include "print.h"
-#include "debug.h"
-#include "sendchar.h"
-#include "suspend.h"
-#include "bluefruit.h"
-
-#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
-
-int main(void) {
- CPU_PRESCALE(0);
-
- // DDRD = _BV(PD5);
- // DDRB = _BV(PB0);
-
- // PORTD = _BV(PD5);
- // PORTB = _BV(PB0);
-
- print_set_sendchar(sendchar);
-
- keyboard_setup();
-
- dprintf("Initializing keyboard...\n");
- keyboard_init();
-
- dprintf("Setting host driver to bluefruit...\n");
- host_set_driver(bluefruit_driver());
-
- dprintf("Initializing serial...\n");
- serial_init();
-
- // char swpa[] = "+++\r\n";
- // for (int i = 0; i < 5; i++) {
- // serial_send(swpa[i]);
- // }
-
- // char ble_enable[] = "AT+BLEKEYBOARDEN=1\r\n";
- // for (int i = 0; i < 20; i++) {
- // serial_send(ble_enable[i]);
- // }
-
- // char reset[] = "ATZ\r\n";
- // for (int i = 0; i < 5; i++) {
- // serial_send(reset[i]);
- // }
-
- // for (int i = 0; i < 5; i++) {
- // serial_send(swpa[i]);
- // }
-
- // wait an extra second for the PC's operating system
- // to load drivers and do whatever it does to actually
- // be ready for input
- _delay_ms(1000);
- // PORTD = ~_BV(PD5);
- dprintf("Starting main loop");
- while (1) {
- keyboard_task();
- }
-}
diff --git a/tmk_core/protocol/ibm4704.c b/tmk_core/protocol/ibm4704.c
index fd8fc4dbd..a19443976 100644
--- a/tmk_core/protocol/ibm4704.c
+++ b/tmk_core/protocol/ibm4704.c
@@ -161,7 +161,9 @@ ISR(IBM4704_INT_VECT) {
case STOP:
// Data:Low
WAIT(data_lo, 100, state);
- rbuf_enqueue(data);
+ if (!rbuf_enqueue(data)) {
+ print("rbuf: full\n");
+ }
ibm4704_error = IBM4704_ERR_NONE;
goto DONE;
break;
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index d673841fd..374add20f 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -801,8 +801,6 @@ ERROR_EXIT:
Endpoint_SelectEndpoint(ep);
return -1;
}
-#else
-int8_t sendchar(uint8_t c) { return 0; }
#endif
/*******************************************************************************
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk
index 897b833e1..6df0d0d33 100644
--- a/tmk_core/protocol/vusb.mk
+++ b/tmk_core/protocol/vusb.mk
@@ -9,13 +9,12 @@ SRC += $(VUSB_DIR)/main.c \
$(VUSB_DIR)/usbdrv/oddebug.c
-ifdef NO_UART
-SRC += $(COMMON_DIR)/sendchar_null.c
-else
+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)
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c
index 610638e7d..7dc16926d 100644
--- a/tmk_core/protocol/vusb/main.c
+++ b/tmk_core/protocol/vusb/main.c
@@ -21,12 +21,23 @@
#include "uart.h"
#include "debug.h"
#include "suspend.h"
+#include "wait.h"
+#include "sendchar.h"
+
#ifdef SLEEP_LED_ENABLE
# include "sleep_led.h"
#endif
#define UART_BAUD_RATE 115200
+#ifdef CONSOLE_ENABLE
+void console_task(void);
+#endif
+
+#ifdef RAW_ENABLE
+void raw_hid_task(void);
+#endif
+
/* This is from main.c of USBaspLoader */
static void initForUsbConnectivity(void) {
uint8_t i = 0;
@@ -39,10 +50,9 @@ static void initForUsbConnectivity(void) {
_delay_ms(1);
}
usbDeviceConnect();
- sei();
}
-void usb_remote_wakeup(void) {
+static void usb_remote_wakeup(void) {
cli();
int8_t ddr_orig = USBDDR;
@@ -59,6 +69,23 @@ void usb_remote_wakeup(void) {
sei();
}
+/** \brief Setup USB
+ *
+ * FIXME: Needs doc
+ */
+static void setup_usb(void) {
+ // debug("initForUsbConnectivity()\n");
+ initForUsbConnectivity();
+
+ // for Console_Task
+ print_set_sendchar(sendchar);
+}
+
+/** \brief Main
+ *
+ * FIXME: Needs doc
+ */
+int main(void) __attribute__((weak));
int main(void) {
bool suspended = false;
#if USB_COUNT_SOF
@@ -76,8 +103,10 @@ int main(void) {
keyboard_setup();
host_set_driver(vusb_driver());
- debug("initForUsbConnectivity()\n");
- initForUsbConnectivity();
+ setup_usb();
+ sei();
+
+ wait_ms(50);
keyboard_init();
#ifdef SLEEP_LED_ENABLE
@@ -120,12 +149,13 @@ int main(void) {
if (!suspended) {
usbPoll();
- // TODO: configuration process is incosistent. it sometime fails.
+ // TODO: configuration process is inconsistent. it sometime fails.
// To prevent failing to configure NOT scan keyboard during configuration
if (usbConfiguration && usbInterruptIsReady()) {
keyboard_task();
}
vusb_transfer_keyboard();
+
#ifdef RAW_ENABLE
usbPoll();
@@ -133,6 +163,13 @@ int main(void) {
raw_hid_task();
}
#endif
+#ifdef CONSOLE_ENABLE
+ usbPoll();
+
+ if (usbConfiguration && usbInterruptIsReady3()) {
+ console_task();
+ }
+#endif
} else if (suspend_wakeup_condition()) {
usb_remote_wakeup();
}
diff --git a/tmk_core/protocol/vusb/usbconfig.h b/tmk_core/protocol/vusb/usbconfig.h
index f118dc8ed..dcef7584c 100644
--- a/tmk_core/protocol/vusb/usbconfig.h
+++ b/tmk_core/protocol/vusb/usbconfig.h
@@ -24,15 +24,21 @@ section at the end of this file).
/* ---------------------------- Hardware Config ---------------------------- */
+#ifndef USB_CFG_IOPORTNAME
#define USB_CFG_IOPORTNAME D
+#endif
/* This is the port where the USB bus is connected. When you configure it to
* "B", the registers PORTB, PINB and DDRB will be used.
*/
+#ifndef USB_CFG_DMINUS_BIT
#define USB_CFG_DMINUS_BIT 3
+#endif
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
* This may be any bit in the port.
*/
+#ifndef USB_CFG_DPLUS_BIT
#define USB_CFG_DPLUS_BIT 2
+#endif
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
* This may be any bit in the port. Please note that D+ must also be connected
* to interrupt pin INT0! [You can also use other interrupts, see section
@@ -151,7 +157,9 @@ section at the end of this file).
/* This macro (if defined) is executed when a USB SET_ADDRESS request was
* received.
*/
+#ifndef USB_COUNT_SOF
#define USB_COUNT_SOF 1
+#endif
/* define this macro to 1 if you need the global variable "usbSofCount" which
* counts SOF packets. This feature requires that the hardware interrupt is
* connected to D- instead of D+.
@@ -321,10 +329,18 @@ section at the end of this file).
/* Set INT1 for D- falling edge to count SOF */
/* #define USB_INTR_CFG EICRA */
+#ifndef USB_INTR_CFG_SET
#define USB_INTR_CFG_SET ((1 << ISC11) | (0 << ISC10))
+#endif
/* #define USB_INTR_CFG_CLR 0 */
/* #define USB_INTR_ENABLE EIMSK */
+#ifndef USB_INTR_ENABLE_BIT
#define USB_INTR_ENABLE_BIT INT1
+#endif
/* #define USB_INTR_PENDING EIFR */
+#ifndef USB_INTR_PENDING_BIT
#define USB_INTR_PENDING_BIT INTF1
+#endif
+#ifndef USB_INTR_VECTOR
#define USB_INTR_VECTOR INT1_vect
+#endif
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index c4baf5ab0..a9f37c61b 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -15,25 +15,53 @@ 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/eeprom.h>
#include <avr/wdt.h>
+#include <util/delay.h>
#include <stdint.h>
#include "usbdrv.h"
#include "usbconfig.h"
#include "host.h"
#include "report.h"
-#include "print.h"
-#include "debug.h"
#include "host_driver.h"
#include "vusb.h"
-#include <util/delay.h>
+#include "print.h"
+#include "debug.h"
#ifdef RAW_ENABLE
# include "raw_hid.h"
#endif
-#if (defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)) && defined(RAW_ENABLE)
-# error "Enabling Mousekeys/Extrakeys and Raw HID at the same time is not currently supported on V-USB."
+#if defined(CONSOLE_ENABLE)
+# define RBUF_SIZE 128
+# include "ring_buffer.h"
+#endif
+
+#define NEXT_INTERFACE __COUNTER__
+
+/*
+ * Interface indexes
+ */
+enum usb_interfaces {
+ KEYBOARD_INTERFACE = NEXT_INTERFACE,
+// It is important that the Raw HID interface is at a constant
+// interface number, to support Linux/OSX platforms and chrome.hid
+// If Raw HID is enabled, let it be always 1.
+#ifdef RAW_ENABLE
+ RAW_INTERFACE = NEXT_INTERFACE,
+#endif
+#if (defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE))
+ MOUSE_EXTRA_INTERFACE = NEXT_INTERFACE,
+#endif
+#ifdef CONSOLE_ENABLE
+ CONSOLE_INTERFACE = NEXT_INTERFACE,
+#endif
+ TOTAL_INTERFACES = NEXT_INTERFACE,
+};
+
+#define MAX_INTERFACES 2
+
+#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;
@@ -120,7 +148,60 @@ void raw_hid_task(void) {
raw_output_received_bytes = 0;
}
}
+#endif
+
+/*------------------------------------------------------------------*
+ * Console
+ *------------------------------------------------------------------*/
+#ifdef CONSOLE_ENABLE
+# define CONSOLE_BUFFER_SIZE 32
+# define CONSOLE_EPSIZE 8
+
+int8_t sendchar(uint8_t c) {
+ rbuf_enqueue(c);
+ return 0;
+}
+
+static inline bool usbSendData3(char *data, uint8_t len) {
+ uint8_t retries = 5;
+ while (!usbInterruptIsReady3()) {
+ if (!(retries--)) {
+ return false;
+ }
+ usbPoll();
+ }
+
+ usbSetInterrupt3((unsigned char *)data, len);
+ return true;
+}
+void console_task(void) {
+ if (!usbConfiguration) {
+ return;
+ }
+
+ if (!rbuf_has_data()) {
+ return;
+ }
+
+ // Send in chunks of 8 padded to 32
+ char send_buf[CONSOLE_BUFFER_SIZE] = {0};
+ uint8_t send_buf_count = 0;
+ while (rbuf_has_data() && send_buf_count < CONSOLE_EPSIZE) {
+ send_buf[send_buf_count++] = rbuf_dequeue();
+ }
+
+ char *temp = send_buf;
+ for (uint8_t i = 0; i < 4; i++) {
+ if (!usbSendData3(temp, 8)) {
+ break;
+ }
+ temp += 8;
+ }
+
+ usbSendData3(0, 0);
+ usbPoll();
+}
#endif
/*------------------------------------------------------------------*
@@ -326,6 +407,29 @@ const PROGMEM uchar keyboard_hid_report[] = {
0xC0 // End Collection
};
+#ifdef RAW_ENABLE
+const PROGMEM uchar raw_hid_report[] = {
+ 0x06, 0x60, 0xFF, // Usage Page (Vendor Defined)
+ 0x09, 0x61, // 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
@@ -410,26 +514,26 @@ const PROGMEM uchar mouse_extra_hid_report[] = {
};
#endif
-#ifdef RAW_ENABLE
-const PROGMEM uchar raw_hid_report[] = {
- 0x06, 0x60, 0xFF, // Usage Page (Vendor Defined)
- 0x09, 0x61, // Usage (Vendor Defined)
+#if defined(CONSOLE_ENABLE)
+const PROGMEM uchar console_hid_report[] = {
+ 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined - PJRC Teensy compatible)
+ 0x09, 0x74, // Usage (Vendor Defined - PJRC Teensy compatible)
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)
+ 0x09, 0x75, // Usage (Vendor Defined)
+ 0x15, 0x00, // Logical Minimum (0x00)
+ 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF)
+ 0x95, CONSOLE_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
+ 0x09, 0x76, // Usage (Vendor Defined)
+ 0x15, 0x00, // Logical Minimum (0x00)
+ 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF)
+ 0x95, CONSOLE_BUFFER_SIZE, // Report Count
+ 0x75, 0x08, // Report Size (8)
+ 0x91, 0x02, // Output (Data)
+ 0xC0 // End Collection
};
#endif
@@ -511,11 +615,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
.bDescriptorType = USBDESCR_CONFIG
},
.wTotalLength = sizeof(usbConfigurationDescriptor_t),
-# if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) || defined(RAW_ENABLE)
- .bNumInterfaces = 2,
-# else
- .bNumInterfaces = 1,
-# endif
+ .bNumInterfaces = TOTAL_INTERFACES,
.bConfigurationValue = 0x01,
.iConfiguration = 0x00,
.bmAttributes = (1 << 7) | USBATTR_REMOTEWAKE,
@@ -530,7 +630,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
.bLength = sizeof(usbInterfaceDescriptor_t),
.bDescriptorType = USBDESCR_INTERFACE
},
- .bInterfaceNumber = 0,
+ .bInterfaceNumber = KEYBOARD_INTERFACE,
.bAlternateSetting = 0x00,
.bNumEndpoints = 1,
.bInterfaceClass = 0x03,
@@ -560,6 +660,55 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
.bInterval = USB_POLLING_INTERVAL_MS
},
+# if defined(RAW_ENABLE)
+ /*
+ * RAW HID
+ */
+ .rawInterface = {
+ .header = {
+ .bLength = sizeof(usbInterfaceDescriptor_t),
+ .bDescriptorType = USBDESCR_INTERFACE
+ },
+ .bInterfaceNumber = RAW_INTERFACE,
+ .bAlternateSetting = 0x00,
+ .bNumEndpoints = 2,
+ .bInterfaceClass = 0x03,
+ .bInterfaceSubClass = 0x00,
+ .bInterfaceProtocol = 0x00,
+ .iInterface = 0x00
+ },
+ .rawHID = {
+ .header = {
+ .bLength = sizeof(usbHIDDescriptor_t),
+ .bDescriptorType = USBDESCR_HID
+ },
+ .bcdHID = 0x0101,
+ .bCountryCode = 0x00,
+ .bNumDescriptors = 2,
+ .bDescriptorType = USBDESCR_HID_REPORT,
+ .wDescriptorLength = sizeof(raw_hid_report)
+ },
+ .rawINEndpoint = {
+ .header = {
+ .bLength = sizeof(usbEndpointDescriptor_t),
+ .bDescriptorType = USBDESCR_ENDPOINT
+ },
+ .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP3_NUMBER),
+ .bmAttributes = 0x03,
+ .wMaxPacketSize = RAW_EPSIZE,
+ .bInterval = USB_POLLING_INTERVAL_MS
+ },
+ .rawOUTEndpoint = {
+ .header = {
+ .bLength = sizeof(usbEndpointDescriptor_t),
+ .bDescriptorType = USBDESCR_ENDPOINT
+ },
+ .bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP3_NUMBER),
+ .bmAttributes = 0x03,
+ .wMaxPacketSize = RAW_EPSIZE,
+ .bInterval = USB_POLLING_INTERVAL_MS
+ },
+# endif
# if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
/*
* Mouse/Extrakeys
@@ -569,7 +718,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
.bLength = sizeof(usbInterfaceDescriptor_t),
.bDescriptorType = USBDESCR_INTERFACE
},
- .bInterfaceNumber = 1,
+ .bInterfaceNumber = MOUSE_EXTRA_INTERFACE,
.bAlternateSetting = 0x00,
.bNumEndpoints = 1,
.bInterfaceClass = 0x03,
@@ -597,14 +746,18 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
.bmAttributes = 0x03,
.wMaxPacketSize = 8,
.bInterval = USB_POLLING_INTERVAL_MS
- }
-# elif defined(RAW_ENABLE)
- .rawInterface = {
+ },
+# endif
+# if defined(CONSOLE_ENABLE)
+ /*
+ * Console
+ */
+ .consoleInterface = {
.header = {
.bLength = sizeof(usbInterfaceDescriptor_t),
.bDescriptorType = USBDESCR_INTERFACE
},
- .bInterfaceNumber = 1,
+ .bInterfaceNumber = CONSOLE_INTERFACE,
.bAlternateSetting = 0x00,
.bNumEndpoints = 2,
.bInterfaceClass = 0x03,
@@ -612,37 +765,37 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
.bInterfaceProtocol = 0x00,
.iInterface = 0x00
},
- .rawHID = {
+ .consoleHID = {
.header = {
.bLength = sizeof(usbHIDDescriptor_t),
.bDescriptorType = USBDESCR_HID
},
- .bcdHID = 0x0101,
+ .bcdHID = 0x0111,
.bCountryCode = 0x00,
- .bNumDescriptors = 2,
+ .bNumDescriptors = 1,
.bDescriptorType = USBDESCR_HID_REPORT,
- .wDescriptorLength = sizeof(raw_hid_report)
+ .wDescriptorLength = sizeof(console_hid_report)
},
- .rawINEndpoint = {
+ .consoleINEndpoint = {
.header = {
.bLength = sizeof(usbEndpointDescriptor_t),
.bDescriptorType = USBDESCR_ENDPOINT
},
.bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP3_NUMBER),
.bmAttributes = 0x03,
- .wMaxPacketSize = RAW_EPSIZE,
- .bInterval = USB_POLLING_INTERVAL_MS
+ .wMaxPacketSize = CONSOLE_EPSIZE,
+ .bInterval = 0x01
},
- .rawOUTEndpoint = {
+ .consoleOUTEndpoint = {
.header = {
.bLength = sizeof(usbEndpointDescriptor_t),
.bDescriptorType = USBDESCR_ENDPOINT
},
.bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP3_NUMBER),
.bmAttributes = 0x03,
- .wMaxPacketSize = RAW_EPSIZE,
- .bInterval = USB_POLLING_INTERVAL_MS
- }
+ .wMaxPacketSize = CONSOLE_EPSIZE,
+ .bInterval = 0x01
+ },
# endif
};
@@ -690,18 +843,25 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
break;
case USBDESCR_HID:
switch (rq->wValue.bytes[0]) {
- case 0:
+ case KEYBOARD_INTERFACE:
usbMsgPtr = (unsigned char *)&usbConfigurationDescriptor.keyboardHID;
len = sizeof(usbHIDDescriptor_t);
break;
+#if defined(RAW_ENABLE)
+ case RAW_INTERFACE:
+ usbMsgPtr = (unsigned char *)&usbConfigurationDescriptor.rawHID;
+ len = sizeof(usbHIDDescriptor_t);
+ break;
+#endif
#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
- case 1:
+ case MOUSE_EXTRA_INTERFACE:
usbMsgPtr = (unsigned char *)&usbConfigurationDescriptor.mouseExtraHID;
len = sizeof(usbHIDDescriptor_t);
break;
-#elif defined(RAW_ENABLE)
- case 1:
- usbMsgPtr = (unsigned char *)&usbConfigurationDescriptor.rawHID;
+#endif
+#if defined(CONSOLE_ENABLE)
+ case CONSOLE_INTERFACE:
+ usbMsgPtr = (unsigned char *)&usbConfigurationDescriptor.consoleHID;
len = sizeof(usbHIDDescriptor_t);
break;
#endif
@@ -710,19 +870,26 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
case USBDESCR_HID_REPORT:
/* interface index */
switch (rq->wIndex.word) {
- case 0:
+ case KEYBOARD_INTERFACE:
usbMsgPtr = (unsigned char *)keyboard_hid_report;
len = sizeof(keyboard_hid_report);
break;
+#if defined(RAW_ENABLE)
+ case RAW_INTERFACE:
+ usbMsgPtr = (unsigned char *)raw_hid_report;
+ len = sizeof(raw_hid_report);
+ break;
+#endif
#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
- case 1:
+ case MOUSE_EXTRA_INTERFACE:
usbMsgPtr = (unsigned char *)mouse_extra_hid_report;
len = sizeof(mouse_extra_hid_report);
break;
-#elif defined(RAW_ENABLE)
- case 1:
- usbMsgPtr = (unsigned char *)raw_hid_report;
- len = sizeof(raw_hid_report);
+#endif
+#if defined(CONSOLE_ENABLE)
+ case CONSOLE_INTERFACE:
+ usbMsgPtr = (unsigned char *)console_hid_report;
+ len = sizeof(console_hid_report);
break;
#endif
}
diff --git a/tmk_core/protocol/vusb/vusb.h b/tmk_core/protocol/vusb/vusb.h
index e097323fd..828960fc3 100644
--- a/tmk_core/protocol/vusb/vusb.h
+++ b/tmk_core/protocol/vusb/vusb.h
@@ -89,23 +89,28 @@ typedef struct usbConfigurationDescriptor {
usbHIDDescriptor_t keyboardHID;
usbEndpointDescriptor_t keyboardINEndpoint;
-#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
- usbInterfaceDescriptor_t mouseExtraInterface;
- usbHIDDescriptor_t mouseExtraHID;
- usbEndpointDescriptor_t mouseExtraINEndpoint;
-#elif defined(RAW_ENABLE)
+#if defined(RAW_ENABLE)
usbInterfaceDescriptor_t rawInterface;
usbHIDDescriptor_t rawHID;
usbEndpointDescriptor_t rawINEndpoint;
usbEndpointDescriptor_t rawOUTEndpoint;
#endif
+
+#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
+ usbInterfaceDescriptor_t mouseExtraInterface;
+ usbHIDDescriptor_t mouseExtraHID;
+ usbEndpointDescriptor_t mouseExtraINEndpoint;
+#endif
+
+#if defined(CONSOLE_ENABLE)
+ usbInterfaceDescriptor_t consoleInterface;
+ usbHIDDescriptor_t consoleHID;
+ usbEndpointDescriptor_t consoleINEndpoint;
+ usbEndpointDescriptor_t consoleOUTEndpoint;
+#endif
} __attribute__((packed)) usbConfigurationDescriptor_t;
#define USB_STRING_LEN(s) (sizeof(usbDescriptorHeader_t) + ((s) << 1))
host_driver_t *vusb_driver(void);
void vusb_transfer_keyboard(void);
-
-#ifdef RAW_ENABLE
-void raw_hid_task(void);
-#endif
diff --git a/tmk_core/ring_buffer.h b/tmk_core/ring_buffer.h
index 6bea3509b..25fab638e 100644
--- a/tmk_core/ring_buffer.h
+++ b/tmk_core/ring_buffer.h
@@ -3,21 +3,26 @@
/*--------------------------------------------------------------------
* Ring buffer to store scan codes from keyboard
*------------------------------------------------------------------*/
-#define RBUF_SIZE 32
+#ifndef RBUF_SIZE
+# define RBUF_SIZE 32
+#endif
#include <util/atomic.h>
+#include <stdint.h>
+#include <stdbool.h>
static uint8_t rbuf[RBUF_SIZE];
static uint8_t rbuf_head = 0;
static uint8_t rbuf_tail = 0;
-static inline void rbuf_enqueue(uint8_t data) {
+static inline bool rbuf_enqueue(uint8_t data) {
+ bool ret = false;
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
if (next != rbuf_tail) {
rbuf[rbuf_head] = data;
rbuf_head = next;
- } else {
- print("rbuf: full\n");
+ ret = true;
}
}
+ return ret;
}
static inline uint8_t rbuf_dequeue(void) {
uint8_t val = 0;