diff options
| author | Sebastian Goll <[email protected]> | 2024-03-27 10:42:38 +0100 |
|---|---|---|
| committer | Sebastian Goll <[email protected]> | 2024-03-27 10:42:38 +0100 |
| commit | bb5fcce0a095431de063aedd6eb12161d94805db (patch) | |
| tree | 17e3926ea18fa601edc22a6ca24deb3a91c241ab | |
| parent | b52e9a60eb929facd21eab2d524781e127f3e04b (diff) | |
Use named imports within function to make code easier to read
| -rw-r--r-- | embassy-stm32/src/i2c/mod.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index d4d4aec5d..a46061d54 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs | |||
| @@ -411,7 +411,7 @@ impl FrameOptions { | |||
| 411 | fn operation_frames<'a, 'b: 'a>( | 411 | fn operation_frames<'a, 'b: 'a>( |
| 412 | operations: &'a mut [embedded_hal_1::i2c::Operation<'b>], | 412 | operations: &'a mut [embedded_hal_1::i2c::Operation<'b>], |
| 413 | ) -> Result<impl IntoIterator<Item = (&'a mut embedded_hal_1::i2c::Operation<'b>, FrameOptions)>, Error> { | 413 | ) -> Result<impl IntoIterator<Item = (&'a mut embedded_hal_1::i2c::Operation<'b>, FrameOptions)>, Error> { |
| 414 | use embedded_hal_1::i2c::Operation; | 414 | use embedded_hal_1::i2c::Operation::{Read, Write}; |
| 415 | 415 | ||
| 416 | // Check empty read buffer before starting transaction. Otherwise, we would risk halting with an | 416 | // Check empty read buffer before starting transaction. Otherwise, we would risk halting with an |
| 417 | // error in the middle of the transaction. | 417 | // error in the middle of the transaction. |
| @@ -420,8 +420,8 @@ fn operation_frames<'a, 'b: 'a>( | |||
| 420 | // at least one byte remains in the final (merged) read operation, but that makes the logic more | 420 | // at least one byte remains in the final (merged) read operation, but that makes the logic more |
| 421 | // complicated and error-prone. | 421 | // complicated and error-prone. |
| 422 | if operations.iter().any(|op| match op { | 422 | if operations.iter().any(|op| match op { |
| 423 | Operation::Read(read) => read.is_empty(), | 423 | Read(read) => read.is_empty(), |
| 424 | Operation::Write(_) => false, | 424 | Write(_) => false, |
| 425 | }) { | 425 | }) { |
| 426 | return Err(Error::Overrun); | 426 | return Err(Error::Overrun); |
| 427 | } | 427 | } |
| @@ -452,12 +452,12 @@ fn operation_frames<'a, 'b: 'a>( | |||
| 452 | // because the resulting frame options are identical for write operations. | 452 | // because the resulting frame options are identical for write operations. |
| 453 | let frame = match (first_frame, next_op) { | 453 | let frame = match (first_frame, next_op) { |
| 454 | (true, None) => FrameOptions::FirstAndLastFrame, | 454 | (true, None) => FrameOptions::FirstAndLastFrame, |
| 455 | (true, Some(Operation::Read(_))) => FrameOptions::FirstAndNextFrame, | 455 | (true, Some(Read(_))) => FrameOptions::FirstAndNextFrame, |
| 456 | (true, Some(Operation::Write(_))) => FrameOptions::FirstFrame, | 456 | (true, Some(Write(_))) => FrameOptions::FirstFrame, |
| 457 | // | 457 | // |
| 458 | (false, None) => FrameOptions::LastFrame, | 458 | (false, None) => FrameOptions::LastFrame, |
| 459 | (false, Some(Operation::Read(_))) => FrameOptions::NextFrame, | 459 | (false, Some(Read(_))) => FrameOptions::NextFrame, |
| 460 | (false, Some(Operation::Write(_))) => FrameOptions::LastFrameNoStop, | 460 | (false, Some(Write(_))) => FrameOptions::LastFrameNoStop, |
| 461 | }; | 461 | }; |
| 462 | 462 | ||
| 463 | // Pre-calculate if `next_op` is the first operation of its type. We do this here and not at | 463 | // Pre-calculate if `next_op` is the first operation of its type. We do this here and not at |
| @@ -465,8 +465,8 @@ fn operation_frames<'a, 'b: 'a>( | |||
| 465 | // anymore in the next iteration. | 465 | // anymore in the next iteration. |
| 466 | next_first_frame = match (&op, next_op) { | 466 | next_first_frame = match (&op, next_op) { |
| 467 | (_, None) => false, | 467 | (_, None) => false, |
| 468 | (Operation::Read(_), Some(Operation::Write(_))) | (Operation::Write(_), Some(Operation::Read(_))) => true, | 468 | (Read(_), Some(Write(_))) | (Write(_), Some(Read(_))) => true, |
| 469 | (Operation::Read(_), Some(Operation::Read(_))) | (Operation::Write(_), Some(Operation::Write(_))) => false, | 469 | (Read(_), Some(Read(_))) | (Write(_), Some(Write(_))) => false, |
| 470 | }; | 470 | }; |
| 471 | 471 | ||
| 472 | Some((op, frame)) | 472 | Some((op, frame)) |
