Replies: 1 comment
-
With the bare
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The issue that I'm currently running into is how to best go about modifying a register's value from the triggering of an interrupt service routine. For example, say there's a button that, when pressed, is to change the compare value of a timer. There's two important aspects of this (at least for the atmega328p):
Both of these would need to be done within the ISR for the button's pin.
Coming from C, I would just directly read, and modify the requisite registers within the ISR, while not thinking too much of it (taking care to avoid data races), but this is proving to be a little more involved in Rust. For example:
atmega_hal::Peripherals::steal()
, and I thought to maybe just steal the peripherals within the ISR; however, I don't quite understand if this is the correct way to use it, and it also feels rather messy and bloated.static mut
feels like possibly the worst solution, and arguably very against the philosophy of Rust, and would result inunsafe
being used everywhere, which, imo, is extremely messy.avr_device::interrupt::Mutex
to grab the peripherals globally along with Critical Sections ofavr_device::interrupt::free
, but I've been unable to find good documentation for this to use it properly, and I have yet to be able to resolve it nicely with the borrow checker. And, regardless, it feels little messy to have these Critical Sections strewn about anytime a register is to be modified.So I'm wondering how interrupts are advised to be, or are commonly done in this context. I've yet to come across any examples of ISR's directly modifying register values from avr-hal. I've seen a handful for other embedded targets, but I haven't been able to successfully port their practices over.
Beta Was this translation helpful? Give feedback.
All reactions