Skip to content

Replace raw slice with dma_accessible::DmaBuffer#1

Open
Dicklessgreat wants to merge 6 commits intomainfrom
dma-accessible
Open

Replace raw slice with dma_accessible::DmaBuffer#1
Dicklessgreat wants to merge 6 commits intomainfrom
dma-accessible

Conversation

@Dicklessgreat
Copy link

@Dicklessgreat Dicklessgreat commented Aug 29, 2025

This pull request introduces support for DMA-accessible SPI communication buffers by integrating the dma-accessible crate and refactoring the Fhx struct and related methods.
DmaBuffer struct is just a wrapper type for the slice, but it ensures that it uses DMA-accessible memory region(unfortunately, it does not check safety at compile-time, but just check and panics if it is invalid at run-time).

DMA integration and buffer handling:

  • Added the dma-accessible crate as a dependency in Cargo.toml to enable DMA-safe buffer management.
  • Refactored the Fhx struct to use a generic DmaAc type parameter and replaced the SPI transmit buffer with a dma_accessible::DmaBuffer, ensuring the buffer is DMA-accessible. [1] [2]
  • Updated the Fhx::new constructor to wrap the transmit buffer in a DmaBuffer and require a 'static mut reference for DMA compatibility. [1] [2]
  • Modified the write method to use the new buffer API, copying data into the DMA buffer and passing the correct slice type to the SPI bus.

Note
Not yet tested on real hardware because I don't have one, but it has been logically tested.

@Dicklessgreat
Copy link
Author

maybe const generics is better because it can preserve tx_buffer's length?
daisy-embassy/dma-accessible#1

@Dicklessgreat Dicklessgreat marked this pull request as ready for review August 30, 2025 06:04
@Dicklessgreat Dicklessgreat requested a review from abey79 August 30, 2025 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant