diff --git a/main.c b/main.c index f5d4634..52ed974 100644 --- a/main.c +++ b/main.c @@ -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); diff --git a/usbstrings.c b/usbstrings.c index 81cf717..bd5bde6 100644 --- a/usbstrings.c +++ b/usbstrings.c @@ -17,13 +17,32 @@ #include // 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); } diff --git a/usbstrings.h b/usbstrings.h index 693b355..90894d6 100644 --- a/usbstrings.h +++ b/usbstrings.h @@ -1,13 +1,21 @@ #ifndef _usbstrings_h__ #define _usbstrings_h__ +#include + 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