Updated and Validated
[betaflight.git] / lib / main / STM32_USB-FS-Device_Driver / src / usb_sil.c
blob5f2e4db0074b0c8a98b96a9d8c72cd10c46e546c
1 /**
2 ******************************************************************************
3 * @file usb_sil.c
4 * @author MCD Application Team
5 * @version V4.0.0
6 * @date 28-August-2012
7 * @brief Simplified Interface Layer for Global Initialization and Endpoint
8 * Rea/Write operations.
9 ******************************************************************************
10 * @attention
12 * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
14 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
15 * You may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at:
18 * http://www.st.com/software_license_agreement_liberty_v2
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
26 ******************************************************************************
30 /* Includes ------------------------------------------------------------------*/
31 #include "usb_lib.h"
33 /* Private typedef -----------------------------------------------------------*/
34 /* Private define ------------------------------------------------------------*/
35 /* Private macro -------------------------------------------------------------*/
36 /* Private variables ---------------------------------------------------------*/
37 /* Extern variables ----------------------------------------------------------*/
38 /* Private function prototypes -----------------------------------------------*/
39 /* Private functions ---------------------------------------------------------*/
41 /*******************************************************************************
42 * Function Name : USB_SIL_Init
43 * Description : Initialize the USB Device IP and the Endpoint 0.
44 * Input : None.
45 * Output : None.
46 * Return : Status.
47 *******************************************************************************/
48 uint32_t USB_SIL_Init(void)
50 /* USB interrupts initialization */
51 /* clear pending interrupts */
52 _SetISTR(0);
53 wInterrupt_Mask = IMR_MSK;
54 /* set interrupts mask */
55 _SetCNTR(wInterrupt_Mask);
56 return 0;
59 /*******************************************************************************
60 * Function Name : USB_SIL_Write
61 * Description : Write a buffer of data to a selected endpoint.
62 * Input : - bEpAddr: The address of the non control endpoint.
63 * - pBufferPointer: The pointer to the buffer of data to be written
64 * to the endpoint.
65 * - wBufferSize: Number of data to be written (in bytes).
66 * Output : None.
67 * Return : Status.
68 *******************************************************************************/
69 uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize)
71 /* Use the memory interface function to write to the selected endpoint */
72 UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize);
74 /* Update the data length in the control register */
75 SetEPTxCount((bEpAddr & 0x7F), wBufferSize);
77 return 0;
80 /*******************************************************************************
81 * Function Name : USB_SIL_Read
82 * Description : Write a buffer of data to a selected endpoint.
83 * Input : - bEpAddr: The address of the non control endpoint.
84 * - pBufferPointer: The pointer to which will be saved the
85 * received data buffer.
86 * Output : None.
87 * Return : Number of received data (in Bytes).
88 *******************************************************************************/
89 uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer)
91 uint32_t DataLength = 0;
93 /* Get the number of received data on the selected Endpoint */
94 DataLength = GetEPRxCount(bEpAddr & 0x7F);
96 /* Use the memory interface function to write to the selected endpoint */
97 PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength);
99 /* Return the number of received data */
100 return DataLength;
103 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/