mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-15 20:42:23 +00:00
create new name for multiple port API, to simplify API
This commit is contained in:
parent
a55fcece4c
commit
08ea1c35cb
@ -79,14 +79,14 @@ int main(void)
|
||||
void virtual_com_task(void)
|
||||
{
|
||||
// connected and there are data available
|
||||
if ( tud_mounted(0) && tud_cdc_available(0) )
|
||||
if ( tud_mounted() && tud_cdc_available() )
|
||||
{
|
||||
uint8_t buf[64];
|
||||
|
||||
// read and echo back
|
||||
uint32_t count = tud_cdc_read(0, buf, sizeof(buf));
|
||||
uint32_t count = tud_cdc_read(buf, sizeof(buf));
|
||||
|
||||
tud_cdc_write(0, buf, count);
|
||||
tud_cdc_write(buf, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,33 +76,33 @@ STATIC_VAR cdcd_data_t cdcd_data[CONTROLLER_DEVICE_NUMBER];
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_cdc_connected(uint8_t port)
|
||||
bool tud_n_cdc_connected(uint8_t port)
|
||||
{
|
||||
return cdcd_data[port].connected;
|
||||
}
|
||||
|
||||
uint32_t tud_cdc_available(uint8_t port)
|
||||
uint32_t tud_n_cdc_available(uint8_t port)
|
||||
{
|
||||
return fifo_count(&_rx_ff);
|
||||
}
|
||||
|
||||
int tud_cdc_read_char(uint8_t port)
|
||||
int tud_n_cdc_read_char(uint8_t port)
|
||||
{
|
||||
uint8_t ch;
|
||||
return fifo_read(&_rx_ff, &ch) ? ch : (-1);
|
||||
}
|
||||
|
||||
uint32_t tud_cdc_read(uint8_t port, void* buffer, uint32_t bufsize)
|
||||
uint32_t tud_n_cdc_read(uint8_t port, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
return fifo_read_n(&_rx_ff, buffer, bufsize);
|
||||
}
|
||||
|
||||
uint32_t tud_cdc_write_char(uint8_t port, char ch)
|
||||
uint32_t tud_n_cdc_write_char(uint8_t port, char ch)
|
||||
{
|
||||
return fifo_write(&_tx_ff, &ch);
|
||||
}
|
||||
|
||||
uint32_t tud_cdc_write(uint8_t port, void const* buffer, uint32_t bufsize)
|
||||
uint32_t tud_n_cdc_write(uint8_t port, void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
return fifo_write_n(&_tx_ff, buffer, bufsize);
|
||||
}
|
||||
@ -280,7 +280,7 @@ tusb_error_t cdcd_xfer_cb(uint8_t port, uint8_t edpt_addr, tusb_event_t event, u
|
||||
|
||||
void cdcd_sof(uint8_t port)
|
||||
{
|
||||
if ( !tud_cdc_connected(port) ) return;
|
||||
if ( !tud_n_cdc_connected(port) ) return;
|
||||
|
||||
uint8_t edpt = cdcd_data[port].edpt_addr[CDC_PIPE_DATA_IN];
|
||||
|
||||
|
@ -53,17 +53,49 @@
|
||||
* @{ */
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
// APPLICATION API (Multiple Ports)
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_cdc_connected(uint8_t port);
|
||||
uint32_t tud_cdc_available(uint8_t port);
|
||||
bool tud_n_cdc_connected(uint8_t port);
|
||||
uint32_t tud_n_cdc_available(uint8_t port);
|
||||
|
||||
int tud_cdc_read_char(uint8_t port);
|
||||
uint32_t tud_cdc_read(uint8_t port, void* buffer, uint32_t bufsize);
|
||||
int tud_n_cdc_read_char(uint8_t port);
|
||||
uint32_t tud_n_cdc_read(uint8_t port, void* buffer, uint32_t bufsize);
|
||||
|
||||
uint32_t tud_cdc_write_char(uint8_t port, char ch);
|
||||
uint32_t tud_cdc_write(uint8_t port, void const* buffer, uint32_t bufsize);
|
||||
uint32_t tud_n_cdc_write_char(uint8_t port, char ch);
|
||||
uint32_t tud_n_cdc_write(uint8_t port, void const* buffer, uint32_t bufsize);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API (Single Port)
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool tud_cdc_connected(void)
|
||||
{
|
||||
return tud_n_cdc_connected(0);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_available(void)
|
||||
{
|
||||
return tud_n_cdc_available(0);
|
||||
}
|
||||
|
||||
static inline int tud_cdc_read_char(void)
|
||||
{
|
||||
return tud_n_cdc_read_char(0);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_read(void* buffer, uint32_t bufsize)
|
||||
{
|
||||
return tud_n_cdc_read(0, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_write_char(char ch)
|
||||
{
|
||||
return tud_n_cdc_write_char(0, ch);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_write(void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
return tud_n_cdc_write(0, buffer, bufsize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CALLBACK API
|
||||
|
@ -108,9 +108,9 @@ static tusb_error_t get_descriptor(uint8_t port, tusb_control_request_t const *
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION INTERFACE
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_mounted(uint8_t port)
|
||||
bool tud_n_mounted(uint8_t port)
|
||||
{
|
||||
return usbd_devices[port].state == TUSB_DEVICE_STATE_CONFIGURED;
|
||||
return usbd_devices[port].state == TUSB_DEVICE_STATE_CONFIGURED;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -100,7 +100,13 @@ typedef struct {
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_mounted(uint8_t port);
|
||||
bool tud_n_mounted(uint8_t port);
|
||||
|
||||
static inline bool tud_mounted(void)
|
||||
{
|
||||
return tud_n_mounted(0);
|
||||
}
|
||||
|
||||
|
||||
/*------------- Callback -------------*/
|
||||
/** \brief Callback function that will be invoked device is mounted (configured) by USB host
|
||||
|
@ -65,22 +65,18 @@ extern "C" {
|
||||
* @{ */
|
||||
|
||||
/** \brief Initialize USB controller hardware
|
||||
* \returns true if succeedded
|
||||
* \returns true if succeeded
|
||||
* \note This function is invoked by \ref tusb_init as part of the initialization.
|
||||
*/
|
||||
bool tusb_hal_init(void);
|
||||
|
||||
/** \brief Enable USB Interrupt on a specific USB Controller
|
||||
* \param[in] port is a zero-based index to identify USB controller's ID
|
||||
* \note Some MCUs such as NXP LPC43xx has multiple USB controllers. It is necessary to know which USB controller for
|
||||
* those MCUs.
|
||||
*/
|
||||
void tusb_hal_init_enable(uint8_t port);
|
||||
|
||||
/** \brief Disable USB Interrupt on a specific USB Controller
|
||||
* \param[in] port is a zero-based index to identify USB controller's ID
|
||||
* \note Some MCUs such as NXP LPC43xx has multiple USB controllers. It is necessary to know which USB controller for
|
||||
* those MCUs.
|
||||
*/
|
||||
void tusb_hal_init_disable(uint8_t port);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user