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

Implement embedded-hal 1.0 I2c trait for Twi and Twim #440

Merged
merged 7 commits into from
Apr 16, 2024
Merged

Implement embedded-hal 1.0 I2c trait for Twi and Twim #440

merged 7 commits into from
Apr 16, 2024

Conversation

qwandor
Copy link
Member

@qwandor qwandor commented Apr 12, 2024

The Twi implementation is untested as I don't have any nrf51 devices.

Unfortunately the Twim implementation isn't working correctly. Adjacent operations of the same type are specified to be carried out without an SR and SAD+R/W, which is why I avoid setting the lastrx_stop or lasttx_stop shortcut in that case, but when testing this I've found that trying to have two read operations in a row results in an overrun error for some reason.

Copy link

@9names 9names left a comment

Choose a reason for hiding this comment

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

Don't have time for a couple of days to test this out again, but logic looks good.

nrf-hal-common/src/twi.rs Show resolved Hide resolved
@@ -392,6 +397,185 @@ where
},
)
}

fn write_part(&mut self, buffer: &[u8], final_operation: bool) -> Result<(), Error> {
unsafe { self.set_tx_buffer(buffer)? };
Copy link

Choose a reason for hiding this comment

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

No fence required here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not entirely sure. Added some more fences to be on the safe side.

@qwandor
Copy link
Member Author

qwandor commented Apr 16, 2024

Don't have time for a couple of days to test this out again, but logic looks good.

I tested the Twim implementation on a Microbit v2 with various combinations of writes and reads (including consecutive reads), and the Twi implementation hasn't changed since you tested it so I think this should be fine.

@qwandor qwandor merged commit ead3042 into master Apr 16, 2024
5 checks passed
@qwandor qwandor deleted the i2c branch April 16, 2024 14:27
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.

None yet

2 participants