Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/daisy_seed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ void DaisySeed::ConfigureAudio()
case BoardVersion::DAISY_SEED:
default:
{
// Same configuration used for Seed Rev4, Seed Rev7 (1.2), and Seed3
// Data Line Directions
sai_config.a_dir = SaiHandle::Config::Direction::TRANSMIT;
sai_config.pin_config.sa = Pin(PORTE, 6);
Expand Down Expand Up @@ -342,22 +343,31 @@ DaisySeed::BoardVersion DaisySeed::CheckBoardVersion()
{
/** Version Checks:
* * Fall through is Daisy Seed v1 (aka Daisy Seed rev4)
* * PD3 tied to gnd is Daisy Seed v1.1 (aka Daisy Seed rev5)
* * PD4 tied to gnd reserved for future hardware
* * PD3 tied to GND is Daisy Seed 1.1 (aka Daisy Seed rev5)
* * PD4 tied to GND is Daisy Seed2 DFM
* * PD5 tied to GND is Daisy Seed 1.2 (aka Daisy Seed rev7)
* * PH6 tied to GND is Daisy Seed 3
*/

/** Initialize GPIO */
GPIO s2dfm_gpio, seed_1_1_gpio;
GPIO s2dfm_gpio, seed_1_1_gpio, seed_1_2_gpio, seed_3_gpio;
Pin seed_1_1_pin(PORTD, 3);
Pin s2dfm_pin(PORTD, 4);
Pin seed_1_2_pin(PORTD, 5);
Pin seed_3_pin(PORTH, 6);
seed_1_1_gpio.Init(seed_1_1_pin, GPIO::Mode::INPUT, GPIO::Pull::PULLUP);
s2dfm_gpio.Init(s2dfm_pin, GPIO::Mode::INPUT, GPIO::Pull::PULLUP);
seed_1_2_gpio.Init(seed_1_2_pin, GPIO::Mode::INPUT, GPIO::Pull::PULLUP);
seed_3_gpio.Init(seed_3_pin, GPIO::Mode::INPUT, GPIO::Pull::PULLUP);

/** Perform Check */
if(!seed_1_1_gpio.Read())
return BoardVersion::DAISY_SEED_1_1;
else if(!s2dfm_gpio.Read())
return BoardVersion::DAISY_SEED_2_DFM;
else if(!seed_1_2_gpio.Read())
return BoardVersion::DAISY_SEED_1_2;
else if(!seed_3_gpio.Read())
return BoardVersion::DAISY_SEED_3;
else
return BoardVersion::DAISY_SEED;
}
32 changes: 22 additions & 10 deletions src/daisy_seed.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace daisy
{
/**
@brief This is the higher-level interface for the Daisy board. \n
@brief This is the higher-level interface for the Daisy board. \n
All basic peripheral configuration/initialization is setup here. \n

@ingroup boards
Expand All @@ -21,12 +21,12 @@ class DaisySeed
DaisySeed() {}
~DaisySeed() {}

/** This function used to provide a pre-initialization configuraiton
/** This function used to provide a pre-initialization configuraiton
* it has since been deprecated, and does nothing.
*/
void Configure();

/**
/**
Initializes the Daisy Seed and the following peripherals:
SDRAM, QSPI, 24-bit 48kHz Audio via AK4556, Internal USB,
as well as the built-in LED and Testpoint.
Expand All @@ -37,18 +37,18 @@ class DaisySeed
*/
void Init(bool boost = false);

/**
/**
Deinitializes all peripherals automatically handled by `Init`.
*/
void DeInit();

/**
/**
Wait some ms before going on.
\param del Delay time in ms.
*/
void DelayMs(size_t del);

/**
/**
Returns the gpio_pin corresponding to the index 0-31.
For the given GPIO on the Daisy Seed (labeled 1-32 in docs).
*/
Expand Down Expand Up @@ -97,9 +97,9 @@ class DaisySeed
/** Returns the rate in Hz that the Audio callback is called */
float AudioCallbackRate() const;

/** Returns the SAI Handle for the Daisy Seed
/** Returns the SAI Handle for the Daisy Seed
* This can be useful when adding a secondary codec,
* the result of this function can be passed to the audio reinit
* the result of this function can be passed to the audio reinit
* with an SAI2 configuration
*/
const SaiHandle& AudioSaiHandle() const;
Expand Down Expand Up @@ -149,7 +149,7 @@ class DaisySeed
System system;
Ak4556 codec;

/** Internal indices for DaisySeed-equivalent devices
/** Internal indices for DaisySeed-equivalent devices
* This shouldn't have any effect on user-facing code,
* and only needs to be checked to properly initialize
* the onboard-circuits.
Expand All @@ -168,6 +168,18 @@ class DaisySeed
* as well as an improved audio codec (PCM3060)
*/
DAISY_SEED_2_DFM,
/** Daisy Seed 1.2 (aka Daisy Seed Rev7)
* Pin-compatible version of the Daisy Seed that uses
* the PCM3060 audio codec
*/
DAISY_SEED_1_2,
/** Daisy Seed3
* Pin-compatible version of the Daisy Seed that uses
* the TAC5242, has a USB-C connector, and replaced
* the SMT Debug connector with pads for installing a
* through-hole connector.
*/
DAISY_SEED_3,
};

/** Returns the BoardVersion detected during intiialization */
Expand All @@ -189,7 +201,7 @@ class DaisySeed
SaiHandle sai_1_handle_;
};

