Commit 043aa837 authored by Johann Fischer's avatar Johann Fischer Committed by Fabio Baltieri
Browse files

drivers: udc_stm32: remove wrong header and fix udc_ep_enable()



Driver includes wrong header zephyr/usb/usb_device.h and uses defines
from include/zephyr/drivers/usb/usb_dc.h.
Also fix udc_ep_enable() implementation in general. HAL_PCD_EP_Open()
takes the ep_type parameter as uint8_t integer type and the shim driver
should not just pass int type.
It is recommended that drivers use ep_cfg or cfg for struct
udc_ep_config, fix this as well.

Signed-off-by: default avatarJohann Fischer <johann.fischer@nordicsemi.no>
parent 9ec7697b
Loading
Loading
Loading
Loading
+24 −26
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
#include <zephyr/sys/util.h>
#include <zephyr/usb/usb_device.h>

#include "udc_common.h"

@@ -636,44 +635,43 @@ static int udc_stm32_host_wakeup(const struct device *dev)
	return 0;
}

static inline int eptype2hal(enum usb_dc_ep_transfer_type eptype)
{
	switch (eptype) {
	case USB_DC_EP_CONTROL:
		return EP_TYPE_CTRL;
	case USB_DC_EP_ISOCHRONOUS:
		return EP_TYPE_ISOC;
	case USB_DC_EP_BULK:
		return EP_TYPE_BULK;
	case USB_DC_EP_INTERRUPT:
		return EP_TYPE_INTR;
	default:
		return -EINVAL;
	}

	return -EINVAL;
}

static int udc_stm32_ep_enable(const struct device *dev,
			       struct udc_ep_config *ep)
			       struct udc_ep_config *ep_cfg)
{
	enum usb_dc_ep_transfer_type type = ep->attributes & USB_EP_TRANSFER_TYPE_MASK;
	struct udc_stm32_data *priv = udc_get_private(dev);
	HAL_StatusTypeDef status;
	uint8_t ep_type;
	int ret;

	LOG_DBG("Enable ep 0x%02x", ep->addr);
	LOG_DBG("Enable ep 0x%02x", ep_cfg->addr);

	switch (ep_cfg->attributes & USB_EP_TRANSFER_TYPE_MASK) {
	case USB_EP_TYPE_CONTROL:
		ep_type = EP_TYPE_CTRL;
		break;
	case USB_EP_TYPE_BULK:
		ep_type = EP_TYPE_BULK;
		break;
	case USB_EP_TYPE_INTERRUPT:
		ep_type = EP_TYPE_INTR;
		break;
	case USB_EP_TYPE_ISO:
		ep_type = EP_TYPE_ISOC;
		break;
	default:
		return -EINVAL;
	}

	ret = udc_stm32_ep_mem_config(dev, ep, true);
	ret = udc_stm32_ep_mem_config(dev, ep_cfg, true);
	if (ret) {
		return ret;
	}

	status = HAL_PCD_EP_Open(&priv->pcd, ep->addr, ep->mps,
				 eptype2hal(type));
	status = HAL_PCD_EP_Open(&priv->pcd, ep_cfg->addr, ep_cfg->mps,
				 ep_type);
	if (status != HAL_OK) {
		LOG_ERR("HAL_PCD_EP_Open failed(0x%02x), %d",
			ep->addr, (int)status);
			ep_cfg->addr, (int)status);
		return -EIO;
	}