mirror of
https://github.com/raphnet/gc_n64_usb-v3
synced 2024-12-21 23:08:53 -05:00
Save memory
Store the device string in 8 bit and in program memory. Also reduce the size of a few variables.
This commit is contained in:
parent
b22985712f
commit
c7e8dc7ad4
23
main.c
23
main.c
@ -55,6 +55,7 @@
|
|||||||
#include "dataHidReport.c"
|
#include "dataHidReport.c"
|
||||||
|
|
||||||
#define MAX_READ_ERRORS 30
|
#define MAX_READ_ERRORS 30
|
||||||
|
static uint8_t error_count[MAX_PLAYERS] = { };
|
||||||
|
|
||||||
struct cfg0 {
|
struct cfg0 {
|
||||||
struct usb_configuration_descriptor configdesc;
|
struct usb_configuration_descriptor configdesc;
|
||||||
@ -434,12 +435,11 @@ int main(void)
|
|||||||
{
|
{
|
||||||
Gamepad *pads[MAX_PLAYERS] = { };
|
Gamepad *pads[MAX_PLAYERS] = { };
|
||||||
gamepad_data pad_data;
|
gamepad_data pad_data;
|
||||||
unsigned char gamepad_vibrate = 0;
|
uint8_t gamepad_vibrate = 0;
|
||||||
unsigned char state = STATE_WAIT_POLLTIME;
|
uint8_t state = STATE_WAIT_POLLTIME;
|
||||||
int error_count[MAX_PLAYERS] = { };
|
uint8_t channel;
|
||||||
int i;
|
uint8_t num_players = 1;
|
||||||
int channel;
|
uint8_t i;
|
||||||
int num_players = 1;
|
|
||||||
|
|
||||||
hwinit();
|
hwinit();
|
||||||
usart1_init();
|
usart1_init();
|
||||||
@ -451,20 +451,21 @@ int main(void)
|
|||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case CFG_MODE_STANDARD:
|
case CFG_MODE_STANDARD:
|
||||||
|
usbstrings_changeProductString_P(PSTR("GC/N64 to USB v"VERSIONSTR_SHORT));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFG_MODE_N64_ONLY:
|
case CFG_MODE_N64_ONLY:
|
||||||
usbstrings_changeProductString(L"N64 to USB v"VERSIONSTR_SHORT);
|
usbstrings_changeProductString_P(PSTR("N64 to USB v"VERSIONSTR_SHORT));
|
||||||
device_descriptor.idProduct = N64_USB_PID;
|
device_descriptor.idProduct = N64_USB_PID;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFG_MODE_GC_ONLY:
|
case CFG_MODE_GC_ONLY:
|
||||||
usbstrings_changeProductString(L"Gamecube to USB v"VERSIONSTR_SHORT);
|
usbstrings_changeProductString_P(PSTR("Gamecube to USB v"VERSIONSTR_SHORT));
|
||||||
device_descriptor.idProduct = GC_USB_PID;
|
device_descriptor.idProduct = GC_USB_PID;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFG_MODE_2P_STANDARD:
|
case CFG_MODE_2P_STANDARD:
|
||||||
usbstrings_changeProductString(L"Dual GC/N64 to USB v"VERSIONSTR_SHORT);
|
usbstrings_changeProductString_P(PSTR("Dual GC/N64 to USB v"VERSIONSTR_SHORT));
|
||||||
device_descriptor.idProduct = DUAL_GCN64_USB_PID;
|
device_descriptor.idProduct = DUAL_GCN64_USB_PID;
|
||||||
usb_params.configdesc = (PGM_VOID_P)&cfg0_2p;
|
usb_params.configdesc = (PGM_VOID_P)&cfg0_2p;
|
||||||
usb_params.configdesc_ttllen = sizeof(cfg0_2p);
|
usb_params.configdesc_ttllen = sizeof(cfg0_2p);
|
||||||
@ -473,7 +474,7 @@ int main(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CFG_MODE_2P_N64_ONLY:
|
case CFG_MODE_2P_N64_ONLY:
|
||||||
usbstrings_changeProductString(L"Dual N64 to USB v"VERSIONSTR_SHORT);
|
usbstrings_changeProductString_P(PSTR("Dual N64 to USB v"VERSIONSTR_SHORT));
|
||||||
device_descriptor.idProduct = DUAL_N64_USB_PID;
|
device_descriptor.idProduct = DUAL_N64_USB_PID;
|
||||||
usb_params.configdesc = (PGM_VOID_P)&cfg0_2p;
|
usb_params.configdesc = (PGM_VOID_P)&cfg0_2p;
|
||||||
usb_params.configdesc_ttllen = sizeof(cfg0_2p);
|
usb_params.configdesc_ttllen = sizeof(cfg0_2p);
|
||||||
@ -482,7 +483,7 @@ int main(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CFG_MODE_2P_GC_ONLY:
|
case CFG_MODE_2P_GC_ONLY:
|
||||||
usbstrings_changeProductString(L"Dual Gamecube to USB v"VERSIONSTR_SHORT);
|
usbstrings_changeProductString_P(PSTR("Dual Gamecube to USB v"VERSIONSTR_SHORT));
|
||||||
device_descriptor.idProduct = DUAL_GC_USB_PID;
|
device_descriptor.idProduct = DUAL_GC_USB_PID;
|
||||||
usb_params.configdesc = (PGM_VOID_P)&cfg0_2p;
|
usb_params.configdesc = (PGM_VOID_P)&cfg0_2p;
|
||||||
usb_params.configdesc_ttllen = sizeof(cfg0_2p);
|
usb_params.configdesc_ttllen = sizeof(cfg0_2p);
|
||||||
|
25
usbstrings.c
25
usbstrings.c
@ -17,13 +17,32 @@
|
|||||||
#include <stdlib.h> // for wchar_t
|
#include <stdlib.h> // for wchar_t
|
||||||
#include "usbstrings.h"
|
#include "usbstrings.h"
|
||||||
|
|
||||||
|
static wchar_t product_string[PRODUCT_STRING_MAXCHARS]; // = L"GC/N64 to USB v"VERSIONSTR_SHORT;
|
||||||
|
|
||||||
const wchar_t *g_usb_strings[] = {
|
const wchar_t *g_usb_strings[] = {
|
||||||
[0] = L"raphnet technologies", // 1 : Vendor
|
[0] = L"raphnet technologies", // 1 : Vendor
|
||||||
[1] = L"GC/N64 to USB v"VERSIONSTR_SHORT, // 2: Product
|
[1] = product_string, // 2: Product
|
||||||
[2] = L"123456", // 3 : Serial
|
[2] = L"123456", // 3 : Serial
|
||||||
};
|
};
|
||||||
|
|
||||||
void usbstrings_changeProductString(const wchar_t *str)
|
void usbstrings_changeProductString_P(const char *str)
|
||||||
{
|
{
|
||||||
g_usb_strings[1] = str;
|
const char *s = str;
|
||||||
|
wchar_t *d = product_string;
|
||||||
|
uint8_t c;
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
/* Make sure target is always NUL terminated. */
|
||||||
|
n++;
|
||||||
|
if (n == PRODUCT_STRING_MAXCHARS) {
|
||||||
|
*d = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = pgm_read_byte(s);
|
||||||
|
|
||||||
|
*d = c;
|
||||||
|
s++; d++;
|
||||||
|
} while (c);
|
||||||
}
|
}
|
||||||
|
10
usbstrings.h
10
usbstrings.h
@ -1,13 +1,21 @@
|
|||||||
#ifndef _usbstrings_h__
|
#ifndef _usbstrings_h__
|
||||||
#define _usbstrings_h__
|
#define _usbstrings_h__
|
||||||
|
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
extern const wchar_t *g_usb_strings[];
|
extern const wchar_t *g_usb_strings[];
|
||||||
|
|
||||||
|
/* Sample: "Dual Gamecube to USB v3.4" (25) */
|
||||||
|
#define PRODUCT_STRING_MAXCHARS 32
|
||||||
|
|
||||||
#define NUM_USB_STRINGS 3
|
#define NUM_USB_STRINGS 3
|
||||||
|
|
||||||
/* Array indexes (i.e. zero-based0 */
|
/* Array indexes (i.e. zero-based0 */
|
||||||
#define USB_STRING_SERIAL_IDX 2
|
#define USB_STRING_SERIAL_IDX 2
|
||||||
|
|
||||||
void usbstrings_changeProductString(const wchar_t *str);
|
/**
|
||||||
|
* \param str Must be in PROGMEM
|
||||||
|
*/
|
||||||
|
void usbstrings_changeProductString_P(const char *str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user