avr-rust / ruduino

Reusable components for the Arduino Uno.
Apache License 2.0
704 stars 50 forks source link

Timer configuration for interruptless mode #50

Open gergoerdi opened 1 year ago

gergoerdi commented 1 year ago

I'd like to configure a timer for CTC mode with polling instead of interrupts. Unfortunately, this is not possible at the moment because setting the comparator target is coupled with turning on interrupts:

    pub fn configure(self) {
        T::ControlA::write(self.a);
        T::ControlB::write(self.b);
        T::ControlC::write(self.c);

        // Reset counter to zero
        T::Counter::write(0u16);

        if let Some(v) = self.output_compare_1 {
            // Set the match
            T::CompareA::write(v);

            // Enable compare interrupt
            T::InterruptMask::set(T::OCIEA);
        }
    }

I think these should be exposed as two orthogonal features.