Skip to content

Commit 1589073

Browse files
Minh HoangKhiemNguyenT
authored andcommitted
hal: renesas: ra: initial support for r_usb_host
First commit to support r_usb_host on USBHS module Signed-off-by: The Nguyen <[email protected]>
1 parent 728ddc4 commit 1589073

File tree

7 files changed

+2221
-0
lines changed

7 files changed

+2221
-0
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_MIPI_DSI
6666
fsp/src/r_mipi_phy/r_mipi_phy.c)
6767
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_DAC
6868
fsp/src/r_dac/r_dac.c)
69+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_USB_HOST
70+
fsp/src/r_usb_host/r_usb_host.c)
6971

7072
if(CONFIG_USE_RA_FSP_SCE)
7173
zephyr_include_directories(

drivers/ra/README

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,10 @@ Patch List:
101101
* Add new define for USB module in bsp_feature.h
102102
Impacted files:
103103
drivers/ra/fsp/src/bsp/mcu/**/bsp_feature.h
104+
105+
* Add new support for r_usb_host (not pull from FSP USB)
106+
Impacted files:
107+
drivers/ra/fsp/inc/api/r_usb_host_api.h
108+
drivers/ra/fsp/inc/instances/r_usb_host.h
109+
drivers/ra/fsp/src/bsp/mcu/**/bsp_feature.h
110+
drivers/ra/fsp/src/r_usb_host/r_usb_host.c

drivers/ra/fsp/inc/api/r_usb_api.h

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef R_USB_API_H
8+
#define R_USB_API_H
9+
10+
/***********************************************************************************************************************
11+
* Includes
12+
**********************************************************************************************************************/
13+
14+
/* Includes board and MCU related header files. */
15+
#include "bsp_api.h"
16+
17+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
18+
FSP_HEADER
19+
20+
/**********************************************************************************************************************
21+
* Macro definitions
22+
**********************************************************************************************************************/
23+
24+
/* Descriptor type Define */
25+
#define USB_DT_DEVICE (0x01U) /* Device Descriptor */
26+
#define USB_DT_CONFIGURATION (0x02U) /* Configuration Descriptor */
27+
#define USB_DT_STRING (0x03U) /* String Descriptor */
28+
#define USB_DT_INTERFACE (0x04U) /* Interface Descriptor */
29+
#define USB_DT_ENDPOINT (0x05U) /* Endpoint Descriptor */
30+
#define USB_DT_DEVICE_QUALIFIER (0x06U) /* Device Qualifier Descriptor */
31+
#define USB_DT_OTHER_SPEED_CONF (0x07U) /* Other Speed Configuration Descriptor */
32+
#define USB_DT_INTERFACE_POWER (0x08U) /* Interface Power Descriptor */
33+
#define USB_DT_OTGDESCRIPTOR (0x09U) /* OTG Descriptor */
34+
#define USB_DT_HUBDESCRIPTOR (0x29U) /* HUB descriptor */
35+
36+
/**********************************************************************************************************************
37+
* Typedef definitions
38+
**********************************************************************************************************************/
39+
40+
/** USB request type */
41+
typedef enum e_usb_request_type
42+
{
43+
USB_REQ_TYPE_STANDARD = 0,
44+
USB_REQ_TYPE_CLASS,
45+
USB_REQ_TYPE_VENDOR,
46+
USB_REQ_TYPE_INVALID
47+
} usb_request_type_t;
48+
49+
/** USB request recipient */
50+
typedef enum e_usb_request_recipient
51+
{
52+
USB_REQ_RCPT_DEVICE = 0,
53+
USB_REQ_RCPT_INTERFACE,
54+
USB_REQ_RCPT_ENDPOINT,
55+
USB_REQ_RCPT_OTHER
56+
} usb_request_recipient_t;
57+
58+
/** USB Endpoint Descriptor */
59+
typedef __PACKED_STRUCT st_usb_desc_endpoint
60+
{
61+
uint8_t bLength; /* Size of this descriptor in bytes */
62+
uint8_t bDescriptorType; /* ENDPOINT Descriptor Type */
63+
uint8_t bEndpointAddress; /* The address of the endpoint */
64+
65+
__PACKED_STRUCT
66+
{
67+
uint8_t xfer : 2; /* Control, ISO, Bulk, Interrupt */
68+
uint8_t sync : 2; /* None, Asynchronous, Adaptive, Synchronous */
69+
uint8_t usage : 2; /* Data, Feedback, Implicit feedback */
70+
uint8_t : 2;
71+
} bmAttributes;
72+
73+
uint16_t wMaxPacketSize; /* Bit 10..0 : max packet size, bit 12..11 additional transaction per highspeed micro-frame */
74+
uint8_t bInterval; /* Polling interval, in frames or microframes depending on the operating speed */
75+
} usb_desc_endpoint_t;
76+
77+
/** USB xfer type */
78+
typedef enum e_usb_xfer_type
79+
{
80+
USB_XFER_CONTROL = 0,
81+
USB_XFER_ISOCHRONOUS,
82+
USB_XFER_BULK,
83+
USB_XFER_INTERRUPT
84+
} usb_xfer_type_t;
85+
86+
/** USB endpoint direction */
87+
typedef enum e_usb_dir
88+
{
89+
USB_DIR_OUT = 0,
90+
USB_DIR_IN = 1,
91+
USB_DIR_IN_MASK = 0x80
92+
} usb_dir_t;
93+
94+
/** USB speed */
95+
typedef enum e_usb_speed
96+
{
97+
USB_SPEED_LS = 0, /* Low speed operation */
98+
USB_SPEED_FS, /* Full speed operation */
99+
USB_SPEED_HS, /* Hi speed operation */
100+
USB_SPEED_INVALID,
101+
} usb_speed_t;
102+
103+
/** USB xfer result */
104+
typedef enum e_usb_xfer_result
105+
{
106+
USB_XFER_RESULT_SUCCESS = 0,
107+
USB_XFER_RESULT_FAILED,
108+
USB_XFER_RESULT_STALLED,
109+
USB_XFER_RESULT_TIMEOUT,
110+
USB_XFER_RESULT_INVALID
111+
} usb_xfer_result_t;
112+
113+
#endif /* R_USB_API_H */
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef R_USB_HOST_API_H
8+
#define R_USB_HOST_API_H
9+
10+
/***********************************************************************************************************************
11+
* Includes
12+
**********************************************************************************************************************/
13+
14+
/* Includes board and MCU related header files. */
15+
#include "bsp_api.h"
16+
#include "r_usb_api.h"
17+
18+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
19+
FSP_HEADER
20+
21+
/**********************************************************************************************************************
22+
* Macro definitions
23+
**********************************************************************************************************************/
24+
25+
/**********************************************************************************************************************
26+
* Typedef definitions
27+
**********************************************************************************************************************/
28+
typedef enum e_usbh_event_id
29+
{
30+
USBH_EVENT_DEVICE_ATTACH = 0,
31+
USBH_EVENT_DEVICE_REMOVE,
32+
USBH_EVENT_XFER_COMPLETE
33+
} usbh_event_id_t;
34+
35+
typedef struct st_usbh_device_attach
36+
{
37+
uint8_t hub_addr;
38+
uint8_t hub_port;
39+
uint8_t speed;
40+
} usbh_device_attach_t;
41+
42+
typedef struct st_usbh_device_remove
43+
{
44+
uint8_t hub_addr;
45+
uint8_t hub_port;
46+
uint8_t speed;
47+
} usbh_device_remove_t;
48+
49+
typedef struct st_usbh_xfer_complete
50+
{
51+
uint8_t ep_addr;
52+
uint8_t result;
53+
uint32_t len;
54+
} usbh_xfer_complete_t;
55+
56+
typedef struct st_usbh_event
57+
{
58+
usbh_event_id_t event_id;
59+
uint8_t dev_addr;
60+
union
61+
{
62+
usbh_device_attach_t attach;
63+
usbh_device_remove_t remove;
64+
usbh_xfer_complete_t complete;
65+
};
66+
} usbh_event_t;
67+
68+
typedef uint32_t usb_status_t;
69+
70+
typedef struct st_usbh_callback_arg
71+
{
72+
uint32_t module_number;
73+
usbh_event_t event;
74+
void const * p_context;
75+
} usbh_callback_arg_t;
76+
77+
typedef struct st_usb_cfg
78+
{
79+
/* USB generic configuration */
80+
uint32_t module_number;
81+
IRQn_Type irq;
82+
IRQn_Type irq_r;
83+
IRQn_Type irq_d0;
84+
IRQn_Type irq_d1;
85+
IRQn_Type hs_irq;
86+
IRQn_Type hsirq_d0;
87+
IRQn_Type hsirq_d1;
88+
uint8_t ipl;
89+
uint8_t ipl_r;
90+
uint8_t ipl_d0;
91+
uint8_t ipl_d1;
92+
uint8_t hsipl;
93+
uint8_t hsipl_d0;
94+
uint8_t hsipl_d1;
95+
96+
/* Configuration for USB Event processing */
97+
void (* p_callback)(usbh_callback_arg_t * p_args);
98+
void const * p_context;
99+
bool high_speed;
100+
} usb_cfg_t;
101+
102+
typedef void usb_ctrl_t;
103+
104+
FSP_FOOTER
105+
106+
#endif /* R_USB_HOST_API_H */
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef R_USB_HOST_H
8+
#define R_USB_HOST_H
9+
10+
/***********************************************************************************************************************
11+
* Includes
12+
**********************************************************************************************************************/
13+
#include "bsp_api.h"
14+
#include "r_usb_host_api.h"
15+
#include "r_usb_host_cfg.h"
16+
17+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
18+
FSP_HEADER
19+
20+
/***********************************************************************************************************************
21+
* Macro definitions
22+
**********************************************************************************************************************/
23+
24+
/**********************************************************************************************************************
25+
* Typedef definitions
26+
**********************************************************************************************************************/
27+
28+
typedef struct st_usbh_instance_ctrl
29+
{
30+
uint32_t open;
31+
void * p_reg;
32+
uint32_t module_number;
33+
usb_speed_t max_speed;
34+
usb_cfg_t const * p_cfg;
35+
void (* p_callback)(usbh_callback_arg_t * p_args);
36+
usbh_callback_arg_t * p_callback_memory;
37+
void const * p_context;
38+
} usbh_instance_ctrl_t;
39+
40+
/**********************************************************************************************************************
41+
* Exported global functions
42+
**********************************************************************************************************************/
43+
fsp_err_t R_USBH_Open(usb_ctrl_t * const p_api_ctrl, usb_cfg_t const * const p_cfg);
44+
fsp_err_t R_USBH_XferStart(usb_ctrl_t * const p_api_ctrl,
45+
uint8_t dev_addr,
46+
uint8_t ep_addr,
47+
uint8_t * buffer,
48+
uint16_t buflen);
49+
fsp_err_t R_USBH_GetDeviceSpeed(usb_ctrl_t * const p_api_ctrl, usb_speed_t * p_speed);
50+
fsp_err_t R_USBH_PortOpen(usb_ctrl_t * const p_api_ctrl, uint8_t dev_addr);
51+
fsp_err_t R_USBH_PortStatusGet(usb_ctrl_t * const p_api_ctrl, usb_status_t * p_status);
52+
fsp_err_t R_USBH_PortReset(usb_ctrl_t * const p_api_ctrl);
53+
fsp_err_t R_USBH_DeviceRelease(usb_ctrl_t * const p_api_ctrl, uint8_t dev_addr);
54+
fsp_err_t R_USBH_SetupSend(usb_ctrl_t * const p_api_ctrl, uint8_t dev_addr, uint8_t const setup_packet[8]);
55+
fsp_err_t R_USBH_EdptOpen(usb_ctrl_t * const p_api_ctrl, uint8_t dev_addr, usb_desc_endpoint_t const * ep_desc);
56+
fsp_err_t R_USBH_XferStart(usb_ctrl_t * const p_api_ctrl,
57+
uint8_t dev_addr,
58+
uint8_t ep_addr,
59+
uint8_t * buffer,
60+
uint16_t buflen);
61+
fsp_err_t R_USBH_Close(usb_ctrl_t * const p_ctrl);
62+
fsp_err_t R_USBH_SOFEnable(usb_ctrl_t * const p_api_ctrl);
63+
fsp_err_t R_USBH_SOFDisable(usb_ctrl_t * const p_api_ctrl);
64+
fsp_err_t R_USBH_BusResume(usb_ctrl_t * const p_api_ctrl);
65+
fsp_err_t R_USBH_BusSuspend(usb_ctrl_t * const p_api_ctrl);
66+
fsp_err_t R_USBH_Enable(usb_ctrl_t * const p_api_ctrl);
67+
fsp_err_t R_USBH_Disable(usb_ctrl_t * const p_api_ctrl);
68+
69+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
70+
FSP_FOOTER
71+
72+
#endif

0 commit comments

Comments
 (0)