Changes between Version 2 and Version 3 of linux/led


Ignore:
Timestamp:
06/18/2021 04:51:43 PM (3 years ago)
Author:
Tim Harvey
Comment:

convert page from raw HTML

Legend:

Unmodified
Added
Removed
Modified
  • linux/led

    v2 v3  
    1 {{{#!html
    2           <div id="wikipage" class="trac-content"><p>
    3 </p><div class="wiki-toc">
    4 <ol>
    5   <li>
    6     <a href="#LinuxLEDclassforGPIOandPWMcontrolledLEDs">Linux LED class for GPIO (and PWM) controlled LEDs</a>
    7     <ol>
    8       <li>
    9         <a href="#LEDTriggers">LED Triggers</a>
    10       </li>
    11     </ol>
    12   </li>
    13   <li>
    14     <a href="#OtherReferences">Other References</a>
    15   </li>
    16 </ol>
    17 </div><p>
    18 </p>
    19 <p>
    20 <span class="wikianchor" id="led_class"></span>
    21 </p>
    22 <h1 id="LinuxLEDclassforGPIOandPWMcontrolledLEDs">Linux LED class for GPIO (and PWM) controlled LEDs</h1>
    23 <p>
     1[[PageOutline]]
     2
     3= Linux LED class for GPIO (and PWM) controlled LEDs
    244GPIO's which are connected directly to LED's on are registered through the Linux LED class sysfs interface and you can control them via /sys/class/leds.
    25 </p>
    26 <p>
    27 Mapping GPIO's to LED's (as well as defining their logic level and default trigger) is done in the board support file or in the case of more modern kernels such as Ventana in the device-tree. See the led node in the <a class="ext-link" href="http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/imx6qdl-gw54xx.dtsi#n38"><span class="icon">​</span>gw54xx device-tree</a> for example.
    28 </p>
    29 <p>
     5
     6Mapping GPIO's to LED's (as well as defining their logic level and default trigger) is done in the board support file or in the case of more modern kernels such as Ventana in the device-tree. See the led node in the ​gw54xx device-tree for example.
     7
    308LED brightness is represented as an integer value and for LED's connected to PWM signals this truly controls the brightness. However for LED's connected to GPIO's a brightness of 0 is off and any other value is on.
    31 </p>
    32 <p>
     9
    3310To list available LED's by name (see product hardware manual to match name to board LED):
    34 </p>
    35 <pre class="wiki">ls /sys/class/leds
    36 </pre><p>
     11{{{#!bash
     12ls /sys/class/leds
     13}}}
     14
    3715To enable/disable LEDs:
    38 </p>
    39 <pre class="wiki">echo 0 &gt; /sys/class/leds/user1/brightness ;# turn off user1 LED
    40 echo 255 &gt; /sys/class/leds/user1/brightness ;# turn on user1 LED
    41 </pre><p>
     16{{{#!bash
     17echo 0 > /sys/class/leds/user1/brightness ;# turn off user1 LED
     18echo 255 > /sys/class/leds/user1/brightness ;# turn on user1 LED
     19}}}
     20
    4221Some boards (consult the board user manual) use a bi-color LED (typical green/red) where 2 GPIO's are used (connected to each side of the LED). In this scenario setting one LED on and the other Off would produce one color and flipping them would produce the other (while turning them both on or both off would result in no LED's lit):
    43 </p>
    44 <pre class="wiki"># turn bi-color LED Red
    45 echo 0 &gt; /sys/class/leds/user1/brightness
    46 echo 255 &gt; /sys/class/leds/user2/brightness
     22{{{#!bash
     23# turn bi-color LED Red
     24echo 0 > /sys/class/leds/user1/brightness
     25echo 255 > /sys/class/leds/user2/brightness
    4726# turn bi-color LED Green
    48 echo 255 &gt; /sys/class/leds/user1/brightness
    49 echo 0 &gt; /sys/class/leds/user2/brightness
    50 </pre><p>
    51 <span class="wikianchor" id="led-trigger"></span>
    52 </p>
    53 <h2 id="LEDTriggers">LED Triggers</h2>
    54 <p>
     27echo 255 > /sys/class/leds/user1/brightness
     28echo 0 > /sys/class/leds/user2/brightness
     29}}}
     30
     31
     32[=#triggers]
     33= LED Triggers
    5534Through the LED class LED's can be triggered by certain events / items depending on kernel configuration.
    56 </p>
    57 <p>
     35
    5836To show what triggers are available in the current kernel:
    59 </p>
    60 <pre class="wiki"># cat /sys/class/leds/user1/trigger
     37{{{#!bash
     38# cat /sys/class/leds/user1/trigger
    6139[none] nand-disk mmc0 timer default-on netdev gpio heartbeat morse usbdev
    62 </pre><ul><li>the one shown in brackets is the current trigger - to disable triggers set to none (as the example above shows)
    63 </li><li>the default trigger is specified in the board support file or device-tree
    64 </li></ul><p>
     40}}}
     41 * the one shown in brackets is the current trigger - to disable triggers set to none (as the example above shows)
     42 * the default trigger is specified in the board support file or device-tree
     43
    6544To set a trigger:
    66 </p>
    67 <pre class="wiki">echo heartbeat &gt; /sys/class/leds/user1/trigger
    68 </pre><ul><li>the hearbeat trigger blinks the LED twice at the end of every second
    69 </li><li>depending on peripherals installed other triggers may be available such as network or disk activity
    70 </li></ul><h1 id="OtherReferences">Other References</h1>
    71 <p>
     45{{{#!bash
     46echo heartbeat > /sys/class/leds/user1/trigger
     47}}}
     48 * the hearbeat trigger blinks the LED twice at the end of every second
     49 * depending on peripherals installed other triggers may be available such as network or disk activity
     50
     51= Other References
    7252Here are some other useful references from our wiki:
    73 </p>
    74 <ul><li><a class="wiki" href="/wiki/gpio">General Purpose I/O (GPIO)</a>
    75 </li><li><a class="wiki" href="/wiki/linux/pwm">Pulse-Width-Modulation (PWM)</a>
    76 </li><li><a class="wiki" href="/wiki/OpenWrt/gpio">GPIO in OpenWrt</a>
    77 </li><li><a class="wiki" href="/wiki/ventana/DigitalIO">Ventana product family Digital I/O</a>
    78 </li></ul
    79 }}}
     53 * [wiki:gpio General Purpose I/O (GPIO)]
     54 * [wiki:linux/pwm Pulse-Width-Modulation (PWM)]