From 07c4cc7a4a0977a42d29f5060d02b7a2ab0ef969 Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Wed, 17 Feb 2021 22:43:08 +0900 Subject: [PATCH] Save memory by not using an unnecessary buffer. Saves (64 - sizeof(struct usb_request)) bytes. --- usb.c | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/usb.c b/usb.c index 42740d1..52c322e 100644 --- a/usb.c +++ b/usb.c @@ -1,5 +1,5 @@ /* gc_n64_usb : Gamecube or N64 controller to USB firmware - Copyright (C) 2007-2016 Raphael Assenat + Copyright (C) 2007-2021 Raphael Assenat This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,7 +32,7 @@ #define STATE_CONFIGURED 3 static volatile uint8_t g_usb_suspend; -static uint8_t g_ep0_buf[64]; +//static uint8_t g_ep0_buf[64]; static uint8_t g_device_state = STATE_DEFAULT; static uint8_t g_current_config; static void *interrupt_data; @@ -129,6 +129,36 @@ static void setupEndpoints() } } +// Requires UENUM already set +static uint16_t getEPlen(void) +{ +#ifdef UEBCHX + return UEBCLX | (UEBCHX << 8); +#else + return UEBCLX; +#endif +} + +// Requires UENUM already set +// writes up to n bytes +static uint16_t readEP2buf_n(void *dstbuf, int n) +{ + uint16_t len; + int i; + uint8_t *dst = dstbuf; +#ifdef UEBCHX + len = UEBCLX | (UEBCHX << 8); +#else + len = UEBCLX; +#endif + for (i=0; i