forked from PAWPAW-Mirror/lib_xua
Merge branch 'ANDROID'
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
*.log
|
||||||
xmosdfu
|
xmosdfu
|
||||||
xmosdfu.*
|
xmosdfu.*
|
||||||
*/.build_*/*
|
*/.build_*/*
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
#ifndef _DFU_H_
|
#ifndef _DFU_H_
|
||||||
#define _DFU_H_ 1
|
#define _DFU_H_ 1
|
||||||
|
|
||||||
|
#include <xccompat.h>
|
||||||
|
#include "usb_std_descriptors.h"
|
||||||
|
|
||||||
#ifndef DFU_VENDOR_ID
|
#ifndef DFU_VENDOR_ID
|
||||||
#error DFU_VENDOR_ID not defined!
|
#error DFU_VENDOR_ID not defined!
|
||||||
#endif
|
#endif
|
||||||
@@ -51,7 +54,7 @@ unsigned char DFUdevDesc[] = {
|
|||||||
unsigned char DFUcfgDesc[] = {
|
unsigned char DFUcfgDesc[] = {
|
||||||
/* Standard USB device descriptor */
|
/* Standard USB device descriptor */
|
||||||
0x09, /* 0 bLength */
|
0x09, /* 0 bLength */
|
||||||
USB_CONFIGURATION, /* 1 bDescriptorType */
|
USB_DESCTYPE_CONFIGURATION, /* 1 bDescriptorType */
|
||||||
0x1b, /* 2 wTotalLength */
|
0x1b, /* 2 wTotalLength */
|
||||||
0x00, /* 3 wTotalLength */
|
0x00, /* 3 wTotalLength */
|
||||||
1, /* 4 bNumInterface: Number of interfaces*/
|
1, /* 4 bNumInterface: Number of interfaces*/
|
||||||
@@ -83,8 +86,12 @@ unsigned char DFUcfgDesc[] = {
|
|||||||
0x01, /* 8 bcdDFUVersion */
|
0x01, /* 8 bcdDFUVersion */
|
||||||
};
|
};
|
||||||
|
|
||||||
int DFUReportResetState(chanend ?c_user_cmd);
|
int DFUReportResetState(NULLABLE_RESOURCE(chanend , c_user_cmd));
|
||||||
int DFUDeviceRequests(XUD_ep c_ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, chanend ?c_user_cmd, unsigned int altInterface, unsigned int user_reset);
|
int DFUDeviceRequests(XUD_ep c_ep0_out, NULLABLE_REFERENCE_PARAM(XUD_ep, ep0_in), REFERENCE_PARAM(USB_SetupPacket_t, sp),
|
||||||
|
NULLABLE_RESOURCE(chanend, c_user_cmd), unsigned int altInterface, unsigned int user_reset);
|
||||||
|
|
||||||
|
/* Helper function for C */
|
||||||
|
void DFUDelay(unsigned d);
|
||||||
|
|
||||||
#endif /* _DFU_H_ */
|
#endif /* _DFU_H_ */
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "devicedefines.h"
|
#include "devicedefines.h"
|
||||||
|
|
||||||
#include "xud.h"
|
#include "xud.h"
|
||||||
#include "usb.h"
|
#include "usb_std_requests.h"
|
||||||
|
|
||||||
#include "dfu_types.h"
|
#include "dfu_types.h"
|
||||||
#include "flash_interface.h"
|
#include "flash_interface.h"
|
||||||
@@ -22,6 +22,15 @@ extern int DFU_reset_override;
|
|||||||
extern void DFUCustomFlashEnable();
|
extern void DFUCustomFlashEnable();
|
||||||
extern void DFUCustomFlashDisable();
|
extern void DFUCustomFlashDisable();
|
||||||
|
|
||||||
|
void DFUDelay(unsigned d)
|
||||||
|
{
|
||||||
|
timer tmr;
|
||||||
|
unsigned s;
|
||||||
|
tmr :> s;
|
||||||
|
tmr when timerafter(s + d) :> void;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void temp()
|
void temp()
|
||||||
{
|
{
|
||||||
asm(".linkset DFU_reset_override, _edp.bss");
|
asm(".linkset DFU_reset_override, _edp.bss");
|
||||||
|
|||||||
@@ -22,10 +22,11 @@
|
|||||||
#define SET_SMUX 7
|
#define SET_SMUX 7
|
||||||
|
|
||||||
/* c_audioControl */
|
/* c_audioControl */
|
||||||
|
//TODO should be an enum
|
||||||
#define SET_SAMPLE_FREQ 4
|
#define SET_SAMPLE_FREQ 4
|
||||||
#define SET_CHAN_COUNT_IN 5
|
|
||||||
#define SET_CHAN_COUNT_OUT 6
|
|
||||||
#define SET_DSD_MODE 7
|
#define SET_DSD_MODE 7
|
||||||
|
#define SET_STREAM_FORMAT_OUT 8
|
||||||
|
#define SET_STREAM_FORMAT_IN 9
|
||||||
|
|
||||||
#include "dsd_support.h"
|
#include "dsd_support.h"
|
||||||
|
|
||||||
|
|||||||
@@ -104,10 +104,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(IO_EXPANSION) && (IO_EXPANSION == 0)
|
|
||||||
#undef IO_EXPANSION
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(IAP) && (IAP == 0)
|
#if defined(IAP) && (IAP == 0)
|
||||||
#undef IAP
|
#undef IAP
|
||||||
#endif
|
#endif
|
||||||
@@ -148,7 +144,10 @@
|
|||||||
#undef ADAT_RX
|
#undef ADAT_RX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DFU) && (DFU == 0)
|
#if !defined(DFU)
|
||||||
|
/* Enable DFU by default */
|
||||||
|
#define DFU 1
|
||||||
|
#elif defined(DFU) && (DFU == 0)
|
||||||
#undef DFU
|
#undef DFU
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -303,40 +302,241 @@
|
|||||||
#define BCD_DEVICE ((BCD_DEVICE_J << 8) | ((BCD_DEVICE_M & 0xF) << 4) | (BCD_DEVICE_N & 0xF))
|
#define BCD_DEVICE ((BCD_DEVICE_J << 8) | ((BCD_DEVICE_M & 0xF) << 4) | (BCD_DEVICE_N & 0xF))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Sample Sub-slot size (bytes) for High Speed. Default is 4 bytes */
|
#define OUTPUT_FORMAT_COUNT 3
|
||||||
#ifndef SAMPLE_SUBSLOT_SIZE_HS
|
|
||||||
#define SAMPLE_SUBSLOT_SIZE_HS 4
|
#ifndef OUTPUT_FORMAT_COUNT
|
||||||
|
#ifndef NATIVE_DSD
|
||||||
|
/* Default format count is 2 (16bit, 24bit) */
|
||||||
|
#define OUTPUT_FORMAT_COUNT 2
|
||||||
|
#else
|
||||||
|
/* Default format count is 3 (16bit, 24bit, DSD) */
|
||||||
|
#define OUTPUT_FORMAT_COUNT 3
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 2) && (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_HS != 4)
|
|
||||||
#error Only SAMPLE_SUBSLOT_SIZE_HS 2, 3 or 4 supported #SAMPLE_SUBSLOT_SIZE_HS
|
|
||||||
|
#if(OUTPUT_FORMAT_COUNT > 3)
|
||||||
|
#error only OUTPUT_FORMAT_COUNT of 3 or less supported
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Sample Sub-slot size (bytes) for Full Speed. Default is 3 bytes */
|
#if defined(NATIVE_DSD) && (OUTPUT_FORMAT_COUNT == 1)
|
||||||
#ifndef SAMPLE_SUBSLOT_SIZE_FS
|
#error OUTPUT_FORMAT_COUNT should be >= 2 when NATIVE_DSD enabled
|
||||||
#define SAMPLE_SUBSLOT_SIZE_FS 3
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (SAMPLE_SUBSLOT_SIZE_FS != 2) && (SAMPLE_SUBSLOT_SIZE_FS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 4)
|
#ifdef NATIVE_DSD
|
||||||
#error Only SAMPLE_SUBSLOT_SIZE_FS 2, 3 or 4 supported
|
/* DSD always the last format */
|
||||||
|
#define NATIVE_DSD_FORMAT_NUM (OUTPUT_FORMAT_COUNT)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Sample bit resolution for High Speed. Default 24bit*/
|
/* Default resolutions */
|
||||||
#ifndef SAMPLE_BIT_RESOLUTION_HS
|
/* Note, 24 on the lowests in case OUTPUT_FORMAT_COUNT = 1 */
|
||||||
#define SAMPLE_BIT_RESOLUTION_HS 24
|
#ifndef STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS
|
||||||
|
#if (NATIVE_DSD_FORMAT_NUM == 1)
|
||||||
|
#define STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS 32 /* DSD requires 32bits */
|
||||||
|
#else
|
||||||
|
#define STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS 24
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (SAMPLE_BIT_RESOLUTION_HS/8) > SAMPLE_SUBSLOT_SIZE_HS
|
#ifndef STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS
|
||||||
#error SAMPLE_BIT_RESOLUTION_HS is too big for SAMPLE_SUBSLOT_SIZE_HS
|
#if (NATIVE_DSD_FORMAT_NUM == 2)
|
||||||
|
#define STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS 32 /* DSD requires 32bits */
|
||||||
|
#else
|
||||||
|
#define STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS 16
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Sample bit resolution for Full Speed. Default 24bit*/
|
#ifndef STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS
|
||||||
#ifndef SAMPLE_BIT_RESOLUTION_FS
|
#if (NATIVE_DSD_FORMAT_NUM == 3)
|
||||||
#define SAMPLE_BIT_RESOLUTION_FS 24
|
#define STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS 32 /* DSD requires 32bits */
|
||||||
|
#else
|
||||||
|
#define STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS 32
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (SAMPLE_BIT_RESOLUTION_FS/8) > SAMPLE_SUBSLOT_SIZE_FS
|
/* Default resolutions for HS */
|
||||||
#error SAMPLE_BIT_RESOLUTION_FS is too big for SAMPLE_SUBSLOT_SIZE_FS
|
#ifndef HS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS
|
||||||
|
#define HS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS
|
||||||
|
#define HS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS
|
||||||
|
#define HS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Default resolutions for FS (same as HS) */
|
||||||
|
#ifndef FS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS
|
||||||
|
#define FS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS
|
||||||
|
#define FS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS
|
||||||
|
#define FS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Setup default subslot size based on resolution
|
||||||
|
* Catch special 24bit case where 4 byte subslot is nicer for our 32-bit machine.
|
||||||
|
* Typically do not care about this extra bus overhead at High-speed */
|
||||||
|
#ifndef HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES
|
||||||
|
#if (HS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS == 24)
|
||||||
|
#define HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES 4 /* 4 byte subslot is nicer for our 32 bit machine to unpack.. */
|
||||||
|
#else
|
||||||
|
#define HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES (HS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS/8)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES
|
||||||
|
#if (HS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS == 24)
|
||||||
|
#define HS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES 4 /* 4 byte subslot is nicer for our 32 bit machine to unpack.. */
|
||||||
|
#else
|
||||||
|
#define HS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES (HS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS/8)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES
|
||||||
|
#if (HS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS == 24)
|
||||||
|
#define HS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES 4 /* 4 byte subslot is nicer for our 32 bit machine to unpack.. */
|
||||||
|
#else
|
||||||
|
#define HS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES (HS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS/8)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Setup default FS subslot sizes - make as small as possible */
|
||||||
|
#ifndef FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES
|
||||||
|
#define FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES (FS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS/8)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES
|
||||||
|
#define FS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES (FS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS/8)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES
|
||||||
|
#define FS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES (FS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS/8)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Setup default formats */
|
||||||
|
#ifndef STREAM_FORMAT_OUTPUT_1_DATAFORMAT
|
||||||
|
#if (NATIVE_DSD_FORMAT_NUM == 1)
|
||||||
|
#define STREAM_FORMAT_OUTPUT_1_DATAFORMAT UAC_FORMAT_TYPEI_RAW_DATA
|
||||||
|
#else
|
||||||
|
#define STREAM_FORMAT_OUTPUT_1_DATAFORMAT UAC_FORMAT_TYPEI_PCM
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STREAM_FORMAT_OUTPUT_2_DATAFORMAT
|
||||||
|
#if (NATIVE_DSD_FORMAT_NUM == 2)
|
||||||
|
#define STREAM_FORMAT_OUTPUT_2_DATAFORMAT UAC_FORMAT_TYPEI_RAW_DATA
|
||||||
|
#else
|
||||||
|
#define STREAM_FORMAT_OUTPUT_2_DATAFORMAT UAC_FORMAT_TYPEI_PCM
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STREAM_FORMAT_OUTPUT_3_DATAFORMAT
|
||||||
|
#if (NATIVE_DSD_FORMAT_NUM == 3)
|
||||||
|
#define STREAM_FORMAT_OUTPUT_3_DATAFORMAT UAC_FORMAT_TYPEI_RAW_DATA
|
||||||
|
#else
|
||||||
|
#define STREAM_FORMAT_OUTPUT_3_DATAFORMAT UAC_FORMAT_TYPEI_PCM
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Some stream format checks */
|
||||||
|
#if (OUTPUT_FORMAT_COUNT > 0)
|
||||||
|
#if !defined(HS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS) || \
|
||||||
|
!defined(HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES) || \
|
||||||
|
!defined(STREAM_FORMAT_OUTPUT_1_DATAFORMAT)
|
||||||
|
#error HS_OUTPUT_STREAM_1 not properly defined
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (OUTPUT_FORMAT_COUNT > 1)
|
||||||
|
#if !defined(HS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS) || \
|
||||||
|
!defined(HS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES) || \
|
||||||
|
!defined(STREAM_FORMAT_OUTPUT_2_DATAFORMAT)
|
||||||
|
#error HS_OUTPUT_STREAM_2 not properly defined
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (OUTPUT_FORMAT_COUNT > 2)
|
||||||
|
#if !defined(HS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS) || \
|
||||||
|
!defined(HS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES) || \
|
||||||
|
!defined(STREAM_FORMAT_OUTPUT_3_DATAFORMAT)
|
||||||
|
#error HS_OUTPUT_STREAM_3 not properly defined
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//#ifdef INPUT
|
||||||
|
#if 1
|
||||||
|
|
||||||
|
/* Only one Input stream format currently supported */
|
||||||
|
#ifndef INPUT_FORMAT_COUNT
|
||||||
|
#define INPUT_FORMAT_COUNT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (INPUT_FORMAT_COUNT > 1)
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STREAM_FORMAT_INPUT_1_RESOLUTION_BITS
|
||||||
|
#define STREAM_FORMAT_INPUT_1_RESOLUTION_BITS 16
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Default resolutions for HS */
|
||||||
|
#ifndef HS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS
|
||||||
|
#define HS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS STREAM_FORMAT_INPUT_1_RESOLUTION_BITS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Default resolutions for FS (same as HS) */
|
||||||
|
#ifndef FS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS
|
||||||
|
#define FS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS STREAM_FORMAT_INPUT_1_RESOLUTION_BITS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Setup default subslot sized based on resolution */
|
||||||
|
#ifndef HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES
|
||||||
|
// #if (HS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS == 24)
|
||||||
|
// #define HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES 4 /* 4 byte subslot is nicer for our 32 bit machine to unpack.. */
|
||||||
|
//#else
|
||||||
|
#define HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES (HS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS/8)
|
||||||
|
//#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Setup default FS subslot sizes */
|
||||||
|
#ifndef FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES
|
||||||
|
#define FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES (FS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS/8)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Setup default formats */
|
||||||
|
#ifndef STREAM_FORMAT_INPUT_1_DATAFORMAT
|
||||||
|
#define STREAM_FORMAT_INPUT_1_DATAFORMAT UAC_FORMAT_TYPEI_PCM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#if((FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 4) || HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 4)
|
||||||
|
#define STREAM_FORMAT_INPUT_SUBSLOT_4_USED 1
|
||||||
|
#else
|
||||||
|
#define STREAM_FORMAT_INPUT_SUBSLOT_4_USED 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if((FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 3) || HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 3)
|
||||||
|
#define STREAM_FORMAT_INPUT_SUBSLOT_3_USED 1
|
||||||
|
#else
|
||||||
|
#define STREAM_FORMAT_INPUT_SUBSLOT_3_USED 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if((FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 2) || HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 2)
|
||||||
|
#define STREAM_FORMAT_INPUT_SUBSLOT_2_USED 1
|
||||||
|
#else
|
||||||
|
#define STREAM_FORMAT_INPUT_SUBSLOT_2_USED 0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Addition interfaces based on defines */
|
/* Addition interfaces based on defines */
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include <xs1.h>
|
#include <xs1.h>
|
||||||
#include "xud.h"
|
#include "xud.h"
|
||||||
#include "usb.h"
|
#include "usb_std_requests.h"
|
||||||
#include "usbaudio20.h"
|
#include "usbaudio20.h"
|
||||||
#include "usbaudio10.h"
|
#include "usbaudio10.h"
|
||||||
#include "dbcalc.h"
|
#include "dbcalc.h"
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
|
* g
|
||||||
* @file endpoint0.xc
|
* @file endpoint0.xc
|
||||||
* @brief Implements endpoint zero for an USB Audio 1.0/2.0 device
|
* @brief Implements endpoint zero for an USB Audio 1.0/2.0 device
|
||||||
* @author Ross Owen, XMOS Semiconductor
|
* @author Ross Owen, XMOS Semiconductor
|
||||||
@@ -8,7 +9,7 @@
|
|||||||
#include <safestring.h>
|
#include <safestring.h>
|
||||||
|
|
||||||
#include "xud.h" /* XUD user defines and functions */
|
#include "xud.h" /* XUD user defines and functions */
|
||||||
#include "usb.h" /* Defines from USB 2.0 Spec */
|
#include "usb_std_requests.h"
|
||||||
#include "usbaudio20.h" /* Defines from USB Audio 2.0 spec */
|
#include "usbaudio20.h" /* Defines from USB Audio 2.0 spec */
|
||||||
|
|
||||||
#include "devicedefines.h"
|
#include "devicedefines.h"
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
#include "vendorrequests.h"
|
#include "vendorrequests.h"
|
||||||
#include "dfu_types.h"
|
#include "dfu_types.h"
|
||||||
#include "xc_ptr.h"
|
#include "xc_ptr.h"
|
||||||
|
#include "audiorequests.h"
|
||||||
#ifdef HID_CONTROLS
|
#ifdef HID_CONTROLS
|
||||||
#include "hid.h"
|
#include "hid.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -27,6 +29,13 @@
|
|||||||
#include "dsd_support.h"
|
#include "dsd_support.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __XC__
|
||||||
|
/* Support for C */
|
||||||
|
#define null 0
|
||||||
|
#define outuint(c, x) asm ("out res[%0], %1" :: "r" (c), "r" (x))
|
||||||
|
#define chkct(c, x) asm ("chkct res[%0], %1" :: "r" (c), "r" (x))
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Some warnings.... */
|
/* Some warnings.... */
|
||||||
|
|
||||||
/* Windows does not have a built in DFU driver (windows will prompt), so warn that DFU will not be functional in Audio 1.0 mode */
|
/* Windows does not have a built in DFU driver (windows will prompt), so warn that DFU will not be functional in Audio 1.0 mode */
|
||||||
@@ -52,13 +61,6 @@ unsigned int DFU_mode_active = 0; // 0 - App active, 1 - DFU active
|
|||||||
extern void device_reboot(chanend);
|
extern void device_reboot(chanend);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Handles Audio Class requests */
|
|
||||||
int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl);
|
|
||||||
int AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl);
|
|
||||||
int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Global volume and mute tables */
|
/* Global volume and mute tables */
|
||||||
int volsOut[NUM_USB_CHAN_OUT + 1];
|
int volsOut[NUM_USB_CHAN_OUT + 1];
|
||||||
unsigned int mutesOut[NUM_USB_CHAN_OUT + 1];
|
unsigned int mutesOut[NUM_USB_CHAN_OUT + 1];
|
||||||
@@ -71,7 +73,6 @@ unsigned int mutesIn[NUM_USB_CHAN_IN + 1];
|
|||||||
#ifdef MIXER
|
#ifdef MIXER
|
||||||
unsigned char mixer1Crossbar[18];
|
unsigned char mixer1Crossbar[18];
|
||||||
short mixer1Weights[18*8];
|
short mixer1Weights[18*8];
|
||||||
//#define MAX_MIX_COUNT 8
|
|
||||||
|
|
||||||
unsigned char channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT];
|
unsigned char channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT];
|
||||||
#if NUM_USB_CHAN_OUT > 0
|
#if NUM_USB_CHAN_OUT > 0
|
||||||
@@ -99,11 +100,29 @@ XUD_BusSpeed_t g_curUsbSpeed = 0;
|
|||||||
unsigned g_dsdMode = 0;
|
unsigned g_dsdMode = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void VendorAudioRequestsInit(chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl);
|
const unsigned g_subSlot_Out_HS[OUTPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES,
|
||||||
|
HS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES,
|
||||||
|
HS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES};
|
||||||
|
|
||||||
|
const unsigned g_subSlot_Out_FS[OUTPUT_FORMAT_COUNT] = {FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES,
|
||||||
|
FS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES,
|
||||||
|
FS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES};
|
||||||
|
|
||||||
|
const unsigned g_dataFormat_Out[OUTPUT_FORMAT_COUNT] = {STREAM_FORMAT_OUTPUT_1_DATAFORMAT,
|
||||||
|
STREAM_FORMAT_OUTPUT_2_DATAFORMAT,
|
||||||
|
STREAM_FORMAT_OUTPUT_3_DATAFORMAT};
|
||||||
|
|
||||||
|
const unsigned g_subSlot_In_HS[INPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES};
|
||||||
|
|
||||||
|
const unsigned g_subSlot_In_FS[INPUT_FORMAT_COUNT] = {FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES};
|
||||||
|
|
||||||
|
const unsigned g_dataFormat_In[INPUT_FORMAT_COUNT] = {STREAM_FORMAT_INPUT_1_DATAFORMAT};
|
||||||
|
|
||||||
/* Endpoint 0 function. Handles all requests to the device */
|
/* Endpoint 0 function. Handles all requests to the device */
|
||||||
void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||||
chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_usb_test)
|
NULLABLE_RESOURCE(chanend, c_mix_ctl),
|
||||||
|
NULLABLE_RESOURCE(chanend, c_clk_ctl),
|
||||||
|
NULLABLE_RESOURCE(chanend, c_usb_test))
|
||||||
{
|
{
|
||||||
USB_SetupPacket_t sp;
|
USB_SetupPacket_t sp;
|
||||||
XUD_ep ep0_out = XUD_InitEp(c_ep0_out);
|
XUD_ep ep0_out = XUD_InitEp(c_ep0_out);
|
||||||
@@ -227,7 +246,11 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
/* Returns 0 for success, -1 for bus reset */
|
/* Returns 0 for success, -1 for bus reset */
|
||||||
|
#if defined(__XC__)
|
||||||
XUD_Result_t result = USB_GetSetupPacket(ep0_out, ep0_in, sp);
|
XUD_Result_t result = USB_GetSetupPacket(ep0_out, ep0_in, sp);
|
||||||
|
#else
|
||||||
|
XUD_Result_t result = USB_GetSetupPacket(ep0_out, ep0_in, &sp);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (result == XUD_RES_OKAY)
|
if (result == XUD_RES_OKAY)
|
||||||
{
|
{
|
||||||
@@ -244,67 +267,62 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
/* Check for audio stream from host start/stop */
|
/* Check for audio stream from host start/stop */
|
||||||
if(sp.wIndex == 1) // Ouput interface
|
if(sp.wIndex == 1) // Ouput interface
|
||||||
{
|
{
|
||||||
switch(sp.wValue)
|
/* Check the alt is in range */
|
||||||
|
if(sp.wValue <= OUTPUT_FORMAT_COUNT)
|
||||||
{
|
{
|
||||||
case 0:
|
/* Alt 0 is stream stop */
|
||||||
/* Stream stop */
|
if(sp.wValue > 0)
|
||||||
#if defined(NATIVE_DSD) && defined(DEFAULT_TO_PCM)
|
{
|
||||||
/* Default to PCM mode */
|
/* Send format of data onto buffering */
|
||||||
if(g_dsdMode)
|
outuint(c_audioControl, SET_STREAM_FORMAT_OUT);
|
||||||
{
|
outuint(c_audioControl, g_dataFormat_Out[sp.wValue-1]); /* Data format (PCM/DSD) */
|
||||||
outuint(c_audioControl, SET_DSD_MODE);
|
|
||||||
outuint(c_audioControl, DSD_MODE_OFF);
|
|
||||||
|
|
||||||
/* Handshake */
|
|
||||||
chkct(c_audioControl, XS1_CT_END);
|
|
||||||
g_dsdMode = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
/* Stream active + 0 chans */
|
|
||||||
/* NOTE there could be a difference between HS/UAC1 and FS/UAC1 channel count
|
|
||||||
* Also note, currently we assume with won't be doing ADAT in FS/UAC1...
|
|
||||||
* Note: This is is important. Decouple uses this to setup the size of the initial IN packet size
|
|
||||||
*/
|
|
||||||
if(g_curUsbSpeed == XUD_SPEED_HS)
|
if(g_curUsbSpeed == XUD_SPEED_HS)
|
||||||
{
|
{
|
||||||
outuint(c_audioControl, SET_CHAN_COUNT_OUT);
|
outuint(c_audioControl, NUM_USB_CHAN_OUT); /* Channel count */
|
||||||
outuint(c_audioControl, NUM_USB_CHAN_OUT);
|
outuint(c_audioControl, g_subSlot_Out_HS[sp.wValue-1]); /* Subslot */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
outuint(c_audioControl, SET_CHAN_COUNT_OUT);
|
|
||||||
outuint(c_audioControl, NUM_USB_CHAN_OUT_FS);
|
outuint(c_audioControl, NUM_USB_CHAN_OUT_FS);
|
||||||
|
outuint(c_audioControl, g_subSlot_Out_FS[sp.wValue-1]);
|
||||||
}
|
}
|
||||||
#ifdef NATIVE_DSD
|
|
||||||
if(g_dsdMode)
|
|
||||||
{
|
|
||||||
outuint(c_audioControl, SET_DSD_MODE);
|
|
||||||
outuint(c_audioControl, DSD_MODE_OFF);
|
|
||||||
|
|
||||||
// Handshake
|
/* Handshake */
|
||||||
chkct(c_audioControl, XS1_CT_END);
|
chkct(c_audioControl, XS1_CT_END);
|
||||||
g_dsdMode = 0;
|
}
|
||||||
}
|
|
||||||
#endif /* NATIVE_DSD */
|
|
||||||
break;
|
|
||||||
#ifdef NATIVE_DSD
|
|
||||||
case 2:
|
|
||||||
|
|
||||||
if(!g_dsdMode)
|
|
||||||
{
|
|
||||||
outuint(c_audioControl, SET_DSD_MODE);
|
|
||||||
outuint(c_audioControl, DSD_MODE_NATIVE);
|
|
||||||
chkct(c_audioControl, XS1_CT_END);
|
|
||||||
g_dsdMode = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#endif /* NATIVE_DSD */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#warning FIXME
|
||||||
else if(sp.wIndex == 2) // Input interface
|
else if(sp.wIndex == 2) // Input interface
|
||||||
{
|
{
|
||||||
|
/* Check the alt is in range */
|
||||||
|
if(sp.wValue <= INPUT_FORMAT_COUNT)
|
||||||
|
{
|
||||||
|
/* Alt 0 is stream stop */
|
||||||
|
if(sp.wValue > 0)
|
||||||
|
{
|
||||||
|
/* Send format of data onto buffering */
|
||||||
|
outuint(c_audioControl, SET_STREAM_FORMAT_IN);
|
||||||
|
outuint(c_audioControl, g_dataFormat_In[sp.wValue-1]); /* Data format (PCM/DSD) */
|
||||||
|
|
||||||
|
if(g_curUsbSpeed == XUD_SPEED_HS)
|
||||||
|
{
|
||||||
|
outuint(c_audioControl, NUM_USB_CHAN_IN); /* Channel count */
|
||||||
|
outuint(c_audioControl, g_subSlot_In_HS[sp.wValue-1]); /* Subslot */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outuint(c_audioControl, NUM_USB_CHAN_IN_FS);
|
||||||
|
outuint(c_audioControl, g_subSlot_In_FS[sp.wValue-1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Handshake */
|
||||||
|
chkct(c_audioControl, XS1_CT_END);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
switch(sp.wValue)
|
switch(sp.wValue)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -350,6 +368,8 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
#if defined(OUTPUT) && defined(INPUT)
|
#if defined(OUTPUT) && defined(INPUT)
|
||||||
/* Check for stream start stop on output and input audio interfaces */
|
/* Check for stream start stop on output and input audio interfaces */
|
||||||
@@ -381,12 +401,12 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
/* Record interface change */
|
///* Record interface change */
|
||||||
if(sp.wIndex < NUM_INTERFACES)
|
//if(sp.wIndex < NUM_INTERFACES)
|
||||||
g_interfaceAlt[sp.wIndex] = sp.wValue;
|
// g_interfaceAlt[sp.wIndex] = sp.wValue;
|
||||||
|
|
||||||
|
//TODO - we should stall out of range requests
|
||||||
|
|
||||||
/* No data stage for this request, just do data stage */
|
|
||||||
result = XUD_DoSetRequestStatus(ep0_in);
|
|
||||||
|
|
||||||
} /* if(sp.bRequest == SET_INTERFACE) */
|
} /* if(sp.bRequest == SET_INTERFACE) */
|
||||||
|
|
||||||
@@ -461,10 +481,10 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
#if (AUDIO_CLASS == 2) && defined(AUDIO_CLASS_FALLBACK)
|
#if (AUDIO_CLASS == 2) && defined(AUDIO_CLASS_FALLBACK)
|
||||||
if(g_curUsbSpeed == XUD_SPEED_FS)
|
if(g_curUsbSpeed == XUD_SPEED_FS)
|
||||||
{
|
{
|
||||||
result = AudioEndpointRequests_1(ep0_out, ep0_in, sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
result = AudioEndpointRequests_1(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
||||||
}
|
}
|
||||||
#elif (AUDIO_CLASS==1)
|
#elif (AUDIO_CLASS==1)
|
||||||
result = AudioEndpointRequests_1(ep0_out, ep0_in, sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
result = AudioEndpointRequests_1(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,14 +520,15 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
// Handshake
|
// Handshake
|
||||||
chkct(c_audioControl, XS1_CT_END);
|
chkct(c_audioControl, XS1_CT_END);
|
||||||
}
|
}
|
||||||
|
#ifdef __XC__
|
||||||
/* This will return 1 if reset requested */
|
/* This will return 1 if reset requested */
|
||||||
if (DFUDeviceRequests(ep0_out, ep0_in, sp, null, g_interfaceAlt[sp.wIndex], 1))
|
if (DFUDeviceRequests(ep0_out, ep0_in, sp, null, g_interfaceAlt[sp.wIndex], 1))
|
||||||
|
#else
|
||||||
|
/* This will return 1 if reset requested */
|
||||||
|
if (DFUDeviceRequests(ep0_out, &ep0_in, &sp, null, g_interfaceAlt[sp.wIndex], 1))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
timer tmr;
|
DFUDelay(50000000);
|
||||||
unsigned s;
|
|
||||||
tmr :> s;
|
|
||||||
tmr when timerafter(s + 50000000) :> s;
|
|
||||||
device_reboot(c_audioControl);
|
device_reboot(c_audioControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,16 +545,16 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
#if (AUDIO_CLASS == 2) && defined(AUDIO_CLASS_FALLBACK)
|
#if (AUDIO_CLASS == 2) && defined(AUDIO_CLASS_FALLBACK)
|
||||||
if(g_curUsbSpeed == XUD_SPEED_HS)
|
if(g_curUsbSpeed == XUD_SPEED_HS)
|
||||||
{
|
{
|
||||||
result = AudioClassRequests_2(ep0_out, ep0_in, sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
result = AudioClassRequests_2(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = AudioClassRequests_1(ep0_out, ep0_in, sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
result = AudioClassRequests_1(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
||||||
}
|
}
|
||||||
#elif (AUDIO_CLASS==2)
|
#elif (AUDIO_CLASS==2)
|
||||||
result = AudioClassRequests_2(ep0_out, ep0_in, sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
result = AudioClassRequests_2(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
||||||
#else
|
#else
|
||||||
result = AudioClassRequests_1(ep0_out, ep0_in, sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
result = AudioClassRequests_1(ep0_out, ep0_in, &sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VENDOR_AUDIO_REQS
|
#ifdef VENDOR_AUDIO_REQS
|
||||||
@@ -566,89 +587,93 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
#ifdef AUDIO_CLASS_FALLBACK
|
#ifdef AUDIO_CLASS_FALLBACK
|
||||||
/* Return Audio 2.0 Descriptors with Audio 1.0 as fallback */
|
/* Return Audio 2.0 Descriptors with Audio 1.0 as fallback */
|
||||||
result = USB_StandardRequests(ep0_out, ep0_in,
|
result = USB_StandardRequests(ep0_out, ep0_in,
|
||||||
devDesc_Audio2, sizeof(devDesc_Audio2),
|
(unsigned char*)&devDesc_Audio2, sizeof(devDesc_Audio2),
|
||||||
cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
(unsigned char*)&cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
||||||
devDesc_Audio1, sizeof(devDesc_Audio1),
|
devDesc_Audio1, sizeof(devDesc_Audio1),
|
||||||
cfgDesc_Audio1, sizeof(cfgDesc_Audio1),
|
cfgDesc_Audio1, sizeof(cfgDesc_Audio1),
|
||||||
strDescs, sizeof(strDescs)/sizeof(strDescs[0]),
|
strDescs, sizeof(strDescs)/sizeof(strDescs[0]),
|
||||||
sp, c_usb_test, g_curUsbSpeed);
|
&sp, c_usb_test, g_curUsbSpeed);
|
||||||
#elif FULL_SPEED_AUDIO_2
|
#elif FULL_SPEED_AUDIO_2
|
||||||
/* Return Audio 2.0 Descriptors for high_speed and full-speed */
|
/* Return Audio 2.0 Descriptors for high_speed and full-speed */
|
||||||
|
|
||||||
/* Unfortunately we need to munge the descriptors a bit between full and high-speed */
|
/* Unfortunately we need to munge the descriptors a bit between full and high-speed */
|
||||||
if(g_curUsbSpeed == XUD_SPEED_HS)
|
if(g_curUsbSpeed == XUD_SPEED_HS)
|
||||||
{
|
{
|
||||||
|
/* Modify Audio Class 2.0 Config descriptor for High-speed operation */
|
||||||
#if (NUM_USB_CHAN_OUT > 0)
|
#if (NUM_USB_CHAN_OUT > 0)
|
||||||
/* Output interface - Interface 1 */
|
cfgDesc_Audio2.Audio_CS_Control_Int.Audio_Out_InputTerminal.bNrChannels = NUM_USB_CHAN_OUT;
|
||||||
/* Mod bSlotSize */
|
#if (NUM_USB_CHAN_OUT > 0)
|
||||||
cfgDesc_Audio2[STREAMING_OUTPUT_ALT1_OFFSET+20] = SAMPLE_SUBSLOT_SIZE_HS;
|
cfgDesc_Audio2.Audio_Out_Format.bSubslotSize = HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES;
|
||||||
|
cfgDesc_Audio2.Audio_Out_Format.bBitResolution = HS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS;
|
||||||
|
cfgDesc_Audio2.Audio_Out_Endpoint.wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE;
|
||||||
|
cfgDesc_Audio2.Audio_Out_ClassStreamInterface.bNrChannels = NUM_USB_CHAN_OUT;
|
||||||
|
#endif
|
||||||
|
#if (OUTPUT_FORMAT_COUNT > 1)
|
||||||
|
cfgDesc_Audio2.Audio_Out_Format_2.bSubslotSize = HS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES;
|
||||||
|
cfgDesc_Audio2.Audio_Out_Format_2.bBitResolution = HS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS;
|
||||||
|
cfgDesc_Audio2.Audio_Out_Endpoint_2.wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_2_MAXPACKETSIZE;
|
||||||
|
cfgDesc_Audio2.Audio_Out_ClassStreamInterface_2.bNrChannels = NUM_USB_CHAN_OUT;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Mod bBitResolution */
|
#if (OUTPUT_FORMAT_COUNT > 2)
|
||||||
cfgDesc_Audio2[STREAMING_OUTPUT_ALT1_OFFSET+21] = SAMPLE_BIT_RESOLUTION_HS;
|
cfgDesc_Audio2.Audio_Out_Format_3.bSubslotSize = HS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES;
|
||||||
|
cfgDesc_Audio2.Audio_Out_Format_3.bBitResolution = HS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS;
|
||||||
/* wMaxPacketSize */
|
cfgDesc_Audio2.Audio_Out_Endpoint_3.wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_3_MAXPACKETSIZE;
|
||||||
cfgDesc_Audio2[STREAMING_OUTPUT_ALT1_OFFSET+26] = MAX_PACKET_SIZE_OUT_HS&0xff;
|
cfgDesc_Audio2.Audio_Out_ClassStreamInterface_3.bNrChannels = NUM_USB_CHAN_OUT;
|
||||||
cfgDesc_Audio2[STREAMING_OUTPUT_ALT1_OFFSET+27] = (MAX_PACKET_SIZE_OUT_HS&0xff00)>>8;
|
#endif
|
||||||
|
|
||||||
/* bNrChannels */
|
|
||||||
cfgDesc_Audio2[STREAMING_OUTPUT_ALT1_OFFSET+10] = NUM_USB_CHAN_OUT;
|
|
||||||
#endif
|
#endif
|
||||||
#if (NUM_USB_CHAN_IN > 0)
|
#if (NUM_USB_CHAN_IN > 0)
|
||||||
/* Input interface - Interface 2 */
|
cfgDesc_Audio2.Audio_CS_Control_Int.Audio_In_InputTerminal.bNrChannels = NUM_USB_CHAN_IN;
|
||||||
/* Mod bSlotSize */
|
cfgDesc_Audio2.Audio_In_Format.bSubslotSize = HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES;
|
||||||
cfgDesc_Audio2[STREAMING_INPUT_ALT1_OFFSET+20] = SAMPLE_SUBSLOT_SIZE_HS;
|
cfgDesc_Audio2.Audio_In_Format.bBitResolution = HS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS;
|
||||||
|
cfgDesc_Audio2.Audio_In_Endpoint.wMaxPacketSize = HS_STREAM_FORMAT_INPUT_1_MAXPACKETSIZE;
|
||||||
/* Mod bBitResolution */
|
cfgDesc_Audio2.Audio_In_ClassStreamInterface.bNrChannels = NUM_USB_CHAN_IN;
|
||||||
cfgDesc_Audio2[STREAMING_INPUT_ALT1_OFFSET+21] = SAMPLE_BIT_RESOLUTION_HS;
|
|
||||||
|
|
||||||
/* wMaxPacketSize */
|
|
||||||
cfgDesc_Audio2[STREAMING_INPUT_ALT1_OFFSET+26] = MAX_PACKET_SIZE_IN_HS&0xff;
|
|
||||||
cfgDesc_Audio2[STREAMING_INPUT_ALT1_OFFSET+27] = (MAX_PACKET_SIZE_IN_HS&0xff00)>>8;
|
|
||||||
|
|
||||||
/* bNrChannels */
|
|
||||||
cfgDesc_Audio2[STREAMING_INPUT_ALT1_OFFSET+10] = NUM_USB_CHAN_IN;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Modify Audio Class 2.0 Config descriptor for Full-speed operation */
|
||||||
#if (NUM_USB_CHAN_OUT > 0)
|
#if (NUM_USB_CHAN_OUT > 0)
|
||||||
/* Output interface - Interface 1 */
|
cfgDesc_Audio2.Audio_CS_Control_Int.Audio_Out_InputTerminal.bNrChannels = NUM_USB_CHAN_OUT_FS;
|
||||||
/* Mod bSlotSize */
|
#if (NUM_USB_CHAN_OUT > 0)
|
||||||
cfgDesc_Audio2[STREAMING_OUTPUT_ALT1_OFFSET+20] = SAMPLE_SUBSLOT_SIZE_FS;
|
cfgDesc_Audio2.Audio_Out_Format.bSubslotSize = FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES;
|
||||||
|
cfgDesc_Audio2.Audio_Out_Format.bBitResolution = FS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS;
|
||||||
|
cfgDesc_Audio2.Audio_Out_Endpoint.wMaxPacketSize = FS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE;
|
||||||
|
cfgDesc_Audio2.Audio_Out_ClassStreamInterface.bNrChannels = NUM_USB_CHAN_OUT_FS;
|
||||||
|
#endif
|
||||||
|
#if (OUTPUT_FORMAT_COUNT > 1)
|
||||||
|
cfgDesc_Audio2.Audio_Out_Format_2.bSubslotSize = FS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES;
|
||||||
|
cfgDesc_Audio2.Audio_Out_Format_2.bBitResolution = FS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS;
|
||||||
|
cfgDesc_Audio2.Audio_Out_Endpoint_2.wMaxPacketSize = FS_STREAM_FORMAT_OUTPUT_2_MAXPACKETSIZE;
|
||||||
|
cfgDesc_Audio2.Audio_Out_ClassStreamInterface_2.bNrChannels = NUM_USB_CHAN_OUT_FS;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Mod bBitResolution */
|
#if (OUTPUT_FORMAT_COUNT > 2)
|
||||||
cfgDesc_Audio2[STREAMING_OUTPUT_ALT1_OFFSET+21] = SAMPLE_BIT_RESOLUTION_FS;
|
cfgDesc_Audio2.Audio_Out_Format_3.bSubslotSize = FS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES;
|
||||||
|
cfgDesc_Audio2.Audio_Out_Format_3.bBitResolution = FS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS;
|
||||||
/* wMaxPacketSize */
|
cfgDesc_Audio2.Audio_Out_Endpoint_3.wMaxPacketSize = FS_STREAM_FORMAT_OUTPUT_3_MAXPACKETSIZE;
|
||||||
cfgDesc_Audio2[STREAMING_OUTPUT_ALT1_OFFSET+26] = MAX_PACKET_SIZE_OUT_FS&0xff;
|
cfgDesc_Audio2.Audio_Out_ClassStreamInterface_3.bNrChannels = NUM_USB_CHAN_OUT_FS;
|
||||||
cfgDesc_Audio2[STREAMING_OUTPUT_ALT1_OFFSET+27] = (MAX_PACKET_SIZE_OUT_FS&0xff00)>>8;
|
#endif
|
||||||
|
|
||||||
/* bNrChannels */
|
|
||||||
cfgDesc_Audio2[STREAMING_OUTPUT_ALT1_OFFSET+10] = NUM_USB_CHAN_OUT_FS;
|
|
||||||
#endif
|
#endif
|
||||||
#if (NUM_USB_CHAN_IN > 0)
|
#if (NUM_USB_CHAN_IN > 0)
|
||||||
/* Input interface - Interface 2 */
|
cfgDesc_Audio2.Audio_CS_Control_Int.Audio_In_InputTerminal.bNrChannels = NUM_USB_CHAN_IN_FS;
|
||||||
/* Mod bSlotSize */
|
cfgDesc_Audio2.Audio_In_Format.bSubslotSize = FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES;
|
||||||
cfgDesc_Audio2[STREAMING_INPUT_ALT1_OFFSET+20] = SAMPLE_SUBSLOT_SIZE_FS;
|
cfgDesc_Audio2.Audio_In_Format.bBitResolution = FS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS;
|
||||||
|
cfgDesc_Audio2.Audio_In_Endpoint.wMaxPacketSize = FS_STREAM_FORMAT_INPUT_1_MAXPACKETSIZE;
|
||||||
/* Mod bBitResolution */
|
cfgDesc_Audio2.Audio_In_ClassStreamInterface.bNrChannels = NUM_USB_CHAN_IN_FS;
|
||||||
cfgDesc_Audio2[STREAMING_INPUT_ALT1_OFFSET+21] = SAMPLE_BIT_RESOLUTION_FS;
|
|
||||||
|
|
||||||
/* wMaxPacketSize */
|
|
||||||
cfgDesc_Audio2[STREAMING_INPUT_ALT1_OFFSET+26] = MAX_PACKET_SIZE_IN_FS&0xff;
|
|
||||||
cfgDesc_Audio2[STREAMING_INPUT_ALT1_OFFSET+27] = (MAX_PACKET_SIZE_IN_FS&0xff00)>>8;
|
|
||||||
|
|
||||||
/* bNrChannels */
|
|
||||||
cfgDesc_Audio2[STREAMING_INPUT_ALT1_OFFSET+10] = NUM_USB_CHAN_IN_FS;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
result = USB_StandardRequests(ep0_out, ep0_in,
|
result = USB_StandardRequests(ep0_out, ep0_in,
|
||||||
devDesc_Audio2, sizeof(devDesc_Audio2),
|
(unsigned char*)&devDesc_Audio2, sizeof(devDesc_Audio2),
|
||||||
cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
(unsigned char*)&cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
||||||
null, 0,
|
null, 0,
|
||||||
null, 0,
|
null, 0,
|
||||||
|
#ifdef __XC__
|
||||||
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed);
|
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed);
|
||||||
|
#else
|
||||||
|
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), &sp, c_usb_test, g_curUsbSpeed);
|
||||||
|
#endif
|
||||||
#elif (AUDIO_CLASS == 1)
|
#elif (AUDIO_CLASS == 1)
|
||||||
/* Return Audio 1.0 Descriptors in FS, should never be in HS! */
|
/* Return Audio 1.0 Descriptors in FS, should never be in HS! */
|
||||||
result = USB_StandardRequests(ep0_out, ep0_in,
|
result = USB_StandardRequests(ep0_out, ep0_in,
|
||||||
@@ -656,15 +681,15 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
null, 0,
|
null, 0,
|
||||||
devDesc_Audio1, sizeof(devDesc_Audio1),
|
devDesc_Audio1, sizeof(devDesc_Audio1),
|
||||||
cfgDesc_Audio1, sizeof(cfgDesc_Audio1),
|
cfgDesc_Audio1, sizeof(cfgDesc_Audio1),
|
||||||
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed);
|
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), &sp, c_usb_test, g_curUsbSpeed);
|
||||||
#else
|
#else
|
||||||
/* Return Audio 2.0 Descriptors with Null device as fallback */
|
/* Return Audio 2.0 Descriptors with Null device as fallback */
|
||||||
result = USB_StandardRequests(ep0_out, ep0_in,
|
result = USB_StandardRequests(ep0_out, ep0_in,
|
||||||
devDesc_Audio2, sizeof(devDesc_Audio2),
|
(unsigned char*)&devDesc_Audio2, sizeof(devDesc_Audio2),
|
||||||
cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
(unsigned char*)&cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
||||||
devDesc_Null, sizeof(devDesc_Null),
|
devDesc_Null, sizeof(devDesc_Null),
|
||||||
cfgDesc_Null, sizeof(cfgDesc_Null),
|
cfgDesc_Null, sizeof(cfgDesc_Null),
|
||||||
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed);
|
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), &sp, c_usb_test, g_curUsbSpeed);
|
||||||
#endif
|
#endif
|
||||||
#ifdef DFU
|
#ifdef DFU
|
||||||
}
|
}
|
||||||
@@ -676,15 +701,22 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
DFUcfgDesc, sizeof(DFUcfgDesc),
|
DFUcfgDesc, sizeof(DFUcfgDesc),
|
||||||
null, 0, /* Used same descriptors for full and high-speed */
|
null, 0, /* Used same descriptors for full and high-speed */
|
||||||
null, 0,
|
null, 0,
|
||||||
strDescs, sizeof(strDescs), sp, c_usb_test, g_curUsbSpeed);
|
#ifdef __XC__
|
||||||
|
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed);
|
||||||
|
#else
|
||||||
|
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), &sp, c_usb_test, g_curUsbSpeed);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == XUD_RES_RST)
|
if (result == XUD_RES_RST)
|
||||||
{
|
{
|
||||||
|
#ifdef __XC__
|
||||||
g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, ep0_in);
|
g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, ep0_in);
|
||||||
|
#else
|
||||||
|
g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, &ep0_in);
|
||||||
|
#endif
|
||||||
g_currentConfig = 0;
|
g_currentConfig = 0;
|
||||||
|
|
||||||
#ifdef DFU
|
#ifdef DFU
|
||||||
@@ -692,8 +724,6 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
{
|
{
|
||||||
if (!DFU_mode_active)
|
if (!DFU_mode_active)
|
||||||
{
|
{
|
||||||
timer tmr;
|
|
||||||
unsigned s;
|
|
||||||
DFU_mode_active = 1;
|
DFU_mode_active = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -701,13 +731,10 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
{
|
{
|
||||||
if (DFU_mode_active)
|
if (DFU_mode_active)
|
||||||
{
|
{
|
||||||
timer tmr;
|
|
||||||
unsigned s;
|
|
||||||
DFU_mode_active = 0;
|
DFU_mode_active = 0;
|
||||||
|
|
||||||
/* Send reboot command */
|
/* Send reboot command */
|
||||||
tmr :> s;
|
DFUDelay(5000000);
|
||||||
tmr when timerafter(s + 5000000) :> s;
|
|
||||||
device_reboot(c_audioControl);
|
device_reboot(c_audioControl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef _VENDORREQUESTS_H_
|
#ifndef _VENDORREQUESTS_H_
|
||||||
#define _VENDORREQUESTS_H_
|
#define _VENDORREQUESTS_H_
|
||||||
|
|
||||||
|
#include <xccompat.h>
|
||||||
|
|
||||||
/* Functions that handle vustomer vendor requests.
|
/* Functions that handle vustomer vendor requests.
|
||||||
*
|
*
|
||||||
* THESE NEED IMPLEMENTING FOR A SPECIFIC DESIGN
|
* THESE NEED IMPLEMENTING FOR A SPECIFIC DESIGN
|
||||||
@@ -10,7 +12,9 @@
|
|||||||
* */
|
* */
|
||||||
|
|
||||||
int VendorAudioRequests(XUD_ep ep0_out, XUD_ep ep0_in, unsigned char bRequest, unsigned char cs, unsigned char cn,
|
int VendorAudioRequests(XUD_ep ep0_out, XUD_ep ep0_in, unsigned char bRequest, unsigned char cs, unsigned char cn,
|
||||||
unsigned short unitId, unsigned char direction, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctL);
|
unsigned short unitId, unsigned char direction, chanend c_audioControl,
|
||||||
|
NULLABLE_RESOURCE(chanend, c_mix_ctl),
|
||||||
|
NULLABLE_RESOURCE(chanend, c_clk_ctL));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "xud.h" /* XMOS USB Device Layer defines and functions */
|
#include "xud.h" /* XMOS USB Device Layer defines and functions */
|
||||||
#include "usb.h" /* Defines from the USB 2.0 Specification */
|
|
||||||
|
|
||||||
#include "devicedefines.h" /* Device specific defines */
|
#include "devicedefines.h" /* Device specific defines */
|
||||||
#include "endpoint0.h"
|
#include "endpoint0.h"
|
||||||
|
|||||||
@@ -4,24 +4,28 @@
|
|||||||
#include "interrupt.h"
|
#include "interrupt.h"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "xud.h"
|
#include "xud.h"
|
||||||
#include "usb.h"
|
|
||||||
|
#ifdef NATIVE_DSD
|
||||||
|
#include "usbaudio20.h" /* Defines from the USB Audio 2.0 Specifications */
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HID_CONTROLS
|
#ifdef HID_CONTROLS
|
||||||
#include "user_hid.h"
|
#include "user_hid.h"
|
||||||
#endif
|
#endif
|
||||||
#define MAX(x,y) ((x)>(y) ? (x) : (y))
|
#define MAX(x,y) ((x)>(y) ? (x) : (y))
|
||||||
|
|
||||||
#define CLASS_TWO_PACKET_SIZE ((((MAX_FREQ+7999)/8000))+3) // Samples per channel
|
#define HS_PACKET_SIZE ((((MAX_FREQ+7999)/8000))+3) // Samples per channel
|
||||||
#define CLASS_ONE_PACKET_SIZE ((((MAX_FREQ_FS+999)/1000))+3) // Samples per channel
|
#define FS_PACKET_SIZE ((((MAX_FREQ_FS+999)/1000))+3) // Samples per channel
|
||||||
|
|
||||||
/* TODO user SLOTSIZE to potentially save memory */
|
/* TODO use SLOTSIZE to potentially save memory */
|
||||||
#define BUFF_SIZE_OUT MAX(4 * CLASS_TWO_PACKET_SIZE * NUM_USB_CHAN_OUT, 4 * CLASS_ONE_PACKET_SIZE * NUM_USB_CHAN_OUT_FS)
|
#define BUFF_SIZE_OUT MAX(4 * HS_PACKET_SIZE * NUM_USB_CHAN_OUT, 4 * FS_PACKET_SIZE * NUM_USB_CHAN_OUT_FS)
|
||||||
#define BUFF_SIZE_IN MAX(4 * CLASS_TWO_PACKET_SIZE * NUM_USB_CHAN_IN, 4 * CLASS_ONE_PACKET_SIZE * NUM_USB_CHAN_IN_FS)
|
#define BUFF_SIZE_IN MAX(4 * HS_PACKET_SIZE * NUM_USB_CHAN_IN, 4 * FS_PACKET_SIZE * NUM_USB_CHAN_IN_FS)
|
||||||
|
|
||||||
/* Maximum USB buffer size (1024 bytes + 1 word to store length) */
|
/* Maximum USB buffer size (1024 bytes + 1 word to store length) */
|
||||||
#define MAX_USB_AUD_PACKET_SIZE 1028
|
#define MAX_USB_AUD_PACKET_SIZE 1028
|
||||||
|
|
||||||
#define OUT_BUFFER_PREFILL (MAX(NUM_USB_CHAN_OUT_FS*CLASS_ONE_PACKET_SIZE*3+4,NUM_USB_CHAN_OUT*CLASS_TWO_PACKET_SIZE*4+4)*1)
|
#define OUT_BUFFER_PREFILL (MAX(NUM_USB_CHAN_OUT_FS*FS_PACKET_SIZE*3+4,NUM_USB_CHAN_OUT*HS_PACKET_SIZE*4+4)*1)
|
||||||
#define IN_BUFFER_PREFILL (MAX(CLASS_ONE_PACKET_SIZE*3+4,CLASS_TWO_PACKET_SIZE*4+4)*2)
|
#define IN_BUFFER_PREFILL (MAX(FS_PACKET_SIZE*2+4, HS_PACKET_SIZE*4+4)*2)
|
||||||
|
|
||||||
/* Volume and mute tables */
|
/* Volume and mute tables */
|
||||||
#ifndef OUT_VOLUME_IN_MIXER
|
#ifndef OUT_VOLUME_IN_MIXER
|
||||||
@@ -37,10 +41,14 @@ static xc_ptr p_multIn;
|
|||||||
unsigned g_numUsbChanOut = NUM_USB_CHAN_OUT;
|
unsigned g_numUsbChanOut = NUM_USB_CHAN_OUT;
|
||||||
unsigned g_numUsbChanIn = NUM_USB_CHAN_IN;
|
unsigned g_numUsbChanIn = NUM_USB_CHAN_IN;
|
||||||
|
|
||||||
#define MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO ((MAX_FREQ/8000+1)*NUM_USB_CHAN_IN*4)
|
/* Note we could improve on this, for one subslot is set to 4 */
|
||||||
#define MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE (((MAX_FREQ_FS/1000+1)*NUM_USB_CHAN_IN_FS*3)+4)
|
#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS ((MAX_FREQ/8000+1)*4)
|
||||||
|
#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS ((MAX_FREQ_FS/1000+1)*4)
|
||||||
|
|
||||||
#define MAX_DEVICE_AUD_PACKET_SIZE (MAX(MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE, MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO))
|
#define MAX_DEVICE_AUD_PACKET_SIZE_HS ((MAX_FREQ/8000+1)*NUM_USB_CHAN_IN*4)
|
||||||
|
#define MAX_DEVICE_AUD_PACKET_SIZE_FS ((MAX_FREQ_FS/1000+1)*NUM_USB_CHAN_IN_FS*4)
|
||||||
|
|
||||||
|
#define MAX_DEVICE_AUD_PACKET_SIZE (MAX(MAX_DEVICE_AUD_PACKET_SIZE_FS, MAX_DEVICE_AUD_PACKET_SIZE_HS))
|
||||||
|
|
||||||
/* Circular audio buffers */
|
/* Circular audio buffers */
|
||||||
unsigned outAudioBuff[BUFF_SIZE_OUT + (MAX_USB_AUD_PACKET_SIZE>>2) + 4];
|
unsigned outAudioBuff[BUFF_SIZE_OUT + (MAX_USB_AUD_PACKET_SIZE>>2) + 4];
|
||||||
@@ -64,6 +72,11 @@ unsigned g_aud_from_host_flag = 0;
|
|||||||
unsigned g_aud_from_host_info;
|
unsigned g_aud_from_host_info;
|
||||||
unsigned g_freqChange_flag = 0;
|
unsigned g_freqChange_flag = 0;
|
||||||
unsigned g_freqChange_sampFreq;
|
unsigned g_freqChange_sampFreq;
|
||||||
|
|
||||||
|
unsigned g_formatChange_SubSlot;
|
||||||
|
unsigned g_formatChange_DataFormat;
|
||||||
|
unsigned g_formatChange_NumChans;
|
||||||
|
|
||||||
int speedRem = 0;
|
int speedRem = 0;
|
||||||
|
|
||||||
xc_ptr aud_from_host_fifo_start;
|
xc_ptr aud_from_host_fifo_start;
|
||||||
@@ -96,12 +109,15 @@ unsigned unpackData = 0;
|
|||||||
unsigned packState = 0;
|
unsigned packState = 0;
|
||||||
unsigned packData = 0;
|
unsigned packData = 0;
|
||||||
|
|
||||||
|
/* Default to something sensible but the following are setup at stream start: */
|
||||||
|
unsigned g_curSubSlot_out = HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES;
|
||||||
|
unsigned g_curSubSlot_in = HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES;
|
||||||
|
|
||||||
|
/* Init to something sensible, but expect to be re-set before stream start */
|
||||||
#if (AUDIO_CLASS==2)
|
#if (AUDIO_CLASS==2)
|
||||||
int g_slotSize = SAMPLE_SUBSLOT_SIZE_HS; /* 4 bytes per ssample for Audio Class 2.0 */
|
int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_HS;
|
||||||
int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO;
|
|
||||||
#else
|
#else
|
||||||
int g_slotSize = SAMPLE_SUBSLOT_SIZE_FS; /* 3 bytes per sample for Audio Class 1.0 */
|
int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_FS;
|
||||||
int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma select handler
|
#pragma select handler
|
||||||
@@ -118,23 +134,6 @@ void handle_audio_request(chanend c_mix_out)
|
|||||||
/* Reply with underflow */
|
/* Reply with underflow */
|
||||||
outuint(c_mix_out, outUnderflow);
|
outuint(c_mix_out, outUnderflow);
|
||||||
|
|
||||||
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
|
|
||||||
|
|
||||||
/* slotSize different for Audio Class 1.0/2.0. */
|
|
||||||
/* TODO It is quite wasteful to run this check every interrupt. Perhaps on stream start is good enough */
|
|
||||||
#if defined(AUDIO_CLASS_FALLBACK) || defined (FULL_SPEED_AUDIO_2)
|
|
||||||
if (usb_speed == XUD_SPEED_HS)
|
|
||||||
{
|
|
||||||
g_slotSize = SAMPLE_SUBSLOT_SIZE_HS; /* Typically 4 bytes per sample for HS */
|
|
||||||
g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_slotSize = SAMPLE_SUBSLOT_SIZE_FS; /* Typically 3 bytes per sample for FS */
|
|
||||||
g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* If in overflow condition then receive samples and throw away */
|
/* If in overflow condition then receive samples and throw away */
|
||||||
if(inOverflow || sampsToWrite == 0)
|
if(inOverflow || sampsToWrite == 0)
|
||||||
{
|
{
|
||||||
@@ -160,14 +159,13 @@ void handle_audio_request(chanend c_mix_out)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Not in overflow, store samples from mixer into sample buffer */
|
/* Not in overflow, store samples from mixer into sample buffer */
|
||||||
switch(g_slotSize)
|
switch(g_curSubSlot_in)
|
||||||
{
|
{
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 4) && (SAMPLE_SUBSLOT_SIZE_FS != 4)
|
#if (STREAM_FORMAT_INPUT_SUBSLOT_4_USED == 1)
|
||||||
__builtin_unreachable();
|
//__builtin_unreachable();
|
||||||
#endif
|
#endif
|
||||||
unsigned ptr = g_aud_to_host_dptr;
|
unsigned ptr = g_aud_to_host_dptr;
|
||||||
|
|
||||||
@@ -183,6 +181,7 @@ __builtin_unreachable();
|
|||||||
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i));
|
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i));
|
||||||
{h, l} = macs(mult, sample, 0, 0);
|
{h, l} = macs(mult, sample, 0, 0);
|
||||||
sample = h << 3;
|
sample = h << 3;
|
||||||
|
#warning FIXME
|
||||||
sample |= (l >> 29) & 0x7; // Note, this step is not required if we assume sample depth is 24 (rather than 32)
|
sample |= (l >> 29) & 0x7; // Note, this step is not required if we assume sample depth is 24 (rather than 32)
|
||||||
#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX)
|
#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX)
|
||||||
sample = sample << 3;
|
sample = sample << 3;
|
||||||
@@ -198,8 +197,8 @@ __builtin_unreachable();
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3)
|
#if (STREAM_FORMAT_INPUT_SUBSLOT_3_USED == 1)
|
||||||
__builtin_unreachable();
|
//__builtin_unreachable();
|
||||||
#endif
|
#endif
|
||||||
for(int i = 0; i < g_numUsbChanIn; i++)
|
for(int i = 0; i < g_numUsbChanIn; i++)
|
||||||
{
|
{
|
||||||
@@ -244,9 +243,8 @@ __builtin_unreachable();
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
#if (STREAM_FORMAT_INPUT_SUBSLOT_2_USED == 1)
|
||||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 2) && (SAMPLE_SUBSLOT_SIZE_FS != 2)
|
//__builtin_unreachable();
|
||||||
__builtin_unreachable();
|
|
||||||
#endif
|
#endif
|
||||||
for(int i = 0; i < g_numUsbChanIn; i++)
|
for(int i = 0; i < g_numUsbChanIn; i++)
|
||||||
{
|
{
|
||||||
@@ -260,24 +258,13 @@ __builtin_unreachable();
|
|||||||
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i));
|
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i));
|
||||||
{h, l} = macs(mult, sample, 0, 0);
|
{h, l} = macs(mult, sample, 0, 0);
|
||||||
sample = h << 3;
|
sample = h << 3;
|
||||||
#if (SAMPLE_BIT_RESOLUTION_HS > 24) || (SAMPLE_BIT_RESOLUTION_FS > 24)
|
|
||||||
sample |= (l >> 29) & 0x7; // Note, this step is not required if we assume sample depth is 24 (rather than 32)
|
/* Note, in 2 byte sub slot - ignore lower bits of macs */
|
||||||
#endif
|
|
||||||
#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX)
|
#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX)
|
||||||
sample = sample << 3;
|
sample = sample << 3;
|
||||||
#endif
|
#endif
|
||||||
/* Write into fifo */
|
write_short_via_xc_ptr(g_aud_to_host_dptr, sample>>16);
|
||||||
switch (packState&0x1)
|
g_aud_to_host_dptr+=2;
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
packData = sample;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
packData = (packData>>16) | (sample & 0xffff0000);
|
|
||||||
write_via_xc_ptr(g_aud_to_host_dptr, packData);
|
|
||||||
g_aud_to_host_dptr+=4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -330,11 +317,41 @@ __builtin_unreachable();
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch(g_slotSize)
|
switch(g_curSubSlot_out)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3)
|
||||||
|
//__builtin_unreachable();
|
||||||
|
#endif
|
||||||
|
/* Buffering not underflow condition send out some samples...*/
|
||||||
|
for(int i = 0; i < g_numUsbChanOut; i++)
|
||||||
|
{
|
||||||
|
#pragma xta endpoint "mixer_request"
|
||||||
|
int sample;
|
||||||
|
int mult;
|
||||||
|
int h;
|
||||||
|
unsigned l;
|
||||||
|
|
||||||
|
read_short_via_xc_ptr(sample, g_aud_from_host_rdptr);
|
||||||
|
g_aud_from_host_rdptr+=2;
|
||||||
|
sample <<= 16;
|
||||||
|
|
||||||
|
#ifndef OUT_VOLUME_IN_MIXER
|
||||||
|
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
||||||
|
{h, l} = macs(mult, sample, 0, 0);
|
||||||
|
/* Note, in 2 byte subslot mode - ignore lower result of macs */
|
||||||
|
h <<= 3;
|
||||||
|
outuint(c_mix_out, h);
|
||||||
|
#else
|
||||||
|
outuint(c_mix_out, sample);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 4) && (SAMPLE_SUBSLOT_SIZE_FS != 4)
|
#if (SAMPLE_SUBSLOT_SIZE_HS != 4) && (SAMPLE_SUBSLOT_SIZE_FS != 4)
|
||||||
__builtin_unreachable();
|
//__builtin_unreachable();
|
||||||
#endif
|
#endif
|
||||||
/* Buffering not underflow condition send out some samples...*/
|
/* Buffering not underflow condition send out some samples...*/
|
||||||
for(int i = 0; i < g_numUsbChanOut; i++)
|
for(int i = 0; i < g_numUsbChanOut; i++)
|
||||||
@@ -352,10 +369,11 @@ __builtin_unreachable();
|
|||||||
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
||||||
{h, l} = macs(mult, sample, 0, 0);
|
{h, l} = macs(mult, sample, 0, 0);
|
||||||
h <<= 3;
|
h <<= 3;
|
||||||
#if (SAMPLE_BIT_RESOLUTION_HS > 24) || (SAMPLE_BIT_RESOLUTION_FS > 24) || defined(NATIVE_DSD)
|
//#if (SAMPLE_BIT_RESOLUTION_HS > 24) || (SAMPLE_BIT_RESOLUTION_FS > 24) || defined(NATIVE_DSD)
|
||||||
|
#warning FIXME
|
||||||
h |= (l >>29)& 0x7; // Note: This step is not required if we assume sample depth is 24bit (rather than 32bit)
|
h |= (l >>29)& 0x7; // Note: This step is not required if we assume sample depth is 24bit (rather than 32bit)
|
||||||
// Note: We need all 32bits for Native DSD
|
// Note: We need all 32bits for Native DSD
|
||||||
#endif
|
//#endif
|
||||||
outuint(c_mix_out, h);
|
outuint(c_mix_out, h);
|
||||||
#else
|
#else
|
||||||
outuint(c_mix_out, sample);
|
outuint(c_mix_out, sample);
|
||||||
@@ -366,7 +384,7 @@ __builtin_unreachable();
|
|||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3)
|
#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3)
|
||||||
__builtin_unreachable();
|
//__builtin_unreachable();
|
||||||
#endif
|
#endif
|
||||||
/* Buffering not underflow condition send out some samples...*/
|
/* Buffering not underflow condition send out some samples...*/
|
||||||
for(int i = 0; i < g_numUsbChanOut; i++)
|
for(int i = 0; i < g_numUsbChanOut; i++)
|
||||||
@@ -415,48 +433,12 @@ __builtin_unreachable();
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
|
||||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3)
|
|
||||||
__builtin_unreachable();
|
|
||||||
#endif
|
|
||||||
/* Buffering not underflow condition send out some samples...*/
|
|
||||||
for(int i = 0; i < g_numUsbChanOut; i++)
|
|
||||||
{
|
|
||||||
#pragma xta endpoint "mixer_request"
|
|
||||||
int sample;
|
|
||||||
int mult;
|
|
||||||
int h;
|
|
||||||
unsigned l;
|
|
||||||
|
|
||||||
switch (unpackState&0x1)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
read_via_xc_ptr(unpackData, g_aud_from_host_rdptr);
|
|
||||||
sample = unpackData << 16;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
g_aud_from_host_rdptr+=4;
|
|
||||||
sample = unpackData & 0xffff0000;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
unpackState++;
|
|
||||||
|
|
||||||
#ifndef OUT_VOLUME_IN_MIXER
|
|
||||||
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
|
||||||
{h, l} = macs(mult, sample, 0, 0);
|
|
||||||
h <<= 3;
|
|
||||||
outuint(c_mix_out, h);
|
|
||||||
#else
|
|
||||||
outuint(c_mix_out, sample);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
__builtin_unreachable();
|
//__builtin_unreachable();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} /* switch(g_slotsize) */
|
} /* switch(g_curSubSlot_out) */
|
||||||
|
|
||||||
/* Output remaining channels. Past this point we always operate on MAX chan count */
|
/* Output remaining channels. Past this point we always operate on MAX chan count */
|
||||||
for(int i = 0; i < NUM_USB_CHAN_OUT - g_numUsbChanOut; i++)
|
for(int i = 0; i < NUM_USB_CHAN_OUT - g_numUsbChanOut; i++)
|
||||||
@@ -465,7 +447,7 @@ __builtin_unreachable();
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 3/4 bytes per sample */
|
/* 3/4 bytes per sample */
|
||||||
aud_data_remaining_to_device -= (g_numUsbChanOut*g_slotSize);
|
aud_data_remaining_to_device -= (g_numUsbChanOut * g_curSubSlot_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inOverflow)
|
if (!inOverflow)
|
||||||
@@ -476,7 +458,7 @@ __builtin_unreachable();
|
|||||||
|
|
||||||
if (totalSampsToWrite)
|
if (totalSampsToWrite)
|
||||||
{
|
{
|
||||||
unsigned datasize = totalSampsToWrite * g_slotSize * g_numUsbChanIn;
|
unsigned datasize = totalSampsToWrite * g_curSubSlot_in * g_numUsbChanIn;
|
||||||
|
|
||||||
/* Round up to nearest word - note, not needed for slotsize == 4! */
|
/* Round up to nearest word - note, not needed for slotsize == 4! */
|
||||||
datasize = (datasize+3) & (~0x3);
|
datasize = (datasize+3) & (~0x3);
|
||||||
@@ -513,7 +495,7 @@ __builtin_unreachable();
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (totalSampsToWrite < 0 || totalSampsToWrite * g_slotSize * g_numUsbChanIn > g_maxPacketSize)
|
if (totalSampsToWrite < 0 || totalSampsToWrite * g_curSubSlot_in * g_numUsbChanIn > g_maxPacketSize)
|
||||||
{
|
{
|
||||||
totalSampsToWrite = 0;
|
totalSampsToWrite = 0;
|
||||||
}
|
}
|
||||||
@@ -528,12 +510,12 @@ __builtin_unreachable();
|
|||||||
space_left = aud_to_host_fifo_end - g_aud_to_host_wrptr;
|
space_left = aud_to_host_fifo_end - g_aud_to_host_wrptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((space_left <= 0) || (space_left > totalSampsToWrite*g_numUsbChanIn * 4 + 4))
|
if ((space_left <= 0) || (space_left > totalSampsToWrite*g_numUsbChanIn * g_curSubSlot_in + 4))
|
||||||
{
|
{
|
||||||
/* Packet okay, write to fifo */
|
/* Packet okay, write to fifo */
|
||||||
if (totalSampsToWrite)
|
if (totalSampsToWrite)
|
||||||
{
|
{
|
||||||
write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite*g_slotSize*g_numUsbChanIn);
|
write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite * g_curSubSlot_in * g_numUsbChanIn);
|
||||||
packState = 0;
|
packState = 0;
|
||||||
g_aud_to_host_dptr = g_aud_to_host_wrptr + 4;
|
g_aud_to_host_dptr = g_aud_to_host_wrptr + 4;
|
||||||
}
|
}
|
||||||
@@ -547,7 +529,7 @@ __builtin_unreachable();
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!outUnderflow && (aud_data_remaining_to_device<(g_slotSize*g_numUsbChanOut)))
|
if (!outUnderflow && (aud_data_remaining_to_device<(g_curSubSlot_out * g_numUsbChanOut)))
|
||||||
{
|
{
|
||||||
/* Handle any tail - incase a bad driver sent us a datalength not a multiple of chan count */
|
/* Handle any tail - incase a bad driver sent us a datalength not a multiple of chan count */
|
||||||
if (aud_data_remaining_to_device)
|
if (aud_data_remaining_to_device)
|
||||||
@@ -620,18 +602,20 @@ static void check_for_interrupt(chanend ?c_clk_int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Mark Endpoint (IN) ready with an appropriately sized zero buffer */
|
/* Mark Endpoint (IN) ready with an appropriately sized zero buffer */
|
||||||
static inline void SetupZerosSendBuffer(XUD_ep aud_to_host_usb_ep, unsigned sampFreq)
|
static inline void SetupZerosSendBuffer(XUD_ep aud_to_host_usb_ep, unsigned sampFreq, unsigned slotSize)
|
||||||
{
|
{
|
||||||
int min, mid, max, usb_speed, p;
|
int min, mid, max, usb_speed, p;
|
||||||
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
|
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
|
||||||
GetADCCounts(sampFreq, min, mid, max);
|
GetADCCounts(sampFreq, min, mid, max);
|
||||||
|
|
||||||
|
// TODO, don't need to use speed.
|
||||||
if (usb_speed == XUD_SPEED_HS)
|
if (usb_speed == XUD_SPEED_HS)
|
||||||
{
|
{
|
||||||
mid*=NUM_USB_CHAN_IN*SAMPLE_SUBSLOT_SIZE_HS;
|
mid *= NUM_USB_CHAN_IN * slotSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mid*=NUM_USB_CHAN_IN_FS*SAMPLE_SUBSLOT_SIZE_FS;
|
mid *= NUM_USB_CHAN_IN_FS * slotSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
asm("stw %0, %1[0]"::"r"(mid),"r"(g_aud_to_host_zeros));
|
asm("stw %0, %1[0]"::"r"(mid),"r"(g_aud_to_host_zeros));
|
||||||
@@ -793,7 +777,7 @@ void decouple(chanend c_mix_out,
|
|||||||
SET_SHARED_GLOBAL(g_aud_to_host_buffer,g_aud_to_host_zeros);
|
SET_SHARED_GLOBAL(g_aud_to_host_buffer,g_aud_to_host_zeros);
|
||||||
|
|
||||||
/* Update size of zeros buffer */
|
/* Update size of zeros buffer */
|
||||||
SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq);
|
SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq, g_curSubSlot_in);
|
||||||
|
|
||||||
/* Reset OUT buffer state */
|
/* Reset OUT buffer state */
|
||||||
outUnderflow = 1;
|
outUnderflow = 1;
|
||||||
@@ -819,12 +803,17 @@ void decouple(chanend c_mix_out,
|
|||||||
speedRem = 0;
|
speedRem = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(tmp == SET_CHAN_COUNT_IN)
|
else if(tmp == SET_STREAM_FORMAT_IN)
|
||||||
{
|
{
|
||||||
|
unsigned dataFormat, usbSpeed;
|
||||||
|
|
||||||
/* Change in IN channel count */
|
/* Change in IN channel count */
|
||||||
DISABLE_INTERRUPTS();
|
DISABLE_INTERRUPTS();
|
||||||
SET_SHARED_GLOBAL(g_freqChange_flag, 0);
|
SET_SHARED_GLOBAL(g_freqChange_flag, 0);
|
||||||
GET_SHARED_GLOBAL(g_numUsbChanIn, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */
|
|
||||||
|
GET_SHARED_GLOBAL(g_numUsbChanIn, g_formatChange_NumChans);
|
||||||
|
GET_SHARED_GLOBAL(g_curSubSlot_in, g_formatChange_SubSlot);
|
||||||
|
GET_SHARED_GLOBAL(dataFormat, g_formatChange_DataFormat); /* Not currently used for input stream */
|
||||||
|
|
||||||
/* Reset IN buffer state */
|
/* Reset IN buffer state */
|
||||||
inOverflow = 0;
|
inOverflow = 0;
|
||||||
@@ -838,22 +827,41 @@ void decouple(chanend c_mix_out,
|
|||||||
SET_SHARED_GLOBAL(g_aud_to_host_buffer, g_aud_to_host_zeros);
|
SET_SHARED_GLOBAL(g_aud_to_host_buffer, g_aud_to_host_zeros);
|
||||||
|
|
||||||
/* Update size of zeros buffer */
|
/* Update size of zeros buffer */
|
||||||
SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq);
|
SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq, g_curSubSlot_in);
|
||||||
|
|
||||||
|
GET_SHARED_GLOBAL(usbSpeed, g_curUsbSpeed);
|
||||||
|
if (usbSpeed == XUD_SPEED_HS)
|
||||||
|
{
|
||||||
|
g_maxPacketSize = (MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS * g_numUsbChanIn);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_maxPacketSize = (MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS * g_numUsbChanIn);
|
||||||
|
}
|
||||||
|
|
||||||
SET_SHARED_GLOBAL(g_freqChange, 0);
|
SET_SHARED_GLOBAL(g_freqChange, 0);
|
||||||
|
asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END));
|
||||||
|
|
||||||
ENABLE_INTERRUPTS();
|
ENABLE_INTERRUPTS();
|
||||||
}
|
}
|
||||||
else if(tmp == SET_CHAN_COUNT_OUT)
|
else if(tmp == SET_STREAM_FORMAT_OUT)
|
||||||
{
|
{
|
||||||
|
unsigned dataFormat;
|
||||||
|
unsigned dsdMode = DSD_MODE_OFF;
|
||||||
|
|
||||||
/* Change in OUT channel count - note we expect this on every stream start event */
|
/* Change in OUT channel count - note we expect this on every stream start event */
|
||||||
DISABLE_INTERRUPTS();
|
DISABLE_INTERRUPTS();
|
||||||
SET_SHARED_GLOBAL(g_freqChange_flag, 0);
|
SET_SHARED_GLOBAL(g_freqChange_flag, 0);
|
||||||
GET_SHARED_GLOBAL(g_numUsbChanOut, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */
|
GET_SHARED_GLOBAL(g_numUsbChanOut, g_formatChange_NumChans);
|
||||||
|
GET_SHARED_GLOBAL(g_curSubSlot_out, g_formatChange_SubSlot);
|
||||||
|
GET_SHARED_GLOBAL(dataFormat, g_formatChange_DataFormat);
|
||||||
|
|
||||||
/* Reset OUT buffer state */
|
/* Reset OUT buffer state */
|
||||||
SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start);
|
SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start);
|
||||||
SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start);
|
SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start);
|
||||||
|
|
||||||
|
unpackState = 0;
|
||||||
|
|
||||||
outUnderflow = 1;
|
outUnderflow = 1;
|
||||||
if(outOverflow)
|
if(outOverflow)
|
||||||
{
|
{
|
||||||
@@ -862,10 +870,28 @@ void decouple(chanend c_mix_out,
|
|||||||
outOverflow = 0;
|
outOverflow = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NATIVE_DSD
|
||||||
|
/* TODO only send when there is a change */
|
||||||
|
if(dataFormat == UAC_FORMAT_TYPEI_RAW_DATA)
|
||||||
|
{
|
||||||
|
dsdMode = DSD_MODE_NATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for the audio code to request samples and respond with command */
|
||||||
|
inuint(c_mix_out);
|
||||||
|
outct(c_mix_out, SET_DSD_MODE);
|
||||||
|
outuint(c_mix_out, dsdMode);
|
||||||
|
|
||||||
|
/* Wait for handshake back */
|
||||||
|
chkct(c_mix_out, XS1_CT_END);
|
||||||
|
#endif
|
||||||
|
asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END));
|
||||||
|
|
||||||
SET_SHARED_GLOBAL(g_freqChange, 0);
|
SET_SHARED_GLOBAL(g_freqChange, 0);
|
||||||
ENABLE_INTERRUPTS();
|
ENABLE_INTERRUPTS();
|
||||||
}
|
}
|
||||||
#ifdef NATIVE_DSD
|
#if 0
|
||||||
|
//#ifdef NATIVE_DSD
|
||||||
else if(tmp == SET_DSD_MODE)
|
else if(tmp == SET_DSD_MODE)
|
||||||
{
|
{
|
||||||
unsigned dsdMode;
|
unsigned dsdMode;
|
||||||
@@ -922,7 +948,7 @@ void decouple(chanend c_mix_out,
|
|||||||
read_via_xc_ptr(datalength, released_buffer);
|
read_via_xc_ptr(datalength, released_buffer);
|
||||||
|
|
||||||
/* Ignore bad small packets */
|
/* Ignore bad small packets */
|
||||||
if ((datalength >= (g_numUsbChanOut * g_slotSize)) && (released_buffer == aud_from_host_wrptr))
|
if ((datalength >= (g_numUsbChanOut * g_curSubSlot_out)) && (released_buffer == aud_from_host_wrptr))
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Move the write pointer of the fifo on - round up to nearest word */
|
/* Move the write pointer of the fifo on - round up to nearest word */
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include <xs1.h>
|
#include <xs1.h>
|
||||||
#include <print.h>
|
#include <print.h>
|
||||||
|
|
||||||
#include "usb.h"
|
|
||||||
#include "devicedefines.h"
|
#include "devicedefines.h"
|
||||||
#ifdef MIDI
|
#ifdef MIDI
|
||||||
#include "usb_midi.h"
|
#include "usb_midi.h"
|
||||||
@@ -241,10 +240,11 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned cmd = inuint(c_aud_ctl);
|
unsigned cmd = inuint(c_aud_ctl);
|
||||||
sampleFreq = inuint(c_aud_ctl);
|
|
||||||
|
|
||||||
if(cmd == SET_SAMPLE_FREQ)
|
if(cmd == SET_SAMPLE_FREQ)
|
||||||
{
|
{
|
||||||
|
sampleFreq = inuint(c_aud_ctl);
|
||||||
|
|
||||||
/* Don't update things for DFU command.. */
|
/* Don't update things for DFU command.. */
|
||||||
if(sampleFreq != AUDIO_STOP_FOR_DFU)
|
if(sampleFreq != AUDIO_STOP_FOR_DFU)
|
||||||
{
|
{
|
||||||
@@ -262,9 +262,31 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
/* Ideally we want to wait for handshake (and pass back up) here. But we cannot keep this
|
/* Ideally we want to wait for handshake (and pass back up) here. But we cannot keep this
|
||||||
* core locked, it must stay responsive to packets (MIDI etc) and SOFs. So, set a flag and check for
|
* core locked, it must stay responsive to packets (MIDI etc) and SOFs. So, set a flag and check for
|
||||||
* handshake elsewhere */
|
* handshake elsewhere */
|
||||||
|
SET_SHARED_GLOBAL(g_freqChange_sampFreq, sampleFreq);
|
||||||
}
|
}
|
||||||
else if (cmd == SET_CHAN_COUNT_OUT)
|
else if(cmd == SET_STREAM_FORMAT_IN)
|
||||||
{
|
{
|
||||||
|
unsigned formatChange_SubSlot, formatChange_NumChans, formatChange_DataFormat;
|
||||||
|
|
||||||
|
formatChange_DataFormat = inuint(c_aud_ctl);
|
||||||
|
formatChange_NumChans = inuint(c_aud_ctl);
|
||||||
|
formatChange_SubSlot = inuint(c_aud_ctl);
|
||||||
|
|
||||||
|
SET_SHARED_GLOBAL(g_formatChange_NumChans, formatChange_NumChans);
|
||||||
|
SET_SHARED_GLOBAL(g_formatChange_SubSlot, formatChange_SubSlot);
|
||||||
|
SET_SHARED_GLOBAL(g_formatChange_DataFormat, formatChange_DataFormat);
|
||||||
|
}
|
||||||
|
else if (cmd == SET_STREAM_FORMAT_OUT)
|
||||||
|
{
|
||||||
|
unsigned formatChange_SubSlot, formatChange_NumChans, formatChange_DataFormat;
|
||||||
|
formatChange_DataFormat = inuint(c_aud_ctl);
|
||||||
|
formatChange_NumChans = inuint(c_aud_ctl);
|
||||||
|
formatChange_SubSlot = inuint(c_aud_ctl);
|
||||||
|
|
||||||
|
SET_SHARED_GLOBAL(g_formatChange_NumChans, formatChange_NumChans);
|
||||||
|
SET_SHARED_GLOBAL(g_formatChange_SubSlot, formatChange_SubSlot);
|
||||||
|
SET_SHARED_GLOBAL(g_formatChange_DataFormat, formatChange_DataFormat);
|
||||||
|
|
||||||
/* Host is starting up the output stream. Setup (or potentially resize) feedback packet based on bus-speed
|
/* Host is starting up the output stream. Setup (or potentially resize) feedback packet based on bus-speed
|
||||||
* This is only really important on inital start up (when bus-speed
|
* This is only really important on inital start up (when bus-speed
|
||||||
was unknown) and when changing bus-speeds */
|
was unknown) and when changing bus-speeds */
|
||||||
@@ -284,8 +306,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
/* Pass on sample freq change to decouple() via global flag (saves a chanend) */
|
/* Pass on sample freq change to decouple() via global flag (saves a chanend) */
|
||||||
/* Note: freqChange flags now used to communicate other commands also */
|
/* Note: freqChange flags now used to communicate other commands also */
|
||||||
SET_SHARED_GLOBAL0(g_freqChange, cmd); /* Set command */
|
SET_SHARED_GLOBAL0(g_freqChange, cmd); /* Set command */
|
||||||
SET_SHARED_GLOBAL(g_freqChange_sampFreq, sampleFreq); /* Set flag */
|
SET_SHARED_GLOBAL(g_freqChange_flag, cmd); /* Set Flag */
|
||||||
SET_SHARED_GLOBAL(g_freqChange_flag, cmd);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -426,7 +447,6 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
if((result == XUD_RES_OKAY) && (length > 0))
|
if((result == XUD_RES_OKAY) && (length > 0))
|
||||||
{
|
{
|
||||||
/* Get buffer data from host - MIDI OUT from host always into a single buffer */
|
/* Get buffer data from host - MIDI OUT from host always into a single buffer */
|
||||||
/* Write datalength (tmp) into buffer[0], data stored in buffer[4] onwards */
|
|
||||||
midi_data_remaining_to_device = length;
|
midi_data_remaining_to_device = length;
|
||||||
|
|
||||||
midi_from_host_rdptr = midi_from_host_buffer;
|
midi_from_host_rdptr = midi_from_host_buffer;
|
||||||
|
|||||||
@@ -14,19 +14,25 @@ inline xc_ptr array_to_xc_ptr(const unsigned a[])
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
|
#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
|
||||||
|
|
||||||
#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
||||||
#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
||||||
|
#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
||||||
|
#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
||||||
// No immediate st8 format
|
// No immediate st8 format
|
||||||
#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
|
#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
|
||||||
|
#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
|
||||||
|
|
||||||
#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
|
#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
|
||||||
|
|
||||||
|
#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
|
||||||
|
#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
|
||||||
|
#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
|
||||||
|
|
||||||
#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
|
|
||||||
#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
|
|
||||||
// No immediate ld8u format
|
// No immediate ld8u format
|
||||||
#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
|
#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
|
||||||
|
#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
|
||||||
|
|
||||||
#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
|
#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
|
||||||
#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
|
#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
|
||||||
|
|||||||
Reference in New Issue
Block a user