1 /***************************************************************************//**
2 * \file cy_keyscan.h
3 * \version 1.0
4 *
5 * \brief
6 * Provides an API declaration of the KEYSCAN driver
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2020-2021, Cypress Semiconductor Corporation. All rights reserved.
11 * You may use this file only in accordance with the license, terms, conditions,
12 * disclaimers, and limitations in the end user license agreement accompanying
13 * the software package with which this file was provided.
14 *******************************************************************************/
15 
16 /**
17 * \addtogroup group_keyscan
18 * \{
19 * MXKEYSCAN is a DEEPSLEEP peripheral IP that performs autonomous key-matrix scan and system notification.
20 * Key processing detects both press and un-press actions,
21 * includes micro and macro de-bouncing filters and ghost key detection.
22 *
23 * Configurable key-matrix size supports up to 20x8 keys.
24 * Up to 20 columns are driven as the output and up to 8 rows are processed as the input.
25 * Key actions are stored in the FIFO with interrupt notification available based on the FIFO threshold.
26 *
27 * The Scan matrix support up to 8X20 matrix, maximum of 160 keys.
28 * Any key press will be translated into an index corresponding column and corresponding row.
29 * Before any key is pressed, the Key Matrix Scan Logic is disabled.
30 * Once a key press is detected by the Key Detection Logic, it will enable the gate for clock to drive the key Matrix Scan Logic for GPIO scanning.
31 * GPIO scanning is done one column at a time by driving each column "low" and reading from the row GPIO pins to find out which input is low.
32 * After the Key Scan Logic had scanned through the matrix for a specific number for debounce times configured by firmware though the configuration register,
33 * keycode representing the pressed key is pushed into the key FIFO for firmware to read and an interrupt to CPU will be generated.
34 * There are two types of debounce mechanisms build into this scan matrix block.
35 * The micro-debounce logic will provide a small debounce period to debounce the break type of mechanical vibration.
36 * The macro debounce logic will scan through the matrix for a number of times for qualify a key as being pressed.
37 *
38 * Features:
39 * * Ability to turn off it's clock if no keys pressed.
40 * * Sequential scanning of up to 160 keys in a 8X20 matrix
41 * * Programmable number of columns from 1 to 20.
42 * * Programmable number of rows from 1 to 8.
43 * * 20-byte key-code buffer.
44 * * 128-kHz clock allow scanning of full 160 key matrix in about 1.2ms.
45 * * Keys are buffered until host microcontroller has a chance to read it, or until overflow occurs.
46 * * Hardware debouncing and noise/glitch filtering.
47 *
48 * This driver provides the user an easy method for accessing KeyScan registers and provides some simple functionality for reading key index
49 * from keyscan FIFO.
50 *
51 * The IP supports only Sequential PIN configuration.
52 * For Example if the user is configuring the IP for 4 pins (2 ROWS and 2 COLUMNs) the user is suggested to use ROWS 0,1 and COLUMNS 0,1.
53 * Interleaved ROWS and COLUMNS are not supported by the IP i.e. User should not configure ROW0 and ROW3 and COLUMN1 and COLUMN4 etc.
54 *
55 * With every Key event, User receives the following information
56 * * Key Code : The keyCode for the key press event detected. Keycode is calculated as ((no of rows * column num) + row num)
57 * * UP/DOWN flag : Whether the key event is for the key press or for the key release event.
58 * * Scan Cycle flag : It is toggled for every scan cycle in which a new event is queued.
59                        Use of this flag is optional. If used, it allows the consumer to determine whether
60                        an event is detected in the same scan cycle as the previous event or a different one.
61                        Note that this flag does not indicate any separation in time.
62 *
63 * \image html keyscan_matrix.png "Keyscan Matrix" width=600px
64 * \image latex keyscan_matrix.png
65 *
66 * Initialization:
67 *
68 * The KeyScan driver initialization is according to the Options setup in the passed Config Struct. Several validations are done before the initialization and an error is returned if invalid Modes are requested.
69 *
70 * KeyScan Configuration
71 *
72 * * Enable/Disable ghost detection
73 * * Enable/Disable wakeup host MCU when key is detected.
74 * * Set the number of rows of key matrix
75 * * Set the no of columns of the key matrix.
76 * * Set the clock to stay on or gated of when no activity is detected.
77 * * Set macro down debounce count.
78 * * Set macro up debounce count.
79 * * Set micro debounce count.
80 *
81 * Application then registers for the callback. Driver notifies the user for any events in this callback function.
82 * \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_Init
83 *
84 * Interrupt Handling
85 *
86 * Keyscan has a dedicated interrupt keyscan_interrupt_IRQn
87 *
88 * There are 2 type of interrupts that the software has to check when there is an interrupt
89 * * MXKEYSCAN_INTR_KEY_EDGE_DONE     : Used for waking up the system from deepsleep. This should be disabled when the MF clock is active.
90 * * MXKEYSCAN_INTR_FIFO_THRESH_DONE  : For all key events
91 *
92 * * MXKEYSCAN_INTR_KEY_EDGE_DONE interrupt is mainly used for waking up the system from deepsleep.
93 * Applications register for this interrupt before going to deepsleep, then with key event MCU will be woken up.
94 * * MXKEYSCAN_INTR_FIFO_THRESH_DONE interrupt is triggered when there are key press/release events.
95 * In the active mode application should be registering only for this interrupt.
96 *
97 * \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_Init_Example
98 *
99 * Applications have to call Cy_Keyscan_Interrupt_Handler function from keyscan interrupt handler.
100 * Applications will be notified of any key events through the registered callback.
101 * Applications have to read the events in the callback function by calling Cy_Keyscan_GetNextEvent function in a loop till the return value is CY_KEYSCAN_EVENT_NONE.
102 * With every Key event, User receives the following information
103 * * Key Code : The keyCode for the key press event detected. Keycode is calculated as ((no of rows * column num) + row num)
104 * * UP/DOWN flag : Whether the key event is for the key press or for the key release.
105 * * Scan Cycle flag : It is toggled for every scan cycle in which a new event is queued. Use of this flag is optional. If used, it allows the consumer to determine whether an event is detected in the same scan cycle as the previous event or a different one. Note that this flag does not indicate any separation in time.
106 *
107 *
108 * \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_ISR
109 *
110 * Handling DeepSleep
111 *
112 * Following are the points users of keyscan have to handle in their code.
113 * * Normal DeepSleep configuration is MFO clock disabled, LF Clock enabled and edge interrupt enabled.
114 * * When edge interrupt occurs, configure MFO to remain enabled in Deepsleep, disable edge interrupt, and go back to Deepsleep.
115 * * Whenever MFO clock is enabled in the Deepsleep and edge interrupt is disabled, user should start a timer. Every time a key event is detected, user should restart the timer. When timer expires (and/or all keys are considered up), user should go back to Deepsleep with MFO disabled and edge interrupt enabled.
116 *
117 *
118 * \section group_keyscan_changelog Changelog
119 * <table class="doxtable">
120 *   <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
121 *   <tr>
122 *     <td>1.0</td>
123 *     <td>Initial version</td>
124 *     <td></td>
125 *   </tr>
126 * </table>
127 *
128 * * \defgroup group_keyscan_macro Macros
129 *   \{
130 *       \defgroup group_keyscan_intr_mask_macro KeyScan ALL interrupt mask definition
131 *   \}
132 * \defgroup group_keyscan_functions Functions
133 * \defgroup group_keyscan_data_structures Data Structures
134 * \defgroup group_keyscan_enums Enumerated Types
135 */
136 
137 
138 #if !defined(CY_KEYSCAN_H)
139 #define CY_KEYSCAN_H
140 #include "cy_device.h"
141 #if defined (CY_IP_MXKEYSCAN)
142 /*****************************************************************************/
143 /* Include files                                                             */
144 /*****************************************************************************/
145 #include <stdint.h>
146 #include <stddef.h>
147 #include <stdbool.h>
148 #include "cy_syslib.h"
149 
150 #if defined(__cplusplus)
151 extern "C" {
152 #endif
153 
154 /**
155 * \addtogroup group_keyscan_macro
156 * \{
157 */
158 
159 
160 /*****************************************************************************/
161 /* Global pre-processor symbols/macros ('#define')                           */
162 /*****************************************************************************/
163 /** Driver major version */
164 #define CY_KEYSCAN_DRV_VERSION_MAJOR    1
165 
166 /** Driver minor version */
167 #define CY_KEYSCAN_DRV_VERSION_MINOR    0
168 
169 /** KEYSCAN driver ID */
170 #define CY_KEYSCAN_ID CY_PDL_DRV_ID(0x72u)
171 /** \} group_keyscan_macro */
172 /**
173 * \addtogroup group_keyscan_enums
174 * \{
175 */
176 /** KEYSCAN API status definition */
177 typedef enum
178 {
179     CY_KEYSCAN_SUCCESS         = 0x00u,                                         /**< Returned successful */
180     CY_KEYSCAN_BAD_PARAM       = CY_KEYSCAN_ID | CY_PDL_STATUS_ERROR | 0x01u,   /**< Bad parameter was passed */
181     CY_KEYSCAN_BUSY            = CY_KEYSCAN_ID | CY_PDL_STATUS_ERROR | 0x02u,   /**< Change settings while tx/rx on-going */
182     CY_KEYSCAN_QUEUE_OVERFLOW  = CY_KEYSCAN_ID | CY_PDL_STATUS_ERROR | 0x03u,   /**< QUEUE Over flow condition */
183     CY_KEYSCAN_QUEUE_EMPTY     = CY_KEYSCAN_ID | CY_PDL_STATUS_ERROR | 0x04u,   /**< QUEUE Empty condition */
184     CY_KEYSCAN_EVENT_NONE      = CY_KEYSCAN_ID | CY_PDL_STATUS_ERROR | 0x05u,   /**< Event None */
185 } cy_en_ks_status_t;
186 
187 /**
188  *****************************************************************************
189  ** \brief Keycode enumerations
190  **
191   *****************************************************************************/
192 typedef enum {
193     KEYSCAN_KEYCODE_GHOST             = 0xf5,   /*!< Ghost key keycode */
194     KEYSCAN_KEYCODE_NONE              = 0xfd,   /*!< Keycode value if no key is pressed.*/
195     KEYSCAN_KEYCODE_END_OF_SCAN_CYCLE = 0xfe,   /*!< Event returned to indicate the end of a scan cycle.*/
196     KEYSCAN_KEYCODE_ROLLOVER          = 0xff,   /*!< Rollover event generated by the keyscan driver in case of an error (ghost or overflow)
197                                                      For every key event its state has to be stored and if there is an error, then rollover event is triggered and driver restores the previous state.*/
198 }cy_en_ks_keycode_t;
199 
200 
201 /** \} group_keyscan_enums */
202 /*****************************************************************************/
203 /* Global variable declarations ('extern', definition in C source)           */
204 /*****************************************************************************/
205 /** \cond Internal */
206 /*
207 * Default values for the CTL Register and Firmware FIFO size.
208 */
209 
210 /** keyscan FW FIFO size. This FIFO  is implemented with KeyscanQueue. */
211 #define KEYSCAN_FW_FIFO_SIZE                    (20u)
212 
213 /** keyscan CTL register KeyScan enable Default value definition. */
214 #define MXKEYSCAN_KEYSCAN_CTL_KS_EN_DEFAULT            0U
215 /** keyscan CTL register ghost enable Default value definition. */
216 #define MXKEYSCAN_KEYSCAN_CTL_GHOST_EN_DEFAULT         1U
217 /** keyscan CTL register keyscan int enable Default value definition. */
218 #define MXKEYSCAN_KEYSCAN_CTL_KS_INT_EN_DEFAULT        1U
219 /** keyscan CTL register keyscan reset enable Default value definition. */
220 #define MXKEYSCAN_KEYSCAN_CTL_KYS_RST_EN_DEFAULT       0U
221 /** keyscan CTL register Idle duration between column scans Default value definition. */
222 #define MXKEYSCAN_KEYSCAN_CTL_RC_EXT_DEFAULT           3U
223 /** keyscan CTL register No of Rows Default value definition. */
224 #define MXKEYSCAN_KEYSCAN_CTL_RCTC_ROW_DEFAULT         7U
225 /** keyscan CTL register No of Columns Default value definition. */
226 #define MXKEYSCAN_KEYSCAN_CTL_RCTC_COLUMN_DEFAULT      19U
227 /** keyscan CTL register used to pull the columns high after each column scan to alleviate slow rise-time due to a large key matrix capacitance.
228  ** Default value definition. */
229 #define MXKEYSCAN_KEYSCAN_CTL_PULL_HIGH_DEFAULT        1U
230 /** keyscan CTL register Default Value.  */
231 #define MXKEYSCAN_KEYSCAN_CTL_KSI_DRV_HIGH_DEFAULT     1U
232 /** keyscan CTL register  keyscan clock will stay on when set; otherwise, the clock will be gated off by when no activity is detected.
233  ** Default value definition  */
234 #define MXKEYSCAN_KEYSCAN_CTL_KYSCLK_STAYON_DEFAULT    1U
235 /** keyscan CTL register  All Default values. */
236 #define KEYSCAN_CTL_DEFAULT (_VAL2FLD(MXKEYSCAN_KEYSCAN_CTL_KS_EN, MXKEYSCAN_KEYSCAN_CTL_KS_EN_DEFAULT) | \
237                                 _VAL2FLD(MXKEYSCAN_KEYSCAN_CTL_GHOST_EN, MXKEYSCAN_KEYSCAN_CTL_GHOST_EN_DEFAULT) | \
238                                 _VAL2FLD(MXKEYSCAN_KEYSCAN_CTL_KS_INT_EN, MXKEYSCAN_KEYSCAN_CTL_KS_INT_EN_DEFAULT) | \
239                                 _VAL2FLD(MXKEYSCAN_KEYSCAN_CTL_KYS_RST_EN, MXKEYSCAN_KEYSCAN_CTL_KYS_RST_EN_DEFAULT) | \
240                                 _VAL2FLD(MXKEYSCAN_KEYSCAN_CTL_RC_EXT, MXKEYSCAN_KEYSCAN_CTL_RC_EXT_DEFAULT) | \
241                                 _VAL2FLD(MXKEYSCAN_KEYSCAN_CTL_RCTC_ROW, MXKEYSCAN_KEYSCAN_CTL_RCTC_ROW_DEFAULT) | \
242                                 _VAL2FLD(MXKEYSCAN_KEYSCAN_CTL_RCTC_COLUMN, MXKEYSCAN_KEYSCAN_CTL_RCTC_COLUMN_DEFAULT) | \
243                                 _VAL2FLD(MXKEYSCAN_KEYSCAN_CTL_PULL_HIGH, MXKEYSCAN_KEYSCAN_CTL_PULL_HIGH_DEFAULT) | \
244                                 _VAL2FLD(MXKEYSCAN_KEYSCAN_CTL_KSI_DRV_HIGH, MXKEYSCAN_KEYSCAN_CTL_KSI_DRV_HIGH_DEFAULT) | \
245                                 _VAL2FLD(MXKEYSCAN_KEYSCAN_CTL_KYSCLK_STAYON, MXKEYSCAN_KEYSCAN_CTL_KYSCLK_STAYON_DEFAULT))
246 /** \endcond */
247 
248 /**
249 * \addtogroup group_keyscan_intr_mask_macro KeyScan ALL interrupt mask definition
250 * \{
251 * Specifies the mask value for interrupt status/mask
252 */
253 /** keyscan Interrupt KEY EDGE value definition.
254  *  this is used only for waking up the CPU.
255  *  User has to ignore this for all the key events. */
256 #define MXKEYSCAN_INTR_KEY_EDGE_DONE        (MXKEYSCAN_INTR_KEY_EDGE_Msk)
257 /** keyscan Interrupt FIFO THRESHOLD value definition.
258  *  triggered when there is one or more events in the keyscan HW FIFO.
259  *  Firmware reads all the pending events from the HW FIFO and Clears the interrupt.
260  *  User has to call function Cy_Keyscan_Interrupt_Handler when this interrupt is triggered. */
261 #define MXKEYSCAN_INTR_FIFO_THRESH_DONE     (MXKEYSCAN_INTR_FIFO_THRESH_Msk)
262 /** keyscan ALL Interrupt value definition. */
263 #define MXKEYSCAN_INTR_ALL                   (MXKEYSCAN_INTR_KEY_EDGE_Msk  |\
264                                              MXKEYSCAN_INTR_FIFO_THRESH_Msk)
265 
266 /** \} group_keyscan_intr_mask_macro */
267 
268 /** \cond Internal */
269 
270 /* Macros for the conditions used by CY_ASSERT calls */
271 #define CY_KEYSCAN_ROW_COUNT_MIN          1U        /** KeyScan Row count Minimum value */
272 #define CY_KEYSCAN_ROW_COUNT_MAX          8U        /** KeyScan Row count Maximum value */
273 #define CY_KEYSCAN_COLUMN_COUNT_MIN       1U        /** KeyScan Column Count Minimum value */
274 #define CY_KEYSCAN_COLUMN_COUNT_MAX       20U        /** KeyScan Column Count Maximum value */
275 
276 #define CY_KEYSCAN_MD_DEBOUNCE_MIN        0U        /** Macro Down Debounce Minimum value */
277 #define CY_KEYSCAN_MD_DEBOUNCE_MAX        15U       /** Macro Down Debounce Maximum value */
278 #define CY_KEYSCAN_MU_DEBOUNCE_MIN        0U        /** Macro Up Debounce Minimum value */
279 #define CY_KEYSCAN_MU_DEBOUNCE_MAX        15U       /** Macro Up Debounce Minimum value */
280 #define CY_KEYSCAN_U_DEBOUNCE_MIN         0U        /** Micro Down Debounce Minimum value */
281 #define CY_KEYSCAN_U_DEBOUNCE_MAX         3U        /** Micro Down Debounce Maximum value */
282 
283 
284 #define CY_KEYSCAN_IS_ROW_COUNT_VALID(count)       (((count) >= CY_KEYSCAN_ROW_COUNT_MIN) && ((count) <= CY_KEYSCAN_ROW_COUNT_MAX))
285 #define CY_KEYSCAN_IS_COLUMN_COUNT_VALID(count)    (((count) >= CY_KEYSCAN_COLUMN_COUNT_MIN) && ((count) <= CY_KEYSCAN_COLUMN_COUNT_MAX))
286 
287 #define CY_KEYSCAN_IS_MD_DEBOUNCE_VALID(count)     ((count) <= CY_KEYSCAN_MD_DEBOUNCE_MAX)
288 #define CY_KEYSCAN_IS_MU_DEBOUNCE_VALID(count)     ((count) <= CY_KEYSCAN_MU_DEBOUNCE_MAX)
289 #define CY_KEYSCAN_IS_U_DEBOUNCE_VALID(count)      ((count) <= CY_KEYSCAN_U_DEBOUNCE_MAX)
290 
291 
292 /** \endcond */
293 
294 /**
295 * \addtogroup group_keyscan_data_structures
296 * \{
297 */
298 /** keyscan callback  function definition.
299  ** Application has to register for callback for receiving the key press events.
300 */
301 typedef void (* cy_cb_keyscan_handle_events_t)(void);
302 /**
303  *****************************************************************************
304  ** \brief keyscan configuration
305  **        These settings are per KEYSCAN instance.
306  *****************************************************************************/
307 typedef struct cy_stc_ks_config_t
308 {
309     uint8_t macroDownDebCnt;             /**< macro down debounce count */
310 
311     uint8_t macroUpDebCnt;               /**< macro Up debounce count */
312 
313     uint8_t microDebCnt;                 /**< micro debounce count */
314 
315     uint8_t noofRows;                    /**< set the number of rows of the key matrix */
316 
317     uint8_t noofColumns;                 /**< set the number of columns of the key matrix */
318 
319     bool ghostEnable;                    /**< Enable ghost detection. */
320 
321     bool cpuWakeupEnable;                /**< enables the keyscan block to wake the MCU module if key is detected. */
322 
323     bool clkStayOn;                      /**< The keyscan clock will stay on when set; otherwise, the clock will be gated off by when no activity is detected*/
324 
325 }cy_stc_ks_config_t ;
326 
327 /**
328  *****************************************************************************
329  ** \brief keyscan key event
330  *****************************************************************************/
331 typedef struct cy_stc_key_event
332 {
333 
334     uint8_t keyCode;            /**< Key code. This is the location in the keyscan matrix that is pressed/released.
335                                     May be implemented as ((row * numCols) + col) or ((col * numRows) + row. */
336 
337     uint8_t upDownFlag;         /**< Up/down flag */
338 
339     uint8_t scanCycleFlag;      /**< Should be toggled for every scan cycle in which a new event is queued.
340                                    Use of this flag is optional. If used, it allows the consumer to determine whether
341                                    an event is detected in the same scan cycle as the previous event or a different one.
342                                    Note that this flag does not indicate any separation in time. */
343 }cy_stc_key_event;
344 
345 
346 /**
347  *****************************************************************************
348  ** \brief KEYSCAN  Context configuration
349  **        These settings are per keyscan context.
350  *****************************************************************************/
351 typedef struct cy_stc_keyscan_context_t
352 {
353     cy_stc_key_event bufStart[KEYSCAN_FW_FIFO_SIZE];   /**< Location where the FW FIFO starts. Provided during initialization. */
354 
355     uint8_t maxNumElements;                   /**< Maximum number of elements that can be placed in the FW FIFO. Provided during initialization. */
356 
357     uint8_t curNumElements;                   /**< Number of elements currently in the FW FIFO */
358 
359     uint8_t readIndex;                        /**< Read index into the FW FIFO. */
360 
361     uint8_t writeIndex;                       /**< Write index into the FW FIFO. */
362 
363     uint8_t savedWriteIndexForRollBack;       /**< Saved write index for rollback. */
364 
365     uint8_t savedNumElements;                 /**< Saved number of elements for rollback. */
366 
367     uint8_t keysPressedCount;                 /**< Number of key down events that are not yet matched by key up events,
368                                                   which gives the number of keys currently being pressed */
369 
370     bool keyscan_pollingKeyscanHw;            /**< Whether HW polling is done from Keyscan */
371 
372     cy_cb_keyscan_handle_events_t cbEvents;   /**< callback function */
373 }cy_stc_keyscan_context_t;
374 
375 /** \} group_keyscan_data_structures */
376 
377 
378 /**
379 * \addtogroup group_keyscan_functions
380 * \{
381 */
382 /*****************************************************************************/
383 /* Global function prototypes ('extern', definition in C source)             */
384 /*****************************************************************************/
385 
386 /**
387  *****************************************************************************
388  ** \brief  Registers for callback
389  ** Application has to register for callback for receiving the key press events.
390  ** In the interrupt handler data from HW FIFO is copied to FW FIFO and
391  ** application is notified to get the data using this callback function.
392  **
393  ** \param [in]  cbEvents    Pointer to the callback function.
394  **
395  ** \param [in]  context     Pointer to the context.
396  **
397  ** \retval Refer \ref cy_en_ks_status_t
398  **
399  ** \funcusage
400  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_Register_Callback
401  *****************************************************************************/
402 cy_en_ks_status_t Cy_Keyscan_Register_Callback(cy_cb_keyscan_handle_events_t cbEvents, cy_stc_keyscan_context_t* context);
403 
404 /**
405  *****************************************************************************
406  ** \brief Register Context with the driver
407  ** This Function registers for the event callback and FW FIFO buffer.
408  **
409  ** \pre The Application must configure corresponding keyscan pins
410  **      according to requirements and settings of keyscan instance.
411  **
412  ** \param [in] base       Pointer to KeyScan instance register area
413  ** \param [in] config     KeyScan module configuration. See #cy_stc_ks_config_t.
414  ** \param [in] context   Pointer to the context.
415  **
416  ** \retval Refer \ref cy_en_ks_status_t
417  **
418  ** \funcusage
419  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_Init
420  *****************************************************************************/
421 cy_en_ks_status_t  Cy_Keyscan_Init(MXKEYSCAN_Type* base, const cy_stc_ks_config_t* config, cy_stc_keyscan_context_t *context );
422 
423 /**
424  *****************************************************************************
425  ** \brief Deinit Keyscan.
426  ** Deinits the Keyscan HW
427  ** Clear FW FIFO after a HW reset.
428  ** Restores the control data and enables scans if they were enabled before this function was called.
429  **
430  ** \param  base     [in]        Pointer to Keyscan instance register area.
431  ** \param  context  [in]        Pointer to the context.
432  **
433  ** \retval Refer \ref cy_en_ks_status_t
434  **
435  ** \funcusage
436  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_DeInit
437  *****************************************************************************/
438 cy_en_ks_status_t Cy_Keyscan_DeInit(MXKEYSCAN_Type* base, cy_stc_keyscan_context_t *context);
439 
440 /**
441  *****************************************************************************
442  ** \brief Enable Keyscan.
443  ** Enables the keyscan hardware.
444  **
445  ** \param  base    [in]  Pointer to KeyScan instance register area.
446  ** \param  context [in]  Pointer to the context.
447  **
448  ** \retval Refer \ref cy_en_ks_status_t
449  **
450  ** \funcusage
451  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_Enable
452  *****************************************************************************/
453 cy_en_ks_status_t Cy_Keyscan_Enable(MXKEYSCAN_Type* base, cy_stc_keyscan_context_t *context);
454 
455 /**
456  *****************************************************************************
457  ** \brief Disable keyscan
458  ** Reset's the Keyscan hardware and disables the keyscan hardware.
459  ** When disabled, clock to the keyscan IP is gated.
460  **
461  ** \param  base    [in]  Pointer to KeyScan instance register area.
462  ** \param  context [in]  Pointer to the context.
463  **
464  ** \retval Refer \ref cy_en_ks_status_t
465  **
466  ** \funcusage
467  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_Disable
468  *****************************************************************************/
469 cy_en_ks_status_t Cy_Keyscan_Disable(MXKEYSCAN_Type* base, cy_stc_keyscan_context_t *context);
470 
471 /**
472  *****************************************************************************
473  ** \brief Events pending
474  ** Return whether any events are in the FW FIFO or not.
475  **
476  ** \param  base          [in]  Pointer to KeyScan instance register area.
477  ** \param  context       [in]  Pointer to the context.
478  ** \param  eventsPending [out] Pointer to the eventsPending, True if events pending and otherwise False.
479  **
480  ** \retval Refer \ref cy_en_ks_status_t
481  **
482  ** \funcusage
483  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_EventsPending
484  *****************************************************************************/
485 cy_en_ks_status_t Cy_Keyscan_EventsPending(MXKEYSCAN_Type* base, bool *eventsPending, cy_stc_keyscan_context_t *context);
486 
487 /**
488  *****************************************************************************
489  ** \brief Get next event from FW FIFO.
490  ** Applications have to call \ref Cy_Keyscan_Interrupt_Handler from keyscan interrupt handler.
491  ** After successfully reading from HW FIFO and writing to FW FIFO applications
492  ** will be notified through the registered callback.
493  ** Applications to read from the FW FIFO has to call this function in a loop till
494  ** the return value is CY_KEYSCAN_EVENT_NONE
495  **
496  ** \param  base          [in]  Pointer to KeyScan instance register area.
497  ** \param  context       [in]  Pointer to the context.
498  ** \param  event         [out] Pointer to the next event.
499  **
500  ** \retval Refer \ref cy_en_ks_status_t
501  **
502  ** \funcusage
503  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_ISR
504  *****************************************************************************/
505 cy_en_ks_status_t Cy_Keyscan_GetNextEvent(MXKEYSCAN_Type* base, cy_stc_key_event *event, cy_stc_keyscan_context_t *context);
506 
507 /**
508  *****************************************************************************
509  ** \brief Setup interrupt source to be accepted.
510  **
511  ** \param  base    [in]  Pointer to KeyScan instance register area.
512  ** \param  mask    [in]  The mask with the OR of the interrupt source to be accepted.
513  **                       See \ref group_keyscan_intr_mask_macro for the set of constants.
514  **
515  ** \retval Refer \ref cy_en_ks_status_t
516  **
517  ** \funcusage
518  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_ISR
519  *****************************************************************************/
520 cy_en_ks_status_t Cy_Keyscan_SetInterruptMask(MXKEYSCAN_Type* base, uint32_t mask);
521 
522 /**
523  *****************************************************************************
524  ** \brief Return interrupt mask setting.
525  **
526  ** \param  base [in]  Pointer to KeyScan instance register area.
527  ** \param  mask  [out] The mask with the OR of the interrupt source which is masked.
528  **                       See \ref group_keyscan_intr_mask_macro for the set of constants.
529  **
530  ** \retval Refer \ref cy_en_ks_status_t
531  **
532  ** \funcusage
533  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_ISR
534  *****************************************************************************/
535 cy_en_ks_status_t Cy_Keyscan_GetInterruptMask(MXKEYSCAN_Type* base, uint32_t *mask);
536 
537 /**
538  *****************************************************************************
539  ** \brief Return interrupt masked status.
540  **
541  ** \param  base    [in]  Pointer to KeyScan instance register area.
542  ** \param  status  [out] The mask with the OR of the interrupt source which occurs.
543  **                       See \ref group_keyscan_intr_mask_macro for the set of constants.
544  **
545  ** \retval Refer \ref cy_en_ks_status_t
546  **
547  ** \funcusage
548  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_ISR
549  *****************************************************************************/
550 cy_en_ks_status_t Cy_Keyscan_GetInterruptMaskedStatus(MXKEYSCAN_Type* base, uint32_t *status);
551 
552 /**
553  *****************************************************************************
554  ** \brief Return interrupt raw status.
555  **
556  ** \param  base    [in]  Pointer to Keyscan instance register area.
557  ** \param  status  [out] The mask with the OR of the interrupt source which occurs.
558  **                       See \ref group_keyscan_intr_mask_macro for the set of constants.
559  **
560  ** \retval Refer \ref cy_en_ks_status_t
561  **
562  ** \funcusage
563  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_ISR
564  *****************************************************************************/
565 cy_en_ks_status_t Cy_Keyscan_GetInterruptStatus(MXKEYSCAN_Type* base, uint32_t *status);
566 
567 /**
568  *****************************************************************************
569  ** \brief Clear interrupt status.
570  **
571  ** \param  base    [in]  Pointer to Keyscan instance register area.
572  ** \param  mask    [in]  The mask with the OR of the interrupt source to be cleared.
573  **                       See \ref group_keyscan_intr_mask_macro for the set of constants.
574  **
575  ** \retval Refer \ref cy_en_ks_status_t
576  **
577  ** \funcusage
578  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_ISR
579  *****************************************************************************/
580 cy_en_ks_status_t Cy_Keyscan_ClearInterrupt(MXKEYSCAN_Type* base, uint32_t mask);
581 
582 /**
583  *****************************************************************************
584  ** \brief Handler for keyscan interrupts.
585  ** Applications have to call this function from keyscan interrupt handler.
586  ** After successfully reading from HW FIFO and writing to FW FIFO this function
587  ** will notify application to read from the FW FIFO.
588  ** Application has to call Cy_Keyscan_getNextEvent() in a loop till
589  ** the return value is CY_KEYSCAN_EVENT_NONE
590  **
591  ** \param  base    [in]  Pointer to Keyscan instance register area.
592  ** \param  context [in]  Pointer to the context.
593  **
594  ** \retval Refer \ref cy_en_ks_status_t
595  **
596  ** \funcusage
597  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_ISR
598  *****************************************************************************/
599 cy_en_ks_status_t Cy_Keyscan_Interrupt_Handler(MXKEYSCAN_Type *base, cy_stc_keyscan_context_t *context);
600 
601 /**
602  *****************************************************************************
603  ** \brief Flush events from HW FIFO.
604  ** Flush the Fw FIFO also and it is equivalent to no key press events.
605  **
606  ** \param  base    [in]  Pointer to Keyscan instance register area.
607  ** \param  context [in]  Pointer to the context.
608  **
609  ** \retval Refer \ref cy_en_ks_status_t
610  **
611  *****************************************************************************/
612 cy_en_ks_status_t Cy_Keyscan_FlushEvents(MXKEYSCAN_Type *base, cy_stc_keyscan_context_t *context);
613 
614 /**
615  *****************************************************************************
616  ** \brief Enables Ghost detection
617  **
618  ** \param  base    [in]  Pointer to Keyscan instance register area.
619  **
620  ** \retval Refer \ref cy_en_ks_status_t
621  **
622  ** \funcusage
623  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_EnableGhostDetection
624  *****************************************************************************/
625 cy_en_ks_status_t Cy_Keyscan_EnableGhostDetection(MXKEYSCAN_Type *base);
626 
627 /**
628  *****************************************************************************
629  ** \brief Disables Ghost detection
630  **
631  ** \param  base    [in]  Pointer to Keyscan instance register area.
632  **
633  ** \retval Refer \ref cy_en_ks_status_t
634  **
635  ** \funcusage
636  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_DisableGhostDetection
637  *****************************************************************************/
638 cy_en_ks_status_t Cy_Keyscan_DisableGhostDetection(MXKEYSCAN_Type *base);
639 
640 /**
641  *****************************************************************************
642  ** \brief Enables Clock Stay On
643  ** Clock to the IP is always enabled.
644  **
645  ** \param  base    [in]  Pointer to Keyscan instance register area.
646  **
647  ** \retval Refer \ref cy_en_ks_status_t
648  **
649  ** \funcusage
650  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_EnableClockStayOn
651  *****************************************************************************/
652 cy_en_ks_status_t Cy_Keyscan_EnableClockStayOn(MXKEYSCAN_Type *base);
653 
654 /**
655  *****************************************************************************
656  ** \brief Disables Clock Stay On
657  **  When there is no activity detected the clock to the Keyscan is gated off.
658  **
659  ** \param  base    [in]  Pointer to Keyscan instance register area.
660  **
661  ** \retval Refer \ref cy_en_ks_status_t
662  **
663  ** \funcusage
664  ** \snippet keyscan/snippet/main.c snippet_Cy_Keyscan_DisableClockStayOn
665  *****************************************************************************/
666 cy_en_ks_status_t Cy_Keyscan_DisableClockStayOn(MXKEYSCAN_Type *base);
667 
668 /** \} group_keyscan_functions */
669 /** @} */
670 
671 
672 
673 
674 #ifdef __cplusplus
675 }
676 #endif
677 #endif /*(CY_IP_MXKEYSCAN) */
678 #endif /* __CY_KEYSCAN_H__ */
679 
680 /** \} group_keyscan */
681 /*****************************************************************************/
682 /* EOF (not truncated)                                                       */
683 /*****************************************************************************/
684