1 /**
2   ******************************************************************************
3   * @file    stm32l1xx_ll_usb.h
4   * @author  MCD Application Team
5   * @brief   Header file of USB Low Layer HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.</center></h2>
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32L1xx_LL_USB_H
22 #define STM32L1xx_LL_USB_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32l1xx_hal_def.h"
30 
31 #if defined (USB)
32 /** @addtogroup STM32L1xx_HAL_Driver
33   * @{
34   */
35 
36 /** @addtogroup USB_LL
37   * @{
38   */
39 
40 /* Exported types ------------------------------------------------------------*/
41 
42 /**
43   * @brief  USB Mode definition
44   */
45 
46 
47 
48 typedef enum
49 {
50   USB_DEVICE_MODE  = 0
51 } USB_ModeTypeDef;
52 
53 /**
54   * @brief  USB Initialization Structure definition
55   */
56 typedef struct
57 {
58   uint32_t dev_endpoints;           /*!< Device Endpoints number.
59                                          This parameter depends on the used USB core.
60                                          This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
61 
62   uint32_t speed;                   /*!< USB Core speed.
63                                          This parameter can be any value of @ref PCD_Speed/HCD_Speed
64                                                                                  (HCD_SPEED_xxx, HCD_SPEED_xxx) */
65 
66   uint32_t ep0_mps;                 /*!< Set the Endpoint 0 Max Packet size.                                    */
67 
68   uint32_t phy_itface;              /*!< Select the used PHY interface.
69                                          This parameter can be any value of @ref PCD_PHY_Module/HCD_PHY_Module  */
70 
71   uint32_t Sof_enable;              /*!< Enable or disable the output of the SOF signal.                        */
72 
73   uint32_t low_power_enable;        /*!< Enable or disable Low Power mode                                       */
74 
75   uint32_t lpm_enable;              /*!< Enable or disable Battery charging.                                    */
76 
77   uint32_t battery_charging_enable; /*!< Enable or disable Battery charging.                                    */
78 } USB_CfgTypeDef;
79 
80 typedef struct
81 {
82   uint8_t   num;             /*!< Endpoint number
83                                   This parameter must be a number between Min_Data = 1 and Max_Data = 15    */
84 
85   uint8_t   is_in;           /*!< Endpoint direction
86                                   This parameter must be a number between Min_Data = 0 and Max_Data = 1     */
87 
88   uint8_t   is_stall;        /*!< Endpoint stall condition
89                                   This parameter must be a number between Min_Data = 0 and Max_Data = 1     */
90 
91   uint8_t   type;            /*!< Endpoint type
92                                   This parameter can be any value of @ref USB_EP_Type                       */
93 
94   uint8_t   data_pid_start;  /*!< Initial data PID
95                                   This parameter must be a number between Min_Data = 0 and Max_Data = 1     */
96 
97   uint16_t  pmaadress;       /*!< PMA Address
98                                   This parameter can be any value between Min_addr = 0 and Max_addr = 1K    */
99 
100   uint16_t  pmaaddr0;        /*!< PMA Address0
101                                   This parameter can be any value between Min_addr = 0 and Max_addr = 1K    */
102 
103   uint16_t  pmaaddr1;        /*!< PMA Address1
104                                   This parameter can be any value between Min_addr = 0 and Max_addr = 1K    */
105 
106   uint8_t   doublebuffer;    /*!< Double buffer enable
107                                   This parameter can be 0 or 1                                              */
108 
109   uint16_t  tx_fifo_num;     /*!< This parameter is not required by USB Device FS peripheral, it is used
110                                   only by USB OTG FS peripheral
111                                   This parameter is added to ensure compatibility across USB peripherals    */
112 
113   uint32_t  maxpacket;       /*!< Endpoint Max packet size
114                                   This parameter must be a number between Min_Data = 0 and Max_Data = 64KB  */
115 
116   uint8_t   *xfer_buff;      /*!< Pointer to transfer buffer                                                */
117 
118   uint32_t  xfer_len;        /*!< Current transfer length                                                   */
119 
120   uint32_t  xfer_count;      /*!< Partial transfer length in case of multi packet transfer                  */
121 
122   uint32_t  xfer_len_db;      /*!< double buffer transfer length used with bulk double buffer in           */
123 
124   uint8_t   xfer_fill_db;     /*!< double buffer Need to Fill new buffer  used with bulk_in                */
125 
126 } USB_EPTypeDef;
127 
128 
129 /* Exported constants --------------------------------------------------------*/
130 
131 /** @defgroup PCD_Exported_Constants PCD Exported Constants
132   * @{
133   */
134 
135 
136 /** @defgroup USB_LL_EP0_MPS USB Low Layer EP0 MPS
137   * @{
138   */
139 #define EP_MPS_64                              0U
140 #define EP_MPS_32                              1U
141 #define EP_MPS_16                              2U
142 #define EP_MPS_8                               3U
143 /**
144   * @}
145   */
146 
147 /** @defgroup USB_LL_EP_Type USB Low Layer EP Type
148   * @{
149   */
150 #define EP_TYPE_CTRL                           0U
151 #define EP_TYPE_ISOC                           1U
152 #define EP_TYPE_BULK                           2U
153 #define EP_TYPE_INTR                           3U
154 #define EP_TYPE_MSK                            3U
155 /**
156   * @}
157   */
158 
159 /** @defgroup USB_LL Device Speed
160   * @{
161   */
162 #define USBD_FS_SPEED                          2U
163 /**
164   * @}
165   */
166 
167 #define BTABLE_ADDRESS                         0x000U
168 #define PMA_ACCESS                             2U
169 
170 #define EP_ADDR_MSK                            0x7U
171 /**
172   * @}
173   */
174 
175 /* Exported macro ------------------------------------------------------------*/
176 /**
177   * @}
178   */
179 
180 /* Exported functions --------------------------------------------------------*/
181 /** @addtogroup USB_LL_Exported_Functions USB Low Layer Exported Functions
182   * @{
183   */
184 
185 
186 HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg);
187 HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg);
188 HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx);
189 HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx);
190 HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode);
191 
192 #if defined (HAL_PCD_MODULE_ENABLED)
193 HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep);
194 HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep);
195 HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep);
196 HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep);
197 HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep);
198 #endif
199 
200 HAL_StatusTypeDef USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address);
201 HAL_StatusTypeDef USB_DevConnect(USB_TypeDef *USBx);
202 HAL_StatusTypeDef USB_DevDisconnect(USB_TypeDef *USBx);
203 HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx);
204 uint32_t          USB_ReadInterrupts(USB_TypeDef *USBx);
205 HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx);
206 HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx);
207 
208 void              USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf,
209                                uint16_t wPMABufAddr, uint16_t wNBytes);
210 
211 void              USB_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf,
212                               uint16_t wPMABufAddr, uint16_t wNBytes);
213 
214 /**
215   * @}
216   */
217 
218 /**
219   * @}
220   */
221 
222 /**
223   * @}
224   */
225 
226 /**
227   * @}
228   */
229 #endif /* defined (USB) */
230 
231 #ifdef __cplusplus
232 }
233 #endif
234 
235 
236 #endif /* STM32L1xx_LL_USB_H */
237 
238 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
239