Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:59

0001 /*
0002  * Copyright 2017, 2019 NXP
0003  * All rights reserved.
0004  *
0005  * SPDX-License-Identifier: BSD-3-Clause
0006  */
0007 #ifndef _FSL_KPP_H_
0008 #define _FSL_KPP_H_
0009 
0010 #include "fsl_common.h"
0011 
0012 /*!
0013  * @addtogroup kpp
0014  * @{
0015  */
0016 
0017 /*******************************************************************************
0018  * Definitions
0019  ******************************************************************************/
0020 
0021 /*! @name Driver version */
0022 /*@{*/
0023 /*! @brief KPP driver version 2.0.0. */
0024 #define FSL_KPP_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
0025 /*@}*/
0026 
0027 #define KPP_KEYPAD_COLUMNNUM_MAX (8U)
0028 #define KPP_KEYPAD_ROWNUM_MAX    (8U)
0029 
0030 /*! @brief List of interrupts supported by the peripheral. This
0031  * enumeration uses one-bot encoding to allow a logical OR of multiple
0032  * members. Members usually map to interrupt enable bits in one or more
0033  * peripheral registers.
0034  */
0035 typedef enum _kpp_interrupt_enable
0036 {
0037     kKPP_keyDepressInterrupt = KPP_KPSR_KDIE_MASK, /*!< Keypad depress interrupt source */
0038     kKPP_keyReleaseInterrupt = KPP_KPSR_KRIE_MASK  /*!< Keypad release interrupt source */
0039 } kpp_interrupt_enable_t;
0040 
0041 /*! @brief Lists of KPP synchronize chain operation. */
0042 typedef enum _kpp_sync_operation
0043 {
0044     kKPP_ClearKeyDepressSyncChain = KPP_KPSR_KDSC_MASK, /*!< Keypad depress interrupt status. */
0045     kKPP_SetKeyReleasesSyncChain  = KPP_KPSR_KRSS_MASK, /*!< Keypad release interrupt status. */
0046 } kpp_sync_operation_t;
0047 
0048 /*! @brief Lists of KPP status. */
0049 typedef struct _kpp_config
0050 {
0051     uint8_t activeRow;    /*!< The row number: bit 7 ~ 0 represents the row 7 ~ 0. */
0052     uint8_t activeColumn; /*!< The column number: bit 7 ~ 0 represents the column 7 ~ 0. */
0053     uint16_t interrupt;   /*!< KPP interrupt source. A logical OR of "kpp_interrupt_enable_t". */
0054 } kpp_config_t;
0055 
0056 /*******************************************************************************
0057  * API
0058  ******************************************************************************/
0059 
0060 #if defined(__cplusplus)
0061 extern "C" {
0062 #endif
0063 
0064 /*!
0065  * @name Initialization and De-initialization
0066  * @{
0067  */
0068 
0069 /*!
0070  * @brief KPP initialize.
0071  * This function ungates the KPP clock and initializes KPP.
0072  * This function must be called before calling any other KPP driver functions.
0073  *
0074  * @param base KPP peripheral base address.
0075  * @param configure The KPP configuration structure pointer.
0076  */
0077 void KPP_Init(KPP_Type *base, kpp_config_t *configure);
0078 
0079 /*!
0080  * @brief Deinitializes the KPP module and gates the clock.
0081  * This function gates the KPP clock. As a result, the KPP
0082  * module doesn't work after calling this function.
0083  *
0084  * @param base KPP peripheral base address.
0085  */
0086 void KPP_Deinit(KPP_Type *base);
0087 
0088 /* @} */
0089 
0090 /*!
0091  * @name KPP Basic Operation
0092  * @{
0093  */
0094 
0095 /*!
0096  * @brief Enable the interrupt.
0097  *
0098  * @param base KPP peripheral base address.
0099  * @param mask  KPP interrupts to enable. This is a logical OR of the
0100  *             enumeration :: kpp_interrupt_enable_t.
0101  */
0102 static inline void KPP_EnableInterrupts(KPP_Type *base, uint16_t mask)
0103 {
0104     uint16_t data = (uint16_t)(base->KPSR & ~(KPP_KPSR_KPKR_MASK | KPP_KPSR_KPKD_MASK));
0105     base->KPSR    = data | mask;
0106 }
0107 
0108 /*!
0109  * @brief Disable the interrupt.
0110  *
0111  * @param base KPP peripheral base address.
0112  * @param mask  KPP interrupts to disable. This is a logical OR of the
0113  *             enumeration :: kpp_interrupt_enable_t.
0114  */
0115 static inline void KPP_DisableInterrupts(KPP_Type *base, uint16_t mask)
0116 {
0117     base->KPSR &= ~(mask | KPP_KPSR_KPKR_MASK | KPP_KPSR_KPKD_MASK);
0118 }
0119 
0120 /*!
0121  * @brief Gets the KPP interrupt event status.
0122  *
0123  * @param base KPP peripheral base address.
0124  * @return The status of the KPP. Application can use the enum type in the "kpp_interrupt_enable_t"
0125  * to get the right status of the related event.
0126  */
0127 static inline uint16_t KPP_GetStatusFlag(KPP_Type *base)
0128 {
0129     return (base->KPSR & (KPP_KPSR_KPKR_MASK | KPP_KPSR_KPKD_MASK)) << KPP_KPSR_KDIE_SHIFT;
0130 }
0131 
0132 /*!
0133  * @brief Clears KPP status flag.
0134  *
0135  * @param base KPP peripheral base address.
0136  * @param mask KPP mask to be cleared. This is a logical OR of the
0137  *             enumeration :: kpp_interrupt_enable_t.
0138  */
0139 static inline void KPP_ClearStatusFlag(KPP_Type *base, uint16_t mask)
0140 {
0141     base->KPSR |= (uint16_t)((mask) >> KPP_KPSR_KDIE_SHIFT);
0142 }
0143 
0144 /*!
0145  * @brief Set KPP synchronization chain.
0146  *
0147  * @param base KPP peripheral base address.
0148  * @param mask KPP mask to be cleared. This is a logical OR of the
0149  *             enumeration :: kpp_sync_operation_t.
0150  */
0151 static inline void KPP_SetSynchronizeChain(KPP_Type *base, uint16_t mask)
0152 {
0153     uint16_t data = base->KPSR & (KPP_KPSR_KRSS_MASK | KPP_KPSR_KDSC_MASK | KPP_KPSR_KRIE_MASK | KPP_KPSR_KDIE_MASK);
0154     base->KPSR    = data | mask;
0155 }
0156 
0157 /*!
0158  * @brief Keypad press scanning.
0159  *
0160  * This function will scanning all columns and rows. so
0161  * all scanning data will be stored in the data pointer.
0162  *
0163  * @param base  KPP peripheral base address.
0164  * @param data  KPP key press scanning data. The data buffer should be prepared with
0165  * length at least equal to KPP_KEYPAD_COLUMNNUM_MAX * KPP_KEYPAD_ROWNUM_MAX.
0166  * the data pointer is recommended to be a array like uint8_t data[KPP_KEYPAD_COLUMNNUM_MAX].
0167  * for example the data[2] = 4, that means in column 1 row 2 has a key press event.
0168  * @param clockSrc_Hz Source clock.
0169  */
0170 void KPP_keyPressScanning(KPP_Type *base, uint8_t *data, uint32_t clockSrc_Hz);
0171 
0172 /* @} */
0173 
0174 #if defined(__cplusplus)
0175 }
0176 #endif
0177 
0178 /*! @}*/
0179 
0180 #endif /* _FSL_KPP_H_*/