Skip to content

Commit

Permalink
Remove Dma[Rx|Tx]Buffer::length
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Fischer committed Nov 22, 2024
1 parent 9c1d99d commit ba39ac9
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 96 deletions.
2 changes: 2 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- DMA channel objects now implement `Peripheral` (#2526)
- DMA channel objects are no longer wrapped in `Channel`. The `Channel` drivers are now managed by DMA enabled peripheral drivers. (#2526)
- The `Dpi` driver and `DpiTransfer` now have a `Mode` type parameter. The driver's asyncness is determined by the asyncness of the `Lcd` used to create it. (#2526)
- `SpiDma` transfers now explicitly take a length along with the DMA buffer object (#0000)

### Fixed

### Removed

- The `configure` and `configure_for_async` DMA channel functions has been removed (#2403)
- The DMA channel objects no longer have `tx` and `rx` fields. (#2526)
- Remove Dma[Rx|Tx]Buffer::length (#0000)

## [0.22.0] - 2024-11-20

Expand Down
21 changes: 21 additions & 0 deletions esp-hal/MIGRATING-0.22.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,24 @@
-.with_dma(dma_channel.configure(false, DmaPriority::Priority1));
+.with_dma(dma_channel);
```

## SpiDma now requires you specify the transfer length explicitly

```diff
dma_tx_buf.set_length(5 /* or greater */);
- spi_dma.write(dma_tx_buf);
+ spi_dma.write(5, dma_tx_buf);
```

```diff
dma_rx_buf.set_length(5 /* or greater */);
- spi_dma.read(dma_rx_buf);
+ spi_dma.read(5, dma_rx_buf);
```

```diff
dma_rx_buf.set_length(5 /* or greater */);
dma_tx_buf.set_length(5 /* or greater */);
- spi_dma.transfer(dma_rx_buf, dma_tx_buf);
+ spi_dma.transfer(5, dma_rx_buf, 5, dma_tx_buf);
```
45 changes: 0 additions & 45 deletions esp-hal/src/dma/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ pub unsafe trait DmaTxBuffer {

/// This is called after the DMA is done using the buffer.
fn from_view(view: Self::View) -> Self;

/// Returns the maximum number of bytes that would be transmitted by this
/// buffer.
///
/// This is a convenience hint for SPI. Most peripherals don't care how long
/// the transfer is.
fn length(&self) -> usize;
}

/// [DmaRxBuffer] is a DMA descriptor + memory combo that can be used for
Expand Down Expand Up @@ -156,12 +149,6 @@ pub unsafe trait DmaRxBuffer {

/// This is called after the DMA is done using the buffer.
fn from_view(view: Self::View) -> Self;

/// Returns the maximum number of bytes that can be received by this buffer.
///
/// This is a convenience hint for SPI. Most peripherals don't care how long
/// the transfer is.
fn length(&self) -> usize;
}

/// An in-progress view into [DmaRxBuf]/[DmaTxBuf].
Expand Down Expand Up @@ -387,10 +374,6 @@ unsafe impl DmaTxBuffer for DmaTxBuf {
fn from_view(view: Self::View) -> Self {
view.0
}

fn length(&self) -> usize {
self.len()
}
}

/// DMA receive buffer
Expand Down Expand Up @@ -543,10 +526,6 @@ unsafe impl DmaRxBuffer for DmaRxBuf {
fn from_view(view: Self::View) -> Self {
view.0
}

fn length(&self) -> usize {
self.len()
}
}

/// DMA transmit and receive buffer.
Expand Down Expand Up @@ -675,10 +654,6 @@ unsafe impl DmaTxBuffer for DmaRxTxBuf {
fn from_view(view: Self::View) -> Self {
view.0
}

fn length(&self) -> usize {
self.len()
}
}

unsafe impl DmaRxBuffer for DmaRxTxBuf {
Expand Down Expand Up @@ -711,10 +686,6 @@ unsafe impl DmaRxBuffer for DmaRxTxBuf {
fn from_view(view: Self::View) -> Self {
view.0
}

fn length(&self) -> usize {
self.len()
}
}

/// DMA Streaming Receive Buffer.
Expand Down Expand Up @@ -865,10 +836,6 @@ unsafe impl DmaRxBuffer for DmaRxStreamBuf {
fn from_view(view: Self::View) -> Self {
view.buf
}

fn length(&self) -> usize {
panic!("DmaCircularBuf doesn't have a length")
}
}

/// A view into a [DmaRxStreamBuf]
Expand Down Expand Up @@ -1072,10 +1039,6 @@ unsafe impl DmaTxBuffer for EmptyBuf {
fn from_view(view: Self::View) -> Self {
view
}

fn length(&self) -> usize {
0
}
}

unsafe impl DmaRxBuffer for EmptyBuf {
Expand Down Expand Up @@ -1103,10 +1066,6 @@ unsafe impl DmaRxBuffer for EmptyBuf {
fn from_view(view: Self::View) -> Self {
view
}

fn length(&self) -> usize {
0
}
}

/// DMA Loop Buffer
Expand Down Expand Up @@ -1180,10 +1139,6 @@ unsafe impl DmaTxBuffer for DmaLoopBuf {
fn from_view(view: Self::View) -> Self {
view
}

fn length(&self) -> usize {
panic!("DmaLoopBuf does not have a length")
}
}

impl Deref for DmaLoopBuf {
Expand Down
Loading

0 comments on commit ba39ac9

Please sign in to comment.