diff options
| author | Ha Thach <[email protected]> | 2020-10-09 21:25:17 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-10-09 21:25:17 +0700 |
| commit | 8a07b9b9c02248fa2bcb809ee6f7949fcd38e217 (patch) | |
| tree | c5f21fda499641a7ac7315bfb5a47e0346d5dfcf /examples | |
| parent | 6f8d0d2c34c61adc7c5202a67eaad69bb7c0f727 (diff) | |
| parent | 3fd38ddf0493f84eb3124aacf9ccd7c76643a2c9 (diff) | |
Merge pull request #532 from hathach/house-keeping
House keeping
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/device/hid_multiple_interface/Makefile (renamed from examples/device/hid_multipleinterface/Makefile) | 0 | ||||
| -rw-r--r-- | examples/device/hid_multiple_interface/src/main.c (renamed from examples/device/hid_multipleinterface/src/main.c) | 27 | ||||
| -rw-r--r-- | examples/device/hid_multiple_interface/src/tusb_config.h (renamed from examples/device/hid_multipleinterface/src/tusb_config.h) | 0 | ||||
| -rw-r--r-- | examples/device/hid_multiple_interface/src/usb_descriptors.c (renamed from examples/device/hid_multipleinterface/src/usb_descriptors.c) | 2 | ||||
| -rw-r--r-- | examples/rules.mk | 7 |
5 files changed, 21 insertions, 15 deletions
diff --git a/examples/device/hid_multipleinterface/Makefile b/examples/device/hid_multiple_interface/Makefile index 69b633fea..69b633fea 100644 --- a/examples/device/hid_multipleinterface/Makefile +++ b/examples/device/hid_multiple_interface/Makefile diff --git a/examples/device/hid_multipleinterface/src/main.c b/examples/device/hid_multiple_interface/src/main.c index b1957b9fc..7cb1d75a7 100644 --- a/examples/device/hid_multipleinterface/src/main.c +++ b/examples/device/hid_multiple_interface/src/main.c @@ -34,6 +34,12 @@ // MACRO CONSTANT TYPEDEF PROTYPES //--------------------------------------------------------------------+ +// Interface index depends on the order in configuration descriptor +enum { + ITF_KEYBOARD = 0, + ITF_MOUSE = 1 +}; + /* Blink pattern * - 250 ms : device not mounted * - 1000 ms : device mounted @@ -104,10 +110,6 @@ void tud_resume_cb(void) void hid_task(void) { - //Set up interfaces - const uint8_t keyboard_interface = 0; - const uint8_t mouse_interface = 1; - // Poll every 10ms const uint32_t interval_ms = 10; static uint32_t start_ms = 0; @@ -126,7 +128,7 @@ void hid_task(void) } /*------------- Keyboard -------------*/ - if ( tud_hid_n_ready(keyboard_interface) ) + if ( tud_hid_n_ready(ITF_KEYBOARD) ) { // use to avoid send multiple consecutive zero report for keyboard static bool has_key = false; @@ -136,29 +138,26 @@ void hid_task(void) uint8_t keycode[6] = { 0 }; keycode[0] = HID_KEY_A; - tud_hid_n_keyboard_report(keyboard_interface, 0, 0, keycode); + tud_hid_n_keyboard_report(ITF_KEYBOARD, 0, 0, keycode); has_key = true; }else { // send empty key report if previously has key pressed - if (has_key) tud_hid_n_keyboard_report(keyboard_interface, 0, 0, NULL); + if (has_key) tud_hid_n_keyboard_report(ITF_KEYBOARD, 0, 0, NULL); has_key = false; } } /*------------- Mouse -------------*/ - if ( tud_hid_n_ready(mouse_interface) ) + if ( tud_hid_n_ready(ITF_MOUSE) ) { if ( btn ) { int8_t const delta = 5; // no button, right + down, no scroll pan - tud_hid_n_mouse_report(mouse_interface, 0, 0x00, delta, delta, 0, 0); - - // delay a bit before attempt to send keyboard report - board_delay(10); + tud_hid_n_mouse_report(ITF_MOUSE, 0, 0x00, delta, delta, 0, 0); } } } @@ -167,7 +166,7 @@ void hid_task(void) // 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_n_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) +uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { // TODO not Implemented (void) itf; @@ -181,7 +180,7 @@ uint16_t tud_hid_n_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type // Invoked when received SET_REPORT control request or // received data on OUT endpoint ( Report ID = 0, Type = 0 ) -void tud_hid_n_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) +void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { // TODO set LED based on CAPLOCK, NUMLOCK etc... (void) itf; diff --git a/examples/device/hid_multipleinterface/src/tusb_config.h b/examples/device/hid_multiple_interface/src/tusb_config.h index 412f9b004..412f9b004 100644 --- a/examples/device/hid_multipleinterface/src/tusb_config.h +++ b/examples/device/hid_multiple_interface/src/tusb_config.h diff --git a/examples/device/hid_multipleinterface/src/usb_descriptors.c b/examples/device/hid_multiple_interface/src/usb_descriptors.c index dd8ef7120..0d67d499a 100644 --- a/examples/device/hid_multipleinterface/src/usb_descriptors.c +++ b/examples/device/hid_multiple_interface/src/usb_descriptors.c @@ -83,7 +83,7 @@ uint8_t const desc_hid_report2[] = // Invoked when received GET HID REPORT DESCRIPTOR // Application return pointer to descriptor // Descriptor contents must exist long enough for transfer to complete -uint8_t const * tud_hid_n_descriptor_report_cb(uint8_t itf) +uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf) { if (itf == 0) { diff --git a/examples/rules.mk b/examples/rules.mk index dacb81363..7ed648a8b 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -147,6 +147,8 @@ else JLINKEXE = JLinkExe endif +JLINK_IF ?= swd + # Flash using jlink flash-jlink: $(BUILD)/$(BOARD)-firmware.hex @echo halt > $(BUILD)/$(BOARD).jlink @@ -161,4 +163,9 @@ flash-jlink: $(BUILD)/$(BOARD)-firmware.hex flash-stlink: $(BUILD)/$(BOARD)-firmware.elf STM32_Programmer_CLI --connect port=swd --write $< --go +# flash with pyocd +flash-pyocd: $(BUILD)/$(BOARD)-firmware.hex + pyocd flash -t $(PYOCD_TARGET) $< + pyocd reset -t $(PYOCD_TARGET) + endif # Make target |
