1 /**
2 ******************************************************************************
3 * @file stm32l1xx_hal_pcd_ex.c
4 * @author MCD Application Team
5 * @brief PCD Extended HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the USB Peripheral Controller:
8 * + Extended features functions
9 *
10 ******************************************************************************
11 * @attention
12 *
13 * <h2><center>© Copyright (c) 2016 STMicroelectronics.
14 * All rights reserved.</center></h2>
15 *
16 * This software component is licensed by ST under BSD 3-Clause license,
17 * the "License"; You may not use this file except in compliance with the
18 * License. You may obtain a copy of the License at:
19 * opensource.org/licenses/BSD-3-Clause
20 *
21 ******************************************************************************
22 */
23
24 /* Includes ------------------------------------------------------------------*/
25 #include "stm32l1xx_hal.h"
26
27 /** @addtogroup STM32L1xx_HAL_Driver
28 * @{
29 */
30
31 /** @defgroup PCDEx PCDEx
32 * @brief PCD Extended HAL module driver
33 * @{
34 */
35
36 #ifdef HAL_PCD_MODULE_ENABLED
37
38 #if defined (USB)
39 /* Private types -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* Private constants ---------------------------------------------------------*/
42 /* Private macros ------------------------------------------------------------*/
43 /* Private functions ---------------------------------------------------------*/
44 /* Exported functions --------------------------------------------------------*/
45
46 /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
47 * @{
48 */
49
50 /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
51 * @brief PCDEx control functions
52 *
53 @verbatim
54 ===============================================================================
55 ##### Extended features functions #####
56 ===============================================================================
57 [..] This section provides functions allowing to:
58 (+) Update FIFO configuration
59
60 @endverbatim
61 * @{
62 */
63
64 /**
65 * @brief Configure PMA for EP
66 * @param hpcd Device instance
67 * @param ep_addr endpoint address
68 * @param ep_kind endpoint Kind
69 * USB_SNG_BUF: Single Buffer used
70 * USB_DBL_BUF: Double Buffer used
71 * @param pmaadress: EP address in The PMA: In case of single buffer endpoint
72 * this parameter is 16-bit value providing the address
73 * in PMA allocated to endpoint.
74 * In case of double buffer endpoint this parameter
75 * is a 32-bit value providing the endpoint buffer 0 address
76 * in the LSB part of 32-bit value and endpoint buffer 1 address
77 * in the MSB part of 32-bit value.
78 * @retval HAL status
79 */
80
HAL_PCDEx_PMAConfig(PCD_HandleTypeDef * hpcd,uint16_t ep_addr,uint16_t ep_kind,uint32_t pmaadress)81 HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr,
82 uint16_t ep_kind, uint32_t pmaadress)
83 {
84 PCD_EPTypeDef *ep;
85
86 /* initialize ep structure*/
87 if ((0x80U & ep_addr) == 0x80U)
88 {
89 ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
90 }
91 else
92 {
93 ep = &hpcd->OUT_ep[ep_addr];
94 }
95
96 /* Here we check if the endpoint is single or double Buffer*/
97 if (ep_kind == PCD_SNG_BUF)
98 {
99 /* Single Buffer */
100 ep->doublebuffer = 0U;
101 /* Configure the PMA */
102 ep->pmaadress = (uint16_t)pmaadress;
103 }
104 else /* USB_DBL_BUF */
105 {
106 /* Double Buffer Endpoint */
107 ep->doublebuffer = 1U;
108 /* Configure the PMA */
109 ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU);
110 ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16);
111 }
112
113 return HAL_OK;
114 }
115
116 /**
117 * @brief Software Device Connection,
118 * this function is not required by USB OTG FS peripheral, it is used
119 * only by USB Device FS peripheral.
120 * @param hpcd PCD handle
121 * @param state connection state (0 : disconnected / 1: connected)
122 * @retval None
123 */
HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef * hpcd,uint8_t state)124 __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
125 {
126 /* Prevent unused argument(s) compilation warning */
127 UNUSED(hpcd);
128 UNUSED(state);
129 /* NOTE : This function Should not be modified, when the callback is needed,
130 the HAL_PCDEx_SetConnectionState could be implemented in the user file
131 */
132 }
133
134
135 /**
136 * @brief Send LPM message to user layer callback.
137 * @param hpcd PCD handle
138 * @param msg LPM message
139 * @retval HAL status
140 */
HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef * hpcd,PCD_LPM_MsgTypeDef msg)141 __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
142 {
143 /* Prevent unused argument(s) compilation warning */
144 UNUSED(hpcd);
145 UNUSED(msg);
146
147 /* NOTE : This function should not be modified, when the callback is needed,
148 the HAL_PCDEx_LPM_Callback could be implemented in the user file
149 */
150 }
151
152 /**
153 * @brief Send BatteryCharging message to user layer callback.
154 * @param hpcd PCD handle
155 * @param msg LPM message
156 * @retval HAL status
157 */
HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef * hpcd,PCD_BCD_MsgTypeDef msg)158 __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
159 {
160 /* Prevent unused argument(s) compilation warning */
161 UNUSED(hpcd);
162 UNUSED(msg);
163
164 /* NOTE : This function should not be modified, when the callback is needed,
165 the HAL_PCDEx_BCD_Callback could be implemented in the user file
166 */
167 }
168
169 /**
170 * @}
171 */
172
173 /**
174 * @}
175 */
176 #endif /* defined (USB) */
177 #endif /* HAL_PCD_MODULE_ENABLED */
178
179 /**
180 * @}
181 */
182
183 /**
184 * @}
185 */
186
187 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
188