Path: blob/master/Documentation/DocBook/v4l/lirc_device_interface.xml
10821 views
<section id="lirc_dev">1<title>LIRC Device Interface</title>234<section id="lirc_dev_intro">5<title>Introduction</title>67<para>The LIRC device interface is a bi-directional interface for8transporting raw IR data between userspace and kernelspace. Fundamentally,9it is just a chardev (/dev/lircX, for X = 0, 1, 2, ...), with a number10of standard struct file_operations defined on it. With respect to11transporting raw IR data to and fro, the essential fops are read, write12and ioctl.</para>1314<para>Example dmesg output upon a driver registering w/LIRC:</para>15<blockquote>16<para>$ dmesg |grep lirc_dev</para>17<para>lirc_dev: IR Remote Control driver registered, major 248</para>18<para>rc rc0: lirc_dev: driver ir-lirc-codec (mceusb) registered at minor = 0</para>19</blockquote>2021<para>What you should see for a chardev:</para>22<blockquote>23<para>$ ls -l /dev/lirc*</para>24<para>crw-rw---- 1 root root 248, 0 Jul 2 22:20 /dev/lirc0</para>25</blockquote>26</section>2728<section id="lirc_read">29<title>LIRC read fop</title>3031<para>The lircd userspace daemon reads raw IR data from the LIRC chardev. The32exact format of the data depends on what modes a driver supports, and what33mode has been selected. lircd obtains supported modes and sets the active mode34via the ioctl interface, detailed at <xref linkend="lirc_ioctl"/>. The generally35preferred mode is LIRC_MODE_MODE2, in which packets containing an int value36describing an IR signal are read from the chardev.</para>3738<para>See also <ulink url="http://www.lirc.org/html/technical.html">http://www.lirc.org/html/technical.html</ulink> for more info.</para>39</section>4041<section id="lirc_write">42<title>LIRC write fop</title>4344<para>The data written to the chardev is a pulse/space sequence of integer45values. Pulses and spaces are only marked implicitly by their position. The46data must start and end with a pulse, therefore, the data must always include47an uneven number of samples. The write function must block until the data has48been transmitted by the hardware.</para>49</section>5051<section id="lirc_ioctl">52<title>LIRC ioctl fop</title>5354<para>The LIRC device's ioctl definition is bound by the ioctl function55definition of struct file_operations, leaving us with an unsigned int56for the ioctl command and an unsigned long for the arg. For the purposes57of ioctl portability across 32-bit and 64-bit, these values are capped58to their 32-bit sizes.</para>5960<para>The following ioctls can be used to change specific hardware settings.61In general each driver should have a default set of settings. The driver62implementation is expected to re-apply the default settings when the device63is closed by user-space, so that every application opening the device can rely64on working with the default settings initially.</para>6566<variablelist>67<varlistentry>68<term>LIRC_GET_FEATURES</term>69<listitem>70<para>Obviously, get the underlying hardware device's features. If a driver71does not announce support of certain features, calling of the corresponding72ioctls is undefined.</para>73</listitem>74</varlistentry>75<varlistentry>76<term>LIRC_GET_SEND_MODE</term>77<listitem>78<para>Get supported transmit mode. Only LIRC_MODE_PULSE is supported by lircd.</para>79</listitem>80</varlistentry>81<varlistentry>82<term>LIRC_GET_REC_MODE</term>83<listitem>84<para>Get supported receive modes. Only LIRC_MODE_MODE2 and LIRC_MODE_LIRCCODE85are supported by lircd.</para>86</listitem>87</varlistentry>88<varlistentry>89<term>LIRC_GET_SEND_CARRIER</term>90<listitem>91<para>Get carrier frequency (in Hz) currently used for transmit.</para>92</listitem>93</varlistentry>94<varlistentry>95<term>LIRC_GET_REC_CARRIER</term>96<listitem>97<para>Get carrier frequency (in Hz) currently used for IR reception.</para>98</listitem>99</varlistentry>100<varlistentry>101<term>LIRC_{G,S}ET_{SEND,REC}_DUTY_CYCLE</term>102<listitem>103<para>Get/set the duty cycle (from 0 to 100) of the carrier signal. Currently,104no special meaning is defined for 0 or 100, but this could be used to switch105off carrier generation in the future, so these values should be reserved.</para>106</listitem>107</varlistentry>108<varlistentry>109<term>LIRC_GET_REC_RESOLUTION</term>110<listitem>111<para>Some receiver have maximum resolution which is defined by internal112sample rate or data format limitations. E.g. it's common that signals can113only be reported in 50 microsecond steps. This integer value is used by114lircd to automatically adjust the aeps tolerance value in the lircd115config file.</para>116</listitem>117</varlistentry>118<varlistentry>119<term>LIRC_GET_M{IN,AX}_TIMEOUT</term>120<listitem>121<para>Some devices have internal timers that can be used to detect when122there's no IR activity for a long time. This can help lircd in detecting123that a IR signal is finished and can speed up the decoding process.124Returns an integer value with the minimum/maximum timeout that can be125set. Some devices have a fixed timeout, in that case both ioctls will126return the same value even though the timeout cannot be changed.</para>127</listitem>128</varlistentry>129<varlistentry>130<term>LIRC_GET_M{IN,AX}_FILTER_{PULSE,SPACE}</term>131<listitem>132<para>Some devices are able to filter out spikes in the incoming signal133using given filter rules. These ioctls return the hardware capabilities134that describe the bounds of the possible filters. Filter settings depend135on the IR protocols that are expected. lircd derives the settings from136all protocols definitions found in its config file.</para>137</listitem>138</varlistentry>139<varlistentry>140<term>LIRC_GET_LENGTH</term>141<listitem>142<para>Retrieves the code length in bits (only for LIRC_MODE_LIRCCODE).143Reads on the device must be done in blocks matching the bit count.144The bit could should be rounded up so that it matches full bytes.</para>145</listitem>146</varlistentry>147<varlistentry>148<term>LIRC_SET_{SEND,REC}_MODE</term>149<listitem>150<para>Set send/receive mode. Largely obsolete for send, as only151LIRC_MODE_PULSE is supported.</para>152</listitem>153</varlistentry>154<varlistentry>155<term>LIRC_SET_{SEND,REC}_CARRIER</term>156<listitem>157<para>Set send/receive carrier (in Hz).</para>158</listitem>159</varlistentry>160<varlistentry>161<term>LIRC_SET_TRANSMITTER_MASK</term>162<listitem>163<para>This enables the given set of transmitters. The first transmitter164is encoded by the least significant bit, etc. When an invalid bit mask165is given, i.e. a bit is set, even though the device does not have so many166transitters, then this ioctl returns the number of available transitters167and does nothing otherwise.</para>168</listitem>169</varlistentry>170<varlistentry>171<term>LIRC_SET_REC_TIMEOUT</term>172<listitem>173<para>Sets the integer value for IR inactivity timeout (cf.174LIRC_GET_MIN_TIMEOUT and LIRC_GET_MAX_TIMEOUT). A value of 0 (if175supported by the hardware) disables all hardware timeouts and data should176be reported as soon as possible. If the exact value cannot be set, then177the next possible value _greater_ than the given value should be set.</para>178</listitem>179</varlistentry>180<varlistentry>181<term>LIRC_SET_REC_TIMEOUT_REPORTS</term>182<listitem>183<para>Enable (1) or disable (0) timeout reports in LIRC_MODE_MODE2. By184default, timeout reports should be turned off.</para>185</listitem>186</varlistentry>187<varlistentry>188<term>LIRC_SET_REC_FILTER_{,PULSE,SPACE}</term>189<listitem>190<para>Pulses/spaces shorter than this are filtered out by hardware. If191filters cannot be set independently for pulse/space, the corresponding192ioctls must return an error and LIRC_SET_REC_FILTER shall be used instead.</para>193</listitem>194</varlistentry>195<varlistentry>196<term>LIRC_SET_MEASURE_CARRIER_MODE</term>197<listitem>198<para>Enable (1)/disable (0) measure mode. If enabled, from the next key199press on, the driver will send LIRC_MODE2_FREQUENCY packets. By default200this should be turned off.</para>201</listitem>202</varlistentry>203<varlistentry>204<term>LIRC_SET_REC_{DUTY_CYCLE,CARRIER}_RANGE</term>205<listitem>206<para>To set a range use LIRC_SET_REC_DUTY_CYCLE_RANGE/LIRC_SET_REC_CARRIER_RANGE207with the lower bound first and later LIRC_SET_REC_DUTY_CYCLE/LIRC_SET_REC_CARRIER208with the upper bound.</para>209</listitem>210</varlistentry>211<varlistentry>212<term>LIRC_NOTIFY_DECODE</term>213<listitem>214<para>This ioctl is called by lircd whenever a successful decoding of an215incoming IR signal could be done. This can be used by supporting hardware216to give visual feedback to the user e.g. by flashing a LED.</para>217</listitem>218</varlistentry>219<varlistentry>220<term>LIRC_SETUP_{START,END}</term>221<listitem>222<para>Setting of several driver parameters can be optimized by encapsulating223the according ioctl calls with LIRC_SETUP_START/LIRC_SETUP_END. When a224driver receives a LIRC_SETUP_START ioctl it can choose to not commit225further setting changes to the hardware until a LIRC_SETUP_END is received.226But this is open to the driver implementation and every driver must also227handle parameter changes which are not encapsulated by LIRC_SETUP_START228and LIRC_SETUP_END. Drivers can also choose to ignore these ioctls.</para>229</listitem>230</varlistentry>231<varlistentry>232<term>LIRC_SET_WIDEBAND_RECEIVER</term>233<listitem>234<para>Some receivers are equipped with special wide band receiver which is intended235to be used to learn output of existing remote.236Calling that ioctl with (1) will enable it, and with (0) disable it.237This might be useful of receivers that have otherwise narrow band receiver238that prevents them to be used with some remotes.239Wide band receiver might also be more precise240On the other hand its disadvantage it usually reduced range of reception.241Note: wide band receiver might be implictly enabled if you enable242carrier reports. In that case it will be disabled as soon as you disable243carrier reports. Trying to disable wide band receiver while carrier244reports are active will do nothing.</para>245</listitem>246</varlistentry>247</variablelist>248249</section>250</section>251252253