1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup HdiSerial 18 * 19 * 20 * @brief Provides unified APIs for serial services to access serial drivers. 21 * 22 * A serial service can obtain a serial driver object or agent and then call APIs provided by this object or agent to 23 * access different types of serial devices based on the serial IDs, thereby obtaining serial information, 24 * subscribing to or unsubscribing from serial data, enabling or disabling a serial, 25 * setting the serial data reporting mode, and setting serial options such as the accuracy and measurement range. 26 * 27 * @since 5.1 28 */ 29 30 /** 31 * @file UsbTypes.idl 32 * 33 * @brief Defines the data used by the serial module, including the serial information, 34 * and reported serial data. 35 * 36 * @since 5.1 37 * @version 1.0 38 */ 39 40 41package ohos.hdi.usb.serial.v1_0; 42 43enum SerialBaudrate : unsigned int { 44 BAUDRATE_50 = 50, 45 BAUDRATE_75 = 75, 46 BAUDRATE_110 = 110, 47 BAUDRATE_134 = 134, 48 BAUDRATE_150 = 150, 49 BAUDRATE_200 = 200, 50 BAUDRATE_300 = 300, 51 BAUDRATE_600 = 600, 52 BAUDRATE_1200 = 1200, 53 BAUDRATE_1800 = 1800, 54 BAUDRATE_2400 = 2400, 55 BAUDRATE_4800 = 4800, 56 BAUDRATE_9600 = 9600, 57 BAUDRATE_19200 = 19200, 58 BAUDRATE_38400 = 38400, 59 BAUDRATE_57600 = 57600, 60 BAUDRATE_115200 = 115200, 61 BAUDRATE_230400 = 230400, 62 BAUDRATE_460800 = 460800, 63 BAUDRATE_500000 = 500000, 64 BAUDRATE_576000 = 576000, 65 BAUDRATE_921600 = 921600, 66 BAUDRATE_1000000 = 1000000, 67 BAUDRATE_1152000 = 1152000, 68 BAUDRATE_1500000 = 1500000, 69 BAUDRATE_2000000 = 2000000, 70 BAUDRATE_2500000 = 2500000, 71 BAUDRATE_3000000 = 3000000, 72 BAUDRATE_3500000 = 3500000, 73 BAUDRATE_4000000 = 4000000 74}; 75 76enum SerialDataBits : unsigned char { 77 /* Indicates the USB word length, which is 8 data bits per frame. */ 78 USB_ATTR_DATABIT_8 = 0, 79 /* Indicates the USB word length, which is 7 data bits per frame. */ 80 USB_ATTR_DATABIT_7, 81 /* Indicates the USB word length, which is 6 data bits per frame. */ 82 USB_ATTR_DATABIT_6, 83 /* Indicates the USB word length, which is 5 data bits per frame. */ 84 USB_ATTR_DATABIT_5, 85 /* Indicates the USB word length, which is 4 data bits per frame. */ 86 USB_ATTR_DATABIT_4 87}; 88 89enum SerialParity : unsigned char { 90 /* Indicates that the USB device has no parity bit. */ 91 USB_ATTR_PARITY_NONE = 0, 92 /* Indicates that the USB device has an odd parity bit. */ 93 USB_ATTR_PARITY_ODD, 94 /* Indicates that the USB device has an even parity bit. */ 95 USB_ATTR_PARITY_EVEN, 96 /* Indicates that the parity bit is 1. */ 97 USB_ATTR_PARITY_MARK, 98 /* Indicates that the parity bit is 0. */ 99 USB_ATTR_PARITY_SPACE 100}; 101 102enum SerialStopBits : unsigned char { 103 /* that the USB device has 1 stop bit. */ 104 USB_ATTR_STOPBIT_1 = 0, 105 /* Indicates that the USB device has 1.5 stop bits. */ 106 USB_ATTR_STOPBIT_1P5, 107 /* Indicates that the USB device has 2 stop bits. */ 108 USB_ATTR_STOPBIT_2 109}; 110 111struct DeviceInfo { 112 unsigned char busNum; 113 unsigned char devAddr; 114 int vid; 115 int pid; 116 String serialNum; 117}; 118 119/** 120 * @brief Defines basic attributes of the USB to serial port. 121 * 122 * You can configure the attributes via {@link SerialSetAttribute}. If the parameters are not set, 123 * default attributes are used. 124 * 125 * @attention The USB controller determines which USB attribute parameters are supported. 126 * 127 */ 128struct SerialAttribute { 129 unsigned int baudrate; 130 unsigned char stopBits; 131 unsigned char parity; 132 unsigned char dataBits; 133}; 134 135struct SerialPort { 136 int portId; 137 DeviceInfo deviceInfo; 138}; 139 140/** 141 * @brief Enumerates USB Serial commands. 142 * 143 */ 144enum SerialIoCmd { 145 USB_SERIAL_GET_PORT_LIST = 0, /**< Get the serial port list. */ 146 USB_SERIAL_OPEN, /**< Reference count management and initialize the USB device. */ 147 USB_SERIAL_CLOSE, /**< Reference count management and deinitialize the USB device. */ 148 USB_SERIAL_READ, /**< Read data. */ 149 USB_SERIAL_WRITE, /**< Write data. */ 150 USB_SERIAL_GET_ATTRIBUTE, /**< Obtain the device attributes. */ 151 USB_SERIAL_SET_ATTRIBUTE /**< Set the device attributes. */ 152};