Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main' into new_spi_dma
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Fischer committed Aug 1, 2024
2 parents eee5dcb + 0c29c43 commit 69f8efd
Show file tree
Hide file tree
Showing 16 changed files with 545 additions and 46 deletions.
20 changes: 14 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ env:
CARGO_TERM_COLOR: always
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MSRV: "1.76.0"
RUSTDOCFLAGS: -Dwarnings

# Cancel any currently running workflows from the same PR, branch, or
# tag when a new workflow is triggered.
Expand Down Expand Up @@ -62,6 +63,13 @@ jobs:
]

steps:
- name: Set up cargo environment
run: |
# Convert the target triple from kebab-case to SCREAMING_SNAKE_CASE:
big_target=$(echo "${{ matrix.device.target }}" | tr [:lower:] [:upper:] | tr '-' '_')
# Set the *target specific* RUSTFLAGS for the current device:
echo "CARGO_TARGET_${big_target}_RUSTFLAGS=-Dwarnings" >> $GITHUB_ENV
- uses: actions/checkout@v4

# Install the Rust toolchain for Xtensa devices:
Expand All @@ -73,12 +81,12 @@ jobs:
- uses: dtolnay/rust-toolchain@v1
with:
target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf
toolchain: stable
toolchain: nightly
components: rust-src
- uses: dtolnay/rust-toolchain@v1
with:
target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf
toolchain: nightly
toolchain: stable
components: rust-src

- uses: Swatinem/rust-cache@v2
Expand All @@ -89,7 +97,7 @@ jobs:
run: cargo xtask build-examples esp-lp-hal ${{ matrix.device.soc }}
- if: contains(fromJson('["esp32c6", "esp32s2", "esp32s3"]'), matrix.device.soc)
name: Check esp-lp-hal documentation
run: RUSTDOCFLAGS="-D warnings" cargo xtask build-documentation --packages esp-lp-hal --chips ${{ matrix.device.soc }}
run: cargo xtask build-documentation --packages esp-lp-hal --chips ${{ matrix.device.soc }}

# Make sure we're able to build the HAL without the default features
# enabled:
Expand All @@ -107,7 +115,7 @@ jobs:
- name: Check doc-tests
run: cargo +esp xtask run-doc-test esp-hal ${{ matrix.device.soc }}
- name: Check documentation
run: RUSTDOCFLAGS="-D warnings" cargo xtask build-documentation --packages esp-hal --chips ${{ matrix.device.soc }}
run: cargo xtask build-documentation --packages esp-hal --chips ${{ matrix.device.soc }}
# Run clippy
- name: Clippy
# We use the 'esp' toolchain for *all* targets, in order to get a
Expand Down Expand Up @@ -224,8 +232,8 @@ jobs:

steps:
- uses: actions/checkout@v4
# Install the Rust toolchain for RISC-V devices:


