mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-29 05:11:31 +00:00
i2s
This commit is contained in:
parent
f2be66a5f9
commit
f9da2888c4
@ -155,6 +155,10 @@ impl ClockPolarity {
|
|||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
/// Frequency
|
||||||
|
pub frequency: Hertz,
|
||||||
|
/// GPIO Speed
|
||||||
|
pub gpio_speed: Speed,
|
||||||
/// Mode
|
/// Mode
|
||||||
pub mode: Mode,
|
pub mode: Mode,
|
||||||
/// Which I2S standard to use.
|
/// Which I2S standard to use.
|
||||||
@ -170,6 +174,8 @@ pub struct Config {
|
|||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
frequency: Hertz::khz(48),
|
||||||
|
gpio_speed: Speed::VeryHigh,
|
||||||
mode: Mode::Master,
|
mode: Mode::Master,
|
||||||
standard: Standard::Philips,
|
standard: Standard::Philips,
|
||||||
format: Format::Data16Channel16,
|
format: Format::Data16Channel16,
|
||||||
@ -243,7 +249,6 @@ impl<'d, W: Word> I2S<'d, W> {
|
|||||||
mck: Peri<'d, impl MckPin<T>>,
|
mck: Peri<'d, impl MckPin<T>>,
|
||||||
txdma: Peri<'d, impl TxDma<T>>,
|
txdma: Peri<'d, impl TxDma<T>>,
|
||||||
txdma_buf: &'d mut [W],
|
txdma_buf: &'d mut [W],
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
@ -255,7 +260,6 @@ impl<'d, W: Word> I2S<'d, W> {
|
|||||||
new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)),
|
new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)),
|
||||||
new_dma!(txdma).map(|d| (d, txdma_buf)),
|
new_dma!(txdma).map(|d| (d, txdma_buf)),
|
||||||
None,
|
None,
|
||||||
freq,
|
|
||||||
config,
|
config,
|
||||||
Function::Transmit,
|
Function::Transmit,
|
||||||
)
|
)
|
||||||
@ -269,7 +273,6 @@ impl<'d, W: Word> I2S<'d, W> {
|
|||||||
ck: Peri<'d, impl CkPin<T>>,
|
ck: Peri<'d, impl CkPin<T>>,
|
||||||
txdma: Peri<'d, impl TxDma<T>>,
|
txdma: Peri<'d, impl TxDma<T>>,
|
||||||
txdma_buf: &'d mut [W],
|
txdma_buf: &'d mut [W],
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
@ -281,7 +284,6 @@ impl<'d, W: Word> I2S<'d, W> {
|
|||||||
None,
|
None,
|
||||||
new_dma!(txdma).map(|d| (d, txdma_buf)),
|
new_dma!(txdma).map(|d| (d, txdma_buf)),
|
||||||
None,
|
None,
|
||||||
freq,
|
|
||||||
config,
|
config,
|
||||||
Function::Transmit,
|
Function::Transmit,
|
||||||
)
|
)
|
||||||
@ -296,7 +298,6 @@ impl<'d, W: Word> I2S<'d, W> {
|
|||||||
mck: Peri<'d, impl MckPin<T>>,
|
mck: Peri<'d, impl MckPin<T>>,
|
||||||
rxdma: Peri<'d, impl RxDma<T>>,
|
rxdma: Peri<'d, impl RxDma<T>>,
|
||||||
rxdma_buf: &'d mut [W],
|
rxdma_buf: &'d mut [W],
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
@ -308,7 +309,6 @@ impl<'d, W: Word> I2S<'d, W> {
|
|||||||
new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)),
|
new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)),
|
||||||
None,
|
None,
|
||||||
new_dma!(rxdma).map(|d| (d, rxdma_buf)),
|
new_dma!(rxdma).map(|d| (d, rxdma_buf)),
|
||||||
freq,
|
|
||||||
config,
|
config,
|
||||||
Function::Receive,
|
Function::Receive,
|
||||||
)
|
)
|
||||||
@ -327,7 +327,6 @@ impl<'d, W: Word> I2S<'d, W> {
|
|||||||
txdma_buf: &'d mut [W],
|
txdma_buf: &'d mut [W],
|
||||||
rxdma: Peri<'d, impl RxDma<T>>,
|
rxdma: Peri<'d, impl RxDma<T>>,
|
||||||
rxdma_buf: &'d mut [W],
|
rxdma_buf: &'d mut [W],
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
@ -339,7 +338,6 @@ impl<'d, W: Word> I2S<'d, W> {
|
|||||||
new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)),
|
new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)),
|
||||||
new_dma!(txdma).map(|d| (d, txdma_buf)),
|
new_dma!(txdma).map(|d| (d, txdma_buf)),
|
||||||
new_dma!(rxdma).map(|d| (d, rxdma_buf)),
|
new_dma!(rxdma).map(|d| (d, rxdma_buf)),
|
||||||
freq,
|
|
||||||
config,
|
config,
|
||||||
Function::FullDuplex,
|
Function::FullDuplex,
|
||||||
)
|
)
|
||||||
@ -473,17 +471,16 @@ impl<'d, W: Word> I2S<'d, W> {
|
|||||||
mck: Option<Peri<'d, AnyPin>>,
|
mck: Option<Peri<'d, AnyPin>>,
|
||||||
txdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>,
|
txdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>,
|
||||||
rxdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>,
|
rxdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>,
|
||||||
freq: Hertz,
|
|
||||||
config: Config,
|
config: Config,
|
||||||
function: Function,
|
function: Function,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
ws.set_as_af(ws.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
ws.set_as_af(ws.af_num(), AfType::output(OutputType::PushPull, config.gpio_speed));
|
||||||
ck.set_as_af(ck.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
ck.set_as_af(ck.af_num(), AfType::output(OutputType::PushPull, config.gpio_speed));
|
||||||
|
|
||||||
let spi = Spi::new_internal(peri, None, None, {
|
let spi = Spi::new_internal(peri, None, None, {
|
||||||
let mut config = SpiConfig::default();
|
let mut spi_config = SpiConfig::default();
|
||||||
config.frequency = freq;
|
spi_config.frequency = config.frequency;
|
||||||
config
|
spi_config
|
||||||
});
|
});
|
||||||
|
|
||||||
let regs = T::info().regs;
|
let regs = T::info().regs;
|
||||||
@ -493,7 +490,7 @@ impl<'d, W: Word> I2S<'d, W> {
|
|||||||
#[cfg(not(all(rcc_f4, not(stm32f410))))]
|
#[cfg(not(all(rcc_f4, not(stm32f410))))]
|
||||||
let pclk = T::frequency();
|
let pclk = T::frequency();
|
||||||
|
|
||||||
let (odd, div) = compute_baud_rate(pclk, freq, config.master_clock, config.format);
|
let (odd, div) = compute_baud_rate(pclk, config.frequency, config.master_clock, config.format);
|
||||||
|
|
||||||
#[cfg(any(spi_v1, spi_v3, spi_f1))]
|
#[cfg(any(spi_v1, spi_v3, spi_f1))]
|
||||||
{
|
{
|
||||||
|
@ -72,7 +72,6 @@ async fn main(_spawner: Spawner) {
|
|||||||
p.PB3, // ck
|
p.PB3, // ck
|
||||||
p.DMA1_CH7,
|
p.DMA1_CH7,
|
||||||
&mut dma_buffer,
|
&mut dma_buffer,
|
||||||
Hertz(48_000),
|
|
||||||
i2s_config,
|
i2s_config,
|
||||||
);
|
);
|
||||||
i2s.start();
|
i2s.start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user