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

drivers/led: add LED_NUMOF and convenience inline functions #20783

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

mguetschow
Copy link
Contributor

Contribution description

While reviewing #20782, I found some expected convenience functions for simple LED usage to be missing from "led.h". This PR adds the following:

  • a macro LED_NUMOF that provides the number of available LEDs at compile-time
  • static inline convenience functions led_{on,off,toggle} with the LED id as run-time argument, mirroring the LED_{ON,OFF,TOGGLE} compile-time macros

Also adapts tests/leds to (partly) use the newly provided functionality.

Testing procedure

make -C tests/leds should still work with the board of your choice.

Issues/PRs references

Could enable an easier application code for examples like #20782

@github-actions github-actions bot added Area: tests Area: tests and testing framework Area: drivers Area: Device drivers labels Jul 11, 2024
@mguetschow mguetschow added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jul 11, 2024
@riot-ci
Copy link

riot-ci commented Jul 11, 2024

Murdock results

✔️ PASSED

bb97445 boards/*: include periph/gpio.h in board.h

Success Failures Total Runtime
146563 0 146563 03h:31m:28s

Artifacts

@github-actions github-actions bot added the Area: boards Area: Board ports label Jul 11, 2024
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition.

@benpicco benpicco enabled auto-merge July 11, 2024 15:46
@benpicco benpicco added this pull request to the merge queue Jul 11, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 11, 2024
drivers/led: add LED_NUMOF and convenience inline functions
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 11, 2024
@mguetschow mguetschow added CI: full build disable CI build filter CI: no fast fail don't abort PR build after first error labels Jul 11, 2024
@@ -20,6 +20,7 @@
#define BOARD_H

#include "cpu.h"
#include "periph/gpio.h"
Copy link
Contributor

@benpicco benpicco Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this to led.h instead to avoid changing all board definitions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we could, but if we want to follow the include-what-you-use paradigm (see #20570), it doesn't make sense to add it to led.h. That file does not use the content of periph/gpio.h, while the board.h files indeed do (e.g., GPIO_PIN).

Copy link
Contributor Author

@mguetschow mguetschow Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, running make -C examples/hello-world BOARD=adafruit-grand-central-m4-express all with the following diff also fails on master due to the missing include in board.h, completely independent of led.h:

diff --git a/examples/hello-world/main.c b/examples/hello-world/main.c
index 213128ac64..a34fcc00bf 100644
--- a/examples/hello-world/main.c
+++ b/examples/hello-world/main.c
@@ -21,6 +21,8 @@
 
 #include <stdio.h>
 
+#include "board.h"
+
 int main(void)
 {
     puts("Hello World!");
@@ -28,5 +30,7 @@ int main(void)
     printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
     printf("This board features a(n) %s CPU.\n", RIOT_CPU);
 
+    printf("board.h defined PIN: %d\n", WS281X_PARAM_PIN);
+
     return 0;
 }

This now only gets apparent because the macros are used in the inline functions.

But anyway, I feel like the board.h include structure could benefit from a bigger overhaul in any case, so I'm not too strictly opposed to put the include in led.h instead for now. What do you think?

@benpicco benpicco added this pull request to the merge queue Jul 12, 2024
Merged via the queue into RIOT-OS:master with commit 57882eb Jul 12, 2024
26 checks passed
@mguetschow mguetschow deleted the led-functions branch July 12, 2024 20:43
@mguetschow mguetschow added this to the Release 2024.07 milestone Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: drivers Area: Device drivers Area: tests Area: tests and testing framework CI: full build disable CI build filter CI: no fast fail don't abort PR build after first error CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants