Merge branch 'master' into async_io
Signed-off-by: HiFiPhile <admin@hifiphile.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -206,153 +206,6 @@
|
||||
// Audio control interrupt EP - 6 Bytes according to UAC 2 specification (p. 74)
|
||||
#define CFG_TUD_AUDIO_INTERRUPT_EP_SZ 6
|
||||
|
||||
// Use software encoding/decoding
|
||||
|
||||
// The software coding feature of the driver is not mandatory. It is useful if, for instance, you have two I2S streams which need to be interleaved
|
||||
// into a single PCM stream as SAMPLE_1 | SAMPLE_2 | SAMPLE_3 | SAMPLE_4.
|
||||
//
|
||||
// Currently, only PCM type I encoding/decoding is supported!
|
||||
//
|
||||
// If the coding feature is to be used, support FIFOs need to be configured. Their sizes and numbers are defined below.
|
||||
|
||||
// Encoding/decoding is done in software and thus time consuming. If you can encode/decode your stream more efficiently do not use the
|
||||
// support FIFOs but write/read directly into/from the EP_X_SW_BUFFER_FIFOs using
|
||||
// - tud_audio_n_write() or
|
||||
// - tud_audio_n_read().
|
||||
// To write/read to/from the support FIFOs use
|
||||
// - tud_audio_n_write_support_ff() or
|
||||
// - tud_audio_n_read_support_ff().
|
||||
//
|
||||
// The encoding/decoding format type done is defined below.
|
||||
//
|
||||
// The encoding/decoding starts when the private callback functions
|
||||
// - audio_tx_done_cb()
|
||||
// - audio_rx_done_cb()
|
||||
// are invoked. If support FIFOs are used, the corresponding encoding/decoding functions are called from there.
|
||||
// Once encoding/decoding is done the result is put directly into the EP_X_SW_BUFFER_FIFOs. You can use the public callback functions
|
||||
// - tud_audio_tx_done_pre_load_cb() or tud_audio_tx_done_post_load_cb()
|
||||
// - tud_audio_rx_done_pre_read_cb() or tud_audio_rx_done_post_read_cb()
|
||||
// if you want to get informed what happened.
|
||||
//
|
||||
// If you don't use the support FIFOs you may use the public callback functions
|
||||
// - tud_audio_tx_done_pre_load_cb() or tud_audio_tx_done_post_load_cb()
|
||||
// - tud_audio_rx_done_pre_read_cb() or tud_audio_rx_done_post_read_cb()
|
||||
// to write/read from/into the EP_X_SW_BUFFER_FIFOs at the right time.
|
||||
//
|
||||
// If you need a different encoding which is not support so far implement it in the
|
||||
// - audio_tx_done_cb()
|
||||
// - audio_rx_done_cb()
|
||||
// functions.
|
||||
|
||||
// Enable encoding/decodings - for these to work, support FIFOs need to be setup in appropriate numbers and size
|
||||
// The actual coding parameters of active AS alternate interface is parsed from the descriptors
|
||||
|
||||
// The item size of the FIFO is always fixed to one i.e. bytes! Furthermore, the actively used FIFO depth is reconfigured such that the depth is a multiple
|
||||
// of the current sample size in order to avoid samples to get split up in case of a wrap in the FIFO ring buffer (depth = (max_depth / sample_sz) * sample_sz)!
|
||||
// This is important to remind in case you use DMAs! If the sample sizes changes, the DMA MUST BE RECONFIGURED just like the FIFOs for a different depth!!!
|
||||
|
||||
// For PCM encoding/decoding
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
#define CFG_TUD_AUDIO_ENABLE_ENCODING 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
#define CFG_TUD_AUDIO_ENABLE_DECODING 0
|
||||
#endif
|
||||
|
||||
// This enabling allows to save the current coding parameters e.g. # of bytes per sample etc. - TYPE_I includes common PCM encoding
|
||||
#ifndef CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
|
||||
#define CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
|
||||
#define CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING 0
|
||||
#endif
|
||||
|
||||
// Type I Coding parameters not given within UAC2 descriptors
|
||||
// It would be possible to allow for a more flexible setting and not fix this parameter as done below. However, this is most often not needed and kept for later if really necessary. The more flexible setting could be implemented within set_interface(), however, how the values are saved per alternate setting is to be determined!
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING && CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX
|
||||
#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
|
||||
#endif
|
||||
#if CFG_TUD_AUDIO > 1
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_2_CHANNEL_PER_FIFO_TX
|
||||
#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
|
||||
#endif
|
||||
#endif
|
||||
#if CFG_TUD_AUDIO > 2
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_3_CHANNEL_PER_FIFO_TX
|
||||
#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING && CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_RX
|
||||
#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
|
||||
#endif
|
||||
#if CFG_TUD_AUDIO > 1
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_2_CHANNEL_PER_FIFO_RX
|
||||
#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
|
||||
#endif
|
||||
#endif
|
||||
#if CFG_TUD_AUDIO > 2
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_3_CHANNEL_PER_FIFO_RX
|
||||
#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Remaining types not support so far
|
||||
|
||||
// Number of support FIFOs to set up - multiple channels can be handled by one FIFO - very common is two channels per FIFO stemming from one I2S interface
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO
|
||||
#define CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO 0
|
||||
#endif
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO
|
||||
#define CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO 0
|
||||
#endif
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO
|
||||
#define CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO
|
||||
#define CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO 0
|
||||
#endif
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO
|
||||
#define CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO 0
|
||||
#endif
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO
|
||||
#define CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO 0
|
||||
#endif
|
||||
|
||||
// Size of support FIFOs IN BYTES - if size > 0 there are as many FIFOs set up as CFG_TUD_AUDIO_FUNC_X_N_TX_SUPP_SW_FIFO and CFG_TUD_AUDIO_FUNC_X_N_RX_SUPP_SW_FIFO
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ
|
||||
#define CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ 0 // FIFO size - minimum size: ceil(f_s/1000) * max(# of TX channels) / (# of TX support FIFOs) * max(# of bytes per sample)
|
||||
#endif
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ
|
||||
#define CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ 0
|
||||
#endif
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ
|
||||
#define CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ
|
||||
#define CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ 0 // FIFO size - minimum size: ceil(f_s/1000) * max(# of RX channels) / (# of RX support FIFOs) * max(# of bytes per sample)
|
||||
#endif
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ
|
||||
#define CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ 0
|
||||
#endif
|
||||
#ifndef CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ
|
||||
#define CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ 0
|
||||
#endif
|
||||
|
||||
//static_assert(sizeof(tud_audio_desc_lengths) != CFG_TUD_AUDIO, "Supply audio function descriptor pack length!");
|
||||
|
||||
// Supported types of this driver:
|
||||
// AUDIO_DATA_FORMAT_TYPE_I_PCM - Required definitions: CFG_TUD_AUDIO_N_CHANNELS and CFG_TUD_AUDIO_BYTES_PER_CHANNEL
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -368,38 +221,23 @@ extern "C" {
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_audio_n_mounted (uint8_t func_id);
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
|
||||
uint16_t tud_audio_n_available (uint8_t func_id);
|
||||
uint16_t tud_audio_n_read (uint8_t func_id, void* buffer, uint16_t bufsize);
|
||||
bool tud_audio_n_clear_ep_out_ff (uint8_t func_id); // Delete all content in the EP OUT FIFO
|
||||
tu_fifo_t* tud_audio_n_get_ep_out_ff (uint8_t func_id);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
bool tud_audio_n_clear_rx_support_ff (uint8_t func_id, uint8_t ff_idx); // Delete all content in the support RX FIFOs
|
||||
uint16_t tud_audio_n_available_support_ff (uint8_t func_id, uint8_t ff_idx);
|
||||
uint16_t tud_audio_n_read_support_ff (uint8_t func_id, uint8_t ff_idx, void* buffer, uint16_t bufsize);
|
||||
tu_fifo_t* tud_audio_n_get_rx_support_ff (uint8_t func_id, uint8_t ff_idx);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN
|
||||
uint16_t tud_audio_n_write (uint8_t func_id, const void * data, uint16_t len);
|
||||
bool tud_audio_n_clear_ep_in_ff (uint8_t func_id); // Delete all content in the EP IN FIFO
|
||||
tu_fifo_t* tud_audio_n_get_ep_in_ff (uint8_t func_id);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
uint16_t tud_audio_n_flush_tx_support_ff (uint8_t func_id); // Force all content in the support TX FIFOs to be written into EP SW FIFO
|
||||
bool tud_audio_n_clear_tx_support_ff (uint8_t func_id, uint8_t ff_idx);
|
||||
uint16_t tud_audio_n_write_support_ff (uint8_t func_id, uint8_t ff_idx, const void * data, uint16_t len);
|
||||
tu_fifo_t* tud_audio_n_get_tx_support_ff (uint8_t func_id, uint8_t ff_idx);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_INTERRUPT_EP
|
||||
bool tud_audio_int_n_write (uint8_t func_id, const audio_interrupt_data_t * data);
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Interface0)
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -408,35 +246,21 @@ static inline bool tud_audio_mounted (void);
|
||||
|
||||
// RX API
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
|
||||
static inline uint16_t tud_audio_available (void);
|
||||
static inline bool tud_audio_clear_ep_out_ff (void); // Delete all content in the EP OUT FIFO
|
||||
static inline uint16_t tud_audio_read (void* buffer, uint16_t bufsize);
|
||||
static inline tu_fifo_t* tud_audio_get_ep_out_ff (void);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
static inline bool tud_audio_clear_rx_support_ff (uint8_t ff_idx);
|
||||
static inline uint16_t tud_audio_available_support_ff (uint8_t ff_idx);
|
||||
static inline uint16_t tud_audio_read_support_ff (uint8_t ff_idx, void* buffer, uint16_t bufsize);
|
||||
static inline tu_fifo_t* tud_audio_get_rx_support_ff (uint8_t ff_idx);
|
||||
#endif
|
||||
|
||||
// TX API
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN
|
||||
static inline uint16_t tud_audio_write (const void * data, uint16_t len);
|
||||
static inline bool tud_audio_clear_ep_in_ff (void);
|
||||
static inline tu_fifo_t* tud_audio_get_ep_in_ff (void);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
static inline uint16_t tud_audio_flush_tx_support_ff (void);
|
||||
static inline uint16_t tud_audio_clear_tx_support_ff (uint8_t ff_idx);
|
||||
static inline uint16_t tud_audio_write_support_ff (uint8_t ff_idx, const void * data, uint16_t len);
|
||||
static inline tu_fifo_t* tud_audio_get_tx_support_ff (uint8_t ff_idx);
|
||||
#endif
|
||||
|
||||
// INT CTR API
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_INTERRUPT_EP
|
||||
@@ -593,7 +417,7 @@ static inline bool tud_audio_mounted(void)
|
||||
|
||||
// RX API
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
|
||||
|
||||
static inline uint16_t tud_audio_available(void)
|
||||
{
|
||||
@@ -617,33 +441,9 @@ static inline tu_fifo_t* tud_audio_get_ep_out_ff(void)
|
||||
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
|
||||
static inline bool tud_audio_clear_rx_support_ff(uint8_t ff_idx)
|
||||
{
|
||||
return tud_audio_n_clear_rx_support_ff(0, ff_idx);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_available_support_ff(uint8_t ff_idx)
|
||||
{
|
||||
return tud_audio_n_available_support_ff(0, ff_idx);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_read_support_ff(uint8_t ff_idx, void* buffer, uint16_t bufsize)
|
||||
{
|
||||
return tud_audio_n_read_support_ff(0, ff_idx, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline tu_fifo_t* tud_audio_get_rx_support_ff(uint8_t ff_idx)
|
||||
{
|
||||
return tud_audio_n_get_rx_support_ff(0, ff_idx);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// TX API
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN
|
||||
|
||||
static inline uint16_t tud_audio_write(const void * data, uint16_t len)
|
||||
{
|
||||
@@ -662,30 +462,6 @@ static inline tu_fifo_t* tud_audio_get_ep_in_ff(void)
|
||||
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
|
||||
static inline uint16_t tud_audio_flush_tx_support_ff(void)
|
||||
{
|
||||
return tud_audio_n_flush_tx_support_ff(0);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_clear_tx_support_ff(uint8_t ff_idx)
|
||||
{
|
||||
return tud_audio_n_clear_tx_support_ff(0, ff_idx);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_write_support_ff(uint8_t ff_idx, const void * data, uint16_t len)
|
||||
{
|
||||
return tud_audio_n_write_support_ff(0, ff_idx, data, len);
|
||||
}
|
||||
|
||||
static inline tu_fifo_t* tud_audio_get_tx_support_ff(uint8_t ff_idx)
|
||||
{
|
||||
return tud_audio_n_get_tx_support_ff(0, ff_idx);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_INTERRUPT_EP
|
||||
static inline bool tud_audio_int_write(const audio_interrupt_data_t * data)
|
||||
{
|
||||
|
||||
@@ -672,7 +672,7 @@ void cdch_close(uint8_t daddr) {
|
||||
|
||||
bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) {
|
||||
// TODO handle stall response, retry failed transfer ...
|
||||
TU_ASSERT(event == XFER_RESULT_SUCCESS);
|
||||
TU_VERIFY(event == XFER_RESULT_SUCCESS);
|
||||
|
||||
uint8_t const idx = get_idx_by_ep_addr(daddr, ep_addr);
|
||||
cdch_interface_t * p_cdc = get_itf(idx);
|
||||
|
||||
@@ -444,7 +444,7 @@ bool hidh_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t result, uint32_t
|
||||
hidh_epbuf_t* epbuf = get_hid_epbuf(idx);
|
||||
|
||||
if (dir == TUSB_DIR_IN) {
|
||||
TU_LOG_DRV(" Get Report callback (%u, %u)\r\n", daddr, idx);
|
||||
TU_LOG_DRV(" [idx=%u] Get Report callback\r\n", idx);
|
||||
TU_LOG3_MEM(epbuf->epin, xferred_bytes, 2);
|
||||
tuh_hid_report_received_cb(daddr, idx, epbuf->epin, (uint16_t) xferred_bytes);
|
||||
} else {
|
||||
@@ -461,7 +461,9 @@ void hidh_close(uint8_t daddr) {
|
||||
hidh_interface_t* p_hid = &_hidh_itf[i];
|
||||
if (p_hid->daddr == daddr) {
|
||||
TU_LOG_DRV(" HIDh close addr = %u index = %u\r\n", daddr, i);
|
||||
if (tuh_hid_umount_cb) tuh_hid_umount_cb(daddr, i);
|
||||
if (tuh_hid_umount_cb) {
|
||||
tuh_hid_umount_cb(daddr, i);
|
||||
}
|
||||
tu_memclr(p_hid, sizeof(hidh_interface_t));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,8 +510,8 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MSC_STAGE_DATA:
|
||||
TU_LOG_DRV(" SCSI Data [Lun%u]\r\n", p_cbw->lun);
|
||||
|
||||
@@ -81,6 +81,7 @@ typedef struct {
|
||||
static netd_interface_t _netd_itf;
|
||||
CFG_TUD_MEM_SECTION static netd_epbuf_t _netd_epbuf;
|
||||
static bool can_xmit;
|
||||
static bool ecm_link_is_up = true; // Store link state for ECM mode
|
||||
|
||||
void tud_network_recv_renew(void) {
|
||||
usbd_edpt_xfer(0, _netd_itf.ep_out, _netd_epbuf.rx, NETD_PACKET_SIZE);
|
||||
@@ -95,7 +96,11 @@ void netd_report(uint8_t *buf, uint16_t len) {
|
||||
const uint8_t rhport = 0;
|
||||
len = tu_min16(len, sizeof(ecm_notify_t));
|
||||
|
||||
TU_VERIFY(usbd_edpt_claim(rhport, _netd_itf.ep_notif), );
|
||||
if (!usbd_edpt_claim(rhport, _netd_itf.ep_notif)) {
|
||||
TU_LOG1("ECM: Failed to claim notification endpoint\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(_netd_epbuf.notify, buf, len);
|
||||
usbd_edpt_xfer(rhport, _netd_itf.ep_notif, _netd_epbuf.notify, len);
|
||||
}
|
||||
@@ -181,8 +186,6 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
|
||||
// Open endpoint pair for RNDIS
|
||||
TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &_netd_itf.ep_out, &_netd_itf.ep_in), 0);
|
||||
|
||||
tud_network_init_cb();
|
||||
|
||||
// we are ready to transmit a packet
|
||||
can_xmit = true;
|
||||
|
||||
@@ -196,11 +199,11 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
|
||||
}
|
||||
|
||||
static void ecm_report(bool nc) {
|
||||
const ecm_notify_t ecm_notify_nc = {
|
||||
ecm_notify_t ecm_notify_nc = {
|
||||
.header = {
|
||||
.bmRequestType = 0xA1,
|
||||
.bRequest = 0, /* NETWORK_CONNECTION aka NetworkConnection */
|
||||
.wValue = 1, /* Connected */
|
||||
.wValue = ecm_link_is_up ? 1 : 0, /* Use current link state */
|
||||
.wLength = 0,
|
||||
},
|
||||
};
|
||||
@@ -259,7 +262,6 @@ bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
|
||||
|
||||
// TODO should be merge with RNDIS's after endpoint opened
|
||||
// Also should have opposite callback for application to disable network !!
|
||||
tud_network_init_cb();
|
||||
can_xmit = true; // we are ready to transmit a packet
|
||||
tud_network_recv_renew(); // prepare for incoming packets
|
||||
}
|
||||
@@ -286,7 +288,10 @@ bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
|
||||
/* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */
|
||||
if (0x43 /* SET_ETHERNET_PACKET_FILTER */ == request->bRequest) {
|
||||
tud_control_xfer(rhport, request, NULL, 0);
|
||||
ecm_report(true);
|
||||
// Only send connection notification if link is up
|
||||
if (ecm_link_is_up) {
|
||||
ecm_report(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (request->bmRequestType_bit.direction == TUSB_DIR_IN) {
|
||||
@@ -363,9 +368,8 @@ bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
}
|
||||
|
||||
if (_netd_itf.ecm_mode && (ep_addr == _netd_itf.ep_notif)) {
|
||||
if (sizeof(tusb_control_request_t) == xferred_bytes) {
|
||||
ecm_report(false);
|
||||
}
|
||||
// Notification transfer complete - endpoint is now free
|
||||
// Don't automatically send speed change notification after link state changes
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -398,4 +402,31 @@ void tud_network_xmit(void *ref, uint16_t arg) {
|
||||
do_in_xfer(_netd_epbuf.tx, len);
|
||||
}
|
||||
|
||||
// Set the network link state (up/down) and notify the host
|
||||
void tud_network_link_state(uint8_t rhport, bool is_up) {
|
||||
(void)rhport;
|
||||
|
||||
if (_netd_itf.ecm_mode) {
|
||||
ecm_link_is_up = is_up;
|
||||
|
||||
// For ECM mode, send network connection notification only
|
||||
// Don't trigger speed change notification for link state changes
|
||||
ecm_notify_t notify = {
|
||||
.header = {
|
||||
.bmRequestType = 0xA1,
|
||||
.bRequest = 0, /* NETWORK_CONNECTION */
|
||||
.wValue = is_up ? 1 : 0, /* 0 = disconnected, 1 = connected */
|
||||
.wLength = 0,
|
||||
},
|
||||
};
|
||||
notify.header.wIndex = _netd_itf.itf_num;
|
||||
netd_report((uint8_t *)¬ify, sizeof(notify.header));
|
||||
} else {
|
||||
// For RNDIS mode, we would need to implement RNDIS status indication
|
||||
// This is more complex and requires RNDIS_INDICATE_STATUS_MSG
|
||||
// For now, RNDIS doesn't support dynamic link state changes
|
||||
(void)is_up;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -110,6 +110,7 @@ typedef struct {
|
||||
NOTIFICATION_DONE
|
||||
} notification_xmit_state; // state of notification transmission
|
||||
bool notification_xmit_is_running; // notification is currently transmitted
|
||||
bool link_is_up; // current link state
|
||||
|
||||
// misc
|
||||
bool tud_network_recv_renew_active; // tud_network_recv_renew() is active (avoid recursive invocations)
|
||||
@@ -218,7 +219,7 @@ static void notification_xmit(uint8_t rhport, bool force_next) {
|
||||
.direction = TUSB_DIR_IN
|
||||
},
|
||||
.bRequest = CDC_NOTIF_NETWORK_CONNECTION,
|
||||
.wValue = 1 /* Connected */,
|
||||
.wValue = ncm_interface.link_is_up ? 1 : 0, /* Dynamic link state */
|
||||
.wIndex = ncm_interface.itf_num,
|
||||
.wLength = 0,
|
||||
},
|
||||
@@ -232,6 +233,7 @@ static void notification_xmit(uint8_t rhport, bool force_next) {
|
||||
ncm_interface.notification_xmit_is_running = true;
|
||||
} else {
|
||||
TU_LOG_DRV(" NOTIFICATION_FINISHED\n");
|
||||
ncm_interface.notification_xmit_is_running = false;
|
||||
}
|
||||
} // notification_xmit
|
||||
|
||||
@@ -755,6 +757,32 @@ static void tud_network_recv_renew_r(uint8_t rhport) {
|
||||
tud_network_recv_renew();
|
||||
} // tud_network_recv_renew
|
||||
|
||||
/**
|
||||
* Set the link state and send notification to host
|
||||
*/
|
||||
void tud_network_link_state(uint8_t rhport, bool is_up) {
|
||||
TU_LOG_DRV("tud_network_link_state(%d, %d)\n", rhport, is_up);
|
||||
|
||||
if (ncm_interface.link_is_up == is_up) {
|
||||
// No change in link state
|
||||
return;
|
||||
}
|
||||
|
||||
ncm_interface.link_is_up = is_up;
|
||||
|
||||
// Only send notification if we have an active data interface
|
||||
if (ncm_interface.itf_data_alt != 1) {
|
||||
TU_LOG_DRV(" link state notification skipped (interface not active)\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset notification state to send link state update
|
||||
ncm_interface.notification_xmit_state = NOTIFICATION_CONNECTED;
|
||||
|
||||
// Trigger notification transmission
|
||||
notification_xmit(rhport, false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// all the netd_*() stuff (interface TinyUSB -> driver)
|
||||
@@ -774,6 +802,12 @@ void netd_init(void) {
|
||||
for (int i = 0; i < RECV_NTB_N; ++i) {
|
||||
ncm_interface.recv_free_ntb[i] = &ncm_epbuf.recv[i].ntb;
|
||||
}
|
||||
// Default link state - can be configured via CFG_TUD_NCM_DEFAULT_LINK_UP
|
||||
#ifdef CFG_TUD_NCM_DEFAULT_LINK_UP
|
||||
ncm_interface.link_is_up = CFG_TUD_NCM_DEFAULT_LINK_UP;
|
||||
#else
|
||||
ncm_interface.link_is_up = true; // Default to link up if not set.
|
||||
#endif
|
||||
} // netd_init
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,6 +87,11 @@ void tud_network_init_cb(void);
|
||||
// TODO removed later since it is not part of tinyusb stack
|
||||
extern uint8_t tud_network_mac_address[6];
|
||||
|
||||
//------------- NCM -------------//
|
||||
|
||||
// Set the network link state (up/down) and notify the host
|
||||
void tud_network_link_state(uint8_t rhport, bool is_up);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL USBD-CLASS DRIVER API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
40
src/class/vendor/vendor_device.c
vendored
40
src/class/vendor/vendor_device.c
vendored
@@ -196,8 +196,8 @@ void vendord_reset(uint8_t rhport) {
|
||||
|
||||
uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) {
|
||||
TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == desc_itf->bInterfaceClass, 0);
|
||||
const uint8_t* desc_end = (const uint8_t*)desc_itf + max_len;
|
||||
const uint8_t* p_desc = tu_desc_next(desc_itf);
|
||||
const uint8_t* desc_end = (uint8_t const*)desc_itf + max_len;
|
||||
|
||||
// Find available interface
|
||||
vendord_interface_t* p_vendor = NULL;
|
||||
@@ -210,26 +210,26 @@ uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uin
|
||||
TU_VERIFY(p_vendor, 0);
|
||||
|
||||
p_vendor->itf_num = desc_itf->bInterfaceNumber;
|
||||
uint8_t found_ep = 0;
|
||||
while (found_ep < desc_itf->bNumEndpoints) {
|
||||
// skip non-endpoint descriptors
|
||||
while ( (TUSB_DESC_ENDPOINT != tu_desc_type(p_desc)) && (p_desc < desc_end) ) {
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
if (p_desc >= desc_end) {
|
||||
break;
|
||||
}
|
||||
while (tu_desc_is_valid(p_desc, desc_end)) {
|
||||
const uint8_t desc_type = tu_desc_type(p_desc);
|
||||
if (desc_type == TUSB_DESC_INTERFACE || desc_type == TUSB_DESC_INTERFACE_ASSOCIATION) {
|
||||
break; // end of this interface
|
||||
} else if (desc_type == TUSB_DESC_ENDPOINT) {
|
||||
const tusb_desc_endpoint_t* desc_ep = (const tusb_desc_endpoint_t*) p_desc;
|
||||
TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
|
||||
|
||||
const tusb_desc_endpoint_t* desc_ep = (const tusb_desc_endpoint_t*) p_desc;
|
||||
TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
|
||||
found_ep++;
|
||||
|
||||
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
|
||||
tu_edpt_stream_open(&p_vendor->tx.stream, desc_ep);
|
||||
tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
|
||||
} else {
|
||||
tu_edpt_stream_open(&p_vendor->rx.stream, desc_ep);
|
||||
TU_ASSERT(tu_edpt_stream_read_xfer(rhport, &p_vendor->rx.stream) > 0, 0); // prepare for incoming data
|
||||
// open endpoint stream, skip if already opened
|
||||
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
|
||||
if (p_vendor->tx.stream.ep_addr == 0) {
|
||||
tu_edpt_stream_open(&p_vendor->tx.stream, desc_ep);
|
||||
tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
|
||||
}
|
||||
} else {
|
||||
if (p_vendor->rx.stream.ep_addr == 0) {
|
||||
tu_edpt_stream_open(&p_vendor->rx.stream, desc_ep);
|
||||
TU_ASSERT(tu_edpt_stream_read_xfer(rhport, &p_vendor->rx.stream) > 0, 0); // prepare for incoming data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
|
||||
Reference in New Issue
Block a user