summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfredizzimo <fsundvik@gmail.com>2018-02-08 22:07:46 +0200
committerJack Humbert <jack.humb@gmail.com>2018-02-08 15:07:46 -0500
commit53ff8a31b61952d9675558149d927f7942071df9 (patch)
treea57b9e6f7d6494c9ef903f886a660dd43f4e5044
parent63c16f4b632a2a82a775f51a3ad0cc690cca1fc9 (diff)
Merge ChibiOS and LUFA descriptor support (#2362)
* Move lufa descriptor to protocol/usb_descriptor * Try to compile usb_descriptor on ChibiOS * Add lufa_utils for ChibiOS Lufa USB descriptors for ChibiOS * More lufa_util compatibility fixes * First compiling version of shared USB descriptor * Send the usb descriptors * Fix the CONSOLE output on ChibiOS * Add errors for unsupported interfaces * Enable support for vitual serial port USB descriptors * Implement virtual serial port for ChibiOS * Cleanup the lufa_utils Use the default lufa header files * Add raw hid support for ChibiOS This is completely untested * Enable midi compilation on ChibiOS * Move midi functionality out of lufa.c * Don't register sysex callback when not needed * ChibiOS compilation fixes * Update ChibiOS submodule * Fix the Midi USB descriptor It didn't work properly when both Midi and Virtual serial port was enabled. * Add MIDI support for ChibiOS * Fix USB descriptor strings on ChibiOS * Use serial usb driver for raw hid * Generalize the ChibiOS stream like drivers This makes the initialization much more simple and eliminates a lot of the code duplication. * Convert console output to chibios stream driver * Fixes for ChibiOS update * Update the ChibiOS contrib submodule To include the usb data toggle synchronization fixes * Fix duplicate reset enumeration on ChibiOS * Add missing include * Add number of endpoints check for ChibiOS * Enable serial USB driver on all keyboards * Add missing includes when API is enabled withot midi * Add another missing inlcude
-rw-r--r--build_keyboard.mk7
-rw-r--r--keyboards/chibios_test/config.h8
-rw-r--r--keyboards/chibios_test/stm32_f072_onekey/halconf.h2
-rw-r--r--keyboards/chibios_test/stm32_f103_onekey/halconf.h2
-rw-r--r--keyboards/chibios_test/teensy_lc_onekey/halconf.h2
-rw-r--r--keyboards/clueboard/60/config.h8
-rw-r--r--keyboards/ergodox_infinity/config.h8
-rw-r--r--keyboards/infinity60/config.h6
-rw-r--r--keyboards/infinity60/halconf.h2
-rw-r--r--keyboards/jm60/config.h8
-rw-r--r--keyboards/jm60/halconf.h2
-rw-r--r--keyboards/whitefox/config.h8
m---------lib/chibios0
m---------lib/chibios-contrib0
-rw-r--r--quantum/api/api_sysex.c1
-rw-r--r--quantum/keymap.h3
-rw-r--r--quantum/process_keycode/process_midi.c58
-rw-r--r--quantum/process_keycode/process_midi.h5
-rw-r--r--quantum/quantum.c8
-rw-r--r--quantum/quantum.h1
-rw-r--r--tmk_core/chibios.mk2
-rw-r--r--tmk_core/common/host_driver.h5
-rw-r--r--tmk_core/common/keyboard.c7
-rw-r--r--tmk_core/common/report.h30
-rw-r--r--tmk_core/protocol/chibios.mk9
-rw-r--r--tmk_core/protocol/chibios/lufa_utils/LUFA/Drivers/USB/USB.h42
-rw-r--r--tmk_core/protocol/chibios/main.c27
-rw-r--r--tmk_core/protocol/chibios/usb_main.c1027
-rw-r--r--tmk_core/protocol/chibios/usb_main.h34
-rw-r--r--tmk_core/protocol/lufa.mk4
-rw-r--r--tmk_core/protocol/lufa/lufa.c338
-rw-r--r--tmk_core/protocol/lufa/lufa.h10
-rw-r--r--tmk_core/protocol/midi.mk3
-rwxr-xr-xtmk_core/protocol/midi/bytequeue/interrupt_setting.c15
-rw-r--r--tmk_core/protocol/midi/qmk_midi.c184
-rw-r--r--tmk_core/protocol/midi/qmk_midi.h9
-rw-r--r--tmk_core/protocol/usb_descriptor.c (renamed from tmk_core/protocol/lufa/descriptor.c)26
-rw-r--r--tmk_core/protocol/usb_descriptor.h (renamed from tmk_core/protocol/lufa/descriptor.h)65
38 files changed, 750 insertions, 1226 deletions
diff --git a/build_keyboard.mk b/build_keyboard.mk
index bee8fcc874..921159a5dd 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -121,7 +121,6 @@ else
endif
ifeq ($(PLATFORM),CHIBIOS)
- include $(TMK_PATH)/protocol/chibios.mk
include $(TMK_PATH)/chibios.mk
OPT_OS = chibios
ifneq ("$(wildcard $(KEYBOARD_PATH_5)/bootloader_defs.h)","")
@@ -197,7 +196,7 @@ else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_1)/keymap.c)","")
KEYMAP_PATH := $(MAIN_KEYMAP_PATH_1)
else ifneq ($(LAYOUTS),)
include build_layout.mk
-else
+else
$(error Could not find keymap)
# this state should never be reached
endif
@@ -247,6 +246,10 @@ endif
include $(TMK_PATH)/avr.mk
endif
+ifeq ($(PLATFORM),CHIBIOS)
+ include $(TMK_PATH)/protocol/chibios.mk
+endif
+
ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
VISUALIZER_DIR = $(QUANTUM_DIR)/visualizer
VISUALIZER_PATH = $(QUANTUM_PATH)/visualizer
diff --git a/keyboards/chibios_test/config.h b/keyboards/chibios_test/config.h
index c32a77b37f..89eb1f33b4 100644
--- a/keyboards/chibios_test/config.h
+++ b/keyboards/chibios_test/config.h
@@ -24,11 +24,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define DEVICE_VER 0x0001
/* in python2: list(u"whatever".encode('utf-16-le')) */
/* at most 32 characters or the ugly hack in usb_main.c borks */
-#define MANUFACTURER "QMK"
-#define USBSTR_MANUFACTURER 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', '\xc6', '\x00'
-#define PRODUCT "ChibiOS QMK test"
-#define USBSTR_PRODUCT 'C', '\x00', 'h', '\x00', 'i', '\x00', 'b', '\x00', 'i', '\x00', 'O', '\x00', 'S', '\x00', ' ', '\x00', 'Q', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', 't', '\x00', 'e', '\x00', 's', '\x00', 't', '\x00'
-#define DESCRIPTION "QMK keyboard firmware test for ChibiOS"
+#define MANUFACTURER QMK
+#define PRODUCT ChibiOS QMK test
+#define DESCRIPTION QMK keyboard firmware test for ChibiOS
/* key matrix size */
#define MATRIX_ROWS 1
diff --git a/keyboards/chibios_test/stm32_f072_onekey/halconf.h b/keyboards/chibios_test/stm32_f072_onekey/halconf.h
index 1a450d6327..46b37a4f46 100644
--- a/keyboards/chibios_test/stm32_f072_onekey/halconf.h
+++ b/keyboards/chibios_test/stm32_f072_onekey/halconf.h
@@ -139,7 +139,7 @@
* @brief Enables the SERIAL over USB subsystem.
*/
#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL_USB FALSE
+#define HAL_USE_SERIAL_USB TRUE
#endif
/**
diff --git a/keyboards/chibios_test/stm32_f103_onekey/halconf.h b/keyboards/chibios_test/stm32_f103_onekey/halconf.h
index 1a450d6327..46b37a4f46 100644
--- a/keyboards/chibios_test/stm32_f103_onekey/halconf.h
+++ b/keyboards/chibios_test/stm32_f103_onekey/halconf.h
@@ -139,7 +139,7 @@
* @brief Enables the SERIAL over USB subsystem.
*/
#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL_USB FALSE
+#define HAL_USE_SERIAL_USB TRUE
#endif
/**
diff --git a/keyboards/chibios_test/teensy_lc_onekey/halconf.h b/keyboards/chibios_test/teensy_lc_onekey/halconf.h
index 0436408b09..f7121f1a90 100644
--- a/keyboards/chibios_test/teensy_lc_onekey/halconf.h
+++ b/keyboards/chibios_test/teensy_lc_onekey/halconf.h
@@ -139,7 +139,7 @@
* @brief Enables the SERIAL over USB subsystem.
*/
#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL_USB FALSE
+#define HAL_USE_SERIAL_USB TRUE
#endif
/**
diff --git a/keyboards/clueboard/60/config.h b/keyboards/clueboard/60/config.h
index 333698a087..5c5a86296f 100644
--- a/keyboards/clueboard/60/config.h
+++ b/keyboards/clueboard/60/config.h
@@ -22,11 +22,9 @@
#define VENDOR_ID 0xC1ED
#define PRODUCT_ID 0x2350
#define DEVICE_VER 0x0001
-#define MANUFACTURER "Clueboard"
-#define USBSTR_MANUFACTURER 'C', '\x00', 'l', '\x00', 'u', '\x00', 'e', '\x00', 'b', '\x00', 'o', '\x00', 'a', '\x00', 'r', '\x00', 'd', '\x00'
-#define PRODUCT "Clueboard60"
-#define USBSTR_PRODUCT 'C', '\x00', 'l', '\x00', 'u', '\x00', 'e', '\x00', 'b', '\x00', 'o', '\x00', 'a', '\x00', 'r', '\x00', 'd', '\x00', ' ', '\x00', '6', '\x00', '0', '\x00', '%', '\x00'
-#define DESCRIPTION "Clueboard 60%"
+#define MANUFACTURER Clueboard
+#define PRODUCT Clueboard 60%
+#define DESCRIPTION Clueboard 60%
/* key matrix size */
#define MATRIX_ROWS 5
diff --git a/keyboards/ergodox_infinity/config.h b/keyboards/ergodox_infinity/config.h
index 094761e0b4..2f1be0d282 100644
--- a/keyboards/ergodox_infinity/config.h
+++ b/keyboards/ergodox_infinity/config.h
@@ -23,12 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x6464
#define DEVICE_VER 0x0001
-/* in python2: list(u"whatever".encode('utf-16-le')) */
-/* at most 32 characters or the ugly hack in usb_main.c borks */
-#define MANUFACTURER "TMK"
-#define USBSTR_MANUFACTURER 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00'
-#define PRODUCT "Infinity keyboard/TMK"
-#define USBSTR_PRODUCT 'I', '\x00', 'n', '\x00', 'f', '\x00', 'i', '\x00', 'n', '\x00', 'i', '\x00', 't', '\x00', 'y', '\x00', ' ', '\x00', 'k', '\x00', 'e', '\x00', 'y', '\x00', 'b', '\x00', 'o', '\x00', 'a', '\x00', 'r', '\x00', 'd', '\x00', '/', '\x00', 'T', '\x00', 'M', '\x00', 'K', '\x00'
+#define MANUFACTURER Input Club
+#define PRODUCT Ergodox Infinity (QMK)
#define MOUSEKEY_INTERVAL 20
#define MOUSEKEY_DELAY 0
diff --git a/keyboards/infinity60/config.h b/keyboards/infinity60/config.h
index 83930901cb..0a2f93e22b 100644
--- a/keyboards/infinity60/config.h
+++ b/keyboards/infinity60/config.h
@@ -26,10 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define DEVICE_VER 0x0001
/* in python2: list(u"whatever".encode('utf-16-le')) */
/* at most 32 characters or the ugly hack in usb_main.c borks */
-#define MANUFACTURER "Input Club"
-#define USBSTR_MANUFACTURER 'I', '\x00', 'n', '\x00', 'p', '\x00', 'u', '\x00', 't', '\x00', ' ', '\x00', 'C', '\x00', 'l', '\x00', 'u', '\x00', 'b', '\x00'
-#define PRODUCT "Infinity keyboard/QMK"
-#define USBSTR_PRODUCT 'I', '\x00', 'n', '\x00', 'f', '\x00', 'i', '\x00', 'n', '\x00', 'i', '\x00', 't', '\x00', 'y', '\x00', ' ', '\x00', 'k', '\x00', 'e', '\x00', 'y', '\x00', 'b', '\x00', 'o', '\x00', 'a', '\x00', 'r', '\x00', 'd', '\x00', '/', '\x00', 'Q', '\x00', 'M', '\x00', 'K', '\x00'
+#define MANUFACTURER Input Club
+#define PRODUCT Infinity 60% keyboard (QMK)
/* key matrix size */
#define MATRIX_ROWS 9
#define MATRIX_COLS 7
diff --git a/keyboards/infinity60/halconf.h b/keyboards/infinity60/halconf.h
index f89dfc2e1e..b380315298 100644
--- a/keyboards/infinity60/halconf.h
+++ b/keyboards/infinity60/halconf.h
@@ -139,7 +139,7 @@
* @brief Enables the SERIAL over USB subsystem.
*/
#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL_USB FALSE
+#define HAL_USE_SERIAL_USB TRUE
#endif
/**
diff --git a/keyboards/jm60/config.h b/keyboards/jm60/config.h
index 2596413313..847cf20780 100644
--- a/keyboards/jm60/config.h
+++ b/keyboards/jm60/config.h
@@ -26,11 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define DEVICE_VER 0x0001
/* in python2: list(u"whatever".encode('utf-16-le')) */
/* at most 32 characters or the ugly hack in usb_main.c borks */
-#define MANUFACTURER "JMWS"
-#define USBSTR_MANUFACTURER 'J', '\x00', 'M', '\x00', 'W', '\x00', 'S', '\x00'
-#define PRODUCT "JM60 RGB Keyboard(QMK)"
-#define USBSTR_PRODUCT 'J', '\x00', 'M', '\x00', '6', '\x00', '0', '\x00', ' ', '\x00', 'R', '\x00', 'G', '\x00', 'B', '\x00', ' ', '\x00', 'K', '\x00', 'e', '\x00', 'y', '\x00', 'b', '\x00', 'o', '\x00', 'a', '\x00', 'r', '\x00', 'd', '\x00', '(', '\x00', 'Q', '\x00', 'M', '\x00', 'K', '\x00', ')', '\x00'
-#define DESCRIPTION "QMK keyboard firmware for JM60 RGB Keyboard"
+#define MANUFACTURER JMWS
+#define PRODUCT JM60 RGB Keyboard(QMK)
+#define DESCRIPTION QMK keyboard firmware for JM60 RGB Keyboard
/* key matrix size */
#define MATRIX_ROWS 5
diff --git a/keyboards/jm60/halconf.h b/keyboards/jm60/halconf.h
index 1a450d6327..46b37a4f46 100644
--- a/keyboards/jm60/halconf.h
+++ b/keyboards/jm60/halconf.h
@@ -139,7 +139,7 @@
* @brief Enables the SERIAL over USB subsystem.
*/
#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL_USB FALSE
+#define HAL_USE_SERIAL_USB TRUE
#endif
/**
diff --git a/keyboards/whitefox/config.h b/keyboards/whitefox/config.h
index dc33a7ce5b..9397bd61f8 100644
--- a/keyboards/whitefox/config.h
+++ b/keyboards/whitefox/config.h
@@ -26,10 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define DEVICE_VER 0x0001
/* in python2: list(u"whatever".encode('utf-16-le')) */
/* at most 32 characters or the ugly hack in usb_main.c borks */
-#define MANUFACTURER "Input Club"
-#define USBSTR_MANUFACTURER 'I', '\x00', 'n', '\x00', 'p', '\x00', 'u', '\x00', 't', '\x00', ' ', '\x00', 'C', '\x00', 'l', '\x00', 'u', '\x00', 'b', '\x00'
-#define PRODUCT "WhiteFox/QMK"
-#define USBSTR_PRODUCT 'W', '\x00', 'h', '\x00', 'i', '\x00', 't', '\x00', 'e', '\x00', 'F', '\x00', 'o', '\x00', 'x', '\x00', ' ', '\x00'
+#define MANUFACTURER Input Club
+#define PRODUCT WhiteFox (QMK)
/* key matrix size */
#define MATRIX_ROWS 9
@@ -81,4 +79,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION
-#endif \ No newline at end of file
+#endif
diff --git a/lib/chibios b/lib/chibios
-Subproject e26cb16a7296a196d7c74eae22cbee00989cb7b
+Subproject 587968d6cbc2b0e1c7147540872f2a67e59ca18
diff --git a/lib/chibios-contrib b/lib/chibios-contrib
-Subproject 432bc1762f17eb7b506e8fbca8ec30a3d61629b
+Subproject ede48346eee4b8d6847c19bc01420bee76a5e48
diff --git a/quantum/api/api_sysex.c b/quantum/api/api_sysex.c
index 6a2ee90124..89c66a2a20 100644
--- a/quantum/api/api_sysex.c
+++ b/quantum/api/api_sysex.c
@@ -16,6 +16,7 @@
#include "api_sysex.h"
#include "sysex_tools.h"
#include "print.h"
+#include "qmk_midi.h"
void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint16_t length) {
// SEND_STRING("\nTX: ");
diff --git a/quantum/keymap.h b/quantum/keymap.h
index 5d64be19c8..bfcb2f7cd5 100644
--- a/quantum/keymap.h
+++ b/quantum/keymap.h
@@ -23,6 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "action.h"
#if defined(__AVR__)
#include <avr/pgmspace.h>
+#elif defined PROTOCOL_CHIBIOS
+//We need to ensure that chibios is include before redefining reset
+#include "ch.h"
#endif
#include "keycode.h"
#include "action_macro.h"
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c
index 9184feaae8..9728076dfd 100644
--- a/quantum/process_keycode/process_midi.c
+++ b/quantum/process_keycode/process_midi.c
@@ -16,11 +16,13 @@
#include "process_midi.h"
#ifdef MIDI_ENABLE
+#include <LUFA/Drivers/USB/USB.h>
#include "midi.h"
+#include "qmk_midi.h"
#ifdef MIDI_BASIC
-void process_midi_basic_noteon(uint8_t note)
+void process_midi_basic_noteon(uint8_t note)
{
midi_send_noteon(&midi_device, 0, note, 128);
}
@@ -46,6 +48,7 @@ static uint8_t tone_status[MIDI_TONE_COUNT];
static uint8_t midi_modulation;
static int8_t midi_modulation_step;
static uint16_t midi_modulation_timer;
+midi_config_t midi_config;
inline uint8_t compute_velocity(uint8_t setting)
{
@@ -70,30 +73,6 @@ void midi_init(void)
midi_modulation_timer = 0;
}
-void midi_task(void)
-{
- if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval)
- return;
- midi_modulation_timer = timer_read();
-
- if (midi_modulation_step != 0)
- {
- dprintf("midi modulation %d\n", midi_modulation);
- midi_send_cc(&midi_device, midi_config.channel, 0x1, midi_modulation);
-
- if (midi_modulation_step < 0 && midi_modulation < -midi_modulation_step) {
- midi_modulation = 0;
- midi_modulation_step = 0;
- return;
- }
-
- midi_modulation += midi_modulation_step;
-
- if (midi_modulation > 127)
- midi_modulation = 127;
- }
-}
-
uint8_t midi_compute_note(uint16_t keycode)
{
return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose;
@@ -250,4 +229,33 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
#endif // MIDI_ADVANCED
+void midi_task(void)
+{
+ midi_device_process(&midi_device);
+#ifdef MIDI_ADVANCED
+ if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval)
+ return;
+ midi_modulation_timer = timer_read();
+
+ if (midi_modulation_step != 0)
+ {
+ dprintf("midi modulation %d\n", midi_modulation);
+ midi_send_cc(&midi_device, midi_config.channel, 0x1, midi_modulation);
+
+ if (midi_modulation_step < 0 && midi_modulation < -midi_modulation_step) {
+ midi_modulation = 0;
+ midi_modulation_step = 0;
+ return;
+ }
+
+ midi_modulation += midi_modulation_step;
+
+ if (midi_modulation > 127)
+ midi_modulation = 127;
+ }
+#endif
+}
+
+
+
#endif // MIDI_ENABLE
diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h
index ccac8981a6..1968fbe3fa 100644
--- a/quantum/process_keycode/process_midi.h
+++ b/quantum/process_keycode/process_midi.h
@@ -27,6 +27,8 @@ void process_midi_basic_noteoff(uint8_t note);
void process_midi_all_notes_off(void);
#endif
+void midi_task(void);
+
#ifdef MIDI_ADVANCED
typedef union {
uint32_t raw;
@@ -39,10 +41,9 @@ typedef union {
};
} midi_config_t;
-midi_config_t midi_config;
+extern midi_config_t midi_config;
void midi_init(void);
-void midi_task(void);
bool process_midi(uint16_t keycode, keyrecord_t *record);
#define MIDI_INVALID_NOTE 0xFF
diff --git a/quantum/quantum.c b/quantum/quantum.c
index d3685f50b8..bd95d5ea80 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -34,6 +34,14 @@ extern backlight_config_t backlight_config;
#include "fauxclicky.h"
#endif
+#ifdef API_ENABLE
+#include "api.h"
+#endif
+
+#ifdef MIDI_ENABLE
+#include "process_midi.h"
+#endif
+
#ifdef AUDIO_ENABLE
#ifndef GOODBYE_SONG
#define GOODBYE_SONG SONG(GOODBYE_SOUND)
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 6ca5ecb5cf..b4c9e0b894 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -49,7 +49,6 @@ extern uint32_t default_layer_state;
#endif
#ifdef MIDI_ENABLE
- #include <lufa.h>
#ifdef MIDI_ADVANCED
#include "process_midi.h"
#endif
diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk
index 1cd0146fe0..7c7f658b25 100644
--- a/tmk_core/chibios.mk
+++ b/tmk_core/chibios.mk
@@ -149,6 +149,7 @@ COMPILEFLAGS += -falign-functions=16
COMPILEFLAGS += -ffunction-sections
COMPILEFLAGS += -fdata-sections
COMPILEFLAGS += -fno-common
+COMPILEFLAGS += -fshort-wchar
COMPILEFLAGS += $(THUMBFLAGS)
CFLAGS += $(COMPILEFLAGS)
@@ -159,6 +160,7 @@ CPPFLAGS += $(COMPILEFLAGS)
CPPFLAGS += -fno-rtti
LDFLAGS +=-Wl,--gc-sections
+LDFLAGS +=-Wl,--no-wchar-size-warning
LDFLAGS += -mno-thumb-interwork -mthumb
LDSYMBOLS =,--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE)
LDSYMBOLS :=$(LDSYMBOLS),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE)
diff --git a/tmk_core/common/host_driver.h b/tmk_core/common/host_driver.h
index 588d1c0be8..e40f0bfd65 100644
--- a/tmk_core/common/host_driver.h
+++ b/tmk_core/common/host_driver.h
@@ -30,11 +30,6 @@ typedef struct {
void (*send_mouse)(report_mouse_t *);
void (*send_system)(uint16_t);
void (*send_consumer)(uint16_t);
-#ifdef MIDI_ENABLE
- void (*usb_send_func)(MidiDevice *, uint16_t, uint8_t, uint8_t, uint8_t);
- void (*usb_get_midi)(MidiDevice *);
- void (*midi_usb_init)(MidiDevice *);
-#endif
} host_driver_t;
#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 436fb60734..001fb00ce5 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -66,6 +66,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef POINTING_DEVICE_ENABLE
# include "pointing_device.h"
#endif
+#ifdef MIDI_ENABLE
+# include "process_midi.h"
+#endif
#ifdef MATRIX_HAS_GHOST
extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
@@ -260,6 +263,10 @@ MATRIX_LOOP_END:
pointing_device_task();
#endif
+#ifdef MIDI_ENABLE
+ midi_task();
+#endif
+
// update LED
if (led_status != host_keyboard_leds()) {
led_status = host_keyboard_leds();
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index a0811f9a3c..6c27eb9dc6 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -73,22 +73,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* key report size(NKRO or boot mode) */
-#if defined(PROTOCOL_PJRC) && defined(NKRO_ENABLE)
-# include "usb.h"
-# define KEYBOARD_REPORT_SIZE KBD2_SIZE
-# define KEYBOARD_REPORT_KEYS (KBD2_SIZE - 2)
-# define KEYBOARD_REPORT_BITS (KBD2_SIZE - 1)
-
-#elif defined(PROTOCOL_LUFA) && defined(NKRO_ENABLE)
-# include "protocol/lufa/descriptor.h"
-# define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
-# define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
-# define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
-#elif defined(PROTOCOL_CHIBIOS) && defined(NKRO_ENABLE)
-# include "protocol/chibios/usb_main.h"
-# define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
-# define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
-# define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
+#if defined(NKRO_ENABLE)
+ #if defined(PROTOCOL_PJRC)
+ #include "usb.h"
+ #define KEYBOARD_REPORT_SIZE KBD2_SIZE
+ #define KEYBOARD_REPORT_KEYS (KBD2_SIZE - 2)
+ #define KEYBOARD_REPORT_BITS (KBD2_SIZE - 1)
+ #elif defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS)
+ #include "protocol/usb_descriptor.h"
+ #define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
+ #define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
+ #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
+ #else
+ #error "NKRO not supported with this protocol"
+#endif
#else
# define KEYBOARD_REPORT_SIZE 8
diff --git a/tmk_core/protocol/chibios.mk b/tmk_core/protocol/chibios.mk
index 3f4e0a71fc..6e7cfbd832 100644
--- a/tmk_core/protocol/chibios.mk
+++ b/tmk_core/protocol/chibios.mk
@@ -4,7 +4,16 @@ CHIBIOS_DIR = $(PROTOCOL_DIR)/chibios
SRC += $(CHIBIOS_DIR)/usb_main.c
SRC += $(CHIBIOS_DIR)/main.c
+SRC += usb_descriptor.c
VPATH += $(TMK_PATH)/$(PROTOCOL_DIR)
VPATH += $(TMK_PATH)/$(CHIBIOS_DIR)
+VPATH += $(TMK_PATH)/$(CHIBIOS_DIR)/lufa_utils
+
+OPT_DEFS += -DFIXED_CONTROL_ENDPOINT_SIZE=64
+OPT_DEFS += -DFIXED_NUM_CONFIGURATIONS=1
+
+ifeq ($(strip $(MIDI_ENABLE)), yes)
+ include $(TMK_PATH)/protocol/midi.mk
+endif
diff --git a/tmk_core/protocol/chibios/lufa_utils/LUFA/Drivers/USB/USB.h b/tmk_core/protocol/chibios/lufa_utils/LUFA/Drivers/USB/USB.h
new file mode 100644
index 0000000000..a5374d820c
--- /dev/null
+++ b/tmk_core/protocol/chibios/lufa_utils/LUFA/Drivers/USB/USB.h
@@ -0,0 +1,42 @@
+#include "progmem.h"
+#include "stddef.h"
+#include "inttypes.h"
+
+#define ATTR_PACKED __attribute__ ((packed))
+/** Concatenates the given input into a single token, via the C Preprocessor.
+ *
+ * \param[in] x First item to concatenate.
+ * \param[in] y Second item to concatenate.
+ *
+ * \return Concatenated version of the input.
+ */
+#define CONCAT(x, y) x ## y
+
+/** CConcatenates the given input into a single token after macro expansion, via the C Preprocessor.
+ *
+ * \param[in] x First item to concatenate.
+ * \param[in] y Second item to concatenate.
+ *
+ * \return Concatenated version of the expanded input.
+ */
+#define CONCAT_EXPANDED(x, y) CONCAT(x, y)
+#define CPU_TO_LE16(x) (x)
+
+// We don't need anything from the following files, or we have defined it already
+#define __LUFA_COMMON_H__
+#define __USBMODE_H__
+#define __USBEVENTS_H__
+#define __HIDPARSER_H__
+#define __USBCONTROLLER_AVR8_H__
+
+#define __INCLUDE_FROM_USB_DRIVER
+#define __INCLUDE_FROM_HID_DRIVER
+#define __INCLUDE_FROM_CDC_DRIVER
+#define __INCLUDE_FROM_AUDIO_DRIVER
+#define __INCLUDE_FROM_MIDI_DRIVER
+#include "lib/lufa/LUFA/Drivers/USB/Class/Common/HIDClassCommon.h"
+#include "lib/lufa/LUFA/Drivers/USB/Class/Common/HIDReportData.h"
+#include "lib/lufa/LUFA/Drivers/USB/Class/Common/CDCClassCommon.h"
+#include "lib/lufa/LUFA/Drivers/USB/Class/Common/AudioClassCommon.h"
+#include "lib/lufa/LUFA/Drivers/USB/Class/Common/MIDIClassCommon.h"
+#include "lib/lufa/LUFA/Drivers/USB/Core/USBController.h"
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c
index 47a7eb09ab..f2abc438d4 100644
--- a/tmk_core/protocol/chibios/main.c
+++ b/tmk_core/protocol/chibios/main.c
@@ -41,6 +41,9 @@
#ifdef VISUALIZER_ENABLE
#include "visualizer/visualizer.h"
#endif
+#ifdef MIDI_ENABLE
+#include "qmk_midi.h"
+#endif
#include "suspend.h"
#include "wait.h"
@@ -65,6 +68,17 @@ host_driver_t chibios_driver = {
send_consumer
};
+#ifdef VIRTSER_ENABLE
+void virtser_task(void);
+#endif
+
+#ifdef RAW_HID_ENABLE
+void raw_hid_task(void);
+#endif
+
+#ifdef CONSOLE_ENABLE
+void console_task(void);
+#endif
/* TESTING
* Amber LED blinker thread, times are in milliseconds.
@@ -104,6 +118,10 @@ int main(void) {
/* init printf */
init_printf(NULL,sendchar_pf);
+#ifdef MIDI_ENABLE
+ setup_midi();
+#endif
+
#ifdef SERIAL_LINK_ENABLE
init_serial_link();
#endif
@@ -182,5 +200,14 @@ int main(void) {
}
keyboard_task();
+#ifdef CONSOLE_ENABLE
+ console_task();
+#endif
+#ifdef VIRTSER_ENABLE
+ virtser_task();
+#endif
+#ifdef RAW_HID_ENABLE
+ raw_hid_task();
+#endif
}
}
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index caa2770b5c..f980024ab8 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -28,6 +28,7 @@
#include "led.h"
#endif
#include "wait.h"
+#include "usb_descriptor.h"
#ifdef NKRO_ENABLE
#include "keycode_config.h"
@@ -63,24 +64,12 @@ report_mouse_t mouse_report_blank = {0};
uint8_t extra_report_blank[3] = {0};
#endif /* EXTRAKEY_ENABLE */
-#ifdef CONSOLE_ENABLE
-/* The emission buffers queue */
-output_buffers_queue_t console_buf_queue;
-static uint8_t console_queue_buffer[BQ_BUFFER_SIZE(CONSOLE_QUEUE_CAPACITY, CONSOLE_EPSIZE)];
-
-static virtual_timer_t console_flush_timer;
-void console_queue_onotify(io_buffers_queue_t *bqp);
-static void console_flush_cb(void *arg);
-#endif /* CONSOLE_ENABLE */
-
/* ---------------------------------------------------------
* Descriptors and USB driver objects
* ---------------------------------------------------------
*/
/* HID specific constants */
-#define USB_DESCRIPTOR_HID 0x21
-#define USB_DESCRIPTOR_HID_REPORT 0x22
#define HID_GET_REPORT 0x01
#define HID_GET_IDLE 0x02
#define HID_GET_PROTOCOL 0x03
@@ -88,593 +77,21 @@ static void console_flush_cb(void *arg);
#define HID_SET_IDLE 0x0A
#define HID_SET_PROTOCOL 0x0B
-/* USB Device Descriptor */
-static const uint8_t usb_device_descriptor_data[] = {
- USB_DESC_DEVICE(0x0200, // bcdUSB (1.1)
- 0, // bDeviceCla