From 1e22954ba72b80921590c64c9e7ca5cca78ec668 Mon Sep 17 00:00:00 2001 From: Dinesh Dwivedi Date: Wed, 21 Jun 2017 16:23:23 +0530 Subject: [PATCH] [USB] Add bulk, interrupt, isochronous Endpoint classes Change-Id: I72cba1373ee9c6f25868f04b6ee5e5f1065cf202 Signed-off-by: Dinesh Dwivedi --- Tizen.System.Usb/Usb/SynchronizationType.cs | 37 ++++++++++++++++ Tizen.System.Usb/Usb/UsageType.cs | 37 ++++++++++++++++ Tizen.System.Usb/Usb/UsbBulkEndpoint.cs | 50 ++++++++++++++++++++++ Tizen.System.Usb/Usb/UsbEndpoint.cs | 13 ++++++ Tizen.System.Usb/Usb/UsbInterruptEndpoint.cs | 59 ++++++++++++++++++++++++++ Tizen.System.Usb/Usb/UsbIsochronousEndpoint.cs | 50 ++++++++++++++++++++++ 6 files changed, 246 insertions(+) create mode 100644 Tizen.System.Usb/Usb/SynchronizationType.cs create mode 100644 Tizen.System.Usb/Usb/UsageType.cs create mode 100644 Tizen.System.Usb/Usb/UsbBulkEndpoint.cs create mode 100644 Tizen.System.Usb/Usb/UsbInterruptEndpoint.cs create mode 100644 Tizen.System.Usb/Usb/UsbIsochronousEndpoint.cs diff --git a/Tizen.System.Usb/Usb/SynchronizationType.cs b/Tizen.System.Usb/Usb/SynchronizationType.cs new file mode 100644 index 0000000..4dcda11 --- /dev/null +++ b/Tizen.System.Usb/Usb/SynchronizationType.cs @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +namespace Tizen.System.Usb +{ + /// + /// Enumeration of isochronous endpoint's synchronization type + /// + public enum SynchronizationType + { + /// + /// Asynchronous + /// + Asynchronous = Interop.SynchronizationType.Async, + /// + /// Adaptive + /// + Adaptive = Interop.SynchronizationType.Adaptive, + /// + /// Synchronous + /// + Synchronous = Interop.SynchronizationType.Sync, + } +} \ No newline at end of file diff --git a/Tizen.System.Usb/Usb/UsageType.cs b/Tizen.System.Usb/Usb/UsageType.cs new file mode 100644 index 0000000..e45ff55 --- /dev/null +++ b/Tizen.System.Usb/Usb/UsageType.cs @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +namespace Tizen.System.Usb +{ + /// + /// Enumeration of an endpoint's usage type + /// + public enum UsageType + { + /// + /// Data endpoint + /// + Data = Interop.UsageType.Data, + /// + /// Feedback endpoint + /// + Feedback = Interop.UsageType.Feedback, + /// + /// Implicit feedback Data endpoint + /// + Implicit = Interop.UsageType.Implicit, + } +} \ No newline at end of file diff --git a/Tizen.System.Usb/Usb/UsbBulkEndpoint.cs b/Tizen.System.Usb/Usb/UsbBulkEndpoint.cs new file mode 100644 index 0000000..f2b8a42 --- /dev/null +++ b/Tizen.System.Usb/Usb/UsbBulkEndpoint.cs @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +using System; + +namespace Tizen.System.Usb +{ + /// + /// USB Bulk Endpoint class + /// + public class UsbBulkEndpoint : UsbEndpoint + { + internal UsbBulkEndpoint(Interop.UsbEndpointHandle handle) : base(handle) + { + } + + /// + /// Performs a USB transfer on given endpoint. Direction of transfer is determined by the endpoint + /// + /// Suitably-sized data buffer for either input or output (depending on endpoint) + /// + /// For writes, the number of bytes from data to be sent, for reads the maximum number of bytes to receive + /// into the data buffer + /// + /// + /// Timeout (in milliseconds) that this function should wait before giving up due to no response being + /// received(for an unlimited timeout 0 value should be used) + /// + /// transferred number of bytes actually transferred + /// Throws excetion if device is disconnected or not opened for operation + /// Throws excetion if transfer timed-out + public int Transfer(byte[] buffer, int length, uint timeout) + { + return TransferImpl(buffer, length, timeout); + } + } +} diff --git a/Tizen.System.Usb/Usb/UsbEndpoint.cs b/Tizen.System.Usb/Usb/UsbEndpoint.cs index ab366a6..914bf2d 100644 --- a/Tizen.System.Usb/Usb/UsbEndpoint.cs +++ b/Tizen.System.Usb/Usb/UsbEndpoint.cs @@ -69,5 +69,18 @@ namespace Tizen.System.Usb _handle.Transfer(buffer, length, out transferred, timeout).ThrowIfFailed("Transfer failed"); return transferred; } + + internal static UsbEndpoint EndpointFactory(Interop.UsbEndpointHandle handle) + { + Interop.TransferType transferType; + handle.GetTransferType(out transferType).ThrowIfFailed("Failed to get transfer type from endpoint"); + switch(transferType) + { + case Interop.TransferType.Bulk: return new UsbBulkEndpoint(handle); + case Interop.TransferType.Interrupt: return new UsbInterruptEndpoint(handle); + case Interop.TransferType.Isochronous: return new UsbIsochronousEndpoint(handle); + default: return new UsbEndpoint(handle); + } + } } } \ No newline at end of file diff --git a/Tizen.System.Usb/Usb/UsbInterruptEndpoint.cs b/Tizen.System.Usb/Usb/UsbInterruptEndpoint.cs new file mode 100644 index 0000000..eb4e5c6 --- /dev/null +++ b/Tizen.System.Usb/Usb/UsbInterruptEndpoint.cs @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +namespace Tizen.System.Usb +{ + /// + /// USB Interrupt Endpoint class + /// + public class UsbInterruptEndpoint : UsbEndpoint + { + internal UsbInterruptEndpoint(Interop.UsbEndpointHandle handle) : base(handle) + { + } + + /// + /// Gets interval for polling endpoint for data transfers, in frame counts (refer to USB protocol specification) + /// + public int PollingInterval + { + get + { + return Interop.NativeGet(_handle.GetInterval); + } + } + + /// + /// Performs a USB transfer on given endpoint. Direction of transfer is determined by the endpoint. + /// + /// Suitably-sized data buffer for either input or output (depending on endpoint) + /// + /// For writes, the number of bytes from data to be sent, for reads the maximum number of bytes to receive + /// into the data buffer + /// + /// + /// Timeout (in milliseconds) that this function should wait before giving up due to no response being + /// received(for an unlimited timeout 0 value should be used) + /// + /// transferred number of bytes actually transferred + /// Throws excetion if device is disconnected or not opened for operation + /// Throws excetion if transfer timed-out + public int Transfer(byte[] buffer, int length, uint timeout) + { + return TransferImpl(buffer, length, timeout); + } + } +} diff --git a/Tizen.System.Usb/Usb/UsbIsochronousEndpoint.cs b/Tizen.System.Usb/Usb/UsbIsochronousEndpoint.cs new file mode 100644 index 0000000..680e184 --- /dev/null +++ b/Tizen.System.Usb/Usb/UsbIsochronousEndpoint.cs @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +namespace Tizen.System.Usb +{ + /// + /// USB Isochronous Endpoint class + /// + public class UsbIsochronousEndpoint : UsbEndpoint + { + internal UsbIsochronousEndpoint(Interop.UsbEndpointHandle handle) : base(handle) + { + } + + /// + /// Gets synchronization type of this endpoint + /// + public SynchronizationType SynchronizationType + { + get + { + return (SynchronizationType)Interop.NativeGet(_handle.GetSynchType); + } + } + + /// + /// Gets usage type of this endpoint + /// + public UsageType UsageType + { + get + { + return (UsageType)Interop.NativeGet(_handle.GetUsageType); + } + } + } +} -- 2.7.4