|
| 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 */ |
0 commit comments