1 /*!
2     \file    usbh_pipe.h
3     \brief   USB host mode pipe header file
4 
5     \version 2020-08-04, V1.1.0, firmware for GD32VF103
6 */
7 
8 /*
9     Copyright (c) 2020, GigaDevice Semiconductor Inc.
10 
11     Redistribution and use in source and binary forms, with or without modification,
12 are permitted provided that the following conditions are met:
13 
14     1. Redistributions of source code must retain the above copyright notice, this
15        list of conditions and the following disclaimer.
16     2. Redistributions in binary form must reproduce the above copyright notice,
17        this list of conditions and the following disclaimer in the documentation
18        and/or other materials provided with the distribution.
19     3. Neither the name of the copyright holder nor the names of its contributors
20        may be used to endorse or promote products derived from this software without
21        specific prior written permission.
22 
23     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 OF SUCH DAMAGE.
33 */
34 
35 #ifndef __USBH_PIPE_H
36 #define __USBH_PIPE_H
37 
38 #include "usbh_core.h"
39 
40 #define HC_MAX                  8U
41 
42 #define HC_OK                   0x0000U
43 #define HC_USED                 0x8000U
44 #define HC_ERROR                0xFFFFU
45 #define HC_USED_MASK            0x7FFFU
46 
47 /*!
48     \brief      set toggle for a pipe
49     \param[in]  pudev: pointer to USB core instance
50     \param[in]  pp_num: pipe number
51     \param[in]  toggle: toggle (0/1)
52     \param[out] none
53     \retval     operation status
54 */
usbh_pipe_toggle_set(usb_core_driver * pudev,uint8_t pp_num,uint8_t toggle)55 static inline void usbh_pipe_toggle_set (usb_core_driver *pudev, uint8_t pp_num, uint8_t toggle)
56 {
57     if (pudev->host.pipe[pp_num].ep.dir) {
58         pudev->host.pipe[pp_num].data_toggle_in = toggle;
59     } else {
60         pudev->host.pipe[pp_num].data_toggle_out = toggle;
61     }
62 }
63 
64 /*!
65     \brief      get toggle flag of pipe
66     \param[in]  pudev: pointer to USB core instance
67     \param[in]  pp_num: pipe number
68     \param[out] none
69     \retval     operation status
70 */
usbh_pipe_toggle_get(usb_core_driver * pudev,uint8_t pp_num)71 static inline uint8_t usbh_pipe_toggle_get (usb_core_driver *pudev, uint8_t pp_num)
72 {
73     if (pudev->host.pipe[pp_num].ep.dir) {
74         return pudev->host.pipe[pp_num].data_toggle_in;
75     } else {
76         return pudev->host.pipe[pp_num].data_toggle_out;
77     }
78 }
79 
80 /* function declarations */
81 /* create a pipe */
82 uint8_t usbh_pipe_create (usb_core_driver *pudev,
83                           usb_dev_prop *udev,
84                           uint8_t  pp_num,
85                           uint8_t  ep_type,
86                           uint16_t ep_mpl);
87 /* modify a pipe */
88 uint8_t usbh_pipe_update (usb_core_driver *pudev,
89                           uint8_t  pp_num,
90                           uint8_t  dev_addr,
91                           uint32_t dev_speed,
92                           uint16_t ep_mpl);
93 /* allocate a new pipe */
94 uint8_t usbh_pipe_allocate (usb_core_driver *pudev, uint8_t ep_addr);
95 /* free a pipe */
96 uint8_t usbh_pipe_free (usb_core_driver *pudev, uint8_t pp_num);
97 /* delete all USB host pipe */
98 uint8_t usbh_pipe_delete (usb_core_driver *pudev);
99 
100 #endif /* __USBH_PIPE_H */
101