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 to i2c master and slave to handle large data buffers #322

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

akshat2112
Copy link
Contributor

Since DMA only handles a maximum of 1024 bytes of data, i2c master and slave need to handle larger buffers by dividing them into chunks of smaller buffers.
The example also demonstrates how to handle both read and write operations for a large buffer.

Closes #255

@akshat2112 akshat2112 self-assigned this Feb 21, 2025
@akshat2112 akshat2112 added the enhancement New feature or request label Feb 21, 2025
@akshat2112 akshat2112 added this to the Code Complete milestone Feb 21, 2025
@akshat2112 akshat2112 force-pushed the i2c-expansion-slave branch 3 times, most recently from 6656153 to 62d4d17 Compare March 3, 2025 18:37
@akshat2112 akshat2112 force-pushed the i2c-expansion-slave branch from a4eb019 to 7d8ce43 Compare March 6, 2025 06:38
@akshat2112 akshat2112 requested a review from Copilot March 6, 2025 06:41
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR updates the I2C master and slave implementations to support large DMA transfers by dividing data buffers into smaller, DMA-safe chunks. The changes include new chunking functions in both master and slave modules, an added constant for the maximum chunk size, and related updates to the Cargo configuration.

  • Added write_chunks and read_chunks functions to I2C master to split large transfers.
  • Updated the I2C slave’s response functions to process data in chunks.
  • Introduced the MAX_I2C_CHUNK_SIZE constant and updated the Cargo config with a new executor arena size.

Reviewed Changes

File Description
src/i2c/master.rs Introduces chunked write/read functions and updates I2C traits.
src/i2c/slave.rs Implements chunking in slave response functions for write/read.
examples/rt685s-evk/.cargo/config.toml Updates Cargo config with linker args and executor arena size.
src/i2c/mod.rs Adds MAX_I2C_CHUNK_SIZE constant for DMA transfer size.

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

@@ -761,6 +761,30 @@ impl<'a> I2cMaster<'a, Async> {
)
.await
}

async fn write_chunks(&mut self, address: u16, write: &[u8]) -> Result<()> {
Copy link
Preview

Copilot AI Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] In write_chunks, when the write buffer is empty the function calls write_no_stop but does not return immediately. To improve clarity and control flow, consider returning immediately after handling the empty buffer.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -502,6 +502,24 @@ impl I2cSlave<'_, Async> {

/// Respond to write command from master
pub async fn respond_to_write(&mut self, buf: &mut [u8]) -> Result<Response> {
let mut xfer_count = 0;
Copy link
Preview

Copilot AI Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] In respond_to_write, the for loop returns as soon as a chunk yields a 'Complete' response, which may unintentionally skip processing remaining chunks. Review this behavior to ensure it meets the intended protocol for multi-chunk transactions.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@akshat2112 akshat2112 marked this pull request as ready for review March 6, 2025 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

i2c transaction needs to handle DMA transfer size large than 1024
3 participants