Changes between Initial Version and Version 1 of linux/led


Ignore:
Timestamp:
10/22/2017 05:28:45 AM (7 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • linux/led

    v1 v1  
     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>
     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.
     25</p>
     26<p>
     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="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>
     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.
     31</p>
     32<p>
     33To 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>
     37To enable/disable LEDs:
     38</p>
     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
     41</pre><p>
     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):
     43</p>
     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
     50</pre><p>
     51<span class="wikianchor" id="led-trigger"></span>
     52</p>
     53<h2 id="LEDTriggers">LED Triggers</h2>
     54<p>
     55Through the LED class LED's can be triggered by certain events / items depending on kernel configuration.
     56</p>
     57<p>
     58To show what triggers are available in the current kernel:
     59</p>
     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
     64</li></ul><p>
     65To 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>
     72Here 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}}}