1 /**
2   ******************************************************************************
3   * @file    rtl8721dlp_captouch.c
4   * @author
5   * @version V1.0.0
6   * @date    2017-11-06
7   * @brief   This file contains all the functions prototypes for the CapTouch function
8   ******************************************************************************
9   * @attention
10   *
11   * This module is a confidential and proprietary property of RealTek and
12   * possession or use of this module requires written permission of RealTek.
13   *
14   * Copyright(c) 2015, Realtek Semiconductor Corporation. All rights reserved.
15   ******************************************************************************
16   */
17 
18 #include "ameba_soc.h"
19 #include "rtl8721d_captouch.h"
20 
21 /**
22   * @brief  Fills each CapTouch_InitStruct member with its default value.
23   * @param  CapTouch_InitStruct: pointer to an CapTouch_InitTypeDef structure which will be initialized.
24   * @retval None
25   */
CapTouch_StructInit(CapTouch_InitTypeDef * CapTouch_InitStruct)26 void CapTouch_StructInit(CapTouch_InitTypeDef* CapTouch_InitStruct)
27 {
28 	u8 i;
29 	/* Load HAL initial data structure default value */
30 	CapTouch_InitStruct->CT_DebounceEn = 1;
31 	CapTouch_InitStruct->CT_SampleCnt = 6;
32 	CapTouch_InitStruct->CT_ScanInterval = 60;
33 	CapTouch_InitStruct->CT_ETCStep = 1;
34 	CapTouch_InitStruct->CT_ETCFactor = 4;
35 	CapTouch_InitStruct->CT_ETCScanInterval = 3;
36 
37 	for(i = 0; i < CT_CHANNEL_NUM; i++) {
38 		CapTouch_InitStruct->CT_Channel[i].CT_CHEnable = DISABLE;
39 		CapTouch_InitStruct->CT_Channel[i].CT_DiffThrehold = 0xf0;
40 		CapTouch_InitStruct->CT_Channel[i].CT_MbiasCurrent = 0x11; 		//6uA
41 		CapTouch_InitStruct->CT_Channel[i].CT_ETCNNoiseThr = 100;
42 		CapTouch_InitStruct->CT_Channel[i].CT_ETCPNoiseThr = 100;
43 	}
44 }
45 
46 
47 /**
48   * @brief  Initializes the CapTouch peripheral according to the specified
49   *			parameters in the CapTouch_InitStruct.
50   * @param  CapTouch: which should be CAPTOUCH_DEV.
51   * @param  CapTouch_InitStruct: pointer to a CapTouch_InitTypeDef structure that contains
52   * 		the configuration information for the specified CapTouch peripheral.
53   * @retval None
54   */
CapTouch_Init(CAPTOUCH_TypeDef * CapTouch,CapTouch_InitTypeDef * CapTouch_InitStruct)55 void CapTouch_Init(CAPTOUCH_TypeDef *CapTouch, CapTouch_InitTypeDef* CapTouch_InitStruct)
56 {
57 	u8 i;
58 
59 	/* Check the parameters */
60 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
61 	assert_param(CapTouch_InitStruct->CT_DebounceEn <= 1 );
62 	assert_param(CapTouch_InitStruct->CT_SampleCnt<= 7 );
63 	assert_param(CapTouch_InitStruct->CT_ScanInterval <= 0xFFF );
64 	assert_param(CapTouch_InitStruct->CT_ETCStep <= 0xF );
65 	assert_param(CapTouch_InitStruct->CT_ETCFactor <= 0xF );
66 	assert_param(CapTouch_InitStruct->CT_ETCScanInterval <= 0x7F );
67 
68 	for(i = 0; i < CT_CHANNEL_NUM ;i++) {
69 		assert_param(CapTouch_InitStruct->CT_Channel[i].CT_DiffThrehold  <= 0xFFF );
70 		assert_param(CapTouch_InitStruct->CT_Channel[i].CT_MbiasCurrent <= 0x3F );
71 		//assert_param(CapTouch_InitStruct->CT_Channel[i].CT_ETCNNoiseThr <= 0xFF );
72 		//assert_param(CapTouch_InitStruct->CT_Channel[i].CT_ETCPNoiseThr <= 0xFF );
73 	}
74 
75 	/* Disable CTC, clear pending interrupt*/
76 	CapTouch_Cmd(CapTouch, DISABLE);
77 	CapTouch->CT_IER = 0;
78 	CapTouch->CT_ICR_ALL = BIT_CT_ALL_INT_CLR;
79 
80 	/* Set control register*/
81 	CapTouch->CT_CTRL = BIT_CT_BL_ENABLE | (CapTouch_InitStruct->CT_DebounceEn << 4);
82 
83 	CapTouch->CT_SP_CTRL = CapTouch_InitStruct->CT_SampleCnt << 16 | \
84 							CapTouch_InitStruct->CT_ScanInterval;
85 
86 	CapTouch->CT_ETC_CTRL = CapTouch_InitStruct->CT_ETCStep << 12 | \
87 							CapTouch_InitStruct->CT_ETCFactor << 8 | \
88 							CapTouch_InitStruct->CT_ETCScanInterval << 1 | \
89 							BIT_CT_ETC_ENABLE;
90 
91 	CapTouch->CT_MODE_CTRL = BIT_CT_AUTO_CHANNEL_ENABLE;
92 
93 	/* Configure each channel */
94 	for(i = 0; i < CT_CHANNEL_NUM ;i++) {
95 		if(CapTouch_InitStruct->CT_Channel[i].CT_CHEnable) {
96 			CapTouch->CT_CH[i].CTRL = (CapTouch_InitStruct->CT_Channel[i].CT_DiffThrehold <<16) | BIT_CT_CHX_ENABLE;
97 			CapTouch->CT_CH[i].MBIAS = CapTouch_InitStruct->CT_Channel[i].CT_MbiasCurrent;
98 			CapTouch->CT_CH[i].ATHR = CapTouch_InitStruct->CT_Channel[i].CT_ETCNNoiseThr << 24 | \
99 									CapTouch_InitStruct->CT_Channel[i].CT_ETCPNoiseThr << 16;
100 		}
101 	}
102 }
103 
104 
105 /**
106   * @brief  Enables or disables the specified CapTouch peripheral.
107   * @param  CapTouch: which should be CAPTOUCH_DEV.
108   * @param  NewState: new state of the CapTouch peripheral.
109   *   This parameter can be: ENABLE or DISABLE.
110   * @retval None
111   */
CapTouch_Cmd(CAPTOUCH_TypeDef * CapTouch,u8 NewState)112 void CapTouch_Cmd(CAPTOUCH_TypeDef *CapTouch, u8 NewState)
113 {
114 	/* Check the parameters */
115 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
116 
117 	if (NewState != DISABLE) {
118 		/* Enable the CapTouch peripheral and baseline */
119 		CapTouch->CT_CTRL |= BIT_CT_ENABLE | BIT_CT_BL_ENABLE;
120 	} else {
121 		/* Disable the CapTouch peripheral */
122 		CapTouch->CT_CTRL &= (~BIT_CT_ENABLE);
123 	}
124 }
125 
126 
127 /**
128   * @brief  Enables or disables the specified CapTouch interrupts.
129   * @param  CapTouch: which should be CAPTOUCH_DEV.
130   * @param  CapTouch_IT: specifies the CapTouch interrupt to be enabled or masked.
131   *          This parameter can be one or combinations of the following values:
132   *            @arg BIT_CT_OVER_N_NOISE_THRESHOLD_INT: CapTouch negetive noise overflow interrupt
133   *            @arg BIT_CT_FIFO_OVERFLOW_INT: CapTouch FIFO overflow interrupt
134   *            @arg BIT_CT_OVER_P_NOISE_THRESHOLD_INT:CapTouch positive noise overflow interrupt
135   *            @arg CT_CHX_PRESS_INT(x): CapTouch channel(x) press interrupt, where x can be 0~3
136   *            @arg CT_CHX_RELEASE_INT(x): CapTouch channel(x) release interrupt, where x can be 0~3
137   * @param  NewState: new state of the specified CapTouch interrupts mask.
138   *   This parameter can be: ENABLE or DISABLE.
139   * @retval None
140   */
CapTouch_INTConfig(CAPTOUCH_TypeDef * CapTouch,uint32_t CapTouch_IT,u8 newState)141 void CapTouch_INTConfig(CAPTOUCH_TypeDef *CapTouch, uint32_t CapTouch_IT, u8 newState)
142 {
143 	/* Check the parameters */
144 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
145 	assert_param(IS_CT_INT_EN(CapTouch_IT));
146 
147 	if (newState == ENABLE) {
148 		/* Enable CapTouch interrupts */
149 		CapTouch->CT_IER |= CapTouch_IT;
150 	} else {
151 		/* Disable CapTouch interrupts */
152 		CapTouch->CT_IER &= (~CapTouch_IT);
153 	}
154 }
155 
156 
157 /**
158   * @brief  Clears the specified CapTouch interrupt pending bit.
159   * @param  CapTouch: which should be CAPTOUCH_DEV.
160   * @param  CapTouch_IT: specifies the CapTouch interrupt to be cleared.
161   *          This parameter can be one or combinations of the following values:
162   *            @arg BIT_CT_N_NOISE_OVERFLOW_INT_CLR:CapTouch negetive noise overflow interrupt
163   *            @arg BIT_CT_FIFO_OVERFLOW_INT_CLR: CapTouch FIFO overflow interrupt
164   *            @arg BIT_CT_P_NOISE_OVERFLOW_INT_CLR:CapTouch positive noise overflow interrupt
165   *            @arg CT_CHX_PRESS_INT(x): CapTouch channel(x) press interrupt, where x can be 0~3
166   *            @arg CT_CHX_RELEASE_INT(x): CapTouch channel(x) release interrupt, where x can be 0~3
167   * @retval None
168   */
CapTouch_INTClearPendingBit(CAPTOUCH_TypeDef * CapTouch,u32 CapTouch_IT)169 void CapTouch_INTClearPendingBit(CAPTOUCH_TypeDef *CapTouch, u32 CapTouch_IT)
170 {
171 	/* Check the parameters */
172 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
173 	assert_param(IS_CT_INT_CLR(CapTouch_IT));
174 
175 	CapTouch->CT_ICR |= CapTouch_IT;
176 }
177 
178 
179 /**
180   * @brief  Get CapTouch Raw Interrupt Status.
181   * @param  CapTouch: which should be CAPTOUCH_DEV.
182   * @retval raw interrupt status
183   */
CapTouch_GetRawISR(CAPTOUCH_TypeDef * CapTouch)184 u32 CapTouch_GetRawISR(CAPTOUCH_TypeDef *CapTouch)
185 {
186 	/* Check the parameters */
187 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
188 
189 	return CapTouch->CT_ISR_RAW;
190 }
191 
192 
193 /**
194   * @brief  Get CapTouch interrupt status.
195   * @param  CapTouch: which should be CAPTOUCH_DEV.
196   * @retval interrupt status
197   */
CapTouch_GetISR(CAPTOUCH_TypeDef * CapTouch)198 u32 CapTouch_GetISR(CAPTOUCH_TypeDef *CapTouch)
199 {
200 	/* Check the parameters */
201 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
202 
203 	return CapTouch->CT_ISR;
204 }
205 
206 /**
207   * @brief  Get CapTouch channel enable status.
208   * @param  CapTouch: which should be CAPTOUCH_DEV.
209   * @param  Channel: specified channel index, which can be 0~3
210   * @retval channel enable status.
211   */
CapTouch_GetChStatus(CAPTOUCH_TypeDef * CapTouch,u32 Channel)212 u32 CapTouch_GetChStatus(CAPTOUCH_TypeDef *CapTouch, u32 Channel)
213 {
214 	/* Check the parameters */
215 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
216 	assert_param(IS_CT_CHANNEL(Channel));
217 
218 	if (CapTouch->CT_CH[Channel].CTRL & BIT_CT_CHX_ENABLE)
219 		return TRUE;
220 	else
221 		return FALSE;
222 }
223 
224 /**
225   * @brief  Enable or disable specified channel.
226   * @param  CapTouch: which should be CAPTOUCH_DEV.
227   * @param  Channel: specified channel index, which can be 0~3
228   * @param  NewState: new state of the specified channel.
229   *   This parameter can be: ENABLE or DISABLE.
230   * @retval None
231   */
CapTouch_ChCmd(CAPTOUCH_TypeDef * CapTouch,u8 Channel,u8 NewState)232 void CapTouch_ChCmd(CAPTOUCH_TypeDef *CapTouch, u8 Channel, u8 NewState)
233 {
234 	/* Check the parameters */
235 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
236 	assert_param(IS_CT_CHANNEL(Channel));
237 
238 	if (NewState != DISABLE) {
239 		/* Enable the CapTouch crossponding channel */
240 		CapTouch->CT_CH[Channel].CTRL |= BIT_CT_CHX_ENABLE;
241 	} else {
242 		/* Disable the CapTouch peripheral */
243 		CapTouch->CT_CH[Channel].CTRL &= ~BIT_CT_CHX_ENABLE;
244 	}
245 }
246 
247 /**
248   * @brief  Set CapTouch Scan interval.
249   * @param  CapTouch: which should be CAPTOUCH_DEV.
250   * @param Interval: scan interval in units of ms
251   * @retval None
252   */
CapTouch_SetScanInterval(CAPTOUCH_TypeDef * CapTouch,u32 Interval)253 void CapTouch_SetScanInterval(CAPTOUCH_TypeDef *CapTouch, u32 Interval)
254 {
255 	u32 TempVal;
256 
257 	/* Check the parameters */
258 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
259 	assert_param(Interval <= 4095);
260 
261 	CapTouch_Cmd(CapTouch, DISABLE);
262 	TempVal = CapTouch->CT_SP_CTRL;
263 	TempVal &= ~BIT_CT_SCAN_INTERVAL;
264 	TempVal |= Interval;
265 	CapTouch->CT_SP_CTRL = TempVal;
266 	CapTouch_Cmd(CapTouch, ENABLE);
267 }
268 
269 /**
270   * @brief  Set Mbias current for specified channel.
271   * @param  CapTouch: which should be CAPTOUCH_DEV.
272   * @param  Channel: specified channel index, which can be 0~3.
273   * @param  Mbias: Mbias value, relate current = 0.25*Mbias.
274   * @retval None
275   */
CapTouch_SetChMbias(CAPTOUCH_TypeDef * CapTouch,u8 Channel,u8 Mbias)276 void CapTouch_SetChMbias(CAPTOUCH_TypeDef *CapTouch, u8 Channel, u8 Mbias)
277 {
278 	/* Check the parameters */
279 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
280 	assert_param(IS_CT_CHANNEL(Channel));
281 	assert_param(Mbias < 64);
282 
283 	CapTouch_Cmd(CapTouch, DISABLE);
284 	CapTouch->CT_CH[Channel].MBIAS =Mbias;
285 	CapTouch_Cmd(CapTouch, ENABLE);
286 }
287 
288 /**
289   * @brief  Set relative touch threshold for related channel.
290   * @param  CapTouch: which should be CAPTOUCH_DEV.
291   * @param  Channel: specified channel index, which can be 0~3
292   * @param  Threshold: Related Threshold value.
293   * @retval None
294   */
CapTouch_SetChDiffThres(CAPTOUCH_TypeDef * CapTouch,u8 Channel,u32 Threshold)295 void CapTouch_SetChDiffThres(CAPTOUCH_TypeDef *CapTouch, u8 Channel, u32 Threshold)
296 {
297 	u32 TempVal;
298 
299 	/* Check the parameters */
300 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
301 	assert_param(IS_CT_CHANNEL(Channel));
302 	assert_param(Threshold < 4096);
303 
304 	CapTouch_Cmd(CapTouch, DISABLE);
305 	TempVal = CapTouch->CT_CH[Channel].CTRL;
306 	TempVal &= ~BIT_CT_CHX_TOUCH_THRES;
307 	TempVal |= Threshold << 16;
308 	CapTouch->CT_CH[Channel].CTRL = TempVal;
309 	CapTouch_Cmd(CapTouch, ENABLE);
310 }
311 
312 /**
313   * @brief  Get relative threshold of touch judgement for specified channel.
314    * @param  CapTouch: which should be CAPTOUCH_DEV.
315   * @param  Channel: specified channel index, which can be 0~3
316   * @retval Difference threshold of specified channel.
317   */
CapTouch_GetChDiffThres(CAPTOUCH_TypeDef * CapTouch,u8 Channel)318 u32 CapTouch_GetChDiffThres(CAPTOUCH_TypeDef *CapTouch, u8 Channel)
319 {
320 	/* Check the parameters */
321 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
322 	assert_param(IS_CT_CHANNEL(Channel));
323 
324 	return (CapTouch->CT_CH[Channel].CTRL & BIT_CT_CHX_TOUCH_THRES) >> 16;
325 }
326 
327 /**
328   * @brief  Get Absolute  threshold of touch judgement for specified channel.
329    * @param  CapTouch: which should be CAPTOUCH_DEV.
330   * @param  Channel: specified channel index, which can be 0~3
331   * @retval Difference threshold of specified channel.
332   */
CapTouch_GetChAbsThres(CAPTOUCH_TypeDef * CapTouch,u8 Channel)333 u32 CapTouch_GetChAbsThres(CAPTOUCH_TypeDef *CapTouch, u8 Channel)
334 {
335 	/* Check the parameters */
336 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
337 	assert_param(IS_CT_CHANNEL(Channel));
338 
339 	return CapTouch->CT_CH[Channel].ATHR & BIT_CT_CHX_TOUCH_ATHRES;
340 }
341 
342 /**
343   * @brief  Get positive or negative noise threshold for specified channel.
344    * @param  CapTouch: which should be CAPTOUCH_DEV.
345   * @param  Channel: specified channel index, which can be 0~3
346   * @param  type: can be P_NOISE_THRES or N_NOISE_THRES
347   * @retval  Noise threshold of specified channel.
348   */
CapTouch_GetNoiseThres(CAPTOUCH_TypeDef * CapTouch,u8 Channel,u8 type)349 u32 CapTouch_GetNoiseThres(CAPTOUCH_TypeDef *CapTouch, u8 Channel, u8 type)
350 {
351 	u8 value;
352 
353 	/* Check the parameters */
354 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
355 	assert_param(IS_CT_CHANNEL(Channel));
356 
357 	if(type)
358 		value = (CapTouch->CT_CH[Channel].ATHR & BIT_MASK_CHX_N_ENT) >> 24;
359 	else
360 		value = (CapTouch->CT_CH[Channel].ATHR & BIT_MASK_CHX_P_ENT) >> 16;
361 
362 	return value;
363 }
364 
365 /**
366   * @brief  Read Baseline data from specified channel.
367   * @param  CapTouch: which should be CAPTOUCH_DEV.
368   * @param  Channel: specified channel index, which can be 0~3
369   * @retval Baseline data
370   */
CapTouch_GetChBaseline(CAPTOUCH_TypeDef * CapTouch,u8 Channel)371 u32 CapTouch_GetChBaseline(CAPTOUCH_TypeDef *CapTouch, u8 Channel)
372 {
373 	/* Check the parameters */
374 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
375 	assert_param(IS_CT_CHANNEL(Channel));
376 
377 	return ((CapTouch->CT_CH[Channel].CTRL & BIT_CT_CHX_BASELINE) >> 4);
378 }
379 
380 
381 /**
382   * @brief  Read average data from specified channel.
383    * @param  CapTouch: which should be CAPTOUCH_DEV.
384   * @param  Channel: specified channel index, which can be 0~3
385   * @retval Average data
386   */
CapTouch_GetChAveData(CAPTOUCH_TypeDef * CapTouch,u8 Channel)387 u32 CapTouch_GetChAveData(CAPTOUCH_TypeDef *CapTouch, u8 Channel)
388 {
389 	/* Check the parameters */
390 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
391 	assert_param(IS_CT_CHANNEL(Channel));
392 
393 	return (CapTouch->CT_CH[Channel].DATA & BIT_CT_CHX_DATA);
394 }
395 
396 /**
397   * @brief  Enable or disable Debug mode.
398   * @param  CapTouch: which should be CAPTOUCH_DEV.
399   * @param  NewState: new state of the Debug mode.
400   *   This parameter can be: ENABLE or DISABLE.
401   * @retval None
402   */
CapTouch_DbgCmd(CAPTOUCH_TypeDef * CapTouch,u8 NewState)403 void CapTouch_DbgCmd(CAPTOUCH_TypeDef *CapTouch, u8 NewState)
404 {
405 	/* Check the parameters */
406 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
407 
408 	if (NewState != DISABLE) {
409 		/* Enable the CapTouch debug mode */
410 		CapTouch->CT_MODE_CTRL |= BIT_CT_DBG_ENABLE;
411 	} else {
412 		/* Disable the CapTouch peripheral */
413 		CapTouch->CT_MODE_CTRL |= BIT_CT_AUTO_CHANNEL_ENABLE;
414 		CapTouch->CT_MODE_CTRL &= (~BIT_CT_DBG_ENABLE);
415 	}
416 }
417 
418 
419 /**
420   * @brief select debug channel
421   * @param  CapTouch: which should be CAPTOUCH_DEV.
422   * @param  Channel: specified channel index, which can be 0~3
423   * @retval none
424   */
CapTouch_DbgChannel(CAPTOUCH_TypeDef * CapTouch,u8 Channel)425 void CapTouch_DbgChannel(CAPTOUCH_TypeDef *CapTouch, u8 Channel)
426 {
427 	u32 data;
428 
429 	/* Check the parameters */
430 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
431 	assert_param(IS_CT_CHANNEL(Channel));
432 
433 	data = CapTouch->CT_MODE_CTRL;
434 	data &= ~(BIT_CT_CHANNEL_SEL | BIT_CT_AUTO_CHANNEL_ENABLE);
435 	data |= Channel << 5;
436 	CapTouch->CT_MODE_CTRL = data;
437 
438 }
439 
440 
441 /**
442   * @brief Get Raw data in debug mode
443   * @param  CapTouch: which should be CAPTOUCH_DEV.
444   * @retval Raw data
445   */
CapTouch_DbgRawData(CAPTOUCH_TypeDef * CapTouch)446 u32 CapTouch_DbgRawData(CAPTOUCH_TypeDef *CapTouch)
447 {
448 	u32 loop = 0;
449 	u32 data;
450 
451 	/* Check the parameters */
452 	assert_param(IS_CAPTOUCH_ALL_PERIPH(CapTouch));
453 
454 	do {
455 		data = CapTouch->CT_FIFO;
456 
457 		if(loop++ > 10000){
458 			DBG_8195A("sample timeout \n" );
459 			return  0xEAEA;
460 		}
461 
462 	} while((data & BIT(31)) == 0);
463 
464 	return (data & 0x0FFF);
465 
466 }
467 
468 /**
469   * @brief Dump all registers
470   * @param  CapTouch: which should be CAPTOUCH_DEV.
471   * @retval NA
472   */
CapTouch_DbgDumpReg(CAPTOUCH_TypeDef * CapTouch)473 void CapTouch_DbgDumpReg(CAPTOUCH_TypeDef *CapTouch)
474 {
475 	DBG_8195A("\n%08x: %08x (CT_CTRL)\n", &(CapTouch->CT_CTRL), CapTouch->CT_CTRL);
476 	DBG_8195A("%08x: %08x (CT_SP_CTRL)\n", &(CapTouch->CT_SP_CTRL), CapTouch->CT_SP_CTRL);
477 	DBG_8195A("%08x: %08x (CT_ETC_CTRL)\n", &(CapTouch->CT_ETC_CTRL), CapTouch->CT_ETC_CTRL);
478 	DBG_8195A("%08x: %08x (CT_SNR)\n", &(CapTouch->CT_SNR), CapTouch->CT_SNR);
479 	DBG_8195A("%08x: %08x (CT_MODE_CTRL)\n", &(CapTouch->CT_MODE_CTRL), CapTouch->CT_MODE_CTRL);
480 	DBG_8195A("%08x: %08x (CT_FIFO_STATUS)\n", &(CapTouch->CT_FIFO_STATUS), CapTouch->CT_FIFO_STATUS);
481 	DBG_8195A("%08x: %08x (CT_FIFO)\n", &(CapTouch->CT_FIFO), CapTouch->CT_FIFO);
482 	DBG_8195A("%08x: %08x (CT_IER)\n", &(CapTouch->CT_IER), CapTouch->CT_IER);
483 	DBG_8195A("%08x: %08x (CT_ISR)\n", &(CapTouch->CT_ISR), CapTouch->CT_ISR);
484 	DBG_8195A("%08x: %08x (CT_ISR_RAW)\n", &(CapTouch->CT_ISR_RAW), CapTouch->CT_ISR_RAW);
485 	DBG_8195A("%08x: %08x (CT_ICR_ALL)\n", &(CapTouch->CT_ICR_ALL), CapTouch->CT_ICR_ALL);
486 	DBG_8195A("%08x: %08x (CT_ICR)\n", &(CapTouch->CT_ICR), CapTouch->CT_ICR);
487 
488 	DBG_8195A("%08x: %08x (CT_CH[0].CTRL)\n", &(CapTouch->CT_CH[0].CTRL), CapTouch->CT_CH[0].CTRL);
489 	DBG_8195A("%08x: %08x (CT_CH[0].ATHR)\n", &(CapTouch->CT_CH[0].ATHR), CapTouch->CT_CH[0].ATHR);
490 	DBG_8195A("%08x: %08x (CT_CH[0].MBIAS)\n", &(CapTouch->CT_CH[0].MBIAS), CapTouch->CT_CH[0].MBIAS);
491 	DBG_8195A("%08x: %08x (CT_CH[0].DATA)\n", &(CapTouch->CT_CH[0].DATA), CapTouch->CT_CH[0].DATA);
492 
493 	DBG_8195A("%08x: %08x (CT_ADC_REG0X_LPAD)\n", &(CapTouch->CT_ADC_REG0X_LPAD), CapTouch->CT_ADC_REG0X_LPAD);
494 	DBG_8195A("%08x: %08x (CT_ADC_REG1X_LPAD)\n", &(CapTouch->CT_ADC_REG1X_LPAD), CapTouch->CT_ADC_REG1X_LPAD);
495 	DBG_8195A("%08x: %08x (CT_ADC_REG0X_LPSD)\n", &(CapTouch->CT_ADC_REG0X_LPSD), CapTouch->CT_ADC_REG0X_LPSD);
496 	DBG_8195A("%08x: %08x (CT_ADC_TIME)\n", &(CapTouch->CT_ADC_TIME), CapTouch->CT_ADC_TIME);
497 }
498 
499 /**
500   * @brief Dump all registers
501   * @param  CapTouch: which should be CAPTOUCH_DEV.
502   * @param  ch: specified channel index, which can be 0~3
503   * @retval NA
504   */
CapTouch_DbgDumpETC(CAPTOUCH_TypeDef * CapTouch,u32 ch)505 void CapTouch_DbgDumpETC(CAPTOUCH_TypeDef *CapTouch, u32 ch)
506 {
507 	/* To avoid gcc warnings */
508 	( void ) CapTouch;
509 
510 	u32 DiffThres = 0;
511 	u32 Baseline = 0;
512 	u32 AveData = 0;
513 	u32 NoiseThresP = 0;
514 	u32 NoiseThresN = 0;
515 	u32 AbsoThres = 0;
516 
517 	DiffThres = CapTouch_GetChDiffThres(CAPTOUCH_DEV, ch);
518 	Baseline = CapTouch_GetChBaseline(CAPTOUCH_DEV, ch);
519 	AveData = CapTouch_GetChAveData(CAPTOUCH_DEV, ch);
520 	NoiseThresP = CapTouch_GetNoiseThres(CAPTOUCH_DEV, ch, P_NOISE_THRES);
521 	NoiseThresN = CapTouch_GetNoiseThres(CAPTOUCH_DEV, ch, N_NOISE_THRES);
522 	AbsoThres = CapTouch_GetChAbsThres(CAPTOUCH_DEV, ch);
523 
524 	DBG_8195A("\nCH[%d] ETC: ChDiffThres:%08x (%d) \n", ch, DiffThres, DiffThres);
525 	DBG_8195A("CH[%d] ETC: Baseline:%08x (%d) \n", ch, Baseline, Baseline);
526 	DBG_8195A("CH[%d] ETC: RawAveData:%08x (%d) Diff:%d \n", ch, AveData, AveData, AveData-Baseline);
527 	DBG_8195A("CH[%d] ETC: NoiseThres P:%08x (%d) \n", ch, NoiseThresP, NoiseThresP);
528 	DBG_8195A("CH[%d] ETC: NoiseThres N:%08x (%d) \n", ch, NoiseThresN, NoiseThresN);
529 	DBG_8195A("CH[%d] ETC: AbsoThres:%08x (%d) \n", ch, AbsoThres, AbsoThres);
530 }
531 
532 /******************* (C) COPYRIGHT 2016 Realtek Semiconductor *****END OF FILE****/
533