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.
m480_gpio.c
00001 /**************************************************************************//** 00002 * @file gpio.c 00003 * @version V3.00 00004 * @brief M480 series GPIO driver source file 00005 * 00006 * @copyright (C) 2011~2016 Nuvoton Technology Corp. All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without modification, 00009 * are permitted provided that the following conditions are met: 00010 * 1. Redistributions of source code must retain the above copyright notice, 00011 * this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright notice, 00013 * this list of conditions and the following disclaimer in the documentation 00014 * and/or other materials provided with the distribution. 00015 * 3. Neither the name of Nuvoton Technology Corp. nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software 00017 * without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00024 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00025 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00026 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00027 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 *****************************************************************************/ 00030 00031 #include "NuMicro.h" 00032 00033 /** @addtogroup Standard_Driver Standard Driver 00034 @{ 00035 */ 00036 00037 /** @addtogroup GPIO_Driver GPIO Driver 00038 @{ 00039 */ 00040 00041 /** @addtogroup GPIO_EXPORTED_FUNCTIONS GPIO Exported Functions 00042 @{ 00043 */ 00044 00045 /** 00046 * @brief Set GPIO operation mode 00047 * 00048 * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH. 00049 * @param[in] u32PinMask The single or multiple pins of specified GPIO port. 00050 * It could be BIT0 ~ BIT15 for PA, PB, PC, PD, PF and PH GPIO port. 00051 * It could be BIT0 ~ BIT13 for PE GPIO port. 00052 * It could be BIT0 ~ BIT11 for PG GPIO port. 00053 * @param[in] u32Mode Operation mode. It could be \n 00054 * GPIO_MODE_INPUT, GPIO_MODE_OUTPUT, GPIO_MODE_OPEN_DRAIN, GPIO_MODE_QUASI. 00055 * 00056 * @return None 00057 * 00058 * @details This function is used to set specified GPIO operation mode. 00059 */ 00060 void GPIO_SetMode(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode) 00061 { 00062 uint32_t i; 00063 00064 for (i = 0ul; i < GPIO_PIN_MAX; i++) { 00065 if ((u32PinMask & (1ul << i)) == (1ul << i)) { 00066 port->MODE = (port->MODE & ~(0x3ul << (i << 1))) | (u32Mode << (i << 1)); 00067 } 00068 } 00069 } 00070 00071 /** 00072 * @brief Enable GPIO interrupt 00073 * 00074 * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH. 00075 * @param[in] u32Pin The pin of specified GPIO port. 00076 * It could be 0 ~ 15 for PA, PB, PC, PD, PF and PH GPIO port. 00077 * It could be 0 ~ 13 for PE GPIO port. 00078 * It could be 0 ~ 11 for PG GPIO port. 00079 * @param[in] u32IntAttribs The interrupt attribute of specified GPIO pin. It could be \n 00080 * GPIO_INT_RISING, GPIO_INT_FALLING, GPIO_INT_BOTH_EDGE, GPIO_INT_HIGH, GPIO_INT_LOW. 00081 * 00082 * @return None 00083 * 00084 * @details This function is used to enable specified GPIO pin interrupt. 00085 */ 00086 void GPIO_EnableInt(GPIO_T *port, uint32_t u32Pin, uint32_t u32IntAttribs) 00087 { 00088 port->INTTYPE = (port->INTTYPE & ~(1ul << u32Pin)) | (((u32IntAttribs >> 24) & 0xFFUL) << u32Pin); 00089 port->INTEN = (port->INTEN & ~(0x00010001ul << u32Pin)) | ((u32IntAttribs & 0xFFFFFFUL) << u32Pin); 00090 } 00091 00092 00093 /** 00094 * @brief Disable GPIO interrupt 00095 * 00096 * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH. 00097 * @param[in] u32Pin The pin of specified GPIO port. 00098 * It could be 0 ~ 15 for PA, PB, PC, PD, PF and PH GPIO port. 00099 * It could be 0 ~ 13 for PE GPIO port. 00100 * It could be 0 ~ 11 for PG GPIO port. 00101 * 00102 * @return None 00103 * 00104 * @details This function is used to disable specified GPIO pin interrupt. 00105 */ 00106 void GPIO_DisableInt(GPIO_T *port, uint32_t u32Pin) 00107 { 00108 port->INTTYPE &= ~(1UL << u32Pin); 00109 port->INTEN &= ~((0x00010001UL) << u32Pin); 00110 } 00111 00112 /** 00113 * @brief Set GPIO slew rate control 00114 * 00115 * @param[in] port GPIO port. It could be \ref PA, \ref PB, ... or \ref GPH 00116 * @param[in] u32PinMask The single or multiple pins of specified GPIO port. 00117 * @param[in] u32Mode Slew rate mode. \ref GPIO_SLEWCTL_NORMAL (maximum 40 MHz at 2.7V) 00118 * \ref GPIO_SLEWCTL_HIGH (maximum 80 MHz at 2.7V) 00119 * \ref GPIO_SLEWCTL_FAST (maximum 100 MHz at 2.7V) 00120 * 00121 * @return None 00122 * 00123 * @details This function is used to set specified GPIO operation mode. 00124 */ 00125 void GPIO_SetSlewCtl(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode) 00126 { 00127 uint32_t i; 00128 00129 for (i = 0ul; i < GPIO_PIN_MAX; i++) { 00130 if (u32PinMask & (1ul << i)) { 00131 port->SLEWCTL = (port->SLEWCTL & ~(0x3ul << (i << 1))) | (u32Mode << (i << 1)); 00132 } 00133 } 00134 } 00135 00136 /** 00137 * @brief Set GPIO Pull-up and Pull-down control 00138 * 00139 * @param[in] port GPIO port. It could be \ref PA, \ref PB, ... or \ref GPH 00140 * @param[in] u32PinMask The pin of specified GPIO port. It could be 0 ~ 15. 00141 * @param[in] u32Mode The pin mode of specified GPIO pin. It could be 00142 * \ref GPIO_PUSEL_DISABLE 00143 * \ref GPIO_PUSEL_PULL_UP 00144 * \ref GPIO_PUSEL_PULL_DOWN 00145 * 00146 * @return None 00147 * 00148 * @details Set the pin mode of specified GPIO pin. 00149 */ 00150 void GPIO_SetPullCtl(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode) 00151 { 00152 uint32_t i; 00153 00154 for (i = 0ul; i < GPIO_PIN_MAX; i++) { 00155 if (u32PinMask & (1ul << i)) { 00156 port->PUSEL = (port->PUSEL & ~(0x3ul << (i << 1))) | (u32Mode << (i << 1)); 00157 } 00158 } 00159 } 00160 00161 00162 /*@}*/ /* end of group GPIO_EXPORTED_FUNCTIONS */ 00163 00164 /*@}*/ /* end of group GPIO_Driver */ 00165 00166 /*@}*/ /* end of group Standard_Driver */ 00167 00168 /*** (C) COPYRIGHT 2011~2016 Nuvoton Technology Corp. ***/
Generated on Tue Jul 12 2022 15:37:20 by
1.7.2