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

i2c: Reimplement with new HAL API design #155

Merged
merged 4 commits into from
Mar 3, 2021
Merged

i2c: Reimplement with new HAL API design #155

merged 4 commits into from
Mar 3, 2021

Conversation

Rahix
Copy link
Owner

@Rahix Rahix commented Mar 3, 2021

Pull off the same design that the USART module is using now in the I2C HAL as well. The key points are:

  • avr-hal-generic defines the user facing API type (e.g. I2c<> or Usart<>). This type implements embedded-hal traits and provides all API which we want to expose.
  • There is a trait defining the lower-level API, called I2cOps (or UsartOps). This trait is "consumed" by the I2c<> type to access the peripheral.
    • The methods of this trait have the prefix raw_ and are not meant to be used directly by the user.
  • A macro exists which implements this trait for a peripheral. E.g. impl_i2c_twi!{} in this case.
  • Because the HAL crate neither "owns" the I2cOps trait nor the peripheral type (it comes from avr-device), we run into the "orphan rule". To "fix" this, the I2cOps trait and I2c<> type have a type-parameter called H which is substituted by a local type from e.g. atmega-hal.

Cc: @explicite

Pull off the same design that the USART module is using now in the I2C
HAL as well.
@Rahix Rahix added hal-impl hal-api API design for the different components of avr-hal hal-generic Related to MCU generic parts of avr-hal labels Mar 3, 2021
@Rahix Rahix added this to the New APIs milestone Mar 3, 2021
Use the newly redesigned I2C HAL from avr-hal-generic and instantiate
the driver for each TWI peripheral of all supported MCUs.
@Rahix Rahix merged commit 22ce19a into next Mar 3, 2021
@Rahix Rahix deleted the new-i2c branch March 3, 2021 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hal-api API design for the different components of avr-hal hal-generic Related to MCU generic parts of avr-hal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant