I2C: add clock configuration#5606
Conversation
|
We need some tests to test that it works on some level with the different clock sources. |
|
/hil full --test i2c |
|
Triggered full HIL run for #5606. Run: https://github.com/esp-rs/esp-hal/actions/runs/26495704750 Status update: ❌ HIL (full) run failed (conclusion: failure). |
|
If we're doing anything, can we do this through the clock tree system? |
| pub(super) fn clock_instance(&self) -> crate::soc::clocks::I2cInstance { | ||
| use crate::soc::clocks::I2cInstance; | ||
| #[cfg(soc_has_i2c1)] | ||
| if self.id == 1 { | ||
| return I2cInstance::I2c1; | ||
| } | ||
| I2cInstance::I2c0 | ||
| } | ||
| } |
There was a problem hiding this comment.
This should be part of Info
| clock_instance: { | ||
| cfg_if::cfg_if! { | ||
| if #[cfg(soc_has_i2c1)] { | ||
| match $id { | ||
| 0 => crate::soc::clocks::I2cInstance::I2c0, | ||
| _ => crate::soc::clocks::I2cInstance::I2c1, | ||
| } | ||
| } else { | ||
| crate::soc::clocks::I2cInstance::I2c0 | ||
| } | ||
| } | ||
| }, |
There was a problem hiding this comment.
| clock_instance: { | |
| cfg_if::cfg_if! { | |
| if #[cfg(soc_has_i2c1)] { | |
| match $id { | |
| 0 => crate::soc::clocks::I2cInstance::I2c0, | |
| _ => crate::soc::clocks::I2cInstance::I2c1, | |
| } | |
| } else { | |
| crate::soc::clocks::I2cInstance::I2c0 | |
| } | |
| } | |
| }, | |
| clock_instance: paste::paste! { crate::soc::clocks::I2cInstance::[<I2c $id>] }, |
I think this should be enough? But we can rename the clock tree instances to I2cExtN and use $peri directly, too
There was a problem hiding this comment.
Yeah, I decided to go for paste as you suggested, I tried to rename the clock tree instances and didn't like it, 1-liner paste is just way more elegant IMO
| cfg_if::cfg_if! { | ||
| if #[cfg(i2c_master_version = "3")] { | ||
| let config = I2cFunctionClockConfig::new(Default::default(), 0); | ||
| } else { | ||
| let config = I2cFunctionClockConfig::new(Default::default()); | ||
| } | ||
| } |
There was a problem hiding this comment.
I think we can do crazy stuff like:
| cfg_if::cfg_if! { | |
| if #[cfg(i2c_master_version = "3")] { | |
| let config = I2cFunctionClockConfig::new(Default::default(), 0); | |
| } else { | |
| let config = I2cFunctionClockConfig::new(Default::default()); | |
| } | |
| } | |
| let config = I2cFunctionClockConfig::new(Default::default(), #[cfg(i2c_master_version = "3")] 0); |
bugadani
left a comment
There was a problem hiding this comment.
I think the set_frequency functions could use some further cleanup but this does what I wanted.
* I2C: add clock configuration * Add test, add RefTick to V2 I2C * Use clock tree * use clocktree * Clock instance -> part of Info fmt * address review, simplify clock instance selection * Simplify cfg_if
closes #2601
Changelog
esp-hal
ClockSourceandConfig::with_clock_source