LED
[Generic Port I/O]

LED handler. More...

Collaboration diagram for LED:

Defines

#define LED_OFF   0
 LED action definitions.
#define LED_ON   1
 Switch LED on.
#define LED_FLIP   2
 Flip the LED state (toggle).
#define LED_BLINK   4
 Let the LED blink continuously.
#define LED_IS_ON   0
#define LED_IS_OFF   1

Functions

int InitLED (LEDEventT *led)
 Configures LED connection port.
void sys_led (void *arg)
 Thread to control blinking and flashing of all registered LEDs.
void NutSetLed (HANDLE ledh, uint_fast8_t fxin, uint32_t timOn, uint32_t timOff)
 sets state of a LED
int NutRegisterLed (HANDLE *ledh, int bank, int pin)
 Register an LED for handling.

Variables

LEDEventT * first_led = NULL
HANDLE led_tmr = NULL
HANDLE led_evt = NULL

Detailed Description

LED handler.


Define Documentation

#define LED_OFF   0

LED action definitions.

The LED modifies the LED according to these tokens when calling NutSetLed().

Switch LED off. The LED will be switched off immediately. If a timOff parameter of not 0 is given, the LED will be switched off for the given time in ms an then return to on state.

Definition at line 73 of file led.h.

#define LED_ON   1

Switch LED on.

The LED will be switched on immediately. If a timOff parameter of not 0 is given, the LED will be switched on for the given time in ms an then return off state.

Definition at line 82 of file led.h.

#define LED_FLIP   2

Flip the LED state (toggle).

Toggle the LED from its actual state the the other. Timing parameters are not supported.

Definition at line 90 of file led.h.

Referenced by Key2Thread(), NutSetLed(), and sys_led().

#define LED_BLINK   4

Let the LED blink continuously.

The parameter timOn specifies the on-time and parameter timOff the off-time. Together with higher timer settings a software dimming can as well be established as a simple blink effect or short / long flash effects. Be adviced that high timer rates can decrease overall system speed. Therefore you have to modify the timer rate in the led.c directly. Standard setting is 10ms cycle time.

Examples:
ioexpander/ioexpander.c.

Definition at line 102 of file led.h.

Referenced by Key1Thread(), main(), NutSetLed(), and sys_led().

#define LED_IS_ON   0

Definition at line 89 of file led.c.

Referenced by NutSetLed().

#define LED_IS_OFF   1

Definition at line 90 of file led.c.

Referenced by NutRegisterLed(), and NutSetLed().


Function Documentation

int InitLED ( LEDEventT *  led  ) 

Configures LED connection port.

This is an internal function called by NutRegisterLED().

Definition at line 117 of file led.c.

References GPIO_CFG_OUTPUT, GpioPinConfigSet(), GpioPinSetHigh(), IOExpPinConfigSet(), IOExpSetBitHigh(), and IOXP_PORT0.

Referenced by NutRegisterLed().

void sys_led ( void *  arg  ) 

Thread to control blinking and flashing of all registered LEDs.

This is the internal LED handler thread. It si blocked by default, waiting for a timer event to run. The thread handles LED timing through reverse calculation of the actual timeout. This uses mor system time, but makes blinking effects more smooth even in situation where high priority tasks are delaying the timer interrupt or this threadf to be executed.

Parameters:
arg Handle of an event queue.

Definition at line 165 of file led.c.

References first_led, LED_BLINK, LED_FLIP, LED_OFF, LED_ON, NUT_WAIT_INFINITE, NUTASSERT, NutEventWait(), NutGetMillis(), NutSetLed(), and NutThreadSetPriority().

Referenced by NutRegisterLed().

void NutSetLed ( HANDLE  ledh,
uint_fast8_t  fxin,
uint32_t  timOn,
uint32_t  timOff 
)

sets state of a LED

Parameters:
ledh The handle to the LED that should be controlled.
fxin Effect to set
timOn Duration of the LED's on-time of the effect given.
timOff Duration of the LED's off time of the effect given.
Note:
Timeout is limited to the granularity of the system timer.

Definition at line 228 of file led.c.

References GpioPinSet(), IOExpSetBit(), IOXP_PORT0, LED_BLINK, LED_FLIP, LED_IS_OFF, LED_IS_ON, LED_OFF, LED_ON, and NUTASSERT.

Referenced by Key1Thread(), Key2Thread(), main(), sys_led(), Thread1(), and Thread2().

int NutRegisterLed ( HANDLE ledh,
int  bank,
int  pin 
)

Register an LED for handling.

Register a LED for beeing controlled by this driver. LED can then be set by NutSetLed() by passing over the LEDs handler to that function. Also LEDs connectd through external (I2C / SPI) port chips can be driven, if the control for that chips is enabled in Nutconf. The desired GPIO pin (internal or external) should be configured correct before you can register a LED on it.

Parameters:
ledh Pointer to a HANDLE for accessing the LED after registering.
bank Port of CPU or IO-Expander the LED is connected to.
pin Pin at the given port.
Returns:
-1 if registering failed, else 0.

Definition at line 288 of file led.c.

References first_led, InitLED(), led_evt, LED_IS_OFF, led_tmr, malloc, memset(), NutEnterCritical, NutExitCritical, NutThreadCreate(), NutTimerStart(), and sys_led().

Referenced by main(), Thread1(), and Thread2().


Variable Documentation

LEDEventT* first_led = NULL

Definition at line 106 of file led.c.

Referenced by NutRegisterLed(), and sys_led().

HANDLE led_tmr = NULL

Definition at line 109 of file led.c.

Referenced by NutRegisterLed().

HANDLE led_evt = NULL

Definition at line 110 of file led.c.

Referenced by NutRegisterLed().


© 2000-2010 by contributors - visit http://www.ethernut.de/