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

Missing impls for Pin<_, DynFunction, _> #756

Open
jannic opened this issue Jan 14, 2024 · 1 comment
Open

Missing impls for Pin<_, DynFunction, _> #756

jannic opened this issue Jan 14, 2024 · 1 comment

Comments

@jannic
Copy link
Member

jannic commented Jan 14, 2024

There are currently not many useful functions implemented for Pin<_, DynFunction, _>. Therefore, pins configured that way can not be used without converting them to a pin with a statically defined function first. That defeats the idea of having a DynFunction in the first place.

One could, for example, implement OutputPin like this:

    #[derive(Debug)]
    pub enum DynFunctionError {
        InvalidFunction,
    }

    impl embedded_hal::digital::Error for DynFunctionError {
        fn kind(&self) -> ErrorKind {
            ErrorKind::Other
        }
    }

    impl<I, P> ErrorType for Pin<I, DynFunction, P>
    where
        I: PinId,
        P: PullType,
    {
        type Error = DynFunctionError;
    }

    impl<I, P> OutputPin for Pin<I, DynFunction, P>
    where
        I: PinId,
        P: PullType,
    {
        fn set_low(&mut self) -> Result<(), Self::Error> {
            if self.function() != DynFunction::Sio(super::DynSioConfig::Output) {
                return Err(DynFunctionError::InvalidFunction);
            }
            self._set_low();
            Ok(())
        }

        fn set_high(&mut self) -> Result<(), Self::Error> {
            if self.function() != DynFunction::Sio(super::DynSioConfig::Output) {
                return Err(DynFunctionError::InvalidFunction);
            }
            self._set_high();
            Ok(())
        }
    }

It may be useful to first describe use cases for DynFunction where it's not feasible to just use a statically defined function.

@jannic
Copy link
Member Author

jannic commented Jan 14, 2024

(I saved some experimental code to https://github.com/jannic/rp-hal/commits/issue-756/)

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

1 participant