From acaa1d25962f2c2d3f5b2f479517ee81d0bae708 Mon Sep 17 00:00:00 2001 From: liebman Date: Sun, 8 Dec 2024 10:13:18 -0800 Subject: [PATCH] update for esp-hal git version --- Cargo.toml | 15 +++++++-- examples/i2s_parallel.rs | 69 +++++++++++++++++++--------------------- examples/lcd_cam.rs | 44 ++++++++++++------------- examples/parl_io.rs | 42 +++++++++++------------- src/i2s_parallel.rs | 3 +- src/parl_io.rs | 14 ++++---- 6 files changed, 92 insertions(+), 95 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a750e40..156c384 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ esp-hal-procmacros = { version = "0.15.0", features = ["ram"] } fugit = { version = "0.3.7" } log = { version = "0.4.22", optional = true } static_cell = { version = "2.1", features = ["nightly"] } -xtensa-lx-rt = { version = "0.17.1", optional = true } [build-dependencies] esp-build = "0.1.0" @@ -35,7 +34,7 @@ esp-backtrace = { version = "0.14.2", features = [ "exception-handler", ] } esp-println = { version = "0.12.0" } -esp-hal-embassy = { version = "0.4.0" } +esp-hal-embassy = { version = "0.5.0" } heapless = { version = "0.8.0", features = ["ufmt"] } [features] @@ -61,15 +60,25 @@ esp32c6 = [ debug = ["esp-hal/debug"] defmt = [ "dep:defmt", + "esp-hal/defmt", "esp-backtrace/defmt", "fugit/defmt" ] log = [ "dep:log", + "esp-hal/log", "esp-backtrace/println", "esp-println/auto", "esp-println/log", "esp-println/colors", ] -xtensa-lx-rt = ["dep:xtensa-lx-rt"] valid-pin = [] # only for parl_io debugging + +[patch.crates-io] +esp-backtrace = { path = "../esp-hal/esp-backtrace" } +esp-build = { path = "../esp-hal/esp-build" } +esp-hal = { path = "../esp-hal/esp-hal" } +esp-hal-embassy = { path = "../esp-hal/esp-hal-embassy" } +esp-println = { path = "../esp-hal/esp-println" } +esp-riscv-rt = { path = "../esp-hal/esp-riscv-rt" } +xtensa-lx-rt = { path = "../esp-hal/xtensa-lx-rt" } diff --git a/examples/i2s_parallel.rs b/examples/i2s_parallel.rs index 542c646..708e2b2 100644 --- a/examples/i2s_parallel.rs +++ b/examples/i2s_parallel.rs @@ -13,16 +13,16 @@ //! - G1 => GPIO4 //! - B1 => GPIO17 //! - R2 => GPIO18 -//! - G2 => GPIO19 -//! - B2 => GPIO5 -//! - A => GPIO12 -//! - B => GPIO14 -//! - C => GPIO26 -//! - D => GPIO27 -//! - E => GPIO13 -//! - OE => GPIO32 -//! - CLK => GPIO25 -//! - LAT => GPIO33 +//! - G2 => GPIO5 +//! - B2 => GPIO19 +//! - A => GPIO15 +//! - B => GPIO13 +//! - C => GPIO12 +//! - D => GPIO14 +//! - E => GPIO2 +//! - OE => GPIO25 +//! - CLK => GPIO27 +//! - LAT => GPIO26 //! //! Note that you most likeliy need level converters 3.3v to 5v for all HUB75 //! signals @@ -53,11 +53,8 @@ use embedded_graphics::text::Alignment; use embedded_graphics::text::Text; use embedded_graphics::Drawable; use esp_backtrace as _; -use esp_hal::dma::Dma; -use esp_hal::dma::DmaPriority; -use esp_hal::dma::I2s0DmaChannelCreator; use esp_hal::gpio::AnyPin; -use esp_hal::gpio::Io; +use esp_hal::i2s::parallel::AnyI2s; use esp_hal::interrupt::software::SoftwareInterruptControl; use esp_hal::interrupt::Priority; use esp_hal::peripherals::I2S0; @@ -99,7 +96,7 @@ type FrameBufferExchange = Signal; pub struct Hub75Peripherals { pub i2s: I2S0, - pub dma_channel: I2s0DmaChannelCreator, + pub dma_channel: esp_hal::dma::I2s0DmaChannel, pub red1: AnyPin, pub grn1: AnyPin, pub blu1: AnyPin, @@ -241,13 +238,13 @@ async fn hub75_task( latch: peripherals.latch, }; - let mut hub75 = Hub75Type::new( - peripherals.i2s, + let mut hub75 = Hub75Type::new_async( + >::into(peripherals.i2s), pins, - channel.configure_for_async(false, DmaPriority::Priority0), + channel, tx_descriptors, 19.MHz(), - ); + ).expect("failed to construct Hub75!"); let mut count = 0u32; let mut start = Instant::now(); @@ -297,8 +294,6 @@ async fn main(spawner: Spawner) { let peripherals = esp_hal::init(config); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); let software_interrupt = sw_ints.software_interrupt2; - let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let dma = Dma::new(peripherals.DMA); let timg0 = TimerGroup::new(peripherals.TIMG0); @@ -320,22 +315,22 @@ async fn main(spawner: Spawner) { let hub75_peripherals = Hub75Peripherals { i2s: peripherals.I2S0, - dma_channel: dma.i2s0channel, - red1: io.pins.gpio16.degrade(), - grn1: io.pins.gpio4.degrade(), - blu1: io.pins.gpio17.degrade(), - red2: io.pins.gpio18.degrade(), - grn2: io.pins.gpio5.degrade(), - blu2: io.pins.gpio19.degrade(), - addr0: io.pins.gpio12.degrade(), - addr1: io.pins.gpio14.degrade(), - addr2: io.pins.gpio27.degrade(), - addr3: io.pins.gpio26.degrade(), - addr4: io.pins.gpio13.degrade(), - blank: io.pins.gpio32.degrade(), - clock: io.pins.gpio25.degrade(), - latch: io.pins.gpio33.degrade(), - }; + dma_channel: peripherals.DMA_I2S0, + red1: peripherals.GPIO16.degrade(), + grn1: peripherals.GPIO4.degrade(), + blu1: peripherals.GPIO17.degrade(), + red2: peripherals.GPIO18.degrade(), + grn2: peripherals.GPIO5.degrade(), + blu2: peripherals.GPIO19.degrade(), + addr0: peripherals.GPIO15.degrade(), + addr1: peripherals.GPIO13.degrade(), + addr2: peripherals.GPIO12.degrade(), + addr3: peripherals.GPIO14.degrade(), + addr4: peripherals.GPIO2.degrade(), + blank: peripherals.GPIO25.degrade(), + clock: peripherals.GPIO27.degrade(), + latch: peripherals.GPIO26.degrade(), +}; let hp_executor = mk_static!( InterruptExecutor<2>, diff --git a/examples/lcd_cam.rs b/examples/lcd_cam.rs index ab3588f..ff24f29 100644 --- a/examples/lcd_cam.rs +++ b/examples/lcd_cam.rs @@ -51,10 +51,9 @@ use embedded_graphics::Drawable; use esp_backtrace as _; use esp_hal::cpu_control::CpuControl; use esp_hal::cpu_control::Stack; -use esp_hal::dma::Dma; +use esp_hal::dma::DmaChannel; use esp_hal::dma::DmaPriority; use esp_hal::gpio::AnyPin; -use esp_hal::gpio::Io; use esp_hal::interrupt::software::SoftwareInterruptControl; use esp_hal::interrupt::Priority; use esp_hal::peripherals::LCD_CAM; @@ -97,7 +96,7 @@ type FrameBufferExchange = Signal; pub struct Hub75Peripherals { pub lcd_cam: LCD_CAM, - pub dma_channel: esp_hal::dma::ChannelCreator<0>, + pub dma_channel: esp_hal::dma::DmaChannel0, pub red1: AnyPin, pub grn1: AnyPin, pub blu1: AnyPin, @@ -220,8 +219,8 @@ async fn hub75_task( ) { info!("hub75_task: starting!"); let channel = peripherals - .dma_channel - .configure_for_async(false, DmaPriority::Priority0); + .dma_channel; + channel.set_priority(DmaPriority::Priority0); let (_, tx_descriptors) = esp_hal::dma_descriptors!(0, SIZE * size_of::()); let pins = Hub75Pins { @@ -242,7 +241,8 @@ async fn hub75_task( }; let mut hub75 = - Hub75Type::new_async(peripherals.lcd_cam, pins, channel, tx_descriptors, 20.MHz()); + Hub75Type::new_async(peripherals.lcd_cam, pins, channel, tx_descriptors, 20.MHz()) + .expect("failed to construct Hub75!"); let mut count = 0u32; let mut start = Instant::now(); @@ -295,8 +295,6 @@ async fn main(_spawner: Spawner) { let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); let software_interrupt = sw_ints.software_interrupt2; let cpu_control = CpuControl::new(peripherals.CPU_CTRL); - let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let dma = Dma::new(peripherals.DMA); let timg0 = TimerGroup::new(peripherals.TIMG0); @@ -318,21 +316,21 @@ async fn main(_spawner: Spawner) { let hub75_peripherals = Hub75Peripherals { lcd_cam: peripherals.LCD_CAM, - dma_channel: dma.channel0, - red1: io.pins.gpio38.degrade(), - grn1: io.pins.gpio42.degrade(), - blu1: io.pins.gpio48.degrade(), - red2: io.pins.gpio47.degrade(), - grn2: io.pins.gpio2.degrade(), - blu2: io.pins.gpio21.degrade(), - addr0: io.pins.gpio14.degrade(), - addr1: io.pins.gpio46.degrade(), - addr2: io.pins.gpio13.degrade(), - addr3: io.pins.gpio9.degrade(), - addr4: io.pins.gpio3.degrade(), - blank: io.pins.gpio11.degrade(), - clock: io.pins.gpio12.degrade(), - latch: io.pins.gpio10.degrade(), + dma_channel: peripherals.DMA_CH0, + red1: peripherals.GPIO38.degrade(), + grn1: peripherals.GPIO42.degrade(), + blu1: peripherals.GPIO48.degrade(), + red2: peripherals.GPIO47.degrade(), + grn2: peripherals.GPIO2.degrade(), + blu2: peripherals.GPIO21.degrade(), + addr0: peripherals.GPIO14.degrade(), + addr1: peripherals.GPIO46.degrade(), + addr2: peripherals.GPIO13.degrade(), + addr3: peripherals.GPIO9.degrade(), + addr4: peripherals.GPIO3.degrade(), + blank: peripherals.GPIO11.degrade(), + clock: peripherals.GPIO12.degrade(), + latch: peripherals.GPIO10.degrade(), }; // run hub75 and display on second core diff --git a/examples/parl_io.rs b/examples/parl_io.rs index 765fdc5..7cac9ee 100644 --- a/examples/parl_io.rs +++ b/examples/parl_io.rs @@ -48,10 +48,9 @@ use embedded_graphics::text::Alignment; use embedded_graphics::text::Text; use embedded_graphics::Drawable; use esp_backtrace as _; -use esp_hal::dma::Dma; +use esp_hal::dma::DmaChannel; use esp_hal::dma::DmaPriority; use esp_hal::gpio::AnyPin; -use esp_hal::gpio::Io; use esp_hal::interrupt::software::SoftwareInterruptControl; use esp_hal::interrupt::Priority; use esp_hal::peripherals::PARL_IO; @@ -80,7 +79,7 @@ macro_rules! mk_static { pub struct DisplayPeripherals { pub parl_io: PARL_IO, - pub dma_channel: esp_hal::dma::ChannelCreator<0>, + pub dma_channel: esp_hal::dma::DmaChannel0, pub red1: AnyPin, pub grn1: AnyPin, pub blu1: AnyPin, @@ -212,9 +211,8 @@ async fn hub75_task( fb: &'static mut FBType, ) { info!("hub75_task: starting!"); - let channel = peripherals - .dma_channel - .configure_for_async(false, DmaPriority::Priority0); + let channel = peripherals.dma_channel; + channel.set_priority(DmaPriority::Priority0); let (_, tx_descriptors) = esp_hal::dma_descriptors!(0, SIZE * size_of::()); let pins = Hub75Pins { @@ -287,8 +285,6 @@ async fn main(spawner: Spawner) { let peripherals = esp_hal::init(config); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); let software_interrupt = sw_ints.software_interrupt2; - let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let dma = Dma::new(peripherals.DMA); let timg0 = TimerGroup::new(peripherals.TIMG0); @@ -308,21 +304,21 @@ async fn main(spawner: Spawner) { let display_peripherals = DisplayPeripherals { parl_io: peripherals.PARL_IO, - dma_channel: dma.channel0, - red1: io.pins.gpio19.degrade(), - grn1: io.pins.gpio20.degrade(), - blu1: io.pins.gpio21.degrade(), - red2: io.pins.gpio22.degrade(), - grn2: io.pins.gpio23.degrade(), - blu2: io.pins.gpio15.degrade(), - addr0: io.pins.gpio10.degrade(), - addr1: io.pins.gpio8.degrade(), - addr2: io.pins.gpio1.degrade(), - addr3: io.pins.gpio0.degrade(), - addr4: io.pins.gpio11.degrade(), - blank: io.pins.gpio5.degrade(), - clock: io.pins.gpio7.degrade(), - latch: io.pins.gpio6.degrade(), + dma_channel: peripherals.DMA_CH0, + red1: peripherals.GPIO19.degrade(), + grn1: peripherals.GPIO20.degrade(), + blu1: peripherals.GPIO21.degrade(), + red2: peripherals.GPIO22.degrade(), + grn2: peripherals.GPIO23.degrade(), + blu2: peripherals.GPIO15.degrade(), + addr0: peripherals.GPIO10.degrade(), + addr1: peripherals.GPIO8.degrade(), + addr2: peripherals.GPIO1.degrade(), + addr3: peripherals.GPIO0.degrade(), + addr4: peripherals.GPIO11.degrade(), + blank: peripherals.GPIO5.degrade(), + clock: peripherals.GPIO7.degrade(), + latch: peripherals.GPIO6.degrade(), }; // run hub75 as high priority task (interrupt executor) diff --git a/src/i2s_parallel.rs b/src/i2s_parallel.rs index 9551dbb..384dca4 100644 --- a/src/i2s_parallel.rs +++ b/src/i2s_parallel.rs @@ -92,5 +92,4 @@ impl<'d> Hub75<'d, esp_hal::Async> { #[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum Hub75Error { -} +pub enum Hub75Error {} diff --git a/src/parl_io.rs b/src/parl_io.rs index cc5b85c..769c9da 100644 --- a/src/parl_io.rs +++ b/src/parl_io.rs @@ -1,8 +1,6 @@ -use esp_hal::dma::Channel; -use esp_hal::dma::DmaChannelConvert; use esp_hal::dma::DmaDescriptor; -use esp_hal::dma::DmaEligible; use esp_hal::dma::ReadBuffer; +use esp_hal::dma::TxChannelFor; use esp_hal::gpio::NoPin; use esp_hal::parl_io::BitPackOrder; use esp_hal::parl_io::ClkOutPin; @@ -12,6 +10,7 @@ use esp_hal::parl_io::SampleEdge; #[cfg(feature = "valid-pin")] use esp_hal::parl_io::TxPinConfigIncludingValidPin; use esp_hal::parl_io::TxSixteenBits; +use esp_hal::peripheral::Peripheral; use esp_hal::peripherals::PARL_IO; use crate::framebuffer::DmaFrameBuffer; @@ -29,12 +28,12 @@ impl<'d> Hub75<'d, esp_hal::Async> { pub fn new_async( parl_io: PARL_IO, hub75_pins: Hub75Pins, // TODO: how can we make this non-static? - channel: Channel<'d, esp_hal::Blocking, CH>, + channel: impl Peripheral

+ 'd, tx_descriptors: &'static mut [DmaDescriptor], frequency: HertzU32, ) -> Self where - CH: DmaChannelConvert<::Dma>, + CH: TxChannelFor, { let (_, blank) = hub75_pins.blank.split(); @@ -86,8 +85,9 @@ impl<'d> Hub75<'d, esp_hal::Async> { // TODO: how can we make this non-static? static CLOCK_PIN: StaticCell = StaticCell::new(); let clock_pin = CLOCK_PIN.init(ClkOutPin::new(hub75_pins.clock)); - let parl_io = - ParlIoTxOnly::new(parl_io, channel.into_async(), tx_descriptors, frequency).unwrap(); // TODO: handle error + let parl_io = ParlIoTxOnly::new(parl_io, channel, tx_descriptors, frequency) + .unwrap() + .into_async(); // TODO: handle error let parl_io = parl_io .tx