1 /***************************************************************************//**
2 * \file cy_usbfs_dev_drv.h
3 * \version 2.30
4 *
5 * Provides API declarations of the USBFS driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2018-2023 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://Infineon.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.30</td>
583 * <td> \ref Cy_USBFS_Dev_Drv_DeInit() was updated to reduce power
584 * consumption of the USB IP block after deinitialization.
585 * </td>
586 * <td> \ref Cy_USBFS_Dev_Drv_DeInit() did not return all registers to the
587 * default value, which caused the USB IP block to consume more current
588 * when it was disabled.
589 * </td>
590 * </tr>
591 * <tr>
592 * <td>2.20.3</td>
593 * <td>Minor syntax update and spell fix.</td>
594 * <td>Updated for compliance with MISRA-C:2012 standard and fixing spell errors.</td>
595 * </tr>
596 * <tr>
597 * <td>2.20.2</td>
598 * <td>Minor syntax updates. Added specific deviations documentation.</td>
599 * <td>Updated for compliance with MISRA-C:2012 standard.</td>
600 * </tr>
601 * <tr>
602 * <td>2.20.1</td>
603 * <td>Minor documentation updates.</td>
604 * <td>Documentation enhancement.</td>
605 * </tr>
606 * <tr>
607 * <td rowspan="2">2.20</td>
608 * <td>Fix configuration register value restoring in resume routine after
609 * Deep Sleep.
610 * </td>
611 * <td>Fix issue that USB Device stops working in DMA modes after wake up
612 * from Deep Sleep.
613 * </td>
614 * </tr>
615 * <tr>
616 * <td>The LPM requests are ignored after wake up from Deep Sleep and the
617 * host starts sending SOFs.</td>
618 * <td>Updated \ref Cy_USBFS_Dev_Drv_Resume function to restore LPM control
619 * register after exit Deep Sleep.
620 * </td>
621 * </tr>
622 * <tr>
623 * <td>2.10</td>
624 * <td>Returns the data toggle bit into the previous state after detecting
625 * that the host is retrying an OUT transaction.</td>
626 * <td>The device was not able to recover the data toggle bit and
627 * continues communication through the endpoint after the host retried
628 * the OUT transaction (the retried transaction has the same toggle bit
629 * as the previous had).
630 * </td>
631 * </tr>
632 * <tr>
633 * <td>2.0</td>
634 * <td>The list of changes to support the MBED-OS USB Device stack is provided below:
635 * - Changed the processing of the control transfers.
636 * - Updated the endpoint 0 service functions to update the endpoint 0 registers
637 * before the function returns.
638 * - Moved the set-device-address processing into the driver from the middleware.
639 * - Changed the flow to configure endpoints after configuration change:
640 * unconfigure the device or remove all endpoints, add endpoints, configure
641 * the device. Updated the functions:
642 * \ref Cy_USBFS_Dev_Drv_UnConfigureDevice, \ref Cy_USBFS_Dev_Drv_AddEndpoint
643 * and \ref Cy_USBFS_Dev_Drv_ConfigDevice.
644 * Removed the Cy_USBFS_Dev_Drv_ConfigDeviceComplete function because it is no needed anymore.
645 * - Added the functions: \ref Cy_USBFS_Dev_Drv_Ep0ReadResult(), \ref Cy_USBFS_Dev_Drv_SetAddress()
646 * and \ref Cy_USBFS_Dev_Drv_GetEp0MaxPacket().
647 * - Changed the function signature \ref Cy_USBFS_Dev_Drv_Ep0Stall().
648 * - Obsolete function Cy_USBFS_Dev_Drv_GetEndpointStallState; the \ref
649 * Cy_USBFS_Dev_Drv_GetEndpointState() updated to be used instead of the obsolete function.
650 * - Reduced the time required to complete abort operation in function \ref Cy_USBFS_Dev_Drv_Abort.
651 * Obsolete function Cy_USBFS_Dev_Drv_AbortComplete because entire abort operation is handled by
652 * \ref Cy_USBFS_Dev_Drv_Abort.
653 * - Added the endpoint address argument to the \ref cy_cb_usbfs_dev_drv_ep_callback_t to simplify
654 * endpoint transfer complete event processing for the MBED-OS USB Device stack.
655 * </td>
656 * <td>Updated the driver to support the MBED-OS USB Device stack and Cypress
657 * USB Device middleware.</td>
658 * </tr>
659 * <tr>
660 * <td rowspan="2">1.10</td>
661 * <td>Fixed the \ref Cy_USBFS_Dev_Drv_Disable function to not disable DMA
662 * in CPU mode.</td>
663 * <td>Calling this function triggers assert because DMA for endpoints is not
664 * initialized/used in the CPU mode.</td>
665 * </tr>
666 * <tr>
667 * <td>Updated the condition statement in the \ref CY_USBFS_DEV_DRV_ALLOC_ENDPOINT_BUFFER
668 * macro to explicitly check against non-zero.</td>
669 * <td>Fixed MISRA 13.2 violation in the macro.</td>
670 * </tr>
671 * <tr>
672 * <td>1.0</td>
673 * <td>The initial version.</td>
674 * <td></td>
675 * </tr>
676 * </table>
677 *
678 ********************************************************************************
679 *
680 * \defgroup group_usbfs_dev_drv_macros Macros
681 * \{
682 \defgroup group_usbfs_dev_drv_macros_intr_level Interrupt Level
683 * \defgroup group_usbfs_dev_drv_macros_intr_cause Interrupt Cause
684 * \defgroup group_usbfs_dev_drv_macros_ep_xfer_err Transfer Errors
685 * \}
686 * \defgroup group_usbfs_dev_drv_functions Functions
687 * \{
688 * \defgroup group_usbfs_dev_hal_functions_common Initialization Functions
689 * \defgroup group_usbfs_dev_drv_functions_interrupts Interrupt Functions
690 * \defgroup group_usbfs_dev_hal_functions_ep0_service Endpoint 0 Service Functions
691 * \defgroup group_usbfs_dev_hal_functions_endpoint_config Data Endpoint Configuration Functions
692 * \defgroup group_usbfs_dev_hal_functions_data_xfer Data Endpoint Transfer Functions
693 * \defgroup group_usbfs_dev_drv_functions_low_power Low Power Functions
694 * \defgroup group_usbfs_dev_drv_functions_lpm LPM (Link Power Management) Functions
695 * \}
696 * \defgroup group_usbfs_dev_drv_data_structures Data Structures
697 * \defgroup group_usbfs_dev_drv_enums Enumerated Types
698 * \}
699 */
700
701
702 #if !defined(CY_USBFS_DEV_DRV_H)
703 #define CY_USBFS_DEV_DRV_H
704
705 #include "cy_device.h"
706
707 #if defined (CY_IP_MXUSBFS) && defined (CY_IP_MXPERI)
708
709 #include "cy_dma.h"
710 #include "cy_trigmux.h"
711 #include "cy_usbfs_dev_drv_reg.h"
712
713 #if defined(__cplusplus)
714 extern "C" {
715 #endif
716
717 /*******************************************************************************
718 * Driver version and ID
719 *******************************************************************************/
720
721 /**
722 * \addtogroup group_usbfs_dev_drv_macros
723 * \{
724 */
725
726 /** USBFS Driver major version */
727 #define CY_USBFS_VERSION_MAJOR (2)
728
729 /** USBFS Driver minor version */
730 #define CY_USBFS_VERSION_MINOR (30)
731
732 /** USBFS Driver identifier */
733 #define CY_USBFS_ID CY_PDL_DRV_ID(0x3BU)
734
735 /** USBFS Driver mode position in STATUS CODE: 0 - Device, 1 - Host */
736 #define CY_USBFS_MODE_POS (15UL)
737
738 /** USBFS Driver status code Device */
739 #define CY_USBFS_DEV_DRV_STATUS_CODE (0U)
740 /** \} group_usbfs_dev_drv_macros */
741
742
743 /*******************************************************************************
744 * Enumerated Types
745 *******************************************************************************/
746
747 /**
748 * \addtogroup group_usbfs_dev_drv_enums
749 * \{
750 */
751 /** USBFS Device Driver return codes */
752 typedef enum
753 {
754 /** Operation completed successfully */
755 CY_USBFS_DEV_DRV_SUCCESS = 0U,
756
757 /** One or more input parameters are invalid */
758 CY_USBFS_DEV_DRV_BAD_PARAM = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 1U),
759
760 /** There is not enough space in the buffer to be allocated for the endpoint (hardware or RAM) */
761 CY_USBFS_DEV_DRV_BUF_ALLOC_FAILED = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 2U),
762
763 /** Failure during DMA configuration */
764 CY_USBFS_DEV_DRV_DMA_CFG_FAILED = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 3U),
765
766 /** Timeout during dynamic reconfiguration */
767 CY_USBFS_DEV_DRV_EP_DYN_RECONFIG_TIMEOUT = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 4U),
768
769 /** Timeout during execution of the DMA read request for the OUT endpoint
770 * (only applicable in \ref group_usbfs_dev_drv_ep_management_mode2)
771 */
772 CY_USBFS_DEV_DRV_EP_DMA_READ_TIMEOUT = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 5U),
773
774 /** Timeout during execution of the DMA read request for the OUT endpoint
775 * (only applicable in \ref group_usbfs_dev_drv_ep_management_mode2)
776 */
777 CY_USBFS_DEV_DRV_EP_DMA_WRITE_TIMEOUT = (CY_USBFS_ID | CY_PDL_STATUS_ERROR | CY_USBFS_DEV_DRV_STATUS_CODE | 6U),
778
779 } cy_en_usbfs_dev_drv_status_t;
780
781
782 /** Data Endpoints Buffer Management Mode */
783 typedef enum
784 {
785 /** CPU manages a data transfer between the hardware endpoints buffer
786 * and the user SRAM
787 */
788 CY_USBFS_DEV_DRV_EP_MANAGEMENT_CPU = 0,
789
790 /** DMA manages data transfer between the hardware endpoints buffer and
791 * the user SRAM
792 */
793 CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA = 1,
794
795 /** The DMA automatically manages a data transfer between the hardware endpoints
796 * FIFO buffer and the user SRAM
797 */
798 CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO = 2,
799 } cy_en_usbfs_dev_drv_ep_management_mode_t;
800
801 /** Data Endpoint Register Access Type */
802 typedef enum
803 {
804 CY_USBFS_DEV_DRV_USE_8_BITS_DR, /**< Use 8-bits registers to access the data endpoints */
805 CY_USBFS_DEV_DRV_USE_16_BITS_DR, /**< Use 16-bits registers to access the data endpoints */
806 } cy_en_usbfs_dev_ep_access_t;
807
808 /** Service Callback Events (this enumerated type is used by middleware) */
809 typedef enum
810 {
811 CY_USB_DEV_BUS_RESET = 0U, /**< Callback hooked to the bus reset interrupt */
812 CY_USB_DEV_EP0_SETUP = 1U, /**< Callback hooked to the endpoint 0 SETUP packet interrupt */
813 CY_USB_DEV_EP0_IN = 2U, /**< Callback hooked to the endpoint 0 IN packet interrupt */
814 CY_USB_DEV_EP0_OUT = 3U, /**< Callback hooked to the endpoint 0 OUT packet interrupt */
815 } cy_en_usb_dev_service_cb_t;
816
817 /** Callback Sources */
818 typedef enum
819 {
820 CY_USBFS_DEV_DRV_EP1 = 0U, /**< Callback hooked to the Data Endpoint 1 completion interrupt */
821 CY_USBFS_DEV_DRV_EP2 = 1U, /**< Callback hooked to the Data Endpoint 2 completion interrupt */
822 CY_USBFS_DEV_DRV_EP3 = 2U, /**< Callback hooked to the Data Endpoint 3 completion interrupt */
823 CY_USBFS_DEV_DRV_EP4 = 3U, /**< Callback hooked to the Data Endpoint 4 completion interrupt */
824 CY_USBFS_DEV_DRV_EP5 = 4U, /**< Callback hooked to the Data Endpoint 5 completion interrupt */
825 CY_USBFS_DEV_DRV_EP6 = 5U, /**< Callback hooked to the Data Endpoint 6 completion interrupt */
826 CY_USBFS_DEV_DRV_EP7 = 6U, /**< Callback hooked to the Data Endpoint 7 completion interrupt */
827 CY_USBFS_DEV_DRV_EP8 = 7U, /**< Callback hooked to the Data Endpoint 8 completion interrupt */
828 CY_USBFS_DEV_DRV_SOF = 8U, /**< Callback hooked to the SOF packet received interrupt */
829 CY_USBFS_DEV_DRV_LPM = 9U, /**< Callback hooked to the LPM request received interrupt */
830 } cy_en_usbfs_dev_drv_cb_source_t;
831
832 /** Data Endpoint States (this enumerated type is used by middleware) */
833 typedef enum
834 {
835 CY_USB_DEV_EP_IDLE, /**< The endpoint is in an idle state after the configuration is set */
836 CY_USB_DEV_EP_PENDING, /**< The transfer targeted at an endpoint is in progress */
837 CY_USB_DEV_EP_COMPLETED, /**< The transfer targeted at an endpoint is completed */
838 CY_USB_DEV_EP_STALLED, /**< The endpoint is stalled */
839 CY_USB_DEV_EP_DISABLED, /**< The endpoint is disabled (not used in this configuration) */
840 CY_USB_DEV_EP_INVALID, /**< The endpoint is not supported by the hardware */
841 } cy_en_usb_dev_ep_state_t;
842
843 /** USB Lines Control */
844 typedef enum
845 {
846 CY_USBFS_DEV_DRV_FORCE_STATE_J = 0xA0U, /**< Force a J State onto the USB lines */
847 CY_USBFS_DEV_DRV_FORCE_STATE_K = 0x80U, /**< Force a K State onto the USB lines */
848 CY_USBFS_DEV_DRV_FORCE_STATE_SE0 = 0xC0U, /**< Force a Single Ended 0 onto the USB lines */
849 CY_USBFS_DEV_DRV_FORCE_STATE_NONE = 0x00U /**< Return the bus to the SIE control */
850 } cy_en_usbfs_dev_drv_force_bus_state_t;
851
852 /** LPM (Link Power Management) Responses */
853 typedef enum
854 {
855 /** The next LPM request will be responded with NACK */
856 CY_USBFS_DEV_DRV_LPM_REQ_NACK = 0x0U,
857
858 /** The next LPM request will be responded with ACK */
859 CY_USBFS_DEV_DRV_LPM_REQ_ACK = 0x1U,
860 } cy_en_usbfs_dev_drv_lpm_req_t;
861
862 /** USB Control EP0 transfer state */
863 typedef enum
864 {
865 CY_USBFS_DEV_DRV_EP0_CTRL_STATE_IDLE,
866 CY_USBFS_DEV_DRV_EP0_CTRL_STATE_SETUP,
867 CY_USBFS_DEV_DRV_EP0_CTRL_STATE_DATA,
868 CY_USBFS_DEV_DRV_EP0_CTRL_STATE_STATUS_IN,
869 CY_USBFS_DEV_DRV_EP0_CTRL_STATE_STATUS_OUT,
870 } cy_en_usbfs_dev_drv_ep0_ctrl_state_t;
871
872 /** \} group_usbfs_dev_drv_enums */
873
874
875 /*******************************************************************************
876 * Type Definitions
877 *******************************************************************************/
878
879 /**
880 * \addtogroup group_usbfs_dev_drv_data_structures
881 * \{
882 */
883
884 /** Data Endpoint Configuration Structure */
885 typedef struct
886 {
887 bool enableEndpoint; /**< Defines if the endpoint becomes active after configuration */
888 bool allocBuffer; /**< Defines if the endpoint needs buffer allocation */
889 uint16_t maxPacketSize; /**< The endpoint max packet size */
890 uint16_t bufferSize; /**< The endpoint buffer size (the biggest max packet size
891 across all alternate for this endpoint) */
892 uint8_t endpointAddr; /**< The endpoint address (number plus direction bit) */
893 uint8_t attributes; /**< The endpoint attributes */
894 } cy_stc_usb_dev_ep_config_t;
895
896 /**
897 * Driver context structure prototype.
898 * The driver define this structure type \ref cy_stc_usbfs_dev_drv_context_t.
899 */
900 struct cy_stc_usbfs_dev_drv_context;
901
902 /**
903 * Provides the typedef for the callback function called in the
904 * \ref Cy_USBFS_Dev_Drv_Interrupt to notify the user interrupt events.
905 */
906 typedef void (* cy_cb_usbfs_dev_drv_callback_t)(USBFS_Type *base,
907 struct cy_stc_usbfs_dev_drv_context *context);
908
909 /**
910 * Provides the typedef for the callback function called in the
911 * \ref Cy_USBFS_Dev_Drv_Interrupt to notify the user about endpoint transfer
912 * completion event.
913 */
914 typedef void (* cy_cb_usbfs_dev_drv_ep_callback_t)(USBFS_Type *base,
915 uint32_t endpointAddr,
916 uint32_t errorType,
917 struct cy_stc_usbfs_dev_drv_context *context);
918
919 /**
920 * Provides the typedef for the user defined function to replace library provided
921 * memcpy function to copy data from endpoint buffer to the user buffer.
922 */
923 typedef uint8_t * (* cy_fn_usbfs_dev_drv_memcpy_ptr_t)(uint8_t *dest,
924 const uint8_t *src,
925 uint32_t size);
926
927 /** \cond INTERNAL*/
928
929 /**
930 * Specifies the typedef for the pointer to the function that adds a data endpoint
931 */
932 typedef cy_en_usbfs_dev_drv_status_t (* cy_fn_usbfs_dev_drv_add_ep_ptr_t)
933 (USBFS_Type *base,
934 cy_stc_usb_dev_ep_config_t const *config,
935 struct cy_stc_usbfs_dev_drv_context *context);
936
937 /**
938 * Specifies the typedef for the pointer to the function that loads data into
939 * the data endpoint.
940 */
941 typedef cy_en_usbfs_dev_drv_status_t (* cy_fn_usbfs_dev_drv_load_ep_ptr_t)
942 (USBFS_Type *base,
943 uint32_t endpoint,
944 const uint8_t *buffer,
945 uint32_t size,
946 struct cy_stc_usbfs_dev_drv_context *context);
947
948 /**
949 * Specifies the typedef for the pointer to the function that reads data from
950 * the data endpoint.
951 */
952 typedef cy_en_usbfs_dev_drv_status_t (* cy_fn_usbfs_dev_drv_read_ep_ptr_t)
953 (USBFS_Type *base,
954 uint32_t endpoint,
955 uint8_t *buffer,
956 uint32_t size,
957 uint32_t *actSize,
958 struct cy_stc_usbfs_dev_drv_context *context);
959 /** \endcond */
960
961 /** DMA Channel Configuration Structure */
962 typedef struct
963 {
964 DW_Type *base; /**< Pointer to the DMA base */
965 uint32_t chNum; /**< Channel number */
966 uint32_t priority; /**< Channel's priority */
967 bool preemptable; /**< Specifies whether the channel is preempt-able by another higher-priority channel */
968
969 /** DMA out trigger mux (applicable only when mode is
970 * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO)
971 */
972 uint32_t outTrigMux;
973
974 /** The pointer to the 1st allocated DMA descriptor (required for DMA operation) */
975 cy_stc_dma_descriptor_t *descr0;
976
977 /** The pointer to the 2nd allocated DMA descriptor (required when mode is
978 * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO)
979 */
980 cy_stc_dma_descriptor_t *descr1;
981
982 } cy_stc_usbfs_dev_drv_dma_config_t;
983
984 /** Driver Configuration Structure */
985 typedef struct cy_stc_usbfs_dev_drv_config
986 {
987 /** Endpoints management mode */
988 cy_en_usbfs_dev_drv_ep_management_mode_t mode;
989
990 /** DMA channels configuration for the endpoints.
991 * Only DMChannels for active endpoints must be configured. Provide NULL
992 * pointer if endpoint is not used. Applicable when \ref mode is
993 * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA or \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO.
994 */
995 const cy_stc_usbfs_dev_drv_dma_config_t *dmaConfig[CY_USBFS_DEV_DRV_NUM_EPS_MAX];
996
997 /**
998 * The pointer to the buffer allocated for the OUT endpoints (applicable only when \ref mode
999 * is \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO)
1000 */
1001 uint8_t *epBuffer;
1002
1003 /**
1004 * The size of the buffer for the OUT endpoints (applicable only when \ref mode
1005 * is \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO)
1006 */
1007 uint16_t epBufferSize;
1008
1009 /** The mask that assigns interrupt sources to trigger: Low, Medium, or High interrupt.
1010 * Use the macros provided in group_usbfs_dev_drv_macros_intr_level to initialize the
1011 * intrLevelSel mask.
1012 */
1013 uint32_t intrLevelSel;
1014
1015 /** Enables LPM (Link Power Management) response */
1016 bool enableLpm;
1017
1018 /** Data endpoints access type */
1019 cy_en_usbfs_dev_ep_access_t epAccess;
1020
1021 } cy_stc_usbfs_dev_drv_config_t;
1022
1023 /** \cond INTERNAL: Endpoint Structure */
1024 typedef struct
1025 {
1026 volatile uint8_t address; /**< Endpoint address (include direction bit) */
1027 volatile uint8_t toggle; /**< Toggle bit in SIE_EP_CNT1 register */
1028 volatile uint8_t sieMode; /**< SIE mode to arm endpoint on the bus */
1029
1030 uint8_t *buffer; /**< The pointer to the buffer */
1031 volatile uint16_t bufferSize; /**< Endpoint buffer size */
1032 volatile uint16_t startBuf; /**< Start of the buffer */
1033
1034 volatile bool isPending; /**< Save the pending state before stall endpoint */
1035 volatile cy_en_usb_dev_ep_state_t state; /**< Endpoint state */
1036
1037 /** Completes an event notification callback */
1038 cy_cb_usbfs_dev_drv_ep_callback_t epComplete;
1039
1040 DW_Type *base; /**< The pointer to the DMA base */
1041 uint32_t chNum; /**< DMA Channel number */
1042 uint32_t outTrigMux; /**< Out trigger mux for DMA channel number */
1043
1044 cy_stc_dma_descriptor_t* descr0; /**< The pointer to the descriptor 0 */
1045 cy_stc_dma_descriptor_t* descr1; /**< The pointer to the descriptor 1 */
1046
1047 cy_fn_usbfs_dev_drv_memcpy_ptr_t copyData; /**< The pointer to the user memcpy function */
1048
1049 } cy_stc_usbfs_dev_drv_endpoint_data_t;
1050 /** \endcond */
1051
1052 /** USBFS Device context structure.
1053 * All fields for the context structure are internal. The firmware never reads or
1054 * writes these values. The firmware allocates a structure and provides the
1055 * address of the structure to the middleware in HID function calls. The firmware
1056 * must ensure that the defined instance of this structure remains in scope while
1057 * the middleware is in use.
1058 */
1059 typedef struct cy_stc_usbfs_dev_drv_context
1060 {
1061 /** \cond INTERNAL */
1062 /** Stores the Endpoint 0 buffer to put the read operation results */
1063 uint8_t *ep0Buffer;
1064
1065 /** Stores the Endpoint 0 buffer size */
1066 uint8_t ep0BufferSize;
1067
1068 /** Endpoint 0 data toggle bit: 0 or USBFS_USBDEV_EP0_CNT_DATA_TOGGLE_Msk */
1069 uint8_t ep0DataToggle;
1070
1071 /** Active endpoint mask */
1072 uint8_t activeEpMask;
1073
1074 /** The device address to set */
1075 uint8_t address;
1076
1077 /** Defines the list of endpoints that waits for abort completion */
1078 volatile uint8_t epAbortMask;
1079
1080 /** Endpoints management mode */
1081 cy_en_usbfs_dev_drv_ep_management_mode_t mode;
1082
1083 /** Stores the control transfer state */
1084 cy_en_usbfs_dev_drv_ep0_ctrl_state_t ep0CtrlState;
1085
1086 /* Status to set or not the device address after the status state of the control transfer */
1087 bool setAddress;
1088
1089 /** Defines which endpoint registers to use: 8-bits or 16-bits */
1090 bool useReg16;
1091
1092 /** Bus reset callback notification */
1093 cy_cb_usbfs_dev_drv_callback_t busReset;
1094
1095 /** Endpoint 0: Setup packet has received callback notification */
1096 cy_cb_usbfs_dev_drv_callback_t ep0Setup;
1097
1098 /** Endpoint 0: IN data packet has received callback notification */
1099 cy_cb_usbfs_dev_drv_callback_t ep0In;
1100
1101 /** Endpoint 0: OUT data packet has received callback notification */
1102 cy_cb_usbfs_dev_drv_callback_t ep0Out;
1103
1104 /** SOF frame has received callback notification */
1105 cy_cb_usbfs_dev_drv_callback_t cbSof;
1106
1107 /** LPM request has received callback notification */
1108 cy_cb_usbfs_dev_drv_callback_t cbLpm;
1109
1110 /** Pointer to addEndpoint function: depends on operation mode */
1111 cy_fn_usbfs_dev_drv_add_ep_ptr_t addEndpoint;
1112
1113 /** Pointer to loadInEndpoint function: depends on operation mode */
1114 cy_fn_usbfs_dev_drv_load_ep_ptr_t loadInEndpoint;
1115
1116 /** Pointer to readOutEndpoint function: depends on operation mode */
1117 cy_fn_usbfs_dev_drv_read_ep_ptr_t readOutEndpoint;
1118
1119 uint8_t *epSharedBuf; /**< Buffer for OUT endpoints */
1120 uint16_t epSharedBufSize; /**< Buffer size */
1121
1122 uint16_t curBufAddr; /** Current position in endpoint buffer (HW or SRAM) */
1123
1124 /** Stores endpoints information */
1125 cy_stc_usbfs_dev_drv_endpoint_data_t epPool[CY_USBFS_DEV_DRV_NUM_EPS_MAX];
1126
1127 /** The pointer to the device context structure */
1128 void *devConext;
1129 /** \endcond */
1130 } cy_stc_usbfs_dev_drv_context_t;
1131 /** \} group_usbfs_dev_drv_data_structures */
1132
1133
1134 /*******************************************************************************
1135 * Function Prototypes
1136 *******************************************************************************/
1137
1138 /**
1139 * \addtogroup group_usbfs_dev_hal_functions_common
1140 * \{
1141 * The Initialization functions provide an API to begin the USBFS driver operation
1142 * (configure and enable) and to stop operation (disable and de-initialize).
1143 */
1144 cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_Init(USBFS_Type *base,
1145 cy_stc_usbfs_dev_drv_config_t const *config,
1146 cy_stc_usbfs_dev_drv_context_t *context);
1147
1148 void Cy_USBFS_Dev_Drv_DeInit(USBFS_Type *base,
1149 cy_stc_usbfs_dev_drv_context_t *context);
1150
1151 void Cy_USBFS_Dev_Drv_Enable(USBFS_Type *base,
1152 cy_stc_usbfs_dev_drv_context_t const *context);
1153
1154 void Cy_USBFS_Dev_Drv_Disable(USBFS_Type *base,
1155 cy_stc_usbfs_dev_drv_context_t *context);
1156
1157 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetAddress(USBFS_Type *base, uint8_t address,
1158 cy_stc_usbfs_dev_drv_context_t *context);
1159 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetDeviceAddress(USBFS_Type *base, uint8_t address);
1160 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetDeviceAddress(USBFS_Type const *base);
1161
1162 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetDevContext(USBFS_Type const *base,
1163 void *devContext,
1164 cy_stc_usbfs_dev_drv_context_t *context);
1165
1166 __STATIC_INLINE void* Cy_USBFS_Dev_Drv_GetDevContext(USBFS_Type const *base,
1167 cy_stc_usbfs_dev_drv_context_t *context);
1168
1169 void Cy_USBFS_Dev_Drv_ConfigDevice(USBFS_Type *base,
1170 cy_stc_usbfs_dev_drv_context_t *context);
1171
1172 void Cy_USBFS_Dev_Drv_UnConfigureDevice(USBFS_Type *base,
1173 cy_stc_usbfs_dev_drv_context_t *context);
1174 /** \} group_usbfs_dev_hal_functions_common */
1175
1176 /**
1177 * \addtogroup group_usbfs_dev_hal_functions_ep0_service
1178 * \{
1179 * The Endpoint 0 Service functions provide an API to establish communication with
1180 * the USB Host using control endpoint 0.
1181 */
1182 void Cy_USBFS_Dev_Drv_Ep0GetSetup(USBFS_Type const *base,
1183 uint8_t *buffer,
1184 cy_stc_usbfs_dev_drv_context_t const *context);
1185
1186 uint32_t Cy_USBFS_Dev_Drv_Ep0Write(USBFS_Type *base,
1187 uint8_t const *buffer,
1188 uint32_t size,
1189 cy_stc_usbfs_dev_drv_context_t *context);
1190
1191 void Cy_USBFS_Dev_Drv_Ep0Read(USBFS_Type *base,
1192 uint8_t *buffer,
1193 uint32_t size,
1194 cy_stc_usbfs_dev_drv_context_t *context);
1195
1196 uint32_t Cy_USBFS_Dev_Drv_Ep0ReadResult(USBFS_Type const *base,
1197 cy_stc_usbfs_dev_drv_context_t *context);
1198
1199 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Ep0Stall(USBFS_Type *base);
1200
1201 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetEp0MaxPacket(USBFS_Type const *base);
1202 /** \} group_usbfs_dev_hal_functions_ep0_service */
1203
1204
1205 /**
1206 * \addtogroup group_usbfs_dev_hal_functions_endpoint_config
1207 * \{
1208 * The Data Endpoint Configuration Functions provide an API to allocate and release
1209 * hardware resources and override the memcpy function for the data endpoints.
1210 */
1211 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_AddEndpoint(USBFS_Type *base,
1212 cy_stc_usb_dev_ep_config_t const *config,
1213 cy_stc_usbfs_dev_drv_context_t *context);
1214
1215 cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_RemoveEndpoint(USBFS_Type *base,
1216 uint32_t endpointAddr,
1217 cy_stc_usbfs_dev_drv_context_t *context);
1218
1219 __STATIC_INLINE void Cy_USBFS_Dev_Drv_OverwriteMemcpy(USBFS_Type const *base,
1220 uint32_t endpoint,
1221 cy_fn_usbfs_dev_drv_memcpy_ptr_t memcpyFunc,
1222 cy_stc_usbfs_dev_drv_context_t *context);
1223 /** \} group_usbfs_dev_hal_functions_endpoint_config */
1224
1225 /**
1226 * \addtogroup group_usbfs_dev_hal_functions_data_xfer
1227 * The Data Endpoint Transfer functions provide an API to establish
1228 * communication with the USB Host using data endpoint.
1229 * \{
1230 */
1231 __STATIC_INLINE cy_en_usb_dev_ep_state_t Cy_USBFS_Dev_Drv_GetEndpointState(USBFS_Type const *base,
1232 uint32_t endpoint,
1233 cy_stc_usbfs_dev_drv_context_t const *context);
1234
1235 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_LoadInEndpoint(USBFS_Type *base,
1236 uint32_t endpoint,
1237 uint8_t const *buffer,
1238 uint32_t size,
1239 cy_stc_usbfs_dev_drv_context_t *context);
1240
1241 void Cy_USBFS_Dev_Drv_EnableOutEndpoint(USBFS_Type *base,
1242 uint32_t endpoint,
1243 cy_stc_usbfs_dev_drv_context_t *context);
1244
1245 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_ReadOutEndpoint(USBFS_Type *base,
1246 uint32_t endpoint,
1247 uint8_t *buffer,
1248 uint32_t size,
1249 uint32_t *actSize,
1250 cy_stc_usbfs_dev_drv_context_t *context);
1251
1252 cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_Abort(USBFS_Type *base,
1253 uint32_t endpoint,
1254 cy_stc_usbfs_dev_drv_context_t *context);
1255
1256 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_GetEndpointAckState(USBFS_Type const *base, uint32_t endpoint);
1257 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetEndpointCount (USBFS_Type const *base, uint32_t endpoint);
1258
1259 cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_StallEndpoint(USBFS_Type *base,
1260 uint32_t endpoint,
1261 cy_stc_usbfs_dev_drv_context_t *context);
1262
1263 cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_UnStallEndpoint(USBFS_Type *base,
1264 uint32_t endpoint,
1265 cy_stc_usbfs_dev_drv_context_t *context);
1266
1267 /** \} group_usbfs_dev_hal_functions_data_xfer */
1268
1269 /**
1270 * \addtogroup group_usbfs_dev_drv_functions_interrupts
1271 * The Functions Interrupt functions provide an API to register callbacks
1272 * for interrupt events provided by the USB block, interrupt handler, and configuration functions.
1273 * \{
1274 */
1275 void Cy_USBFS_Dev_Drv_Interrupt(USBFS_Type *base, uint32_t intrCause, cy_stc_usbfs_dev_drv_context_t *context);
1276
1277 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseHi (USBFS_Type const *base);
1278 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseMed(USBFS_Type const *base);
1279 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseLo (USBFS_Type const *base);
1280
1281 void Cy_USBFS_Dev_Drv_RegisterServiceCallback(USBFS_Type const *base,
1282 cy_en_usb_dev_service_cb_t source,
1283 cy_cb_usbfs_dev_drv_callback_t callback,
1284 cy_stc_usbfs_dev_drv_context_t *context);
1285
1286 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterSofCallback(USBFS_Type *base,
1287 cy_cb_usbfs_dev_drv_callback_t callback,
1288 cy_stc_usbfs_dev_drv_context_t *context);
1289
1290 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterLpmCallback(USBFS_Type *base,
1291 cy_cb_usbfs_dev_drv_callback_t callback,
1292 cy_stc_usbfs_dev_drv_context_t *context);
1293
1294 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterEndpointCallback(USBFS_Type const *base,
1295 uint32_t endpoint,
1296 cy_cb_usbfs_dev_drv_ep_callback_t callback,
1297 cy_stc_usbfs_dev_drv_context_t *context);
1298
1299 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetInterruptsLevel(USBFS_Type *base, uint32_t intrLevel);
1300 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptsLevel(USBFS_Type const *base);
1301
1302 __STATIC_INLINE void Cy_USBFS_Dev_Drv_DisableEp0Interrupt(USBFS_Type *base);
1303 __STATIC_INLINE void Cy_USBFS_Dev_Drv_EnableEp0Interrupt(USBFS_Type *base);
1304 /** \} group_usbfs_dev_drv_functions_interrupts */
1305
1306 /**
1307 * \addtogroup group_usbfs_dev_drv_functions_low_power
1308 * The Low-power functions provide an API to implement Low-power callback at the application level.
1309 * \{
1310 */
1311 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_CheckActivity(USBFS_Type *base);
1312 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Force (USBFS_Type *base, cy_en_usbfs_dev_drv_force_bus_state_t state);
1313 void Cy_USBFS_Dev_Drv_Suspend(USBFS_Type *base, cy_stc_usbfs_dev_drv_context_t *context);
1314 void Cy_USBFS_Dev_Drv_Resume (USBFS_Type *base, cy_stc_usbfs_dev_drv_context_t *context);
1315 /** \} group_usbfs_dev_drv_functions_low_power */
1316
1317 /**
1318 * \addtogroup group_usbfs_dev_drv_functions_lpm
1319 * The LPM functions provide an API to use the LPM feature available in the USB block.
1320 * \{
1321 */
1322 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_Lpm_GetBeslValue (USBFS_Type const *base);
1323 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_Lpm_RemoteWakeUpAllowed(USBFS_Type const *base);
1324 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Lpm_SetResponse (USBFS_Type *base, cy_en_usbfs_dev_drv_lpm_req_t response);
1325 __STATIC_INLINE cy_en_usbfs_dev_drv_lpm_req_t Cy_USBFS_Dev_Drv_Lpm_GetResponse(USBFS_Type const *base);
1326 /** \} group_usbfs_dev_drv_functions_lpm */
1327
1328
1329 /*******************************************************************************
1330 * Driver Constants
1331 *******************************************************************************/
1332
1333 /**
1334 * \addtogroup group_usbfs_dev_drv_macros
1335 * \{
1336 */
1337 /** Allocates a static buffer for the data endpoint. The size parameter must be a constant.
1338 * The allocated buffer is aligned to a 2-byte boundary. <b>An odd buffer size is
1339 * converted to even, consuming 1 extra byte. The application must discard this
1340 * extra byte</b> to support different 8-bit and 16-bit hardware buffer access types
1341 * in the driver. For more detail, refer to \ref group_usbfs_dev_drv_ep_management_buf_access.
1342 */
1343 #define CY_USBFS_DEV_DRV_ALLOC_ENDPOINT_BUFFER(buf, size) uint8_t buf[(0U != ((size) & 0x1U)) ? ((size) + 1U) : (size)] CY_ALIGN(2)
1344 /** \} group_usbfs_dev_drv_macros */
1345
1346 /**
1347 * \addtogroup group_usbfs_dev_drv_macros_intr_level
1348 * \{
1349 */
1350 /** The interrupt source is assigned to a trigger High interrupt */
1351 #define CY_USBFS_DEV_DRV_LVL_HIGH (0U)
1352 /** The interrupt source is assigned to a trigger Medium interrupt */
1353 #define CY_USBFS_DEV_DRV_LVL_MEDIUM (1U)
1354 /** The interrupt source is assigned to a trigger Low interrupt */
1355 #define CY_USBFS_DEV_DRV_LVL_LOW (2U)
1356
1357 /** Assigns the SOF interrupt source to a trigger interrupt: Low, Medium, or High */
1358 #define CY_USBFS_DEV_DRV_SET_SOF_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_SOF_LVL_SEL, level)
1359 /** Assigns the Bus Reset interrupt source to a trigger interrupt: Low, Medium, or High */
1360 #define CY_USBFS_DEV_DRV_SET_BUS_RESET_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_BUS_RESET_LVL_SEL, level)
1361 /** Assigns the Endpoint 0 interrupt source to a trigger interrupt Low, Medium, or High */
1362 #define CY_USBFS_DEV_DRV_SET_EP0_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP0_LVL_SEL, level)
1363 /** Assigns the LPM interrupt source to a trigger interrupt: Low, Medium, or High */
1364 #define CY_USBFS_DEV_DRV_SET_LPM_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_LPM_LVL_SEL, level)
1365 /** Assigns the Resume interrupt source to a trigger interrupt: Low, Medium, or High */
1366 #define CY_USBFS_DEV_DRV_SET_RESUME_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_RESUME_LVL_SEL, level)
1367 /** Assigns the Arbiter interrupt source to a trigger interrupt: Low, Medium, or High */
1368 #define CY_USBFS_DEV_DRV_SET_ARB_EP_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_ARB_EP_LVL_SEL, level)
1369 /** Assigns the Endpoint 1 interrupt source to a trigger interrupt: Low, Medium, or High */
1370 #define CY_USBFS_DEV_DRV_SET_EP1_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP1_LVL_SEL, level)
1371 /** Assigns the Endpoint 2 interrupt source to a trigger interrupt: Low, Medium, or High */
1372 #define CY_USBFS_DEV_DRV_SET_EP2_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP2_LVL_SEL, level)
1373 /** Assigns the Endpoint 3 interrupt source to a trigger interrupt: Low, Medium, or High */
1374 #define CY_USBFS_DEV_DRV_SET_EP3_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP3_LVL_SEL, level)
1375 /** Assigns the Endpoint 4 interrupt source to a trigger interrupt: Low, Medium, or High */
1376 #define CY_USBFS_DEV_DRV_SET_EP4_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP4_LVL_SEL, level)
1377 /** Assigns the Endpoint 5 interrupt source to a trigger interrupt: Low, Medium, or High */
1378 #define CY_USBFS_DEV_DRV_SET_EP5_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP5_LVL_SEL, level)
1379 /** Assigns the Endpoint 6 interrupt source to a trigger interrupt: Low, Medium, or High */
1380 #define CY_USBFS_DEV_DRV_SET_EP6_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP6_LVL_SEL, level)
1381 /** Assigns the Endpoint 7 interrupt source to a trigger interrupt: Low, Medium, or High */
1382 #define CY_USBFS_DEV_DRV_SET_EP7_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP7_LVL_SEL, level)
1383 /** Assigns the Endpoint 8 interrupt source to a trigger interrupt: Low, Medium, or High */
1384 #define CY_USBFS_DEV_DRV_SET_EP8_LVL(level) _VAL2FLD(USBFS_USBLPM_INTR_LVL_SEL_EP8_LVL_SEL, level)
1385 /** \} group_usbfs_dev_drv_macros_intr_level */
1386
1387 /**
1388 * \addtogroup group_usbfs_dev_drv_macros_intr_cause
1389 * \{
1390 */
1391 #define CY_USBFS_DEV_DRV_LPM_INTR USBFS_USBLPM_INTR_CAUSE_HI_LPM_INTR_Msk /**< Link Power Management request interrupt */
1392 #define CY_USBFS_DEV_DRV_ARBITER_INTR USBFS_USBLPM_INTR_CAUSE_HI_ARB_EP_INTR_Msk /**< Arbiter interrupt */
1393 #define CY_USBFS_DEV_DRV_EP0_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP0_INTR_Msk /**< Endpoint 0 interrupt */
1394 #define CY_USBFS_DEV_DRV_SOF_INTR USBFS_USBLPM_INTR_CAUSE_HI_SOF_INTR_Msk /**< SOF interrupt */
1395 #define CY_USBFS_DEV_DRV_BUS_RESET_INTR USBFS_USBLPM_INTR_CAUSE_HI_BUS_RESET_INTR_Msk /**< Bus Reset interrupt */
1396 #define CY_USBFS_DEV_DRV_EP1_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP1_INTR_Msk /**< Data endpoint 1 interrupt */
1397 #define CY_USBFS_DEV_DRV_EP2_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP2_INTR_Msk /**< Data endpoint 2 interrupt */
1398 #define CY_USBFS_DEV_DRV_EP3_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP3_INTR_Msk /**< Data endpoint 3 interrupt */
1399 #define CY_USBFS_DEV_DRV_EP4_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP4_INTR_Msk /**< Data endpoint 4 interrupt */
1400 #define CY_USBFS_DEV_DRV_EP5_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP5_INTR_Msk /**< Data endpoint 5 interrupt */
1401 #define CY_USBFS_DEV_DRV_EP6_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP6_INTR_Msk /**< Data endpoint 6 interrupt */
1402 #define CY_USBFS_DEV_DRV_EP7_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP7_INTR_Msk /**< Data endpoint 7 interrupt */
1403 #define CY_USBFS_DEV_DRV_EP8_INTR USBFS_USBLPM_INTR_CAUSE_HI_EP8_INTR_Msk /**< Data endpoint 8 interrupt */
1404 /** \} group_usbfs_dev_drv_macros_intr_cause */
1405
1406 /**
1407 * \addtogroup group_usbfs_dev_drv_macros_ep_xfer_err
1408 * \{
1409 */
1410 /**
1411 * An error occurred during a USB transfer.
1412 * For an IN transaction, this indicates a "no response" from the HOST scenario.
1413 * For an OUT transaction, this represents a "PID or CRC error" or the bit-stuff
1414 * error scenario.
1415 */
1416 #define CY_USBFS_DEV_ENDPOINT_TRANSFER_ERROR (0x1U)
1417
1418 /**
1419 * The data toggle bit remains the same.
1420 * The received OUT packet has the same data toggle bit that the previous
1421 * packet had. This indicates that the Host retransmitted the packet.
1422 */
1423 #define CY_USBFS_DEV_ENDPOINT_SAME_DATA_TOGGLE (0x2U)
1424 /** \} group_usbfs_dev_drv_macros_ep_xfer_err */
1425
1426
1427 /*******************************************************************************
1428 * Internal Constants
1429 *******************************************************************************/
1430
1431 /** \cond INTERNAL */
1432 /* The start position of the data endpoints SIE interrupt sources */
1433 #define USBFS_USBLPM_INTR_CAUSE_LPM_INTR_Msk USBFS_USBLPM_INTR_CAUSE_HI_LPM_INTR_Msk
1434 #define USBFS_USBLPM_INTR_CAUSE_ARB_EP_INTR_Msk USBFS_USBLPM_INTR_CAUSE_HI_ARB_EP_INTR_Msk
1435 #define USBFS_USBLPM_INTR_CAUSE_EP0_INTR_Msk USBFS_USBLPM_INTR_CAUSE_HI_EP0_INTR_Msk
1436 #define USBFS_USBLPM_INTR_CAUSE_SOF_INTR_Msk USBFS_USBLPM_INTR_CAUSE_HI_SOF_INTR_Msk
1437 #define USBFS_USBLPM_INTR_CAUSE_BUS_RESET_INTR_Msk USBFS_USBLPM_INTR_CAUSE_HI_BUS_RESET_INTR_Msk
1438 #define USBFS_USBLPM_INTR_CAUSE_EP1_INTR_Pos USBFS_USBLPM_INTR_CAUSE_HI_EP1_INTR_Pos
1439
1440 /* Validation macros */
1441 #define CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint) (((endpoint) > 0U) && ((endpoint) <= CY_USBFS_DEV_DRV_NUM_EPS_MAX))
1442 #define CY_USBFS_DEV_DRV_EP2PHY(endpoint) ((uint32_t) (endpoint) - 1U)
1443 #define CY_USBFS_DEV_DRV_EP2MASK(endpoint) ((uint32_t) (0x1UL << (endpoint)))
1444
1445 #define CY_USBFS_DEV_DRV_EPADDR2EP(endpointAddr) ((uint32_t) (endpointAddr) & 0x0FU)
1446 #define CY_USBFS_DEV_DRV_IS_EP_DIR_IN(endpointAddr) (0U != ((endpointAddr) & 0x80U))
1447 #define CY_USBFS_DEV_DRV_IS_EP_DIR_OUT(endpointAddr) (0U == ((endpointAddr) & 0x80U))
1448 #define CY_USBFS_DEV_DRV_EPADDR2PHY(endpointAddr) CY_USBFS_DEV_DRV_EP2PHY(CY_USBFS_DEV_DRV_EPADDR2EP(endpointAddr))
1449
1450 #define CY_USBFS_DEV_DRV_IS_MODE_VALID(mode) (((mode) == CY_USBFS_DEV_DRV_EP_MANAGEMENT_CPU) || \
1451 ((mode) == CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA) || \
1452 ((mode) == CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO))
1453
1454 /* Obsolete function */
1455 #define Cy_USBFS_Dev_Drv_GetEndpointStallState Cy_USBFS_Dev_Drv_GetEndpointState
1456 /** \endcond */
1457 /** \} group_usbfs_drv_macros */
1458
1459
1460 /*******************************************************************************
1461 * In-line Function Implementation
1462 *******************************************************************************/
1463
1464 /**
1465 * \addtogroup group_usbfs_dev_hal_functions_common
1466 * \{
1467 */
1468
1469 /*******************************************************************************
1470 * Function Name: Cy_USBFS_Dev_Drv_SetAddress
1471 ****************************************************************************//**
1472 *
1473 * Posts a request to set the device address after the completion status stage of
1474 * the control transfer. This function must be used if a higher level requests
1475 * to set an address before the status stage of the control transfer.
1476 *
1477 * \param base
1478 * The pointer to the USBFS instance.
1479 *
1480 * \param address
1481 * The device address.
1482 *
1483 * \param context
1484 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1485 * allocated by the user. The structure is used during the USBFS Device
1486 * operation for internal configuration and data retention. The user must not
1487 * modify anything in this structure.
1488 *
1489 *******************************************************************************/
Cy_USBFS_Dev_Drv_SetAddress(USBFS_Type * base,uint8_t address,cy_stc_usbfs_dev_drv_context_t * context)1490 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetAddress(USBFS_Type *base, uint8_t address,
1491 cy_stc_usbfs_dev_drv_context_t *context)
1492 {
1493 (void)base; /* Suppress warning */
1494 /* Stores the address to set later after the status stage of setup request completed */
1495 context->address = address;
1496 context->setAddress = true;
1497 }
1498
1499
1500 /*******************************************************************************
1501 * Function Name: Cy_USBFS_Dev_Drv_SetDeviceAddress
1502 ****************************************************************************//**
1503 *
1504 * Sets the device address (writes the address directly into the register).
1505 *
1506 * \param base
1507 * The pointer to the USBFS instance.
1508 *
1509 * \param address
1510 * Device address.
1511 *
1512 *******************************************************************************/
Cy_USBFS_Dev_Drv_SetDeviceAddress(USBFS_Type * base,uint8_t address)1513 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetDeviceAddress(USBFS_Type *base, uint8_t address)
1514 {
1515 base->USBDEV.CR0 = _CLR_SET_FLD32U(base->USBDEV.CR0, USBFS_USBDEV_CR0_DEVICE_ADDRESS, address);
1516 }
1517
1518
1519 /*******************************************************************************
1520 * Function Name: Cy_USBFS_Dev_Drv_GetDeviceAddress
1521 ****************************************************************************//**
1522 *
1523 * Returns the device address (reads the address directly from the register).
1524 *
1525 * \param base
1526 * The pointer to the USBFS instance.
1527 *
1528 * \return
1529 * The device address.
1530 * The device address is assigned by the Host during device enumeration.
1531 * Zero means that the device address is not assigned.
1532 *
1533 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetDeviceAddress(USBFS_Type const * base)1534 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetDeviceAddress(USBFS_Type const *base)
1535 {
1536 return _FLD2VAL(USBFS_USBDEV_CR0_DEVICE_ADDRESS, base->USBDEV.CR0);
1537 }
1538
1539
1540 /*******************************************************************************
1541 * Function Name: Cy_USBFS_Dev_Drv_SetDevContext
1542 ****************************************************************************//**
1543 *
1544 * Stores a pointer to the USB Device context in the driver context.
1545 *
1546 * \param base
1547 * The pointer to the USBFS instance
1548 *
1549 * \param devContext
1550 * The pointer to the USB Device context structure.
1551 *
1552 * \param context
1553 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1554 * allocated by the user. The structure is used during the USBFS Device
1555 * operation for internal configuration and data retention. The user must not
1556 * modify anything in this structure.
1557 *
1558 * \note
1559 * This function is intended for the USB Device middleware operation.
1560 *
1561 *******************************************************************************/
Cy_USBFS_Dev_Drv_SetDevContext(USBFS_Type const * base,void * devContext,cy_stc_usbfs_dev_drv_context_t * context)1562 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetDevContext(USBFS_Type const *base,
1563 void *devContext,
1564 cy_stc_usbfs_dev_drv_context_t *context)
1565 {
1566 /* Suppresses a compiler warning about unused variables. */
1567 (void) base;
1568
1569 context->devConext = devContext;
1570 }
1571
1572
1573 /*******************************************************************************
1574 * Function Name: Cy_USBFS_Dev_Drv_GetDevContext
1575 ****************************************************************************//**
1576 *
1577 * Returns a pointer to the USB Device context.
1578 *
1579 * \param base
1580 * The pointer to the USBFS instance.
1581 *
1582 * \param context
1583 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1584 * allocated by the user. The structure is used during USBFS Device
1585 * operation for internal configuration and data retention. The user must not
1586 * modify anything in this structure.
1587 *
1588 * \return
1589 * The pointer to the USB Device context.
1590 *
1591 * \note
1592 * This function is intended for the USB Device middleware operation.
1593 *
1594 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetDevContext(USBFS_Type const * base,cy_stc_usbfs_dev_drv_context_t * context)1595 __STATIC_INLINE void* Cy_USBFS_Dev_Drv_GetDevContext(USBFS_Type const *base,
1596 cy_stc_usbfs_dev_drv_context_t *context)
1597 {
1598 /* Suppresses a compiler warning about unused variables */
1599 (void) base;
1600
1601 return (context->devConext);
1602 }
1603 /** \} group_usbfs_dev_hal_functions_common */
1604
1605
1606 /**
1607 * \addtogroup group_usbfs_dev_drv_functions_interrupts
1608 * \{
1609 */
1610 /*******************************************************************************
1611 * Function Name: Cy_USBFS_Dev_Drv_RegisterSofCallback
1612 ****************************************************************************//**
1613 *
1614 * Registers a callback function to notify about an SOF event in
1615 * \ref Cy_USBFS_Dev_Drv_Interrupt. The SOF interrupt source is enabled after
1616 * registration. To remove callback function, pass NULL as the function pointer.
1617 * When the callback is removed, the interrupt source is disabled.
1618 *
1619 * \param base
1620 * The pointer to the USBFS instance.
1621 *
1622 * \param callback
1623 * The pointer to a callback function.
1624 *
1625 * \param context
1626 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1627 * allocated by the user. The structure is used during the USBFS Device
1628 * operation for internal configuration and data retention. The user must not
1629 * modify anything in this structure.
1630 *
1631 * \note
1632 * To remove the callback, pass NULL as the pointer to a callback function.
1633 *
1634 *******************************************************************************/
Cy_USBFS_Dev_Drv_RegisterSofCallback(USBFS_Type * base,cy_cb_usbfs_dev_drv_callback_t callback,cy_stc_usbfs_dev_drv_context_t * context)1635 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterSofCallback(USBFS_Type *base,
1636 cy_cb_usbfs_dev_drv_callback_t callback,
1637 cy_stc_usbfs_dev_drv_context_t *context)
1638 {
1639 uint32_t mask;
1640
1641 context->cbSof = callback;
1642
1643 /* Enables/Disables SOF interrupt */
1644 mask = Cy_USBFS_Dev_Drv_GetSieInterruptMask(base);
1645
1646 if (NULL != callback)
1647 {
1648 mask |= CY_USBFS_DEV_DRV_INTR_SIE_SOF;
1649 }
1650 else
1651 {
1652 mask &= ~CY_USBFS_DEV_DRV_INTR_SIE_SOF;
1653 }
1654
1655 Cy_USBFS_Dev_Drv_ClearSieInterrupt(base, CY_USBFS_DEV_DRV_INTR_SIE_SOF);
1656 Cy_USBFS_Dev_Drv_SetSieInterruptMask(base, mask);
1657 }
1658
1659
1660 /*******************************************************************************
1661 * Function Name: Cy_USBFS_Dev_Drv_RegisterLpmCallback
1662 ****************************************************************************//**
1663 *
1664 * Registers a callback function to notify about an LPM event in
1665 * \ref Cy_USBFS_Dev_Drv_Interrupt. The LPM interrupt source is enabled after
1666 * registration. To remove the callback function, pass NULL as the function pointer.
1667 * When the callback is removed, the interrupt source is disabled.
1668 *
1669 * \param base
1670 * The pointer to the USBFS instance.
1671 *
1672 * \param callback
1673 * The pointer to a callback function.
1674 *
1675 * \param context
1676 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1677 * allocated by the user. The structure is used during the USBFS Device
1678 * operation for internal configuration and data retention. The user must not
1679 * modify anything in this structure.
1680 *
1681 * \note
1682 * To remove the callback, pass NULL as the pointer to the callback function.
1683 *
1684 *******************************************************************************/
Cy_USBFS_Dev_Drv_RegisterLpmCallback(USBFS_Type * base,cy_cb_usbfs_dev_drv_callback_t callback,cy_stc_usbfs_dev_drv_context_t * context)1685 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterLpmCallback(USBFS_Type *base,
1686 cy_cb_usbfs_dev_drv_callback_t callback,
1687 cy_stc_usbfs_dev_drv_context_t *context)
1688
1689 {
1690 uint32_t mask;
1691
1692 context->cbLpm = callback;
1693
1694 /* Enables/Disables the LPM interrupt source */
1695 mask = Cy_USBFS_Dev_Drv_GetSieInterruptMask(base);
1696
1697 if (NULL != callback)
1698 {
1699 mask |= CY_USBFS_DEV_DRV_INTR_SIE_LPM;
1700 }
1701 else
1702 {
1703 mask &= ~CY_USBFS_DEV_DRV_INTR_SIE_LPM;
1704 }
1705
1706 Cy_USBFS_Dev_Drv_ClearSieInterrupt(base, CY_USBFS_DEV_DRV_INTR_SIE_LPM);
1707 Cy_USBFS_Dev_Drv_SetSieInterruptMask(base, mask);
1708 }
1709
1710
1711 /*******************************************************************************
1712 * Function Name: Cy_USBFS_Dev_Drv_RegisterEndpointCallback
1713 ****************************************************************************//**
1714 *
1715 * Registers a callback function to notify of an endpoint transfer completion
1716 * event in \ref Cy_USBFS_Dev_Drv_Interrupt.
1717 * * IN endpoint - The Host read data from the endpoint and new data can be
1718 * loaded.
1719 * * OUT endpoint - The Host has written data into the endpoint and the data is
1720 * ready to be read.
1721 * To remove the callback function, pass NULL as function pointer.
1722 *
1723 * \param base
1724 * The pointer to the USBFS instance.
1725 *
1726 * \param endpoint
1727 * The data endpoint number.
1728 *
1729 * \param callback
1730 * The pointer to a callback function.
1731 *
1732 * \param context
1733 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
1734 * allocated by the user. The structure is used during the USBFS Device
1735 * operation for internal configuration and data retention. The user must not
1736 * modify anything in this structure.
1737 *
1738 * \note
1739 * To remove the callback, pass NULL as the pointer to the callback function.
1740 *
1741 *******************************************************************************/
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)1742 __STATIC_INLINE void Cy_USBFS_Dev_Drv_RegisterEndpointCallback(USBFS_Type const *base,
1743 uint32_t endpoint,
1744 cy_cb_usbfs_dev_drv_ep_callback_t callback,
1745 cy_stc_usbfs_dev_drv_context_t *context)
1746
1747 {
1748 /* Suppresses a compiler warning about unused variables */
1749 (void) base;
1750
1751 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
1752
1753 endpoint = CY_USBFS_DEV_DRV_EP2PHY(endpoint);
1754 context->epPool[endpoint].epComplete = callback;
1755 }
1756
1757
1758 /*******************************************************************************
1759 * Function Name: Cy_USBFS_Dev_Drv_GetInterruptCauseHi
1760 ****************************************************************************//**
1761 *
1762 * Returns the mask of bits showing the source of the current triggered
1763 * interrupt. This is useful for modes of operation where an interrupt can
1764 * be generated by conditions in multiple interrupt source registers.
1765 *
1766 * \param base
1767 * The pointer to the USBFS instance.
1768 *
1769 * \return
1770 * The mask with the OR of the following conditions that have been triggered.
1771 * See \ref group_usbfs_dev_drv_macros_intr_cause for the set of constants.
1772 *
1773 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetInterruptCauseHi(USBFS_Type const * base)1774 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseHi(USBFS_Type const *base)
1775 {
1776 return USBFS_DEV_LPM_INTR_CAUSE_HI(base);
1777 }
1778
1779
1780 /*******************************************************************************
1781 * Function Name: Cy_USBFS_Dev_Drv_GetInterruptCauseMed
1782 ****************************************************************************//**
1783 *
1784 * Returns the mask of bits showing the source of the current triggered
1785 * interrupt. This is useful for modes of operation where an interrupt can
1786 * be generated by conditions in multiple interrupt source registers.
1787 *
1788 * \param base
1789 * The pointer to the USBFS instance.
1790 *
1791 * \return
1792 * The mask with the OR of the following conditions that have been triggered.
1793 * See \ref group_usbfs_dev_drv_macros_intr_cause for the set of constants.
1794 *
1795 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetInterruptCauseMed(USBFS_Type const * base)1796 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseMed(USBFS_Type const *base)
1797 {
1798 return USBFS_DEV_LPM_INTR_CAUSE_MED(base);
1799 }
1800
1801
1802 /*******************************************************************************
1803 * Function Name: Cy_USBFS_Dev_Drv_GetInterruptCauseLo
1804 ****************************************************************************//**
1805 *
1806 * Returns the mask of bits showing the source of the current triggered
1807 * interrupt. This is useful for modes of operation where an interrupt can
1808 * be generated by conditions in multiple interrupt source registers.
1809 *
1810 * \param base
1811 * The pointer to the USBFS instance.
1812 *
1813 * \return
1814 * The mask with the OR of the following conditions that have been triggered.
1815 * See \ref group_usbfs_dev_drv_macros_intr_cause for the set of constants.
1816 *
1817 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetInterruptCauseLo(USBFS_Type const * base)1818 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptCauseLo(USBFS_Type const *base)
1819 {
1820 return USBFS_DEV_LPM_INTR_CAUSE_LO(base);
1821 }
1822
1823
1824 /*******************************************************************************
1825 * Function Name: Cy_USBFS_Dev_Drv_SetInterruptsLevel
1826 ****************************************************************************//**
1827 *
1828 * Writes INTR_LVL_SEL register which contains groups for all interrupt sources.
1829 *
1830 * \param base
1831 * The pointer to the USBFS instance.
1832 *
1833 * \param intrLevel
1834 * INTR_LVL_SEL register value.
1835 *
1836 *******************************************************************************/
Cy_USBFS_Dev_Drv_SetInterruptsLevel(USBFS_Type * base,uint32_t intrLevel)1837 __STATIC_INLINE void Cy_USBFS_Dev_Drv_SetInterruptsLevel(USBFS_Type *base, uint32_t intrLevel)
1838 {
1839 USBFS_DEV_LPM_INTR_LVL_SEL(base) = intrLevel;
1840 }
1841
1842
1843 /*******************************************************************************
1844 * Function Name: Cy_USBFS_Dev_Drv_GetInterruptsLevel
1845 ****************************************************************************//**
1846 *
1847 * Returns the INTR_LVL_SEL register that contains groups for all interrupt sources.
1848 *
1849 * \param base
1850 * The pointer to the USBFS instance.
1851 *
1852 * \return
1853 * Returns the INTR_LVL_SEL register that contains groups for all interrupt sources.
1854 *
1855 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetInterruptsLevel(USBFS_Type const * base)1856 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetInterruptsLevel(USBFS_Type const *base)
1857 {
1858 return base->USBLPM.INTR_LVL_SEL;
1859 }
1860
1861
1862 /*******************************************************************************
1863 * Function Name: Cy_USBFS_Dev_Drv_DisableEp0Interrupt
1864 ****************************************************************************//**
1865 *
1866 * Enables the Control Endpoint 0 interrupt source.
1867 *
1868 * \param base
1869 * The pointer to the USBFS instance.
1870 *
1871 *******************************************************************************/
Cy_USBFS_Dev_Drv_DisableEp0Interrupt(USBFS_Type * base)1872 __STATIC_INLINE void Cy_USBFS_Dev_Drv_DisableEp0Interrupt(USBFS_Type *base)
1873 {
1874 uint32_t mask = (Cy_USBFS_Dev_Drv_GetSieInterruptMask(base) & ~CY_USBFS_DEV_DRV_INTR_SIE_EP0);
1875 Cy_USBFS_Dev_Drv_SetSieInterruptMask(base, mask);
1876 }
1877
1878
1879 /*******************************************************************************
1880 * Function Name: Cy_USBFS_Dev_Drv_EnableEp0Interrupt
1881 ****************************************************************************//**
1882 *
1883 * Enables the Control Endpoint 0 interrupt.
1884 *
1885 * \param base
1886 * The pointer to the USBFS instance source.
1887 *
1888 *******************************************************************************/
Cy_USBFS_Dev_Drv_EnableEp0Interrupt(USBFS_Type * base)1889 __STATIC_INLINE void Cy_USBFS_Dev_Drv_EnableEp0Interrupt(USBFS_Type *base)
1890 {
1891 uint32_t mask = (Cy_USBFS_Dev_Drv_GetSieInterruptMask(base) | CY_USBFS_DEV_DRV_INTR_SIE_EP0);
1892 Cy_USBFS_Dev_Drv_SetSieInterruptMask(base, mask);
1893 }
1894 /** \} group_usbfs_dev_drv_functions_interrupts */
1895
1896 /**
1897 * \addtogroup group_usbfs_dev_drv_functions_low_power
1898 * \{
1899 */
1900 /*******************************************************************************
1901 * Function Name: Cy_USBFS_Dev_Drv_CheckActivity
1902 ****************************************************************************//**
1903 *
1904 * Returns the activity status of the bus.
1905 * It clears the hardware status to provide an updated status on the next call of
1906 * this function. This function is useful to determine whether there is any USB bus
1907 * activity between function calls. A typical use case is to determine whether
1908 * the USB suspend conditions are met.
1909 *
1910 * \param base
1911 * The pointer to the USBFS instance.
1912 *
1913 * \return
1914 * The bus activity since the last call.
1915 *
1916 *******************************************************************************/
Cy_USBFS_Dev_Drv_CheckActivity(USBFS_Type * base)1917 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_CheckActivity(USBFS_Type *base)
1918 {
1919 uint32_t tmpReg = base->USBDEV.CR1;
1920
1921 /* Clear hardware status */
1922 base->USBDEV.CR1 &= (tmpReg & ~USBFS_USBDEV_CR1_BUS_ACTIVITY_Msk);
1923 (void) base->USBDEV.CR1;
1924
1925 return (0U != (tmpReg & USBFS_USBDEV_CR1_BUS_ACTIVITY_Msk));
1926 }
1927
1928
1929 /*******************************************************************************
1930 * Function Name: Cy_USBFS_Dev_Drv_Force
1931 ****************************************************************************//**
1932 *
1933 * Forces a USB J, K, or SE0 state on the USB lines.
1934 * A typical use case is to signal a Remote Wakeup condition on the USB bus.
1935 *
1936 * \param base
1937 * The pointer to the USBFS instance.
1938 *
1939 * \param state
1940 * The desired bus state.
1941 * See \ref cy_en_usbfs_dev_drv_force_bus_state_t for the set of constants.
1942 *
1943 *******************************************************************************/
Cy_USBFS_Dev_Drv_Force(USBFS_Type * base,cy_en_usbfs_dev_drv_force_bus_state_t state)1944 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Force(USBFS_Type *base, cy_en_usbfs_dev_drv_force_bus_state_t state)
1945 {
1946 base->USBDEV.USBIO_CR0 = (uint32_t) state;
1947 (void) base->USBDEV.USBIO_CR0;
1948 }
1949 /** \} group_usbfs_dev_drv_functions_low_power */
1950
1951
1952 /**
1953 * \addtogroup group_usbfs_dev_drv_functions_lpm
1954 * \{
1955 */
1956 /*******************************************************************************
1957 * Function Name: Cy_USBFS_Dev_Drv_Lpm_GetBeslValue
1958 ****************************************************************************//**
1959 *
1960 * Returns the Best Effort Service Latency (BESL) value sent by the host as
1961 * part of the LPM token transaction.
1962 *
1963 * \param base
1964 * The pointer to the USBFS instance.
1965 *
1966 * \return
1967 * BESL value (4-bits)
1968 *
1969 *******************************************************************************/
Cy_USBFS_Dev_Drv_Lpm_GetBeslValue(USBFS_Type const * base)1970 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_Lpm_GetBeslValue(USBFS_Type const *base)
1971 {
1972 return _FLD2VAL(USBFS_USBLPM_LPM_STAT_LPM_BESL, USBFS_DEV_LPM_LPM_STAT(base));
1973 }
1974
1975
1976 /*******************************************************************************
1977 * Function Name: Cy_USBFS_Dev_Drv_Lpm_RemoteWakeUpAllowed
1978 ****************************************************************************//**
1979 *
1980 * Returns the remote wakeup permission set by the Host as part of the
1981 * LPM token transaction.
1982 *
1983 * \param base
1984 * The pointer to the USBFS instance.
1985 *
1986 * \return
1987 * Remote wakeup permission: true - allowed, false - not allowed.
1988 *
1989 *******************************************************************************/
Cy_USBFS_Dev_Drv_Lpm_RemoteWakeUpAllowed(USBFS_Type const * base)1990 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_Lpm_RemoteWakeUpAllowed(USBFS_Type const *base)
1991 {
1992 return _FLD2BOOL(USBFS_USBLPM_LPM_STAT_LPM_REMOTEWAKE, USBFS_DEV_LPM_LPM_STAT(base));
1993 }
1994
1995
1996 /*******************************************************************************
1997 * Function Name: Cy_USBFS_Dev_Drv_Lpm_SetResponse
1998 ****************************************************************************//**
1999 *
2000 * Configures the response in the handshake packet that the device sends when
2001 * an LPM token packet is received.
2002 *
2003 * \param base
2004 * The pointer to the USBFS instance.
2005 *
2006 * \param response
2007 * The response to return for an LPM token packet.
2008 * See \ref cy_en_usbfs_dev_drv_lpm_req_t for the set of options.
2009 *
2010 *******************************************************************************/
Cy_USBFS_Dev_Drv_Lpm_SetResponse(USBFS_Type * base,cy_en_usbfs_dev_drv_lpm_req_t response)2011 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Lpm_SetResponse(USBFS_Type *base, cy_en_usbfs_dev_drv_lpm_req_t response)
2012 {
2013 USBFS_DEV_LPM_LPM_CTL(base) = _CLR_SET_FLD32U(USBFS_DEV_LPM_LPM_CTL(base),
2014 USBFS_USBLPM_LPM_CTL_LPM_RESP, ((uint32_t) response));
2015 }
2016
2017
2018 /*******************************************************************************
2019 * Function Name: Cy_USBFS_Dev_Drv_Lpm_GetResponse
2020 ****************************************************************************//**
2021 *
2022 * Returns the response value that the device sends as part of the handshake
2023 * packet when an LPM token packet is received.
2024 *
2025 * \param base
2026 * The pointer to the USBFS instance.
2027 *
2028 * \return
2029 * The response to return for an LPM token packet.
2030 * See \ref cy_en_usbfs_dev_drv_lpm_req_t for the set of options.
2031 *
2032 *******************************************************************************/
Cy_USBFS_Dev_Drv_Lpm_GetResponse(USBFS_Type const * base)2033 __STATIC_INLINE cy_en_usbfs_dev_drv_lpm_req_t Cy_USBFS_Dev_Drv_Lpm_GetResponse(USBFS_Type const *base)
2034 {
2035 uint32_t retValue = _FLD2VAL(USBFS_USBLPM_LPM_CTL_LPM_RESP, USBFS_DEV_LPM_LPM_CTL(base));
2036 return (cy_en_usbfs_dev_drv_lpm_req_t) retValue;
2037 }
2038 /** \} group_usbfs_dev_drv_functions_lpm */
2039
2040
2041 /**
2042 * \addtogroup group_usbfs_dev_hal_functions_endpoint_config
2043 * \{
2044 */
2045 /*******************************************************************************
2046 * Function Name: Cy_USBFS_Dev_Drv_AddEndpoint
2047 ****************************************************************************//**
2048 *
2049 * Configures a data endpoint for the following operation (allocates hardware
2050 * resources for data endpoint).
2051 *
2052 * \param base
2053 * The pointer to the USBFS instance.
2054 *
2055 * \param config
2056 * The pointer to data endpoint configuration \ref cy_stc_usb_dev_ep_config_t.
2057 *
2058 * \param context
2059 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
2060 * allocated by the user. The structure is used during the USBFS Device
2061 * operation for internal configuration and data retention. The user must not
2062 * modify anything in this structure.
2063 *
2064 * \return
2065 * The status code of the function execution \ref cy_en_usbfs_dev_drv_status_t.
2066 *
2067 *******************************************************************************/
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)2068 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_AddEndpoint(USBFS_Type *base,
2069 cy_stc_usb_dev_ep_config_t const *config,
2070 cy_stc_usbfs_dev_drv_context_t *context)
2071 {
2072 cy_en_usbfs_dev_drv_status_t retStatus = CY_USBFS_DEV_DRV_BAD_PARAM;
2073
2074 uint32_t endpoint = CY_USBFS_DEV_DRV_EPADDR2EP(config->endpointAddr);
2075
2076 /* Checks if the endpoint is supported by the driver */
2077 if (CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint))
2078 {
2079 retStatus = context->addEndpoint(base, config, context);
2080 }
2081
2082 return retStatus;
2083 }
2084
2085
2086 /*******************************************************************************
2087 * Function Name: Cy_USBFS_Dev_Drv_OverwriteMemcpy
2088 ****************************************************************************//**
2089 *
2090 * Overwrites the memory copy (memcpy) function used to copy data with the user-
2091 * implemented:
2092 * * \ref Cy_USBFS_Dev_Drv_ReadOutEndpoint copies data from from the internal
2093 * buffer to the application buffer for OUT endpoint.
2094 * * \ref Cy_USBFS_Dev_Drv_LoadInEndpoint copies data from the application buffer
2095 * for IN endpoint to the the internal buffer.
2096 * Only applicable when endpoint management mode is
2097 * \ref CY_USBFS_DEV_DRV_EP_MANAGEMENT_DMA_AUTO.
2098 *
2099 * \param base
2100 * The pointer to the USBFS instance.
2101 *
2102 * \param endpoint
2103 * The data endpoint number.
2104 *
2105 * \param memcpyFunc
2106 * The pointer to the function that copies data.
2107 *
2108 * \param context
2109 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
2110 * allocated by the user. The structure is used during the USBFS Device
2111 * operation for internal configuration and data retention. The user must not
2112 * modify anything in this structure.
2113 *
2114 *******************************************************************************/
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)2115 __STATIC_INLINE void Cy_USBFS_Dev_Drv_OverwriteMemcpy(USBFS_Type const *base,
2116 uint32_t endpoint,
2117 cy_fn_usbfs_dev_drv_memcpy_ptr_t memcpyFunc,
2118 cy_stc_usbfs_dev_drv_context_t *context)
2119 {
2120 /* Suppress a compiler warning about unused variables */
2121 (void) base;
2122
2123 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
2124
2125 endpoint = CY_USBFS_DEV_DRV_EP2PHY(endpoint);
2126 context->epPool[endpoint].copyData = memcpyFunc;
2127 }
2128 /** \} group_usbfs_dev_hal_functions_endpoint_config */
2129
2130
2131 /**
2132 * \addtogroup group_usbfs_dev_hal_functions_data_xfer
2133 * \{
2134 */
2135 /*******************************************************************************
2136 * Function Name: Cy_USBFS_Dev_Drv_GetEndpointState
2137 ****************************************************************************//**
2138 *
2139 * Returns the state of the endpoint.
2140 *
2141 * \param base
2142 * The pointer to the USBFS instance.
2143 *
2144 * \param endpoint
2145 * The data endpoint number.
2146 *
2147 * \param context
2148 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
2149 * allocated by the user. The structure is used during the USBFS Device
2150 * operation for internal configuration and data retention. The user must not
2151 * modify anything in this structure.
2152 *
2153 * \return
2154 * Data endpoint state \ref cy_en_usb_dev_ep_state_t.
2155 *
2156 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetEndpointState(USBFS_Type const * base,uint32_t endpoint,cy_stc_usbfs_dev_drv_context_t const * context)2157 __STATIC_INLINE cy_en_usb_dev_ep_state_t Cy_USBFS_Dev_Drv_GetEndpointState(
2158 USBFS_Type const *base,
2159 uint32_t endpoint,
2160 cy_stc_usbfs_dev_drv_context_t const *context)
2161
2162 {
2163 cy_en_usb_dev_ep_state_t retState = CY_USB_DEV_EP_INVALID;
2164
2165 (void)base; /* Suppress warning */
2166
2167 if (CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint))
2168 {
2169 retState = context->epPool[CY_USBFS_DEV_DRV_EP2PHY(endpoint)].state;
2170 }
2171
2172 return retState;
2173 }
2174
2175
2176 /*******************************************************************************
2177 * Function Name: Cy_USBFS_Dev_Drv_LoadInEndpoint
2178 ****************************************************************************//**
2179 *
2180 * Loads data into the IN endpoint buffer. After data loads, the
2181 * endpoint is ready to be read by the host.
2182 *
2183 * \param base
2184 * The pointer to the USBFS instance.
2185 *
2186 * \param endpoint
2187 * The IN data endpoint number.
2188 *
2189 * \param buffer
2190 * The pointer to the buffer containing data bytes to load.
2191 *
2192 * \param size
2193 * The number of bytes to load into the endpoint.
2194 * This value must be less than or equal to endpoint maximum packet size.
2195 *
2196 * \param context
2197 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
2198 * allocated by the user. The structure is used during the USBFS Device
2199 * operation for internal configuration and data retention. The user must not
2200 * modify anything in this structure.
2201 *
2202 * \return
2203 * The status code of the function execution \ref cy_en_usbfs_dev_drv_status_t.
2204 *
2205 *******************************************************************************/
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)2206 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_LoadInEndpoint(
2207 USBFS_Type *base,
2208 uint32_t endpoint,
2209 uint8_t const *buffer,
2210 uint32_t size,
2211 cy_stc_usbfs_dev_drv_context_t *context)
2212 {
2213 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
2214 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_DIR_IN(context->epPool[CY_USBFS_DEV_DRV_EP2PHY(endpoint)].address));
2215
2216 return context->loadInEndpoint(base, CY_USBFS_DEV_DRV_EP2PHY(endpoint), buffer, size, context);
2217 }
2218
2219
2220 /*******************************************************************************
2221 * Function Name: Cy_USBFS_Dev_Drv_ReadOutEndpoint
2222 ****************************************************************************//**
2223 *
2224 * Reads data from the OUT endpoint buffer.
2225 * Before executing a next read, the \ref Cy_USBFS_Dev_Drv_EnableOutEndpoint must be
2226 * called to allow the Host to write data into the endpoint.
2227 *
2228 * \param base
2229 * The pointer to the USBFS instance.
2230 *
2231 * \param endpoint
2232 * The OUT data endpoint number.
2233 *
2234 * \param buffer
2235 * The pointer to the buffer that stores read data.
2236 *
2237 * \param size
2238 * The number of bytes to read from the endpoint.
2239 * This value must be less than or equal to the endpoint maximum packet size.
2240 *
2241 * \param actSize
2242 * The number of actually read bytes.
2243 *
2244 * \param context
2245 * The pointer to the context structure \ref cy_stc_usbfs_dev_drv_context_t
2246 * allocated by the user. The structure is used during the USBFS Device
2247 * operation for internal configuration and data retention. The user must not
2248 * modify anything in this structure.
2249 *
2250 * \return
2251 * The status code of the function execution \ref cy_en_usbfs_dev_drv_status_t.
2252 *
2253 *******************************************************************************/
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)2254 __STATIC_INLINE cy_en_usbfs_dev_drv_status_t Cy_USBFS_Dev_Drv_ReadOutEndpoint(
2255 USBFS_Type *base,
2256 uint32_t endpoint,
2257 uint8_t *buffer,
2258 uint32_t size,
2259 uint32_t *actSize,
2260 cy_stc_usbfs_dev_drv_context_t *context)
2261 {
2262 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
2263 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_DIR_OUT(context->epPool[CY_USBFS_DEV_DRV_EP2PHY(endpoint)].address));
2264
2265 return context->readOutEndpoint(base, CY_USBFS_DEV_DRV_EP2PHY(endpoint), buffer, size, actSize, context);
2266 }
2267
2268
2269 /*******************************************************************************
2270 * Function Name: Cy_USBFS_Dev_Drv_GetEndpointAckState
2271 ****************************************************************************//**
2272 *
2273 * Returns whether the transaction completed with ACK for a certain endpoint.
2274 *
2275 * \param base
2276 * The pointer to the USBFS instance.
2277 *
2278 * \param endpoint
2279 * The data endpoint number.
2280 *
2281 * \return
2282 * ACK state: true - transaction completed with ACK, false - otherwise.
2283 *
2284 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetEndpointAckState(USBFS_Type const * base,uint32_t endpoint)2285 __STATIC_INLINE bool Cy_USBFS_Dev_Drv_GetEndpointAckState(USBFS_Type const *base, uint32_t endpoint)
2286 {
2287 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
2288
2289 endpoint = CY_USBFS_DEV_DRV_EP2PHY(endpoint);
2290 return _FLD2BOOL(USBFS_USBDEV_SIE_EP1_CR0_ACKED_TXN, USBFS_DEV_SIE_EP_CR0(base, endpoint));
2291 }
2292
2293
2294 /*******************************************************************************
2295 * Function Name: Cy_USBFS_Dev_Drv_GetEndpointCount
2296 ****************************************************************************//**
2297 *
2298 * Returns the number of data bytes in the transaction for a certain endpoint.
2299 * Before calling this function, ensure the Host has written data into the
2300 * endpoint. The returned value is updated after the Host access to the
2301 * endpoint but remains unchanged after data has been read from the endpoint
2302 * buffer.
2303 * A typical use case is to read the number of bytes that the Host wrote into the
2304 * OUT endpoint.
2305 *
2306 * \param base
2307 * The pointer to the USBFS instance.
2308 *
2309 * \param endpoint
2310 * The data endpoint number.
2311 *
2312 * \return
2313 * The number of data bytes in the transaction.
2314 *
2315 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetEndpointCount(USBFS_Type const * base,uint32_t endpoint)2316 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetEndpointCount(USBFS_Type const *base, uint32_t endpoint)
2317 {
2318 CY_ASSERT_L1(CY_USBFS_DEV_DRV_IS_EP_VALID(endpoint));
2319
2320 return Cy_USBFS_Dev_Drv_GetSieEpCount(base, CY_USBFS_DEV_DRV_EP2PHY(endpoint));
2321 }
2322 /** \} group_usbfs_dev_hal_functions_data_xfer */
2323
2324
2325 /**
2326 * \addtogroup group_usbfs_dev_hal_functions_ep0_service
2327 * \{
2328 */
2329 /*******************************************************************************
2330 * Function Name: Cy_USBFS_Dev_Drv_Ep0Stall
2331 ****************************************************************************//**
2332 *
2333 * Stalls endpoint 0.
2334 *
2335 * \param base
2336 * The pointer to the USBFS instance.
2337 *
2338 *******************************************************************************/
Cy_USBFS_Dev_Drv_Ep0Stall(USBFS_Type * base)2339 __STATIC_INLINE void Cy_USBFS_Dev_Drv_Ep0Stall(USBFS_Type *base)
2340 {
2341 /* Updates the CR registers to STALL a request (CNT register does not care) */
2342 Cy_USBFS_Dev_Drv_WriteEp0Mode(base, CY_USBFS_DEV_DRV_EP_CR_STALL_INOUT);
2343 }
2344
2345
2346 /*******************************************************************************
2347 * Function Name: Cy_USBFS_Dev_Drv_GetEp0MaxPacket
2348 ****************************************************************************//**
2349 *
2350 * Returns the endpoint 0 maximum packet size that can be for read or write from
2351 * the endpoint 0 buffer.
2352 *
2353 * \param base
2354 * The pointer to the USBFS instance.
2355 *
2356 * \return
2357 * The endpoint 0 maximum packet size (endpoint 0 has a dedicated hardware buffer).
2358 *
2359 *******************************************************************************/
Cy_USBFS_Dev_Drv_GetEp0MaxPacket(USBFS_Type const * base)2360 __STATIC_INLINE uint32_t Cy_USBFS_Dev_Drv_GetEp0MaxPacket(USBFS_Type const *base)
2361 {
2362 /* Suppresses a compiler warning about unused variables */
2363 (void) base;
2364
2365 return (CY_USBFS_DEV_DRV_EP0_BUFFER_SIZE);
2366 }
2367
2368
2369 /** \} group_usbfs_dev_hal_functions_ep0_service */
2370
2371 #if defined(__cplusplus)
2372 }
2373 #endif
2374
2375 #endif /* CY_IP_MXUSBFS */
2376
2377 #endif /* (CY_USBFS_DEV_DRV_H) */
2378
2379
2380 /* [] END OF FILE */
2381