1 /**************************************************************************//** 2 * @file ecap.c 3 * @version V3.00 4 5 * @brief Enhanced Input Capture Timer (ECAP) driver source file 6 * 7 * @copyright SPDX-License-Identifier: Apache-2.0 8 * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved. 9 *****************************************************************************/ 10 #include "NuMicro.h" 11 12 13 14 /** @addtogroup Standard_Driver Standard Driver 15 @{ 16 */ 17 18 /** @addtogroup ECAP_Driver ECAP Driver 19 @{ 20 */ 21 22 /** @addtogroup ECAP_EXPORTED_FUNCTIONS ECAP Exported Functions 23 @{ 24 */ 25 26 /** 27 * @brief Enable ECAP function 28 * @param[in] ecap The pointer of the specified ECAP module. 29 * @param[in] u32FuncMask Input capture function select 30 * - \ref ECAP_DISABLE_COMPARE 31 * - \ref ECAP_COMPARE_FUNCTION 32 * @return None 33 * @details This macro enable input capture function and select compare and reload function. 34 */ ECAP_Open(ECAP_T * ecap,uint32_t u32FuncMask)35void ECAP_Open(ECAP_T* ecap, uint32_t u32FuncMask) 36 { 37 /* Clear Input capture mode*/ 38 ecap->CTL0 = ecap->CTL0 & ~(ECAP_CTL0_CMPEN_Msk); 39 40 /* Enable Input Capture and set mode */ 41 ecap->CTL0 |= ECAP_CTL0_CAPEN_Msk | (u32FuncMask); 42 } 43 44 45 46 /** 47 * @brief Disable ECAP function 48 * @param[in] ecap The pointer of the specified ECAP module. 49 * @return None 50 * @details This macro disable input capture function. 51 */ ECAP_Close(ECAP_T * ecap)52void ECAP_Close(ECAP_T* ecap) 53 { 54 /* Disable Input Capture*/ 55 ecap->CTL0 &= ~ECAP_CTL0_CAPEN_Msk; 56 } 57 58 /** 59 * @brief This macro is used to enable input channel interrupt 60 * @param[in] ecap Specify ECAP port 61 * @param[in] u32Mask The input channel Mask 62 * - \ref ECAP_CTL0_CAPIEN0_Msk 63 * - \ref ECAP_CTL0_CAPIEN1_Msk 64 * - \ref ECAP_CTL0_CAPIEN2_Msk 65 * - \ref ECAP_CTL0_OVIEN_Msk 66 * - \ref ECAP_CTL0_CMPIEN_Msk 67 * @return None 68 * @details This macro will enable the input channel_n interrupt. 69 */ ECAP_EnableINT(ECAP_T * ecap,uint32_t u32Mask)70void ECAP_EnableINT(ECAP_T* ecap, uint32_t u32Mask) 71 { 72 /* Enable input channel interrupt */ 73 ecap->CTL0 |= (u32Mask); 74 75 /* Enable NVIC ECAP IRQ */ 76 if((ecap == ECAP0) || (ecap == ECAP0_NS)) 77 { 78 NVIC_EnableIRQ(ECAP0_IRQn); 79 } 80 else 81 { 82 NVIC_EnableIRQ(ECAP1_IRQn); 83 } 84 } 85 86 /** 87 * @brief This macro is used to disable input channel interrupt 88 * @param[in] ecap Specify ECAP port 89 * @param[in] u32Mask The input channel number 90 * - \ref ECAP_CTL0_CAPIEN0_Msk 91 * - \ref ECAP_CTL0_CAPIEN1_Msk 92 * - \ref ECAP_CTL0_CAPIEN2_Msk 93 * - \ref ECAP_CTL0_OVIEN_Msk 94 * - \ref ECAP_CTL0_CMPIEN_Msk 95 * @return None 96 * @details This macro will disable the input channel_n interrupt. 97 */ ECAP_DisableINT(ECAP_T * ecap,uint32_t u32Mask)98void ECAP_DisableINT(ECAP_T* ecap, uint32_t u32Mask) 99 { 100 /* Disable input channel interrupt */ 101 (ecap->CTL0) &= ~(u32Mask); 102 103 /* Disable NVIC ECAP IRQ */ 104 if((ecap == ECAP0) || (ecap == ECAP0_NS)) 105 { 106 NVIC_DisableIRQ(ECAP0_IRQn); 107 } 108 else 109 { 110 NVIC_DisableIRQ(ECAP1_IRQn); 111 } 112 } 113 114 /**@}*/ /* end of group ECAP_EXPORTED_FUNCTIONS */ 115 116 /**@}*/ /* end of group ECAP_Driver */ 117 118 /**@}*/ /* end of group Standard_Driver */ 119