Implement USBGadgetPin and appropriate boot messages. (#674)

pull/690/head
Kevin 4 months ago committed by GitHub
parent 6664e63fe5
commit 3b033db4af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 27
      src/config.cpp
  2. 7
      src/config.h
  3. 26
      src/kernel.cpp
  4. 28
      src/minidexed.cpp

@ -22,7 +22,6 @@
// //
#include "config.h" #include "config.h"
#include "../Synth_Dexed/src/dexed.h" #include "../Synth_Dexed/src/dexed.h"
#include <circle/gpiopin.h>
CConfig::CConfig (FATFS *pFileSystem) CConfig::CConfig (FATFS *pFileSystem)
: m_Properties ("minidexed.ini", pFileSystem) : m_Properties ("minidexed.ini", pFileSystem)
@ -37,14 +36,9 @@ void CConfig::Load (void)
{ {
m_Properties.Load (); m_Properties.Load ();
m_bUSBGadgetMode = m_Properties.GetNumber ("USBGadget", 0) != 0; m_bUSBGadget = m_Properties.GetNumber ("USBGadget", 0) != 0;
unsigned usbGadgetPinNumber = m_Properties.GetNumber ("USBGadgetPin", 26); // Default to GPIO pin 26 if not specified m_nUSBGadgetPin = m_Properties.GetNumber ("USBGadgetPin", 0); // Default OFF
CGPIOPin usbGadgetPin(usbGadgetPinNumber, GPIOModeInputPullUp); SetUSBGadgetMode(m_bUSBGadget); // Might get overriden later by USBGadgetPin state
if (usbGadgetPin.Read() == 0) // If the pin is pulled down
{
m_bUSBGadgetMode = true;
}
m_SoundDevice = m_Properties.GetString ("SoundDevice", "pwm"); m_SoundDevice = m_Properties.GetString ("SoundDevice", "pwm");
@ -183,11 +177,26 @@ void CConfig::Load (void)
m_bPerformanceSelectChannel = m_Properties.GetNumber ("PerformanceSelectChannel", 0); m_bPerformanceSelectChannel = m_Properties.GetNumber ("PerformanceSelectChannel", 0);
} }
bool CConfig::GetUSBGadget (void) const
{
return m_bUSBGadget;
}
unsigned CConfig::GetUSBGadgetPin (void) const
{
return m_nUSBGadgetPin;
}
bool CConfig::GetUSBGadgetMode (void) const bool CConfig::GetUSBGadgetMode (void) const
{ {
return m_bUSBGadgetMode; return m_bUSBGadgetMode;
} }
void CConfig::SetUSBGadgetMode (bool USBGadgetMode)
{
m_bUSBGadgetMode = USBGadgetMode;
}
const char *CConfig::GetSoundDevice (void) const const char *CConfig::GetSoundDevice (void) const
{ {
return m_SoundDevice.c_str (); return m_SoundDevice.c_str ();

@ -68,7 +68,10 @@ public:
void Load (void); void Load (void);
// USB Mode // USB Mode
bool GetUSBGadgetMode (void) const; // true if in USB gadget mode bool GetUSBGadget (void) const;
unsigned GetUSBGadgetPin (void) const;
bool GetUSBGadgetMode (void) const; // true if in USB gadget mode depending on USBGadget and USBGadgetPin
void SetUSBGadgetMode (bool USBGadgetMode);
// Sound device // Sound device
const char *GetSoundDevice (void) const; const char *GetSoundDevice (void) const;
@ -192,6 +195,8 @@ public:
private: private:
CPropertiesFatFsFile m_Properties; CPropertiesFatFsFile m_Properties;
bool m_bUSBGadget;
unsigned m_nUSBGadgetPin;
bool m_bUSBGadgetMode; bool m_bUSBGadgetMode;
std::string m_SoundDevice; std::string m_SoundDevice;

@ -20,6 +20,7 @@
#include "kernel.h" #include "kernel.h"
#include <circle/logger.h> #include <circle/logger.h>
#include <circle/synchronize.h> #include <circle/synchronize.h>
#include <circle/gpiopin.h>
#include <assert.h> #include <assert.h>
#include <circle/usb/usbhcidevice.h> #include <circle/usb/usbhcidevice.h>
#include "usbminidexedmidigadget.h" #include "usbminidexedmidigadget.h"
@ -93,7 +94,29 @@ bool CKernel::Initialize (void)
} }
} }
if (m_Config.GetUSBGadgetMode()) bool bUSBGadgetMode = false;
if (m_Config.GetUSBGadget())
{
unsigned nUSBGadgetPin = m_Config.GetUSBGadgetPin();
if (nUSBGadgetPin == 0)
{
// No hardware config option
bUSBGadgetMode = true;
}
else
{
// State of USB Gadget Mode determined by state of the pin.
// Pulled down = enable USB Gadget mode
CGPIOPin usbGadgetPin(nUSBGadgetPin, GPIOModeInputPullUp);
if (usbGadgetPin.Read() == 0)
{
bUSBGadgetMode = true;
}
}
}
if (bUSBGadgetMode)
{ {
#if RASPPI==5 #if RASPPI==5
#warning No support for USB Gadget Mode on RPI 5 yet #warning No support for USB Gadget Mode on RPI 5 yet
@ -107,6 +130,7 @@ bool CKernel::Initialize (void)
// Run the USB stack in USB Host (default) mode // Run the USB stack in USB Host (default) mode
m_pUSB = new CUSBHCIDevice (&mInterrupt, &mTimer, TRUE); m_pUSB = new CUSBHCIDevice (&mInterrupt, &mTimer, TRUE);
} }
m_Config.SetUSBGadgetMode(bUSBGadgetMode);
if (!m_pUSB->Initialize ()) if (!m_pUSB->Initialize ())
{ {

@ -102,18 +102,44 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt,
m_pTG[i]->activate (); m_pTG[i]->activate ();
} }
if (pConfig->GetUSBGadgetMode()) unsigned nUSBGadgetPin = pConfig->GetUSBGadgetPin();
bool bUSBGadget = pConfig->GetUSBGadget();
bool bUSBGadgetMode = pConfig->GetUSBGadgetMode();
if (bUSBGadgetMode)
{ {
#if RASPPI==5 #if RASPPI==5
LOGNOTE ("USB Gadget (Device) Mode NOT supported on RPI 5"); LOGNOTE ("USB Gadget (Device) Mode NOT supported on RPI 5");
#else #else
if (nUSBGadgetPin == 0)
{
LOGNOTE ("USB In Gadget (Device) Mode"); LOGNOTE ("USB In Gadget (Device) Mode");
}
else
{
LOGNOTE ("USB In Gadget (Device) Mode [USBGadgetPin %d = LOW]", nUSBGadgetPin);
}
#endif #endif
} }
else else
{
if (bUSBGadget)
{
if (nUSBGadgetPin == 0)
{
// This shouldn't be possible...
LOGNOTE ("USB State Unknown");
}
else
{
LOGNOTE ("USB In Host Mode [USBGadgetPin %d = HIGH]", nUSBGadgetPin);
}
}
else
{ {
LOGNOTE ("USB In Host Mode"); LOGNOTE ("USB In Host Mode");
} }
}
for (unsigned i = 0; i < CConfig::MaxUSBMIDIDevices; i++) for (unsigned i = 0; i < CConfig::MaxUSBMIDIDevices; i++)
{ {

Loading…
Cancel
Save