summaryrefslogtreecommitdiff
path: root/at91lib
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2011-07-31 13:23:17 +0200
committerHarald Welte <laforge@gnumonks.org>2011-07-31 13:27:30 +0200
commit245e794b26158fded2025508e7c63be52d0e60b4 (patch)
tree49a959551546d319b36fc7498459323c05e42079 /at91lib
parenta2def0e915285177799c5d33c27715538f0e80d4 (diff)
at91lib: Core support for multiple configurations
Diffstat (limited to 'at91lib')
-rw-r--r--at91lib/usb/device/core/USBDDriver.c57
1 files changed, 34 insertions, 23 deletions
diff --git a/at91lib/usb/device/core/USBDDriver.c b/at91lib/usb/device/core/USBDDriver.c
index c2a8abd..83cbd9e 100644
--- a/at91lib/usb/device/core/USBDDriver.c
+++ b/at91lib/usb/device/core/USBDDriver.c
@@ -49,6 +49,35 @@
#include <string.h>
+static const USBConfigurationDescriptor *GetCurConfigDesc(USBDDriver *pDriver)
+{
+ unsigned char cfgidx = pDriver->cfgnum;
+
+ if (cfgidx != 0)
+ cfgidx -= 1;
+
+ // Use different descriptor depending on device speed
+ if (USBD_IsHighSpeed())
+ return &pDriver->pDescriptors->pHsConfiguration[cfgidx];
+ else
+ return &pDriver->pDescriptors->pFsConfiguration[cfgidx];
+}
+
+static const USBConfigurationDescriptor *GetCurOtherSpeedDesc(USBDDriver *pDriver)
+{
+ unsigned char cfgidx = pDriver->cfgnum;
+
+ if (cfgidx != 0)
+ cfgidx -= 1;
+
+ // Use different descriptor depending on device speed
+ if (USBD_IsHighSpeed())
+ return &pDriver->pDescriptors->pHsOtherSpeed[cfgidx];
+ else
+ return &pDriver->pDescriptors->pFsOtherSpeed[cfgidx];
+}
+
+
//------------------------------------------------------------------------------
// Local functions
//------------------------------------------------------------------------------
@@ -64,20 +93,12 @@ static void SetConfiguration(USBDDriver *pDriver, unsigned char cfgnum)
USBEndpointDescriptor *pEndpoints[BOARD_USB_NUMENDPOINTS+1];
const USBConfigurationDescriptor *pConfiguration;
- // Use different descriptor depending on device speed
- if (USBD_IsHighSpeed()) {
-
- pConfiguration = pDriver->pDescriptors->pHsConfiguration;
- }
- else {
-
- pConfiguration = pDriver->pDescriptors->pFsConfiguration;
- }
-
// Set & save the desired configuration
USBD_SetConfiguration(cfgnum);
pDriver->cfgnum = cfgnum;
+ pConfiguration = GetCurConfigDesc(pDriver);
+
// If the configuration is not 0, configure endpoints
if (cfgnum != 0) {
@@ -121,15 +142,7 @@ static void GetDeviceStatus(const USBDDriver *pDriver)
unsigned short data = 0;
const USBConfigurationDescriptor *pConfiguration;
- // Use different configuration depending on device speed
- if (USBD_IsHighSpeed()) {
-
- pConfiguration = pDriver->pDescriptors->pHsConfiguration;
- }
- else {
-
- pConfiguration = pDriver->pDescriptors->pFsConfiguration;
- }
+ pConfiguration = GetCurConfigDesc(pDriver);
// Check current configuration for power mode (if device is configured)
if (pDriver->cfgnum != 0) {
@@ -204,18 +217,16 @@ static void GetDescriptor(
TRACE_DEBUG("HS ");
pDevice = pDriver->pDescriptors->pHsDevice;
- pConfiguration = pDriver->pDescriptors->pHsConfiguration;
pQualifier = pDriver->pDescriptors->pHsQualifier;
- pOtherSpeed = pDriver->pDescriptors->pHsOtherSpeed;
}
else {
TRACE_DEBUG("FS ");
pDevice = pDriver->pDescriptors->pFsDevice;
- pConfiguration = pDriver->pDescriptors->pFsConfiguration;
pQualifier = pDriver->pDescriptors->pFsQualifier;
- pOtherSpeed = pDriver->pDescriptors->pFsOtherSpeed;
}
+ pConfiguration = GetCurConfigDesc(pDriver);
+ pOtherSpeed = GetCurOtherSpeedDesc(pDriver);
// Check the descriptor type
switch (type) {
personal git repositories of Harald Welte. Your mileage may vary