DISTORTEC / distortos

object-oriented C++ RTOS for microcontrollers
https://distortos.org/
Mozilla Public License 2.0
434 stars 67 forks source link

Move buttons and leds indexes to enum type #28

Closed CezaryGapinski closed 7 years ago

FreddieChopin commented 7 years ago

Merged with a couple of fixes:

  1. Some headers are no longer needed in buttons.hpp and leds.hpp
  2. The "alternative" indexes for LEDs also need the same conditions as original indexes, otherwise you'd get a compilation failure when the port is disabled.
  3. The "alternative" indexes were moved "inside" the CONFIG_BOARD_LEDS_ENABLE condition. Without the removed table with pin identifiers, these are not needed when LEDs are disabled.
  4. Updated copyright years.
FreddieChopin commented 7 years ago

I had to make some further changes... The main reason is that if examples should stay simple, they really need the number of LEDs as a preprocessor constant. Otherwise we enter the land of complex code with uninitialized storage and placement new, which is probably not the best thing to use in simple examples.

That's why I've implemented following changes:

  1. I've added simple macros like DISTORTOS_BOARD_LD2_LED_ENABLE, which depend of apropriate GPIO port, but the macro is always either 1 or 0. Easy to generate with your script.
  2. I've added macros like DISTORTOS_BOARD_TOTAL_LEDS which is just defined to be a sum of all previously defined DISTORTOS_BOARD_..._LED_ENABLE macros. Also easy for your script (* - see the paragraph at the end).
  3. Every place that previously depended on the GPIO port now depends just on it's DISTORTOS_BOARD_..._LED_ENABLE - there's no need to repeat the more complex GPIO condition.

I hope you're OK with that. The crack between the generator of boards and Kconfig is pretty wide...

#define DISTORTOS_BOARD_TOTAL_LEDS      (DISTORTOS_BOARD_LD3_LED_ENABLE + DISTORTOS_BOARD_LD4_LED_ENABLE + \
        DISTORTOS_BOARD_LD5_LED_ENABLE + DISTORTOS_BOARD_LD6_LED_ENABLE)

But if that's not convenient for your script this can be changed to:

/// total number of LEDs on the board
#define DISTORTOS_BOARD_TOTAL_LEDS      (DISTORTOS_BOARD_LD3_LED_ENABLE + DISTORTOS_BOARD_LD4_LED_ENABLE + \
        DISTORTOS_BOARD_LD5_LED_ENABLE + DISTORTOS_BOARD_LD6_LED_ENABLE + 0)

(note the 0 at the end, which would allow you to generate each token as <name> +)

or even to sth like this:

/// total number of LEDs on the board
#define DISTORTOS_BOARD_TOTAL_LEDS      ( \
        DISTORTOS_BOARD_LD3_LED_ENABLE + \
        DISTORTOS_BOARD_LD4_LED_ENABLE + \
        DISTORTOS_BOARD_LD5_LED_ENABLE + \
        DISTORTOS_BOARD_LD6_LED_ENABLE + \
        0)

(which would allow you to generate one token per line, always in the form \t\t<name> + \)