forked from PAWPAW-Mirror/lib_xua
Basic hook up of audio to buffer (without FIFO) - output audible!
This commit is contained in:
@@ -6,8 +6,6 @@ TARGET = RPI_HAT_60QFN.xn
|
||||
XCC_FLAGS = -fcomment-asm -Xmapper --map -Xmapper MAPFILE -Os -report \
|
||||
-g -Wno-unused-function -Wno-timing -DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSB_TILE=tile[1]
|
||||
|
||||
#-DSDA_HIGH=2 -DSCL_HIGH=1 -fxscope
|
||||
|
||||
# The USED_MODULES variable lists other module used by the application. These
|
||||
# modules will extend the SOURCE_DIRS, INCLUDE_DIRS and LIB_DIRS variables.
|
||||
# Modules are expected to be in the directory above the BASE_DIR directory.
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
// Copyright (c) 2017-2018, XMOS Ltd, All rights reserved
|
||||
|
||||
// A very simple *example* of a USB audio application (and as such is un-verified for production)
|
||||
#include <stdint.h>
|
||||
|
||||
#include <xs1.h>
|
||||
#include <platform.h>
|
||||
|
||||
#include "xua.h"
|
||||
#include "xud.h"
|
||||
#include "i2s.h"
|
||||
#include "i2c.h"
|
||||
#include "gpio.h"
|
||||
@@ -15,8 +17,8 @@
|
||||
#include "debug_print.h"
|
||||
|
||||
// Port declarations. Note, the defines come from the xn file
|
||||
on tile[0]: buffered out port:32 p_i2s_dac[] = {XS1_PORT_1M}; //DAC
|
||||
on tile[0]: buffered in port:32 p_i2s_adc[] = {XS1_PORT_1N}; //Unused currently
|
||||
on tile[0]: buffered out port:32 p_i2s_dac[] = {XS1_PORT_1N}; //DAC
|
||||
on tile[0]: buffered in port:32 p_i2s_adc[] = {XS1_PORT_1F}; //Unused currently
|
||||
on tile[0]: buffered out port:32 p_lrclk = XS1_PORT_1O; //I2S Bit-clock
|
||||
on tile[0]: out port p_bclk = XS1_PORT_1P; //I2S L/R-clock
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
[[distributable]]
|
||||
void AudioHub(server i2s_frame_callback_if i2s,
|
||||
chanend c_aud,
|
||||
chanend c_audio_hub,
|
||||
client i2c_master_if ?i_i2c,
|
||||
client output_gpio_if dac_reset)
|
||||
{
|
||||
int32_t samples[8] = {0}; // Array used for looping back samples
|
||||
|
||||
int32_t samples_out[NUM_USB_CHAN_OUT] = {0};
|
||||
int32_t samples_in[NUM_USB_CHAN_IN] = {0};
|
||||
|
||||
// Set reset DAC
|
||||
dac_reset.output(0);
|
||||
@@ -29,19 +29,21 @@ void AudioHub(server i2s_frame_callback_if i2s,
|
||||
i2s_config.mclk_bclk_ratio = (MCLK_48/DEFAULT_FREQ)/64;
|
||||
|
||||
debug_printf("I2S init\n");
|
||||
break;
|
||||
break;
|
||||
|
||||
case i2s.receive(size_t n_chans, int32_t in_samps[n_chans]):
|
||||
for (int i = 0; i < n_chans; i++) samples[i] = in_samps[i]; // copy samples
|
||||
break;
|
||||
for (int i = 0; i < n_chans; i++) samples_in[i] = in_samps[i];
|
||||
break;
|
||||
|
||||
case i2s.send(size_t n_chans, int32_t out_samps[n_chans]):
|
||||
for (int i = 0; i < n_chans; i++) out_samps[i] = samples[i]; // copy samples
|
||||
break;
|
||||
for (int i = 0; i < n_chans; i++) out_samps[i] = samples_out[i];
|
||||
break;
|
||||
|
||||
case i2s.restart_check() -> i2s_restart_t restart:
|
||||
restart = I2S_NO_RESTART; // Keep on looping
|
||||
break;
|
||||
for (int i = 0; i < NUM_USB_CHAN_IN; i++) c_audio_hub <: samples_in[i];
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub :> samples_out[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <xs1.h>
|
||||
|
||||
#include "xua_commands.h"
|
||||
#include "xud.h"
|
||||
#include "testct_byref.h"
|
||||
@@ -135,6 +138,8 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
|
||||
// printintln(MAX_OUT_SAMPLES_PER_SOF_PERIOD);
|
||||
|
||||
int loopback_samples[MAX_OUT_SAMPLES_PER_SOF_PERIOD] = {0};
|
||||
int32_t samples_out[NUM_USB_CHAN_OUT] = {0};
|
||||
int32_t samples_in[NUM_USB_CHAN_IN] = {0};
|
||||
|
||||
while(1){
|
||||
XUD_Result_t result;
|
||||
@@ -218,6 +223,7 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
|
||||
clocks = clockcounter / MCLK_48;
|
||||
mod_from_last_time = clockcounter % MCLK_48;
|
||||
|
||||
//Scale for working out number of samps to take from device for input
|
||||
if(AUDIO_CLASS == 2)
|
||||
{
|
||||
clocks <<= 3;
|
||||
@@ -226,20 +232,16 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
|
||||
{
|
||||
clocks <<= 6;
|
||||
}
|
||||
asm volatile("stw %0, dp[g_speed]"::"r"(clocks)); // g_speed = clocks
|
||||
|
||||
//Write to feedback EP buffer
|
||||
if (AUDIO_CLASS == 2)
|
||||
{
|
||||
int usb_speed;
|
||||
asm volatile("stw %0, dp[g_speed]"::"r"(clocks)); // g_speed = clocks
|
||||
|
||||
|
||||
if (AUDIO_CLASS == 2)
|
||||
{
|
||||
fb_clocks[0] = clocks;
|
||||
}
|
||||
else
|
||||
{
|
||||
fb_clocks[0] = clocks >> 2;
|
||||
}
|
||||
fb_clocks[0] = clocks;
|
||||
}
|
||||
else
|
||||
{
|
||||
fb_clocks[0] = clocks >> 2;
|
||||
}
|
||||
clockcounter = 0;
|
||||
}
|
||||
@@ -287,6 +289,12 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
|
||||
XUD_SetReady_InPtr(ep_aud_in, (unsigned)buffer_aud_in, input_buffer_size); //loopback
|
||||
num_samples_to_send_to_host = 0;
|
||||
break;
|
||||
|
||||
case c_audio_hub :> samples_in[0]:
|
||||
for (int i = 1; i < NUM_USB_CHAN_IN; i++) c_audio_hub :> samples_in[i];
|
||||
// for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: samples_out[1];
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: loopback_samples[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,15 +14,16 @@
|
||||
|
||||
#define EXCLUDE_USB_AUDIO_MAIN
|
||||
|
||||
#define VENDOR_STR "XMOS"
|
||||
#define VENDOR_ID 0x20B1
|
||||
#define PRODUCT_STR_A2 "XUA Lite"
|
||||
#define PRODUCT_STR_A1 "XUA Lite"
|
||||
#define PID_AUDIO_1 1
|
||||
#define PID_AUDIO_2 2
|
||||
#define XUA_DFU_EN 0 /* Disable DFU (for simplicity of example */
|
||||
#define VENDOR_STR "XMOS"
|
||||
#define VENDOR_ID 0x20B1
|
||||
#define PRODUCT_STR_A2 "XUA Lite Class 2"
|
||||
#define PRODUCT_STR_A1 "XUA Lite Class 1"
|
||||
#define PID_AUDIO_1 1
|
||||
#define PID_AUDIO_2 2
|
||||
#define XUA_DFU_EN 0 /* Disable DFU (for simplicity of example) */
|
||||
|
||||
#define UAC_FORCE_FEEDBACK_EP 1
|
||||
#define XUA_LITE 1
|
||||
#define XUA_LITE 1 // Use simple/optimised USB buffer tasks
|
||||
#define AUDIO_CLASS 2
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user