xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/rc/lirc-write.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2*4882a593Smuzhiyun.. c:namespace:: RC
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun.. _lirc-write:
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun************
7*4882a593SmuzhiyunLIRC write()
8*4882a593Smuzhiyun************
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunName
11*4882a593Smuzhiyun====
12*4882a593Smuzhiyun
13*4882a593Smuzhiyunlirc-write - Write to a LIRC device
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunSynopsis
16*4882a593Smuzhiyun========
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun.. code-block:: c
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun    #include <unistd.h>
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun.. c:function:: ssize_t write( int fd, void *buf, size_t count )
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunArguments
25*4882a593Smuzhiyun=========
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun``fd``
28*4882a593Smuzhiyun    File descriptor returned by ``open()``.
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun``buf``
31*4882a593Smuzhiyun    Buffer with data to be written
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun``count``
34*4882a593Smuzhiyun    Number of bytes at the buffer
35*4882a593Smuzhiyun
36*4882a593SmuzhiyunDescription
37*4882a593Smuzhiyun===========
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun:c:func:`write()` writes up to ``count`` bytes to the device
40*4882a593Smuzhiyunreferenced by the file descriptor ``fd`` from the buffer starting at
41*4882a593Smuzhiyun``buf``.
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunThe exact format of the data depends on what mode a driver is in, use
44*4882a593Smuzhiyun:ref:`lirc_get_features` to get the supported modes and use
45*4882a593Smuzhiyun:ref:`lirc_set_send_mode` set the mode.
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunWhen in :ref:`LIRC_MODE_PULSE <lirc-mode-PULSE>` mode, the data written to
48*4882a593Smuzhiyunthe chardev is a pulse/space sequence of integer values. Pulses and spaces
49*4882a593Smuzhiyunare only marked implicitly by their position. The data must start and end
50*4882a593Smuzhiyunwith a pulse, therefore, the data must always include an uneven number of
51*4882a593Smuzhiyunsamples. The write function blocks until the data has been transmitted
52*4882a593Smuzhiyunby the hardware. If more data is provided than the hardware can send, the
53*4882a593Smuzhiyundriver returns ``EINVAL``.
54*4882a593Smuzhiyun
55*4882a593SmuzhiyunWhen in :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` mode, one
56*4882a593Smuzhiyun``struct lirc_scancode`` must be written to the chardev at a time, else
57*4882a593Smuzhiyun``EINVAL`` is returned. Set the desired scancode in the ``scancode`` member,
58*4882a593Smuzhiyunand the :ref:`IR protocol <Remote_controllers_Protocols>` in the
59*4882a593Smuzhiyun:c:type:`rc_proto`: member. All other members must be
60*4882a593Smuzhiyunset to 0, else ``EINVAL`` is returned. If there is no protocol encoder
61*4882a593Smuzhiyunfor the protocol or the scancode is not valid for the specified protocol,
62*4882a593Smuzhiyun``EINVAL`` is returned. The write function blocks until the scancode
63*4882a593Smuzhiyunis transmitted by the hardware.
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunReturn Value
66*4882a593Smuzhiyun============
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunOn success, the number of bytes written is returned. It is not an error if
69*4882a593Smuzhiyunthis number is smaller than the number of bytes requested, or the amount
70*4882a593Smuzhiyunof data required for one frame.  On error, -1 is returned, and the ``errno``
71*4882a593Smuzhiyunvariable is set appropriately. The generic error codes are described at the
72*4882a593Smuzhiyun:ref:`Generic Error Codes <gen-errors>` chapter.
73