tao_z
2022-05-25 1044ba0d2286698d0da28112bffc0f114bef2134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
  ******************************************************************************
  * @file     xl_kbi.c
  * @author   Kirk ,xu.wang
  * @version  4.5.2
  * @date     Fri Mar 26 17:29:12 2021
  * @brief    This file provide function about KBI firmware program 
  ******************************************************************************
  * @attention
  *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */
    
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
 
/* Includes ---------------------------------------------------------------*/
#include "xl_kbi.h"
    
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @defgroup KBI KBI Module 
  * @brief KBI Driver Modules Library
  * @{
  */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/    
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
/** @defgroup KBI_Private_Functions
  * @{
  */ 
 
/**
  * @brief KBIĬÈϳõʼ»¯
  * @param KBIx: Ñ¡ÔñKBIÍâÉè.
  * @retval None.
  */
void KBI_Deinit(KBI_Type *KBIx)
{
    /* De-initialize the KBI module return to the default state. */
    KBIx->PE = 0u ;
    KBIx->ES = 0u;
    KBIx->SC = 0u ;
}
 
/**
  * @brief KBI³õʼ»¯
  * @param KBIx: Ñ¡ÔñKBIÍâÉè.
  * @param KBI_InitStruct: Ö¸Ïò°üº¬Ö¸¶¨KBIÍâÉèÅäÖÃÐÅÏ¢µÄKBI_InitTypeDef½á¹¹.
  * @retval None.
  */
void KBI_Init(KBI_Type *KBIx, const KBI_InitTypeDef *KBI_InitStruct)
{
    uint32_t tmpreg;
 
    /* configure the register */
    /* Get the CS Register. */
    tmpreg = KBIx->SC;
    /* clear the KBSPEN,KBMOD bit*/
    tmpreg &= ~ (KBI_SC_KBSPEN_MASK | KBI_SC_KBMOD_MASK);
    /* set the KBI_SC register */
    tmpreg |= ((KBI_InitStruct->KBI_SPRegValue)|(KBI_InitStruct->KBI_DetectMode));        
    /* Write to KBI SC */
    KBIx->SC = tmpreg ;
}
 
/**
  * @brief ÅäÖÃÒ»¸öÖ¸¶¨µÄpinλ.
  * @param KBIx: Ñ¡ÔñKBIÍâÉè.
  * @param KBI_Pin:  Ö¸¶¨pin(KBI_P0~KBI_P31)
  * @param EdgeSelect:  ±ßԵѡÔñ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg KBI_FallEdge_LowLevel: Ñ¡ÔñϽµÑØºÍµÍµçÆ½
  *            @arg KBI_RiseEdge_HighLevel: Ñ¡ÔñÉÏÉýÑØºÍ¸ßµçƽ
  * @retval None.
  */
void KBI_PinConfig(KBI_Type *KBIx, uint8_t KBI_Pin,uint8_t EdgeSelect)
{
    /*Enable the KBI pin speified.*/
    KBIx->PE |= (( (uint32_t)1    <<    KBI_Pin) & KBI_PE_KBIPE_MASK);
    
    /*first clear the KBI Edge Select speified.*/
    KBIx->ES &= ~(( (uint32_t)1u << KBI_Pin) & KBI_ES_KBEDG_MASK);
 
    /*Selet the falling edge/low-lever or rising edge/high-lever.*/
    KBIx->ES |= ( ((uint32_t)EdgeSelect << KBI_Pin) & KBI_ES_KBEDG_MASK);
}
 
/**
  * @brief ÅäÖÃËùÓеÄpinλ.
  * @param KBIx: Ñ¡ÔñKBIÍâÉè.
  * @param KBI_Pin: Ö¸¶¨pin(KBI_P0~KBI_P31)
  * @param EdgeRegSelect: Ñ¡Ôñpin±ßÔµ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg KBI_FallEdge_LowLevel: Ï½µÑØºÍµÍµçÆ½
  *            @arg KBI_RiseEdge_HighLevel: ÉÏÉýÑØºÍ¸ßµçƽ
  * @retval None.
  */
void KBI_BatchPinConfig(KBI_Type *KBIx, uint32_t KBI_Pin, uint32_t EdgeRegSelect)
{
    /* Set the pins whether enable or not.*/
    KBIx->PE = KBI_Pin;
    
    /* Set the pins edge selection.*/
    KBIx->ES = EdgeRegSelect;
}    
 
/**
  * @brief Æô¶¯Ò»¸öKBIÖжÏ.
  * Õâ¸öº¯ÊýÓÃÓÚÆô¶¯Ò»¸öKBIÖжÏ.
  * @param  KBIx: Ñ¡ÔñKBIÍâÉè
  * @param  NewState:KBIÖжÏʹÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: Ê¹ÄÜKBIÖжÏ
  *            @arg DISABLE: Ê¹ÄÜKBIÖжÏ
  * @retval None.
  */
void KBI_InterruptEn(KBI_Type *KBIx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Enable KBI Interrupt. */
        KBIx ->SC |= KBI_SC_KBIE_MASK;
    }
    else 
    {
        /* Disable KBI Interrupt. */
        KBIx ->SC &= ~KBI_SC_KBIE_MASK;
    }
}
 
/**
  * @brief Ö¸Ê¾ºÎʱ¼ì²âµ½KBIÖжÏÇëÇó.
  * @param KBIx: Ñ¡ÔñKBIÍâÉè¡£
  * @retval  ÊÇ·ñ¼ì²âµ½ÁËÒ»¸öKBIÖжÏÇëÇ󣺣¨SET or RESET£©
  */
FlagStatus KBI_GetInterruptFlag(const KBI_Type *KBIx)
{
    FlagStatus ret;
    /*Whether a KBI interrupt request is detected or not.*/
    if((KBIx->SC & KBI_SC_KBF_MASK) == KBI_SC_KBF_MASK)
    {
        ret = SET;
    }        
    else    
    {
        ret = RESET;
    }
    return ret;
}
 
/**
 * @brief Çå³ýÏàÓ¦µÄÖжϱê־λ¡£
 * @param KBIx: Ñ¡ÔñKBIÍâÉè¡£
 * @retval  None.
 */
void KBI_ClrInterruptFlag(KBI_Type *KBIx)
{
    /*Write a 1 to KBACK to clear the flag.*/
    KBIx->SC |= KBI_SC_KBACK_MASK;
}
 
/**
  * @brief ¸´Î»KIB_SP¼Ä´æÆ÷.
  * @param KBIx:  Ñ¡ÔñKBIÍâÉè¡£
  * @retval None.
  */
void KBI_RstSP(KBI_Type *KBIx)
{
    /*Write a 1 to RSTKBSP to reset clesr the KBIxSP register.*/
    KBIx->SC |= KBI_SC_RSTKBSP_MASK;
}
    
/**
  * @brief »ñÈ¡KBIÔ´pin¼Ä´æÆ÷×ֶΡ£
  * @param KBIx: Ñ¡ÔñKBIÍâÉè¡£
  * @retval the active pin defined as keyboard interrupt which is push. 
  */
uint32_t KBI_GetSP(const KBI_Type *KBIx)
{
    /*Get the active pin defined as keyboard interrrupt which is pushed.*/
    return (KBIx->SP & KBI_SP_SP_MASK); 
}
 
/**
  * @}
  */
 
/**
  * @}
  */
 
/**
  * @}
  */
 
 
#ifdef __cplusplus
}
#endif /* __cplusplus */