diff options
| author | hathach <[email protected]> | 2019-05-02 20:30:44 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-05-02 20:30:44 +0700 |
| commit | 867e69ed9d1ef44a7574ccf6543c8a46ef8d8e6c (patch) | |
| tree | 59b0e0aad89d7735585737be52fd2daffdbab5c0 /examples/device/cdc_msc_hid | |
| parent | 2341ecb4188b1998e1e682a09e9b04570929a5a4 (diff) | |
| parent | 7e2088765daf15f59f43c9e7cffb46b9ae997e19 (diff) | |
Merge pull request #61 from hathach/develop
enhance HID, add HID out endpoint support
Diffstat (limited to 'examples/device/cdc_msc_hid')
| -rw-r--r-- | examples/device/cdc_msc_hid/Makefile | 186 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid/src/main.c | 15 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid/src/tusb_config.h | 15 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid/src/usb_descriptors.c | 21 |
4 files changed, 37 insertions, 200 deletions
diff --git a/examples/device/cdc_msc_hid/Makefile b/examples/device/cdc_msc_hid/Makefile index 69bffaace..4ff3371dc 100644 --- a/examples/device/cdc_msc_hid/Makefile +++ b/examples/device/cdc_msc_hid/Makefile @@ -1,185 +1,15 @@ include ../../../tools/top.mk +include ../../make.mk -# Select the board to build for. -ifeq ($(BOARD),) - $(info You must provide a BOARD parameter with 'BOARD=') - $(info Possible values are:) - $(info $(sort $(subst /.,,$(subst $(TOP)/hw/bsp/,,$(wildcard $(TOP)/hw/bsp/*/.))))) - $(error BOARD not defined) -else - ifeq ($(wildcard $(TOP)/hw/bsp/$(BOARD)/.),) - $(error Invalid BOARD specified) - endif -endif - -# Verbose mode (V=). 0: default, 1: print out CFLAG, LDFLAG 2: print all compile command -ifeq ("$(V)","2") - QUIET = -else - QUIET = @ -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -CROSS_COMPILE = arm-none-eabi- - -include $(TOP)/hw/bsp/$(BOARD)/board.mk - -CC = $(CROSS_COMPILE)gcc -CXX = $(CROSS_COMPILE)g++ -OBJCOPY = $(CROSS_COMPILE)objcopy -SIZE = $(CROSS_COMPILE)size -MKDIR = mkdir -SED = sed -CP = cp -RM = rm - -INC += -Isrc \ - -I$(TOP)/hw \ - -I$(TOP)/src - -CFLAGS += \ - -fsingle-precision-constant \ - -fno-strict-aliasing \ - -Wdouble-promotion \ - -Wno-endif-labels \ - -Wstrict-prototypes \ - -Werror-implicit-function-declaration \ - -Wfloat-equal \ - -Wundef \ - -Wshadow \ - -Wwrite-strings \ - -Wsign-compare \ - -Wmissing-format-attribute \ - -Wno-deprecated-declarations \ - -Wnested-externs \ - -Wunreachable-code \ - -Wno-error=lto-type-mismatch \ - -ffunction-sections \ - -fdata-sections - -# This causes lots of warning with nrf5x build due to nrfx code -# CFLAGS += -Wcast-align - -#Debugging/Optimization -ifeq ($(DEBUG), 1) - CFLAGS += -O0 -ggdb -else - CFLAGS += -flto -Os -endif - -CFLAGS += $(INC) -Wall -Werror -std=gnu11 -DBOARD_$(shell echo $(BOARD) | tr '[:lower:]' '[:upper:]') -LDFLAGS += $(CFLAGS) -fshort-enums -Wl,-T,$(TOP)/$(LD_FILE) -Wl,[email protected] -Wl,-cref -Wl,-gc-sections -specs=nosys.specs -specs=nano.specs - -ifeq ("$(V)","1") -$(info CFLAGS $(CFLAGS)) -$(info ) -$(info LDFLAGS $(LDFLAGS)) -$(info ) -$(info ASFLAGS $(ASFLAGS)) -$(info ) -endif - -LIBS = -lgcc -lc -lm -lnosys +INC += \ + src \ + $(TOP)/hw \ +# Example source EXAMPLE_SOURCE += $(wildcard src/*.c) SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) -LIB_SOURCE += \ - hw/bsp/$(BOARD)/board_$(BOARD).c \ - src/common/tusb_fifo.c \ - src/device/usbd.c \ - src/device/usbd_control.c \ - src/class/msc/msc_device.c \ - src/class/cdc/cdc_device.c \ - src/class/hid/hid_device.c \ - src/tusb.c \ - src/portable/$(VENDOR)/$(CHIP_FAMILY)/dcd_$(CHIP_FAMILY).c - -SRC_C += $(LIB_SOURCE) - -# Assembly files can be name with upper case .S, convert it to .s -SRC_S := $(SRC_S:.S=.s) - -# Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966 -# assembly file should be placed first in linking order -OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=.o)) -OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o)) - -# Set all as default goal -.DEFAULT_GOAL := all -all: $(BUILD)/$(BOARD)-firmware.bin size - -OBJ_DIRS = $(sort $(dir $(OBJ))) -$(OBJ): | $(OBJ_DIRS) -$(OBJ_DIRS): - @$(MKDIR) -p $@ - -$(BUILD)/$(BOARD)-firmware.elf: $(OBJ) - @echo LINK $@ - $(QUIET)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group - -$(BUILD)/$(BOARD)-firmware.bin: $(BUILD)/$(BOARD)-firmware.elf - @echo CREATE $@ - @$(OBJCOPY) -O binary -j .vectors -j .text -j .data $^ $@ - -$(BUILD)/$(BOARD)-firmware.hex: $(BUILD)/$(BOARD)-firmware.elf - @echo CREATE $@ - @$(OBJCOPY) -O ihex $^ $@ - -# We set vpath to point to the top of the tree so that the source files -# can be located. By following this scheme, it allows a single build rule -# to be used to compile all .c files. -vpath %.c . $(TOP) -$(BUILD)/obj/%.o: %.c - @echo CC $(notdir $@) - $(QUIET)$(CC) $(CFLAGS) -c -MD -o $@ $< - @# The following fixes the dependency file. - @# See http://make.paulandlesley.org/autodep.html for details. - @# Regex adjusted from the above to play better with Windows paths, etc. - @$(CP) $(@:.o=.d) $(@:.o=.P); \ - $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \ - -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \ - $(RM) $(@:.o=.d) - -# ASM sources lower case .s -vpath %.s . $(TOP) -$(BUILD)/obj/%.o: %.s - @echo AS $(notdir $@) - $(QUIET)$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $< - -# ASM sources upper case .S -vpath %.S . $(TOP) -$(BUILD)/obj/%.o: %.S - @echo AS $(notdir $@) - $(QUIET)$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $< - -# Flash binary using Jlink, should be added into system path -ifeq ($(OS),Windows_NT) - JLINKEXE = JLink.exe -else - JLINKEXE = JLinkExe -endif - -# default jlink interface is swd -ifeq ($(JLINK_IF),) - JLINK_IF = swd -endif - -# Flash using jlink -flash-jlink: $(BUILD)/$(BOARD)-firmware.hex - @echo halt > $(BUILD)/$(BOARD).jlink - @echo loadfile $^ >> $(BUILD)/$(BOARD).jlink - @echo r >> $(BUILD)/$(BOARD).jlink - @echo go >> $(BUILD)/$(BOARD).jlink - @echo exit >> $(BUILD)/$(BOARD).jlink - $(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -speed auto -CommandFile $(BUILD)/$(BOARD).jlink - -size: $(BUILD)/$(BOARD)-firmware.elf - -@echo '' - @$(SIZE) $< - -@echo '' +# Board source +SRC_C += hw/bsp/$(BOARD)/board_$(BOARD).c -clean: - rm -rf build-$(BOARD) +include ../../rules.mk diff --git a/examples/device/cdc_msc_hid/src/main.c b/examples/device/cdc_msc_hid/src/main.c index fc2f2aad0..f743026c2 100644 --- a/examples/device/cdc_msc_hid/src/main.c +++ b/examples/device/cdc_msc_hid/src/main.c @@ -49,8 +49,8 @@ static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED; void led_blinking_task(void); -extern void cdc_task(void); -extern void hid_task(void); +void cdc_task(void); +void hid_task(void); /*------------- MAIN -------------*/ int main(void) @@ -196,7 +196,9 @@ void hid_task(void) if ( btn ) { int8_t const delta = 5; - tud_hid_mouse_move(REPORT_ID_MOUSE, delta, delta); // right + down + + // no button, right + down, no scroll pan + tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta, delta, 0, 0); // delay a bit before attempt to send keyboard report board_delay(2); @@ -220,12 +222,15 @@ void hid_task(void) }else { // send empty key report if previously has key pressed - if (has_key) tud_hid_keyboard_key_release(REPORT_ID_KEYBOARD); + if (has_key) tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL); has_key = false; } } } +// Invoked when received GET_REPORT control request +// Application must fill buffer report's content and return its length. +// Return zero will cause the stack to STALL request uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { // TODO not Implemented @@ -237,6 +242,8 @@ uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, return 0; } +// Invoked when received SET_REPORT control request or +// received data on OUT endpoint ( Report ID = 0, Type = 0 ) void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { // TODO not Implemented diff --git a/examples/device/cdc_msc_hid/src/tusb_config.h b/examples/device/cdc_msc_hid/src/tusb_config.h index 400afb620..c1210152e 100644 --- a/examples/device/cdc_msc_hid/src/tusb_config.h +++ b/examples/device/cdc_msc_hid/src/tusb_config.h @@ -77,17 +77,13 @@ #define CFG_TUD_MIDI 0 #define CFG_TUD_CUSTOM_CLASS 0 -//-------------------------------------------------------------------- -// CDC -//-------------------------------------------------------------------- +//------------- CDC -------------// // FIFO size of CDC TX and RX #define CFG_TUD_CDC_RX_BUFSIZE 64 #define CFG_TUD_CDC_TX_BUFSIZE 64 -//-------------------------------------------------------------------- -// MSC -//-------------------------------------------------------------------- +//------------- MSC -------------// // Buffer size of Device Mass storage #define CFG_TUD_MSC_BUFSIZE 512 @@ -101,9 +97,10 @@ // Product revision string included in Inquiry response, max 4 bytes #define CFG_TUD_MSC_PRODUCT_REV "1.0" -//-------------------------------------------------------------------- -// HID -//-------------------------------------------------------------------- +//------------- HID -------------// + +// Should be sufficient to hold ID (if any) + Data +#define CFG_TUD_HID_BUFSIZE 16 #ifdef __cplusplus } diff --git a/examples/device/cdc_msc_hid/src/usb_descriptors.c b/examples/device/cdc_msc_hid/src/usb_descriptors.c index c3bcc6f2b..72d280c2f 100644 --- a/examples/device/cdc_msc_hid/src/usb_descriptors.c +++ b/examples/device/cdc_msc_hid/src/usb_descriptors.c @@ -76,8 +76,8 @@ enum uint8_t const desc_hid_report[] = { - HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD), ), - HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE), ) + TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD), ), + TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE), ) }; #endif @@ -117,19 +117,22 @@ enum uint8_t const desc_configuration[] = { - // Config: self-powered with remote wakeup support, max power up to 100 mA + // Inteface count, string index, total length, attribute, power in mA TUD_CONFIG_DESCRIPTOR(ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), #if CFG_TUD_CDC + // Interface number, string index, EP notification address and size, EP data address (out, in) and size. TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, 0x81, 8, 0x02, 0x82, 64), #endif #if CFG_TUD_MSC + // Interface number, string index, EP Out & EP In address, EP size TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC, 0x80 | EPNUM_MSC, 64), // highspeed 512 #endif #if CFG_TUD_HID - TUD_HID_DESCRIPTOR(ITF_NUM_HID, 6, HID_PROTOCOL_KEYBOARD, sizeof(desc_hid_report), 0x84, 16, 10) + // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval + TUD_HID_DESCRIPTOR(ITF_NUM_HID, 6, HID_PROTOCOL_NONE, sizeof(desc_hid_report), 0x84, 16, 10) #endif }; @@ -162,13 +165,13 @@ uint16_t const * const string_desc_arr [] = // tud_desc_set is required by tinyusb stack tud_desc_set_t tud_desc_set = { - .device = &desc_device, - .config = desc_configuration, + .device = &desc_device, + .config = desc_configuration, - .string_arr = (uint8_t const **) string_desc_arr, - .string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]), + .string_arr = (uint8_t const **) string_desc_arr, + .string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]), #if CFG_TUD_HID - .hid_report = desc_hid_report, + .hid_report = desc_hid_report, #endif }; |
