mirror of
https://github.com/cathery/sys-con.git
synced 2024-10-06 06:19:43 +00:00
Fixed input packets bleeding into each other to fix #78
This commit is contained in:
parent
c2e12bc2e9
commit
7356a742c9
@ -10,6 +10,8 @@ private:
|
|||||||
UsbHsClientIfSession *m_ifSession;
|
UsbHsClientIfSession *m_ifSession;
|
||||||
usb_endpoint_descriptor *m_descriptor;
|
usb_endpoint_descriptor *m_descriptor;
|
||||||
|
|
||||||
|
void *m_buffer = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//Pass the necessary information to be able to open the endpoint
|
//Pass the necessary information to be able to open the endpoint
|
||||||
SwitchUSBEndpoint(UsbHsClientIfSession &if_session, usb_endpoint_descriptor &desc);
|
SwitchUSBEndpoint(UsbHsClientIfSession &if_session, usb_endpoint_descriptor &desc);
|
||||||
|
@ -15,60 +15,65 @@ SwitchUSBEndpoint::~SwitchUSBEndpoint()
|
|||||||
|
|
||||||
Result SwitchUSBEndpoint::Open(int maxPacketSize)
|
Result SwitchUSBEndpoint::Open(int maxPacketSize)
|
||||||
{
|
{
|
||||||
Result rc = usbHsIfOpenUsbEp(m_ifSession, &m_epSession, 1, (maxPacketSize != 0 ? maxPacketSize : m_descriptor->wMaxPacketSize), m_descriptor);
|
maxPacketSize = maxPacketSize != 0 ? maxPacketSize : m_descriptor->wMaxPacketSize;
|
||||||
|
|
||||||
|
Result rc = usbHsIfOpenUsbEp(m_ifSession, &m_epSession, 1, maxPacketSize, m_descriptor);
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
return 73011;
|
return 73011;
|
||||||
|
|
||||||
|
m_buffer = memalign(0x1000, maxPacketSize);
|
||||||
|
if (m_buffer == nullptr)
|
||||||
|
return -1;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchUSBEndpoint::Close()
|
void SwitchUSBEndpoint::Close()
|
||||||
{
|
{
|
||||||
|
if (m_buffer != nullptr)
|
||||||
|
{
|
||||||
|
free(m_buffer);
|
||||||
|
m_buffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
usbHsEpClose(&m_epSession);
|
usbHsEpClose(&m_epSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SwitchUSBEndpoint::Write(const void *inBuffer, size_t bufferSize)
|
Result SwitchUSBEndpoint::Write(const void *inBuffer, size_t bufferSize)
|
||||||
{
|
{
|
||||||
void *temp_buffer = memalign(0x1000, bufferSize);
|
if (m_buffer == nullptr)
|
||||||
if (temp_buffer == nullptr)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
u32 transferredSize = 0;
|
u32 transferredSize = 0;
|
||||||
|
|
||||||
for (size_t byte = 0; byte != bufferSize; ++byte)
|
for (size_t byte = 0; byte != bufferSize; ++byte)
|
||||||
{
|
{
|
||||||
static_cast<uint8_t *>(temp_buffer)[byte] = static_cast<const uint8_t *>(inBuffer)[byte];
|
static_cast<uint8_t *>(m_buffer)[byte] = static_cast<const uint8_t *>(inBuffer)[byte];
|
||||||
}
|
}
|
||||||
|
|
||||||
Result rc = usbHsEpPostBuffer(&m_epSession, temp_buffer, bufferSize, &transferredSize);
|
Result rc = usbHsEpPostBuffer(&m_epSession, m_buffer, bufferSize, &transferredSize);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
{
|
{
|
||||||
svcSleepThread(m_descriptor->bInterval * 1e+6L);
|
svcSleepThread(m_descriptor->bInterval * 1e+6L);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(temp_buffer);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SwitchUSBEndpoint::Read(void *outBuffer, size_t bufferSize)
|
Result SwitchUSBEndpoint::Read(void *outBuffer, size_t bufferSize)
|
||||||
{
|
{
|
||||||
void *temp_buffer = memalign(0x1000, bufferSize);
|
if (m_buffer == nullptr)
|
||||||
if (temp_buffer == nullptr)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
u32 transferredSize;
|
u32 transferredSize;
|
||||||
|
|
||||||
Result rc = usbHsEpPostBuffer(&m_epSession, temp_buffer, bufferSize, &transferredSize);
|
Result rc = usbHsEpPostBuffer(&m_epSession, m_buffer, bufferSize, &transferredSize);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
{
|
{
|
||||||
for (u32 byte = 0; byte != transferredSize; ++byte)
|
for (u32 byte = 0; byte != transferredSize; ++byte)
|
||||||
{
|
{
|
||||||
static_cast<uint8_t *>(outBuffer)[byte] = static_cast<uint8_t *>(temp_buffer)[byte];
|
static_cast<uint8_t *>(outBuffer)[byte] = static_cast<uint8_t *>(m_buffer)[byte];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(temp_buffer);
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user