title: IR remote control using LIRC. (NEC)
body: <p>I am working on Imx8mm evk and yocto project.</p>
  
  <p>I have been trying ir-receiver solution.</p>
  
  <p>The Remote Control is using the NEC IR Protocol.</p>
  
  <p><strong>1. GPIO setting</strong></p>
  
  <ul>
  <li><p>IR receiver is connected to GPIO13.</p></li>
  <li><p>Edit fsl-imx8mm-evk.dts</p>
  
  <pre><code>{             
      ir_recv {
          compatible = "gpio-ir-receiver";
          gpios = &lt;&amp;gpio1 13 GPIO_ACTIVE_HIGH&gt;;
          pinctrl-names = "default";
          pinctrl-0 = &lt;&amp;pinctrl_ir&gt;;
      };
                            :
                            :
                            :
  };
  
  &amp;iomuxc {
      pinctrl-names = "default";
  
      pinctrl_ir: irgrp {
          fsl,pins = &lt;
              MX8MM_IOMUXC_GPIO1_IO13_GPIO1_IO13        0x1d6
          &gt;;
      };                      
                            :
                            :
                            :
  </code></pre></li>
  <li><p>GPIO13 : Input and pull-up mode</p>
  
  <pre><code>root@imx8mmevk:~# cat /sys/kernel/debug/gpio
  gpiochip0: GPIOs 0-31, parent: platform/30200000.gpio, 30200000.gpio:
  gpio-13  (                    |gpio-ir-recv        ) in  hi IRQ
  gpio-15  (                    |cd                  ) in  lo IRQ
  </code></pre></li>
  <li><p>Enable GPIO IR remote control</p>
  
  <pre><code>menuconfig ---&gt; Device Drivers ---&gt; Remote Controller devices ---&gt; &lt;*&gt; GPIO IR remote control 
  </code></pre></li>
  </ul>
  
  <p><strong>2. LIRC install</strong></p>
  
  <ul>
  <li><p>Edit the local.conf file</p>
  
  <p>Add this line.</p>
  
  <pre><code>IMAGE_INSTALL_append = " lirc"
  </code></pre></li>
  <li><p>lircd version and check lirc driver</p>
  
  <pre><code>root@imx8mmevk:~# lircd -version
  lircd 0.9.4d
  root@imx8mmevk:~# dmesg | grep "LIRC" -i
  [    1.455517] lirc_dev: IR Remote Control driver registered, major 236
  [    1.500490] IR LIRC bridge handler initialized
  [    1.535966] rc rc0: lirc_dev: driver ir-lirc-codec (gpio-rc-recv) registered at minor = 0
  </code></pre></li>
  </ul>
  
  <p><strong>3. TEST remote using mode2 command</strong></p>
  
  <ul>
  <li><p>Stop and check status lirc driver</p>
  
  <pre><code>root@imx8mmevk:~# systemctl stop lircd.socket lircd.service
  root@imx8mmevk:~# systemctl status lircd.socket lircd.service
  ● lircd.socket
     Loaded: loaded (/lib/systemd/system/lircd.socket; disabled; vendor preset: e&gt;
     Active: inactive (dead) since Thu 2019-09-26 07:17:02 UTC; 2min 19s ago
     Listen: /run/lirc/lircd (Stream)
  
  Sep 26 06:59:56 imx8mmevk systemd[1]: Listening on lircd.socket.
  Sep 26 07:17:02 imx8mmevk systemd[1]: Closed lircd.socket.
  
  ● lircd.service - LIRC Infrared Signal Decoder
     Loaded: loaded (/lib/systemd/system/lircd.service; enabled; vendor preset: e&gt;
     Active: inactive (dead) since Thu 2019-09-26 07:17:02 UTC; 2min 19s ago
    Process: 3653 ExecStopPost=/bin/rm -fR /run/lirc (code=exited, status=0/SUCCE&gt;
    Process: 3652 ExecStopPost=/bin/rm -f /dev/lircd (code=exited, status=0/SUCCE&gt;
    Process: 3617 ExecStart=/usr/sbin/lircd --pidfile=/run/lirc/lircd.pid --devic&gt;
    Process: 3615 ExecStartPre=/bin/ln -s /run/lirc/lircd /dev/lircd (code=exited&gt;
    Process: 3603 ExecStartPre=/bin/rm -f /run/lirc/lircd (code=exited, status=0/&gt;
    Process: 3602 ExecStartPre=/bin/rm -f /dev/lircd (code=exited, status=0/SUCCE&gt;
    Process: 3601 ExecStartPre=/bin/mkdir -p /run/lirc (code=exited, status=0/SUC&gt;
   Main PID: 3622 (code=killed, signal=TERM)
  
  Sep 26 06:59:58 imx8mmevk systemd[1]: Starting LIRC Infrared Signal Decoder...
  Sep 26 06:59:58 imx8mmevk systemd[1]: Started LIRC Infrared Signal Decoder.
  Sep 26 07:17:02 imx8mmevk systemd[1]: Stopping LIRC Infrared Signal Decoder...
  </code></pre></li>
  <li><p>Run mode2 and test remote control</p>
  
  <pre><code>root@imx8mmevk:~# mode2 --driver default --device /dev/lirc0
  Using driver default on device /dev/lirc0
  Trying device: /dev/lirc0
  Using device: /dev/lirc0
  Warning: Running as root.
  </code></pre>
  
  <p>Pressing button on my remote control (NEC protocol)</p>
  
  <pre><code>space 13301060
  pulse 399019
  space 9015
  pulse 4474
  space 594
  pulse 1661
  space 574
  pulse 556
  space 575
  pulse 556
  space 575
  pulse 555
  space 574
  pulse 557
  space 574
  pulse 557
  space 574
  pulse 557
  space 573
  pulse 558
  space 573
  pulse 558
  space 574
  pulse 1663
  space 573
  pulse 1664
  space 572
  pulse 1663
  space 573
  pulse 1664
  space 572
  pulse 1663
  space 573
  pulse 1664
  space 573
  pulse 1663
  space 573
  pulse 1665
  space 572
  pulse 1664
  space 573
  pulse 558
  space 572
  pulse 1664
  space 573
  pulse 558
  space 572
  pulse 558
  space 572
  pulse 558
  space 572
  pulse 558
  space 573
  pulse 557
  space 572
  pulse 559
  space 572
  pulse 1665
  space 571
  pulse 558
  space 572
  pulse 1664
  space 573
  pulse 1663
  space 572
  pulse 1665
  space 571
  pulse 1664
  space 572
  </code></pre>
  
  <p>But, I don't understand first and last log.</p>
  
  <p><strong>space 13301060, space 572</strong></p>
  
  <p><a href="https://i.stack.imgur.com/mrlAT.png" rel="nofollow noreferrer">Logic Analyzer - capture signal</a></p>
  
  <p>Start and End logic is High.</p>
  
  <p>But, mode2 first and last log is space.. </p>
  
  <p>I know 'space' is logic low time.</p>
  
  <p>Is there anything wrong?</p>
  
  <p>Please suggest me how can I supposed to solve.</p>
  
  <p>Thank you!!</p></li>
  <li><p>irrecord</p>
  
  <pre><code>root@imx8mmevk:~# irrecord -n -d /dev/lirc0 test_remote.conf
  Warning: Running as root.
  Using driver default on device /dev/lirc0
  
  irrecord -  application for recording IR-codes for usage with lirc
  Copyright (C) 1998,1999 Christoph Bartelmus(lirc@bartelmus.de)
  
  This program will record the signals from your remote control
  and create a config file for lircd.
  
  A proper config file for lircd is maybe the most vital part of this
  package, so you should invest some time to create a working config
  file. Although I put a good deal of effort in this program it is often
  not possible to automatically recognize all features of a remote
  control. Often short-comings of the receiver hardware make it nearly
  impossible. If you have problems to create a config file READ THE
  DOCUMENTATION at https://sf.net/p/lirc-remotes/wiki
  
  If there already is a remote control of the same brand available at
  http://sf.net/p/lirc-remotes you might want to try using such a
  remote as a template. The config files already contains all
  parameters of the protocol used by remotes of a certain brand and
  knowing these parameters makes the job of this program much
  easier. There are also template files for the most common protocols
  available. Templates can be downloaded using irdb-get(1). You use a
  template file by providing the path of the file as a command line
  parameter.
  
  Please take the time to finish the file as described in
  https://sourceforge.net/p/lirc-remotes/wiki/Checklist/ an send it
  to  &lt;lirc@bartelmus.de&gt; so it can be made available to others.
  
  Press RETURN to continue.
  
  Checking for ambient light  creating too much disturbances.
  Please don't press any buttons, just wait a few seconds...
  
  No significant noise (received 0 bytes)
  
  Enter name of remote (only ascii, no spaces) :NEC1
  Using NEC1.lircd.conf as output filename
  
  Now start pressing buttons on your remote control.
  
  It is very important that you press many different buttons randomly
  and hold them down for approximately one second. Each button should
  generate at least one dot but never more than ten dots of output.
  Don't stop pressing buttons until two lines of dots (2x80) have
  been generated.
  
  Press RETURN now to start recording.
  ................................................................................
  Got gap (8996 us)}
  
  Please keep on pressing buttons like described above.
  Cannot find any gap, using an arbitrary 50 ms one. If you have a
  regular remote for e. g., a TV or such this is probably a point
  where you hit control-C. However, technical hardware like air
  condition gear often works without any gap. If you think it's
  reasonable that your remote lacks gap you can proceed.
  Press RETURN to continue.
  
  
  Please enter the name for the next button (press &lt;ENTER&gt; to finish recording)
  KEY_POWER
  
  Now hold down button "KEY_POWER".
  
  Please enter the name for the next button (press &lt;ENTER&gt; to finish recording)
  KEY_MODE
  
  Now hold down button "KEY_MODE".
  
  Please enter the name for the next button (press &lt;ENTER&gt; to finish recording)
  KEY_1
  
  Now hold down button "KEY_1".
  
  Please enter the name for the next button (press &lt;ENTER&gt; to finish recording)
  KEY_2
  
  Now hold down button "KEY_2".
  
  Please enter the name for the next button (press &lt;ENTER&gt; to finish recording)
  
  Checking for toggle bit mask.
  Please press an arbitrary button repeatedly as fast as possible.
  Make sure you keep pressing the SAME button and that you DON'T HOLD
  the button down!.
  If you can't see any dots appear, wait a bit between button presses.
  
  Press RETURN to continue.
  Cannot find any toggle mask.
  
  Successfully written config file NEC1.lircd.conf
  </code></pre></li>
  <li><p>NEC1.lircd.conf</p>
  
  <pre><code>begin remote
  
  name  NEC1
  bits            0
  eps             0
  aeps            0
  
  one             0     0
  zero            0     0
  gap          50000
  toggle_bit_mask 0x0
  frequency    38000
  
      begin codes
          KEY_POWER                0x0
          KEY_MODE                 0x0
          KEY_1                    0x0
          KEY_2                    0x0
      end codes
  
  end remote
  </code></pre></li>
  </ul>