Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes for next esp-hal release (current git version) #6

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ rust-version = "1.71"
[dependencies]
bitfield = { version = "0.17.0" }
cfg-if = "1.0.0"
critical-section = { version = "1.1.2" }
critical-section = { version = "1.2.0" }
defmt = { version = "0.3.8", optional = true }
embedded-graphics = { version = "0.8.1" }
embedded-hal = { version = "1.0.0" }
embedded-hal-async = { version = "1.0.0" }
esp-hal = { version = "0.22.0" }
esp-hal = { version = "0.22.0", features = ["unstable"] }
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 Down Expand Up @@ -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" }
32 changes: 17 additions & 15 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,9 +53,6 @@ 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::i2s::parallel::AnyI2s;
use esp_hal::interrupt::software::SoftwareInterruptControl;
Expand Down Expand Up @@ -242,7 +239,13 @@ async fn hub75_task(
latch: peripherals.latch,
};

let mut hub75 = Hub75Type::new_async(peripherals.i2s, pins, channel, tx_descriptors, 19.MHz());
let mut hub75 = Hub75Type::new_async(
<esp_hal::peripherals::I2S0 as Into<AnyI2s>>::into(peripherals.i2s),
pins,
channel,
tx_descriptors,
19.MHz(),
).expect("failed to construct Hub75!");

let mut count = 0u32;
let mut start = Instant::now();
Expand Down Expand Up @@ -292,7 +295,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 dma = Dma::new(peripherals.DMA);

let timg0 = TimerGroup::new(peripherals.TIMG0);

