summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2021-11-13 13:09:22 +0800
committersakumisu <[email protected]>2021-11-14 21:14:51 +0800
commit5a22e7a57b08686483a44ab4a7adc915976041fb (patch)
treedf436f92e8dc08eb10d40c303815e7ccda5abf12 /common
parent27bbaa0e0e668508eb003189b70b3ed038795384 (diff)
modify print log,add USBD_LOG_INFO forever print
Diffstat (limited to 'common')
-rw-r--r--common/usb_dc.h29
-rw-r--r--common/usb_util.h20
2 files changed, 38 insertions, 11 deletions
diff --git a/common/usb_dc.h b/common/usb_dc.h
index 29997c11..02e6e6c0 100644
--- a/common/usb_dc.h
+++ b/common/usb_dc.h
@@ -8,12 +8,23 @@ extern "C" {
#endif
/**
- * @brief USB Device Controller API
- * @defgroup _usb_device_controller_api USB Device Controller API
- * @{
+ * USB endpoint direction and number.
*/
-/**< maximum packet size (MPS) for EP 0 */
-#define USB_CTRL_EP_MPS 64
+#define USB_EP_DIR_MASK 0x80U
+#define USB_EP_DIR_IN 0x80U
+#define USB_EP_DIR_OUT 0x00U
+
+/** Get endpoint index (number) from endpoint address */
+#define USB_EP_GET_IDX(ep) ((ep) & ~USB_EP_DIR_MASK)
+/** Get direction from endpoint address */
+#define USB_EP_GET_DIR(ep) ((ep)&USB_EP_DIR_MASK)
+/** Get endpoint address from endpoint index and direction */
+#define USB_EP_GET_ADDR(idx, dir) ((idx) | ((dir)&USB_EP_DIR_MASK))
+/** True if the endpoint is an IN endpoint */
+#define USB_EP_DIR_IS_IN(ep) (USB_EP_GET_DIR(ep) == USB_EP_DIR_IN)
+/** True if the endpoint is an OUT endpoint */
+#define USB_EP_DIR_IS_OUT(ep) (USB_EP_GET_DIR(ep) == USB_EP_DIR_OUT)
+
/**
* USB endpoint Transfer Type mask.
*/
@@ -28,6 +39,14 @@ extern "C" {
#define USB_CONTROL_IN_EP0 0x80
/**
+ * @brief USB Device Controller API
+ * @defgroup _usb_device_controller_api USB Device Controller API
+ * @{
+ */
+/**< maximum packet size (MPS) for EP 0 */
+#define USB_CTRL_EP_MPS 64
+
+/**
* @brief USB Endpoint Transfer Type
*/
enum usb_dc_ep_transfer_type {
diff --git a/common/usb_util.h b/common/usb_util.h
index 4c18cc14..4586b360 100644
--- a/common/usb_util.h
+++ b/common/usb_util.h
@@ -38,8 +38,12 @@
#endif
#define __unused __attribute__((__unused__))
-#define __ALIGN_END __attribute__((aligned(4)))
+#ifndef __ALIGN_BEGIN
#define __ALIGN_BEGIN
+#endif
+#ifndef __ALIGN_END
+#define __ALIGN_END __attribute__((aligned(4)))
+#endif
#ifndef LO_BYTE
#define LO_BYTE(x) ((uint8_t)(x & 0x00FF))
@@ -85,10 +89,12 @@
((int)((sizeof(array) / sizeof((array)[0]))))
#endif
-#define USB_DESC_SECTION __attribute__((section("usb_desc"))) __used __aligned(1)
-
+#ifndef BSWAP16
#define BSWAP16(u16) (__builtin_bswap16(u16))
+#endif
+#ifndef BSWAP32
#define BSWAP32(u32) (__builtin_bswap32(u32))
+#endif
#define GET_BE16(field) \
(((uint16_t)(field)[0] << 8) | ((uint16_t)(field)[1]))
@@ -127,15 +133,17 @@
#define WBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF)
#define DBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF), ((x >> 16) & 0xFF), ((x >> 24) & 0xFF)
+#define USB_DESC_SECTION __attribute__((section("usb_desc"))) __used __aligned(1)
+
#if 0
#define USBD_LOG_WRN(a, ...) printf(a, ##__VA_ARGS__)
#define USBD_LOG_DBG(a, ...) printf(a, ##__VA_ARGS__)
#define USBD_LOG_ERR(a, ...) printf(a, ##__VA_ARGS__)
#else
-#define USBD_LOG_WRN(a, ...) printf(a, ##__VA_ARGS__)
+#define USBD_LOG_INFO(a, ...) printf(a, ##__VA_ARGS__)
#define USBD_LOG_DBG(a, ...)
-#define USBD_LOG_ERR(a, ...) printf(a, ##__VA_ARGS__)
-#define USBD_LOG(a, ...) printf(a, ##__VA_ARGS__)
+#define USBD_LOG_WRN(a, ...) printf(a, ##__VA_ARGS__)
+#define USBD_LOG_ERR(a, ...) printf(a, ##__VA_ARGS__)
#endif
#endif \ No newline at end of file