Mouse code for the MacroRat
mbed-dev/targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_hal_pcd_ex.c@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /** |
sahilmgandhi | 18:6a4db94011d3 | 2 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @file stm32f2xx_hal_pcd_ex.c |
sahilmgandhi | 18:6a4db94011d3 | 4 | * @author MCD Application Team |
sahilmgandhi | 18:6a4db94011d3 | 5 | * @version V1.1.3 |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @date 29-June-2016 |
sahilmgandhi | 18:6a4db94011d3 | 7 | * @brief PCD HAL module driver. |
sahilmgandhi | 18:6a4db94011d3 | 8 | * This file provides firmware functions to manage the following |
sahilmgandhi | 18:6a4db94011d3 | 9 | * functionalities of the USB Peripheral Controller: |
sahilmgandhi | 18:6a4db94011d3 | 10 | * + Extended features functions |
sahilmgandhi | 18:6a4db94011d3 | 11 | * |
sahilmgandhi | 18:6a4db94011d3 | 12 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 13 | * @attention |
sahilmgandhi | 18:6a4db94011d3 | 14 | * |
sahilmgandhi | 18:6a4db94011d3 | 15 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
sahilmgandhi | 18:6a4db94011d3 | 16 | * |
sahilmgandhi | 18:6a4db94011d3 | 17 | * Redistribution and use in source and binary forms, with or without modification, |
sahilmgandhi | 18:6a4db94011d3 | 18 | * are permitted provided that the following conditions are met: |
sahilmgandhi | 18:6a4db94011d3 | 19 | * 1. Redistributions of source code must retain the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 20 | * this list of conditions and the following disclaimer. |
sahilmgandhi | 18:6a4db94011d3 | 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 22 | * this list of conditions and the following disclaimer in the documentation |
sahilmgandhi | 18:6a4db94011d3 | 23 | * and/or other materials provided with the distribution. |
sahilmgandhi | 18:6a4db94011d3 | 24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
sahilmgandhi | 18:6a4db94011d3 | 25 | * may be used to endorse or promote products derived from this software |
sahilmgandhi | 18:6a4db94011d3 | 26 | * without specific prior written permission. |
sahilmgandhi | 18:6a4db94011d3 | 27 | * |
sahilmgandhi | 18:6a4db94011d3 | 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
sahilmgandhi | 18:6a4db94011d3 | 29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
sahilmgandhi | 18:6a4db94011d3 | 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
sahilmgandhi | 18:6a4db94011d3 | 31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
sahilmgandhi | 18:6a4db94011d3 | 32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
sahilmgandhi | 18:6a4db94011d3 | 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
sahilmgandhi | 18:6a4db94011d3 | 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
sahilmgandhi | 18:6a4db94011d3 | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
sahilmgandhi | 18:6a4db94011d3 | 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
sahilmgandhi | 18:6a4db94011d3 | 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
sahilmgandhi | 18:6a4db94011d3 | 38 | * |
sahilmgandhi | 18:6a4db94011d3 | 39 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 40 | */ |
sahilmgandhi | 18:6a4db94011d3 | 41 | |
sahilmgandhi | 18:6a4db94011d3 | 42 | /* Includes ------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 43 | #include "stm32f2xx_hal.h" |
sahilmgandhi | 18:6a4db94011d3 | 44 | |
sahilmgandhi | 18:6a4db94011d3 | 45 | /** @addtogroup STM32F2xx_HAL_Driver |
sahilmgandhi | 18:6a4db94011d3 | 46 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 47 | */ |
sahilmgandhi | 18:6a4db94011d3 | 48 | |
sahilmgandhi | 18:6a4db94011d3 | 49 | /** @defgroup PCDEx PCDEx |
sahilmgandhi | 18:6a4db94011d3 | 50 | * @brief PCD Extended HAL module driver |
sahilmgandhi | 18:6a4db94011d3 | 51 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 52 | */ |
sahilmgandhi | 18:6a4db94011d3 | 53 | #ifdef HAL_PCD_MODULE_ENABLED |
sahilmgandhi | 18:6a4db94011d3 | 54 | |
sahilmgandhi | 18:6a4db94011d3 | 55 | /* Private types -------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 56 | /* Private variables ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 57 | /* Private constants ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 58 | /* Private macros ------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 59 | /* Private functions ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 60 | /* Exported functions --------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 61 | |
sahilmgandhi | 18:6a4db94011d3 | 62 | /** @defgroup PCDEx_Exported_Functions PCD Extended Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 63 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 64 | */ |
sahilmgandhi | 18:6a4db94011d3 | 65 | |
sahilmgandhi | 18:6a4db94011d3 | 66 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions |
sahilmgandhi | 18:6a4db94011d3 | 67 | * @brief PCDEx control functions |
sahilmgandhi | 18:6a4db94011d3 | 68 | * |
sahilmgandhi | 18:6a4db94011d3 | 69 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 70 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 71 | ##### Extended features functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 72 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 73 | [..] This section provides functions allowing to: |
sahilmgandhi | 18:6a4db94011d3 | 74 | (+) Update FIFO configuration |
sahilmgandhi | 18:6a4db94011d3 | 75 | |
sahilmgandhi | 18:6a4db94011d3 | 76 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 77 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 78 | */ |
sahilmgandhi | 18:6a4db94011d3 | 79 | |
sahilmgandhi | 18:6a4db94011d3 | 80 | /** |
sahilmgandhi | 18:6a4db94011d3 | 81 | * @brief Set Tx FIFO |
sahilmgandhi | 18:6a4db94011d3 | 82 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 83 | * @param fifo: The number of Tx fifo |
sahilmgandhi | 18:6a4db94011d3 | 84 | * @param size: Fifo size |
sahilmgandhi | 18:6a4db94011d3 | 85 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 86 | */ |
sahilmgandhi | 18:6a4db94011d3 | 87 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size) |
sahilmgandhi | 18:6a4db94011d3 | 88 | { |
sahilmgandhi | 18:6a4db94011d3 | 89 | uint8_t i = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 90 | uint32_t Tx_Offset = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 91 | |
sahilmgandhi | 18:6a4db94011d3 | 92 | /* TXn min size = 16 words. (n : Transmit FIFO index) |
sahilmgandhi | 18:6a4db94011d3 | 93 | When a TxFIFO is not used, the Configuration should be as follows: |
sahilmgandhi | 18:6a4db94011d3 | 94 | case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes) |
sahilmgandhi | 18:6a4db94011d3 | 95 | --> Txm can use the space allocated for Txn. |
sahilmgandhi | 18:6a4db94011d3 | 96 | case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes) |
sahilmgandhi | 18:6a4db94011d3 | 97 | --> Txn should be configured with the minimum space of 16 words |
sahilmgandhi | 18:6a4db94011d3 | 98 | The FIFO is used optimally when used TxFIFOs are allocated in the top |
sahilmgandhi | 18:6a4db94011d3 | 99 | of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones. |
sahilmgandhi | 18:6a4db94011d3 | 100 | When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */ |
sahilmgandhi | 18:6a4db94011d3 | 101 | |
sahilmgandhi | 18:6a4db94011d3 | 102 | Tx_Offset = hpcd->Instance->GRXFSIZ; |
sahilmgandhi | 18:6a4db94011d3 | 103 | |
sahilmgandhi | 18:6a4db94011d3 | 104 | if(fifo == 0U) |
sahilmgandhi | 18:6a4db94011d3 | 105 | { |
sahilmgandhi | 18:6a4db94011d3 | 106 | hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (uint32_t)(((uint32_t)size << 16U) | Tx_Offset); |
sahilmgandhi | 18:6a4db94011d3 | 107 | } |
sahilmgandhi | 18:6a4db94011d3 | 108 | else |
sahilmgandhi | 18:6a4db94011d3 | 109 | { |
sahilmgandhi | 18:6a4db94011d3 | 110 | Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16U; |
sahilmgandhi | 18:6a4db94011d3 | 111 | for (i = 0U; i < (fifo - 1U); i++) |
sahilmgandhi | 18:6a4db94011d3 | 112 | { |
sahilmgandhi | 18:6a4db94011d3 | 113 | Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16U); |
sahilmgandhi | 18:6a4db94011d3 | 114 | } |
sahilmgandhi | 18:6a4db94011d3 | 115 | |
sahilmgandhi | 18:6a4db94011d3 | 116 | /* Multiply Tx_Size by 2 to get higher performance */ |
sahilmgandhi | 18:6a4db94011d3 | 117 | hpcd->Instance->DIEPTXF[fifo - 1U] = (uint32_t)(((uint32_t)size << 16U) | Tx_Offset); |
sahilmgandhi | 18:6a4db94011d3 | 118 | } |
sahilmgandhi | 18:6a4db94011d3 | 119 | |
sahilmgandhi | 18:6a4db94011d3 | 120 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 121 | } |
sahilmgandhi | 18:6a4db94011d3 | 122 | |
sahilmgandhi | 18:6a4db94011d3 | 123 | /** |
sahilmgandhi | 18:6a4db94011d3 | 124 | * @brief Set Rx FIFO |
sahilmgandhi | 18:6a4db94011d3 | 125 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 126 | * @param size: Size of Rx fifo |
sahilmgandhi | 18:6a4db94011d3 | 127 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 128 | */ |
sahilmgandhi | 18:6a4db94011d3 | 129 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size) |
sahilmgandhi | 18:6a4db94011d3 | 130 | { |
sahilmgandhi | 18:6a4db94011d3 | 131 | hpcd->Instance->GRXFSIZ = size; |
sahilmgandhi | 18:6a4db94011d3 | 132 | |
sahilmgandhi | 18:6a4db94011d3 | 133 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 134 | } |
sahilmgandhi | 18:6a4db94011d3 | 135 | |
sahilmgandhi | 18:6a4db94011d3 | 136 | /** |
sahilmgandhi | 18:6a4db94011d3 | 137 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 138 | */ |
sahilmgandhi | 18:6a4db94011d3 | 139 | |
sahilmgandhi | 18:6a4db94011d3 | 140 | /** |
sahilmgandhi | 18:6a4db94011d3 | 141 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 142 | */ |
sahilmgandhi | 18:6a4db94011d3 | 143 | |
sahilmgandhi | 18:6a4db94011d3 | 144 | #endif /* HAL_PCD_MODULE_ENABLED */ |
sahilmgandhi | 18:6a4db94011d3 | 145 | /** |
sahilmgandhi | 18:6a4db94011d3 | 146 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 147 | */ |
sahilmgandhi | 18:6a4db94011d3 | 148 | |
sahilmgandhi | 18:6a4db94011d3 | 149 | /** |
sahilmgandhi | 18:6a4db94011d3 | 150 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 151 | */ |
sahilmgandhi | 18:6a4db94011d3 | 152 | |
sahilmgandhi | 18:6a4db94011d3 | 153 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |