MCU selection/setup for UAC1.0, SPI, LEDs, key matrix? - Page 1
Forum section: electronics / general

author: kraethi
author_rank: Newbie
timestamp: September 23, 2023, 06:11:42 am
content: Hello all, I'm working on putting an unusual combination of features together into a project, and I'd much appreciate some advice in terms of what hardware is most suitable for it!The general idea is to have a keyboard-like device for selecting music based on some characteristics for the purposes of providing ambiance for tabletop roleplaying games. So it takes power in (probably over usb-c), and based on user interaction with the buttons, send audio out, along with some UX in the form of per-button lighting and a small display.I am planning on using AMB Labs' Gamma1.5 DAC/Amphttps://www.amb.org/audio/gamma1.5/for all things analog on this project, largely since I have one built already. This device has two boards-- the top one implements UAC1/2 in isochronous-asynchronous mode, outputting i2s to the bottom board, which does the DAC and analog output. I'm aware that this device is probably overkill, but hey, I already have one around.Here is a list of the functions I'd like the main board to handle, in order of descending importance:1. Reading .mp3 files off of a microSD card (SPI?) to send over USB UAC1. For the most part, lossless or uncompressed versions of these files don't exist. UAC1.0 should be enough in this case.2. USB audio output to the AMB Gamma1.5. This should probably be UAC1 given the files. UAC2 would be nice to implement later, but seems much more difficult and not really necessary?3. Scanning a ~35-key matrix and implementing some more advanced keyboard-style functions (function layers, long key presses, modifier key)4. Driving a 128x64 monochrome OLED display over SPI for simple text/progress bar rendering5. Sending data to ~35 WS2812B-style RGB LEDsOn Raspberry Pi this was all pretty trivial to get working, but I'm much less skilled with C and lower-level code. I will eagerly use any existing drivers and libraries I can get my hands on, particularly for UAC2 and things like the display driver. I am also fine with using additional ICs which may make this list of functions more achievable. The plan is to build a custom PCB supporting all of these functions (resembling a keyboard PCB with some extra headers).My initial rationale was that this is something like a keyboard that plays audio, so I started looking at the boards supported by QMK Firmware (https://github.com/qmk/qmk_firmware), but ultimately I think it's more like an audio player that also has keyboard functionality! That said, the STM32s seemed like a good starting point. I've looked at ChibiOS as a starting point since that's what QMK uses, but it seems there are some issues with the UAC2 stack, so I have also just learned of the EZ-USB FX2 and the XMOS X-CORE (and of course there is the AVR audio-widget project upon which the top half of the AMB Gamma1.5 is based). The main thing I'm struggling with in terms of finding examples is that almost nobody ever wants to do USB audio OUT, they typically want to go the other way and have their MCU either do ADC from a mic, or do DAC as a sound card.Any advice on implementation? Seems easy enough to find drivers for any given purpose, but identifying implementations that all work on the same platform together is where I start to lose the plot. I am new to all this, so I also assume I have made some naive assumptions or overlooked some obvious facts along the way.I think my first goal on some STM32-Discovery board (or similar) is to make a device that will deliver audio data to the AMB Gamma1.5 over UAC1.0, likely from a short .mp3 stuffed into the firmware.Thank you for reading!

author: brucehoult
author_rank: Super Contributor
timestamp: September 23, 2023, 06:33:13 am
content: You're only making one of these? And you already have the functionality working on a Raspberry Pi, using stock apps and high level scripting such as bash or Python or something?Given that you can buy a Pi Zero 2 W for under $20 and various Pi 3/4 clones (or RISC-V) with a lot more USB ports etc for a few bucks more ... is it worth your time to do it with bare metal programming on a $5 microcontroller?

author: kraethi
author_rank: Newbie
timestamp: September 23, 2023, 06:45:47 am
content: One is the plan for now-- I'm not against making more in the future, but fabrication costs for the fancy enclosure are the real limit moreso than the electronics (though the Gamma1.5 isn't incredibly cheap either).When you put it like that, the Pi does make a lot of sense to consider! I guess I'm still in the "don't know what I don't know" phase of design where I'm figuring out if a MCU is reasonable to consider-- so I would say this counts as a point for the Pi.The main reason I was considering something lower-level was for admittedly fairly aesthetic reasons, such as faster startup, though I'm sure I could get deeper into the weeds on making a Pi boot faster.If there were some easy-enough STM32 solution I'd go for it (If I could just get QMK to stop being a USB HID and become a USB Audio Device...), but your perspective makes sense. Thanks for the advice!