Skip to content

Some comments #1

Description

@japaric

Hey @etrombly. You asked for some feedback. Here are my thoughts:

  • First of all, it's really nice that you have taken to time to extend the original SVD to make the API safer. Great work!

  • I think that HAL traits should never include references to device specific register blocks otherwise they won't be able to be device agnostic and usable across different device families / vendors. This pretty much means that init doesn't belong in a trait as it's highly device dependent. Initialization would be the reponsability of the application writer. The rest of the application logic can use the HAL traits.

  • I can't comment on the clock code as I haven't run into the need of increasing the clock speed given that the scheduler is so fast and efficient. However, I do think that all API that deals with time should work with ticks rather than with units of time or frequency; that way their implementations can be device agnostic. For example, in your code you require a reference to &Rcc to get the system clock frequencies; at some point that &Rcc will leak into the signature of some API making less portable across devices. With ticks, the responsability of mapping seconds / Hz to ticks is up to the application which knows exactly what the clock frequencies are and thus can do the conversions (effetively) at compile time and without involving reads to registers.

  • The reason why I use a newtype around e.g. Tim6 instead of using a trait to add methods to Tim6 is that I hope that eventually we'll settle on some HAL traits and those would end up being in a crate that most crates in the ecosystem would depend on. In that case you would need the newtype because you can't implement a trait that you didn't defined for a type you didn't define so I'm getting use to the idea early on.

  • You can use the fact that Tim{2,3,4,5} all deref to tim2::RegisterBlock to reduce duplicated code. You could probably write something like this impl Timer for T where T: Deref<tim2::RegisterBlock> { .. } once and the implementation would work for all the timers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions