summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-12-12 00:27:20 +0700
committerhathach <[email protected]>2025-12-12 00:27:20 +0700
commit711879b2f1bcb122c084e6a8bc93c5d2c599ab84 (patch)
tree15389fe812ec3964ab4957f37a25706dd9e9ff3b
parentc7f7dc6ee1f4f56ccb86adabb2ca3f14c212e985 (diff)
remove bitfield in usbd_device_t state to reduce code size
-rw-r--r--src/common/tusb_fifo.c6
-rw-r--r--src/common/tusb_fifo.h2
-rw-r--r--src/device/usbd.c50
3 files changed, 29 insertions, 29 deletions
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c
index 1fca1fd32..ef787c6e6 100644
--- a/src/common/tusb_fifo.c
+++ b/src/common/tusb_fifo.c
@@ -96,9 +96,9 @@ void tu_fifo_clear(tu_fifo_t *f) {
}
// Change the fifo overwritable mode
-bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable) {
+void tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable) {
if (f->overwritable == overwritable) {
- return true;
+ return;
}
ff_lock(f->mutex_wr);
@@ -108,8 +108,6 @@ bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable) {
ff_unlock(f->mutex_wr);
ff_unlock(f->mutex_rd);
-
- return true;
}
//--------------------------------------------------------------------+
diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h
index 26ac38073..f13c195e5 100644
--- a/src/common/tusb_fifo.h
+++ b/src/common/tusb_fifo.h
@@ -157,7 +157,7 @@ typedef enum {
// Setup API
//--------------------------------------------------------------------+
bool tu_fifo_config(tu_fifo_t *f, void *buffer, uint16_t depth, uint16_t item_size, bool overwritable);
-bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable);
+void tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable);
void tu_fifo_clear(tu_fifo_t *f);
#if OSAL_MUTEX_REQUIRED
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 4cbba1240..6c2ff2f62 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -116,25 +116,28 @@ TU_ATTR_WEAK bool dcd_dcache_clean_invalidate(const void* addr, uint32_t data_si
// Device Data
//--------------------------------------------------------------------+
typedef struct {
- struct TU_ATTR_PACKED {
- volatile uint8_t connected : 1;
- volatile uint8_t addressed : 1;
- volatile uint8_t suspended : 1;
+ // Note: these may share an enum state
+ volatile uint8_t connected;
+ volatile uint8_t addressed;
+ volatile uint8_t suspended;
- uint8_t remote_wakeup_en : 1; // enable/disable by host
- uint8_t remote_wakeup_support : 1; // configuration descriptor's attribute
- uint8_t self_powered : 1; // configuration descriptor's attribute
+ union {
+ struct TU_ATTR_PACKED {
+ uint8_t self_powered : 1; // configuration descriptor's attribute;
+ uint8_t remote_wakeup_en : 1; // enable/disable by host
+ };
+ uint8_t dev_state_bm;
};
- volatile uint8_t cfg_num; // current active configuration (0x00 is not configured)
- uint8_t speed;
+
+ uint8_t cfg_num; // current active configuration (0x00 is not configured)
+ uint8_t speed;
volatile uint8_t sof_consumer;
uint8_t itf2drv[CFG_TUD_INTERFACE_MAX]; // map interface number to driver (0xff is invalid)
uint8_t ep2drv[CFG_TUD_ENDPPOINT_MAX][2]; // map endpoint to driver ( 0xff is invalid ), can use only 4-bit each
tu_edpt_state_t ep_status[CFG_TUD_ENDPPOINT_MAX][2];
-
-}usbd_device_t;
+} usbd_device_t;
static usbd_device_t _usbd_dev;
static volatile uint8_t _usbd_queued_setup;
@@ -142,11 +145,11 @@ static volatile uint8_t _usbd_queued_setup;
//--------------------------------------------------------------------+
// Class Driver
//--------------------------------------------------------------------+
-#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
- #define DRIVER_NAME(_name) _name
-#else
- #define DRIVER_NAME(_name) NULL
-#endif
+ #if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
+ #define DRIVER_NAME(_name) _name
+ #else
+ #define DRIVER_NAME(_name) NULL
+ #endif
// Built-in class drivers
static const usbd_class_driver_t _usbd_driver[] = {
@@ -471,8 +474,8 @@ bool tud_suspended(void) {
}
bool tud_remote_wakeup(void) {
- // only wake up host if this feature is supported and enabled and we are suspended
- TU_VERIFY (_usbd_dev.suspended && _usbd_dev.remote_wakeup_support && _usbd_dev.remote_wakeup_en);
+ // only wake up host if this feature is enabled and we are suspended
+ TU_VERIFY(_usbd_dev.suspended && _usbd_dev.remote_wakeup_en);
dcd_remote_wakeup(_usbd_rhport);
return true;
}
@@ -881,7 +884,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
case TUSB_REQ_FEATURE_REMOTE_WAKEUP:
TU_LOG_USBD(" Enable Remote Wakeup\r\n");
// Host may enable remote wake up before suspending especially HID device
- _usbd_dev.remote_wakeup_en = true;
+ _usbd_dev.remote_wakeup_en = 1;
tud_control_status(rhport, p_request);
break;
@@ -910,15 +913,15 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
TU_LOG_USBD(" Disable Remote Wakeup\r\n");
// Host may disable remote wake up after resuming
- _usbd_dev.remote_wakeup_en = false;
+ _usbd_dev.remote_wakeup_en = 0;
tud_control_status(rhport, p_request);
break;
case TUSB_REQ_GET_STATUS: {
// Device status bit mask
- // - Bit 0: Self Powered
+ // - Bit 0: Self Powered TODO must invoke callback to get actual status
// - Bit 1: Remote Wakeup enabled
- uint16_t status = (uint16_t) ((_usbd_dev.self_powered ? 1u : 0u) | (_usbd_dev.remote_wakeup_en ? 2u : 0u));
+ uint16_t status = (uint16_t)_usbd_dev.dev_state_bm;
tud_control_xfer(rhport, p_request, &status, 2);
break;
}
@@ -1039,8 +1042,7 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num) {
TU_ASSERT(desc_cfg != NULL && desc_cfg->bDescriptorType == TUSB_DESC_CONFIGURATION);
// Parse configuration descriptor
- _usbd_dev.remote_wakeup_support = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP) ? 1u : 0u;
- _usbd_dev.self_powered = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_SELF_POWERED) ? 1u : 0u;
+ _usbd_dev.self_powered = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_SELF_POWERED) ? 1u : 0u;
// Parse interface descriptor
const uint8_t *p_desc = ((const uint8_t *)desc_cfg) + sizeof(tusb_desc_configuration_t);