Expand Down
14 changes: 7 additions & 7 deletions examples/lcd_cam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ 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::interrupt::software::SoftwareInterruptControl;
Expand Down Expand Up @@ -96,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 @@ -219,8 +219,8 @@ async fn hub75_task(
) {
info!("hub75_task: starting!");
let channel = peripherals
.dma_channel
.configure(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 @@ -241,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 @@ -294,7 +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 dma = Dma::new(peripherals.DMA);

let timg0 = TimerGroup::new(peripherals.TIMG0);

Expand All @@ -316,7 +316,7 @@ async fn main(_spawner: Spawner) {

let hub75_peripherals = Hub75Peripherals {
lcd_cam: peripherals.LCD_CAM,
dma_channel: dma.channel0,
dma_channel: peripherals.DMA_CH0,
red1: peripherals.GPIO38.degrade(),
grn1: peripherals.GPIO42.degrade(),
blu1: peripherals.GPIO48.degrade(),
Expand Down
13 changes: 5 additions & 8 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(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,7 +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 dma = Dma::new(peripherals.DMA);

let timg0 = TimerGroup::new(peripherals.TIMG0);

Expand All @@ -307,7 +304,7 @@ async fn main(spawner: Spawner) {

let display_peripherals = DisplayPeripherals {
parl_io: peripherals.PARL_IO,
dma_channel: dma.channel0,
dma_channel: peripherals.DMA_CH0,
red1: peripherals.GPIO19.degrade(),
grn1: peripherals.GPIO20.degrade(),
blu1: peripherals.GPIO21.degrade(),
Expand Down
23 changes: 14 additions & 9 deletions src/i2s_parallel.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use core::cell::Cell;

use esp_hal::dma::Channel;
use esp_hal::dma::DmaChannelConvert;
use esp_hal::dma::DmaChannelFor;
use esp_hal::dma::DmaDescriptor;
use esp_hal::dma::DmaEligible;
use esp_hal::dma::DmaTxBuf;
use esp_hal::gpio::NoPin;
use esp_hal::i2s::parallel::AnyI2s;
Expand All @@ -21,13 +19,16 @@ pub struct Hub75<'d, DM: esp_hal::Mode> {
}

impl<'d> Hub75<'d, esp_hal::Async> {
pub fn new_async<CH: DmaChannelConvert<<AnyI2s as DmaEligible>::Dma>>(
pub fn new_async<CH>(
i2s: impl Peripheral<P = AnyI2s> + 'd,
hub75_pins: Hub75Pins,
channel: Channel<'d, esp_hal::Blocking, CH>,
channel: impl Peripheral<P = CH> + 'd,
tx_descriptors: &'static mut [DmaDescriptor],
frequency: HertzU32,
) -> Self {
) -> Result<Self, Hub75Error>
where
CH: DmaChannelFor<AnyI2s>,
{
let (_, blank) = hub75_pins.blank.split();
let pins = TxSixteenBits::new(
hub75_pins.addr0,
Expand All @@ -48,13 +49,13 @@ impl<'d> Hub75<'d, esp_hal::Async> {
NoPin,
);

let i2s = I2sParallel::new(i2s, channel.into_async(), frequency, pins, hub75_pins.clock);
let i2s = I2sParallel::new(i2s, channel, frequency, pins, hub75_pins.clock).into_async();
let i2s = Cell::new(Some(i2s));
let tx_descriptors = Cell::new(Some(tx_descriptors));
Self {
Ok(Self {
i2s,
tx_descriptors,
}
})
}

pub async fn render_async<
Expand Down Expand Up @@ -88,3 +89,7 @@ impl<'d> Hub75<'d, esp_hal::Async> {
self.tx_descriptors.set(Some(tx_descriptors));
}
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Hub75Error {}
47 changes: 28 additions & 19 deletions src/lcd_cam.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
use core::cell::Cell;

use esp_hal::dma::Channel;
use esp_hal::dma::DmaChannelConvert;
#[cfg(feature = "defmt")]
use defmt::debug;
use esp_hal::dma::DmaDescriptor;
use esp_hal::dma::DmaEligible;
use esp_hal::dma::DmaTxBuf;
use esp_hal::dma::TxChannelFor;
use esp_hal::gpio::NoPin;
use esp_hal::lcd_cam::lcd::i8080;
use esp_hal::lcd_cam::lcd::i8080::Command;
use esp_hal::lcd_cam::lcd::i8080::TxSixteenBits;
use esp_hal::lcd_cam::lcd::i8080::I8080;
use esp_hal::lcd_cam::LcdCam;
use esp_hal::peripheral::Peripheral;
use esp_hal::peripherals::LCD_CAM;
#[cfg(feature = "log")]
use log::debug;

use crate::framebuffer::DmaFrameBuffer;
use crate::HertzU32;
Expand All @@ -26,12 +29,12 @@ impl<'d> Hub75<'d, esp_hal::Async> {
pub fn new_async<CH>(
lcd_cam: LCD_CAM,
hub75_pins: Hub75Pins,
channel: Channel<'d, esp_hal::Blocking, CH>,
channel: impl Peripheral<P = CH> + 'd,
tx_descriptors: &'static mut [DmaDescriptor],
frequency: HertzU32,
) -> Self
) -> Result<Self, Hub75Error>
where
CH: DmaChannelConvert<<LCD_CAM as DmaEligible>::Dma>,
CH: TxChannelFor<LCD_CAM>,
{
let lcd_cam = LcdCam::new(lcd_cam).into_async();
Self::new_internal(lcd_cam, hub75_pins, channel, tx_descriptors, frequency)
Expand All @@ -55,10 +58,13 @@ impl<'d> Hub75<'d, esp_hal::Async> {
core::slice::from_raw_parts_mut(ptr as *mut u8, len)
};
let tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).expect("DmaTxBuf::new failed");
debug!("lcd_cam: Sending buffer");
let mut xfer = i8080
.send(Command::<u16>::None, 0, tx_buf)
.expect("send failed");
debug!("lcd_cam: Waiting for transfer to complete");
xfer.wait_for_done().await;
debug!("lcd_cam: Transfer complete");
let (result, i8080, tx_buf) = xfer.wait();
result.expect("transfer failed");
let (tx_descriptors, _) = tx_buf.split();
Expand All @@ -71,12 +77,12 @@ impl<'d, DM: esp_hal::Mode> Hub75<'d, DM> {
fn new_internal<CH>(
lcd_cam: LcdCam<'d, DM>,
hub75_pins: Hub75Pins,
channel: Channel<'d, esp_hal::Blocking, CH>,
channel: impl Peripheral<P = CH> + 'd,
tx_descriptors: &'static mut [DmaDescriptor],
frequency: HertzU32,
) -> Self
) -> Result<Self, Hub75Error>
where
CH: DmaChannelConvert<<LCD_CAM as DmaEligible>::Dma>,
CH: TxChannelFor<LCD_CAM>,
{
let (_, blank) = hub75_pins.blank.split();
let pins = TxSixteenBits::new(
Expand All @@ -98,19 +104,22 @@ impl<'d, DM: esp_hal::Mode> Hub75<'d, DM> {
NoPin,
);

let i8080 = I8080::new(
lcd_cam.lcd,
channel.tx,
pins,
frequency,
i8080::Config::default(),
)
.with_ctrl_pins(NoPin, hub75_pins.clock);
let mut config = esp_hal::lcd_cam::lcd::i8080::Config::default();
config.frequency = frequency;
let i8080 = I8080::new(lcd_cam.lcd, channel, pins, i8080::Config::default())
.map_err(Hub75Error::I8080)?
.with_ctrl_pins(NoPin, hub75_pins.clock);
let i8080 = Cell::new(Some(i8080));
let tx_descriptors = Cell::new(Some(tx_descriptors));
Self {
Ok(Self {
i8080,
tx_descriptors,
}
})
}
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Hub75Error {
I8080(esp_hal::lcd_cam::lcd::i8080::ConfigError),
}
Loading