1
0
mirror of https://github.com/raphnet/gc_n64_usb-v3 synced 2024-12-21 06:48:52 -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:
Raphael Assenat 2017-01-08 15:58:45 -05:00
parent b22985712f
commit c7e8dc7ad4
3 changed files with 43 additions and 15 deletions

23
main.c
View File

@ -55,6 +55,7 @@
#include "dataHidReport.c"
#define MAX_READ_ERRORS 30
static uint8_t error_count[MAX_PLAYERS] = { };
struct cfg0 {
struct usb_configuration_descriptor configdesc;
@ -434,12 +435,11 @@ int main(void)
{
Gamepad *pads[MAX_PLAYERS] = { };
gamepad_data pad_data;
unsigned char gamepad_vibrate = 0;
unsigned char state = STATE_WAIT_POLLTIME;
int error_count[MAX_PLAYERS] = { };
int i;
int channel;
int num_players = 1;
uint8_t gamepad_vibrate = 0;
uint8_t state = STATE_WAIT_POLLTIME;
uint8_t channel;
uint8_t num_players = 1;
uint8_t i;
hwinit();
usart1_init();
@ -451,20 +451,21 @@ int main(void)
{
default:
case CFG_MODE_STANDARD:
usbstrings_changeProductString_P(PSTR("GC/N64 to USB v"VERSIONSTR_SHORT));
break;
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;
break;
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;
break;
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;
usb_params.configdesc = (PGM_VOID_P)&cfg0_2p;
usb_params.configdesc_ttllen = sizeof(cfg0_2p);
@ -473,7 +474,7 @@ int main(void)
break;
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;
usb_params.configdesc = (PGM_VOID_P)&cfg0_2p;
usb_params.configdesc_ttllen = sizeof(cfg0_2p);
@ -482,7 +483,7 @@ int main(void)
break;
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;
usb_params.configdesc = (PGM_VOID_P)&cfg0_2p;
usb_params.configdesc_ttllen = sizeof(cfg0_2p);

View File

@ -17,13 +17,32 @@
#include <stdlib.h> // for wchar_t
#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[] = {
[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
};
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);
}

View File

@ -1,13 +1,21 @@
#ifndef _usbstrings_h__
#define _usbstrings_h__
#include <avr/pgmspace.h>
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
/* Array indexes (i.e. zero-based0 */
#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