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
added the possibility to add None gpio pins #1690
Conversation
The one bit of weirdness doing this adds is the return value for command 0, aka the number of pins on the board. I'm not sure if that should return the number of array items or the number of actual pins. Perhaps array items is right for now, and if we add more return values in 2.0 we could return both numbers. In some sense this change goes farther from making apps easily portable. However, I don't believe that any of the gpio/adc/spi/etc. capsules will ever be conducive to portable apps. In that case, I like this change because it gives more flexibility to board authors to make an intuitive interface for the low-level hardware resources they want to provide to userspace. For example, imix has no pins labeled "D0" or "D1" (but has D2-D8). Should the board author make pin "D2" index 0 in the userspace code? Or should it be index 2? I argue the author should be able to decide what is a better representation of the hardware for their users, and this change would let them decide. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quite like this. Since there's some lingering issues with the macro already, I might offer a different thought on its design: Should we maybe be more explicit about the indices, in a way that would make lookup easier and the intent of the None
s clearer, perhaps:
let gpio = GpioComponent::new(board_kernel).finalize(components::gpio_component_array!(
0: stm32f4xx::gpio::PIN[6][9].as_ref().unwrap(), //D0
1: stm32f4xx::gpio::PIN[6][14].as_ref().unwrap(), //D1
@gap,
5: stm32f4xx::gpio::PIN[4][11].as_ref().unwrap(), //D5
6: stm32f4xx::gpio::PIN[4][9].as_ref().unwrap(), //D6
@end
)
This borrows a bit from the registers interface, that only requires you to specify the hardware that is present and lets the macro fill in the gaps automatically. It also makes it clearer that this list is actually an array intended to be indexed.
Thoughts?
6c7cdb5
to
8865fd4
Compare
As @ppannuto suggested, I modified the macro to have the following form: let gpio = components::gpio::GpioComponent::new(board_kernel).finalize(
components::gpio_component_helper!(
// pin number => pin reference
2 => &nrf52840::gpio::PORT[GPIO_D2],
3 => &nrf52840::gpio::PORT[GPIO_D3],
4 => &nrf52840::gpio::PORT[GPIO_D4],
5 => &nrf52840::gpio::PORT[GPIO_D5],
6 => &nrf52840::gpio::PORT[GPIO_D6],
7 => &nrf52840::gpio::PORT[GPIO_D7],
8 => &nrf52840::gpio::PORT[GPIO_D8],
9 => &nrf52840::gpio::PORT[GPIO_D9],
10 => &nrf52840::gpio::PORT[GPIO_D10]
)); The |
I think this looks great! And yeah, the It looks like that travis error is real, but otherwise I think this is good to go. |
I'll make the changes for all the platform. |
9a69ec4
to
fe7a07f
Compare
I have a question related to the pin assignment for: hail I assigned the pins according to their Dx, so instead of being 0,1,2,3 they will be 0, 1, None ..., 6, 7. Is this ok? 0 => &sam4l::gpio::PB[14], // DO
1 => &sam4l::gpio::PB[15], // D1
6 => &sam4l::gpio::PB[11], // D6
7 => &sam4l::gpio::PB[12] // D7 nrf52dk As all the pins are on P0 and seem to have printed numbers on the PCB, I assigned them like this: // Bottom right header on DK board
3 => &nrf52832::gpio::PORT[Pin::P0_03],
4 => &nrf52832::gpio::PORT[Pin::P0_04],
28 => &nrf52832::gpio::PORT[Pin::P0_28],
29 => &nrf52832::gpio::PORT[Pin::P0_29],
30 => &nrf52832::gpio::PORT[Pin::P0_30],
31 => &nrf52832::gpio::PORT[Pin::P0_31],
// Top mid header on DK board
12 => &nrf52832::gpio::PORT[Pin::P0_12],
11 => &nrf52832::gpio::PORT[Pin::P0_11],
// Top left header on DK board
27 => &nrf52832::gpio::PORT[Pin::P0_27],
26 => &nrf52832::gpio::PORT[Pin::P0_26],
2 => &nrf52832::gpio::PORT[Pin::P0_02],
25 => &nrf52832::gpio::PORT[Pin::P0_25] Is this ok, or should they be assigned in sequence? |
3ab96e3
to
464d1bb
Compare
In both cases I think this is the correct choice. Having the software id match the number that is printed on the board makes a lot of sense to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nits, but then I think this is probably good to go post-1.5 release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome!
Blocked pending 1.5 release
I like the flexibility, but I worry about the breaking changes to boards. It's probably better to not change boards like opentitan and hail. |
We made an argument during the "should GPIO be a stable driver" discussion that GPIO is too low-level for that and if you're using GPIO directly then you should understand the risk of being tied to board implementations. From a quick Given that we just did a 1.5 release, this actually seems like a very reasonable time to make a change like this. |
Well, of code that we wrote in libtock-c. Hail, for example, we made available and I don't think it is worth changing the GPIO interface from userland right now. I know I would be annoyed if someone changed it on me. Maybe 2.0 would be a time to change it, otherwise I see risks with minimal upside. |
I can change back imix and hail so that we can merge this without any breaking changes. Once you decide that pin numbering may be changed for these ones, I submit a new PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick doc update and not changing existing boards for me this is good to go.
1aead24
to
1837b6b
Compare
I reverted the pins to their original values, there should be no breaking changes now. |
Co-authored-by: Hudson Ayers <32688905+hudson-ayers@users.noreply.github.com>
Co-authored-by: Brad Campbell <bradjc5@gmail.com>
7d52b3a
bors r+ |
Pull Request Overview
Following the discussion for #1675, this pull request adds the possibility to add None gpio pins, basically preserving pin index numbers when some of the gpio pins are not exported.
I make a change to:
The format is a little strange, boards need to declare
Is there any way to check inside a macro if the value supplied is None (textual None) or an expression?
Any feedback is welcome.