summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2025-12-14 21:33:55 +0100
committerHiFiPhile <[email protected]>2025-12-14 21:33:55 +0100
commitc5f91ec6f54509d03529e276ffd42b0d9abab695 (patch)
tree282a2c91f917a09f3bb6611e37bfe93c5d134b47 /src
parent23451ce886ba1eddf194edba4f9b65794dcdc3bd (diff)
reduce code size
Signed-off-by: HiFiPhile <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/class/audio/audio_device.c2
-rw-r--r--src/class/dfu/dfu_device.c2
-rw-r--r--src/device/usbd_control.c19
-rw-r--r--src/device/usbd_pvt.h7
4 files changed, 13 insertions, 17 deletions
diff --git a/src/class/audio/audio_device.c b/src/class/audio/audio_device.c
index 02f9257af..03cb51efe 100644
--- a/src/class/audio/audio_device.c
+++ b/src/class/audio/audio_device.c
@@ -430,7 +430,7 @@ static inline uint8_t* get_ctrl_buffer(void) {
#if CFG_TUD_AUDIO_CTRL_BUF_SZ > CFG_TUD_ENDPOINT0_BUFSIZE
return ctrl_buf;
#else
- return usbd_control_get_buffer();
+ return _usbd_ctrl_epbuf.buf;
#endif
}
diff --git a/src/class/dfu/dfu_device.c b/src/class/dfu/dfu_device.c
index 6c42ca4e6..36f9ffcf4 100644
--- a/src/class/dfu/dfu_device.c
+++ b/src/class/dfu/dfu_device.c
@@ -75,7 +75,7 @@ static inline uint8_t* get_xfer_buffer(void) {
#if CFG_TUD_DFU_XFER_BUFSIZE > CFG_TUD_ENDPOINT0_BUFSIZE
return _transfer_buf;
#else
- return usbd_control_get_buffer();
+ return _usbd_ctrl_epbuf.buf;
#endif
}
diff --git a/src/device/usbd_control.c b/src/device/usbd_control.c
index 49fdce214..1064185d4 100644
--- a/src/device/usbd_control.c
+++ b/src/device/usbd_control.c
@@ -59,9 +59,7 @@ typedef struct {
static usbd_control_xfer_t _ctrl_xfer;
-CFG_TUD_MEM_SECTION static struct {
- TUD_EPBUF_DEF(buf, CFG_TUD_ENDPOINT0_BUFSIZE);
-} _ctrl_epbuf;
+CFG_TUD_MEM_SECTION usbd_ctrl_epbuf_t _usbd_ctrl_epbuf;
//--------------------------------------------------------------------+
// Application API
@@ -93,12 +91,12 @@ static bool data_stage_xact(uint8_t rhport) {
if (_ctrl_xfer.request.bmRequestType_bit.direction == TUSB_DIR_IN) {
ep_addr = EDPT_CTRL_IN;
- if (0u != xact_len && _ctrl_xfer.buffer != _ctrl_epbuf.buf) {
- TU_VERIFY(0 == tu_memcpy_s(_ctrl_epbuf.buf, CFG_TUD_ENDPOINT0_BUFSIZE, _ctrl_xfer.buffer, xact_len));
+ if (0u != xact_len && _ctrl_xfer.buffer != _usbd_ctrl_epbuf.buf) {
+ TU_VERIFY(0 == tu_memcpy_s(_usbd_ctrl_epbuf.buf, CFG_TUD_ENDPOINT0_BUFSIZE, _ctrl_xfer.buffer, xact_len));
}
}
- return usbd_edpt_xfer(rhport, ep_addr, xact_len ? _ctrl_epbuf.buf : NULL, xact_len, false);
+ return usbd_edpt_xfer(rhport, ep_addr, xact_len ? _usbd_ctrl_epbuf.buf : NULL, xact_len, false);
}
// Transmit data to/from the control endpoint.
@@ -121,11 +119,6 @@ bool tud_control_xfer(uint8_t rhport, const tusb_control_request_t* request, voi
return true;
}
-// Get control transfer endpoint buffer
-uint8_t* usbd_control_get_buffer(void) {
- return _ctrl_epbuf.buf;
-}
-
//--------------------------------------------------------------------+
// USBD API
//--------------------------------------------------------------------+
@@ -174,8 +167,8 @@ bool usbd_control_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result,
if (_ctrl_xfer.request.bmRequestType_bit.direction == TUSB_DIR_OUT) {
TU_VERIFY(_ctrl_xfer.buffer);
- if (_ctrl_xfer.buffer != _ctrl_epbuf.buf) {
- memcpy(_ctrl_xfer.buffer, _ctrl_epbuf.buf, xferred_bytes);
+ if (_ctrl_xfer.buffer != _usbd_ctrl_epbuf.buf) {
+ memcpy(_ctrl_xfer.buffer, _usbd_ctrl_epbuf.buf, xferred_bytes);
}
TU_LOG_MEM(CFG_TUD_LOG_LEVEL, _ctrl_xfer.buffer, xferred_bytes, 2);
}
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h
index f556b556b..bc9a737b2 100644
--- a/src/device/usbd_pvt.h
+++ b/src/device/usbd_pvt.h
@@ -72,8 +72,11 @@ void usbd_int_set(bool enabled);
void usbd_spin_lock(bool in_isr);
void usbd_spin_unlock(bool in_isr);
-// Get control transfer endpoint buffer
-uint8_t* usbd_control_get_buffer(void);
+typedef struct {
+ TUD_EPBUF_DEF(buf, CFG_TUD_ENDPOINT0_BUFSIZE);
+} usbd_ctrl_epbuf_t;
+
+extern usbd_ctrl_epbuf_t _usbd_ctrl_epbuf;
//--------------------------------------------------------------------+
// USBD Endpoint API