xref: /aosp_15_r20/external/pigweed/pw_stream_uart_linux/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_stream_uart_linux:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker====================
4*61c4878aSAndroid Build Coastguard Workerpw_stream_uart_linux
5*61c4878aSAndroid Build Coastguard Worker====================
6*61c4878aSAndroid Build Coastguard Worker``pw_stream_uart_linux`` implements the
7*61c4878aSAndroid Build Coastguard Worker:cpp:class:`pw::stream::NonSeekableReaderWriter` interface for reading from and
8*61c4878aSAndroid Build Coastguard Workerwriting to a UART using Linux TTY interfaces.
9*61c4878aSAndroid Build Coastguard Worker
10*61c4878aSAndroid Build Coastguard Worker.. note::
11*61c4878aSAndroid Build Coastguard Worker  This module will likely be superseded by a future ``pw_uart`` interface.
12*61c4878aSAndroid Build Coastguard Worker
13*61c4878aSAndroid Build Coastguard WorkerC++
14*61c4878aSAndroid Build Coastguard Worker===
15*61c4878aSAndroid Build Coastguard Worker.. doxygenclass:: pw::stream::UartStreamLinux
16*61c4878aSAndroid Build Coastguard Worker   :members:
17*61c4878aSAndroid Build Coastguard Worker
18*61c4878aSAndroid Build Coastguard WorkerExamples
19*61c4878aSAndroid Build Coastguard Worker========
20*61c4878aSAndroid Build Coastguard WorkerA simple example illustrating only changing baud-rate and writing to a UART:
21*61c4878aSAndroid Build Coastguard Worker
22*61c4878aSAndroid Build Coastguard Worker.. code-block:: cpp
23*61c4878aSAndroid Build Coastguard Worker
24*61c4878aSAndroid Build Coastguard Worker   constexpr const char* kUartPath = "/dev/ttyS0";
25*61c4878aSAndroid Build Coastguard Worker   constexpr pw::stream::UartStreamLinux::Config kConfig = {
26*61c4878aSAndroid Build Coastguard Worker     .baud_rate = 115200,
27*61c4878aSAndroid Build Coastguard Worker    // Flow control is unmodified on tty.
28*61c4878aSAndroid Build Coastguard Worker   };
29*61c4878aSAndroid Build Coastguard Worker   pw::stream::UartStreamLinux stream;
30*61c4878aSAndroid Build Coastguard Worker   PW_TRY(stream.Open(kUartPath, kConfig));
31*61c4878aSAndroid Build Coastguard Worker
32*61c4878aSAndroid Build Coastguard Worker   std::array<std::byte, 10> to_write = {};
33*61c4878aSAndroid Build Coastguard Worker   PW_TRY(stream.Write(to_write));
34*61c4878aSAndroid Build Coastguard Worker
35*61c4878aSAndroid Build Coastguard Worker
36*61c4878aSAndroid Build Coastguard WorkerA simple example illustrating enabling flow control and writing to a UART:
37*61c4878aSAndroid Build Coastguard Worker
38*61c4878aSAndroid Build Coastguard Worker.. code-block:: cpp
39*61c4878aSAndroid Build Coastguard Worker
40*61c4878aSAndroid Build Coastguard Worker   constexpr const char* kUartPath = "/dev/ttyS0";
41*61c4878aSAndroid Build Coastguard Worker   constexpr pw::stream::UartStreamLinux::Config kConfig = {
42*61c4878aSAndroid Build Coastguard Worker     .baud_rate = 115200,
43*61c4878aSAndroid Build Coastguard Worker     .flow_control = true, // Enable hardware flow control.
44*61c4878aSAndroid Build Coastguard Worker   };
45*61c4878aSAndroid Build Coastguard Worker   pw::stream::UartStreamLinux stream;
46*61c4878aSAndroid Build Coastguard Worker   PW_TRY(stream.Open(kUartPath, kConfig));
47*61c4878aSAndroid Build Coastguard Worker
48*61c4878aSAndroid Build Coastguard Worker   std::array<std::byte, 10> to_write = {};
49*61c4878aSAndroid Build Coastguard Worker   PW_TRY(stream.Write(to_write));
50*61c4878aSAndroid Build Coastguard Worker
51*61c4878aSAndroid Build Coastguard WorkerCaveats
52*61c4878aSAndroid Build Coastguard Worker=======
53*61c4878aSAndroid Build Coastguard WorkerNo interfaces are supplied for configuring data bits, stop bits, or parity.
54*61c4878aSAndroid Build Coastguard WorkerThese attributes are left as they are already configured on the TTY; only the
55*61c4878aSAndroid Build Coastguard Workerspeed or flow control is modified.
56