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

Needs a TICK_RATE or similar way to figure out the frequency #1

Open
riskable opened this issue Apr 22, 2022 · 3 comments
Open

Needs a TICK_RATE or similar way to figure out the frequency #1

riskable opened this issue Apr 22, 2022 · 3 comments

Comments

@riskable
Copy link

Was trying to implement the infrared crate's MultiReceiver (https://docs.rs/infrared/0.13.0/infrared/receiver/struct.MultiReceiver.html) which requires the frequency of the monotonic timer you're using with it. Except there's no way to tell the tick rate/frequency when using rp2040-monotonic: It doesn't provide any constants or functions that would provide that info.

It was suggested by some guy 😁 in the RTIC Matrix chat that the monotonic timer implementation could provide this sort of info:

korken89
You do however have access to the monotonic's type, so if the monotonic implements it you can do MyMono::TICK_RATE
@korken89
Copy link
Owner

This is however not part of the Monotonic API.

It's probably better to implement a helper to extract the const generic from the type.

@riskable
Copy link
Author

I think having a little helper function inside impl Rp2040Monotonic that returns the tick rate would be totally fine. Put const TICK_RATE: usize = 1_000_000; at the top of lib.rs and then add something like:

pub fn tick_rate() -> usize {
    TICK_RATE
}

...just below new() in impl Rp2040Monotonic. Or alternatively, just put pub const TICK_RATE: usize = 1_000_000; at the top of lib.rs (and use it inside impl Monotonic for Rp2040Monotonic):

    type Instant = fugit::TimerInstantU64<{ TICK_RATE }>;
    type Duration = fugit::TimerDurationU64< { TICK_RATE }>;

Just having the tick rate be available via rp2040-monotonic::TICK_RATE would suffice, honestly.

@korken89
Copy link
Owner

Yes if you want to fix it specifically for this monotonic, however what I'm gesturing at is that it is not a portable solution. :)
For it to be portable, either across RTIC's monotonics or fugit, the fix should be there.

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

No branches or pull requests

2 participants