# Install the Rust toolchain for RISC-V devices:
- if: ${{ !contains(fromJson('["esp32", "esp32s2", "esp32s3"]'), matrix.target.soc) }}
uses: dtolnay/rust-toolchain@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/hil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
uses: dtolnay/rust-toolchain@v1
with:
target: ${{ matrix.target.rust-target }}
toolchain: nightly
toolchain: stable
components: rust-src
# Install the Rust toolchain for Xtensa devices:
- if: contains(fromJson('["esp32", "esp32s2", "esp32s3"]'), matrix.target.soc)
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:
# RISC-V devices:
- soc: esp32c2
runner: esp32c2-jtag
usb: ACM0
usb: USB2
- soc: esp32c3
runner: esp32c3-usb
usb: ACM0
Expand All @@ -112,7 +112,7 @@ jobs:
usb: ACM0
- soc: esp32h2
runner: esp32h2-usb
usb: ACM0
usb: USB0
# Xtensa devices:
- soc: esp32s2
runner: esp32s2-jtag
Expand Down
2 changes: 2 additions & 0 deletions esp-hal-embassy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fixed a bug where the timeout was huge whenever the timestamp at the time of scheduling was already in the past (#1875)

### Removed

## 0.2.0 - 2024-07-15
Expand Down
18 changes: 10 additions & 8 deletions esp-hal-embassy/src/time_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ impl EmbassyTimer {
handler0, handler1, handler2, handler3, handler4, handler5, handler6,
];

timers
.iter_mut()
.enumerate()
.for_each(|(n, timer)| timer.set_interrupt_handler(HANDLERS[n]));

critical_section::with(|cs| {
timers.iter_mut().enumerate().for_each(|(n, timer)| {
timer.enable_interrupt(false);
timer.stop();
timer.set_interrupt_handler(HANDLERS[n]);
});

TIMERS.replace(cs, Some(timers));
});

Expand Down Expand Up @@ -99,7 +100,7 @@ impl EmbassyTimer {
fn on_interrupt(&self, id: usize) {
let cb = critical_section::with(|cs| {
let mut timers = TIMERS.borrow_ref_mut(cs);
let timers = timers.as_mut().unwrap();
let timers = timers.as_mut().expect("Time driver not initialized");
let timer = &mut timers[id];

timer.clear_interrupt();
Expand All @@ -121,7 +122,8 @@ impl EmbassyTimer {
fn arm(timer: &mut Timer, timestamp: u64) {
let now = current_time().duration_since_epoch();
let ts = timestamp.micros();
let timeout = if ts > now { ts - now } else { now };
// if the TS is already in the past make the timer fire immediately
let timeout = if ts > now { ts - now } else { 0.micros() };
timer.schedule(timeout).unwrap();
timer.enable_interrupt(true);
}
Expand Down Expand Up @@ -169,7 +171,7 @@ impl Driver for EmbassyTimer {
// soon as possible, but not synchronously.)
critical_section::with(|cs| {
let mut timers = TIMERS.borrow_ref_mut(cs);
let timers = timers.as_mut().unwrap();
let timers = timers.as_mut().expect("Time driver not initialized");
let timer = &mut timers[alarm.id() as usize];

Self::arm(timer, timestamp);
Expand Down
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add DmaTransactionTxOwned, DmaTransactionRxOwned, DmaTransactionTxRxOwned, functions to do owning transfers added to SPI half-duplex (#1672)
- uart: Implement `embedded_io::ReadReady` for `Uart` and `UartRx` (#1702)
- ESP32-S3: Expose optional HSYNC input in LCD_CAM (#1707)
- ESP32-S3: Add async support to the LCD_CAM I8080 driver (#1834)
- ESP32-C6: Support lp-core as wake-up source (#1723)
- Add support for GPIO wake-up source (#1724)
- gpio: add DummyPin (#1769)
Expand Down
51 changes: 42 additions & 9 deletions esp-hal/src/lcd_cam/lcd/i8080.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@
//! # }
//! ```

use core::{fmt::Formatter, mem::size_of};
use core::{fmt::Formatter, marker::PhantomData, mem::size_of};

use fugit::HertzU32;

#[cfg(feature = "async")]
use crate::lcd_cam::asynch::LcdDoneFuture;
use crate::{
clock::Clocks,
dma::{
Expand All @@ -86,22 +88,24 @@ use crate::{
},
peripheral::{Peripheral, PeripheralRef},
peripherals::LCD_CAM,
Mode,
};

pub struct I8080<'d, CH: DmaChannel, P> {
pub struct I8080<'d, CH: DmaChannel, P, DM: Mode> {
lcd_cam: PeripheralRef<'d, LCD_CAM>,
tx_channel: ChannelTx<'d, CH>,
tx_chain: DescriptorChain,
_pins: P,
_phantom: PhantomData<DM>,
}

impl<'d, CH: DmaChannel, P: TxPins> I8080<'d, CH, P>
impl<'d, CH: DmaChannel, P: TxPins, DM: Mode> I8080<'d, CH, P, DM>
where
CH::P: LcdCamPeripheral,
P::Word: Into<u16>,
{
pub fn new(
lcd: Lcd<'d>,
lcd: Lcd<'d, DM>,
mut channel: ChannelTx<'d, CH>,
descriptors: &'static mut [DmaDescriptor],
mut pins: P,
Expand Down Expand Up @@ -249,11 +253,12 @@ where
tx_channel: channel,
tx_chain: DescriptorChain::new(descriptors),
_pins: pins,
_phantom: PhantomData,
}
}
}

impl<'d, CH: DmaChannel, P: TxPins> DmaSupport for I8080<'d, CH, P> {
impl<'d, CH: DmaChannel, P: TxPins, DM: Mode> DmaSupport for I8080<'d, CH, P, DM> {
fn peripheral_wait_dma(&mut self, _is_tx: bool, _is_rx: bool) {
let lcd_user = self.lcd_cam.lcd_user();
// Wait until LCD_START is cleared by hardware.
Expand All @@ -266,7 +271,7 @@ impl<'d, CH: DmaChannel, P: TxPins> DmaSupport for I8080<'d, CH, P> {
}
}

impl<'d, CH: DmaChannel, P: TxPins> DmaSupportTx for I8080<'d, CH, P> {
impl<'d, CH: DmaChannel, P: TxPins, DM: Mode> DmaSupportTx for I8080<'d, CH, P, DM> {
type TX = ChannelTx<'d, CH>;

fn tx(&mut self) -> &mut Self::TX {
Expand All @@ -278,7 +283,7 @@ impl<'d, CH: DmaChannel, P: TxPins> DmaSupportTx for I8080<'d, CH, P> {
}
}

impl<'d, CH: DmaChannel, P: TxPins> I8080<'d, CH, P>
impl<'d, CH: DmaChannel, P: TxPins, DM: Mode> I8080<'d, CH, P, DM>
where
P::Word: Into<u16>,
{
Expand Down Expand Up @@ -364,7 +369,35 @@ where
}
}

impl<'d, CH: DmaChannel, P> I8080<'d, CH, P> {
#[cfg(feature = "async")]
impl<'d, CH: DmaChannel, P: TxPins> I8080<'d, CH, P, crate::Async>
where
P::Word: Into<u16>,
{
pub async fn send_dma_async<'t, TXBUF>(
&'t mut self,
cmd: impl Into<Command<P::Word>>,
dummy: u8,
data: &'t TXBUF,
) -> Result<(), DmaError>
where
TXBUF: ReadBuffer,
{
let (ptr, len) = unsafe { data.read_buffer() };

self.setup_send(cmd.into(), dummy);
self.start_write_bytes_dma(ptr as _, len)?;
self.start_send();

LcdDoneFuture::new().await;
if self.tx_channel.has_error() {
return Err(DmaError::DescriptorError);
}
Ok(())
}
}

impl<'d, CH: DmaChannel, P, DM: Mode> I8080<'d, CH, P, DM> {
fn setup_send<T: Copy + Into<u16>>(&mut self, cmd: Command<T>, dummy: u8) {
// Reset LCD control unit and Async Tx FIFO
self.lcd_cam
Expand Down Expand Up @@ -476,7 +509,7 @@ impl<'d, CH: DmaChannel, P> I8080<'d, CH, P> {
}
}

impl<'d, CH: DmaChannel, P> core::fmt::Debug for I8080<'d, CH, P> {
impl<'d, CH: DmaChannel, P, DM: Mode> core::fmt::Debug for I8080<'d, CH, P, DM> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("I8080").finish()
}
Expand Down
3 changes: 2 additions & 1 deletion esp-hal/src/lcd_cam/lcd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use crate::{peripheral::PeripheralRef, peripherals::LCD_CAM};

pub mod i8080;

pub struct Lcd<'d> {
pub struct Lcd<'d, DM: crate::Mode> {
pub(crate) lcd_cam: PeripheralRef<'d, LCD_CAM>,
pub(crate) _mode: core::marker::PhantomData<DM>,
}

#[derive(Debug, Clone, Copy, PartialEq, Default)]
Expand Down
Loading

0 comments on commit 69f8efd

Please sign in to comment.