Add USB Gadget Device support (#567)

* Initial attempt to include USB Gadget Mode as a configuration option.  Note: Also requires a move to the latest release of circle.

* Set "official" (as allocated from pid.codes) USB vendor and device ID for MiniDexed
switch_perf_dir
Kevin 1 year ago committed by GitHub
parent c5c4e13814
commit 258a456d40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      USBID.sh
  2. 9
      build.sh
  3. 1
      src/Rules.mk
  4. 13
      src/circle_stdlib_app.h
  5. 7
      src/config.cpp
  6. 5
      src/config.h
  7. 20
      src/kernel.cpp
  8. 2
      src/kernel.h
  9. 9
      src/minidexed.cpp
  10. 15
      submod.sh

@ -0,0 +1,2 @@
USB_VID=0x1209
USB_DID=0xF043

@ -20,6 +20,15 @@ if [ "${RPI}" -gt "1" ]; then
OPTIONS="${OPTIONS} -o ARM_ALLOW_MULTI_CORE" OPTIONS="${OPTIONS} -o ARM_ALLOW_MULTI_CORE"
fi fi
# USB Vendor and Device ID for use with USB Gadget Mode
source USBID.sh
if [ "${USB_VID}" ] ; then
OPTIONS="${OPTIONS} -o USB_GADGET_VENDOR_ID=${USB_VID}"
fi
if [ "${USB_DID}" ] ; then
OPTIONS="${OPTIONS} -o USB_GADGET_DEVICE_ID=${USB_DID}"
fi
# Build circle-stdlib library # Build circle-stdlib library
cd circle-stdlib/ cd circle-stdlib/
make mrproper || true make mrproper || true

@ -22,6 +22,7 @@ LIBS += \
$(CIRCLEHOME)/addon/Properties/libproperties.a \ $(CIRCLEHOME)/addon/Properties/libproperties.a \
$(CIRCLEHOME)/addon/SDCard/libsdcard.a \ $(CIRCLEHOME)/addon/SDCard/libsdcard.a \
$(CIRCLEHOME)/lib/usb/libusb.a \ $(CIRCLEHOME)/lib/usb/libusb.a \
$(CIRCLEHOME)/lib/usb/gadget/libusbgadget.a \
$(CIRCLEHOME)/lib/input/libinput.a \ $(CIRCLEHOME)/lib/input/libinput.a \
$(CIRCLEHOME)/lib/sound/libsound.a \ $(CIRCLEHOME)/lib/sound/libsound.a \
$(CIRCLEHOME)/addon/fatfs/libfatfs.a \ $(CIRCLEHOME)/addon/fatfs/libfatfs.a \

@ -25,7 +25,6 @@
#include <circle/writebuffer.h> #include <circle/writebuffer.h>
#include <circle/timer.h> #include <circle/timer.h>
#include <circle/logger.h> #include <circle/logger.h>
#include <circle/usb/usbhcidevice.h>
#include <SDCard/emmc.h> #include <SDCard/emmc.h>
#include <circle/input/console.h> #include <circle/input/console.h>
#include <circle/sched/scheduler.h> #include <circle/sched/scheduler.h>
@ -160,7 +159,6 @@ public:
const char *pPartitionName = CSTDLIBAPP_DEFAULT_PARTITION) const char *pPartitionName = CSTDLIBAPP_DEFAULT_PARTITION)
: CStdlibAppScreen (kernel), : CStdlibAppScreen (kernel),
mpPartitionName (pPartitionName), mpPartitionName (pPartitionName),
mUSBHCI (&mInterrupt, &mTimer, TRUE),
mEMMC (&mInterrupt, &mTimer, &mActLED), mEMMC (&mInterrupt, &mTimer, &mActLED),
#if !defined(__aarch64__) || !defined(LEAVE_QEMU_ON_HALT) #if !defined(__aarch64__) || !defined(LEAVE_QEMU_ON_HALT)
//mConsole (&mScreen, TRUE) //mConsole (&mScreen, TRUE)
@ -199,16 +197,6 @@ public:
return false; return false;
} }
#if !defined(__aarch64__) || !defined(LEAVE_QEMU_ON_HALT)
// The USB driver is not supported under 64-bit QEMU, so
// the initialization must be skipped in this case, or an
// exit happens here under 64-bit QEMU.
if (!mUSBHCI.Initialize ())
{
return false;
}
#endif
if (!mConsole.Initialize ()) if (!mConsole.Initialize ())
{ {
return false; return false;
@ -232,7 +220,6 @@ public:
} }
protected: protected:
CUSBHCIDevice mUSBHCI;
CEMMCDevice mEMMC; CEMMCDevice mEMMC;
FATFS mFileSystem; FATFS mFileSystem;
CConsole mConsole; CConsole mConsole;

