| // Copyright 2017 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| module device.mojom; |
| |
| import "mojo/public/mojom/base/file_path.mojom"; |
| import "mojo/public/mojom/base/unguessable_token.mojom"; |
| |
| struct SerialPortInfo { |
| mojo_base.mojom.UnguessableToken token; |
| mojo_base.mojom.FilePath path; |
| uint16 vendor_id; |
| bool has_vendor_id = false; |
| uint16 product_id; |
| bool has_product_id = false; |
| string? display_name; |
| }; |
| |
| enum SerialSendError { |
| NONE, |
| DISCONNECTED, |
| PENDING, |
| TIMEOUT, |
| SYSTEM_ERROR, |
| }; |
| |
| enum SerialReceiveError { |
| NONE, |
| DISCONNECTED, |
| TIMEOUT, |
| DEVICE_LOST, |
| BREAK, |
| FRAME_ERROR, |
| OVERRUN, |
| BUFFER_OVERFLOW, |
| PARITY_ERROR, |
| SYSTEM_ERROR, |
| }; |
| |
| enum SerialDataBits { |
| NONE, |
| SEVEN, |
| EIGHT, |
| }; |
| |
| enum SerialParityBit { |
| NONE, |
| NO_PARITY, |
| ODD, |
| EVEN, |
| }; |
| |
| enum SerialStopBits { |
| NONE, |
| ONE, |
| TWO, |
| }; |
| |
| struct SerialConnectionOptions { |
| uint32 bitrate = 0; |
| SerialDataBits data_bits = NONE; |
| SerialParityBit parity_bit = NONE; |
| SerialStopBits stop_bits = NONE; |
| bool cts_flow_control; |
| bool has_cts_flow_control = false; |
| }; |
| |
| struct SerialConnectionInfo { |
| uint32 bitrate = 0; |
| SerialDataBits data_bits = NONE; |
| SerialParityBit parity_bit = NONE; |
| SerialStopBits stop_bits = NONE; |
| bool cts_flow_control; |
| }; |
| |
| struct SerialHostControlSignals { |
| bool dtr; |
| bool has_dtr = false; |
| bool rts; |
| bool has_rts = false; |
| }; |
| |
| struct SerialPortControlSignals { |
| bool dcd; |
| bool cts; |
| bool ri; |
| bool dsr; |
| }; |
| |
| // Discovers and enumerates serial devices available to the host. |
| interface SerialPortManager { |
| GetDevices() => (array<SerialPortInfo> devices); |
| GetPort(mojo_base.mojom.UnguessableToken token, SerialPort& port_request); |
| }; |
| |
| // Performs asynchronous I/O on serial devices. |
| interface SerialPort { |
| // Initiates an Open of the device then returns result. |
| Open(SerialConnectionOptions options, |
| handle<data_pipe_producer> out_stream, |
| associated SerialPortClient client) => (bool success); |
| |
| // Performs a Write operation then returns written data and the result. |
| // Note that the Write may succeed partially, means that even if |error| |
| // indicates an error other than NONE, |bytes_written| bytes have already been |
| // written although it may be <= size of |data|. Behavior is undefined if this |
| // is called while a Write is already pending. |
| Write(array<uint8> data) => (uint32 bytes_written, SerialSendError error); |
| |
| // Try to clear existing read error and reconnect the data pipe for read. |
| // This is supposed to be called after SerialPortClient#OnReadError is |
| // notified. |
| ClearReadError(handle<data_pipe_producer> producer); |
| |
| // Attempts to cancel a pending write operation. |
| CancelWrite(SerialSendError reason); |
| |
| // Flushes input and output buffers. |
| Flush() => (bool success); |
| |
| // Reads current control signals (DCD, CTS, etc.). |
| GetControlSignals() => (SerialPortControlSignals signals); |
| |
| // Sets one or more control signals (DTR and/or RTS) and returns result. |
| SetControlSignals(SerialHostControlSignals signals) => (bool success); |
| |
| // Performs platform-specific port configuration and returns result. |
| ConfigurePort(SerialConnectionOptions options) => (bool success); |
| |
| // Performs a platform-specific port configuration query and returns got info. |
| GetPortInfo() => (SerialConnectionInfo info); |
| |
| // Initiates a BREAK signal. Places the transmission line in a break state |
| // until the |ClearBreak| is called. |
| SetBreak() => (bool success); |
| |
| // Terminates the BREAK signal. Places the transmission line in a nonbreak |
| // state. |
| ClearBreak() => (bool success); |
| }; |
| |
| interface SerialPortClient { |
| OnReadError(SerialReceiveError error); |
| }; |