Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
TARGET_NUCLEO_F070RB/stm32f0xx_hal_pcd.h@122:f9eeca106725, 2016-07-07 (annotated)
- Committer:
- Kojto
- Date:
- Thu Jul 07 14:34:11 2016 +0100
- Revision:
- 122:f9eeca106725
- Parent:
- 108:34e6b704fe68
Release 122 of the mbed library
Changes:
- new targets - Nucleo L432KC, Beetle, Nucleo F446ZE, Nucleo L011K4
- Thread safety addition - mbed API should contain a statement about thread safety
- critical section API addition
- CAS API (core_util_atomic_incr/decr)
- DEVICE_ are generated from targets.json file, device.h deprecated
- Callback replaces FunctionPointer to provide std like interface
- mbed HAL API docs improvements
- toolchain - prexif attributes with MBED_
- add new attributes - packed, weak, forcedinline, align
- target.json - contains targets definitions
- ST - L1XX - Cube update to 1.5
- SPI clock selection fix (clock from APB domain)
- F7 - Cube update v1.4.0
- L0 - baudrate init fix
- L1 - Cube update v1.5
- F3 - baudrate init fix, 3 targets CAN support
- F4 - Cube update v1.12.0, 3 targets CAN support
- L4XX - Cube update v1.5.1
- F0 - update Cube to v1.5.0
- L4 - 2 targets (L476RG/VG) CAN support
- NXP - pwm clock fix for KSDK2 MCU
- LPC2368 - remove ARM toolchain support - due to regression
- KSDK2 - fix SPI , I2C address and repeat start
- Silabs - some fixes backported from mbed 3
- Renesas - RZ_A1H - SystemCoreClockUpdate addition
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| Kojto | 93:e188a91d3eaa | 1 | /** | 
| Kojto | 93:e188a91d3eaa | 2 | ****************************************************************************** | 
| Kojto | 93:e188a91d3eaa | 3 | * @file stm32f0xx_hal_pcd.h | 
| Kojto | 93:e188a91d3eaa | 4 | * @author MCD Application Team | 
| Kojto | 122:f9eeca106725 | 5 | * @version V1.4.0 | 
| Kojto | 122:f9eeca106725 | 6 | * @date 27-May-2016 | 
| Kojto | 93:e188a91d3eaa | 7 | * @brief Header file of PCD HAL module. | 
| Kojto | 93:e188a91d3eaa | 8 | ****************************************************************************** | 
| Kojto | 93:e188a91d3eaa | 9 | * @attention | 
| Kojto | 93:e188a91d3eaa | 10 | * | 
| Kojto | 122:f9eeca106725 | 11 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> | 
| Kojto | 93:e188a91d3eaa | 12 | * | 
| Kojto | 93:e188a91d3eaa | 13 | * Redistribution and use in source and binary forms, with or without modification, | 
| Kojto | 93:e188a91d3eaa | 14 | * are permitted provided that the following conditions are met: | 
| Kojto | 93:e188a91d3eaa | 15 | * 1. Redistributions of source code must retain the above copyright notice, | 
| Kojto | 93:e188a91d3eaa | 16 | * this list of conditions and the following disclaimer. | 
| Kojto | 93:e188a91d3eaa | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, | 
| Kojto | 93:e188a91d3eaa | 18 | * this list of conditions and the following disclaimer in the documentation | 
| Kojto | 93:e188a91d3eaa | 19 | * and/or other materials provided with the distribution. | 
| Kojto | 93:e188a91d3eaa | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors | 
| Kojto | 93:e188a91d3eaa | 21 | * may be used to endorse or promote products derived from this software | 
| Kojto | 93:e188a91d3eaa | 22 | * without specific prior written permission. | 
| Kojto | 93:e188a91d3eaa | 23 | * | 
| Kojto | 93:e188a91d3eaa | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
| Kojto | 93:e188a91d3eaa | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| Kojto | 93:e188a91d3eaa | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
| Kojto | 93:e188a91d3eaa | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
| Kojto | 93:e188a91d3eaa | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
| Kojto | 93:e188a91d3eaa | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
| Kojto | 93:e188a91d3eaa | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
| Kojto | 93:e188a91d3eaa | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
| Kojto | 93:e188a91d3eaa | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| Kojto | 93:e188a91d3eaa | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| Kojto | 93:e188a91d3eaa | 34 | * | 
| Kojto | 93:e188a91d3eaa | 35 | ****************************************************************************** | 
| Kojto | 93:e188a91d3eaa | 36 | */ | 
| Kojto | 93:e188a91d3eaa | 37 | |
| Kojto | 93:e188a91d3eaa | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ | 
| Kojto | 93:e188a91d3eaa | 39 | #ifndef __STM32F0xx_HAL_PCD_H | 
| Kojto | 93:e188a91d3eaa | 40 | #define __STM32F0xx_HAL_PCD_H | 
| Kojto | 93:e188a91d3eaa | 41 | |
| Kojto | 93:e188a91d3eaa | 42 | #ifdef __cplusplus | 
| Kojto | 93:e188a91d3eaa | 43 | extern "C" { | 
| Kojto | 93:e188a91d3eaa | 44 | #endif | 
| Kojto | 93:e188a91d3eaa | 45 | |
| Kojto | 93:e188a91d3eaa | 46 | #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)|| defined(STM32F070x6) | 
| Kojto | 93:e188a91d3eaa | 47 | |
| Kojto | 93:e188a91d3eaa | 48 | /* Includes ------------------------------------------------------------------*/ | 
| Kojto | 93:e188a91d3eaa | 49 | #include "stm32f0xx_hal_def.h" | 
| Kojto | 93:e188a91d3eaa | 50 | |
| Kojto | 93:e188a91d3eaa | 51 | /** @addtogroup STM32F0xx_HAL_Driver | 
| Kojto | 93:e188a91d3eaa | 52 | * @{ | 
| Kojto | 93:e188a91d3eaa | 53 | */ | 
| Kojto | 93:e188a91d3eaa | 54 | |
| Kojto | 93:e188a91d3eaa | 55 | /** @addtogroup PCD | 
| Kojto | 93:e188a91d3eaa | 56 | * @{ | 
| Kojto | 93:e188a91d3eaa | 57 | */ | 
| Kojto | 93:e188a91d3eaa | 58 | |
| Kojto | 93:e188a91d3eaa | 59 | /* Exported types ------------------------------------------------------------*/ | 
| Kojto | 93:e188a91d3eaa | 60 | /** @defgroup PCD_Exported_Types PCD Exported Types | 
| Kojto | 93:e188a91d3eaa | 61 | * @{ | 
| Kojto | 93:e188a91d3eaa | 62 | */ | 
| Kojto | 93:e188a91d3eaa | 63 | |
| Kojto | 93:e188a91d3eaa | 64 | /** | 
| Kojto | 108:34e6b704fe68 | 65 | * @brief PCD State structure definition | 
| Kojto | 93:e188a91d3eaa | 66 | */ | 
| Kojto | 93:e188a91d3eaa | 67 | typedef enum | 
| Kojto | 93:e188a91d3eaa | 68 | { | 
| Kojto | 108:34e6b704fe68 | 69 | HAL_PCD_STATE_RESET = 0x00, | 
| Kojto | 108:34e6b704fe68 | 70 | HAL_PCD_STATE_READY = 0x01, | 
| Kojto | 108:34e6b704fe68 | 71 | HAL_PCD_STATE_ERROR = 0x02, | 
| Kojto | 108:34e6b704fe68 | 72 | HAL_PCD_STATE_BUSY = 0x03, | 
| Kojto | 108:34e6b704fe68 | 73 | HAL_PCD_STATE_TIMEOUT = 0x04 | 
| Kojto | 93:e188a91d3eaa | 74 | } PCD_StateTypeDef; | 
| Kojto | 93:e188a91d3eaa | 75 | |
| Kojto | 108:34e6b704fe68 | 76 | /** | 
| Kojto | 108:34e6b704fe68 | 77 | * @brief PCD double buffered endpoint direction | 
| Kojto | 108:34e6b704fe68 | 78 | */ | 
| Kojto | 93:e188a91d3eaa | 79 | typedef enum | 
| Kojto | 93:e188a91d3eaa | 80 | { | 
| Kojto | 93:e188a91d3eaa | 81 | PCD_EP_DBUF_OUT, | 
| Kojto | 93:e188a91d3eaa | 82 | PCD_EP_DBUF_IN, | 
| Kojto | 93:e188a91d3eaa | 83 | PCD_EP_DBUF_ERR, | 
| Kojto | 93:e188a91d3eaa | 84 | }PCD_EP_DBUF_DIR; | 
| Kojto | 93:e188a91d3eaa | 85 | |
| Kojto | 108:34e6b704fe68 | 86 | /** | 
| Kojto | 108:34e6b704fe68 | 87 | * @brief PCD endpoint buffer number | 
| Kojto | 108:34e6b704fe68 | 88 | */ | 
| Kojto | 93:e188a91d3eaa | 89 | typedef enum | 
| Kojto | 93:e188a91d3eaa | 90 | { | 
| Kojto | 93:e188a91d3eaa | 91 | PCD_EP_NOBUF, | 
| Kojto | 93:e188a91d3eaa | 92 | PCD_EP_BUF0, | 
| Kojto | 93:e188a91d3eaa | 93 | PCD_EP_BUF1 | 
| Kojto | 93:e188a91d3eaa | 94 | }PCD_EP_BUF_NUM; | 
| Kojto | 93:e188a91d3eaa | 95 | |
| Kojto | 93:e188a91d3eaa | 96 | /** | 
| Kojto | 93:e188a91d3eaa | 97 | * @brief PCD Initialization Structure definition | 
| Kojto | 93:e188a91d3eaa | 98 | */ | 
| Kojto | 93:e188a91d3eaa | 99 | typedef struct | 
| Kojto | 93:e188a91d3eaa | 100 | { | 
| Kojto | 108:34e6b704fe68 | 101 | uint32_t dev_endpoints; /*!< Device Endpoints number. | 
| Kojto | 108:34e6b704fe68 | 102 | This parameter depends on the used USB core. | 
| Kojto | 108:34e6b704fe68 | 103 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ | 
| Kojto | 108:34e6b704fe68 | 104 | |
| Kojto | 108:34e6b704fe68 | 105 | uint32_t speed; /*!< USB Core speed. | 
| Kojto | 108:34e6b704fe68 | 106 | This parameter can be any value of @ref PCD_Core_Speed */ | 
| Kojto | 108:34e6b704fe68 | 107 | |
| Kojto | 108:34e6b704fe68 | 108 | uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. | 
| Kojto | 108:34e6b704fe68 | 109 | This parameter can be any value of @ref PCD_EP0_MPS */ | 
| Kojto | 108:34e6b704fe68 | 110 | |
| Kojto | 108:34e6b704fe68 | 111 | uint32_t phy_itface; /*!< Select the used PHY interface. | 
| Kojto | 108:34e6b704fe68 | 112 | This parameter can be any value of @ref PCD_Core_PHY */ | 
| Kojto | 108:34e6b704fe68 | 113 | |
| Kojto | 108:34e6b704fe68 | 114 | uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. | 
| Kojto | 108:34e6b704fe68 | 115 | This parameter can be set to ENABLE or DISABLE */ | 
| Kojto | 108:34e6b704fe68 | 116 | |
| Kojto | 108:34e6b704fe68 | 117 | uint32_t low_power_enable; /*!< Enable or disable Low Power mode | 
| Kojto | 108:34e6b704fe68 | 118 | This parameter can be set to ENABLE or DISABLE */ | 
| Kojto | 108:34e6b704fe68 | 119 | |
| Kojto | 108:34e6b704fe68 | 120 | uint32_t lpm_enable; /*!< Enable or disable the Link Power Management . | 
| Kojto | 108:34e6b704fe68 | 121 | This parameter can be set to ENABLE or DISABLE */ | 
| Kojto | 108:34e6b704fe68 | 122 | |
| Kojto | 108:34e6b704fe68 | 123 | uint32_t battery_charging_enable; /*!< Enable or disable Battery charging. | 
| Kojto | 108:34e6b704fe68 | 124 | This parameter can be set to ENABLE or DISABLE */ | 
| Kojto | 108:34e6b704fe68 | 125 | |
| Kojto | 93:e188a91d3eaa | 126 | }PCD_InitTypeDef; | 
| Kojto | 93:e188a91d3eaa | 127 | |
| Kojto | 93:e188a91d3eaa | 128 | typedef struct | 
| Kojto | 93:e188a91d3eaa | 129 | { | 
| Kojto | 93:e188a91d3eaa | 130 | uint8_t num; /*!< Endpoint number | 
| Kojto | 93:e188a91d3eaa | 131 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ | 
| Kojto | 93:e188a91d3eaa | 132 | |
| Kojto | 93:e188a91d3eaa | 133 | uint8_t is_in; /*!< Endpoint direction | 
| Kojto | 93:e188a91d3eaa | 134 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | 
| Kojto | 93:e188a91d3eaa | 135 | |
| Kojto | 93:e188a91d3eaa | 136 | uint8_t is_stall; /*!< Endpoint stall condition | 
| Kojto | 93:e188a91d3eaa | 137 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | 
| Kojto | 93:e188a91d3eaa | 138 | |
| Kojto | 93:e188a91d3eaa | 139 | uint8_t type; /*!< Endpoint type | 
| Kojto | 93:e188a91d3eaa | 140 | This parameter can be any value of @ref PCD_EP_Type */ | 
| Kojto | 93:e188a91d3eaa | 141 | |
| Kojto | 93:e188a91d3eaa | 142 | uint16_t pmaadress; /*!< PMA Address | 
| Kojto | 93:e188a91d3eaa | 143 | This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ | 
| Kojto | 108:34e6b704fe68 | 144 | |
| Kojto | 93:e188a91d3eaa | 145 | uint16_t pmaaddr0; /*!< PMA Address0 | 
| Kojto | 93:e188a91d3eaa | 146 | This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ | 
| Kojto | 108:34e6b704fe68 | 147 | |
| Kojto | 93:e188a91d3eaa | 148 | uint16_t pmaaddr1; /*!< PMA Address1 | 
| Kojto | 93:e188a91d3eaa | 149 | This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ | 
| Kojto | 108:34e6b704fe68 | 150 | |
| Kojto | 93:e188a91d3eaa | 151 | uint8_t doublebuffer; /*!< Double buffer enable | 
| Kojto | 93:e188a91d3eaa | 152 | This parameter can be 0 or 1 */ | 
| Kojto | 93:e188a91d3eaa | 153 | |
| Kojto | 93:e188a91d3eaa | 154 | uint32_t maxpacket; /*!< Endpoint Max packet size | 
| Kojto | 93:e188a91d3eaa | 155 | This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */ | 
| Kojto | 93:e188a91d3eaa | 156 | |
| Kojto | 93:e188a91d3eaa | 157 | uint8_t *xfer_buff; /*!< Pointer to transfer buffer */ | 
| Kojto | 93:e188a91d3eaa | 158 | |
| Kojto | 93:e188a91d3eaa | 159 | uint32_t xfer_len; /*!< Current transfer length */ | 
| Kojto | 93:e188a91d3eaa | 160 | |
| Kojto | 93:e188a91d3eaa | 161 | uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */ | 
| Kojto | 93:e188a91d3eaa | 162 | |
| Kojto | 93:e188a91d3eaa | 163 | }PCD_EPTypeDef; | 
| Kojto | 93:e188a91d3eaa | 164 | |
| Kojto | 93:e188a91d3eaa | 165 | typedef USB_TypeDef PCD_TypeDef; | 
| Kojto | 93:e188a91d3eaa | 166 | |
| Kojto | 93:e188a91d3eaa | 167 | /** | 
| Kojto | 93:e188a91d3eaa | 168 | * @brief PCD Handle Structure definition | 
| Kojto | 93:e188a91d3eaa | 169 | */ | 
| Kojto | 93:e188a91d3eaa | 170 | typedef struct | 
| Kojto | 93:e188a91d3eaa | 171 | { | 
| Kojto | 108:34e6b704fe68 | 172 | PCD_TypeDef *Instance; /*!< Register base address */ | 
| Kojto | 108:34e6b704fe68 | 173 | PCD_InitTypeDef Init; /*!< PCD required parameters */ | 
| Kojto | 108:34e6b704fe68 | 174 | __IO uint8_t USB_Address; /*!< USB Address */ | 
| Kojto | 108:34e6b704fe68 | 175 | PCD_EPTypeDef IN_ep[8]; /*!< IN endpoint parameters */ | 
| Kojto | 108:34e6b704fe68 | 176 | PCD_EPTypeDef OUT_ep[8]; /*!< OUT endpoint parameters */ | 
| Kojto | 108:34e6b704fe68 | 177 | HAL_LockTypeDef Lock; /*!< PCD peripheral status */ | 
| Kojto | 108:34e6b704fe68 | 178 | __IO PCD_StateTypeDef State; /*!< PCD communication state */ | 
| Kojto | 108:34e6b704fe68 | 179 | uint32_t Setup[12]; /*!< Setup packet buffer */ | 
| Kojto | 108:34e6b704fe68 | 180 | void *pData; /*!< Pointer to upper stack Handler */ | 
| Kojto | 93:e188a91d3eaa | 181 | |
| Kojto | 93:e188a91d3eaa | 182 | } PCD_HandleTypeDef; | 
| Kojto | 93:e188a91d3eaa | 183 | |
| Kojto | 93:e188a91d3eaa | 184 | /** | 
| Kojto | 93:e188a91d3eaa | 185 | * @} | 
| Kojto | 93:e188a91d3eaa | 186 | */ | 
| Kojto | 93:e188a91d3eaa | 187 | |
| Kojto | 108:34e6b704fe68 | 188 | /* Include PCD HAL Extension module */ | 
| Kojto | 108:34e6b704fe68 | 189 | #include "stm32f0xx_hal_pcd_ex.h" | 
| Kojto | 108:34e6b704fe68 | 190 | |
| Kojto | 93:e188a91d3eaa | 191 | /* Exported constants --------------------------------------------------------*/ | 
| Kojto | 93:e188a91d3eaa | 192 | /** @defgroup PCD_Exported_Constants PCD Exported Constants | 
| Kojto | 93:e188a91d3eaa | 193 | * @{ | 
| Kojto | 93:e188a91d3eaa | 194 | */ | 
| Kojto | 93:e188a91d3eaa | 195 | |
| Kojto | 93:e188a91d3eaa | 196 | /** @defgroup PCD_Core_Speed PCD Core Speed | 
| Kojto | 93:e188a91d3eaa | 197 | * @{ | 
| Kojto | 93:e188a91d3eaa | 198 | */ | 
| Kojto | 93:e188a91d3eaa | 199 | #define PCD_SPEED_HIGH 0 /* Not Supported */ | 
| Kojto | 93:e188a91d3eaa | 200 | #define PCD_SPEED_FULL 2 | 
| Kojto | 93:e188a91d3eaa | 201 | /** | 
| Kojto | 93:e188a91d3eaa | 202 | * @} | 
| Kojto | 93:e188a91d3eaa | 203 | */ | 
| Kojto | 93:e188a91d3eaa | 204 | |
| Kojto | 93:e188a91d3eaa | 205 | /** @defgroup PCD_Core_PHY PCD Core PHY | 
| Kojto | 93:e188a91d3eaa | 206 | * @{ | 
| Kojto | 93:e188a91d3eaa | 207 | */ | 
| Kojto | 93:e188a91d3eaa | 208 | #define PCD_PHY_EMBEDDED 2 | 
| Kojto | 93:e188a91d3eaa | 209 | /** | 
| Kojto | 93:e188a91d3eaa | 210 | * @} | 
| Kojto | 93:e188a91d3eaa | 211 | */ | 
| Kojto | 108:34e6b704fe68 | 212 | /** | 
| Kojto | 108:34e6b704fe68 | 213 | * @} | 
| Kojto | 108:34e6b704fe68 | 214 | */ | 
| Kojto | 108:34e6b704fe68 | 215 | |
| Kojto | 108:34e6b704fe68 | 216 | /* Exported macros -----------------------------------------------------------*/ | 
| Kojto | 108:34e6b704fe68 | 217 | /** @defgroup PCD_Exported_Macros PCD Exported Macros | 
| Kojto | 108:34e6b704fe68 | 218 | * @brief macros to handle interrupts and specific clock configurations | 
| Kojto | 108:34e6b704fe68 | 219 | * @{ | 
| Kojto | 108:34e6b704fe68 | 220 | */ | 
| Kojto | 108:34e6b704fe68 | 221 | #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISTR) & (__INTERRUPT__)) == (__INTERRUPT__)) | 
| Kojto | 122:f9eeca106725 | 222 | #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISTR) &= (uint16_t)(~(__INTERRUPT__)))) | 
| Kojto | 108:34e6b704fe68 | 223 | |
| Kojto | 108:34e6b704fe68 | 224 | #define __HAL_USB_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= USB_WAKEUP_EXTI_LINE | 
| Kojto | 108:34e6b704fe68 | 225 | #define __HAL_USB_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_WAKEUP_EXTI_LINE) | 
| Kojto | 108:34e6b704fe68 | 226 | #define __HAL_USB_EXTI_GENERATE_SWIT(__EXTILINE__) (EXTI->SWIER |= (__EXTILINE__)) | 
| Kojto | 108:34e6b704fe68 | 227 | |
| Kojto | 108:34e6b704fe68 | 228 | /** | 
| Kojto | 108:34e6b704fe68 | 229 | * @} | 
| Kojto | 108:34e6b704fe68 | 230 | */ | 
| Kojto | 108:34e6b704fe68 | 231 | |
| Kojto | 108:34e6b704fe68 | 232 | /* Exported functions --------------------------------------------------------*/ | 
| Kojto | 108:34e6b704fe68 | 233 | /** @addtogroup PCD_Exported_Functions PCD Exported Functions | 
| Kojto | 108:34e6b704fe68 | 234 | * @{ | 
| Kojto | 108:34e6b704fe68 | 235 | */ | 
| Kojto | 108:34e6b704fe68 | 236 | |
| Kojto | 108:34e6b704fe68 | 237 | /* Initialization/de-initialization functions ********************************/ | 
| Kojto | 108:34e6b704fe68 | 238 | /** @addtogroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions | 
| Kojto | 108:34e6b704fe68 | 239 | * @{ | 
| Kojto | 108:34e6b704fe68 | 240 | */ | 
| Kojto | 108:34e6b704fe68 | 241 | HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 242 | HAL_StatusTypeDef HAL_PCD_DeInit (PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 243 | void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 244 | void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 245 | /** | 
| Kojto | 108:34e6b704fe68 | 246 | * @} | 
| Kojto | 108:34e6b704fe68 | 247 | */ | 
| Kojto | 108:34e6b704fe68 | 248 | |
| Kojto | 108:34e6b704fe68 | 249 | /* I/O operation functions ***************************************************/ | 
| Kojto | 108:34e6b704fe68 | 250 | /* Non-Blocking mode: Interrupt */ | 
| Kojto | 108:34e6b704fe68 | 251 | /** @addtogroup PCD_Exported_Functions_Group2 IO operation functions | 
| Kojto | 108:34e6b704fe68 | 252 | * @{ | 
| Kojto | 108:34e6b704fe68 | 253 | */ | 
| Kojto | 108:34e6b704fe68 | 254 | HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 255 | HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 256 | void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 257 | |
| Kojto | 108:34e6b704fe68 | 258 | void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | 
| Kojto | 108:34e6b704fe68 | 259 | void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | 
| Kojto | 108:34e6b704fe68 | 260 | void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 261 | void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 262 | void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 263 | void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 264 | void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 265 | void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | 
| Kojto | 108:34e6b704fe68 | 266 | void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | 
| Kojto | 108:34e6b704fe68 | 267 | void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 268 | void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 269 | /** | 
| Kojto | 108:34e6b704fe68 | 270 | * @} | 
| Kojto | 108:34e6b704fe68 | 271 | */ | 
| Kojto | 108:34e6b704fe68 | 272 | |
| Kojto | 108:34e6b704fe68 | 273 | /* Peripheral Control functions **********************************************/ | 
| Kojto | 108:34e6b704fe68 | 274 | /** @addtogroup PCD_Exported_Functions_Group3 Peripheral Control functions | 
| Kojto | 108:34e6b704fe68 | 275 | * @{ | 
| Kojto | 108:34e6b704fe68 | 276 | */ | 
| Kojto | 108:34e6b704fe68 | 277 | HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 278 | HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 279 | HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address); | 
| Kojto | 108:34e6b704fe68 | 280 | HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type); | 
| Kojto | 108:34e6b704fe68 | 281 | HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | 
| Kojto | 108:34e6b704fe68 | 282 | HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len); | 
| Kojto | 108:34e6b704fe68 | 283 | HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len); | 
| Kojto | 108:34e6b704fe68 | 284 | uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | 
| Kojto | 108:34e6b704fe68 | 285 | HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | 
| Kojto | 108:34e6b704fe68 | 286 | HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | 
| Kojto | 108:34e6b704fe68 | 287 | HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | 
| Kojto | 108:34e6b704fe68 | 288 | HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 289 | HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 290 | /** | 
| Kojto | 108:34e6b704fe68 | 291 | * @} | 
| Kojto | 108:34e6b704fe68 | 292 | */ | 
| Kojto | 108:34e6b704fe68 | 293 | |
| Kojto | 108:34e6b704fe68 | 294 | /* Peripheral State functions ************************************************/ | 
| Kojto | 108:34e6b704fe68 | 295 | /** @addtogroup PCD_Exported_Functions_Group4 Peripheral State functions | 
| Kojto | 108:34e6b704fe68 | 296 | * @{ | 
| Kojto | 108:34e6b704fe68 | 297 | */ | 
| Kojto | 108:34e6b704fe68 | 298 | PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd); | 
| Kojto | 108:34e6b704fe68 | 299 | /** | 
| Kojto | 108:34e6b704fe68 | 300 | * @} | 
| Kojto | 108:34e6b704fe68 | 301 | */ | 
| Kojto | 108:34e6b704fe68 | 302 | |
| Kojto | 108:34e6b704fe68 | 303 | /** | 
| Kojto | 108:34e6b704fe68 | 304 | * @} | 
| Kojto | 108:34e6b704fe68 | 305 | */ | 
| Kojto | 108:34e6b704fe68 | 306 | |
| Kojto | 108:34e6b704fe68 | 307 | /* Private constants ---------------------------------------------------------*/ | 
| Kojto | 108:34e6b704fe68 | 308 | /** @defgroup PCD_Private_Constants PCD Private Constants | 
| Kojto | 108:34e6b704fe68 | 309 | * @{ | 
| Kojto | 108:34e6b704fe68 | 310 | */ | 
| Kojto | 108:34e6b704fe68 | 311 | /** @defgroup USB_EXTI_Line_Interrupt USB EXTI line interrupt | 
| Kojto | 108:34e6b704fe68 | 312 | * @{ | 
| Kojto | 108:34e6b704fe68 | 313 | */ | 
| Kojto | 108:34e6b704fe68 | 314 | #define USB_WAKEUP_EXTI_LINE ((uint32_t)EXTI_IMR_MR18) /*!< External interrupt line 18 Connected to the USB FS EXTI Line */ | 
| Kojto | 108:34e6b704fe68 | 315 | /** | 
| Kojto | 108:34e6b704fe68 | 316 | * @} | 
| Kojto | 108:34e6b704fe68 | 317 | */ | 
| Kojto | 93:e188a91d3eaa | 318 | |
| Kojto | 93:e188a91d3eaa | 319 | /** @defgroup PCD_EP0_MPS PCD EP0 MPS | 
| Kojto | 93:e188a91d3eaa | 320 | * @{ | 
| Kojto | 93:e188a91d3eaa | 321 | */ | 
| Kojto | 93:e188a91d3eaa | 322 | #define DEP0CTL_MPS_64 0 | 
| Kojto | 93:e188a91d3eaa | 323 | #define DEP0CTL_MPS_32 1 | 
| Kojto | 93:e188a91d3eaa | 324 | #define DEP0CTL_MPS_16 2 | 
| Kojto | 93:e188a91d3eaa | 325 | #define DEP0CTL_MPS_8 3 | 
| Kojto | 93:e188a91d3eaa | 326 | |
| Kojto | 93:e188a91d3eaa | 327 | #define PCD_EP0MPS_64 DEP0CTL_MPS_64 | 
| Kojto | 93:e188a91d3eaa | 328 | #define PCD_EP0MPS_32 DEP0CTL_MPS_32 | 
| Kojto | 93:e188a91d3eaa | 329 | #define PCD_EP0MPS_16 DEP0CTL_MPS_16 | 
| Kojto | 93:e188a91d3eaa | 330 | #define PCD_EP0MPS_08 DEP0CTL_MPS_8 | 
| Kojto | 93:e188a91d3eaa | 331 | /** | 
| Kojto | 93:e188a91d3eaa | 332 | * @} | 
| Kojto | 93:e188a91d3eaa | 333 | */ | 
| Kojto | 93:e188a91d3eaa | 334 | |
| Kojto | 93:e188a91d3eaa | 335 | /** @defgroup PCD_EP_Type PCD EP Type | 
| Kojto | 93:e188a91d3eaa | 336 | * @{ | 
| Kojto | 93:e188a91d3eaa | 337 | */ | 
| Kojto | 108:34e6b704fe68 | 338 | #define PCD_EP_TYPE_CTRL 0 | 
| Kojto | 108:34e6b704fe68 | 339 | #define PCD_EP_TYPE_ISOC 1 | 
| Kojto | 108:34e6b704fe68 | 340 | #define PCD_EP_TYPE_BULK 2 | 
| Kojto | 108:34e6b704fe68 | 341 | #define PCD_EP_TYPE_INTR 3 | 
| Kojto | 93:e188a91d3eaa | 342 | /** | 
| Kojto | 93:e188a91d3eaa | 343 | * @} | 
| Kojto | 93:e188a91d3eaa | 344 | */ | 
| Kojto | 93:e188a91d3eaa | 345 | |
| Kojto | 108:34e6b704fe68 | 346 | /** @defgroup PCD_ENDP PCD ENDP | 
| Kojto | 93:e188a91d3eaa | 347 | * @{ | 
| Kojto | 93:e188a91d3eaa | 348 | */ | 
| Kojto | 108:34e6b704fe68 | 349 | #define PCD_ENDP0 ((uint8_t)0) | 
| Kojto | 108:34e6b704fe68 | 350 | #define PCD_ENDP1 ((uint8_t)1) | 
| Kojto | 108:34e6b704fe68 | 351 | #define PCD_ENDP2 ((uint8_t)2) | 
| Kojto | 108:34e6b704fe68 | 352 | #define PCD_ENDP3 ((uint8_t)3) | 
| Kojto | 108:34e6b704fe68 | 353 | #define PCD_ENDP4 ((uint8_t)4) | 
| Kojto | 108:34e6b704fe68 | 354 | #define PCD_ENDP5 ((uint8_t)5) | 
| Kojto | 108:34e6b704fe68 | 355 | #define PCD_ENDP6 ((uint8_t)6) | 
| Kojto | 108:34e6b704fe68 | 356 | #define PCD_ENDP7 ((uint8_t)7) | 
| Kojto | 108:34e6b704fe68 | 357 | /** | 
| Kojto | 108:34e6b704fe68 | 358 | * @} | 
| Kojto | 108:34e6b704fe68 | 359 | */ | 
| Kojto | 93:e188a91d3eaa | 360 | |
| Kojto | 108:34e6b704fe68 | 361 | /** @defgroup PCD_ENDP_Kind PCD Endpoint Kind | 
| Kojto | 108:34e6b704fe68 | 362 | * @{ | 
| Kojto | 108:34e6b704fe68 | 363 | */ | 
| Kojto | 108:34e6b704fe68 | 364 | #define PCD_SNG_BUF 0 | 
| Kojto | 108:34e6b704fe68 | 365 | #define PCD_DBL_BUF 1 | 
| Kojto | 93:e188a91d3eaa | 366 | /** | 
| Kojto | 93:e188a91d3eaa | 367 | * @} | 
| Kojto | 108:34e6b704fe68 | 368 | */ | 
| Kojto | 93:e188a91d3eaa | 369 | |
| Kojto | 93:e188a91d3eaa | 370 | /** | 
| Kojto | 93:e188a91d3eaa | 371 | * @} | 
| Kojto | 93:e188a91d3eaa | 372 | */ | 
| Kojto | 93:e188a91d3eaa | 373 | |
| Kojto | 108:34e6b704fe68 | 374 | /* Private macros ------------------------------------------------------------*/ | 
| Kojto | 108:34e6b704fe68 | 375 | /** @addtogroup PCD_Private_Macros PCD Private Macros | 
| Kojto | 93:e188a91d3eaa | 376 | * @{ | 
| Kojto | 93:e188a91d3eaa | 377 | */ | 
| Kojto | 93:e188a91d3eaa | 378 | |
| Kojto | 93:e188a91d3eaa | 379 | /* SetENDPOINT */ | 
| Kojto | 122:f9eeca106725 | 380 | #define PCD_SET_ENDPOINT(USBx, bEpNum,wRegValue) (*((uint16_t *)(((uint32_t)(&(USBx)->EP0R + (bEpNum) * 2))))= (uint16_t)(wRegValue)) | 
| Kojto | 93:e188a91d3eaa | 381 | |
| Kojto | 93:e188a91d3eaa | 382 | /* GetENDPOINT */ | 
| Kojto | 122:f9eeca106725 | 383 | #define PCD_GET_ENDPOINT(USBx, bEpNum) (*((uint16_t *)(((uint32_t)(&(USBx)->EP0R + (bEpNum) * 2))))) | 
| Kojto | 93:e188a91d3eaa | 384 | |
| Kojto | 93:e188a91d3eaa | 385 | |
| Kojto | 93:e188a91d3eaa | 386 | |
| Kojto | 93:e188a91d3eaa | 387 | /** | 
| Kojto | 93:e188a91d3eaa | 388 | * @brief sets the type in the endpoint register(bits EP_TYPE[1:0]) | 
| Kojto | 93:e188a91d3eaa | 389 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 390 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 391 | * @param wType: Endpoint Type. | 
| Kojto | 93:e188a91d3eaa | 392 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 393 | */ | 
| Kojto | 93:e188a91d3eaa | 394 | #define PCD_SET_EPTYPE(USBx, bEpNum,wType) (PCD_SET_ENDPOINT((USBx), (bEpNum),\ | 
| Kojto | 122:f9eeca106725 | 395 | ((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & ((uint32_t)(USB_EP_T_MASK))) | ((uint32_t)(wType)) ))) | 
| Kojto | 93:e188a91d3eaa | 396 | |
| Kojto | 93:e188a91d3eaa | 397 | /** | 
| Kojto | 93:e188a91d3eaa | 398 | * @brief gets the type in the endpoint register(bits EP_TYPE[1:0]) | 
| Kojto | 93:e188a91d3eaa | 399 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 400 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 401 | * @retval Endpoint Type | 
| Kojto | 93:e188a91d3eaa | 402 | */ | 
| Kojto | 122:f9eeca106725 | 403 | #define PCD_GET_EPTYPE(USBx, bEpNum) (((uint16_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EP_T_FIELD) | 
| Kojto | 93:e188a91d3eaa | 404 | |
| Kojto | 93:e188a91d3eaa | 405 | |
| Kojto | 93:e188a91d3eaa | 406 | /** | 
| Kojto | 93:e188a91d3eaa | 407 | * @brief free buffer used from the application realizing it to the line | 
| Kojto | 93:e188a91d3eaa | 408 | toggles bit SW_BUF in the double buffered endpoint register | 
| Kojto | 93:e188a91d3eaa | 409 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 410 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 411 | * @param bDir: Direction | 
| Kojto | 93:e188a91d3eaa | 412 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 413 | */ | 
| Kojto | 93:e188a91d3eaa | 414 | #define PCD_FreeUserBuffer(USBx, bEpNum, bDir)\ | 
| Kojto | 93:e188a91d3eaa | 415 | {\ | 
| Kojto | 93:e188a91d3eaa | 416 | if ((bDir) == PCD_EP_DBUF_OUT)\ | 
| Kojto | 93:e188a91d3eaa | 417 | { /* OUT double buffered endpoint */\ | 
| Kojto | 93:e188a91d3eaa | 418 | PCD_TX_DTOG((USBx), (bEpNum));\ | 
| Kojto | 93:e188a91d3eaa | 419 | }\ | 
| Kojto | 93:e188a91d3eaa | 420 | else if ((bDir) == PCD_EP_DBUF_IN)\ | 
| Kojto | 93:e188a91d3eaa | 421 | { /* IN double buffered endpoint */\ | 
| Kojto | 93:e188a91d3eaa | 422 | PCD_RX_DTOG((USBx), (bEpNum));\ | 
| Kojto | 93:e188a91d3eaa | 423 | }\ | 
| Kojto | 93:e188a91d3eaa | 424 | } | 
| Kojto | 93:e188a91d3eaa | 425 | |
| Kojto | 93:e188a91d3eaa | 426 | /** | 
| Kojto | 93:e188a91d3eaa | 427 | * @brief gets direction of the double buffered endpoint | 
| Kojto | 93:e188a91d3eaa | 428 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 429 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 430 | * @retval EP_DBUF_OUT, EP_DBUF_IN, | 
| Kojto | 93:e188a91d3eaa | 431 | * EP_DBUF_ERR if the endpoint counter not yet programmed. | 
| Kojto | 93:e188a91d3eaa | 432 | */ | 
| Kojto | 93:e188a91d3eaa | 433 | #define PCD_GET_DB_DIR(USBx, bEpNum)\ | 
| Kojto | 93:e188a91d3eaa | 434 | {\ | 
| Kojto | 122:f9eeca106725 | 435 | if ((uint16_t)(*PCD_EP_RX_CNT((USBx), (bEpNum)) & 0xFC00U) != 0)\ | 
| Kojto | 93:e188a91d3eaa | 436 | return(PCD_EP_DBUF_OUT);\ | 
| Kojto | 122:f9eeca106725 | 437 | else if (((uint16_t)(*PCD_EP_TX_CNT((USBx), (bEpNum))) & 0x03FFU) != 0)\ | 
| Kojto | 93:e188a91d3eaa | 438 | return(PCD_EP_DBUF_IN);\ | 
| Kojto | 93:e188a91d3eaa | 439 | else\ | 
| Kojto | 93:e188a91d3eaa | 440 | return(PCD_EP_DBUF_ERR);\ | 
| Kojto | 93:e188a91d3eaa | 441 | } | 
| Kojto | 93:e188a91d3eaa | 442 | |
| Kojto | 93:e188a91d3eaa | 443 | /** | 
| Kojto | 93:e188a91d3eaa | 444 | * @brief sets the status for tx transfer (bits STAT_TX[1:0]). | 
| Kojto | 93:e188a91d3eaa | 445 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 446 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 447 | * @param wState: new state | 
| Kojto | 93:e188a91d3eaa | 448 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 449 | */ | 
| Kojto | 122:f9eeca106725 | 450 | #define PCD_SET_EP_TX_STATUS(USBx, bEpNum, wState) { register uint16_t _wRegVal;\ | 
| Kojto | 93:e188a91d3eaa | 451 | \ | 
| Kojto | 122:f9eeca106725 | 452 | _wRegVal = (uint32_t) (((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPTX_DTOGMASK);\ | 
| Kojto | 93:e188a91d3eaa | 453 | /* toggle first bit ? */ \ | 
| Kojto | 122:f9eeca106725 | 454 | if((USB_EPTX_DTOG1 & (wState))!= 0)\ | 
| Kojto | 122:f9eeca106725 | 455 | { \ | 
| Kojto | 122:f9eeca106725 | 456 | _wRegVal ^=(uint16_t) USB_EPTX_DTOG1; \ | 
| Kojto | 122:f9eeca106725 | 457 | } \ | 
| Kojto | 93:e188a91d3eaa | 458 | /* toggle second bit ? */ \ | 
| Kojto | 122:f9eeca106725 | 459 | if((USB_EPTX_DTOG2 & ((uint32_t)(wState)))!= 0) \ | 
| Kojto | 122:f9eeca106725 | 460 | { \ | 
| Kojto | 122:f9eeca106725 | 461 | _wRegVal ^=(uint16_t) USB_EPTX_DTOG2; \ | 
| Kojto | 122:f9eeca106725 | 462 | } \ | 
| Kojto | 122:f9eeca106725 | 463 | PCD_SET_ENDPOINT((USBx), (bEpNum), (((uint32_t)(_wRegVal)) | USB_EP_CTR_RX|USB_EP_CTR_TX));\ | 
| Kojto | 93:e188a91d3eaa | 464 | } /* PCD_SET_EP_TX_STATUS */ | 
| Kojto | 93:e188a91d3eaa | 465 | |
| Kojto | 93:e188a91d3eaa | 466 | /** | 
| Kojto | 93:e188a91d3eaa | 467 | * @brief sets the status for rx transfer (bits STAT_TX[1:0]) | 
| Kojto | 93:e188a91d3eaa | 468 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 469 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 470 | * @param wState: new state | 
| Kojto | 93:e188a91d3eaa | 471 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 472 | */ | 
| Kojto | 93:e188a91d3eaa | 473 | #define PCD_SET_EP_RX_STATUS(USBx, bEpNum,wState) {\ | 
| Kojto | 93:e188a91d3eaa | 474 | register uint16_t _wRegVal; \ | 
| Kojto | 93:e188a91d3eaa | 475 | \ | 
| Kojto | 122:f9eeca106725 | 476 | _wRegVal = (uint32_t) (((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPRX_DTOGMASK);\ | 
| Kojto | 93:e188a91d3eaa | 477 | /* toggle first bit ? */ \ | 
| Kojto | 93:e188a91d3eaa | 478 | if((USB_EPRX_DTOG1 & (wState))!= 0) \ | 
| Kojto | 122:f9eeca106725 | 479 | { \ | 
| Kojto | 122:f9eeca106725 | 480 | _wRegVal ^= (uint16_t) USB_EPRX_DTOG1; \ | 
| Kojto | 122:f9eeca106725 | 481 | } \ | 
| Kojto | 93:e188a91d3eaa | 482 | /* toggle second bit ? */ \ | 
| Kojto | 122:f9eeca106725 | 483 | if((USB_EPRX_DTOG2 & ((uint32_t)(wState)))!= 0) \ | 
| Kojto | 122:f9eeca106725 | 484 | { \ | 
| Kojto | 122:f9eeca106725 | 485 | _wRegVal ^= (uint16_t) USB_EPRX_DTOG2; \ | 
| Kojto | 122:f9eeca106725 | 486 | } \ | 
| Kojto | 122:f9eeca106725 | 487 | PCD_SET_ENDPOINT((USBx), (bEpNum), (((uint32_t)(_wRegVal)) | USB_EP_CTR_RX|USB_EP_CTR_TX)); \ | 
| Kojto | 93:e188a91d3eaa | 488 | } /* PCD_SET_EP_RX_STATUS */ | 
| Kojto | 93:e188a91d3eaa | 489 | |
| Kojto | 93:e188a91d3eaa | 490 | /** | 
| Kojto | 93:e188a91d3eaa | 491 | * @brief sets the status for rx & tx (bits STAT_TX[1:0] & STAT_RX[1:0]) | 
| Kojto | 93:e188a91d3eaa | 492 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 493 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 494 | * @param wStaterx: new state. | 
| Kojto | 93:e188a91d3eaa | 495 | * @param wStatetx: new state. | 
| Kojto | 93:e188a91d3eaa | 496 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 497 | */ | 
| Kojto | 93:e188a91d3eaa | 498 | #define PCD_SET_EP_TXRX_STATUS(USBx,bEpNum,wStaterx,wStatetx) {\ | 
| Kojto | 93:e188a91d3eaa | 499 | register uint32_t _wRegVal; \ | 
| Kojto | 93:e188a91d3eaa | 500 | \ | 
| Kojto | 93:e188a91d3eaa | 501 | _wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & (USB_EPRX_DTOGMASK |USB_EPTX_STAT) ;\ | 
| Kojto | 93:e188a91d3eaa | 502 | /* toggle first bit ? */ \ | 
| Kojto | 93:e188a91d3eaa | 503 | if((USB_EPRX_DTOG1 & ((wStaterx)))!= 0) \ | 
| Kojto | 122:f9eeca106725 | 504 | { \ | 
| Kojto | 93:e188a91d3eaa | 505 | _wRegVal ^= USB_EPRX_DTOG1; \ | 
| Kojto | 122:f9eeca106725 | 506 | } \ | 
| Kojto | 93:e188a91d3eaa | 507 | /* toggle second bit ? */ \ | 
| Kojto | 93:e188a91d3eaa | 508 | if((USB_EPRX_DTOG2 & (wStaterx))!= 0) \ | 
| Kojto | 122:f9eeca106725 | 509 | { \ | 
| Kojto | 93:e188a91d3eaa | 510 | _wRegVal ^= USB_EPRX_DTOG2; \ | 
| Kojto | 122:f9eeca106725 | 511 | } \ | 
| Kojto | 93:e188a91d3eaa | 512 | /* toggle first bit ? */ \ | 
| Kojto | 93:e188a91d3eaa | 513 | if((USB_EPTX_DTOG1 & (wStatetx))!= 0) \ | 
| Kojto | 122:f9eeca106725 | 514 | { \ | 
| Kojto | 93:e188a91d3eaa | 515 | _wRegVal ^= USB_EPTX_DTOG1; \ | 
| Kojto | 122:f9eeca106725 | 516 | } \ | 
| Kojto | 93:e188a91d3eaa | 517 | /* toggle second bit ? */ \ | 
| Kojto | 93:e188a91d3eaa | 518 | if((USB_EPTX_DTOG2 & (wStatetx))!= 0) \ | 
| Kojto | 122:f9eeca106725 | 519 | { \ | 
| Kojto | 93:e188a91d3eaa | 520 | _wRegVal ^= USB_EPTX_DTOG2; \ | 
| Kojto | 122:f9eeca106725 | 521 | } \ | 
| Kojto | 93:e188a91d3eaa | 522 | PCD_SET_ENDPOINT((USBx), (bEpNum), _wRegVal | USB_EP_CTR_RX|USB_EP_CTR_TX); \ | 
| Kojto | 93:e188a91d3eaa | 523 | } /* PCD_SET_EP_TXRX_STATUS */ | 
| Kojto | 93:e188a91d3eaa | 524 | |
| Kojto | 93:e188a91d3eaa | 525 | /** | 
| Kojto | 93:e188a91d3eaa | 526 | * @brief gets the status for tx/rx transfer (bits STAT_TX[1:0] | 
| Kojto | 93:e188a91d3eaa | 527 | * /STAT_RX[1:0]) | 
| Kojto | 93:e188a91d3eaa | 528 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 529 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 530 | * @retval status | 
| Kojto | 93:e188a91d3eaa | 531 | */ | 
| Kojto | 122:f9eeca106725 | 532 | #define PCD_GET_EP_TX_STATUS(USBx, bEpNum) (((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPTX_STAT) | 
| Kojto | 122:f9eeca106725 | 533 | #define PCD_GET_EP_RX_STATUS(USBx, bEpNum) (((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPRX_STAT) | 
| Kojto | 93:e188a91d3eaa | 534 | |
| Kojto | 93:e188a91d3eaa | 535 | /** | 
| Kojto | 93:e188a91d3eaa | 536 | * @brief sets directly the VALID tx/rx-status into the endpoint register | 
| Kojto | 93:e188a91d3eaa | 537 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 538 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 539 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 540 | */ | 
| Kojto | 93:e188a91d3eaa | 541 | #define PCD_SET_EP_TX_VALID(USBx, bEpNum) (PCD_SET_EP_TX_STATUS((USBx), (bEpNum), USB_EP_TX_VALID)) | 
| Kojto | 93:e188a91d3eaa | 542 | #define PCD_SET_EP_RX_VALID(USBx, bEpNum) (PCD_SET_EP_RX_STATUS((USBx), (bEpNum), USB_EP_RX_VALID)) | 
| Kojto | 93:e188a91d3eaa | 543 | |
| Kojto | 93:e188a91d3eaa | 544 | /** | 
| Kojto | 93:e188a91d3eaa | 545 | * @brief checks stall condition in an endpoint. | 
| Kojto | 93:e188a91d3eaa | 546 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 547 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 548 | * @retval TRUE = endpoint in stall condition. | 
| Kojto | 93:e188a91d3eaa | 549 | */ | 
| Kojto | 93:e188a91d3eaa | 550 | #define PCD_GET_EP_TX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_TX_STATUS((USBx), (bEpNum)) \ | 
| Kojto | 93:e188a91d3eaa | 551 | == USB_EP_TX_STALL) | 
| Kojto | 93:e188a91d3eaa | 552 | #define PCD_GET_EP_RX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_RX_STATUS((USBx), (bEpNum)) \ | 
| Kojto | 93:e188a91d3eaa | 553 | == USB_EP_RX_STALL) | 
| Kojto | 93:e188a91d3eaa | 554 | |
| Kojto | 93:e188a91d3eaa | 555 | /** | 
| Kojto | 93:e188a91d3eaa | 556 | * @brief set & clear EP_KIND bit. | 
| Kojto | 93:e188a91d3eaa | 557 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 558 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 559 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 560 | */ | 
| Kojto | 93:e188a91d3eaa | 561 | #define PCD_SET_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum), \ | 
| Kojto | 122:f9eeca106725 | 562 | (USB_EP_CTR_RX|USB_EP_CTR_TX|((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) | USB_EP_KIND) & USB_EPREG_MASK)))) | 
| Kojto | 93:e188a91d3eaa | 563 | #define PCD_CLEAR_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum), \ | 
| Kojto | 122:f9eeca106725 | 564 | (USB_EP_CTR_RX|USB_EP_CTR_TX|((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPKIND_MASK)))) | 
| Kojto | 93:e188a91d3eaa | 565 | |
| Kojto | 93:e188a91d3eaa | 566 | /** | 
| Kojto | 93:e188a91d3eaa | 567 | * @brief Sets/clears directly STATUS_OUT bit in the endpoint register. | 
| Kojto | 93:e188a91d3eaa | 568 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 569 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 570 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 571 | */ | 
| Kojto | 93:e188a91d3eaa | 572 | #define PCD_SET_OUT_STATUS(USBx, bEpNum) PCD_SET_EP_KIND((USBx), (bEpNum)) | 
| Kojto | 93:e188a91d3eaa | 573 | #define PCD_CLEAR_OUT_STATUS(USBx, bEpNum) PCD_CLEAR_EP_KIND((USBx), (bEpNum)) | 
| Kojto | 93:e188a91d3eaa | 574 | |
| Kojto | 93:e188a91d3eaa | 575 | /** | 
| Kojto | 93:e188a91d3eaa | 576 | * @brief Sets/clears directly EP_KIND bit in the endpoint register. | 
| Kojto | 93:e188a91d3eaa | 577 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 578 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 579 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 580 | */ | 
| Kojto | 93:e188a91d3eaa | 581 | #define PCD_SET_EP_DBUF(USBx, bEpNum) PCD_SET_EP_KIND((USBx), (bEpNum)) | 
| Kojto | 93:e188a91d3eaa | 582 | #define PCD_CLEAR_EP_DBUF(USBx, bEpNum) PCD_CLEAR_EP_KIND((USBx), (bEpNum)) | 
| Kojto | 93:e188a91d3eaa | 583 | |
| Kojto | 93:e188a91d3eaa | 584 | /** | 
| Kojto | 93:e188a91d3eaa | 585 | * @brief Clears bit CTR_RX / CTR_TX in the endpoint register. | 
| Kojto | 93:e188a91d3eaa | 586 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 587 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 588 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 589 | */ | 
| Kojto | 93:e188a91d3eaa | 590 | #define PCD_CLEAR_RX_EP_CTR(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum),\ | 
| Kojto | 122:f9eeca106725 | 591 | PCD_GET_ENDPOINT((USBx), (bEpNum)) & 0x7FFFU & USB_EPREG_MASK)) | 
| Kojto | 93:e188a91d3eaa | 592 | #define PCD_CLEAR_TX_EP_CTR(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum),\ | 
| Kojto | 122:f9eeca106725 | 593 | PCD_GET_ENDPOINT((USBx), (bEpNum)) & 0xFF7FU & USB_EPREG_MASK)) | 
| Kojto | 93:e188a91d3eaa | 594 | |
| Kojto | 93:e188a91d3eaa | 595 | /** | 
| Kojto | 93:e188a91d3eaa | 596 | * @brief Toggles DTOG_RX / DTOG_TX bit in the endpoint register. | 
| Kojto | 93:e188a91d3eaa | 597 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 598 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 599 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 600 | */ | 
| Kojto | 93:e188a91d3eaa | 601 | #define PCD_RX_DTOG(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum), \ | 
| Kojto | 122:f9eeca106725 | 602 | USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_RX | (((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPREG_MASK))) | 
| Kojto | 93:e188a91d3eaa | 603 | #define PCD_TX_DTOG(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum), \ | 
| Kojto | 122:f9eeca106725 | 604 | USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_TX | (((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPREG_MASK))) | 
| Kojto | 93:e188a91d3eaa | 605 | |
| Kojto | 93:e188a91d3eaa | 606 | /** | 
| Kojto | 93:e188a91d3eaa | 607 | * @brief Clears DTOG_RX / DTOG_TX bit in the endpoint register. | 
| Kojto | 93:e188a91d3eaa | 608 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 609 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 610 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 611 | */ | 
| Kojto | 122:f9eeca106725 | 612 | #define PCD_CLEAR_RX_DTOG(USBx, bEpNum) if((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EP_DTOG_RX) != 0)\ | 
| Kojto | 122:f9eeca106725 | 613 | { \ | 
| Kojto | 122:f9eeca106725 | 614 | PCD_RX_DTOG((USBx),(bEpNum));\ | 
| Kojto | 122:f9eeca106725 | 615 | } | 
| Kojto | 122:f9eeca106725 | 616 | #define PCD_CLEAR_TX_DTOG(USBx, bEpNum) if((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EP_DTOG_TX) != 0)\ | 
| Kojto | 122:f9eeca106725 | 617 | {\ | 
| Kojto | 122:f9eeca106725 | 618 | PCD_TX_DTOG((USBx),(bEpNum));\ | 
| Kojto | 122:f9eeca106725 | 619 | } | 
| Kojto | 93:e188a91d3eaa | 620 | |
| Kojto | 93:e188a91d3eaa | 621 | /** | 
| Kojto | 93:e188a91d3eaa | 622 | * @brief Sets address in an endpoint register. | 
| Kojto | 93:e188a91d3eaa | 623 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 624 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 625 | * @param bAddr: Address. | 
| Kojto | 93:e188a91d3eaa | 626 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 627 | */ | 
| Kojto | 93:e188a91d3eaa | 628 | #define PCD_SET_EP_ADDRESS(USBx, bEpNum,bAddr) PCD_SET_ENDPOINT((USBx), (bEpNum),\ | 
| Kojto | 122:f9eeca106725 | 629 | USB_EP_CTR_RX|USB_EP_CTR_TX|(((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPREG_MASK) | (bAddr)) | 
| Kojto | 93:e188a91d3eaa | 630 | |
| Kojto | 93:e188a91d3eaa | 631 | /** | 
| Kojto | 93:e188a91d3eaa | 632 | * @brief Gets address in an endpoint register. | 
| Kojto | 93:e188a91d3eaa | 633 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 634 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 635 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 636 | */ | 
| Kojto | 93:e188a91d3eaa | 637 | #define PCD_GET_EP_ADDRESS(USBx, bEpNum) ((uint8_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPADDR_FIELD)) | 
| Kojto | 93:e188a91d3eaa | 638 | |
| Kojto | 122:f9eeca106725 | 639 | #define PCD_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t *)((uint32_t)((((USBx)->BTABLE+(bEpNum)*8)+ ((uint32_t)(USBx) + 0x400))))) | 
| Kojto | 122:f9eeca106725 | 640 | #define PCD_EP_TX_CNT(USBx, bEpNum) ((uint16_t *)((uint32_t)((((USBx)->BTABLE+(bEpNum)*8+2)+ ((uint32_t)(USBx) + 0x400))))) | 
| Kojto | 122:f9eeca106725 | 641 | #define PCD_EP_RX_ADDRESS(USBx, bEpNum) ((uint16_t *)((uint32_t)((((USBx)->BTABLE+(bEpNum)*8+4)+ ((uint32_t)(USBx) + 0x400))))) | 
| Kojto | 122:f9eeca106725 | 642 | |
| Kojto | 122:f9eeca106725 | 643 | #define PCD_EP_RX_CNT(USBx, bEpNum) ((uint16_t *)((uint32_t)((((USBx)->BTABLE+(bEpNum)*8+6)+ ((uint32_t)(USBx) + 0x400))))) | 
| Kojto | 93:e188a91d3eaa | 644 | |
| Kojto | 93:e188a91d3eaa | 645 | /** | 
| Kojto | 93:e188a91d3eaa | 646 | * @brief sets address of the tx/rx buffer. | 
| Kojto | 93:e188a91d3eaa | 647 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 648 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 649 | * @param wAddr: address to be set (must be word aligned). | 
| Kojto | 93:e188a91d3eaa | 650 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 651 | */ | 
| Kojto | 93:e188a91d3eaa | 652 | #define PCD_SET_EP_TX_ADDRESS(USBx, bEpNum,wAddr) (*PCD_EP_TX_ADDRESS((USBx), (bEpNum)) = (((wAddr) >> 1) << 1)) | 
| Kojto | 93:e188a91d3eaa | 653 | #define PCD_SET_EP_RX_ADDRESS(USBx, bEpNum,wAddr) (*PCD_EP_RX_ADDRESS((USBx), (bEpNum)) = (((wAddr) >> 1) << 1)) | 
| Kojto | 93:e188a91d3eaa | 654 | |
| Kojto | 93:e188a91d3eaa | 655 | /** | 
| Kojto | 93:e188a91d3eaa | 656 | * @brief Gets address of the tx/rx buffer. | 
| Kojto | 93:e188a91d3eaa | 657 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 658 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 659 | * @retval address of the buffer. | 
| Kojto | 93:e188a91d3eaa | 660 | */ | 
| Kojto | 93:e188a91d3eaa | 661 | #define PCD_GET_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_TX_ADDRESS((USBx), (bEpNum))) | 
| Kojto | 93:e188a91d3eaa | 662 | #define PCD_GET_EP_RX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_RX_ADDRESS((USBx), (bEpNum))) | 
| Kojto | 93:e188a91d3eaa | 663 | |
| Kojto | 93:e188a91d3eaa | 664 | /** | 
| Kojto | 93:e188a91d3eaa | 665 | * @brief Sets counter of rx buffer with no. of blocks. | 
| Kojto | 93:e188a91d3eaa | 666 | * @param dwReg: Register | 
| Kojto | 93:e188a91d3eaa | 667 | * @param wCount: Counter. | 
| Kojto | 93:e188a91d3eaa | 668 | * @param wNBlocks: no. of Blocks. | 
| Kojto | 93:e188a91d3eaa | 669 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 670 | */ | 
| Kojto | 93:e188a91d3eaa | 671 | #define PCD_CALC_BLK32(dwReg,wCount,wNBlocks) {\ | 
| Kojto | 93:e188a91d3eaa | 672 | (wNBlocks) = (wCount) >> 5;\ | 
| Kojto | 93:e188a91d3eaa | 673 | if(((wCount) & 0x1f) == 0)\ | 
| Kojto | 122:f9eeca106725 | 674 | { \ | 
| Kojto | 93:e188a91d3eaa | 675 | (wNBlocks)--;\ | 
| Kojto | 122:f9eeca106725 | 676 | } \ | 
| Kojto | 122:f9eeca106725 | 677 | *pdwReg = (uint16_t)((uint16_t)((wNBlocks) << 10) | (uint16_t)0x8000); \ | 
| Kojto | 93:e188a91d3eaa | 678 | }/* PCD_CALC_BLK32 */ | 
| Kojto | 93:e188a91d3eaa | 679 | |
| Kojto | 122:f9eeca106725 | 680 | |
| Kojto | 93:e188a91d3eaa | 681 | #define PCD_CALC_BLK2(dwReg,wCount,wNBlocks) {\ | 
| Kojto | 93:e188a91d3eaa | 682 | (wNBlocks) = (wCount) >> 1;\ | 
| Kojto | 93:e188a91d3eaa | 683 | if(((wCount) & 0x1) != 0)\ | 
| Kojto | 122:f9eeca106725 | 684 | { \ | 
| Kojto | 93:e188a91d3eaa | 685 | (wNBlocks)++;\ | 
| Kojto | 122:f9eeca106725 | 686 | } \ | 
| Kojto | 93:e188a91d3eaa | 687 | *pdwReg = (uint16_t)((wNBlocks) << 10);\ | 
| Kojto | 93:e188a91d3eaa | 688 | }/* PCD_CALC_BLK2 */ | 
| Kojto | 93:e188a91d3eaa | 689 | |
| Kojto | 122:f9eeca106725 | 690 | |
| Kojto | 93:e188a91d3eaa | 691 | #define PCD_SET_EP_CNT_RX_REG(dwReg,wCount) {\ | 
| Kojto | 93:e188a91d3eaa | 692 | uint16_t wNBlocks;\ | 
| Kojto | 122:f9eeca106725 | 693 | if((wCount) > 62) \ | 
| Kojto | 122:f9eeca106725 | 694 | { \ | 
| Kojto | 122:f9eeca106725 | 695 | PCD_CALC_BLK32((dwReg),(wCount),wNBlocks) \ | 
| Kojto | 122:f9eeca106725 | 696 | } \ | 
| Kojto | 122:f9eeca106725 | 697 | else \ | 
| Kojto | 122:f9eeca106725 | 698 | { \ | 
| Kojto | 122:f9eeca106725 | 699 | PCD_CALC_BLK2((dwReg),(wCount),wNBlocks) \ | 
| Kojto | 122:f9eeca106725 | 700 | } \ | 
| Kojto | 93:e188a91d3eaa | 701 | }/* PCD_SET_EP_CNT_RX_REG */ | 
| Kojto | 93:e188a91d3eaa | 702 | |
| Kojto | 122:f9eeca106725 | 703 | |
| Kojto | 93:e188a91d3eaa | 704 | #define PCD_SET_EP_RX_DBUF0_CNT(USBx, bEpNum,wCount) {\ | 
| Kojto | 93:e188a91d3eaa | 705 | uint16_t *pdwReg = PCD_EP_TX_CNT((USBx), (bEpNum)); \ | 
| Kojto | 122:f9eeca106725 | 706 | PCD_SET_EP_CNT_RX_REG(pdwReg, (wCount))\ | 
| Kojto | 93:e188a91d3eaa | 707 | } | 
| Kojto | 122:f9eeca106725 | 708 | |
| Kojto | 93:e188a91d3eaa | 709 | /** | 
| Kojto | 93:e188a91d3eaa | 710 | * @brief sets counter for the tx/rx buffer. | 
| Kojto | 93:e188a91d3eaa | 711 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 712 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 713 | * @param wCount: Counter value. | 
| Kojto | 93:e188a91d3eaa | 714 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 715 | */ | 
| Kojto | 93:e188a91d3eaa | 716 | #define PCD_SET_EP_TX_CNT(USBx, bEpNum,wCount) (*PCD_EP_TX_CNT((USBx), (bEpNum)) = (wCount)) | 
| Kojto | 93:e188a91d3eaa | 717 | #define PCD_SET_EP_RX_CNT(USBx, bEpNum,wCount) {\ | 
| Kojto | 122:f9eeca106725 | 718 | uint16_t *pdwReg =PCD_EP_RX_CNT((USBx),(bEpNum)); \ | 
| Kojto | 122:f9eeca106725 | 719 | PCD_SET_EP_CNT_RX_REG((pdwReg), (wCount))\ | 
| Kojto | 93:e188a91d3eaa | 720 | } | 
| Kojto | 93:e188a91d3eaa | 721 | |
| Kojto | 93:e188a91d3eaa | 722 | /** | 
| Kojto | 93:e188a91d3eaa | 723 | * @brief gets counter of the tx buffer. | 
| Kojto | 93:e188a91d3eaa | 724 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 725 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 726 | * @retval Counter value | 
| Kojto | 93:e188a91d3eaa | 727 | */ | 
| Kojto | 93:e188a91d3eaa | 728 | #define PCD_GET_EP_TX_CNT(USBx, bEpNum)((uint16_t)(*PCD_EP_TX_CNT((USBx), (bEpNum))) & 0x3ff) | 
| Kojto | 93:e188a91d3eaa | 729 | #define PCD_GET_EP_RX_CNT(USBx, bEpNum)((uint16_t)(*PCD_EP_RX_CNT((USBx), (bEpNum))) & 0x3ff) | 
| Kojto | 93:e188a91d3eaa | 730 | |
| Kojto | 93:e188a91d3eaa | 731 | /** | 
| Kojto | 93:e188a91d3eaa | 732 | * @brief Sets buffer 0/1 address in a double buffer endpoint. | 
| Kojto | 93:e188a91d3eaa | 733 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 734 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 735 | * @param wBuf0Addr: buffer 0 address. | 
| Kojto | 93:e188a91d3eaa | 736 | * @retval Counter value | 
| Kojto | 93:e188a91d3eaa | 737 | */ | 
| Kojto | 122:f9eeca106725 | 738 | #define PCD_SET_EP_DBUF0_ADDR(USBx, bEpNum,wBuf0Addr) (PCD_SET_EP_TX_ADDRESS((USBx), (bEpNum), (wBuf0Addr))) | 
| Kojto | 122:f9eeca106725 | 739 | #define PCD_SET_EP_DBUF1_ADDR(USBx, bEpNum,wBuf1Addr) (PCD_SET_EP_RX_ADDRESS((USBx), (bEpNum), (wBuf1Addr))) | 
| Kojto | 93:e188a91d3eaa | 740 | |
| Kojto | 93:e188a91d3eaa | 741 | /** | 
| Kojto | 93:e188a91d3eaa | 742 | * @brief Sets addresses in a double buffer endpoint. | 
| Kojto | 93:e188a91d3eaa | 743 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 744 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 745 | * @param wBuf0Addr: buffer 0 address. | 
| Kojto | 93:e188a91d3eaa | 746 | * @param wBuf1Addr = buffer 1 address. | 
| Kojto | 93:e188a91d3eaa | 747 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 748 | */ | 
| Kojto | 93:e188a91d3eaa | 749 | #define PCD_SET_EP_DBUF_ADDR(USBx, bEpNum,wBuf0Addr,wBuf1Addr) { \ | 
| Kojto | 93:e188a91d3eaa | 750 | PCD_SET_EP_DBUF0_ADDR((USBx), (bEpNum), (wBuf0Addr));\ | 
| Kojto | 93:e188a91d3eaa | 751 | PCD_SET_EP_DBUF1_ADDR((USBx), (bEpNum), (wBuf1Addr));\ | 
| Kojto | 93:e188a91d3eaa | 752 | } /* PCD_SET_EP_DBUF_ADDR */ | 
| Kojto | 93:e188a91d3eaa | 753 | |
| Kojto | 93:e188a91d3eaa | 754 | /** | 
| Kojto | 93:e188a91d3eaa | 755 | * @brief Gets buffer 0/1 address of a double buffer endpoint. | 
| Kojto | 93:e188a91d3eaa | 756 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 757 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 758 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 759 | */ | 
| Kojto | 93:e188a91d3eaa | 760 | #define PCD_GET_EP_DBUF0_ADDR(USBx, bEpNum) (PCD_GET_EP_TX_ADDRESS((USBx), (bEpNum))) | 
| Kojto | 93:e188a91d3eaa | 761 | #define PCD_GET_EP_DBUF1_ADDR(USBx, bEpNum) (PCD_GET_EP_RX_ADDRESS((USBx), (bEpNum))) | 
| Kojto | 93:e188a91d3eaa | 762 | |
| Kojto | 93:e188a91d3eaa | 763 | /** | 
| Kojto | 93:e188a91d3eaa | 764 | * @brief Gets buffer 0/1 address of a double buffer endpoint. | 
| Kojto | 93:e188a91d3eaa | 765 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 766 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 767 | * @param bDir: endpoint dir EP_DBUF_OUT = OUT | 
| Kojto | 93:e188a91d3eaa | 768 | * EP_DBUF_IN = IN | 
| Kojto | 93:e188a91d3eaa | 769 | * @param wCount: Counter value | 
| Kojto | 93:e188a91d3eaa | 770 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 771 | */ | 
| Kojto | 93:e188a91d3eaa | 772 | #define PCD_SET_EP_DBUF0_CNT(USBx, bEpNum, bDir, wCount) { \ | 
| Kojto | 93:e188a91d3eaa | 773 | if((bDir) == PCD_EP_DBUF_OUT)\ | 
| Kojto | 93:e188a91d3eaa | 774 | /* OUT endpoint */ \ | 
| Kojto | 122:f9eeca106725 | 775 | {PCD_SET_EP_RX_DBUF0_CNT((USBx), (bEpNum),(wCount))} \ | 
| Kojto | 93:e188a91d3eaa | 776 | else if((bDir) == PCD_EP_DBUF_IN)\ | 
| Kojto | 122:f9eeca106725 | 777 | { \ | 
| Kojto | 93:e188a91d3eaa | 778 | *PCD_EP_TX_CNT((USBx), (bEpNum)) = (uint32_t)(wCount); \ | 
| Kojto | 122:f9eeca106725 | 779 | } \ | 
| Kojto | 93:e188a91d3eaa | 780 | } /* SetEPDblBuf0Count*/ | 
| Kojto | 93:e188a91d3eaa | 781 | |
| Kojto | 93:e188a91d3eaa | 782 | #define PCD_SET_EP_DBUF1_CNT(USBx, bEpNum, bDir, wCount) { \ | 
| Kojto | 93:e188a91d3eaa | 783 | if((bDir) == PCD_EP_DBUF_OUT)\ | 
| Kojto | 122:f9eeca106725 | 784 | {/* OUT endpoint */ \ | 
| Kojto | 122:f9eeca106725 | 785 | PCD_SET_EP_RX_CNT((USBx), (bEpNum),(wCount)) \ | 
| Kojto | 122:f9eeca106725 | 786 | } \ | 
| Kojto | 93:e188a91d3eaa | 787 | else if((bDir) == PCD_EP_DBUF_IN)\ | 
| Kojto | 122:f9eeca106725 | 788 | {/* IN endpoint */ \ | 
| Kojto | 108:34e6b704fe68 | 789 | *PCD_EP_TX_CNT((USBx), (bEpNum)) = (uint32_t)(wCount); \ | 
| Kojto | 122:f9eeca106725 | 790 | } \ | 
| Kojto | 122:f9eeca106725 | 791 | } /* SetEPDblBuf1Count */ | 
| Kojto | 93:e188a91d3eaa | 792 | |
| Kojto | 93:e188a91d3eaa | 793 | #define PCD_SET_EP_DBUF_CNT(USBx, bEpNum, bDir, wCount) {\ | 
| Kojto | 122:f9eeca106725 | 794 | PCD_SET_EP_DBUF0_CNT((USBx), (bEpNum), (bDir), (wCount)) \ | 
| Kojto | 122:f9eeca106725 | 795 | PCD_SET_EP_DBUF1_CNT((USBx), (bEpNum), (bDir), (wCount)) \ | 
| Kojto | 93:e188a91d3eaa | 796 | } /* PCD_SET_EP_DBUF_CNT */ | 
| Kojto | 93:e188a91d3eaa | 797 | |
| Kojto | 93:e188a91d3eaa | 798 | /** | 
| Kojto | 93:e188a91d3eaa | 799 | * @brief Gets buffer 0/1 rx/tx counter for double buffering. | 
| Kojto | 93:e188a91d3eaa | 800 | * @param USBx: USB peripheral instance register address. | 
| Kojto | 93:e188a91d3eaa | 801 | * @param bEpNum: Endpoint Number. | 
| Kojto | 93:e188a91d3eaa | 802 | * @retval None | 
| Kojto | 93:e188a91d3eaa | 803 | */ | 
| Kojto | 93:e188a91d3eaa | 804 | #define PCD_GET_EP_DBUF0_CNT(USBx, bEpNum) (PCD_GET_EP_TX_CNT((USBx), (bEpNum))) | 
| Kojto | 93:e188a91d3eaa | 805 | #define PCD_GET_EP_DBUF1_CNT(USBx, bEpNum) (PCD_GET_EP_RX_CNT((USBx), (bEpNum))) | 
| Kojto | 93:e188a91d3eaa | 806 | |
| Kojto | 108:34e6b704fe68 | 807 | /** @defgroup PCD_Instance_definition PCD Instance definition | 
| Kojto | 93:e188a91d3eaa | 808 | * @{ | 
| Kojto | 93:e188a91d3eaa | 809 | */ | 
| Kojto | 108:34e6b704fe68 | 810 | #define IS_PCD_ALL_INSTANCE IS_USB_ALL_INSTANCE | 
| Kojto | 93:e188a91d3eaa | 811 | /** | 
| Kojto | 93:e188a91d3eaa | 812 | * @} | 
| Kojto | 93:e188a91d3eaa | 813 | */ | 
| Kojto | 93:e188a91d3eaa | 814 | |
| Kojto | 93:e188a91d3eaa | 815 | /** | 
| Kojto | 93:e188a91d3eaa | 816 | * @} | 
| Kojto | 93:e188a91d3eaa | 817 | */ | 
| Kojto | 93:e188a91d3eaa | 818 | |
| Kojto | 93:e188a91d3eaa | 819 | /** | 
| Kojto | 93:e188a91d3eaa | 820 | * @} | 
| Kojto | 93:e188a91d3eaa | 821 | */ | 
| Kojto | 93:e188a91d3eaa | 822 | |
| Kojto | 93:e188a91d3eaa | 823 | /** | 
| Kojto | 93:e188a91d3eaa | 824 | * @} | 
| Kojto | 93:e188a91d3eaa | 825 | */ | 
| Kojto | 93:e188a91d3eaa | 826 | |
| Kojto | 93:e188a91d3eaa | 827 | #endif /* STM32F042x6 || STM32F072xB || STM32F078xx || STM32F070xB || STM32F070x6 */ | 
| Kojto | 93:e188a91d3eaa | 828 | |
| Kojto | 93:e188a91d3eaa | 829 | #ifdef __cplusplus | 
| Kojto | 93:e188a91d3eaa | 830 | } | 
| Kojto | 93:e188a91d3eaa | 831 | #endif | 
| Kojto | 93:e188a91d3eaa | 832 | |
| Kojto | 93:e188a91d3eaa | 833 | |
| Kojto | 93:e188a91d3eaa | 834 | #endif /* __STM32F0xx_HAL_PCD_H */ | 
| Kojto | 93:e188a91d3eaa | 835 | |
| Kojto | 93:e188a91d3eaa | 836 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | 
| Kojto | 93:e188a91d3eaa | 837 | 


