Skip to content

Commit

Permalink
Merge ChibiOS and LUFA descriptor support (#2362)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fredizzimo authored and jackhumbert committed Feb 8, 2018
1 parent 63c16f4 commit 53ff8a3
Show file tree
Hide file tree
Showing 38 changed files with 752 additions and 1,228 deletions.
7 changes: 5 additions & 2 deletions build_keyboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)","")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions keyboards/chibios_test/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion keyboards/chibios_test/stm32_f072_onekey/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
2 changes: 1 addition & 1 deletion keyboards/chibios_test/stm32_f103_onekey/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
2 changes: 1 addition & 1 deletion keyboards/chibios_test/teensy_lc_onekey/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
8 changes: 3 additions & 5 deletions keyboards/clueboard/60/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions keyboards/ergodox_infinity/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions keyboards/infinity60/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion keyboards/infinity60/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
8 changes: 3 additions & 5 deletions keyboards/jm60/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion keyboards/jm60/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
8 changes: 3 additions & 5 deletions keyboards/whitefox/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
#endif
2 changes: 1 addition & 1 deletion lib/chibios
2 changes: 1 addition & 1 deletion lib/chibios-contrib
1 change: 1 addition & 0 deletions quantum/api/api_sysex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: ");
Expand Down
3 changes: 3 additions & 0 deletions quantum/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
58 changes: 33 additions & 25 deletions quantum/process_keycode/process_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions quantum/process_keycode/process_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion quantum/quantum.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tmk_core/chibios.mk
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ COMPILEFLAGS += -falign-functions=16
COMPILEFLAGS += -ffunction-sections
COMPILEFLAGS += -fdata-sections
COMPILEFLAGS += -fno-common
COMPILEFLAGS += -fshort-wchar
COMPILEFLAGS += $(THUMBFLAGS)

CFLAGS += $(COMPILEFLAGS)
Expand All @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions tmk_core/common/host_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions tmk_core/common/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -260,6 +263,10 @@ void keyboard_task(void)
pointing_device_task();
#endif

#ifdef MIDI_ENABLE
midi_task();
#endif

// update LED
if (led_status != host_keyboard_leds()) {
led_status = host_keyboard_leds();
Expand Down
Loading

0 comments on commit 53ff8a3

Please sign in to comment.