123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- /**************************************************************************//**
- * @file nu_qei.h
- * @version V3.00
- * @brief Quadrature Encoder Interface (QEI) driver header file
- *
- * SPDX-License-Identifier: Apache-2.0
- * @copyright (C) 2016-2020 Nuvoton Technology Corp. All rights reserved.
- *****************************************************************************/
- #ifndef __NU_QEI_H__
- #define __NU_QEI_H__
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- /** @addtogroup Standard_Driver Standard Driver
- @{
- */
- /** @addtogroup QEI_Driver QEI Driver
- @{
- */
- /** @addtogroup QEI_EXPORTED_CONSTANTS QEI Exported Constants
- @{
- */
- /*---------------------------------------------------------------------------------------------------------*/
- /* QEI counting mode selection constants definitions */
- /*---------------------------------------------------------------------------------------------------------*/
- #define QEI_CTL_X4_FREE_COUNTING_MODE (0x0<<QEI_CTL_MODE_Pos) /*!< QEI operate in X4 free-counting mode \hideinitializer */
- #define QEI_CTL_X2_FREE_COUNTING_MODE (0x1<<QEI_CTL_MODE_Pos) /*!< QEI operate in X2 free-counting mode \hideinitializer */
- #define QEI_CTL_X4_COMPARE_COUNTING_MODE (0x2<<QEI_CTL_MODE_Pos) /*!< QEI operate in X4 compare-counting mode \hideinitializer */
- #define QEI_CTL_X2_COMPARE_COUNTING_MODE (0x3<<QEI_CTL_MODE_Pos) /*!< QEI operate in X2 compare-counting mode \hideinitializer */
- /*---------------------------------------------------------------------------------------------------------*/
- /* QEI noise filter clock pre-divide selection constants definitions */
- /*---------------------------------------------------------------------------------------------------------*/
- #define QEI_CTL_NFCLKSEL_DIV1 (0x0<<QEI_CTL_NFCLKSEL_Pos) /*!< The sampling frequency of the noise filter is QEI_CLK \hideinitializer */
- #define QEI_CTL_NFCLKSEL_DIV2 (0x1<<QEI_CTL_NFCLKSEL_Pos) /*!< The sampling frequency of the noise filter is QEI_CLK/2 \hideinitializer */
- #define QEI_CTL_NFCLKSEL_DIV4 (0x2<<QEI_CTL_NFCLKSEL_Pos) /*!< The sampling frequency of the noise filter is QEI_CLK/4 \hideinitializer */
- #define QEI_CTL_NFCLKSEL_DIV16 (0x3<<QEI_CTL_NFCLKSEL_Pos) /*!< The sampling frequency of the noise filter is QEI_CLK/16 \hideinitializer */
- #define QEI_CTL_NFCLKSEL_DIV32 (0x4<<QEI_CTL_NFCLKSEL_Pos) /*!< The sampling frequency of the noise filter is QEI_CLK/32 \hideinitializer */
- #define QEI_CTL_NFCLKSEL_DIV64 (0x5<<QEI_CTL_NFCLKSEL_Pos) /*!< The sampling frequency of the noise filter is QEI_CLK/64 \hideinitializer */
- /*@}*/ /* end of group QEI_EXPORTED_CONSTANTS */
- /** @addtogroup QEI_EXPORTED_FUNCTIONS QEI Exported Functions
- @{
- */
- /**
- * @brief Disable QEI compare function
- * @param[in] qei The pointer of the specified QEI module.
- * @return None
- * @details This macro disable QEI counter compare function.
- * \hideinitializer
- */
- #define QEI_DISABLE_CNT_CMP(qei) ((qei)->CTL &= (~QEI_CTL_CMPEN_Msk))
- /**
- * @brief Enable QEI compare function
- * @param[in] qei The pointer of the specified QEI module.
- * @return None
- * @details This macro enable QEI counter compare function.
- * \hideinitializer
- */
- #define QEI_ENABLE_CNT_CMP(qei) ((qei)->CTL |= QEI_CTL_CMPEN_Msk)
- /**
- * @brief Disable QEI index latch function
- * @param[in] qei The pointer of the specified QEI module.
- * @return None
- * @details This macro disable QEI index trigger counter latch function.
- * \hideinitializer
- */
- #define QEI_DISABLE_INDEX_LATCH(qei) ((qei)->CTL &= (~QEI_CTL_IDXLATEN_Msk))
- /**
- * @brief Enable QEI index latch function
- * @param[in] qei The pointer of the specified QEI module.
- * @return None
- * @details This macro enable QEI index trigger counter latch function.
- * \hideinitializer
- */
- #define QEI_ENABLE_INDEX_LATCH(qei) ((qei)->CTL |= QEI_CTL_IDXLATEN_Msk)
- /**
- * @brief Disable QEI index reload function
- * @param[in] qei The pointer of the specified QEI module.
- * @return None
- * @details This macro disable QEI index trigger counter reload function.
- * \hideinitializer
- */
- #define QEI_DISABLE_INDEX_RELOAD(qei) ((qei)->CTL &= (~QEI_CTL_IDXRLDEN_Msk))
- /**
- * @brief Enable QEI index reload function
- * @param[in] qei The pointer of the specified QEI module.
- * @return None
- * @details This macro enable QEI index trigger counter reload function.
- * \hideinitializer
- */
- #define QEI_ENABLE_INDEX_RELOAD(qei) ((qei)->CTL |= QEI_CTL_IDXRLDEN_Msk)
- /**
- * @brief Disable QEI input
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32InputType Input signal type.
- * - \ref QEI_CTL_CHAEN_Msk : QEA input
- * - \ref QEI_CTL_CHAEN_Msk : QEB input
- * - \ref QEI_CTL_IDXEN_Msk : IDX input
- * @return None
- * @details This macro disable specified QEI signal input.
- * \hideinitializer
- */
- #define QEI_DISABLE_INPUT(qei, u32InputType) ((qei)->CTL &= ~(u32InputType))
- /**
- * @brief Enable QEI input
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32InputType Input signal type .
- * - \ref QEI_CTL_CHAEN_Msk : QEA input
- * - \ref QEI_CTL_CHBEN_Msk : QEB input
- * - \ref QEI_CTL_IDXEN_Msk : IDX input
- * @return None
- * @details This macro enable specified QEI signal input.
- * \hideinitializer
- */
- #define QEI_ENABLE_INPUT(qei, u32InputType) ((qei)->CTL |= (u32InputType))
- /**
- * @brief Disable inverted input polarity
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32InputType Input signal type .
- * - \ref QEI_CTL_CHAINV_Msk : QEA Input
- * - \ref QEI_CTL_CHBINV_Msk : QEB Input
- * - \ref QEI_CTL_IDXINV_Msk : IDX Input
- * @return None
- * @details This macro disable specified QEI signal inverted input polarity.
- * \hideinitializer
- */
- #define QEI_DISABLE_INPUT_INV(qei, u32InputType) ((qei)->CTL &= ~(u32InputType))
- /**
- * @brief Enable inverted input polarity
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32InputType Input signal type.
- * - \ref QEI_CTL_CHAINV_Msk : QEA Input
- * - \ref QEI_CTL_CHBINV_Msk : QEB Input
- * - \ref QEI_CTL_IDXINV_Msk : IDX Input
- * @return None
- * @details This macro inverse specified QEI signal input polarity.
- * \hideinitializer
- */
- #define QEI_ENABLE_INPUT_INV(qei, u32InputType) ((qei)->CTL |= (u32InputType))
- /**
- * @brief Disable QEI interrupt
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32IntSel Interrupt type selection.
- * - \ref QEI_CTL_DIRIEN_Msk : Direction change interrupt
- * - \ref QEI_CTL_OVUNIEN_Msk : Counter overflow or underflow interrupt
- * - \ref QEI_CTL_CMPIEN_Msk : Compare-match interrupt
- * - \ref QEI_CTL_IDXIEN_Msk : Index detected interrupt
- * @return None
- * @details This macro disable specified QEI interrupt.
- * \hideinitializer
- */
- #define QEI_DISABLE_INT(qei, u32IntSel) ((qei)->CTL &= ~(u32IntSel))
- /**
- * @brief Enable QEI interrupt
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32IntSel Interrupt type selection.
- * - \ref QEI_CTL_DIRIEN_Msk : Direction change interrupt
- * - \ref QEI_CTL_OVUNIEN_Msk : Counter overflow or underflow interrupt
- * - \ref QEI_CTL_CMPIEN_Msk : Compare-match interrupt
- * - \ref QEI_CTL_IDXIEN_Msk : Index detected interrupt
- * @return None
- * @details This macro enable specified QEI interrupt.
- * \hideinitializer
- */
- #define QEI_ENABLE_INT(qei, u32IntSel) ((qei)->CTL |= (u32IntSel))
- /**
- * @brief Disable QEI noise filter
- * @param[in] qei The pointer of the specified QEI module.
- * @return None
- * @details This macro disable QEI noise filter function.
- * \hideinitializer
- */
- #define QEI_DISABLE_NOISE_FILTER(qei) ((qei)->CTL |= QEI_CTL_NFDIS_Msk)
- /**
- * @brief Enable QEI noise filter
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32ClkSel The sampling frequency of the noise filter clock.
- * - \ref QEI_CTL_NFCLKSEL_DIV1
- * - \ref QEI_CTL_NFCLKSEL_DIV2
- * - \ref QEI_CTL_NFCLKSEL_DIV4
- * - \ref QEI_CTL_NFCLKSEL_DIV16
- * - \ref QEI_CTL_NFCLKSEL_DIV32
- * - \ref QEI_CTL_NFCLKSEL_DIV64
- * @return None
- * @details This macro enable QEI noise filter function and select noise filter clock.
- * \hideinitializer
- */
- #define QEI_ENABLE_NOISE_FILTER(qei, u32ClkSel) ((qei)->CTL = ((qei)->CTL & (~(QEI_CTL_NFDIS_Msk|QEI_CTL_NFCLKSEL_Msk))) | (u32ClkSel))
- /**
- * @brief Get QEI counter value
- * @param[in] qei The pointer of the specified QEI module.
- * @return QEI pulse counter register value.
- * @details This macro get QEI pulse counter value.
- * \hideinitializer
- */
- #define QEI_GET_CNT_VALUE(qei) ((qei)->CNT)
- /**
- * @brief Get QEI counting direction
- * @param[in] qei The pointer of the specified QEI module.
- * @retval 0 QEI counter is in down-counting.
- * @retval 1 QEI counter is in up-counting.
- * @details This macro get QEI counting direction.
- * \hideinitializer
- */
- #define QEI_GET_DIR(qei) (((qei)->STATUS & (QEI_STATUS_DIRF_Msk))?1:0)
- /**
- * @brief Get QEI counter hold value
- * @param[in] qei The pointer of the specified QEI module.
- * @return QEI pulse counter hold register value.
- * @details This macro get QEI pulse counter hold value, which is updated with counter value in hold counter value control.
- * \hideinitializer
- */
- #define QEI_GET_HOLD_VALUE(qei) ((qei)->CNTHOLD)
- /**
- * @brief Get QEI counter index latch value
- * @param[in] qei The pointer of the specified QEI module.
- * @return QEI pulse counter index latch value
- * @details This macro get QEI pulse counter index latch value, which is updated with counter value when the index is detected.
- * \hideinitializer
- */
- #define QEI_GET_INDEX_LATCH_VALUE(qei) ((qei)->CNTLATCH)
- /**
- * @brief Set QEI counter index latch value
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32Val The latch value.
- * @return QEI pulse counter index latch value
- * @details This macro set QEI pulse counter index latch value, which is updated with counter value when the index is detected.
- * \hideinitializer
- */
- #define QEI_SET_INDEX_LATCH_VALUE(qei,u32Val) ((qei)->CNTLATCH = (u32Val))
- /**
- * @brief Get QEI interrupt flag status
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32IntSel Interrupt type selection.
- * - \ref QEI_STATUS_DIRF_Msk : Counting direction flag
- * - \ref QEI_STATUS_DIRCHGF_Msk : Direction change flag
- * - \ref QEI_STATUS_OVUNF_Msk : Counter overflow or underflow flag
- * - \ref QEI_STATUS_CMPF_Msk : Compare-match flag
- * - \ref QEI_STATUS_IDXF_Msk : Index detected flag
- * @retval 0 QEI specified interrupt flag is not set.
- * @retval 1 QEI specified interrupt flag is set.
- * @details This macro get QEI specified interrupt flag status.
- * \hideinitializer
- */
- #define QEI_GET_INT_FLAG(qei, u32IntSel) (((qei)->STATUS & (u32IntSel))?1:0)
- /**
- * @brief Clear QEI interrupt flag
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32IntSel Interrupt type selection.
- * - \ref QEI_STATUS_DIRCHGF_Msk : Direction change flag
- * - \ref QEI_STATUS_OVUNF_Msk : Counter overflow or underflow flag
- * - \ref QEI_STATUS_CMPF_Msk : Compare-match flag
- * - \ref QEI_STATUS_IDXF_Msk : Index detected flag
- * @return None
- * @details This macro clear QEI specified interrupt flag.
- * \hideinitializer
- */
- #define QEI_CLR_INT_FLAG(qei, u32IntSel) ((qei)->STATUS = (u32IntSel))
- /**
- * @brief Set QEI counter compare value
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32Value The counter compare value.
- * @return None
- * @details This macro set QEI pulse counter compare value.
- * \hideinitializer
- */
- #define QEI_SET_CNT_CMP(qei, u32Value) ((qei)->CNTCMP = (u32Value))
- /**
- * @brief Set QEI counter value
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32Value The counter compare value.
- * @return None
- * @details This macro set QEI pulse counter value.
- * \hideinitializer
- */
- #define QEI_SET_CNT_VALUE(qei, u32Value) ((qei)->CNT = (u32Value))
- /**
- * @brief Enable QEI counter hold mode
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32Type The triggered type.
- * - \ref QEI_CTL_HOLDCNT_Msk : Hold QEI_CNT control
- * - \ref QEI_CTL_HOLDTMR0_Msk : Hold QEI_CNT by Timer0
- * - \ref QEI_CTL_HOLDTMR1_Msk : Hold QEI_CNT by Timer1
- * - \ref QEI_CTL_HOLDTMR2_Msk : Hold QEI_CNT by Timer2
- * - \ref QEI_CTL_HOLDTMR3_Msk : Hold QEI_CNT by Timer3
- * @return None
- * @details This macro enable QEI counter hold mode.
- * \hideinitializer
- */
- #define QEI_ENABLE_HOLD_TRG_SRC(qei, u32Type) ((qei)->CTL |= (u32Type))
- /**
- * @brief Disable QEI counter hold mode
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32Type The triggered type.
- * - \ref QEI_CTL_HOLDCNT_Msk : Hold QEI_CNT control
- * - \ref QEI_CTL_HOLDTMR0_Msk : Hold QEI_CNT by Timer0
- * - \ref QEI_CTL_HOLDTMR1_Msk : Hold QEI_CNT by Timer1
- * - \ref QEI_CTL_HOLDTMR2_Msk : Hold QEI_CNT by Timer2
- * - \ref QEI_CTL_HOLDTMR3_Msk : Hold QEI_CNT by Timer3
- * @return None
- * @details This macro disable QEI counter hold mode.
- * \hideinitializer
- */
- #define QEI_DISABLE_HOLD_TRG_SRC(qei, u32Type) ((qei)->CTL &= ~(u32Type))
- /**
- * @brief Set QEI maximum count value
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32Value The counter maximum value.
- * @return QEI maximum count value
- * @details This macro set QEI maximum count value.
- * \hideinitializer
- */
- #define QEI_SET_CNT_MAX(qei, u32Value) ((qei)->CNTMAX = (u32Value))
- /**
- * @brief Set QEI counting mode
- * @param[in] qei The pointer of the specified QEI module.
- * @param[in] u32Mode QEI counting mode.
- * - \ref QEI_CTL_X4_FREE_COUNTING_MODE
- * - \ref QEI_CTL_X2_FREE_COUNTING_MODE
- * - \ref QEI_CTL_X4_COMPARE_COUNTING_MODE
- * - \ref QEI_CTL_X2_COMPARE_COUNTING_MODE
- * @return None
- * @details This macro set QEI counting mode.
- * \hideinitializer
- */
- #define QEI_SET_CNT_MODE(qei, u32Mode) ((qei)->CTL = ((qei)->CTL & (~QEI_CTL_MODE_Msk)) | (u32Mode))
- void QEI_Close(QEI_T* qei);
- void QEI_DisableInt(QEI_T* qei, uint32_t u32IntSel);
- void QEI_EnableInt(QEI_T* qei, uint32_t u32IntSel);
- void QEI_Open(QEI_T* qei, uint32_t u32Mode, uint32_t u32Value);
- void QEI_Start(QEI_T* qei);
- void QEI_Stop(QEI_T* qei);
- /*@}*/ /* end of group QEI_EXPORTED_FUNCTIONS */
- /*@}*/ /* end of group QEI_Driver */
- /*@}*/ /* end of group Standard_Driver */
- #ifdef __cplusplus
- }
- #endif
- #endif /* __NU_QEI_H__ */
- /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
|