Skip to content

Commit

Permalink
update for esp-hal git version
Browse files Browse the repository at this point in the history
  • Loading branch information
liebman committed Dec 8, 2024
1 parent 15e9901 commit acaa1d2
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 95 deletions.
15 changes: 12 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand All @@ -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" }
69 changes: 32 additions & 37 deletions examples/i2s_parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +96,7 @@ type FrameBufferExchange = Signal<CriticalSectionRawMutex, &'static mut FBType>;

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,
Expand Down Expand Up @@ -241,13 +238,13 @@ async fn hub75_task(
latch: peripherals.latch,
};

let mut hub75 = Hub75Type::new(
peripherals.i2s,
let mut hub75 = Hub75Type::new_async(
<esp_hal::peripherals::I2S0 as Into<AnyI2s>>::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();
Expand Down Expand Up @@ -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);

Expand All @@ -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>,
Expand Down
44 changes: 21 additions & 23 deletions examples/lcd_cam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,7 +96,7 @@ type FrameBufferExchange = Signal<CriticalSectionRawMutex, &'static mut FBType>;

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,
Expand Down Expand Up @@ -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::<Entry>());

let pins = Hub75Pins {
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down
42 changes: 19 additions & 23 deletions examples/parl_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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::<Entry>());

let pins = Hub75Pins {
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/i2s_parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
14 changes: 7 additions & 7 deletions src/parl_io.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -29,12 +28,12 @@ impl<'d> Hub75<'d, esp_hal::Async> {
pub fn new_async<CH>(
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<P = CH> + 'd,
tx_descriptors: &'static mut [DmaDescriptor],
frequency: HertzU32,
) -> Self
where
CH: DmaChannelConvert<<PARL_IO as DmaEligible>::Dma>,
CH: TxChannelFor<PARL_IO>,
{
let (_, blank) = hub75_pins.blank.split();

Expand Down Expand Up @@ -86,8 +85,9 @@ impl<'d> Hub75<'d, esp_hal::Async> {
// TODO: how can we make this non-static?
static CLOCK_PIN: StaticCell<ClkOutPin> = 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
Expand Down

0 comments on commit acaa1d2

Please sign in to comment.