mirror of
https://github.com/cathery/sys-con.git
synced 2025-03-14 01:27:37 +00:00
Revert back to allocating aligned memory when needed
This commit is contained in:
parent
744c42a250
commit
1219a249be
@ -10,8 +10,6 @@ private:
|
||||
UsbHsClientIfSession *m_ifSession;
|
||||
usb_endpoint_descriptor *m_descriptor;
|
||||
|
||||
void *m_buffer;
|
||||
|
||||
public:
|
||||
//Pass the necessary information to be able to open the endpoint
|
||||
SwitchUSBEndpoint(UsbHsClientIfSession &if_session, usb_endpoint_descriptor &desc);
|
||||
|
@ -14,8 +14,6 @@ private:
|
||||
std::array<std::unique_ptr<IUSBEndpoint>, 15> m_inEndpoints;
|
||||
std::array<std::unique_ptr<IUSBEndpoint>, 15> m_outEndpoints;
|
||||
|
||||
void *m_controlTransferBuffer;
|
||||
|
||||
public:
|
||||
//Pass the specified interface to allow for opening the session
|
||||
SwitchUSBInterface(UsbHsInterface &interface);
|
||||
|
@ -6,12 +6,10 @@ SwitchUSBEndpoint::SwitchUSBEndpoint(UsbHsClientIfSession &if_session, usb_endpo
|
||||
: m_ifSession(&if_session),
|
||||
m_descriptor(&desc)
|
||||
{
|
||||
m_buffer = memalign(0x1000, 64);
|
||||
}
|
||||
|
||||
SwitchUSBEndpoint::~SwitchUSBEndpoint()
|
||||
{
|
||||
free(m_buffer);
|
||||
Close();
|
||||
}
|
||||
|
||||
@ -30,44 +28,47 @@ void SwitchUSBEndpoint::Close()
|
||||
|
||||
Result SwitchUSBEndpoint::Write(const void *inBuffer, size_t bufferSize)
|
||||
{
|
||||
Result rc = -1;
|
||||
if (m_buffer != nullptr)
|
||||
void *temp_buffer = memalign(0x1000, bufferSize);
|
||||
if (temp_buffer == nullptr)
|
||||
return -1;
|
||||
|
||||
u32 transferredSize = 0;
|
||||
|
||||
for (size_t byte = 0; byte != bufferSize; ++byte)
|
||||
{
|
||||
u32 transferredSize = 0;
|
||||
memset(m_buffer, 0, bufferSize);
|
||||
|
||||
for (size_t byte = 0; byte != bufferSize; ++byte)
|
||||
{
|
||||
static_cast<uint8_t *>(m_buffer)[byte] = static_cast<const uint8_t *>(inBuffer)[byte];
|
||||
}
|
||||
|
||||
rc = usbHsEpPostBuffer(&m_epSession, m_buffer, bufferSize, &transferredSize);
|
||||
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
svcSleepThread(m_descriptor->bInterval * 1e+6L);
|
||||
}
|
||||
static_cast<uint8_t *>(temp_buffer)[byte] = static_cast<const uint8_t *>(inBuffer)[byte];
|
||||
}
|
||||
|
||||
Result rc = usbHsEpPostBuffer(&m_epSession, temp_buffer, bufferSize, &transferredSize);
|
||||
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
svcSleepThread(m_descriptor->bInterval * 1e+6L);
|
||||
}
|
||||
|
||||
free(temp_buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result SwitchUSBEndpoint::Read(void *outBuffer, size_t bufferSize)
|
||||
{
|
||||
if (m_buffer == nullptr)
|
||||
void *temp_buffer = memalign(0x1000, bufferSize);
|
||||
if (temp_buffer == nullptr)
|
||||
return -1;
|
||||
|
||||
u32 transferredSize;
|
||||
memset(m_buffer, 0, bufferSize);
|
||||
|
||||
Result rc = usbHsEpPostBuffer(&m_epSession, m_buffer, bufferSize, &transferredSize);
|
||||
Result rc = usbHsEpPostBuffer(&m_epSession, temp_buffer, bufferSize, &transferredSize);
|
||||
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
for (u32 byte = 0; byte != transferredSize; ++byte)
|
||||
{
|
||||
static_cast<uint8_t *>(outBuffer)[byte] = static_cast<uint8_t *>(m_buffer)[byte];
|
||||
static_cast<uint8_t *>(outBuffer)[byte] = static_cast<uint8_t *>(temp_buffer)[byte];
|
||||
}
|
||||
}
|
||||
free(temp_buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -6,12 +6,10 @@
|
||||
SwitchUSBInterface::SwitchUSBInterface(UsbHsInterface &interface)
|
||||
: m_interface(interface)
|
||||
{
|
||||
m_controlTransferBuffer = memalign(0x1000, 64);
|
||||
}
|
||||
|
||||
SwitchUSBInterface::~SwitchUSBInterface()
|
||||
{
|
||||
free(m_controlTransferBuffer);
|
||||
Close();
|
||||
}
|
||||
|
||||
@ -68,26 +66,28 @@ void SwitchUSBInterface::Close()
|
||||
|
||||
Result SwitchUSBInterface::ControlTransfer(u8 bmRequestType, u8 bmRequest, u16 wValue, u16 wIndex, u16 wLength, void *buffer)
|
||||
{
|
||||
if (m_controlTransferBuffer == nullptr)
|
||||
void *temp_buffer = memalign(0x1000, wLength);
|
||||
if (temp_buffer == nullptr)
|
||||
return -1;
|
||||
|
||||
u32 transferredSize;
|
||||
|
||||
for (u16 byte = 0; byte != wLength; ++byte)
|
||||
{
|
||||
static_cast<uint8_t *>(m_controlTransferBuffer)[byte] = static_cast<uint8_t *>(buffer)[byte];
|
||||
static_cast<uint8_t *>(temp_buffer)[byte] = static_cast<uint8_t *>(buffer)[byte];
|
||||
}
|
||||
|
||||
Result rc = usbHsIfCtrlXfer(&m_session, bmRequestType, bmRequest, wValue, wIndex, wLength, m_controlTransferBuffer, &transferredSize);
|
||||
Result rc = usbHsIfCtrlXfer(&m_session, bmRequestType, bmRequest, wValue, wIndex, wLength, temp_buffer, &transferredSize);
|
||||
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
memset(buffer, 0, wLength);
|
||||
for (u32 byte = 0; byte != transferredSize; ++byte)
|
||||
{
|
||||
static_cast<uint8_t *>(buffer)[byte] = static_cast<uint8_t *>(m_controlTransferBuffer)[byte];
|
||||
static_cast<uint8_t *>(buffer)[byte] = static_cast<uint8_t *>(temp_buffer)[byte];
|
||||
}
|
||||
}
|
||||
free(temp_buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user