esp-idf-hal icon indicating copy to clipboard operation
esp-idf-hal copied to clipboard

Set GPIO level before setting output mode.

Open lynaghk opened this issue 3 years ago • 0 comments

Re: #151's commit 058a0a0, instead of removing the docstrings as in this commit I'm also open to submitting a patch to support the described use case of setting an output pin's level before driving the output. As far as I can tell, the current typestate design makes this impossible to do.

One solution could be to add additional arities for the conversion functions, e.g.,

    pub fn into_output_with_level(self, level: Level) -> Result<PinDriver<'d, T, Output>, EspError>
    where
        T: OutputPin,
    {
        self.set_level(level);
        self.into_mode(gpio_mode_t_GPIO_MODE_OUTPUT)
    }

(I'd need to refactor set_level into a private method without the MODE: OutputMode constraint so that it could actually be called.)

Let me know if y'all are interested in such a patch and I'd be happy to open a PR. (Or feel free to implement on your own if you think that'd be faster.)

lynaghk avatar Oct 22 '22 13:10 lynaghk