Add new product name filter to cypress shared code

This commit is contained in:
Lorenzooone 2025-04-02 22:46:38 +02:00
parent d71db0761d
commit 7aabe62753
7 changed files with 52 additions and 17 deletions

View File

@ -50,6 +50,8 @@ struct cy_device_usb_device {
const void* full_data;
cy_get_serial_function get_serial_fn;
cy_create_device_function create_device_fn;
bool filter_for_product;
std::string wanted_product_str;
};
struct cy_device_device_handlers {

View File

@ -20,6 +20,8 @@
#define FTD2_INTRA_PACKET_HEADER_SIZE 2
#define MAX_PACKET_SIZE_FTD2 (MAX_PACKET_SIZE_USB2 - FTD2_INTRA_PACKET_HEADER_SIZE)
#define OPTIMIZE_NEW_3DS_ALTERNATIVE_PRODUCT_NAME "N3DSCC"
enum CaptureConnectionType { CAPTURE_CONN_FTD3, CAPTURE_CONN_USB, CAPTURE_CONN_FTD2, CAPTURE_CONN_IS_NITRO, CAPTURE_CONN_CYPRESS_NISETRO, CAPTURE_CONN_CYPRESS_NEW_OPTIMIZE };
enum InputVideoDataType { VIDEO_DATA_RGB, VIDEO_DATA_BGR, VIDEO_DATA_RGB16, VIDEO_DATA_BGR16 };
enum CaptureScreensType { CAPTURE_SCREENS_BOTH, CAPTURE_SCREENS_TOP, CAPTURE_SCREENS_BOTTOM, CAPTURE_SCREENS_ENUM_END };

View File

@ -333,7 +333,7 @@ static std::string cypress_driver_get_device_path(HDEVINFO DeviceInfoSet, SP_DEV
return result;
}
static bool cypress_driver_get_device_pid_vid_ids(HANDLE handle, uint16_t& out_vid, uint16_t& out_pid, UCHAR &imanufacturer, UCHAR &iserial, USHORT &bcdDevice) {
static bool cypress_driver_get_device_pid_vid_ids(HANDLE handle, uint16_t& out_vid, uint16_t& out_pid, UCHAR &imanufacturer, UCHAR &iproduct, UCHAR &iserial, USHORT &bcdDevice) {
if (handle == INVALID_HANDLE_VALUE)
return false;
USB_DEVICE_DESCRIPTOR out_descriptor;
@ -345,24 +345,27 @@ static bool cypress_driver_get_device_pid_vid_ids(HANDLE handle, uint16_t& out_v
out_vid = out_descriptor.idVendor;
out_pid = out_descriptor.idProduct;
imanufacturer = out_descriptor.iManufacturer;
iproduct = out_descriptor.iProduct;
iserial = out_descriptor.iSerialNumber;
bcdDevice = out_descriptor.bcdDevice;
return true;
}
static bool cypress_driver_get_device_pid_vid_manufacturer_serial_number(std::string path, uint16_t& out_vid, uint16_t& out_pid, std::string &manufacturer, std::string &serial, uint16_t& bcd_device) {
static bool cypress_driver_get_device_pid_vid_manufacturer_product_serial_number(std::string path, uint16_t& out_vid, uint16_t& out_pid, std::string &manufacturer, std::string &product, std::string &serial, uint16_t& bcd_device) {
HANDLE handle = CreateFile(path.c_str(), (GENERIC_READ | GENERIC_WRITE), (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, 0, NULL);
if (handle == INVALID_HANDLE_VALUE)
return false;
UCHAR imanufacturer;
UCHAR iproduct;
UCHAR iserial;
if(!cypress_driver_get_device_pid_vid_ids(handle, out_vid, out_pid, imanufacturer, iserial, bcd_device)) {
if(!cypress_driver_get_device_pid_vid_ids(handle, out_vid, out_pid, imanufacturer, iproduct, iserial, bcd_device)) {
CloseHandle(handle);
return false;
}
USHORT language = 0;
cypress_driver_get_string_language_info(handle, language);
cypress_driver_get_string_info(handle, imanufacturer, language, manufacturer);
cypress_driver_get_string_info(handle, iproduct, language, product);
cypress_driver_get_string_info(handle, iserial, language, serial);
CloseHandle(handle);
return true;
@ -460,12 +463,13 @@ void cypress_driver_list_devices(std::vector<CaptureDevice> &devices_list, bool*
uint16_t pid = 0;
uint16_t bcd_device = 0;
std::string manufacturer;
std::string product;
std::string serial;
if(!cypress_driver_get_device_pid_vid_manufacturer_serial_number(path, vid, pid, manufacturer, serial, bcd_device))
if(!cypress_driver_get_device_pid_vid_manufacturer_product_serial_number(path, vid, pid, manufacturer, product, serial, bcd_device))
continue;
for (int j = 0; j < device_descriptions.size(); j++) {
const cy_device_usb_device* usb_device_desc = device_descriptions[j];
if(not_supported_elems[j] && (usb_device_desc->vid == vid) && (usb_device_desc->pid == pid)) {
if(not_supported_elems[j] && (usb_device_desc->vid == vid) && (usb_device_desc->pid == pid) && ((!usb_device_desc->filter_for_product) || (usb_device_desc->wanted_product_str == product))) {
cy_device_device_handlers handlers;
bool result_conn_check = cypress_driver_setup_connection(&handlers, path, usb_device_desc->do_pipe_clear_reset);
cypress_driver_end_connection(&handlers);
@ -505,11 +509,12 @@ cy_device_device_handlers* cypress_driver_find_by_serial_number(const cy_device_
uint16_t pid = 0;
uint16_t bcd_device = 0;
std::string manufacturer;
std::string product;
std::string serial;
if(!cypress_driver_get_device_pid_vid_manufacturer_serial_number(path, vid, pid, manufacturer, serial, bcd_device))
if(!cypress_driver_get_device_pid_vid_manufacturer_product_serial_number(path, vid, pid, manufacturer, product, serial, bcd_device))
continue;
std::string read_serial = cypress_get_serial(usb_device_desc, serial, bcd_device, curr_serial_extra_id);
if((usb_device_desc->vid == vid) && (usb_device_desc->pid == pid) && (wanted_serial_number == read_serial)) {
if((usb_device_desc->vid == vid) && (usb_device_desc->pid == pid) && (wanted_serial_number == read_serial) && ((!usb_device_desc->filter_for_product) || (usb_device_desc->wanted_product_str == product))) {
cy_device_device_handlers handlers;
if(cypress_driver_setup_connection(&handlers, path, usb_device_desc->do_pipe_clear_reset)) {
final_handlers = new cy_device_device_handlers;
@ -637,11 +642,12 @@ void cypress_driver_find_used_serial(const cy_device_usb_device* usb_device_desc
uint16_t pid = 0;
uint16_t bcd_device = 0;
std::string manufacturer;
std::string product;
std::string serial;
if(!cypress_driver_get_device_pid_vid_manufacturer_serial_number(path, vid, pid, manufacturer, serial, bcd_device))
if(!cypress_driver_get_device_pid_vid_manufacturer_product_serial_number(path, vid, pid, manufacturer, product, serial, bcd_device))
continue;
std::string read_serial = cypress_get_serial(usb_device_desc, serial, bcd_device, curr_serial_extra_id);
if((usb_device_desc->vid == vid) && (usb_device_desc->pid == pid)) {
if((usb_device_desc->vid == vid) && (usb_device_desc->pid == pid) && ((!usb_device_desc->filter_for_product) || (usb_device_desc->wanted_product_str == product))) {
try {
int pos = std::stoi(read_serial);
if((pos < 0) || (pos >= num_free_fw_ids))

View File

@ -97,12 +97,15 @@ static bool cypress_libusb_setup_connection(libusb_device_handle* handle, const
return true;
}
static void read_strings(libusb_device_handle *handle, libusb_device_descriptor *usb_descriptor, char* manufacturer, char* serial) {
static void read_strings(libusb_device_handle *handle, libusb_device_descriptor *usb_descriptor, char* manufacturer, char* product, char* serial) {
manufacturer[0] = 0;
product[0] = 0;
serial[0] = 0;
libusb_get_string_descriptor_ascii(handle, usb_descriptor->iManufacturer, (uint8_t*)manufacturer, 0x100);
libusb_get_string_descriptor_ascii(handle, usb_descriptor->iProduct, (uint8_t*)product, 0x100);
libusb_get_string_descriptor_ascii(handle, usb_descriptor->iSerialNumber, (uint8_t*)serial, 0x100);
manufacturer[0xFF] = 0;
product[0xFF] = 0;
serial[0xFF] = 0;
}
@ -114,8 +117,14 @@ static int cypress_libusb_insert_device(std::vector<CaptureDevice> &devices_list
if((result < 0) || (handle == NULL))
return result;
char manufacturer[0x100];
char product[0x100];
char serial[0x100];
read_strings(handle, usb_descriptor, manufacturer, serial);
read_strings(handle, usb_descriptor, manufacturer, product, serial);
std::string product_str = (std::string)product;
if(usb_device_desc->filter_for_product && (usb_device_desc->wanted_product_str != product_str)) {
libusb_close(handle);
return LIBUSB_ERROR_NOT_FOUND;
}
bool claimed = false;
bool result_setup = cypress_libusb_setup_connection(handle, usb_device_desc, &claimed);
if(result_setup)
@ -145,8 +154,14 @@ cy_device_device_handlers* cypress_libusb_serial_reconnection(const cy_device_us
if((result < 0) || (handlers.usb_handle == NULL))
continue;
char manufacturer[0x100];
char product[0x100];
char serial[0x100];
read_strings(handlers.usb_handle, &usb_descriptor, manufacturer, serial);
read_strings(handlers.usb_handle, &usb_descriptor, manufacturer, product, serial);
std::string product_str = (std::string)product;
if(usb_device_desc->filter_for_product && (usb_device_desc->wanted_product_str != product_str)) {
libusb_close(handlers.usb_handle);
continue;
}
std::string device_serial_number = cypress_get_serial(usb_device_desc, (std::string)(serial), usb_descriptor.bcdDevice, curr_serial_extra_id);
bool claimed = false;
if((wanted_serial_number == device_serial_number) && (cypress_libusb_setup_connection(handlers.usb_handle, usb_device_desc, &claimed))) {
@ -193,9 +208,13 @@ void cypress_libusb_find_used_serial(const cy_device_usb_device* usb_device_desc
if(result || (handlers.usb_handle == NULL))
continue;
char manufacturer[0x100];
char product[0x100];
char serial[0x100];
read_strings(handlers.usb_handle, &usb_descriptor, manufacturer, serial);
read_strings(handlers.usb_handle, &usb_descriptor, manufacturer, product, serial);
libusb_close(handlers.usb_handle);
std::string product_str = (std::string)product;
if(usb_device_desc->filter_for_product && (usb_device_desc->wanted_product_str != product_str))
continue;
std::string device_serial_number = cypress_get_serial(usb_device_desc, (std::string)(serial), usb_descriptor.bcdDevice, curr_serial_extra_id);
try {
int pos = std::stoi(device_serial_number);

View File

@ -48,7 +48,9 @@ static const cyni_device_usb_device cypress_fx2_generic_device = {
.alt_interface = 1,
.full_data = &cypress_fx2_generic_device,
.get_serial_fn = cypress_nisetro_get_serial,
.create_device_fn = cypress_nisetro_create_device
.create_device_fn = cypress_nisetro_create_device,
.filter_for_product = false,
.wanted_product_str = ""
}
};
@ -70,7 +72,9 @@ static const cyni_device_usb_device cypress_fx2_nisetro_ds_device = {
.alt_interface = 0,
.full_data = &cypress_fx2_nisetro_ds_device,
.get_serial_fn = cypress_nisetro_get_serial,
.create_device_fn = cypress_nisetro_create_device
.create_device_fn = cypress_nisetro_create_device,
.filter_for_product = false,
.wanted_product_str = ""
}
};

View File

@ -41,7 +41,9 @@ static const cyopn_device_usb_device cypress_optimize_new_3ds_generic_device = {
.alt_interface = 1,
.full_data = &cypress_optimize_new_3ds_generic_device,
.get_serial_fn = cypress_optimize_new_3ds_get_serial,
.create_device_fn = cypress_optimize_new_3ds_create_device
.create_device_fn = cypress_optimize_new_3ds_create_device,
.filter_for_product = false,
.wanted_product_str = ""
}
};

View File

@ -139,7 +139,7 @@ static bool check_product_usable(libusb_device_handle *handle, libusb_device_des
data[PRODUCT_SIZE] = '\0';
product_str = std::string((const char*)data);
}
return product_str != "N3DSCC";
return product_str != OPTIMIZE_NEW_3DS_ALTERNATIVE_PRODUCT_NAME;
}
static int do_usb_config_device(libusb_device_handle *handle, const usb_device* usb_device_desc) {