Compare commits

..

2 commits

Author SHA1 Message Date
Lephe
c2cc3e48f2
cpg: allow overclock settings to be made permanent 2025-02-20 19:16:33 +01:00
Lephe
d858405102
usb: add WCID support to have WinUSB driver automatically
This should work on Windows Vista onwards. By specifying Windows OS 1.0
descriptors announcing compatibility with WinUSB, we get it as a driver
plug-and-play style with no manual intervention (e.g. no Zadig).

From there libusb can enumerate the device, which is awesome.
2025-02-19 20:00:49 +01:00
3 changed files with 127 additions and 2 deletions

View file

@ -157,6 +157,11 @@ void cpg_get_overclock_setting(struct cpg_overclock_setting *s);
/* Applies the specified overclock setting. */
void cpg_set_overclock_setting(struct cpg_overclock_setting const *s);
/* Sets whether or node CPG parameters are retained when world switching, i.e.
mostly whether overclock setting will remain while in the OS world and when
leaving the add-in. */
void cpg_set_overclock_permanent(bool permanent);
//---
// Sleep functions
//---

View file

@ -12,6 +12,7 @@
#include <gint/clock.h>
#include <gint/gint.h>
#include <gint/hardware.h>
#include <gint/drivers.h>
#include <gint/mpu/cpg.h>
#include <gint/mpu/bsc.h>
#include <gint/mpu/wdt.h>
@ -142,6 +143,17 @@ void cpg_set_overclock_setting(struct cpg_overclock_setting const *s)
cpu_atomic_end();
}
void cpg_set_overclock_permanent(bool permanent)
{
extern gint_driver_t drv_cpg;
int i = &drv_cpg - gint_drivers;
if(permanent)
gint_driver_flags[i] |= GINT_DRV_SHARED;
else
gint_driver_flags[i] &= ~GINT_DRV_SHARED;
}
#if GINT_HW_FX
static struct cpg_overclock_setting const settings_fx9860g_sh3[5] = {

View file

@ -33,7 +33,9 @@ static usb_dc_device_t dc_device = {
.bMaxPacketSize0 = 64,
.idVendor = htole16(0x07cf), /* Casio Computer Co., Ltd. */
.idProduct = htole16(ID_PRODUCT),
.bcdDevice = htole16(0x0100),
/* CASIO sets bcdDevice to 0x0100. Use a different value so that Windows
won't rely on cached registry entries and check for WCID support. */
.bcdDevice = htole16(0x0177),
.iManufacturer = 0,
.iProduct = 0,
.iSerialNumber = 0,
@ -55,6 +57,65 @@ static usb_dc_string_t dc_string0 = {
.data = { htole16(0x0409) }, /* English (US) */
};
struct MOS1_String_0xEE_Descriptor {
usb_dc_string_t dc;
u16 signature[7];
u8 bMS_VendorCode;
u8 bPad;
};
static struct MOS1_String_0xEE_Descriptor dc_string_ee = {
.dc = { .bLength = 18, .bDescriptorType = USB_DC_STRING },
.signature = { 0x4D00, 0x5300, 0x4600, 0x5400, 0x3100, 0x3000, 0x3000 },
.bMS_VendorCode = 0x7b, /* Arbitrarily-chosen value */
.bPad = 0,
};
struct MOS1_Extended_Compat_ID_Function_Section {
u8 bFirstInterfaceNumber;
u8 bReserved1;
u8 compatibleID[8];
u8 subcompatibleID[8];
u8 bReserved2[6];
};
struct MOS1_Extended_Compat_ID_Descriptor {
// 16 byte header
u32 dwLength;
u16 bcdVersion;
u16 wIndex;
u8 bCount;
u8 bReserved[7];
// hardcoded to size 1 for convenience here
struct MOS1_Extended_Compat_ID_Function_Section f;
};
static struct MOS1_Extended_Compat_ID_Descriptor dc_compatid = {
.dwLength = htole32(0x10 + 24 * 1),
.bcdVersion = htole16(0x0100),
.wIndex = htole16(0x0004),
.bCount = 1,
.f = {
.bFirstInterfaceNumber = 0,
.bReserved1 = 0x01,
.compatibleID = { 0x57, 0x49, 0x4e, 0x55, 0x53, 0x42, 0x00, 0x00 },
.subcompatibleID = { 0 },
.bReserved2 = { 0 },
},
};
struct MOS1_Extended_Properties_Descriptor {
// 10 byte header
u32 dwLength;
u16 bcdVersion;
u16 wIndex;
u16 wCount;
};
static struct MOS1_Extended_Properties_Descriptor dc_extprops = {
.dwLength = htole32(10),
.bcdVersion = htole16(0x0100),
.wIndex = htole16(0x0005),
.wCount = htole16(0),
};
GCONSTRUCTOR static void set_strings(void)
{
char const *serial_base =
@ -139,12 +200,40 @@ static void req_get_descriptor(int wValue, int wLength)
else if(type == USB_DC_STRING)
{
usb_dc_string_t *dc = usb_dc_string_get(num);
usb_dc_string_t *dc;
if(num == 0xee) {
dc = &dc_string_ee.dc;
USB_LOG("Selecting MOS1 string descriptor\n");
}
else
dc = usb_dc_string_get(num);
if(dc) dcp_write(dc, dc->bLength);
else USB.DCPCTR.PID = 2;
}
}
static void req_get_MOS_feature_descriptor(int wValue, int wIndex, int wLength)
{
int intf = (wValue >> 8) & 0xff;
int page = (wValue & 0xff);
USB_LOG("GET_MS_DESCRIPTOR: i%d p%d #%d len:%d\n", intf, page, wIndex, wLength);
if(wIndex == 0x0004) {
/* Extended Compat ID descriptor */
dcp_write(&dc_compatid, wLength);
USB_LOG("Compat ID descriptor given\n");
}
else if(wIndex == 0x0005) {
/* Extended Properties descriptor */
dcp_write(&dc_extprops, wLength);
USB_LOG("Extended properties descriptor given\n");
}
else {
USB_LOG("Unknown MS descriptor!\n");
}
}
static void req_get_configuration(void)
{
USB_LOG("GET_CONFIGURATION -> %d\n", 1);
@ -158,6 +247,12 @@ static void req_set_configuration(int wValue)
USB.DCPCTR.PID = (wValue == 1) ? 1 : 2;
}
static void req_get_device_status(void)
{
USB_LOG("GET_STATUS device -> 0x0001\n");
dcp_write("\x01\x00", 2);
}
void usb_req_setup(void)
{
/* Respond to setup requests */
@ -181,6 +276,19 @@ void usb_req_setup(void)
else if(bmRequestType == 0x00 && bRequest == SET_CONFIGURATION)
req_set_configuration(wValue);
else if(bmRequestType == 0x80 && bRequest == GET_STATUS)
req_get_device_status();
// 0x81 / GET_STATUS : get intf status
// 0x82 / GET_STATUS : get endpoint status
// CESG502 initial 0x01 comm
// else if(bmRequestType == 0x41 && bRequest == 0x01)
// USB.DCPCTR.PID = 1;
else if((bmRequestType == 0xc0 || bmRequestType == 0xc1)
&& bRequest == 0x7b)
req_get_MOS_feature_descriptor(wValue, wIndex, wLength);
/* TODO: Other standard SETUP requests */
else USB_LOG("SETUP: bRequest=%02x bmRequestType=%02x wValue=%04x\n"
" wIndex=%04x wLength=%d -> ???\n",