1 /***************************************************************************//**
2 * \file cy_usbfs_dev_drv.h
3 * \version 2.20.2
4 *
5 * Provides API declarations of the USBFS driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2018-2020 Cypress Semiconductor Corporation
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *******************************************************************************/
24
25
26 /**
27 * \addtogroup group_usbfs_dev_drv
28 * \{
29 * The USBFS driver provides an API to interact with a fixed-function USB block.
30 *
31 * The functions and other declarations used in this driver are in cy_usbfs_dev_drv.h.
32 * You can include cy_pdl.h to get access to all functions
33 * and declarations in the PDL.
34 *
35 * The USB block supports Host and Device modes of operation. This version of the
36 * driver supports only Device mode.
37 *
38 * <b>Features:</b>
39 * * Complies with USB Specification 2.0
40 * * Supports full-speed peripheral device operation with a signaling bit
41 * rate of 12 Mbps.
42 * * Supports eight data endpoints and one control endpoint.
43 * * Provides a shared 512-byte buffer for data endpoints.
44 * * Provides dedicated 8-byte memory for control endpoint (EP0).
45 * * Supports four types of transfers: bulk, interrupt, isochronous, and control
46 * * Supports bus- and self-powered configurations
47 * * Supports USB suspend, resume, and remove wakeup.
48 * * Supports three types of logical transfer modes:
49 * * CPU (No DMA) mode (Mode 1).
50 * * Manual DMA mode (Mode 2).
51 * * Automatic DMA mode (Mode 3).
52 * * Supports the maximum packet size:
53 * * 512 bytes using Mode 1 and Mode 2.
54 * * 1023 bytes for isochronous transfer using Mode 3.
55 * * Provides integrated 22 Ohm USB termination resistors on D+ and D- lines,
56 * and 1.5 kOhm pull-up resistor on the D+ line.
57 * * Supports USB 2.0 Link Power Management (LPM).
58 *
59 *
60 ********************************************************************************
61 * \section group_usbfs_dev_drv_use_cases Common Use Cases
62 ********************************************************************************
63 *
64 * <b>The primary usage model for the USBFS driver is to provide a defined API
65 * interface to
66 * <a href="https://cypresssemiconductorco.github.io/usbdev/usbfs_dev_api_reference_manual/html/index.html" target="_blank">
67 * USB Device Middleware</a> component that works on top of it.</b> \n
68 * The driver also provides an API interface for the application to implement the required
69 * functionality:
70 * * \ref group_usbfs_dev_drv_callbacks
71 * * \ref group_usbfs_dev_drv_low_power
72 * * \ref group_usbfs_dev_drv_lpm
73 * * \ref group_usbfs_dev_drv_vbus
74 *
75 ********************************************************************************
76 * \section group_usbfs_dev_drv_configuration Configuration Considerations
77 ********************************************************************************
78 *
79 * This section explains how to configure the USBFS driver and system resources to
80 * enable USB Device operation. The pointers to the populated \ref cy_stc_usbfs_dev_drv_config_t configuration
81 * structure and allocated context are passed in the middleware initialization.
82 * function Cy_USB_Dev_Init. After middleware initialization, it calls
83 * \ref Cy_USBFS_Dev_Drv_Init to initialize the USBFS driver for Device operation.
84
85 ********************************************************************************
86 * \subsection group_usbfs_dev_drv_config Configure Driver
87 ********************************************************************************
88 *
89 * To configure the USBFS driver in Device mode, the configuration structure
90 * \ref cy_stc_usbfs_dev_drv_config_t parameters must be populated.
91 * The configuration structure content significantly depends on the selected
92 * endpoints management mode parameter:
93 *
94 * * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_CPU \n
95 * The <i>epAccess, intrLevelSel and enableLpm</i> must be provided. All
96 * other parameters are do not cares for this mode. Refer to section
97 * \ref group_usbfs_dev_drv_intr to get information about <i>intrLevelSel</i>
98 * configuration.
99 *
100 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_CfgCpu
101 *
102 * * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA \n
103 * To enable DMA operation, the DMA channels must be assigned for each endpoint
104 * to be used. Each DMA channel needs a single DMA descriptor to
105 * operate. The USBFS driver defines the DMA configuration structure
106 * \ref cy_stc_usbfs_dev_drv_dma_config_t to be populated for each DMA
107 * channel.
108 * The code example below provides an initialized USBFS driver DMA configuration
109 * structure:
110 *
111 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_CfgDma_DmaInit
112 *
113 * The pointers to the DMA configuration structure are required into the
114 * \ref cy_stc_usbfs_dev_drv_config_t USBFS driver configuration structure
115 * to allow the USBFS driver to use DMA channels for used endpoints.
116 * The <i>dmaConfig[0]</i> field expects a pointer to the DMA configuration for
117 * data endpoint 1, the <i>dmaConfig[1]</i> field pointer to the DMA configuration
118 * for data endpoint 2, and so on up to data endpoint 8.
119 * The code example below provides an initialized USBFS driver configuration
120 * structure which uses endpoint 1:
121 *
122 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_CfgDma
123 *
124 * * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO \n
125 * DMA Automatic mode needs a DMA channels configuration similar to the described
126 * above. But it also requires one more DMA descriptor for each DMA channel and
127 * DMA output trigger multiplexer. Refer to the \ref group_usbfs_dev_drv_dma section,
128 * for more detail about the trigger multiplexer .
129 * The code example below provides an initialized USBFS driver DMA configuration
130 * structure:
131 *
132 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_CfgDmaAuto_DmaInit
133 *
134 * The driver requires a buffer for data endpoints to operate. This buffer must be
135 * allocated by the user. The buffer size is equal to the sum of all used
136 * endpoints maximum packet sizes. If an endpoint belongs to more than
137 * one alternate setting, select the greatest maximum packet size for this
138 * endpoint. The driver configuration structure \ref cy_stc_usbfs_dev_drv_config_t
139 * parameters <i>epBuffer and epBufferSize</i> pass the buffer to the driver.
140 *
141 * The code example below provides an initialized USBFS driver configuration
142 * structure that uses data endpoint 1 with a maximum packet size of 63 bytes and
143 * set 16-bit access:
144 *
145 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_CfgDmaAuto
146 *
147 *
148 * \note
149 * The endpoint buffer allocation depends on the access type used: 8-bit or 16-bit.
150 * Refer to \ref group_usbfs_dev_drv_ep_management_buf_access for more information.
151 *
152 ********************************************************************************
153 * \subsection group_usbfs_dev_drv_pins Assign and Configure Pins
154 ********************************************************************************
155 *
156 * Only dedicated USB pins can be used for USB operation. Keep the default
157 * USB pins configuration because after the USBFS driver initializes, the
158 * USB block takes control over the pins and drives them properly.
159 *
160 ********************************************************************************
161 * \subsection group_usbfs_dev_drv_clock Assign and Configure Clocks
162 ********************************************************************************
163 *
164 * The USB hardware block requires two clock sources for operation:
165 * * Clk_HF3 (USB clock) must be 48 MHz. The accuracy of the USB clock must be
166 * within -/+ 0.25%. Note that Clk_HF3 has an integer divider so the input
167 * clock can be a multiple of 48. The valid options to get an internal USB
168 * clock are PLL or ECO.\n
169 * <b>The typical configuration is:</b> the IMO output is used by the PLL to
170 * generate Clk_HF3 (USB clock). To meet USB clock accuracy requirements
171 * the IMO must be trimmed with USB SOF signal. Therefore, the driver
172 * \ref Cy_USBFS_Dev_Drv_Init function enables the IMO trim from USB.
173 *
174 * * Divided Clk_Peri clock (PCLK_USB_CLOCK_DEV_BRS) equal to 100 kHz
175 * used to detect a Bus Reset event. Use one of the 8-bit or 16-bit dividers
176 * to provide required clock frequency.
177 *
178 * The code example below shows the connection source path 1
179 * (which expected provide 48 MHz -/+ 0.25% clock) to Clk_HF3 and Bus Reset clock
180 * (Clk_Peri assumed to be 50 MHz):
181 *
182 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_ClockInit
183 *
184 * Refer to \ref group_sysclk driver API for more detail about clock
185 * configuration.
186 *
187 * The FLL (Clock Path 0) with ECO also can be used as an alternative USB source
188 * with the next configuration settings, for 48 MHz:
189 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_fllConfig48MHz
190 * And for 96 MHz:
191 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_fllConfig96MHz
192 * Use these structures with \ref Cy_SysClk_FllManualConfigure
193 *
194 ********************************************************************************
195 * \subsection group_usbfs_dev_drv_dma Assign and Route DMA Channels
196 ********************************************************************************
197 *
198 * The USBFS driver requires a DMA controller to operate in DMA Manual and Automatic modes.
199 * The USB hardware block supports the DMA request and feedback lines for each
200 * data endpoint. Therefore, up to eight DMA channels serve eight data endpoints.
201 * The connection between the USB block and the DMA channels is set using the trigger
202 * muxes infrastructure. The USB block output DMA request line is connected to
203 * the DMA channel trigger input. This allows the USB block to request a DMA transfer.
204 * The DMA completion output is connected to the USB block burst end input.
205 * This allows the USB block to get notification that a DMA transfer has been completed
206 * and a next DMA request can be sent. The USBFS driver DMA configuration
207 * structure requires the <i>outTrigMux</i> field to provide the trigger mux that
208 * performs DMA completion and USB block burst end connection.
209 *
210 * Refer to \ref group_trigmux for more detail on the routing capabilities.
211 *
212 * The code examples below shows a connection DMA channel and USB block and the define
213 * for <i>outTrigMux</i> field initialization for the CY8C6xx6 or CY8C6xx7 devices.
214 *
215 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_DmaConnect
216 *
217 ********************************************************************************
218 * \subsection group_usbfs_dev_drv_intr Configure Interrupts
219 ********************************************************************************
220 *
221 * <b>The interrupts are mandatory for the USBFS driver operation.</b>
222 * The USBFS block provides multiple interrupt sources to be assigned to
223 * trigger one of the three interrupts: Low, Medium, or High. This allows to
224 * assign different priority to the interrupt sources handling.
225 * The \ref cy_stc_usbfs_dev_drv_config_t structure provides the
226 * <i>intrLevelSel</i> field which initializes the INTR_LVL_SEL
227 * register. This register configures which interrupt the interrupt source will trigger.
228 *
229 * \note
230 * The interrupt name (Low, Medium, or High) does not specify the interrupt
231 * priority. The interrupt priority is configured in NVIC.
232 *
233 * The recommended/default configuration is:
234 * * Interrupt Low: Bus Reset, Control Endpoint and SOF.
235 * * Interrupt Medium: Endpoint 1-8 Completion.
236 * * Interrupt High: Arbiter and LPM.
237 *
238 * However, the final configuration must be defined by the application.
239 *
240 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_UserLvlSel
241 *
242 * The \ref Cy_USBFS_Dev_Drv_Interrupt function must be called in the interrupt
243 * handler for the selected USB block instance. Note that
244 * the \ref Cy_USBFS_Dev_Drv_Interrupt has the parameter <i>intrCause</i> that
245 * must be assigned by calling the appropriate interrupt cause function:
246 * * \ref Cy_USBFS_Dev_Drv_GetInterruptCauseHi
247 * * \ref Cy_USBFS_Dev_Drv_GetInterruptCauseMed
248 * * \ref Cy_USBFS_Dev_Drv_GetInterruptCauseLo
249 *
250 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_IntrHandlers
251 *
252 * Finally, the interrupts must be configured and interrupt handler routines
253 * hook up to NVIC. The code below assigns the interrupt priorities accordingly
254 * to interrupt names. The priorities among the USBFS interrupts are as follows:
255 * High - the greatest; Medium - the middle; Low - the lowest.
256 *
257 * \note
258 * For proper operation in Manual DMA mode (Mode 2) the Arbiter interrupt source
259 * must be assigned to interrupt which priority is greater than interrupt
260 * triggered by Data Endpoint 1-8 Completion interrupt sources. \n
261 * For Automatic DMA mode (Mode 3) the rule above is recommend to follow.
262 *
263 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_IntrCfg
264 * \snippet usbfs/snippet/main.c snipped_Cy_USBFS_Dev_Drv_IntrCfgHook
265 *
266 ********************************************************************************
267 * \section group_usbfs_dev_drv_ep_management Endpoint Buffer Management Modes
268 ********************************************************************************
269 *
270 * The USBFS hardware block supports three endpoint buffer management modes:
271 * CPU (No DMA) mode (Mode 1), Manual DMA mode (Mode 2), and Automatic DMA mode (Mode 3).
272 * These modes are listed using enum \ref cy_en_usbfs_dev_drv_ep_management_mode_t.
273 * The following sub-sections provide more information about the endpoint buffer
274 * management.
275 *
276 ********************************************************************************
277 * \subsection group_usbfs_dev_drv_ep_management_buff Hardware buffers
278 ********************************************************************************
279 *
280 * The USBFS block has a 512-byte hardware buffer that is divided between all
281 * data endpoints used in the selected configuration. How the hardware buffer
282 * is divided between endpoints depends on the selected endpoint buffer management
283 * modes:
284 *
285 * * \ref group_usbfs_dev_drv_ep_management_mode1 and \ref group_usbfs_dev_drv_ep_management_mode2
286 * Each data endpoint consumes space (number of bytes) in the hardware buffer
287 * that is equal to the endpoint maximum packet size defined in the endpoint
288 * descriptor. The total space consumed by all endpoints is restricted
289 * by the size of hardware buffer (512 bytes). When an endpoint appears in the
290 * different alternate settings and has a different maximum packet size, the greatest
291 * value is selected to the allocate space of the endpoint in the
292 * hardware buffer. This is to ensure correct USB Device operation when interface
293 * alternate settings are changed. Note that endpoint can consume extra byte in
294 * the hardware buffer when 16-bit access is used (See \ref
295 * group_usbfs_dev_drv_ep_management_buf_access for more information).
296 *
297 * * \ref group_usbfs_dev_drv_ep_management_mode3
298 * Each data endpoint consumes 32 bytes in the hardware buffer (if all eight
299 * endpoints are used, the consumed buffer space is 32 * 8 = 256 byte).
300 * This buffer is called "dedicated endpoint buffer". It acts as an endpoint
301 * FIFO. The remaining space (256 bytes, if all eight endpoints are
302 * used) in the hardware buffer is used by any endpoint that currently
303 * communicates. This part of the buffer is called "common area". This hardware
304 * buffer configuration gives a sufficient dedicated buffer size for each used
305 * endpoint and common area for operation. The total space consumed by all
306 * endpoints is not restricted by the size of the hardware buffer.
307 *
308 * To access the hardware buffer, the endpoint data register is read or written by
309 * CPU or DMA. On each read or write, buffer pointers are updated to access
310 * a next data element.
311 *
312 ********************************************************************************
313 * \subsection group_usbfs_dev_drv_ep_management_buf_access Hardware Buffer Access
314 ********************************************************************************
315 *
316 * The USBFS block provides two sets of data registers: 8-bit and 16-bit. Either
317 * the 8-bit endpoint data register or the 16-bit endpoint data register can
318 * be used to read/write to the endpoint buffer. The buffer access is controlled
319 * by the <i>epAccess</i> field of the driver configuration structure
320 * \ref cy_stc_usbfs_dev_drv_config_t.
321 * The endpoint hardware buffer and SRAM buffer must be allocated using the
322 * rules below when the 16-bit access is used:
323 * * The buffer size must be even. If the endpoint maximum packet size is odd
324 * the allocated buffer size must be equal to (maximum packet size + 1).
325 * * The buffer must be aligned to the 2-byte boundary.
326 *
327 * The driver provides the \ref CY_USBFS_DEV_DRV_ALLOC_ENDPOINT_BUFFER macro that
328 * applies the rules above to allocate the SRAM buffer for an endpoint. This macro
329 * should be used by application to hide configuration differences.
330 * <b>However, in this case the application must ignore extra bytes in the buffer.</b>
331 * Alternately, apply the rules above only for the 16-bits access type configuration.
332 *
333 * The driver firmware allocates an endpoint hardware buffer (dividing hardware buffer
334 * between utilized endpoints). Therefore, for \ref group_usbfs_dev_drv_ep_management_mode1
335 * and \ref group_usbfs_dev_drv_ep_management_mode2, an endpoint whose
336 * maximum packet size is odd, consumes an extra byte in the hardware buffer
337 * when the 16-bit access is used. This is not applicable for \ref group_usbfs_dev_drv_ep_management_mode3
338 * because endpoints dedicated buffer are even and aligned.
339 *
340 * In addition, to operate in \ref group_usbfs_dev_drv_ep_management_mode3,
341 * the driver needs an internal SRAM buffer for endpoints. The buffer size is a
342 * sum of all endpoint buffers. When the 16-bit access is used, each endpoint buffer
343 * must be allocated using the rules above. The driver configuration structure
344 * \ref cy_stc_usbfs_dev_drv_config_t has <i>epBuffer and epBufferSize</i> fields
345 * to pass the allocated buffer to the driver. \n
346 * For example: the USB Device uses three data endpoints whose max packets are
347 * 63 bytes, 63 bytes, and 8 bytes. The endpoints buffer for the driver must be
348 * allocated as follows:
349 * * 8-bits: uint8_t endpointsBuffer[63 + 63 + 8];
350 * * 16-bits: uint8_t endpointsBuffer[(63+1) + (63+1) + 8] CY_ALLIGN(2); or
351 * CY_USBFS_DEV_DRV_ALLOC_ENDPOINT_BUFFER((63+1) + (63+1) + 8);
352 *
353 ********************************************************************************
354 * \subsection group_usbfs_dev_drv_ep_management_mode1 CPU mode (Mode 1)
355 ********************************************************************************
356 *
357 * CPU handles data transfers between the user-provided SRAM endpoint-buffer
358 * and the USB block hardware-buffer when \ref Cy_USBFS_Dev_Drv_ReadOutEndpoint
359 * or \ref Cy_USBFS_Dev_Drv_LoadInEndpoint is called.
360 *
361 * \image html usbfs_ep_mngmnt_mode1.png
362 *
363 ********************************************************************************
364 * \subsection group_usbfs_dev_drv_ep_management_mode2 Manual DMA mode (Mode 2)
365 ********************************************************************************
366 *
367 * DMA handles data transfers between the user-provided SRAM endpoint
368 * buffer and the USB block hardware buffer. The DMA request is issued by CPU
369 * to execute a data transfer when \ref Cy_USBFS_Dev_Drv_ReadOutEndpoint or
370 * \ref Cy_USBFS_Dev_Drv_LoadInEndpoint.
371 *
372 * \image html usbfs_ep_mngmnt_mode2.png
373 *
374 ********************************************************************************
375 * \subsection group_usbfs_dev_drv_ep_management_mode3 Automatic DMA mode (Mode 3)
376 ********************************************************************************
377 *
378 * DMA handles data transfers between the driver SRAM endpoints buffer and
379 * the USB block hardware buffer. The USB block generates DMA requests
380 * automatically. When USB transfer starts, the USB block triggers DMA
381 * requests to transfer data between the driver endpoint buffer and the hardware
382 * buffer until transfer completion. The common area acts as a FIFO to (and keeps
383 * data that does not fit into) the endpoint dedicated buffer. For IN endpoints,
384 * the dedicated buffer is pre-loaded before enabling USB Host access to the endpoint.
385 * This gives time for the DMA to provide remaining data before underflow
386 * occurs. The USB block hardware has a feedback connection with the DMA
387 * and does not issue new DMA request until it receives notification that the
388 * previous DMA transfer completed.
389 * When the \ref Cy_USBFS_Dev_Drv_ReadOutEndpoint or \ref Cy_USBFS_Dev_Drv_LoadInEndpoint
390 * function is called, the memcpy function is used to copy data from/into the
391 * driver endpoints buffer to the user-provided endpoint buffer.
392 * The driver provides the \ref Cy_USBFS_Dev_Drv_OverwriteMemcpy function to
393 * replace memcpy function by one that has been custom implemented (the DMA can be used for data copy).
394 *
395 * \image html usbfs_ep_mngmnt_mode3.png
396 *
397 * \warning
398 * When DMA data transfer is not fast enough, an overflow or underflow
399 * interrupt triggers for the impacted endpoint. This must never happen
400 * because this error condition indicates a system failure with no recovery.
401 * To fix this, get the DMA channel assigned to this endpoint greater priority or
402 * increase the clock the DMA operates at.
403 *
404 ********************************************************************************
405 * \section group_usbfs_dev_drv_callbacks Callbacks Usage
406 ********************************************************************************
407 *
408 * The driver provides the following callbacks that can be used by the application:
409 * 1. Data endpoint 1-8 completion. This callback is invoked when the USB Host
410 * completed communication with the endpoint. For IN endpoints, it means that data has
411 * been read by the USB Host. For OUT endpoints, it means that data has been written
412 * by the USB Host. Call \ref Cy_USBFS_Dev_Drv_RegisterEndpointCallback to
413 * register callback function.
414 *
415 * 2. Start Of Frame packet received. This can be used in the application to
416 * synchronize with SOF packets or for monitoring the bus activity.
417 * Call \ref Cy_USBFS_Dev_Drv_RegisterSofCallback to register callback function.
418 *
419 * 3. LPM (Link Power Management) packet received. This must be used to implement
420 * LPM power optimization. Call \ref Cy_USBFS_Dev_Drv_RegisterLpmCallback to
421 * register callback function.
422 *
423 * Also, the driver provides callbacks for a Bus Reset event and Control Endpoint 0
424 * communication events (setup packet, in packet, out packet). But these
425 * callbacks are used by middleware and must not be used by the application directly.
426 * The middleware provides appropriate hooks for these events.
427 *
428 ********************************************************************************
429 * \section group_usbfs_dev_drv_vbus VBUS Detection
430 ********************************************************************************
431 *
432 * The USB specification requires that no device supplies current on VBUS at its
433 * upstream facing port at any time. To meet this requirement, the device must
434 * monitors for the presence or absence of VBUS and removes power from the Dp/Dm
435 * pull-up resistor if VBUS is absent. The USBFS driver does not provide any
436 * support of VBUS monitoring or detection. The application firmware must implement
437 * the required functionality using a VDDUSB power pad or GPIO. Refer to the
438 * Universal Serial Bus (USB) Device Mode section, sub-section VBUS Detection
439 * in the technical reference manual (TRM).
440 *
441 * Connect the VBUS through a resistive network when the
442 * regular GPIO is used for VBUS detection to save the pin from voltage picks on VBUS,
443 * or use GPIO tolerant over the voltage. An example schematic is shown below.
444 *
445 * \image html usbfs_vbus_connect_schem.png
446 *
447 * \note Power is removed when the USB cable is removed from the USB Host
448 * for bus-powered USB Device. Therefore, such a USB Device complies with
449 * specification requirement above.
450 *
451 ********************************************************************************
452 * \section group_usbfs_dev_drv_low_power Low Power Support
453 ********************************************************************************
454 *
455 * The USBFS driver supports the USB Suspend, Resume, and Remote Wakeup functionality.
456 * This functionality is tightly related with the user application. The USBFS
457 * driver provides only the API interface which helps the user achieve the desired
458 * low-power behavior. The additional processing is required from the user application.
459 * The description of application processing is provided below.
460 *
461 * Normally, the USB Host sends an SOF packet every 1 ms (at full speed), and this
462 * keeps the USB Device awake. The USB Host suspends the USB Device by not
463 * sending anything to the USB Device for 3 ms. To recognize this condition, the bus
464 * activity must be checked. This can be done using the \ref Cy_USBFS_Dev_Drv_CheckActivity
465 * function or by monitoring the SOF interrupt. A suspended device may draw no
466 * more than 0.5 mA from VBUS. Therefore, put the device into low-power
467 * mode to consume less current.
468 * The \ref Cy_USBFS_Dev_Drv_Suspend function must be called before entering
469 * low-power mode. When the USB Host wants to wake the device after a suspend,
470 * it does so by reversing the polarity of the signal on the data lines for at
471 * least 20 ms. The resume signaling is completed with a low-speed end-of-packet
472 * signal. The USB block is disabled during Deep Sleep or Hibernate low-power modes.
473 * To exit a low-power mode when USB Host drives resume, a falling edge interrupt
474 * on Dp must be configured before entering these modes. The \ref Cy_USBFS_Dev_Drv_Resume
475 * function must be called after exiting the low-power mode. To resume communication with
476 * the USB Host, the data endpoints must be managed: the OUT endpoints must be
477 * enabled and IN endpoints must be loaded with data.
478 *
479 * \note After entering low-power mode, the data which was left in the IN or OUT
480 * endpoint buffers is not restored after the device's wake-up and is lost.
481 * Therefore, it must be stored in the SRAM for OUT endpoint or read by the Host for
482 * the IN endpoint before entering Low-power mode.
483 *
484 * If the USB Device supports remote wakeup functionality, the application has
485 * to use middleware function Cy_USB_Dev_IsRemoteWakeupEnabled to determine whether
486 * remote wakeup was enabled by the USB Host. When the device is suspended and
487 * it determines the conditions to initiate a remote wakeup are met,
488 * the application must call the \ref Cy_USBFS_Dev_Drv_Force
489 * function to force the appropriate J and K states onto the USB bus, signaling a
490 * remote wakeup condition. Note that \ref Cy_USBFS_Dev_Drv_Resume must be called
491 * first to restore the condition.
492 *
493 ********************************************************************************
494 * \section group_usbfs_dev_drv_lpm Link Power Management (LPM)
495 ********************************************************************************
496 *
497 * Link Power Management is a USB low-power mode feature that provides more
498 * flexibility in terms of features than the existing resume mode. This feature
499 * is similar to the existing Suspend/Resume, but has transitional latencies of
500 * tens of microseconds between power states (instead of 3 to greater than 20
501 * millisecond latencies of the USB 2.0 Suspend/Resume).
502 *
503 * USB2.0 Power states are re-arranged as below with the introduction of LPM.
504 * The existing power states are re-named with LPM:
505 * * L0 (On)
506 * * L1 (Sleep) -- Newly Introduced State in LPM
507 * * L2 (Suspend)
508 * * L3 (Powered-Off)
509 *
510 * LPM state transitions between is shown below:
511 *
512 * \image html usbfs_lpm_state_transition.png
513 *
514 * For example, a USB Host must transition a link from L1 (Sleep) to L0 before
515 * transitioning it to L2 (Suspend), and similarly when transitioning from L2 to L1.
516 *
517 * When a USB Host is ready to transition a USB Device from L0 to a deeper power
518 * savings state, it issues an LPM transaction to the USB Device. The USB Device
519 * function responds with an ACK if it is ready to make the transition or a NYET
520 * (Not Yet) if it is not ready (usually because it is has data pending for the
521 * USB Host). A USB Device will transmit a STALL handshake if it does not support
522 * the requested link state. If the USB Device detects errors in either of the
523 * token packets or does not understand the protocol extension transaction,
524 * no handshake is returned.
525 *
526 * \image html usbfs_lpm_responses.png
527 *
528 * After USB Device is initialized, the LPM transaction is to be acknowledged (ACKed)
529 * meaning that the device is ready to enter the requested low-power mode. To override this
530 * behavior, use \ref Cy_USBFS_Dev_Drv_Lpm_SetResponse. \n
531 *
532 * The USB block provides an interrupt source to define that an LPM transaction was
533 * received and acknowledged (ACKed). Use the \ref Cy_USBFS_Dev_Drv_RegisterLpmCallback
534 * function to register the application level callback function to serve the LPM
535 * transaction. The callback function can notify the application about an LPM transaction
536 * and can use \ref Cy_USBFS_Dev_Drv_Lpm_GetBeslValue read to read Best Effort Service
537 * Latency (BESL) values provided as part of an LPM transaction. The BESL value
538 * indicates the amount of time from the start of a resume to when the USB Host
539 * attempts to begin issuing transactions to the USB Device. The
540 * application must use the value BESL to decide which low-power mode is entered
541 * to meet wakeup timing. The LPM transaction also contains the field that allows a
542 * remote to wake up. Use \ref Cy_USBFS_Dev_Drv_Lpm_RemoteWakeUpAllowed to get its
543 * value.
544 *
545 * LPM related USB 2.0 Extension Descriptor provides attributes fields named
546 * baseline BESL and deep BESL to provide a range of values for different low-power
547 * optimization. The recommended use of these fields is that the
548 * baseline BESL field will have a value less than the deep BESL field. The
549 * expected use is the baseline BESL value communicates a nominal power savings
550 * design point and the deep BESL value communicates a significant power saving
551 * design point.
552 * For example, when the received BESL is less than baseline BESL, leave the device in
553 * Active mode. When it is between baseline BESL and deep BESL, put the device into
554 * Deep Sleep mode. When it is greater than deep BESL, put the device into
555 * Hibernate mode.
556 *
557 * \note
558 * The driver implements the USB Full-Speed device which does not support the LPM
559 * NYET response.
560 *
561 * \note
562 * The device will restart after Hibernate mode and the USB Device must
563 * be initialized at the application level. Call the initialization functions
564 * instead of \ref Cy_USBFS_Dev_Drv_Resume. The application must ensure that
565 * the device will resume within the time defined in the BESL value of LPM request.
566 *
567 ********************************************************************************
568 * \section group_usbfs_drv_more_information More Information
569 ********************************************************************************
570 *
571 * For more detail on the USB Full-Speed Device peripheral, refer to the
572 * section Universal Serial Bus (USB) Device Mode in the technical reference
573 * manual (TRM).
574 *
575 ********************************************************************************
576 * \section group_usbfs_drv_changelog Changelog
577 ********************************************************************************
578 *
579 * <table class="doxtable">
580 * <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
581 * <tr>
582 * <td>2.20.2</td>
583 * <td>Minor syntax updates. Added specific deviations documentation.</td>
584 * <td>Updated for compliance with MISRA-C:2012 standard.</td>
585 * </tr>
586 * <tr>
587 * <td>2.20.1</td>
588 * <td>Minor documentation updates.</td>
589 * <td>Documentation enhancement.</td>
590 * </tr>
591 * <tr>
592 * <td rowspan="2">2.20</td>
593 * <td>Fix configuration register value restoring in resume routine after
594 * Deep Sleep.
595 * </td>
596 * <td>Fix issue that USB Device stops working in DMA modes after wake up
597 * from Deep Sleep.
598 * </td>
599 * </tr>
600 * <tr>
601 * <td>The LPM requests are ignored after wake up from Deep Sleep and the
602 * host starts sending SOFs.</td>
603 * <td>Updated \ref Cy_USBFS_Dev_Drv_Resume function to restore LPM control
604 * register after exit Deep Sleep.
605 * </td>
606 * </tr>
607 * <tr>
608 * <td>2.10</td>
609 * <td>Returns the data toggle bit into the previous state after detecting
610 * that the host is retrying an OUT transaction.</td>
611 * <td>The device was not able to recover the data toggle bit and
612 * continues communication through the endpoint after the host retried
613 * the OUT transaction (the retried transaction has the same toggle bit
614 * as the previous had).
615 * </td>
616 * </tr>
617 * <tr>
618 * <td>2.0</td>
619 * <td>The list of changes to support the MBED-OS USB Device stack is provided below:
620 * - Changed the processing of the control transfers.
621 * - Updated the endpoint 0 service functions to update the endpoint 0 registers
622 * before the function returns.
623 * - Moved the set-device-address processing into the driver from the middleware.
624 * - Changed the flow to configure endpoints after configuration change:
625 * unconfigure the device or remove all endpoints, add endpoints, configure
626 * the device. Updated the functions:
627 * \ref Cy_USBFS_Dev_Drv_UnConfigureDevice, \ref Cy_USBFS_Dev_Drv_AddEndpoint
628 * and \ref Cy_USBFS_Dev_Drv_ConfigDevice.
629 * Removed the Cy_USBFS_Dev_Drv_ConfigDeviceComplete function because it is no needed anymore.
630 * - Added the functions: \ref Cy_USBFS_Dev_Drv_Ep0ReadResult(), \ref Cy_USBFS_Dev_Drv_SetAddress()
631 * and \ref Cy_USBFS_Dev_Drv_GetEp0MaxPacket().
632 * - Changed the function signature \ref Cy_USBFS_Dev_Drv_Ep0Stall().
633 * - Obsolete function Cy_USBFS_Dev_Drv_GetEndpointStallState; the \ref
634 * Cy_USBFS_Dev_Drv_GetEndpointState() updated to be used instead of the obsolete function.
635 * - Reduced the time required to complete abort operation in function \ref Cy_USBFS_Dev_Drv_Abort.
636 * Obsolete function Cy_USBFS_Dev_Drv_AbortComplete because entire abort operation is handled by
637 * \ref Cy_USBFS_Dev_Drv_Abort.
638 * - Added the endpoint address argument to the \ref cy_cb_usbfs_dev_drv_ep_callback_t to simplify
639 * endpoint transfer complete event processing for the MBED-OS USB Device stack.
640 * </td>
641 * <td>Updated the driver to support the MBED-OS USB Device stack and Cypress
642 * USB Device middleware.</td>
643 * </tr>
644 * <tr>
645 * <td rowspan="2">1.10</td>
646 * <td>Fixed the \ref Cy_USBFS_Dev_Drv_Disable function to not disable DMA
647 * in CPU mode.</td>
648 * <td>Calling this function triggers assert because DMA for endpoints is not
649 * initialized/used in the CPU mode.</td>
650 * </tr>
651 * <tr>
652 * <td>Updated the condition statement in the \ref CY_USBFS_DEV_DRV_ALLOC_ENDPOINT_BUFFER
653 * macro to explicitly check against non-zero.</td>
654 * <td>Fixed MISRA 13.2 violation in the macro.</td>
655 * </tr>
656 * <tr>
657 * <td>1.0</td>
658 * <td>The initial version.</td>
659 * <td></td>
660 * </tr>
661 * </table>
662 *
663 ********************************************************************************
664 *
665 * \defgroup group_usbfs_dev_drv_macros Macros
666 * \{
667 \defgroup group_usbfs_dev_drv_macros_intr_level Interrupt Level
668 * \defgroup group_usbfs_dev_drv_macros_intr_cause Interrupt Cause
669 * \defgroup group_usbfs_dev_drv_macros_ep_xfer_err Transfer Errors
670 * \}
671 * \defgroup group_usbfs_dev_drv_functions Functions
672 * \{
673 * \defgroup group_usbfs_dev_hal_functions_common Initialization Functions
674 * \defgroup group_usbfs_dev_drv_functions_interrupts Interrupt Functions
675 * \defgroup group_usbfs_dev_hal_functions_ep0_service Endpoint 0 Service Functions
676 * \defgroup group_usbfs_dev_hal_functions_endpoint_config Data Endpoint Configuration Functions
677 * \defgroup group_usbfs_dev_hal_functions_data_xfer Data Endpoint Transfer Functions
678 * \defgroup group_usbfs_dev_drv_functions_low_power Low Power Functions
679 * \defgroup group_usbfs_dev_drv_functions_lpm LPM (Link Power Management) Functions
680 * \}
681 * \defgroup group_usbfs_dev_drv_data_structures Data Structures
682 * \defgroup group_usbfs_dev_drv_enums Enumerated Types
683 * \}
684 */
685
686
687 #if !defined(CY_USBFS_DEV_DRV_H)
688 #define CY_USBFS_DEV_DRV_H
689
690 #include "cy_device.h"
691
692 #if defined (CY_IP_MXUSBFS) && defined (CY_IP_MXPERI)
693
694 #include "cy_dma.h"
695 #include "cy_trigmux.h"
696 #include "cy_usbfs_dev_drv_reg.h"
697
698 #if defined(__cplusplus)
699 extern "C" {
700 #endif
701
702 /*******************************************************************************
703 * Driver version and ID
704 *******************************************************************************/
705
706 /**
707 * \addtogroup group_usbfs_dev_drv_macros
708 * \{
709 */
710
711 /** USBFS Driver major version */
712 #define CY_USBFS_VERSION_MAJOR (2)
713
714 /** USBFS Driver minor version */
715 #define CY_USBFS_VERSION_MINOR (20)
716
717 /** USBFS Driver identifier */
718 #define CY_USBFS_ID CY_PDL_DRV_ID(0x3BU)
719
720 /** USBFS Driver mode position in STATUS CODE: 0 - Device, 1 - Host */
721 #define CY_USBFS_MODE_POS (15UL)
722
723 /** USBFS Driver status code Device */
724 #define CY_USBFS_DEV_DRV_STATUS_CODE (0U)
725 /** \} group_usbfs_dev_drv_macros */
726
727
728 /*******************************************************************************
729 * Enumerated Types
730 *******************************************************************************/
731
732 /**
733 * \addtogroup group_usbfs_dev_drv_enums
734 * \{
735 */
736 /** USBFS Device Driver return codes */
737 typedef enum
738 {
739 /** Operation completed successfully */
740 CY_USBFS_DEV_DRV_SUCCESS = 0U,
741
742 /** One or more input parameters are invalid */
743 CY_USBFS_DEV_DRV_BAD_PARAM = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 1U),
744
745 /** There is not enough space in the buffer to be allocated for the endpoint (hardware or RAM) */
746 CY_USBFS_DEV_DRV_BUF_ALLOC_FAILED = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 2U),
747
748 /** Failure during DMA configuration */
749 CY_USBFS_DEV_DRV_DMA_CFG_FAILED = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 3U),
750
751 /** Timeout during dynamic reconfiguration */
752 CY_USBFS_DEV_DRV_EP_DYN_RECONFIG_TIMEOUT = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 4U),
753
754 /** Timeout during execution of the DMA read request for the OUT endpoint
755 * (only applicable in \ref group_usbfs_dev_drv_ep_management_mode2)
756 */
757 CY_USBFS_DEV_DRV_EP_DMA_READ_TIMEOUT = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 5U),
758
759 /** Timeout during execution of the DMA read request for the OUT endpoint
760 * (only applicable in \ref group_usbfs_dev_drv_ep_management_mode2)
761 */
762 CY_USBFS_DEV_DRV_EP_DMA_WRITE_TIMEOUT = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 6U),
763
764 } cy_en_usbfs_dev_drv_status_t;
765
766
767 /** Data Endpoints Buffer Management Mode */
768 typedef enum
769 {
770 /** CPU manages a data transfer between the hardware endpoints buffer
771 * and the user SRAM
772 */
773 CY_USBFS_DEV_DRV_EP_MANAGEMENT_CPU = 0,
774
775 /** DMA manages data transfer between the hardware endpoints buffer and
776 * the user SRAM
777 */
778 CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA = 1,
779
780 /** The DMA automatically manages a data transfer between the hardware endpoints
781 * FIFO buffer and the user SRAM
782 */
783 CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO = 2,
784 } cy_en_usbfs_dev_drv_ep_management_mode_t;
785
786 /** Data Endpoint Register Access Type */
787 typedef enum
788 {
789 CY_USBFS_DEV_DRV_USE_8_BITS_DR, /**< Use 8-bits registers to access the data endpoints */
790 CY_USBFS_DEV_DRV_USE_16_BITS_DR, /**< Use 16-bits registers to access the data endpoints */
791 } cy_en_usbfs_dev_ep_access_t;
792
793 /** Service Callback Events (this enumerated type is used by middleware) */
794 typedef enum
795 {
796 CY_USB_DEV_BUS_RESET = 0U, /**< Callback hooked to the bus reset interrupt */
797 CY_USB_DEV_EP0_SETUP = 1U, /**< Callback hooked to the endpoint 0 SETUP packet interrupt */
798 CY_USB_DEV_EP0_IN = 2U, /**< Callback hooked to the endpoint 0 IN packet interrupt */
799 CY_USB_DEV_EP0_OUT = 3U, /**< Callback hooked to the endpoint 0 OUT packet interrupt */
800 } cy_en_usb_dev_service_cb_t;
801
802 /** Callback Sources */
803 typedef enum
804 {
805 CY_USBFS_DEV_DRV_EP1 = 0U, /**< Callback hooked to the Data Endpoint 1 completion interrupt */
806 CY_USBFS_DEV_DRV_EP2 = 1U, /**< Callback hooked to the Data Endpoint 2 completion interrupt */
807 CY_USBFS_DEV_DRV_EP3 = 2U, /**< Callback hooked to the Data Endpoint 3 completion interrupt */
808 CY_USBFS_DEV_DRV_EP4 = 3U, /**< Callback hooked to the Data Endpoint 4 completion interrupt */
809 CY_USBFS_DEV_DRV_EP5 = 4U, /**< Callback hooked to the Data Endpoint 5 completion interrupt */
810 CY_USBFS_DEV_DRV_EP6 = 5U, /**< Callback hooked to the Data Endpoint 6 completion interrupt */
811 CY_USBFS_DEV_DRV_EP7 = 6U, /**< Callback hooked to the Data Endpoint 7 completion interrupt */
812 CY_USBFS_DEV_DRV_EP8 = 7U, /**< Callback hooked to the Data Endpoint 8 completion interrupt */
813 CY_USBFS_DEV_DRV_SOF = 8U, /**< Callback hooked to the SOF packet received interrupt */
814 CY_USBFS_DEV_DRV_LPM = 9U, /**< Callback hooked to the LPM request received interrupt */
815 } cy_en_usbfs_dev_drv_cb_source_t;
816
817 /** Data Endpoint States (this enumerated type is used by middleware) */
818 typedef enum
819 {
820 CY_USB_DEV_EP_IDLE, /**< The endpoint is in an idle state after the configuration is set */
821 CY_USB_DEV_EP_PENDING, /**< The transfer targeted at an endpoint is in progress */
822 CY_USB_DEV_EP_COMPLETED, /**< The transfer targeted at an endpoint is completed */
823 CY_USB_DEV_EP_STALLED, /**< The endpoint is stalled */
824 CY_USB_DEV_EP_DISABLED, /**< The endpoint is disabled (not used in this configuration) */
825 CY_USB_DEV_EP_INVALID, /**< The endpoint is not supported by the hardware */
826 } cy_en_usb_dev_ep_state_t;
827
828 /** USB Lines Control */
829 typedef enum
830 {
831 CY_USBFS_DEV_DRV_FORCE_STATE_J = 0xA0U, /**< Force a J State onto the USB lines */
832 CY_USBFS_DEV_DRV_FORCE_STATE_K = 0x80U, /**< Force a K State onto the USB lines */
833 CY_USBFS_DEV_DRV_FORCE_STATE_SE0 = 0xC0U, /**< Force a Single Ended 0 onto the USB lines */
834 CY_USBFS_DEV_DRV_FORCE_STATE_NONE = 0x00U /**< Return the bus to the SIE control */
835 } cy_en_usbfs_dev_drv_force_bus_state_t;
836
837 /** LPM (Link Power Management) Responses */
838 typedef enum
839 {
840 /** The next LPM request will be responded with NACK */
841 CY_USBFS_DEV_DRV_LPM_REQ_NACK = 0x0U,
842
843 /** The next LPM request will be responded with ACK */
844 CY_USBFS_DEV_DRV_LPM_REQ_ACK = 0x1U,
845 } cy_en_usbfs_dev_drv_lpm_req_t;
846
847 /** USB Control EP0 transfer state */
848 typedef enum
849 {
850 CY_USBFS_DEV_DRV_EP0_CTRL_STATE_IDLE,
851 CY_USBFS_DEV_DRV_EP0_CTRL_STATE_SETUP,
852 CY_USBFS_DEV_DRV_EP0_CTRL_STATE_DATA,
853 CY_USBFS_DEV_DRV_EP0_CTRL_STATE_STATUS_IN,
854 CY_USBFS_DEV_DRV_EP0_CTRL_STATE_STATUS_OUT,
855 } cy_en_usbfs_dev_drv_ep0_ctrl_state_t;
856
857 /** \} group_usbfs_dev_drv_enums */
858
859
860 /*******************************************************************************
861 * Type Definitions
862 *******************************************************************************/
863
864 /**
865 * \addtogroup group_usbfs_dev_drv_data_structures
866 * \{
867 */
868
869 /** Data Endpoint Configuration Structure */
870 typedef struct
871 {
872 bool enableEndpoint; /**< Defines if the endpoint becomes active after configuration */
873 bool allocBuffer; /**< Defines if the endpoint needs buffer allocation */
874 uint16_t maxPacketSize; /**< The endpoint max packet size */
875 uint16_t bufferSize; /**< The endpoint buffer size (the biggest max packet size
876 across all alternate for this endpoint) */
877 uint8_t endpointAddr; /**< The endpoint address (number plus direction bit) */
878 uint8_t attributes; /**< The endpoint attributes */
879 } cy_stc_usb_dev_ep_config_t;
880
881 /**
882 * Driver context structure prototype.
883 * The driver define this structure type \ref cy_stc_usbfs_dev_drv_context_t.
884 */
885 struct cy_stc_usbfs_dev_drv_context;
886
887 /**
888 * Provides the typedef for the callback function called in the
889 * \ref Cy_USBFS_Dev_Drv_Interrupt to notify the user interrupt events.
890 */
891 typedef void (* cy_cb_usbfs_dev_drv_callback_t)(USBFS_Type *base,
892 struct cy_stc_usbfs_dev_drv_context *context);
893
894 /**
895 * Provides the typedef for the callback function called in the
896 * \ref Cy_USBFS_Dev_Drv_Interrupt to notify the user about endpoint transfer
897 * completion event.
898 */
899 typedef void (* cy_cb_usbfs_dev_drv_ep_callback_t)(USBFS_Type *base,
900 uint32_t endpointAddr,
901 uint32_t errorType,
902 struct cy_stc_usbfs_dev_drv_context *context);
903
904 /**
905 * Provides the typedef for the user defined function to replace library provided
906 * memcpy function to copy data from endpoint buffer to the user buffer.
907 */
908 typedef uint8_t * (* cy_fn_usbfs_dev_drv_memcpy_ptr_t)(uint8_t *dest,
909 const uint8_t *src,
910 uint32_t size);
911
912 /** \cond INTERNAL*/
913
914 /**
915 * Specifies the typedef for the pointer to the function that adds a data endpoint
916 */
917 typedef cy_en_usbfs_dev_drv_status_t (* cy_fn_usbfs_dev_drv_add_ep_ptr_t)
918 (USBFS_Type *base,
919 cy_stc_usb_dev_ep_config_t const *config,
920 struct cy_stc_usbfs_dev_drv_context *context);
921
922 /**
923 * Specifies the typedef for the pointer to the function that loads data into
924 * the data endpoint.
925 */
926 typedef cy_en_usbfs_dev_drv_status_t (* cy_fn_usbfs_dev_drv_load_ep_ptr_t)
927 (USBFS_Type *base,
928 uint32_t endpoint,
929 const uint8_t *buffer,
930 uint32_t size,
931 struct cy_stc_usbfs_dev_drv_context *context);
932
933 /**
934 * Specifies the typedef for the pointer to the function that reads data from
935 * the data endpoint.
936 */
937 typedef cy_en_usbfs_dev_drv_status_t (* cy_fn_usbfs_dev_drv_read_ep_ptr_t)
938 (USBFS_Type *base,
939 uint32_t endpoint,
940 uint8_t *buffer,
941 uint32_t size,
942 uint32_t *actSize,
943 struct cy_stc_usbfs_dev_drv_context *context);
944 /** \endcond */
945
946 /** DMA Channel Configuration Structure */
947 typedef struct
948 {
949 DW_Type *base; /**< Pointer to the DMA base */
950 uint32_t chNum; /**< Channel number */
951 uint32_t priority; /**< Channel's priority */
952 bool preemptable; /**< Specifies whether the channel is preempt-able by another higher-priority channel */
953
954 /** DMA out trigger mux (applicable only when mode is
955 * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO)
956 */
957 uint32_t outTrigMux;
958
959 /** The pointer to the 1st allocated DMA descriptor (required for DMA operation) */
960 cy_stc_dma_descriptor_t *descr0;
961
962 /** The pointer to the 2nd allocated DMA descriptor (required when mode is
963 * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO)
964 */
965 cy_stc_dma_descriptor_t *descr1;
966
967 } cy_stc_usbfs_dev_drv_dma_config_t;
968
969 /** Driver Configuration Structure */
970 typedef struct cy_stc_usbfs_dev_drv_config
971 {
972 /** Endpoints management mode */
973 cy_en_usbfs_dev_drv_ep_management_mode_t mode;
974
975 /** DMA channels configuration for the endpoints.
976 * Only DMChannels for active endpoints must be configured. Provide NULL
977 * pointer if endpoint is not used. Applicable when \ref mode is
978 * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA or \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO.
979 */
980 const cy_stc_usbfs_dev_drv_dma_config_t *dmaConfig[CY_USBFS_DEV_DRV_NUM_EPS_MAX];
981
982 /**
983 * The pointer to the buffer allocated for the OUT endpoints (applicable only when \ref mode
984 * is \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO)
985 */
986 uint8_t *epBuffer;
987
988 /**
989 * The size of the buffer for the OUT endpoints (applicable only when \ref mode
990 * is \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO)
991 */
992 uint16_t epBufferSize;
993
994 /** The mask that assigns interrupt sources to trigger: Low, Medium, or High interrupt.
995 * Use the macros provided in group_usbfs_dev_drv_macros_intr_level to initialize the
996 * intrLevelSel mask.
997 */
998 uint32_t intrLevelSel;
999
1000 /** Enables LPM (Link Power Management) response */
1001 bool enableLpm;
1002
1003 /** Data endpoints access type */
1004 cy_en_usbfs_dev_ep_access_t epAccess;
1005
1006 } cy_stc_usbfs_dev_drv_config_t;
1007
1008 /** \cond INTERNAL: Endpoint Structure */
1009 typedef struct
1010 {
1011 volatile uint8_t address; /**< Endpoint address (include direction bit) */
1012 volatile uint8_t toggle; /**< Toggle bit in SIE_EP_CNT1 register */
1013 volatile uint8_t sieMode; /**< SIE mode to arm endpoint on the bus */
1014
1015 uint8_t *buffer; /**< The pointer to the buffer */
1016 volatile uint16_t bufferSize; /**< Endpoint buffer size */
1017 volatile uint16_t startBuf; /**< Start of the buffer */
1018
1019 volatile bool isPending; /**< Save the pending state before stall endpoint */
1020 volatile cy_en_usb_dev_ep_state_t state; /**< Endpoint state */
1021
1022 /** Completes an event notification callback */
1023 cy_cb_usbfs_dev_drv_ep_callback_t epComplete;
1024
1025 DW_Type *base; /**< The pointer to the DMA base */
1026 uint32_t chNum; /**< DMA Channel number */
1027 uint32_t outTrigMux; /**< Out trigger mux for DMA channel number */
1028
1029 cy_stc_dma_descriptor_t* descr0; /**< The pointer to the descriptor 0 */
1030 cy_stc_dma_descriptor_t* descr1; /**< The pointer to the descriptor 1 */
1031
1032 cy_fn_usbfs_dev_drv_memcpy_ptr_t copyData; /**< The pointer to the user memcpy function */
1033
1034 } cy_stc_usbfs_dev_drv_endpoint_data_t;
1035 /** \endcond */
1036
1037 /** USBFS Device context structure.
1038 * All fields for the context structure are internal. The firmware never reads or
1039 * writes these values. The firmware allocates a structure and provides the
1040 * address of the structure to the middleware in HID function calls. The firmware
1041 * must ensure that the defined instance of this structure remains in scope while
1042 * the middleware is in use.
1043 */
1044 typedef struct cy_stc_usbfs_dev_drv_context
1045 {
1046 /** \cond INTERNAL */
1047 /** Stores the Endpoint 0 buffer to put the read operation results */
1048 uint8_t *ep0Buffer;
1049
1050 /** Stores the Endpoint 0 buffer size */
1051 uint8_t ep0BufferSize;
1052
1053 /** Endpoint 0 data toggle bit: 0 or USBFS_USBDEV_EP0_CNT_DATA_TOGGLE_Msk */
1054 uint8_t ep0DataToggle;
1055
1056 /** Active endpoint mask */
1057 uint8_t activeEpMask;
1058
1059 /** The device address to set */
1060 uint8_t address;
1061
1062 /** Defines the list of endpoints that waits for abort completion */
1063 volatile uint8_t epAbortMask;
1064
1065 /** Endpoints management mode */
1066 cy_en_usbfs_dev_drv_ep_management_mode_t mode;
1067
1068 /** Stores the control transfer state */
1069 cy_en_usbfs_dev_drv_ep0_ctrl_state_t ep0CtrlState;
1070
1071 /* Status to set or not the device address after the status state of the control transfer */
1072 bool setAddress;
1073
1074 /** Defines which endpoint registers to use: 8-bits or 16-bits */
1075 bool useReg16;
1076
1077 /** Bus reset callback notification */
1078 cy_cb_usbfs_dev_drv_callback_t busReset;
1079
1080 /** Endpoint 0: Setup packet has received callback notification */
1081 cy_cb_usbfs_dev_drv_callback_t ep0Setup;
1082
1083 /** Endpoint 0: IN data packet has received callback notification */
1084 cy_cb_usbfs_dev_drv_callback_t ep0In;
1085
1086 /** Endpoint 0: OUT data packet has received callback notification */
1087 cy_cb_usbfs_dev_drv_callback_t ep0Out;
1088
1089 /** SOF frame has received callback notification */
1090 cy_cb_usbfs_dev_drv_callback_t cbSof;
1091
1092 /** LPM request has received callback notification */
1093 cy_cb_usbfs_dev_drv_callback_t cbLpm;
1094
1095 /** Pointer to addEndpoint function: depends on operation mode */
1096 cy_fn_usbfs_dev_drv_add_ep_ptr_t addEndpoint;
1097
1098 /** Pointer to loadInEndpoint function: depends on operation mode */
1099 cy_fn_usbfs_dev_drv_load_ep_ptr_t loadInEndpoint;
1100
1101 /** Pointer to readOutEndpoint function: depends on operation mode */
1102 cy_fn_usbfs_dev_drv_read_ep_ptr_t readOutEndpoint;
1103
1104 uint8_t *epSharedBuf; /**< Buffer for OUT endpoints */
1105 uint16_t epSharedBufSize; /**< Buffer size */
1106
1107 uint16_t curBufAddr; /** Current position in endpoint buffer (HW or SRAM) */
1108
1109 /** Stores endpoints information */
1110 cy_stc_usbfs_dev_drv_endpoint_data_t epPool[CY_USBFS_DEV_DRV_NUM_EPS_MAX];
1111
1112 /** The pointer to the device context structure */
1113 void *devConext;
1114 /** \endcond */
1115 } cy_stc_usbfs_dev_drv_context_t;
1116 /** \} group_usbfs_dev_drv_data_structures */
1117
1118
1119 /*******************************************************************************
1120 * Function Prototypes
1121 *******************************************************************************/
1122
1123 /**
1124 * \addtogroup group_usbfs_dev_hal_functions_common
1125 * \{
1126 * The Initialization functions provide an API to begin the USBFS driver operation
1127 * (configure and enable) and to stop operation (disable and de-initialize).
1128 */
1129 cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_Init(USBFS_Type *base,
1130 cy_stc_usbfs_dev_drv_config_t const *config,
1131 cy_stc_usbfs_dev_drv_context_t *context);
1132
1133 void Cy_USBFS_Dev_Drv_DeInit(USBFS_Type *base,
1134 cy_stc_usbfs_dev_drv_context_t *context);
1135
1136 void Cy_USBFS_Dev_Drv_Enable(USBFS_Type *base,
1137 cy_stc_usbfs_dev_drv_context_t const *context);
1138
1139 void Cy_USBFS_Dev_Drv_Disable(USBFS_Type *base,
1140 cy_stc_usbfs_dev_drv_context_t *context);
1141
1142 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetAddress(USBFS_Type *base, uint8_t address,
1143 cy_stc_usbfs_dev_drv_context_t *context);
1144 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetDeviceAddress(USBFS_Type *base, uint8_t address);
1145 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetDeviceAddress(USBFS_Type const *base);
1146
1147 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetDevContext(USBFS_Type const *base,
1148 void *devContext,
1149 cy_stc_usbfs_dev_drv_context_t *context);
1150
1151 __STATIC_INLINE void* Cy_USBFS_Dev_Drv_GetDevContext(USBFS_Type const *base,
1152 cy_stc_usbfs_dev_drv_context_t *context);
1153
1154 void Cy_USBFS_Dev_Drv_ConfigDevice(USBFS_Type *base,
1155 cy_stc_usbfs_dev_drv_context_t *context);
1156
1157 void Cy_USBFS_Dev_Drv_UnConfigureDevice(USBFS_Type *base,
1158 cy_stc_usbfs_dev_drv_context_t *context);
1159 /** \} group_usbfs_dev_hal_functions_common */
1160
1161 /**
1162 * \addtogroup group_usbfs_dev_hal_functions_ep0_service
1163 * \{
1164 * The Endpoint 0 Service functions provide an API to establish communication with
1165 * the USB Host using control endpoint 0.
1166 */
1167 void Cy_USBFS_Dev_Drv_Ep0GetSetup(USBFS_Type const *base,
1168 uint8_t *buffer,
1169 cy_stc_usbfs_dev_drv_context_t const *context);
1170
1171 uint32_t Cy_USBFS_Dev_Drv_Ep0Write(USBFS_Type *base,
1172 uint8_t const *buffer,
1173 uint32_t size,
1174 cy_stc_usbfs_dev_drv_context_t *context);
1175
1176 void Cy_USBFS_Dev_Drv_Ep0Read(USBFS_Type *base,
1177 uint8_t *buffer,
1178 uint32_t size,
1179 cy_stc_usbfs_dev_drv_context_t *context);
1180
1181 uint32_t Cy_USBFS_Dev_Drv_Ep0ReadResult(USBFS_Type const *base,
1182 cy_stc_usbfs_dev_drv_context_t *context);
1183
1184 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Ep0Stall(USBFS_Type *base);
1185
1186 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetEp0MaxPacket(USBFS_Type const *base);
1187 /** \} group_usbfs_dev_hal_functions_ep0_service */
1188
1189
1190 /**
1191 * \addtogroup group_usbfs_dev_hal_functions_endpoint_config
1192 * \{
1193 * The Data Endpoint Configuration Functions provide an API to allocate and release
1194 * hardware resources and override the memcpy function for the data endpoints.
1195 */
1196 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_AddEndpoint(USBFS_Type *base,
1197 cy_stc_usb_dev_ep_config_t const *config,
1198 cy_stc_usbfs_dev_drv_context_t *context);
1199
1200 cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_RemoveEndpoint(USBFS_Type *base,
1201 uint32_t endpointAddr,
1202 cy_stc_usbfs_dev_drv_context_t *context);
1203
1204 __STATIC_INLINE void Cy_USBFS_Dev_Drv_OverwriteMemcpy(USBFS_Type const *base,
1205 uint32_t endpoint,
1206 cy_fn_usbfs_dev_drv_memcpy_ptr_t memcpyFunc,
1207 cy_stc_usbfs_dev_drv_context_t *context);
1208 /** \} group_usbfs_dev_hal_functions_endpoint_config */
1209
1210 /**
1211 * \addtogroup group_usbfs_dev_hal_functions_data_xfer
1212 * The Data Endpoint Transfer functions provide an API to establish
1213 * communication with the USB Host using data endpoint.
1214 * \{
1215 */
1216 __STATIC_INLINE cy_en_usb_dev_ep_state_t Cy_USBFS_Dev_Drv_GetEndpointState(USBFS_Type const *base,
1217 uint32_t endpoint,
1218 cy_stc_usbfs_dev_drv_context_t const *context);
1219
1220 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_LoadInEndpoint(USBFS_Type *base,
1221 uint32_t endpoint,
1222 uint8_t const *buffer,
1223 uint32_t size,
1224 cy_stc_usbfs_dev_drv_context_t *context);
1225
1226 void Cy_USBFS_Dev_Drv_EnableOutEndpoint(USBFS_Type *base,
1227 uint32_t endpoint,
1228 cy_stc_usbfs_dev_drv_context_t *context);
1229
1230 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_ReadOutEndpoint(USBFS_Type *base,
1231 uint32_t endpoint,
1232 uint8_t *buffer,
1233 uint32_t size,
1234 uint32_t *actSize,
1235 cy_stc_usbfs_dev_drv_context_t *context);
1236
1237 cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_Abort(USBFS_Type *base,
1238 uint32_t endpoint,
1239 cy_stc_usbfs_dev_drv_context_t *context);
1240
1241 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_GetEndpointAckState(USBFS_Type const *base, uint32_t endpoint);
1242 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetEndpointCount (USBFS_Type const *base, uint32_t endpoint);
1243
1244 cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_StallEndpoint(USBFS_Type *base,
1245 uint32_t endpoint,
1246 cy_stc_usbfs_dev_drv_context_t *context);
1247
1248 cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_UnStallEndpoint(USBFS_Type *base,
1249 uint32_t endpoint,
1250 cy_stc_usbfs_dev_drv_context_t *context);
1251
1252 /** \} group_usbfs_dev_hal_functions_data_xfer */
1253
1254 /**
1255 * \addtogroup group_usbfs_dev_drv_functions_interrupts
1256 * The Functions Interrupt functions provide an API to register callbacks
1257 * for interrupt events provided by the USB block, interrupt handler, and configuration functions.
1258 * \{
1259 */
1260 void Cy_USBFS_Dev_Drv_Interrupt(USBFS_Type *base, uint32_t intrCause, cy_stc_usbfs_dev_drv_context_t *context);
1261
1262 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseHi (USBFS_Type const *base);
1263 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseMed(USBFS_Type const *base);
1264 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseLo (USBFS_Type const *base);
1265
1266 void Cy_USBFS_Dev_Drv_RegisterServiceCallback(USBFS_Type const *base,
1267 cy_en_usb_dev_service_cb_t source,
1268 cy_cb_usbfs_dev_drv_callback_t callback,
1269 cy_stc_usbfs_dev_drv_context_t *context);
1270
1271 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterSofCallback(USBFS_Type *base,
1272 cy_cb_usbfs_dev_drv_callback_t callback,
1273 cy_stc_usbfs_dev_drv_context_t *context);
1274
1275 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterLpmCallback(USBFS_Type *base,
1276 cy_cb_usbfs_dev_drv_callback_t callback,
1277 cy_stc_usbfs_dev_drv_context_t *context);
1278
1279 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterEndpointCallback(USBFS_Type const *base,
1280 uint32_t endpoint,
1281 cy_cb_usbfs_dev_drv_ep_callback_t callback,
1282 cy_stc_usbfs_dev_drv_context_t *context);
1283
1284 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetInterruptsLevel(USBFS_Type *base, uint32_t intrLevel);
1285 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptsLevel(USBFS_Type const *base);
1286
1287 __STATIC_INLINE void Cy_USBFS_Dev_Drv_DisableEp0Interrupt(USBFS_Type *base);
1288 __STATIC_INLINE void Cy_USBFS_Dev_Drv_EnableEp0Interrupt(USBFS_Type *base);
1289 /** \} group_usbfs_dev_drv_functions_interrupts */
1290
1291 /**
1292 * \addtogroup group_usbfs_dev_drv_functions_low_power
1293 * The Low-power functions provide an API to implement Low-power callback at the application level.
1294 * \{
1295 */
1296 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_CheckActivity(USBFS_Type *base);
1297 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Force (USBFS_Type *base, cy_en_usbfs_dev_drv_force_bus_state_t state);
1298 void Cy_USBFS_Dev_Drv_Suspend(USBFS_Type *base, cy_stc_usbfs_dev_drv_context_t *context);
1299 void Cy_USBFS_Dev_Drv_Resume (USBFS_Type *base, cy_stc_usbfs_dev_drv_context_t *context);
1300 /** \} group_usbfs_dev_drv_functions_low_power */
1301
1302 /**
1303 * \addtogroup group_usbfs_dev_drv_functions_lpm
1304 * The LPM functions provide an API to use the LPM feature available in the USB block.
1305 * \{
1306 */
1307 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_Lpm_GetBeslValue (USBFS_Type const *base);
1308 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_Lpm_RemoteWakeUpAllowed(USBFS_Type const *base);
1309 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Lpm_SetResponse (USBFS_Type *base, cy_en_usbfs_dev_drv_lpm_req_t response);
1310 __STATIC_INLINE cy_en_usbfs_dev_drv_lpm_req_t Cy_USBFS_Dev_Drv_Lpm_GetResponse(USBFS_Type const *base);
1311 /** \} group_usbfs_dev_drv_functions_lpm */
1312
1313
1314 /*******************************************************************************
1315 * Driver Constants
1316 *******************************************************************************/
1317
1318 /**
1319 * \addtogroup group_usbfs_dev_drv_macros
1320 * \{
1321 */
1322 /** Allocates a static buffer for the data endpoint. The size parameter must be a constant.
1323 * The allocated buffer is aligned to a 2-byte boundary. <b>An odd buffer size is
1324 * converted to even, consuming 1 extra byte. The application must discard this
1325 * extra byte</b> to support different 8-bit and 16-bit hardware buffer access types
1326 * in the driver. For more detail, refer to \ref group_usbfs_dev_drv_ep_management_buf_access.
1327 */
1328 #define CY_USBFS_DEV_DRV_ALLOC_ENDPOINT_BUFFER(buf, size) uint8_t buf[(0U != ((size) & 0x1U)) ? ((size) + 1U) : (size)] CY_ALIGN(2)
1329 /** \} group_usbfs_dev_drv_macros */
1330
1331 /**
1332 * \addtogroup group_usbfs_dev_drv_macros_intr_level
1333 * \{
1334 */
1335 /** The interrupt source is assigned to a trigger High interrupt */
1336 #define CY_USBFS_DEV_DRV_LVL_HIGH (0U)
1337 /** The interrupt source is assigned to a trigger Medium interrupt */
1338 #define CY_USBFS_DEV_DRV_LVL_MEDIUM (1U)
1339 /** The interrupt source is assigned to a trigger Low interrupt */
1340 #define CY_USBFS_DEV_DRV_LVL_LOW (2U)
1341
1342 /** Assigns the SOF interrupt source to a trigger interrupt: Low, Medium, or High */
1343 #define CY_USBFS_DEV_DRV_SET_SOF_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_SOF_LVL_SEL, level)
1344 /** Assigns the Bus Reset interrupt source to a trigger interrupt: Low, Medium, or High */
1345 #define CY_USBFS_DEV_DRV_SET_BUS_RESET_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_BUS_RESET_LVL_SEL, level)
1346 /** Assigns the Endpoint 0 interrupt source to a trigger interrupt Low, Medium, or High */
1347 #define CY_USBFS_DEV_DRV_SET_EP0_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP0_LVL_SEL, level)
1348 /** Assigns the LPM interrupt source to a trigger interrupt: Low, Medium, or High */
1349 #define CY_USBFS_DEV_DRV_SET_LPM_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_LPM_LVL_SEL, level)
1350 /** Assigns the Resume interrupt source to a trigger interrupt: Low, Medium, or High */
1351 #define CY_USBFS_DEV_DRV_SET_RESUME_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_RESUME_LVL_SEL, level)
1352 /** Assigns the Arbiter interrupt source to a trigger interrupt: Low, Medium, or High */
1353 #define CY_USBFS_DEV_DRV_SET_ARB_EP_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_ARB_EP_LVL_SEL, level)
1354 /** Assigns the Endpoint 1 interrupt source to a trigger interrupt: Low, Medium, or High */
1355 #define CY_USBFS_DEV_DRV_SET_EP1_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP1_LVL_SEL, level)
1356 /** Assigns the Endpoint 2 interrupt source to a trigger interrupt: Low, Medium, or High */
1357 #define CY_USBFS_DEV_DRV_SET_EP2_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP2_LVL_SEL, level)
1358 /** Assigns the Endpoint 3 interrupt source to a trigger interrupt: Low, Medium, or High */
1359 #define CY_USBFS_DEV_DRV_SET_EP3_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP3_LVL_SEL, level)
1360 /** Assigns the Endpoint 4 interrupt source to a trigger interrupt: Low, Medium, or High */
1361 #define CY_USBFS_DEV_DRV_SET_EP4_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP4_LVL_SEL, level)
1362 /** Assigns the Endpoint 5 interrupt source to a trigger interrupt: Low, Medium, or High */
1363 #define CY_USBFS_DEV_DRV_SET_EP5_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP5_LVL_SEL, level)
1364 /** Assigns the Endpoint 6 interrupt source to a trigger interrupt: Low, Medium, or High */
1365 #define CY_USBFS_DEV_DRV_SET_EP6_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP6_LVL_SEL, level)
1366 /** Assigns the Endpoint 7 interrupt source to a trigger interrupt: Low, Medium, or High */
1367 #define CY_USBFS_DEV_DRV_SET_EP7_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP7_LVL_SEL, level)
1368 /** Assigns the Endpoint 8 interrupt source to a trigger interrupt: Low, Medium, or High */
1369 #define CY_USBFS_DEV_DRV_SET_EP8_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP8_LVL_SEL, level)
1370 /** \} group_usbfs_dev_drv_macros_intr_level */
1371
1372 /**
1373 * \addtogroup group_usbfs_dev_drv_macros_intr_cause
1374 * \{
1375 */
1376 #define CY_USBFS_DEV_DRV_LPM_INTR USBFS_USBLPM_INTR_CAUSE_HI_LPM_INTR_Msk /**< Link Power Management request interrupt */
1377 #define CY_USBFS_DEV_DRV_ARBITER_INTR USBFS_USBLPM_INTR_CAUSE_HI_ARB_EP_INTR_Msk /**< Arbiter interrupt */
1378 #define CY_USBFS_DEV_DRV_EP0_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP0_INTR_Msk /**< Endpoint 0 interrupt */
1379 #define CY_USBFS_DEV_DRV_SOF_INTR USBFS_USBLPM_INTR_CAUSE_HI_SOF_INTR_Msk /**< SOF interrupt */
1380 #define CY_USBFS_DEV_DRV_BUS_RESET_INTR USBFS_USBLPM_INTR_CAUSE_HI_BUS_RESET_INTR_Msk /**< Bus Reset interrupt */
1381 #define CY_USBFS_DEV_DRV_EP1_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP1_INTR_Msk /**< Data endpoint 1 interrupt */
1382 #define CY_USBFS_DEV_DRV_EP2_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP2_INTR_Msk /**< Data endpoint 2 interrupt */
1383 #define CY_USBFS_DEV_DRV_EP3_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP3_INTR_Msk /**< Data endpoint 3 interrupt */
1384 #define CY_USBFS_DEV_DRV_EP4_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP4_INTR_Msk /**< Data endpoint 4 interrupt */
1385 #define CY_USBFS_DEV_DRV_EP5_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP5_INTR_Msk /**< Data endpoint 5 interrupt */
1386 #define CY_USBFS_DEV_DRV_EP6_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP6_INTR_Msk /**< Data endpoint 6 interrupt */
1387 #define CY_USBFS_DEV_DRV_EP7_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP7_INTR_Msk /**< Data endpoint 7 interrupt */
1388 #define CY_USBFS_DEV_DRV_EP8_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP8_INTR_Msk /**< Data endpoint 8 interrupt */
1389 /** \} group_usbfs_dev_drv_macros_intr_cause */
1390
1391 /**
1392 * \addtogroup group_usbfs_dev_drv_macros_ep_xfer_err
1393 * \{
1394 */
1395 /**
1396 * An error occurred during a USB transfer.
1397 * For an IN transaction, this indicates a "no response" from the HOST scenario.
1398 * For an OUT transaction, this represents a "PID or CRC error" or the bit-stuff
1399 * error scenario.
1400 */
1401 #define CY_USBFS_DEV_ENDPOINT_TRANSFER_ERROR (0x1U)
1402
1403 /**
1404 * The data toggle bit remains the same.
1405 * The received OUT packet has the same data toggle bit that the previous
1406 * packet had. This indicates that the Host retransmitted the packet.
1407 */
1408 #define CY_USBFS_DEV_ENDPOINT_SAME_DATA_TOGGLE (0x2U)
1409 /** \} group_usbfs_dev_drv_macros_ep_xfer_err */
1410
1411
1412 /*******************************************************************************
1413 * Internal Constants
1414 *******************************************************************************/
1415
1416 /** \cond INTERNAL */
1417 /* The start position of the data endpoints SIE interrupt sources */
1418 #define USBFS_USBLPM_INTR_CAUSE_LPM_INTR_Msk USBFS_USBLPM_INTR_CAUSE_HI_LPM_INTR_Msk
1419 #define USBFS_USBLPM_INTR_CAUSE_ARB_EP_INTR_Msk USBFS_USBLPM_INTR_CAUSE_HI_ARB_EP_INTR_Msk
1420 #define USBFS_USBLPM_INTR_CAUSE_EP0_INTR_Msk USBFS_USBLPM_INTR_CAUSE_HI_EP0_INTR_Msk
1421 #define USBFS_USBLPM_INTR_CAUSE_SOF_INTR_Msk USBFS_USBLPM_INTR_CAUSE_HI_SOF_INTR_Msk
1422 #define USBFS_USBLPM_INTR_CAUSE_BUS_RESET_INTR_Msk USBFS_USBLPM_INTR_CAUSE_HI_BUS_RESET_INTR_Msk
1423 #define USBFS_USBLPM_INTR_CAUSE_EP1_INTR_Pos USBFS_USBLPM_INTR_CAUSE_HI_EP1_INTR_Pos
1424
1425 /* Validation macros */
1426 #define CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint) (((endpoint) > 0U) && ((endpoint) <= CY_USBFS_DEV_DRV_NUM_EPS_MAX))
1427 #define CY_USBFS_DEV_DRV_EP2PHY(endpoint) ((uint32_t) (endpoint) - 1U)
1428 #define CY_USBFS_DEV_DRV_EP2MASK(endpont) ((uint32_t) (0x1UL << endpoint))
1429
1430 #define CY_USBFS_DEV_DRV_EPADDR2EP(endpointAddr) ((uint32_t) (endpointAddr) & 0x0FU)
1431 #define CY_USBFS_DEV_DRV_IS_EP_DIR_IN(endpointAddr) (0U != ((endpointAddr) & 0x80U))
1432 #define CY_USBFS_DEV_DRV_IS_EP_DIR_OUT(endpointAddr) (0U == ((endpointAddr) & 0x80U))
1433 #define CY_USBFS_DEV_DRV_EPADDR2PHY(endpointAddr) CY_USBFS_DEV_DRV_EP2PHY(CY_USBFS_DEV_DRV_EPADDR2EP(endpointAddr))
1434
1435 #define CY_USBFS_DEV_DRV_IS_MODE_VALID(mode) (((mode) == CY_USBFS_DEV_DRV_EP_MANAGEMENT_CPU) || \
1436 ((mode) == CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA) || \
1437 ((mode) == CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO))
1438
1439 /* Obsolete function */
1440 #define Cy_USBFS_Dev_Drv_GetEndpointStallState Cy_USBFS_Dev_Drv_GetEndpointState
1441 /** \endcond */
1442 /** \} group_usbfs_drv_macros */
1443
1444
1445 /*******************************************************************************
1446 * In-line Function Implementation
1447 *******************************************************************************/
1448
1449 /**
1450 * \addtogroup group_usbfs_dev_hal_functions_common
1451 * \{
1452 */
1453
1454 /*******************************************************************************
1455 * Function Name: Cy_USBFS_Dev_Drv_SetAddress
1456 ****************************************************************************//**
1457 *
1458 * Posts a request to set the device address after the completion status stage of
1459 * the control transfer. This function must be used if a higher level requests
1460 * to set an address before the status stage of the control transfer.
1461 *
1462 * \param base
1463 * The pointer to the USBFS instance.
1464 *
1465 * \param address
1466 * The device address.
1467 *
1468 * \param context
1469 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1470 * allocated by the user. The structure is used during the USBFS Device
1471 * operation for internal configuration and data retention. The user must not
1472 * modify anything in this structure.
1473 *
1474 *******************************************************************************/
Cy_USBFS_Dev_Drv_SetAddress(USBFS_Type * base,uint8_t address,cy_stc_usbfs_dev_drv_context_t * context)1475 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetAddress(USBFS_Type *base, uint8_t address,
1476 cy_stc_usbfs_dev_drv_context_t *context)
1477 {
1478 (void)base; /* Suppress warning */
1479 /* Stores the address to set later after the status stage of setup request completed */
1480 context->address = address;
1481 context->setAddress = true;
1482 }
1483
1484
1485 /*******************************************************************************
1486 * Function Name: Cy_USBFS_Dev_Drv_SetDeviceAddress
1487 ****************************************************************************//**
1488 *
1489 * Sets the device address (writes the address directly into the register).
1490 *
1491 * \param base
1492 * The pointer to the USBFS instance.
1493 *
1494 * \param address
1495 * Device address.
1496 *
1497 *******************************************************************************/
Cy_USBFS_Dev_Drv_SetDeviceAddress(USBFS_Type * base,uint8_t address)1498 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetDeviceAddress(USBFS_Type *base, uint8_t address)
1499 {
1500 base->USBDEV.CR0 = _CLR_SET_FLD32U(base->USBDEV.CR0, USBFS_USBDEV_CR0_DEVICE_ADDRESS, address);
1501 }
1502
1503
1504 /*******************************************************************************
1505 * Function Name: Cy_USBFS_Dev_Drv_GetDeviceAddress
1506 ****************************************************************************//**
1507 *
1508 * Returns the device address (reads the address directly from the register).
1509 *
1510 * \param base
1511 * The pointer to the USBFS instance.
1512 *
1513 * \return
1514 * The device address.
1515 * The device address is assigned by the Host during device enumeration.
1516 * Zero means that the device address is not assigned.
1517 *
1518 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetDeviceAddress(USBFS_Type const * base)1519 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetDeviceAddress(USBFS_Type const *base)
1520 {
1521 return _FLD2VAL(USBFS_USBDEV_CR0_DEVICE_ADDRESS, base->USBDEV.CR0);
1522 }
1523
1524
1525 /*******************************************************************************
1526 * Function Name: Cy_USBFS_Dev_Drv_SetDevContext
1527 ****************************************************************************//**
1528 *
1529 * Stores a pointer to the USB Device context in the driver context.
1530 *
1531 * \param base
1532 * The pointer to the USBFS instance
1533 *
1534 * \param devContext
1535 * The pointer to the USB Device context structure.
1536 *
1537 * \param context
1538 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1539 * allocated by the user. The structure is used during the USBFS Device
1540 * operation for internal configuration and data retention. The user must not
1541 * modify anything in this structure.
1542 *
1543 * \note
1544 * This function is intended for the USB Device middleware operation.
1545 *
1546 *******************************************************************************/
Cy_USBFS_Dev_Drv_SetDevContext(USBFS_Type const * base,void * devContext,cy_stc_usbfs_dev_drv_context_t * context)1547 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetDevContext(USBFS_Type const *base,
1548 void *devContext,
1549 cy_stc_usbfs_dev_drv_context_t *context)
1550 {
1551 /* Suppresses a compiler warning about unused variables. */
1552 (void) base;
1553
1554 context->devConext = devContext;
1555 }
1556
1557
1558 /*******************************************************************************
1559 * Function Name: Cy_USBFS_Dev_Drv_GetDevContext
1560 ****************************************************************************//**
1561 *
1562 * Returns a pointer to the USB Device context.
1563 *
1564 * \param base
1565 * The pointer to the USBFS instance.
1566 *
1567 * \param context
1568 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1569 * allocated by the user. The structure is used during USBFS Device
1570 * operation for internal configuration and data retention. The user must not
1571 * modify anything in this structure.
1572 *
1573 * \return
1574 * The pointer to the USB Device context.
1575 *
1576 * \note
1577 * This function is intended for the USB Device middleware operation.
1578 *
1579 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetDevContext(USBFS_Type const * base,cy_stc_usbfs_dev_drv_context_t * context)1580 __STATIC_INLINE void* Cy_USBFS_Dev_Drv_GetDevContext(USBFS_Type const *base,
1581 cy_stc_usbfs_dev_drv_context_t *context)
1582 {
1583 /* Suppresses a compiler warning about unused variables */
1584 (void) base;
1585
1586 return (context->devConext);
1587 }
1588 /** \} group_usbfs_dev_hal_functions_common */
1589
1590
1591 /**
1592 * \addtogroup group_usbfs_dev_drv_functions_interrupts
1593 * \{
1594 */
1595 /*******************************************************************************
1596 * Function Name: Cy_USBFS_Dev_Drv_RegisterSofCallback
1597 ****************************************************************************//**
1598 *
1599 * Registers a callback function to notify about an SOF event in
1600 * \ref Cy_USBFS_Dev_Drv_Interrupt. The SOF interrupt source is enabled after
1601 * registration. To remove callback function, pass NULL as the function pointer.
1602 * When the callback is removed, the interrupt source is disabled.
1603 *
1604 * \param base
1605 * The pointer to the USBFS instance.
1606 *
1607 * \param callback
1608 * The pointer to a callback function.
1609 *
1610 * \param context
1611 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1612 * allocated by the user. The structure is used during the USBFS Device
1613 * operation for internal configuration and data retention. The user must not
1614 * modify anything in this structure.
1615 *
1616 * \note
1617 * To remove the callback, pass NULL as the pointer to a callback function.
1618 *
1619 *******************************************************************************/
Cy_USBFS_Dev_Drv_RegisterSofCallback(USBFS_Type * base,cy_cb_usbfs_dev_drv_callback_t callback,cy_stc_usbfs_dev_drv_context_t * context)1620 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterSofCallback(USBFS_Type *base,
1621 cy_cb_usbfs_dev_drv_callback_t callback,
1622 cy_stc_usbfs_dev_drv_context_t *context)
1623 {
1624 uint32_t mask;
1625
1626 context->cbSof = callback;
1627
1628 /* Enables/Disables SOF interrupt */
1629 mask = Cy_USBFS_Dev_Drv_GetSieInterruptMask(base);
1630
1631 if (NULL != callback)
1632 {
1633 mask |= CY_USBFS_DEV_DRV_INTR_SIE_SOF;
1634 }
1635 else
1636 {
1637 mask &= ~CY_USBFS_DEV_DRV_INTR_SIE_SOF;
1638 }
1639
1640 Cy_USBFS_Dev_Drv_ClearSieInterrupt(base, CY_USBFS_DEV_DRV_INTR_SIE_SOF);
1641 Cy_USBFS_Dev_Drv_SetSieInterruptMask(base, mask);
1642 }
1643
1644
1645 /*******************************************************************************
1646 * Function Name: Cy_USBFS_Dev_Drv_RegisterLpmCallback
1647 ****************************************************************************//**
1648 *
1649 * Registers a callback function to notify about an LPM event in
1650 * \ref Cy_USBFS_Dev_Drv_Interrupt. The LPM interrupt source is enabled after
1651 * registration. To remove the callback function, pass NULL as the function pointer.
1652 * When the callback is removed, the interrupt source is disabled.
1653 *
1654 * \param base
1655 * The pointer to the USBFS instance.
1656 *
1657 * \param callback
1658 * The pointer to a callback function.
1659 *
1660 * \param context
1661 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1662 * allocated by the user. The structure is used during the USBFS Device
1663 * operation for internal configuration and data retention. The user must not
1664 * modify anything in this structure.
1665 *
1666 * \note
1667 * To remove the callback, pass NULL as the pointer to the callback function.
1668 *
1669 *******************************************************************************/
Cy_USBFS_Dev_Drv_RegisterLpmCallback(USBFS_Type * base,cy_cb_usbfs_dev_drv_callback_t callback,cy_stc_usbfs_dev_drv_context_t * context)1670 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterLpmCallback(USBFS_Type *base,
1671 cy_cb_usbfs_dev_drv_callback_t callback,
1672 cy_stc_usbfs_dev_drv_context_t *context)
1673
1674 {
1675 uint32_t mask;
1676
1677 context->cbLpm = callback;
1678
1679 /* Enables/Disables the LPM interrupt source */
1680 mask = Cy_USBFS_Dev_Drv_GetSieInterruptMask(base);
1681
1682 if (NULL != callback)
1683 {
1684 mask |= CY_USBFS_DEV_DRV_INTR_SIE_LPM;
1685 }
1686 else
1687 {
1688 mask &= ~CY_USBFS_DEV_DRV_INTR_SIE_LPM;
1689 }
1690
1691 Cy_USBFS_Dev_Drv_ClearSieInterrupt(base, CY_USBFS_DEV_DRV_INTR_SIE_LPM);
1692 Cy_USBFS_Dev_Drv_SetSieInterruptMask(base, mask);
1693 }
1694
1695
1696 /*******************************************************************************
1697 * Function Name: Cy_USBFS_Dev_Drv_RegisterEndpointCallback
1698 ****************************************************************************//**
1699 *
1700 * Registers a callback function to notify of an endpoint transfer completion
1701 * event in \ref Cy_USBFS_Dev_Drv_Interrupt.
1702 * * IN endpoint - The Host read data from the endpoint and new data can be
1703 * loaded.
1704 * * OUT endpoint - The Host has written data into the endpoint and the data is
1705 * ready to be read.
1706 * To remove the callback function, pass NULL as function pointer.
1707 *
1708 * \param base
1709 * The pointer to the USBFS instance.
1710 *
1711 * \param endpoint
1712 * The data endpoint number.
1713 *
1714 * \param callback
1715 * The pointer to a callback function.
1716 *
1717 * \param context
1718 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1719 * allocated by the user. The structure is used during the USBFS Device
1720 * operation for internal configuration and data retention. The user must not
1721 * modify anything in this structure.
1722 *
1723 * \note
1724 * To remove the callback, pass NULL as the pointer to the callback function.
1725 *
1726 *******************************************************************************/
Cy_USBFS_Dev_Drv_RegisterEndpointCallback(USBFS_Type const * base,uint32_t endpoint,cy_cb_usbfs_dev_drv_ep_callback_t callback,cy_stc_usbfs_dev_drv_context_t * context)1727 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterEndpointCallback(USBFS_Type const *base,
1728 uint32_t endpoint,
1729 cy_cb_usbfs_dev_drv_ep_callback_t callback,
1730 cy_stc_usbfs_dev_drv_context_t *context)
1731
1732 {
1733 /* Suppresses a compiler warning about unused variables */
1734 (void) base;
1735
1736 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
1737
1738 endpoint = CY_USBFS_DEV_DRV_EP2PHY(endpoint);
1739 context->epPool[endpoint].epComplete = callback;
1740 }
1741
1742
1743 /*******************************************************************************
1744 * Function Name: Cy_USBFS_Dev_Drv_GetInterruptCauseHi
1745 ****************************************************************************//**
1746 *
1747 * Returns the mask of bits showing the source of the current triggered
1748 * interrupt. This is useful for modes of operation where an interrupt can
1749 * be generated by conditions in multiple interrupt source registers.
1750 *
1751 * \param base
1752 * The pointer to the USBFS instance.
1753 *
1754 * \return
1755 * The mask with the OR of the following conditions that have been triggered.
1756 * See \ref group_usbfs_dev_drv_macros_intr_cause for the set of constants.
1757 *
1758 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetInterruptCauseHi(USBFS_Type const * base)1759 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseHi(USBFS_Type const *base)
1760 {
1761 return USBFS_DEV_LPM_INTR_CAUSE_HI(base);
1762 }
1763
1764
1765 /*******************************************************************************
1766 * Function Name: Cy_USBFS_Dev_Drv_GetInterruptCauseMed
1767 ****************************************************************************//**
1768 *
1769 * Returns the mask of bits showing the source of the current triggered
1770 * interrupt. This is useful for modes of operation where an interrupt can
1771 * be generated by conditions in multiple interrupt source registers.
1772 *
1773 * \param base
1774 * The pointer to the USBFS instance.
1775 *
1776 * \return
1777 * The mask with the OR of the following conditions that have been triggered.
1778 * See \ref group_usbfs_dev_drv_macros_intr_cause for the set of constants.
1779 *
1780 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetInterruptCauseMed(USBFS_Type const * base)1781 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseMed(USBFS_Type const *base)
1782 {
1783 return USBFS_DEV_LPM_INTR_CAUSE_MED(base);
1784 }
1785
1786
1787 /*******************************************************************************
1788 * Function Name: Cy_USBFS_Dev_Drv_GetInterruptCauseLo
1789 ****************************************************************************//**
1790 *
1791 * Returns the mask of bits showing the source of the current triggered
1792 * interrupt. This is useful for modes of operation where an interrupt can
1793 * be generated by conditions in multiple interrupt source registers.
1794 *
1795 * \param base
1796 * The pointer to the USBFS instance.
1797 *
1798 * \return
1799 * The mask with the OR of the following conditions that have been triggered.
1800 * See \ref group_usbfs_dev_drv_macros_intr_cause for the set of constants.
1801 *
1802 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetInterruptCauseLo(USBFS_Type const * base)1803 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseLo(USBFS_Type const *base)
1804 {
1805 return USBFS_DEV_LPM_INTR_CAUSE_LO(base);
1806 }
1807
1808
1809 /*******************************************************************************
1810 * Function Name: Cy_USBFS_Dev_Drv_SetInterruptsLevel
1811 ****************************************************************************//**
1812 *
1813 * Writes INTR_LVL_SEL register which contains groups for all interrupt sources.
1814 *
1815 * \param base
1816 * The pointer to the USBFS instance.
1817 *
1818 * \param intrLevel
1819 * INTR_LVL_SEL register value.
1820 *
1821 *******************************************************************************/
Cy_USBFS_Dev_Drv_SetInterruptsLevel(USBFS_Type * base,uint32_t intrLevel)1822 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetInterruptsLevel(USBFS_Type *base, uint32_t intrLevel)
1823 {
1824 USBFS_DEV_LPM_INTR_LVL_SEL(base) = intrLevel;
1825 }
1826
1827
1828 /*******************************************************************************
1829 * Function Name: Cy_USBFS_Dev_Drv_GetInterruptsLevel
1830 ****************************************************************************//**
1831 *
1832 * Returns the INTR_LVL_SEL register that contains groups for all interrupt sources.
1833 *
1834 * \param base
1835 * The pointer to the USBFS instance.
1836 *
1837 * \return
1838 * Returns the INTR_LVL_SEL register that contains groups for all interrupt sources.
1839 *
1840 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetInterruptsLevel(USBFS_Type const * base)1841 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptsLevel(USBFS_Type const *base)
1842 {
1843 return base->USBLPM.INTR_LVL_SEL;
1844 }
1845
1846
1847 /*******************************************************************************
1848 * Function Name: Cy_USBFS_Dev_Drv_DisableEp0Interrupt
1849 ****************************************************************************//**
1850 *
1851 * Enables the Control Endpoint 0 interrupt source.
1852 *
1853 * \param base
1854 * The pointer to the USBFS instance.
1855 *
1856 *******************************************************************************/
Cy_USBFS_Dev_Drv_DisableEp0Interrupt(USBFS_Type * base)1857 __STATIC_INLINE void Cy_USBFS_Dev_Drv_DisableEp0Interrupt(USBFS_Type *base)
1858 {
1859 uint32_t mask = (Cy_USBFS_Dev_Drv_GetSieInterruptMask(base) & ~CY_USBFS_DEV_DRV_INTR_SIE_EP0);
1860 Cy_USBFS_Dev_Drv_SetSieInterruptMask(base, mask);
1861 }
1862
1863
1864 /*******************************************************************************
1865 * Function Name: Cy_USBFS_Dev_Drv_EnableEp0Interrupt
1866 ****************************************************************************//**
1867 *
1868 * Enables the Control Endpoint 0 interrupt.
1869 *
1870 * \param base
1871 * The pointer to the USBFS instance source.
1872 *
1873 *******************************************************************************/
Cy_USBFS_Dev_Drv_EnableEp0Interrupt(USBFS_Type * base)1874 __STATIC_INLINE void Cy_USBFS_Dev_Drv_EnableEp0Interrupt(USBFS_Type *base)
1875 {
1876 uint32_t mask = (Cy_USBFS_Dev_Drv_GetSieInterruptMask(base) | CY_USBFS_DEV_DRV_INTR_SIE_EP0);
1877 Cy_USBFS_Dev_Drv_SetSieInterruptMask(base, mask);
1878 }
1879 /** \} group_usbfs_dev_drv_functions_interrupts */
1880
1881 /**
1882 * \addtogroup group_usbfs_dev_drv_functions_low_power
1883 * \{
1884 */
1885 /*******************************************************************************
1886 * Function Name: Cy_USBFS_Dev_Drv_CheckActivity
1887 ****************************************************************************//**
1888 *
1889 * Returns the activity status of the bus.
1890 * It clears the hardware status to provide an updated status on the next call of
1891 * this function. This function is useful to determine whether there is any USB bus
1892 * activity between function calls. A typical use case is to determine whether
1893 * the USB suspend conditions are met.
1894 *
1895 * \param base
1896 * The pointer to the USBFS instance.
1897 *
1898 * \return
1899 * The bus activity since the last call.
1900 *
1901 *******************************************************************************/
Cy_USBFS_Dev_Drv_CheckActivity(USBFS_Type * base)1902 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_CheckActivity(USBFS_Type *base)
1903 {
1904 uint32_t tmpReg = base->USBDEV.CR1;
1905
1906 /* Clear hardware status */
1907 base->USBDEV.CR1 &= (tmpReg & ~USBFS_USBDEV_CR1_BUS_ACTIVITY_Msk);
1908 (void) base->USBDEV.CR1;
1909
1910 return (0U != (tmpReg & USBFS_USBDEV_CR1_BUS_ACTIVITY_Msk));
1911 }
1912
1913
1914 /*******************************************************************************
1915 * Function Name: Cy_USBFS_Dev_Drv_Force
1916 ****************************************************************************//**
1917 *
1918 * Forces a USB J, K, or SE0 state on the USB lines.
1919 * A typical use case is to signal a Remote Wakeup condition on the USB bus.
1920 *
1921 * \param base
1922 * The pointer to the USBFS instance.
1923 *
1924 * \param state
1925 * The desired bus state.
1926 * See \ref cy_en_usbfs_dev_drv_force_bus_state_t for the set of constants.
1927 *
1928 *******************************************************************************/
Cy_USBFS_Dev_Drv_Force(USBFS_Type * base,cy_en_usbfs_dev_drv_force_bus_state_t state)1929 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Force(USBFS_Type *base, cy_en_usbfs_dev_drv_force_bus_state_t state)
1930 {
1931 base->USBDEV.USBIO_CR0 = (uint32_t) state;
1932 (void) base->USBDEV.USBIO_CR0;
1933 }
1934 /** \} group_usbfs_dev_drv_functions_low_power */
1935
1936
1937 /**
1938 * \addtogroup group_usbfs_dev_drv_functions_lpm
1939 * \{
1940 */
1941 /*******************************************************************************
1942 * Function Name: Cy_USBFS_Dev_Drv_Lpm_GetBeslValue
1943 ****************************************************************************//**
1944 *
1945 * Returns the Best Effort Service Latency (BESL) value sent by the host as
1946 * part of the LPM token transaction.
1947 *
1948 * \param base
1949 * The pointer to the USBFS instance.
1950 *
1951 * \return
1952 * BESL value (4-bits)
1953 *
1954 *******************************************************************************/
Cy_USBFS_Dev_Drv_Lpm_GetBeslValue(USBFS_Type const * base)1955 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_Lpm_GetBeslValue(USBFS_Type const *base)
1956 {
1957 return _FLD2VAL(USBFS_USBLPM_LPM_STAT_LPM_BESL, USBFS_DEV_LPM_LPM_STAT(base));
1958 }
1959
1960
1961 /*******************************************************************************
1962 * Function Name: Cy_USBFS_Dev_Drv_Lpm_RemoteWakeUpAllowed
1963 ****************************************************************************//**
1964 *
1965 * Returns the remote wakeup permission set by the Host as part of the
1966 * LPM token transaction.
1967 *
1968 * \param base
1969 * The pointer to the USBFS instance.
1970 *
1971 * \return
1972 * Remote wakeup permission: true - allowed, false - not allowed.
1973 *
1974 *******************************************************************************/
Cy_USBFS_Dev_Drv_Lpm_RemoteWakeUpAllowed(USBFS_Type const * base)1975 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_Lpm_RemoteWakeUpAllowed(USBFS_Type const *base)
1976 {
1977 return _FLD2BOOL(USBFS_USBLPM_LPM_STAT_LPM_REMOTEWAKE, USBFS_DEV_LPM_LPM_STAT(base));
1978 }
1979
1980
1981 /*******************************************************************************
1982 * Function Name: Cy_USBFS_Dev_Drv_Lpm_SetResponse
1983 ****************************************************************************//**
1984 *
1985 * Configures the response in the handshake packet that the device sends when
1986 * an LPM token packet is received.
1987 *
1988 * \param base
1989 * The pointer to the USBFS instance.
1990 *
1991 * \param response
1992 * The response to return for an LPM token packet.
1993 * See \ref cy_en_usbfs_dev_drv_lpm_req_t for the set of options.
1994 *
1995 *******************************************************************************/
Cy_USBFS_Dev_Drv_Lpm_SetResponse(USBFS_Type * base,cy_en_usbfs_dev_drv_lpm_req_t response)1996 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Lpm_SetResponse(USBFS_Type *base, cy_en_usbfs_dev_drv_lpm_req_t response)
1997 {
1998 USBFS_DEV_LPM_LPM_CTL(base) = _CLR_SET_FLD32U(USBFS_DEV_LPM_LPM_CTL(base),
1999 USBFS_USBLPM_LPM_CTL_LPM_RESP, ((uint32_t) response));
2000 }
2001
2002
2003 /*******************************************************************************
2004 * Function Name: Cy_USBFS_Dev_Drv_Lpm_GetResponse
2005 ****************************************************************************//**
2006 *
2007 * Returns the response value that the device sends as part of the handshake
2008 * packet when an LPM token packet is received.
2009 *
2010 * \param base
2011 * The pointer to the USBFS instance.
2012 *
2013 * \return
2014 * The response to return for an LPM token packet.
2015 * See \ref cy_en_usbfs_dev_drv_lpm_req_t for the set of options.
2016 *
2017 *******************************************************************************/
Cy_USBFS_Dev_Drv_Lpm_GetResponse(USBFS_Type const * base)2018 __STATIC_INLINE cy_en_usbfs_dev_drv_lpm_req_t Cy_USBFS_Dev_Drv_Lpm_GetResponse(USBFS_Type const *base)
2019 {
2020 uint32_t retValue = _FLD2VAL(USBFS_USBLPM_LPM_CTL_LPM_RESP, USBFS_DEV_LPM_LPM_CTL(base));
2021 return (cy_en_usbfs_dev_drv_lpm_req_t) retValue;
2022 }
2023 /** \} group_usbfs_dev_drv_functions_lpm */
2024
2025
2026 /**
2027 * \addtogroup group_usbfs_dev_hal_functions_endpoint_config
2028 * \{
2029 */
2030 /*******************************************************************************
2031 * Function Name: Cy_USBFS_Dev_Drv_AddEndpoint
2032 ****************************************************************************//**
2033 *
2034 * Configures a data endpoint for the following operation (allocates hardware
2035 * resources for data endpoint).
2036 *
2037 * \param base
2038 * The pointer to the USBFS instance.
2039 *
2040 * \param config
2041 * The pointer to data endpoint configuration \ref cy_stc_usb_dev_ep_config_t.
2042 *
2043 * \param context
2044 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
2045 * allocated by the user. The structure is used during the USBFS Device
2046 * operation for internal configuration and data retention. The user must not
2047 * modify anything in this structure.
2048 *
2049 * \return
2050 * The status code of the function execution \ref cy_en_usbfs_dev_drv_status_t.
2051 *
2052 *******************************************************************************/
Cy_USBFS_Dev_Drv_AddEndpoint(USBFS_Type * base,cy_stc_usb_dev_ep_config_t const * config,cy_stc_usbfs_dev_drv_context_t * context)2053 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_AddEndpoint(USBFS_Type *base,
2054 cy_stc_usb_dev_ep_config_t const *config,
2055 cy_stc_usbfs_dev_drv_context_t *context)
2056 {
2057 cy_en_usbfs_dev_drv_status_t retStatus = CY_USBFS_DEV_DRV_BAD_PARAM;
2058
2059 uint32_t endpoint = CY_USBFS_DEV_DRV_EPADDR2EP(config->endpointAddr);
2060
2061 /* Checks if the endpoint is supported by the driver */
2062 if (CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint))
2063 {
2064 retStatus = context->addEndpoint(base, config, context);
2065 }
2066
2067 return retStatus;
2068 }
2069
2070
2071 /*******************************************************************************
2072 * Function Name: Cy_USBFS_Dev_Drv_OverwriteMemcpy
2073 ****************************************************************************//**
2074 *
2075 * Overwrites the memory copy (memcpy) function used to copy data with the user-
2076 * implemented:
2077 * * \ref Cy_USBFS_Dev_Drv_ReadOutEndpoint copies data from from the internal
2078 * buffer to the application buffer for OUT endpoint.
2079 * * \ref Cy_USBFS_Dev_Drv_LoadInEndpoint copies data from the application buffer
2080 * for IN endpoint to the the internal buffer.
2081 * Only applicable when endpoint management mode is
2082 * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO.
2083 *
2084 * \param base
2085 * The pointer to the USBFS instance.
2086 *
2087 * \param endpoint
2088 * The data endpoint number.
2089 *
2090 * \param memcpyFunc
2091 * The pointer to the function that copies data.
2092 *
2093 * \param context
2094 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
2095 * allocated by the user. The structure is used during the USBFS Device
2096 * operation for internal configuration and data retention. The user must not
2097 * modify anything in this structure.
2098 *
2099 *******************************************************************************/
Cy_USBFS_Dev_Drv_OverwriteMemcpy(USBFS_Type const * base,uint32_t endpoint,cy_fn_usbfs_dev_drv_memcpy_ptr_t memcpyFunc,cy_stc_usbfs_dev_drv_context_t * context)2100 __STATIC_INLINE void Cy_USBFS_Dev_Drv_OverwriteMemcpy(USBFS_Type const *base,
2101 uint32_t endpoint,
2102 cy_fn_usbfs_dev_drv_memcpy_ptr_t memcpyFunc,
2103 cy_stc_usbfs_dev_drv_context_t *context)
2104 {
2105 /* Suppress a compiler warning about unused variables */
2106 (void) base;
2107
2108 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
2109
2110 endpoint = CY_USBFS_DEV_DRV_EP2PHY(endpoint);
2111 context->epPool[endpoint].copyData = memcpyFunc;
2112 }
2113 /** \} group_usbfs_dev_hal_functions_endpoint_config */
2114
2115
2116 /**
2117 * \addtogroup group_usbfs_dev_hal_functions_data_xfer
2118 * \{
2119 */
2120 /*******************************************************************************
2121 * Function Name: Cy_USBFS_Dev_Drv_GetEndpointState
2122 ****************************************************************************//**
2123 *
2124 * Returns the state of the endpoint.
2125 *
2126 * \param base
2127 * The pointer to the USBFS instance.
2128 *
2129 * \param endpoint
2130 * The data endpoint number.
2131 *
2132 * \param context
2133 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
2134 * allocated by the user. The structure is used during the USBFS Device
2135 * operation for internal configuration and data retention. The user must not
2136 * modify anything in this structure.
2137 *
2138 * \return
2139 * Data endpoint state \ref cy_en_usb_dev_ep_state_t.
2140 *
2141 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetEndpointState(USBFS_Type const * base,uint32_t endpoint,cy_stc_usbfs_dev_drv_context_t const * context)2142 __STATIC_INLINE cy_en_usb_dev_ep_state_t Cy_USBFS_Dev_Drv_GetEndpointState(
2143 USBFS_Type const *base,
2144 uint32_t endpoint,
2145 cy_stc_usbfs_dev_drv_context_t const *context)
2146
2147 {
2148 cy_en_usb_dev_ep_state_t retState = CY_USB_DEV_EP_INVALID;
2149
2150 (void)base; /* Suppress warning */
2151
2152 if (CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint))
2153 {
2154 retState = context->epPool[CY_USBFS_DEV_DRV_EP2PHY(endpoint)].state;
2155 }
2156
2157 return retState;
2158 }
2159
2160
2161 /*******************************************************************************
2162 * Function Name: Cy_USBFS_Dev_Drv_LoadInEndpoint
2163 ****************************************************************************//**
2164 *
2165 * Loads data into the IN endpoint buffer. After data loads, the
2166 * endpoint is ready to be read by the host.
2167 *
2168 * \param base
2169 * The pointer to the USBFS instance.
2170 *
2171 * \param endpoint
2172 * The IN data endpoint number.
2173 *
2174 * \param buffer
2175 * The pointer to the buffer containing data bytes to load.
2176 *
2177 * \param size
2178 * The number of bytes to load into the endpoint.
2179 * This value must be less than or equal to endpoint maximum packet size.
2180 *
2181 * \param context
2182 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
2183 * allocated by the user. The structure is used during the USBFS Device
2184 * operation for internal configuration and data retention. The user must not
2185 * modify anything in this structure.
2186 *
2187 * \return
2188 * The status code of the function execution \ref cy_en_usbfs_dev_drv_status_t.
2189 *
2190 *******************************************************************************/
Cy_USBFS_Dev_Drv_LoadInEndpoint(USBFS_Type * base,uint32_t endpoint,uint8_t const * buffer,uint32_t size,cy_stc_usbfs_dev_drv_context_t * context)2191 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_LoadInEndpoint(
2192 USBFS_Type *base,
2193 uint32_t endpoint,
2194 uint8_t const *buffer,
2195 uint32_t size,
2196 cy_stc_usbfs_dev_drv_context_t *context)
2197 {
2198 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
2199 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_DIR_IN(context->epPool[CY_USBFS_DEV_DRV_EP2PHY(endpoint)].address));
2200
2201 return context->loadInEndpoint(base, CY_USBFS_DEV_DRV_EP2PHY(endpoint), buffer, size, context);
2202 }
2203
2204
2205 /*******************************************************************************
2206 * Function Name: Cy_USBFS_Dev_Drv_ReadOutEndpoint
2207 ****************************************************************************//**
2208 *
2209 * Reads data from the OUT endpoint buffer.
2210 * Before executing a next read, the \ref Cy_USBFS_Dev_Drv_EnableOutEndpoint must be
2211 * called to allow the Host to write data into the endpoint.
2212 *
2213 * \param base
2214 * The pointer to the USBFS instance.
2215 *
2216 * \param endpoint
2217 * The OUT data endpoint number.
2218 *
2219 * \param buffer
2220 * The pointer to the buffer that stores read data.
2221 *
2222 * \param size
2223 * The number of bytes to read from the endpoint.
2224 * This value must be less than or equal to the endpoint maximum packet size.
2225 *
2226 * \param actSize
2227 * The number of actually read bytes.
2228 *
2229 * \param context
2230 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
2231 * allocated by the user. The structure is used during the USBFS Device
2232 * operation for internal configuration and data retention. The user must not
2233 * modify anything in this structure.
2234 *
2235 * \return
2236 * The status code of the function execution \ref cy_en_usbfs_dev_drv_status_t.
2237 *
2238 *******************************************************************************/
Cy_USBFS_Dev_Drv_ReadOutEndpoint(USBFS_Type * base,uint32_t endpoint,uint8_t * buffer,uint32_t size,uint32_t * actSize,cy_stc_usbfs_dev_drv_context_t * context)2239 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_ReadOutEndpoint(
2240 USBFS_Type *base,
2241 uint32_t endpoint,
2242 uint8_t *buffer,
2243 uint32_t size,
2244 uint32_t *actSize,
2245 cy_stc_usbfs_dev_drv_context_t *context)
2246 {
2247 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
2248 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_DIR_OUT(context->epPool[CY_USBFS_DEV_DRV_EP2PHY(endpoint)].address));
2249
2250 return context->readOutEndpoint(base, CY_USBFS_DEV_DRV_EP2PHY(endpoint), buffer, size, actSize, context);
2251 }
2252
2253
2254 /*******************************************************************************
2255 * Function Name: Cy_USBFS_Dev_Drv_GetEndpointAckState
2256 ****************************************************************************//**
2257 *
2258 * Returns whether the transaction completed with ACK for a certain endpoint.
2259 *
2260 * \param base
2261 * The pointer to the USBFS instance.
2262 *
2263 * \param endpoint
2264 * The data endpoint number.
2265 *
2266 * \return
2267 * ACK state: true - transaction completed with ACK, false - otherwise.
2268 *
2269 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetEndpointAckState(USBFS_Type const * base,uint32_t endpoint)2270 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_GetEndpointAckState(USBFS_Type const *base, uint32_t endpoint)
2271 {
2272 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
2273
2274 endpoint = CY_USBFS_DEV_DRV_EP2PHY(endpoint);
2275 return _FLD2BOOL(USBFS_USBDEV_SIE_EP1_CR0_ACKED_TXN, USBFS_DEV_SIE_EP_CR0(base, endpoint));
2276 }
2277
2278
2279 /*******************************************************************************
2280 * Function Name: Cy_USBFS_Dev_Drv_GetEndpointCount
2281 ****************************************************************************//**
2282 *
2283 * Returns the number of data bytes in the transaction for a certain endpoint.
2284 * Before calling this function, ensure the Host has written data into the
2285 * endpoint. The returned value is updated after the Host access to the
2286 * endpoint but remains unchanged after data has been read from the endpoint
2287 * buffer.
2288 * A typical use case is to read the number of bytes that the Host wrote into the
2289 * OUT endpoint.
2290 *
2291 * \param base
2292 * The pointer to the USBFS instance.
2293 *
2294 * \param endpoint
2295 * The data endpoint number.
2296 *
2297 * \return
2298 * The number of data bytes in the transaction.
2299 *
2300 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetEndpointCount(USBFS_Type const * base,uint32_t endpoint)2301 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetEndpointCount(USBFS_Type const *base, uint32_t endpoint)
2302 {
2303 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
2304
2305 return Cy_USBFS_Dev_Drv_GetSieEpCount(base, CY_USBFS_DEV_DRV_EP2PHY(endpoint));
2306 }
2307 /** \} group_usbfs_dev_hal_functions_data_xfer */
2308
2309
2310 /**
2311 * \addtogroup group_usbfs_dev_hal_functions_ep0_service
2312 * \{
2313 */
2314 /*******************************************************************************
2315 * Function Name: Cy_USBFS_Dev_Drv_Ep0Stall
2316 ****************************************************************************//**
2317 *
2318 * Stalls endpoint 0.
2319 *
2320 * \param base
2321 * The pointer to the USBFS instance.
2322 *
2323 *******************************************************************************/
Cy_USBFS_Dev_Drv_Ep0Stall(USBFS_Type * base)2324 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Ep0Stall(USBFS_Type *base)
2325 {
2326 /* Updates the CR registers to STALL a request (CNT register does not care) */
2327 Cy_USBFS_Dev_Drv_WriteEp0Mode(base, CY_USBFS_DEV_DRV_EP_CR_STALL_INOUT);
2328 }
2329
2330
2331 /*******************************************************************************
2332 * Function Name: Cy_USBFS_Dev_Drv_GetEp0MaxPacket
2333 ****************************************************************************//**
2334 *
2335 * Returns the endpoint 0 maximum packet size that can be for read or write from
2336 * the endpoint 0 buffer.
2337 *
2338 * \param base
2339 * The pointer to the USBFS instance.
2340 *
2341 * \return
2342 * The endpoint 0 maximum packet size (endpoint 0 has a dedicated hardware buffer).
2343 *
2344 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetEp0MaxPacket(USBFS_Type const * base)2345 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetEp0MaxPacket(USBFS_Type const *base)
2346 {
2347 /* Suppresses a compiler warning about unused variables */
2348 (void) base;
2349
2350 return (CY_USBFS_DEV_DRV_EP0_BUFFER_SIZE);
2351 }
2352
2353
2354 /** \} group_usbfs_dev_hal_functions_ep0_service */
2355
2356 #if defined(__cplusplus)
2357 }
2358 #endif
2359
2360 #endif /* CY_IP_MXUSBFS */
2361
2362 #endif /* (CY_USBFS_DEV_DRV_H) */
2363
2364
2365 /* [] END OF FILE */
2366