Also, I was thinking that you can bitbang the SPI protocol using the Bela digital or analog outputs! This should give you about 22.05kHz bitrate if using the digital outputs, or 44.1kHz using the analog outputs at 88.2kHz (which could also mean running them at 22.05kHz and OR-wire together the odd and even channels) ... lots of possibilities there. I have some untested code for that:
int clockChannel = //Bela digital channel where to send the clock
int misoChannel = // Bela digital channel where to send the data
int chipSelectChannel= // Bela digital channel to use as chip select(if needed)
// device-dependent configuration:
bool chipSelectIdle = 1; // chip select idle value
bool chipSelectActive = 0; // chip select active value
bool samplingEdge = 1; // 1 means that the receiving device samples on a rising clock edge, 0 means it samples on a falling edge
bool nonSamplingEdge = !samplingEdge;
bool setup()
{
pinMode(context, 0, clockChannel, OUTPUT);
pinMode(context, 0, misoChannel, OUTPUT);
pinMode(context, 0, chipSelectChannel, OUTPUT);
}
void render()
{
...
static bool outputBitValue = 0;
static bool chipSelectOutputValue = chipSelectIdle;
static bool clockValue = 0;
static uint32_t outputWord;
static int clockCount;
static int currentIndexInOutputWord = -1;
static unsigned int wordLength = sizeof(outputWord);
for(int n = 0; n < context->digitalFrames; ++n)
{
if(newWordAvailableToWrite) // up to you
{
outputWord = // set value here;
currentIndexInOutputWord = 0;
chipSelectOutputValue = chipSelectActive;
clockCount = 0;
}
if(currentIndexInOutputWord >= 0)
{
// generate a clock at half sampling rate
if((clockCount++ & 2) == 0)
{
clockValue = samplingEdge;
}
else
{
clockValue = nonSamplingEdge;
outputBitValue = (bool)(outputWord & (1 << currentIndexInOutputWord));
++currentIndexInOutputWord;
}
if(currentIndexInOutputWord == wordLength && clockValue == samplingEdge)
{
currentIndexInOutputWord = -1; // done transmitting one word
chipSelectOutputValue = chipSelectIdleValue;
}
}
// write clock
digitalWriteOnce(context, n, clockChannel, clockValue);
// write output bit
digitalWriteOnce(context, n, misoChannel, outputBitValue);
// write chip select value
digitalWriteOnce(context, n, chipSelectChannel, chipSelectValue);
}
...
}