/** seed namespace contains pinout constants for addressing
/** seed namespace contains pinout constants for addressing
* the pins on the Daisy Seed SOM.
*/
namespace seed
Expand Down
5 changes: 5 additions & 0 deletions src/per/sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ SaiHandle::Result SaiHandle::Impl::Init(const SaiHandle::Config& config)
sai_a_handle_.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_96K;
sai_b_handle_.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_96K;
break;
case Config::SampleRate::SAI_192KHZ:
sai_a_handle_.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_192K;
sai_b_handle_.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_192K;
break;
default: break;
}
const bool both_blocks_slave = config.a_sync == Config::Sync::SLAVE
Expand Down Expand Up @@ -362,6 +366,7 @@ float SaiHandle::Impl::GetSampleRate()
case Config::SampleRate::SAI_32KHZ: return 32000.f;
case Config::SampleRate::SAI_48KHZ: return 48000.f;
case Config::SampleRate::SAI_96KHZ: return 96000.f;
case Config::SampleRate::SAI_192KHZ: return 192000.f;
default: return 48000.f;
}
}
Expand Down
29 changes: 15 additions & 14 deletions src/per/sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

namespace daisy
{
/**
/**
* Support for I2S Audio Protocol with different bit-depth, samplerate options
* Allows for master or slave, as well as freedom of selecting direction,
* Allows for master or slave, as well as freedom of selecting direction,
* and other behavior for each peripheral, and block.
*
*
* DMA Transfer commands must use buffers located within non-cached memory or use cache maintenance
* To declare an unitialized global element in the DMA memory section:
* int32_t DSY_DMA_BUFFER_SECTOR my_buffer[96];
*
* Callback functions will be called once per half of the buffer. In the above example,
* Callback functions will be called once per half of the buffer. In the above example,
* the callback function would be called once for every 48 samples.
*
*
* Use SAI Handle like this:
*
*
* SaiHandle::Config sai_config;
* sai_config.periph = SaiHandle::Config::Peripheral::SAI_1;
* sai_config.sr = SaiHandle::Config::SampleRate::SAI_48KHZ;
Expand Down Expand Up @@ -61,6 +61,7 @@ class SaiHandle
SAI_32KHZ,
SAI_48KHZ,
SAI_96KHZ,
SAI_192KHZ,
};

/** Bit Depth that the hardware expects to be transferred to/from the device. */
Expand All @@ -71,7 +72,7 @@ class SaiHandle
SAI_32BIT,
};

/** Specifies whether a particular block is the master or the slave
/** Specifies whether a particular block is the master or the slave
** If both are set to slave, no MCLK signal will be used, and it is
** expected that the codec will have its own xtal.
*/
Expand Down Expand Up @@ -119,16 +120,16 @@ class SaiHandle
/** Returns the current configuration */
const Config& GetConfig() const;

/** Callback Function to be called when DMA transfer is complete and half complete.
/** Callback Function to be called when DMA transfer is complete and half complete.
** This callback is prepared however the data is transmitted/received from the device.
** For example, using an AK4556 the data will be interleaved 24bit MSB Justified
**
**
** The hid/audio class will be allow for type conversions, de-interleaving, etc.
*/
typedef void (*CallbackFunctionPtr)(int32_t* in, int32_t* out, size_t size);

/** Starts Rx and Tx in Circular Buffer Mode
** The callback will be called when half of the buffer is ready,
/** Starts Rx and Tx in Circular Buffer Mode
** The callback will be called when half of the buffer is ready,
** and will handle size/2 samples per callback.
*/
Result StartDma(int32_t* buffer_rx,
Expand All @@ -142,12 +143,12 @@ class SaiHandle
/** Returns the samplerate based on the current configuration */
float GetSampleRate();

/** Returns the number of samples per audio block
/** Returns the number of samples per audio block
** Calculated as Buffer Size / 2 / number of channels */
size_t GetBlockSize();

/** Returns the Block Rate of the current stream based on the size
** of the buffer passed in, and the current samplerate.
/** Returns the Block Rate of the current stream based on the size
** of the buffer passed in, and the current samplerate.
*/
float GetBlockRate();

Expand Down