-
I'm feeding i2s through DMA. I ended up with somewhat weird code in my let mut i2s_driver = I2sDriver::new(i2s_peripheral, i2s_driver_config);
i2s_driver.set_tx_dma(true);
i2s_driver.enable();
let buffer1 = cortex_m::singleton!(: [u16; ARRAY_SIZE] = [1; ARRAY_SIZE]).unwrap();
let buffer2 = cortex_m::singleton!(: [u16; ARRAY_SIZE] = [1; ARRAY_SIZE]).unwrap();
let buffer3 = cortex_m::singleton!(: [u16; ARRAY_SIZE] = [1; ARRAY_SIZE]).unwrap(); // but why :D ?
let mut transfer = Transfer::init_memory_to_peripheral(
stream,
i2s_driver,
buffer1,
Some(buffer3),
config::DmaConfig::default()
.memory_increment(true)
.fifo_enable(true)
.double_buffer(true)
.fifo_error_interrupt(true)
.half_transfer_interrupt(true),
);
transfer.start(|_tx| {});
unsafe {
cortex_m::peripheral::NVIC::unmask(Interrupt::DMA2_STREAM2);
}
(
Shared {},
Local {
i2s_transfer: transfer,
buffer: Some(buffer2)
},
init::Monotonics(),
) Do I really need 3 buffers or is there a smarter way of dealing with this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You are right. This part of API looks bad designed. |
Beta Was this translation helpful? Give feedback.
-
No idea, I'm just starting with this stuff. In fact it's my first time using DMA directly and I'm still super-confused. Based on C++ tutorials, I though that I should swap buffers on half_transfer and on transfer_complete. But an attempt to do so on half_transfer results in |
Beta Was this translation helpful? Give feedback.
You are right. This part of API looks bad designed.
If you have ideas how to fix this, I'd look at them.