Now I have a very noisy output, because I am sending the 4 channels to the DAC as it would be only a stereo. So channel 3&4 is interleaved with channel 1&2. I did some modifications, to at least hear one of the two stereo streams.
Now it’s time to connect my hardware to the Djay.
And it works! 🙂
The next step is to add MIDI interface. Algoriddim Djay did not recognized my device as Reloop Beatpad after cloning VID and PID. Maybe after cloning the MIDI interface it will.
I cloned the MIDI descriptor part from Beatpad. I added EP1 IN and EP2 OUT Bulk endpoints. The addresses are different from the Beatpad endpoint addresses, but as I mentioned earlier I cannot set the endpoint addresses in the FS USB core. I hope the software is not too picky about addresses.
At this point I would like to make a 4 channel sound card out of the 2 channels. I started with modifing the USB descriptors in usbd_audio.c. I more or less cloned the first part of Reloop Beatpad descriptors. So I deleted the Audio Feature descriptor. I modified everything to 4 channel and stuff like that.
Today I looked into the USB descriptors of my Beatpad with USBLyzer.
Here is what I found:
Audio Control Interface
Audio Streaming Interface: ISO OUT: 4ch, 16bit, 44,1 KHz, but max packet size is 384bytes
MIDI streaming Interface: BULK IN and OUT with 32byte maximum packet size
HID interface with vendor defined functions
I introduced some new definitions in usbd_conf.h file, because I have to modify the whole project from stereo to 4 channels later.
/* AUDIO Class Config */
#define USBD_AUDIO_FREQ 48000
#define USBD_AUDIO_CHANNELS 2
#define USBD_AUDIO_BYTES 2
After I had a working demo, I studied the code, to understand how does it work in details. Here is a simplified description:
1) Initialize EP 1 OUT which is the ISO endpoint, and preapare it for receiving.
2) When it receives something in Data_Out, It starts to Play it in the DAC by sending the data to I2S interface with DMA.
3) During the DMA transfer, we have a HalfComlete and a Complete interrupt. They invoke a simple audio synchronization part, which compensates the clock difference between the USB clock and I2S clock. Here I read a bunch of standards and literature about the clock syncronization possibilities of USB Audio Class.
4) While DMA is sending the data to I2S, the USB still receives the packets and stores them in a buffer.