Difference between revisions of "Platform:new:LEDs"
(New page: How to define or add LEDs for a platform "xxx". * Find a template for a ledslist.h file, for example, from telosb, pc or some other platform. * Place it in mos/platforms/xxx/ * Edit as...) |
|||
Line 1: | Line 1: | ||
{{TocRight}} |
|||
How to define or add LEDs for a platform "xxx". |
How to define or add LEDs for a platform "xxx". |
||
⚫ | |||
⚫ | |||
* Place it in mos/platforms/xxx/ |
* Place it in mos/platforms/xxx/ |
||
Line 28: | Line 28: | ||
For example: |
For example: |
||
<source> |
<source lang="c"> |
||
#define LEDS_ON_PIN_VALUE 0 |
#define LEDS_ON_PIN_VALUE 0 |
||
#define LEDS_PORT 5 |
#define LEDS_PORT 5 |
||
Line 43: | Line 43: | ||
The default LED name is provided by defining the DEFAULT_LED macro as follows: |
The default LED name is provided by defining the DEFAULT_LED macro as follows: |
||
<source> |
<source lang="c"> |
||
#define LED_DEFAULT redLed |
#define LED_DEFAULT redLed |
||
</source> |
</source> |
||
Line 53: | Line 53: | ||
You may create one or several aliases for any LED using the LED_ALIAS( alias, original-name ) macro. |
You may create one or several aliases for any LED using the LED_ALIAS( alias, original-name ) macro. |
||
For example: |
For example: |
||
<source> |
<source lang="c"> |
||
LED_ALIAS(myFavoriteLedNickname, redLed) |
LED_ALIAS(myFavoriteLedNickname, redLed) |
||
</source> |
</source> |
||
Line 63: | Line 63: | ||
Therefore, you must provide a list of DOIT() calls for each LED name. Note, you do not need to include the LED alias names in this list. |
Therefore, you must provide a list of DOIT() calls for each LED name. Note, you do not need to include the LED alias names in this list. |
||
For example: |
For example: |
||
<source> |
<source lang="c"> |
||
#define DOIT_FIRST_LINE __LINE__ |
#define DOIT_FIRST_LINE __LINE__ |
||
DOIT(redLed) |
DOIT(redLed) |
||
Line 71: | Line 71: | ||
Here is the example usage of the LED iterator, as used in leds.c: |
Here is the example usage of the LED iterator, as used in leds.c: |
||
<source> |
<source lang="c"> |
||
void ledsInit() |
void ledsInit() |
||
{ |
{ |
Revision as of 14:37, 26 November 2011
How to define or add LEDs for a platform "xxx".
- Find a template for a ledslist.h file, for example, from telosb, pc or some other platform.
- Place it in mos/platforms/xxx/
- Edit as appropriate.
ledslist.h
LEDs are identified by their names, for example, redLed, or led1, led2, and so on. These names need to appear in two places:
- where the LEDs are defined. look for the LEDS_DEFINE macro section
- where the LEDs are listed to be used in the code that iterates through all the available LEDs. Look for the macro DOIT section.
LEDS_DEFINE
Please provide here the following:
- define a LED hardware interface.
- add aliases to some LEDs, as needed
- define a default led.
Define a LED
Use LED_DEFINE(name, port, pin, led-on-pin-value) macro to define the hardware interface for each LED. For example:
#define LEDS_ON_PIN_VALUE 0
#define LEDS_PORT 5
LED_DEFINE(redLed, LEDS_PORT, 4, LEDS_ON_PIN_VALUE)
LED_DEFINE(greenLed, LEDS_PORT, 5, LEDS_ON_PIN_VALUE)
LED_DEFINE(blueLed, LEDS_PORT, 6, LEDS_ON_PIN_VALUE)
Default LED
The default led is named "led". Therefore, any application, such as apps/demo/Blink, may use the standard functions such as ledToggle().
The default LED name is provided by defining the DEFAULT_LED macro as follows:
#define LED_DEFAULT redLed
If no default LED ia specified, the led* interface function calls are created as empty calls and ignored by the compiler.
LED aliases
You may create one or several aliases for any LED using the LED_ALIAS( alias, original-name ) macro. For example:
LED_ALIAS(myFavoriteLedNickname, redLed)
DOIT
DOIT(led) is a macro that is iterated for each LED every time the "ledslist.h" file is included. Therefore, you must provide a list of DOIT() calls for each LED name. Note, you do not need to include the LED alias names in this list. For example:
#define DOIT_FIRST_LINE __LINE__
DOIT(redLed)
DOIT(greenLed)
DOIT(blueLed)
Here is the example usage of the LED iterator, as used in leds.c:
void ledsInit()
{
# define DOIT(_led) _led##Init();
# include "ledslist.h"
}
Hardware interface notes
GPIO LEDs
If LEDs in your platform are attached to GPIO pins - you are in luck. Just list their names.
Custom interface for LEDs
If LEDs have a different hardware interface, such as dedicated I2C controller, you may need to write code to implement the main functions.
The LED functions are declared in mos/hil/leds.h file. In particular, pay attention to the LED_DEFINE macro, that lists all the individual LED functions that have to be implemented.