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

Note on how to acquire Pin's number as an integer #771

Open
elfmimi opened this issue Feb 14, 2024 · 1 comment
Open

Note on how to acquire Pin's number as an integer #771

elfmimi opened this issue Feb 14, 2024 · 1 comment

Comments

@elfmimi
Copy link

elfmimi commented Feb 14, 2024

This is not an issue, but a sharing of knowledge that I wanted to have when I started.

It is about rp2040_hal::gpio::Pin .

at v0.9.0 it is like,

pub struct Pin<I: PinId, F: func::Function, P: PullType> {
id: I,
function: F,
pull_type: P,
}

at v0.8.0 and v0.7.0 respectively, it was like,

pub struct Pin<I, M>
where
I: PinId,
M: PinMode + ValidPinMode<I>,
{
regs: Registers<I>,
mode: PhantomData<M>,
}

pub struct Pin<I, M>
where
I: PinId,
M: PinMode + ValidPinMode<I>,
{
regs: Registers<I>,
mode: PhantomData<M>,
}

Suppose we had a trait like this.

pub trait PinIdNum {
    fn get_id_num(&self) -> u8;
}

for v0.9.0 you can implement it like this.

impl<I, F, P> PinIdNum for Pin<I, F, P> where I: PinId, F: Function, P: PullType {
    fn get_id_num(&self) -> u8 { self.id().num }
}

for v0.8.0 it can be like following two ways.

impl<I, M> PinIdNum for Pin<I, M> where I: PinId, M: PinMode + ValidPinMode<I> {
    fn get_id_num(&self) -> u8 { self.id().num }
}
impl<I, M> PinIdNum for Pin<I, M> where I: PinId, M: PinMode + ValidPinMode<I> {
    fn get_id_num(&self) -> u8 { I::DYN.num }
}

for v0.7.0 only the latter of above two is valid.

impl<I, M> PinIdNum for Pin<I, M> where I: PinId, M: PinMode + ValidPinMode<I> {
    fn get_id_num(&self) -> u8 { I::DYN.num }
}
@elfmimi
Copy link
Author

elfmimi commented Feb 14, 2024

version correspondence
rp-pico 0.6.0 => rp2040-hal 0.7.0
rp-pico 0.7.0 => rp2040-hal 0.8.0
rp-pico 0.8.0 => rp2040-hal 0.9.0

@elfmimi elfmimi changed the title Note on how to aquire Pin's number as an integer Note on how to acquire Pin's number as an integer Feb 18, 2024
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