Skip to content

Choose which USB and USB HID devices to include at compile-time #2116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ports/atmel-samd/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ifeq ($(CHIP_FAMILY),samd21)
CIRCUITPY_AUDIOMIXER = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_TOUCHIO_USE_NATIVE = 1

# SAMD21 needs separate endpoint pairs for MSC BULK IN and BULK OUT, otherwise it's erratic.
USB_MSC_NUM_ENDPOINT_PAIRS = 2
endif

# Put samd51-only choices here.
Expand Down
4 changes: 1 addition & 3 deletions shared-module/usb_hid/Device.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t*
// Wait until interface is ready, timeout = 2 seconds
uint64_t end_ticks = ticks_ms + 2000;
while ( (ticks_ms < end_ticks) && !tud_hid_ready() ) {
#ifdef MICROPY_VM_HOOK_LOOP
MICROPY_VM_HOOK_LOOP;
#endif
RUN_BACKGROUND_TASKS;
}

if ( !tud_hid_ready() ) {
Expand Down
129 changes: 1 addition & 128 deletions shared-module/usb_hid/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,131 +24,4 @@
* THE SOFTWARE.
*/

#include "py/obj.h"
#include "py/mphal.h"
#include "py/runtime.h"

#include "genhdr/autogen_usb_descriptor.h"
#include "shared-module/usb_hid/Device.h"
#include "shared-bindings/usb_hid/Device.h"
#include "tusb.h"

#ifdef USB_HID_REPORT_ID_KEYBOARD
static uint8_t keyboard_report_buffer[USB_HID_REPORT_LENGTH_KEYBOARD];
#endif

#ifdef USB_HID_REPORT_ID_MOUSE
static uint8_t mouse_report_buffer[USB_HID_REPORT_LENGTH_MOUSE];
#endif

#ifdef USB_HID_REPORT_ID_CONSUMER
static uint8_t consumer_report_buffer[USB_HID_REPORT_LENGTH_CONSUMER];
#endif

#ifdef USB_HID_REPORT_ID_SYS_CONTROL
static uint8_t sys_control_report_buffer[USB_HID_REPORT_LENGTH_SYS_CONTROL];
#endif

#ifdef USB_HID_REPORT_ID_GAMEPAD
static uint8_t gamepad_report_buffer[USB_HID_REPORT_LENGTH_GAMEPAD];
#endif

#ifdef USB_HID_REPORT_ID_DIGITIZER
static uint8_t digitizer_report_buffer[USB_HID_REPORT_LENGTH_DIGITIZER];
#endif

usb_hid_device_obj_t usb_hid_devices[] = {
#ifdef USB_HID_REPORT_ID_KEYBOARD
{
.base = { .type = &usb_hid_device_type } ,
.report_buffer = keyboard_report_buffer ,
.report_id = USB_HID_REPORT_ID_KEYBOARD ,
.report_length = USB_HID_REPORT_LENGTH_KEYBOARD ,
.usage_page = HID_USAGE_PAGE_DESKTOP ,
.usage = HID_USAGE_DESKTOP_KEYBOARD ,
},
#endif

#ifdef USB_HID_REPORT_ID_MOUSE
{
.base = { .type = &usb_hid_device_type } ,
.report_buffer = mouse_report_buffer ,
.report_id = USB_HID_REPORT_ID_MOUSE ,
.report_length = USB_HID_REPORT_LENGTH_MOUSE ,
.usage_page = HID_USAGE_PAGE_DESKTOP ,
.usage = HID_USAGE_DESKTOP_MOUSE ,
},
#endif

#ifdef USB_HID_REPORT_ID_CONSUMER
{
.base = { .type = &usb_hid_device_type } ,
.report_buffer = consumer_report_buffer ,
.report_id = USB_HID_REPORT_ID_CONSUMER ,
.report_length = USB_HID_REPORT_LENGTH_CONSUMER ,
.usage_page = HID_USAGE_PAGE_CONSUMER ,
.usage = HID_USAGE_CONSUMER_CONTROL ,
},
#endif

#ifdef USB_HID_REPORT_ID_SYS_CONTROL
{
.base = { .type = &usb_hid_device_type } ,
.report_buffer = sys_control_report_buffer ,
.report_id = USB_HID_REPORT_ID_SYS_CONTROL ,
.report_length = USB_HID_REPORT_LENGTH_SYS_CONTROL ,
.usage_page = HID_USAGE_PAGE_DESKTOP ,
.usage = HID_USAGE_DESKTOP_SYSTEM_CONTROL ,
},
#endif

#ifdef USB_HID_REPORT_ID_GAMEPAD
{
.base = { .type = &usb_hid_device_type } ,
.report_buffer = gamepad_report_buffer ,
.report_id = USB_HID_REPORT_ID_GAMEPAD ,
.report_length = USB_HID_REPORT_LENGTH_GAMEPAD ,
.usage_page = HID_USAGE_PAGE_DESKTOP ,
.usage = HID_USAGE_DESKTOP_GAMEPAD ,
},
#endif

#ifdef USB_HID_REPORT_ID_DIGITIZER
{
.base = { .type = &usb_hid_device_type } ,
.report_buffer = digitizer_report_buffer ,
.report_id = USB_HID_REPORT_ID_DIGITIZER ,
.report_length = USB_HID_REPORT_LENGTH_DIGITIZER ,
.usage_page = 0x0D ,
.usage = 0x02 ,
},
#endif
};


mp_obj_tuple_t common_hal_usb_hid_devices = {
.base = {
.type = &mp_type_tuple,
},
.len = USB_HID_NUM_DEVICES,
.items = {
#if USB_HID_NUM_DEVICES >= 1
(mp_obj_t) &usb_hid_devices[0],
#endif
#if USB_HID_NUM_DEVICES >= 2
(mp_obj_t) &usb_hid_devices[1],
#endif
#if USB_HID_NUM_DEVICES >= 3
(mp_obj_t) &usb_hid_devices[2],
#endif
#if USB_HID_NUM_DEVICES >= 4
(mp_obj_t) &usb_hid_devices[3],
#endif
#if USB_HID_NUM_DEVICES >= 5
(mp_obj_t) &usb_hid_devices[4],
#endif
#if USB_HID_NUM_DEVICES >= 6
(mp_obj_t) &usb_hid_devices[5],
#endif
}
};
// Nothing needed here. Tables of HID devices are generated in autogen_usb_descriptor.c at compile-time.
16 changes: 16 additions & 0 deletions supervisor/supervisor.mk
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ else
CFLAGS += -DUSB_AVAILABLE
endif

ifndef USB_DEVICES
USB_DEVICES = "CDC,MSC,AUDIO,HID"
endif

ifndef USB_HID_DEVICES
USB_HID_DEVICES = "KEYBOARD,MOUSE,CONSUMER,GAMEPAD"
endif

# SAMD21 needs separate endpoint pairs for MSC BULK IN and BULK OUT, otherwise it's erratic.
ifndef USB_MSC_NUM_ENDPOINT_PAIRS
USB_MSC_NUM_ENDPOINT_PAIRS = 1
endif

SUPERVISOR_O = $(addprefix $(BUILD)/, $(SRC_SUPERVISOR:.c=.o)) $(BUILD)/autogen_display_resources.o

$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h
Expand All @@ -103,6 +116,9 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile
--vid $(USB_VID)\
--pid $(USB_PID)\
--serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\
--devices $(USB_DEVICES)\
--hid_devices $(USB_HID_DEVICES)\
--msc_num_endpoint_pairs $(USB_MSC_NUM_ENDPOINT_PAIRS)\
--output_c_file $(BUILD)/autogen_usb_descriptor.c\
--output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h

Expand Down
Loading