diff options
| author | hathach <[email protected]> | 2013-07-02 16:41:13 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-07-02 16:41:13 +0700 |
| commit | 6ce90e2bd8d1599df22af8dc670d4187a1ec6dc5 (patch) | |
| tree | 65d8a8eb72322d5b09e35aa42ea5f05e4d2a5663 /tinyusb | |
| parent | 51f894b0bf31fd046cca6251679b188bed3e3024 (diff) | |
add tusbh_cdc_send, t usbh_cdc_receive
add cdc_serial_app for virtual com demo
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/class/cdc_host.c | 37 | ||||
| -rw-r--r-- | tinyusb/class/cdc_host.h | 6 | ||||
| -rw-r--r-- | tinyusb/class/custom_class.h | 2 | ||||
| -rw-r--r-- | tinyusb/common/errors.h | 1 |
4 files changed, 40 insertions, 6 deletions
diff --git a/tinyusb/class/cdc_host.c b/tinyusb/class/cdc_host.c index ce1f67e20..1520656fe 100644 --- a/tinyusb/class/cdc_host.c +++ b/tinyusb/class/cdc_host.c @@ -57,18 +57,51 @@ //--------------------------------------------------------------------+ /*STATIC_*/ cdch_data_t cdch_data[TUSB_CFG_HOST_DEVICE_MAX]; +STATIC_ INLINE_ bool tusbh_cdc_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; +STATIC_ INLINE_ bool tusbh_cdc_is_mounted(uint8_t dev_addr) +{ + return (tusbh_device_get_mounted_class_flag(dev_addr) & BIT_(TUSB_CLASS_CDC)) != 0; +} + //--------------------------------------------------------------------+ // APPLICATION API (parameter validation needed) //--------------------------------------------------------------------+ bool tusbh_cdc_serial_is_mounted(uint8_t dev_addr) { // TODO consider all AT Command as serial candidate - return - (tusbh_device_get_mounted_class_flag(dev_addr) & BIT_(TUSB_CLASS_CDC) ) && + return tusbh_cdc_is_mounted(dev_addr) && (CDC_COMM_PROTOCOL_ATCOMMAND <= cdch_data[dev_addr-1].interface_protocol) && (cdch_data[dev_addr-1].interface_protocol <= CDC_COMM_PROTOCOL_ATCOMMAND_CDMA); } +tusb_error_t tusbh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify) +{ + ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); + ASSERT( p_data != NULL && length, TUSB_ERROR_INVALID_PARA); + + pipe_handle_t pipe_out = cdch_data[dev_addr-1].pipe_out; + if ( !hcd_pipe_is_idle(pipe_out) ) + { + return TUSB_ERROR_INTERFACE_IS_BUSY; + } + + return hcd_pipe_xfer( pipe_out, (void *) p_data, length, is_notify); +} + +tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify) +{ + ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); + ASSERT( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA); + + pipe_handle_t pipe_in = cdch_data[dev_addr-1].pipe_in; + if ( !hcd_pipe_is_idle(pipe_in) ) + { + return TUSB_ERROR_INTERFACE_IS_BUSY; + } + + return hcd_pipe_xfer( pipe_in, p_buffer, length, is_notify); +} + //--------------------------------------------------------------------+ // USBH-CLASS DRIVER API //--------------------------------------------------------------------+ diff --git a/tinyusb/class/cdc_host.h b/tinyusb/class/cdc_host.h index 2b39a6fd7..fde2e2e11 100644 --- a/tinyusb/class/cdc_host.h +++ b/tinyusb/class/cdc_host.h @@ -57,12 +57,12 @@ //--------------------------------------------------------------------+ // APPLICATION PUBLIC API //--------------------------------------------------------------------+ -//bool tusbh_cdc_acm_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; bool tusbh_cdc_serial_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; bool tusbh_cdc_rndis_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; -tusb_interface_status_t tusbh_cdc_send(void const * p_data, uint32_t length, bool is_notify); - +void tusbh_cdc_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK; +tusb_error_t tusbh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify); +tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify); //--------------------------------------------------------------------+ // USBH-CLASS API //--------------------------------------------------------------------+ diff --git a/tinyusb/class/custom_class.h b/tinyusb/class/custom_class.h index 1d226d489..9bc4046fe 100644 --- a/tinyusb/class/custom_class.h +++ b/tinyusb/class/custom_class.h @@ -61,7 +61,7 @@ typedef struct { //--------------------------------------------------------------------+ // USBH-CLASS DRIVER API //--------------------------------------------------------------------+ -STATIC_ INLINE_ bool tusbh_custom_is_mounted(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id); +STATIC_ INLINE_ bool tusbh_custom_is_mounted(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id) ATTR_PURE ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; STATIC_ INLINE_ bool tusbh_custom_is_mounted(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id) { (void) vendor_id; // TODO check this later diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h index 6118242ad..61ac3998d 100644 --- a/tinyusb/common/errors.h +++ b/tinyusb/common/errors.h @@ -83,6 +83,7 @@ ENTRY(TUSB_ERROR_CDCH_DESCRIPTOR_CORRUPTED )\ ENTRY(TUSB_ERROR_CDCH_UNSUPPORTED_SUBCLASS )\ ENTRY(TUSB_ERROR_CDCH_UNSUPPORTED_PROTOCOL )\ + ENTRY(TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED )\ ENTRY(TUSB_ERROR_NOT_SUPPORTED_YET )\ ENTRY(TUSB_ERROR_FAILED )\ |
