Changes between Initial Version and Version 1 of linux/led

10/22/2017 05:28:45 AM (2 years ago)



  • linux/led

    v1 v1  
     2          <div id="wikipage" class="trac-content"><p>
     3</p><div class="wiki-toc">
     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>
     20<span class="wikianchor" id="led_class"></span>
     22<h1 id="LinuxLEDclassforGPIOandPWMcontrolledLEDs">Linux LED class for GPIO (and PWM) controlled LEDs</h1>
     24GPIO'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.
     27Mapping 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=""><span class="icon">​</span>gw54xx device-tree</a> for example.
     30LED 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.
     33To list available LED's by name (see product hardware manual to match name to board LED):
     35<pre class="wiki">ls /sys/class/leds
     37To enable/disable LEDs:
     39<pre class="wiki">echo 0 &gt; /sys/class/leds/user1/brightness ;# turn off user1 LED
     40echo 255 &gt; /sys/class/leds/user1/brightness ;# turn on user1 LED
     42Some 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):
     44<pre class="wiki"># turn bi-color LED Green
     45echo 0 &gt; /sys/class/leds/user1/brightness
     46echo 255 &gt; /sys/class/leds/user2/brightness
     47# turn bi-color LED Red
     48echo 255 &gt; /sys/class/leds/user1/brightness
     49echo 0 &gt; /sys/class/leds/user2/brightness
     51<span class="wikianchor" id="led-trigger"></span>
     53<h2 id="LEDTriggers">LED Triggers</h2>
     55Through the LED class LED's can be triggered by certain events / items depending on kernel configuration.
     58To show what triggers are available in the current kernel:
     60<pre class="wiki"># cat /sys/class/leds/user1/trigger
     61[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
     65To set a trigger:
     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>
     72Here are some other useful references from our wiki:
     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>