From 6e158a593b6fa9348f94744135add81587645877 Mon Sep 17 00:00:00 2001 From: naturarum <34517524+naturarum@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:49:00 +0100 Subject: [PATCH 1/2] Digitone II: USB Multi 0.4.1-experimental, a draft module (42-channel class-compliant USB audio) --- sdk/digitone-ii/modules/usb-multi/LICENSE | 338 ++++++++++++++ sdk/digitone-ii/modules/usb-multi/README.md | 55 +++ sdk/digitone-ii/modules/usb-multi/TESTING.md | 41 ++ sdk/digitone-ii/modules/usb-multi/build.json | 94 ++++ .../modules/usb-multi/media/thumbnail.svg | 1 + .../modules/usb-multi/modwerk.module.json | 107 +++++ sdk/digitone-ii/modules/usb-multi/src/um.c | 439 ++++++++++++++++++ .../modules/usb-multi/src/um_stubs.s | 45 ++ ...usb-multi-0.4.1-experimental-os1.12.elemod | 347 ++++++++++++++ .../digitone-ii-usb-multi.json | 12 + 10 files changed, 1479 insertions(+) create mode 100644 sdk/digitone-ii/modules/usb-multi/LICENSE create mode 100644 sdk/digitone-ii/modules/usb-multi/README.md create mode 100644 sdk/digitone-ii/modules/usb-multi/TESTING.md create mode 100644 sdk/digitone-ii/modules/usb-multi/build.json create mode 100644 sdk/digitone-ii/modules/usb-multi/media/thumbnail.svg create mode 100644 sdk/digitone-ii/modules/usb-multi/modwerk.module.json create mode 100644 sdk/digitone-ii/modules/usb-multi/src/um.c create mode 100644 sdk/digitone-ii/modules/usb-multi/src/um_stubs.s create mode 100644 sdk/imports/packages/usb-multi/usb-multi-0.4.1-experimental-os1.12.elemod create mode 100644 src/community/module-changelogs/digitone-ii-usb-multi.json diff --git a/sdk/digitone-ii/modules/usb-multi/LICENSE b/sdk/digitone-ii/modules/usb-multi/LICENSE new file mode 100644 index 0000000000..9efa6fbc96 --- /dev/null +++ b/sdk/digitone-ii/modules/usb-multi/LICENSE @@ -0,0 +1,338 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 2 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 . + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Moe Ghoul, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/sdk/digitone-ii/modules/usb-multi/README.md b/sdk/digitone-ii/modules/usb-multi/README.md new file mode 100644 index 0000000000..55d1d97711 --- /dev/null +++ b/sdk/digitone-ii/modules/usb-multi/README.md @@ -0,0 +1,55 @@ +# USB Multi + +A fourth USB CONFIG choice for the Digitone II, **USB MULTI/MIDI**. With it the Digitone shows up as a +class-compliant USB Audio 2.0 device with 42 inputs at 48 kHz and 24 bits, no driver needed. + +| USB inputs | what | +| --- | --- | +| 1-32 | the 16 tracks as stereo pairs: track 1 on 1-2, track 2 on 3-4, and so on to track 16 on 31-32 | +| 33-34 | the main mix | +| 35-36 | the delay's return | +| 37-38 | the reverb's return | +| 39-40 | the chorus's return | +| 41-42 | the audio inputs | + +USB AUDIO/MIDI stays the stock stereo mode. USB MIDI, OVERBRIDGE and audio from the computer are unchanged. + +## Quick tutorial + +1. Open SETTINGS (FUNC + PROJECT), then SYSTEM > USB CONFIG. +2. Choose USB MULTI/MIDI, the fourth item, and press YES. The Digitone leaves the computer and comes back with 42 + inputs. +3. In your audio app, pick the Digitone as the input device and arm the pairs you want. +4. Before an OS update, or before going back to the stock OS, pick one of Elektron's three choices again. + +## How it works + +The DSP already produces these 42 channels every 32-sample block: 14 arrive in the SSI0 words, 28 in the DSP's SPI +reply. Stock USB AUDIO/MIDI sends two of them (USB OUT's choice). With USB MULTI/MIDI chosen, the mod packs all 42 +into a larger packet ring (15 packets of 882 bytes, 3-byte subslots) and gives the stream and the mode-5 descriptors +42 channels. The stock sender's rate estimate and restart flags are kept and used as the stock uses them; every packet +stays inside its slot whatever the rate estimate says (0.4). + +The choice is stored as USB CONFIG 3. Every stock reader of USB CONFIG turns a 3 into 2, so the stock code runs USB +AUDIO/MIDI's mode as it always does; only this mod tells the two apart. Switching between USB AUDIO/MIDI and USB +MULTI/MIDI restarts USB with the stock's own stop and start, so the computer sees the device leave and come back. + +The mod uses no core event. It patches nine sites of its own (`build.json`), none of them a base site. + +## Changes to stock flows + +- **SETTINGS > SYSTEM > USB CONFIG** gets a fourth item. The three stock items are unchanged; USB AUDIO/MIDI's + check box is not ticked while USB MULTI/MIDI is chosen. The item exists only while the module is in the build. +- **Going back to the stock OS:** the stock OS reads a saved USB MULTI/MIDI as USB MIDI at power-on. Choosing USB + CONFIG again there sets it right. + +## Limitations + +- 48 kHz and 24 bits only. All 42 inputs are always sent, whatever USB OUT is set to. +- Sending audio from the computer to the Digitone works as in USB AUDIO/MIDI (stereo). +- Not yet run on Modwerk's Digitone II base; see [TESTING.md](TESTING.md). + +## Credits and licence + +By naturarum, from a study of OS 1.12. First released in Digiwerk (github.com/naturarum/dn2-cfw), built there with +an elekloader fork; this folder is now its source. GPL-2.0-or-later ([LICENSE](LICENSE)). diff --git a/sdk/digitone-ii/modules/usb-multi/TESTING.md b/sdk/digitone-ii/modules/usb-multi/TESTING.md new file mode 100644 index 0000000000..5e36ffe374 --- /dev/null +++ b/sdk/digitone-ii/modules/usb-multi/TESTING.md @@ -0,0 +1,41 @@ +# USB Multi: testing + +## This version on Modwerk's base + +Not tested. 0.4.1-experimental has not been built with Modwerk's toolchain or run on Modwerk's Digitone II base yet. +Still to do, on a Digitone II with OS 1.12 and the base alone plus this module: + +- build it from this folder and record the package's and the image's SHA-256; +- USB MULTI/MIDI chosen: the 42 inputs on a Mac and on an iPhone or iPad; a recording of busy patterns for at least + an hour, checked for dropouts; +- switching between all four USB CONFIG choices, with the computer connected; +- USB AUDIO/MIDI, USB MIDI and OVERBRIDGE with the module present and not chosen: unchanged; +- a project save and reload, and a power cycle with USB MULTI/MIDI chosen; +- an OS transfer with Elektron Transfer after a long quiet spell (the case that crashed 0.3); +- the base's own events (draw, keys, encoders, settings) still working beside it; +- screenshots of SETTINGS > SYSTEM > USB CONFIG with the fourth item. + +## Earlier runs, in Digiwerk builds (not this base) + +0.3 and 0.4 ran on a Digitone II, OS 1.12, in Digiwerk builds (github.com/naturarum/dn2-cfw), linked with +Digiwerk's own elekloader core and its other mods. Tester: naturarum (the author). + +0.4.1-experimental, the version here, is 0.4 with the fourth USB CONFIG item's callbacks rewritten for Modwerk: in +0.4 they were assembly modelled instruction for instruction on USB AUDIO/MIDI's own callbacks. YES, the turn and the +check box are now C in `um.c`, and the name is eight instructions of our own in `um_stubs.s`. Apart from that and +the comments, the code is 0.4's. The rewrite has not run on a unit yet. + +| version | date | what was seen | +| --- | --- | --- | +| 0.3 | 1 and 3 November 2026 | 42 inputs on a Mac; with AUM on an iPhone, the phone picked up the new channel layout quickly. Three crashes in all: one when starting an OS transfer after the USB tests, one after a while of not playing, one not described. | +| 0.4 | 4 November 2026 | 42 inputs, recordings clean; about an hour of playing with USB MULTI/MIDI on, no lock. Seven other builds carrying it ran about a minute each. | + +What 0.4 changed: 0.3's sender could write past its packet ring, after the stock rate estimate went wrong across a +pause longer than about one second with no other USB traffic (found by reading the code and by a host test under +AddressSanitizer). 0.4 keeps every packet inside its slot whatever the estimate says. Not shown to be the cause of +the 0.3 crashes, though it fits them; no crash has been seen with 0.4 so far. + +## Host and emulator checks + +In Digiwerk: a host test of the packing code under AddressSanitizer, and emulator boots of the builds. These are +for iteration only and qualify nothing. diff --git a/sdk/digitone-ii/modules/usb-multi/build.json b/sdk/digitone-ii/modules/usb-multi/build.json new file mode 100644 index 0000000000..d40efecbed --- /dev/null +++ b/sdk/digitone-ii/modules/usb-multi/build.json @@ -0,0 +1,94 @@ +{ + "schemaVersion": 1, + "sources": [ + "src/um.c", + "src/um_stubs.s" + ], + "defsym": {}, + "cflags": [], + "weak": [], + "subscribe": [], + "contribute": [], + "collections": {}, + "copied": [], + "regions": [], + "claims": [ + "settings:SYSTEM > USB CONFIG", + "usb:USB AUDIO/MIDI stream and descriptors", + "memory:SRAM 0x80009700-0x8000cb36 (Overbridge's packet ring)" + ], + "requires": [], + "derive": null, + "releases": { + "1.12": { + "defsym": {}, + "cflags": [], + "sites": [ + { + "addr": "0x400040e6", + "len": 6, + "stockSha256": "4ccb73ab1a83a4b42f5e2f068f076ebc531a5e7abfefff1b8d279e2dcbacdcbd", + "op": "jsr", + "target": "um_dqh" + }, + { + "addr": "0x40027772", + "len": 6, + "stockSha256": "d9b6012720be6c5051f159adc950143d0dd1960589fb6e62764c25111903ccc9", + "op": "jsr", + "target": "um_send" + }, + { + "addr": "0x400279d4", + "len": 6, + "stockSha256": "d9b6012720be6c5051f159adc950143d0dd1960589fb6e62764c25111903ccc9", + "op": "jsr", + "target": "um_mute" + }, + { + "addr": "0x4000655e", + "len": 6, + "stockSha256": "4202be4af42748c3dfbcf9742e626d26394a3504d2de6eb8e45ea02723c3a6a5", + "op": "jsr", + "target": "um_start" + }, + { + "addr": "0x40006880", + "len": 8, + "stockSha256": "3d1009518b8a72f12cc47e46e8da2980056530779dbf3a2db241eeb940de9418", + "op": "jmp", + "target": "um_desc" + }, + { + "addr": "0x400cf22c", + "len": 2, + "stockSha256": "b3529f78982d3e1f0e3966ca195e56a9a3825209fc606fb231c0855a98fa25a8", + "op": "bytes", + "new": "6e06", + "kind": "code" + }, + { + "addr": "0x40105220", + "len": 6, + "stockSha256": "f9e4e460a94d586bd50a8538ac6ecd2a217e485ea070088393ded7cc52205994", + "op": "jsr", + "target": "um_menu_hook" + }, + { + "addr": "0x40104d54", + "len": 6, + "stockSha256": "01c6e7c73a918fc96c0ce8f7325505133f27f53201e2dfa0db12bee6e58f1304", + "op": "jsr", + "target": "um_cfg_get" + }, + { + "addr": "0x40104e02", + "len": 6, + "stockSha256": "80985e81a9746e733cfd2a4490954040cea5b1b66bb002b0eac12321b9591c8b", + "op": "jmp", + "target": "um_mode_set" + } + ] + } + } +} diff --git a/sdk/digitone-ii/modules/usb-multi/media/thumbnail.svg b/sdk/digitone-ii/modules/usb-multi/media/thumbnail.svg new file mode 100644 index 0000000000..0d6d4fb35f --- /dev/null +++ b/sdk/digitone-ii/modules/usb-multi/media/thumbnail.svg @@ -0,0 +1 @@ +USB MULTI 42 IN diff --git a/sdk/digitone-ii/modules/usb-multi/modwerk.module.json b/sdk/digitone-ii/modules/usb-multi/modwerk.module.json new file mode 100644 index 0000000000..61ae6e5f62 --- /dev/null +++ b/sdk/digitone-ii/modules/usb-multi/modwerk.module.json @@ -0,0 +1,107 @@ +{ + "schemaVersion": 3, + "id": "usb-multi", + "name": "USB Multi", + "version": "0.4.1-experimental", + "machine": "digitone-ii", + "category": "midi-usb", + "exclusive": false, + "author": { + "github": "naturarum", + "credits": [ + "naturarum" + ] + }, + "maintainers": [ + "naturarum" + ], + "presentation": { + "label": "USB MULTI", + "family": "USB audio", + "summary": "A fourth USB CONFIG choice that sends all 42 channels to the computer: the 16 tracks as stereo pairs, the main mix, the FX returns and the inputs.", + "overview": "USB MULTI/MIDI makes the Digitone II a class-compliant USB Audio 2.0 device with 42 inputs at 48 kHz and 24 bits, no driver needed. The DSP already produces these channels every block; the mod sends them all instead of the two USB AUDIO/MIDI sends. USB AUDIO/MIDI stays the stock stereo mode, and USB MIDI, OVERBRIDGE and audio from the computer are unchanged.", + "highlights": [ + "42 inputs, class compliant, 48 kHz, 24 bits", + "Track 1 on inputs 1-2, track 16 on 31-32", + "Main mix, delay, reverb and chorus returns, and the audio inputs too", + "The stock USB AUDIO/MIDI, USB MIDI and OVERBRIDGE choices unchanged" + ], + "usage": [ + "Record every track to its own pair in a DAW in one pass.", + "Use it with an iPhone or iPad app that takes class-compliant multichannel audio." + ] + }, + "access": { + "location": "SETTINGS > SYSTEM > USB CONFIG, the fourth choice: USB MULTI/MIDI.", + "steps": [ + "Open SETTINGS (FUNC + PROJECT), then SYSTEM > USB CONFIG.", + "Choose USB MULTI/MIDI, the fourth item, and press YES. The Digitone leaves the computer and comes back with 42 inputs.", + "In your audio app, pick the Digitone as the input device: 1-32 are the 16 tracks as stereo pairs (track n on 2n-1 and 2n), 33-34 the main mix, 35-40 the delay, reverb and chorus returns, 41-42 the audio inputs.", + "Before an OS update or before going back to the stock OS, pick one of Elektron's three choices again." + ], + "screenshots": [] + }, + "controls": [], + "compatibility": { + "releases": [ + "1.12" + ], + "requires": [], + "conflicts": [], + "limitations": [ + "48 kHz and 24 bits only; all 42 inputs are always sent, whatever USB OUT is set to.", + "Saved as USB CONFIG 3, which the stock OS reads as USB MIDI at power-on: pick one of the stock choices again after going back to stock.", + "Not yet run on Modwerk's Digitone II base: the hardware runs so far were on Digiwerk builds (TESTING.md)." + ] + }, + "platform": { + "kind": "elemod", + "core": "1.1", + "build": "build.json", + "events": [], + "claims": [ + "settings:SYSTEM > USB CONFIG", + "usb:USB AUDIO/MIDI stream and descriptors", + "memory:SRAM 0x80009700-0x8000cb36 (Overbridge's packet ring)" + ] + }, + "resources": { + "memoryBytes": 2772, + "fastBytes": 0, + "load": { + "display": "Not measured on a unit", + "method": "unmeasured", + "conditions": "Runs in the stock audio block handler, once per 32-sample block, only while USB MULTI/MIDI streams: it packs 42 channels into its packet ring in place of the stock stereo pack. Memory measured from the linked image: the base alone leaves 255,328 bytes of its RAM free, with this module 252,556." + } + }, + "evidence": { + "tier": "none", + "moduleVersion": "0.4.1-experimental", + "sourceSha256": null, + "reports": [ + "TESTING.md" + ], + "hardware": null, + "verifiedBy": null + }, + "tests": { + "report": "TESTING.md", + "summary": "0.3 and 0.4 ran on a Digitone II in Digiwerk builds (OS 1.12, Digiwerk's own core), with a Mac and an iPhone. 0.4.1-experimental (0.4 with the USB CONFIG item's callbacks rewritten) has not run on a unit or on Modwerk's Digitone II base yet." + }, + "license": { + "spdx": "GPL-2.0-or-later", + "file": "LICENSE", + "declaration": "Original work by naturarum, from a study of OS 1.12. First released in Digiwerk (github.com/naturarum/dn2-cfw)." + }, + "media": [ + { + "path": "media/thumbnail.svg", + "kind": "thumbnail", + "caption": "USB Multi", + "alt": "Forty-two thin bars in pairs, standing for the USB inputs.", + "credit": "naturarum", + "license": "GPL-2.0-or-later", + "source": "Original vector illustration; not a device screenshot." + } + ] +} diff --git a/sdk/digitone-ii/modules/usb-multi/src/um.c b/sdk/digitone-ii/modules/usb-multi/src/um.c new file mode 100644 index 0000000000..3a9c4756b0 --- /dev/null +++ b/sdk/digitone-ii/modules/usb-multi/src/um.c @@ -0,0 +1,439 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* usb-multi (Digitone II OS 1.12): a fourth USB CONFIG choice, USB MULTI/MIDI, with which the Digitone sends all 42 of + * its DSP's output channels to the computer as a class-compliant USB Audio 2.0 device, 24-bit at 48 kHz, the 16 + * tracks first as stereo pairs. USB AUDIO/MIDI stays Elektron's stereo mode. For dn2-cfw's UM builds + * (github.com/naturarum/dn2-cfw, notes/USB01-class-compliant-multichannel.md). + * 0.1 ran on the unit 31 Oct (the 42 channels on a Mac; the sequencer lagged: see um_frame). 0.2: um_frame (no lag on + * the unit). 0.3: the 42 channels as their own USB CONFIG choice, in place of USB AUDIO/MIDI's stereo. 0.4: every + * packet inside its slot of the ring, whatever state the stock's sender left and whatever its rate says (um_next, + * um_rate, um_target, um_run). + * + * The DSP already sends 42 channels every 32-sample block, in normal running: channels 0-13 in the SSI0 TDM words + * (0x4e6e7100, two halves of 32 frames x 16 slots x 4 bytes, the 24-bit sample in the low three bytes), 14-41 in its + * SPI reply (0x800053c0, 32 rows of 84 bytes, two 24-bit big-endian samples in each 6 bytes). Its output table + * (DSP 0x25d760) puts the main mix on 0-1, track n's L and R on 2n and 2n + 1, the delay, reverb and chorus returns + * on 34-39 and the inputs on 40-41. Stock USB AUDIO mode sends two of them (USB OUT's choice): the block handler + * 0x40025e36 builds a stereo buffer and calls the sender 0x40003d00, which packs 5 to 7 frames a packet (the rate + * re-estimated every 1,024 packets by 0x400036fc) into a ring of 16 x 56 bytes at 0x80009000, each packet a dTD + * (0x400036c0) primed on endpoint index 7, EP 0x83 IN (0x40005a86). At the start of a stream, 0x40003b32 primes 11 + * silent packets of 6 stereo frames from the same ring. + * + * With USB MULTI/MIDI the stream carries all 42, track one first (channel one is track one): + * USB 1-32 tracks 1-16, L and R (DSP 2-33) + * USB 33-34 the main mix (DSP 0-1) + * USB 35-40 delay, reverb, chorus (DSP 34-39) + * USB 41-42 the inputs (DSP 40-41) + * 3-byte little-endian subslots (the DSP's own 24 bits): a frame is 126 bytes, a packet at most 7 x 126 = 882, + * one high-speed transaction. The ring is 15 packets of 882 bytes at 0x80009700-0x8000cb36: inside Overbridge's + * packet ring (16 x 1,012 at 0x80008c00, mode 6 only), after the stock ring and the stock receive buffers + * (0x80009380-0x80009700, audio from the computer, mode 5). The stock sender's state words are kept and used as it + * uses them, so its rate estimate, restart and skip flags behave as before. + * + * The choice. USB CONFIG is the byte 0x405ce898 of the saved settings: 0 USB MIDI, 1 OVERBRIDGE, 2 USB AUDIO/MIDI; + * USB MULTI/MIDI stores 3. The stock reads it through 0x400bb798, which turns anything above 2 into 2, so to every + * stock reader 3 is USB AUDIO/MIDI, USB mode 5, and the stock code runs mode 5 as it always does; only this mod + * tells the two apart. The start-up code 0x400cf216 reads the byte itself (1 -> mode 6, 2 -> mode 5, anything else + * -> mode 2, USB MIDI): one branch makes it 2 or more -> mode 5. Elektron's OS reading a 3 starts in USB MIDI, and + * USB CONFIG picked again sets it right. The descriptors of mode 5 live in the main OS's data, in RAM, and the stock + * writes their run-time values once, at the USB start-up (0x4000677a, from 0x40006c52); um_on says which set they + * hold, the stereo one or ours, and the stream follows it. A switch between USB AUDIO/MIDI and USB MULTI/MIDI keeps + * the mode (5), so the stock 0x40006c16 would not restart USB: um_mode_set does, with the stock's own stop and start, + * the new descriptors written in between, and the computer sees the device leave and come back. + * + * Sites (build.json): + * - 0x40027772 jsr 0x40003d00 (the block's stereo frames) -> um_send; 0x400279d4 (the silent path) -> um_mute; + * - 0x4000655e jsr 0x40003b32 (the stream's start) -> um_start; with um_on off, each calls the stock one; + * - 0x400040e6: move.l #0x40380000,d0, the dQH word of EP 0x83 IN (one transaction, 56 bytes) -> jsr um_dqh (that, + * or 0x43720000, 882 bytes, with um_on); + * - 0x40006880, the last write, cache push and rts of 0x4000677a -> jmp um_desc. 0x4000677a writes into the + * descriptors (each configuration's wTotalLength, string lengths), pushing each byte out of the data cache for + * the controller's DMA. um_desc does the stock's last write, then the descriptors for the choice: input terminal + * 5 and AS interface 2 alt 1 carry 42 channels (bmChannelConfig stays 0: no spatial positions), the format 3-byte + * subslots of 24 bits, EP 0x83's wMaxPacketSize 882, or the stock's 2 channels, 4 bytes of 32 bits, 56. The stored + * image keeps Elektron's descriptor bytes: only the copy in RAM changes; + * - 0x400cf22c, the start-up's bne (the byte is not 2: USB MIDI) -> bgt (it is below 2); + * - the USB CFG menu (0x40104f42 builds it, three items, each four std::function: the name, the choice on YES, its + * check box, the choice on a turn): 0x40105220, after the third item -> jsr um_menu_hook, which adds the fourth + * (um_menu_add, with our four callbacks); 0x40104d54, USB AUDIO/MIDI's check box, jsr + * 0x400bb798 -> um_cfg_get (0-3, so a 3 does not tick it); 0x40104e02, USB AUDIO/MIDI's choice, jmp 0x40006c16 + * -> um_mode_set. + * USB CONFIG's other choices (OVERBRIDGE, USB MIDI) and their descriptors are untouched. + */ +typedef unsigned long u32; +typedef unsigned char u8; + +#ifndef UM_HOST /* the stock OS's addresses (a host test supplies its own: dn2-cfw scripts/um01/test_um.c) */ +#define DTD_GET ((u32 (*)(void))0x400036c0) /* the next free IN dTD (in d0) */ +#define EP_PRIME ((int (*)(u32, u32))0x40005a86) /* (endpoint index, dTD chain) */ +#define RATE_EST ((u32 (*)(u32, u32 *))0x400036fc) /* (last estimate, &frames per packet 16.16) */ +#define ZERO ((void (*)(void *, u32))0x4013419c) /* memset 0 */ +#define START_CB 0x400039feu /* the first priming dTD's completion handler */ +#define START_2 ((void (*)(void))0x40003a92) /* the rest of the stream's start */ + +#define W(a) (*(volatile u32 *)(a)) +#define ON W(0x4058eee8) /* the host has the IN alternate setting on */ +#define RESTART W(0x4058eed0) +#define SKIP W(0x4058eec4) /* frames to drop (sync) */ +#define UNMUTE W(0x4058eee4) +#define FILL W(0x4058ee84) /* frames in the packet being filled */ +#define CUR W(0x4058ee78) /* that packet */ +#define IDX W(0x4058eea0) /* the ring's next packet */ +#define CNT W(0x4058ee7c) /* packets to the next rate estimate */ +#define FRAC W(0x4058ee80) +#define TARGET W(0x40287a8c) /* frames in this packet, 5 to 7 */ +#define EST W(0x40287a88) +#define RATE (*(u32 *)0x40287a84) +#define FLAG_A W(0x4058eedc) +#define FLAG_B W(0x4058eed4) +#define START_P W(0x4058eebc) +#define TXPOS W(0xfc045640) /* the SSI DMA's place, as the block handler reads it */ +#define TXHALF 0x4e6e8900u + +#define SSI0 0x4e6e7100u +#define SPI0 0x800053c0u +#define RING 0x80009700u + +#define STOCK_SEND ((void (*)(const void *, int))0x40003d00) /* the stereo sender (frames, count) */ +#define STOCK_START ((void (*)(u32))0x40003b32) /* the stereo stream's start */ +#define CFG (*(volatile signed char *)0x405ce898) /* USB CONFIG as saved: 0 MIDI, 1 OVERBRIDGE, 2 AUDIO; 3 ours */ +#define CFG_SET ((void (*)(volatile void *, const void *, u32))0x400bb65c) /* (setting, bytes, n): set, mark to save */ +#define MODE W(0x4058f2a8) /* the USB mode running: 2 USB MIDI, 5 USB AUDIO/MIDI, 6 Overbridge */ +#define MODE_SET ((void (*)(u32))0x40006c16) /* a new mode: stop, the mode and its table, start */ +#define USB_STOP ((void (*)(void))0x40006bac) +#define USB_START ((void (*)(void))0x40006bc6) /* the start, after the stop's 30 ticks */ +#define NEW ((void *(*)(u32))0x40120544) /* operator new */ +#define ITEM ((void (*)(void *, void *, void *, void *, void *, int, int))0x401173b8) /* a menu item's constructor */ +#define FN_DEL ((void (*)(void *))0x40188366) /* std::function's destructor */ +#define MGR_NAME 0x40104b22u /* USB AUDIO/MIDI's four std::function managers: a lambda without state, and three */ +#define MGR_YES 0x40104b74u /* that keep the menu's pointer (the same as ours) */ +#define MGR_BOX 0x40104bd0u +#define MGR_TURN 0x40104c2cu + +/* a byte of the descriptors, out of the data cache as 0x4000677a does (the controller reads them by DMA) */ +static void um_poke(u32 a, u8 v) +{ + *(volatile u8 *)a = v; + __asm__ volatile ("cpushl %%dc,(%0)" : : "a"(a) : "memory"); +} +#define POKE um_poke +#endif +#define NPKT 15u +#define FRAME 126u +#define PKT 882u /* 7 frames */ + +/* One frame, 42 channels as 3-byte little-endian samples (126 bytes): USB 1-12 from SSI slots 2-13, 13-32 from SPI + samples 0-19, 33-34 from SSI slots 0-1, 35-42 from SPI samples 20-27. The main OS's start-up (0x40000554) sets + CACR 0xa50ce100 (data cache on, by default cache-inhibited) and ACR0 0x4007e020 (0x40000000-0x47ffffff copyback), + so the SSI DMA buffers at 0x4e6e7100 are uncached and every read of them goes to memory: the SSI words are read + once each, as 32-bit words (the sample in their low three bytes), and the order is code, not a table; the SPI row + (two big-endian samples in each 6 bytes) and the ring are in SRAM. 0.1 read every SSI byte (42 uncached reads a + frame, 1,344 a block) and the sequencer lagged on the unit (31 Oct). */ +static inline void um_put(volatile u8 *d, u32 w) /* byte stores: never merged into a word at an odd address */ +{ + d[0] = (u8)w; + d[1] = (u8)(w >> 8); + d[2] = (u8)(w >> 16); +} + +static inline void um_swap(volatile u8 *d, const u8 *s, int n) +{ + while (n-- > 0) { + d[0] = s[2]; + d[1] = s[1]; + d[2] = s[0]; + d += 3; + s += 3; + } +} + +#ifdef UM_HOST /* a host test: the unit's big-endian 32-bit read, from bytes */ +#define SSI_WORD(s, i) ((u32)(s)[4 * (i) + 1] << 16 | (u32)(s)[4 * (i) + 2] << 8 | (u32)(s)[4 * (i) + 3]) +#else +#define SSI_WORD(s, i) ((u32)((const volatile unsigned int *)(s))[i]) +#endif + +static inline void um_frame(volatile u8 *d, const u8 *ssi, const u8 *spi) +{ + int c; + for (c = 0; c < 12; c++) /* tracks 1-6: SSI slots 2-13 */ + um_put(d + 3 * c, SSI_WORD(ssi, 2 + c)); + um_swap(d + 36, spi, 20); /* tracks 7-16: SPI samples 0-19 */ + um_put(d + 96, SSI_WORD(ssi, 0)); /* the main mix: SSI slots 0-1 */ + um_put(d + 99, SSI_WORD(ssi, 1)); + um_swap(d + 102, spi + 60, 8); /* delay, reverb, chorus, the inputs: SPI samples 20-27 */ +} + +/* The next packet's slot. IDX is the stock sender's, which counts 16 slots: after its stream it can be 15, one past + our ring (0.3 then wrote its first packet over 0x8000caae-0x8000ce20) */ +static u32 um_next(void) +{ + u32 i = IDX < NPKT ? IDX : 0; + IDX = i + 1 < NPKT ? i + 1 : 0; + return RING + i * PKT; +} + +/* Frames a packet, 16.16, from the stock's estimate (0x40003732, on the USB interrupt's start-of-frame list: timer + ticks over USB microframes, the microframes counted in 13 bits, so a pause between two measurements longer than + 8,192 of them counts short and the estimate comes out too high; the first after a reset is taken unfiltered). Real + rates are 6 frames a packet within a few hundred ppm (48 kHz over 8,000 microframes a second): outside 5.5 to 6.5 + the estimate is wrong and 6 goes instead, so the packets keep pace with the microframes */ +static u32 um_rate(void) +{ + u32 r = RATE; + return r < 0x58000u || r > 0x68000u ? 0x60000u : r; +} + +/* Frames in a packet: the stock's rate gives 5 to 7, and nothing in it stops a wrong estimate from giving more, which + its 56-byte slots barely feel but ours would: a packet of 7 x 126 = 882 bytes fills a slot and is wMaxPacketSize */ +static u32 um_target(u32 t) +{ + return t < 5 ? 5 : t > PKT / FRAME ? PKT / FRAME : t; +} + +/* CUR is one of our slots (the stock sender's packets lie in its own ring, 0x80009000-0x80009380) */ +static int um_slot(u32 p) +{ + return p >= RING && p < RING + NPKT * PKT && (p - RING) % PKT == 0; +} + +static void um_run(int n, int silent) +{ + u32 done = 0, k, j; + const u8 *ssi, *spi; + u8 *d; + if (!ON) + return; + if (RESTART) { + RESTART = 0; + FILL = 0; + TARGET = 6; + FRAC = 0; + EST = 0xffffffff; + CNT = 0; + } + TARGET = um_target(TARGET); + if (FILL >= TARGET || !um_slot(CUR)) /* a packet the stock began, or one past its size: a new one */ + FILL = 0; + if ((int)SKIP > 0) { + k = (int)SKIP < n ? SKIP : (u32)n; + SKIP = SKIP - k; + n -= k; + done = k; + } + ssi = (const u8 *)(SSI0 + (TXPOS < TXHALF ? 0x800u : 0u)); + spi = (const u8 *)SPI0; + while (n > 0) { + k = TARGET - FILL; + if ((int)k > n) + k = n; + if (FILL == 0) + CUR = um_next(); + d = (u8 *)(CUR + FILL * FRAME); + if (silent || !UNMUTE) + ZERO(d, k * FRAME); + else + for (j = 0; j < k; j++, d += FRAME) + um_frame(d, ssi + (done + j) * 64, spi + (done + j) * 84); + done += k; + n -= k; + FILL = FILL + k; + if (FILL == TARGET) { + volatile u32 *t = (volatile u32 *)DTD_GET(); + u32 bytes = FILL * FRAME; + t[2] = CUR; + t[3] = (CUR + 0x1000) & ~(u32)0xfff; + t[1] = bytes << 16 | 0x80; + t[8] = bytes; + t[9] = 0; + EP_PRIME(7, (u32)t); + FILL = 0; + CNT = CNT - 1; + if ((int)CNT < 1) { + EST = RATE_EST(EST, (u32 *)&RATE); + CNT = 0x400; + } + FRAC = FRAC + um_rate(); + TARGET = um_target(FRAC >> 16); + FRAC = FRAC & 0xffff; + } + } +} + +/* the descriptors and the stream are ours (USB MULTI/MIDI) or the stock's stereo ones (USB AUDIO/MIDI); um_dqh + (um_stubs.s) reads it too */ +u32 um_on; + +/* in place of 0x40003d00: the block's frames (the stereo ones are not used with um_on) */ +void um_send(const void *stereo, int n) +{ + if (!um_on) { + STOCK_SEND(stereo, n); + return; + } + um_run(n, 0); +} + +void um_mute(const void *stereo, int n) +{ + if (!um_on) { + STOCK_SEND(stereo, n); + return; + } + um_run(n, 1); +} + +/* in place of 0x40003b32: the stream's start, 11 silent packets of 6 frames, as the stock does with its own sizes */ +void um_start(u32 p) +{ + int i; + if (!um_on) { + STOCK_START(p); + return; + } + FLAG_A = 1; + FLAG_B = 1; + RESTART = 1; + for (i = 0; i < 11; i++) { + volatile u32 *t = (volatile u32 *)DTD_GET(); + u32 b = um_next(); + ZERO((void *)b, 6 * FRAME); + t[2] = b; + t[3] = (b + 0x1000) & ~(u32)0xfff; + t[1] = (6 * FRAME) << 16 | 0x80; + t[0] = 0xdead0001; + t[8] = 6 * FRAME; + t[9] = i == 0 ? START_CB : 0; + EP_PRIME(7, (u32)t); + } + START_P = p; + START_2(); +} + +/* mode 5's descriptors for the choice: ours (42 channels) or the stock's (2), and um_on with them */ +static void um_apply(u32 on) +{ + um_on = on; + POKE(0x402fc407u, on ? 42 : 2); /* input terminal 5 (the Digitone's audio): bNrChannels */ + POKE(0x402fc494u, on ? 42 : 2); /* AS interface 2 alt 1, AS_GENERAL: bNrChannels */ + POKE(0x402fc49eu, on ? 3 : 4); /* FORMAT_TYPE I: bSubslotSize */ + POKE(0x402fc49fu, on ? 24 : 32); /* bBitResolution */ + POKE(0x402fc4a4u, on ? PKT & 0xff : 56); /* EP 0x83 IN: wMaxPacketSize, little-endian */ + POKE(0x402fc4a5u, on ? PKT >> 8 : 0); +} + +/* in place of 0x4000677a's last instructions (0x40006880: move.b #0x22,(a0); cpushl; rts), reached by jmp with the + caller's return address on the stack, once at the USB start-up: that write, then the descriptors for the choice */ +void um_desc(void) +{ + POKE(0x402fc000u, 0x22); /* the stock's own last write */ + um_apply(CFG == 3); +} + +/* USB CONFIG as saved, 0-3 (the stock's 0x400bb798 gives 0-2): USB AUDIO/MIDI's check box, through 0x40104d54, and + ours */ +u32 um_cfg_get(void) +{ + int v = CFG; + return v < 0 ? 0 : v > 3 ? 3 : (u32)v; +} + +/* in place of the stock's 0x40006c16(mode) in USB AUDIO/MIDI's choice (0x40104e02, a jmp: the mode on the stack as + its argument), and from USB MULTI/MIDI's: the descriptors for the choice, and USB restarted when the mode stays 5 */ +void um_mode_set(u32 mode) +{ + u32 on = CFG == 3; + if (mode == 5 && on != um_on) { + if (MODE == 5) { /* 0x40006c16 without its "same mode" return */ + USB_STOP(); + um_apply(on); + USB_START(); + return; + } + um_apply(on); /* not served in another mode */ + } + MODE_SET(mode); +} + +/* USB MULTI/MIDI chosen (YES, or a turn, on the fourth item): saved as 3, as the stock's 0x400bb7ba saves 0-2 */ +void um_choose(void) +{ + unsigned char v = 3; + CFG_SET(&CFG, &v, 1); + um_mode_set(5); +} + +/* The fourth item of the USB CFG menu, after USB AUDIO/MIDI, made as 0x40104f42 makes each of the three: four + std::function (16 bytes as this OS lays them out: the lambda's pointer, a word, the manager, the invoker), the name, + the choice on YES, the check box, the choice on a turn; the item (0x54 bytes) built from them, then handed to the + menu (its vtable's third entry) and the four destroyed. The managers are USB AUDIO/MIDI's; the invokers ours. */ +typedef struct { + void *p; + u32 x; + u32 mgr; + u32 inv; +} um_fn; + +const char um_name[] = "USB MULTI/MIDI"; +void um_inv_name(void); /* um_stubs.s: the string's place comes in a0 */ + +/* The other three callbacks. The menu calls each through its std::function with the function's storage first (its + first word points to a word holding the menu: um_fn_make) and the call's own arguments after it, and reads d0. */ +#define MENU_BUILD ((u32 (*)(void *))0x40104f42) /* builds the USB CFG menu, its boxes from the setting */ +#define BOX_DRAW ((u32 (*)(u32, u32, u32, u32, u32))0x40115adc) /* draws a box's picture */ +#define BOX_PICS (*(const u32 *)0x44645d84) /* the empty box's picture; the ticked one 28 bytes on */ + +/* YES on the item: the choice, then the menu built again so the boxes follow */ +u32 um_inv_yes(void ***fn) +{ + void *menu = **fn; + um_choose(); + return MENU_BUILD(menu); +} + +/* a turn on the item: as YES when it turns up (step above 0) */ +u32 um_inv_turn(void ***fn, u32 x, long step) +{ + void *menu = **fn; + (void)x; + if (step <= 0) + return 0; + um_choose(); + return MENU_BUILD(menu); +} + +/* the item's box, ticked when USB CONFIG is 3 */ +u32 um_inv_box(void ***fn, u32 x, u32 a, u32 b, u32 c) +{ + u32 pic = BOX_PICS + (um_cfg_get() == 3 ? 28 : 0); + (void)fn; + (void)x; + return BOX_DRAW(a, pic, b + 11, c, 0); +} + +static void um_fn_make(um_fn *f, u32 size, void *menu, u32 mgr, u32 inv) +{ + void **p = (void **)NEW(size); + if (size == 4) + *p = menu; + f->p = p; + f->x = 0; + f->mgr = mgr; + f->inv = inv; +} + +void um_menu_add(void *menu) +{ + um_fn f[4]; + void *item; + um_fn_make(&f[0], 1, menu, MGR_NAME, (u32)um_inv_name); + um_fn_make(&f[1], 4, menu, MGR_YES, (u32)um_inv_yes); + um_fn_make(&f[2], 4, menu, MGR_BOX, (u32)um_inv_box); + um_fn_make(&f[3], 4, menu, MGR_TURN, (u32)um_inv_turn); + item = NEW(0x54); + ITEM(item, &f[0], &f[1], &f[2], &f[3], -1, 8); + ((void (*)(void *, void *))(*(u32 **)menu)[2])(menu, item); + FN_DEL(&f[3]); + FN_DEL(&f[2]); + FN_DEL(&f[1]); + FN_DEL(&f[0]); +} diff --git a/sdk/digitone-ii/modules/usb-multi/src/um_stubs.s b/sdk/digitone-ii/modules/usb-multi/src/um_stubs.s new file mode 100644 index 0000000000..f7d0f7ef5c --- /dev/null +++ b/sdk/digitone-ii/modules/usb-multi/src/um_stubs.s @@ -0,0 +1,45 @@ +| SPDX-License-Identifier: GPL-2.0-or-later +| usb-multi (Digitone II OS 1.12): the three pieces um.c cannot hold as plain C: the dQH word at 0x400040e6, the hook +| in the middle of the USB CFG menu's builder at 0x40105220, and the fourth item's name, which the menu asks for with +| the string's place in a0. The item's other three callbacks are C, in um.c. + + .text + +| in place of 0x400040e6's move.l #0x40380000,d0 (FUN_400040a6, mode 5's endpoints): the dQH capabilities of EP 0x83 +| IN, one transaction of 56 bytes (stereo) or of 882 (ours); d0 and the flags as that move leaves them + .globl um_dqh +um_dqh: + tst.l um_on + bne.s 1f + move.l #0x40380000,%d0 + rts +1: move.l #0x43720000,%d0 + rts + +| in place of 0x40105220's three instructions in 0x40104f42 (the USB CFG menu, after its third item): +| movea.l (a2),a0; clr.l -(sp); move.l d6,-(sp). The fourth item first (a2: the menu); d0, d1, a0 and a1 are not +| read after them before a call. + .globl um_menu_hook +um_menu_hook: + move.l %a2,-(%sp) + jsr um_menu_add + addq.l #4,%sp + movea.l (%sp)+,%a1 | the return address + clr.l -(%sp) + move.l %d6,-(%sp) + movea.l (%a2),%a0 + jmp (%a1) + +| the fourth item's name: the menu calls it through its std::function with the place for a std::string in a0, and +| builds the string there from um_name with the OS's own constructor (0x401ceab8: place, C string, allocator). +| The allocator is empty and never read; its argument is the address of the saved a0. + .globl um_inv_name +um_inv_name: + move.l %a0,-(%sp) + pea (%sp) + pea um_name + move.l %a0,-(%sp) + jsr 0x401ceab8 + lea 12(%sp),%sp + move.l (%sp)+,%d0 + rts diff --git a/sdk/imports/packages/usb-multi/usb-multi-0.4.1-experimental-os1.12.elemod b/sdk/imports/packages/usb-multi/usb-multi-0.4.1-experimental-os1.12.elemod new file mode 100644 index 0000000000..3407f233a0 --- /dev/null +++ b/sdk/imports/packages/usb-multi/usb-multi-0.4.1-experimental-os1.12.elemod @@ -0,0 +1,347 @@ +{ + "elemod": 2, + "id": "usb-multi", + "version": "0.4.1-experimental", + "title": "USB Multi", + "description": "A fourth USB CONFIG choice that sends all 42 channels to the computer: the 16 tracks as stereo pairs, the main mix, the FX returns and the inputs.", + "category": "midi-usb", + "author": "naturarum", + "license": "GPL-2.0-or-later", + "target": { + "device": "digitone-mk2", + "product": "Digitone II", + "os": "1.12", + "syx_sha256": "7e5b8a733d4ab1fdf7e5d22757f7d8eddaa3cbf71d0858874a791844c02ceb35", + "section3_sha256": "a098f620019b2ad38fd7e0397df39501fb1cf6bc26d0283915f34c49446fdf1a", + "section3_len": 3196288 + }, + "sections": { + ".run": { + "align": 4, + "len": 2767, + "parts": [ + [ + "hex", + "202f000423c0000000004a80675c702a207c402fc40713c0402fc407f468207c402fc49413c0402fc494f4687003207c402fc49e13c0402fc49ef4687018207c402fc49f13c0402fc49ff4687072207c402fc4a413c0402fc4a4f4687003207c402fc4a51080f4684e757002207c402fc40713c0402fc407f468207c402fc49413c0402fc494f4687004207c402fc49e13c0402fc49ef4687020207c402fc49f13c0402fc49ff4687038207c402fc4a413c0402fc4a4f4684200207c402fc4a51080f4684e752f0376022f027539405ce898222f0014206f0018226f001c203944645d84b6826d2241e8000b42af001c2f4900182f4800142f4000102f41000c241f261f4ef940115adc06800000001c41e8000b42af001c2f4900182f4800142f4000102f41000c241f261f4ef940115adc4fefffd048d77cfc2e2f00344ab94058eed0672842b94058eed0700642b94058ee8472ff23c040287a8c42b94058ee8023c140287a8842b94058ee7c7407203940287a8cb4806400012c700723c040287a8c243940287a8cb4b94058ee84630000e220394058ee7806807fff69000c80000033ad620000cc243c000003724c4200014a81660000bc207c4058eec44a906f0000c2be906f0000ea2c10203c4e6e88ff9e869d90b0b9fc045640650000b8223c4e6e79002f41002c4a876f7a2a472e0d207940287a8c220820394058ee849280bbc16d0003369088dbc02e014ab94058ee846700016e26794058ee78727e20394058ee844c010800d7c04aaf0038660a4ab94058eee4660001d0747e4c0728002f022f0b4eb94013419c508fdc87dfb94058ee84243940287a8cb4b94058ee8467604a8d6e884cd77cfc4fef00304e7542b94058ee84207c4058eec44a906e00ff424286203c4e6e88ffb0b9fc0456406400ff4c243c4e6e71002f42002c6000ff487205b2806300fed270056000fecc9f904cd77cfc2039fc0456404fef00304e754eb9400036c0747e22394058ee84227c4058ee7820402151000820110680000010000280fffff0004c0218002140000c20014840424008c00007214000042141002042a800242f08487800074eb940005a8642b94058ee84508f53b94058ee7c4ab94058ee7c6f000094203940287a842040d1fcfffa800022394058ee80b1fc00010000620001b4d28023c14058ee80720720394058ee8042404840b280640001b8700723c040287a8c203c0000ffffc1b94058ee804a8d6e00fe726000fee6700eb0b94058eea0650001be20394058eea0223c00000372740e4c0018005280068180009700b4806402428023c04058eea023c14058ee786000fe5a203940287a882f3c40287a842f004eb9400036fc508f23c040287a88203c0000040023c04058ee7c203940287a84204022394058ee80d1fcfffa8000b1fc000100006300ff48600000f64a876700fe4022067a54ed894c065800707e4c070800260b224b06830000002428050684800053fc204406858000541428412c40d9ef002cddcb41e8ffc445ec0008201a2200424148412400e08a128056891342fffe1341ffffb3c366e412a8000256881368fffe00011368fffd00025689b88866e820142200424148412400e08a1740006043eb00661742006117410062202c00042200424148412400e08a17400063174200641741006512a8000256881368fffe00011368fffd00025689ba8866e847eb007e06840000005406850000005449ec004006830000007eb7ce6700fd622044224b41e8ffc445ec00086000ff5070064840d28023c14058ee80720720394058ee8042404840b2806500fe4c7405b4806300fe46700523c040287a8c203c0000ffffc1b94058ee806000fe409bcd4ab94058ee846600fcd26000fe3a7001223c8000970023c04058eea023c14058ee786000fcb6222f0004202f00084ab90000000067164ab94058eee8670c42af00082f4000046000fbaa4e752f4000082f4100044ef940003d00222f0004202f00084ab90000000067184ab94058eee8670e72012f4100082f4000046000fb744e752f4000082f4100044ef940003d004fefffe848d7043c2a2f001c2f4500144ab900000000670001307001428323c04058eedc23c04058eed423c04058eed04eb9400036c07a0e223c800097002440bab94058eea06500009a20394058eea0243c000003724c0028005280280206828000a700d8810282fffff0002204ba806402428023c04058eea02a3c000002f4487802f42f014eb94013419c254400082542000c508f203c02f400802540000424bcdead0001254500204a83677c42aa00247a0b2f0a487800074eb940005a865283508fba836600ff682a2f001423c54058eebc4cd7043c4fef00184ef940003a92700123c04058eea0283c80009700487802f4243c8000a0002f012a3c000002f44eb94013419c254400082542000c508f203c02f400802540000424bcdead0001254500204a836684203c400039fe7601254000242f0a487800074eb940005a86508f6000feea2f45001c4cd7043c4fef00184ef940003b327022207c402fc00013c0402fc000f4681239405ce8987003b380730157814a0057c07100448023c0000000004a81665c702a207c402fc40713c0402fc407f468207c402fc49413c0402fc494f4687003207c402fc49e13c0402fc49ef4687018207c402fc49f13c0402fc49ff4687072207c402fc4a413c0402fc4a4f4687003207c402fc4a51080f4684e757002207c402fc40713c0402fc407f468207c402fc49413c0402fc494f4687004207c402fc49e13c0402fc49ef4687020207c402fc49f13c0402fc49ff4687038207c402fc4a413c0402fc4a4f4684200207c402fc4a51080f4684e757139405ce8987203b2806c0470034e754a806cfa42804e75598f2f027405222f000c1039405ce898b481670e2f41000c241f588f4ef940006c167403b5804a0057c071004480b0b90000000067de7405b4b94058f2a8671e2f002f4100084ebaf78e588f222f00042f41000c241f588f4ef940006c162f4000044eb940006bac202f00042f004ebaf766588f241f588f4ef940006bc670034e56fff8206e000820501d40ffff2d50fff848780001486effff2f3c405ce8984eb9400bb65c487800054ebaff544fef00102d6efff800084e5e4ef940104f424e56fff8206e00084aae00106f3a700320502d50fff848780001486effff2f3c405ce8981d40ffff4eb9400bb65c487800054ebaff0c4fef00102d6efff800084e5e4ef940104f4242804e5e4e7570034e56fffc48780001486effff2f3c405ce8981d40ffff4eb9400bb65c487800054ebafece4fef00104e5e4e754fefffa848d7443c48780001247c401205442c6f00604e924878000442af002441f9000000002f400020203c40104b222f48002c2f4000284e922040208e487800042f400034203c40104b7441fafef42f48004042af00382f40003c4e922040208e487800042f400048203c40104bd041faf6ee2f48005442af004c2f4000504e922040208e4878005441fafef82f40005c203c40104c2c2f48006842af00602f4000644e92487800084878ffff2a0f0685000000642f05280f0684000000582f04260f06830000004c2f03240f0682000000402f0224402f004eb9401173b84fef003020562f0a247c401883662f0e206800084e902f054e922f044e922f034e922f024e924cef443c00184fef00704e754ab9000000006608203c403800004e75203c437200004e752f0a4eb900000000588f225f42a72f0620524ed12f0848574879000000002f084eb9401ceab84fef000c201f4e750000555342204d554c54492f4d49444900" + ] + ] + }, + ".bss": { + "align": 4, + "size": 4 + } + }, + "symbols": { + "um_apply": [ + ".run", + 0 + ], + "um_run.part.0": [ + ".run", + 306 + ], + "um_dqh": [ + ".run", + 2680 + ], + "um_name": [ + ".run", + 2752 + ], + "um_on": [ + ".bss", + 0 + ], + "um_inv_box": [ + ".run", + 198 + ], + "um_choose": [ + ".run", + 2360 + ], + "um_mode_set": [ + ".run", + 2090 + ], + "um_menu_hook": [ + ".run", + 2704 + ], + "um_desc": [ + ".run", + 1834 + ], + "um_inv_yes": [ + ".run", + 2216 + ], + "um_mute": [ + ".run", + 1434 + ], + "um_inv_turn": [ + ".run", + 2282 + ], + "um_menu_add": [ + ".run", + 2406 + ], + "um_cfg_get": [ + ".run", + 2066 + ], + "um_start": [ + ".run", + 1488 + ], + "um_send": [ + ".run", + 1382 + ], + "um_inv_name": [ + ".run", + 2724 + ] + }, + "exports": [ + "um_cfg_get", + "um_choose", + "um_desc", + "um_dqh", + "um_inv_box", + "um_inv_name", + "um_inv_turn", + "um_inv_yes", + "um_menu_add", + "um_menu_hook", + "um_mode_set", + "um_mute", + "um_name", + "um_on", + "um_send", + "um_start" + ], + "imports": [], + "weak": [], + "relocs": [ + [ + ".run", + 6, + "abs32", + "sec:.bss", + 0 + ], + [ + ".run", + 1392, + "abs32", + "sec:.bss", + 0 + ], + [ + ".run", + 1444, + "abs32", + "sec:.bss", + 0 + ], + [ + ".run", + 1506, + "abs32", + "sec:.bss", + 0 + ], + [ + ".run", + 1874, + "abs32", + "sec:.bss", + 0 + ], + [ + ".run", + 2138, + "abs32", + "sec:.bss", + 0 + ], + [ + ".run", + 2440, + "abs32", + "sec:.run", + 2724 + ], + [ + ".run", + 2682, + "abs32", + "sec:.bss", + 0 + ], + [ + ".run", + 2708, + "abs32", + "sec:.run", + 2406 + ], + [ + ".run", + 2730, + "abs32", + "sec:.run", + 2752 + ] + ], + "sites": [ + { + "addr": "0x400040e6", + "len": 6, + "stock_sha256": "4ccb73ab1a83a4b42f5e2f068f076ebc531a5e7abfefff1b8d279e2dcbacdcbd", + "new": "4eb900000000", + "kind": "code", + "relocs": [ + [ + 2, + "abs32", + "sym:um_dqh", + 0 + ] + ] + }, + { + "addr": "0x40027772", + "len": 6, + "stock_sha256": "d9b6012720be6c5051f159adc950143d0dd1960589fb6e62764c25111903ccc9", + "new": "4eb900000000", + "kind": "code", + "relocs": [ + [ + 2, + "abs32", + "sym:um_send", + 0 + ] + ] + }, + { + "addr": "0x400279d4", + "len": 6, + "stock_sha256": "d9b6012720be6c5051f159adc950143d0dd1960589fb6e62764c25111903ccc9", + "new": "4eb900000000", + "kind": "code", + "relocs": [ + [ + 2, + "abs32", + "sym:um_mute", + 0 + ] + ] + }, + { + "addr": "0x4000655e", + "len": 6, + "stock_sha256": "4202be4af42748c3dfbcf9742e626d26394a3504d2de6eb8e45ea02723c3a6a5", + "new": "4eb900000000", + "kind": "code", + "relocs": [ + [ + 2, + "abs32", + "sym:um_start", + 0 + ] + ] + }, + { + "addr": "0x40006880", + "len": 8, + "stock_sha256": "3d1009518b8a72f12cc47e46e8da2980056530779dbf3a2db241eeb940de9418", + "new": "4ef9000000004e71", + "kind": "code", + "relocs": [ + [ + 2, + "abs32", + "sym:um_desc", + 0 + ] + ] + }, + { + "addr": "0x400cf22c", + "len": 2, + "stock_sha256": "b3529f78982d3e1f0e3966ca195e56a9a3825209fc606fb231c0855a98fa25a8", + "new": "6e06", + "kind": "code", + "relocs": [] + }, + { + "addr": "0x40105220", + "len": 6, + "stock_sha256": "f9e4e460a94d586bd50a8538ac6ecd2a217e485ea070088393ded7cc52205994", + "new": "4eb900000000", + "kind": "code", + "relocs": [ + [ + 2, + "abs32", + "sym:um_menu_hook", + 0 + ] + ] + }, + { + "addr": "0x40104d54", + "len": 6, + "stock_sha256": "01c6e7c73a918fc96c0ce8f7325505133f27f53201e2dfa0db12bee6e58f1304", + "new": "4eb900000000", + "kind": "code", + "relocs": [ + [ + 2, + "abs32", + "sym:um_cfg_get", + 0 + ] + ] + }, + { + "addr": "0x40104e02", + "len": 6, + "stock_sha256": "80985e81a9746e733cfd2a4490954040cea5b1b66bb002b0eac12321b9591c8b", + "new": "4ef900000000", + "kind": "code", + "relocs": [ + [ + 2, + "abs32", + "sym:um_mode_set", + 0 + ] + ] + } + ], + "collections": {}, + "contribute": [], + "copied": [], + "resources": { + "regions": [], + "names": [ + "settings:SYSTEM > USB CONFIG", + "usb:USB AUDIO/MIDI stream and descriptors", + "memory:SRAM 0x80009700-0x8000cb36 (Overbridge's packet ring)" + ], + "core": "1.1" + }, + "requires": [ + "core" + ], + "conflicts": [], + "signature": null +} diff --git a/src/community/module-changelogs/digitone-ii-usb-multi.json b/src/community/module-changelogs/digitone-ii-usb-multi.json new file mode 100644 index 0000000000..3887b7c9f3 --- /dev/null +++ b/src/community/module-changelogs/digitone-ii-usb-multi.json @@ -0,0 +1,12 @@ +[ + { + "version": "0.4.1-experimental", + "date": "2026-11-23", + "changes": [ + "First release for Digitone II OS 1.12.", + "USB MULTI/MIDI, a fourth choice in SETTINGS > SYSTEM > USB CONFIG, sends 42 channels to the computer.", + "Inputs 1-32 are the 16 tracks as stereo pairs, then the main mix, the delay, reverb and chorus returns and the audio inputs.", + "Class compliant, 48 kHz, 24 bits: no driver needed." + ] + } +] From 48caf0fd0d3f7522631423e8379f9e1fe30f2739 Mon Sep 17 00:00:00 2001 From: naturarum <34517524+naturarum@users.noreply.github.com> Date: Mon, 30 Nov 2026 10:39:58 +0100 Subject: [PATCH 2/2] USB Multi: 0.4.1-experimental ran on a Digitone II with Modwerk's base (MW41, 30 November 2026) --- sdk/digitone-ii/modules/usb-multi/TESTING.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sdk/digitone-ii/modules/usb-multi/TESTING.md b/sdk/digitone-ii/modules/usb-multi/TESTING.md index 5e36ffe374..0a3b2e76cf 100644 --- a/sdk/digitone-ii/modules/usb-multi/TESTING.md +++ b/sdk/digitone-ii/modules/usb-multi/TESTING.md @@ -2,10 +2,17 @@ ## This version on Modwerk's base -Not tested. 0.4.1-experimental has not been built with Modwerk's toolchain or run on Modwerk's Digitone II base yet. -Still to do, on a Digitone II with OS 1.12 and the base alone plus this module: +Built with Modwerk's pinned toolchain (the isolated Docker build): `usb-multi-0.4.1-experimental-os1.12.elemod`, +SHA-256 `af6d8fbc94f15171c9efd8ed4f33a2c382aee1a38554b9248a10a3fcc40dcebf`. Linked with Modwerk's Digitone II base +(`base/digitone-ii-next` at `c69793f8e`) and stock OS 1.12, alone, into the test image MW41, SHA-256 +`af0671ed337595ca8b4900e0c3ff83c7aa10c3e62d6f18e1c3263b0891bd52f5`. + +| date | build | tester | as reported | +| --- | --- | --- | --- | +| 30 November 2026 | MW41 on a Digitone II, OS 1.12 | naturarum (the author) | "ok mw41 flashed and working". No per-test results were reported. | + +Not reported yet, on that build: -- build it from this folder and record the package's and the image's SHA-256; - USB MULTI/MIDI chosen: the 42 inputs on a Mac and on an iPhone or iPad; a recording of busy patterns for at least an hour, checked for dropouts; - switching between all four USB CONFIG choices, with the computer connected; @@ -23,7 +30,7 @@ Digiwerk's own elekloader core and its other mods. Tester: naturarum (the author 0.4.1-experimental, the version here, is 0.4 with the fourth USB CONFIG item's callbacks rewritten for Modwerk: in 0.4 they were assembly modelled instruction for instruction on USB AUDIO/MIDI's own callbacks. YES, the turn and the check box are now C in `um.c`, and the name is eight instructions of our own in `um_stubs.s`. Apart from that and -the comments, the code is 0.4's. The rewrite has not run on a unit yet. +the comments, the code is 0.4's. The rewrite ran on a unit on 30 November 2026, on Modwerk's base (above). | version | date | what was seen | | --- | --- | --- |