mirror of
https://github.com/Lorenzooone/cc3dsfs.git
synced 2026-09-07 08:05:16 -05:00
Base Partner CTR commit with cypress shared
This commit is contained in:
@@ -34,12 +34,13 @@ set(IS_DEVICES_SUPPORT 1)
|
||||
set(OLD_DS_3DS_LOOPY_SUPPORT 1)
|
||||
set(CYPRESS_NISETRO_SUPPORT 1)
|
||||
set(OPTIMIZE_3DS_SUPPORT 1)
|
||||
set(PARTNER_CTR_SUPPORT 1)
|
||||
|
||||
set(USE_FTD2XX_FOR_NEW_DS_LOOPY ${NEW_DS_LOOPY_SUPPORT})
|
||||
set(USE_LIBUSB_FOR_NEW_DS_LOOPY ${NEW_DS_LOOPY_SUPPORT})
|
||||
set(USE_FTD3XX_FOR_N3DSXL_LOOPY ${N3DSXL_LOOPY_SUPPORT})
|
||||
set(USE_LIBUSB_FOR_N3DSXL_LOOPY ${N3DSXL_LOOPY_SUPPORT})
|
||||
set(USE_CYPRESS_USB_SUPPORT ${CYPRESS_NISETRO_SUPPORT} OR ${OPTIMIZE_3DS_SUPPORT})
|
||||
set(USE_CYPRESS_USB_SUPPORT ${CYPRESS_NISETRO_SUPPORT} OR ${OPTIMIZE_3DS_SUPPORT} OR ${PARTNER_CTR_SUPPORT})
|
||||
set(USE_LIBUSB_SUPPORT ${IS_DEVICES_SUPPORT} OR ${OLD_DS_3DS_LOOPY_SUPPORT} OR ${USE_LIBUSB_FOR_NEW_DS_LOOPY} OR ${USE_LIBUSB_FOR_N3DSXL_LOOPY} OR ${USE_CYPRESS_USB_SUPPORT})
|
||||
if(NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Windows"))
|
||||
#Performance outside of Windows is very bad for the official drivers...
|
||||
@@ -337,6 +338,7 @@ set(SOURCE_CPP_FTD3_FILES_BASE_PATH "${SOURCE_CPP_DEVICE_FILES_BASE_PATH}/3DSCap
|
||||
set(SOURCE_CPP_CYPRESS_USB_FILES_BASE_PATH "${SOURCE_CPP_DEVICE_FILES_BASE_PATH}/CypressShared")
|
||||
set(SOURCE_CPP_CYPRESS_NISETRO_DEVICES_FILES_BASE_PATH "${SOURCE_CPP_DEVICE_FILES_BASE_PATH}/Nisetro")
|
||||
set(SOURCE_CPP_CYPRESS_OPTIMIZE_3DS_FILES_BASE_PATH "${SOURCE_CPP_DEVICE_FILES_BASE_PATH}/Optimize_3DS")
|
||||
set(SOURCE_CPP_PARTNER_CTR_FILES_BASE_PATH "${SOURCE_CPP_DEVICE_FILES_BASE_PATH}/Partner_CTR")
|
||||
if(N3DSXL_LOOPY_SUPPORT)
|
||||
list(APPEND SOURCE_CPP_EXTRA_FILES ${SOURCE_CPP_FTD3_FILES_BASE_PATH}/3dscapture_ftd3_shared.cpp ${SOURCE_CPP_FTD3_FILES_BASE_PATH}/3dscapture_ftd3_compatibility.cpp)
|
||||
add_compile_flag("USE_FTD3")
|
||||
@@ -375,6 +377,10 @@ if(OPTIMIZE_3DS_SUPPORT)
|
||||
list(APPEND SOURCE_CPP_EXTRA_FILES ${SOURCE_CPP_CYPRESS_OPTIMIZE_3DS_FILES_BASE_PATH}/cypress_optimize_3ds_communications.cpp ${SOURCE_CPP_CYPRESS_OPTIMIZE_3DS_FILES_BASE_PATH}/cypress_optimize_3ds_acquisition.cpp ${TOOLS_DATA_DIR}/optimize_new_3ds_fw.cpp ${TOOLS_DATA_DIR}/optimize_new_3ds_565_fpga_pl.cpp ${TOOLS_DATA_DIR}/optimize_new_3ds_888_fpga_pl.cpp ${TOOLS_DATA_DIR}/optimize_old_3ds_fw.cpp ${TOOLS_DATA_DIR}/optimize_old_3ds_565_fpga_pl.cpp ${TOOLS_DATA_DIR}/optimize_old_3ds_888_fpga_pl.cpp ${TOOLS_DATA_DIR}/adler_crc32_table_sp.cpp ${TOOLS_DATA_DIR}/optimize_serial_key_to_byte_table.cpp)
|
||||
add_compile_flag("USE_CYPRESS_OPTIMIZE")
|
||||
endif()
|
||||
if(PARTNER_CTR_SUPPORT)
|
||||
list(APPEND SOURCE_CPP_EXTRA_FILES ${SOURCE_CPP_PARTNER_CTR_FILES_BASE_PATH}/cypress_partner_ctr_communications.cpp ${SOURCE_CPP_PARTNER_CTR_FILES_BASE_PATH}/cypress_partner_ctr_acquisition.cpp)
|
||||
add_compile_flag("USE_PARTNER_CTR")
|
||||
endif()
|
||||
if(NEW_DS_LOOPY_SUPPORT)
|
||||
list(APPEND SOURCE_CPP_EXTRA_FILES ${SOURCE_CPP_FTD2_FILES_BASE_PATH}/dscapture_ftd2_shared.cpp ${SOURCE_CPP_FTD2_FILES_BASE_PATH}/dscapture_ftd2_compatibility.cpp ${TOOLS_DATA_DIR}/ftd2_ds2_fw_1.cpp ${TOOLS_DATA_DIR}/ftd2_ds2_fw_2.cpp)
|
||||
add_compile_flag("USE_FTD2")
|
||||
@@ -551,7 +557,7 @@ endif()
|
||||
if(USE_FTD2XX_FOR_NEW_DS_LOOPY)
|
||||
target_link_libraries(${OUTPUT_NAME} PRIVATE ${ftd2xx_BINARY_DIR}/${FTD2XX_SUBFOLDER}/${FTD2XX_LIB})
|
||||
endif()
|
||||
target_include_directories(${OUTPUT_NAME} PRIVATE ${EXTRA_INCLUDE_DIRECTORIES} ${TOOLS_DATA_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include/Menus ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/ISDevices ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/Nisetro ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/Optimize_3DS ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/CypressShared ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/3DSCapture_FTD3 ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/DSCapture_FTD2)
|
||||
target_include_directories(${OUTPUT_NAME} PRIVATE ${EXTRA_INCLUDE_DIRECTORIES} ${TOOLS_DATA_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include/Menus ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/ISDevices ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/Nisetro ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/Optimize_3DS ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/CypressShared ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/3DSCapture_FTD3 ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/DSCapture_FTD2 ${CMAKE_SOURCE_DIR}/include/CaptureDeviceSpecific/Partner_CTR)
|
||||
target_compile_features(${OUTPUT_NAME} PRIVATE cxx_std_20)
|
||||
target_compile_options(${OUTPUT_NAME} PRIVATE ${EXTRA_CXX_FLAGS})
|
||||
|
||||
|
||||
@@ -10,9 +10,18 @@
|
||||
|
||||
typedef void (*cy_async_callback_function)(void* user_data, int transfer_length, int transfer_status);
|
||||
typedef void (*cy_error_function)(void* user_data, int error);
|
||||
typedef std::string (*cy_get_serial_function)(const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id);
|
||||
typedef CaptureDevice (*cy_create_device_function)(const void* usb_device_desc, std::string serial, std::string path);
|
||||
|
||||
struct cy_device_device_handlers {
|
||||
libusb_device_handle* usb_handle;
|
||||
void* read_handle;
|
||||
void* write_handle;
|
||||
void* mutex;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
typedef std::string (*cy_get_serial_function)(cy_device_device_handlers* handlers, const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id);
|
||||
|
||||
struct cy_async_callback_data {
|
||||
cy_async_callback_function function;
|
||||
cy_error_function error_function;
|
||||
@@ -48,34 +57,27 @@ struct cy_device_usb_device {
|
||||
bool do_pipe_clear_reset;
|
||||
int alt_interface;
|
||||
const void* full_data;
|
||||
bool get_serial_requires_setup;
|
||||
cy_get_serial_function get_serial_fn;
|
||||
cy_create_device_function create_device_fn;
|
||||
uint16_t bcd_device_mask;
|
||||
uint16_t bcd_device_wanted_value;
|
||||
};
|
||||
|
||||
struct cy_device_device_handlers {
|
||||
libusb_device_handle* usb_handle;
|
||||
void* read_handle;
|
||||
void* write_handle;
|
||||
void* mutex;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
// Helper methods
|
||||
CaptureDevice cypress_create_device(const cy_device_usb_device* usb_device_desc, std::string serial, std::string path = "");
|
||||
std::string cypress_get_serial(const cy_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id);
|
||||
void cypress_insert_device(std::vector<CaptureDevice>& devices_list, const cy_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id, std::string path = "");
|
||||
std::string cypress_get_serial(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id);
|
||||
void cypress_insert_device(std::vector<CaptureDevice>& devices_list, const cy_device_usb_device* usb_device_desc, std::string real_serial, std::string path = "");
|
||||
|
||||
int cypress_ctrl_in_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, uint8_t request, uint16_t value, uint16_t index, int* transferred);
|
||||
int cypress_ctrl_out_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, uint8_t request, uint16_t value, uint16_t index, int* transferred);
|
||||
int cypress_bulk_in_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred);
|
||||
int cypress_bulk_in_async(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t *buf, int length, cy_async_callback_data* cb_data);
|
||||
int cypress_ctrl_bulk_in_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred);
|
||||
int cypress_ctrl_bulk_out_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, const uint8_t* buf, int length, int* transferred);
|
||||
int cypress_ctrl_bulk_in_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred, int chosen_endpoint = -1);
|
||||
int cypress_ctrl_bulk_out_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, const uint8_t* buf, int length, int* transferred, int chosen_endpoint = -1);
|
||||
void cypress_pipe_reset_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc);
|
||||
void cypress_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc);
|
||||
void cypress_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc);
|
||||
void cypress_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint = -1);
|
||||
void cypress_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint = -1);
|
||||
void CypressSetMaxTransferSize(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, size_t new_max_transfer_size);
|
||||
void CypressCloseAsyncRead(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, cy_async_callback_data* cb_data);
|
||||
void CypressSetupCypressDeviceAsyncThread(cy_device_device_handlers* handlers, std::vector<cy_async_callback_data*> &cb_data_vector, std::thread* thread_ptr, bool* keep_going);
|
||||
|
||||
@@ -16,11 +16,11 @@ void cypress_driver_end_connection(cy_device_device_handlers* handlers);
|
||||
int cypress_driver_ctrl_transfer_in(cy_device_device_handlers* handlers, uint8_t* buffer, size_t inner_size, uint16_t value, uint16_t index, uint16_t request_code, int* num_read);
|
||||
int cypress_driver_ctrl_transfer_out(cy_device_device_handlers* handlers, uint8_t* buffer, size_t inner_size, uint16_t value, uint16_t index, uint16_t request_code, int* num_read);
|
||||
int cypress_driver_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred);
|
||||
int cypress_driver_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred);
|
||||
int cypress_driver_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred);
|
||||
int cypress_driver_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred, int chosen_endpoint = -1);
|
||||
int cypress_driver_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred, int chosen_endpoint = -1);
|
||||
void cypress_driver_pipe_reset_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc);
|
||||
void cypress_driver_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc);
|
||||
void cypress_driver_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc);
|
||||
void cypress_driver_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint = -1);
|
||||
void cypress_driver_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint = -1);
|
||||
int cypress_driver_async_in_start(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, cy_async_callback_data* cb_data);
|
||||
void cypress_driver_start_thread(std::thread* thread_ptr, bool* usb_thread_run, std::vector<cy_async_callback_data*> &cb_data_vector, cy_device_device_handlers* handlers);
|
||||
void cypress_driver_close_thread(std::thread* thread_ptr, bool* usb_thread_run, std::vector<cy_async_callback_data*> cb_data_vector);
|
||||
|
||||
@@ -10,11 +10,11 @@ cy_device_device_handlers* cypress_libusb_serial_reconnection(const cy_device_us
|
||||
void cypress_libusb_find_used_serial(const cy_device_usb_device* usb_device_desc, bool* found, size_t num_free_fw_ids, int &curr_serial_extra_id);
|
||||
void cypress_libusb_end_connection(cy_device_device_handlers* handlers, const cy_device_usb_device* device_desc, bool interface_claimed);
|
||||
int cypress_libusb_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred);
|
||||
int cypress_libusb_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred);
|
||||
int cypress_libusb_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred);
|
||||
int cypress_libusb_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred, int chosen_endpoint = -1);
|
||||
int cypress_libusb_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred, int chosen_endpoint = -1);
|
||||
void cypress_libusb_pipe_reset_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc);
|
||||
void cypress_libusb_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc);
|
||||
void cypress_libusb_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc);
|
||||
void cypress_libusb_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint = -1);
|
||||
void cypress_libusb_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint = -1);
|
||||
int cypress_libusb_ctrl_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, uint8_t request, uint16_t value, uint16_t index, int* transferred);
|
||||
int cypress_libusb_ctrl_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, uint8_t request, uint16_t value, uint16_t index, int* transferred);
|
||||
int cypress_libusb_async_in_start(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, cy_async_callback_data* cb_data);
|
||||
|
||||
@@ -100,7 +100,7 @@ int StopUsbCaptureDma(is_device_device_handlers* handlers, const is_device_usb_d
|
||||
int SetForwardFrameCount(is_device_device_handlers* handlers, uint16_t count, const is_device_usb_device* device_desc);
|
||||
int SetForwardFramePermanent(is_device_device_handlers* handlers, const is_device_usb_device* device_desc);
|
||||
int GetFrameCounter(is_device_device_handlers* handlers, uint16_t* out, const is_device_usb_device* device_desc);
|
||||
int GetDeviceSerial(is_device_device_handlers* handlers, uint8_t* buf, const is_device_usb_device* device_desc);
|
||||
int GetIsDeviceSerial(is_device_device_handlers* handlers, uint8_t* buf, const is_device_usb_device* device_desc);
|
||||
int UpdateFrameForwardConfig(is_device_device_handlers* handlers, is_device_forward_config_values_colors colors, is_device_forward_config_values_screens screens, is_device_forward_config_values_rate rate, const is_device_usb_device* device_desc);
|
||||
int UpdateFrameForwardEnable(is_device_device_handlers* handlers, bool enable, bool restart, const is_device_usb_device* device_desc);
|
||||
int ReadLidState(is_device_device_handlers* handlers, bool* out, const is_device_usb_device* device_desc);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "cypress_shared_communications.hpp"
|
||||
#include "cypress_nisetro_communications.hpp"
|
||||
|
||||
std::string cypress_nisetro_get_serial(const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id);
|
||||
std::string cypress_nisetro_get_serial(cy_device_device_handlers* handlers, const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id);
|
||||
CaptureDevice cypress_nisetro_create_device(const void* usb_device_desc, std::string serial, std::string path);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "cypress_shared_communications.hpp"
|
||||
#include "cypress_optimize_3ds_communications.hpp"
|
||||
|
||||
std::string cypress_optimize_3ds_get_serial(const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id);
|
||||
std::string cypress_optimize_3ds_get_serial(cy_device_device_handlers* handlers, const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id);
|
||||
CaptureDevice cypress_optimize_3ds_create_device(const void* usb_device_desc, std::string serial, std::string path);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef __CYPRESS_PARTNER_CTR_ACQUISITION_HPP
|
||||
#define __CYPRESS_PARTNER_CTR_ACQUISITION_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "utils.hpp"
|
||||
#include "hw_defs.hpp"
|
||||
#include "capture_structs.hpp"
|
||||
#include "display_structs.hpp"
|
||||
#include "devicecapture.hpp"
|
||||
|
||||
void list_devices_cypart_device(std::vector<CaptureDevice> &devices_list, std::vector<no_access_recap_data> &no_access_list, bool* devices_allowed_scan);
|
||||
bool cypart_device_connect_usb(bool print_failed, CaptureData* capture_data, CaptureDevice* device);
|
||||
uint64_t cypart_device_get_video_in_size(CaptureStatus* status);
|
||||
uint64_t cypart_device_get_video_in_size(CaptureData* capture_data);
|
||||
void cypart_device_acquisition_main_loop(CaptureData* capture_data);
|
||||
void usb_cypart_device_acquisition_cleanup(CaptureData* capture_data);
|
||||
void usb_cypart_device_init();
|
||||
void usb_cypart_device_close();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef __CYPRESS_PARTNER_CTR_ACQUISITION_GENERAL_HPP
|
||||
#define __CYPRESS_PARTNER_CTR_ACQUISITION_GENERAL_HPP
|
||||
|
||||
#include "cypress_shared_communications.hpp"
|
||||
#include "cypress_partner_ctr_communications.hpp"
|
||||
|
||||
std::string cypress_partner_ctr_get_serial(cy_device_device_handlers* handlers, const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id);
|
||||
CaptureDevice cypress_partner_ctr_create_device(const void* usb_device_desc, std::string serial, std::string path);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef __CYPRESS_PARTNER_CTR_DEVICE_COMMUNICATIONS_HPP
|
||||
#define __CYPRESS_PARTNER_CTR_DEVICE_COMMUNICATIONS_HPP
|
||||
|
||||
#include <libusb.h>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
#include "utils.hpp"
|
||||
#include "capture_structs.hpp"
|
||||
#include "cypress_shared_communications.hpp"
|
||||
|
||||
struct cypart_device_usb_device {
|
||||
std::string name;
|
||||
std::string long_name;
|
||||
InputVideoDataType video_data_type;
|
||||
PossibleCaptureDevices index_in_allowed_scan;
|
||||
int ep_ctrl_serial_io_pipe;
|
||||
cy_device_usb_device usb_device_info;
|
||||
};
|
||||
|
||||
int GetNumCyPartnerCTRDeviceDesc(void);
|
||||
const cypart_device_usb_device* GetCyPartnerCTRDeviceDesc(int index);
|
||||
const cy_device_usb_device* get_cy_usb_info(const cypart_device_usb_device* usb_device_desc);
|
||||
std::string read_serial_ctr_capture(cy_device_device_handlers* handlers, const cypart_device_usb_device* device);
|
||||
int capture_start(cy_device_device_handlers* handlers, const cypart_device_usb_device* device);
|
||||
int StartCaptureDma(cy_device_device_handlers* handlers, const cypart_device_usb_device* device);
|
||||
int capture_end(cy_device_device_handlers* handlers, const cypart_device_usb_device* device);
|
||||
int ReadFrame(cy_device_device_handlers* handlers, uint8_t* buf, int length, const cypart_device_usb_device* device_desc);
|
||||
int ReadFrameAsync(cy_device_device_handlers* handlers, uint8_t* buf, int length, const cypart_device_usb_device* device_desc, cy_async_callback_data* cb_data);
|
||||
|
||||
#endif
|
||||
@@ -14,12 +14,12 @@ CaptureDevice cypress_create_device(const cy_device_usb_device* usb_device_desc,
|
||||
return usb_device_desc->create_device_fn(usb_device_desc->full_data, serial, path);
|
||||
}
|
||||
|
||||
std::string cypress_get_serial(const cy_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) {
|
||||
return usb_device_desc->get_serial_fn(usb_device_desc->full_data, serial, bcd_device, curr_serial_extra_id);
|
||||
std::string cypress_get_serial(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) {
|
||||
return usb_device_desc->get_serial_fn(handlers, usb_device_desc->full_data, serial, bcd_device, curr_serial_extra_id);
|
||||
}
|
||||
|
||||
void cypress_insert_device(std::vector<CaptureDevice>& devices_list, const cy_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id, std::string path) {
|
||||
devices_list.push_back(cypress_create_device(usb_device_desc, cypress_get_serial(usb_device_desc, serial, bcd_device, curr_serial_extra_id), path));
|
||||
void cypress_insert_device(std::vector<CaptureDevice>& devices_list, const cy_device_usb_device* usb_device_desc, std::string real_serial, std::string path) {
|
||||
devices_list.push_back(cypress_create_device(usb_device_desc, real_serial, path));
|
||||
}
|
||||
|
||||
int cypress_ctrl_in_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, uint8_t request, uint16_t value, uint16_t index, int* transferred) {
|
||||
@@ -46,16 +46,16 @@ int cypress_bulk_in_async(cy_device_device_handlers* handlers, const cy_device_u
|
||||
return cypress_driver_async_in_start(handlers, usb_device_desc, buf, length, cb_data);
|
||||
}
|
||||
|
||||
int cypress_ctrl_bulk_in_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) {
|
||||
int cypress_ctrl_bulk_in_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred, int chosen_endpoint) {
|
||||
if(handlers->usb_handle)
|
||||
return cypress_libusb_ctrl_bulk_in(handlers, usb_device_desc, buf, length, transferred);
|
||||
return cypress_driver_ctrl_bulk_in(handlers, usb_device_desc, buf, length, transferred);
|
||||
return cypress_libusb_ctrl_bulk_in(handlers, usb_device_desc, buf, length, transferred, chosen_endpoint);
|
||||
return cypress_driver_ctrl_bulk_in(handlers, usb_device_desc, buf, length, transferred, chosen_endpoint);
|
||||
}
|
||||
|
||||
int cypress_ctrl_bulk_out_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, const uint8_t* buf, int length, int* transferred) {
|
||||
int cypress_ctrl_bulk_out_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, const uint8_t* buf, int length, int* transferred, int chosen_endpoint) {
|
||||
if(handlers->usb_handle)
|
||||
return cypress_libusb_ctrl_bulk_out(handlers, usb_device_desc, (uint8_t*)buf, length, transferred);
|
||||
return cypress_driver_ctrl_bulk_out(handlers, usb_device_desc, (uint8_t*)buf, length, transferred);
|
||||
return cypress_libusb_ctrl_bulk_out(handlers, usb_device_desc, (uint8_t*)buf, length, transferred, chosen_endpoint);
|
||||
return cypress_driver_ctrl_bulk_out(handlers, usb_device_desc, (uint8_t*)buf, length, transferred, chosen_endpoint);
|
||||
}
|
||||
|
||||
void cypress_pipe_reset_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) {
|
||||
@@ -64,16 +64,16 @@ void cypress_pipe_reset_bulk_in(cy_device_device_handlers* handlers, const cy_de
|
||||
return cypress_driver_pipe_reset_bulk_in(handlers, usb_device_desc);
|
||||
}
|
||||
|
||||
void cypress_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) {
|
||||
void cypress_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint) {
|
||||
if(handlers->usb_handle)
|
||||
return cypress_libusb_pipe_reset_ctrl_bulk_in(handlers, usb_device_desc);
|
||||
return cypress_driver_pipe_reset_ctrl_bulk_in(handlers, usb_device_desc);
|
||||
return cypress_libusb_pipe_reset_ctrl_bulk_in(handlers, usb_device_desc, chosen_endpoint);
|
||||
return cypress_driver_pipe_reset_ctrl_bulk_in(handlers, usb_device_desc, chosen_endpoint);
|
||||
}
|
||||
|
||||
void cypress_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) {
|
||||
void cypress_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint) {
|
||||
if(handlers->usb_handle)
|
||||
return cypress_libusb_pipe_reset_ctrl_bulk_out(handlers, usb_device_desc);
|
||||
return cypress_driver_pipe_reset_ctrl_bulk_out(handlers, usb_device_desc);
|
||||
return cypress_libusb_pipe_reset_ctrl_bulk_out(handlers, usb_device_desc, chosen_endpoint);
|
||||
return cypress_driver_pipe_reset_ctrl_bulk_out(handlers, usb_device_desc, chosen_endpoint);
|
||||
}
|
||||
|
||||
void CypressSetMaxTransferSize(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, size_t new_max_transfer_size) {
|
||||
|
||||
@@ -593,31 +593,37 @@ int cypress_driver_bulk_in(cy_device_device_handlers* handlers, const cy_device_
|
||||
return result;
|
||||
}
|
||||
|
||||
int cypress_driver_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) {
|
||||
int cypress_driver_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred, int chosen_endpoint) {
|
||||
if(chosen_endpoint == -1)
|
||||
chosen_endpoint = usb_device_desc->ep_ctrl_bulk_in;
|
||||
int result = LIBUSB_SUCCESS;
|
||||
#ifdef _WIN32
|
||||
DWORD inner_transfered = 0;
|
||||
if(!cypress_driver_bulk_sync_start(handlers->read_handle, buf, length, &inner_transfered, usb_device_desc->ep_ctrl_bulk_in))
|
||||
if(!cypress_driver_bulk_sync_start(handlers->read_handle, buf, length, &inner_transfered, chosen_endpoint))
|
||||
result = -1;
|
||||
*transferred = inner_transfered;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
int cypress_driver_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) {
|
||||
int cypress_driver_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred, int chosen_endpoint) {
|
||||
if(chosen_endpoint == -1)
|
||||
chosen_endpoint = usb_device_desc->ep_ctrl_bulk_out;
|
||||
int result = LIBUSB_SUCCESS;
|
||||
#ifdef _WIN32
|
||||
DWORD inner_transfered = 0;
|
||||
if(!cypress_driver_bulk_sync_start(handlers->write_handle, buf, length, &inner_transfered, usb_device_desc->ep_ctrl_bulk_out))
|
||||
if(!cypress_driver_bulk_sync_start(handlers->write_handle, buf, length, &inner_transfered, chosen_endpoint))
|
||||
result = -1;
|
||||
*transferred = inner_transfered;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
void cypress_driver_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) {
|
||||
void cypress_driver_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint) {
|
||||
if(chosen_endpoint == -1)
|
||||
chosen_endpoint = usb_device_desc->ep_ctrl_bulk_in;
|
||||
#ifdef _WIN32
|
||||
cypress_driver_pipe_reset(handlers->read_handle, usb_device_desc->ep_ctrl_bulk_in);
|
||||
cypress_driver_pipe_reset(handlers->read_handle, chosen_endpoint);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -627,9 +633,11 @@ void cypress_driver_pipe_reset_bulk_in(cy_device_device_handlers* handlers, cons
|
||||
#endif
|
||||
}
|
||||
|
||||
void cypress_driver_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) {
|
||||
void cypress_driver_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint) {
|
||||
if(chosen_endpoint == -1)
|
||||
chosen_endpoint = usb_device_desc->ep_ctrl_bulk_out;
|
||||
#ifdef _WIN32
|
||||
cypress_driver_pipe_reset(handlers->read_handle, usb_device_desc->ep_ctrl_bulk_out);
|
||||
cypress_driver_pipe_reset(handlers->read_handle, chosen_endpoint);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -26,25 +26,33 @@ int cypress_libusb_bulk_in(cy_device_device_handlers* handlers, const cy_device_
|
||||
}
|
||||
|
||||
// Read from ctrl bulk
|
||||
int cypress_libusb_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) {
|
||||
return libusb_bulk_transfer(handlers->usb_handle, usb_device_desc->ep_ctrl_bulk_in, buf, length, transferred, usb_device_desc->bulk_timeout);
|
||||
int cypress_libusb_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred, int chosen_endpoint) {
|
||||
if(chosen_endpoint == -1)
|
||||
chosen_endpoint = usb_device_desc->ep_ctrl_bulk_in;
|
||||
return libusb_bulk_transfer(handlers->usb_handle, chosen_endpoint, buf, length, transferred, usb_device_desc->bulk_timeout);
|
||||
}
|
||||
|
||||
// Write to ctrl bulk
|
||||
int cypress_libusb_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) {
|
||||
return libusb_bulk_transfer(handlers->usb_handle, usb_device_desc->ep_ctrl_bulk_out, buf, length, transferred, usb_device_desc->bulk_timeout);
|
||||
int cypress_libusb_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred, int chosen_endpoint) {
|
||||
if(chosen_endpoint == -1)
|
||||
chosen_endpoint = usb_device_desc->ep_ctrl_bulk_out;
|
||||
return libusb_bulk_transfer(handlers->usb_handle, chosen_endpoint, buf, length, transferred, usb_device_desc->bulk_timeout);
|
||||
}
|
||||
|
||||
void cypress_libusb_pipe_reset_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) {
|
||||
libusb_clear_halt(handlers->usb_handle, usb_device_desc->ep_bulk_in);
|
||||
}
|
||||
|
||||
void cypress_libusb_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) {
|
||||
libusb_clear_halt(handlers->usb_handle, usb_device_desc->ep_ctrl_bulk_in);
|
||||
void cypress_libusb_pipe_reset_ctrl_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint) {
|
||||
if(chosen_endpoint == -1)
|
||||
chosen_endpoint = usb_device_desc->ep_ctrl_bulk_in;
|
||||
libusb_clear_halt(handlers->usb_handle, chosen_endpoint);
|
||||
}
|
||||
|
||||
void cypress_libusb_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) {
|
||||
libusb_clear_halt(handlers->usb_handle, usb_device_desc->ep_ctrl_bulk_out);
|
||||
void cypress_libusb_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, int chosen_endpoint) {
|
||||
if(chosen_endpoint == -1)
|
||||
chosen_endpoint = usb_device_desc->ep_ctrl_bulk_out;
|
||||
libusb_clear_halt(handlers->usb_handle, chosen_endpoint);
|
||||
}
|
||||
|
||||
void cypress_libusb_cancell_callback(cy_async_callback_data* cb_data) {
|
||||
@@ -78,7 +86,13 @@ int cypress_libusb_async_in_start(cy_device_device_handlers* handlers, const cy_
|
||||
return retval;
|
||||
}
|
||||
|
||||
static bool cypress_libusb_setup_connection(libusb_device_handle* handle, const cy_device_usb_device* usb_device_desc, bool *claimed) {
|
||||
static bool cypress_libusb_setup_connection(libusb_device_handle* handle, const cy_device_usb_device* usb_device_desc, bool *claimed, bool &executed_setup) {
|
||||
static bool last_result = false;
|
||||
if(executed_setup)
|
||||
return last_result;
|
||||
|
||||
last_result = false;
|
||||
executed_setup = true;
|
||||
*claimed = false;
|
||||
libusb_check_and_detach_kernel_driver(handle, usb_device_desc->default_interface);
|
||||
int result = libusb_check_and_set_configuration(handle, usb_device_desc->default_config);
|
||||
@@ -94,6 +108,7 @@ static bool cypress_libusb_setup_connection(libusb_device_handle* handle, const
|
||||
if(result != LIBUSB_SUCCESS)
|
||||
return false;
|
||||
}
|
||||
last_result = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -106,6 +121,18 @@ static void read_strings(libusb_device_handle *handle, libusb_device_descriptor
|
||||
serial[0xFF] = 0;
|
||||
}
|
||||
|
||||
static std::string read_real_serial(libusb_device_handle *handle, libusb_device_descriptor *usb_descriptor, const cy_device_usb_device* usb_device_desc, char* serial, int &curr_serial_extra_id, bool *claimed, bool &executed_setup) {
|
||||
if(handle == NULL)
|
||||
return "";
|
||||
|
||||
if(usb_device_desc->get_serial_requires_setup && (!cypress_libusb_setup_connection(handle, usb_device_desc, claimed, executed_setup)))
|
||||
return "";
|
||||
|
||||
cy_device_device_handlers handlers;
|
||||
handlers.usb_handle = handle;
|
||||
return cypress_get_serial(&handlers, usb_device_desc, (std::string)(serial), usb_descriptor->bcdDevice, curr_serial_extra_id);
|
||||
}
|
||||
|
||||
static int cypress_libusb_insert_device(std::vector<CaptureDevice> &devices_list, const cy_device_usb_device* usb_device_desc, libusb_device *usb_device, libusb_device_descriptor *usb_descriptor, int &curr_serial_extra_id) {
|
||||
libusb_device_handle *handle = NULL;
|
||||
if((usb_descriptor->idVendor != usb_device_desc->vid) || (usb_descriptor->idProduct != usb_device_desc->pid))
|
||||
@@ -120,9 +147,12 @@ static int cypress_libusb_insert_device(std::vector<CaptureDevice> &devices_list
|
||||
char serial[0x100];
|
||||
read_strings(handle, usb_descriptor, manufacturer, serial);
|
||||
bool claimed = false;
|
||||
bool result_setup = cypress_libusb_setup_connection(handle, usb_device_desc, &claimed);
|
||||
if(result_setup)
|
||||
cypress_insert_device(devices_list, usb_device_desc, (std::string)(serial), usb_descriptor->bcdDevice, curr_serial_extra_id);
|
||||
bool executed_setup = false;
|
||||
bool result_setup = cypress_libusb_setup_connection(handle, usb_device_desc, &claimed, executed_setup);
|
||||
if(result_setup) {
|
||||
std::string device_serial_number = read_real_serial(handle, usb_descriptor, usb_device_desc, serial, curr_serial_extra_id, &claimed, executed_setup);
|
||||
cypress_insert_device(devices_list, usb_device_desc, device_serial_number);
|
||||
}
|
||||
if(claimed)
|
||||
libusb_release_interface(handle, usb_device_desc->default_interface);
|
||||
libusb_close(handle);
|
||||
@@ -169,9 +199,10 @@ cy_device_device_handlers* cypress_libusb_serial_reconnection(const cy_device_us
|
||||
char manufacturer[0x100];
|
||||
char serial[0x100];
|
||||
read_strings(handlers.usb_handle, &usb_descriptor, manufacturer, serial);
|
||||
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))) {
|
||||
bool executed_setup = false;
|
||||
std::string device_serial_number = read_real_serial(handlers.usb_handle, &usb_descriptor, usb_device_desc, serial, curr_serial_extra_id, &claimed, executed_setup);
|
||||
if((wanted_serial_number == device_serial_number) && (cypress_libusb_setup_connection(handlers.usb_handle, usb_device_desc, &claimed, executed_setup))) {
|
||||
final_handlers = new cy_device_device_handlers;
|
||||
final_handlers->usb_handle = handlers.usb_handle;
|
||||
if(new_device != NULL)
|
||||
@@ -230,7 +261,10 @@ void cypress_libusb_find_used_serial(const cy_device_usb_device* usb_device_desc
|
||||
char serial[0x100];
|
||||
read_strings(handlers.usb_handle, &usb_descriptor, manufacturer, serial);
|
||||
libusb_close(handlers.usb_handle);
|
||||
std::string device_serial_number = cypress_get_serial(usb_device_desc, (std::string)(serial), usb_descriptor.bcdDevice, curr_serial_extra_id);
|
||||
// This is only called when we can set this stuff ourselves...
|
||||
// For now, do not update it with the setup part, as there is no
|
||||
// case in which it would be used for it...
|
||||
std::string device_serial_number = cypress_get_serial(NULL, usb_device_desc, (std::string)(serial), usb_descriptor.bcdDevice, curr_serial_extra_id);
|
||||
try {
|
||||
int pos = std::stoi(device_serial_number);
|
||||
if((pos < 0) || (pos >= ((int)num_free_fw_ids)))
|
||||
|
||||
@@ -58,7 +58,7 @@ std::string get_serial(const is_device_usb_device* usb_device_desc, is_device_de
|
||||
bool conn_success = true;
|
||||
if(initial_cleanup(usb_device_desc, handlers))
|
||||
conn_success = false;
|
||||
if(conn_success && (GetDeviceSerial(handlers, data, usb_device_desc) != LIBUSB_SUCCESS))
|
||||
if(conn_success && (GetIsDeviceSerial(handlers, data, usb_device_desc) != LIBUSB_SUCCESS))
|
||||
conn_success = false;
|
||||
if(conn_success) {
|
||||
data[IS_DEVICE_REAL_SERIAL_NUMBER_SIZE] = '\0';
|
||||
|
||||
@@ -750,7 +750,7 @@ static int AuthCtrlIn(is_device_device_handlers* handlers, const is_device_usb_d
|
||||
}
|
||||
}
|
||||
|
||||
int GetDeviceSerial(is_device_device_handlers* handlers, uint8_t* buf, const is_device_usb_device* device_desc) {
|
||||
int GetIsDeviceSerial(is_device_device_handlers* handlers, uint8_t* buf, const is_device_usb_device* device_desc) {
|
||||
int ret = 0;
|
||||
uint32_t value = 0;
|
||||
switch(device_desc->device_type) {
|
||||
|
||||
@@ -99,7 +99,7 @@ static std::string _cypress_nisetro_get_serial(const cyni_device_usb_device* usb
|
||||
return std::to_string((curr_serial_extra_id++) + 1);
|
||||
}
|
||||
|
||||
std::string cypress_nisetro_get_serial(const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) {
|
||||
std::string cypress_nisetro_get_serial(cy_device_device_handlers* handlers, const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) {
|
||||
if(usb_device_desc == NULL)
|
||||
return "";
|
||||
const cyni_device_usb_device* in_usb_device_desc = (const cyni_device_usb_device*)usb_device_desc;
|
||||
|
||||
@@ -50,6 +50,7 @@ static const cyni_device_usb_device cypress_fx2_generic_device = {
|
||||
.do_pipe_clear_reset = false,
|
||||
.alt_interface = 1,
|
||||
.full_data = &cypress_fx2_generic_device,
|
||||
.get_serial_requires_setup = false,
|
||||
.get_serial_fn = cypress_nisetro_get_serial,
|
||||
.create_device_fn = cypress_nisetro_create_device,
|
||||
.bcd_device_mask = 0x0000,
|
||||
@@ -75,6 +76,7 @@ static const cyni_device_usb_device cypress_fx2_nisetro_ds_device = {
|
||||
.do_pipe_clear_reset = true,
|
||||
.alt_interface = 0,
|
||||
.full_data = &cypress_fx2_nisetro_ds_device,
|
||||
.get_serial_requires_setup = false,
|
||||
.get_serial_fn = cypress_nisetro_get_serial,
|
||||
.create_device_fn = cypress_nisetro_create_device,
|
||||
.bcd_device_mask = 0xFF00,
|
||||
|
||||
@@ -121,7 +121,7 @@ static std::string _cypress_optimize_3ds_get_serial(const cyop_device_usb_device
|
||||
return std::to_string((curr_serial_extra_id++) + 1);
|
||||
}
|
||||
|
||||
std::string cypress_optimize_3ds_get_serial(const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) {
|
||||
std::string cypress_optimize_3ds_get_serial(cy_device_device_handlers* handlers, const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) {
|
||||
if(usb_device_desc == NULL)
|
||||
return "";
|
||||
const cyop_device_usb_device* in_usb_device_desc = (const cyop_device_usb_device*)usb_device_desc;
|
||||
|
||||
@@ -78,6 +78,7 @@ static const cyop_device_usb_device cypress_optimize_new_3ds_generic_device = {
|
||||
.do_pipe_clear_reset = false,
|
||||
.alt_interface = 1,
|
||||
.full_data = &cypress_optimize_new_3ds_generic_device,
|
||||
.get_serial_requires_setup = false,
|
||||
.get_serial_fn = cypress_optimize_3ds_get_serial,
|
||||
.create_device_fn = cypress_optimize_3ds_create_device,
|
||||
.bcd_device_mask = 0x0000,
|
||||
@@ -105,6 +106,7 @@ static const cyop_device_usb_device cypress_optimize_new_3ds_instantiated_device
|
||||
.do_pipe_clear_reset = true,
|
||||
.alt_interface = 0,
|
||||
.full_data = &cypress_optimize_new_3ds_instantiated_device,
|
||||
.get_serial_requires_setup = false,
|
||||
.get_serial_fn = cypress_optimize_3ds_get_serial,
|
||||
.create_device_fn = cypress_optimize_3ds_create_device,
|
||||
.bcd_device_mask = 0xFF00,
|
||||
@@ -132,6 +134,7 @@ static const cyop_device_usb_device cypress_optimize_old_3ds_generic_device = {
|
||||
.do_pipe_clear_reset = false,
|
||||
.alt_interface = 1,
|
||||
.full_data = &cypress_optimize_old_3ds_generic_device,
|
||||
.get_serial_requires_setup = false,
|
||||
.get_serial_fn = cypress_optimize_3ds_get_serial,
|
||||
.create_device_fn = cypress_optimize_3ds_create_device,
|
||||
.bcd_device_mask = 0x0000,
|
||||
@@ -159,6 +162,7 @@ static const cyop_device_usb_device cypress_optimize_old_3ds_instantiated_device
|
||||
.do_pipe_clear_reset = true,
|
||||
.alt_interface = 0,
|
||||
.full_data = &cypress_optimize_old_3ds_instantiated_device,
|
||||
.get_serial_requires_setup = false,
|
||||
.get_serial_fn = cypress_optimize_3ds_get_serial,
|
||||
.create_device_fn = cypress_optimize_3ds_create_device,
|
||||
.bcd_device_mask = 0xFF00,
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
#include "devicecapture.hpp"
|
||||
#include "cypress_shared_driver_comms.hpp"
|
||||
#include "cypress_shared_libusb_comms.hpp"
|
||||
#include "cypress_shared_communications.hpp"
|
||||
#include "cypress_partner_ctr_communications.hpp"
|
||||
#include "cypress_partner_ctr_acquisition.hpp"
|
||||
#include "cypress_partner_ctr_acquisition_general.hpp"
|
||||
#include "usb_generic.hpp"
|
||||
|
||||
#include <libusb.h>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
|
||||
#define PARTNER_CTR_CYPRESS_USB_WINDOWS_DRIVER CYPRESS_WINDOWS_DEFAULT_USB_DRIVER
|
||||
|
||||
static cy_device_device_handlers* usb_reconnect(const cypart_device_usb_device* usb_device_desc, CaptureDevice* device) {
|
||||
cy_device_device_handlers* final_handlers = NULL;
|
||||
int curr_serial_extra_id = 0;
|
||||
final_handlers = cypress_libusb_serial_reconnection(get_cy_usb_info(usb_device_desc), device->serial_number, curr_serial_extra_id, NULL);
|
||||
|
||||
if (final_handlers == NULL)
|
||||
final_handlers = cypress_driver_serial_reconnection(device);
|
||||
return final_handlers;
|
||||
}
|
||||
|
||||
static std::string _cypress_partner_ctr_get_serial(cy_device_device_handlers* handlers, const cypart_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) {
|
||||
if(serial != "")
|
||||
return serial;
|
||||
serial = read_serial_ctr_capture(handlers, usb_device_desc);
|
||||
if(serial != "")
|
||||
return serial;
|
||||
return std::to_string((curr_serial_extra_id++) + 1);
|
||||
}
|
||||
|
||||
std::string cypress_partner_ctr_get_serial(cy_device_device_handlers* handlers, const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) {
|
||||
if(usb_device_desc == NULL)
|
||||
return "";
|
||||
if(handlers == NULL)
|
||||
return "";
|
||||
const cypart_device_usb_device* in_usb_device_desc = (const cypart_device_usb_device*)usb_device_desc;
|
||||
return _cypress_partner_ctr_get_serial(handlers, in_usb_device_desc, serial, bcd_device, curr_serial_extra_id);
|
||||
}
|
||||
|
||||
static CaptureDevice _cypress_partner_ctr_create_device(const cypart_device_usb_device* usb_device_desc, std::string serial, std::string path) {
|
||||
CaptureDevice out_device = CaptureDevice(serial, usb_device_desc->name, usb_device_desc->long_name, CAPTURE_CONN_PARTNER_CTR, (void*)usb_device_desc, true, true, true, TOP_WIDTH_3DS, HEIGHT_3DS * 2, TOP_WIDTH_3DS, HEIGHT_3DS * 3, N3DSXL_SAMPLES_IN, 180, 0, HEIGHT_3DS, 0, 2 * HEIGHT_3DS, 0, 0, false, usb_device_desc->video_data_type, 0x200, path);
|
||||
out_device.is_horizontally_flipped = true;
|
||||
out_device.continuous_3d_screens = false;
|
||||
return out_device;
|
||||
}
|
||||
|
||||
CaptureDevice cypress_partner_ctr_create_device(const void* usb_device_desc, std::string serial, std::string path) {
|
||||
if(usb_device_desc == NULL)
|
||||
return CaptureDevice();
|
||||
return _cypress_partner_ctr_create_device((const cypart_device_usb_device*)usb_device_desc, serial, path);
|
||||
}
|
||||
|
||||
static void cypress_partner_ctr_connection_end(cy_device_device_handlers* handlers, const cypart_device_usb_device *device_desc, bool interface_claimed = true) {
|
||||
if (handlers == NULL)
|
||||
return;
|
||||
if (handlers->usb_handle)
|
||||
cypress_libusb_end_connection(handlers, get_cy_usb_info(device_desc), interface_claimed);
|
||||
else
|
||||
cypress_driver_end_connection(handlers);
|
||||
delete handlers;
|
||||
}
|
||||
|
||||
void list_devices_cypart_device(std::vector<CaptureDevice> &devices_list, std::vector<no_access_recap_data> &no_access_list, bool* devices_allowed_scan) {
|
||||
const size_t num_cypart_device_desc = GetNumCyPartnerCTRDeviceDesc();
|
||||
int* curr_serial_extra_id_cypart_device = new int[num_cypart_device_desc];
|
||||
bool* no_access_elems = new bool[num_cypart_device_desc];
|
||||
bool* not_supported_elems = new bool[num_cypart_device_desc];
|
||||
std::vector<const cy_device_usb_device*> usb_devices_to_check;
|
||||
for (size_t i = 0; i < num_cypart_device_desc; i++) {
|
||||
no_access_elems[i] = false;
|
||||
not_supported_elems[i] = false;
|
||||
curr_serial_extra_id_cypart_device[i] = 0;
|
||||
const cypart_device_usb_device* curr_device_desc = GetCyPartnerCTRDeviceDesc((int)i);
|
||||
if(devices_allowed_scan[curr_device_desc->index_in_allowed_scan])
|
||||
usb_devices_to_check.push_back(get_cy_usb_info(curr_device_desc));
|
||||
}
|
||||
cypress_libusb_list_devices(devices_list, no_access_elems, not_supported_elems, curr_serial_extra_id_cypart_device, usb_devices_to_check);
|
||||
|
||||
bool any_not_supported = false;
|
||||
for(size_t i = 0; i < num_cypart_device_desc; i++)
|
||||
any_not_supported |= not_supported_elems[i];
|
||||
for(size_t i = 0; i < num_cypart_device_desc; i++)
|
||||
if(no_access_elems[i])
|
||||
no_access_list.emplace_back(usb_devices_to_check[i]->vid, usb_devices_to_check[i]->pid);
|
||||
if(any_not_supported)
|
||||
cypress_driver_list_devices(devices_list, not_supported_elems, curr_serial_extra_id_cypart_device, usb_devices_to_check, PARTNER_CTR_CYPRESS_USB_WINDOWS_DRIVER);
|
||||
|
||||
delete[] curr_serial_extra_id_cypart_device;
|
||||
delete[] no_access_elems;
|
||||
delete[] not_supported_elems;
|
||||
}
|
||||
|
||||
bool cypart_device_connect_usb(bool print_failed, CaptureData* capture_data, CaptureDevice* device) {
|
||||
const cypart_device_usb_device* usb_device_info = (const cypart_device_usb_device*)device->descriptor;
|
||||
cy_device_device_handlers* handlers = usb_reconnect(usb_device_info, device);
|
||||
if(handlers == NULL) {
|
||||
capture_error_print(true, capture_data, "Device not found");
|
||||
return false;
|
||||
}
|
||||
capture_data->handle = (void*)handlers;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t cypart_device_get_video_in_size(CaptureStatus* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint64_t cypart_device_get_video_in_size(CaptureData* capture_data) {
|
||||
return cypart_device_get_video_in_size(&capture_data->status);
|
||||
}
|
||||
|
||||
void cypart_device_acquisition_main_loop(CaptureData* capture_data) {
|
||||
if(!usb_is_initialized())
|
||||
return;
|
||||
}
|
||||
|
||||
void usb_cypart_device_acquisition_cleanup(CaptureData* capture_data) {
|
||||
if(!usb_is_initialized())
|
||||
return;
|
||||
cypress_partner_ctr_connection_end((cy_device_device_handlers*)capture_data->handle, (const cypart_device_usb_device*)capture_data->status.device.descriptor);
|
||||
capture_data->handle = NULL;
|
||||
}
|
||||
void usb_cypart_device_init() {
|
||||
return usb_init();
|
||||
}
|
||||
|
||||
void usb_cypart_device_close() {
|
||||
usb_close();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
#include "frontend.hpp"
|
||||
#include "cypress_partner_ctr_communications.hpp"
|
||||
#include "cypress_shared_communications.hpp"
|
||||
#include "cypress_partner_ctr_acquisition_general.hpp"
|
||||
#include "usb_generic.hpp"
|
||||
|
||||
#include <libusb.h>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
#define CYPRESS_PARTNER_CTR_USB_PACKET_LIMIT 512
|
||||
|
||||
#define PARTNER_CTR_OUT_GET_SERIAL 0x5F
|
||||
|
||||
#define PARTNER_CTR_SERIAL_SIZE 8
|
||||
|
||||
static const cypart_device_usb_device cypress_partner_ctr_device = {
|
||||
.name = "P.CTR-Cap", .long_name = "Partner CTR Capture",
|
||||
.video_data_type = VIDEO_DATA_BGR,
|
||||
.index_in_allowed_scan = CC_PARTNER_CTR,
|
||||
.ep_ctrl_serial_io_pipe = 1,
|
||||
.usb_device_info = {
|
||||
.vid = 0x0ED2, .pid = 0x0004,
|
||||
.default_config = 1, .default_interface = 0,
|
||||
.bulk_timeout = 500,
|
||||
.ep_ctrl_bulk_in = 4 | LIBUSB_ENDPOINT_IN, .ep_ctrl_bulk_out = 2 | LIBUSB_ENDPOINT_OUT,
|
||||
.ep_bulk_in = 6 | LIBUSB_ENDPOINT_IN,
|
||||
.max_usb_packet_size = CYPRESS_PARTNER_CTR_USB_PACKET_LIMIT,
|
||||
.do_pipe_clear_reset = true,
|
||||
.alt_interface = 0,
|
||||
.full_data = &cypress_partner_ctr_device,
|
||||
.get_serial_requires_setup = true,
|
||||
.get_serial_fn = cypress_partner_ctr_get_serial,
|
||||
.create_device_fn = cypress_partner_ctr_create_device,
|
||||
.bcd_device_mask = 0x0000,
|
||||
.bcd_device_wanted_value = 0x0000
|
||||
}
|
||||
};
|
||||
|
||||
static const cypart_device_usb_device cypress_partner_ctr2_device = {
|
||||
.name = "P.CTR-Cap2", .long_name = "Partner CTR Capture 2",
|
||||
.video_data_type = VIDEO_DATA_BGR,
|
||||
.index_in_allowed_scan = CC_PARTNER_CTR,
|
||||
.ep_ctrl_serial_io_pipe = 1,
|
||||
.usb_device_info = {
|
||||
.vid = 0x0ED2, .pid = 0x000B,
|
||||
.default_config = 1, .default_interface = 0,
|
||||
.bulk_timeout = 500,
|
||||
.ep_ctrl_bulk_in = 4 | LIBUSB_ENDPOINT_IN, .ep_ctrl_bulk_out = 2 | LIBUSB_ENDPOINT_OUT,
|
||||
.ep_bulk_in = 6 | LIBUSB_ENDPOINT_IN,
|
||||
.max_usb_packet_size = CYPRESS_PARTNER_CTR_USB_PACKET_LIMIT,
|
||||
.do_pipe_clear_reset = true,
|
||||
.alt_interface = 0,
|
||||
.full_data = &cypress_partner_ctr2_device,
|
||||
.get_serial_requires_setup = true,
|
||||
.get_serial_fn = cypress_partner_ctr_get_serial,
|
||||
.create_device_fn = cypress_partner_ctr_create_device,
|
||||
.bcd_device_mask = 0x0000,
|
||||
.bcd_device_wanted_value = 0x0000
|
||||
}
|
||||
};
|
||||
|
||||
static const cypart_device_usb_device* all_usb_cypart_device_devices_desc[] = {
|
||||
&cypress_partner_ctr_device,
|
||||
&cypress_partner_ctr2_device,
|
||||
};
|
||||
|
||||
const cy_device_usb_device* get_cy_usb_info(const cypart_device_usb_device* usb_device_desc) {
|
||||
return &usb_device_desc->usb_device_info;
|
||||
}
|
||||
|
||||
int GetNumCyPartnerCTRDeviceDesc() {
|
||||
return sizeof(all_usb_cypart_device_devices_desc) / sizeof(all_usb_cypart_device_devices_desc[0]);
|
||||
}
|
||||
|
||||
const cypart_device_usb_device* GetCyPartnerCTRDeviceDesc(int index) {
|
||||
if((index < 0) || (index >= GetNumCyPartnerCTRDeviceDesc()))
|
||||
index = 0;
|
||||
return all_usb_cypart_device_devices_desc[index];
|
||||
}
|
||||
|
||||
std::string read_serial_ctr_capture(cy_device_device_handlers* handlers, const cypart_device_usb_device* device) {
|
||||
uint8_t buffer[] = { PARTNER_CTR_OUT_GET_SERIAL, 0};
|
||||
uint8_t buffer_in[PARTNER_CTR_SERIAL_SIZE];
|
||||
int transferred = 0;
|
||||
cypress_pipe_reset_ctrl_bulk_out(handlers, get_cy_usb_info(device), device->ep_ctrl_serial_io_pipe | LIBUSB_ENDPOINT_OUT);
|
||||
cypress_pipe_reset_ctrl_bulk_in(handlers, get_cy_usb_info(device), device->ep_ctrl_serial_io_pipe | LIBUSB_ENDPOINT_IN);
|
||||
int ret = cypress_ctrl_bulk_out_transfer(handlers, get_cy_usb_info(device), buffer, sizeof(buffer), &transferred, device->ep_ctrl_serial_io_pipe | LIBUSB_ENDPOINT_OUT);
|
||||
if(ret < 0)
|
||||
return "";
|
||||
ret = cypress_ctrl_bulk_in_transfer(handlers, get_cy_usb_info(device), buffer_in, sizeof(buffer_in), &transferred, device->ep_ctrl_serial_io_pipe | LIBUSB_ENDPOINT_IN);
|
||||
if(ret < 0)
|
||||
return "";
|
||||
if(transferred != sizeof(buffer_in))
|
||||
return "";
|
||||
|
||||
uint16_t serial_part_1 = read_be16(buffer_in + 2);
|
||||
return std::to_string(serial_part_1) + "-" + read_string(buffer_in + 5, 3);
|
||||
}
|
||||
|
||||
int capture_start(cy_device_device_handlers* handlers, const cypart_device_usb_device* device) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int StartCaptureDma(cy_device_device_handlers* handlers, const cypart_device_usb_device* device) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int capture_end(cy_device_device_handlers* handlers, const cypart_device_usb_device* device) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ReadFrame(cy_device_device_handlers* handlers, uint8_t* buf, int length, const cypart_device_usb_device* device_desc) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ReadFrameAsync(cy_device_device_handlers* handlers, uint8_t* buf, int length, const cypart_device_usb_device* device_desc, cy_async_callback_data* cb_data) {
|
||||
return 0;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "dscapture_ftd2_shared.hpp"
|
||||
#include "usb_ds_3ds_capture.hpp"
|
||||
#include "usb_is_device_acquisition.hpp"
|
||||
#include "cypress_partner_ctr_acquisition.hpp"
|
||||
#include "cypress_nisetro_acquisition.hpp"
|
||||
#include "cypress_optimize_3ds_acquisition.hpp"
|
||||
|
||||
@@ -147,6 +148,9 @@ bool connect(bool print_failed, CaptureData* capture_data, FrontendData* fronten
|
||||
#ifdef USE_IS_DEVICES_USB
|
||||
list_devices_is_device(devices_list, no_access_list, devices_allowed_scan);
|
||||
#endif
|
||||
#ifdef USE_PARTNER_CTR
|
||||
list_devices_cypart_device(devices_list, no_access_list, devices_allowed_scan);
|
||||
#endif
|
||||
|
||||
if(devices_list.size() <= 0) {
|
||||
if(no_access_list.size() <= 0)
|
||||
@@ -196,6 +200,10 @@ bool connect(bool print_failed, CaptureData* capture_data, FrontendData* fronten
|
||||
if((devices_list[chosen_device].cc_type == CAPTURE_CONN_IS_NITRO) && (!is_device_connect_usb(print_failed, capture_data, &devices_list[chosen_device])))
|
||||
return false;
|
||||
#endif
|
||||
#ifdef USE_PARTNER_CTR
|
||||
if((devices_list[chosen_device].cc_type == CAPTURE_CONN_PARTNER_CTR) && (!cypart_device_connect_usb(print_failed, capture_data, &devices_list[chosen_device])))
|
||||
return false;
|
||||
#endif
|
||||
update_connected_3ds_ds(frontend_data, capture_data->status.device, devices_list[chosen_device]);
|
||||
capture_data->status.device = devices_list[chosen_device];
|
||||
|
||||
@@ -240,6 +248,10 @@ void captureCall(CaptureData* capture_data) {
|
||||
if(capture_data->status.device.cc_type == CAPTURE_CONN_IS_NITRO)
|
||||
is_device_acquisition_main_loop(capture_data);
|
||||
#endif
|
||||
#ifdef USE_PARTNER_CTR
|
||||
if(capture_data->status.device.cc_type == CAPTURE_CONN_PARTNER_CTR)
|
||||
cypart_device_acquisition_main_loop(capture_data);
|
||||
#endif
|
||||
|
||||
capture_data->status.close_success = false;
|
||||
capture_data->status.connected = false;
|
||||
@@ -274,6 +286,10 @@ void captureCall(CaptureData* capture_data) {
|
||||
if(capture_data->status.device.cc_type == CAPTURE_CONN_IS_NITRO)
|
||||
usb_is_device_acquisition_cleanup(capture_data);
|
||||
#endif
|
||||
#ifdef USE_PARTNER_CTR
|
||||
if(capture_data->status.device.cc_type == CAPTURE_CONN_PARTNER_CTR)
|
||||
usb_cypart_device_acquisition_cleanup(capture_data);
|
||||
#endif
|
||||
|
||||
capture_data->status.close_success = false;
|
||||
capture_data->status.connected = false;
|
||||
@@ -323,6 +339,10 @@ uint64_t get_video_in_size(CaptureData* capture_data, bool is_3d, bool should_be
|
||||
if(capture_data->status.device.cc_type == CAPTURE_CONN_IS_NITRO)
|
||||
return usb_is_device_get_video_in_size(capture_data);
|
||||
#endif
|
||||
#ifdef USE_PARTNER_CTR
|
||||
if(capture_data->status.device.cc_type == CAPTURE_CONN_PARTNER_CTR)
|
||||
return cypart_device_get_video_in_size(capture_data);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -481,6 +501,9 @@ void capture_init() {
|
||||
#ifdef USE_IS_DEVICES_USB
|
||||
usb_is_device_init();
|
||||
#endif
|
||||
#ifdef USE_PARTNER_CTR
|
||||
usb_cypart_device_init();
|
||||
#endif
|
||||
#ifdef USE_FTD2
|
||||
ftd2_init_shared();
|
||||
#endif
|
||||
@@ -499,6 +522,9 @@ void capture_close() {
|
||||
#ifdef USE_IS_DEVICES_USB
|
||||
usb_is_device_close();
|
||||
#endif
|
||||
#ifdef USE_PARTNER_CTR
|
||||
usb_cypart_device_close();
|
||||
#endif
|
||||
#ifdef USE_FTD2
|
||||
ftd2_end_shared();
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user