mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 14:44:42 +00:00

* Add macro to create DMA buffers and descriptors * Remove WDT disabling from remaining examples * CHANGELOG.md entry * Remove redundant `unsafe` * Easier way to make RX and TX same sized
84 lines
2.1 KiB
Rust
84 lines
2.1 KiB
Rust
//! This shows how to continously receive data via I2S
|
|
//!
|
|
//! Pins used
|
|
//! MCLK GPIO4
|
|
//! BCLK GPIO1
|
|
//! WS GPIO2
|
|
//! DIN GPIO5
|
|
//!
|
|
//! Without an additional I2S source device you can connect 3V3 or GND to DIN to
|
|
//! read 0 or 0xFF or connect DIN to WS to read two different values
|
|
//!
|
|
//! You can also inspect the MCLK, BCLK and WS with a logic analyzer
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use esp32s3_hal::{
|
|
clock::ClockControl,
|
|
dma::DmaPriority,
|
|
dma_buffers,
|
|
gdma::Gdma,
|
|
i2s::{DataFormat, I2s, I2sReadDma, Standard},
|
|
peripherals::Peripherals,
|
|
prelude::*,
|
|
IO,
|
|
};
|
|
use esp_backtrace as _;
|
|
use esp_println::println;
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let peripherals = Peripherals::take();
|
|
let system = peripherals.SYSTEM.split();
|
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
|
|
let dma = Gdma::new(peripherals.DMA);
|
|
let dma_channel = dma.channel0;
|
|
|
|
let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4 * 4092);
|
|
|
|
// Here we test that the type is
|
|
// 1) reasonably simple (or at least this will flag changes that may make it
|
|
// more complex)
|
|
// 2) can be spelled out by the user
|
|
let i2s = I2s::new(
|
|
peripherals.I2S0,
|
|
Standard::Philips,
|
|
DataFormat::Data16Channel16,
|
|
44100u32.Hz(),
|
|
dma_channel.configure(
|
|
false,
|
|
&mut tx_descriptors,
|
|
&mut rx_descriptors,
|
|
DmaPriority::Priority0,
|
|
),
|
|
&clocks,
|
|
)
|
|
.with_mclk(io.pins.gpio4);
|
|
|
|
let i2s_rx = i2s
|
|
.i2s_rx
|
|
.with_bclk(io.pins.gpio1)
|
|
.with_ws(io.pins.gpio2)
|
|
.with_din(io.pins.gpio5)
|
|
.build();
|
|
|
|
let buffer = rx_buffer;
|
|
|
|
let mut transfer = i2s_rx.read_dma_circular(buffer).unwrap();
|
|
println!("Started transfer");
|
|
|
|
loop {
|
|
let avail = transfer.available();
|
|
|
|
if avail > 0 {
|
|
let mut rcv = [0u8; 5000];
|
|
transfer.pop(&mut rcv[..avail]).unwrap();
|
|
println!("Received {:x?}...", &rcv[..30]);
|
|
}
|
|
}
|
|
}
|