1 /* 2 * Copyright 2017-2020 NXP 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 #ifndef FSL_KBI_H_ 8 #define FSL_KBI_H_ 9 10 #include "fsl_common.h" 11 12 /*! 13 * @addtogroup kbi 14 * @{ 15 */ 16 17 /******************************************************************************* 18 * Definitions 19 ******************************************************************************/ 20 21 /*! @name Driver version */ 22 /*! @{ */ 23 /*! @brief KBI driver version. */ 24 #define FSL_KBI_DRIVER_VERSION (MAKE_VERSION(2, 0, 3)) 25 /*! @} */ 26 27 #if (defined(FSL_FEATURE_KBI_REG_WIDTH) && (FSL_FEATURE_KBI_REG_WIDTH == 8)) 28 typedef uint8_t kbi_reg_t; 29 #else 30 typedef uint32_t kbi_reg_t; 31 #endif 32 33 /*! @brief KBI detection mode. */ 34 typedef enum _kbi_detect_mode 35 { 36 kKBI_EdgesDetect = 0, /*!< The keyboard detects edges only. */ 37 kKBI_EdgesLevelDetect /*!< The keyboard detects both edges and levels. */ 38 } kbi_detect_mode_t; 39 40 /*! @brief KBI configuration. */ 41 typedef struct _kbi_config 42 { 43 uint32_t pinsEnabled; /*!< The eight kbi pins, set 1 to enable the corresponding KBI interrupt pins. */ 44 uint32_t pinsEdge; /*!< The edge selection for each kbi pin: 1 -- rinsing edge, 0 -- falling edge. */ 45 kbi_detect_mode_t mode; /*!< The kbi detection mode. */ 46 } kbi_config_t; 47 48 /******************************************************************************* 49 * API 50 ******************************************************************************/ 51 52 #if defined(__cplusplus) 53 extern "C" { 54 #endif 55 56 /*! 57 * @name Initialization and De-initialization 58 * @{ 59 */ 60 61 /*! 62 * @brief KBI initialize. 63 * This function ungates the KBI clock and initializes KBI. 64 * This function must be called before calling any other KBI driver functions. 65 * 66 * @param base KBI peripheral base address. 67 * @param configure The KBI configuration structure pointer. 68 */ 69 void KBI_Init(KBI_Type *base, kbi_config_t *configure); 70 71 /*! 72 * @brief Deinitializes the KBI module and gates the clock. 73 * This function gates the KBI clock. As a result, the KBI 74 * module doesn't work after calling this function. 75 * 76 * @param base KBI peripheral base address. 77 */ 78 void KBI_Deinit(KBI_Type *base); 79 80 /*! @} */ 81 82 /*! 83 * @name KBI Basic Operation 84 * @{ 85 */ 86 87 /*! 88 * @brief Enables the interrupt. 89 * 90 * @param base KBI peripheral base address. 91 */ KBI_EnableInterrupts(KBI_Type * base)92static inline void KBI_EnableInterrupts(KBI_Type *base) 93 { 94 base->SC |= KBI_SC_KBIE_MASK; 95 } 96 97 /*! 98 * @brief Disables the interrupt. 99 * 100 * @param base KBI peripheral base address. 101 */ KBI_DisableInterrupts(KBI_Type * base)102static inline void KBI_DisableInterrupts(KBI_Type *base) 103 { 104 base->SC &= ~(kbi_reg_t)KBI_SC_KBIE_MASK; 105 } 106 107 /*! 108 * @brief Gets the KBI interrupt event status. 109 * 110 * @param base KBI peripheral base address. 111 * @return The status of the KBI interrupt request is detected. 112 */ KBI_IsInterruptRequestDetected(KBI_Type * base)113static inline bool KBI_IsInterruptRequestDetected(KBI_Type *base) 114 { 115 return ((base->SC & KBI_SC_KBF_MASK) != 0U); 116 } 117 118 /*! 119 * @brief Clears KBI status flag. 120 * 121 * @param base KBI peripheral base address. 122 */ KBI_ClearInterruptFlag(KBI_Type * base)123static inline void KBI_ClearInterruptFlag(KBI_Type *base) 124 { 125 base->SC |= KBI_SC_KBACK_MASK; 126 } 127 128 #if defined(FSL_FEATURE_KBI_HAS_SOURCE_PIN) && FSL_FEATURE_KBI_HAS_SOURCE_PIN 129 /*! 130 * @brief Gets the KBI Source pin status. 131 * 132 * @param base KBI peripheral base address. 133 * @return The status indicates the active pin defined as keyboard interrupt 134 * which is pushed. 135 */ KBI_GetSourcePinStatus(KBI_Type * base)136static inline uint32_t KBI_GetSourcePinStatus(KBI_Type *base) 137 { 138 return base->SP; 139 } 140 #endif /* FSL_FEATURE_KBI_HAS_SOURCE_PIN */ 141 142 /*! @} */ 143 144 #if defined(__cplusplus) 145 } 146 #endif 147 148 /*! @}*/ 149 150 #endif /* FSL_KBI_H_*/ 151