summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Lawrence <[email protected]>2021-02-22 20:53:16 -0600
committerPeter Lawrence <[email protected]>2021-02-22 20:53:16 -0600
commit592d047936544af03e7704ad7a88acef88fd6aee (patch)
tree9e526e203b5ea7ba77b22a6b6620e34b74d5eeb6 /src
parent99d3a32ba24fd16e847f442cf9ad50bd07aa65dc (diff)
rp2040: correctly size variables to reduce RAM usage
Diffstat (limited to 'src')
-rw-r--r--src/portable/raspberrypi/rp2040/dcd_rp2040.c10
-rw-r--r--src/portable/raspberrypi/rp2040/rp2040_usb.c9
-rw-r--r--src/portable/raspberrypi/rp2040/rp2040_usb.h12
3 files changed, 17 insertions, 14 deletions
diff --git a/src/portable/raspberrypi/rp2040/dcd_rp2040.c b/src/portable/raspberrypi/rp2040/dcd_rp2040.c
index 95b0963a3..d329d40c3 100644
--- a/src/portable/raspberrypi/rp2040/dcd_rp2040.c
+++ b/src/portable/raspberrypi/rp2040/dcd_rp2040.c
@@ -48,8 +48,8 @@
// Init these in dcd_init
static uint8_t *next_buffer_ptr;
-// Endpoints 0-15, direction 0 for out and 1 for in.
-static struct hw_endpoint hw_endpoints[16][2] = {0};
+// Endpoints 0-TUD_OPT_RP2040_USB_MAX_ENDPOINTS, direction 0 for out and 1 for in.
+static struct hw_endpoint hw_endpoints[TUD_OPT_RP2040_USB_MAX_ENDPOINTS][2] = {0};
static inline struct hw_endpoint *hw_endpoint_get_by_num(uint8_t num, uint8_t in)
{
@@ -64,7 +64,7 @@ static struct hw_endpoint *hw_endpoint_get_by_addr(uint8_t ep_addr)
}
static void _hw_endpoint_alloc(struct hw_endpoint *ep)
{
- uint size = TU_MIN(64, ep->wMaxPacketSize);
+ uint16_t size = TU_MIN(64, ep->wMaxPacketSize);
// Assumes single buffered for now
ep->hw_data_buf = next_buffer_ptr;
@@ -99,7 +99,7 @@ static void _hw_endpoint_alloc(struct hw_endpoint *ep)
*ep->endpoint_control = reg;
}
-static void _hw_endpoint_init(struct hw_endpoint *ep, uint8_t ep_addr, uint wMaxPacketSize, uint8_t transfer_type)
+static void _hw_endpoint_init(struct hw_endpoint *ep, uint8_t ep_addr, uint16_t wMaxPacketSize, uint8_t transfer_type)
{
uint8_t num = tu_edpt_number(ep_addr);
bool in = ep_addr & TUSB_DIR_IN_MASK;
@@ -194,7 +194,7 @@ static void hw_endpoint_close(uint8_t ep_addr)
}
#endif
-static void hw_endpoint_init(uint8_t ep_addr, uint wMaxPacketSize, uint8_t bmAttributes)
+static void hw_endpoint_init(uint8_t ep_addr, uint16_t wMaxPacketSize, uint8_t bmAttributes)
{
struct hw_endpoint *ep = hw_endpoint_get_by_addr(ep_addr);
_hw_endpoint_init(ep, ep_addr, wMaxPacketSize, bmAttributes);
diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.c b/src/portable/raspberrypi/rp2040/rp2040_usb.c
index 339297ad6..ecd474695 100644
--- a/src/portable/raspberrypi/rp2040/rp2040_usb.c
+++ b/src/portable/raspberrypi/rp2040/rp2040_usb.c
@@ -30,7 +30,6 @@
#include <stdlib.h>
#include "rp2040_usb.h"
-#include "hardware/clocks.h"
// Direction strings for debug
const char *ep_dir_string[] = {
@@ -153,7 +152,7 @@ void _hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t t
// Fill in info now that we're kicking off the hw
ep->total_len = total_len;
ep->len = 0;
- ep->transfer_size = tu_min32(total_len, ep->wMaxPacketSize);
+ ep->transfer_size = tu_min16(total_len, ep->wMaxPacketSize);
ep->active = true;
ep->user_buf = buffer;
// Recalculate if this is the last buffer
@@ -172,7 +171,7 @@ void _hw_endpoint_xfer_sync(struct hw_endpoint *ep)
// Get the buffer state and amount of bytes we have
// transferred
uint32_t buf_ctrl = _hw_endpoint_buffer_control_get_value32(ep);
- uint transferred_bytes = buf_ctrl & USB_BUF_CTRL_LEN_MASK;
+ uint16_t transferred_bytes = buf_ctrl & USB_BUF_CTRL_LEN_MASK;
#ifdef RP2040_USB_HOST_MODE
// tag::host_buf_sel_fix[]
@@ -230,8 +229,8 @@ bool _hw_endpoint_xfer_continue(struct hw_endpoint *ep)
_hw_endpoint_xfer_sync(ep);
// Now we have synced our state with the hardware. Is there more data to transfer?
- uint remaining_bytes = ep->total_len - ep->len;
- ep->transfer_size = tu_min32(remaining_bytes, ep->wMaxPacketSize);
+ uint16_t remaining_bytes = ep->total_len - ep->len;
+ ep->transfer_size = tu_min16(remaining_bytes, ep->wMaxPacketSize);
_hw_endpoint_update_last_buf(ep);
// Can happen because of programmer error so check for it
diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.h b/src/portable/raspberrypi/rp2040/rp2040_usb.h
index 7c3234e8d..be9b507c2 100644
--- a/src/portable/raspberrypi/rp2040/rp2040_usb.h
+++ b/src/portable/raspberrypi/rp2040/rp2040_usb.h
@@ -16,6 +16,10 @@
#define TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX PICO_RP2040_USB_DEVICE_ENUMERATION_FIX
#endif
+#if !defined(TUD_OPT_RP2040_USB_MAX_ENDPOINTS)
+#define TUD_OPT_RP2040_USB_MAX_ENDPOINTS 16
+#endif
+
// For memset
#include <string.h>
@@ -67,10 +71,10 @@ struct hw_endpoint
// Current transfer information
bool active;
- uint total_len;
- uint len;
+ uint16_t total_len;
+ uint16_t len;
// Amount of data with the hardware
- uint transfer_size;
+ uint16_t transfer_size;
// Only needed for host mode
bool last_buf;
// HOST BUG. Host will incorrect write status to top half of buffer
@@ -80,7 +84,7 @@ struct hw_endpoint
uint8_t *user_buf;
// Data needed from EP descriptor
- uint wMaxPacketSize;
+ uint16_t wMaxPacketSize;
// Interrupt, bulk, etc
uint8_t transfer_type;