Skip to content

[RFC] introduce common periph led driver#7321

Closed
smlng wants to merge 4 commits intoRIOT-OS:masterfrom
smlng:rfc/drivers/periph/led
Closed

[RFC] introduce common periph led driver#7321
smlng wants to merge 4 commits intoRIOT-OS:masterfrom
smlng:rfc/drivers/periph/led

Conversation

@smlng
Copy link
Copy Markdown
Member

@smlng smlng commented Jul 5, 2017

this PR introduces a simplified handling of on-board LEDs by fully utilizing RIOTs hardware independent gpio driver. That way per board redefinition of led macros such as LEDX_ON, LEDX_OFF, and LEDX_TOGGLE will be obsolete, it simple requires to define the respective gpio pin for each LED as it is already done.

As an example this PR shows this feature on board remote-revb. However, this is foremost a Request-For-Comments and hence Work-In-Progress.

@smlng smlng self-assigned this Jul 5, 2017
@smlng smlng added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Area: drivers Area: Device drivers Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Jul 5, 2017
@miri64
Copy link
Copy Markdown
Member

miri64 commented Jul 5, 2017

What is the reasoning for the change? What is the overall size benefit/drawback?

Copy link
Copy Markdown
Contributor

@kYc0o kYc0o left a comment

Choose a reason for hiding this comment

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

I'd also like to have a "easy to use" LED interface, especially for educational purposes this is very useful, however I would like to know, as Martine pointed out, the benefits on code size of this approach.

#define LED7_INIT do { gpio_init(LED7_PIN, GPIO_OUT); LED7_OFF; } while(0)
#endif /* LED7_INIT */
#endif /* LED7_PIN */
/** @} */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe instead of creating a define per "possibly" LEDs present in a board (what if I have 8 LEDs? This won't work), you can propose a definition similar to UART, SPI or (future) I2C, on which you have a general structure and is the board which defines how many "objects" of this kind it has, this way you'll avoid the need to define everything possible.

However, I doubt if such a solution would have a negative impact on code size.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought about this, too ... will try this later on. For now this PR is mostly about avoiding redefinition per board for common function such as LED[0-7]_ON

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

btw. 8 LEDs would still work (0-7, it is). However, supporting arbitrary numbers of LEDs is difficult while using macros

#ifdef LED7_PIN
LED7_INIT;
#endif /* LED7_PIN */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here too, same comment as above.

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Jul 5, 2017

the reasoning behind this is that currently each board redefines macros LED0_[ON|OFF|TOGGLE] which is unnecessary as all boards define on-board LEDs using the GPIO_PIN macro of the common gpio API. Further, all of these macros (e.g. LED0_ON) use CPU specific gpio handling which is already implemented by the CPU specific low lever gpio driver cpu/<cpu_name>/periph/gpio.c - compare for instance 1 and 2

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Jul 5, 2017

btw. @miri64 regarding code size, using tests/led this already safes 280B 😮

master

text	   data	    bss	    dec	    hex	filename
9104	    136	   2860	  12100	   2f44	/RIOT/tests/leds/bin/remote-revb/tests_leds.elf

this PR

text	   data	    bss	    dec	    hex	filename
8824	    136	   2860	  11820	   2e2c	/RIOT/tests/leds/bin/remote-revb/tests_leds.elf

@jnohlgard
Copy link
Copy Markdown
Member

Why not just use the normal GPIO API and create macros as aliases for the GPIO pins?
Instead of LED0_ON, LED0_ON, LED0_TOGGLE you will only need LED_0 and call gpio_init(LED_0), gpio_set(LED_0) etc

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Jul 5, 2017

@gebart that's already and still possible - though not with LED_0 but LED0_PIN, which is by the way what this PR uses, eg. LED0_ON is defined as gpio_set(LED0_PIN). However, we have and use the util macros LED0_ON|OFF|TOGGLE throughout the code, so IMHO it would be bad to remove these short hand macros.

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Jul 5, 2017

and as I already said, primary goal of this PR is to remove redundant redefinition of LED macros and that way also reduce stuff defined in board.h and or periph_conf.h on a per board basis.

@smlng smlng force-pushed the rfc/drivers/periph/led branch from a5fef44 to 7015eb6 Compare July 7, 2017 08:13
@smlng
Copy link
Copy Markdown
Member Author

smlng commented Jul 7, 2017

I ported this to samr21-xpro and pba-d-01-kw2x where it introduces an overhead of >100B in both cases.

Still I think its worth discussing and reconsidering current handling of on-board leds - but not the way I proposed here, I'll try something different, too.

Will close this soonish as memo, just keep it open if someone wants to had her/his 2 cents

@haukepetersen
Copy link
Copy Markdown
Contributor

I agree that we should revisit this topic, its been a while since we had this on our list (hello @OlegHahm :-) ).

To recab: the reason for having the LED macros was/is simply to be able to control selected pins (i.e. those that have LEDs connected to them) with the least amount of overhead, so they can used for timing analysis. I personally don't think this use is not very pressing (anymore), as most timing analysis are carried out using hardware timers and/or other profiling solutions.

Also I think the usefulness of the LED macros for debugging has quite degraded over time, as we have access to decent debuggers on most platforms, that make the use of LED macros for debugging obsolete on these.

Bottom line: I think we can deprecate the existing LED macros and move to something easier maintainable.

I do however not like the proposed solution:

  • the LED handling does not belong into periph! LEDs do not have anything to do with MCU peripherals!
  • we can simplify the LED handling even more, just played around a bit and came up with boards: re-work LED handling #7350

@smlng
Copy link
Copy Markdown
Member Author

smlng commented Jul 11, 2017

@haukepetersen your #7350 is basically what I had in mind with:

but not the way I proposed here, I'll try something different,

so, now its really time to close this and move the discussion to your PR ...

@smlng smlng closed this Jul 11, 2017
@smlng smlng removed the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Jul 11, 2017
@smlng smlng deleted the rfc/drivers/periph/led branch July 5, 2018 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants