Skip to content

Commit ae72627

Browse files
committed
reduce diff with misc. reversions
1 parent 6543876 commit ae72627

File tree

2 files changed

+131
-110
lines changed

2 files changed

+131
-110
lines changed

embassy-stm32/src/i2c/mod.rs

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -436,55 +436,58 @@ impl<'d, IM: MasterMode> embedded_hal_async::i2c::I2c for I2c<'d, Async, IM> {
436436
}
437437
}
438438

439-
/// Operation framing configuration for I2C transactions.
439+
/// Frame type in I2C transaction.
440440
///
441-
/// This determines the I2C frame boundaries for each operation within a transaction,
442-
/// controlling the generation of start conditions (ST or SR), stop conditions (SP),
443-
/// and ACK/NACK behavior for read operations.
441+
/// This tells each method what kind of frame to use, to generate a (repeated) start condition (ST
442+
/// or SR), and/or a stop condition (SP). For read operations, this also controls whether to send an
443+
/// ACK or NACK after the last byte received.
444444
///
445-
/// For write operations, some framing configurations are functionally identical
446-
/// because they differ only in ACK/NACK treatment which is relevant only for reads:
445+
/// For write operations, the following options are identical because they differ only in the (N)ACK
446+
/// treatment relevant for read operations:
447447
///
448-
/// - `First` and `FirstAndNext` behave identically for writes
449-
/// - `Next` and `LastNoStop` behave identically for writes
448+
/// - `FirstFrame` and `FirstAndNextFrame` behave identically for writes
449+
/// - `NextFrame` and `LastFrameNoStop` behave identically for writes
450+
///
451+
/// Abbreviations used below:
450452
///
451-
/// **Framing Legend:**
452453
/// - `ST` = start condition
453-
/// - `SR` = repeated start condition
454+
/// - `SR` = repeated start condition
454455
/// - `SP` = stop condition
455-
/// - `ACK/NACK` = acknowledgment behavior for the final byte of read operations
456+
/// - `ACK`/`NACK` = last byte in read operation
456457
#[derive(Copy, Clone)]
457458
#[allow(dead_code)]
458-
enum OperationFraming {
459-
/// `[ST/SR]+[NACK]+[SP]` - First operation of its type in the transaction and also the final operation overall.
460-
FirstAndLast,
461-
/// `[ST/SR]+[NACK]` - First operation of its type in the transaction, final operation in a read sequence, but not the final operation overall.
462-
First,
463-
/// `[ST/SR]+[ACK]` - First operation of its type in the transaction, but neither the final operation overall nor the final operation in a read sequence.
464-
FirstAndNext,
465-
/// `[ACK]` - Continuation operation in a read sequence (neither first nor last).
466-
Next,
467-
/// `[NACK]+[SP]` - Final operation overall in the transaction, but not the first operation of its type.
468-
Last,
469-
/// `[NACK]` - Final operation in a read sequence, but not the final operation overall in the transaction.
470-
LastNoStop,
459+
enum FrameOptions {
460+
/// `[ST/SR]+[NACK]+[SP]` First frame (of this type) in transaction and also last frame overall.
461+
FirstAndLastFrame,
462+
/// `[ST/SR]+[NACK]` First frame of this type in transaction, last frame in a read operation but
463+
/// not the last frame overall.
464+
FirstFrame,
465+
/// `[ST/SR]+[ACK]` First frame of this type in transaction, neither last frame overall nor last
466+
/// frame in a read operation.
467+
FirstAndNextFrame,
468+
/// `[ACK]` Middle frame in a read operation (neither first nor last).
469+
NextFrame,
470+
/// `[NACK]+[SP]` Last frame overall in this transaction but not the first frame.
471+
LastFrame,
472+
/// `[NACK]` Last frame in a read operation but not last frame overall in this transaction.
473+
LastFrameNoStop,
471474
}
472475

473476
#[allow(dead_code)]
474-
impl OperationFraming {
477+
impl FrameOptions {
475478
/// Returns true if a start or repeated start condition should be generated before this operation.
476479
fn send_start(self) -> bool {
477480
match self {
478-
Self::FirstAndLast | Self::First | Self::FirstAndNext => true,
479-
Self::Next | Self::Last | Self::LastNoStop => false,
481+
Self::FirstAndLastFrame | Self::FirstFrame | Self::FirstAndNextFrame => true,
482+
Self::NextFrame | Self::LastFrame | Self::LastFrameNoStop => false,
480483
}
481484
}
482485

483486
/// Returns true if a stop condition should be generated after this operation.
484487
fn send_stop(self) -> bool {
485488
match self {
486-
Self::FirstAndLast | Self::Last => true,
487-
Self::First | Self::FirstAndNext | Self::Next | Self::LastNoStop => false,
489+
Self::FirstAndLastFrame | Self::LastFrame => true,
490+
Self::FirstFrame | Self::FirstAndNextFrame | Self::NextFrame | Self::LastFrameNoStop => false,
488491
}
489492
}
490493

@@ -494,16 +497,16 @@ impl OperationFraming {
494497
/// next transmission (or stop condition).
495498
fn send_nack(self) -> bool {
496499
match self {
497-
Self::FirstAndLast | Self::First | Self::Last | Self::LastNoStop => true,
498-
Self::FirstAndNext | Self::Next => false,
500+
Self::FirstAndLastFrame | Self::FirstFrame | Self::LastFrame | Self::LastFrameNoStop => true,
501+
Self::FirstAndNextFrame | Self::NextFrame => false,
499502
}
500503
}
501504
}
502505

503-
/// Analyzes I2C transaction operations and assigns appropriate framing to each.
506+
/// Analyzes I2C transaction operations and assigns appropriate frame to each.
504507
///
505508
/// This function processes a sequence of I2C operations and determines the correct
506-
/// framing configuration for each operation to ensure proper I2C protocol compliance.
509+
/// frame configuration for each operation to ensure proper I2C protocol compliance.
507510
/// It handles the complex logic of:
508511
///
509512
/// - Generating start conditions for the first operation of each type (read/write)
@@ -512,7 +515,7 @@ impl OperationFraming {
512515
/// - Ensuring proper bus handoff between different operation types
513516
///
514517
/// **Transaction Contract Compliance:**
515-
/// The framing assignments ensure compliance with the embedded-hal I2C transaction contract,
518+
/// The frame assignments ensure compliance with the embedded-hal I2C transaction contract,
516519
/// where consecutive operations of the same type are logically merged while maintaining
517520
/// proper protocol boundaries.
518521
///
@@ -524,12 +527,12 @@ impl OperationFraming {
524527
/// * `operations` - Mutable slice of I2C operations from embedded-hal
525528
///
526529
/// # Returns
527-
/// An iterator over (operation, framing) pairs, or an error if the transaction is invalid
530+
/// An iterator over (operation, frame) pairs, or an error if the transaction is invalid
528531
///
529532
#[allow(dead_code)]
530-
fn assign_operation_framing<'a, 'b: 'a>(
533+
fn operation_frames<'a, 'b: 'a>(
531534
operations: &'a mut [embedded_hal_1::i2c::Operation<'b>],
532-
) -> Result<impl IntoIterator<Item = (&'a mut embedded_hal_1::i2c::Operation<'b>, OperationFraming)>, Error> {
535+
) -> Result<impl IntoIterator<Item = (&'a mut embedded_hal_1::i2c::Operation<'b>, FrameOptions)>, Error> {
533536
use embedded_hal_1::i2c::Operation::{Read, Write};
534537

535538
// Validate that no read operations have empty buffers before starting the transaction.
@@ -555,29 +558,29 @@ fn assign_operation_framing<'a, 'b: 'a>(
555558
let is_first_of_type = next_first_operation;
556559
let next_op = operations.peek();
557560

558-
// Compute the appropriate framing based on three key properties:
561+
// Compute the appropriate frame based on three key properties:
559562
//
560563
// 1. **Start Condition**: Generate (repeated) start for first operation of each type
561564
// 2. **Stop Condition**: Generate stop for the final operation in the entire transaction
562565
// 3. **ACK/NACK for Reads**: For read operations, send ACK if more reads follow in the
563566
// sequence, or NACK for the final read in a sequence (before write or transaction end)
564567
//
565-
// The third property is checked for all operations since the resulting framing
568+
// The third property is checked for all operations since the resulting frame
566569
// configurations are identical for write operations regardless of ACK/NACK treatment.
567-
let framing = match (is_first_of_type, next_op) {
570+
let frame = match (is_first_of_type, next_op) {
568571
// First operation of type, and it's also the final operation overall
569-
(true, None) => OperationFraming::FirstAndLast,
572+
(true, None) => FrameOptions::FirstAndLastFrame,
570573
// First operation of type, next operation is also a read (continue read sequence)
571-
(true, Some(Read(_))) => OperationFraming::FirstAndNext,
574+
(true, Some(Read(_))) => FrameOptions::FirstAndNextFrame,
572575
// First operation of type, next operation is write (end current sequence)
573-
(true, Some(Write(_))) => OperationFraming::First,
576+
(true, Some(Write(_))) => FrameOptions::FirstFrame,
574577

575578
// Continuation operation, and it's the final operation overall
576-
(false, None) => OperationFraming::Last,
579+
(false, None) => FrameOptions::LastFrame,
577580
// Continuation operation, next operation is also a read (continue read sequence)
578-
(false, Some(Read(_))) => OperationFraming::Next,
581+
(false, Some(Read(_))) => FrameOptions::NextFrame,
579582
// Continuation operation, next operation is write (end current sequence, no stop)
580-
(false, Some(Write(_))) => OperationFraming::LastNoStop,
583+
(false, Some(Write(_))) => FrameOptions::LastFrameNoStop,
581584
};
582585

583586
// Pre-calculate whether the next operation will be the first of its type.
@@ -592,6 +595,6 @@ fn assign_operation_framing<'a, 'b: 'a>(
592595
(Read(_), Some(Read(_))) | (Write(_), Some(Write(_))) => false,
593596
};
594597

595-
Some((current_op, framing))
598+
Some((current_op, frame))
596599
}))
597600
}

0 commit comments

Comments
 (0)