Skip to content

I2c unify #339

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

Merged
merged 1 commit into from
Jan 18, 2022
Merged

I2c unify #339

merged 1 commit into from
Jan 18, 2022

Conversation

Dirbaio
Copy link
Member

@Dirbaio Dirbaio commented Dec 20, 2021

Depends on #336

Equivalent of #323 but for I2c.

I think for i2c unifying everything in a single trait makes the most sense. The i2c bus is specified to be bidirectional, I believe no hardware out there can "only write" or "only read" (and writing requires reading ACK bits anyway!).

@Dirbaio Dirbaio requested a review from a team as a code owner December 20, 2021 23:01
@rust-highfive
Copy link

r? @eldruin

(rust-highfive has picked a reviewer for you, use r? to override)

Copy link
Member

@eldruin eldruin left a comment

Choose a reason for hiding this comment

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

Seems like a good idea, although the trait has a lot of methods now.
Are we sure it is always possible to implement the iterator methods?
Also, for consistency, if we rename the exec method in SPI batch we should do so here as well.

@Dirbaio
Copy link
Member Author

Dirbaio commented Dec 21, 2021

Are we sure it is always possible to implement the iterator methods?

For stm32, rp2040 yes.

For nRF it'd need to drain the iterator into a temp buffer then DMA that out. However there are other cases that nRF has to do similar copies to temp bufs (for example, it can't DMA out of flash, so if TXing from flash it has to be copied to RAM) so I don't think it's that bad.

If the iterator methods were separate traits, we'd have the usual problem: some HALs wouldn't impl them, so driver authors wouldn't use them since they want their driver to work everywhere. IMO they should be either in the main trait, or removed.

Also, for consistency, if we rename the exec method in SPI batch we should do so here as well.

Agreed they should be consistent! I'm not 100% happy with the batch name though. I liked "Transactional", it emphasizes it's a single transaction, not equivalent to just doing multiple read/write calls. Perhaps transaction? exec_transaction?

@burrbull
Copy link
Member

For stm32

Yes for writing. Probably not for reading.

For correct ending of read operation we need to know length of remaining piece.

https://github.com/stm32-rs/stm32f1xx-hal/blob/e790b27663c03362b7dfac924f55b02d00869c08/src/i2c/blocking.rs#L291

@Dirbaio
Copy link
Member Author

Dirbaio commented Dec 21, 2021

There's no iterator-based reading.

@burrbull
Copy link
Member

For this reason it is not there. Same as Transactional.

@Dirbaio
Copy link
Member Author

Dirbaio commented Jan 2, 2022

@burrbull not sure if I understand. The trait proposed in this PR has a write_iter, but no read_iter, so AFAIK all the methods should be implementable for stm32s. Are you saying a method is not implementable, or just "if there was a read_iter method, it wouldn't be"?

@burrbull
Copy link
Member

burrbull commented Jan 2, 2022

The trait proposed in this PR has a write_iter, but no read_iter

Oh, sorry. I was sure I'd seen it.

@Dirbaio Dirbaio force-pushed the i2c-unify branch 2 times, most recently from c71675b to dd27ab5 Compare January 11, 2022 22:15
@Dirbaio
Copy link
Member Author

Dirbaio commented Jan 11, 2022

Renamed exec to transaction, naming is now consistent with #323

Copy link
Member

@eldruin eldruin left a comment

Choose a reason for hiding this comment

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

Great work, thank you!
bors r+

@bors
Copy link
Contributor

bors bot commented Jan 18, 2022

👎 Rejected by too few approved reviews

Copy link
Member

@eldruin eldruin left a comment

Choose a reason for hiding this comment

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

bors r+

@bors bors bot merged commit 599f8bd into rust-embedded:master Jan 18, 2022
bors bot added a commit that referenced this pull request Jan 18, 2022
348: async: add i2c r=eldruin a=Dirbaio

This mirrors the blocking i2c trait (including the changes proposed in #339 ), except the following:

- Removed all `iter` methods since they don't play well with DMA.

Co-authored-by: Dario Nieuwenhuis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Review is incomplete T-hal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants