From 7e29508b59797e4abc60f94a8d03a6b2f5803412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 27 Mar 2018 17:29:25 +0200 Subject: [PATCH] [usb] Clean Interface code. Change-Id: I06526265a6876bc905bcce668f38f24df64c9b27 --- ion/src/device/usb/interface.cpp | 20 ++++++++++---------- ion/src/device/usb/interface.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ion/src/device/usb/interface.cpp b/ion/src/device/usb/interface.cpp index aab1ce1d6..3fa95947e 100644 --- a/ion/src/device/usb/interface.cpp +++ b/ion/src/device/usb/interface.cpp @@ -16,7 +16,7 @@ bool Interface::processSetupInRequest(SetupPacket * request, uint8_t * transferB case (int) Request::SetInterface: return setInterface(request, transferBufferLength); case (int) Request::GetInterface: - return getInterface(transferBuffer, transferBufferLength); + return getInterface(transferBuffer, transferBufferLength, transferBufferMaxLength); case (int) Request::ClearFeature: return clearFeature(transferBufferLength); case (int) Request::SetFeature: @@ -28,35 +28,35 @@ bool Interface::processSetupInRequest(SetupPacket * request, uint8_t * transferB bool Interface::getStatus(uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) { *transferBufferLength = min(2, transferBufferMaxLength); for (int i = 0; i<*transferBufferLength; i++) { - transferBuffer[i] = 0; // By specification + transferBuffer[i] = 0; // Reserved, must be set to 0 } return true; } -bool Interface::getInterface(uint8_t * transferBuffer, uint16_t * transferBufferLength) { - *transferBufferLength = 1; - transferBuffer[0] = getActiveInterfaceAlternative(); +bool Interface::getInterface(uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength) { + *transferBufferLength = min(1, transferBufferMaxLength);; + if (*transferBufferLength > 0) { + transferBuffer[0] = getActiveInterfaceAlternative(); + } return true; } bool Interface::setInterface(SetupPacket * request, uint16_t * transferBufferLength) { // We support one interface only setActiveInterfaceAlternative(request->wValue()); - /* There is one interface alternative only, we no need to set it again, just - * reset the endpoint. */ - //m_ep0->reset(); //TODO Needed? + // There is one interface alternative only, we no need to set it again. *transferBufferLength = 0; return true; } bool Interface::clearFeature(uint16_t * transferBufferLength) { - //TODO ? + // Not needed for now *transferBufferLength = 0; return true; } bool Interface::setFeature(uint16_t * transferBufferLength) { - //TODO ? + // Not needed for now *transferBufferLength = 0; return true; } diff --git a/ion/src/device/usb/interface.h b/ion/src/device/usb/interface.h index 7f5d6be60..40376e197 100644 --- a/ion/src/device/usb/interface.h +++ b/ion/src/device/usb/interface.h @@ -29,7 +29,7 @@ private: SetInterface = 11, }; bool getStatus(uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength); - bool getInterface(uint8_t * transferBuffer, uint16_t * transferBufferLength); + bool getInterface(uint8_t * transferBuffer, uint16_t * transferBufferLength, uint16_t transferBufferMaxLength); bool setInterface(SetupPacket * request, uint16_t * transferBufferLength); bool clearFeature(uint16_t * transferBufferLength); bool setFeature(uint16_t * transferBufferLength);