forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RIOT-OS#20783 from mguetschow/led-functions
drivers/led: add LED_NUMOF and convenience inline functions
- Loading branch information
Showing
34 changed files
with
138 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#define BOARD_H | ||
|
||
#include "cpu.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#define BOARD_H | ||
|
||
#include "cpu.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#define BOARD_H | ||
|
||
#include "cpu.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
#define BOARD_H | ||
|
||
#include "cpu.h" | ||
#include "periph/gpio.h" | ||
#include "periph/pm.h" | ||
|
||
#ifdef __cplusplus | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
#define BOARD_H | ||
|
||
#include "cpu.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#define BOARD_H | ||
|
||
#include "board_common.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#define BOARD_H | ||
|
||
#include "cpu.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#define BOARD_H | ||
|
||
#include "cpu.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
#define BOARD_H | ||
|
||
#include "cpu.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#define BOARD_H | ||
|
||
#include "cpu.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
#define BOARD_H | ||
|
||
#include "board_common.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
|
||
#include "cpu.h" | ||
#include "periph_conf.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
|
||
#include "cpu.h" | ||
#include "periph_conf.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#define BOARD_H | ||
|
||
#include "board_common.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
#include "cpu.h" | ||
#include "board_common.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
#include "cpu.h" | ||
#include "board_common.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
#include "cpu.h" | ||
#include "board_common.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
#include "cpu.h" | ||
#include "board_common.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
#include "cpu.h" | ||
#include "board_common.h" | ||
#include "periph/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
/** | ||
* @defgroup drivers_led Control on-board LEDs | ||
* @ingroup drivers_actuators | ||
* @brief Access macros to control the on-board LEDs | ||
* @brief Access macros and functions to control the on-board LEDs | ||
* | ||
* This header contains a set of macros for controlling the on-board LEDs of | ||
* a board. The LEDs are enumerated, starting from LED0 to LED7. As most | ||
|
@@ -24,7 +24,7 @@ | |
* @{ | ||
* | ||
* @file | ||
* @brief Macros for controlling the on-board LEDs | ||
* @brief Macros and inline functions for controlling the on-board LEDs | ||
* | ||
* @author Hauke Petersen <[email protected]> | ||
*/ | ||
|
@@ -106,15 +106,102 @@ extern "C" { | |
#define LED7_IS_PRESENT /**< indicate that LED7 is present */ | ||
#endif | ||
|
||
/** | ||
* Number of LEDs available on the current board. | ||
*/ | ||
#if defined(LED7_IS_PRESENT) | ||
#define LED_NUMOF 8 | ||
#elif defined(LED6_IS_PRESENT) | ||
#define LED_NUMOF 7 | ||
#elif defined(LED5_IS_PRESENT) | ||
#define LED_NUMOF 6 | ||
#elif defined(LED4_IS_PRESENT) | ||
#define LED_NUMOF 5 | ||
#elif defined(LED3_IS_PRESENT) | ||
#define LED_NUMOF 4 | ||
#elif defined(LED2_IS_PRESENT) | ||
#define LED_NUMOF 3 | ||
#elif defined(LED1_IS_PRESENT) | ||
#define LED_NUMOF 2 | ||
#elif defined(LED0_IS_PRESENT) | ||
#define LED_NUMOF 1 | ||
#else | ||
#define LED_NUMOF 0 | ||
#endif | ||
|
||
/** @} */ | ||
|
||
/** | ||
* @name Convenience LED control macros | ||
* @name Convenience LED control functions and macros | ||
* @{ | ||
*/ | ||
#define LED_ON(x) LED ## x ##_ON /**< Turn on led x */ | ||
#define LED_OFF(x) LED ## x ## _OFF /**< Turn off led x */ | ||
#define LED_TOGGLE(x) LED ## x ##_TOGGLE /**< Toggle led x */ | ||
#define LED_ON(id) LED ## id ##_ON /**< Turn on an LED */ | ||
#define LED_OFF(id) LED ## id ## _OFF /**< Turn off an LED */ | ||
#define LED_TOGGLE(id) LED ## id ##_TOGGLE /**< Toggle an LED */ | ||
|
||
/** | ||
* Turn on an LED. | ||
* | ||
* @note If id is a compile-time constant, consider using @ref LED_ON(id) instead. | ||
* | ||
* @param id id of LED between 0 and 7 | ||
*/ | ||
static inline void led_on(unsigned id) | ||
{ | ||
switch (id) { | ||
case 0: LED0_ON; break; | ||
case 1: LED1_ON; break; | ||
case 2: LED2_ON; break; | ||
case 3: LED3_ON; break; | ||
case 4: LED4_ON; break; | ||
case 5: LED5_ON; break; | ||
case 6: LED6_ON; break; | ||
case 7: LED7_ON; break; | ||
} | ||
} | ||
|
||
/** | ||
* Turn off an LED. | ||
* | ||
* @note If id is a compile-time constant, consider using @ref LED_OFF(id) instead. | ||
* | ||
* @param id id of LED between 0 and 7 | ||
*/ | ||
static inline void led_off(unsigned id) | ||
{ | ||
switch (id) { | ||
case 0: LED0_OFF; break; | ||
case 1: LED1_OFF; break; | ||
case 2: LED2_OFF; break; | ||
case 3: LED3_OFF; break; | ||
case 4: LED4_OFF; break; | ||
case 5: LED5_OFF; break; | ||
case 6: LED6_OFF; break; | ||
case 7: LED7_OFF; break; | ||
} | ||
} | ||
|
||
/** | ||
* Toggle an LED. | ||
* | ||
* @note If id is a compile-time constant, consider using @ref LED_TOGGLE(id) instead. | ||
* | ||
* @param id id of LED between 0 and 7 | ||
*/ | ||
static inline void led_toggle(unsigned id) | ||
{ | ||
switch (id) { | ||
case 0: LED0_TOGGLE; break; | ||
case 1: LED1_TOGGLE; break; | ||
case 2: LED2_TOGGLE; break; | ||
case 3: LED3_TOGGLE; break; | ||
case 4: LED4_TOGGLE; break; | ||
case 5: LED5_TOGGLE; break; | ||
case 6: LED6_TOGGLE; break; | ||
case 7: LED7_TOGGLE; break; | ||
} | ||
} | ||
|
||
/** @} */ | ||
|
||
#ifdef __cplusplus | ||
|
Oops, something went wrong.