]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBDevice/USBDevice/TARGET_RENESAS/TARGET_RZ_A1H/inc/devdrv_usb_function_api.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / USBDevice / USBDevice / TARGET_RENESAS / TARGET_RZ_A1H / inc / devdrv_usb_function_api.h
1 /*******************************************************************************
2 * DISCLAIMER
3 * This software is supplied by Renesas Electronics Corporation and is only
4 * intended for use with Renesas products. No other uses are authorized. This
5 * software is owned by Renesas Electronics Corporation and is protected under
6 * all applicable laws, including copyright laws.
7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
16 * Renesas reserves the right, without notice, to make changes to this software
17 * and to discontinue the availability of this software. By using this software,
18 * you agree to the additional terms and conditions found by accessing the
19 * following link:
20 * http://www.renesas.com/disclaimer
21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
22 *******************************************************************************/
23 /*******************************************************************************
24 * File Name : devdrv_usb_function_api.h
25 * $Rev: 1116 $
26 * $Date:: 2014-07-09 16:29:19 +0900#$
27 * Description : RZ/A1H R7S72100 USB Sample Program
28 *******************************************************************************/
29 #ifndef USB_FUNCTION_API_H
30 #define USB_FUNCTION_API_H
31
32
33 /*******************************************************************************
34 Includes <System Includes> , "Project Includes"
35 *******************************************************************************/
36 #include <MBRZA1H.h>
37 #include "r_typedefs.h"
38 #include "usb0_function_api.h"
39 #include "usb1_function_api.h"
40
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /*******************************************************************************
47 Typedef definitions
48 *******************************************************************************/
49 typedef struct
50 {
51 uint32_t fifo;
52 uint32_t buffer;
53 uint32_t bytes;
54 uint32_t dir;
55 uint32_t size;
56 } USB_FUNCTION_DMA_t;
57
58
59 /*******************************************************************************
60 Macro definitions
61 *******************************************************************************/
62 #define USBFCLOCK_X1_48MHZ (0x0000u) /* USB_X1_48MHz */
63 #define USBFCLOCK_EXTAL_12MHZ (0x0004u) /* EXTAL_12MHz */
64
65 #define DEVDRV_USBF_ON (1)
66 #define DEVDRV_USBF_OFF (0)
67 #define DEVDRV_USBF_YES (1)
68 #define DEVDRV_USBF_NO (0)
69
70 #define DEVDRV_USBF_STALL (-2)
71
72 #define DEVDRV_USBF_WRITEEND (0)
73 #define DEVDRV_USBF_WRITESHRT (1)
74 #define DEVDRV_USBF_WRITING (2)
75 #define DEVDRV_USBF_WRITEDMA (3)
76
77 #define DEVDRV_USBF_FIFOERROR (0xffff)
78
79 #define DEVDRV_USBF_PIPE_IDLE (0x00)
80 #define DEVDRV_USBF_PIPE_WAIT (0x01)
81 #define DEVDRV_USBF_PIPE_DONE (0x02)
82 #define DEVDRV_USBF_PIPE_NORES (0x03)
83 #define DEVDRV_USBF_PIPE_STALL (0x04)
84
85 #define DEVDRV_USBF_PID_NAK (0x0000u)
86 #define DEVDRV_USBF_PID_BUF (0x0001u)
87 #define DEVDRV_USBF_PID_STALL (0x0002u)
88 #define DEVDRV_USBF_PID_STALL2 (0x0003u)
89
90 #define USB_FUNCTION_NON_SPEED (0)
91 #define USB_FUNCTION_LOW_SPEED (1)
92 #define USB_FUNCTION_FULL_SPEED (2)
93 #define USB_FUNCTION_HIGH_SPEED (3)
94
95 #define USB_FUNCTION_READEND (0)
96 #define USB_FUNCTION_READSHRT (1)
97 #define USB_FUNCTION_READING (2)
98 #define USB_FUNCTION_READOVER (3)
99 #define USB_FUNCTION_READZERO (4)
100
101 #define USB_FUNCTION_MAX_PIPE_NO (15u)
102 #define USB_FUNCTION_PIPE0 (0)
103 #define USB_FUNCTION_PIPE1 (1)
104 #define USB_FUNCTION_PIPE2 (2)
105 #define USB_FUNCTION_PIPE3 (3)
106 #define USB_FUNCTION_PIPE4 (4)
107 #define USB_FUNCTION_PIPE5 (5)
108 #define USB_FUNCTION_PIPE6 (6)
109 #define USB_FUNCTION_PIPE7 (7)
110 #define USB_FUNCTION_PIPE8 (8)
111 #define USB_FUNCTION_PIPE9 (9)
112 #define USB_FUNCTION_PIPEA (10)
113 #define USB_FUNCTION_PIPEB (11)
114 #define USB_FUNCTION_PIPEC (12)
115 #define USB_FUNCTION_PIPED (13)
116 #define USB_FUNCTION_PIPEE (14)
117 #define USB_FUNCTION_PIPEF (15)
118
119 #define USB_FUNCTION_ISO (0xc000u)
120 #define USB_FUNCTION_INTERRUPT (0x8000u)
121 #define USB_FUNCTION_BULK (0x4000u)
122
123 #define USB_FUNCTION_NONE (0x0000u)
124 #define USB_FUNCTON_BFREFIELD (0x0400u)
125 #define USB_FUNCTION_BFREON (0x0400u)
126 #define USB_FUNCTION_BFREOFF (0x0000u)
127 #define USB_FUNCTION_DBLBFIELD (0x0200u)
128 #define USB_FUNCTION_DBLBON (0x0200u)
129 #define USB_FUNCTION_DBLBOFF (0x0000u)
130 #define USB_FUNCTION_CNTMDFIELD (0x0100u)
131 #define USB_FUNCTION_CNTMDON (0x0100u)
132 #define USB_FUNCTION_CNTMDOFF (0x0000u)
133 #define USB_FUNCTION_SHTNAKON (0x0080u)
134 #define USB_FUNCTION_SHTNAKOFF (0x0000u)
135 #define USB_FUNCTION_DIRFIELD (0x0010u)
136 #define USB_FUNCTION_DIR_P_OUT (0x0000u)
137 #define USB_FUNCTION_DIR_P_IN (0x0010u)
138 #define USB_FUNCTION_EPNUMFIELD (0x000fu)
139 #define USB_FUNCTION_MAX_EP_NO (15u)
140 #define USB_FUNCTION_EP0 (0u)
141 #define USB_FUNCTION_EP1 (1u)
142 #define USB_FUNCTION_EP2 (2u)
143 #define USB_FUNCTION_EP3 (3u)
144 #define USB_FUNCTION_EP4 (4u)
145 #define USB_FUNCTION_EP5 (5u)
146 #define USB_FUNCTION_EP6 (6u)
147 #define USB_FUNCTION_EP7 (7u)
148 #define USB_FUNCTION_EP8 (8u)
149 #define USB_FUNCTION_EP9 (9u)
150 #define USB_FUNCTION_EP10 (10u)
151 #define USB_FUNCTION_EP11 (11u)
152 #define USB_FUNCTION_EP12 (12u)
153 #define USB_FUNCTION_EP13 (13u)
154 #define USB_FUNCTION_EP14 (14u)
155 #define USB_FUNCTION_EP15 (15u)
156
157 #define USB_FUNCTION_EPTABLE_LENGTH (5u)
158
159 #define USB_FUNCTION_CUSE (0)
160 #define USB_FUNCTION_D0USE (1)
161 #define USB_FUNCTION_D0DMA (2)
162 #define USB_FUNCTION_D1USE (3)
163 #define USB_FUNCTION_D1DMA (4)
164
165 #define USB_FUNCTION_CFIFO_USE (0x0000)
166 #define USB_FUNCTION_D0FIFO_USE (0x1000)
167 #define USB_FUNCTION_D1FIFO_USE (0x2000)
168 #define USB_FUNCTION_D0FIFO_DMA (0x5000)
169 #define USB_FUNCTION_D1FIFO_DMA (0x6000)
170
171 #define USB_FUNCTION_BUF2FIFO (0)
172 #define USB_FUNCTION_FIFO2BUF (1)
173
174 #define USB_FUNCTION_DVST_POWERED (0x0001)
175 #define USB_FUNCTION_DVST_DEFAULT (0x0002)
176 #define USB_FUNCTION_DVST_ADDRESS (0x0003)
177 #define USB_FUNCTION_DVST_CONFIGURED (0x0004)
178 #define USB_FUNCTION_DVST_SUSPEND (0x0005)
179 #define USB_FUNCTION_DVST_CONFIGURED_SUSPEND (0x0006)
180
181 #define USB_FUNCTION_FUNCTION_TEST_SELECT (0xff00u)
182 #define USB_FUNCTION_FUNCTION_TEST_J (0x0100u)
183 #define USB_FUNCTION_FUNCTION_TEST_K (0x0200u)
184 #define USB_FUNCTION_FUNCTION_TEST_SE0_NAK (0x0300u)
185 #define USB_FUNCTION_FUNCTION_TEST_PACKET (0x0400u)
186 #define USB_FUNCTION_FUNCTION_TEST_FORCE_ENABLE (0x0500u)
187 #define USB_FUNCTION_FUNCTION_TEST_STSelectors (0x0600u)
188 #define USB_FUNCTION_FUNCTION_TEST_Reserved (0x4000u)
189 #define USB_FUNCTION_FUNCTION_TEST_VSTModes (0xc000u)
190
191 #define USB_FUNCTION_DT_TYPE (0xff00u)
192 #define USB_FUNCTION_DT_INDEX (0xff)
193 #define USB_FUNCTION_DT_DEVICE (0x01)
194 #define USB_FUNCTION_DT_CONFIGURATION (0x02)
195 #define USB_FUNCTION_DT_STRING (0x03)
196 #define USB_FUNCTION_DT_INTERFACE (0x04)
197 #define USB_FUNCTION_DT_ENDPOINT (0x05)
198 #define USB_FUNCTION_DT_DEVICE_QUALIFIER (0x06)
199 #define USB_FUNCTION_DT_OTHER_SPEED_CONFIGURATION (0x07)
200 #define USB_FUNCTION_DT_INTERFACE_POWER (0x08)
201
202 #define USB_FUNCTION_CF_RESERVED (0x80)
203 #define USB_FUNCTION_CF_SELF (0x40)
204 #define USB_FUNCTION_CF_RWUP (0x20)
205 #define USB_FUNCTION_CF_NORWUP (0x00)
206 #define USB_FUNCTION_EP_ERROR (0xff)
207
208 #define USB_FUNCTION_EP_OUT (0x00)
209 #define USB_FUNCTION_EP_IN (0x80)
210 #define USB_FUNCTION_EP_CNTRL (0x00)
211 #define USB_FUNCTION_EP_ISO (0x01)
212 #define USB_FUNCTION_EP_BULK (0x02)
213 #define USB_FUNCTION_EP_INT (0x03)
214
215 #define USB_FUNCTION_STANDARD_REQUEST (0x0000u)
216 #define USB_FUNCTION_CLASS_REQUEST (0x0020u)
217 #define USB_FUNCTION_VENDOR_REQUEST (0x0040u)
218 #define USB_FUNCTION_DEVICE_REQUEST (0x0000u)
219 #define USB_FUNCTION_INTERFACE_REQUEST (0x0001u)
220 #define USB_FUNCTION_ENDPOINT_REQUEST (0x0002u)
221
222 #define USB_FUNCTION_GETSTATUS_BUSPOWERD (0x0000u)
223 #define USB_FUNCTION_GETSTATUS_SELFPOWERD (0x0001u)
224 #define USB_FUNCTION_GETSTATUS_REMOTEWAKEUP (0x0002u)
225 #define USB_FUNCTION_GETSTATUS_NOTHALT (0x0000u)
226 #define USB_FUNCTION_GETSTATUS_HALT (0x0001u)
227
228 #define USB_FUNCTION_FEATURE_ENDPOINT_HALT (0x0000u)
229 #define USB_FUNCTION_FEATURE_REMOTE_WAKEUP (0x0001u)
230 #define USB_FUNCTION_FEATURE_TEST_MODE (0x0002u)
231
232 #define USB_FUNCTION_bRequest (0xff00u) /* b15-8:bRequest */
233 #define USB_FUNCTION_bmRequestType (0x00ffu) /* b7-0: bmRequestType */
234 #define USB_FUNCTION_bmRequestTypeDir (0x0080u) /* b7 : Data transfer direction */
235 #define USB_FUNCTION_bmRequestTypeType (0x0060u) /* b6-5: Type */
236 #define USB_FUNCTION_bmRequestTypeRecip (0x001fu) /* b4-0: Recipient */
237
238
239 /*******************************************************************************
240 Variable Externs
241 *******************************************************************************/
242
243
244 /*******************************************************************************
245 Functions Prototypes
246 *******************************************************************************/
247 #if 0
248 void R_USB_api_function_init(uint16_t root, uint8_t int_level, uint16_t mode, uint16_t clockmode);
249 uint16_t R_USB_api_function_IsConfigured(uint16_t root);
250 uint16_t R_USB_api_function_CtrlReadStart(uint16_t root, uint32_t size, uint8_t *data);
251 void R_USB_api_function_CtrlWriteStart(uint16_t root, uint32_t size, uint8_t *data);
252 uint16_t R_USB_api_function_start_send_transfer(uint16_t root, uint16_t pipe, uint32_t size, uint8_t *data);
253 uint16_t R_USB_api_function_check_pipe_status(uint16_t root, uint16_t pipe, uint32_t *size);
254 void R_USB_api_function_clear_pipe_status(uint16_t root, uint16_t pipe);
255 void R_USB_api_function_start_receive_transfer(uint16_t root, uint16_t pipe, uint32_t size, uint8_t *data);
256 void R_USB_api_function_set_pid_buf(uint16_t root, uint16_t pipe);
257 void R_USB_api_function_set_pid_nak(uint16_t root, uint16_t pipe);
258 void R_USB_api_function_set_pid_stall(uint16_t root, uint16_t pipe);
259 void R_USB_api_function_clear_pid_stall(uint16_t root, uint16_t pipe);
260 uint16_t R_USB_api_function_get_pid(uint16_t root, uint16_t pipe);
261 int32_t R_USB_api_function_check_stall(uint16_t root, uint16_t pipe);
262 void R_USB_api_function_set_sqclr(uint16_t root, uint16_t pipe);
263 void R_USB_api_function_set_sqset(uint16_t root, uint16_t pipe);
264 void R_USB_api_function_set_csclr(uint16_t root, uint16_t pipe);
265 void R_USB_api_function_set_curpipe(uint16_t root, uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw);
266 void R_USB_api_function_clear_brdy_sts(uint16_t root, uint16_t pipe);
267 void R_USB_api_function_clear_bemp_sts(uint16_t root, uint16_t pipe);
268 void R_USB_api_function_clear_nrdy_sts(uint16_t root, uint16_t pipe);
269 void R_USB_api_function_enable_brdy_int(uint16_t root, uint16_t pipe);
270 void R_USB_api_function_disable_brdy_int(uint16_t root, uint16_t pipe);
271 void R_USB_api_function_enable_bemp_int(uint16_t root, uint16_t pipe);
272 void R_USB_api_function_disable_bemp_int(uint16_t root, uint16_t pipe);
273 void R_USB_api_function_enable_nrdy_int(uint16_t root, uint16_t pipe);
274 void R_USB_api_function_disable_nrdy_int(uint16_t root, uint16_t pipe);
275 void R_USB_api_function_stop_transfer(uint16_t root, uint16_t pipe);
276 #endif
277
278 #ifdef USB0_FUNCTION_API_H
279 void usb0_function_interrupt(uint32_t int_sense);
280 void usb0_function_dma_interrupt_d0fifo(uint32_t int_sense);
281 void usb0_function_dma_interrupt_d1fifo(uint32_t int_sense);
282
283 void usb0_function_Class0(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
284 void usb0_function_Class1(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
285 void usb0_function_Class2(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
286 void usb0_function_Class3(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
287 void usb0_function_Class4(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
288 void usb0_function_Class5(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
289 void usb0_function_Vendor0(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
290 void usb0_function_Vendor1(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
291 void usb0_function_Vendor2(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
292 void usb0_function_Vendor3(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
293 void usb0_function_Vendor4(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
294 void usb0_function_Vendor5(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
295 void usb0_function_ResetDescriptor(uint16_t mode);
296
297 IRQn_Type Userdef_USB_usb0_function_d0fifo_dmaintid(void);
298 IRQn_Type Userdef_USB_usb0_function_d1fifo_dmaintid(void);
299 void Userdef_USB_usb0_function_attach(void);
300 void Userdef_USB_usb0_function_detach(void);
301 void Userdef_USB_usb0_function_delay_1ms(void);
302 void Userdef_USB_usb0_function_delay_xms(uint32_t msec);
303 void Userdef_USB_usb0_function_delay_10us(uint32_t usec);
304 void Userdef_USB_usb0_function_delay_500ns(void);
305 void Userdef_USB_usb0_function_start_dma(USB_FUNCTION_DMA_t *dma, uint16_t dfacc);
306 uint32_t Userdef_USB_usb0_function_stop_dma0(void);
307 uint32_t Userdef_USB_usb0_function_stop_dma1(void);
308
309 void usb0_function_stop_transfer(uint16_t pipe);
310 void usb0_function_enable_brdy_int(uint16_t pipe);
311 void usb0_function_disable_brdy_int(uint16_t pipe);
312 void usb0_function_enable_bemp_int(uint16_t pipe);
313 void usb0_function_disable_bemp_int(uint16_t pipe);
314 void usb0_function_enable_nrdy_int(uint16_t pipe);
315 void usb0_function_disable_nrdy_int(uint16_t pipe);
316 #endif
317
318 #ifdef USB1_FUNCTION_API_H
319 void usb1_function_interrupt(uint32_t int_sense);
320 void usb1_function_dma_interrupt_d0fifo(uint32_t int_sense);
321 void usb1_function_dma_interrupt_d1fifo(uint32_t int_sense);
322
323 void usb1_function_Class0(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
324 void usb1_function_Class1(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
325 void usb1_function_Class2(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
326 void usb1_function_Class3(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
327 void usb1_function_Class4(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
328 void usb1_function_Class5(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
329 void usb1_function_Vendor0(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
330 void usb1_function_Vendor1(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
331 void usb1_function_Vendor2(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
332 void usb1_function_Vendor3(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
333 void usb1_function_Vendor4(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
334 void usb1_function_Vendor5(uint16_t type, uint16_t req, uint16_t value, uint16_t index, uint16_t length);
335 void usb1_function_ResetDescriptor(uint16_t mode);
336
337 uint16_t Userdef_USB_usb1_function_d0fifo_dmaintid(void);
338 uint16_t Userdef_USB_usb1_function_d1fifo_dmaintid(void);
339 void Userdef_USB_usb1_function_attach(void);
340 void Userdef_USB_usb1_function_detach(void);
341 void Userdef_USB_usb1_function_delay_1ms(void);
342 void Userdef_USB_usb1_function_delay_xms(uint32_t msec);
343 void Userdef_USB_usb1_function_delay_10us(uint32_t usec);
344 void Userdef_USB_usb1_function_delay_500ns(void);
345 void Userdef_USB_usb1_function_start_dma(USB_FUNCTION_DMA_t *dma, uint16_t dfacc);
346 uint32_t Userdef_USB_usb1_function_stop_dma0(void);
347 uint32_t Userdef_USB_usb1_function_stop_dma1(void);
348
349 void usb1_function_stop_transfer(uint16_t pipe);
350 void usb1_function_enable_brdy_int(uint16_t pipe);
351 void usb1_function_disable_brdy_int(uint16_t pipe);
352 void usb1_function_enable_bemp_int(uint16_t pipe);
353 void usb1_function_disable_bemp_int(uint16_t pipe);
354 void usb1_function_enable_nrdy_int(uint16_t pipe);
355 void usb1_function_disable_nrdy_int(uint16_t pipe);
356 #endif
357
358 #ifdef __cplusplus
359 }
360 #endif
361
362
363 #endif /* USB_FUNCTION_API_H */
364
365 /* End of File */
Imprint / Impressum