drivers: usb: use new USB framework header

Use macros and types from usb/usb_ch9.h header where it
is possible. This patch also adds local macros, USB_REQTYPE_GET_DIR
and USB_REQTYPE_GET_TYPE, which is an intermediate solution and
these will be removed later.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
Johann Fischer 2021-05-12 11:17:06 +02:00 committed by Carles Cufí
commit 6954554284
5 changed files with 9 additions and 16 deletions

View file

@ -462,8 +462,7 @@ static void update_control_stage(usb_device_callback_message_struct_t *cb_msg,
if (cb_msg->isSetup) { if (cb_msg->isSetup) {
if (usbd_setup->wLength == 0) { if (usbd_setup->wLength == 0) {
dev_data.setupDataStage = SETUP_DATA_STAGE_DONE; dev_data.setupDataStage = SETUP_DATA_STAGE_DONE;
} else if (REQTYPE_GET_DIR(usbd_setup->bmRequestType) } else if (usb_reqtype_is_to_host(usbd_setup)) {
== REQTYPE_DIR_TO_HOST) {
dev_data.setupDataStage = SETUP_DATA_STAGE_IN; dev_data.setupDataStage = SETUP_DATA_STAGE_IN;
} else { } else {
dev_data.setupDataStage = SETUP_DATA_STAGE_OUT; dev_data.setupDataStage = SETUP_DATA_STAGE_OUT;

View file

@ -513,8 +513,7 @@ int handle_usb_control(struct usbip_header *hdr)
} }
if ((ntohl(hdr->common.direction) == USBIP_DIR_IN) ^ if ((ntohl(hdr->common.direction) == USBIP_DIR_IN) ^
(REQTYPE_GET_DIR(hdr->u.submit.bmRequestType) == USB_REQTYPE_GET_DIR(hdr->u.submit.bmRequestType)) {
REQTYPE_DIR_TO_HOST)) {
LOG_ERR("Failed to verify bmRequestType"); LOG_ERR("Failed to verify bmRequestType");
return -EIO; return -EIO;
} }

View file

@ -25,8 +25,6 @@
/* Zephyr headers */ /* Zephyr headers */
#include <kernel.h> #include <kernel.h>
#include <usb/usb_common.h>
#include <usb/usbstruct.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <posix_board_if.h> #include <posix_board_if.h>
@ -75,7 +73,7 @@ static void usbip_header_dump(struct usbip_header *hdr)
void get_interface(uint8_t *descriptors) void get_interface(uint8_t *descriptors)
{ {
while (descriptors[0]) { while (descriptors[0]) {
if (descriptors[1] == USB_INTERFACE_DESC) { if (descriptors[1] == USB_DESC_INTERFACE) {
LOG_DBG("interface found"); LOG_DBG("interface found");
} }
@ -94,7 +92,7 @@ static int send_interfaces(const uint8_t *descriptors, int connfd)
} __packed iface; } __packed iface;
while (descriptors[0]) { while (descriptors[0]) {
if (descriptors[1] == USB_INTERFACE_DESC) { if (descriptors[1] == USB_DESC_INTERFACE) {
struct usb_if_descriptor *desc = (void *)descriptors; struct usb_if_descriptor *desc = (void *)descriptors;
iface.bInterfaceClass = desc->bInterfaceClass; iface.bInterfaceClass = desc->bInterfaceClass;

View file

@ -796,9 +796,7 @@ static inline void usbd_work_process_setup(struct nrf_usbd_ep_ctx *ep_ctx)
struct nrf_usbd_ctx *ctx = get_usbd_ctx(); struct nrf_usbd_ctx *ctx = get_usbd_ctx();
if ((REQTYPE_GET_DIR(usbd_setup->bmRequestType) if (usb_reqtype_is_to_device(usbd_setup) && usbd_setup->wLength) {
== REQTYPE_DIR_TO_DEVICE)
&& (usbd_setup->wLength)) {
ctx->ctrl_read_len = usbd_setup->wLength; ctx->ctrl_read_len = usbd_setup->wLength;
/* Allow data chunk on EP0 OUT */ /* Allow data chunk on EP0 OUT */
nrfx_usbd_setup_data_clear(); nrfx_usbd_setup_data_clear();
@ -1127,9 +1125,9 @@ static void usbd_event_handler(nrfx_usbd_evt_t const *const p_event)
nrfx_usbd_setup_t drv_setup; nrfx_usbd_setup_t drv_setup;
nrfx_usbd_setup_get(&drv_setup); nrfx_usbd_setup_get(&drv_setup);
if ((drv_setup.bRequest != REQ_SET_ADDRESS) if ((drv_setup.bRequest != USB_SREQ_SET_ADDRESS)
|| (REQTYPE_GET_TYPE(drv_setup.bmRequestType) || (USB_REQTYPE_GET_TYPE(drv_setup.bmRequestType)
!= REQTYPE_TYPE_STANDARD)) { != USB_REQTYPE_TYPE_STANDARD)) {
/* SetAddress is habdled by USBD hardware. /* SetAddress is habdled by USBD hardware.
* No software action required. * No software action required.
*/ */

View file

@ -1042,8 +1042,7 @@ void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
ep_state->cb(EP0_OUT, USB_DC_EP_SETUP); ep_state->cb(EP0_OUT, USB_DC_EP_SETUP);
if (!(setup->wLength == 0U) && if (!(setup->wLength == 0U) &&
!(REQTYPE_GET_DIR(setup->bmRequestType) == usb_reqtype_is_to_device(setup)) {
REQTYPE_DIR_TO_HOST)) {
usb_dc_ep_start_read(EP0_OUT, usb_dc_ep_start_read(EP0_OUT,
usb_dc_stm32_state.ep_buf[EP0_IDX], usb_dc_stm32_state.ep_buf[EP0_IDX],
setup->wLength); setup->wLength);