mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
simplify tusbh_cdc_ to tuh_cdc_
This commit is contained in:
parent
6ee14bdd23
commit
a3e7c104b3
@ -60,7 +60,7 @@ static uint8_t received_bytes; // set by transfer complete callback
|
||||
//--------------------------------------------------------------------+
|
||||
// tinyusb callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
void tusbh_cdc_mounted_cb(uint8_t dev_addr)
|
||||
void tuh_cdc_mounted_cb(uint8_t dev_addr)
|
||||
{ // application set-up
|
||||
printf("\na CDC device (address %d) is mounted\n", dev_addr);
|
||||
|
||||
@ -69,16 +69,16 @@ void tusbh_cdc_mounted_cb(uint8_t dev_addr)
|
||||
received_bytes = 0;
|
||||
|
||||
osal_semaphore_reset(sem_hdl);
|
||||
tusbh_cdc_receive(dev_addr, serial_in_buffer, SERIAL_BUFFER_SIZE, true); // schedule first transfer
|
||||
tuh_cdc_receive(dev_addr, serial_in_buffer, SERIAL_BUFFER_SIZE, true); // schedule first transfer
|
||||
}
|
||||
|
||||
void tusbh_cdc_unmounted_cb(uint8_t dev_addr)
|
||||
void tuh_cdc_unmounted_cb(uint8_t dev_addr)
|
||||
{ // application tear-down
|
||||
printf("\na CDC device (address %d) is unmounted \n", dev_addr);
|
||||
}
|
||||
|
||||
// invoked ISR context
|
||||
void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes)
|
||||
void tuh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes)
|
||||
{
|
||||
(void) dev_addr; // compiler warnings
|
||||
|
||||
@ -94,7 +94,7 @@ void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_
|
||||
|
||||
case TUSB_EVENT_XFER_ERROR:
|
||||
received_bytes = 0; // ignore
|
||||
tusbh_cdc_receive(dev_addr, serial_in_buffer, SERIAL_BUFFER_SIZE, true); // waiting for next data
|
||||
tuh_cdc_receive(dev_addr, serial_in_buffer, SERIAL_BUFFER_SIZE, true); // waiting for next data
|
||||
break;
|
||||
|
||||
case TUSB_EVENT_XFER_STALLED:
|
||||
@ -131,16 +131,16 @@ OSAL_TASK_FUNCTION( cdc_serial_host_app_task, p_task_para)
|
||||
//------------- send characters got from uart terminal to the first CDC device -------------//
|
||||
for(uint8_t dev_addr=1; dev_addr <= TUSB_CFG_HOST_DEVICE_MAX; dev_addr++)
|
||||
{
|
||||
if ( tusbh_cdc_serial_is_mounted(dev_addr) )
|
||||
if ( tuh_cdc_serial_is_mounted(dev_addr) )
|
||||
{
|
||||
int ch_tx = getchar();
|
||||
if ( ch_tx > 0 )
|
||||
{ // USB is much faster than serial, here we assume usb is always complete. There could be some characters missing though
|
||||
serial_out_buffer[0] = (uint8_t) ch_tx;
|
||||
|
||||
if ( !tusbh_cdc_is_busy(dev_addr, CDC_PIPE_DATA_OUT) )
|
||||
if ( !tuh_cdc_is_busy(dev_addr, CDC_PIPE_DATA_OUT) )
|
||||
{
|
||||
tusbh_cdc_send(dev_addr, serial_out_buffer, 1, false); // no need for callback on serial out pipe
|
||||
tuh_cdc_send(dev_addr, serial_out_buffer, 1, false); // no need for callback on serial out pipe
|
||||
}
|
||||
}
|
||||
break; // demo app only communicate with the first CDC-capable device
|
||||
@ -157,9 +157,9 @@ OSAL_TASK_FUNCTION( cdc_serial_host_app_task, p_task_para)
|
||||
|
||||
for(uint8_t dev_addr=1; dev_addr <= TUSB_CFG_HOST_DEVICE_MAX; dev_addr++)
|
||||
{
|
||||
if ( tusbh_cdc_serial_is_mounted(dev_addr) )
|
||||
if ( tuh_cdc_serial_is_mounted(dev_addr) )
|
||||
{
|
||||
tusbh_cdc_receive(dev_addr, serial_in_buffer, SERIAL_BUFFER_SIZE, true);
|
||||
tuh_cdc_receive(dev_addr, serial_in_buffer, SERIAL_BUFFER_SIZE, true);
|
||||
|
||||
break; // demo app only communicate with the first CDC-capable device
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ STATIC_ INLINE_ bool tusbh_cdc_is_mounted(uint8_t dev_addr)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool tusbh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid)
|
||||
bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid)
|
||||
{
|
||||
if ( !tusbh_cdc_is_mounted(dev_addr) ) return false;
|
||||
|
||||
@ -106,7 +106,7 @@ bool tusbh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid)
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API (parameter validation needed)
|
||||
//--------------------------------------------------------------------+
|
||||
bool tusbh_cdc_serial_is_mounted(uint8_t dev_addr)
|
||||
bool tuh_cdc_serial_is_mounted(uint8_t dev_addr)
|
||||
{
|
||||
// TODO consider all AT Command as serial candidate
|
||||
return tusbh_cdc_is_mounted(dev_addr) &&
|
||||
@ -114,7 +114,7 @@ bool tusbh_cdc_serial_is_mounted(uint8_t dev_addr)
|
||||
(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)
|
||||
tusb_error_t tuh_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);
|
||||
@ -125,7 +125,7 @@ tusb_error_t tusbh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t leng
|
||||
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)
|
||||
tusb_error_t tuh_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);
|
||||
@ -217,7 +217,7 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
|
||||
|
||||
{
|
||||
// FIXME mounted class flag is not set yet
|
||||
tusbh_cdc_mounted_cb(dev_addr);
|
||||
tuh_cdc_mounted_cb(dev_addr);
|
||||
}
|
||||
|
||||
OSAL_SUBTASK_END
|
||||
@ -225,7 +225,7 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
|
||||
|
||||
void cdch_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
tusbh_cdc_xfer_isr( pipe_hdl.dev_addr, event, get_app_pipeid(pipe_hdl), xferred_bytes );
|
||||
tuh_cdc_xfer_isr( pipe_hdl.dev_addr, event, get_app_pipeid(pipe_hdl), xferred_bytes );
|
||||
}
|
||||
|
||||
void cdch_close(uint8_t dev_addr)
|
||||
@ -238,7 +238,7 @@ void cdch_close(uint8_t dev_addr)
|
||||
|
||||
memclr_(p_cdc, sizeof(cdch_data_t));
|
||||
|
||||
tusbh_cdc_unmounted_cb(dev_addr);
|
||||
tuh_cdc_unmounted_cb(dev_addr);
|
||||
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@
|
||||
* \retval true if device supports
|
||||
* \retval false if device does not support or is not mounted
|
||||
*/
|
||||
bool tusbh_cdc_serial_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
|
||||
bool tuh_cdc_serial_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
/** \brief Check if the interface is currently busy or not
|
||||
* \param[in] dev_addr device address
|
||||
@ -71,9 +71,9 @@ bool tusbh_cdc_serial_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RE
|
||||
* \retval false if the interface is not busy, meaning the stack successfully transferred data from/to device
|
||||
* \note This function is used to check if previous transfer is complete (success or error), so that the next transfer
|
||||
* can be scheduled. User needs to make sure the corresponding interface is mounted
|
||||
* (by \ref tusbh_cdc_serial_is_mounted) before calling this function.
|
||||
* (by \ref tuh_cdc_serial_is_mounted) before calling this function.
|
||||
*/
|
||||
bool tusbh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
|
||||
bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
/** \brief Perform USB OUT transfer to device
|
||||
* \param[in] dev_addr device address
|
||||
@ -86,7 +86,7 @@ bool tusbh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) ATTR_PURE ATTR_WA
|
||||
* \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the
|
||||
* interface's callback function. \a p_data must be declared with \ref TUSB_CFG_ATTR_USBRAM.
|
||||
*/
|
||||
tusb_error_t tusbh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify);
|
||||
tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify);
|
||||
|
||||
/** \brief Perform USB IN transfer to get data from device
|
||||
* \param[in] dev_addr device address
|
||||
@ -99,7 +99,7 @@ tusb_error_t tusbh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t leng
|
||||
* \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the
|
||||
* interface's callback function. \a p_data must be declared with \ref TUSB_CFG_ATTR_USBRAM.
|
||||
*/
|
||||
tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify);
|
||||
tusb_error_t tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CDC APPLICATION CALLBACKS
|
||||
@ -108,13 +108,13 @@ tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t lengt
|
||||
* \param[in] dev_addr Address of newly mounted device
|
||||
* \note This callback should be used by Application to set-up interface-related data
|
||||
*/
|
||||
void tusbh_cdc_mounted_cb(uint8_t dev_addr);
|
||||
void tuh_cdc_mounted_cb(uint8_t dev_addr);
|
||||
|
||||
/** \brief Callback function that will be invoked when a device with CDC Abstract Control Model interface is unmounted
|
||||
* \param[in] dev_addr Address of newly unmounted device
|
||||
* \note This callback should be used by Application to tear-down interface-related data
|
||||
*/
|
||||
void tusbh_cdc_unmounted_cb(uint8_t dev_addr);
|
||||
void tuh_cdc_unmounted_cb(uint8_t dev_addr);
|
||||
|
||||
/** \brief Callback function that is invoked when an transferring event occurred
|
||||
* \param[in] dev_addr Address of device
|
||||
@ -127,7 +127,7 @@ void tusbh_cdc_unmounted_cb(uint8_t dev_addr);
|
||||
* - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
|
||||
* \note
|
||||
*/
|
||||
void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes);
|
||||
void tuh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes);
|
||||
|
||||
/// @} // group CDC_Serial_Host
|
||||
/// @}
|
||||
|
Loading…
x
Reference in New Issue
Block a user