1 //
2 // Copyright (c) 2010-2018 Antmicro
3 //
4 // This file is licensed under the MIT License.
5 // Full license text is available in 'licenses/MIT.txt'.
6 //
7 using Antmicro.Renode.Utilities.Packets;
8 
9 namespace Antmicro.Renode.Core.USB
10 {
11     [LeastSignificantByteFirst]
12     public struct SetupPacket
13     {
14         [PacketField, Width(5)]
15         public PacketRecipient Recipient;
16         [PacketField, Offset(bytes: 0, bits: 5), Width(2)]
17         public PacketType Type;
18         [PacketField, Offset(bytes: 0, bits: 7), Width(1)]
19         public Direction Direction;
20         [PacketField]
21         public byte Request;
22         [PacketField]
23         public ushort Value;
24         [PacketField]
25         public ushort Index;
26         [PacketField]
27         public ushort Count;
28 
ToStringAntmicro.Renode.Core.USB.SetupPacket29         public override string ToString()
30         {
31             return $"[Recipient: {Recipient}, Type: {Type}, Direction: {Direction}, Request: {DecodeRequest()} (0x{Request:X}), Value: 0x{Value:X}, Index: 0x{Index:X}, Count: 0x{Count:X}]";
32         }
33 
DecodeRequestAntmicro.Renode.Core.USB.SetupPacket34         private string DecodeRequest()
35         {
36             if(Type == PacketType.Standard)
37             {
38                 return ((StandardRequest)Request).ToString();
39             }
40             return "[unknown]";
41         }
42     }
43 }
44