Skip to content

Conversation

Iooon
Copy link
Contributor

@Iooon Iooon commented Aug 29, 2025

Implement the i2c target interface from https://github.com/embassy-rs/embassy/tree/main/embassy-rp for mspm0.
In the interface we define a listen function that is used to receive the commands from the i2c controller asynchronously so that the user can handle them accordingly.
Currently the implementation heavily favors async because of the easier implementation with interrupts.

The example was tested on the dev. board: MSPM0G3507
Sadly my MSPM0L1306 board is broken at the moment, but the example should work exactly the same. So if needed I can add the example to the L1306 , but someone else would need to test it.

Done,
/// Transaction Incomplete, controller trying to read more bytes than were provided
NeedMoreBytes,
/// Transaction Complere, but controller stopped reading bytes before we ran out
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Transaction Complere, but controller stopped reading bytes before we ran out
/// Transaction complete, but controller stopped reading bytes before we ran out

/// Transaction completed successfully. The controller either NACKed the last byte
/// or sent a STOP condition.
Done,
/// Transaction Incomplete, controller trying to read more bytes than were provided
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Transaction Incomplete, controller trying to read more bytes than were provided
/// Transaction incomplete, controller trying to read more bytes than were provided

pub bus_speed: BusSpeed,

/// 7-bit Target Address
pub target_addr: u8,
Copy link
Member

Choose a reason for hiding this comment

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

Do the other hals add target_addr as a field for target mode? Or do the other hals make a new config type?

Comment on lines +73 to +87
impl From<ClockDiv> for vals::Ratio {
fn from(value: ClockDiv) -> Self {
match value {
ClockDiv::DivBy1 => Self::DIV_BY_1,
ClockDiv::DivBy2 => Self::DIV_BY_2,
ClockDiv::DivBy3 => Self::DIV_BY_3,
ClockDiv::DivBy4 => Self::DIV_BY_4,
ClockDiv::DivBy5 => Self::DIV_BY_5,
ClockDiv::DivBy6 => Self::DIV_BY_6,
ClockDiv::DivBy7 => Self::DIV_BY_7,
ClockDiv::DivBy8 => Self::DIV_BY_8,
}
}
}

Copy link
Member

Choose a reason for hiding this comment

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

I think we did this as an associated function rather than a trait impl to avoid making From<ClockDiv> for vals::Ratio public API. Probably should revert this part.

let sda = p.PB3;

let mut config = i2c::Config::default();
config.general_call = true;
Copy link
Member

Choose a reason for hiding this comment

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

I think we should explicitly set the target address here, even if redundant for the sake of making the examples helpful.

@charlesbmi
Copy link

Just dropping in to say thanks for writing this; since there was a comment about not yet testing on MSPM0L1306, which I'm using, I tried it out on an LP-MSPM0L1306 and it worked after making basic pin-revisions:

  • Peripheral: I2C1 → I2C0
  • Pins: SCL PB2 → PA1, SDA PB3 → PA0
  • Interrupt: I2C1 => InterruptHandler → I2C0 => InterruptHandler

Posting screenshot of aardvark + logs in case it's helpful
image

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.

3 participants