From 9bc36800b905e2ea6fc93dde0a1d76be80b49e82 Mon Sep 17 00:00:00 2001 From: Kevin <68612569+diyelectromusic@users.noreply.github.com> Date: Sat, 30 Dec 2023 12:06:10 +0000 Subject: [PATCH] Set USB Gadget name to MiniDexed and fix setting of USB product (device) ID. Fixes #416 (#593) --- build.sh | 2 +- src/kernel.cpp | 4 +- src/usbminidexedmidigadget.h | 86 ++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 src/usbminidexedmidigadget.h diff --git a/build.sh b/build.sh index 9e8fc7a..b69ba6b 100755 --- a/build.sh +++ b/build.sh @@ -26,7 +26,7 @@ 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}" + OPTIONS="${OPTIONS} -o USB_GADGET_DEVICE_ID_BASE=${USB_DID}" fi # Build circle-stdlib library diff --git a/src/kernel.cpp b/src/kernel.cpp index e7a3738..c06c386 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include "usbminidexedmidigadget.h" LOGMODULE ("kernel"); @@ -69,7 +69,7 @@ bool CKernel::Initialize (void) if (m_Config.GetUSBGadgetMode()) { // Run the USB stack in USB Gadget (device) mode - m_pUSB = new CUSBMIDIGadget (&mInterrupt); + m_pUSB = new CUSBMiniDexedMIDIGadget (&mInterrupt); } else { diff --git a/src/usbminidexedmidigadget.h b/src/usbminidexedmidigadget.h new file mode 100644 index 0000000..bbb5f44 --- /dev/null +++ b/src/usbminidexedmidigadget.h @@ -0,0 +1,86 @@ +// +// usbminidexedmidigadget.h +// +// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi +// Copyright (C) 2022 The MiniDexed Team +// +// Based on circle/usb/gadget/usbmidigadget.h +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +#ifndef _usbminidexedmidigadget_h +#define _usbminidexedmidigadget_h + +#include +#include +#include +#include + +class CUSBMiniDexedMIDIGadget : public CUSBMIDIGadget +{ +private: +#define MDSTRINGDESCRIPTORS 3 + const char *const s_MiniDexedStringDescriptor[MDSTRINGDESCRIPTORS] = + { + "\x04\x03\x09\x04", // Language ID + "probonopd", + "MiniDexed" + }; + +public: + CUSBMiniDexedMIDIGadget (CInterruptSystem *pInterruptSystem) + : CUSBMIDIGadget (pInterruptSystem) + { + } + + ~CUSBMiniDexedMIDIGadget (void) + { + assert(0); + } + +protected: + // Override GetDescriptor frmo CUSBMIDIGadget. + // See CUSBMIDIGadget for details. + // This will only act on the DESCRIPOR_STRING. + // All other descriptors are returned from USBMIDIGadget. + // + const void *GetDescriptor (u16 wValue, u16 wIndex, size_t *pLength) override + { + assert (pLength); + + u8 uchDescIndex = wValue & 0xFF; + + switch (wValue >> 8) + { + case DESCRIPTOR_STRING: + if (!uchDescIndex) + { + *pLength = (u8) s_MiniDexedStringDescriptor[0][0]; + return s_MiniDexedStringDescriptor[0]; + } + else if (uchDescIndex < MDSTRINGDESCRIPTORS) + { + return CUSBMIDIGadget::ToStringDescriptor (s_MiniDexedStringDescriptor[uchDescIndex], pLength); + } + break; + + default: + break; + } + + return CUSBMIDIGadget::GetDescriptor(wValue, wIndex, pLength); + } +}; + +#endif