diff --git a/demos/host/host_bulk_xfer/main.c b/demos/host/host_bulk_xfer/main.c index 7c20c4f30..8ce7ef6b4 100644 --- a/demos/host/host_bulk_xfer/main.c +++ b/demos/host/host_bulk_xfer/main.c @@ -112,12 +112,18 @@ int main(void) // BLINKING TASK //--------------------------------------------------------------------+ uint8_t custom_read_buffer[4*1024] TUSB_CFG_ATTR_USBRAM; -uint8_t custom_write_buffer[4*1024] TUSB_CFG_ATTR_USBRAM; +uint32_t custom_write_buffer[1024] TUSB_CFG_ATTR_USBRAM; void custom_class_loopback_task (void* p_task_para) { if( tusbh_custom_is_mounted(1, 0, 0) ) // hardcode addr = 1, ignore vendor/product ID { tusbh_custom_read(1, 0, 0, custom_read_buffer, sizeof(custom_read_buffer)); + + static uint32_t magic_number = 1; + custom_write_buffer[0] = magic_number; + tusbh_custom_write(1, 0, 0, custom_write_buffer, sizeof(custom_write_buffer)); + + magic_number += 2; } } diff --git a/tinyusb/class/custom_class_host.c b/tinyusb/class/custom_class_host.c index e0f9ce5b0..39d4c260a 100644 --- a/tinyusb/class/custom_class_host.c +++ b/tinyusb/class/custom_class_host.c @@ -57,10 +57,7 @@ //--------------------------------------------------------------------+ custom_interface_info_t custom_interface[TUSB_CFG_HOST_DEVICE_MAX]; -//--------------------------------------------------------------------+ -// APPLICATION API -//--------------------------------------------------------------------+ -tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length) +static tusb_error_t cush_validate_paras(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length) { if ( !tusbh_custom_is_mounted(dev_addr, vendor_id, product_id) ) { @@ -68,6 +65,16 @@ tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t pr } ASSERT( p_buffer != NULL && length != 0, TUSB_ERROR_INVALID_PARA); + + return TUSB_ERROR_NONE; +} +//--------------------------------------------------------------------+ +// APPLICATION API (need to check parameters) +//--------------------------------------------------------------------+ +tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length) +{ + ASSERT_STATUS( cush_validate_paras(dev_addr, vendor_id, product_id, p_buffer, length) ); + if ( !hcd_pipe_is_idle(custom_interface[dev_addr-1].pipe_in) ) { return TUSB_ERROR_INTERFACE_IS_BUSY; @@ -80,6 +87,15 @@ tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t pr tusb_error_t tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void const * p_data, uint16_t length) { + ASSERT_STATUS( cush_validate_paras(dev_addr, vendor_id, product_id, p_data, length) ); + + if ( !hcd_pipe_is_idle(custom_interface[dev_addr-1].pipe_out) ) + { + return TUSB_ERROR_INTERFACE_IS_BUSY; + } + + (void) hcd_pipe_xfer( custom_interface[dev_addr-1].pipe_out, p_data, length, true); + return TUSB_ERROR_NONE; } diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index 89e5ab57b..0a15f9355 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -456,7 +456,7 @@ bool hcd_pipe_is_idle(pipe_handle_t pipe_hdl) void async_advance_isr(ehci_qhd_t * const async_head) { // TODO do we need to close addr0 - if(async_head->is_removing) // closing control pipe of addr0 + if (async_head->is_removing) // closing control pipe of addr0 { async_head->is_removing = 0; async_head->p_qtd_list_head = async_head->p_qtd_list_tail = NULL; @@ -469,17 +469,17 @@ void async_advance_isr(ehci_qhd_t * const async_head) { // check if control endpoint is removing ehci_qhd_t *p_control_qhd = &ehci_data.device[relative_dev_addr].control.qhd; - if( p_control_qhd->is_removing ) + if ( p_control_qhd->is_removing ) { - p_control_qhd->is_removing = 0; - p_control_qhd->used = 0; + p_control_qhd->is_removing = 0; + p_control_qhd->used = 0; // Host Controller has cleaned up its cached data for this device, set state to unplug usbh_devices[relative_dev_addr+1].state = TUSB_DEVICE_STATE_UNPLUG; for (uint8_t i=0; i