Difference between revisions of "MansOS LEDs"

From DiLab
Jump to: navigation, search
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{TocRight}}

Key include files:

mos/hil/leds.h
mos/hil/leds.h
mos/platforms/<name>/ledslist.h


MansOS provides API for Light-Emitting Diode (LED) setting and status checking (whether a LED is ON or OFF). LEDs are connected directly to GPIO pins, and each platform must define pin numbers for available LEDs on the hardware platform.
MansOS provides API for Light-Emitting Diode (LED) setting and status checking (whether a LED is ON or OFF). LEDs are connected directly to GPIO pins, and each platform must define pin numbers for available LEDs on the hardware platform.
Line 20: Line 25:
All platform-independent LED functions are described in mos/hil/leds.h . Implementation can be found under mos/hal/platforms/<platform-name>/
All platform-independent LED functions are described in mos/hil/leds.h . Implementation can be found under mos/hal/platforms/<platform-name>/


The following functions are available for '''any individual led'''. The ''"redLed"'' prefix is used as an example, and can be substituted by any other LED name or alias valid for the chosen platform, such as ''greenLed'' or ''led3''.
// Toggle an LED, addressed by color
toggleRedLed()
toggleGreenLed()
toggleBlueLed()

// Toggle an LED, addressed by number
toggleLed(ledNr)

// Toggle platform's default LED
toggleLed()

// Turn ON an LED, addressed by color
redLedOn()
greenLedOn()
blueLedOn()

// Turn OFF an LED, addressed by color
redLedOff()
greenLedOff()
blueLedOff()


redLedInit(); // Initialize the LED
// Turn ON/OFF an LED, addressed by number
redLedGet(); // Get the state of the LED
ledOn(uint8_t ledNr)
redLedSet( val ); // Set the state of the LED to "val"
ledOff(uint8_t ledNr)
redLedOn(); // Turn the LED on
redLedOff(); // Turn the LED off
redLedToggle(); // Toggle the LED
redLedMask(); // Get the mask value for the LED


// Turn platform's default LED ON/OFF
ledOn();
ledOff();


// Return true, if an LED, addressed by number, is ON; false (zero) otherwise
The following functions are for a '''group of leds''', addressed by using a mask, a bitfield.
bool ledIsOn(ledNr)


// Init All leds (kernel uses this)
// Get and set all LEDs, addressed by a bitmask
void ledsInit(void);
// for example, if getLeds() returns 5, LEDs #0 and #2 are ON ((2 << 0) + (2 << 2) = 5)
uint8_t getLeds()
// Set LEDs from a bitmask
setLeds(bitmap)
void ledsSet(uint_t led_bitmask);
// Which LEDs are on? Returns a bitmask
uint_t ledsGet(void);
// Turn LEDs on using a bitmask
#define ledsOn(led_bitmask) ...
// Turn LEDs off using a bitmask
#define ledsOff(led_bitmask) ...
// Toggle LEDs using a bitmask
#define ledsToggle(led_bitmask) ...
// LEDs Constants
leds_count_t LEDS_COUNT; // Number of available LEDs
leds_all_t LEDS_ALL_MASK; // Mask for all LEDs


== Examples ==
== Examples ==
Line 63: Line 66:
Blink the platform's default LED once every second.
Blink the platform's default LED once every second.


<pre>
// Example from apps/demo/Blink
// Example from apps/demo/Blink


while (1) {
while (1) {
// change red LED status
// change the red (default) LED status
toggleLed();
ledToggle();
// wait for 1000 milliseconds
mdelay(1000);
// wait for 1000 milliseconds
}
mdelay(1000);
}
</pre>


=== Counter representation on LEDs ===
=== Counter representation on LEDs ===
Line 76: Line 82:
Represent an incrementing counter on the LEDs. If less than 8 LEDs are supported by the platform, the youngest bits are shown.
Represent an incrementing counter on the LEDs. If less than 8 LEDs are supported by the platform, the youngest bits are shown.


<pre>
// Example from apps/demo/CounterToLeds
// Example from apps/demo/CounterToLeds


uint8_t counter;
uint8_t counter;
counter = 1;
counter = 1;
while (1) {
while (1) {
setLeds(counter++);
ledsSet(counter++);
msleep(1000); // sleep one second
msleep(1000); // sleep one second
}
}
</pre>

Latest revision as of 15:36, 15 October 2014

Key include files:

mos/hil/leds.h
mos/platforms/<name>/ledslist.h

MansOS provides API for Light-Emitting Diode (LED) setting and status checking (whether a LED is ON or OFF). LEDs are connected directly to GPIO pins, and each platform must define pin numbers for available LEDs on the hardware platform.

LEDs can be addressed in two different forms: by color or by led number. LEDs are always accessible by number, starting from 0 up to LED_COUNT - 1, where LED_COUNT is a constant specifying LED count on the particular platform. LED addressing by color is optional, platform-dependent. On some platforms, such as TelosB, different colors are available, for example, red, green and blue LED. On some platforms all the LEDs can be of the same color.

Up to 8 LEDs are supported.

Usage and configuration

LED support is turned ON by default. It can be disabled by adding the following line to the application config file:

USE_LEDS = n

Dependencies

There are no dependencies for using LEDs.

Function reference

All platform-independent LED functions are described in mos/hil/leds.h . Implementation can be found under mos/hal/platforms/<platform-name>/

The following functions are available for any individual led. The "redLed" prefix is used as an example, and can be substituted by any other LED name or alias valid for the chosen platform, such as greenLed or led3.

redLedInit();        // Initialize the LED
redLedGet();         // Get the state of the LED
redLedSet( val );    // Set the state of the LED to "val"
redLedOn();          // Turn the LED on
redLedOff();         // Turn the LED off
redLedToggle();      // Toggle the LED
redLedMask();        // Get the mask value for the LED


The following functions are for a group of leds, addressed by using a mask, a bitfield.

// Init All leds (kernel uses this)
void ledsInit(void);               

// Set LEDs from a bitmask
void ledsSet(uint_t led_bitmask);

// Which LEDs are on? Returns a bitmask
uint_t ledsGet(void);

// Turn LEDs on using a bitmask
#define ledsOn(led_bitmask) ...

// Turn LEDs off using a bitmask
#define ledsOff(led_bitmask) ...

// Toggle LEDs using a bitmask
#define ledsToggle(led_bitmask) ...

// LEDs Constants
leds_count_t   LEDS_COUNT;     // Number of available LEDs
leds_all_t     LEDS_ALL_MASK;   // Mask for all LEDs

Examples

Blink

Blink the platform's default LED once every second.

// Example from apps/demo/Blink

while (1) {
    // change the red (default) LED status
    ledToggle();
 
    // wait for 1000 milliseconds
     mdelay(1000);
}

Counter representation on LEDs

Represent an incrementing counter on the LEDs. If less than 8 LEDs are supported by the platform, the youngest bits are shown.

// Example from apps/demo/CounterToLeds

uint8_t counter;
counter = 1;
while (1) {
    ledsSet(counter++);
    msleep(1000); // sleep one second
}