summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/class/cdc/cdc_device.c4
-rw-r--r--src/class/cdc/cdc_rndis_host.h2
-rw-r--r--src/class/custom/custom_host.h4
-rw-r--r--src/class/hid/hid.h36
-rw-r--r--src/class/hid/hid_device.c2
-rw-r--r--src/class/hid/hid_device.h1
-rw-r--r--src/class/hid/hid_host.h24
-rw-r--r--src/class/msc/msc_device.c4
-rw-r--r--src/class/msc/msc_host.h12
-rw-r--r--src/common/binary.h132
-rw-r--r--src/common/compiler/tusb_compiler_gcc.h68
-rw-r--r--src/common/compiler/tusb_compiler_iar.h31
-rw-r--r--src/common/tusb_common.h156
-rw-r--r--src/common/tusb_timeout.h10
-rw-r--r--src/common/tusb_types.h6
-rw-r--r--src/device/dcd.h4
-rw-r--r--src/host/ehci/ehci.c14
-rw-r--r--src/host/ehci/ehci.h24
-rw-r--r--src/host/hcd.h2
-rw-r--r--src/host/hub.c4
-rw-r--r--src/host/hub.h2
-rw-r--r--src/host/ohci/ohci.c56
-rw-r--r--src/host/usbh.c4
-rw-r--r--src/portable/microchip/samd21/dcd_samd21.c6
-rw-r--r--src/portable/microchip/samd51/dcd_samd51.c6
-rw-r--r--src/portable/nordic/nrf5x/dcd_nrf5x.c29
-rw-r--r--src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c39
-rw-r--r--src/portable/nxp/lpc17_40/dcd_lpc17_40.c34
-rw-r--r--src/portable/nxp/lpc17_40/dcd_lpc17_40.h78
-rw-r--r--src/portable/nxp/lpc18_43/dcd_lpc18_43.c36
-rw-r--r--src/portable/nxp/lpc18_43/dcd_lpc18_43.h36
-rw-r--r--src/tusb.h1
32 files changed, 374 insertions, 493 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index 7ec7a1eb2..b8678c1c4 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -93,7 +93,7 @@ CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
bool tud_cdc_n_connected(uint8_t itf)
{
// DTR (bit 0) active is considered as connected
- return BIT_TEST_(_cdcd_itf[itf].line_state, 0);
+ return TU_BIT_TEST(_cdcd_itf[itf].line_state, 0);
}
uint8_t tud_cdc_n_get_line_state (uint8_t itf)
@@ -349,7 +349,7 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request
usbd_control_status(rhport, request);
// Invoke callback
- if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, BIT_TEST_(request->wValue, 0), BIT_TEST_(request->wValue, 1));
+ if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, TU_BIT_TEST(request->wValue, 0), TU_BIT_TEST(request->wValue, 1));
break;
default: return false; // stall unsupported request
diff --git a/src/class/cdc/cdc_rndis_host.h b/src/class/cdc/cdc_rndis_host.h
index 3b92d3f23..730df2e23 100644
--- a/src/class/cdc/cdc_rndis_host.h
+++ b/src/class/cdc/cdc_rndis_host.h
@@ -64,7 +64,7 @@ typedef struct {
}rndish_data_t;
void rndish_init(void);
-tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc) ATTR_WARN_UNUSED_RESULT;
+tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc);
void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes);
void rndish_close(uint8_t dev_addr);
diff --git a/src/class/custom/custom_host.h b/src/class/custom/custom_host.h
index 5f9c25dda..a5fcb6fb4 100644
--- a/src/class/custom/custom_host.h
+++ b/src/class/custom/custom_host.h
@@ -62,7 +62,7 @@ static inline bool tusbh_custom_is_mounted(uint8_t dev_addr, uint16_t vendor_id,
{
(void) vendor_id; // TODO check this later
(void) product_id;
-// return (tusbh_device_get_mounted_class_flag(dev_addr) & BIT_(TUSB_CLASS_MAPPED_INDEX_END-1) ) != 0;
+// return (tusbh_device_get_mounted_class_flag(dev_addr) & TU_BIT(TUSB_CLASS_MAPPED_INDEX_END-1) ) != 0;
return false;
}
@@ -72,7 +72,7 @@ tusb_error_t tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t p
#ifdef _TINY_USB_SOURCE_FILE_
void cush_init(void);
-tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
+tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length);
void cush_isr(pipe_handle_t pipe_hdl, xfer_result_t event);
void cush_close(uint8_t dev_addr);
diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h
index 8bfede2da..6abc71e0d 100644
--- a/src/class/hid/hid.h
+++ b/src/class/hid/hid.h
@@ -173,11 +173,11 @@ typedef struct ATTR_PACKED
/// Standard Mouse Buttons Bitmap
typedef enum
{
- MOUSE_BUTTON_LEFT = BIT_(0), ///< Left button
- MOUSE_BUTTON_RIGHT = BIT_(1), ///< Right button
- MOUSE_BUTTON_MIDDLE = BIT_(2), ///< Middle button
- MOUSE_BUTTON_BACKWARD = BIT_(3), ///< Backward button,
- MOUSE_BUTTON_FORWARD = BIT_(4), ///< Forward button,
+ MOUSE_BUTTON_LEFT = TU_BIT(0), ///< Left button
+ MOUSE_BUTTON_RIGHT = TU_BIT(1), ///< Right button
+ MOUSE_BUTTON_MIDDLE = TU_BIT(2), ///< Middle button
+ MOUSE_BUTTON_BACKWARD = TU_BIT(3), ///< Backward button,
+ MOUSE_BUTTON_FORWARD = TU_BIT(4), ///< Forward button,
}hid_mouse_button_bm_t;
/// @}
@@ -199,23 +199,23 @@ typedef struct ATTR_PACKED
/// Keyboard modifier codes bitmap
typedef enum
{
- KEYBOARD_MODIFIER_LEFTCTRL = BIT_(0), ///< Left Control
- KEYBOARD_MODIFIER_LEFTSHIFT = BIT_(1), ///< Left Shift
- KEYBOARD_MODIFIER_LEFTALT = BIT_(2), ///< Left Alt
- KEYBOARD_MODIFIER_LEFTGUI = BIT_(3), ///< Left Window
- KEYBOARD_MODIFIER_RIGHTCTRL = BIT_(4), ///< Right Control
- KEYBOARD_MODIFIER_RIGHTSHIFT = BIT_(5), ///< Right Shift
- KEYBOARD_MODIFIER_RIGHTALT = BIT_(6), ///< Right Alt
- KEYBOARD_MODIFIER_RIGHTGUI = BIT_(7) ///< Right Window
+ KEYBOARD_MODIFIER_LEFTCTRL = TU_BIT(0), ///< Left Control
+ KEYBOARD_MODIFIER_LEFTSHIFT = TU_BIT(1), ///< Left Shift
+ KEYBOARD_MODIFIER_LEFTALT = TU_BIT(2), ///< Left Alt
+ KEYBOARD_MODIFIER_LEFTGUI = TU_BIT(3), ///< Left Window
+ KEYBOARD_MODIFIER_RIGHTCTRL = TU_BIT(4), ///< Right Control
+ KEYBOARD_MODIFIER_RIGHTSHIFT = TU_BIT(5), ///< Right Shift
+ KEYBOARD_MODIFIER_RIGHTALT = TU_BIT(6), ///< Right Alt
+ KEYBOARD_MODIFIER_RIGHTGUI = TU_BIT(7) ///< Right Window
}hid_keyboard_modifier_bm_t;
typedef enum
{
- KEYBOARD_LED_NUMLOCK = BIT_(0), ///< Num Lock LED
- KEYBOARD_LED_CAPSLOCK = BIT_(1), ///< Caps Lock LED
- KEYBOARD_LED_SCROLLLOCK = BIT_(2), ///< Scroll Lock LED
- KEYBOARD_LED_COMPOSE = BIT_(3), ///< Composition Mode
- KEYBOARD_LED_KANA = BIT_(4) ///< Kana mode
+ KEYBOARD_LED_NUMLOCK = TU_BIT(0), ///< Num Lock LED
+ KEYBOARD_LED_CAPSLOCK = TU_BIT(1), ///< Caps Lock LED
+ KEYBOARD_LED_SCROLLLOCK = TU_BIT(2), ///< Scroll Lock LED
+ KEYBOARD_LED_COMPOSE = TU_BIT(3), ///< Composition Mode
+ KEYBOARD_LED_KANA = TU_BIT(4) ///< Kana mode
}hid_keyboard_led_bm_t;
/// @}
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index 70aa7370d..3b882f705 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -207,6 +207,7 @@ bool tud_hid_keyboard_key_press(char ch)
return tud_hid_keyboard_keycode(modifier, keycode);
}
+#if 0 // should be at application
bool tud_hid_keyboard_key_sequence(const char* str, uint32_t interval_ms)
{
// Send each key in string
@@ -231,6 +232,7 @@ bool tud_hid_keyboard_key_sequence(const char* str, uint32_t interval_ms)
return true;
}
+#endif
#endif // CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h
index 885f33443..f3d5087a2 100644
--- a/src/class/hid/hid_device.h
+++ b/src/class/hid/hid_device.h
@@ -95,7 +95,6 @@ static inline bool tud_hid_keyboard_key_release(void) { return tud_hid_keyboard_
#if CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
bool tud_hid_keyboard_key_press(char ch);
-bool tud_hid_keyboard_key_sequence(const char* str, uint32_t interval_ms);
typedef struct{
uint8_t shift;
diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h
index 7336f5ada..9d4b2b5b6 100644
--- a/src/class/hid/hid_host.h
+++ b/src/class/hid/hid_host.h
@@ -67,7 +67,7 @@ extern uint8_t const hid_keycode_to_ascii_tbl[2][128]; // TODO used weak attr if
* \retval true if device supports Keyboard interface
* \retval false if device does not support Keyboard interface or is not mounted
*/
-bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
+bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr);
/** \brief Check if the interface is currently busy or not
* \param[in] dev_addr device address
@@ -76,7 +76,7 @@ bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_
* \note This function is primarily used for polling/waiting result after \ref tuh_hid_keyboard_get_report.
* Alternatively, asynchronous event API can be used
*/
-bool tuh_hid_keyboard_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
+bool tuh_hid_keyboard_is_busy(uint8_t dev_addr);
/** \brief Perform a get report from Keyboard interface
* \param[in] dev_addr device address
@@ -88,7 +88,7 @@ bool tuh_hid_keyboard_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNU
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
* \note This function is non-blocking and returns immediately. The result of usb transfer will be reported by the interface's callback function
*/
-tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void * p_report) /*ATTR_WARN_UNUSED_RESULT*/;
+tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void * p_report);
//------------- Application Callback -------------//
/** \brief Callback function that is invoked when an transferring event occurred
@@ -132,7 +132,7 @@ void tuh_hid_keyboard_unmounted_cb(uint8_t dev_addr);
* \retval true if device supports Mouse interface
* \retval false if device does not support Mouse interface or is not mounted
*/
-bool tuh_hid_mouse_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
+bool tuh_hid_mouse_is_mounted(uint8_t dev_addr);
/** \brief Check if the interface is currently busy or not
* \param[in] dev_addr device address
@@ -141,7 +141,7 @@ bool tuh_hid_mouse_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNU
* \note This function is primarily used for polling/waiting result after \ref tuh_hid_mouse_get_report.
* Alternatively, asynchronous event API can be used
*/
-bool tuh_hid_mouse_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
+bool tuh_hid_mouse_is_busy(uint8_t dev_addr);
/** \brief Perform a get report from Mouse interface
* \param[in] dev_addr device address
@@ -153,7 +153,7 @@ bool tuh_hid_mouse_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
* \note This function is non-blocking and returns immediately. The result of usb transfer will be reported by the interface's callback function
*/
-tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void* p_report) /*ATTR_WARN_UNUSED_RESULT*/;
+tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void* p_report);
//------------- Application Callback -------------//
/** \brief Callback function that is invoked when an transferring event occurred
@@ -192,11 +192,11 @@ void tuh_hid_mouse_unmounted_cb(uint8_t dev_addr);
* The interface API includes status checking function, data transferring function and callback functions
* @{ */
-bool tuh_hid_generic_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
-tusb_error_t tuh_hid_generic_get_report(uint8_t dev_addr, void* p_report, bool int_on_complete) ATTR_WARN_UNUSED_RESULT;
-tusb_error_t tuh_hid_generic_set_report(uint8_t dev_addr, void* p_report, bool int_on_complete) ATTR_WARN_UNUSED_RESULT;
-tusb_interface_status_t tuh_hid_generic_get_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT;
-tusb_interface_status_t tuh_hid_generic_set_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT;
+bool tuh_hid_generic_is_mounted(uint8_t dev_addr);
+tusb_error_t tuh_hid_generic_get_report(uint8_t dev_addr, void* p_report, bool int_on_complete);
+tusb_error_t tuh_hid_generic_set_report(uint8_t dev_addr, void* p_report, bool int_on_complete);
+tusb_interface_status_t tuh_hid_generic_get_status(uint8_t dev_addr);
+tusb_interface_status_t tuh_hid_generic_set_status(uint8_t dev_addr);
//------------- Application Callback -------------//
void tuh_hid_generic_isr(uint8_t dev_addr, xfer_result_t event);
@@ -216,7 +216,7 @@ typedef struct {
}hidh_interface_info_t;
void hidh_init(void);
-bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
+bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length);
void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes);
void hidh_close(uint8_t dev_addr);
diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c
index d4d115bce..5d2758414 100644
--- a/src/class/msc/msc_device.c
+++ b/src/class/msc/msc_device.c
@@ -385,7 +385,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
p_csw->status = MSC_CSW_STATUS_PASSED;
}
}
- else if ( !BIT_TEST_(p_cbw->dir, 7) )
+ else if ( !TU_BIT_TEST(p_cbw->dir, 7) )
{
// OUT transfer
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
@@ -426,7 +426,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
case MSC_STAGE_DATA:
// OUT transfer, invoke callback if needed
- if ( !BIT_TEST_(p_cbw->dir, 7) )
+ if ( !TU_BIT_TEST(p_cbw->dir, 7) )
{
if ( SCSI_CMD_WRITE_10 != p_cbw->command[0] )
{
diff --git a/src/class/msc/msc_host.h b/src/class/msc/msc_host.h
index 968d221b4..9035cb845 100644
--- a/src/class/msc/msc_host.h
+++ b/src/class/msc/msc_host.h
@@ -60,7 +60,7 @@
* \retval true if device supports
* \retval false if device does not support or is not mounted
*/
-bool tuh_msc_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
+bool tuh_msc_is_mounted(uint8_t dev_addr);
/** \brief Check if the interface is currently busy or not
* \param[in] dev_addr device address
@@ -70,7 +70,7 @@ bool tuh_msc_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RE
* can be scheduled. User needs to make sure the corresponding interface is mounted (by \ref tuh_msc_is_mounted)
* before calling this function
*/
-bool tuh_msc_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
+bool tuh_msc_is_busy(uint8_t dev_addr);
/** \brief Get SCSI vendor's name of MassStorage device
* \param[in] dev_addr device address
@@ -113,7 +113,7 @@ tusb_error_t tuh_msc_get_capacity(uint8_t dev_addr, uint32_t* p_last_lba, uint32
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
* \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the interface's callback function
*/
-tusb_error_t tuh_msc_read10 (uint8_t dev_addr, uint8_t lun, void * p_buffer, uint32_t lba, uint16_t block_count) ATTR_WARN_UNUSED_RESULT;
+tusb_error_t tuh_msc_read10 (uint8_t dev_addr, uint8_t lun, void * p_buffer, uint32_t lba, uint16_t block_count);
/** \brief Perform SCSI WRITE 10 command to write data to MassStorage device
* \param[in] dev_addr device address
@@ -127,7 +127,7 @@ tusb_error_t tuh_msc_read10 (uint8_t dev_addr, uint8_t lun, void * p_buffer, uin
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
* \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the interface's callback function
*/
-tusb_error_t tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * p_buffer, uint32_t lba, uint16_t block_count) ATTR_WARN_UNUSED_RESULT;
+tusb_error_t tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * p_buffer, uint32_t lba, uint16_t block_count);
/** \brief Perform SCSI REQUEST SENSE command, used to retrieve sense data from MassStorage device
* \param[in] dev_addr device address
@@ -150,11 +150,11 @@ tusb_error_t tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, uint8_t *p_dat
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
* \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the interface's callback function
*/
-tusb_error_t tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, msc_csw_t * p_csw) ATTR_WARN_UNUSED_RESULT; // TODO to be refractor
+tusb_error_t tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, msc_csw_t * p_csw); // TODO to be refractor
//tusb_error_t tusbh_msc_scsi_send(uint8_t dev_addr, uint8_t lun, bool is_direction_in,
// uint8_t const * p_command, uint8_t cmd_len,
-// uint8_t * p_response, uint32_t resp_len) ATTR_WARN_UNUSED_RESULT;
+// uint8_t * p_response, uint32_t resp_len);
//------------- Application Callback -------------//
/** \brief Callback function that will be invoked when a device with MassStorage interface is mounted
diff --git a/src/common/binary.h b/src/common/binary.h
deleted file mode 100644
index 3ab87e3f8..000000000
--- a/src/common/binary.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/**************************************************************************/
-/*!
- @file binary.h
- @author hathach (tinyusb.org)
-
- @section LICENSE
-
- Software License Agreement (BSD License)
-
- Copyright (c) 2013, hathach (tinyusb.org)
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- This file is part of the tinyusb stack.
-*/
-/**************************************************************************/
-
-/** \ingroup Group_Common
- * \defgroup Group_Binary Binary
- * @{ */
-
-#ifndef _TUSB_BINARY_H_
-#define _TUSB_BINARY_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#include <stdbool.h>
-#include <stdint.h>
-#include "tusb_compiler.h"
-
-//------------- Bit manipulation -------------//
-#define BIT_(n) (1U << (n)) ///< n-th Bit
-#define BIT_SET_(x, n) ( (x) | BIT_(n) ) ///< set n-th bit of x to 1
-#define BIT_CLR_(x, n) ( (x) & (~BIT_(n)) ) ///< clear n-th bit of x
-#define BIT_TEST_(x, n) ( ((x) & BIT_(n)) ? true : false ) ///< check if n-th bit of x is 1
-
-static inline uint32_t bit_set(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
-static inline uint32_t bit_set(uint32_t value, uint8_t n)
-{
- return value | BIT_(n);
-}
-
-static inline uint32_t bit_clear(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
-static inline uint32_t bit_clear(uint32_t value, uint8_t n)
-{
- return value & (~BIT_(n));
-}
-
-static inline bool bit_test(uint32_t value, uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
-static inline bool bit_test(uint32_t value, uint8_t n)
-{
- return (value & BIT_(n)) ? true : false;
-}
-
-///< create a mask with n-bit lsb set to 1
-static inline uint32_t bit_mask(uint8_t n) ATTR_CONST ATTR_ALWAYS_INLINE;
-static inline uint32_t bit_mask(uint8_t n)
-{
- return (n < 32) ? ( BIT_(n) - 1 ) : UINT32_MAX;
-}
-
-static inline uint32_t bit_mask_range(uint8_t start, uint32_t end) ATTR_CONST ATTR_ALWAYS_INLINE;
-static inline uint32_t bit_mask_range(uint8_t start, uint32_t end)
-{
- return bit_mask(end+1) & ~ bit_mask(start);
-}
-
-static inline uint32_t bit_set_range(uint32_t value, uint8_t start, uint8_t end, uint32_t pattern) ATTR_CONST ATTR_ALWAYS_INLINE;
-static inline uint32_t bit_set_range(uint32_t value, uint8_t start, uint8_t end, uint32_t pattern)
-{
- return ( value & ~bit_mask_range(start, end) ) | (pattern << start);
-}
-
-
-//------------- Binary Constant -------------//
-#if defined(__GNUC__) && !defined(__CC_ARM)
-
-#define BIN8(x) ((uint8_t) (0b##x))
-#define BIN16(b1, b2) ((uint16_t) (0b##b1##b2))
-#define BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4))
-
-#else
-
-// internal macro of B8, B16, B32
-#define _B8__(x) (((x&0x0000000FUL)?1:0) \
- +((x&0x000000F0UL)?2:0) \
- +((x&0x00000F00UL)?4:0) \
- +((x&0x0000F000UL)?8:0) \
- +((x&0x000F0000UL)?16:0) \
- +((x&0x00F00000UL)?32:0) \
- +((x&0x0F000000UL)?64:0) \
- +((x&0xF0000000UL)?128:0))
-
-#define BIN8(d) ((uint8_t) _B8__(0x##d##UL))
-#define BIN16(dmsb,dlsb) (((uint16_t)BIN8(dmsb)<<8) + BIN8(dlsb))
-#define BIN32(dmsb,db2,db3,dlsb) \
- (((uint32_t)BIN8(dmsb)<<24) \
- + ((uint32_t)BIN8(db2)<<16) \
- + ((uint32_t)BIN8(db3)<<8) \
- + BIN8(dlsb))
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _TUSB_BINARY_H_ */
-
-/** @} */
diff --git a/src/common/compiler/tusb_compiler_gcc.h b/src/common/compiler/tusb_compiler_gcc.h
index e40ad9c41..6ea89f24f 100644
--- a/src/common/compiler/tusb_compiler_gcc.h
+++ b/src/common/compiler/tusb_compiler_gcc.h
@@ -1,6 +1,6 @@
/**************************************************************************/
/*!
- @file compiler_gcc.h
+ @file tusb_compiler_gcc.h
@author hathach (tinyusb.org)
@section LICENSE
@@ -49,72 +49,34 @@
#define ALIGN_OF(x) __alignof__(x)
-/// Normally, the compiler places the objects it generates in sections like data or bss & function in text. Sometimes, however, you need additional sections, or you need certain particular variables to appear in special sections, for example to map to special hardware. The section attribute specifies that a variable (or function) lives in a particular section
-#define ATTR_SECTION(sec_name) __attribute__ (( section(#sec_name) ))
-
-/// If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, an error that includes message is diagnosed. This is useful for compile-time checking
-#define ATTR_ERROR(Message) __attribute__ ((error(Message)))
-
-/// If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, a warning that includes message is diagnosed. This is useful for compile-time checking
-#define ATTR_WARNING(Message) __attribute__ ((warning(Message)))
-
-/** \defgroup Group_VariableAttr Variable Attributes
- * @{ */
-
/// This attribute specifies a minimum alignment for the variable or structure field, measured in bytes
#define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
-/// The packed attribute specifies that a variable or structure field should have the smallest possible alignment—one byte for a variable, and one bit for a field, unless you specify a larger value with the aligned attribute
+/// Place variable in a specific section
+#define ATTR_SECTION(sec_name) __attribute__ (( section(#sec_name) ))
+
+/// The packed attribute specifies that a variable or structure field should have
+/// the smallest possible alignment—one byte for a variable, and one bit for a field.
#define ATTR_PACKED __attribute__ ((packed))
#define ATTR_PREPACKED
-/** @} */
-
-/** \defgroup Group_FuncAttr Function Attributes
- * @{ */
-
-/// Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level is specified
+/// This attribute inlines the function even if no optimization level is specified
#define ATTR_ALWAYS_INLINE __attribute__ ((always_inline))
-/// The nonnull attribute specifies that some function parameters should be non-null pointers. f the compiler determines that a null pointer is passed in an argument slot marked as non-null, and the -Wnonnull option is enabled, a warning is issued. All pointer arguments are marked as non-null
-#define ATTR_NON_NULL __attribute__ ((nonull))
+/// The deprecated attribute results in a warning if the function is used anywhere in the source file.
+/// This is useful when identifying functions that are expected to be removed in a future version of a program.
+#define ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess)))
-/// Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute pure
-#define ATTR_PURE __attribute__ ((pure))
-
-/// \brief Many functions do not examine any values except their arguments, and have no effects except the return value. Basically this is just slightly more strict class than the pure attribute below, since function is not allowed to read global memory.
-/// Note that a function that has pointer arguments and examines the data pointed to must not be declared const. Likewise, a function that calls a non-const function usually must not be const. It does not make sense for a const function to return void
-#define ATTR_CONST __attribute__ ((const))
-
-/// The deprecated attribute results in a warning if the function is used anywhere in the source file. This is useful when identifying functions that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated function, to enable users to easily find further information about why the function is deprecated, or what they should do instead. Note that the warnings only occurs for uses
-#define ATTR_DEPRECATED __attribute__ ((deprecated))
-
-/// Same as the deprecated attribute with optional message in the warning
-#define ATTR_DEPRECATED_MESS(mess) __attribute__ ((deprecated(mess)))
-
-/// The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions that can be overridden in user code
+/// The weak attribute causes the declaration to be emitted as a weak symbol rather than a global.
+/// This is primarily useful in defining library functions that can be overridden in user code
#define ATTR_WEAK __attribute__ ((weak))
-/// The alias attribute causes the declaration to be emitted as an alias for another symbol, which must be specified
-#define ATTR_ALIAS(func) __attribute__ ((alias(#func)))
-
-/// The weakref attribute marks a declaration as a weak reference. It is equivalent with weak + alias attribute, but require function is static
-#define ATTR_WEAKREF(func) __attribute__ ((weakref(#func)))
-
-/// The warn_unused_result attribute causes a warning to be emitted if a caller of the function with this attribute does not use its return value. This is useful for functions where not checking the result is either a security problem or always a bug
+/// Warn if a caller of the function with this attribute does not use its return value.
#define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
-/// This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. This is useful, for example, when the function is referenced only in inline assembly.
-#define ATTR_USED __attribute__ ((used))
-
-/// This attribute, attached to a function, means that the function is meant to be possibly unused. GCC does not produce a warning for this function.
+/// Function is meant to be possibly unused. GCC does not produce a warning for this function.
#define ATTR_UNUSED __attribute__ ((unused))
-/** @} */
-
-/** \defgroup Group_BuiltinFunc Built-in Functions
-* @{ */
-
// TODO mcu specific
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __n2be(x) __builtin_bswap32(x) ///< built-in function to convert 32-bit from native to Big Endian
@@ -124,8 +86,6 @@
#define __be2n_16(u16) __n2be_16(u16)
#endif
-/** @} */
-
#ifdef __cplusplus
}
#endif
diff --git a/src/common/compiler/tusb_compiler_iar.h b/src/common/compiler/tusb_compiler_iar.h
index 1f8936859..d62a65e27 100644
--- a/src/common/compiler/tusb_compiler_iar.h
+++ b/src/common/compiler/tusb_compiler_iar.h
@@ -1,6 +1,6 @@
/**************************************************************************/
/*!
- @file compiler_iar.h
+ @file tusb_compiler_iar.h
@author hathach (tinyusb.org)
@section LICENSE
@@ -36,15 +36,6 @@
*/
/**************************************************************************/
-/** \file
- * \brief IAR Compiler
- */
-
-/** \ingroup Group_Compiler
- * \defgroup Group_IAR IAR ARM
- * @{
- */
-
#ifndef _TUSB_COMPILER_IAR_H_
#define _TUSB_COMPILER_IAR_H_
@@ -52,24 +43,17 @@
extern "C" {
#endif
-#define ALIGN_OF(x) __ALIGNOF__(x)
-#define ATTR_PREPACKED __packed
-#define ATTR_PACKED
+#define ALIGN_OF(x) __ALIGNOF__(x)
+#define ATTR_ALIGNED(bytes) _Pragma(XSTRING_(data_alignment=##bytes))
//#define ATTR_SECTION(section) _Pragma((#section))
+#define ATTR_PREPACKED __packed
+#define ATTR_PACKED
-#define ATTR_ALIGNED(bytes) _Pragma(XSTRING_(data_alignment=##bytes))
-
-#ifndef ATTR_ALWAYS_INLINE
-/// Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level is specified
-#define ATTR_ALWAYS_INLINE error
-#endif
-
-#define ATTR_PURE // TODO IAR pure function attribute
-#define ATTR_CONST // TODO IAR const function attribute
+#define ATTR_ALWAYS_INLINE
+#define ATTR_DEPRECATED(mess)
#define ATTR_WEAK __weak
#define ATTR_WARN_UNUSED_RESULT
-#define ATTR_USED
#define ATTR_UNUSED
// built-in function to convert 32-bit Big-Endian to Little-Endian
@@ -86,4 +70,3 @@
#endif /* _TUSB_COMPILER_IAR_H_ */
-/** @} */
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h
index f4fac96b8..22eddd913 100644
--- a/src/common/tusb_common.h
+++ b/src/common/tusb_common.h
@@ -47,30 +47,8 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// INCLUDES
-//--------------------------------------------------------------------+
-
-//------------- Standard Header -------------//
-#include <stdbool.h>
-#include <stdint.h>
-#include <stddef.h>
-#include <string.h>
-#include <stdio.h>
-
-//------------- TUSB Option Header -------------//
-#include "tusb_option.h"
-
-//------------- Common Header -------------//
-#include "tusb_compiler.h"
-#include "tusb_verify.h"
-#include "binary.h"
-#include "tusb_error.h"
-#include "tusb_timeout.h"
-#include "tusb_types.h"
-
-//--------------------------------------------------------------------+
-// MACROS
+ //--------------------------------------------------------------------+
+// Macros Helper
//--------------------------------------------------------------------+
#define TU_ARRAY_SZIE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
#define TU_MIN(_x, _y) ( (_x) < (_y) ) ? (_x) : (_y) )
@@ -89,54 +67,77 @@
#define U32_TO_U8S_BE(u32) U32_B1_U8(u32), U32_B2_U8(u32), U32_B3_U8(u32), U32_B4_U8(u32)
#define U32_TO_U8S_LE(u32) U32_B4_U8(u32), U32_B3_U8(u32), U32_B2_U8(u32), U32_B1_U8(u32)
+//------------- Bit -------------//
+#define TU_BIT(n) (1U << (n)) ///< n-th Bit
+#define TU_BIT_SET(x, n) ( (x) | TU_BIT(n) ) ///< set n-th bit of x to 1
+#define TU_BIT_CLEAR(x, n) ( (x) & (~TU_BIT(n)) ) ///< clear n-th bit of x
+#define TU_BIT_TEST(x, n) ( ((x) & TU_BIT(n)) ? true : false ) ///< check if n-th bit of x is 1
+
//------------- Endian Conversion -------------//
#define ENDIAN_BE(u32) \
(uint32_t) ( (((u32) & 0xFF) << 24) | (((u32) & 0xFF00) << 8) | (((u32) >> 8) & 0xFF00) | (((u32) >> 24) & 0xFF) )
#define ENDIAN_BE16(le16) ((uint16_t) ((U16_LOW_U8(le16) << 8) | U16_HIGH_U8(le16)) )
-#ifndef __n2be_16
-#define __n2be_16(u16) ((uint16_t) ((U16_LOW_U8(u16) << 8) | U16_HIGH_U8(u16)) )
-#define __be2n_16(u16) __n2be_16(u16)
-#endif
+//------------- Binary constant -------------//
+#if defined(__GNUC__) && !defined(__CC_ARM)
+
+#define TU_BIN8(x) ((uint8_t) (0b##x))
+#define TU_BIN16(b1, b2) ((uint16_t) (0b##b1##b2))
+#define TU_BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4))
+#else
+
+// internal macro of B8, B16, B32
+#define _B8__(x) (((x&0x0000000FUL)?1:0) \
+ +((x&0x000000F0UL)?2:0) \
+ +((x&0x00000F00UL)?4:0) \
+ +((x&0x0000F000UL)?8:0) \
+ +((x&0x000F0000UL)?16:0) \
+ +((x&0x00F00000UL)?32:0) \
+ +((x&0x0F000000UL)?64:0) \
+ +((x&0xF0000000UL)?128:0))
+
+#define TU_BIN8(d) ((uint8_t) _B8__(0x##d##UL))
+#define TU_BIN16(dmsb,dlsb) (((uint16_t)TU_BIN8(dmsb)<<8) + TU_BIN8(dlsb))
+#define TU_BIN32(dmsb,db2,db3,dlsb) \
+ (((uint32_t)TU_BIN8(dmsb)<<24) \
+ + ((uint32_t)TU_BIN8(db2)<<16) \
+ + ((uint32_t)TU_BIN8(db3)<<8) \
+ + TU_BIN8(dlsb))
+#endif
// for declaration of reserved field, make use of _TU_COUNTER_
#define TU_RESERVED XSTRING_CONCAT_(reserved, _TU_COUNTER_)
-/*------------------------------------------------------------------*/
-/* Count number of arguments of __VA_ARGS__
- * - reference https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s
- * - _GET_NTH_ARG() takes args >= N (64) but only expand to Nth one (64th)
- * - _RSEQ_N() is reverse sequential to N to add padding to have
- * Nth position is the same as the number of arguments
- * - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma)
- *------------------------------------------------------------------*/
-#ifndef VA_ARGS_NUM_
+//--------------------------------------------------------------------+
+// INCLUDES
+//--------------------------------------------------------------------+
-#define VA_ARGS_NUM_(...) NARG_(_0, ##__VA_ARGS__,_RSEQ_N())
-#define NARG_(...) _GET_NTH_ARG(__VA_ARGS__)
-#define _GET_NTH_ARG( \
- _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
- _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
- _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
- _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
- _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
- _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
- _61,_62,_63,N,...) N
-#define _RSEQ_N() \
- 62,61,60, \
- 59,58,57,56,55,54,53,52,51,50, \
- 49,48,47,46,45,44,43,42,41,40, \
- 39,38,37,36,35,34,33,32,31,30, \
- 29,28,27,26,25,24,23,22,21,20, \
- 19,18,17,16,15,14,13,12,11,10, \
- 9,8,7,6,5,4,3,2,1,0
-#endif
+// Standard Headers
+#include <stdbool.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+
+// Tinyusb Common Headers
+#include "tusb_option.h"
+#include "tusb_compiler.h"
+#include "tusb_verify.h"
+//#include "binary.h"
+#include "tusb_error.h"
+#include "tusb_timeout.h"
+#include "tusb_types.h"
//--------------------------------------------------------------------+
// INLINE FUNCTION
//--------------------------------------------------------------------+
+#ifndef __n2be_16 // TODO clean up
+#define __n2be_16(u16) ((uint16_t) ((U16_LOW_U8(u16) << 8) | U16_HIGH_U8(u16)) )
+#define __be2n_16(u16) __n2be_16(u16)
+#endif
+
#define tu_memclr(buffer, size) memset((buffer), 0, (size))
#define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var)))
@@ -188,10 +189,7 @@ static inline uint32_t tu_align4k (uint32_t value) { return (value & 0xFFFFF000U
static inline uint32_t tu_offset4k(uint32_t value) { return (value & 0xFFFUL); }
//------------- Mathematics -------------//
-static inline uint32_t tu_abs(int32_t value)
-{
- return (value < 0) ? (-value) : value;
-}
+static inline uint32_t tu_abs(int32_t value) { return (value < 0) ? (-value) : value; }
/// inclusive range checking
static inline bool tu_within(uint32_t lower, uint32_t value, uint32_t upper)
@@ -199,10 +197,11 @@ static inline bool tu_within(uint32_t lower, uint32_t value, uint32_t upper)
return (lower <= value) && (value <= upper);
}
+// log2 of a value is its MSB's position
// TODO use clz
static inline uint8_t tu_log2(uint32_t value)
{
- uint8_t result = 0; // log2 of a value is its MSB's position
+ uint8_t result = 0;
while (value >>= 1)
{
@@ -211,6 +210,41 @@ static inline uint8_t tu_log2(uint32_t value)
return result;
}
+// Bit
+static inline uint32_t tu_bit_set(uint32_t value, uint8_t n) { return value | TU_BIT(n); }
+static inline uint32_t tu_bit_clear(uint32_t value, uint8_t n) { return value & (~TU_BIT(n)); }
+static inline bool tu_bit_test(uint32_t value, uint8_t n) { return (value & TU_BIT(n)) ? true : false; }
+
+/*------------------------------------------------------------------*/
+/* Count number of arguments of __VA_ARGS__
+ * - reference https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s
+ * - _GET_NTH_ARG() takes args >= N (64) but only expand to Nth one (64th)
+ * - _RSEQ_N() is reverse sequential to N to add padding to have
+ * Nth position is the same as the number of arguments
+ * - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma)
+ *------------------------------------------------------------------*/
+#ifndef VA_ARGS_NUM_
+
+#define VA_ARGS_NUM_(...) NARG_(_0, ##__VA_ARGS__,_RSEQ_N())
+#define NARG_(...) _GET_NTH_ARG(__VA_ARGS__)
+#define _GET_NTH_ARG( \
+ _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
+ _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
+ _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
+ _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
+ _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
+ _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
+ _61,_62,_63,N,...) N
+#define _RSEQ_N() \
+ 62,61,60, \
+ 59,58,57,56,55,54,53,52,51,50, \
+ 49,48,47,46,45,44,43,42,41,40, \
+ 39,38,37,36,35,34,33,32,31,30, \
+ 29,28,27,26,25,24,23,22,21,20, \
+ 19,18,17,16,15,14,13,12,11,10, \
+ 9,8,7,6,5,4,3,2,1,0
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/src/common/tusb_timeout.h b/src/common/tusb_timeout.h
index 9d80f5fe7..06d5ff5bf 100644
--- a/src/common/tusb_timeout.h
+++ b/src/common/tusb_timeout.h
@@ -79,16 +79,6 @@ static inline void tu_timeout_restart(tu_timeout_t* tt)
tt->start = tusb_hal_millis();
}
-
-static inline void tu_timeout_wait(uint32_t msec)
-{
- tu_timeout_t tt;
- tu_timeout_set(&tt, msec);
-
- // blocking delay
- while ( !tu_timeout_expired(&tt) ) { }
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h
index 6f0167898..9a6d5a520 100644
--- a/src/common/tusb_types.h
+++ b/src/common/tusb_types.h
@@ -170,9 +170,9 @@ typedef enum
}misc_protocol_type_t;
enum {
- TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = BIT_(5),
- TUSB_DESC_CONFIG_ATT_SELF_POWER = BIT_(6),
- TUSB_DESC_CONFIG_ATT_BUS_POWER = BIT_(7)
+ TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = TU_BIT(5),
+ TUSB_DESC_CONFIG_ATT_SELF_POWER = TU_BIT(6),
+ TUSB_DESC_CONFIG_ATT_BUS_POWER = TU_BIT(7)
};
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
diff --git a/src/device/dcd.h b/src/device/dcd.h
index 6b1356cbf..abd85a70b 100644
--- a/src/device/dcd.h
+++ b/src/device/dcd.h
@@ -93,12 +93,16 @@ TU_VERIFY_STATIC(sizeof(dcd_event_t) <= 12, "size is not correct");
/* Device API
*------------------------------------------------------------------*/
bool dcd_init (uint8_t rhport);
+
void dcd_int_enable (uint8_t rhport);
void dcd_int_disable(uint8_t rhport);
void dcd_set_address(uint8_t rhport, uint8_t dev_addr);
void dcd_set_config (uint8_t rhport, uint8_t config_num);
+// Get current frame number
+uint32_t dcd_get_frame_number(uint8_t rhport);
+
/*------------------------------------------------------------------*/
/* Event Function
* Called by DCD to notify USBD
diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c
index b46c9bc64..b8f724122 100644
--- a/src/host/ehci/ehci.c
+++ b/src/host/ehci/ehci.c
@@ -260,9 +260,9 @@ static bool ehci_init(uint8_t rhport)
regs->nxp_tt_control = 0;
//------------- USB CMD Register -------------//
- regs->command |= BIT_(EHCI_USBCMD_POS_RUN_STOP) | BIT_(EHCI_USBCMD_POS_ASYNC_ENABLE)
- | BIT_(EHCI_USBCMD_POS_PERIOD_ENABLE) // TODO enable period list only there is int/iso endpoint
- | ((EHCI_CFG_FRAMELIST_SIZE_BITS & BIN8(011)) << EHCI_USBCMD_POS_FRAMELIST_SZIE)
+ regs->command |= TU_BIT(EHCI_USBCMD_POS_RUN_STOP) | TU_BIT(EHCI_USBCMD_POS_ASYNC_ENABLE)
+ | TU_BIT(EHCI_USBCMD_POS_PERIOD_ENABLE) // TODO enable period list only there is int/iso endpoint
+ | ((EHCI_CFG_FRAMELIST_SIZE_BITS & TU_BIN8(011)) << EHCI_USBCMD_POS_FRAMELIST_SZIE)
| ((EHCI_CFG_FRAMELIST_SIZE_BITS >> 2) << EHCI_USBCMD_POS_NXP_FRAMELIST_SIZE_MSB);
//------------- ConfigFlag Register (skip) -------------//
@@ -791,19 +791,19 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c
if ( interval < 4) // sub milisecond interval
{
p_qhd->interval_ms = 0;
- p_qhd->int_smask = (interval == 1) ? BIN8(11111111) :
- (interval == 2) ? BIN8(10101010) : BIN8(01000100);
+ p_qhd->int_smask = (interval == 1) ? TU_BIN8(11111111) :
+ (interval == 2) ? TU_BIN8(10101010) : TU_BIN8(01000100);
}else
{
p_qhd->interval_ms = (uint8_t) tu_min16( 1 << (interval-4), 255 );
- p_qhd->int_smask = BIT_(interval % 8);
+ p_qhd->int_smask = TU_BIT(interval % 8);
}
}else
{
TU_ASSERT( 0 != interval, );
// Full/Low: 4.12.2.1 (EHCI) case 1 schedule start split at 1 us & complete split at 2,3,4 uframes
p_qhd->int_smask = 0x01;
- p_qhd->fl_int_cmask = BIN8(11100);
+ p_qhd->fl_int_cmask = TU_BIN8(11100);
p_qhd->interval_ms = interval;
}
}else
diff --git a/src/host/ehci/ehci.h b/src/host/ehci/ehci.h
index c1c274793..23bbb310a 100644
--- a/src/host/ehci/ehci.h
+++ b/src/host/ehci/ehci.h
@@ -294,17 +294,17 @@ TU_VERIFY_STATIC( sizeof(ehci_sitd_t) == 32, "size is not correct" );
// EHCI Operational Register
//--------------------------------------------------------------------+
enum ehci_interrupt_mask_{
- EHCI_INT_MASK_USB = BIT_(0),
- EHCI_INT_MASK_ERROR = BIT_(1),
- EHCI_INT_MASK_PORT_CHANGE = BIT_(2),
+ EHCI_INT_MASK_USB = TU_BIT(0),
+ EHCI_INT_MASK_ERROR = TU_BIT(1),
+ EHCI_INT_MASK_PORT_CHANGE = TU_BIT(2),
- EHCI_INT_MASK_FRAMELIST_ROLLOVER = BIT_(3),
- EHCI_INT_MASK_PCI_HOST_SYSTEM_ERROR = BIT_(4),
- EHCI_INT_MASK_ASYNC_ADVANCE = BIT_(5),
- EHCI_INT_MASK_NXP_SOF = BIT_(7),
+ EHCI_INT_MASK_FRAMELIST_ROLLOVER = TU_BIT(3),
+ EHCI_INT_MASK_PCI_HOST_SYSTEM_ERROR = TU_BIT(4),
+ EHCI_INT_MASK_ASYNC_ADVANCE = TU_BIT(5),
+ EHCI_INT_MASK_NXP_SOF = TU_BIT(7),
- EHCI_INT_MASK_NXP_ASYNC = BIT_(18),
- EHCI_INT_MASK_NXP_PERIODIC = BIT_(19),
+ EHCI_INT_MASK_NXP_ASYNC = TU_BIT(18),
+ EHCI_INT_MASK_NXP_PERIODIC = TU_BIT(19),
EHCI_INT_MASK_ALL =
EHCI_INT_MASK_USB | EHCI_INT_MASK_ERROR | EHCI_INT_MASK_PORT_CHANGE |
@@ -323,9 +323,9 @@ enum ehci_usbcmd_pos_ {
};
enum ehci_portsc_change_mask_{
- EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE = BIT_(1),
- EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE = BIT_(3),
- EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE = BIT_(5),
+ EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE = TU_BIT(1),
+ EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE = TU_BIT(3),
+ EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE = TU_BIT(5),
EHCI_PORTSC_MASK_ALL =
EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE |
diff --git a/src/host/hcd.h b/src/host/hcd.h
index e117c20ff..8753543d6 100644
--- a/src/host/hcd.h
+++ b/src/host/hcd.h
@@ -146,7 +146,7 @@ bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], ui
bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete);
#if 0
-tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT;
+tusb_error_t hcd_pipe_cancel();
#endif
#ifdef __cplusplus
diff --git a/src/host/hub.c b/src/host/hub.c
index 6b87e935e..16560a812 100644
--- a/src/host/hub.c
+++ b/src/host/hub.c
@@ -97,7 +97,7 @@ bool hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t
hub_port_status_response_t * p_port_status;
p_port_status = (hub_port_status_response_t *) hub_enum_buffer;
- TU_ASSERT( !BIT_TEST_(p_port_status->status_change.value, feature-16) );
+ TU_ASSERT( !TU_BIT_TEST(p_port_status->status_change.value, feature-16) );
return true;
}
@@ -225,7 +225,7 @@ void hub_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xf
for (uint8_t port=1; port <= p_hub->port_number; port++)
{
// TODO HUB ignore bit0 hub_status_change
- if ( BIT_TEST_(p_hub->status_change, port) )
+ if ( TU_BIT_TEST(p_hub->status_change, port) )
{
hcd_event_t event =
{
diff --git a/src/host/hub.h b/src/host/hub.h
index f8d8a4c6a..626cb4592 100644
--- a/src/host/hub.h
+++ b/src/host/hub.h
@@ -195,7 +195,7 @@ bool hub_status_pipe_queue(uint8_t dev_addr);
#ifdef _TINY_USB_SOURCE_FILE_
void hub_init(void);
-bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
+bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length);
void hub_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
void hub_close(uint8_t dev_addr);
diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c
index bebb8a2ef..887b3e561 100644
--- a/src/host/ohci/ohci.c
+++ b/src/host/ohci/ohci.c
@@ -65,10 +65,10 @@ enum {
enum {
OHCI_CONTROL_CONTROL_BULK_RATIO = 3, ///< This specifies the service ratio between Control and Bulk EDs. 0 = 1:1, 3 = 4:1
- OHCI_CONTROL_LIST_PERIODIC_ENABLE_MASK = BIT_(2),
- OHCI_CONTROL_LIST_ISOCHRONOUS_ENABLE_MASK = BIT_(3),
- OHCI_CONTROL_LIST_CONTROL_ENABLE_MASK = BIT_(4),
- OHCI_CONTROL_LIST_BULK_ENABLE_MASK = BIT_(5),
+ OHCI_CONTROL_LIST_PERIODIC_ENABLE_MASK = TU_BIT(2),
+ OHCI_CONTROL_LIST_ISOCHRONOUS_ENABLE_MASK = TU_BIT(3),
+ OHCI_CONTROL_LIST_CONTROL_ENABLE_MASK = TU_BIT(4),
+ OHCI_CONTROL_LIST_BULK_ENABLE_MASK = TU_BIT(5),
};
enum {
@@ -81,33 +81,33 @@ enum {
};
enum {
- OHCI_INT_SCHEDULING_OVERUN_MASK = BIT_(0),
- OHCI_INT_WRITEBACK_DONEHEAD_MASK = BIT_(1),
- OHCI_INT_SOF_MASK = BIT_(2),
- OHCI_INT_RESUME_DETECTED_MASK = BIT_(3),
- OHCI_INT_UNRECOVERABLE_ERROR_MASK = BIT_(4),
- OHCI_INT_FRAME_OVERFLOW_MASK = BIT_(5),
- OHCI_INT_RHPORT_STATUS_CHANGE_MASK = BIT_(6),
+ OHCI_INT_SCHEDULING_OVERUN_MASK = TU_BIT(0),
+ OHCI_INT_WRITEBACK_DONEHEAD_MASK = TU_BIT(1),
+ OHCI_INT_SOF_MASK = TU_BIT(2),
+ OHCI_INT_RESUME_DETECTED_MASK = TU_BIT(3),
+ OHCI_INT_UNRECOVERABLE_ERROR_MASK = TU_BIT(4),
+ OHCI_INT_FRAME_OVERFLOW_MASK = TU_BIT(5),
+ OHCI_INT_RHPORT_STATUS_CHANGE_MASK = TU_BIT(6),
- OHCI_INT_OWNERSHIP_CHANGE_MASK = BIT_(30),
- OHCI_INT_MASTER_ENABLE_MASK = BIT_(31),
+ OHCI_INT_OWNERSHIP_CHANGE_MASK = TU_BIT(30),
+ OHCI_INT_MASTER_ENABLE_MASK = TU_BIT(31),
};
enum {
- OHCI_RHPORT_CURRENT_CONNECT_STATUS_MASK = BIT_(0),
- OHCI_RHPORT_PORT_ENABLE_STATUS_MASK = BIT_(1),
- OHCI_RHPORT_PORT_SUSPEND_STATUS_MASK = BIT_(2),
- OHCI_RHPORT_PORT_OVER_CURRENT_INDICATOR_MASK = BIT_(3),
- OHCI_RHPORT_PORT_RESET_STATUS_MASK = BIT_(4), ///< write '1' to reset port
+ OHCI_RHPORT_CURRENT_CONNECT_STATUS_MASK = TU_BIT(0),
+ OHCI_RHPORT_PORT_ENABLE_STATUS_MASK = TU_BIT(1),
+ OHCI_RHPORT_PORT_SUSPEND_STATUS_MASK = TU_BIT(2),
+ OHCI_RHPORT_PORT_OVER_CURRENT_INDICATOR_MASK = TU_BIT(3),
+ OHCI_RHPORT_PORT_RESET_STATUS_MASK = TU_BIT(4), ///< write '1' to reset port
- OHCI_RHPORT_PORT_POWER_STATUS_MASK = BIT_(8),
- OHCI_RHPORT_LOW_SPEED_DEVICE_ATTACHED_MASK = BIT_(9),
+ OHCI_RHPORT_PORT_POWER_STATUS_MASK = TU_BIT(8),
+ OHCI_RHPORT_LOW_SPEED_DEVICE_ATTACHED_MASK = TU_BIT(9),
- OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK = BIT_(16),
- OHCI_RHPORT_PORT_ENABLE_CHANGE_MASK = BIT_(17),
- OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK = BIT_(18),
- OHCI_RHPORT_OVER_CURRENT_CHANGE_MASK = BIT_(19),
- OHCI_RHPORT_PORT_RESET_CHANGE_MASK = BIT_(20),
+ OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK = TU_BIT(16),
+ OHCI_RHPORT_PORT_ENABLE_CHANGE_MASK = TU_BIT(17),
+ OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK = TU_BIT(18),
+ OHCI_RHPORT_OVER_CURRENT_CHANGE_MASK = TU_BIT(19),
+ OHCI_RHPORT_PORT_RESET_CHANGE_MASK = TU_BIT(20),
OHCI_RHPORT_ALL_CHANGE_MASK = OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK | OHCI_RHPORT_PORT_ENABLE_CHANGE_MASK |
OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK | OHCI_RHPORT_OVER_CURRENT_CHANGE_MASK | OHCI_RHPORT_PORT_RESET_CHANGE_MASK
@@ -131,7 +131,7 @@ enum {
enum {
OHCI_INT_ON_COMPLETE_YES = 0,
- OHCI_INT_ON_COMPLETE_NO = BIN8(111)
+ OHCI_INT_ON_COMPLETE_NO = TU_BIN8(111)
};
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
@@ -300,7 +300,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
gtd_init(p_setup, (void*) setup_packet, 8);
p_setup->index = dev_addr;
p_setup->pid = OHCI_PID_SETUP;
- p_setup->data_toggle = BIN8(10); // DATA0
+ p_setup->data_toggle = TU_BIN8(10); // DATA0
p_setup->delay_interrupt = OHCI_INT_ON_COMPLETE_YES;
//------------- Attach TDs list to Control Endpoint -------------//
@@ -328,7 +328,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
p_data->index = dev_addr;
p_data->pid = dir ? OHCI_PID_IN : OHCI_PID_OUT;
- p_data->data_toggle = BIN8(11); // DATA1
+ p_data->data_toggle = TU_BIN8(11); // DATA1
p_data->delay_interrupt = OHCI_INT_ON_COMPLETE_YES;
p_ed->td_head.address = (uint32_t) p_data;
diff --git a/src/host/usbh.c b/src/host/usbh.c
index d0b5edb63..4334729e9 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -128,8 +128,8 @@ CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) static uint8_t _usbh_ctrl_buf[CFG_TUSB_HOST
//------------- Reporter Task Data -------------//
//------------- Helper Function Prototypes -------------//
-static inline uint8_t get_new_address(void) ATTR_ALWAYS_INLINE;
-static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_desc) ATTR_ALWAYS_INLINE;
+static inline uint8_t get_new_address(void);
+static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_desc);
static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id);
//--------------------------------------------------------------------+
diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c
index af0721ec3..7b2a57eeb 100644
--- a/src/portable/microchip/samd21/dcd_samd21.c
+++ b/src/portable/microchip/samd21/dcd_samd21.c
@@ -124,6 +124,12 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
// Nothing to do
}
+uint32_t dcd_get_frame_number(uint8_t rhport)
+{
+ (void) rhport;
+ return USB->DEVICE.FNUM.bit.FNUM;
+}
+
/*------------------------------------------------------------------*/
/* DCD Endpoint port
*------------------------------------------------------------------*/
diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c
index ce66b8245..1de3fadb2 100644
--- a/src/portable/microchip/samd51/dcd_samd51.c
+++ b/src/portable/microchip/samd51/dcd_samd51.c
@@ -129,6 +129,12 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
// Nothing to do
}
+uint32_t dcd_get_frame_number(uint8_t rhport)
+{
+ (void) rhport;
+ return USB->DEVICE.FNUM.bit.FNUM;
+}
+
/*------------------------------------------------------------------*/
/* DCD Endpoint port
*------------------------------------------------------------------*/
diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c
index ad5090eb0..49984eae8 100644
--- a/src/portable/nordic/nrf5x/dcd_nrf5x.c
+++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c
@@ -187,7 +187,7 @@ static void xact_in_prepare(uint8_t epnum)
}
//--------------------------------------------------------------------+
-// Tinyusb DCD API
+// Controller API
//--------------------------------------------------------------------+
bool dcd_init (uint8_t rhport)
{
@@ -221,6 +221,15 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
// Nothing to do
}
+uint32_t dcd_get_frame_number(uint8_t rhport)
+{
+ (void) rhport;
+ return NRF_USBD->FRAMECNTR;
+}
+
+//--------------------------------------------------------------------+
+// Endpoint API
+//--------------------------------------------------------------------+
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
{
(void) rhport;
@@ -232,12 +241,12 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
if ( dir == TUSB_DIR_OUT )
{
- NRF_USBD->INTENSET = BIT_(USBD_INTEN_ENDEPOUT0_Pos + epnum);
- NRF_USBD->EPOUTEN |= BIT_(epnum);
+ NRF_USBD->INTENSET = TU_BIT(USBD_INTEN_ENDEPOUT0_Pos + epnum);
+ NRF_USBD->EPOUTEN |= TU_BIT(epnum);
}else
{
- NRF_USBD->INTENSET = BIT_(USBD_INTEN_ENDEPIN0_Pos + epnum);
- NRF_USBD->EPINEN |= BIT_(epnum);
+ NRF_USBD->INTENSET = TU_BIT(USBD_INTEN_ENDEPIN0_Pos + epnum);
+ NRF_USBD->EPINEN |= TU_BIT(epnum);
}
__ISB(); __DSB();
@@ -368,9 +377,9 @@ void USBD_IRQHandler(void)
for(uint8_t i=0; i<USBD_INTEN_EPDATA_Pos+1; i++)
{
- if ( BIT_TEST_(inten, i) && regevt[i] )
+ if ( TU_BIT_TEST(inten, i) && regevt[i] )
{
- int_status |= BIT_(i);
+ int_status |= TU_BIT(i);
// event clear
regevt[i] = 0;
@@ -445,7 +454,7 @@ void USBD_IRQHandler(void)
*/
for(uint8_t epnum=0; epnum<8; epnum++)
{
- if ( BIT_TEST_(int_status, USBD_INTEN_ENDEPOUT0_Pos+epnum))
+ if ( TU_BIT_TEST(int_status, USBD_INTEN_ENDEPOUT0_Pos+epnum))
{
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT);
uint8_t const xact_len = NRF_USBD->EPOUT[epnum].AMOUNT;
@@ -485,7 +494,7 @@ void USBD_IRQHandler(void)
// CBI In: Endpoint -> Host (transaction complete)
for(uint8_t epnum=0; epnum<8; epnum++)
{
- if ( BIT_TEST_(data_status, epnum ) || ( epnum == 0 && is_control_in) )
+ if ( TU_BIT_TEST(data_status, epnum ) || ( epnum == 0 && is_control_in) )
{
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_IN);
@@ -506,7 +515,7 @@ void USBD_IRQHandler(void)
// CBI OUT: Host -> Endpoint
for(uint8_t epnum=0; epnum<8; epnum++)
{
- if ( BIT_TEST_(data_status, 16+epnum ) || ( epnum == 0 && is_control_out) )
+ if ( TU_BIT_TEST(data_status, 16+epnum ) || ( epnum == 0 && is_control_out) )
{
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT);
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 c910bf1ec..a9ba5e336 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
@@ -64,20 +64,20 @@ enum {
};
enum {
- INT_SOF_MASK = BIT_(30),
- INT_DEVICE_STATUS_MASK = BIT_(31)
+ INT_SOF_MASK = TU_BIT(30),
+ INT_DEVICE_STATUS_MASK = TU_BIT(31)
};
enum {
- CMDSTAT_DEVICE_ADDR_MASK = BIT_(7 )-1,
- CMDSTAT_DEVICE_ENABLE_MASK = BIT_(7 ),
- CMDSTAT_SETUP_RECEIVED_MASK = BIT_(8 ),
- CMDSTAT_DEVICE_CONNECT_MASK = BIT_(16), ///< reflect the softconnect only, does not reflect the actual attached state
- CMDSTAT_DEVICE_SUSPEND_MASK = BIT_(17),
- CMDSTAT_CONNECT_CHANGE_MASK = BIT_(24),
- CMDSTAT_SUSPEND_CHANGE_MASK = BIT_(25),
- CMDSTAT_RESET_CHANGE_MASK = BIT_(26),
- CMDSTAT_VBUS_DEBOUNCED_MASK = BIT_(28),
+ CMDSTAT_DEVICE_ADDR_MASK = TU_BIT(7 )-1,
+ CMDSTAT_DEVICE_ENABLE_MASK = TU_BIT(7 ),
+ CMDSTAT_SETUP_RECEIVED_MASK = TU_BIT(8 ),
+ CMDSTAT_DEVICE_CONNECT_MASK = TU_BIT(16), ///< reflect the softconnect only, does not reflect the actual attached state
+ CMDSTAT_DEVICE_SUSPEND_MASK = TU_BIT(17),
+ CMDSTAT_CONNECT_CHANGE_MASK = TU_BIT(24),
+ CMDSTAT_SUSPEND_CHANGE_MASK = TU_BIT(25),
+ CMDSTAT_RESET_CHANGE_MASK = TU_BIT(26),
+ CMDSTAT_VBUS_DEBOUNCED_MASK = TU_BIT(28),
};
typedef struct ATTR_PACKED
@@ -165,6 +165,13 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
LPC_USB->DEVCMDSTAT |= dev_addr;
}
+uint32_t dcd_get_frame_number(uint8_t rhport)
+{
+ (void) rhport;
+
+ return LPC_USB->INFO & (TU_BIT(11) - 1);
+}
+
bool dcd_init(uint8_t rhport)
{
(void) rhport;
@@ -237,7 +244,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
_dcd.ep[ep_id][0].is_iso = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS);
// Enable EP interrupt
- LPC_USB->INTEN |= BIT_(ep_id);
+ LPC_USB->INTEN |= TU_BIT(ep_id);
return true;
}
@@ -296,14 +303,14 @@ static void bus_reset(void)
LPC_USB->INTSTAT = LPC_USB->INTSTAT; // clear all pending interrupt
LPC_USB->DEVCMDSTAT |= CMDSTAT_SETUP_RECEIVED_MASK; // clear setup received interrupt
- LPC_USB->INTEN = INT_DEVICE_STATUS_MASK | BIT_(0) | BIT_(1); // enable device status & control endpoints
+ LPC_USB->INTEN = INT_DEVICE_STATUS_MASK | TU_BIT(0) | TU_BIT(1); // enable device status & control endpoints
}
static void process_xfer_isr(uint32_t int_status)
{
for(uint8_t ep_id = 0; ep_id < EP_COUNT; ep_id++ )
{
- if ( BIT_TEST_(int_status, ep_id) )
+ if ( TU_BIT_TEST(int_status, ep_id) )
{
ep_cmd_sts_t * ep_cs = &_dcd.ep[ep_id][0];
xfer_dma_t* xfer_dma = &_dcd.dma[ep_id];
@@ -378,7 +385,7 @@ void USB_IRQHandler(void)
}
// Setup Receive
- if ( BIT_TEST_(int_status, 0) && (dev_cmd_stat & CMDSTAT_SETUP_RECEIVED_MASK) )
+ if ( TU_BIT_TEST(int_status, 0) && (dev_cmd_stat & CMDSTAT_SETUP_RECEIVED_MASK) )
{
// Follow UM flowchart to clear Active & Stall on both Control IN/OUT endpoints
_dcd.ep[0][0].active = _dcd.ep[1][0].active = 0;
@@ -392,7 +399,7 @@ void USB_IRQHandler(void)
_dcd.ep[0][1].buffer_offset = get_buf_offset(_dcd.setup_packet);
// clear bit0
- int_status = BIT_CLR_(int_status, 0);
+ int_status = TU_BIT_CLEAR(int_status, 0);
}
// Endpoint transfer complete interrupt
diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
index 82d3c3cac..e3286b1cb 100644
--- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
+++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
@@ -148,7 +148,7 @@ static inline uint8_t ep_addr2idx(uint8_t ep_addr)
static void set_ep_size(uint8_t ep_id, uint16_t max_packet_size)
{
// follows example in 11.10.4.2
- LPC_USB->ReEp |= BIT_(ep_id);
+ LPC_USB->ReEp |= TU_BIT(ep_id);
LPC_USB->EpInd = ep_id; // select index before setting packet size
LPC_USB->MaxPSize = max_packet_size;
@@ -227,6 +227,12 @@ void dcd_set_config(uint8_t rhport, uint8_t config_num)
sie_write(SIE_CMDCODE_CONFIGURE_DEVICE, 1, 1);
}
+uint32_t dcd_get_frame_number(uint8_t rhport)
+{
+ (void) rhport;
+ return (uint32_t) sie_read(SIE_CMDCODE_READ_FRAME_NUMBER);
+}
+
//--------------------------------------------------------------------+
// CONTROL HELPER
//--------------------------------------------------------------------+
@@ -419,15 +425,15 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t t
if ( ep_id % 2 )
{
// Clear EP interrupt before Enable DMA
- LPC_USB->EpIntEn &= ~BIT_(ep_id);
- LPC_USB->EpDMAEn = BIT_(ep_id);
+ LPC_USB->EpIntEn &= ~TU_BIT(ep_id);
+ LPC_USB->EpDMAEn = TU_BIT(ep_id);
// endpoint IN need to actively raise DMA request
- LPC_USB->DMARSet = BIT_(ep_id);
+ LPC_USB->DMARSet = TU_BIT(ep_id);
}else
{
// Enable DMA
- LPC_USB->EpDMAEn = BIT_(ep_id);
+ LPC_USB->EpDMAEn = TU_BIT(ep_id);
}
return true;
@@ -442,11 +448,11 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t t
static void control_xfer_isr(uint8_t rhport, uint32_t ep_int_status)
{
// Control out complete
- if ( ep_int_status & BIT_(0) )
+ if ( ep_int_status & TU_BIT(0) )
{
bool is_setup = sie_read(SIE_CMDCODE_ENDPOINT_SELECT+0) & SIE_SELECT_ENDPOINT_SETUP_RECEIVED_MASK;
- LPC_USB->EpIntClr = BIT_(0);
+ LPC_USB->EpIntClr = TU_BIT(0);
if (is_setup)
{
@@ -472,9 +478,9 @@ static void control_xfer_isr(uint8_t rhport, uint32_t ep_int_status)
}
// Control In complete
- if ( ep_int_status & BIT_(1) )
+ if ( ep_int_status & TU_BIT(1) )
{
- LPC_USB->EpIntClr = BIT_(1);
+ LPC_USB->EpIntClr = TU_BIT(1);
dcd_event_xfer_complete(rhport, TUSB_DIR_IN_MASK, _dcd.control.in_bytes, XFER_RESULT_SUCCESS, true);
}
}
@@ -546,12 +552,12 @@ void hal_dcd_isr(uint8_t rhport)
{
for ( uint8_t ep_id = 3; ep_id < DCD_ENDPOINT_MAX; ep_id += 2 )
{
- if ( BIT_TEST_(ep_int_status, ep_id) )
+ if ( TU_BIT_TEST(ep_int_status, ep_id) )
{
- LPC_USB->EpIntClr = BIT_(ep_id);
+ LPC_USB->EpIntClr = TU_BIT(ep_id);
// Clear Ep interrupt for next DMA
- LPC_USB->EpIntEn &= ~BIT_(ep_id);
+ LPC_USB->EpIntEn &= ~TU_BIT(ep_id);
dd_complete_isr(rhport, ep_id);
}
@@ -569,12 +575,12 @@ void hal_dcd_isr(uint8_t rhport)
for ( uint8_t ep_id = 2; ep_id < DCD_ENDPOINT_MAX; ep_id++ )
{
- if ( BIT_TEST_(eot, ep_id) )
+ if ( TU_BIT_TEST(eot, ep_id) )
{
if ( ep_id & 0x01 )
{
// IN enable EpInt for end of usb transfer
- LPC_USB->EpIntEn |= BIT_(ep_id);
+ LPC_USB->EpIntEn |= TU_BIT(ep_id);
}else
{
// OUT
diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.h b/src/portable/nxp/lpc17_40/dcd_lpc17_40.h
index d6b76fcd1..eac8ec99b 100644
--- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.h
+++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.h
@@ -51,45 +51,45 @@
//------------- USB Interrupt USBIntSt -------------//
//enum {
-// DCD_USB_REQ_LOW_PRIO_MASK = BIT_(0),
-// DCD_USB_REQ_HIGH_PRIO_MASK = BIT_(1),
-// DCD_USB_REQ_DMA_MASK = BIT_(2),
-// DCD_USB_REQ_NEED_CLOCK_MASK = BIT_(8),
-// DCD_USB_REQ_ENABLE_MASK = BIT_(31)
+// DCD_USB_REQ_LOW_PRIO_MASK = TU_BIT(0),
+// DCD_USB_REQ_HIGH_PRIO_MASK = TU_BIT(1),
+// DCD_USB_REQ_DMA_MASK = TU_BIT(2),
+// DCD_USB_REQ_NEED_CLOCK_MASK = TU_BIT(8),
+// DCD_USB_REQ_ENABLE_MASK = TU_BIT(31)
//};
//------------- Device Interrupt USBDevInt -------------//
enum {
- DEV_INT_FRAME_MASK = BIT_(0),
- DEV_INT_ENDPOINT_FAST_MASK = BIT_(1),
- DEV_INT_ENDPOINT_SLOW_MASK = BIT_(2),
- DEV_INT_DEVICE_STATUS_MASK = BIT_(3),
- DEV_INT_COMMAND_CODE_EMPTY_MASK = BIT_(4),
- DEV_INT_COMMAND_DATA_FULL_MASK = BIT_(5),
- DEV_INT_RX_ENDPOINT_PACKET_MASK = BIT_(6),
- DEV_INT_TX_ENDPOINT_PACKET_MASK = BIT_(7),
- DEV_INT_ENDPOINT_REALIZED_MASK = BIT_(8),
- DEV_INT_ERROR_MASK = BIT_(9)
+ DEV_INT_FRAME_MASK = TU_BIT(0),
+ DEV_INT_ENDPOINT_FAST_MASK = TU_BIT(1),
+ DEV_INT_ENDPOINT_SLOW_MASK = TU_BIT(2),
+ DEV_INT_DEVICE_STATUS_MASK = TU_BIT(3),
+ DEV_INT_COMMAND_CODE_EMPTY_MASK = TU_BIT(4),
+ DEV_INT_COMMAND_DATA_FULL_MASK = TU_BIT(5),
+ DEV_INT_RX_ENDPOINT_PACKET_MASK = TU_BIT(6),
+ DEV_INT_TX_ENDPOINT_PACKET_MASK = TU_BIT(7),
+ DEV_INT_ENDPOINT_REALIZED_MASK = TU_BIT(8),
+ DEV_INT_ERROR_MASK = TU_BIT(9)
};
//------------- DMA Interrupt USBDMAInt-------------//
enum {
- DMA_INT_END_OF_XFER_MASK = BIT_(0),
- DMA_INT_NEW_DD_REQUEST_MASK = BIT_(1),
- DMA_INT_ERROR_MASK = BIT_(2)
+ DMA_INT_END_OF_XFER_MASK = TU_BIT(0),
+ DMA_INT_NEW_DD_REQUEST_MASK = TU_BIT(1),
+ DMA_INT_ERROR_MASK = TU_BIT(2)
};
//------------- USBCtrl -------------//
enum {
- USBCTRL_READ_ENABLE_MASK = BIT_(0),
- USBCTRL_WRITE_ENABLE_MASK = BIT_(1),
+ USBCTRL_READ_ENABLE_MASK = TU_BIT(0),
+ USBCTRL_WRITE_ENABLE_MASK = TU_BIT(1),
};
//------------- USBRxPLen -------------//
enum {
- USBRXPLEN_PACKET_LENGTH_MASK = (BIT_(10)-1),
- USBRXPLEN_DATA_VALID_MASK = BIT_(10),
- USBRXPLEN_PACKET_READY_MASK = BIT_(11),
+ USBRXPLEN_PACKET_LENGTH_MASK = (TU_BIT(10)-1),
+ USBRXPLEN_DATA_VALID_MASK = TU_BIT(10),
+ USBRXPLEN_PACKET_READY_MASK = TU_BIT(11),
};
//------------- SIE Command Code -------------//
@@ -121,30 +121,30 @@ enum {
//------------- SIE Device Status (get/set from SIE_CMDCODE_DEVICE_STATUS) -------------//
enum {
- SIE_DEV_STATUS_CONNECT_STATUS_MASK = BIT_(0),
- SIE_DEV_STATUS_CONNECT_CHANGE_MASK = BIT_(1),
- SIE_DEV_STATUS_SUSPEND_MASK = BIT_(2),
- SIE_DEV_STATUS_SUSPEND_CHANGE_MASK = BIT_(3),
- SIE_DEV_STATUS_RESET_MASK = BIT_(4)
+ SIE_DEV_STATUS_CONNECT_STATUS_MASK = TU_BIT(0),
+ SIE_DEV_STATUS_CONNECT_CHANGE_MASK = TU_BIT(1),
+ SIE_DEV_STATUS_SUSPEND_MASK = TU_BIT(2),
+ SIE_DEV_STATUS_SUSPEND_CHANGE_MASK = TU_BIT(3),
+ SIE_DEV_STATUS_RESET_MASK = TU_BIT(4)
};
//------------- SIE Select Endpoint Command -------------//
enum {
- SIE_SELECT_ENDPOINT_FULL_EMPTY_MASK = BIT_(0), // 0: empty, 1 full. IN endpoint checks empty, OUT endpoint check full
- SIE_SELECT_ENDPOINT_STALL_MASK = BIT_(1),
- SIE_SELECT_ENDPOINT_SETUP_RECEIVED_MASK = BIT_(2), // clear by SIE_CMDCODE_ENDPOINT_SELECT_CLEAR_INTERRUPT
- SIE_SELECT_ENDPOINT_PACKET_OVERWRITTEN_MASK = BIT_(3), // previous packet is overwritten by a SETUP packet
- SIE_SELECT_ENDPOINT_NAK_MASK = BIT_(4), // last packet response is NAK (auto clear by an ACK)
- SIE_SELECT_ENDPOINT_BUFFER1_FULL_MASK = BIT_(5),
- SIE_SELECT_ENDPOINT_BUFFER2_FULL_MASK = BIT_(6)
+ SIE_SELECT_ENDPOINT_FULL_EMPTY_MASK = TU_BIT(0), // 0: empty, 1 full. IN endpoint checks empty, OUT endpoint check full
+ SIE_SELECT_ENDPOINT_STALL_MASK = TU_BIT(1),
+ SIE_SELECT_ENDPOINT_SETUP_RECEIVED_MASK = TU_BIT(2), // clear by SIE_CMDCODE_ENDPOINT_SELECT_CLEAR_INTERRUPT
+ SIE_SELECT_ENDPOINT_PACKET_OVERWRITTEN_MASK = TU_BIT(3), // previous packet is overwritten by a SETUP packet
+ SIE_SELECT_ENDPOINT_NAK_MASK = TU_BIT(4), // last packet response is NAK (auto clear by an ACK)
+ SIE_SELECT_ENDPOINT_BUFFER1_FULL_MASK = TU_BIT(5),
+ SIE_SELECT_ENDPOINT_BUFFER2_FULL_MASK = TU_BIT(6)
};
typedef enum
{
- SIE_SET_ENDPOINT_STALLED_MASK = BIT_(0),
- SIE_SET_ENDPOINT_DISABLED_MASK = BIT_(5),
- SIE_SET_ENDPOINT_RATE_FEEDBACK_MASK = BIT_(6),
- SIE_SET_ENDPOINT_CONDITION_STALLED_MASK = BIT_(7),
+ SIE_SET_ENDPOINT_STALLED_MASK = TU_BIT(0),
+ SIE_SET_ENDPOINT_DISABLED_MASK = TU_BIT(5),
+ SIE_SET_ENDPOINT_RATE_FEEDBACK_MASK = TU_BIT(6),
+ SIE_SET_ENDPOINT_CONDITION_STALLED_MASK = TU_BIT(7),
}sie_endpoint_set_status_mask_t;
//------------- DMA Descriptor Status -------------//
diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c
index 70b34d848..65b0728eb 100644
--- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c
+++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c
@@ -92,17 +92,6 @@ static dcd_data_t* const dcd_data_ptr[2] =
//--------------------------------------------------------------------+
// CONTROLLER API
//--------------------------------------------------------------------+
-void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
-{
- LPC_USB[rhport]->DEVICEADDR = (dev_addr << 25) | BIT_(24);
-}
-
-void dcd_set_config(uint8_t rhport, uint8_t config_num)
-{
- (void) rhport;
- (void) config_num;
- // nothing to do
-}
/// follows LPC43xx User Manual 23.10.3
static void bus_reset(uint8_t rhport)
@@ -158,7 +147,7 @@ bool dcd_init(uint8_t rhport)
lpc_usb->USBINTR_D = INT_MASK_USB | INT_MASK_ERROR | INT_MASK_PORT_CHANGE | INT_MASK_RESET | INT_MASK_SUSPEND | INT_MASK_SOF;
lpc_usb->USBCMD_D &= ~0x00FF0000; // Interrupt Threshold Interval = 0
- lpc_usb->USBCMD_D |= BIT_(0); // connect
+ lpc_usb->USBCMD_D |= TU_BIT(0); // connect
return true;
}
@@ -173,6 +162,23 @@ void dcd_int_disable(uint8_t rhport)
NVIC_DisableIRQ(rhport ? USB1_IRQn : USB0_IRQn);
}
+void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
+{
+ LPC_USB[rhport]->DEVICEADDR = (dev_addr << 25) | TU_BIT(24);
+}
+
+void dcd_set_config(uint8_t rhport, uint8_t config_num)
+{
+ (void) rhport;
+ (void) config_num;
+ // nothing to do
+}
+
+uint32_t dcd_get_frame_number(uint8_t rhport)
+{
+ return LPC_USB[rhport]->FRINDEX_D >> 3;
+}
+
//--------------------------------------------------------------------+
// HELPER
//--------------------------------------------------------------------+
@@ -284,7 +290,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t t
{
// follows UM 24.10.8.1.1 Setup packet handling using setup lockout mechanism
// wait until ENDPTSETUPSTAT before priming data/status in response TODO add time out
- while(LPC_USB[rhport]->ENDPTSETUPSTAT & BIT_(0)) {}
+ while(LPC_USB[rhport]->ENDPTSETUPSTAT & TU_BIT(0)) {}
}
dcd_qhd_t * p_qhd = &dcd_data_ptr[rhport]->qhd[ep_idx];
@@ -296,7 +302,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t t
p_qhd->qtd_overlay.next = (uint32_t) p_qtd; // link qtd to qhd
// start transfer
- LPC_USB[rhport]->ENDPTPRIME = BIT_( ep_idx2bit(ep_idx) ) ;
+ LPC_USB[rhport]->ENDPTPRIME = TU_BIT( ep_idx2bit(ep_idx) ) ;
return true;
}
@@ -363,7 +369,7 @@ void hal_dcd_isr(uint8_t rhport)
{
for(uint8_t ep_idx = 0; ep_idx < QHD_MAX; ep_idx++)
{
- if ( BIT_TEST_(edpt_complete, ep_idx2bit(ep_idx)) )
+ if ( TU_BIT_TEST(edpt_complete, ep_idx2bit(ep_idx)) )
{
// 23.10.12.3 Failed QTD also get ENDPTCOMPLETE set
dcd_qtd_t * p_qtd = &dcd_data_ptr[rhport]->qtd[ep_idx];
diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.h b/src/portable/nxp/lpc18_43/dcd_lpc18_43.h
index faf0e3b0f..c380be724 100644
--- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.h
+++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.h
@@ -55,37 +55,37 @@
/*---------- ENDPTCTRL ----------*/
enum {
- ENDPTCTRL_MASK_STALL = BIT_(0),
- ENDPTCTRL_MASK_TOGGLE_INHIBIT = BIT_(5), ///< used for test only
- ENDPTCTRL_MASK_TOGGLE_RESET = BIT_(6),
- ENDPTCTRL_MASK_ENABLE = BIT_(7)
+ ENDPTCTRL_MASK_STALL = TU_BIT(0),
+ ENDPTCTRL_MASK_TOGGLE_INHIBIT = TU_BIT(5), ///< used for test only
+ ENDPTCTRL_MASK_TOGGLE_RESET = TU_BIT(6),
+ ENDPTCTRL_MASK_ENABLE = TU_BIT(7)
};
/*---------- USBCMD ----------*/
enum {
- USBCMD_MASK_RUN_STOP = BIT_(0),
- USBCMD_MASK_RESET = BIT_(1),
- USBCMD_MASK_SETUP_TRIPWIRE = BIT_(13),
- USBCMD_MASK_ADD_QTD_TRIPWIRE = BIT_(14) ///< This bit is used as a semaphore to ensure the to proper addition of a new dTD to an active (primed) endpoint’s linked list. This bit is set and cleared by software during the process of adding a new dTD
+ USBCMD_MASK_RUN_STOP = TU_BIT(0),
+ USBCMD_MASK_RESET = TU_BIT(1),
+ USBCMD_MASK_SETUP_TRIPWIRE = TU_BIT(13),
+ USBCMD_MASK_ADD_QTD_TRIPWIRE = TU_BIT(14) ///< This bit is used as a semaphore to ensure the to proper addition of a new dTD to an active (primed) endpoint’s linked list. This bit is set and cleared by software during the process of adding a new dTD
};
// Interrupt Threshold bit 23:16
/*---------- USBSTS, USBINTR ----------*/
enum {
- INT_MASK_USB = BIT_(0),
- INT_MASK_ERROR = BIT_(1),
- INT_MASK_PORT_CHANGE = BIT_(2),
- INT_MASK_RESET = BIT_(6),
- INT_MASK_SOF = BIT_(7),
- INT_MASK_SUSPEND = BIT_(8),
- INT_MASK_NAK = BIT_(16)
+ INT_MASK_USB = TU_BIT(0),
+ INT_MASK_ERROR = TU_BIT(1),
+ INT_MASK_PORT_CHANGE = TU_BIT(2),
+ INT_MASK_RESET = TU_BIT(6),
+ INT_MASK_SOF = TU_BIT(7),
+ INT_MASK_SUSPEND = TU_BIT(8),
+ INT_MASK_NAK = TU_BIT(16)
};
//------------- PORTSC -------------//
enum {
- PORTSC_CURRENT_CONNECT_STATUS_MASK = BIT_(0),
- PORTSC_FORCE_PORT_RESUME_MASK = BIT_(6),
- PORTSC_SUSPEND_MASK = BIT_(7)
+ PORTSC_CURRENT_CONNECT_STATUS_MASK = TU_BIT(0),
+ PORTSC_FORCE_PORT_RESUME_MASK = TU_BIT(6),
+ PORTSC_SUSPEND_MASK = TU_BIT(7)
};
typedef struct
diff --git a/src/tusb.h b/src/tusb.h
index 3a13bbecc..389bf54d4 100644
--- a/src/tusb.h
+++ b/src/tusb.h
@@ -109,6 +109,7 @@ bool tusb_init(void);
// backward compatible only. TODO remove later
+ATTR_DEPRECATED("Please use either tud_task() or tuh_task()")
static inline void tusb_task(void)
{
#if TUSB_OPT_HOST_ENABLED