Commit f6d338c1 authored by Johann Fischer's avatar Johann Fischer Committed by Benjamin Cabé
Browse files

usb: host: fix set/clear feature shell commands



Implement Set/Clear Feature endpoint halt request and
fix the corresponding commands in the shell.

Signed-off-by: default avatarJohann Fischer <johann.fischer@nordicsemi.no>
parent 9be4c0fe
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -247,6 +247,30 @@ int usbh_req_clear_sfs_rwup(struct usb_device *const udev)
			      NULL);
}

int usbh_req_set_sfs_halt(struct usb_device *const udev, const uint8_t ep)
{
	const uint8_t bmRequestType = USB_REQTYPE_RECIPIENT_ENDPOINT;
	const uint8_t bRequest = USB_SREQ_SET_FEATURE;
	const uint16_t wValue = USB_SFS_ENDPOINT_HALT;
	const uint16_t wIndex = ep;

	return usbh_req_setup(udev,
			      bmRequestType, bRequest, wValue, wIndex, 0,
			      NULL);
}

int usbh_req_clear_sfs_halt(struct usb_device *const udev, const uint8_t ep)
{
	const uint8_t bmRequestType = USB_REQTYPE_RECIPIENT_ENDPOINT;
	const uint8_t bRequest = USB_SREQ_CLEAR_FEATURE;
	const uint16_t wValue = USB_SFS_ENDPOINT_HALT;
	const uint16_t wIndex = ep;

	return usbh_req_setup(udev,
			      bmRequestType, bRequest, wValue, wIndex, 0,
			      NULL);
}

int usbh_req_set_hcfs_ppwr(struct usb_device *const udev,
			   const uint8_t port)
{
+4 −0
Original line number Diff line number Diff line
@@ -52,6 +52,10 @@ int usbh_req_set_sfs_rwup(struct usb_device *const udev);

int usbh_req_clear_sfs_rwup(struct usb_device *const udev);

int usbh_req_set_sfs_halt(struct usb_device *const udev, const uint8_t ep);

int usbh_req_clear_sfs_halt(struct usb_device *const udev, const uint8_t ep);

int usbh_req_set_hcfs_ppwr(const struct usb_device *udev,
			   const uint8_t port);

+30 −3
Original line number Diff line number Diff line
@@ -300,6 +300,34 @@ static int cmd_desc_string(const struct shell *sh,
	return err;
}

static int cmd_feature_clear_halt(const struct shell *sh,
				  size_t argc, char **argv)
{
	static struct usb_device *udev;
	uint8_t addr;
	uint8_t ep;
	int err;

	addr = strtol(argv[1], NULL, 10);
	udev = usbh_device_get(&uhs_ctx, addr);
	if (udev == NULL) {
		shell_error(sh, "host: No USB device with address %u", addr);
		return -ENOMEM;
	}

	ep = strtol(argv[2], NULL, 16);

	err = usbh_req_clear_sfs_halt(udev, ep);
	if (err) {
		shell_error(sh, "host: Failed to clear halt feature");
	} else {
		shell_print(sh, "host: Device 0x%02x, ep 0x%02x halt feature cleared",
			    udev->addr, ep);
	}

	return err;
}

static int cmd_feature_set_halt(const struct shell *sh,
				size_t argc, char **argv)
{
@@ -317,8 +345,7 @@ static int cmd_feature_set_halt(const struct shell *sh,

	ep = strtol(argv[2], NULL, 16);

	/* TODO: add usbh_req_set_sfs_halt(&uhs_ctx, NULL, 0); */
	err = usbh_req_set_sfs_rwup(udev);
	err = usbh_req_set_sfs_halt(udev, ep);
	if (err) {
		shell_error(sh, "host: Failed to set halt feature");
	} else {
@@ -684,7 +711,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(feature_clear_cmds,
	SHELL_CMD_ARG(rwup, NULL, "<addr>",
		      cmd_feature_clear_rwup, 2, 0),
	SHELL_CMD_ARG(halt, NULL, "<addr> <endpoint>",
		      cmd_feature_set_halt, 3, 0),
		      cmd_feature_clear_halt, 3, 0),
	SHELL_SUBCMD_SET_END
);