diff --git a/usb/bundle.json b/usb/bundle.json index 8fdca89e462c86820fdfaabe810191152b625471..76915c6fad4ea403ad553caf9aef741589e6d0c1 100644 --- a/usb/bundle.json +++ b/usb/bundle.json @@ -32,6 +32,7 @@ "sub_component": [ "//drivers/interface/usb/v1_0:usb_idl_target", "//drivers/interface/usb/v1_1:usb_idl_target", + "//drivers/interface/usb/serial/v1_0:serial_idl_target", "//drivers/interface/usb/gadget/mtp/v1_0:usbfn_mtp_idl_target", "//drivers/interface/usb/ddk/v1_0:usb_ddk_idl_target" ], @@ -120,8 +121,29 @@ "header_files": [], "header_base": "//drivers/interface/usb" } + }, + { + "name": "//drivers/interface/usb/serial/v1_0:libserial_proxy_1.0", + "header": { + "header_files": [], + "header_base": "//drivers/interface/usb/serial" + } + }, + { + "name": "//drivers/interface/usb/serial/v1_0:libserial_stub_1.0", + "header": { + "header_files": [], + "header_base": "//drivers/interface/usb/serial" + } + }, + { + "name": "//drivers/interface/usb/serial/v1_0:serial_idl_headers", + "header": { + "header_files": [], + "header_base": "//drivers/interface/usb/serial" + } } ] } } -} \ No newline at end of file +} diff --git a/usb/serial/v1_0/BUILD.gn b/usb/serial/v1_0/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b7b1b99bc1a7b7d2fc6e1cbe26251c9b24338613 --- /dev/null +++ b/usb/serial/v1_0/BUILD.gn @@ -0,0 +1,26 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/hdi/hdi.gni") +hdi("serial") { + module_name = "serial" + + sources = [ + "ISerialInterface.idl", + "SerialTypes.idl", + ] + + language = "cpp" + subsystem_name = "hdf" + part_name = "drivers_interface_usb" +} diff --git a/usb/serial/v1_0/ISerialInterface.idl b/usb/serial/v1_0/ISerialInterface.idl new file mode 100644 index 0000000000000000000000000000000000000000..27e78341cc497445823934059e0d62e211e0bc8e --- /dev/null +++ b/usb/serial/v1_0/ISerialInterface.idl @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* * + * @addtogroup HdiSerial + * @{ + * + * @brief Provides unified APIs for serial services to access serial drivers. + * + * A serial service can obtain a serial driver object or agent and then call APIs provided by this object or agent to + * access different types of serial devices based on the serial IDs, thereby obtaining serial information, + * subscribing to or unsubscribing from serial data, enabling or disabling a serial, + * setting the serial data reporting mode, and setting serial options such as the accuracy and measurement range. + * + * @since 5.0 + */ + +/* * + * @file ISerialInterface.idl + * + * @brief Declares the APIs provided by the serial module for obtaining serial information, subscribing to or + * unsubscribing from serial data, enabling or disabling a serial, setting the serial data reporting mode, + * and setting serial options such as the accuracy and measurement range. + * + * @since 5.0 + * @version 1.0 + */ + +package ohos.hdi.usb.serial.v1_0; +import ohos.hdi.usb.serial.v1_0.SerialTypes; + +/* * + * @brief Defines the functions for performing basic operations on serial. + * + * The operations include obtaining serial port list information, opening and closing serial port, + * reading or writing serial port data, and setting or obtaining serial port properties. + */ +interface ISerialInterface { + + /** + * @brief Open and configure the serial port. + * + * Initializes and opens a serial communication port and sets communication parameters such as baud rate + * and parity. + * + * @param portId Indicates the Serial port device portId. + * + * @return Returns 0 if the setting is successful; returns a negative number otherwise. + */ + SerialOpen([in] int portId); + + /** + * @brief Close the serial port and release resources. + * + * Terminate the connection to the serial port, ensuring that the port and associated resources are released + * after all data transfers are complete. + * + * @param portId Indicates the Serial port device portId. + * + * @return Returns 0 if the setting is successful; returns a negative number otherwise. + */ + SerialClose([in] int portId); + + /** + * @brief Read data from the serial port. + * + * @param portId Indicates the Serial port device portId + * @param data Indicates the pointer to the buffer for receiving the data. + * + * @return Returns the size of the data that is successfully read; returns a negative number if the reading fails. + */ + SerialRead([in] int portId, [out] unsigned char []data); + + /** + * @brief Read data from the serial port. + * + * @param portId Indicates the Serial port device portId + * @param data Indicates the pointer to the data to write. + * + * @return Returns the size of the data that is successfully write; returns a negative number if the reading + * fails. + */ + SerialWrite([in] int portId, [in] unsigned char []data); + + /** + * @brief Sets the SERIAL attribute. + * + * SERIAL attributes include data bits, stop bits, parity bit, CTS, RTS, and receiving and transmitting FIFO. + * + * @param portId Indicates the Serial port device portId + * @param attribute Indicates the pointer to the SERIAL attribute to set. + * + * @return Returns 0 if the setting is successful; returns a negative number otherwise. + */ + SerialSetAttribute([in] int portId, [in] struct SerialAttribute []attribute); + + /** + * @brief Obtains the SERIAL attribute. + * + * SERIAL attributes include data bits, stop bits, parity bit, CTS, RTS, and receiving and transmitting FIFO. + * + * @param portId Indicates the Serial port device portId + * @param attribute Indicates the pointer to the obtained SERIAL attribute. + * + * @return Returns 0 if the setting is successful; returns a negative number otherwise. + */ + SerialGetAttribute([in] int portId, [out] struct SerialAttribute []attribute); + + /** + * @brief Obtains the SERIAL Port list. + * + * @param portId Indicates the Serial port device portId + * + * @return Returns 0 if the setting is successful; returns a negative number otherwise. + */ + SerialGetPortList([in] int []portId); +} + + diff --git a/usb/serial/v1_0/SerialTypes.idl b/usb/serial/v1_0/SerialTypes.idl new file mode 100644 index 0000000000000000000000000000000000000000..9e281e6bca2b93cdf7e226cff1911924b2ef206d --- /dev/null +++ b/usb/serial/v1_0/SerialTypes.idl @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup HdiSerial + * @{ + * + * @brief Provides unified APIs for serial services to access serial drivers. + * + * A serial service can obtain a serial driver object or agent and then call APIs provided by this object or agent to + * access different types of serial devices based on the serial IDs, thereby obtaining serial information, + * subscribing to or unsubscribing from serial data, enabling or disabling a serial, + * setting the serial data reporting mode, and setting serial options such as the accuracy and measurement range. + * + * @since 5.0 + */ + +/** + * @file UsbTypes.idl + * + * @brief Defines the data used by the serial module, including the serial information, + * and reported serial data. + * + * @since 5.0 + * @version 1.0 + */ + + +package ohos.hdi.usb.serial.v1_0; + +enum SerialBaudrate : unsigned int { + BAUDRATE_50 = 50, + BAUDRATE_75 = 75, + BAUDRATE_110 = 110, + BAUDRATE_134 = 134, + BAUDRATE_150 = 150, + BAUDRATE_200 = 200, + BAUDRATE_300 = 300, + BAUDRATE_600 = 600, + BAUDRATE_1200 = 1200, + BAUDRATE_1800 = 1800, + BAUDRATE_2400 = 2400, + BAUDRATE_4800 = 4800, + BAUDRATE_9600 = 9600, + BAUDRATE_19200 = 19200, + BAUDRATE_38400 = 38400, + BAUDRATE_57600 = 57600, + BAUDRATE_115200 = 115200, + BAUDRATE_230400 = 230400, + BAUDRATE_460800 = 460800, + BAUDRATE_500000 = 500000, + BAUDRATE_576000 = 576000, + BAUDRATE_921600 = 921600, + BAUDRATE_1000000 = 1000000, + BAUDRATE_1152000 = 1152000, + BAUDRATE_1500000 = 1500000, + BAUDRATE_2000000 = 2000000, + BAUDRATE_2500000 = 2500000, + BAUDRATE_3000000 = 3000000, + BAUDRATE_3500000 = 3500000, + BAUDRATE_4000000 = 4000000 +}; + +enum SerialDataBits : unsigned char { + /* Indicates the USB word length, which is 8 data bits per frame. */ + USB_ATTR_DATABIT_8 = 0, + /* Indicates the USB word length, which is 7 data bits per frame. */ + USB_ATTR_DATABIT_7, + /* Indicates the USB word length, which is 6 data bits per frame. */ + USB_ATTR_DATABIT_6, + /* Indicates the USB word length, which is 5 data bits per frame. */ + USB_ATTR_DATABIT_5, + /* Indicates the USB word length, which is 4 data bits per frame. */ + USB_ATTR_DATABIT_4 +}; + +enum SerialParity : unsigned char { + /* Indicates that the USB device has no parity bit. */ + USB_ATTR_PARITY_NONE = 0, + /* Indicates that the USB device has an odd parity bit. */ + USB_ATTR_PARITY_ODD, + /* Indicates that the USB device has an even parity bit. */ + USB_ATTR_PARITY_EVEN, + /* Indicates that the parity bit is 1. */ + USB_ATTR_PARITY_MARK, + /* Indicates that the parity bit is 0. */ + USB_ATTR_PARITY_SPACE +}; + +enum SerialStopBits : unsigned char { + /* that the USB device has 1 stop bit. */ + USB_ATTR_STOPBIT_1 = 0, + /* Indicates that the USB device has 1.5 stop bits. */ + USB_ATTR_STOPBIT_1P5, + /* Indicates that the USB device has 2 stop bits. */ + USB_ATTR_STOPBIT_2 +}; + +/** + * @brief Defines basic attributes of the USB to serial port. + * + * You can configure the attributes via {@link SerialSetAttribute}. If the parameters are not set, + * default attributes are used. + * + * @attention The USB controller determines which USB attribute parameters are supported. + * + */ +struct SerialAttribute { + unsigned int baudrate; + unsigned char dataBits; + unsigned char parity; + unsigned char stopBits; +}; + +/** + * @brief Enumerates USB Serial commands. + * + */ +enum SerialIoCmd { + USB_SERIAL_GET_PORT_LIST = 0, /**< Get the serial port list. */ + USB_SERIAL_OPEN, /**< Reference count management and initialize the USB device. */ + USB_SERIAL_CLOSE, /**< Reference count management and deinitialize the USB device. */ + USB_SERIAL_READ, /**< Read data. */ + USB_SERIAL_WRITE, /**< Write data. */ + USB_SERIAL_GET_ATTRIBUTE, /**< Obtain the device attributes. */ + USB_SERIAL_SET_ATTRIBUTE /**< Set the device attributes. */ +}; + +