-
Notifications
You must be signed in to change notification settings - Fork 39
Conversation
It seems natural to me. Do you have any other idea?
This version is only more functionality without breaking change. Thus I vote for that for now, and possibly doing something more complex in a future incompatible version. An expanded solution might be having a
No, it will not be better as the developer can't handle the failing case. Panicking is great when you want to provide a simpler API, but you should always have a non panicking version. But maybe getting the USB clock can return an option? |
Another possibility for a clock source setting API could be something like a
That might more clearly indicate that you're choosing between two things instead of just enabling something. If It's more wordy though, and requires another "use". If there were more than two oscillators available an enum would definitely be better in my opinion. The USB clock has only one valid frequency, so I don't think using an option for it would be that useful. |
No, I mean you have a token in pub struct UsbClock { _0: () }
pub struct Clocks {
// ...
pub usb_clock: Option<UsbClock>,
}
fn usb_driver(_: UsbClock) -> UsbDriver {
// ...
} But it means |
The actual solution is more ergonomic in most case I think. But the 2 solutions can be present at the same time. Maybe renaming the setter |
That could be better. If it's OK to some extra related cleanup I could also add documentation comments to all the methods which makes it even easier to tell what they do, and change them all to use |
+1 for doc comments. |
@japaric any feedback? That's really an important feature to use the blue pill at full speed. |
src/rcc.rs
Outdated
hclk: Option<u32>, | ||
pclk1: Option<u32>, | ||
pclk2: Option<u32>, | ||
sysclk: Option<u32>, | ||
} | ||
|
||
impl CFGR { | ||
pub fn hse<F>(mut self, freq: F) -> Self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you
fn use_hse<H: Into<Hertz>>(self, hse_freq: H) -> Self
and add doc comments? I will then be OK to merge if @therealprof have no objection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, looks good (I presume "mut self"?), it'll have to wait for a while though as I only have my phone with me while traveling for a couple of weeks. Thanks for taking a look!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, mut self. No hurry, take your time 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally got around to this! Does it look good to you?
src/rcc.rs
Outdated
} | ||
|
||
// set prescalers and clock source | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better? :)
02825f1
to
03a90bc
Compare
03a90bc
to
0dd491d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Here's an initial idea for supporting the HSE clock input (which is needed for a within-spec USB clock) as well as configuring the USB clock (or more like validating, as there's only one bit to configure, and it's only valid when the other clocks are configured correctly).
I've manually tested this on hardware using the clock output function and a scope with various clock combinations and it seems to work in practice.
I'm not quite sure about the API though. Here's potential issues I'd like to get feedback on:
Result
? (That'll introduce warnings everywhere though, so I'd consider it a breaking change).require_usbclk()
as there's no frequency to configure) and the method paniced if the rest of the clock configuration wasn't correct? Currently it just returns ausbclk_valid
value in theClocks
struct that the user or a USB HAL could check with asserts.I also changed the calculation for the PLL multiplier a bit in order to calculate it correctly with HSE, which may have changed behavior in cases where there was rounding involved. I'm not 100% sure how the original math worked.
Additionally this fixes an off-by-one error in the HCLK/PCLK2 frequency asserts, which only manifested when I added HSE support as the maximum frequency can only be reached with it.