AndyCap You also mentioned it is possible to run Bela code (C++ here) without xenomai, are we at a state we can do this yet?
That would be a matter of replacing all the __wrap_
calls in the core code removing the __wrap_
, and passing BELA_USE_DEFINE=BELA_USE_POLL
to make
. However, this would still rely on having the PRU code working, which is not yet the case for the AI. I am currently (i.e.: just now) trying to understand what is wrong with receiving inbound data over SPI, and I won't move to the PRU until this is sorted.
In the meantime if you want to run audio on the AI, you should use ALSA. I have some code to write to the SPI DAC, though, which requires this library and the GPIOcontrol files you can get from the Bela code (include/GPIOcontrol.h
and core/GPIOcontrol.cpp
), here it is:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "SPI.h"
#include "GPIOcontrol.h"
const int busSpeedHz = 12000000;
const int wordLength = 32;
#define AD5668_COMMAND_OFFSET 24
#define AD5668_ADDRESS_OFFSET 20
#define AD5668_DATA_OFFSET 4
#define AD5668_REF_OFFSET 0
#include <fcntl.h>
int cs_pin = 6*32 + 17; // P9.17a
int cs_fd;
int my_transfer(uint32_t oword) {
uint32_t iword;
int transmissionLength = 4;
gpio_write(cs_fd, 0);
usleep(30);
int ret = SPIDEV1_transfer((unsigned char*)&oword, (unsigned char*)&iword, transmissionLength);
usleep(30);
gpio_write(cs_fd, 1);
return ret;
}
int main()
{
gpio_export(cs_pin);
cs_fd = gpio_fd_open(cs_pin, O_WRONLY);
gpio_set_dir(cs_pin, OUTPUT_PIN);
gpio_write(cs_fd, 1); // de-assert
if (SPI_DEV1_init(0, busSpeedHz, SPI_SS_LOW, 0, wordLength, SPI_MODE3) == -1)
{
printf("(Main)Initialization failed\r\n");
return -1;
}
else
printf("(Main) initialized - READY\r\n");
uint32_t oword;
// DAC power-on reset sequence
// MOV r2, (0x07 << AD5668_COMMAND_OFFSET)
oword = 0x07 << AD5668_COMMAND_OFFSET;
my_transfer(oword);
// Enable DAC internal reference
// MOV r2, (0x08 << AD5668_COMMAND_OFFSET) | (0x01 << AD5668_REF_OFFSET)
oword = (0x08 << AD5668_COMMAND_OFFSET) | (0x01 << AD5668_REF_OFFSET);
my_transfer(oword);
int count = 0;
while (1)
{
unsigned char channel = 0xf; // 0xf for all channels
uint16_t reg_dac_data = 1000 * count;
oword = ((0x3 << AD5668_COMMAND_OFFSET) | (channel << AD5668_ADDRESS_OFFSET) | (1000*count << AD5668_DATA_OFFSET));
if (my_transfer(oword) == 0)
;
else
printf("(Main) Transaction Failed\r\n");
count++;
if(count > 64)
count = 0;
usleep(10000);
}
gpio_dismiss(cs_fd, cs_pin);
return 0;
}