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}; 86 87enum SerialParity : unsigned char { 88 /* Indicates that the USB device has no parity bit. */ 89 USB_ATTR_PARITY_NONE = 0, 90 /* Indicates that the USB device has an odd parity bit. */ 91 USB_ATTR_PARITY_ODD, 92 /* Indicates that the USB device has an even parity bit. */ 93 USB_ATTR_PARITY_EVEN, 94 /* Indicates that the parity bit is 1. */ 95 USB_ATTR_PARITY_MARK, 96 /* Indicates that the parity bit is 0. */ 97 USB_ATTR_PARITY_SPACE 98}; 99 100enum SerialStopBits : unsigned char { 101 /* that the USB device has 1 stop bit. */ 102 USB_ATTR_STOPBIT_1 = 0, 103 /* Indicates that the USB device has 2 stop bits. */ 104 USB_ATTR_STOPBIT_2 105}; 106 107struct DeviceInfo { 108 unsigned char busNum; 109 unsigned char devAddr; 110 int vid; 111 int pid; 112 String serialNum; 113}; 114 115/** 116 * @brief Defines basic attributes of the USB to serial port. 117 * 118 * You can configure the attributes via {@link SerialSetAttribute}. If the parameters are not set, 119 * default attributes are used. 120 * 121 * @attention The USB controller determines which USB attribute parameters are supported. 122 * 123 */ 124struct SerialAttribute { 125 unsigned int baudrate; 126 unsigned char stopBits; 127 unsigned char parity; 128 unsigned char dataBits; 129}; 130 131struct SerialPort { 132 int portId; 133 DeviceInfo deviceInfo; 134}; 135 136/** 137 * @brief Enumerates USB Serial commands. 138 * 139 */ 140enum SerialIoCmd { 141 USB_SERIAL_GET_PORT_LIST = 0, /**< Get the serial port list. */ 142 USB_SERIAL_OPEN, /**< Reference count management and initialize the USB device. */ 143 USB_SERIAL_CLOSE, /**< Reference count management and deinitialize the USB device. */ 144 USB_SERIAL_READ, /**< Read data. */ 145 USB_SERIAL_WRITE, /**< Write data. */ 146 USB_SERIAL_GET_ATTRIBUTE, /**< Obtain the device attributes. */ 147 USB_SERIAL_SET_ATTRIBUTE /**< Set the device attributes. */ 148};