mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 06:40:47 +00:00
94 lines
2.4 KiB
Rust
94 lines
2.4 KiB
Rust
//! This shows using Parallel IO to output 4 bit parallel data at 1MHz clock
|
|
//! rate.
|
|
//!
|
|
//! Uses GPIO 1, 2, 3 and 4 as the data pins.
|
|
//! GPIO 5 as the "valid pin" (driven high during an active transfer) and GPIO
|
|
//! 8 as the clock signal output.
|
|
//!
|
|
//! You can use a logic analyzer to see how the pins are used.
|
|
|
|
//% CHIPS: esp32c6 esp32h2
|
|
//% FEATURES: async embassy embassy-time-timg0 embassy-generic-timers
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use embassy_executor::Spawner;
|
|
use embassy_time::{Duration, Timer};
|
|
use esp_backtrace as _;
|
|
use esp_hal::{
|
|
clock::ClockControl,
|
|
dma::{Dma, DmaPriority},
|
|
dma_buffers,
|
|
gpio::Io,
|
|
parl_io::{
|
|
BitPackOrder,
|
|
ClkOutPin,
|
|
ParlIoTxOnly,
|
|
SampleEdge,
|
|
TxFourBits,
|
|
TxPinConfigWithValidPin,
|
|
},
|
|
peripherals::Peripherals,
|
|
prelude::*,
|
|
system::SystemControl,
|
|
timer::timg::TimerGroup,
|
|
};
|
|
use esp_println::println;
|
|
|
|
#[main]
|
|
async fn main(_spawner: Spawner) {
|
|
esp_println::println!("Init!");
|
|
let peripherals = Peripherals::take();
|
|
let system = SystemControl::new(peripherals.SYSTEM);
|
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks);
|
|
esp_hal_embassy::init(&clocks, timg0);
|
|
|
|
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
|
|
let (tx_buffer, mut tx_descriptors, _, _) = dma_buffers!(32000, 0);
|
|
|
|
let dma = Dma::new(peripherals.DMA);
|
|
let dma_channel = dma.channel0;
|
|
|
|
let tx_pins = TxFourBits::new(io.pins.gpio1, io.pins.gpio2, io.pins.gpio3, io.pins.gpio4);
|
|
|
|
let mut pin_conf = TxPinConfigWithValidPin::new(tx_pins, io.pins.gpio5);
|
|
|
|
let parl_io = ParlIoTxOnly::new(
|
|
peripherals.PARL_IO,
|
|
dma_channel.configure_for_async(false, DmaPriority::Priority0),
|
|
tx_descriptors,
|
|
1.MHz(),
|
|
&clocks,
|
|
)
|
|
.unwrap();
|
|
|
|
let mut clock_pin = ClkOutPin::new(io.pins.gpio8);
|
|
|
|
let mut parl_io_tx = parl_io
|
|
.tx
|
|
.with_config(
|
|
&mut pin_conf,
|
|
&mut clock_pin,
|
|
0,
|
|
SampleEdge::Normal,
|
|
BitPackOrder::Msb,
|
|
)
|
|
.unwrap();
|
|
|
|
let buffer = tx_buffer;
|
|
for i in 0..buffer.len() {
|
|
buffer[i] = (i % 255) as u8;
|
|
}
|
|
|
|
loop {
|
|
parl_io_tx.write_dma_async(buffer).await.unwrap();
|
|
println!("Transferred {} bytes", buffer.len());
|
|
|
|
Timer::after(Duration::from_millis(500)).await;
|
|
}
|
|
}
|