1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-22 18:26:39 +00:00

usb: modified usbIsReady() to return the speed selected by the host device.

This commit is contained in:
Pablo Curiel 2021-06-25 17:01:15 -04:00
parent e32782f322
commit b23af8c131
5 changed files with 55 additions and 16 deletions

View file

@ -33,6 +33,14 @@ extern "C" {
#define USB_TRANSFER_BUFFER_SIZE 0x800000 /* 8 MiB. */ #define USB_TRANSFER_BUFFER_SIZE 0x800000 /* 8 MiB. */
/// Used to indicate the USB speed selected by the host device.
typedef enum {
UsbHostSpeed_None = 0,
UsbHostSpeed_FullSpeed = 1, ///< USB 1.x.
UsbHostSpeed_HighSpeed = 2, ///< USB 2.0.
UsbHostSpeed_SuperSpeed = 3 ///< USB 3.0.
} UsbHostSpeed;
/// Initializes the USB interface, input and output endpoints and allocates an internal transfer buffer. /// Initializes the USB interface, input and output endpoints and allocates an internal transfer buffer.
bool usbInitialize(void); bool usbInitialize(void);
@ -43,7 +51,8 @@ void usbExit(void);
void *usbAllocatePageAlignedBuffer(size_t size); void *usbAllocatePageAlignedBuffer(size_t size);
/// Used to check if the console has been connected to a USB host device and if a valid USB session has been established. /// Used to check if the console has been connected to a USB host device and if a valid USB session has been established.
bool usbIsReady(void); /// Returns a value from the UsbHostSpeed enum.
u8 usbIsReady(void);
/// Sends file properties to the host device before starting a file data transfer. Must be called before usbSendFileData(). /// Sends file properties to the host device before starting a file data transfer. Must be called before usbSendFileData().
/// If 'nsp_header_size' is greater than zero, NSP transfer mode will be enabled. The file will be treated as a NSP and this value will be taken as its full Partition FS header size. /// If 'nsp_header_size' is greater than zero, NSP transfer mode will be enabled. The file will be treated as a NSP and this value will be taken as its full Partition FS header size.

View file

@ -53,7 +53,7 @@ namespace nxdt::tasks
typedef brls::Event<GameCardStatus> GameCardStatusEvent; typedef brls::Event<GameCardStatus> GameCardStatusEvent;
typedef brls::Event<const TitleApplicationMetadataVector*> TitleEvent; typedef brls::Event<const TitleApplicationMetadataVector*> TitleEvent;
typedef brls::Event<const UmsDeviceVector*> UmsEvent; typedef brls::Event<const UmsDeviceVector*> UmsEvent;
typedef brls::Event<bool> UsbHostEvent; typedef brls::Event<UsbHostSpeed> UsbHostEvent;
/* Status info task. */ /* Status info task. */
/* Its event returns a pointer to a StatusInfoData struct. */ /* Its event returns a pointer to a StatusInfoData struct. */
@ -175,9 +175,8 @@ namespace nxdt::tasks
{ {
private: private:
UsbHostEvent usb_host_event; UsbHostEvent usb_host_event;
UsbHostSpeed cur_usb_host_speed = UsbHostSpeed_None;
bool cur_usb_host_status = false; UsbHostSpeed prev_usb_host_speed = UsbHostSpeed_None;
bool prev_usb_host_status = false;
protected: protected:
void run(retro_time_t current_time) override; void run(retro_time_t current_time) override;

View file

@ -1,6 +1,9 @@
{ {
"notifications": { "notifications": {
"gamecard": "Gamecard status change detected!", "gamecard": "Gamecard status change detected!",
"user_titles": "User titles updated!" "user_titles": "User titles updated!",
"ums_device": "USB Mass Storage devices updated!",
"usb_host_connected": "USB host connected!",
"usb_host_disconnected": "USB host disconnected!"
} }
} }

View file

@ -305,10 +305,30 @@ void *usbAllocatePageAlignedBuffer(size_t size)
return memalign(USB_TRANSFER_ALIGNMENT, size); return memalign(USB_TRANSFER_ALIGNMENT, size);
} }
bool usbIsReady(void) u8 usbIsReady(void)
{ {
bool ret = false; u8 ret = UsbHostSpeed_None;
SCOPED_TRY_LOCK(&g_usbInterfaceMutex) ret = (g_usbHostAvailable && g_usbSessionStarted);
SCOPED_TRY_LOCK(&g_usbInterfaceMutex)
{
if (!g_usbHostAvailable || !g_usbSessionStarted) break;
switch(g_usbEndpointMaxPacketSize)
{
case USB_FS_EP_MAX_PACKET_SIZE: /* USB 1.x. */
ret = UsbHostSpeed_FullSpeed;
break;
case USB_HS_EP_MAX_PACKET_SIZE: /* USB 2.0. */
ret = UsbHostSpeed_HighSpeed;
break;
case USB_SS_EP_MAX_PACKET_SIZE: /* USB 3.0. */
ret = UsbHostSpeed_SuperSpeed;
break;
default:
break;
}
}
return ret; return ret;
} }

View file

@ -76,6 +76,7 @@ namespace nxdt::tasks
status_info_data->ip_addr = NULL; status_info_data->ip_addr = NULL;
} }
/* Fire task event. */
this->status_info_event.fire(status_info_data); this->status_info_event.fire(status_info_data);
} }
@ -96,7 +97,7 @@ namespace nxdt::tasks
{ {
brls::RepeatingTask::run(current_time); brls::RepeatingTask::run(current_time);
this->cur_gc_status = (GameCardStatus)gamecardGetStatus(); this->cur_gc_status = static_cast<GameCardStatus>(gamecardGetStatus());
if (this->cur_gc_status != this->prev_gc_status) if (this->cur_gc_status != this->prev_gc_status)
{ {
brls::Logger::debug("Gamecard status change triggered: {}.", this->cur_gc_status); brls::Logger::debug("Gamecard status change triggered: {}.", this->cur_gc_status);
@ -201,12 +202,14 @@ namespace nxdt::tasks
if (umsIsDeviceInfoUpdated()) if (umsIsDeviceInfoUpdated())
{ {
brls::Logger::debug("UMS device info updated.");
brls::Application::notify("tasks/notifications/ums_device"_i18n);
/* Update UMS device vector. */ /* Update UMS device vector. */
this->PopulateUmsDeviceVector(); this->PopulateUmsDeviceVector();
/* Fire task event. */ /* Fire task event. */
this->ums_event.fire(&(this->ums_devices)); this->ums_event.fire(&(this->ums_devices));
brls::Logger::debug("UMS device info updated.");
} }
} }
@ -249,12 +252,17 @@ namespace nxdt::tasks
{ {
brls::RepeatingTask::run(current_time); brls::RepeatingTask::run(current_time);
this->cur_usb_host_status = usbIsReady(); this->cur_usb_host_speed = static_cast<UsbHostSpeed>(usbIsReady());
if (this->cur_usb_host_status != this->prev_usb_host_status) if (this->cur_usb_host_speed != this->prev_usb_host_speed)
{ {
this->prev_usb_host_status = this->cur_usb_host_status; brls::Logger::debug("USB host speed changed: {}.", this->cur_usb_host_speed);
this->usb_host_event.fire(this->cur_usb_host_status); brls::Application::notify(this->cur_usb_host_speed ? "tasks/notifications/usb_host_connected"_i18n : "tasks/notifications/usb_host_disconnected"_i18n);
brls::Logger::debug("USB host status change triggered: {}.", this->cur_usb_host_status);
/* Update previous USB host speed. */
this->prev_usb_host_speed = this->cur_usb_host_speed;
/* Fire task event. */
this->usb_host_event.fire(this->cur_usb_host_speed);
} }
} }
} }