diff --git a/src/usb-device-control.adb b/src/usb-device-control.adb index b37a8bd..96fde63 100644 --- a/src/usb-device-control.adb +++ b/src/usb-device-control.adb @@ -253,7 +253,7 @@ package body USB.Device.Control is case Req.Request is when 0 => -- GET_STATUS - raise Program_Error with "GET_STATUS not implemented"; + return Get_Status (This, Req); when 1 => -- CLEAR_FEATURE raise Program_Error with "CLEAR_FEATURE not implemented"; when 3 => -- SET_FEATURE diff --git a/src/usb-device.adb b/src/usb-device.adb index 6cf93de..3a8b0e7 100644 --- a/src/usb-device.adb +++ b/src/usb-device.adb @@ -57,6 +57,26 @@ package body USB.Device is This.Ctrl.State := Idle; end Stall_Control_EP; + ---------------- + -- Get_Status -- + ---------------- + + function Get_Status (This : in out USB_Device_Stack; + Req : Setup_Data) + return Setup_Request_Answer + is + begin + if Req.Value = 0 and then Req.Index = 0 and then Req.Length = 2 then + This.Ctrl.Buffer (1) := 0; -- Reserved + This.Ctrl.Buffer (2) := 0; -- B1: Remote Wakeup; B0: Self Powered + This.Ctrl.Buf := This.Ctrl.Buffer'Address; + This.Ctrl.Len := Storage_Offset (2); + return Handled; + end if; + + return Not_Supported; + end Get_Status; + ---------------- -- Get_String -- ---------------- diff --git a/src/usb-device.ads b/src/usb-device.ads index 401f825..c02944d 100644 --- a/src/usb-device.ads +++ b/src/usb-device.ads @@ -253,6 +253,10 @@ private procedure Stall_Control_EP (This : in out USB_Device_Stack); + function Get_Status (This : in out USB_Device_Stack; + Req : Setup_Data) + return Setup_Request_Answer; + function Get_String (This : in out USB_Device_Stack; Index : String_Id) return Setup_Request_Answer; diff --git a/tests/src/tests-device.adb b/tests/src/tests-device.adb index 95ba763..350a047 100644 --- a/tests/src/tests-device.adb +++ b/tests/src/tests-device.adb @@ -160,6 +160,34 @@ package body Tests.Device is Early_Address => True); end Set_Early_Address; + ---------------- + -- Get_Status -- + ---------------- + + procedure Get_Status (Unused : in out UDC_Stub_Fixture) is + Scenario : aliased constant UDC_Stub.Stub_Scenario := + UDC_Scenarios.Enumeration (Verbose => False) & + UDC_Scenarios.Get_Status (Verbose => True); + + RX_Data : aliased constant UInt8_Array := (1 .. 2 => 0); + + Expected : constant AAA.Strings.Vector := AAA.Strings.Empty_Vector + .Append ("UDC Verbose on") + .Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (DEVICE_TO_HOST,STAND,DEV) Req: 0 Val: 0 Index: 0 Len: 2") + .Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE") + .Append ("UDC EP_Write_Packet [EP_IN 0] 2 bytes") + .Append ("0000_0000_0000_0000: 00 00 ..") + .Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 0] BCNT: 2") + .Append ("UDC EP_Ready_For_Data [EP_OUT 0] TRUE") + .Append ("UDC Poll -> NONE"); + begin + + USB_Testing.UDC_Scenarios.Basic_UDC_Test (Scenario, + Expected, + RX_Data, + Early_Address => True); + end Get_Status; + ---------------------- -- Control_Data_Out -- ---------------------- @@ -365,6 +393,7 @@ begin Suite.Add_Test (UDC_Stub_Caller.Create ("No Status Out ZLP", No_Status_Out_ZLP'Access)); Suite.Add_Test (UDC_Stub_Caller.Create ("Set_Address", Set_Address'Access)); Suite.Add_Test (UDC_Stub_Caller.Create ("Set_Early_Address", Set_Early_Address'Access)); + Suite.Add_Test (UDC_Stub_Caller.Create ("Get_Status", Get_Status'Access)); Suite.Add_Test (UDC_Stub_Caller.Create ("Control_Data_Out", Control_Data_Out'Access)); Suite.Add_Test (UDC_Stub_Caller.Create ("String Descriptor", String_Descriptor'Access)); Suite.Add_Test (UDC_Stub_Caller.Create ("iface Setup Dispatch", Iface_Setup_Dispatch'Access)); diff --git a/tests/src/usb_testing-udc_scenarios.ads b/tests/src/usb_testing-udc_scenarios.ads index 3f46884..2a53d73 100644 --- a/tests/src/usb_testing-udc_scenarios.ads +++ b/tests/src/usb_testing-udc_scenarios.ads @@ -88,6 +88,18 @@ package USB_Testing.UDC_Scenarios is ) ); + function Get_Status (Verbose : Boolean) + return UDC_Stub.Stub_Scenario + is (((Kind => Set_Verbose, Verbose => Verbose) + + , (Kind => UDC_Event_E, + Evt => (Kind => Setup_Request, + Req => ((Dev, 0, Stand, Device_To_Host), + 0, 0, 0, 2), + Req_EP => 0)) + ) + ); + function Get_Config (Verbose : Boolean) return UDC_Stub.Stub_Scenario is (((Kind => Set_Verbose, Verbose => Verbose)