cpu/native: Allow Access to Hardware GPIO Pins on Linux#12451
cpu/native: Allow Access to Hardware GPIO Pins on Linux#12451aabadie merged 6 commits intoRIOT-OS:masterfrom
Conversation
|
This was on my to do list for quite some time, but I never came to id. Thanks for tackling this! |
|
I'd appreciate that feature, too! Just a short note here, with #11352 being merged now: I think, the definition of |
08f0de4 to
2f10b6d
Compare
|
If you already have a solution in mind, feel free to send a PR to my native-gpio branch. |
|
By now, RIOT can only control hardware CS lines, as Linux' userspace SPI API only allows those hard-wired connections. In case of the Raspberry Pi, this is pin CE0 (GPIO8) on However, there is a flag in the SPI API called If that works, it would allow arbitrary GPIOs for CS and also more than two devices. If not, I'd at least separate the number space, so that I'll have a look at it and see if that flag behaves like expected. |
|
Sorry that it took me so long, testing this with limited access to actual SPI hardware was not that easy. benpicco#4 contains a suggestion to solve the numbering issue between |
|
No support yet? |
aabadie
left a comment
There was a problem hiding this comment.
I haven't checked all the details but it seems to me that this PR is in quite a good shape. There's just the problem that I see with the module dependency that I think should be changed.
|
@aabadie your comments seem to be addressed. Care to take another look, please? |
Problem is that it depends on #12428 which cannot be easily tested on OSX. |
aabadie
left a comment
There was a problem hiding this comment.
This ends-up in lots of not directly related changes unfortunately (because now new drivers/packages can be build on native).
I'm wondering if we should split them in separate PRs to have more focused reviews.
cpu/native/Makefile.dep
Outdated
| USEMODULE += periph_spidev_linux | ||
| ifeq ($(OS),Linux) | ||
| ifneq (,$(filter periph_gpio,$(USEMODULE))) | ||
| DEFAULT_MODULE += periph_gpio_linux |
There was a problem hiding this comment.
| DEFAULT_MODULE += periph_gpio_linux | |
| USEMODULE += periph_gpio_linux |
I would not use DEFAULT_MODULE for this.
If it's because of the failing tests, then in the tests, instead of using DISABLE_MODULE, add native to CI_BOARD_BLACKLIST.
There was a problem hiding this comment.
I guess it could still be useful if someone wants to use the mock GPIO implementation instead.
There was a problem hiding this comment.
How is the mock named?, maybe something like this can be used?
| DEFAULT_MODULE += periph_gpio_linux | |
| ifneq (,$(filter periph_gpio_mock,$(USEMODULE))) | |
| USEMODULE += periph_gpio_linux | |
| endif |
There was a problem hiding this comment.
The mock is just periph_gpio.
I can make that a pseudomodule and move the implementation to gpio_mock.c.
Then in the tests we can do
ifeq (native,$(BOARD))
USEMODULE += periph_gpio_mock
endif|
I moved all the unrelated commits to a separate PR: #14663 |
aabadie
left a comment
There was a problem hiding this comment.
Looks good now. Please squash.
ACK!
|
Murdock found a couple of problems. Can you have a look @benpicco ? |
This is a GCC extension. Use hex constant instead.
|
Rebased to fix the warnings introduced by |
Contribution description
This adds GPIO support for native using the new Linux GPIO API.
Testing procedure
Compile
tests/periph_gpiofor thenativeboard on any SBC, e.g. a Raspberry Pi.Run
bin/native/tests_periph_gpio.elf --gpio=/dev/gpiochip0Please consult your board's manual for the pin mapping. For the Raspberry Pi, this would be

Here, GPIO20 and GPIO21 can be conveniently bridged with a jumper.
Setting and Reading GPIOs should work with this PR already:
For interrupts to work, #12428 is needed:
Issues/PRs references
depends on #12428
supersedes #7530