diff options
| author | hathach <[email protected]> | 2019-07-04 02:09:12 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-07-04 02:09:12 +0700 |
| commit | 2dd8dba4a7dc7b288a94054080932513ab1e98e3 (patch) | |
| tree | 9759fd0cdf4fab9eb4a7674c37e1ea6aa61f1927 /src/class/cdc | |
| parent | 393492823ce037a2e46d367d61fad1235859af2e (diff) | |
| parent | 3ec279b424ea463577420e75db54deebf409be2b (diff) | |
Merge pull request #84 from hathach/develop
better support device MIDI
Diffstat (limited to 'src/class/cdc')
| -rw-r--r-- | src/class/cdc/cdc.h | 20 | ||||
| -rw-r--r-- | src/class/cdc/cdc_device.c | 19 | ||||
| -rw-r--r-- | src/class/cdc/cdc_device.h | 100 | ||||
| -rw-r--r-- | src/class/cdc/cdc_host.c | 2 |
4 files changed, 108 insertions, 33 deletions
diff --git a/src/class/cdc/cdc.h b/src/class/cdc/cdc.h index 2e865bdbb..9cc8b82e3 100644 --- a/src/class/cdc/cdc.h +++ b/src/class/cdc/cdc.h @@ -41,7 +41,7 @@ /** \defgroup ClassDriver_CDC_Common Common Definitions
* @{ */
-
+// TODO remove
/// CDC Pipe ID, used to indicate which pipe the API is addressing to (Notification, Out, In)
typedef enum
{
@@ -52,8 +52,9 @@ typedef enum }cdc_pipeid_t;
//--------------------------------------------------------------------+
-// CDC COMMUNICATION INTERFACE CLASS
+// CDC Communication Interface Class
//--------------------------------------------------------------------+
+
/// Communication Interface Subclass Codes
typedef enum
{
@@ -117,7 +118,7 @@ typedef enum }cdc_func_desc_type_t;
//--------------------------------------------------------------------+
-// CDC DATA INTERFACE CLASS
+// CDC Data Interface Class
//--------------------------------------------------------------------+
// SUBCLASS code of Data Interface is not used and should/must be zero
@@ -138,8 +139,9 @@ typedef enum{ }cdc_data_protocol_type_t;
//--------------------------------------------------------------------+
-// MANAGEMENT ELEMENT REQUEST (CONTROL ENDPOINT)
+// Management Element Request (Control Endpoint)
//--------------------------------------------------------------------+
+
/// Communication Interface Management Element Request Codes
typedef enum
{
@@ -189,8 +191,9 @@ typedef enum }cdc_management_request_t;
//--------------------------------------------------------------------+
-// MANAGEMENT ELEMENENT NOTIFICATION (NOTIFICATION ENDPOINT)
+// Management Elemenent Notification (Notification Endpoint)
//--------------------------------------------------------------------+
+
/// Communication Interface Management Element Notification Codes
typedef enum
{
@@ -209,14 +212,15 @@ typedef enum }cdc_notification_request_t;
//--------------------------------------------------------------------+
-// FUNCTIONAL DESCRIPTOR (COMMUNICATION INTERFACE)
+// Class Specific Functional Descriptor (Communication Interface)
//--------------------------------------------------------------------+
+
/// Header Functional Descriptor (Communication Interface)
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
+ uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUNC_DESC_
uint16_t bcdCDC ; ///< CDC release number in Binary-Coded Decimal
}cdc_desc_func_header_t;
@@ -246,7 +250,7 @@ typedef struct TU_ATTR_PACKED uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
uint8_t iCountryCodeRelDate ; ///< Index of a string giving the release date for the implemented ISO 3166 Country Codes.
- uint16_t wCountryCode[] ; ///< Country code in the format as defined in [ISO3166], release date as specified inoffset 3 for the first supported country.
+ uint16_t wCountryCode ; ///< Country code in the format as defined in [ISO3166], release date as specified inoffset 3 for the first supported country.
}cdc_desc_func_country_selection_t;
#define cdc_desc_func_country_selection_n_t(no_country) \
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index 0a41147c9..6d13dafc0 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -73,21 +73,18 @@ typedef struct //--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
-//bool pending_read_from_host; TODO remove
static void _prep_out_transaction (uint8_t itf)
{
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
// skip if previous transfer not complete
if ( usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_out) ) return;
- //if (pending_read_from_host) return;
// Prepare for incoming data but only allow what we can store in the ring buffer.
uint16_t max_read = tu_fifo_remaining(&p_cdc->rx_ff);
if ( max_read >= CFG_TUD_CDC_EPSIZE )
{
usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
-// pending_read_from_host = true;
}
}
@@ -265,7 +262,7 @@ bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t (*p_length) = sizeof(tusb_desc_interface_t);
// Communication Functional Descriptors
- while ( TUSB_DESC_CLASS_SPECIFIC == tu_desc_type(p_desc) )
+ while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) )
{
(*p_length) += tu_desc_len(p_desc);
p_desc = tu_desc_next(p_desc);
@@ -296,7 +293,6 @@ bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t }
// Prepare for incoming data
-// pending_read_from_host = false;
_prep_out_transaction(cdc_id);
return true;
@@ -374,7 +370,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_ uint8_t const itf = 0;
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
- // receive new data
+ // Received new data
if ( ep_addr == p_cdc->ep_out )
{
for(uint32_t i=0; i<xferred_bytes; i++)
@@ -392,11 +388,18 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_ if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
// prepare for OUT transaction
-// pending_read_from_host = false;
_prep_out_transaction(itf);
}
- // nothing to do with in and notif endpoint for now
+ // Data sent to host, we could continue to fetch data tx fifo to send.
+ // But it will cause incorrect baudrate set in line coding.
+ // Though maybe the baudrate is not really important !!!
+// if ( ep_addr == p_cdc->ep_in )
+// {
+//
+// }
+
+ // nothing to do with notif endpoint for now
return true;
}
diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 3c1af9dbf..8d09094a0 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -48,7 +48,7 @@ * @{ */
//--------------------------------------------------------------------+
-// APPLICATION API (Multiple Interfaces)
+// Application API (Multiple Interfaces)
// CFG_TUD_CDC > 1
//--------------------------------------------------------------------+
bool tud_cdc_n_connected (uint8_t itf);
@@ -68,26 +68,26 @@ uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str); bool tud_cdc_n_write_flush (uint8_t itf);
//--------------------------------------------------------------------+
-// APPLICATION API (Interface0)
+// Application API (Interface0)
//--------------------------------------------------------------------+
-static inline bool tud_cdc_connected (void) { return tud_cdc_n_connected(0); }
-static inline uint8_t tud_cdc_get_line_state (void) { return tud_cdc_n_get_line_state(0); }
-static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding) { return tud_cdc_n_get_line_coding(0, coding);}
-static inline void tud_cdc_set_wanted_char (char wanted) { tud_cdc_n_set_wanted_char(0, wanted); }
+static inline bool tud_cdc_connected (void);
+static inline uint8_t tud_cdc_get_line_state (void);
+static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding);
+static inline void tud_cdc_set_wanted_char (char wanted);
-static inline uint32_t tud_cdc_available (void) { return tud_cdc_n_available(0); }
-static inline signed char tud_cdc_read_char (void) { return tud_cdc_n_read_char(0); }
-static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize) { return tud_cdc_n_read(0, buffer, bufsize); }
-static inline void tud_cdc_read_flush (void) { tud_cdc_n_read_flush(0); }
-static inline signed char tud_cdc_peek (int pos) { return tud_cdc_n_peek(0, pos); }
+static inline uint32_t tud_cdc_available (void);
+static inline signed char tud_cdc_read_char (void);
+static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize);
+static inline void tud_cdc_read_flush (void);
+static inline signed char tud_cdc_peek (int pos);
-static inline uint32_t tud_cdc_write_char (char ch) { return tud_cdc_n_write_char(0, ch); }
-static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize) { return tud_cdc_n_write(0, buffer, bufsize); }
-static inline uint32_t tud_cdc_write_str (char const* str) { return tud_cdc_n_write_str(0, str); }
-static inline bool tud_cdc_write_flush (void) { return tud_cdc_n_write_flush(0); }
+static inline uint32_t tud_cdc_write_char (char ch);
+static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize);
+static inline uint32_t tud_cdc_write_str (char const* str);
+static inline bool tud_cdc_write_flush (void);
//--------------------------------------------------------------------+
-// APPLICATION CALLBACK API (WEAK is optional)
+// Application Callback API (weak is optional)
//--------------------------------------------------------------------+
// Invoked when received new data
@@ -102,6 +102,74 @@ TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts); // Invoked when line coding is change via SET_LINE_CODING
TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
+//--------------------------------------------------------------------+
+// Inline Functions
+//--------------------------------------------------------------------+
+static inline bool tud_cdc_connected (void)
+{
+ return tud_cdc_n_connected(0);
+}
+
+static inline uint8_t tud_cdc_get_line_state (void)
+{
+ return tud_cdc_n_get_line_state(0);
+}
+
+static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding)
+{
+ return tud_cdc_n_get_line_coding(0, coding);
+}
+
+static inline void tud_cdc_set_wanted_char (char wanted)
+{
+ tud_cdc_n_set_wanted_char(0, wanted);
+}
+
+static inline uint32_t tud_cdc_available (void)
+{
+ return tud_cdc_n_available(0);
+}
+
+static inline signed char tud_cdc_read_char (void)
+{
+ return tud_cdc_n_read_char(0);
+}
+
+static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize)
+{
+ return tud_cdc_n_read(0, buffer, bufsize);
+}
+
+static inline void tud_cdc_read_flush (void)
+{
+ tud_cdc_n_read_flush(0);
+}
+
+static inline signed char tud_cdc_peek (int pos)
+{
+ return tud_cdc_n_peek(0, pos);
+}
+
+static inline uint32_t tud_cdc_write_char (char ch)
+{
+ return tud_cdc_n_write_char(0, ch);
+}
+
+static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize)
+{
+ return tud_cdc_n_write(0, buffer, bufsize);
+}
+
+static inline uint32_t tud_cdc_write_str (char const* str)
+{
+ return tud_cdc_n_write_str(0, str);
+}
+
+static inline bool tud_cdc_write_flush (void)
+{
+ return tud_cdc_n_write_flush(0);
+}
+
/** @} */
/** @} */
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index b64d4a1fe..6a6f508b3 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -142,7 +142,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it (*p_length) = sizeof(tusb_desc_interface_t);
// Communication Functional Descriptors
- while( TUSB_DESC_CLASS_SPECIFIC == p_desc[DESC_OFFSET_TYPE] )
+ while( TUSB_DESC_CS_INTERFACE == p_desc[DESC_OFFSET_TYPE] )
{
if ( CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT == cdc_functional_desc_typeof(p_desc) )
{
|
