PAN1080 Peripheral API
pan_kscan.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Panchip Technology Corp. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
14#ifndef __PAN_KSCAN_H__
15#define __PAN_KSCAN_H__
16
22#ifdef __cplusplus
23extern "C"
24{
25#endif
26
30#define KS_PERIPHRAL_ENABLE (0X00000001)
31#define KS_WAKEUP_ENABLE (0X00000002)
32#define KS_WAKEUP_AND_PERIPH_ENABLE (0X00000003)
38#define KS_INTERVAL_TIME_CLK_1 (0X0)
39#define KS_INTERVAL_TIME_CLK_2 (0X1)
40#define KS_INTERVAL_TIME_CLK_4 (0X2)
41#define KS_INTERVAL_TIME_CLK_8 (0X3)
42#define KS_INTERVAL_TIME_CLK_16 (0X4)
43#define KS_INTERVAL_TIME_CLK_32 (0X5)
44#define KS_INTERVAL_TIME_CLK_64 (0X6)
45#define KS_INTERVAL_TIME_CLK_128 (0X7)
46#define KS_INTERVAL_TIME_CLK_256 (0X8)
47#define KS_INTERVAL_TIME_CLK_512 (0X9)
48#define KS_INTERVAL_TIME_CLK_1024 (0XA)
49#define KS_INTERVAL_TIME_CLK_2048 (0XB)
50#define KS_INTERVAL_TIME_CLK_4K (0XC)
51#define KS_INTERVAL_TIME_CLK_8K (0XD)
52#define KS_INTERVAL_TIME_CLK_16K (0XE)
53#define KS_INTERVAL_TIME_CLK_32K (0XF)
67__STATIC_INLINE void KS_Enable(KSCAN_T *ks,FunctionalState NewState,uint32_t func)
68{
69 (NewState != DISABLE)?((ks)->KS_EN |= func):((ks)->KS_EN &= ~func);
70}
71
72
80__STATIC_INLINE void KS_InputEnable(KSCAN_T *ks,FunctionalState NewState,uint32_t func)
81{
82 (NewState != DISABLE)?((ks)->KS_IO_CFG |= func):((ks)->KS_IO_CFG &= ~func);
83}
84
92__STATIC_INLINE void KS_OutputEnable(KSCAN_T *ks,FunctionalState NewState,uint32_t func)
93{
94 (NewState != DISABLE)?((ks)->KS_IO_CFG |= (func << 8)):((ks)->KS_IO_CFG &= ~(func << 8));
95}
96
103__STATIC_INLINE void KS_IntEnable(KSCAN_T *ks,FunctionalState NewState)
104{
105 (NewState != DISABLE)?((ks)->KS_INT_CFG |= KS_INT_ENABLE_Msk):((ks)->KS_INT_CFG &= ~KS_INT_ENABLE_Msk);
106}
107
116__STATIC_INLINE bool KS_StatusCheck(KSCAN_T *ks,uint32_t func)
117{
118 return ((ks)->KS_INT_CFG & func)?(true):(false);
119}
120
129__STATIC_INLINE void KS_ClearFlag(KSCAN_T *ks,uint32_t func)
130{
131 (ks)->KS_INT_CFG |= func;
132}
133
140__STATIC_INLINE void KS_SetKeyscanPolarity(KSCAN_T *ks,FunctionalState NewState)
141{
142 (NewState != DISABLE)?((ks)->KS_CFG |= KS_POLARITY_VALID_HIGH_Msk):((ks)->KS_CFG &= ~KS_POLARITY_VALID_HIGH_Msk);
143}
144
151__STATIC_INLINE void KS_ClearKeyscanStatus(KSCAN_T *ks,FunctionalState NewState)
152{
153 (NewState != DISABLE)?((ks)->KS_CFG |= KS_STATUS_CLEAR_Msk):((ks)->KS_CFG &= ~KS_STATUS_CLEAR_Msk);
154}
155
163__STATIC_INLINE void KS_SetFrameInterval(KSCAN_T *ks,uint32_t func)
164{
165 (ks)->KS_CFG = ((ks)->KS_CFG & ~KS_SCAN_INTERVAL_Msk) | (func << KS_SCAN_INTERVAL_Pos);
166}
167
173__STATIC_INLINE uint32_t KS_GetFrameInterval(KSCAN_T *ks)
174{
175 return (((ks)->KS_CFG & KS_SCAN_INTERVAL_Msk) >> KS_SCAN_INTERVAL_Pos);
176}
177
185__STATIC_INLINE void KS_SetRowInterval(KSCAN_T *ks,uint32_t func)
186{
187 (ks)->KS_CFG = ((ks)->KS_CFG & ~KS_ROW_INTERVAL_Msk) | (func << KS_ROW_INTERVAL_Pos);
188}
194__STATIC_INLINE uint32_t KS_GetRowInterval(KSCAN_T *ks)
195{
196 return (((ks)->KS_CFG & KS_ROW_INTERVAL_Msk) >> KS_ROW_INTERVAL_Pos);
197}
198
206__STATIC_INLINE void KS_SetDebounceTime(KSCAN_T *ks,uint32_t func)
207{
208 (ks)->KS_CFG = ((ks)->KS_CFG & ~KS_DEBOUNCE_TIME_Msk) | (func << KS_DEBOUNCE_TIME_Pos);
209}
210
216__STATIC_INLINE uint32_t KS_GetDebounceTime(KSCAN_T *ks)
217{
218 return (((ks)->KS_CFG & KS_DEBOUNCE_TIME_Msk) >> KS_DEBOUNCE_TIME_Pos);
219}
227__STATIC_INLINE void KS_WaitScanFinish(KSCAN_T *ks,bool enable)
228{
229 (enable) ? (ks->KS_EN |= KS_DLY_DISABLE_Msk) : (ks->KS_EN &= ~KS_DLY_DISABLE_Msk);
230}
237uint32_t KS_ReadKeyRowInfo(KSCAN_T *ks,uint8_t rowIdx);
238
246bool KS_IsKeyPressed(KSCAN_T *ks,uint8_t rowIdx,uint8_t colIdx);
247
250#ifdef __cplusplus
251}
252#endif
253
254#endif /* __PAN_KSCAN_H__ */
__STATIC_INLINE void KS_SetFrameInterval(KSCAN_T *ks, uint32_t func)
This function is used to set keyscan interval time between current frame to next.
Definition: pan_kscan.h:163
__STATIC_INLINE void KS_WaitScanFinish(KSCAN_T *ks, bool enable)
This function is used to enable keyscan delay function,if enabled isr will reported after scan finish...
Definition: pan_kscan.h:227
__STATIC_INLINE bool KS_StatusCheck(KSCAN_T *ks, uint32_t func)
This function is used to check keyscan status.
Definition: pan_kscan.h:116
__STATIC_INLINE void KS_ClearKeyscanStatus(KSCAN_T *ks, FunctionalState NewState)
This function is used to clear all key status enable.
Definition: pan_kscan.h:151
__STATIC_INLINE uint32_t KS_GetRowInterval(KSCAN_T *ks)
This function is used to get keyscan interval time between current row to next.
Definition: pan_kscan.h:194
uint32_t KS_ReadKeyRowInfo(KSCAN_T *ks, uint8_t rowIdx)
This function is used to read key info.
__STATIC_INLINE void KS_OutputEnable(KSCAN_T *ks, FunctionalState NewState, uint32_t func)
This function is set keyscan output enable function.
Definition: pan_kscan.h:92
__STATIC_INLINE void KS_SetDebounceTime(KSCAN_T *ks, uint32_t func)
This function is used to set keyscan debounce time.
Definition: pan_kscan.h:206
__STATIC_INLINE void KS_ClearFlag(KSCAN_T *ks, uint32_t func)
This function is used to clear keyscan status.
Definition: pan_kscan.h:129
__STATIC_INLINE void KS_SetKeyscanPolarity(KSCAN_T *ks, FunctionalState NewState)
This function is used to set keyscan polarity as high.
Definition: pan_kscan.h:140
__STATIC_INLINE uint32_t KS_GetFrameInterval(KSCAN_T *ks)
This function is used to get keyscan interval time between current frame to next.
Definition: pan_kscan.h:173
__STATIC_INLINE void KS_SetRowInterval(KSCAN_T *ks, uint32_t func)
This function is used to set keyscan interval time between current row to next.
Definition: pan_kscan.h:185
__STATIC_INLINE void KS_IntEnable(KSCAN_T *ks, FunctionalState NewState)
This function is used to check keyscan status.
Definition: pan_kscan.h:103
__STATIC_INLINE uint32_t KS_GetDebounceTime(KSCAN_T *ks)
This function is used to get keyscan debounce time.
Definition: pan_kscan.h:216
__STATIC_INLINE void KS_InputEnable(KSCAN_T *ks, FunctionalState NewState, uint32_t func)
This function is set keyscan input enable function.
Definition: pan_kscan.h:80
bool KS_IsKeyPressed(KSCAN_T *ks, uint8_t rowIdx, uint8_t colIdx)
This function is used to read key info.
__STATIC_INLINE void KS_Enable(KSCAN_T *ks, FunctionalState NewState, uint32_t func)
This function is set keyscan enable bit.
Definition: pan_kscan.h:67