1 /*
2  * Copyright 2022 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 #ifndef FSL_TSI_V6_H_
8 #define FSL_TSI_V6_H_
9 
10 #include "fsl_common.h"
11 
12 /*!
13  * @addtogroup tsi_v6_driver
14  * @{
15  */
16 /*******************************************************************************
17  * Variables
18  ******************************************************************************/
19 /* Array of TSI clock name. */
20 extern const clock_ip_name_t s_tsiClock[];
21 /* Array of TSI peripheral base address. */
22 extern TSI_Type *const s_tsiBases[];
23 /*******************************************************************************
24  * Definitions
25  ******************************************************************************/
26 
27 /*! @brief TSI driver version */
28 #define FSL_TSI_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
29 
30 /*! @brief TSI status flags macro collection */
31 #define ALL_FLAGS_MASK (TSI_DATA_EOSF_MASK | TSI_DATA_OUTRGF_MASK)
32 
33 /*!
34  * @brief TSI main clock selection.
35  *
36  * These constants set the tsi main clock.
37  */
38 typedef enum _tsi_main_clock_selection
39 {
40     kTSI_MainClockSlection_0 = 0U, /*!< Set TSI main clock frequency to 20.72MHz */
41     kTSI_MainClockSlection_1 = 1U, /*!< Set TSI main clock frequency to 16.65MHz */
42     kTSI_MainClockSlection_2 = 2U, /*!< Set TSI main clock frequency to 13.87MHz */
43     kTSI_MainClockSlection_3 = 3U, /*!< Set TSI main clock frequency to 11.91MHz */
44 } tsi_main_clock_selection_t;
45 
46 /*!
47  * @brief TSI sensing mode selection.
48  *
49  * These constants set the tsi sensing mode.
50  */
51 typedef enum _tsi_sensing_mode_selection
52 {
53     kTSI_SensingModeSlection_Self   = 0U, /*!< Set TSI sensing mode to self-cap mode */
54     kTSI_SensingModeSlection_Mutual = 1U, /*!< Set TSI sensing mode to mutual-cap mode */
55 } tsi_sensing_mode_selection_t;
56 
57 /*!
58  * @brief TSI DVOLT settings
59  *
60  * These bits indicate the comparator vp, vm and dvolt voltage.
61  */
62 typedef enum _tsi_dvolt_option
63 {
64     kTSI_DvoltOption_0 = 0U, /*!< DVOLT value option 0, the value may differ on different platforms */
65     kTSI_DvoltOption_1 = 1U, /*!< DVOLT value option 1, the value may differ on different platforms */
66     kTSI_DvoltOption_2 = 2U, /*!< DVOLT value option 2, the value may differ on different platforms */
67     kTSI_DvoltOption_3 = 3U, /*!< DVOLT value option 3, the value may differ on different platforms */
68     kTSI_DvoltOption_4 = 4U, /*!< DVOLT value option 4, the value may differ on different platforms */
69     kTSI_DvoltOption_5 = 5U  /*!< DVOLT value option 5, the value may differ on different platforms */
70 } tsi_dvolt_option_t;
71 
72 /*!
73  * @brief TSI sensitivity ajustment (XDN option).
74  *
75  * These constants define the tsi sensitivity ajustment in self-cap mode, when TSI_MODE[S_SEN] = 1.
76  */
77 typedef enum _tsi_sensitivity_xdn_option
78 {
79     kTSI_SensitivityXdnOption_0 = 0U, /*!< Adjust sensitivity in self-cap mode, 1/16 */
80     kTSI_SensitivityXdnOption_1 = 1U, /*!< Adjust sensitivity in self-cap mode, 1/8  */
81     kTSI_SensitivityXdnOption_2 = 2U, /*!< Adjust sensitivity in self-cap mode, 1/4  */
82     kTSI_SensitivityXdnOption_3 = 3U, /*!< Adjust sensitivity in self-cap mode, 1/2  */
83     kTSI_SensitivityXdnOption_4 = 4U, /*!< Adjust sensitivity in self-cap mode, 1/1  */
84     kTSI_SensitivityXdnOption_5 = 5U, /*!< Adjust sensitivity in self-cap mode, 2/1  */
85     kTSI_SensitivityXdnOption_6 = 6U, /*!< Adjust sensitivity in self-cap mode, 4/1  */
86     kTSI_SensitivityXdnOption_7 = 7U, /*!< Adjust sensitivity in self-cap mode, 8/1  */
87 } tsi_sensitivity_xdn_option_t;
88 
89 /*!
90  * @brief TSI Shield setting (S_W_SHIELD option).
91  *
92  * These constants define the shield pin used for HW shielding functionality. One or more shield pin can be selected.
93  * The involved bitfield is not fix can change from device to device (KE16Z7 and KE17Z7 support 3 shield pins, other KE
94  * serials only support 1 shield pin).
95  */
96 typedef enum _tsi_shield
97 {
98     kTSI_shieldAllOff  = 0U, /*!< No pin used */
99     kTSI_shield0On     = 1U, /*!< Shield 0   pin used */
100     kTSI_shield1On     = 2U, /*!< Shield 1   pin used */
101     kTSI_shield1and0On = 3U, /*!< Shield 0,1 pins used */
102     kTSI_shield2On     = 4U, /*!< Shield 2   pin used */
103     kTSI_shield2and0On = 5U, /*!< Shield 2,0 pins used */
104     kTSI_shield2and1On = 6U, /*!< Shield 2,1 pins used */
105     kTSI_shieldAllOn   = 7U, /*!< Shield 2,1,0 pins used */
106 } tsi_shield_t;
107 
108 /*!
109  * @brief TSI sensitivity ajustment (CTRIM option).
110  *
111  * These constants define the tsi sensitivity ajustment in self-cap mode, when TSI_MODE[S_SEN] = 1.
112  */
113 typedef enum _tsi_sensitivity_ctrim_option
114 {
115     kTSI_SensitivityCtrimOption_0 = 0U, /*!< Adjust sensitivity in self-cap mode, 2.5p  */
116     kTSI_SensitivityCtrimOption_1 = 1U, /*!< Adjust sensitivity in self-cap mode, 5.0p  */
117     kTSI_SensitivityCtrimOption_2 = 2U, /*!< Adjust sensitivity in self-cap mode, 7.5p  */
118     kTSI_SensitivityCtrimOption_3 = 3U, /*!< Adjust sensitivity in self-cap mode, 10.0p */
119     kTSI_SensitivityCtrimOption_4 = 4U, /*!< Adjust sensitivity in self-cap mode, 12.5p */
120     kTSI_SensitivityCtrimOption_5 = 5U, /*!< Adjust sensitivity in self-cap mode, 15.0p */
121     kTSI_SensitivityCtrimOption_6 = 6U, /*!< Adjust sensitivity in self-cap mode, 17.5p */
122     kTSI_SensitivityCtrimOption_7 = 7U, /*!< Adjust sensitivity in self-cap mode, 20.0p */
123 } tsi_sensitivity_ctrim_option_t;
124 
125 /*!
126  * @brief TSI current ajustment (Input current multiple).
127  *
128  * These constants set the tsi input current multiple in self-cap mode.
129  */
130 typedef enum _tsi_current_multiple_input
131 {
132     kTSI_CurrentMultipleInputValue_0 = 0U, /*!< Adjust input current multiple in self-cap mode, 1/8 */
133     kTSI_CurrentMultipleInputValue_1 = 1U, /*!< Adjust input current multiple in self-cap mode, 1/4 */
134 } tsi_current_multiple_input_t;
135 
136 /*!
137  * @brief TSI current ajustment (Charge/Discharge current multiple).
138  *
139  * These constants set the tsi charge/discharge current multiple in self-cap mode.
140  */
141 typedef enum _tsi_current_multiple_charge
142 {
143     kTSI_CurrentMultipleChargeValue_0 = 0U, /*!< Adjust charge/discharge current multiple in self-cap mode, 1/16 */
144     kTSI_CurrentMultipleChargeValue_1 = 1U, /*!< Adjust charge/discharge current multiple in self-cap mode, 1/8  */
145     kTSI_CurrentMultipleChargeValue_2 = 2U, /*!< Adjust charge/discharge current multiple in self-cap mode, 1/4  */
146     kTSI_CurrentMultipleChargeValue_3 = 3U, /*!< Adjust charge/discharge current multiple in self-cap mode, 1/2  */
147     kTSI_CurrentMultipleChargeValue_4 = 4U, /*!< Adjust charge/discharge current multiple in self-cap mode, 1/1  */
148     kTSI_CurrentMultipleChargeValue_5 = 5U, /*!< Adjust charge/discharge current multiple in self-cap mode, 2/1  */
149     kTSI_CurrentMultipleChargeValue_6 = 6U, /*!< Adjust charge/discharge current multiple in self-cap mode, 4/1  */
150     kTSI_CurrentMultipleChargeValue_7 = 7U, /*!< Adjust charge/discharge current multiple in self-cap mode, 8/1  */
151 } tsi_current_multiple_charge_t;
152 
153 /*!
154  * @brief TSI current used in vref generator
155  *
156  * These constants Choose the current used in vref generator.
157  */
158 typedef enum _tsi_mutual_pre_current
159 {
160     kTSI_MutualPreCurrent_1uA = 0U, /*!< Vref generator current is 1uA, used in mutual-cap mode */
161     kTSI_MutualPreCurrent_2uA = 1U, /*!< Vref generator current is 2uA, used in mutual-cap mode */
162     kTSI_MutualPreCurrent_3uA = 2U, /*!< Vref generator current is 3uA, used in mutual-cap mode */
163     kTSI_MutualPreCurrent_4uA = 3U, /*!< Vref generator current is 4uA, used in mutual-cap mode */
164     kTSI_MutualPreCurrent_5uA = 4U, /*!< Vref generator current is 5uA, used in mutual-cap mode */
165     kTSI_MutualPreCurrent_6uA = 5U, /*!< Vref generator current is 6uA, used in mutual-cap mode */
166     kTSI_MutualPreCurrent_7uA = 6U, /*!< Vref generator current is 7uA, used in mutual-cap mode */
167     kTSI_MutualPreCurrent_8uA = 7U  /*!< Vref generator current is 8uA, used in mutual-cap mode */
168 } tsi_mutual_pre_current_t;
169 
170 /*!
171  * @brief TSI resistor used in pre-charge
172  *
173  * These constants Choose the resistor used in pre-charge.
174  */
175 typedef enum _tsi_mutual_pre_resistor
176 {
177     kTSI_MutualPreResistor_1k = 0U, /*!< Vref generator resistor is 1k, used in mutual-cap mode */
178     kTSI_MutualPreResistor_2k = 1U, /*!< Vref generator resistor is 2k, used in mutual-cap mode */
179     kTSI_MutualPreResistor_3k = 2U, /*!< Vref generator resistor is 3k, used in mutual-cap mode */
180     kTSI_MutualPreResistor_4k = 3U, /*!< Vref generator resistor is 4k, used in mutual-cap mode */
181     kTSI_MutualPreResistor_5k = 4U, /*!< Vref generator resistor is 5k, used in mutual-cap mode */
182     kTSI_MutualPreResistor_6k = 5U, /*!< Vref generator resistor is 6k, used in mutual-cap mode */
183     kTSI_MutualPreResistor_7k = 6U, /*!< Vref generator resistor is 7k, used in mutual-cap mode */
184     kTSI_MutualPreResistor_8k = 7U  /*!< Vref generator resistor is 8k, used in mutual-cap mode */
185 } tsi_mutual_pre_resistor_t;
186 
187 /*!
188  * @brief TSI resistor used in I-sense generator
189  *
190  * These constants Choose the resistor used in I-sense generator.
191  */
192 typedef enum _tsi_mutual_sense_resistor
193 {
194     kTSI_MutualSenseResistor_2k5  = 0U,  /*!< I-sense resistor is 2.5k , used in mutual-cap mode */
195     kTSI_MutualSenseResistor_5k   = 1U,  /*!< I-sense resistor is 5.0k , used in mutual-cap mode */
196     kTSI_MutualSenseResistor_7k5  = 2U,  /*!< I-sense resistor is 7.5k , used in mutual-cap mode */
197     kTSI_MutualSenseResistor_10k  = 3U,  /*!< I-sense resistor is 10.0k, used in mutual-cap mode */
198     kTSI_MutualSenseResistor_12k5 = 4U,  /*!< I-sense resistor is 12.5k, used in mutual-cap mode */
199     kTSI_MutualSenseResistor_15k  = 5U,  /*!< I-sense resistor is 15.0k, used in mutual-cap mode */
200     kTSI_MutualSenseResistor_17k5 = 6U,  /*!< I-sense resistor is 17.5k, used in mutual-cap mode */
201     kTSI_MutualSenseResistor_20k  = 7U,  /*!< I-sense resistor is 20.0k, used in mutual-cap mode */
202     kTSI_MutualSenseResistor_22k5 = 8U,  /*!< I-sense resistor is 22.5k, used in mutual-cap mode */
203     kTSI_MutualSenseResistor_25k  = 9U,  /*!< I-sense resistor is 25.0k, used in mutual-cap mode */
204     kTSI_MutualSenseResistor_27k5 = 10U, /*!< I-sense resistor is 27.5k, used in mutual-cap mode */
205     kTSI_MutualSenseResistor_30k  = 11U, /*!< I-sense resistor is 30.0k, used in mutual-cap mode */
206     kTSI_MutualSenseResistor_32k5 = 12U, /*!< I-sense resistor is 32.5k, used in mutual-cap mode */
207     kTSI_MutualSenseResistor_35k  = 13U, /*!< I-sense resistor is 35.0k, used in mutual-cap mode */
208     kTSI_MutualSenseResistor_37k5 = 14U, /*!< I-sense resistor is 37.5k, used in mutual-cap mode */
209     kTSI_MutualSenseResistor_40k  = 15U  /*!< I-sense resistor is 40.0k, used in mutual-cap mode */
210 } tsi_mutual_sense_resistor_t;
211 
212 /*!
213  * @brief TSI TX channel selection in mutual-cap mode
214  *
215  * These constants Choose the TX channel used in mutual-cap mode.
216  */
217 typedef enum _tsi_mutual_tx_channel
218 {
219     kTSI_MutualTxChannel_0 = 0U, /*!< Select channel 0 as tx0, used in mutual-cap mode */
220     kTSI_MutualTxChannel_1 = 1U, /*!< Select channel 1 as tx1, used in mutual-cap mode */
221     kTSI_MutualTxChannel_2 = 2U, /*!< Select channel 2 as tx2, used in mutual-cap mode */
222     kTSI_MutualTxChannel_3 = 3U, /*!< Select channel 3 as tx3, used in mutual-cap mode */
223     kTSI_MutualTxChannel_4 = 4U, /*!< Select channel 4 as tx4, used in mutual-cap mode */
224     kTSI_MutualTxChannel_5 = 5U, /*!< Select channel 5 as tx5, used in mutual-cap mode */
225 } tsi_mutual_tx_channel_t;
226 
227 /*!
228  * @brief TSI RX channel selection in mutual-cap mode
229  *
230  * These constants Choose the RX channel used in mutual-cap mode.
231  */
232 typedef enum _tsi_mutual_rx_channel
233 {
234     kTSI_MutualRxChannel_6  = 0U, /*!< Select channel 6  as rx6, used in mutual-cap mode */
235     kTSI_MutualRxChannel_7  = 1U, /*!< Select channel 7  as rx7, used in mutual-cap mode */
236     kTSI_MutualRxChannel_8  = 2U, /*!< Select channel 8  as rx8, used in mutual-cap mode */
237     kTSI_MutualRxChannel_9  = 3U, /*!< Select channel 9  as rx9, used in mutual-cap mode */
238     kTSI_MutualRxChannel_10 = 4U, /*!< Select channel 10 as rx10, used in mutual-cap mode */
239     kTSI_MutualRxChannel_11 = 5U, /*!< Select channel 11 as rx11, used in mutual-cap mode */
240 } tsi_mutual_rx_channel_t;
241 
242 /*!
243  * @brief TSI sensitivity boost current settings
244  *
245  * These constants set the sensitivity boost current.
246  */
247 typedef enum _tsi_mutual_sense_boost_current
248 {
249     kTSI_MutualSenseBoostCurrent_0uA  = 0U,  /*!< Sensitivity boost current is 0uA , used in mutual-cap mode */
250     kTSI_MutualSenseBoostCurrent_2uA  = 1U,  /*!< Sensitivity boost current is 2uA , used in mutual-cap mode */
251     kTSI_MutualSenseBoostCurrent_4uA  = 2U,  /*!< Sensitivity boost current is 4uA , used in mutual-cap mode */
252     kTSI_MutualSenseBoostCurrent_6uA  = 3U,  /*!< Sensitivity boost current is 6uA , used in mutual-cap mode */
253     kTSI_MutualSenseBoostCurrent_8uA  = 4U,  /*!< Sensitivity boost current is 8uA , used in mutual-cap mode */
254     kTSI_MutualSenseBoostCurrent_10uA = 5U,  /*!< Sensitivity boost current is 10uA, used in mutual-cap mode */
255     kTSI_MutualSenseBoostCurrent_12uA = 6U,  /*!< Sensitivity boost current is 12uA, used in mutual-cap mode */
256     kTSI_MutualSenseBoostCurrent_14uA = 7U,  /*!< Sensitivity boost current is 14uA, used in mutual-cap mode */
257     kTSI_MutualSenseBoostCurrent_16uA = 8U,  /*!< Sensitivity boost current is 16uA, used in mutual-cap mode */
258     kTSI_MutualSenseBoostCurrent_18uA = 9U,  /*!< Sensitivity boost current is 18uA, used in mutual-cap mode */
259     kTSI_MutualSenseBoostCurrent_20uA = 10U, /*!< Sensitivity boost current is 20uA, used in mutual-cap mode */
260     kTSI_MutualSenseBoostCurrent_22uA = 11U, /*!< Sensitivity boost current is 22uA, used in mutual-cap mode */
261     kTSI_MutualSenseBoostCurrent_24uA = 12U, /*!< Sensitivity boost current is 24uA, used in mutual-cap mode */
262     kTSI_MutualSenseBoostCurrent_26uA = 13U, /*!< Sensitivity boost current is 26uA, used in mutual-cap mode */
263     kTSI_MutualSenseBoostCurrent_28uA = 14U, /*!< Sensitivity boost current is 28uA, used in mutual-cap mode */
264     kTSI_MutualSenseBoostCurrent_30uA = 15U, /*!< Sensitivity boost current is 30uA, used in mutual-cap mode */
265     kTSI_MutualSenseBoostCurrent_32uA = 16U, /*!< Sensitivity boost current is 32uA, used in mutual-cap mode */
266     kTSI_MutualSenseBoostCurrent_34uA = 17U, /*!< Sensitivity boost current is 34uA, used in mutual-cap mode */
267     kTSI_MutualSenseBoostCurrent_36uA = 18U, /*!< Sensitivity boost current is 36uA, used in mutual-cap mode */
268     kTSI_MutualSenseBoostCurrent_38uA = 19U, /*!< Sensitivity boost current is 38uA, used in mutual-cap mode */
269     kTSI_MutualSenseBoostCurrent_40uA = 20U, /*!< Sensitivity boost current is 40uA, used in mutual-cap mode */
270     kTSI_MutualSenseBoostCurrent_42uA = 21U, /*!< Sensitivity boost current is 42uA, used in mutual-cap mode */
271     kTSI_MutualSenseBoostCurrent_44uA = 22U, /*!< Sensitivity boost current is 44uA, used in mutual-cap mode */
272     kTSI_MutualSenseBoostCurrent_46uA = 23U, /*!< Sensitivity boost current is 46uA, used in mutual-cap mode */
273     kTSI_MutualSenseBoostCurrent_48uA = 24U, /*!< Sensitivity boost current is 48uA, used in mutual-cap mode */
274     kTSI_MutualSenseBoostCurrent_50uA = 25U, /*!< Sensitivity boost current is 50uA, used in mutual-cap mode */
275     kTSI_MutualSenseBoostCurrent_52uA = 26U, /*!< Sensitivity boost current is 52uA, used in mutual-cap mode */
276     kTSI_MutualSenseBoostCurrent_54uA = 27U, /*!< Sensitivity boost current is 54uA, used in mutual-cap mode */
277     kTSI_MutualSenseBoostCurrent_56uA = 28U, /*!< Sensitivity boost current is 56uA, used in mutual-cap mode */
278     kTSI_MutualSenseBoostCurrent_58uA = 29U, /*!< Sensitivity boost current is 58uA, used in mutual-cap mode */
279     kTSI_MutualSenseBoostCurrent_60uA = 30U, /*!< Sensitivity boost current is 60uA, used in mutual-cap mode */
280     kTSI_MutualSenseBoostCurrent_62uA = 31U  /*!< Sensitivity boost current is 62uA, used in mutual-cap mode */
281 } tsi_mutual_sense_boost_current_t;
282 
283 /*!
284  * @brief TSI TX drive mode control
285  *
286  * These constants Choose the TX drive mode control setting.
287  */
288 typedef enum _tsi_mutual_tx_drive_mode
289 {
290     kTSI_MutualTxDriveModeOption_0 = 0U, /*!< TX drive mode is -5v ~ +5v, used in mutual-cap mode */
291     kTSI_MutualTxDriveModeOption_1 = 1U, /*!< TX drive mode is  0v ~ +5v, used in mutual-cap mode */
292 } tsi_mutual_tx_drive_mode_t;
293 
294 /*!
295  * @brief TSI Pmos current mirror selection on the left side
296  *
297  * These constants set the Pmos current mirror on the left side used in mutual-cap mode.
298  */
299 typedef enum _tsi_mutual_pmos_current_left
300 {
301     kTSI_MutualPmosCurrentMirrorLeft_4  = 0U, /*!< Set Pmos current mirror left value as 4,  used in mutual-cap mode */
302     kTSI_MutualPmosCurrentMirrorLeft_8  = 1U, /*!< Set Pmos current mirror left value as 8,  used in mutual-cap mode */
303     kTSI_MutualPmosCurrentMirrorLeft_12 = 2U, /*!< Set Pmos current mirror left value as 12, used in mutual-cap mode */
304     kTSI_MutualPmosCurrentMirrorLeft_16 = 3U, /*!< Set Pmos current mirror left value as 16, used in mutual-cap mode */
305     kTSI_MutualPmosCurrentMirrorLeft_20 = 4U, /*!< Set Pmos current mirror left value as 20, used in mutual-cap mode */
306     kTSI_MutualPmosCurrentMirrorLeft_24 = 5U, /*!< Set Pmos current mirror left value as 24, used in mutual-cap mode */
307     kTSI_MutualPmosCurrentMirrorLeft_28 = 6U, /*!< Set Pmos current mirror left value as 28, used in mutual-cap mode */
308     kTSI_MutualPmosCurrentMirrorLeft_32 = 7U, /*!< Set Pmos current mirror left value as 32, used in mutual-cap mode */
309 } tsi_mutual_pmos_current_left_t;
310 
311 /*!
312  * @brief TSI Pmos current mirror selection on the right side
313  *
314  * These constants set the Pmos current mirror on the right side used in mutual-cap mode.
315  */
316 typedef enum _tsi_mutual_pmos_current_right
317 {
318     kTSI_MutualPmosCurrentMirrorRight_1 = 0U, /*!< Set Pmos current mirror right value as 1, used in mutual-cap mode */
319     kTSI_MutualPmosCurrentMirrorRight_2 = 1U, /*!< Set Pmos current mirror right value as 2, used in mutual-cap mode */
320     kTSI_MutualPmosCurrentMirrorRight_3 = 2U, /*!< Set Pmos current mirror right value as 3, used in mutual-cap mode */
321     kTSI_MutualPmosCurrentMirrorRight_4 = 3U, /*!< Set Pmos current mirror right value as 4, used in mutual-cap mode */
322 } tsi_mutual_pmos_current_right_t;
323 
324 /*!
325  * @brief TSI Nmos current mirror selection
326  *
327  * These constants set the Nmos current mirror used in mutual-cap mode.
328  */
329 typedef enum _tsi_mutual_nmos_current
330 {
331     kTSI_MutualNmosCurrentMirror_1 = 0U, /*!< Set Nmos current mirror value as 1, used in mutual-cap mode */
332     kTSI_MutualNmosCurrentMirror_2 = 1U, /*!< Set Nmos current mirror value as 2, used in mutual-cap mode */
333     kTSI_MutualNmosCurrentMirror_3 = 2U, /*!< Set Nmos current mirror value as 3, used in mutual-cap mode */
334     kTSI_MutualNmosCurrentMirror_4 = 3U, /*!< Set Nmos current mirror value as 4, used in mutual-cap mode */
335 } tsi_mutual_nmos_current_t;
336 
337 /*!
338  * @brief TSI SINC cutoff divider setting
339  *
340  * These bits set the SINC cutoff divider.
341  */
342 typedef enum _tsi_sinc_cutoff_div
343 {
344     kTSI_SincCutoffDiv_1   = 0U, /*!< Set SINC cutoff divider as 1   */
345     kTSI_SincCutoffDiv_2   = 1U, /*!< Set SINC cutoff divider as 2   */
346     kTSI_SincCutoffDiv_4   = 2U, /*!< Set SINC cutoff divider as 4   */
347     kTSI_SincCutoffDiv_8   = 3U, /*!< Set SINC cutoff divider as 8   */
348     kTSI_SincCutoffDiv_16  = 4U, /*!< Set SINC cutoff divider as 16  */
349     kTSI_SincCutoffDiv_32  = 5U, /*!< Set SINC cutoff divider as 32  */
350     kTSI_SincCutoffDiv_64  = 6U, /*!< Set SINC cutoff divider as 64  */
351     kTSI_SincCutoffDiv_128 = 7U  /*!< Set SINC cutoff divider as 128 */
352 } tsi_sinc_cutoff_div_t;
353 
354 /*!
355  * @brief TSI SINC filter order setting
356  *
357  * These bits set the SINC filter order.
358  */
359 typedef enum _tsi_sinc_filter_order
360 {
361     kTSI_SincFilterOrder_1 = 0U, /*!< Use 1 order SINC filter */
362     kTSI_SincFilterOrder_2 = 1U, /*!< Use 1 order SINC filter */
363 } tsi_sinc_filter_order_t;
364 
365 /*!
366  * @brief TSI SINC decimation value setting
367  *
368  * These bits set the SINC decimation value.
369  */
370 typedef enum _tsi_sinc_decimation_value
371 {
372     kTSI_SincDecimationValue_1  = 0U,  /*!< The TSI_DATA[TSICH] bits is the counter value of 1  triger period. */
373     kTSI_SincDecimationValue_2  = 1U,  /*!< The TSI_DATA[TSICH] bits is the counter value of 2  triger period. */
374     kTSI_SincDecimationValue_3  = 2U,  /*!< The TSI_DATA[TSICH] bits is the counter value of 3  triger period. */
375     kTSI_SincDecimationValue_4  = 3U,  /*!< The TSI_DATA[TSICH] bits is the counter value of 4  triger period. */
376     kTSI_SincDecimationValue_5  = 4U,  /*!< The TSI_DATA[TSICH] bits is the counter value of 5  triger period. */
377     kTSI_SincDecimationValue_6  = 5U,  /*!< The TSI_DATA[TSICH] bits is the counter value of 6  triger period. */
378     kTSI_SincDecimationValue_7  = 6U,  /*!< The TSI_DATA[TSICH] bits is the counter value of 7  triger period. */
379     kTSI_SincDecimationValue_8  = 7U,  /*!< The TSI_DATA[TSICH] bits is the counter value of 8  triger period. */
380     kTSI_SincDecimationValue_9  = 8U,  /*!< The TSI_DATA[TSICH] bits is the counter value of 9  triger period. */
381     kTSI_SincDecimationValue_10 = 9U,  /*!< The TSI_DATA[TSICH] bits is the counter value of 10 triger period. */
382     kTSI_SincDecimationValue_11 = 10U, /*!< The TSI_DATA[TSICH] bits is the counter value of 11 triger period. */
383     kTSI_SincDecimationValue_12 = 11U, /*!< The TSI_DATA[TSICH] bits is the counter value of 12 triger period. */
384     kTSI_SincDecimationValue_13 = 12U, /*!< The TSI_DATA[TSICH] bits is the counter value of 13 triger period. */
385     kTSI_SincDecimationValue_14 = 13U, /*!< The TSI_DATA[TSICH] bits is the counter value of 14 triger period. */
386     kTSI_SincDecimationValue_15 = 14U, /*!< The TSI_DATA[TSICH] bits is the counter value of 15 triger period. */
387     kTSI_SincDecimationValue_16 = 15U, /*!< The TSI_DATA[TSICH] bits is the counter value of 16 triger period. */
388     kTSI_SincDecimationValue_17 = 16U, /*!< The TSI_DATA[TSICH] bits is the counter value of 17 triger period. */
389     kTSI_SincDecimationValue_18 = 17U, /*!< The TSI_DATA[TSICH] bits is the counter value of 18 triger period. */
390     kTSI_SincDecimationValue_19 = 18U, /*!< The TSI_DATA[TSICH] bits is the counter value of 19 triger period. */
391     kTSI_SincDecimationValue_20 = 19U, /*!< The TSI_DATA[TSICH] bits is the counter value of 20 triger period. */
392     kTSI_SincDecimationValue_21 = 20U, /*!< The TSI_DATA[TSICH] bits is the counter value of 21 triger period. */
393     kTSI_SincDecimationValue_22 = 21U, /*!< The TSI_DATA[TSICH] bits is the counter value of 22 triger period. */
394     kTSI_SincDecimationValue_23 = 22U, /*!< The TSI_DATA[TSICH] bits is the counter value of 23 triger period. */
395     kTSI_SincDecimationValue_24 = 23U, /*!< The TSI_DATA[TSICH] bits is the counter value of 24 triger period. */
396     kTSI_SincDecimationValue_25 = 24U, /*!< The TSI_DATA[TSICH] bits is the counter value of 25 triger period. */
397     kTSI_SincDecimationValue_26 = 25U, /*!< The TSI_DATA[TSICH] bits is the counter value of 26 triger period. */
398     kTSI_SincDecimationValue_27 = 26U, /*!< The TSI_DATA[TSICH] bits is the counter value of 27 triger period. */
399     kTSI_SincDecimationValue_28 = 27U, /*!< The TSI_DATA[TSICH] bits is the counter value of 28 triger period. */
400     kTSI_SincDecimationValue_29 = 28U, /*!< The TSI_DATA[TSICH] bits is the counter value of 29 triger period. */
401     kTSI_SincDecimationValue_30 = 29U, /*!< The TSI_DATA[TSICH] bits is the counter value of 30 triger period. */
402     kTSI_SincDecimationValue_31 = 30U, /*!< The TSI_DATA[TSICH] bits is the counter value of 31 triger period. */
403     kTSI_SincDecimationValue_32 = 31U  /*!< The TSI_DATA[TSICH] bits is the counter value of 32 triger period. */
404 } tsi_sinc_decimation_value_t;
405 
406 /*!
407  * @brief TSI SSC output bit0's period setting(SSC0[CHARGE_NUM])
408  *
409  * These bits set the SSC output bit0's period setting.
410  */
411 typedef enum _tsi_ssc_charge_num
412 {
413     kTSI_SscChargeNumValue_1  = 0U,  /*!< The SSC output bit 0's period will be 1  clock cycle of system clock. */
414     kTSI_SscChargeNumValue_2  = 1U,  /*!< The SSC output bit 0's period will be 2  clock cycle of system clock. */
415     kTSI_SscChargeNumValue_3  = 2U,  /*!< The SSC output bit 0's period will be 3  clock cycle of system clock. */
416     kTSI_SscChargeNumValue_4  = 3U,  /*!< The SSC output bit 0's period will be 4  clock cycle of system clock. */
417     kTSI_SscChargeNumValue_5  = 4U,  /*!< The SSC output bit 0's period will be 5  clock cycle of system clock. */
418     kTSI_SscChargeNumValue_6  = 5U,  /*!< The SSC output bit 0's period will be 6  clock cycle of system clock. */
419     kTSI_SscChargeNumValue_7  = 6U,  /*!< The SSC output bit 0's period will be 7  clock cycle of system clock. */
420     kTSI_SscChargeNumValue_8  = 7U,  /*!< The SSC output bit 0's period will be 8  clock cycle of system clock. */
421     kTSI_SscChargeNumValue_9  = 8U,  /*!< The SSC output bit 0's period will be 9  clock cycle of system clock. */
422     kTSI_SscChargeNumValue_10 = 9U,  /*!< The SSC output bit 0's period will be 10 clock cycle of system clock. */
423     kTSI_SscChargeNumValue_11 = 10U, /*!< The SSC output bit 0's period will be 11 clock cycle of system clock. */
424     kTSI_SscChargeNumValue_12 = 11U, /*!< The SSC output bit 0's period will be 12 clock cycle of system clock. */
425     kTSI_SscChargeNumValue_13 = 12U, /*!< The SSC output bit 0's period will be 13 clock cycle of system clock. */
426     kTSI_SscChargeNumValue_14 = 13U, /*!< The SSC output bit 0's period will be 14 clock cycle of system clock. */
427     kTSI_SscChargeNumValue_15 = 14U, /*!< The SSC output bit 0's period will be 15 clock cycle of system clock. */
428     kTSI_SscChargeNumValue_16 = 15U, /*!< The SSC output bit 0's period will be 16 clock cycle of system clock. */
429 } tsi_ssc_charge_num_t;
430 
431 /*!
432  * @brief TSI SSC output bit1's period setting(SSC0[BASE_NOCHARGE_NUM])
433  *
434  * These bits set the SSC output bit1's period setting.
435  */
436 typedef enum _tsi_ssc_nocharge_num
437 {
438     kTSI_SscNoChargeNumValue_1 = 0U, /*!< The SSC output bit 1's basic period will be 1  clock cycle of system clock. */
439     kTSI_SscNoChargeNumValue_2 = 1U, /*!< The SSC output bit 1's basic period will be 2  clock cycle of system clock. */
440     kTSI_SscNoChargeNumValue_3 = 2U, /*!< The SSC output bit 1's basic period will be 3  clock cycle of system clock. */
441     kTSI_SscNoChargeNumValue_4 = 3U, /*!< The SSC output bit 1's basic period will be 4  clock cycle of system clock. */
442     kTSI_SscNoChargeNumValue_5 = 4U, /*!< The SSC output bit 1's basic period will be 5  clock cycle of system clock. */
443     kTSI_SscNoChargeNumValue_6 = 5U, /*!< The SSC output bit 1's basic period will be 6  clock cycle of system clock. */
444     kTSI_SscNoChargeNumValue_7 = 6U, /*!< The SSC output bit 1's basic period will be 7  clock cycle of system clock. */
445     kTSI_SscNoChargeNumValue_8 = 7U, /*!< The SSC output bit 1's basic period will be 8  clock cycle of system clock. */
446     kTSI_SscNoChargeNumValue_9 = 8U, /*!< The SSC output bit 1's basic period will be 9  clock cycle of system clock. */
447     kTSI_SscNoChargeNumValue_10 =
448         9U, /*!< The SSC output bit 1's basic period will be 10 clock cycle of system clock. */
449     kTSI_SscNoChargeNumValue_11 =
450         10U, /*!< The SSC output bit 1's basic period will be 11 clock cycle of system clock. */
451     kTSI_SscNoChargeNumValue_12 =
452         11U, /*!< The SSC output bit 1's basic period will be 12 clock cycle of system clock. */
453     kTSI_SscNoChargeNumValue_13 =
454         12U, /*!< The SSC output bit 1's basic period will be 13 clock cycle of system clock. */
455     kTSI_SscNoChargeNumValue_14 =
456         13U, /*!< The SSC output bit 1's basic period will be 14 clock cycle of system clock. */
457     kTSI_SscNoChargeNumValue_15 =
458         14U, /*!< The SSC output bit 1's basic period will be 15 clock cycle of system clock. */
459     kTSI_SscNoChargeNumValue_16 =
460         15U, /*!< The SSC output bit 1's basic period will be 16 clock cycle of system clock. */
461 } tsi_ssc_nocharge_num_t;
462 
463 /*!
464  * @brief TSI SSC outsel choosing the length of the PRBS (Pseudo-RandomBinarySequence) method
465  * setting(SSC0[TSI_SSC0_PRBS_OUTSEL])
466  *
467  * These bits set the SSC PRBS length.
468  */
469 typedef enum _tsi_ssc_prbs_outsel
470 {
471     kTSI_SscPrbsOutsel_2  = 2U,  /*!< The length of the PRBS is 2. */
472     kTSI_SscPrbsOutsel_3  = 3U,  /*!< The length of the PRBS is 3. */
473     kTSI_SscPrbsOutsel_4  = 4U,  /*!< The length of the PRBS is 4. */
474     kTSI_SscPrbsOutsel_5  = 5U,  /*!< The length of the PRBS is 5. */
475     kTSI_SscPrbsOutsel_6  = 6U,  /*!< The length of the PRBS is 6. */
476     kTSI_SscPrbsOutsel_7  = 7U,  /*!< The length of the PRBS is 7. */
477     kTSI_SscPrbsOutsel_8  = 8U,  /*!< The length of the PRBS is 8. */
478     kTSI_SscPrbsOutsel_9  = 9U,  /*!< The length of the PRBS is 9. */
479     kTSI_SscPrbsOutsel_10 = 10U, /*!< The length of the PRBS is 10. */
480     kTSI_SscPrbsOutsel_11 = 11U, /*!< The length of the PRBS is 11. */
481     kTSI_SscPrbsOutsel_12 = 12U, /*!< The length of the PRBS is 12. */
482     kTSI_SscPrbsOutsel_13 = 13U, /*!< The length of the PRBS is 13. */
483     kTSI_SscPrbsOutsel_14 = 14U, /*!< The length of the PRBS is 14. */
484     kTSI_SscPrbsOutsel_15 = 15U, /*!< The length of the PRBS is 15. */
485 } tsi_ssc_prbs_outsel_t;
486 
487 /*! @brief TSI status flags. */
488 typedef enum _tsi_status_flags
489 {
490     kTSI_EndOfScanFlag  = TSI_DATA_EOSF_MASK,       /*!< End-Of-Scan flag */
491     kTSI_OutOfRangeFlag = (int)TSI_DATA_OUTRGF_MASK /*!< Out-Of-Range flag */
492 } tsi_status_flags_t;
493 
494 /*! @brief TSI feature interrupt source.*/
495 typedef enum _tsi_interrupt_enable
496 {
497     kTSI_GlobalInterruptEnable     = 1U, /*!< TSI module global interrupt */
498     kTSI_OutOfRangeInterruptEnable = 2U, /*!< Out-Of-Range interrupt */
499     kTSI_EndOfScanInterruptEnable  = 4U  /*!< End-Of-Scan interrupt */
500 } tsi_interrupt_enable_t;
501 
502 /*!
503  * @brief TSI SSC mode selection.
504  *
505  * These constants set the SSC mode.
506  */
507 typedef enum _tsi_ssc_mode
508 {
509     kTSI_ssc_prbs_method     = 0U, /*!< Using PRBS method generating SSC output bit. */
510     kTSI_ssc_up_down_counter = 1U, /*!< Using up-down counter generating SSC output bit. */
511     kTSI_ssc_dissable        = 2U, /*!< SSC function is disabled. */
512 } tsi_ssc_mode_t;
513 
514 /*!
515  * @brief TSI main clock selection.
516  *
517  * These constants set select the divider ratio for the clock used for generating the SSC output bit.
518  */
519 typedef enum _tsi_ssc_prescaler
520 {
521     kTSI_ssc_div_by_1   = 0x0U,  /*!< Set SSC divider to 00000000 div1(2^0) */
522     kTSI_ssc_div_by_2   = 0x1U,  /*!< Set SSC divider to 00000001 div2(2^1) */
523     kTSI_ssc_div_by_4   = 0x3U,  /*!< Set SSC divider to 00000011 div4(2^2) */
524     kTSI_ssc_div_by_8   = 0x7U,  /*!< Set SSC divider to 00000111 div8(2^3) */
525     kTSI_ssc_div_by_16  = 0xfU,  /*!< Set SSC divider to 00001111 div16(2^4) */
526     kTSI_ssc_div_by_32  = 0x1fU, /*!< Set SSC divider to 00011111 div32(2^5) */
527     kTSI_ssc_div_by_64  = 0x3fU, /*!< Set SSC divider to 00111111 div64(2^6) */
528     kTSI_ssc_div_by_128 = 0x7fU, /*!< Set SSC divider to 01111111 div128(2^7) */
529     kTSI_ssc_div_by_256 = 0xffU, /*!< Set SSC divider to 11111111 div256(2^8) */
530 } tsi_ssc_prescaler_t;
531 
532 /*! @brief TSI calibration data storage. */
533 typedef struct _tsi_calibration_data
534 {
535     uint16_t calibratedData[FSL_FEATURE_TSI_CHANNEL_COUNT]; /*!< TSI calibration data storage buffer */
536 } tsi_calibration_data_t;
537 
538 /*!
539  * @brief TSI common configuration structure
540  *
541  * This structure contains the common settings for TSI self-cap or mutual-cap mode, configurations including
542  * the TSI module main clock, sensing mode, DVOLT options, SINC and SSC configurations.
543  */
544 typedef struct _tsi_common_config
545 {
546     tsi_main_clock_selection_t mainClock;   /*!< Set main clock. */
547     tsi_sensing_mode_selection_t mode;      /*!< Choose sensing mode. */
548     tsi_dvolt_option_t dvolt;               /*!< DVOLT option value.  */
549     tsi_sinc_cutoff_div_t cutoff;           /*!< Cutoff divider.  */
550     tsi_sinc_filter_order_t order;          /*!< SINC filter order. */
551     tsi_sinc_decimation_value_t decimation; /*!< SINC decimation value. */
552     tsi_ssc_charge_num_t chargeNum;         /*!< SSC High Width (t1), SSC output bit0's period setting. */
553     tsi_ssc_prbs_outsel_t prbsOutsel;   /*!< SSC High Random Width (t2), length of PRBS(Pseudo-RandomBinarySequence),SSC
554                                            output bit2's period setting. */
555     tsi_ssc_nocharge_num_t noChargeNum; /*!< SSC Low Width (t3), SSC output bit1's period setting. */
556     tsi_ssc_mode_t ssc_mode;            /*!< Clock mode selection (basic - from main clock by divider,advanced - using
557                                            SSC(Switching Speed Clock) by three configurable intervals. */
558     tsi_ssc_prescaler_t ssc_prescaler;  /*!< Set clock divider for basic mode. */
559 } tsi_common_config_t;
560 
561 /*!
562  * @brief TSI configuration structure for self-cap mode
563  *
564  * This structure contains the settings for the most common TSI self-cap configurations including
565  * the TSI module charge currents, sensitivity configuration and so on.
566  */
567 typedef struct _tsi_selfCap_config
568 {
569     tsi_common_config_t commonConfig;            /*!< Common settings.          */
570     bool enableSensitivity;                      /*!< Enable sensitivity boost of self-cap or not. */
571     tsi_shield_t enableShield;                   /*!< Enable shield of self-cap mode or not. */
572     tsi_sensitivity_xdn_option_t xdn;            /*!< Sensitivity XDN option.   */
573     tsi_sensitivity_ctrim_option_t ctrim;        /*!< Sensitivity CTRIM option. */
574     tsi_current_multiple_input_t inputCurrent;   /*!< Input current multiple.   */
575     tsi_current_multiple_charge_t chargeCurrent; /*!< Charge/Discharge current multiple. */
576 } tsi_selfCap_config_t;
577 
578 /*!
579  * @brief TSI configuration structure for mutual-cap mode
580  *
581  * This structure contains the settings for the most common TSI mutual-cap configurations including
582  * the TSI module generator settings, sensitivity related current settings and so on.
583  */
584 typedef struct _tsi_mutualCap_config
585 {
586     tsi_common_config_t commonConfig;                 /*!< Common settings.          */
587     tsi_mutual_pre_current_t preCurrent;              /*!< Vref generator current.  */
588     tsi_mutual_pre_resistor_t preResistor;            /*!< Vref generator resistor. */
589     tsi_mutual_sense_resistor_t senseResistor;        /*!< I-sense generator resistor. */
590     tsi_mutual_sense_boost_current_t boostCurrent;    /*!< Sensitivity boost current setting. */
591     tsi_mutual_tx_drive_mode_t txDriveMode;           /*!< TX drive mode control setting. */
592     tsi_mutual_pmos_current_left_t pmosLeftCurrent;   /*!< Pmos current mirror on the left side.  */
593     tsi_mutual_pmos_current_right_t pmosRightCurrent; /*!< Pmos current mirror on the right side. */
594     bool enableNmosMirror;                            /*!< Enable Nmos current mirror setting or not. */
595     tsi_mutual_nmos_current_t nmosCurrent;            /*!< Nmos current mirror setting. */
596 } tsi_mutualCap_config_t;
597 
598 /*******************************************************************************
599  * API
600  ******************************************************************************/
601 
602 #ifdef __cplusplus
603 extern "C" {
604 #endif
605 
606 /*!
607  * @brief Get the TSI instance from peripheral base address.
608  *
609  * @param base TSI peripheral base address.
610  * @return TSI instance.
611  */
612 uint32_t TSI_GetInstance(TSI_Type *base);
613 
614 /*!
615  * @brief Initialize hardware to Self-cap mode.
616  *
617  * @details Initialize the peripheral to the targeted state specified by parameter config,
618  *          such as sets sensitivity adjustment, current settings.
619  * @param  base    TSI peripheral base address.
620  * @param  config  Pointer to TSI self-cap configuration structure.
621  * @return none
622  */
623 void TSI_InitSelfCapMode(TSI_Type *base, const tsi_selfCap_config_t *config);
624 
625 /*!
626  * @brief Initialize hardware to Mutual-cap mode.
627  *
628  * @details Initialize the peripheral to the targeted state specified by parameter config,
629  *          such as sets Vref generator setting, sensitivity boost settings, Pmos/Nmos settings.
630  * @param  base    TSI peripheral base address.
631  * @param  config  Pointer to TSI mutual-cap configuration structure.
632  * @return none
633  */
634 void TSI_InitMutualCapMode(TSI_Type *base, const tsi_mutualCap_config_t *config);
635 
636 /*!
637  * @brief De-initialize hardware.
638  *
639  * @details De-initialize the peripheral to default state.
640  *
641  * @param  base  TSI peripheral base address.
642  * @return none
643  */
644 void TSI_Deinit(TSI_Type *base);
645 
646 /*!
647  * @brief Get TSI self-cap mode user configure structure.
648  * This interface sets userConfig structure to a default value. The configuration structure only
649  * includes the settings for the whole TSI.
650  * The user configure is set to a value:
651  * @code
652     userConfig->commonConfig.mainClock     = kTSI_MainClockSlection_0;
653     userConfig->commonConfig.mode          = kTSI_SensingModeSlection_Self;
654     userConfig->commonConfig.dvolt         = kTSI_DvoltOption_2;
655     userConfig->commonConfig.cutoff        = kTSI_SincCutoffDiv_1;
656     userConfig->commonConfig.order         = kTSI_SincFilterOrder_1;
657     userConfig->commonConfig.decimation    = kTSI_SincDecimationValue_8;
658     userConfig->commonConfig.chargeNum     = kTSI_SscChargeNumValue_3;
659     userConfig->commonConfig.prbsOutsel    = kTSI_SscPrbsOutsel_2;
660     userConfig->commonConfig.noChargeNum   = kTSI_SscNoChargeNumValue_2;
661     userConfig->commonConfig.ssc_mode      = kTSI_ssc_prbs_method;
662     userConfig->commonConfig.ssc_prescaler = kTSI_ssc_div_by_1;
663     userConfig->enableSensitivity          = true;
664     userConfig->enableShield               = false;
665     userConfig->xdn                        = kTSI_SensitivityXdnOption_1;
666     userConfig->ctrim                      = kTSI_SensitivityCtrimOption_7;
667     userConfig->inputCurrent               = kTSI_CurrentMultipleInputValue_0;
668     userConfig->chargeCurrent              = kTSI_CurrentMultipleChargeValue_1;
669    @endcode
670  *
671  * @param userConfig Pointer to TSI user configure structure.
672  */
673 void TSI_GetSelfCapModeDefaultConfig(tsi_selfCap_config_t *userConfig);
674 
675 /*!
676  * @brief Get TSI mutual-cap mode default user configure structure.
677  * This interface sets userConfig structure to a default value. The configuration structure only
678  * includes the settings for the whole TSI.
679  * The user configure is set to a value:
680  * @code
681     userConfig->commonConfig.mainClock     = kTSI_MainClockSlection_1;
682     userConfig->commonConfig.mode          = kTSI_SensingModeSlection_Mutual;
683     userConfig->commonConfig.dvolt         = kTSI_DvoltOption_0;
684     userConfig->commonConfig.cutoff        = kTSI_SincCutoffDiv_1;
685     userConfig->commonConfig.order         = kTSI_SincFilterOrder_1;
686     userConfig->commonConfig.decimation    = kTSI_SincDecimationValue_8;
687     userConfig->commonConfig.chargeNum     = kTSI_SscChargeNumValue_4;
688     userConfig->commonConfig.prbsOutsel    = kTSI_SscPrbsOutsel_2;
689     userConfig->commonConfig.noChargeNum   = kTSI_SscNoChargeNumValue_5;
690     userConfig->commonConfig.ssc_mode      = kTSI_ssc_prbs_method;
691     userConfig->commonConfig.ssc_prescaler = kTSI_ssc_div_by_1;
692     userConfig->preCurrent                 = kTSI_MutualPreCurrent_4uA;
693     userConfig->preResistor                = kTSI_MutualPreResistor_4k;
694     userConfig->senseResistor              = kTSI_MutualSenseResistor_10k;
695     userConfig->boostCurrent               = kTSI_MutualSenseBoostCurrent_0uA;
696     userConfig->txDriveMode                = kTSI_MutualTxDriveModeOption_0;
697     userConfig->pmosLeftCurrent            = kTSI_MutualPmosCurrentMirrorLeft_32;
698     userConfig->pmosRightCurrent           = kTSI_MutualPmosCurrentMirrorRight_1;
699     userConfig->enableNmosMirror           = true;
700     userConfig->nmosCurrent                = kTSI_MutualNmosCurrentMirror_1;
701    @endcode
702  *
703  * @param userConfig Pointer to TSI user configure structure.
704  */
705 void TSI_GetMutualCapModeDefaultConfig(tsi_mutualCap_config_t *userConfig);
706 
707 /*!
708  * @brief Hardware base counter value for calibration.
709  *
710  * @details Calibrate the peripheral to fetch the initial counter value of
711  *          the enabled channels.
712  *          This API is mostly used at initial application setup, it shall be called
713  *          after the TSI_Init API, then user can use the calibrated
714  *          counter values to setup applications(such as to determine
715  *          under which counter value we can confirm a touch event occurs).
716  *
717  * @param   base    TSI peripheral base address.
718  * @param   calBuff Data buffer that store the calibrated counter value.
719  * @return  none
720  * @note    This API is mainly used for self-cap mode;
721  * @note    The calibration work in mutual-cap mode shall be done in applications due to different board layout.
722  *
723  */
724 void TSI_SelfCapCalibrate(TSI_Type *base, tsi_calibration_data_t *calBuff);
725 
726 /*!
727  * @brief Enables TSI interrupt requests.
728  * @param base TSI peripheral base address.
729  * @param mask interrupt source
730  *     The parameter can be combination of the following source if defined:
731  *     @arg kTSI_GlobalInterruptEnable
732  *     @arg kTSI_EndOfScanInterruptEnable
733  *     @arg kTSI_OutOfRangeInterruptEnable
734  */
735 void TSI_EnableInterrupts(TSI_Type *base, uint32_t mask);
736 
737 /*!
738  * @brief Disables TSI interrupt requests.
739  * @param base TSI peripheral base address.
740  * @param mask interrupt source
741  *     The parameter can be combination of the following source if defined:
742  *     @arg kTSI_GlobalInterruptEnable
743  *     @arg kTSI_EndOfScanInterruptEnable
744  *     @arg kTSI_OutOfRangeInterruptEnable
745  */
746 void TSI_DisableInterrupts(TSI_Type *base, uint32_t mask);
747 
748 /*!
749  * @brief Get interrupt flag.
750  * This function get tsi interrupt flags.
751  *
752  * @param    base  TSI peripheral base address.
753  * @return         The mask of these status flags combination.
754  */
TSI_GetStatusFlags(TSI_Type * base)755 static inline uint32_t TSI_GetStatusFlags(TSI_Type *base)
756 {
757     return (base->DATA & (uint32_t)((uint32_t)kTSI_EndOfScanFlag | (uint32_t)kTSI_OutOfRangeFlag));
758 }
759 
760 /*!
761  * @brief Clear interrupt flag.
762  *
763  * This function clear tsi interrupt flag,
764  * automatically cleared flags can not be cleared by this function.
765  *
766  * @param base TSI peripheral base address.
767  * @param mask The status flags to clear.
768  */
769 void TSI_ClearStatusFlags(TSI_Type *base, uint32_t mask);
770 
771 /*!
772  * @brief Get TSI scan trigger mode.
773  *
774  * @param  base  TSI peripheral base address.
775  * @return       Scan trigger mode.
776  */
TSI_GetScanTriggerMode(TSI_Type * base)777 static inline uint32_t TSI_GetScanTriggerMode(TSI_Type *base)
778 {
779     return (base->GENCS & TSI_GENCS_STM_MASK);
780 }
781 
782 /*!
783  * @brief Enables the TSI Module or not.
784  *
785  * @param   base   TSI peripheral base address.
786  * @param   enable Choose whether to enable or disable module;
787  *                 - true   Enable TSI module;
788  *                 - false  Disable TSI module;
789  * @return  none.
790  */
TSI_EnableModule(TSI_Type * base,bool enable)791 static inline void TSI_EnableModule(TSI_Type *base, bool enable)
792 {
793     if (enable)
794     {
795         base->DATA  = base->DATA & ~ALL_FLAGS_MASK;
796         base->GENCS = base->GENCS | TSI_GENCS_TSIEN_MASK; /* Enable module */
797     }
798     else
799     {
800         base->DATA  = base->DATA & ~ALL_FLAGS_MASK;
801         base->GENCS = base->GENCS & ~TSI_GENCS_TSIEN_MASK; /* Disable module */
802     }
803 }
804 
805 /*!
806  * @brief Sets the TSI low power STOP mode enable or not.
807  *        This enables TSI module function in low power modes.
808  *
809  * @param    base    TSI peripheral base address.
810  * @param    enable  Choose to enable or disable STOP mode.
811  *                   - true   Enable module in STOP mode;
812  *                   - false  Disable module in STOP mode;
813  * @return   none.
814  */
TSI_EnableLowPower(TSI_Type * base,bool enable)815 static inline void TSI_EnableLowPower(TSI_Type *base, bool enable)
816 {
817     if (enable)
818     {
819         base->GENCS =
820             (base->GENCS & ~ALL_FLAGS_MASK) | TSI_GENCS_STPE_MASK; /* Module enabled in low power stop modes */
821     }
822     else
823     {
824         base->GENCS =
825             (base->GENCS & ~ALL_FLAGS_MASK) & (~TSI_GENCS_STPE_MASK); /* Module disabled in low power stop modes */
826     }
827 }
828 
829 /*!
830  * @brief Enable the hardware trigger scan or not.
831  *
832  * @param    base TSI peripheral base address.
833  * @param    enable Choose to enable hardware trigger or software trigger scan.
834  *                  - true    Enable hardware trigger scan;
835  *                  - false   Enable software trigger scan;
836  * @return   none.
837  */
TSI_EnableHardwareTriggerScan(TSI_Type * base,bool enable)838 static inline void TSI_EnableHardwareTriggerScan(TSI_Type *base, bool enable)
839 {
840     if (enable)
841     {
842         base->DATA  = base->DATA & ~ALL_FLAGS_MASK;
843         base->GENCS = base->GENCS | TSI_GENCS_STM_MASK; /* Enable hardware trigger scan */
844     }
845     else
846     {
847         base->DATA  = base->DATA & ~ALL_FLAGS_MASK;
848         base->GENCS = base->GENCS & ~TSI_GENCS_STM_MASK; /* Enable software trigger scan */
849     }
850 }
851 
852 /*!
853  * @brief Start one sotware trigger measurement (trigger a new measurement).
854  *
855  * @param    base TSI peripheral base address.
856  * @return   none.
857  */
TSI_StartSoftwareTrigger(TSI_Type * base)858 static inline void TSI_StartSoftwareTrigger(TSI_Type *base)
859 {
860     base->GENCS |= TSI_GENCS_SWTS_MASK;
861 }
862 
863 /*!
864  * @brief Set the measured channel number for self-cap mode.
865  *
866  * @param    base    TSI peripheral base address.
867  * @param    channel Channel number 0 ... 24.
868  * @return   none.
869  * @note     This API can only be used in self-cap mode!
870  */
TSI_SetSelfCapMeasuredChannel(TSI_Type * base,uint8_t channel)871 static inline void TSI_SetSelfCapMeasuredChannel(TSI_Type *base, uint8_t channel)
872 {
873     assert(channel < (uint8_t)FSL_FEATURE_TSI_CHANNEL_COUNT);
874 
875     base->CONFIG = ((base->CONFIG) & ~TSI_CONFIG_TSICH_MASK) | (TSI_CONFIG_TSICH(channel));
876 }
877 
878 /*!
879  * @brief Get the current measured channel number, in self-cap mode.
880  *
881  * @param    base    TSI peripheral base address.
882  * @return   uint8_t    Channel number 0 ... 24.
883  * @note     This API can only be used in self-cap mode!
884  */
TSI_GetSelfCapMeasuredChannel(TSI_Type * base)885 static inline uint8_t TSI_GetSelfCapMeasuredChannel(TSI_Type *base)
886 {
887     return (uint8_t)((base->CONFIG & TSI_CONFIG_TSICH_MASK) >> TSI_CONFIG_TSICH_SHIFT);
888 }
889 
890 /*!
891  * @brief Decide whether to enable End of Scan DMA transfer request only.
892  *
893  * @param    base TSI peripheral base address.
894  * @param    enable  Choose whether to enable End of Scan DMA transfer request only.
895  *                   - true  Enable End of Scan DMA transfer request only;
896  *                   - false Both End-of-Scan and Out-of-Range can generate DMA transfer request.
897  * @return   none.
898  */
TSI_EnableEndOfScanDmaTransferOnly(TSI_Type * base,bool enable)899 static inline void TSI_EnableEndOfScanDmaTransferOnly(TSI_Type *base, bool enable)
900 {
901     if (enable)
902     {
903         base->GENCS = (base->GENCS & ~ALL_FLAGS_MASK) |
904                       TSI_GENCS_DMAEN_EOS_MASK; /* Enable End of Scan DMA transfer request only; */
905     }
906     else
907     {
908         base->GENCS = (base->GENCS & ~ALL_FLAGS_MASK) &
909                       (~TSI_GENCS_DMAEN_EOS_MASK); /* Both types of events can generate DMA transfer request. */
910     }
911 }
912 
913 /*!
914  * @brief Gets the conversion counter value.
915  *
916  * @param    base TSI peripheral base address.
917  * @return   Accumulated scan counter value ticked by the reference clock.
918  */
TSI_GetCounter(TSI_Type * base)919 static inline uint16_t TSI_GetCounter(TSI_Type *base)
920 {
921     return (uint16_t)(base->DATA & TSI_DATA_TSICNT_MASK);
922 }
923 
924 /*!
925  * @brief Set the TSI wake-up channel low threshold.
926  *
927  * @param    base           TSI peripheral base address.
928  * @param    low_threshold  Low counter threshold.
929  * @return   none.
930  */
TSI_SetLowThreshold(TSI_Type * base,uint16_t low_threshold)931 static inline void TSI_SetLowThreshold(TSI_Type *base, uint16_t low_threshold)
932 {
933     base->TSHD = ((base->TSHD) & ~TSI_TSHD_THRESL_MASK) | (TSI_TSHD_THRESL(low_threshold));
934 }
935 
936 /*!
937  * @brief Set the TSI wake-up channel high threshold.
938  *
939  * @param    base            TSI peripheral base address.
940  * @param    high_threshold  High counter threshold.
941  * @return   none.
942  */
TSI_SetHighThreshold(TSI_Type * base,uint16_t high_threshold)943 static inline void TSI_SetHighThreshold(TSI_Type *base, uint16_t high_threshold)
944 {
945     base->TSHD = ((base->TSHD) & ~TSI_TSHD_THRESH_MASK) | (TSI_TSHD_THRESH(high_threshold));
946 }
947 
948 /*!
949  * @brief Set the main clock of the TSI module.
950  *
951  * @param    base   TSI peripheral base address.
952  * @param    mainClock   clock option value.
953  * @return   none.
954  */
TSI_SetMainClock(TSI_Type * base,tsi_main_clock_selection_t mainClock)955 static inline void TSI_SetMainClock(TSI_Type *base, tsi_main_clock_selection_t mainClock)
956 {
957     base->GENCS = ((base->GENCS) & ~TSI_GENCS_SETCLK_MASK) | (TSI_GENCS_SETCLK(mainClock));
958 }
959 
960 /*!
961  * @brief Set the sensing mode of the TSI module.
962  *
963  * @param    base   TSI peripheral base address.
964  * @param    mode   Mode value.
965  * @return   none.
966  */
TSI_SetSensingMode(TSI_Type * base,tsi_sensing_mode_selection_t mode)967 static inline void TSI_SetSensingMode(TSI_Type *base, tsi_sensing_mode_selection_t mode)
968 {
969     base->CONFIG = ((base->CONFIG) & ~TSI_CONFIG_MODE_MASK) | (TSI_CONFIG_MODE(mode));
970 }
971 
972 /*!
973  * @brief Get the sensing mode of the TSI module.
974  *
975  * @param    base   TSI peripheral base address.
976  * @return   Currently selected sensing mode.
977  */
TSI_GetSensingMode(TSI_Type * base)978 static inline tsi_sensing_mode_selection_t TSI_GetSensingMode(TSI_Type *base)
979 {
980     return (tsi_sensing_mode_selection_t)(uint32_t)((base->CONFIG & TSI_CONFIG_MODE_MASK) >> TSI_CONFIG_MODE_SHIFT);
981 }
982 
983 /*!
984  * @brief Set the DVOLT settings.
985  *
986  * @param    base    TSI peripheral base address.
987  * @param    dvolt   The voltage rails.
988  * @return   none.
989  */
TSI_SetDvolt(TSI_Type * base,tsi_dvolt_option_t dvolt)990 static inline void TSI_SetDvolt(TSI_Type *base, tsi_dvolt_option_t dvolt)
991 {
992     base->GENCS = (base->GENCS & ~(TSI_GENCS_DVOLT_MASK | ALL_FLAGS_MASK)) | (TSI_GENCS_DVOLT(dvolt));
993 }
994 
995 /*!
996  * @brief Enable self-cap mode noise cancellation function or not.
997  *
998  * @param    base                TSI peripheral base address.
999  * @param    enableCancellation  Choose whether to enable noise cancellation in self-cap mode
1000  *                               - true  Enable noise cancellation;
1001  *                               - false Disable noise cancellation;
1002  * @return   none.
1003  */
TSI_EnableNoiseCancellation(TSI_Type * base,bool enableCancellation)1004 static inline void TSI_EnableNoiseCancellation(TSI_Type *base, bool enableCancellation)
1005 {
1006     base->CONFIG = ((base->CONFIG) & ~TSI_CONFIG_S_NOISE_MASK) | (TSI_CONFIG_S_NOISE(enableCancellation));
1007 }
1008 
1009 /*!
1010  * @brief Set the mutual-cap mode TX channel.
1011  *
1012  * @param    base       TSI peripheral base address.
1013  * @param    txChannel  Mutual-cap mode TX channel number
1014  * @return   none.
1015  */
TSI_SetMutualCapTxChannel(TSI_Type * base,tsi_mutual_tx_channel_t txChannel)1016 static inline void TSI_SetMutualCapTxChannel(TSI_Type *base, tsi_mutual_tx_channel_t txChannel)
1017 {
1018     base->CONFIG_MUTUAL =
1019         ((base->CONFIG_MUTUAL) & ~TSI_CONFIG_MUTUAL_M_SEL_TX_MASK) | (TSI_CONFIG_MUTUAL_M_SEL_TX(txChannel));
1020 }
1021 
1022 /*!
1023  * @brief Get the current measured TX channel number, in mutual-cap mode.
1024  *
1025  * @param    base    TSI peripheral base address;
1026  * @return           Tx Channel number 0 ... 5;
1027  * @note     This API can only be used in mutual-cap mode!
1028  */
TSI_GetTxMutualCapMeasuredChannel(TSI_Type * base)1029 static inline tsi_mutual_tx_channel_t TSI_GetTxMutualCapMeasuredChannel(TSI_Type *base)
1030 {
1031     return (tsi_mutual_tx_channel_t)(uint32_t)((base->CONFIG_MUTUAL & TSI_CONFIG_MUTUAL_M_SEL_TX_MASK) >>
1032                                                TSI_CONFIG_MUTUAL_M_SEL_TX_SHIFT);
1033 }
1034 
1035 /*!
1036  * @brief Set the mutual-cap mode RX channel.
1037  *
1038  * @param    base       TSI peripheral base address.
1039  * @param    rxChannel  Mutual-cap mode RX channel number
1040  * @return   none.
1041  */
TSI_SetMutualCapRxChannel(TSI_Type * base,tsi_mutual_rx_channel_t rxChannel)1042 static inline void TSI_SetMutualCapRxChannel(TSI_Type *base, tsi_mutual_rx_channel_t rxChannel)
1043 {
1044     base->CONFIG_MUTUAL =
1045         ((base->CONFIG_MUTUAL) & ~TSI_CONFIG_MUTUAL_M_SEL_RX_MASK) | (TSI_CONFIG_MUTUAL_M_SEL_RX(rxChannel));
1046 }
1047 
1048 /*!
1049  * @brief Get the current measured RX channel number, in mutual-cap mode.
1050  *
1051  * @param    base    TSI peripheral base address;
1052  * @return           Rx Channel number 6 ... 11;
1053  * @note     This API can only be used in mutual-cap mode!
1054  */
TSI_GetRxMutualCapMeasuredChannel(TSI_Type * base)1055 static inline tsi_mutual_rx_channel_t TSI_GetRxMutualCapMeasuredChannel(TSI_Type *base)
1056 {
1057     return (tsi_mutual_rx_channel_t)(uint32_t)((base->CONFIG_MUTUAL & TSI_CONFIG_MUTUAL_M_SEL_RX_MASK) >>
1058                                                TSI_CONFIG_MUTUAL_M_SEL_RX_SHIFT);
1059 }
1060 
1061 /*!
1062  * @brief Set the SSC clock mode of the TSI module.
1063  *
1064  * @param    base   TSI peripheral base address.
1065  * @param    mode   SSC mode option value.
1066  * @return   none.
1067  */
TSI_SetSscMode(TSI_Type * base,tsi_ssc_mode_t mode)1068 static inline void TSI_SetSscMode(TSI_Type *base, tsi_ssc_mode_t mode)
1069 {
1070     base->SSC0 = ((base->SSC0) & ~TSI_SSC0_SSC_MODE_MASK) | (TSI_SSC0_SSC_MODE(mode));
1071 }
1072 
1073 /*!
1074  * @brief Set the SSC prescaler of the TSI module.
1075  *
1076  * @param    base   TSI peripheral base address.
1077  * @param    prescaler  SSC prescaler option value.
1078  * @return   none.
1079  */
TSI_SetSscPrescaler(TSI_Type * base,tsi_ssc_prescaler_t prescaler)1080 static inline void TSI_SetSscPrescaler(TSI_Type *base, tsi_ssc_prescaler_t prescaler)
1081 {
1082     base->SSC0 = ((base->SSC0) & ~TSI_SSC0_SSC_PRESCALE_NUM_MASK) | (TSI_SSC0_SSC_PRESCALE_NUM(prescaler));
1083 }
1084 
1085 /*!
1086  * @brief Set used mutual-cap TX channel.
1087  *
1088  * @param    base       TSI peripheral base address.
1089  * @param    txChannel  Mutual-cap mode TX channel number
1090  * @return   none.
1091  */
TSI_SetUsedTxChannel(TSI_Type * base,tsi_mutual_tx_channel_t txChannel)1092 static inline void TSI_SetUsedTxChannel(TSI_Type *base, tsi_mutual_tx_channel_t txChannel)
1093 {
1094     base->MUL = (base->MUL) | (TSI_MUL_M_TX_USED(1UL << (uint8_t)txChannel));
1095 }
1096 
1097 /*!
1098  * @brief Clear used mutual-cap TX channel.
1099  *
1100  * @param    base       TSI peripheral base address.
1101  * @param    txChannel  Mutual-cap mode TX channel number
1102  * @return   none.
1103  */
TSI_ClearUsedTxChannel(TSI_Type * base,tsi_mutual_tx_channel_t txChannel)1104 static inline void TSI_ClearUsedTxChannel(TSI_Type *base, tsi_mutual_tx_channel_t txChannel)
1105 {
1106     base->MUL &= ~TSI_MUL_M_TX_USED(1UL << (uint8_t)txChannel);
1107 }
1108 
1109 #ifdef __cplusplus
1110 }
1111 #endif /* __cplusplus */
1112 
1113 /*! @}*/
1114 
1115 #endif /* FSL_TSI_V6_H_ */
1116