From 6183dbd0ceefdbff42d30e6691fa9948a695e9af Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 27 Sep 2019 00:15:43 +0700 Subject: add -Wextra for more warnings to example non-stack warning (probably mcu driver) should be suppressed in the board.mk --- src/class/midi/midi_device.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/class') diff --git a/src/class/midi/midi_device.c b/src/class/midi/midi_device.c index 50826a1f4..11fe06e38 100644 --- a/src/class/midi/midi_device.c +++ b/src/class/midi/midi_device.c @@ -86,16 +86,19 @@ bool tud_midi_n_mounted (uint8_t itf) //--------------------------------------------------------------------+ uint32_t tud_midi_n_available(uint8_t itf, uint8_t jack_id) { + (void) jack_id; return tu_fifo_count(&_midid_itf[itf].rx_ff); } uint32_t tud_midi_n_read(uint8_t itf, uint8_t jack_id, void* buffer, uint32_t bufsize) { + (void) jack_id; return tu_fifo_read_n(&_midid_itf[itf].rx_ff, buffer, bufsize); } void tud_midi_n_read_flush (uint8_t itf, uint8_t jack_id) { + (void) jack_id; tu_fifo_clear(&_midid_itf[itf].rx_ff); } @@ -128,6 +131,8 @@ void midi_rx_done_cb(midid_interface_t* midi, uint8_t const* buffer, uint32_t bu static bool maybe_transmit(midid_interface_t* midi, uint8_t itf_index) { + (void) itf_index; + // skip if previous transfer not complete TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, midi->ep_in) ); @@ -309,11 +314,15 @@ bool midid_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, bool midid_control_complete(uint8_t rhport, tusb_control_request_t const * p_request) { - return false; + (void) rhport; + (void) p_request; + return true; } bool midid_control_request(uint8_t rhport, tusb_control_request_t const * p_request) { + (void) rhport; + //------------- Class Specific Request -------------// if (p_request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS) return false; @@ -322,6 +331,8 @@ bool midid_control_request(uint8_t rhport, tusb_control_request_t const * p_requ bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) { + (void) result; + // TODO Support multiple interfaces uint8_t const itf = 0; midid_interface_t* p_midi = &_midid_itf[itf]; -- cgit v1.3.1 From 204791b3e787ed75b0f9d722392a601458417ceb Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 1 Oct 2019 22:19:04 +0700 Subject: 2nd attempt to fix #161 --- src/class/hid/hid_device.c | 2 +- src/device/usbd.c | 29 ++++++++++++++++------------- src/device/usbd_pvt.h | 11 +++++++++++ 3 files changed, 28 insertions(+), 14 deletions(-) (limited to 'src/class') diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index b57d6219f..40ec52886 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -74,7 +74,7 @@ bool tud_hid_ready(void) { uint8_t itf = 0; uint8_t const ep_in = _hidd_itf[itf].ep_in; - return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in); + return tud_ready() && (ep_in != 0) && usbd_edpt_ready(TUD_OPT_RHPORT, ep_in); } bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len) diff --git a/src/device/usbd.c b/src/device/usbd.c index 7f819d8f9..14e56a9b7 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -52,11 +52,16 @@ typedef struct { uint8_t self_powered : 1; // configuration descriptor's attribute }; - volatile uint8_t ep_busy_map[2]; // bit mask for busy endpoint - volatile uint8_t ep_stall_map[2]; // bit map for stalled endpoint - uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid) uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid ) + + struct TU_ATTR_PACKED + { + volatile bool busy : 1; + volatile bool stalled : 1; + + // TODO merge ep2drv here, 4-bit should be sufficient + }ep_status[8][2]; }usbd_device_t; static usbd_device_t _usbd_dev; @@ -310,7 +315,7 @@ void tud_task (void) uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const ep_dir = tu_edpt_dir(ep_addr); - _usbd_dev.ep_busy_map[ep_dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_busy_map[ep_dir], epnum); + _usbd_dev.ep_status[epnum][ep_dir].busy = false; if ( 0 == epnum ) { @@ -864,8 +869,7 @@ bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t uint8_t const dir = tu_edpt_dir(ep_addr); TU_VERIFY( dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes) ); - - _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_busy_map[dir], epnum); + _usbd_dev.ep_status[epnum][dir].busy = true; return true; } @@ -877,18 +881,17 @@ bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr) uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const dir = tu_edpt_dir(ep_addr); - return tu_bit_test(_usbd_dev.ep_busy_map[dir], epnum); + return _usbd_dev.ep_status[epnum][dir].busy; } - void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr) { uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const dir = tu_edpt_dir(ep_addr); dcd_edpt_stall(rhport, ep_addr); - _usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_stall_map[dir], epnum); - _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_busy_map[dir], epnum); + _usbd_dev.ep_status[epnum][dir].stalled = true; + _usbd_dev.ep_status[epnum][dir].busy = true; } void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) @@ -897,8 +900,8 @@ void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) uint8_t const dir = tu_edpt_dir(ep_addr); dcd_edpt_clear_stall(rhport, ep_addr); - _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_busy_map[dir], epnum); - _usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_stall_map[dir], epnum); + _usbd_dev.ep_status[epnum][dir].stalled = false; + _usbd_dev.ep_status[epnum][dir].busy = false; } bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) @@ -908,7 +911,7 @@ bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const dir = tu_edpt_dir(ep_addr); - return tu_bit_test(_usbd_dev.ep_stall_map[dir], epnum); + return _usbd_dev.ep_status[epnum][dir].stalled; } #endif diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index fbf030ce3..892680142 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -47,10 +47,21 @@ bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t // Check if endpoint transferring is complete bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr); +// Stall endpoint void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr); + +// Clear stalled endpoint void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr); + +// Check if endpoint is stalled bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr); +static inline +bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr) +{ + return !usbd_edpt_busy(rhport, ep_addr) && !usbd_edpt_stalled(rhport, ep_addr); +} + /*------------------------------------------------------------------*/ /* Helper *------------------------------------------------------------------*/ -- cgit v1.3.1