From 4b9e3235931ba3c3a144f43fffa9eec9c3644779 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 7 Dec 2016 11:41:05 +0000 Subject: [PATCH] Move defines and checks to expected places --- module_usb_audio/audio_io/audio_io.xc | 26 -------------------- module_usb_audio/devicedefines.h | 35 +++++++++++++++++++++++++++ module_usb_audio/warnings.xc | 6 +++++ 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 2f6fb0e2..ba067156 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -32,32 +32,6 @@ #include "commands.h" #include "xc_ptr.h" -#ifndef I2S_DOWNSAMPLE_FACTOR -#define I2S_DOWNSAMPLE_FACTOR (1) -#endif - -#ifndef I2S_DOWNSAMPLE_MONO -#define I2S_DOWNSAMPLE_MONO (0) -#endif - -#if (I2S_DOWNSAMPLE_MONO == 1) -#define I2S_DOWNSAMPLE_CHANS (I2S_CHANS_DAC/2) -#else -#define I2S_DOWNSAMPLE_CHANS I2S_CHANS_DAC -#endif - -#if (I2S_DOWNSAMPLE_FACTOR != 1) && (I2S_DOWNSAMPLE_FACTOR != 3) -#error "Unsupported I2S downsampling configuration" -#endif - -#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (I2S_CHANS_ADC + NUM_PDM_MICS))) -#error "Not enough USB input channels to support number of I2S and PDM inputs" -#endif - -#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (NUM_PDM_MICS + PDM_MIC_INDEX))) -#error "PDM mic inputs mapping exceeds bounds of USB input channel" -#endif - /* TODO 32 is max expected channels */ static unsigned samplesOut[32]; diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index ffc11fde..ca7ac85c 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -121,6 +121,41 @@ #define I2S_WIRES_ADC (I2S_CHANS_ADC / I2S_CHANS_PER_FRAME) #endif +/** + * @brief Incoming I2S (device to host) channels can be downsampled by a factor of 3. + * + * Default: 1 i.e. downsampling is disabled. + */ +#ifndef I2S_DOWNSAMPLE_FACTOR +#define I2S_DOWNSAMPLE_FACTOR (1) +#else + #if (I2S_DOWNSAMPLE_FACTOR != 3) + #error Unsupported I2S downsampling configuration + #endif +#endif + +/** + * @brief Only downsample one channel per I2S frame. + * + * Default: 0 i.e. mono mode is disabled, all channels will be downsampled. + */ +#ifndef I2S_DOWNSAMPLE_MONO +#define I2S_DOWNSAMPLE_MONO (0) +#endif + +/** + * @brief Number of incoming (device to host) I2S channels to downsample. + * + * Default: The number of I2S incoming channels, or half this if mono downsampling is enabled. + */ +#if (I2S_DOWNSAMPLE_MONO == 1) + #define I2S_DOWNSAMPLE_CHANS (I2S_CHANS_ADC / 2) + #if ((I2S_DOWNSAMPLE_FACTOR > 1) && (I2S_MODE_TDM == 1)) + #error Mono I2S downsampling is not avaliable in TDM mode + #endif +#else +#define I2S_DOWNSAMPLE_CHANS I2S_CHANS_ADC +#endif /** * @brief Max supported sample frequency for device (Hz). Default: 192000 diff --git a/module_usb_audio/warnings.xc b/module_usb_audio/warnings.xc index c1646213..7c0f753d 100644 --- a/module_usb_audio/warnings.xc +++ b/module_usb_audio/warnings.xc @@ -72,4 +72,10 @@ Warnings relating to configuration defines located in this XC source file rather #error NUM_USB_CHAN_IN_FS expected to be less than or equal to NUM_USB_CHAN_IN #endif +#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (I2S_CHANS_ADC + NUM_PDM_MICS))) +#error Not enough USB input channels to support number of I2S and PDM inputs +#endif +#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (NUM_PDM_MICS + PDM_MIC_INDEX))) +#error PDM mic inputs mapping exceeds bounds of USB input channel +#endif