Numbered LEDs, their /dev/ledN files, and the driver interface.
More...
|
| struct | led_ops_t |
| | Operations an LED driver provides; every one is required. More...
|
| |
| struct | led_t |
| | An LED: driver operations bound to one device instance. More...
|
| |
| struct | led_table_t |
| | Every LED in index order; generated in devicetree.c. More...
|
| |
|
| unsigned | led_count (void) |
| | Report how many LEDs the board describes.
|
| |
| int | led_set (unsigned index, bool on) |
| | Turn an LED on or off.
|
| |
| int | led_get (unsigned index, bool *on) |
| | Read whether an LED is lit.
|
| |
| int | led_toggle (unsigned index) |
| | Invert an LED.
|
| |
Numbered LEDs, their /dev/ledN files, and the driver interface.
Every enabled device whose binding has led: true is an LED. They are numbered in description order, and each registers a device file, by default /dev/ plus its node name, so boards name the nodes led0, led1, and so on. The generated dt_led_table lists them.
| Driver | Compatible | Use |
| GPIO LED | homecore,gpio-led | An LED on a GPIO pin, optionally active-low |
| Console LED | homecore,console-led | A stand-in for emulators without LEDs: prints each |
change on the console |
Device files
Reading a /dev/ledN file returns its state captured at open, 0\n or 1\n, then end of file. Each write sets the LED: 1 or on lights it, 0 or off turns it off, and toggle inverts it. Surrounding whitespace, such as a trailing newline, is ignored; anything else fails with EINVAL. The file accepts O_CREAT, O_TRUNC, and O_APPEND, so fopen(path, "w") works.
write /dev/led0 on
cat /dev/led0
The functions below are for thread context, like the VFS.
- See also
- LEDs for the Drivers, their configuration, and tests.
◆ led_count()
| unsigned led_count |
( |
void |
| ) |
|
Report how many LEDs the board describes.
- Returns
- The number of LEDs; valid indices are 0 to one less.
◆ led_set()
| int led_set |
( |
unsigned |
index, |
|
|
bool |
on |
|
) |
| |
Turn an LED on or off.
- Parameters
-
| index | LED number. |
| on | true to light the LED. |
- Return values
-
| 0 | The LED was set. |
| -1 | errno is ENODEV for an index without an LED, or set by the driver. |
◆ led_get()
| int led_get |
( |
unsigned |
index, |
|
|
bool * |
on |
|
) |
| |
Read whether an LED is lit.
- Parameters
-
| index | LED number. |
| [out] | on | true if the LED is lit. Must not be NULL. |
- Return values
-
| 0 | on holds the state. |
| -1 | errno is ENODEV for an index without an LED, or set by the driver. |
◆ led_toggle()
| int led_toggle |
( |
unsigned |
index | ) |
|
Invert an LED.
- Parameters
-
- Return values
-
◆ led_register_node()
| void led_register_node |
( |
vfs_node_t * |
node, |
|
|
const char * |
path, |
|
|
const led_t * |
led |
|
) |
| |
Register the device file of an LED.
Called by LED drivers from their init function. Sets up node as a readable and writable device file for led and registers it.
- Parameters
-
| node | Node storage owned by the driver instance; must remain valid for the rest of the program. |
| path | Device file path, such as /dev/led0; must remain valid. |
| led | The LED; must remain valid for the rest of the program. |