Skip to content

Commit 24d972f

Browse files
thenguyenyfKhiemNguyenT
authored andcommitted
hal: renesas: ra: add support for r_usb_device
first commit to support r_usb_device Signed-off-by: The Nguyen <[email protected]>
1 parent 1032651 commit 24d972f

File tree

5 files changed

+1739
-0
lines changed

5 files changed

+1739
-0
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_CANFD
5151
fsp/src/r_canfd/r_canfd.c)
5252
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_QSPI_NOR_FLASH
5353
fsp/src/r_qspi/r_qspi.c)
54+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_USB_DEVICE
55+
fsp/src/r_usb_device/r_usb_device.c)
5456

5557
if(CONFIG_USE_RA_FSP_SCE)
5658
zephyr_include_directories(
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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_DEVICE_API_H
8+
#define R_USB_DEVICE_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+
/**********************************************************************************************************************
25+
* Typedef definitions
26+
**********************************************************************************************************************/
27+
28+
/** USB setup packet */
29+
typedef struct __PACKED st_usbd_setup
30+
{
31+
uint16_t request_type;
32+
uint16_t request_value;
33+
uint16_t request_index;
34+
uint16_t request_length;
35+
} usbd_setup_t;
36+
37+
/** USB Endpoint Descriptor */
38+
typedef struct __PACKED st_usbd_desc_endpoint
39+
{
40+
uint8_t bLength;
41+
uint8_t bDescriptorType;
42+
uint8_t bEndpointAddress;
43+
union
44+
{
45+
uint8_t bmAttributes;
46+
struct
47+
{
48+
uint8_t xfer : 2;
49+
uint8_t sync : 2;
50+
uint8_t usage : 2;
51+
uint8_t : 2;
52+
} Attributes;
53+
};
54+
55+
uint16_t wMaxPacketSize;
56+
uint8_t bInterval;
57+
} usbd_desc_endpoint_t;
58+
59+
/** USB speed */
60+
typedef enum e_usbd_speed
61+
{
62+
USBD_SPEED_LS = 0,
63+
USBD_SPEED_FS,
64+
USBD_SPEED_HS,
65+
USBD_SPEED_INVALID,
66+
} usbd_speed_t;
67+
68+
/** USB event code */
69+
typedef enum e_usbd_event_id
70+
{
71+
USBD_EVENT_INVALID = 0,
72+
USBD_EVENT_BUS_RESET,
73+
USBD_EVENT_VBUS_RDY,
74+
USBD_EVENT_VBUS_REMOVED,
75+
USBD_EVENT_SOF,
76+
USBD_EVENT_SUSPEND,
77+
USBD_EVENT_RESUME,
78+
USBD_EVENT_SETUP_RECEIVED,
79+
USBD_EVENT_XFER_COMPLETE,
80+
} usbd_event_id_t;
81+
82+
/** USB transfer result code */
83+
typedef enum e_usbd_xfer_result
84+
{
85+
USBD_XFER_RESULT_SUCCESS = 0,
86+
USBD_XFER_RESULT_FAILED,
87+
USBD_XFER_RESULT_STALLED,
88+
USBD_XFER_RESULT_TIMEOUT,
89+
USBD_XFER_RESULT_INVALID
90+
} usbd_xfer_result_t;
91+
92+
/** USB bus reset event input argument */
93+
typedef struct st_usbd_bus_reset_evt
94+
{
95+
usbd_speed_t speed;
96+
} usbd_bus_reset_evt_t;
97+
98+
/** USB SOF detection event input argument */
99+
typedef struct st_usbd_sof_evt
100+
{
101+
uint32_t frame_count;
102+
} usbd_sof_evt_t;
103+
104+
/** USB transfer complete event input argument */
105+
typedef struct st_usbd_xfer_complete
106+
{
107+
usbd_xfer_result_t result;
108+
uint8_t ep_addr;
109+
uint32_t len;
110+
} usbd_xfer_complete_t;
111+
112+
typedef struct st_usb_event
113+
{
114+
usbd_event_id_t event_id;
115+
union
116+
{
117+
usbd_bus_reset_evt_t bus_reset;
118+
usbd_sof_evt_t sof;
119+
usbd_setup_t setup_received;
120+
usbd_xfer_complete_t xfer_complete;
121+
};
122+
} usbd_event_t;
123+
124+
typedef struct st_usbd_callback_arg
125+
{
126+
uint32_t module_number;
127+
usbd_event_t event;
128+
void const * p_context;
129+
} usbd_callback_arg_t;
130+
131+
/** USB configuration */
132+
typedef struct st_usbd_cfg
133+
{
134+
uint32_t module_number;
135+
usbd_speed_t usb_speed;
136+
IRQn_Type irq;
137+
IRQn_Type irq_r;
138+
IRQn_Type irq_d0;
139+
IRQn_Type irq_d1;
140+
IRQn_Type hs_irq;
141+
IRQn_Type hsirq_d0;
142+
IRQn_Type hsirq_d1;
143+
uint8_t ipl;
144+
uint8_t ipl_r;
145+
uint8_t ipl_d0;
146+
uint8_t ipl_d1;
147+
uint8_t hsipl;
148+
uint8_t hsipl_d0;
149+
uint8_t hsipl_d1;
150+
void (* p_callback)(usbd_callback_arg_t * p_args);
151+
void const * p_context;
152+
void const * p_extend;
153+
} usbd_cfg_t;
154+
155+
typedef void usbd_ctrl_t;
156+
157+
#endif /* R_USB_DEVICE_API_H */
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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_DEVICE_H
8+
#define R_USB_DEVICE_H
9+
10+
/***********************************************************************************************************************
11+
* Includes
12+
**********************************************************************************************************************/
13+
#include "bsp_api.h"
14+
#include "r_usb_device_api.h"
15+
#include "r_usb_device_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_usbd_instance_ctrl
29+
{
30+
uint32_t open;
31+
void * p_reg;
32+
usbd_cfg_t const * p_cfg;
33+
void (* p_callback)(usbd_callback_arg_t * p_args);
34+
usbd_callback_arg_t * p_callback_memory;
35+
void const * p_context;
36+
} usbd_instance_ctrl_t;
37+
38+
/**********************************************************************************************************************
39+
* Exported global variables
40+
**********************************************************************************************************************/
41+
42+
fsp_err_t R_USBD_Open(usbd_ctrl_t * const p_api_ctrl, usbd_cfg_t const * const p_cfg);
43+
fsp_err_t R_USBD_RemoteWakeup(usbd_ctrl_t * const p_api_ctrl);
44+
fsp_err_t R_USBD_Connect(usbd_ctrl_t * const p_api_ctrl);
45+
fsp_err_t R_USBD_Disconnect(usbd_ctrl_t * const p_api_ctrl);
46+
fsp_err_t R_USBD_EdptOpen(usbd_ctrl_t * const p_api_ctrl, usbd_desc_endpoint_t const * p_ep_desc);
47+
fsp_err_t R_USBD_EdptClose(usbd_ctrl_t * const p_api_ctrl, uint8_t ep_addr);
48+
fsp_err_t R_USBD_XferStart(usbd_ctrl_t * const p_api_ctrl, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
49+
fsp_err_t R_USBD_XferAbort(usbd_ctrl_t * const p_api_ctrl, uint8_t ep_addr);
50+
fsp_err_t R_USBD_EdptStall(usbd_ctrl_t * const p_api_ctrl, uint8_t ep_addr);
51+
fsp_err_t R_USBD_EdptClearStall(usbd_ctrl_t * const p_api_ctrl, uint8_t ep_addr);
52+
fsp_err_t R_USBD_Close(usbd_ctrl_t * const p_api_ctrl);
53+
54+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
55+
FSP_FOOTER
56+
57+
#endif /* R_USB_DEVICE_H */

0 commit comments

Comments
 (0)