1 //
2 // Copyright (c) 2010-2024 Antmicro
3 //
4 //  This file is licensed under the MIT License.
5 //  Full license text is available in 'licenses/MIT.txt'.
6 //
7 
8 using Antmicro.Renode.Core.Structure;
9 
10 namespace Antmicro.Renode.Core.USB
11 {
12     public static class USBConnectorExtensions
13     {
CreateUSBConnector(this Emulation emulation, string name)14         public static void CreateUSBConnector(this Emulation emulation, string name)
15         {
16             emulation.ExternalsManager.AddExternal(new USBConnector(), name);
17         }
18     }
19 
20     public class USBConnector : IExternal, IConnectable<IUSBDevice>, IUSBDevice
21     {
RegisterInController(SimpleContainerBase<IUSBDevice> controller, int address = 1)22         public void RegisterInController(SimpleContainerBase<IUSBDevice> controller, int address = 1)
23         {
24             controller.Register(dev, new NumberRegistrationPoint<int>(address));
25         }
26 
AttachTo(IUSBDevice obj)27         public void AttachTo(IUSBDevice obj)
28         {
29             dev = obj;
30         }
31 
DetachFrom(IUSBDevice obj)32         public void DetachFrom(IUSBDevice obj)
33         {
34             dev = null;
35         }
36 
Reset()37         public void Reset()
38         {
39         }
40 
41         public USBDeviceCore USBCore => dev?.USBCore;
42 
43         private IUSBDevice dev;
44     }
45 }
46