diff --git a/CMakeLists.txt b/CMakeLists.txt index f755188..86cc252 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -356,7 +356,7 @@ if(OLD_DS_3DS_LOOPY_SUPPORT) endif() endif() if(CYPRESS_NISETRO_SUPPORT) - list(APPEND SOURCE_CPP_EXTRA_FILES ${SOURCE_CPP_CYPRESS_NISETRO_DEVICES_FILES_BASE_PATH}/cypress_nisetro_driver_comms.cpp ${SOURCE_CPP_CYPRESS_NISETRO_DEVICES_FILES_BASE_PATH}/cypress_nisetro_libusb_comms.cpp ${SOURCE_CPP_CYPRESS_NISETRO_DEVICES_FILES_BASE_PATH}/cypress_nisetro_communications.cpp ${SOURCE_CPP_CYPRESS_NISETRO_DEVICES_FILES_BASE_PATH}/cypress_nisetro_acquisition.cpp ${TOOLS_DATA_DIR}/nisetro_ds_fw.cpp) + list(APPEND SOURCE_CPP_EXTRA_FILES ${SOURCE_CPP_CYPRESS_NISETRO_DEVICES_FILES_BASE_PATH}/cypress_shared_driver_comms.cpp ${SOURCE_CPP_CYPRESS_NISETRO_DEVICES_FILES_BASE_PATH}/cypress_shared_libusb_comms.cpp ${SOURCE_CPP_CYPRESS_NISETRO_DEVICES_FILES_BASE_PATH}/cypress_shared_communications.cpp ${SOURCE_CPP_CYPRESS_NISETRO_DEVICES_FILES_BASE_PATH}/cypress_nisetro_communications.cpp ${SOURCE_CPP_CYPRESS_NISETRO_DEVICES_FILES_BASE_PATH}/cypress_nisetro_acquisition.cpp ${TOOLS_DATA_DIR}/nisetro_ds_fw.cpp) if(MSVC) list(APPEND EXTRA_CXX_FLAGS "/DUSE_CYNI_USB") else() diff --git a/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_acquisition_general.hpp b/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_acquisition_general.hpp index af3a797..619ff54 100644 --- a/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_acquisition_general.hpp +++ b/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_acquisition_general.hpp @@ -1,6 +1,7 @@ #ifndef __CYPRESS_NISETRO_ACQUISITION_GENERAL_HPP #define __CYPRESS_NISETRO_ACQUISITION_GENERAL_HPP +#include "cypress_shared_communications.hpp" #include "cypress_nisetro_communications.hpp" #define NUM_CAPTURE_RECEIVED_DATA_BUFFERS NUM_CONCURRENT_DATA_BUFFER_WRITERS @@ -19,24 +20,10 @@ struct CypressDeviceCaptureReceivedData { int* consecutive_output_to_thread; CaptureData* capture_data; std::chrono::time_point* clock_start; - cyni_async_callback_data cb_data; + cy_async_callback_data cb_data; }; -std::string get_serial(const cyni_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id); -CaptureDevice cypress_create_device(const cyni_device_usb_device* usb_device_desc, std::string serial, std::string path); -CaptureDevice cypress_create_device(const cyni_device_usb_device* usb_device_desc, std::string serial); -void cypress_insert_device(std::vector& devices_list, const cyni_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id, std::string path); -void cypress_insert_device(std::vector& devices_list, const cyni_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id); -void cypress_output_to_thread(CaptureData* capture_data, CaptureReceived* capture_buf, CaptureScreensType curr_capture_type, std::chrono::time_point* clock_start, size_t read_size); -int cypress_device_read_frame_and_output(CaptureData* capture_data, CaptureReceived* capture_buf, CaptureScreensType curr_capture_type, std::chrono::time_point &clock_start); -int cypress_device_read_frame_request(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, CaptureScreensType curr_capture_type, uint32_t index); -int cypress_device_get_num_free_buffers(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data); -void wait_all_cypress_device_buffers_free(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data); -void wait_one_cypress_device_buffer_free(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data); -bool cypress_device_are_buffers_all_free(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data); -CypressDeviceCaptureReceivedData* cypress_device_get_free_buffer(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data); -int get_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data); -void error_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, int error_val); -void reset_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data); +std::string cypress_nisetro_get_serial(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 diff --git a/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_communications.hpp b/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_communications.hpp index cfc0b20..1d0585d 100644 --- a/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_communications.hpp +++ b/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_communications.hpp @@ -7,78 +7,36 @@ #include #include "utils.hpp" #include "capture_structs.hpp" +#include "cypress_shared_communications.hpp" enum cypress_nisetro_device_type { CYPRESS_NISETRO_BLANK_DEVICE, CYPRESS_NISETRO_DS_DEVICE, }; -typedef void (*cyni_async_callback_function)(void* user_data, int transfer_length, int transfer_status); - -struct cyni_async_callback_data { - cyni_async_callback_function function; - void* actual_user_data; - void* transfer_data; - void* handle; - void* extra_transfer_data; - void* base_transfer_data; - std::mutex transfer_data_access; - SharedConsumerMutex* is_transfer_done_mutex; - SharedConsumerMutex* is_transfer_data_ready_mutex; - std::chrono::time_point start_request; - float timeout_s; - size_t requested_length; - uint8_t* buffer; - size_t actual_length; - int status_value; - int internal_index; - bool is_data_ready; -}; - struct cyni_device_usb_device { std::string name; std::string long_name; - int vid; - int pid; - int default_config; - int default_interface; - int bulk_timeout; - int ep_ctrl_bulk_in; - int ep_ctrl_bulk_out; - int ep_bulk_in; cypress_nisetro_device_type device_type; InputVideoDataType video_data_type; - size_t max_usb_packet_size; - bool do_pipe_clear_reset; uint8_t* firmware_to_load; size_t firmware_size; cypress_nisetro_device_type next_device; bool has_bcd_device_serial; - int alt_interface; + cy_device_usb_device usb_device_info; }; -struct cyni_device_device_handlers { - libusb_device_handle* usb_handle; - void* read_handle; - void* write_handle; - void* mutex; - std::string path; -}; int GetNumCyNiDeviceDesc(void); -const cyni_device_usb_device* GetCyNiDeviceDesc(int index);const cyni_device_usb_device* GetNextDeviceDesc(const cyni_device_usb_device* device); +const cyni_device_usb_device* GetCyNiDeviceDesc(int index); const cyni_device_usb_device* GetNextDeviceDesc(const cyni_device_usb_device* device); +const cy_device_usb_device* get_cy_usb_info(const cyni_device_usb_device* usb_device_desc); bool has_to_load_firmware(const cyni_device_usb_device* device); -bool load_firmware(cyni_device_device_handlers* handlers, const cyni_device_usb_device* device, uint8_t patch_id); -int capture_start(cyni_device_device_handlers* handlers, const cyni_device_usb_device* device); -int StartCaptureDma(cyni_device_device_handlers* handlers, const cyni_device_usb_device* device); -int capture_end(cyni_device_device_handlers* handlers, const cyni_device_usb_device* device); -int ReadFrame(cyni_device_device_handlers* handlers, uint8_t* buf, int length, const cyni_device_usb_device* device_desc); -int ReadFrameAsync(cyni_device_device_handlers* handlers, uint8_t* buf, int length, const cyni_device_usb_device* device_desc, cyni_async_callback_data* cb_data); -void CloseAsyncRead(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, cyni_async_callback_data* cb_data); -void SetupCypressDeviceAsyncThread(cyni_device_device_handlers* handlers, void* user_data, std::thread* thread_ptr, bool* keep_going, ConsumerMutex* is_data_ready); -void EndCypressDeviceAsyncThread(cyni_device_device_handlers* handlers, void* user_data, std::thread* thread_ptr, bool* keep_going, ConsumerMutex* is_data_ready); -void SetMaxTransferSize(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, size_t new_max_transfer_size); -void pipe_reset_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc); +bool load_firmware(cy_device_device_handlers* handlers, const cyni_device_usb_device* device, uint8_t patch_id); +int capture_start(cy_device_device_handlers* handlers, const cyni_device_usb_device* device); +int StartCaptureDma(cy_device_device_handlers* handlers, const cyni_device_usb_device* device); +int capture_end(cy_device_device_handlers* handlers, const cyni_device_usb_device* device); +int ReadFrame(cy_device_device_handlers* handlers, uint8_t* buf, int length, const cyni_device_usb_device* device_desc); +int ReadFrameAsync(cy_device_device_handlers* handlers, uint8_t* buf, int length, const cyni_device_usb_device* device_desc, cy_async_callback_data* cb_data); #endif diff --git a/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_driver_comms.hpp b/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_driver_comms.hpp deleted file mode 100644 index f99e194..0000000 --- a/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_driver_comms.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __CYPRESS_NISETRO_DRIVER_COMMS_HPP -#define __CYPRESS_NISETRO_DRIVER_COMMS_HPP - -#include -#include "capture_structs.hpp" -#include "utils.hpp" -#include "cypress_nisetro_communications.hpp" -#include "cypress_nisetro_acquisition_general.hpp" - -void cypress_driver_list_devices(std::vector& devices_list, bool* not_supported_elems, int* curr_serial_extra_id_cypress, const size_t num_cypress_desc); -void cypress_driver_find_used_serial(const cyni_device_usb_device* usb_device_desc, bool* found, size_t num_free_fw_ids, int &curr_serial_extra_id); -void cypress_nisetro_driver_end_connection(cyni_device_device_handlers* handlers); -int cypress_driver_ctrl_transfer_in(cyni_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(cyni_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(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred); -int cypress_driver_ctrl_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred); -int cypress_driver_ctrl_bulk_out(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred); -void cypress_driver_pipe_reset_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc); -void cypress_driver_pipe_reset_ctrl_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc); -void cypress_driver_pipe_reset_ctrl_bulk_out(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc); -cyni_device_device_handlers* cypress_driver_serial_reconnection(CaptureDevice* device); -cyni_device_device_handlers* cypress_driver_find_by_serial_number(const cyni_device_usb_device* usb_device_desc, std::string wanted_serial_number, int &curr_serial_extra_id, CaptureDevice* new_device); -int cypress_driver_async_in_start(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, cyni_async_callback_data* cb_data); -void cypress_driver_start_thread(std::thread* thread_ptr, bool* usb_thread_run, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, cyni_device_device_handlers* handlers, ConsumerMutex* AsyncMutexPtr); -void cypress_driver_close_thread(std::thread* thread_ptr, bool* usb_thread_run, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data); -void cypress_driver_cancel_callback(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, cyni_async_callback_data* cb_data); -void cypress_driver_set_transfer_size_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, size_t new_transfer_size); - -#endif diff --git a/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_libusb_comms.hpp b/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_libusb_comms.hpp deleted file mode 100644 index 995559d..0000000 --- a/include/CaptureDeviceSpecific/Nisetro/cypress_nisetro_libusb_comms.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __CYPRESS_NISETRO_DEVICE_LIBUSB_HPP -#define __CYPRESS_NISETRO_DEVICE_LIBUSB_HPP - -#include -#include "capture_structs.hpp" -#include "cypress_nisetro_communications.hpp" - -void cypress_libusb_list_devices(std::vector &devices_list, bool* no_access_elems, bool* not_supported_elems, int *curr_serial_extra_id_cypress, const size_t num_cypress_desc); -cyni_device_device_handlers* cypress_libusb_serial_reconnection(const cyni_device_usb_device* usb_device_desc, std::string wanted_serial_number, int &curr_serial_extra_id, CaptureDevice* new_device); -void cypress_libusb_find_used_serial(const cyni_device_usb_device* usb_device_desc, bool* found, size_t num_free_fw_ids, int &curr_serial_extra_id); -void cypress_libusb_end_connection(cyni_device_device_handlers* handlers, const cyni_device_usb_device* device_desc, bool interface_claimed); -int cypress_libusb_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred); -int cypress_libusb_ctrl_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred); -int cypress_libusb_ctrl_bulk_out(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred); -void cypress_libusb_pipe_reset_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc); -void cypress_libusb_pipe_reset_ctrl_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc); -void cypress_libusb_pipe_reset_ctrl_bulk_out(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc); -int cypress_libusb_ctrl_in(cyni_device_device_handlers* handlers, const cyni_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(cyni_device_device_handlers* handlers, const cyni_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(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, cyni_async_callback_data* cb_data); -void cypress_libusb_cancell_callback(cyni_async_callback_data* cb_data); - -#endif diff --git a/include/CaptureDeviceSpecific/Nisetro/cypress_shared_communications.hpp b/include/CaptureDeviceSpecific/Nisetro/cypress_shared_communications.hpp new file mode 100644 index 0000000..291d853 --- /dev/null +++ b/include/CaptureDeviceSpecific/Nisetro/cypress_shared_communications.hpp @@ -0,0 +1,82 @@ +#ifndef __CYPRESS_SHARED_DEVICE_COMMUNICATIONS_HPP +#define __CYPRESS_SHARED_DEVICE_COMMUNICATIONS_HPP + +#include +#include +#include +#include +#include "utils.hpp" +#include "capture_structs.hpp" + +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_async_callback_data { + cy_async_callback_function function; + cy_error_function error_function; + volatile bool* in_use_ptr; + void* actual_user_data; + void* transfer_data; + void* handle; + void* extra_transfer_data; + void* base_transfer_data; + std::mutex transfer_data_access; + SharedConsumerMutex* is_transfer_done_mutex; + SharedConsumerMutex* is_transfer_data_ready_mutex; + std::chrono::time_point start_request; + float timeout_s; + size_t requested_length; + uint8_t* buffer; + size_t actual_length; + int status_value; + int internal_index; + bool is_data_ready; +}; + +struct cy_device_usb_device { + int vid; + int pid; + int default_config; + int default_interface; + int bulk_timeout; + int ep_ctrl_bulk_in; + int ep_ctrl_bulk_out; + int ep_bulk_in; + size_t max_usb_packet_size; + bool do_pipe_clear_reset; + int alt_interface; + const void* full_data; + cy_get_serial_function get_serial_fn; + cy_create_device_function create_device_fn; +}; + +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& 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 = ""); + +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, uint8_t* buf, int length, int* transferred); +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 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 &cb_data_vector, std::thread* thread_ptr, bool* keep_going); +void CypressEndCypressDeviceAsyncThread(cy_device_device_handlers* handlers, std::vector &cb_data_vector, std::thread* thread_ptr, bool* keep_going); + +#endif diff --git a/include/CaptureDeviceSpecific/Nisetro/cypress_shared_driver_comms.hpp b/include/CaptureDeviceSpecific/Nisetro/cypress_shared_driver_comms.hpp new file mode 100644 index 0000000..9bc2907 --- /dev/null +++ b/include/CaptureDeviceSpecific/Nisetro/cypress_shared_driver_comms.hpp @@ -0,0 +1,28 @@ +#ifndef __CYPRESS_NISETRO_DRIVER_COMMS_HPP +#define __CYPRESS_NISETRO_DRIVER_COMMS_HPP + +#include +#include "capture_structs.hpp" +#include "utils.hpp" +#include "cypress_shared_communications.hpp" + +void cypress_driver_list_devices(std::vector& devices_list, bool* not_supported_elems, int* curr_serial_extra_id_cypress, std::vector &device_descriptions); +void cypress_driver_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_nisetro_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); +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); +cy_device_device_handlers* cypress_driver_serial_reconnection(CaptureDevice* device); +cy_device_device_handlers* cypress_driver_find_by_serial_number(const cy_device_usb_device* usb_device_desc, std::string wanted_serial_number, int &curr_serial_extra_id, CaptureDevice* new_device); +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 &cb_data_vector, cy_device_device_handlers* handlers); +void cypress_driver_close_thread(std::thread* thread_ptr, bool* usb_thread_run, std::vector cb_data_vector); +void cypress_driver_cancel_callback(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, cy_async_callback_data* cb_data); +void cypress_driver_set_transfer_size_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, size_t new_transfer_size); + +#endif diff --git a/include/CaptureDeviceSpecific/Nisetro/cypress_shared_libusb_comms.hpp b/include/CaptureDeviceSpecific/Nisetro/cypress_shared_libusb_comms.hpp new file mode 100644 index 0000000..9536202 --- /dev/null +++ b/include/CaptureDeviceSpecific/Nisetro/cypress_shared_libusb_comms.hpp @@ -0,0 +1,23 @@ +#ifndef __CYPRESS_NISETRO_DEVICE_LIBUSB_HPP +#define __CYPRESS_NISETRO_DEVICE_LIBUSB_HPP + +#include +#include "capture_structs.hpp" +#include "cypress_shared_communications.hpp" + +void cypress_libusb_list_devices(std::vector &devices_list, bool* no_access_elems, bool* not_supported_elems, int *curr_serial_extra_id_cypress, std::vector &device_descriptions); +cy_device_device_handlers* cypress_libusb_serial_reconnection(const cy_device_usb_device* usb_device_desc, std::string wanted_serial_number, int &curr_serial_extra_id, CaptureDevice* new_device); +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); +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); +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); +void cypress_libusb_cancell_callback(cy_async_callback_data* cb_data); + +#endif diff --git a/include/audio.hpp b/include/audio.hpp index 7f5e73b..7a7a3c9 100755 --- a/include/audio.hpp +++ b/include/audio.hpp @@ -7,10 +7,10 @@ #include "utils.hpp" struct Sample { - Sample(std::int16_t *bytes, std::size_t size, double time) : bytes(bytes), size(size), time(time) {} + Sample(int16_t *bytes, uint64_t size, double time) : bytes(bytes), size(size), time(time) {} - std::int16_t *bytes; - std::size_t size; + int16_t *bytes; + uint64_t size; double time; }; diff --git a/include/capture_structs.hpp b/include/capture_structs.hpp index 5325091..7afa023 100755 --- a/include/capture_structs.hpp +++ b/include/capture_structs.hpp @@ -170,10 +170,10 @@ union CaptureReceived { struct CaptureDevice { // This is so messy... Wish there was a clearer way... - CaptureDevice(std::string serial_number, std::string name, CaptureConnectionType cc_type, const void* descriptor, bool is_3ds, bool has_3d, bool has_audio, int width, int height, int max_samples_in, int base_rotation, int top_screen_x, int top_screen_y, int bot_screen_x, int bot_screen_y, InputVideoDataType video_data_type) : serial_number(serial_number), name(name), cc_type(cc_type), descriptor(descriptor), is_3ds(is_3ds), has_3d(has_3d), has_audio(has_audio), width(width), height(height), max_samples_in(max_samples_in), base_rotation(base_rotation), top_screen_x(top_screen_x), top_screen_y(top_screen_y), bot_screen_x(bot_screen_x), bot_screen_y(bot_screen_y), video_data_type(video_data_type), long_name(name) {} - CaptureDevice(std::string serial_number, std::string name, std::string long_name, CaptureConnectionType cc_type, const void* descriptor, bool is_3ds, bool has_3d, bool has_audio, int width, int height, int max_samples_in, int base_rotation, int top_screen_x, int top_screen_y, int bot_screen_x, int bot_screen_y, InputVideoDataType video_data_type, std::string path = "") : serial_number(serial_number), name(name), cc_type(cc_type), descriptor(descriptor), is_3ds(is_3ds), has_3d(has_3d), has_audio(has_audio), width(width), height(height), max_samples_in(max_samples_in), base_rotation(base_rotation), top_screen_x(top_screen_x), top_screen_y(top_screen_y), bot_screen_x(bot_screen_x), bot_screen_y(bot_screen_y), video_data_type(video_data_type) {} - CaptureDevice(std::string serial_number, std::string name, std::string long_name, CaptureConnectionType cc_type, const void* descriptor, bool is_3ds, bool has_3d, bool has_audio, int width, int height, int max_samples_in, int base_rotation, int top_screen_x, int top_screen_y, int bot_screen_x, int bot_screen_y, InputVideoDataType video_data_type, int firmware_id, bool is_rgb_888, std::string path = "") : serial_number(serial_number), name(name), cc_type(cc_type), descriptor(descriptor), is_3ds(is_3ds), has_3d(has_3d), has_audio(has_audio), width(width), height(height), max_samples_in(max_samples_in), base_rotation(base_rotation), top_screen_x(top_screen_x), top_screen_y(top_screen_y), bot_screen_x(bot_screen_x), bot_screen_y(bot_screen_y), path(path), video_data_type(video_data_type), firmware_id(firmware_id), is_rgb_888(is_rgb_888), long_name(long_name) {} - CaptureDevice(std::string serial_number, std::string name, std::string long_name, CaptureConnectionType cc_type, const void* descriptor, bool is_3ds, bool has_3d, bool has_audio, int width, int height, int width_3d, int height_3d, int max_samples_in, int base_rotation, int top_screen_x, int top_screen_y, int second_top_screen_x, int second_top_screen_y, int bot_screen_x, int bot_screen_y, bool is_second_top_screen_right, InputVideoDataType video_data_type, uint32_t usb_speed) : serial_number(serial_number), name(name), cc_type(cc_type), descriptor(descriptor), is_3ds(is_3ds), has_3d(has_3d), has_audio(has_audio), width(width), height(height), max_samples_in(max_samples_in), base_rotation(base_rotation), top_screen_x(top_screen_x), top_screen_y(top_screen_y), bot_screen_x(bot_screen_x), bot_screen_y(bot_screen_y), video_data_type(video_data_type), long_name(long_name), usb_speed(usb_speed), second_top_screen_x(second_top_screen_x), second_top_screen_y(second_top_screen_y), width_3d(width_3d), height_3d(height_3d), is_second_top_screen_right(is_second_top_screen_right) {} + CaptureDevice(std::string serial_number, std::string name, CaptureConnectionType cc_type, const void* descriptor, bool is_3ds, bool has_3d, bool has_audio, int width, int height, uint64_t max_samples_in, int base_rotation, int top_screen_x, int top_screen_y, int bot_screen_x, int bot_screen_y, InputVideoDataType video_data_type) : serial_number(serial_number), name(name), cc_type(cc_type), descriptor(descriptor), is_3ds(is_3ds), has_3d(has_3d), has_audio(has_audio), width(width), height(height), max_samples_in(max_samples_in), base_rotation(base_rotation), top_screen_x(top_screen_x), top_screen_y(top_screen_y), bot_screen_x(bot_screen_x), bot_screen_y(bot_screen_y), video_data_type(video_data_type), long_name(name) {} + CaptureDevice(std::string serial_number, std::string name, std::string long_name, CaptureConnectionType cc_type, const void* descriptor, bool is_3ds, bool has_3d, bool has_audio, int width, int height, uint64_t max_samples_in, int base_rotation, int top_screen_x, int top_screen_y, int bot_screen_x, int bot_screen_y, InputVideoDataType video_data_type, std::string path = "") : serial_number(serial_number), name(name), cc_type(cc_type), descriptor(descriptor), is_3ds(is_3ds), has_3d(has_3d), has_audio(has_audio), width(width), height(height), max_samples_in(max_samples_in), base_rotation(base_rotation), top_screen_x(top_screen_x), top_screen_y(top_screen_y), bot_screen_x(bot_screen_x), bot_screen_y(bot_screen_y), video_data_type(video_data_type), path(path), long_name(long_name) {} + CaptureDevice(std::string serial_number, std::string name, std::string long_name, CaptureConnectionType cc_type, const void* descriptor, bool is_3ds, bool has_3d, bool has_audio, int width, int height, uint64_t max_samples_in, int base_rotation, int top_screen_x, int top_screen_y, int bot_screen_x, int bot_screen_y, InputVideoDataType video_data_type, int firmware_id, bool is_rgb_888, std::string path = "") : serial_number(serial_number), name(name), cc_type(cc_type), descriptor(descriptor), is_3ds(is_3ds), has_3d(has_3d), has_audio(has_audio), width(width), height(height), max_samples_in(max_samples_in), base_rotation(base_rotation), top_screen_x(top_screen_x), top_screen_y(top_screen_y), bot_screen_x(bot_screen_x), bot_screen_y(bot_screen_y), path(path), video_data_type(video_data_type), firmware_id(firmware_id), is_rgb_888(is_rgb_888), long_name(long_name) {} + CaptureDevice(std::string serial_number, std::string name, std::string long_name, CaptureConnectionType cc_type, const void* descriptor, bool is_3ds, bool has_3d, bool has_audio, int width, int height, int width_3d, int height_3d, uint64_t max_samples_in, int base_rotation, int top_screen_x, int top_screen_y, int second_top_screen_x, int second_top_screen_y, int bot_screen_x, int bot_screen_y, bool is_second_top_screen_right, InputVideoDataType video_data_type, uint32_t usb_speed) : serial_number(serial_number), name(name), cc_type(cc_type), descriptor(descriptor), is_3ds(is_3ds), has_3d(has_3d), has_audio(has_audio), width(width), height(height), max_samples_in(max_samples_in), base_rotation(base_rotation), top_screen_x(top_screen_x), top_screen_y(top_screen_y), bot_screen_x(bot_screen_x), bot_screen_y(bot_screen_y), video_data_type(video_data_type), long_name(long_name), usb_speed(usb_speed), second_top_screen_x(second_top_screen_x), second_top_screen_y(second_top_screen_y), width_3d(width_3d), height_3d(height_3d), is_second_top_screen_right(is_second_top_screen_right) {} CaptureDevice() : usb_speed(0) {} std::string serial_number = ""; @@ -190,7 +190,7 @@ struct CaptureDevice { int height = 0; int width_3d = 0; int height_3d = 0; - int max_samples_in = 0; + uint64_t max_samples_in = 0; int base_rotation = 0; int top_screen_x = 0; int top_screen_y = 0; diff --git a/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_acquisition.cpp b/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_acquisition.cpp index 2db0a3c..b4593b4 100644 --- a/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_acquisition.cpp +++ b/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_acquisition.cpp @@ -1,6 +1,7 @@ #include "devicecapture.hpp" -#include "cypress_nisetro_driver_comms.hpp" -#include "cypress_nisetro_libusb_comms.hpp" +#include "cypress_shared_driver_comms.hpp" +#include "cypress_shared_libusb_comms.hpp" +#include "cypress_shared_communications.hpp" #include "cypress_nisetro_communications.hpp" #include "cypress_nisetro_acquisition.hpp" #include "cypress_nisetro_acquisition_general.hpp" @@ -10,20 +11,31 @@ #include #include +// The driver only seems to support up to 4 concurrent reads. Not more... +#ifdef NUM_CAPTURE_RECEIVED_DATA_BUFFERS +#if NUM_CAPTURE_RECEIVED_DATA_BUFFERS > 4 +#define NUM_NISETRO_CYPRESS_BUFFERS 4 +#else +#define NUM_NISETRO_CYPRESS_BUFFERS NUM_CAPTURE_RECEIVED_DATA_BUFFERS +#endif +#endif + #define SERIAL_NUMBER_SIZE (0x100 + 1) #define MAX_TIME_WAIT 1.0 #define MAX_ERRORS_ALLOWED 100 #define NUM_CONSECUTIVE_NEEDED_OUTPUT 6 static void cypress_device_read_frame_cb(void* user_data, int transfer_length, int transfer_status); +static int get_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data); +static void error_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, int error_val); -static cyni_device_device_handlers* usb_find_by_serial_number(const cyni_device_usb_device* usb_device_desc, std::string wanted_serial_number, CaptureDevice* new_device) { - cyni_device_device_handlers* final_handlers = NULL; +static cy_device_device_handlers* usb_find_by_serial_number(const cyni_device_usb_device* usb_device_desc, std::string wanted_serial_number, CaptureDevice* new_device) { + cy_device_device_handlers* final_handlers = NULL; int curr_serial_extra_id = 0; - final_handlers = cypress_libusb_serial_reconnection(usb_device_desc, wanted_serial_number, curr_serial_extra_id, new_device); + final_handlers = cypress_libusb_serial_reconnection(get_cy_usb_info(usb_device_desc), wanted_serial_number, curr_serial_extra_id, new_device); if(final_handlers == NULL) - final_handlers = cypress_driver_find_by_serial_number(usb_device_desc, wanted_serial_number, curr_serial_extra_id, new_device); + final_handlers = cypress_driver_find_by_serial_number(get_cy_usb_info(usb_device_desc), wanted_serial_number, curr_serial_extra_id, new_device); return final_handlers; } @@ -33,8 +45,8 @@ static int usb_find_free_fw_id(const cyni_device_usb_device* usb_device_desc) { bool found[num_free_fw_ids]; for(int i = 0; i < num_free_fw_ids; i++) found[i] = false; - cypress_libusb_find_used_serial(usb_device_desc, found, num_free_fw_ids, curr_serial_extra_id); - cypress_driver_find_used_serial(usb_device_desc, found, num_free_fw_ids, curr_serial_extra_id); + cypress_libusb_find_used_serial(get_cy_usb_info(usb_device_desc), found, num_free_fw_ids, curr_serial_extra_id); + cypress_driver_find_used_serial(get_cy_usb_info(usb_device_desc), found, num_free_fw_ids, curr_serial_extra_id); for(int i = 0; i < num_free_fw_ids; i++) if(!found[i]) @@ -42,48 +54,48 @@ static int usb_find_free_fw_id(const cyni_device_usb_device* usb_device_desc) { return 0; } -static cyni_device_device_handlers* usb_reconnect(const cyni_device_usb_device* usb_device_desc, CaptureDevice* device) { - cyni_device_device_handlers* final_handlers = NULL; +static cy_device_device_handlers* usb_reconnect(const cyni_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(usb_device_desc, device->serial_number, curr_serial_extra_id, NULL); + 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; } -std::string get_serial(const cyni_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) { - if(serial != "") +static std::string _cypress_nisetro_get_serial(const cyni_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) { + if((!usb_device_desc->has_bcd_device_serial) && (serial != "")) return serial; if(usb_device_desc->has_bcd_device_serial) return std::to_string(bcd_device & 0xFF); return std::to_string((curr_serial_extra_id++) + 1); } -static void cypress_nisetro_connection_end(cyni_device_device_handlers* handlers, const cyni_device_usb_device *device_desc, bool interface_claimed = true) { - if (handlers == NULL) - return; - if (handlers->usb_handle) - cypress_libusb_end_connection(handlers, device_desc, interface_claimed); - else - cypress_nisetro_driver_end_connection(handlers); - delete handlers; +std::string cypress_nisetro_get_serial(const void* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) { + if(usb_device_desc == NULL) + return ""; + return _cypress_nisetro_get_serial((const cyni_device_usb_device*)usb_device_desc, serial, bcd_device, curr_serial_extra_id); } -CaptureDevice cypress_create_device(const cyni_device_usb_device* usb_device_desc, std::string serial, std::string path) { +static CaptureDevice _cypress_nisetro_create_device(const cyni_device_usb_device* usb_device_desc, std::string serial, std::string path) { return CaptureDevice(serial, usb_device_desc->name, usb_device_desc->long_name, CAPTURE_CONN_CYPRESS_NISETRO, (void*)usb_device_desc, false, false, false, WIDTH_DS, HEIGHT_DS + HEIGHT_DS, 0, 0, 0, 0, 0, HEIGHT_DS, usb_device_desc->video_data_type, path); } -CaptureDevice cypress_create_device(const cyni_device_usb_device* usb_device_desc, std::string serial) { - return cypress_create_device(usb_device_desc, serial, ""); +CaptureDevice cypress_nisetro_create_device(const void* usb_device_desc, std::string serial, std::string path) { + if(usb_device_desc == NULL) + return CaptureDevice(); + return _cypress_nisetro_create_device((const cyni_device_usb_device*)usb_device_desc, serial, path); } -void cypress_insert_device(std::vector& devices_list, const cyni_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, get_serial(usb_device_desc, serial, bcd_device, curr_serial_extra_id), path)); -} - -void cypress_insert_device(std::vector& devices_list, const cyni_device_usb_device* usb_device_desc, std::string serial, uint16_t bcd_device, int& curr_serial_extra_id) { - devices_list.push_back(cypress_create_device(usb_device_desc, get_serial(usb_device_desc, serial, bcd_device, curr_serial_extra_id))); +static void cypress_nisetro_connection_end(cy_device_device_handlers* handlers, const cyni_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_nisetro_driver_end_connection(handlers); + delete handlers; } void list_devices_cyni_device(std::vector &devices_list, std::vector &no_access_list) { @@ -91,23 +103,24 @@ void list_devices_cyni_device(std::vector &devices_list, std::vec int* curr_serial_extra_id_cyni_device = new int[num_cyni_device_desc]; bool* no_access_elems = new bool[num_cyni_device_desc]; bool* not_supported_elems = new bool[num_cyni_device_desc]; + std::vector usb_devices_to_check; for (int i = 0; i < num_cyni_device_desc; i++) { no_access_elems[i] = false; not_supported_elems[i] = false; curr_serial_extra_id_cyni_device[i] = 0; + const cyni_device_usb_device* curr_device_desc = GetCyNiDeviceDesc(i); + 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_cyni_device, num_cyni_device_desc); + cypress_libusb_list_devices(devices_list, no_access_elems, not_supported_elems, curr_serial_extra_id_cyni_device, usb_devices_to_check); bool any_not_supported = false; for(int i = 0; i < num_cyni_device_desc; i++) any_not_supported |= not_supported_elems[i]; for(int i = 0; i < num_cyni_device_desc; i++) - if(no_access_elems[i]) { - const cyni_device_usb_device* usb_device = GetCyNiDeviceDesc(i); - no_access_list.emplace_back(usb_device->vid, usb_device->pid); - } + 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_cyni_device, num_cyni_device_desc); + cypress_driver_list_devices(devices_list, not_supported_elems, curr_serial_extra_id_cyni_device, usb_devices_to_check); delete[] curr_serial_extra_id_cyni_device; delete[] no_access_elems; @@ -116,7 +129,7 @@ void list_devices_cyni_device(std::vector &devices_list, std::vec bool cyni_device_connect_usb(bool print_failed, CaptureData* capture_data, CaptureDevice* device) { const cyni_device_usb_device* usb_device_info = (const cyni_device_usb_device*)device->descriptor; - cyni_device_device_handlers* handlers = usb_reconnect(usb_device_info, device); + 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; @@ -175,13 +188,13 @@ static int find_first_vsync_byte(CaptureReceived* capture_buf, size_t read_size) return pos; } -void cypress_output_to_thread(CaptureData* capture_data, int internal_index, std::chrono::time_point* clock_start, size_t read_size, size_t* scheduled_special_read, bool* recalibration_request) { +static void cypress_output_to_thread(CaptureData* capture_data, int internal_index, std::chrono::time_point* clock_start, size_t read_size, size_t* scheduled_special_read, bool* recalibration_request) { // Output to the other threads... CaptureDataSingleBuffer* data_buf = capture_data->data_buffers.GetWriterBuffer(internal_index); int offset = find_first_vsync_byte(&data_buf->capture_buf, read_size); const cyni_device_usb_device* usb_device_info = (const cyni_device_usb_device*)capture_data->status.device.descriptor; if(offset) { - if(offset % usb_device_info->max_usb_packet_size) + if(offset % get_cy_usb_info(usb_device_info)->max_usb_packet_size) *recalibration_request = true; else *scheduled_special_read = offset; @@ -198,14 +211,14 @@ void cypress_output_to_thread(CaptureData* capture_data, int internal_index, std capture_data->status.audio_wait.unlock(); } -int cypress_device_read_frame_and_output(CaptureData* capture_data, int internal_index, std::chrono::time_point &clock_start, size_t* scheduled_special_read, bool* recalibration_request) { +static int cypress_device_read_frame_and_output(CaptureData* capture_data, int internal_index, std::chrono::time_point &clock_start, size_t* scheduled_special_read, bool* recalibration_request) { const cyni_device_usb_device* usb_device_info = (const cyni_device_usb_device*)capture_data->status.device.descriptor; size_t read_size = cyni_device_get_video_in_size(usb_device_info->device_type); if(*scheduled_special_read) read_size = *scheduled_special_read; CaptureDataSingleBuffer* data_buf = capture_data->data_buffers.GetWriterBuffer(internal_index); uint8_t* buffer = (uint8_t*)&data_buf->capture_buf; - int ret = ReadFrame((cyni_device_device_handlers*)capture_data->handle, buffer, read_size, usb_device_info); + int ret = ReadFrame((cy_device_device_handlers*)capture_data->handle, buffer, read_size, usb_device_info); if (ret < 0) return ret; if(*scheduled_special_read) { @@ -216,7 +229,7 @@ int cypress_device_read_frame_and_output(CaptureData* capture_data, int internal return ret; } -int cypress_device_read_frame_request(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, uint32_t index) { +static int cypress_device_read_frame_request(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, uint32_t index) { if(cypress_device_capture_recv_data == NULL) return LIBUSB_SUCCESS; if((*cypress_device_capture_recv_data->status) < 0) { @@ -235,7 +248,7 @@ int cypress_device_read_frame_request(CaptureData* capture_data, CypressDeviceCa } CaptureDataSingleBuffer* data_buf = capture_data->data_buffers.GetWriterBuffer(cypress_device_capture_recv_data->cb_data.internal_index); uint8_t* buffer = (uint8_t*)&data_buf->capture_buf; - return ReadFrameAsync((cyni_device_device_handlers*)capture_data->handle, buffer, read_size, usb_device_info, &cypress_device_capture_recv_data->cb_data); + return ReadFrameAsync((cy_device_device_handlers*)capture_data->handle, buffer, read_size, usb_device_info, &cypress_device_capture_recv_data->cb_data); } static void end_cypress_device_read_frame_cb(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, bool early_release) { @@ -283,25 +296,25 @@ static void cypress_device_read_frame_cb(void* user_data, int transfer_length, i end_cypress_device_read_frame_cb(cypress_device_capture_recv_data, false); } -int cypress_device_get_num_free_buffers(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { +static int cypress_device_get_num_free_buffers(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { int num_free = 0; - for(int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) + for(int i = 0; i < NUM_NISETRO_CYPRESS_BUFFERS; i++) if(!cypress_device_capture_recv_data[i].in_use) num_free += 1; return num_free; } static void close_all_reads_error(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, bool &async_read_closed) { - cyni_device_device_handlers* handlers = (cyni_device_device_handlers*)capture_data->handle; + cy_device_device_handlers* handlers = (cy_device_device_handlers*)capture_data->handle; const cyni_device_usb_device* usb_device_desc = (const cyni_device_usb_device*)capture_data->status.device.descriptor; if(get_cypress_device_status(cypress_device_capture_recv_data) < 0) { if(!async_read_closed) { if(handlers->usb_handle) { - for (int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) - CloseAsyncRead(handlers, usb_device_desc, &cypress_device_capture_recv_data[i].cb_data); + for (int i = 0; i < NUM_NISETRO_CYPRESS_BUFFERS; i++) + CypressCloseAsyncRead(handlers, get_cy_usb_info(usb_device_desc), &cypress_device_capture_recv_data[i].cb_data); } else - CloseAsyncRead(handlers, usb_device_desc, &cypress_device_capture_recv_data[0].cb_data); + CypressCloseAsyncRead(handlers, get_cy_usb_info(usb_device_desc), &cypress_device_capture_recv_data[0].cb_data); async_read_closed = true; } } @@ -320,26 +333,26 @@ static void error_too_much_time_passed(CaptureData* capture_data, CypressDeviceC } } -void wait_all_cypress_device_buffers_free(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { +static void wait_all_cypress_device_buffers_free(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { if(cypress_device_capture_recv_data == NULL) return; - cyni_device_device_handlers* handlers = (cyni_device_device_handlers*)capture_data->handle; + cy_device_device_handlers* handlers = (cy_device_device_handlers*)capture_data->handle; bool async_read_closed = false; close_all_reads_error(capture_data, cypress_device_capture_recv_data, async_read_closed); const auto start_time = std::chrono::high_resolution_clock::now(); - for(int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) + for(int i = 0; i < NUM_NISETRO_CYPRESS_BUFFERS; i++) while(cypress_device_capture_recv_data[i].in_use) { error_too_much_time_passed(capture_data, cypress_device_capture_recv_data, async_read_closed, start_time); cypress_device_capture_recv_data[i].is_buffer_free_shared_mutex->specific_timed_lock(i); } } -void wait_one_cypress_device_buffer_free(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { - cyni_device_device_handlers* handlers = (cyni_device_device_handlers*)capture_data->handle; +static void wait_one_cypress_device_buffer_free(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { + cy_device_device_handlers* handlers = (cy_device_device_handlers*)capture_data->handle; bool done = false; const auto start_time = std::chrono::high_resolution_clock::now(); while(!done) { - for(int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) { + for(int i = 0; i < NUM_NISETRO_CYPRESS_BUFFERS; i++) { if(!cypress_device_capture_recv_data[i].in_use) done = true; } @@ -354,8 +367,8 @@ void wait_one_cypress_device_buffer_free(CaptureData* capture_data, CypressDevic } } -void wait_specific_cypress_device_buffer_free(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { - cyni_device_device_handlers* handlers = (cyni_device_device_handlers*)capture_data->handle; +static void wait_specific_cypress_device_buffer_free(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { + cy_device_device_handlers* handlers = (cy_device_device_handlers*)capture_data->handle; bool done = false; const auto start_time = std::chrono::high_resolution_clock::now(); while(!done) { @@ -372,15 +385,15 @@ void wait_specific_cypress_device_buffer_free(CaptureData* capture_data, Cypress } } -bool cypress_device_are_buffers_all_free(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { - return cypress_device_get_num_free_buffers(cypress_device_capture_recv_data) == NUM_CAPTURE_RECEIVED_DATA_BUFFERS; +static bool cypress_device_are_buffers_all_free(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { + return cypress_device_get_num_free_buffers(cypress_device_capture_recv_data) == NUM_NISETRO_CYPRESS_BUFFERS; } -CypressDeviceCaptureReceivedData* cypress_device_get_free_buffer(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { +static CypressDeviceCaptureReceivedData* cypress_device_get_free_buffer(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { wait_one_cypress_device_buffer_free(capture_data, cypress_device_capture_recv_data); if(get_cypress_device_status(cypress_device_capture_recv_data) < 0) return NULL; - for(int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) + for(int i = 0; i < NUM_NISETRO_CYPRESS_BUFFERS; i++) if(!cypress_device_capture_recv_data[i].in_use) { cypress_device_capture_recv_data[i].is_buffer_free_shared_mutex->specific_try_lock(i); cypress_device_capture_recv_data[i].in_use = true; @@ -389,20 +402,26 @@ CypressDeviceCaptureReceivedData* cypress_device_get_free_buffer(CaptureData* ca return NULL; } -int get_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { +static int get_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { return *cypress_device_capture_recv_data[0].status; } -void error_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, int error_val) { +static void error_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, int error_val) { if((error_val == 0) || (get_cypress_device_status(cypress_device_capture_recv_data) == 0)) *cypress_device_capture_recv_data[0].status = error_val; } -void reset_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { +static void exported_error_cypress_device_status(void* data, int error_val) { + if(data == NULL) + return; + return error_cypress_device_status((CypressDeviceCaptureReceivedData*)data, error_val); +} + +static void reset_cypress_device_status(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { error_cypress_device_status(cypress_device_capture_recv_data, 0); } -void recalibration_reads(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, CypressDeviceCaptureReceivedData* chosen_buffer, uint32_t &index) { +static void recalibration_reads(cy_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, CypressDeviceCaptureReceivedData* chosen_buffer, uint32_t &index) { // Enforce properly synchronized reads. // Reduces complexity and latency, at the cost of some extra // time between lid reopening and visible video output. @@ -441,7 +460,7 @@ void recalibration_reads(cyni_device_device_handlers* handlers, const cyni_devic } static bool cyni_device_acquisition_loop(CaptureData* capture_data, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { - cyni_device_device_handlers* handlers = (cyni_device_device_handlers*)capture_data->handle; + cy_device_device_handlers* handlers = (cy_device_device_handlers*)capture_data->handle; const cyni_device_usb_device* usb_device_desc = (const cyni_device_usb_device*)capture_data->status.device.descriptor; uint32_t index = 0; int ret = capture_start(handlers, usb_device_desc); @@ -449,9 +468,9 @@ static bool cyni_device_acquisition_loop(CaptureData* capture_data, CypressDevic capture_error_print(true, capture_data, "Capture Start: Failed"); return false; } - SetMaxTransferSize(handlers, usb_device_desc, cyni_device_get_video_in_size(usb_device_desc->device_type)); + CypressSetMaxTransferSize(handlers, get_cy_usb_info(usb_device_desc), cyni_device_get_video_in_size(usb_device_desc->device_type)); auto clock_last_reset = std::chrono::high_resolution_clock::now(); - for(int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) { + for(int i = 0; i < NUM_NISETRO_CYPRESS_BUFFERS; i++) { CypressDeviceCaptureReceivedData* chosen_buffer = cypress_device_get_free_buffer(capture_data, cypress_device_capture_recv_data); ret = cypress_device_read_frame_request(capture_data, chosen_buffer, index++); if(ret < 0) { @@ -474,7 +493,7 @@ static bool cyni_device_acquisition_loop(CaptureData* capture_data, CypressDevic *cypress_device_capture_recv_data[0].recalibration_request = false; *cypress_device_capture_recv_data[0].scheduled_special_read = 0; *cypress_device_capture_recv_data[0].is_active_special_read = false; - pipe_reset_bulk_in(handlers, usb_device_desc); + cypress_pipe_reset_bulk_in(handlers, get_cy_usb_info(usb_device_desc)); reset_cypress_device_status(cypress_device_capture_recv_data); default_sleep(100); } @@ -500,14 +519,13 @@ void cyni_device_acquisition_main_loop(CaptureData* capture_data) { if(!usb_is_initialized()) return; bool is_done_thread; - ConsumerMutex has_data_been_processed; std::thread async_processing_thread; - cyni_device_device_handlers* handlers = (cyni_device_device_handlers*)capture_data->handle; + cy_device_device_handlers* handlers = (cy_device_device_handlers*)capture_data->handle; const cyni_device_usb_device* usb_device_desc = (const cyni_device_usb_device*)capture_data->status.device.descriptor; uint32_t last_index = -1; int status = 0; - cyni_async_callback_data* cb_queue[NUM_CAPTURE_RECEIVED_DATA_BUFFERS]; + std::vector cb_queue; int queue_elems = 0; size_t scheduled_special_read = 0; uint32_t active_special_read_index = 0; @@ -516,12 +534,12 @@ void cyni_device_acquisition_main_loop(CaptureData* capture_data) { bool recalibration_request = false; int errors_since_last_output = 0; int consecutive_output_to_thread = 0; - SharedConsumerMutex is_buffer_free_shared_mutex(NUM_CAPTURE_RECEIVED_DATA_BUFFERS); - SharedConsumerMutex is_transfer_done_shared_mutex(NUM_CAPTURE_RECEIVED_DATA_BUFFERS); - SharedConsumerMutex is_transfer_data_ready_shared_mutex(NUM_CAPTURE_RECEIVED_DATA_BUFFERS); + SharedConsumerMutex is_buffer_free_shared_mutex(NUM_NISETRO_CYPRESS_BUFFERS); + SharedConsumerMutex is_transfer_done_shared_mutex(NUM_NISETRO_CYPRESS_BUFFERS); + SharedConsumerMutex is_transfer_data_ready_shared_mutex(NUM_NISETRO_CYPRESS_BUFFERS); std::chrono::time_point clock_start = std::chrono::high_resolution_clock::now(); - CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data = new CypressDeviceCaptureReceivedData[NUM_CAPTURE_RECEIVED_DATA_BUFFERS]; - for(int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) { + CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data = new CypressDeviceCaptureReceivedData[NUM_NISETRO_CYPRESS_BUFFERS]; + for(int i = 0; i < NUM_NISETRO_CYPRESS_BUFFERS; i++) { cypress_device_capture_recv_data[i].in_use = false; cypress_device_capture_recv_data[i].index = i; cypress_device_capture_recv_data[i].capture_data = capture_data; @@ -540,11 +558,14 @@ void cyni_device_acquisition_main_loop(CaptureData* capture_data) { cypress_device_capture_recv_data[i].cb_data.is_transfer_done_mutex = &is_transfer_done_shared_mutex; cypress_device_capture_recv_data[i].cb_data.internal_index = i; cypress_device_capture_recv_data[i].cb_data.is_transfer_data_ready_mutex = &is_transfer_data_ready_shared_mutex; + cypress_device_capture_recv_data[i].cb_data.in_use_ptr = &cypress_device_capture_recv_data[i].in_use; + cypress_device_capture_recv_data[i].cb_data.error_function = exported_error_cypress_device_status; + cb_queue.push_back(&cypress_device_capture_recv_data[i].cb_data); } - SetupCypressDeviceAsyncThread(handlers, cypress_device_capture_recv_data, &async_processing_thread, &is_done_thread, &has_data_been_processed); + CypressSetupCypressDeviceAsyncThread(handlers, cb_queue, &async_processing_thread, &is_done_thread); bool proper_return = cyni_device_acquisition_loop(capture_data, cypress_device_capture_recv_data); wait_all_cypress_device_buffers_free(capture_data, cypress_device_capture_recv_data); - EndCypressDeviceAsyncThread(handlers, cypress_device_capture_recv_data, &async_processing_thread, &is_done_thread, &has_data_been_processed); + CypressEndCypressDeviceAsyncThread(handlers, cb_queue, &async_processing_thread, &is_done_thread); delete []cypress_device_capture_recv_data; if(proper_return) @@ -554,9 +575,9 @@ void cyni_device_acquisition_main_loop(CaptureData* capture_data) { void usb_cyni_device_acquisition_cleanup(CaptureData* capture_data) { if(!usb_is_initialized()) return; - for(int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) + for(int i = 0; i < NUM_NISETRO_CYPRESS_BUFFERS; i++) capture_data->data_buffers.ReleaseWriterBuffer(i, false); - cypress_nisetro_connection_end((cyni_device_device_handlers*)capture_data->handle, (const cyni_device_usb_device*)capture_data->status.device.descriptor); + cypress_nisetro_connection_end((cy_device_device_handlers*)capture_data->handle, (const cyni_device_usb_device*)capture_data->status.device.descriptor); capture_data->handle = NULL; } void usb_cyni_device_init() { diff --git a/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_communications.cpp b/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_communications.cpp index 4fa26ab..49bb0ae 100644 --- a/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_communications.cpp +++ b/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_communications.cpp @@ -1,7 +1,6 @@ #include "frontend.hpp" #include "cypress_nisetro_communications.hpp" -#include "cypress_nisetro_libusb_comms.hpp" -#include "cypress_nisetro_driver_comms.hpp" +#include "cypress_shared_communications.hpp" #include "cypress_nisetro_acquisition_general.hpp" #include "nisetro_ds_fw.h" #include "usb_generic.hpp" @@ -33,32 +32,46 @@ static const cyni_device_usb_device cypress_fx2_generic_device = { .name = "EZ-USB FX2", .long_name = "EZ-USB FX2", -.vid = 0x04B4, .pid = 0x8613, -.default_config = 1, .default_interface = 0, -.bulk_timeout = 500, -.ep_ctrl_bulk_in = 0, .ep_ctrl_bulk_out = 0, -.ep_bulk_in = 0, .device_type = CYPRESS_NISETRO_BLANK_DEVICE, -.video_data_type = VIDEO_DATA_RGB, .max_usb_packet_size = CYPRESS_BASE_USB_PACKET_LIMIT, -.do_pipe_clear_reset = false, +.video_data_type = VIDEO_DATA_RGB, .firmware_to_load = nisetro_ds_fw, .firmware_size = nisetro_ds_fw_len, .next_device = CYPRESS_NISETRO_DS_DEVICE, -.has_bcd_device_serial = false, .alt_interface = 1 +.has_bcd_device_serial = false, +.usb_device_info = { + .vid = 0x04B4, .pid = 0x8613, + .default_config = 1, .default_interface = 0, + .bulk_timeout = 500, + .ep_ctrl_bulk_in = 0, .ep_ctrl_bulk_out = 0, + .ep_bulk_in = 0, + .max_usb_packet_size = CYPRESS_BASE_USB_PACKET_LIMIT, + .do_pipe_clear_reset = false, + .alt_interface = 1, + .full_data = &cypress_fx2_generic_device, + .get_serial_fn = cypress_nisetro_get_serial, + .create_device_fn = cypress_nisetro_create_device +} }; static const cyni_device_usb_device cypress_fx2_nisetro_ds_device = { .name = "Nisetro DS", .long_name = "Nisetro DS", -.vid = 0x04B4, .pid = 0x1004, -.default_config = 1, .default_interface = 0, -.bulk_timeout = 500, -.ep_ctrl_bulk_in = 1 | LIBUSB_ENDPOINT_IN, .ep_ctrl_bulk_out = 1 | LIBUSB_ENDPOINT_OUT, -.ep_bulk_in = 6 | LIBUSB_ENDPOINT_IN, .device_type = CYPRESS_NISETRO_DS_DEVICE, -.video_data_type = VIDEO_DATA_RGB, .max_usb_packet_size = CYPRESS_NISETRO_USB_PACKET_LIMIT, -.do_pipe_clear_reset = true, +.video_data_type = VIDEO_DATA_RGB, .firmware_to_load = NULL, .firmware_size = 0, .next_device = CYPRESS_NISETRO_DS_DEVICE, -.has_bcd_device_serial = true, .alt_interface = 0 +.has_bcd_device_serial = true, +.usb_device_info = { + .vid = 0x04B4, .pid = 0x1004, + .default_config = 1, .default_interface = 0, + .bulk_timeout = 500, + .ep_ctrl_bulk_in = 1 | LIBUSB_ENDPOINT_IN, .ep_ctrl_bulk_out = 1 | LIBUSB_ENDPOINT_OUT, + .ep_bulk_in = 6 | LIBUSB_ENDPOINT_IN, + .max_usb_packet_size = CYPRESS_NISETRO_USB_PACKET_LIMIT, + .do_pipe_clear_reset = true, + .alt_interface = 0, + .full_data = &cypress_fx2_nisetro_ds_device, + .get_serial_fn = cypress_nisetro_get_serial, + .create_device_fn = cypress_nisetro_create_device +} }; static const cyni_device_usb_device* all_usb_cyni_device_devices_desc[] = { @@ -66,58 +79,8 @@ static const cyni_device_usb_device* all_usb_cyni_device_devices_desc[] = { &cypress_fx2_nisetro_ds_device, }; -static int ctrl_in_transfer(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, uint8_t request, uint16_t value, uint16_t index, int* transferred) { - if(handlers->usb_handle) - return cypress_libusb_ctrl_in(handlers, usb_device_desc, buf, length, request, value, index, transferred); - return cypress_driver_ctrl_transfer_in(handlers, buf, length, value, index, request, transferred); -} - -static int ctrl_out_transfer(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, uint8_t request, uint16_t value, uint16_t index, int* transferred) { - if(handlers->usb_handle) - return cypress_libusb_ctrl_out(handlers, usb_device_desc, buf, length, request, value, index, transferred); - return cypress_driver_ctrl_transfer_out(handlers, buf, length, value, index, request, transferred); -} - -static int bulk_in_transfer(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) { - if(handlers->usb_handle) - return cypress_libusb_bulk_in(handlers, usb_device_desc, buf, length, transferred); - return cypress_driver_bulk_in(handlers, usb_device_desc, buf, length, transferred); -} - -static int bulk_in_async(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t *buf, int length, cyni_async_callback_data* cb_data) { - if(handlers->usb_handle) - return cypress_libusb_async_in_start(handlers, usb_device_desc, buf, length, cb_data); - return cypress_driver_async_in_start(handlers, usb_device_desc, buf, length, cb_data); -} - -static int ctrl_bulk_in_transfer(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) { - 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); -} - -static int ctrl_bulk_out_transfer(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) { - if(handlers->usb_handle) - return cypress_libusb_ctrl_bulk_out(handlers, usb_device_desc, buf, length, transferred); - return cypress_driver_ctrl_bulk_out(handlers, usb_device_desc, buf, length, transferred); -} - -void pipe_reset_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc) { - if(handlers->usb_handle) - return cypress_libusb_pipe_reset_bulk_in(handlers, usb_device_desc); - return cypress_driver_pipe_reset_bulk_in(handlers, usb_device_desc); -} - -static void pipe_reset_ctrl_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc) { - 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); -} - -static void pipe_reset_ctrl_bulk_out(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc) { - 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); +const cy_device_usb_device* get_cy_usb_info(const cyni_device_usb_device* usb_device_desc) { + return &usb_device_desc->usb_device_info; } int GetNumCyNiDeviceDesc() { @@ -143,7 +106,7 @@ bool has_to_load_firmware(const cyni_device_usb_device* device) { return !((device->firmware_to_load == NULL) || (device->firmware_size == 0)); } -bool load_firmware(cyni_device_device_handlers* handlers, const cyni_device_usb_device* device, uint8_t patch_id) { +bool load_firmware(cy_device_device_handlers* handlers, const cyni_device_usb_device* device, uint8_t patch_id) { if(!has_to_load_firmware(device)) return true; int transferred = 0; @@ -156,7 +119,7 @@ bool load_firmware(cyni_device_device_handlers* handlers, const cyni_device_usb_ } uint8_t buffer[0x8000]; buffer[0] = 1; - int ret = ctrl_out_transfer(handlers, device, buffer, 1, 0xA0, 0xE600, 0, &transferred); + int ret = cypress_ctrl_out_transfer(handlers, get_cy_usb_info(device), buffer, 1, 0xA0, 0xE600, 0, &transferred); if(ret < 0) { delete []fw_data; return false; @@ -175,7 +138,7 @@ bool load_firmware(cyni_device_device_handlers* handlers, const cyni_device_usb_ } memcpy(buffer, fw_data + fw_pos, inside_len); fw_pos += inside_len; - ret = ctrl_out_transfer(handlers, device, buffer, inside_len, 0xA0, offset, 0, &transferred); + ret = cypress_ctrl_out_transfer(handlers, get_cy_usb_info(device), buffer, inside_len, 0xA0, offset, 0, &transferred); if(ret < 0) { delete []fw_data; return false; @@ -185,73 +148,49 @@ bool load_firmware(cyni_device_device_handlers* handlers, const cyni_device_usb_ return true; } -int capture_start(cyni_device_device_handlers* handlers, const cyni_device_usb_device* device) { +int capture_start(cy_device_device_handlers* handlers, const cyni_device_usb_device* device) { uint8_t buffer[] = { CMD_PORT_CFG, 0x07, PIO_RESET | PIO_DIR, CMD_MODE_IDLE, CMD_IFCONFIG, 0xE3, CMD_REG_WRITE, 0, 0x08, CMD_MODE_IDLE}; int transferred = 0; - pipe_reset_ctrl_bulk_in(handlers, device); - pipe_reset_ctrl_bulk_out(handlers, device); - int ret = ctrl_bulk_out_transfer(handlers, device, buffer, sizeof(buffer), &transferred); + cypress_pipe_reset_ctrl_bulk_in(handlers, get_cy_usb_info(device)); + cypress_pipe_reset_ctrl_bulk_out(handlers, get_cy_usb_info(device)); + int ret = cypress_ctrl_bulk_out_transfer(handlers, get_cy_usb_info(device), buffer, sizeof(buffer), &transferred); if(ret < 0) return ret; - pipe_reset_bulk_in(handlers, device); + cypress_pipe_reset_bulk_in(handlers, get_cy_usb_info(device)); return ret; } -int StartCaptureDma(cyni_device_device_handlers* handlers, const cyni_device_usb_device* device) { +int StartCaptureDma(cy_device_device_handlers* handlers, const cyni_device_usb_device* device) { uint8_t buffer[] = { CMD_PORT_WRITE, PIO_RESET, CMD_EP6IN_START, CMD_PORT_WRITE, 0}; int transferred = 0; - return ctrl_bulk_out_transfer(handlers, device, buffer, sizeof(buffer), &transferred); + return cypress_ctrl_bulk_out_transfer(handlers, get_cy_usb_info(device), buffer, sizeof(buffer), &transferred); } -int capture_end(cyni_device_device_handlers* handlers, const cyni_device_usb_device* device) { +int capture_end(cy_device_device_handlers* handlers, const cyni_device_usb_device* device) { int transferred = 0; uint8_t buffer[] = { CMD_PORT_WRITE, 0, CMD_EP6IN_STOP, CMD_MODE_IDLE}; - int ret = ctrl_bulk_out_transfer(handlers, device, buffer, sizeof(buffer), &transferred); + int ret = cypress_ctrl_bulk_out_transfer(handlers, get_cy_usb_info(device), buffer, sizeof(buffer), &transferred); if(ret < 0) return ret; uint8_t buffer2[] = { CMD_REG_READ, 0, CMD_REG_READ, 1, CMD_REG_READ, 2, CMD_REG_READ, 3, CMD_REG_READ, 4, CMD_REG_READ, 5, CMD_REG_READ, 6, CMD_REG_READ, 7}; - ret = ctrl_bulk_out_transfer(handlers, device, buffer2, sizeof(buffer2), &transferred); + ret = cypress_ctrl_bulk_out_transfer(handlers, get_cy_usb_info(device), buffer2, sizeof(buffer2), &transferred); if(ret < 0) return ret; - pipe_reset_ctrl_bulk_in(handlers, device); - return ctrl_bulk_in_transfer(handlers, device, buffer2, 8, &transferred); + cypress_pipe_reset_ctrl_bulk_in(handlers, get_cy_usb_info(device)); + return cypress_ctrl_bulk_in_transfer(handlers, get_cy_usb_info(device), buffer2, 8, &transferred); } -void SetMaxTransferSize(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, size_t new_max_transfer_size) { - if(handlers->usb_handle) - return; - cypress_driver_set_transfer_size_bulk_in(handlers, usb_device_desc, new_max_transfer_size); -} - -int ReadFrame(cyni_device_device_handlers* handlers, uint8_t* buf, int length, const cyni_device_usb_device* device_desc) { +int ReadFrame(cy_device_device_handlers* handlers, uint8_t* buf, int length, const cyni_device_usb_device* device_desc) { // Maybe making this async would be better for lower end hardware... int num_bytes = 0; - int ret = bulk_in_transfer(handlers, device_desc, buf, length, &num_bytes); + int ret = cypress_bulk_in_transfer(handlers, get_cy_usb_info(device_desc), buf, length, &num_bytes); if(num_bytes != length) return LIBUSB_ERROR_INTERRUPTED; return ret; } -int ReadFrameAsync(cyni_device_device_handlers* handlers, uint8_t* buf, int length, const cyni_device_usb_device* device_desc, cyni_async_callback_data* cb_data) { - return bulk_in_async(handlers, device_desc, buf, length, cb_data); -} - -void CloseAsyncRead(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, cyni_async_callback_data* cb_data) { - if(handlers->usb_handle) - return cypress_libusb_cancell_callback(cb_data); - return cypress_driver_cancel_callback(handlers, usb_device_desc, cb_data); -} - -void SetupCypressDeviceAsyncThread(cyni_device_device_handlers* handlers, void* user_data, std::thread* thread_ptr, bool* keep_going, ConsumerMutex* is_data_ready) { - if(handlers->usb_handle) - return libusb_register_to_event_thread(); - return cypress_driver_start_thread(thread_ptr, keep_going, (CypressDeviceCaptureReceivedData*)user_data, handlers, is_data_ready); -} - -void EndCypressDeviceAsyncThread(cyni_device_device_handlers* handlers, void* user_data, std::thread* thread_ptr, bool* keep_going, ConsumerMutex* is_data_ready) { - if(handlers->usb_handle) - return libusb_unregister_from_event_thread(); - return cypress_driver_close_thread(thread_ptr, keep_going, (CypressDeviceCaptureReceivedData*)user_data); +int ReadFrameAsync(cy_device_device_handlers* handlers, uint8_t* buf, int length, const cyni_device_usb_device* device_desc, cy_async_callback_data* cb_data) { + return cypress_bulk_in_async(handlers, get_cy_usb_info(device_desc), buf, length, cb_data); } diff --git a/source/CaptureDeviceSpecific/Nisetro/cypress_shared_communications.cpp b/source/CaptureDeviceSpecific/Nisetro/cypress_shared_communications.cpp new file mode 100644 index 0000000..6b66058 --- /dev/null +++ b/source/CaptureDeviceSpecific/Nisetro/cypress_shared_communications.cpp @@ -0,0 +1,101 @@ +#include "frontend.hpp" +#include "cypress_shared_communications.hpp" +#include "cypress_shared_libusb_comms.hpp" +#include "cypress_shared_driver_comms.hpp" +#include "usb_generic.hpp" + +#include +#include +#include +#include +#include + +CaptureDevice cypress_create_device(const cy_device_usb_device* usb_device_desc, std::string serial, std::string path) { + 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); +} + +void cypress_insert_device(std::vector& 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)); +} + +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) { + if(handlers->usb_handle) + return cypress_libusb_ctrl_in(handlers, usb_device_desc, buf, length, request, value, index, transferred); + return cypress_driver_ctrl_transfer_in(handlers, buf, length, value, index, request, 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) { + if(handlers->usb_handle) + return cypress_libusb_ctrl_out(handlers, usb_device_desc, buf, length, request, value, index, transferred); + return cypress_driver_ctrl_transfer_out(handlers, buf, length, value, index, request, 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) { + if(handlers->usb_handle) + return cypress_libusb_bulk_in(handlers, usb_device_desc, buf, length, transferred); + return cypress_driver_bulk_in(handlers, usb_device_desc, buf, length, 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) { + if(handlers->usb_handle) + return cypress_libusb_async_in_start(handlers, usb_device_desc, buf, length, cb_data); + 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) { + 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); +} + +int cypress_ctrl_bulk_out_transfer(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) { + if(handlers->usb_handle) + return cypress_libusb_ctrl_bulk_out(handlers, usb_device_desc, buf, length, transferred); + return cypress_driver_ctrl_bulk_out(handlers, usb_device_desc, buf, length, transferred); +} + +void cypress_pipe_reset_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) { + if(handlers->usb_handle) + return cypress_libusb_pipe_reset_bulk_in(handlers, usb_device_desc); + 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) { + 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); +} + +void cypress_pipe_reset_ctrl_bulk_out(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) { + 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); +} + +void CypressSetMaxTransferSize(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, size_t new_max_transfer_size) { + if(handlers->usb_handle) + return; + cypress_driver_set_transfer_size_bulk_in(handlers, usb_device_desc, 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) { + if(handlers->usb_handle) + return cypress_libusb_cancell_callback(cb_data); + return cypress_driver_cancel_callback(handlers, usb_device_desc, cb_data); +} + +void CypressSetupCypressDeviceAsyncThread(cy_device_device_handlers* handlers, std::vector &cb_data_vector, std::thread* thread_ptr, bool* keep_going) { + if(handlers->usb_handle) + return libusb_register_to_event_thread(); + return cypress_driver_start_thread(thread_ptr, keep_going, cb_data_vector, handlers); +} + +void CypressEndCypressDeviceAsyncThread(cy_device_device_handlers* handlers, std::vector &cb_data_vector, std::thread* thread_ptr, bool* keep_going) { + if(handlers->usb_handle) + return libusb_unregister_from_event_thread(); + return cypress_driver_close_thread(thread_ptr, keep_going, cb_data_vector); +} diff --git a/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_driver_comms.cpp b/source/CaptureDeviceSpecific/Nisetro/cypress_shared_driver_comms.cpp similarity index 79% rename from source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_driver_comms.cpp rename to source/CaptureDeviceSpecific/Nisetro/cypress_shared_driver_comms.cpp index c4871ed..983b146 100644 --- a/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_driver_comms.cpp +++ b/source/CaptureDeviceSpecific/Nisetro/cypress_shared_driver_comms.cpp @@ -1,5 +1,4 @@ -#include "cypress_nisetro_driver_comms.hpp" -#include "cypress_nisetro_acquisition_general.hpp" +#include "cypress_shared_driver_comms.hpp" #include #include @@ -140,26 +139,19 @@ struct PACKED CYPRESS_SET_TRANSFER_SIZE_INFO { static GUID cypress_driver_guid = {.Data1 = 0xae18aa60, .Data2 = 0x7f6a, .Data3 = 0x11d4, .Data4 = {0x97, 0xdd, 0x0, 0x1, 0x2, 0x29, 0xb9, 0x59}}; -static void cypress_driver_wait_async_transfers(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { - HANDLE to_wait_array[NUM_CAPTURE_RECEIVED_DATA_BUFFERS]; - for(int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) - to_wait_array[i] = ((OVERLAPPED*)cypress_device_capture_recv_data[i].cb_data.base_transfer_data)->hEvent; - WaitForMultipleObjects(NUM_CAPTURE_RECEIVED_DATA_BUFFERS, to_wait_array, false, 300); -} - -static bool cypress_driver_process_async_transfers(CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, cyni_device_device_handlers* handlers) { +static bool cypress_driver_process_async_transfers(std::vector *cb_data_vector, cy_device_device_handlers* handlers) { bool found = false; - for (int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) { - cyni_async_callback_data* cb_data = (cyni_async_callback_data*)&cypress_device_capture_recv_data[i].cb_data; + for (int i = 0; i < cb_data_vector->size(); i++) { + cy_async_callback_data* cb_data = cb_data_vector->at(i); bool possible_result = false; bool is_data_ready = false; cb_data->transfer_data_access.lock(); possible_result = cb_data->transfer_data != NULL; is_data_ready = cb_data->is_data_ready; cb_data->transfer_data_access.unlock(); - if(cypress_device_capture_recv_data[i].in_use && is_data_ready) + if((*cb_data->in_use_ptr) && is_data_ready) found = true; - if(cypress_device_capture_recv_data[i].in_use && possible_result) { + if((*cb_data->in_use_ptr) && possible_result) { DWORD bytes_transferred = 0; int error = 0; if(!GetOverlappedResult(handlers->read_handle, (OVERLAPPED*)cb_data->transfer_data, &bytes_transferred, false)) @@ -168,7 +160,7 @@ static bool cypress_driver_process_async_transfers(CypressDeviceCaptureReceivedD const auto curr_time = std::chrono::high_resolution_clock::now(); const std::chrono::duration diff = curr_time - cb_data->start_request; if(diff.count() > cb_data->timeout_s) - error_cypress_device_status(cypress_device_capture_recv_data, LIBUSB_ERROR_TIMEOUT); + cb_data->error_function(cb_data->actual_user_data, LIBUSB_ERROR_TIMEOUT); } if(error != ERROR_IO_INCOMPLETE) { CYPRESS_SINGLE_TRANSFER* transfer_info = (CYPRESS_SINGLE_TRANSFER*)cb_data->extra_transfer_data; @@ -188,25 +180,30 @@ static bool cypress_driver_process_async_transfers(CypressDeviceCaptureReceivedD return found; } -static void cypress_driver_function(bool* usb_thread_run, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, cyni_device_device_handlers* handlers) { +static void cypress_driver_function(bool* usb_thread_run, std::vector *cb_data_vector, cy_device_device_handlers* handlers) { int ret = 0; + HANDLE* to_wait_array = new HANDLE[cb_data_vector->size()]; + for(int i = 0; i < cb_data_vector->size(); i++) + to_wait_array[i] = ((OVERLAPPED*)cb_data_vector->at(i)->base_transfer_data)->hEvent; + while(*usb_thread_run) { - if(cypress_driver_process_async_transfers(cypress_device_capture_recv_data, handlers)) { - for (int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) { - cyni_async_callback_data* cb_data = (cyni_async_callback_data*)&cypress_device_capture_recv_data[i].cb_data; + if(cypress_driver_process_async_transfers(cb_data_vector, handlers)) { + for (int i = 0; i < cb_data_vector->size(); i++) { + cy_async_callback_data* cb_data = cb_data_vector->at(i); bool is_data_ready = false; cb_data->transfer_data_access.lock(); is_data_ready = cb_data->is_data_ready; cb_data->transfer_data_access.unlock(); - if(cypress_device_capture_recv_data[i].in_use && is_data_ready) { + if((*cb_data->in_use_ptr) && is_data_ready) { cb_data->is_data_ready = false; - cb_data->function(&cypress_device_capture_recv_data[i], cb_data->actual_length, cb_data->status_value); + cb_data->function(cb_data->actual_user_data, cb_data->actual_length, cb_data->status_value); } } } else - cypress_driver_wait_async_transfers(cypress_device_capture_recv_data); + WaitForMultipleObjects(cb_data_vector->size(), to_wait_array, false, 300); } + delete []to_wait_array; } static bool cypress_driver_bulk_async_start(HANDLE handle, uint8_t* buffer, size_t size, DWORD* num_read, uint8_t ep_num, OVERLAPPED* overlap, CYPRESS_SINGLE_TRANSFER* single_transfer) { @@ -298,7 +295,7 @@ static bool cypress_driver_get_string_info(HANDLE handle, UCHAR string_index, US bytes = num_read; uint8_t signature = buffer[1]; if((signature == 3) && (bytes > 2)) - out_str = read_string(buffer, bytes - 2); + out_str = read_string(buffer + 2, bytes - 2); } delete []buffer; return retval; @@ -359,7 +356,7 @@ static bool cypress_driver_get_device_pid_vid_manufacturer_serial_number(std::st return true; } -static bool cypress_nisetro_driver_setup_connection(cyni_device_device_handlers* handlers, std::string path, bool do_pipe_clear_reset) { +static bool cypress_nisetro_driver_setup_connection(cy_device_device_handlers* handlers, std::string path, bool do_pipe_clear_reset) { handlers->usb_handle = NULL; handlers->mutex = NULL; handlers->write_handle = INVALID_HANDLE_VALUE; @@ -407,14 +404,14 @@ static void cypress_driver_pipe_reset(HANDLE handle, uint8_t endpoint) { #endif -cyni_device_device_handlers* cypress_driver_serial_reconnection(CaptureDevice* device) { - cyni_device_device_handlers* final_handlers = NULL; +cy_device_device_handlers* cypress_driver_serial_reconnection(CaptureDevice* device) { + cy_device_device_handlers* final_handlers = NULL; #ifdef _WIN32 if(device->path != "") { - cyni_device_device_handlers handlers; - const cyni_device_usb_device* usb_device_info = (const cyni_device_usb_device*)device->descriptor; + cy_device_device_handlers handlers; + const cy_device_usb_device* usb_device_info = (const cy_device_usb_device*)device->descriptor; if(cypress_nisetro_driver_setup_connection(&handlers, device->path, usb_device_info->do_pipe_clear_reset)) { - final_handlers = new cyni_device_device_handlers; + final_handlers = new cy_device_device_handlers; final_handlers->usb_handle = NULL; final_handlers->mutex = handlers.mutex; final_handlers->read_handle = handlers.read_handle; @@ -428,7 +425,7 @@ cyni_device_device_handlers* cypress_driver_serial_reconnection(CaptureDevice* d return final_handlers; } -void cypress_driver_list_devices(std::vector &devices_list, bool* not_supported_elems, int *curr_serial_extra_id_cypress, const size_t num_cypress_desc) { +void cypress_driver_list_devices(std::vector &devices_list, bool* not_supported_elems, int *curr_serial_extra_id_cypress, std::vector &device_descriptions) { #ifdef _WIN32 HDEVINFO DeviceInfoSet = SetupDiGetClassDevs( &cypress_driver_guid, @@ -451,10 +448,10 @@ void cypress_driver_list_devices(std::vector &devices_list, bool* std::string serial; if(!cypress_driver_get_device_pid_vid_manufacturer_serial_number(path, vid, pid, manufacturer, serial, bcd_device)) continue; - for (int j = 0; j < num_cypress_desc; j++) { - const cyni_device_usb_device* usb_device_desc = GetCyNiDeviceDesc(j); + 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)) { - cyni_device_device_handlers handlers; + cy_device_device_handlers handlers; bool result_conn_check = cypress_nisetro_driver_setup_connection(&handlers, path, usb_device_desc->do_pipe_clear_reset); cypress_nisetro_driver_end_connection(&handlers); if(result_conn_check) @@ -469,8 +466,8 @@ void cypress_driver_list_devices(std::vector &devices_list, bool* #endif } -cyni_device_device_handlers* cypress_driver_find_by_serial_number(const cyni_device_usb_device* usb_device_desc, std::string wanted_serial_number, int &curr_serial_extra_id, CaptureDevice* new_device) { - cyni_device_device_handlers* final_handlers = NULL; +cy_device_device_handlers* cypress_driver_find_by_serial_number(const cy_device_usb_device* usb_device_desc, std::string wanted_serial_number, int &curr_serial_extra_id, CaptureDevice* new_device) { + cy_device_device_handlers* final_handlers = NULL; #ifdef _WIN32 HDEVINFO DeviceInfoSet = SetupDiGetClassDevs( &cypress_driver_guid, @@ -493,11 +490,11 @@ cyni_device_device_handlers* cypress_driver_find_by_serial_number(const cyni_dev std::string serial; if(!cypress_driver_get_device_pid_vid_manufacturer_serial_number(path, vid, pid, manufacturer, serial, bcd_device)) continue; - std::string read_serial = get_serial(usb_device_desc, serial, bcd_device, curr_serial_extra_id); + 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)) { - cyni_device_device_handlers handlers; + cy_device_device_handlers handlers; if(cypress_nisetro_driver_setup_connection(&handlers, path, usb_device_desc->do_pipe_clear_reset)) { - final_handlers = new cyni_device_device_handlers; + final_handlers = new cy_device_device_handlers; final_handlers->usb_handle = NULL; final_handlers->mutex = handlers.mutex; final_handlers->read_handle = handlers.read_handle; @@ -518,7 +515,7 @@ cyni_device_device_handlers* cypress_driver_find_by_serial_number(const cyni_dev return final_handlers; } -int cypress_driver_ctrl_transfer_in(cyni_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_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) { #ifdef _WIN32 DWORD dummy = 0; bool retval = cypress_driver_generic_ctrl_transfer(handlers->read_handle, buffer, inner_size, (value >> 8) & 0xFF, value & 0xFF, index, 1, TARGET_DEVICE, REQUEST_VENDOR, DIR_DEVICE_TO_HOST, request_code, &dummy); @@ -529,7 +526,7 @@ int cypress_driver_ctrl_transfer_in(cyni_device_device_handlers* handlers, uint8 #endif } -int cypress_driver_ctrl_transfer_out(cyni_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) { #ifdef _WIN32 DWORD dummy = 0; bool retval = cypress_driver_generic_ctrl_transfer(handlers->write_handle, buffer, inner_size, (value >> 8) & 0xFF, value & 0xFF, index, 1, TARGET_DEVICE, REQUEST_VENDOR, DIR_HOST_TO_DEVICE, request_code, &dummy); @@ -540,7 +537,7 @@ int cypress_driver_ctrl_transfer_out(cyni_device_device_handlers* handlers, uint #endif } -void cypress_nisetro_driver_end_connection(cyni_device_device_handlers* handlers) { +void cypress_nisetro_driver_end_connection(cy_device_device_handlers* handlers) { #ifdef _WIN32 cypress_nisetro_driver_close_handle(&handlers->write_handle); handlers->read_handle = handlers->write_handle; @@ -548,7 +545,7 @@ void cypress_nisetro_driver_end_connection(cyni_device_device_handlers* handlers #endif } -int cypress_driver_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) { +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 result = LIBUSB_SUCCESS; #ifdef _WIN32 DWORD inner_transfered = 0; @@ -559,7 +556,7 @@ int cypress_driver_bulk_in(cyni_device_device_handlers* handlers, const cyni_dev return result; } -int cypress_driver_ctrl_bulk_in(cyni_device_device_handlers* handlers, const cyni_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 result = LIBUSB_SUCCESS; #ifdef _WIN32 DWORD inner_transfered = 0; @@ -570,7 +567,7 @@ int cypress_driver_ctrl_bulk_in(cyni_device_device_handlers* handlers, const cyn return result; } -int cypress_driver_ctrl_bulk_out(cyni_device_device_handlers* handlers, const cyni_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 result = LIBUSB_SUCCESS; #ifdef _WIN32 DWORD inner_transfered = 0; @@ -581,25 +578,25 @@ int cypress_driver_ctrl_bulk_out(cyni_device_device_handlers* handlers, const cy return result; } -void cypress_driver_pipe_reset_ctrl_bulk_in(cyni_device_device_handlers* handlers, const cyni_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) { #ifdef _WIN32 cypress_driver_pipe_reset(handlers->read_handle, usb_device_desc->ep_ctrl_bulk_in); #endif } -void cypress_driver_pipe_reset_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc) { +void cypress_driver_pipe_reset_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc) { #ifdef _WIN32 cypress_driver_pipe_reset(handlers->read_handle, usb_device_desc->ep_bulk_in); #endif } -void cypress_driver_pipe_reset_ctrl_bulk_out(cyni_device_device_handlers* handlers, const cyni_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) { #ifdef _WIN32 cypress_driver_pipe_reset(handlers->read_handle, usb_device_desc->ep_ctrl_bulk_out); #endif } -void cypress_driver_find_used_serial(const cyni_device_usb_device* usb_device_desc, bool* found, size_t num_free_fw_ids, int &curr_serial_extra_id) { +void cypress_driver_find_used_serial(const cy_device_usb_device* usb_device_desc, bool* found, size_t num_free_fw_ids, int &curr_serial_extra_id) { #ifdef _WIN32 HDEVINFO DeviceInfoSet = SetupDiGetClassDevs( &cypress_driver_guid, @@ -622,7 +619,7 @@ void cypress_driver_find_used_serial(const cyni_device_usb_device* usb_device_de std::string serial; if(!cypress_driver_get_device_pid_vid_manufacturer_serial_number(path, vid, pid, manufacturer, serial, bcd_device)) continue; - std::string read_serial = get_serial(usb_device_desc, serial, bcd_device, curr_serial_extra_id); + 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)) { try { int pos = std::stoi(read_serial); @@ -641,7 +638,7 @@ void cypress_driver_find_used_serial(const cyni_device_usb_device* usb_device_de #endif } -int cypress_driver_async_in_start(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, cyni_async_callback_data* cb_data) { +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) { #ifdef _WIN32 cb_data->transfer_data_access.lock(); cb_data->transfer_data = cb_data->base_transfer_data; @@ -663,31 +660,31 @@ int cypress_driver_async_in_start(cyni_device_device_handlers* handlers, const c return LIBUSB_SUCCESS; } -void cypress_driver_start_thread(std::thread* thread_ptr, bool* usb_thread_run, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data, cyni_device_device_handlers* handlers, ConsumerMutex* AsyncMutexPtr) { +void cypress_driver_start_thread(std::thread* thread_ptr, bool* usb_thread_run, std::vector &cb_data_vector, cy_device_device_handlers* handlers) { #ifdef _WIN32 *usb_thread_run = true; - for (int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) { - cypress_device_capture_recv_data[i].cb_data.extra_transfer_data = new CYPRESS_SINGLE_TRANSFER; - cypress_device_capture_recv_data[i].cb_data.base_transfer_data = new OVERLAPPED; - ((OVERLAPPED*)cypress_device_capture_recv_data[i].cb_data.base_transfer_data)->hEvent = CreateEvent(NULL, false, false, NULL); + for (int i = 0; i < cb_data_vector.size(); i++) { + cb_data_vector[i]->extra_transfer_data = new CYPRESS_SINGLE_TRANSFER; + cb_data_vector[i]->base_transfer_data = new OVERLAPPED; + ((OVERLAPPED*)cb_data_vector[i]->base_transfer_data)->hEvent = CreateEvent(NULL, false, false, NULL); } - *thread_ptr = std::thread(cypress_driver_function, usb_thread_run, cypress_device_capture_recv_data, handlers); + *thread_ptr = std::thread(cypress_driver_function, usb_thread_run, &cb_data_vector, handlers); #endif } -void cypress_driver_close_thread(std::thread* thread_ptr, bool* usb_thread_run, CypressDeviceCaptureReceivedData* cypress_device_capture_recv_data) { +void cypress_driver_close_thread(std::thread* thread_ptr, bool* usb_thread_run, std::vector cb_data_vector) { #ifdef _WIN32 *usb_thread_run = false; thread_ptr->join(); - for (int i = 0; i < NUM_CAPTURE_RECEIVED_DATA_BUFFERS; i++) { - CloseHandle(((OVERLAPPED*)cypress_device_capture_recv_data[i].cb_data.base_transfer_data)->hEvent); - delete ((OVERLAPPED*)cypress_device_capture_recv_data[i].cb_data.base_transfer_data); - delete ((CYPRESS_SINGLE_TRANSFER*)cypress_device_capture_recv_data[i].cb_data.extra_transfer_data); + for (int i = 0; i < cb_data_vector.size(); i++) { + CloseHandle(((OVERLAPPED*)cb_data_vector[i]->base_transfer_data)->hEvent); + delete ((OVERLAPPED*)cb_data_vector[i]->base_transfer_data); + delete ((CYPRESS_SINGLE_TRANSFER*)cb_data_vector[i]->extra_transfer_data); } #endif } -void cypress_driver_cancel_callback(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, cyni_async_callback_data* cb_data) { +void cypress_driver_cancel_callback(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, cy_async_callback_data* cb_data) { #ifdef _WIN32 DWORD transferred = 0; OVERLAPPED ov; @@ -701,7 +698,7 @@ void cypress_driver_cancel_callback(cyni_device_device_handlers* handlers, const #endif } -void cypress_driver_set_transfer_size_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, size_t new_transfer_size) { +void cypress_driver_set_transfer_size_bulk_in(cy_device_device_handlers* handlers, const cy_device_usb_device* usb_device_desc, size_t new_transfer_size) { #ifdef _WIN32 DWORD transferred; CYPRESS_SET_TRANSFER_SIZE_INFO SetTransferInfo; diff --git a/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_libusb_comms.cpp b/source/CaptureDeviceSpecific/Nisetro/cypress_shared_libusb_comms.cpp similarity index 70% rename from source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_libusb_comms.cpp rename to source/CaptureDeviceSpecific/Nisetro/cypress_shared_libusb_comms.cpp index 89d33f3..75e638f 100644 --- a/source/CaptureDeviceSpecific/Nisetro/cypress_nisetro_libusb_comms.cpp +++ b/source/CaptureDeviceSpecific/Nisetro/cypress_shared_libusb_comms.cpp @@ -1,12 +1,11 @@ -#include "cypress_nisetro_libusb_comms.hpp" -#include "cypress_nisetro_acquisition_general.hpp" +#include "cypress_shared_libusb_comms.hpp" #include #include #include "usb_generic.hpp" // Read from ctrl_in -int cypress_libusb_ctrl_in(cyni_device_device_handlers* handlers, const cyni_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_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 ret = libusb_control_transfer(handlers->usb_handle, 0xC0, request, value, index, buf, length, usb_device_desc->bulk_timeout); if(ret >= 0) *transferred = ret; @@ -14,7 +13,7 @@ int cypress_libusb_ctrl_in(cyni_device_device_handlers* handlers, const cyni_dev } // Write to ctrl_out -int cypress_libusb_ctrl_out(cyni_device_device_handlers* handlers, const cyni_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 ret = libusb_control_transfer(handlers->usb_handle, 0x40, request, value, index, buf, length, usb_device_desc->bulk_timeout); if(ret >= 0) *transferred = ret; @@ -22,33 +21,33 @@ int cypress_libusb_ctrl_out(cyni_device_device_handlers* handlers, const cyni_de } // Read from bulk -int cypress_libusb_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, int* transferred) { +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) { return libusb_bulk_transfer(handlers->usb_handle, usb_device_desc->ep_bulk_in, buf, length, transferred, usb_device_desc->bulk_timeout); } // Read from ctrl bulk -int cypress_libusb_ctrl_bulk_in(cyni_device_device_handlers* handlers, const cyni_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) { return libusb_bulk_transfer(handlers->usb_handle, usb_device_desc->ep_ctrl_bulk_in, buf, length, transferred, usb_device_desc->bulk_timeout); } // Write to ctrl bulk -int cypress_libusb_ctrl_bulk_out(cyni_device_device_handlers* handlers, const cyni_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) { return libusb_bulk_transfer(handlers->usb_handle, usb_device_desc->ep_ctrl_bulk_out, buf, length, transferred, usb_device_desc->bulk_timeout); } -void cypress_libusb_pipe_reset_bulk_in(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc) { +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(cyni_device_device_handlers* handlers, const cyni_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) { libusb_clear_halt(handlers->usb_handle, usb_device_desc->ep_ctrl_bulk_in); } -void cypress_libusb_pipe_reset_ctrl_bulk_out(cyni_device_device_handlers* handlers, const cyni_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) { libusb_clear_halt(handlers->usb_handle, usb_device_desc->ep_ctrl_bulk_out); } -void cypress_libusb_cancell_callback(cyni_async_callback_data* cb_data) { +void cypress_libusb_cancell_callback(cy_async_callback_data* cb_data) { cb_data->transfer_data_access.lock(); if(cb_data->transfer_data) libusb_cancel_transfer((libusb_transfer*)cb_data->transfer_data); @@ -56,7 +55,7 @@ void cypress_libusb_cancell_callback(cyni_async_callback_data* cb_data) { } void STDCALL cypress_libusb_async_callback(libusb_transfer* transfer) { - cyni_async_callback_data* cb_data = (cyni_async_callback_data*)transfer->user_data; + cy_async_callback_data* cb_data = (cy_async_callback_data*)transfer->user_data; cb_data->transfer_data_access.lock(); cb_data->transfer_data = NULL; cb_data->is_transfer_done_mutex->specific_unlock(cb_data->internal_index); @@ -65,7 +64,7 @@ void STDCALL cypress_libusb_async_callback(libusb_transfer* transfer) { } // Read from bulk -int cypress_libusb_async_in_start(cyni_device_device_handlers* handlers, const cyni_device_usb_device* usb_device_desc, uint8_t* buf, int length, cyni_async_callback_data* cb_data) { +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) { libusb_transfer *transfer_in = libusb_alloc_transfer(0); if(!transfer_in) return LIBUSB_ERROR_OTHER; @@ -79,7 +78,7 @@ int cypress_libusb_async_in_start(cyni_device_device_handlers* handlers, const c return retval; } -static bool cypress_libusb_setup_connection(libusb_device_handle* handle, const cyni_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) { *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); @@ -107,7 +106,7 @@ static void read_strings(libusb_device_handle *handle, libusb_device_descriptor serial[0xFF] = 0; } -static int cypress_libusb_insert_device(std::vector &devices_list, const cyni_device_usb_device* usb_device_desc, libusb_device *usb_device, libusb_device_descriptor *usb_descriptor, int &curr_serial_extra_id) { +static int cypress_libusb_insert_device(std::vector &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)) return LIBUSB_ERROR_NOT_FOUND; @@ -127,16 +126,16 @@ static int cypress_libusb_insert_device(std::vector &devices_list return result; } -cyni_device_device_handlers* cypress_libusb_serial_reconnection(const cyni_device_usb_device* usb_device_desc, std::string wanted_serial_number, int &curr_serial_extra_id, CaptureDevice* new_device) { +cy_device_device_handlers* cypress_libusb_serial_reconnection(const cy_device_usb_device* usb_device_desc, std::string wanted_serial_number, int &curr_serial_extra_id, CaptureDevice* new_device) { if(!usb_is_initialized()) return NULL; libusb_device **usb_devices; int num_devices = libusb_get_device_list(get_usb_ctx(), &usb_devices); libusb_device_descriptor usb_descriptor{}; - cyni_device_device_handlers* final_handlers = NULL; + cy_device_device_handlers* final_handlers = NULL; for(int i = 0; i < num_devices; i++) { - cyni_device_device_handlers handlers; + cy_device_device_handlers handlers; int result = libusb_get_device_descriptor(usb_devices[i], &usb_descriptor); if(result < 0) continue; @@ -148,10 +147,10 @@ cyni_device_device_handlers* cypress_libusb_serial_reconnection(const cyni_devic char manufacturer[0x100]; char serial[0x100]; read_strings(handlers.usb_handle, &usb_descriptor, manufacturer, serial); - std::string device_serial_number = get_serial(usb_device_desc, (std::string)(serial), usb_descriptor.bcdDevice, curr_serial_extra_id); + 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))) { - final_handlers = new cyni_device_device_handlers; + final_handlers = new cy_device_device_handlers; final_handlers->usb_handle = handlers.usb_handle; if(new_device != NULL) *new_device = cypress_create_device(usb_device_desc, wanted_serial_number); @@ -168,23 +167,23 @@ cyni_device_device_handlers* cypress_libusb_serial_reconnection(const cyni_devic return final_handlers; } -void cypress_libusb_end_connection(cyni_device_device_handlers* handlers, const cyni_device_usb_device* device_desc, bool interface_claimed) { +void cypress_libusb_end_connection(cy_device_device_handlers* handlers, const cy_device_usb_device* device_desc, bool interface_claimed) { if (interface_claimed) libusb_release_interface(handlers->usb_handle, device_desc->default_interface); libusb_close(handlers->usb_handle); handlers->usb_handle = NULL; } -void cypress_libusb_find_used_serial(const cyni_device_usb_device* usb_device_desc, bool* found, size_t num_free_fw_ids, int &curr_serial_extra_id) { +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) { if(!usb_is_initialized()) return; libusb_device **usb_devices; int num_devices = libusb_get_device_list(get_usb_ctx(), &usb_devices); libusb_device_descriptor usb_descriptor{}; - cyni_device_device_handlers* final_handlers = NULL; + cy_device_device_handlers* final_handlers = NULL; for(int i = 0; i < num_devices; i++) { - cyni_device_device_handlers handlers; + cy_device_device_handlers handlers; int result = libusb_get_device_descriptor(usb_devices[i], &usb_descriptor); if(result < 0) continue; @@ -197,7 +196,7 @@ void cypress_libusb_find_used_serial(const cyni_device_usb_device* usb_device_de char serial[0x100]; read_strings(handlers.usb_handle, &usb_descriptor, manufacturer, serial); libusb_close(handlers.usb_handle); - std::string device_serial_number = get_serial(usb_device_desc, (std::string)(serial), usb_descriptor.bcdDevice, curr_serial_extra_id); + 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); if((pos < 0) || (pos >= num_free_fw_ids)) @@ -215,7 +214,7 @@ void cypress_libusb_find_used_serial(const cyni_device_usb_device* usb_device_de return; } -void cypress_libusb_list_devices(std::vector &devices_list, bool* no_access_elems, bool* not_supported_elems, int *curr_serial_extra_id_cypress, const size_t num_cypress_desc) { +void cypress_libusb_list_devices(std::vector &devices_list, bool* no_access_elems, bool* not_supported_elems, int *curr_serial_extra_id_cypress, std::vector &device_descriptions) { if(!usb_is_initialized()) return; libusb_device **usb_devices; @@ -226,8 +225,8 @@ void cypress_libusb_list_devices(std::vector &devices_list, bool* int result = libusb_get_device_descriptor(usb_devices[i], &usb_descriptor); if(result < 0) continue; - for (int j = 0; j < num_cypress_desc; j++) { - result = cypress_libusb_insert_device(devices_list, GetCyNiDeviceDesc(j), usb_devices[i], &usb_descriptor, curr_serial_extra_id_cypress[j]); + for (int j = 0; j < device_descriptions.size(); j++) { + result = cypress_libusb_insert_device(devices_list, device_descriptions[j], usb_devices[i], &usb_descriptor, curr_serial_extra_id_cypress[j]); if (result != LIBUSB_ERROR_NOT_FOUND) { if (result == LIBUSB_ERROR_ACCESS) no_access_elems[j] = true; diff --git a/source/audio.cpp b/source/audio.cpp index f450d6f..3caaf37 100755 --- a/source/audio.cpp +++ b/source/audio.cpp @@ -121,7 +121,7 @@ bool Audio::onGetData(sf::SoundStream::Chunk &data) { for(int i = 0; i < loaded_samples; i++) { const std::int16_t *data_samples = samples.front().bytes; - int count = samples.front().size; + uint64_t count = samples.front().size; memcpy(buffer + data.sampleCount, data_samples, count * sizeof(std::int16_t)); // Unused, but could be useful info //double real_sample_rate = (1.0 / samples.front().time) * count / 2;