diff options
| author | hathach <[email protected]> | 2019-06-10 18:50:59 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-06-10 18:50:59 +0700 |
| commit | 393492823ce037a2e46d367d61fad1235859af2e (patch) | |
| tree | 7bc829e94b0a542e6990566e71ec293a600d3553 /src | |
| parent | 69e98215ea94bf5d6a8adc042732fe2a67df9764 (diff) | |
| parent | 7156bfb54d5e9e13c8574b2384a47bd5554798a9 (diff) | |
Merge pull request #80 from hathach/develop
added usbd_edpt_xfer/usbd_edpt_busy to replace dcd_edpt_transfer/dcd_edpt_busy()
Diffstat (limited to 'src')
39 files changed, 535 insertions, 354 deletions
diff --git a/src/class/cdc/cdc.h b/src/class/cdc/cdc.h index 200f6eaae..2e865bdbb 100644 --- a/src/class/cdc/cdc.h +++ b/src/class/cdc/cdc.h @@ -212,7 +212,7 @@ typedef enum // FUNCTIONAL DESCRIPTOR (COMMUNICATION INTERFACE)
//--------------------------------------------------------------------+
/// Header Functional Descriptor (Communication Interface)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -221,7 +221,7 @@ typedef struct ATTR_PACKED }cdc_desc_func_header_t;
/// Union Functional Descriptor (Communication Interface)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -231,7 +231,7 @@ typedef struct ATTR_PACKED }cdc_desc_func_union_t;
#define cdc_desc_func_union_n_t(no_slave)\
- struct ATTR_PACKED { \
+ struct TU_ATTR_PACKED { \
uint8_t bLength ;\
uint8_t bDescriptorType ;\
uint8_t bDescriptorSubType ;\
@@ -240,7 +240,7 @@ typedef struct ATTR_PACKED }
/// Country Selection Functional Descriptor (Communication Interface)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -250,7 +250,7 @@ typedef struct ATTR_PACKED }cdc_desc_func_country_selection_t;
#define cdc_desc_func_country_selection_n_t(no_country) \
- struct ATTR_PACKED {\
+ struct TU_ATTR_PACKED {\
uint8_t bLength ;\
uint8_t bDescriptorType ;\
uint8_t bDescriptorSubType ;\
@@ -264,7 +264,7 @@ typedef struct ATTR_PACKED /// \brief Call Management Functional Descriptor
/// \details This functional descriptor describes the processing of calls for the Communications Class interface.
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -280,7 +280,7 @@ typedef struct ATTR_PACKED }cdc_desc_func_call_management_t;
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t support_comm_request : 1; ///< Device supports the request combination of Set_Comm_Feature, Clear_Comm_Feature, and Get_Comm_Feature.
uint8_t support_line_request : 1; ///< Device supports the request combination of Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State.
@@ -293,7 +293,7 @@ TU_VERIFY_STATIC(sizeof(cdc_acm_capability_t) == 1, "mostly problem with compile /// \brief Abstract Control Management Functional Descriptor
/// \details This functional descriptor describes the commands supported by by the Communications Class interface with SubClass code of \ref CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -303,7 +303,7 @@ typedef struct ATTR_PACKED /// \brief Direct Line Management Functional Descriptor
/// \details This functional descriptor describes the commands supported by the Communications Class interface with SubClass code of \ref CDC_FUNC_DESC_DIRECT_LINE_MANAGEMENT
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -319,7 +319,7 @@ typedef struct ATTR_PACKED /// \brief Telephone Ringer Functional Descriptor
/// \details The Telephone Ringer functional descriptor describes the ringer capabilities supported by the Communications Class interface,
/// with the SubClass code of \ref CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -331,7 +331,7 @@ typedef struct ATTR_PACKED /// \brief Telephone Operational Modes Functional Descriptor
/// \details The Telephone Operational Modes functional descriptor describes the operational modes supported by
/// the Communications Class interface, with the SubClass code of \ref CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -347,7 +347,7 @@ typedef struct ATTR_PACKED /// \brief Telephone Call and Line State Reporting Capabilities Descriptor
/// \details The Telephone Call and Line State Reporting Capabilities functional descriptor describes the abilities of a
/// telephone device to report optional call and line states.
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -371,7 +371,7 @@ static inline uint8_t cdc_functional_desc_typeof(uint8_t const * p_desc) //--------------------------------------------------------------------+
// Requests
//--------------------------------------------------------------------+
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint32_t bit_rate;
uint8_t stop_bits; ///< 0: 1 stop bit - 1: 1.5 stop bits - 2: 2 stop bits
@@ -381,7 +381,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(cdc_line_coding_t) == 7, "size is not correct");
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint16_t dte_is_present : 1; ///< Indicates to DCE if DTE is presentor not. This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR.
uint16_t half_duplex_carrier_control : 1;
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index 1583b71fa..0a41147c9 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -73,23 +73,21 @@ typedef struct //--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
-// TODO will be replaced by dcd_edpt_busy()
-bool pending_read_from_host;
+//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
- // dcd_edpt_busy() doesn't work, probably transfer is complete but not properly handled by the stack
-// if ( dcd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_out) ) return;
- if (pending_read_from_host) return;
+ 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 )
{
- dcd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
- pending_read_from_host = true;
+ usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
+// pending_read_from_host = true;
}
}
@@ -183,13 +181,13 @@ uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize) bool tud_cdc_n_write_flush (uint8_t itf)
{
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
- TU_VERIFY( !dcd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete
+ TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete
uint16_t count = tu_fifo_read_n(&_cdcd_itf[itf].tx_ff, p_cdc->epin_buf, CFG_TUD_CDC_EPSIZE);
if ( count )
{
TU_VERIFY( tud_cdc_n_connected(itf) ); // fifo is empty if not connected
- TU_ASSERT( dcd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epin_buf, count) );
+ TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epin_buf, count) );
}
return true;
@@ -298,7 +296,7 @@ bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t }
// Prepare for incoming data
- pending_read_from_host = false;
+// pending_read_from_host = false;
_prep_out_transaction(cdc_id);
return true;
@@ -394,7 +392,7 @@ 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;
+// pending_read_from_host = false;
_prep_out_transaction(itf);
}
diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 9e1087631..3c1af9dbf 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -91,16 +91,16 @@ static inline bool tud_cdc_write_flush (void) //--------------------------------------------------------------------+
// Invoked when received new data
-ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf);
+TU_ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf);
// Invoked when received `wanted_char`
-ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
+TU_ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
// Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE
-ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
+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
-ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
+TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
/** @} */
/** @} */
diff --git a/src/class/cdc/cdc_rndis_host.c b/src/class/cdc/cdc_rndis_host.c index c604aef4a..767b917a1 100644 --- a/src/class/cdc/cdc_rndis_host.c +++ b/src/class/cdc/cdc_rndis_host.c @@ -41,7 +41,7 @@ #define RNDIS_MSG_PAYLOAD_MAX (1024*4) CFG_TUSB_MEM_SECTION static uint8_t msg_notification[CFG_TUSB_HOST_DEVICE_MAX][8]; -CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) static uint8_t msg_payload[RNDIS_MSG_PAYLOAD_MAX]; +CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4) static uint8_t msg_payload[RNDIS_MSG_PAYLOAD_MAX]; static rndish_data_t rndish_data[CFG_TUSB_HOST_DEVICE_MAX]; diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index 18aea94cc..02a711621 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -70,7 +70,7 @@ bool cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_ (*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); // TODO Prepare for incoming data -// TU_ASSERT( dcd_edpt_xfer(rhport, p_itf->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) ); +// TU_ASSERT( usbd_edpt_xfer(rhport, p_itf->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) ); return true; } diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 902c01ef5..a3a9ffc88 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -44,7 +44,7 @@ * @{ */
/// USB HID Descriptor
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
@@ -150,7 +150,7 @@ typedef enum * @{ */
/// Standard HID Boot Protocol Mouse Report.
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t buttons; /**< buttons mask for currently pressed buttons in the mouse. */
int8_t x; /**< Current delta x movement of the mouse. */
@@ -178,7 +178,7 @@ typedef enum * @{ */
/// Standard HID Boot Protocol Keyboard Report.
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t modifier; /**< Keyboard modifier (KEYBOARD_MODIFER_* masks). */
uint8_t reserved; /**< Reserved for OEM use, always set to 0. */
@@ -598,6 +598,272 @@ enum HID_USAGE_CONSUMER_AC_PAN = 0x0238,
};
+/*--------------------------------------------------------------------
+ * ASCII to KEYCODE Conversion
+ * Expand to array of [128][2] (shift, keycode)
+ *
+ * Usage: example to convert input chr into keyboard report (modifier + keycode)
+ *
+ * uint8_t const conv_table[128][2] = { HID_ASCII_TO_KEYCODE };
+ *
+ * uint8_t keycode[6] = { 0 };
+ * uint8_t modifier = 0;
+ *
+ * if ( conv_table[chr][0] ) modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
+ * keycode[0] = conv_table[chr][1];
+ * tud_hid_keyboard_report(report_id, modifier, keycode);
+ *
+ *--------------------------------------------------------------------*/
+#define HID_ASCII_TO_KEYCODE \
+ {0, 0 }, /* 0x00 Null */ \
+ {0, 0 }, /* 0x01 */ \
+ {0, 0 }, /* 0x02 */ \
+ {0, 0 }, /* 0x03 */ \
+ {0, 0 }, /* 0x04 */ \
+ {0, 0 }, /* 0x05 */ \
+ {0, 0 }, /* 0x06 */ \
+ {0, 0 }, /* 0x07 */ \
+ {0, HID_KEY_BACKSPACE }, /* 0x08 Backspace */ \
+ {0, HID_KEY_TAB }, /* 0x09 Tab */ \
+ {0, HID_KEY_RETURN }, /* 0x0A Line Feed */ \
+ {0, 0 }, /* 0x0B */ \
+ {0, 0 }, /* 0x0C */ \
+ {0, HID_KEY_RETURN }, /* 0x0D CR */ \
+ {0, 0 }, /* 0x0E */ \
+ {0, 0 }, /* 0x0F */ \
+ {0, 0 }, /* 0x10 */ \
+ {0, 0 }, /* 0x11 */ \
+ {0, 0 }, /* 0x12 */ \
+ {0, 0 }, /* 0x13 */ \
+ {0, 0 }, /* 0x14 */ \
+ {0, 0 }, /* 0x15 */ \
+ {0, 0 }, /* 0x16 */ \
+ {0, 0 }, /* 0x17 */ \
+ {0, 0 }, /* 0x18 */ \
+ {0, 0 }, /* 0x19 */ \
+ {0, 0 }, /* 0x1A */ \
+ {0, HID_KEY_ESCAPE }, /* 0x1B Escape */ \
+ {0, 0 }, /* 0x1C */ \
+ {0, 0 }, /* 0x1D */ \
+ {0, 0 }, /* 0x1E */ \
+ {0, 0 }, /* 0x1F */ \
+ \
+ {0, HID_KEY_SPACE }, /* 0x20 */ \
+ {1, HID_KEY_1 }, /* 0x21 ! */ \
+ {1, HID_KEY_APOSTROPHE }, /* 0x22 " */ \
+ {1, HID_KEY_3 }, /* 0x23 # */ \
+ {1, HID_KEY_4 }, /* 0x24 $ */ \
+ {1, HID_KEY_5 }, /* 0x25 % */ \
+ {1, HID_KEY_7 }, /* 0x26 & */ \
+ {0, HID_KEY_APOSTROPHE }, /* 0x27 ' */ \
+ {1, HID_KEY_9 }, /* 0x28 ( */ \
+ {1, HID_KEY_0 }, /* 0x29 ) */ \
+ {1, HID_KEY_8 }, /* 0x2A * */ \
+ {1, HID_KEY_EQUAL }, /* 0x2B + */ \
+ {0, HID_KEY_COMMA }, /* 0x2C , */ \
+ {0, HID_KEY_MINUS }, /* 0x2D - */ \
+ {0, HID_KEY_PERIOD }, /* 0x2E . */ \
+ {0, HID_KEY_SLASH }, /* 0x2F / */ \
+ {0, HID_KEY_0 }, /* 0x30 0 */ \
+ {0, HID_KEY_1 }, /* 0x31 1 */ \
+ {0, HID_KEY_2 }, /* 0x32 2 */ \
+ {0, HID_KEY_3 }, /* 0x33 3 */ \
+ {0, HID_KEY_4 }, /* 0x34 4 */ \
+ {0, HID_KEY_5 }, /* 0x35 5 */ \
+ {0, HID_KEY_6 }, /* 0x36 6 */ \
+ {0, HID_KEY_7 }, /* 0x37 7 */ \
+ {0, HID_KEY_8 }, /* 0x38 8 */ \
+ {0, HID_KEY_9 }, /* 0x39 9 */ \
+ {1, HID_KEY_SEMICOLON }, /* 0x3A : */ \
+ {0, HID_KEY_SEMICOLON }, /* 0x3B ; */ \
+ {1, HID_KEY_COMMA }, /* 0x3C < */ \
+ {0, HID_KEY_EQUAL }, /* 0x3D = */ \
+ {1, HID_KEY_PERIOD }, /* 0x3E > */ \
+ {1, HID_KEY_SLASH }, /* 0x3F ? */ \
+ \
+ {1, HID_KEY_2 }, /* 0x40 @ */ \
+ {1, HID_KEY_A }, /* 0x41 A */ \
+ {1, HID_KEY_B }, /* 0x42 B */ \
+ {1, HID_KEY_C }, /* 0x43 C */ \
+ {1, HID_KEY_D }, /* 0x44 D */ \
+ {1, HID_KEY_E }, /* 0x45 E */ \
+ {1, HID_KEY_F }, /* 0x46 F */ \
+ {1, HID_KEY_G }, /* 0x47 G */ \
+ {1, HID_KEY_H }, /* 0x48 H */ \
+ {1, HID_KEY_I }, /* 0x49 I */ \
+ {1, HID_KEY_J }, /* 0x4A J */ \
+ {1, HID_KEY_K }, /* 0x4B K */ \
+ {1, HID_KEY_L }, /* 0x4C L */ \
+ {1, HID_KEY_M }, /* 0x4D M */ \
+ {1, HID_KEY_N }, /* 0x4E N */ \
+ {1, HID_KEY_O }, /* 0x4F O */ \
+ {1, HID_KEY_P }, /* 0x50 P */ \
+ {1, HID_KEY_Q }, /* 0x51 Q */ \
+ {1, HID_KEY_R }, /* 0x52 R */ \
+ {1, HID_KEY_S }, /* 0x53 S */ \
+ {1, HID_KEY_T }, /* 0x55 T */ \
+ {1, HID_KEY_U }, /* 0x55 U */ \
+ {1, HID_KEY_V }, /* 0x56 V */ \
+ {1, HID_KEY_W }, /* 0x57 W */ \
+ {1, HID_KEY_X }, /* 0x58 X */ \
+ {1, HID_KEY_Y }, /* 0x59 Y */ \
+ {1, HID_KEY_Z }, /* 0x5A Z */ \
+ {0, HID_KEY_BRACKET_LEFT }, /* 0x5B [ */ \
+ {0, HID_KEY_BACKSLASH }, /* 0x5C '\' */ \
+ {0, HID_KEY_BRACKET_RIGHT }, /* 0x5D ] */ \
+ {1, HID_KEY_6 }, /* 0x5E ^ */ \
+ {1, HID_KEY_MINUS }, /* 0x5F _ */ \
+ \
+ {0, HID_KEY_GRAVE }, /* 0x60 ` */ \
+ {0, HID_KEY_A }, /* 0x61 a */ \
+ {0, HID_KEY_B }, /* 0x62 b */ \
+ {0, HID_KEY_C }, /* 0x63 c */ \
+ {0, HID_KEY_D }, /* 0x66 d */ \
+ {0, HID_KEY_E }, /* 0x65 e */ \
+ {0, HID_KEY_F }, /* 0x66 f */ \
+ {0, HID_KEY_G }, /* 0x67 g */ \
+ {0, HID_KEY_H }, /* 0x68 h */ \
+ {0, HID_KEY_I }, /* 0x69 i */ \
+ {0, HID_KEY_J }, /* 0x6A j */ \
+ {0, HID_KEY_K }, /* 0x6B k */ \
+ {0, HID_KEY_L }, /* 0x6C l */ \
+ {0, HID_KEY_M }, /* 0x6D m */ \
+ {0, HID_KEY_N }, /* 0x6E n */ \
+ {0, HID_KEY_O }, /* 0x6F o */ \
+ {0, HID_KEY_P }, /* 0x70 p */ \
+ {0, HID_KEY_Q }, /* 0x71 q */ \
+ {0, HID_KEY_R }, /* 0x72 r */ \
+ {0, HID_KEY_S }, /* 0x73 s */ \
+ {0, HID_KEY_T }, /* 0x75 t */ \
+ {0, HID_KEY_U }, /* 0x75 u */ \
+ {0, HID_KEY_V }, /* 0x76 v */ \
+ {0, HID_KEY_W }, /* 0x77 w */ \
+ {0, HID_KEY_X }, /* 0x78 x */ \
+ {0, HID_KEY_Y }, /* 0x79 y */ \
+ {0, HID_KEY_Z }, /* 0x7A z */ \
+ {1, HID_KEY_BRACKET_LEFT }, /* 0x7B { */ \
+ {1, HID_KEY_BACKSLASH }, /* 0x7C | */ \
+ {1, HID_KEY_BRACKET_RIGHT }, /* 0x7D } */ \
+ {1, HID_KEY_GRAVE }, /* 0x7E ~ */ \
+ {0, HID_KEY_DELETE } /* 0x7F Delete */ \
+
+/*--------------------------------------------------------------------
+ * KEYCODE to Ascii Conversion
+ * Expand to array of [128][2] (ascii without shift, ascii with shift)
+ *
+ * Usage: example to convert ascii from keycode (key) and shift modifier (shift).
+ * Here we assume key < 128 ( printable )
+ *
+ * uint8_t const conv_table[128][2] = { HID_KEYCODE_TO_ASCII };
+ * char ch = shift ? conv_table[chr][1] : conv_table[chr][0];
+ *
+ *--------------------------------------------------------------------*/
+#define HID_KEYCODE_TO_ASCII \
+ {0 , 0 }, /* 0x00 */ \
+ {0 , 0 }, /* 0x01 */ \
+ {0 , 0 }, /* 0x02 */ \
+ {0 , 0 }, /* 0x03 */ \
+ {'a' , 'A' }, /* 0x04 */ \
+ {'b' , 'B' }, /* 0x05 */ \
+ {'c' , 'C' }, /* 0x06 */ \
+ {'d' , 'D' }, /* 0x07 */ \
+ {'e' , 'E' }, /* 0x08 */ \
+ {'f' , 'F' }, /* 0x09 */ \
+ {'g' , 'G' }, /* 0x0a */ \
+ {'h' , 'H' }, /* 0x0b */ \
+ {'i' , 'I' }, /* 0x0c */ \
+ {'j' , 'J' }, /* 0x0d */ \
+ {'k' , 'K' }, /* 0x0e */ \
+ {'l' , 'L' }, /* 0x0f */ \
+ {'m' , 'M' }, /* 0x10 */ \
+ {'n' , 'N' }, /* 0x11 */ \
+ {'o' , 'O' }, /* 0x12 */ \
+ {'p' , 'P' }, /* 0x13 */ \
+ {'q' , 'Q' }, /* 0x14 */ \
+ {'r' , 'R' }, /* 0x15 */ \
+ {'s' , 'S' }, /* 0x16 */ \
+ {'t' , 'T' }, /* 0x17 */ \
+ {'u' , 'U' }, /* 0x18 */ \
+ {'v' , 'V' }, /* 0x19 */ \
+ {'w' , 'W' }, /* 0x1a */ \
+ {'x' , 'X' }, /* 0x1b */ \
+ {'y' , 'Y' }, /* 0x1c */ \
+ {'z' , 'Z' }, /* 0x1d */ \
+ {'1' , '!' }, /* 0x1e */ \
+ {'2' , '@' }, /* 0x1f */ \
+ {'3' , '#' }, /* 0x20 */ \
+ {'4' , '$' }, /* 0x21 */ \
+ {'5' , '%' }, /* 0x22 */ \
+ {'6' , '^' }, /* 0x23 */ \
+ {'7' , '&' }, /* 0x24 */ \
+ {'8' , '*' }, /* 0x25 */ \
+ {'9' , '(' }, /* 0x26 */ \
+ {'0' , ')' }, /* 0x27 */ \
+ {'\r' , '\r' }, /* 0x28 */ \
+ {'\x1b', '\x1b' }, /* 0x29 */ \
+ {'\b' , '\b' }, /* 0x2a */ \
+ {'\t' , '\t' }, /* 0x2b */ \
+ {' ' , ' ' }, /* 0x2c */ \
+ {'-' , '_' }, /* 0x2d */ \
+ {'=' , '+' }, /* 0x2e */ \
+ {'[' , '{' }, /* 0x2f */ \
+ {']' , '}' }, /* 0x30 */ \
+ {'\\' , '|' }, /* 0x31 */ \
+ {'#' , '~' }, /* 0x32 */ \
+ {';' , ':' }, /* 0x33 */ \
+ {'\'' , '\"' }, /* 0x34 */ \
+ {0 , 0 }, /* 0x35 */ \
+ {',' , '<' }, /* 0x36 */ \
+ {'.' , '>' }, /* 0x37 */ \
+ {'/' , '?' }, /* 0x38 */ \
+ \
+ {0 , 0 }, /* 0x39 */ \
+ {0 , 0 }, /* 0x3a */ \
+ {0 , 0 }, /* 0x3b */ \
+ {0 , 0 }, /* 0x3c */ \
+ {0 , 0 }, /* 0x3d */ \
+ {0 , 0 }, /* 0x3e */ \
+ {0 , 0 }, /* 0x3f */ \
+ {0 , 0 }, /* 0x40 */ \
+ {0 , 0 }, /* 0x41 */ \
+ {0 , 0 }, /* 0x42 */ \
+ {0 , 0 }, /* 0x43 */ \
+ {0 , 0 }, /* 0x44 */ \
+ {0 , 0 }, /* 0x45 */ \
+ {0 , 0 }, /* 0x46 */ \
+ {0 , 0 }, /* 0x47 */ \
+ {0 , 0 }, /* 0x48 */ \
+ {0 , 0 }, /* 0x49 */ \
+ {0 , 0 }, /* 0x4a */ \
+ {0 , 0 }, /* 0x4b */ \
+ {0 , 0 }, /* 0x4c */ \
+ {0 , 0 }, /* 0x4d */ \
+ {0 , 0 }, /* 0x4e */ \
+ {0 , 0 }, /* 0x4f */ \
+ {0 , 0 }, /* 0x50 */ \
+ {0 , 0 }, /* 0x51 */ \
+ {0 , 0 }, /* 0x52 */ \
+ {0 , 0 }, /* 0x53 */ \
+ \
+ {'/' , '/' }, /* 0x54 */ \
+ {'*' , '*' }, /* 0x55 */ \
+ {'-' , '-' }, /* 0x56 */ \
+ {'+' , '+' }, /* 0x57 */ \
+ {'\r' , '\r' }, /* 0x58 */ \
+ {'1' , 0 }, /* 0x59 */ \
+ {'2' , 0 }, /* 0x5a */ \
+ {'3' , 0 }, /* 0x5b */ \
+ {'4' , 0 }, /* 0x5c */ \
+ {'5' , '5' }, /* 0x5d */ \
+ {'6' , 0 }, /* 0x5e */ \
+ {'7' , 0 }, /* 0x5f */ \
+ {'8' , 0 }, /* 0x60 */ \
+ {'9' , 0 }, /* 0x61 */ \
+ {'0' , 0 }, /* 0x62 */ \
+ {'0' , 0 }, /* 0x63 */ \
+ {'=' , '=' }, /* 0x67 */ \
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index aea16efc1..d3f59ed62 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -73,28 +73,31 @@ bool tud_hid_ready(void) {
uint8_t itf = 0;
uint8_t const ep_in = _hidd_itf[itf].ep_in;
- return tud_ready() && (ep_in != 0) && !dcd_edpt_busy(TUD_OPT_RHPORT, ep_in);
+ return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
}
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
{
- TU_VERIFY( tud_hid_ready() && (len <= CFG_TUD_HID_BUFSIZE) );
+ TU_VERIFY( tud_hid_ready() );
uint8_t itf = 0;
hidd_interface_t * p_hid = &_hidd_itf[itf];
- // If report id = 0, skip ID field
if (report_id)
{
+ len = tu_min8(len, CFG_TUD_HID_BUFSIZE-1);
+
p_hid->epin_buf[0] = report_id;
memcpy(p_hid->epin_buf+1, report, len);
len++;
}else
{
+ // If report id = 0, skip ID field
+ len = tu_min8(len, CFG_TUD_HID_BUFSIZE);
memcpy(p_hid->epin_buf, report, len);
}
- return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
+ return usbd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
}
bool tud_hid_boot_mode(void)
@@ -180,7 +183,7 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
// Prepare for output endpoint
- if (p_hid->ep_out) TU_ASSERT(dcd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
+ if (p_hid->ep_out) TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
return true;
}
@@ -303,7 +306,7 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_ if (ep_addr == p_hid->ep_out)
{
tud_hid_set_report_cb(0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes);
- TU_ASSERT(dcd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
+ TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
}
return true;
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index be7999770..da239cc84 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -82,12 +82,12 @@ uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
// Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report )
-ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
+TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
// Invoked when received SET_IDLE request. return false will stall the request
// - Idle Rate = 0 : only send report if there is changes, i.e skip duplication
// - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
-ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
+TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
/* --------------------------------------------------------------------+
* HID Report Descriptor Template
@@ -297,155 +297,6 @@ ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate); HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\
HID_COLLECTION_END \
-/*--------------------------------------------------------------------
- * ASCII to KEYCODE Conversion
- * Expand to array of [128][2] (shift, keycode)
- *
- * Usage: example to convert input char into keyboard report (modifier + keycode)
- *
- * uint8_t const conv_table[128][2] = { HID_ASCII_TO_KEYCODE };
- *
- * uint8_t keycode[6] = { 0 };
- * uint8_t modifier = 0;
- *
- * if ( conv_table[chr][0] ) modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
- * keycode[0] = conv_table[chr][1];
- * tud_hid_keyboard_report(report_id, modifier, keycode);
- *
- *--------------------------------------------------------------------*/
-#define HID_ASCII_TO_KEYCODE \
- {0, 0 }, /* 0x00 Null */ \
- {0, 0 }, /* 0x01 */ \
- {0, 0 }, /* 0x02 */ \
- {0, 0 }, /* 0x03 */ \
- {0, 0 }, /* 0x04 */ \
- {0, 0 }, /* 0x05 */ \
- {0, 0 }, /* 0x06 */ \
- {0, 0 }, /* 0x07 */ \
- {0, HID_KEY_BACKSPACE }, /* 0x08 Backspace */ \
- {0, HID_KEY_TAB }, /* 0x09 Tab */ \
- {0, HID_KEY_RETURN }, /* 0x0A Line Feed */ \
- {0, 0 }, /* 0x0B */ \
- {0, 0 }, /* 0x0C */ \
- {0, HID_KEY_RETURN }, /* 0x0D CR */ \
- {0, 0 }, /* 0x0E */ \
- {0, 0 }, /* 0x0F */ \
- {0, 0 }, /* 0x10 */ \
- {0, 0 }, /* 0x11 */ \
- {0, 0 }, /* 0x12 */ \
- {0, 0 }, /* 0x13 */ \
- {0, 0 }, /* 0x14 */ \
- {0, 0 }, /* 0x15 */ \
- {0, 0 }, /* 0x16 */ \
- {0, 0 }, /* 0x17 */ \
- {0, 0 }, /* 0x18 */ \
- {0, 0 }, /* 0x19 */ \
- {0, 0 }, /* 0x1A */ \
- {0, HID_KEY_ESCAPE }, /* 0x1B Escape */ \
- {0, 0 }, /* 0x1C */ \
- {0, 0 }, /* 0x1D */ \
- {0, 0 }, /* 0x1E */ \
- {0, 0 }, /* 0x1F */ \
- \
- {0, HID_KEY_SPACE }, /* 0x20 */ \
- {1, HID_KEY_1 }, /* 0x21 ! */ \
- {1, HID_KEY_APOSTROPHE }, /* 0x22 " */ \
- {1, HID_KEY_3 }, /* 0x23 # */ \
- {1, HID_KEY_4 }, /* 0x24 $ */ \
- {1, HID_KEY_5 }, /* 0x25 % */ \
- {1, HID_KEY_7 }, /* 0x26 & */ \
- {0, HID_KEY_APOSTROPHE }, /* 0x27 ' */ \
- {1, HID_KEY_9 }, /* 0x28 ( */ \
- {1, HID_KEY_0 }, /* 0x29 ) */ \
- {1, HID_KEY_8 }, /* 0x2A * */ \
- {1, HID_KEY_EQUAL }, /* 0x2B + */ \
- {0, HID_KEY_COMMA }, /* 0x2C , */ \
- {0, HID_KEY_MINUS }, /* 0x2D - */ \
- {0, HID_KEY_PERIOD }, /* 0x2E . */ \
- {0, HID_KEY_SLASH }, /* 0x2F / */ \
- {0, HID_KEY_0 }, /* 0x30 0 */ \
- {0, HID_KEY_1 }, /* 0x31 1 */ \
- {0, HID_KEY_2 }, /* 0x32 2 */ \
- {0, HID_KEY_3 }, /* 0x33 3 */ \
- {0, HID_KEY_4 }, /* 0x34 4 */ \
- {0, HID_KEY_5 }, /* 0x35 5 */ \
- {0, HID_KEY_6 }, /* 0x36 6 */ \
- {0, HID_KEY_7 }, /* 0x37 7 */ \
- {0, HID_KEY_8 }, /* 0x38 8 */ \
- {0, HID_KEY_9 }, /* 0x39 9 */ \
- {1, HID_KEY_SEMICOLON }, /* 0x3A : */ \
- {0, HID_KEY_SEMICOLON }, /* 0x3B ; */ \
- {1, HID_KEY_COMMA }, /* 0x3C < */ \
- {0, HID_KEY_EQUAL }, /* 0x3D = */ \
- {1, HID_KEY_PERIOD }, /* 0x3E > */ \
- {1, HID_KEY_SLASH }, /* 0x3F ? */ \
- \
- {1, HID_KEY_2 }, /* 0x40 @ */ \
- {1, HID_KEY_A }, /* 0x41 A */ \
- {1, HID_KEY_B }, /* 0x42 B */ \
- {1, HID_KEY_C }, /* 0x43 C */ \
- {1, HID_KEY_D }, /* 0x44 D */ \
- {1, HID_KEY_E }, /* 0x45 E */ \
- {1, HID_KEY_F }, /* 0x46 F */ \
- {1, HID_KEY_G }, /* 0x47 G */ \
- {1, HID_KEY_H }, /* 0x48 H */ \
- {1, HID_KEY_I }, /* 0x49 I */ \
- {1, HID_KEY_J }, /* 0x4A J */ \
- {1, HID_KEY_K }, /* 0x4B K */ \
- {1, HID_KEY_L }, /* 0x4C L */ \
- {1, HID_KEY_M }, /* 0x4D M */ \
- {1, HID_KEY_N }, /* 0x4E N */ \
- {1, HID_KEY_O }, /* 0x4F O */ \
- {1, HID_KEY_P }, /* 0x50 P */ \
- {1, HID_KEY_Q }, /* 0x51 Q */ \
- {1, HID_KEY_R }, /* 0x52 R */ \
- {1, HID_KEY_S }, /* 0x53 S */ \
- {1, HID_KEY_T }, /* 0x55 T */ \
- {1, HID_KEY_U }, /* 0x55 U */ \
- {1, HID_KEY_V }, /* 0x56 V */ \
- {1, HID_KEY_W }, /* 0x57 W */ \
- {1, HID_KEY_X }, /* 0x58 X */ \
- {1, HID_KEY_Y }, /* 0x59 Y */ \
- {1, HID_KEY_Z }, /* 0x5A Z */ \
- {0, HID_KEY_BRACKET_LEFT }, /* 0x5B [ */ \
- {0, HID_KEY_BACKSLASH }, /* 0x5C '\' */ \
- {0, HID_KEY_BRACKET_RIGHT }, /* 0x5D ] */ \
- {1, HID_KEY_6 }, /* 0x5E ^ */ \
- {1, HID_KEY_MINUS }, /* 0x5F _ */ \
- \
- {0, HID_KEY_GRAVE }, /* 0x60 ` */ \
- {0, HID_KEY_A }, /* 0x61 a */ \
- {0, HID_KEY_B }, /* 0x62 b */ \
- {0, HID_KEY_C }, /* 0x63 c */ \
- {0, HID_KEY_D }, /* 0x66 d */ \
- {0, HID_KEY_E }, /* 0x65 e */ \
- {0, HID_KEY_F }, /* 0x66 f */ \
- {0, HID_KEY_G }, /* 0x67 g */ \
- {0, HID_KEY_H }, /* 0x68 h */ \
- {0, HID_KEY_I }, /* 0x69 i */ \
- {0, HID_KEY_J }, /* 0x6A j */ \
- {0, HID_KEY_K }, /* 0x6B k */ \
- {0, HID_KEY_L }, /* 0x6C l */ \
- {0, HID_KEY_M }, /* 0x6D m */ \
- {0, HID_KEY_N }, /* 0x6E n */ \
- {0, HID_KEY_O }, /* 0x6F o */ \
- {0, HID_KEY_P }, /* 0x70 p */ \
- {0, HID_KEY_Q }, /* 0x71 q */ \
- {0, HID_KEY_R }, /* 0x72 r */ \
- {0, HID_KEY_S }, /* 0x73 s */ \
- {0, HID_KEY_T }, /* 0x75 t */ \
- {0, HID_KEY_U }, /* 0x75 u */ \
- {0, HID_KEY_V }, /* 0x76 v */ \
- {0, HID_KEY_W }, /* 0x77 w */ \
- {0, HID_KEY_X }, /* 0x78 x */ \
- {0, HID_KEY_Y }, /* 0x79 y */ \
- {0, HID_KEY_Z }, /* 0x7A z */ \
- {1, HID_KEY_BRACKET_LEFT }, /* 0x7B { */ \
- {1, HID_KEY_BACKSLASH }, /* 0x7C | */ \
- {1, HID_KEY_BRACKET_RIGHT }, /* 0x7D } */ \
- {1, HID_KEY_GRAVE }, /* 0x7E ~ */ \
- {0, HID_KEY_DELETE } /* 0x7F Delete */ \
-
//--------------------------------------------------------------------+
// Internal Class Driver API
//--------------------------------------------------------------------+
diff --git a/src/class/midi/midi.h b/src/class/midi/midi.h index ee318f788..50f2be679 100644 --- a/src/class/midi/midi.h +++ b/src/class/midi/midi.h @@ -42,7 +42,7 @@ // FUNCTIONAL DESCRIPTOR (COMMUNICATION INTERFACE)
//--------------------------------------------------------------------+
/// Header Functional Descriptor (Communication Interface)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -52,7 +52,7 @@ typedef struct ATTR_PACKED }midi_desc_func_header_t;
/// Union Functional Descriptor (Communication Interface)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
diff --git a/src/class/midi/midi_device.c b/src/class/midi/midi_device.c index e834e0632..2454db47e 100644 --- a/src/class/midi/midi_device.c +++ b/src/class/midi/midi_device.c @@ -72,7 +72,7 @@ typedef struct //--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-CFG_TUSB_ATTR_USBRAM midid_interface_t _midid_itf[CFG_TUD_MIDI];
+CFG_TUSB_MEM_SECTION midid_interface_t _midid_itf[CFG_TUD_MIDI];
bool tud_midi_n_connected(uint8_t itf) {
midid_interface_t* midi = &_midid_itf[itf];
@@ -133,13 +133,13 @@ void midi_rx_done_cb(midid_interface_t* midi, uint8_t const* buffer, uint32_t bu static bool maybe_transmit(midid_interface_t* midi, uint8_t itf_index)
{
- TU_VERIFY( !dcd_edpt_busy(TUD_OPT_RHPORT, midi->ep_in) ); // skip if previous transfer not complete
+ TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, midi->ep_in) ); // skip if previous transfer not complete
uint16_t count = tu_fifo_read_n(&midi->tx_ff, midi->epin_buf, CFG_TUD_MIDI_EPSIZE);
if (count > 0)
{
TU_VERIFY( tud_midi_n_connected(itf_index) ); // fifo is empty if not connected
- TU_ASSERT( dcd_edpt_xfer(TUD_OPT_RHPORT, midi->ep_in, midi->epin_buf, count) );
+ TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, midi->ep_in, midi->epin_buf, count) );
}
return true;
}
@@ -304,7 +304,7 @@ bool midid_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, }
// Prepare for incoming data
- TU_ASSERT( dcd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EPSIZE), false);
+ TU_ASSERT( usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EPSIZE), false);
return true;
}
@@ -334,7 +334,7 @@ bool midid_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint midi_rx_done_cb(p_midi, p_midi->epout_buf, xferred_bytes);
// prepare for next
- TU_ASSERT( dcd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EPSIZE), false );
+ TU_ASSERT( usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EPSIZE), false );
} else if ( edpt_addr == p_midi->ep_in ) {
maybe_transmit(p_midi, itf);
}
diff --git a/src/class/midi/midi_device.h b/src/class/midi/midi_device.h index 84f4c57bd..45e009010 100644 --- a/src/class/midi/midi_device.h +++ b/src/class/midi/midi_device.h @@ -82,7 +82,7 @@ static inline bool tud_midi_write_flush (void) //--------------------------------------------------------------------+
// APPLICATION CALLBACK API (WEAK is optional)
//--------------------------------------------------------------------+
-ATTR_WEAK void tud_midi_rx_cb(uint8_t itf);
+TU_ATTR_WEAK void tud_midi_rx_cb(uint8_t itf);
//--------------------------------------------------------------------+
// Internal Class Driver API
diff --git a/src/class/msc/msc.h b/src/class/msc/msc.h index 95fac6598..d461513fc 100644 --- a/src/class/msc/msc.h +++ b/src/class/msc/msc.h @@ -86,7 +86,7 @@ typedef enum }msc_csw_status_t;
/// Command Block Wrapper
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint32_t signature; ///< Signature that helps identify this data packet as a CBW. The signature field shall contain the value 43425355h (little endian), indicating a CBW.
uint32_t tag; ///< Tag sent by the host. The device shall echo the contents of this field back to the host in the dCSWTagfield of the associated CSW. The dCSWTagpositively associates a CSW with the corresponding CBW.
@@ -100,7 +100,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(msc_cbw_t) == 31, "size is not correct");
/// Command Status Wrapper
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint32_t signature ; ///< Signature that helps identify this data packet as a CSW. The signature field shall contain the value 53425355h (little endian), indicating CSW.
uint32_t tag ; ///< The device shall set this field to the value received in the dCBWTag of the associated CBW.
@@ -153,7 +153,7 @@ typedef enum //--------------------------------------------------------------------+
/// SCSI Test Unit Ready Command
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_TEST_UNIT_READY
uint8_t lun ; ///< Logical Unit
@@ -164,7 +164,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct");
/// SCSI Inquiry Command
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_INQUIRY
uint8_t reserved1 ;
@@ -177,7 +177,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(scsi_inquiry_t) == 6, "size is not correct");
/// SCSI Inquiry Response Data
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t peripheral_device_type : 5;
uint8_t peripheral_qualifier : 3;
@@ -223,7 +223,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(scsi_inquiry_resp_t) == 36, "size is not correct");
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t response_code : 7; ///< 70h - current errors, Fixed Format 71h - deferred errors, Fixed Format
uint8_t valid : 1;
@@ -249,7 +249,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(scsi_sense_fixed_resp_t) == 18, "size is not correct");
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_MODE_SENSE_6
@@ -268,7 +268,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_t) == 6, "size is not correct");
// This is only a Mode parameter header(6).
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t data_len;
uint8_t medium_type;
@@ -281,7 +281,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_resp_t) == 4, "size is not correct");
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code; ///< SCSI OpCode for \ref SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL
uint8_t reserved[3];
@@ -291,7 +291,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct");
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code;
@@ -318,7 +318,7 @@ TU_VERIFY_STATIC( sizeof(scsi_start_stop_unit_t) == 6, "size is not correct"); // SCSI MMC
//--------------------------------------------------------------------+
/// SCSI Read Format Capacity: Write Capacity
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code;
uint8_t reserved[6];
@@ -328,7 +328,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct");
-typedef struct ATTR_PACKED{
+typedef struct TU_ATTR_PACKED{
uint8_t reserved[3];
uint8_t list_length; /// must be 8*n, length in bytes of formattable capacity descriptor followed it.
@@ -348,7 +348,7 @@ TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not c //--------------------------------------------------------------------+
/// SCSI Read Capacity 10 Command: Read Capacity
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_READ_CAPACITY_10
uint8_t reserved1 ;
@@ -369,7 +369,7 @@ typedef struct { TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_resp_t) == 8, "size is not correct");
/// SCSI Read 10 Command
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code ; ///< SCSI OpCode
uint8_t reserved ; // has LUN according to wiki
diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 2fd3d44a1..5681e4f07 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -139,7 +139,7 @@ bool mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t (*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
// Prepare for Command Block Wrapper
- TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
+ TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
return true;
}
@@ -394,7 +394,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t if ( (p_cbw->total_bytes > 0 ) && !tu_bit_test(p_cbw->dir, 7) )
{
// queue transfer
- TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
+ TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
}else
{
int32_t resplen;
@@ -428,7 +428,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t if (p_msc->total_len)
{
TU_ASSERT( p_cbw->total_bytes >= p_msc->total_len ); // cannot return more than host expect
- TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len) );
+ TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len) );
}else
{
p_msc->stage = MSC_STAGE_STATUS;
@@ -543,7 +543,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t p_msc->stage = MSC_STAGE_CMD;
// Send SCSI Status
- TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
+ TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
// Invoke complete callback if defined
if ( SCSI_CMD_READ_10 == p_cbw->command[0])
@@ -560,7 +560,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t }
// Queue for the next CBW
- TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
+ TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
}
}
@@ -602,7 +602,7 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc) }
else
{
- TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, nbytes), );
+ TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, nbytes), );
}
}
@@ -627,7 +627,7 @@ static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc) int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
// Write10 callback will be called later when usb transfer complete
- TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, nbytes), );
+ TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, nbytes), );
}
#endif
diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index cf228dad9..03a4afadb 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -126,24 +126,24 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, /*------------- Optional callbacks -------------*/
// Invoked when received GET_MAX_LUN request, required for multiple LUNs implementation
-ATTR_WEAK uint8_t tud_msc_get_maxlun_cb(void);
+TU_ATTR_WEAK uint8_t tud_msc_get_maxlun_cb(void);
// Invoked when received Start Stop Unit command
// - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage
// - Start = 1 : active mode, if load_eject = 1 : load disk storage
-ATTR_WEAK void tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject);
+TU_ATTR_WEAK void tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject);
// Invoked when Read10 command is complete
-ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun);
+TU_ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun);
// Invoke when Write10 command is complete, can be used to flush flash caching
-ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun);
+TU_ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun);
// Invoked when command in tud_msc_scsi_cb is complete
-ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[16]);
+TU_ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[16]);
// Hook to make a mass storage device read-only. TODO remove
-ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun);
+TU_ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun);
/** @} */
/** @} */
diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index d2a1a00f7..0507c5f6d 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -44,7 +44,7 @@ static osal_semaphore_def_t msch_sem_def; static osal_semaphore_t msch_sem_hdl;
// buffer used to read scsi information when mounted, largest response data currently is inquiry
-CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) static uint8_t msch_buffer[sizeof(scsi_inquiry_resp_t)];
+CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4) static uint8_t msch_buffer[sizeof(scsi_inquiry_resp_t)];
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 4b74bcfc0..c77be2a9f 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -57,9 +57,6 @@ #define TU_BIT(n) (1U << (n))
-// for declaration of reserved field, make use of _TU_COUNTER_
-#define TU_RESERVED XSTRING_CONCAT_(reserved, _TU_COUNTER_)
-
//--------------------------------------------------------------------+
// INCLUDES
//--------------------------------------------------------------------+
diff --git a/src/common/tusb_compiler.h b/src/common/tusb_compiler.h index 0978d1c0f..09768ef88 100644 --- a/src/common/tusb_compiler.h +++ b/src/common/tusb_compiler.h @@ -32,10 +32,10 @@ #ifndef _TUSB_COMPILER_H_
#define _TUSB_COMPILER_H_
-#define STRING_(x) #x ///< stringify without expand
-#define XSTRING_(x) STRING_(x) ///< expand then stringify
-#define STRING_CONCAT_(a, b) a##b ///< concat without expand
-#define XSTRING_CONCAT_(a, b) STRING_CONCAT_(a, b) ///< expand then concat
+#define TU_STRING(x) #x ///< stringify without expand
+#define TU_XSTRING(x) TU_STRING(x) ///< expand then stringify
+#define TU_STRCAT(a, b) a##b ///< concat without expand
+#define TU_XSTRCAT(a, b) TU_STRCAT(a, b) ///< expand then concat
#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
#define _TU_COUNTER_ __COUNTER__
@@ -47,20 +47,23 @@ #if __STDC_VERSION__ >= 201112L
#define TU_VERIFY_STATIC _Static_assert
#else
- #define TU_VERIFY_STATIC(const_expr, _mess) enum { XSTRING_CONCAT_(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) }
+ #define TU_VERIFY_STATIC(const_expr, _mess) enum { TU_XSTRCAT(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) }
#endif
+// for declaration of reserved field, make use of _TU_COUNTER_
+#define TU_RESERVED TU_XSTRCAT(reserved, _TU_COUNTER_)
+
//--------------------------------------------------------------------+
// Compiler porting with Attribute and Endian
//--------------------------------------------------------------------+
#if defined(__GNUC__)
- #define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
- #define ATTR_SECTION(sec_name) __attribute__ ((section(#sec_name)))
- #define ATTR_PACKED __attribute__ ((packed))
- #define ATTR_PREPACKED
- #define ATTR_WEAK __attribute__ ((weak))
- #define ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used
- #define ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused
+ #define TU_ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
+ #define TU_ATTR_SECTION(sec_name) __attribute__ ((section(#sec_name)))
+ #define TU_ATTR_PACKED __attribute__ ((packed))
+ #define TU_ATTR_PREPACKED
+ #define TU_ATTR_WEAK __attribute__ ((weak))
+ #define TU_ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used
+ #define TU_ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused
// Endian conversion use well-known host to network (big endian) naming
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c index e2ed51cd6..455b1ad34 100644 --- a/src/common/tusb_fifo.c +++ b/src/common/tusb_fifo.c @@ -71,6 +71,35 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si return true;
}
+// retrieve data from fifo
+static void _tu_ff_pull(tu_fifo_t* f, void * buffer)
+{
+ memcpy(buffer,
+ f->buffer + (f->rd_idx * f->item_size),
+ f->item_size);
+
+ f->rd_idx = (f->rd_idx + 1) % f->depth;
+ f->count--;
+}
+
+// send data to fifo
+static void _tu_ff_push(tu_fifo_t* f, void const * data)
+{
+ memcpy( f->buffer + (f->wr_idx * f->item_size),
+ data,
+ f->item_size);
+
+ f->wr_idx = (f->wr_idx + 1) % f->depth;
+
+ if (tu_fifo_full(f))
+ {
+ f->rd_idx = f->wr_idx; // keep the full state (rd == wr && len = size)
+ }
+ else
+ {
+ f->count++;
+ }
+}
/******************************************************************************/
/*!
@@ -82,23 +111,19 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si @param[in] f
Pointer to the FIFO buffer to manipulate
- @param[in] p_buffer
+ @param[in] buffer
Pointer to the place holder for data read from the buffer
@returns TRUE if the queue is not empty
*/
/******************************************************************************/
-bool tu_fifo_read(tu_fifo_t* f, void * p_buffer)
+bool tu_fifo_read(tu_fifo_t* f, void * buffer)
{
if( tu_fifo_empty(f) ) return false;
tu_fifo_lock(f);
- memcpy(p_buffer,
- f->buffer + (f->rd_idx * f->item_size),
- f->item_size);
- f->rd_idx = (f->rd_idx + 1) % f->depth;
- f->count--;
+ _tu_ff_pull(f, buffer);
tu_fifo_unlock(f);
@@ -113,7 +138,7 @@ bool tu_fifo_read(tu_fifo_t* f, void * p_buffer) @param[in] f
Pointer to the FIFO buffer to manipulate
- @param[in] p_data
+ @param[in] buffer
The pointer to data location
@param[in] count
Number of element that buffer can afford
@@ -121,27 +146,28 @@ bool tu_fifo_read(tu_fifo_t* f, void * p_buffer) @returns number of items read from the FIFO
*/
/******************************************************************************/
-uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t count)
+uint16_t tu_fifo_read_n (tu_fifo_t* f, void * buffer, uint16_t count)
{
if( tu_fifo_empty(f) ) return 0;
+ tu_fifo_lock(f);
+
/* Limit up to fifo's count */
if ( count > f->count ) count = f->count;
- /* Could copy up to 2 portions marked as 'x' if queue is wrapped around
- * case 1: ....RxxxxW.......
- * case 2: xxxxxW....Rxxxxxx
- */
-// uint16_t index2upper = tu_min16(count, f->count-f->rd_idx);
-
- uint8_t* p_buf = (uint8_t*) p_buffer;
+ uint8_t* buf8 = (uint8_t*) buffer;
uint16_t len = 0;
- while( (len < count) && tu_fifo_read(f, p_buf) )
+
+ while (len < count)
{
+ _tu_ff_pull(f, buf8);
+
len++;
- p_buf += f->item_size;
+ buf8 += f->item_size;
}
+ tu_fifo_unlock(f);
+
return len;
}
@@ -182,33 +208,20 @@ bool tu_fifo_peek_at(tu_fifo_t* f, uint16_t pos, void * p_buffer) @param[in] f
Pointer to the FIFO buffer to manipulate
- @param[in] p_data
+ @param[in] data
The byte to add to the FIFO
@returns TRUE if the data was written to the FIFO (overwrittable
FIFO will always return TRUE)
*/
/******************************************************************************/
-bool tu_fifo_write (tu_fifo_t* f, const void * p_data)
+bool tu_fifo_write (tu_fifo_t* f, const void * data)
{
if ( tu_fifo_full(f) && !f->overwritable ) return false;
tu_fifo_lock(f);
- memcpy( f->buffer + (f->wr_idx * f->item_size),
- p_data,
- f->item_size);
-
- f->wr_idx = (f->wr_idx + 1) % f->depth;
-
- if (tu_fifo_full(f))
- {
- f->rd_idx = f->wr_idx; // keep the full state (rd == wr && len = size)
- }
- else
- {
- f->count++;
- }
+ _tu_ff_push(f, data);
tu_fifo_unlock(f);
@@ -223,26 +236,35 @@ bool tu_fifo_write (tu_fifo_t* f, const void * p_data) @param[in] f
Pointer to the FIFO buffer to manipulate
- @param[in] p_data
+ @param[in] data
The pointer to data to add to the FIFO
@param[in] count
Number of element
@return Number of written elements
*/
/******************************************************************************/
-uint16_t tu_fifo_write_n (tu_fifo_t* f, const void * p_data, uint16_t count)
+uint16_t tu_fifo_write_n (tu_fifo_t* f, const void * data, uint16_t count)
{
if ( count == 0 ) return 0;
- uint8_t const* p_buf = (uint8_t const*) p_data;
+ tu_fifo_lock(f);
+
+ // Not overwritable limit up to full
+ if (!f->overwritable) count = tu_min16(count, tu_fifo_remaining(f));
+ uint8_t const* buf8 = (uint8_t const*) data;
uint16_t len = 0;
- while( (len < count) && tu_fifo_write(f, p_buf) )
+
+ while (len < count)
{
+ _tu_ff_push(f, buf8);
+
len++;
- p_buf += f->item_size;
+ buf8 += f->item_size;
}
+ tu_fifo_unlock(f);
+
return len;
}
diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index 786533849..34ad26f15 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -200,7 +200,7 @@ enum //--------------------------------------------------------------------+
/// USB Standard Device Descriptor (section 9.6.1, table 9-8)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< DEVICE Descriptor Type.
@@ -222,7 +222,7 @@ typedef struct ATTR_PACKED } tusb_desc_device_t;
/// USB Standard Configuration Descriptor (section 9.6.1 table 9-10) */
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
@@ -236,7 +236,7 @@ typedef struct ATTR_PACKED } tusb_desc_configuration_t;
/// USB Standard Interface Descriptor (section 9.6.1 table 9-12)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< INTERFACE Descriptor Type
@@ -251,21 +251,21 @@ typedef struct ATTR_PACKED } tusb_desc_interface_t;
/// USB Standard Endpoint Descriptor (section 9.6.1 table 9-13)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< ENDPOINT Descriptor Type
uint8_t bEndpointAddress ; ///< The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: \n Bit 3...0: The endpoint number \n Bit 6...4: Reserved, reset to zero \n Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint.
- struct ATTR_PACKED {
+ struct TU_ATTR_PACKED {
uint8_t xfer : 2;
uint8_t sync : 2;
uint8_t usage : 2;
uint8_t : 2;
} bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host.
- struct ATTR_PACKED {
+ struct TU_ATTR_PACKED {
uint16_t size : 11; ///< Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. \n For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. \n For all endpoints, bits 10..0 specify the maximum packet size (in bytes). \n For high-speed isochronous and interrupt endpoints: \n Bits 12..11 specify the number of additional transaction opportunities per microframe: \n- 00 = None (1 transaction per microframe) \n- 01 = 1 additional (2 per microframe) \n- 10 = 2 additional (3 per microframe) \n- 11 = Reserved \n Bits 15..13 are reserved and must be set to zero.
uint16_t hs_period_mult : 2;
uint16_t : 0;
@@ -275,7 +275,7 @@ typedef struct ATTR_PACKED } tusb_desc_endpoint_t;
/// USB Other Speed Configuration Descriptor (section 9.6.1 table 9-11)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
@@ -289,7 +289,7 @@ typedef struct ATTR_PACKED } tusb_desc_other_speed_t;
/// USB Device Qualifier Descriptor (section 9.6.1 table 9-9)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Device Qualifier Type
@@ -304,7 +304,7 @@ typedef struct ATTR_PACKED } tusb_desc_device_qualifier_t;
/// USB Interface Association Descriptor (IAD ECN)
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
@@ -320,13 +320,13 @@ typedef struct ATTR_PACKED } tusb_desc_interface_assoc_t;
/// USB Header Descriptor
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< Descriptor Type
} tusb_desc_header_t;
-typedef struct ATTR_PACKED
+typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< Descriptor Type
@@ -337,9 +337,9 @@ typedef struct ATTR_PACKED /*------------------------------------------------------------------*/
/* Types
*------------------------------------------------------------------*/
-typedef struct ATTR_PACKED{
+typedef struct TU_ATTR_PACKED{
union {
- struct ATTR_PACKED {
+ struct TU_ATTR_PACKED {
uint8_t recipient : 5; ///< Recipient type tusb_request_recipient_t.
uint8_t type : 2; ///< Request type tusb_request_type_t.
uint8_t direction : 1; ///< Direction type. tusb_dir_t
diff --git a/src/device/dcd.h b/src/device/dcd.h index 35164ac62..0ed4a77d9 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -52,7 +52,7 @@ typedef enum USBD_EVENT_FUNC_CALL
} dcd_eventid_t;
-typedef struct ATTR_ALIGNED(4)
+typedef struct TU_ATTR_ALIGNED(4)
{
uint8_t rhport;
uint8_t event_id;
@@ -100,25 +100,28 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num); // Wake up host
void dcd_remote_wakeup(uint8_t rhport);
-/*------------------------------------------------------------------*/
-/* Endpoint API
- * - open : Configure endpoint's registers
- * - xfer : Submit a transfer. When complete dcd_event_xfer_complete
- * must be called to notify the stack
- * - busy : Check if endpoint transferring is complete (TODO remove)
- * - stall : stall endpoint
- * - clear_stall : clear stall, data toggle is also reset to DATA0
- *------------------------------------------------------------------*/
+//--------------------------------------------------------------------+
+// Endpoint API
+//--------------------------------------------------------------------+
+
+// Configure endpoint's registers according to descriptor
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
+
+// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
+
+// Check if endpoint transferring is complete (TODO remove)
bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr);
+// Stall endpoint
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr);
+
+// clear stall, data toggle is also reset to DATA0
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr);
/*------------------------------------------------------------------*/
/* Event Function
- * Called by DCD to notify USBD
+ * Called by DCD to notify device stack
*------------------------------------------------------------------*/
void dcd_event_handler(dcd_event_t const * event, bool in_isr);
diff --git a/src/device/usbd.c b/src/device/usbd.c index 56d895388..a68953151 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -31,6 +31,7 @@ #include "tusb.h"
#include "usbd.h"
#include "device/usbd_pvt.h"
+#include "dcd.h"
#ifndef CFG_TUD_TASK_QUEUE_SZ
#define CFG_TUD_TASK_QUEUE_SZ 16
@@ -40,7 +41,7 @@ // Device Data
//--------------------------------------------------------------------+
typedef struct {
- struct ATTR_PACKED
+ struct TU_ATTR_PACKED
{
volatile uint8_t connected : 1;
volatile uint8_t configured : 1;
@@ -51,8 +52,8 @@ typedef struct { uint8_t self_powered : 1; // configuration descriptor's attribute
};
-// uint8_t ep_busy_mask[2]; // bit mask for busy endpoint
- uint8_t ep_stall_mask[2]; // bit mask for stalled endpoint
+ uint8_t ep_busy_map[2]; // bit mask for busy endpoint
+ uint8_t ep_stall_map[2]; // bit map for stalled endpoint
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
@@ -287,6 +288,10 @@ void tud_task (void) {
// Invoke the class callback associated with the endpoint address
uint8_t const ep_addr = event.xfer_complete.ep_addr;
+ uint8_t const epnum = tu_edpt_number(ep_addr);
+ uint8_t const dir = tu_edpt_dir(ep_addr);
+
+ _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_busy_map[dir], epnum);
if ( 0 == tu_edpt_number(ep_addr) )
{
@@ -621,7 +626,7 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) case DCD_EVENT_SUSPEND:
// NOTE: When plugging/unplugging device, the D+/D- state are unstable and can accidentally meet the
- // SUSPEND condition ( Idle for 3ms ). Some MCUs such as samd don't distinguish suspend vs disconnect as well.
+ // SUSPEND condition ( Idle for 3ms ). Some MCUs such as SAMD doesn't distinguish suspend vs disconnect as well.
// We will skip handling SUSPEND/RESUME event if not currently connected
if ( _usbd_dev.connected )
{
@@ -643,7 +648,8 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) break;
case DCD_EVENT_XFER_COMPLETE:
- // skip zero-length control status complete event, should dcd notifies us.
+ // skip zero-length control status complete event, should DCD notify us.
+ // TODO could cause issue with actual zero length data used by class such as DFU
if ( (0 == tu_edpt_number(event->xfer_complete.ep_addr)) && (event->xfer_complete.len == 0) ) break;
osal_queue_send(_usbd_q, event, in_isr);
@@ -733,13 +739,37 @@ void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr) //--------------------------------------------------------------------+
// USBD Endpoint API
//--------------------------------------------------------------------+
+
+bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
+{
+ uint8_t const epnum = tu_edpt_number(ep_addr);
+ uint8_t const dir = tu_edpt_dir(ep_addr);
+
+ TU_VERIFY( dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes) );
+
+ _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_busy_map[dir], epnum);
+
+ return true;
+}
+
+bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr)
+{
+ (void) rhport;
+
+ uint8_t const epnum = tu_edpt_number(ep_addr);
+ uint8_t const dir = tu_edpt_dir(ep_addr);
+
+ return tu_bit_test(_usbd_dev.ep_busy_map[dir], epnum);
+}
+
+
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
{
uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
dcd_edpt_stall(rhport, ep_addr);
- _usbd_dev.ep_stall_mask[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_stall_mask[dir], epnum);
+ _usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_stall_map[dir], epnum);
}
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
@@ -748,7 +778,7 @@ void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) uint8_t const dir = tu_edpt_dir(ep_addr);
dcd_edpt_clear_stall(rhport, ep_addr);
- _usbd_dev.ep_stall_mask[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_stall_mask[dir], epnum);
+ _usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_stall_map[dir], epnum);
}
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
@@ -758,7 +788,7 @@ bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
- return tu_bit_test(_usbd_dev.ep_stall_mask[dir], epnum);
+ return tu_bit_test(_usbd_dev.ep_stall_map[dir], epnum);
}
#endif
diff --git a/src/device/usbd.h b/src/device/usbd.h index 46143a215..47e0e531c 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -35,7 +35,7 @@ #endif
#include "common/tusb_common.h"
-#include "device/dcd.h"
+#include "dcd.h"
//--------------------------------------------------------------------+
// Application API
@@ -76,17 +76,17 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index); uint16_t const* tud_descriptor_string_cb(uint8_t index);
// Invoked when device is mounted (configured)
-ATTR_WEAK void tud_mount_cb(void);
+TU_ATTR_WEAK void tud_mount_cb(void);
// Invoked when device is unmounted
-ATTR_WEAK void tud_umount_cb(void);
+TU_ATTR_WEAK void tud_umount_cb(void);
// Invoked when usb bus is suspended
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
-ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en);
+TU_ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en);
// Invoked when usb bus is resumed
-ATTR_WEAK void tud_resume_cb(void);
+TU_ATTR_WEAK void tud_resume_cb(void);
//--------------------------------------------------------------------+
// Interface Descriptor Template
diff --git a/src/device/usbd_control.c b/src/device/usbd_control.c index 1b5ee9f91..49293b832 100644 --- a/src/device/usbd_control.c +++ b/src/device/usbd_control.c @@ -30,6 +30,7 @@ #include "tusb.h"
#include "device/usbd_pvt.h"
+#include "dcd.h"
enum
{
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index f20532627..706857d45 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -33,10 +33,11 @@ extern "C" { #endif +bool usbd_init (void); + //--------------------------------------------------------------------+ -// INTERNAL API for stack management +// USBD Endpoint API //--------------------------------------------------------------------+ -bool usbd_init (void); // Carry out Data and Status stage of control transfer // - If len = 0, it is equivalent to sending status only @@ -46,6 +47,12 @@ bool usbd_control_xfer(uint8_t rhport, tusb_control_request_t const * request, v // Send STATUS (zero length) packet bool usbd_control_status(uint8_t rhport, tusb_control_request_t const * request); +// Submit a usb transfer +bool usbd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes); + +// Check if endpoint transferring is complete +bool usbd_edpt_busy (uint8_t rhport, uint8_t ep_addr); + void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr); void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr); bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr); diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 2973c6895..63e87dd54 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -44,7 +44,7 @@ // INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
// Periodic frame list must be 4K alignment
-CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4096) static ehci_data_t ehci_data;
+CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4096) static ehci_data_t ehci_data;
// EHCI portable
uint32_t hcd_ehci_register_addr(uint8_t rhport);
diff --git a/src/host/ehci/ehci.h b/src/host/ehci/ehci.h index f64c58a0c..ce2f56771 100644 --- a/src/host/ehci/ehci.h +++ b/src/host/ehci/ehci.h @@ -95,7 +95,7 @@ typedef union { }ehci_link_t; /// Queue Element Transfer Descriptor -/// Qtd is used to declare overlay in ehci_qhd_t -> cannot be declared with ATTR_ALIGNED(32) +/// Qtd is used to declare overlay in ehci_qhd_t -> cannot be declared with TU_ATTR_ALIGNED(32) typedef struct { // Word 0: Next QTD Pointer @@ -137,7 +137,7 @@ typedef struct TU_VERIFY_STATIC( sizeof(ehci_qtd_t) == 32, "size is not correct" ); /// Queue Head -typedef struct ATTR_ALIGNED(32) +typedef struct TU_ATTR_ALIGNED(32) { // Word 0: Next QHD ehci_link_t next; @@ -185,7 +185,7 @@ typedef struct ATTR_ALIGNED(32) TU_VERIFY_STATIC( sizeof(ehci_qhd_t) == 64, "size is not correct" ); /// Highspeed Isochronous Transfer Descriptor (section 3.3) -typedef struct ATTR_ALIGNED(32) { +typedef struct TU_ATTR_ALIGNED(32) { // Word 0: Next Link Pointer ehci_link_t next; @@ -217,7 +217,7 @@ typedef struct ATTR_ALIGNED(32) { TU_VERIFY_STATIC( sizeof(ehci_itd_t) == 64, "size is not correct" ); /// Split (Full-Speed) Isochronous Transfer Descriptor -typedef struct ATTR_ALIGNED(32) +typedef struct TU_ATTR_ALIGNED(32) { // Word 0: Next Link Pointer ehci_link_t next; @@ -442,7 +442,7 @@ typedef struct }control[CFG_TUSB_HOST_DEVICE_MAX+1]; ehci_qhd_t qhd_pool[HCD_MAX_ENDPOINT]; - ehci_qtd_t qtd_pool[HCD_MAX_XFER] ATTR_ALIGNED(32); + ehci_qtd_t qtd_pool[HCD_MAX_XFER] TU_ATTR_ALIGNED(32); ehci_registers_t* regs; }ehci_data_t; diff --git a/src/host/hub.c b/src/host/hub.c index cc440086f..a2d4e8429 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -45,7 +45,7 @@ typedef struct }usbh_hub_t;
CFG_TUSB_MEM_SECTION static usbh_hub_t hub_data[CFG_TUSB_HOST_DEVICE_MAX];
-ATTR_ALIGNED(4) CFG_TUSB_MEM_SECTION static uint8_t hub_enum_buffer[sizeof(descriptor_hub_desc_t)];
+TU_ATTR_ALIGNED(4) CFG_TUSB_MEM_SECTION static uint8_t hub_enum_buffer[sizeof(descriptor_hub_desc_t)];
//OSAL_SEM_DEF(hub_enum_semaphore);
//static osal_semaphore_handle_t hub_enum_sem_hdl;
diff --git a/src/host/hub.h b/src/host/hub.h index 0182337b1..51d33d4e5 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -81,7 +81,7 @@ //indicators. See Section 11.5.3.
//D15...D8: Reserved
-typedef struct ATTR_PACKED{
+typedef struct TU_ATTR_PACKED{
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint8_t bNbrPorts;
@@ -135,7 +135,7 @@ enum{ // data in response of HUB_REQUEST_GET_STATUS, wIndex = 0 (hub)
typedef struct {
union{
- struct ATTR_PACKED {
+ struct TU_ATTR_PACKED {
uint16_t local_power_source : 1;
uint16_t over_current : 1;
uint16_t : 14;
@@ -150,7 +150,7 @@ TU_VERIFY_STATIC( sizeof(hub_status_response_t) == 4, "size is not correct"); // data in response of HUB_REQUEST_GET_STATUS, wIndex = Port num
typedef struct {
union {
- struct ATTR_PACKED {
+ struct TU_ATTR_PACKED {
uint16_t connect_status : 1;
uint16_t port_enable : 1;
uint16_t suspend : 1;
diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index e22f04f9b..ea553baa2 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -124,7 +124,7 @@ enum { //--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-CFG_TUSB_MEM_SECTION ATTR_ALIGNED(256) static ohci_data_t ohci_data;
+CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static ohci_data_t ohci_data;
static ohci_ed_t * const p_ed_head[] =
{
diff --git a/src/host/ohci/ohci.h b/src/host/ohci/ohci.h index ec35edf19..a8aae251b 100644 --- a/src/host/ohci/ohci.h +++ b/src/host/ohci/ohci.h @@ -65,7 +65,7 @@ typedef struct { volatile uint16_t frame_pad;
volatile uint32_t done_head;
uint8_t reserved[116+4]; // TODO try to make use of this area if possible, extra 4 byte to make the whole struct size = 256
-}ohci_hcca_t; // ATTR_ALIGNED(256)
+}ohci_hcca_t; // TU_ATTR_ALIGNED(256)
TU_VERIFY_STATIC( sizeof(ohci_hcca_t) == 256, "size is not correct" );
@@ -76,7 +76,7 @@ typedef struct { }ohci_td_item_t;
-typedef struct ATTR_ALIGNED(16)
+typedef struct TU_ATTR_ALIGNED(16)
{
// Word 0
uint32_t used : 1;
@@ -102,7 +102,7 @@ typedef struct ATTR_ALIGNED(16) TU_VERIFY_STATIC( sizeof(ohci_gtd_t) == 16, "size is not correct" );
-typedef struct ATTR_ALIGNED(16)
+typedef struct TU_ATTR_ALIGNED(16)
{
// Word 0
uint32_t dev_addr : 7;
@@ -137,7 +137,7 @@ typedef struct ATTR_ALIGNED(16) TU_VERIFY_STATIC( sizeof(ohci_ed_t) == 16, "size is not correct" );
-typedef struct ATTR_ALIGNED(32)
+typedef struct TU_ATTR_ALIGNED(32)
{
/*---------- Word 1 ----------*/
uint32_t starting_frame : 16;
@@ -163,7 +163,7 @@ typedef struct ATTR_ALIGNED(32) TU_VERIFY_STATIC( sizeof(ochi_itd_t) == 32, "size is not correct" );
// structure with member alignment required from large to small
-typedef struct ATTR_ALIGNED(256)
+typedef struct TU_ATTR_ALIGNED(256)
{
ohci_hcca_t hcca;
diff --git a/src/host/usbh.c b/src/host/usbh.c index f370b62f4..655e3dd4b 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -109,7 +109,7 @@ CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; OSAL_QUEUE_DEF(OPT_MODE_HOST, _usbh_qdef, CFG_TUH_TASK_QUEUE_SZ, hcd_event_t);
static osal_queue_t _usbh_q;
-CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) static uint8_t _usbh_ctrl_buf[CFG_TUSB_HOST_ENUM_BUFFER_SIZE];
+CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4) static uint8_t _usbh_ctrl_buf[CFG_TUSB_HOST_ENUM_BUFFER_SIZE];
//------------- Reporter Task Data -------------//
diff --git a/src/host/usbh.h b/src/host/usbh.h index a0955e9f9..311b2514d 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -77,13 +77,13 @@ static inline bool tuh_device_is_configured(uint8_t dev_addr) //--------------------------------------------------------------------+ // APPLICATION CALLBACK //--------------------------------------------------------------------+ -ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device); +TU_ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device); /** Callback invoked when device is mounted (configured) */ -ATTR_WEAK void tuh_mount_cb (uint8_t dev_addr); +TU_ATTR_WEAK void tuh_mount_cb (uint8_t dev_addr); /** Callback invoked when device is unmounted (bus reset/unplugged) */ -ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr); +TU_ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr); //--------------------------------------------------------------------+ // CLASS-USBH & INTERNAL API diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c index 9a9964505..fedfa2ec9 100644 --- a/src/portable/microchip/samd21/dcd_samd21.c +++ b/src/portable/microchip/samd21/dcd_samd21.c @@ -34,8 +34,8 @@ /*------------------------------------------------------------------*/ /* MACRO TYPEDEF CONSTANT ENUM *------------------------------------------------------------------*/ -static ATTR_ALIGNED(4) UsbDeviceDescBank sram_registers[8][2]; -static ATTR_ALIGNED(4) uint8_t _setup_packet[8]; +static TU_ATTR_ALIGNED(4) UsbDeviceDescBank sram_registers[8][2]; +static TU_ATTR_ALIGNED(4) uint8_t _setup_packet[8]; // Setup the control endpoint 0. static void bus_reset(void) diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c index 6a4bd0e63..a43609b9e 100644 --- a/src/portable/microchip/samd51/dcd_samd51.c +++ b/src/portable/microchip/samd51/dcd_samd51.c @@ -35,7 +35,7 @@ /* MACRO TYPEDEF CONSTANT ENUM *------------------------------------------------------------------*/ static UsbDeviceDescBank sram_registers[8][2]; -static ATTR_ALIGNED(4) uint8_t _setup_packet[8]; +static TU_ATTR_ALIGNED(4) uint8_t _setup_packet[8]; // Setup the control endpoint 0. static void bus_reset(void) diff --git a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c index b63bf1feb..0dab2caf7 100644 --- a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c +++ b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c @@ -67,7 +67,7 @@ enum { CMDSTAT_VBUS_DEBOUNCED_MASK = TU_BIT(28), }; -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { // Bits 21:6 (aligned 64) used in conjunction with bit 31:22 of DATABUFSTART volatile uint16_t buffer_offset; @@ -101,7 +101,7 @@ typedef struct xfer_dma_t dma[EP_COUNT]; - ATTR_ALIGNED(64) uint8_t setup_packet[8]; + TU_ATTR_ALIGNED(64) uint8_t setup_packet[8]; }dcd_data_t; //--------------------------------------------------------------------+ @@ -109,7 +109,7 @@ typedef struct //--------------------------------------------------------------------+ // EP list must be 256-byte aligned -CFG_TUSB_MEM_SECTION ATTR_ALIGNED(256) static dcd_data_t _dcd; +CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static dcd_data_t _dcd; static inline uint16_t get_buf_offset(void const * buffer) { diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index a14d20e30..cdc4d58db 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -37,7 +37,7 @@ //--------------------------------------------------------------------+ #define DCD_ENDPOINT_MAX 32 -typedef struct ATTR_ALIGNED(4) +typedef struct TU_ATTR_ALIGNED(4) { //------------- Word 0 -------------// uint32_t next; @@ -91,7 +91,7 @@ typedef struct } dcd_data_t; -CFG_TUSB_MEM_SECTION ATTR_ALIGNED(128) static dcd_data_t _dcd; +CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(128) static dcd_data_t _dcd; //--------------------------------------------------------------------+ diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c index 89dc98ce4..049624d92 100644 --- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c @@ -46,16 +46,16 @@ typedef struct { // Must be at 2K alignment - dcd_qhd_t qhd[QHD_MAX] ATTR_ALIGNED(64); - dcd_qtd_t qtd[QHD_MAX] ATTR_ALIGNED(32); + dcd_qhd_t qhd[QHD_MAX] TU_ATTR_ALIGNED(64); + dcd_qtd_t qtd[QHD_MAX] TU_ATTR_ALIGNED(32); }dcd_data_t; #if (CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE) -CFG_TUSB_MEM_SECTION ATTR_ALIGNED(2048) static dcd_data_t dcd_data0; +CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(2048) static dcd_data_t dcd_data0; #endif #if (CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE) -CFG_TUSB_MEM_SECTION ATTR_ALIGNED(2048) static dcd_data_t dcd_data1; +CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(2048) static dcd_data_t dcd_data1; #endif static LPC_USBHS_T * const LPC_USB[2] = { LPC_USB0, LPC_USB1 }; diff --git a/src/portable/st/stm32f4/dcd_stm32f4.c b/src/portable/st/stm32f4/dcd_stm32f4.c index f7128344d..996950ab0 100644 --- a/src/portable/st/stm32f4/dcd_stm32f4.c +++ b/src/portable/st/stm32f4/dcd_stm32f4.c @@ -39,7 +39,7 @@ #define IN_EP_BASE (USB_OTG_INEndpointTypeDef *) (USB_OTG_FS_PERIPH_BASE + USB_OTG_IN_ENDPOINT_BASE) #define FIFO_BASE(_x) (uint32_t *) (USB_OTG_FS_PERIPH_BASE + USB_OTG_FIFO_BASE + (_x) * USB_OTG_FIFO_SIZE) -static ATTR_ALIGNED(4) uint32_t _setup_packet[6]; +static TU_ATTR_ALIGNED(4) uint32_t _setup_packet[6]; static uint8_t _setup_offs; // We store up to 3 setup packets. typedef struct { diff --git a/src/tusb_option.h b/src/tusb_option.h index 694191406..9415992a7 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -131,7 +131,7 @@ #endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4)
+#define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
#endif
#ifndef CFG_TUSB_OS
|
