1 /*********************************************************************************************************//**
2 * @file ht32f5xxxx_tkey.c
3 * @version $Rev:: 5500 $
4 * @date $Date:: 2021-07-20 #$
5 * @brief This file provides all the TKEY firmware functions.
6 *************************************************************************************************************
7 * @attention
8 *
9 * Firmware Disclaimer Information
10 *
11 * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
12 * code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
13 * proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
14 * other intellectual property laws.
15 *
16 * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
17 * code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
18 * other than HOLTEK and the customer.
19 *
20 * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
21 * only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
22 * the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
23 * the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
24 *
25 * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
26 ************************************************************************************************************/
27
28 /* Includes ------------------------------------------------------------------------------------------------*/
29 #include "ht32f5xxxx_tkey.h"
30
31 /** @addtogroup HT32F5xxxx_Peripheral_Driver HT32F5xxxx Peripheral Driver
32 * @{
33 */
34
35 /** @defgroup TKEY TKEY
36 * @brief TKEY driver modules
37 * @{
38 */
39
40
41 /* Private constants ---------------------------------------------------------------------------------------*/
42 /** @defgroup TKEY_Private_Define TKEY private definitions
43 * @{
44 */
45 #define TKCLKSEL_MASK (0x80000000)
46 /**
47 * @}
48 */
49
50 /* Global functions ----------------------------------------------------------------------------------------*/
51 /** @defgroup TKEY_Exported_Functions TKEY exported functions
52 * @{
53 */
54 /*********************************************************************************************************//**
55 * @brief Deinitialize the TKEY peripheral registers to their default reset values.
56 * @retval None
57 ************************************************************************************************************/
TKEY_DeInit(void)58 void TKEY_DeInit(void)
59 {
60 RSTCU_PeripReset_TypeDef RSTCUReset = {{0}};
61
62 RSTCUReset.Bit.TKEY = 1;
63 RSTCU_PeripReset(RSTCUReset, ENABLE);
64 }
65
66 /*********************************************************************************************************//**
67 * @brief Configure Touch key IP clock source.
68 * @param Sel: Specify the Touch key IP clock source..
69 * This parameter can be one of the following values:
70 * @arg TKEY_PCLK : PCLK.
71 * @arg TKEY_LSI : LSI.
72 * @retval None
73 ************************************************************************************************************/
TKEY_IPClockConfig(TKEY_IP_CLK_Enum Sel)74 void TKEY_IPClockConfig(TKEY_IP_CLK_Enum Sel)
75 {
76 Assert_Param(IS_TKEY_IP_CLK(Sel));
77
78 HT_TKEY->TKCR = (HT_TKEY->TKCR & TKCLKSEL_MASK) | (Sel << 31);
79 }
80
81 /*********************************************************************************************************//**
82 * @brief Configure the RefOSC Delay time.
83 * @param Sel: Specify the periodic auto scan mode time out.
84 * This parameter can be one of the following values:
85 * @arg TKEY_RefOSC_DelayTime_0 : 4 RefOSC clock.
86 * @arg TKEY_RefOSC_DelayTime_1 : 2 RefOSC clock.
87 * @arg TKEY_RefOSC_DelayTime_2 : 4 RefOSC clock.
88 * @arg TKEY_RefOSC_DelayTime_3 : 8 RefOSC clock.
89 * @arg TKEY_RefOSC_DelayTime_4 : 16 RefOSC clock.
90 * @arg TKEY_RefOSC_DelayTime_5 : 32 RefOSC clock.
91 * @arg TKEY_RefOSC_DelayTime_6 : 64 RefOSC clock.
92 * @arg TKEY_RefOSC_DelayTime_7 : 4 RefOSC clock.
93 * @retval None
94 ************************************************************************************************************/
TKEY_RefOSCDelayTimeConfig(TKEY_RefOSC_DelayTime_Enum Sel)95 void TKEY_RefOSCDelayTimeConfig(TKEY_RefOSC_DelayTime_Enum Sel)
96 {
97 /* Check the parameters */
98 Assert_Param(IS_TKEY_RefOSC_DelayTime(Sel));
99
100 HT_TKEY->TKCR = (HT_TKEY->TKCR & ~(7 << 13)) | Sel;
101 }
102 /*********************************************************************************************************//**
103 * @brief Configure the periodic auto scan mode time out.
104 * @param Sel: Specify the periodic auto scan mode time out.
105 * This parameter can be one of the following values:
106 * @arg TKEY_PASM_TIMEOUT_0 : 2^13/FLIRC.
107 * @arg TKEY_PASM_TIMEOUT_1 : 2^14/FLIRC.
108 * @arg TKEY_PASM_TIMEOUT_2 : 2^15/FLIRC.
109 * @arg TKEY_PASM_TIMEOUT_3 : 2^16/FLIRC.
110 * @arg TKEY_PASM_TIMEOUT_4 : 2^17/FLIRC.
111 * @arg TKEY_PASM_TIMEOUT_5 : 2^18/FLIRC.
112 * @retval None
113 ************************************************************************************************************/
TKEY_PASMTimeoutConfig(TKEY_PASM_TIMEOUT_Enum Sel)114 void TKEY_PASMTimeoutConfig(TKEY_PASM_TIMEOUT_Enum Sel)
115 {
116 /* Check the parameters */
117 Assert_Param(IS_TKEY_PASM_TIMEOUT(Sel));
118
119 HT_TKEY->TKCR = (HT_TKEY->TKCR & ~(7 << 10)) | Sel;
120 }
121
122 /*********************************************************************************************************//**
123 * @brief Configure the periodic auto scan mode period.
124 * @param Sel: Specify the periodic auto scan mode period.
125 * This parameter can be one of the following values:
126 * @arg TKEY_PASM_PERIOD_0 : 2^14/FLIRC.
127 * @arg TKEY_PASM_PERIOD_1 : 2^13/FLIRC.
128 * @arg TKEY_PASM_PERIOD_2 : 2^12/FLIRC.
129 * @arg TKEY_PASM_PERIOD_3 : 2^11/FLIRC.
130 * @retval None
131 ************************************************************************************************************/
TKEY_PASMPeriodConfig(TKEY_PASM_PERIOD_Enum Sel)132 void TKEY_PASMPeriodConfig(TKEY_PASM_PERIOD_Enum Sel)
133 {
134 /* Check the parameters */
135 Assert_Param(IS_TKEY_PASM_PERIOD(Sel));
136
137 HT_TKEY->TKCR = (HT_TKEY->TKCR & ~(3 << 8)) | Sel;
138 }
139
140 /*********************************************************************************************************//**
141 * @brief Configure the touch key 16-bit counter clock source.
142 * @param Sel: Specify the 16-bit counter clock source.
143 * This parameter can be one of the following values:
144 * @arg TKEY_TK16S_CLK_0 : TKCLK/16.
145 * @arg TKEY_TK16S_CLK_1 : TKCLK/32.
146 * @arg TKEY_TK16S_CLK_2 : TKCLK/64.
147 * @arg TKEY_TK16S_CLK_3 : TKCLK/128.
148 * @retval None
149 ************************************************************************************************************/
TKEY_16BitCounterClockConfig(TKEY_TK16S_CLK_Enum Sel)150 void TKEY_16BitCounterClockConfig(TKEY_TK16S_CLK_Enum Sel)
151 {
152 /* Check the parameters */
153 Assert_Param(IS_TKEY_TK16S_CLK(Sel));
154
155 HT_TKEY->TKCR = (HT_TKEY->TKCR & ~(3 << 5)) | Sel;
156 }
157
158 /*********************************************************************************************************//**
159 * @brief Configure the touch key OSC frequency.
160 * @param Sel: Specify the Touch Key frequency.
161 * This parameter can be one of the following values:
162 * @arg TKEY_TKFS_FREQ_0 : 1MHz.
163 * @arg TKEY_TKFS_FREQ_1 : 3MHz.
164 * @arg TKEY_TKFS_FREQ_2 : 7MHz.
165 * @arg TKEY_TKFS_FREQ_3 : 11MHz.
166 * @retval None
167 ************************************************************************************************************/
TKEY_OSCFreqConfig(TKEY_TKFS_FREQ_Enum Sel)168 void TKEY_OSCFreqConfig(TKEY_TKFS_FREQ_Enum Sel)
169 {
170 /* Check the parameters */
171 Assert_Param(IS_TKEY_TKFS_FREQ(Sel));
172
173 HT_TKEY->TKCR = (HT_TKEY->TKCR & ~(3 << 3)) | Sel;
174 }
175
176 /*********************************************************************************************************//**
177 * @brief Configure the touch key operation mode.
178 * @param Sel: Specify the Touch Key mode.
179 * This parameter can be one of the following values:
180 * @arg TKEY_MODE_AUTOSCAN : Auto scan mode.
181 * @arg TKEY_MODE_MANUAL : Manual mode.
182 * @arg TKEY_MODE_PASM : Periodic auto scan mode.
183 * @retval None
184 ************************************************************************************************************/
TKEY_ModeConfig(TKEY_MODE_Enum Sel)185 void TKEY_ModeConfig(TKEY_MODE_Enum Sel)
186 {
187 /* Check the parameters */
188 Assert_Param(IS_TKEY_MODE(Sel));
189
190 HT_TKEY->TKCR = (HT_TKEY->TKCR & ~(3 << 1)) | Sel;
191 }
192
193 /*********************************************************************************************************//**
194 * @brief Touch Key detection control.
195 * @param NewState: This parameter can be ENABLE or DISABLE.
196 * @retval None
197 ************************************************************************************************************/
TKEY_StartCmd(ControlStatus NewState)198 void TKEY_StartCmd(ControlStatus NewState)
199 {
200 /* Check the parameters */
201 Assert_Param(IS_CONTROL_STATUS(NewState));
202
203 if (NewState != DISABLE)
204 {
205 HT_TKEY->TKCR |= (1 << 0);
206 }
207 else
208 {
209 HT_TKEY->TKCR &= ~(1 << 0);
210 }
211 }
212
213 /*********************************************************************************************************//**
214 * @brief Enable or Disable the specified TKEY interrupt.
215 * @param TKEY_Int: specify if the TKEY interrupt source to be enabled or disabled.
216 * This parameter can be any combination of the following values:
217 * @arg TKEY_INT_TKRCOVE : 8-bit time slot counter overflow interrupt
218 * @arg TKEY_INT_TKTHE : Touch Key threshold match interrupt
219 * @param NewState: This parameter can be ENABLE or DISABLE.
220 * @retval None
221 ************************************************************************************************************/
TKEY_IntConfig(u32 TKEY_Int,ControlStatus NewState)222 void TKEY_IntConfig(u32 TKEY_Int, ControlStatus NewState)
223 {
224 /* Check the parameters */
225 Assert_Param(IS_TKEY_INT(TKEY_Int));
226 Assert_Param(IS_CONTROL_STATUS(NewState));
227
228 if (NewState != DISABLE)
229 {
230 HT_TKEY->TKIER |= TKEY_Int;
231 }
232 else
233 {
234 HT_TKEY->TKIER &= ~TKEY_Int;
235 }
236 }
237
238 /*********************************************************************************************************//**
239 * @brief Check whether the specified TKEY flag has been set or not.
240 * @param TKEY_Flag: specify the flag that is to be check.
241 * This parameter can be one of the following values:
242 * @arg TKEY_FLAG_TKBUSY : Touch Key busy flag
243 * @arg TKEY_FLAG_TKCFOV : Touch Key 16-bit C/F counter overflow flag
244 * @arg TKEY_FLAG_TK16OV : Touch Key 16-bit counter overflow flag
245 * @arg TKEY_FLAG_TKRCOVF : 8-bit time slot counter overflow flag
246 * @arg TKEY_FLAG_TKTHF : Touch Key threshold match flag
247 * @retval SET or RESET
248 ************************************************************************************************************/
TKEY_GetFlagStatus(u32 TKEY_Flag)249 FlagStatus TKEY_GetFlagStatus(u32 TKEY_Flag)
250 {
251 /* Check the parameters */
252 Assert_Param(IS_TKEY_FLAG(TKEY_Flag));
253
254 if ((HT_TKEY->TKSR & TKEY_Flag) != RESET)
255 {
256 return SET;
257 }
258 else
259 {
260 return RESET;
261 }
262 }
263
264 /*********************************************************************************************************//**
265 * @brief Clear the specified TKEY flag.
266 * @param TKEY_Flag: specify the flag that is to be cleared.
267 * This parameter can be one of the following values:
268 * @arg TKEY_FLAG_TKCFOV : Touch Key 16-bit C/F counter overflow flag
269 * @arg TKEY_FLAG_TK16OV : Touch Key 16-bit counter overflow flag
270 * @arg TKEY_FLAG_TKRCOVF : 8-bit time slot counter overflow flag
271 * @arg TKEY_FLAG_TKTHF : Touch Key threshold match flag
272 * @retval None
273 ************************************************************************************************************/
TKEY_ClearFlag(u32 TKEY_Flag)274 void TKEY_ClearFlag(u32 TKEY_Flag)
275 {
276 /* Check the parameters */
277 Assert_Param(IS_TKEY_FLAG_CLEAR(TKEY_Flag));
278
279 HT_TKEY->TKSR = TKEY_Flag;
280 }
281
282 /*********************************************************************************************************//**
283 * @brief Get the touch key 16-bit counter value.
284 * @retval The counter value
285 ************************************************************************************************************/
TKEY_Get16BitCounterValue(void)286 u32 TKEY_Get16BitCounterValue(void)
287 {
288 return HT_TKEY->TKCNTR;
289 }
290
291 /*********************************************************************************************************//**
292 * @brief Set the 8-bit time slot counter reload value.
293 * @param Reload: Specify the counter reload value.
294 * @retval None
295 ************************************************************************************************************/
TKEY_Set8BitCounterReload(u32 Reload)296 void TKEY_Set8BitCounterReload(u32 Reload)
297 {
298 HT_TKEY->TKTSCRR = Reload;
299 }
300
301 /*********************************************************************************************************//**
302 * @brief Get the 8-bit time slot counter reload value.
303 * @retval The counter reload value
304 ************************************************************************************************************/
TKEY_Get8BitCounterReload(void)305 u32 TKEY_Get8BitCounterReload(void)
306 {
307 return HT_TKEY->TKTSCRR;
308 }
309
310 /*********************************************************************************************************//**
311 * @brief Configure the 8-bit time slot counter clock source.
312 * @param TKMn: TKM_0 ~ TKM_5
313 * @param Sel: Specify the 8-bit time slot counter clock source.
314 * This parameter can be one of the following values:
315 * @arg TKM_TSS_CLK_0 : Ref OSC.
316 * @arg TKM_TSS_CLK_1 : TKCLK/32.
317 * @arg TKM_TSS_CLK_2 : TKCLK/64.
318 * @arg TKM_TSS_CLK_3 : TKCLK/128.
319 * @retval None
320 ************************************************************************************************************/
TKM_TimeSlotCounterClockConfig(TKM_Enum TKMn,TKM_TSS_CLK_Enum Sel)321 void TKM_TimeSlotCounterClockConfig(TKM_Enum TKMn, TKM_TSS_CLK_Enum Sel)
322 {
323 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
324
325 /* Check the parameters */
326 Assert_Param(IS_TKM(TKMn));
327 Assert_Param(IS_TKM_TSS_CLK(Sel));
328
329 TKMx->CR = (TKMx->CR & ~(3 << 8)) | Sel;
330 }
331
332 /*********************************************************************************************************//**
333 * @brief Enable or Disable the Reference OSC.
334 * @param TKMn: TKM_0 ~ TKM_5
335 * @param NewState: This parameter can be ENABLE or DISABLE.
336 * @retval None
337 ************************************************************************************************************/
TKM_RefOSCCmd(TKM_Enum TKMn,ControlStatus NewState)338 void TKM_RefOSCCmd(TKM_Enum TKMn, ControlStatus NewState)
339 {
340 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
341
342 /* Check the parameters */
343 Assert_Param(IS_TKM(TKMn));
344 Assert_Param(IS_CONTROL_STATUS(NewState));
345
346 if (NewState != DISABLE)
347 {
348 TKMx->CR |= (1 << 7);
349 }
350 else
351 {
352 TKMx->CR &= ~(1 << 7);
353 }
354 }
355
356 /*********************************************************************************************************//**
357 * @brief Enable or Disable the Key OSC.
358 * @param TKMn: TKM_0 ~ TKM_5
359 * @param NewState: This parameter can be ENABLE or DISABLE.
360 * @retval None
361 ************************************************************************************************************/
TKM_KeyOSCCmd(TKM_Enum TKMn,ControlStatus NewState)362 void TKM_KeyOSCCmd(TKM_Enum TKMn, ControlStatus NewState)
363 {
364 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
365
366 /* Check the parameters */
367 Assert_Param(IS_TKM(TKMn));
368 Assert_Param(IS_CONTROL_STATUS(NewState));
369
370 if (NewState != DISABLE)
371 {
372 TKMx->CR |= (1 << 6);
373 }
374 else
375 {
376 TKMx->CR &= ~(1 << 6);
377 }
378 }
379
380 /*********************************************************************************************************//**
381 * @brief Enable or Disable the Multi-frequency.
382 * @param TKMn: TKM_0 ~ TKM_5
383 * @param NewState: This parameter can be ENABLE or DISABLE.
384 * @retval None
385 ************************************************************************************************************/
TKM_MultiFreqCmd(TKM_Enum TKMn,ControlStatus NewState)386 void TKM_MultiFreqCmd(TKM_Enum TKMn, ControlStatus NewState)
387 {
388 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
389
390 /* Check the parameters */
391 Assert_Param(IS_TKM(TKMn));
392 Assert_Param(IS_CONTROL_STATUS(NewState));
393
394 if (NewState != DISABLE)
395 {
396 TKMx->CR |= (1 << 5);
397 }
398 else
399 {
400 TKMx->CR &= ~(1 << 5);
401 }
402 }
403
404 /*********************************************************************************************************//**
405 * @brief Configure the C/F OSC frequency-hopping.
406 * @param TKMn: TKM_0 ~ TKM_5
407 * @param Sel: Specify the C/F OSC frequency-hopping method.
408 * This paramter can be one of the following values:
409 * @arg TKM_SOF_CTRL_SW :
410 * @arg TKM_SOF_CTRL_HW :
411 * @retval None
412 ************************************************************************************************************/
TKM_SOFCtrlConfig(TKM_Enum TKMn,TKM_SOF_CTRL_Enum Sel)413 void TKM_SOFCtrlConfig(TKM_Enum TKMn, TKM_SOF_CTRL_Enum Sel)
414 {
415 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
416
417 /* Check the parameters */
418 Assert_Param(IS_TKM(TKMn));
419 Assert_Param(IS_TKM_SOF_CTRL(Sel));
420
421 TKMx->CR = (TKMx->CR & ~(1 << 3)) | Sel;
422 }
423
424 /*********************************************************************************************************//**
425 * @brief Configure the Key OSC and the Reference OSC frequency.
426 * @param TKMn: TKM_0 ~ TKM_5
427 * @param Sel: Specify the OSC frequency.
428 * This paramter can be one of the following values:
429 * @arg TKM_SOF_FREQ_0 : 1.020MHz.
430 * @arg TKM_SOF_FREQ_1 : 1.040MHz.
431 * @arg TKM_SOF_FREQ_2 : 1.059MHz.
432 * @arg TKM_SOF_FREQ_3 : 1.074MHz.
433 * @arg TKM_SOF_FREQ_4 : 1.085MHz.
434 * @arg TKM_SOF_FREQ_5 : 1.099MHz.
435 * @arg TKM_SOF_FREQ_6 : 1.111MHz.
436 * @arg TKM_SOF_FREQ_7 : 1.125MHz.
437 * @retval None
438 ************************************************************************************************************/
TKM_SOFFreqConfig(TKM_Enum TKMn,TKM_SOF_FREQ_Enum Sel)439 void TKM_SOFFreqConfig(TKM_Enum TKMn, TKM_SOF_FREQ_Enum Sel)
440 {
441 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
442
443 /* Check the parameters */
444 Assert_Param(IS_TKM(TKMn));
445 Assert_Param(IS_TKM_SOF_FREQ(Sel));
446
447 TKMx->CR = (TKMx->CR & ~(7 << 0)) | Sel;
448 }
449
450 /*********************************************************************************************************//**
451 * @brief Enable or Disable the specified Touch Key.
452 * @param TKMn: TKM_0 ~ TKM_5
453 * @param Key: TKM_KEY_0 ~ TKM_KEY_3
454 * @param NewState: This parameter can be ENABLE or DISABLE.
455 * @retval None
456 ************************************************************************************************************/
TKM_KeyCmd(TKM_Enum TKMn,TKM_KEY_Enum Key,ControlStatus NewState)457 void TKM_KeyCmd(TKM_Enum TKMn, TKM_KEY_Enum Key, ControlStatus NewState)
458 {
459 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
460
461 /* Check the parameters */
462 Assert_Param(IS_TKM(TKMn));
463 Assert_Param(IS_TKM_KEY(Key));
464 Assert_Param(IS_CONTROL_STATUS(NewState));
465
466 if (NewState != DISABLE)
467 {
468 TKMx->KCFGR |= (1 << Key);
469 }
470 else
471 {
472 TKMx->KCFGR &= ~(1 << Key);
473 }
474 }
475
476 /*********************************************************************************************************//**
477 * @brief Configure the Time Slot X key selection (for auto scan mode & Periodic auto scan mode).
478 * @param TKMn: TKM_0 ~ TKM_5
479 * @param Slot: TKM_TIME_SLOT_0 ~ TKM_TIME_SLOT_3
480 * @param Key: TKM_KEY_0 ~ TKM_KEY_3
481 * @retval None
482 ************************************************************************************************************/
TKM_TimeSlotKeyConfig(TKM_Enum TKMn,TKM_TIME_SLOT_Enum Slot,TKM_KEY_Enum Key)483 void TKM_TimeSlotKeyConfig(TKM_Enum TKMn, TKM_TIME_SLOT_Enum Slot, TKM_KEY_Enum Key)
484 {
485 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
486 u32 offset = (16 + (Slot * 2));
487
488 /* Check the parameters */
489 Assert_Param(IS_TKM(TKMn));
490 Assert_Param(IS_TKM_TIME_SLOT(Slot));
491 Assert_Param(IS_TKM_KEY(Key));
492
493 TKMx->KCFGR = (TKMx->KCFGR & ~(3 << offset)) | (Key << offset);
494 }
495
496 /*********************************************************************************************************//**
497 * @brief Configure the Key threshold.
498 * @param TKMn: TKM_0 ~ TKM_5
499 * @param Key: TKM_KEY_0 ~ TKM_KEY_3
500 * @param Sel: Specify the Key threshold.
501 * This parameter can be one of the following values:
502 * @arg TKM_KEY_THR_LOWER :
503 * @arg TKM_KEY_THR_UPPER :
504 * @retval None
505 ************************************************************************************************************/
TKM_KeyThresholdConfig(TKM_Enum TKMn,TKM_KEY_Enum Key,TKM_KEY_THR_Enum Sel)506 void TKM_KeyThresholdConfig(TKM_Enum TKMn, TKM_KEY_Enum Key, TKM_KEY_THR_Enum Sel)
507 {
508 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
509 u32 offset = (8 + Key);
510
511 /* Check the parameters */
512 Assert_Param(IS_TKM(TKMn));
513 Assert_Param(IS_TKM_KEY(Key));
514 Assert_Param(IS_TKM_KEY_THR(Sel));
515
516 TKMx->KCFGR = (TKMx->KCFGR & ~(1 << offset)) | (Sel << offset);
517 }
518
519 /*********************************************************************************************************//**
520 * @brief Check whether the specified key threshold match flag has been set or not.
521 * @param TKMn: TKM_0 ~ TKM_5
522 * @param Key: TKM_KEY_0 ~ TKM_KEY_3
523 * @retval SET or RESET
524 ************************************************************************************************************/
TKM_GetMatchFlagStatus(TKM_Enum TKMn,TKM_KEY_Enum Key)525 FlagStatus TKM_GetMatchFlagStatus(TKM_Enum TKMn, TKM_KEY_Enum Key)
526 {
527 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
528
529 /* Check the parameters */
530 Assert_Param(IS_TKM(TKMn));
531 Assert_Param(IS_TKM_KEY(Key));
532
533 if ((TKMx->SR & (1 << Key)) != RESET)
534 {
535 return SET;
536 }
537 else
538 {
539 return RESET;
540 }
541 }
542
543 /*********************************************************************************************************//**
544 * @brief Clear the specified key threshold match flag.
545 * @param TKMn: TKM_0 ~ TKM_5
546 * @param Key: TKM_KEY_0 ~ TKM_KEY_3
547 * @retval None
548 ************************************************************************************************************/
TKM_ClearMatchFlag(TKM_Enum TKMn,TKM_KEY_Enum Key)549 void TKM_ClearMatchFlag(TKM_Enum TKMn, TKM_KEY_Enum Key)
550 {
551 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
552
553 /* Check the parameters */
554 Assert_Param(IS_TKM(TKMn));
555 Assert_Param(IS_TKM_KEY(Key));
556
557 TKMx->SR = (1 << Key);
558 }
559
560 /*********************************************************************************************************//**
561 * @brief Set the reference OSC capacitor value.
562 * @param TKMn: TKM_0 ~ TKM_5
563 * @param Value: Specify the capacitor value between 0x000 ~ 0x3FF.
564 * @retval None
565 ************************************************************************************************************/
TKM_SetRefOSCCapacitor(TKM_Enum TKMn,u32 Value)566 void TKM_SetRefOSCCapacitor(TKM_Enum TKMn, u32 Value)
567 {
568 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
569
570 /* Check the parameters */
571 Assert_Param(IS_TKM(TKMn));
572
573 TKMx->ROCPR = Value;
574 }
575
576 /*********************************************************************************************************//**
577 * @brief Get the reference OSC capacitor value.
578 * @param TKMn: TKM_0 ~ TKM_5
579 * @retval The capacitor value
580 ************************************************************************************************************/
TKM_GetRefOSCCapacitor(TKM_Enum TKMn)581 u32 TKM_GetRefOSCCapacitor(TKM_Enum TKMn)
582 {
583 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
584
585 /* Check the parameters */
586 Assert_Param(IS_TKM(TKMn));
587
588 return TKMx->ROCPR;
589 }
590
591 /*********************************************************************************************************//**
592 * @brief Set the key capacitor value.
593 * @param TKMn: TKM_0 ~ TKM_5
594 * @param Key: TKM_KEY_0 ~ TKM_KEY_3
595 * @param Value: Specify the capacitor value between 0x000 ~ 0x3FF.
596 * @retval None
597 ************************************************************************************************************/
TKM_SetKeyCapacitor(TKM_Enum TKMn,TKM_KEY_Enum Key,u32 Value)598 void TKM_SetKeyCapacitor(TKM_Enum TKMn, TKM_KEY_Enum Key, u32 Value)
599 {
600 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
601
602 /* Check the parameters */
603 Assert_Param(IS_TKM(TKMn));
604 Assert_Param(IS_TKM_KEY(Key));
605
606 *(vu32*)((u32)&TKMx->K3CPR + ((3 - Key) * 4)) = Value;
607 }
608
609 /*********************************************************************************************************//**
610 * @brief Get the key capacitor value.
611 * @param TKMn: TKM_0 ~ TKM_5
612 * @param Key: TKM_KEY_0 ~ TKM_KEY_3
613 * @retval The capacitor value
614 ************************************************************************************************************/
TKM_GetKeyCapacitor(TKM_Enum TKMn,TKM_KEY_Enum Key)615 u32 TKM_GetKeyCapacitor(TKM_Enum TKMn, TKM_KEY_Enum Key)
616 {
617 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
618
619 /* Check the parameters */
620 Assert_Param(IS_TKM(TKMn));
621 Assert_Param(IS_TKM_KEY(Key));
622
623 return *(vu32*)((u32)&TKMx->K3CPR + ((3 - Key) * 4));
624 }
625
626 /*********************************************************************************************************//**
627 * @brief Get the 16-bit C/F counter value.
628 * @param TKMn: TKM_0 ~ TKM_5
629 * @retval The counter value
630 ************************************************************************************************************/
TKM_Get16BitCFCounterValue(TKM_Enum TKMn)631 u32 TKM_Get16BitCFCounterValue(TKM_Enum TKMn)
632 {
633 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
634
635 /* Check the parameters */
636 Assert_Param(IS_TKM(TKMn));
637
638 return TKMx->CFCNTR;
639 }
640
641 /*********************************************************************************************************//**
642 * @brief Get the key counter value.
643 * @param TKMn: TKM_0 ~ TKM_5
644 * @param Key: TKM_KEY_0 ~ TKM_KEY_3
645 * @retval None
646 ************************************************************************************************************/
TKM_GetKeyCounterValue(TKM_Enum TKMn,TKM_KEY_Enum Key)647 u32 TKM_GetKeyCounterValue(TKM_Enum TKMn, TKM_KEY_Enum Key)
648 {
649 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
650
651 /* Check the parameters */
652 Assert_Param(IS_TKM(TKMn));
653 Assert_Param(IS_TKM_KEY(Key));
654
655 return *(vu32*)((u32)&TKMx->K3CNTR + ((3 - Key) * 4));
656 }
657
658 /*********************************************************************************************************//**
659 * @brief Set the key threshold value.
660 * @param TKMn: TKM_0 ~ TKM_5
661 * @param Key: TKM_KEY_0 ~ TKM_KEY_3
662 * @param Value: Specify the key threshold value between 0x0000 ~ 0xFFFF.
663 * @retval None
664 ************************************************************************************************************/
TKM_SetKeyThreshold(TKM_Enum TKMn,TKM_KEY_Enum Key,u32 Value)665 void TKM_SetKeyThreshold(TKM_Enum TKMn, TKM_KEY_Enum Key, u32 Value)
666 {
667 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
668
669 /* Check the parameters */
670 Assert_Param(IS_TKM(TKMn));
671 Assert_Param(IS_TKM_KEY(Key));
672
673 *(vu32*)((u32)&TKMx->K3THR + ((3 - Key) * 4)) = Value;
674 }
675
676 /*********************************************************************************************************//**
677 * @brief Get the key threshold value.
678 * @param TKMn: TKM_0 ~ TKM_5
679 * @param Key: TKM_KEY_0 ~ TKM_KEY_3
680 * @retval The threshold value
681 ************************************************************************************************************/
TKEY_GetKeyThreshold(TKM_Enum TKMn,TKM_KEY_Enum Key)682 u32 TKEY_GetKeyThreshold(TKM_Enum TKMn, TKM_KEY_Enum Key)
683 {
684 HT_TKM_TypeDef *TKMx = (HT_TKM_TypeDef *)((u32)&HT_TKEY->TKM0 + (TKMn * 0x100));
685
686 /* Check the parameters */
687 Assert_Param(IS_TKM(TKMn));
688 Assert_Param(IS_TKM_KEY(Key));
689
690 return *(vu32*)((u32)&TKMx->K3THR + ((3 - Key) * 4));
691 }
692 /**
693 * @}
694 */
695
696
697 /**
698 * @}
699 */
700
701 /**
702 * @}
703 */
704