@ -36,6 +36,8 @@ void CConfig::Load (void)
{ {
m_Properties.Load (); m_Properties.Load ();
m_bUSBGadgetMode = m_Properties.GetNumber ("USBGadget", 0) != 0;
m_SoundDevice = m_Properties.GetString ("SoundDevice", "pwm"); m_SoundDevice = m_Properties.GetString ("SoundDevice", "pwm");
m_nSampleRate = m_Properties.GetNumber ("SampleRate", 48000); m_nSampleRate = m_Properties.GetNumber ("SampleRate", 48000);
@ -152,6 +154,11 @@ void CConfig::Load (void)
m_bPerformanceSelectChannel = m_Properties.GetNumber ("PerformanceSelectChannel", 0); m_bPerformanceSelectChannel = m_Properties.GetNumber ("PerformanceSelectChannel", 0);
} }
bool CConfig::GetUSBGadgetMode (void) const
{
return m_bUSBGadgetMode;
}
const char *CConfig::GetSoundDevice (void) const const char *CConfig::GetSoundDevice (void) const
{ {
return m_SoundDevice.c_str (); return m_SoundDevice.c_str ();

@ -63,6 +63,9 @@ public:
void Load (void); void Load (void);
// USB Mode
bool GetUSBGadgetMode (void) const; // true if in USB gadget mode
// Sound device // Sound device
const char *GetSoundDevice (void) const; const char *GetSoundDevice (void) const;
unsigned GetSampleRate (void) const; unsigned GetSampleRate (void) const;
@ -168,6 +171,8 @@ public:
private: private:
CPropertiesFatFsFile m_Properties; CPropertiesFatFsFile m_Properties;
bool m_bUSBGadgetMode;
std::string m_SoundDevice; std::string m_SoundDevice;
unsigned m_nSampleRate; unsigned m_nSampleRate;
unsigned m_nChunkSize; unsigned m_nChunkSize;

@ -21,6 +21,8 @@
#include <circle/logger.h> #include <circle/logger.h>
#include <circle/synchronize.h> #include <circle/synchronize.h>
#include <assert.h> #include <assert.h>
#include <circle/usb/usbhcidevice.h>
#include <circle/usb/gadget/usbmidigadget.h>
LOGMODULE ("kernel"); LOGMODULE ("kernel");
@ -64,6 +66,22 @@ bool CKernel::Initialize (void)
m_Config.Load (); m_Config.Load ();
if (m_Config.GetUSBGadgetMode())
{
// Run the USB stack in USB Gadget (device) mode
m_pUSB = new CUSBMIDIGadget (&mInterrupt);
}
else
{
// Run the USB stack in USB Host (default) mode
m_pUSB = new CUSBHCIDevice (&mInterrupt, &mTimer, TRUE);
}
if (!m_pUSB->Initialize ())
{
return FALSE;
}
m_pDexed = new CMiniDexed (&m_Config, &mInterrupt, &m_GPIOManager, &m_I2CMaster, m_pDexed = new CMiniDexed (&m_Config, &mInterrupt, &m_GPIOManager, &m_I2CMaster,
&mFileSystem); &mFileSystem);
assert (m_pDexed); assert (m_pDexed);
@ -82,7 +100,7 @@ CStdlibApp::TShutdownMode CKernel::Run (void)
while (42 == 42) while (42 == 42)
{ {
boolean bUpdated = mUSBHCI.UpdatePlugAndPlay (); boolean bUpdated = m_pUSB->UpdatePlugAndPlay ();
m_pDexed->Process(bUpdated); m_pDexed->Process(bUpdated);

@ -24,6 +24,7 @@
#include <circle/cputhrottle.h> #include <circle/cputhrottle.h>
#include <circle/gpiomanager.h> #include <circle/gpiomanager.h>
#include <circle/i2cmaster.h> #include <circle/i2cmaster.h>
#include <circle/usb/usbcontroller.h>
#include "config.h" #include "config.h"
#include "minidexed.h" #include "minidexed.h"
@ -54,6 +55,7 @@ private:
CGPIOManager m_GPIOManager; CGPIOManager m_GPIOManager;
CI2CMaster m_I2CMaster; CI2CMaster m_I2CMaster;
CMiniDexed *m_pDexed; CMiniDexed *m_pDexed;
CUSBController *m_pUSB;
static CKernel *s_pThis; static CKernel *s_pThis;
}; };

@ -98,6 +98,15 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt,
m_pTG[i]->activate (); m_pTG[i]->activate ();
} }
if (pConfig->GetUSBGadgetMode())
{
LOGNOTE ("USB In Gadget (Device) Mode");
}
else
{
LOGNOTE ("USB In Host Mode");
}
for (unsigned i = 0; i < CConfig::MaxUSBMIDIDevices; i++) for (unsigned i = 0; i < CConfig::MaxUSBMIDIDevices; i++)
{ {
m_pMIDIKeyboard[i] = new CMIDIKeyboard (this, pConfig, &m_UI, i); m_pMIDIKeyboard[i] = new CMIDIKeyboard (this, pConfig, &m_UI, i);

@ -1,15 +1,24 @@
#!/bin/bash #!/bin/bash
set -ex set -ex
#
# Update top-level modules as a baseline
git submodule update --init --recursive git submodule update --init --recursive
#
# Use fixed master branch of circle-stdlib then re-update
cd circle-stdlib/ cd circle-stdlib/
git checkout e318f89 # Needed to support Circle develop? git checkout 695ab4a
git submodule update --init --recursive
cd - cd -
#
# Optional update submodules explicitly
cd circle-stdlib/libs/circle cd circle-stdlib/libs/circle
git checkout ec09d7e # develop git checkout fe09c4b
cd - cd -
cd circle-stdlib/libs/circle-newlib cd circle-stdlib/libs/circle-newlib
git checkout 48bf91d # needed for circle ec09d7e #git checkout develop
cd - cd -
#
# Use fixed master branch of Synth_Dexed
cd Synth_Dexed/ cd Synth_Dexed/
git checkout c9f5274 git checkout c9f5274
cd - cd -

Loading…
Cancel
Save