0% found this document useful (0 votes)
28 views7 pages

XMC Ledts C

ledts

Uploaded by

Roberto Dias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views7 pages

XMC Ledts C

ledts

Uploaded by

Roberto Dias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1 /**

2 * @file xmc_ledts.c
3 * @date 2019-12-16
4 *
5 * @cond
6 *****************************************************************************
7 * XMClib v2.2.0 - XMC Peripheral Driver Library
8 *
9 * Copyright (c) 2015-2020, Infineon Technologies AG
10 * All rights reserved.
11 *
12 * Boost Software License - Version 1.0 - August 17th, 2003
13 *
14 * Permission is hereby granted, free of charge, to any person or organization
15 * obtaining a copy of the software and accompanying documentation covered by
16 * this license (the "Software") to use, reproduce, display, distribute,
17 * execute, and transmit the Software, and to prepare derivative works of the
18 * Software, and to permit third-parties to whom the Software is furnished to
19 * do so, all subject to the following:
20 *
21 * The copyright notices in the Software and this entire statement, including
22 * the above license grant, this restriction and the following disclaimer,
23 * must be included in all copies of the Software, in whole or in part, and
24 * all derivative works of the Software, unless such copies or derivative
25 * works are solely in the form of machine-executable object code generated by
26 * a source language processor.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
31 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
32 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
33 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
34 * DEALINGS IN THE SOFTWARE.
35 *
36 * To improve the quality of the software, users are encouraged to share
37 * modifications, enhancements or bug fixes with Infineon Technologies AG
38 * at XMCSupport@infineon.com.
39 *****************************************************************************
40 *
41 * Change History
42 * --------------
43 *
44 * 2015-02-20:
45 * - Initial draft <br>
46 * - New API added: XMC_LEDTS_SetActivePADNo() <br>
47 *
48 * 2015-06-20:
49 * - Removed version macros and declaration of GetDriverVersion API
50 *
51 * 2017-02-25:
52 * - XMC_LEDTS_InitGlobal() fixed compilation warnings
53 *
54 * 2019-12-16:
55 * - Fix including files following the convention: angle brackets are used for
standard includes and double quotes for everything else.
56 *
57 * <b>Detailed description of file:</b><br>
58 * APIs for the functional blocks of LEDTS have been defined:<br>
59 * -- GLOBAL (APIs prefixed with LEDTS_GLOBAL_) <br>
60 * -- Clock configuration, Function/Event configuration, Interrupt configuration
61 *
62 * @endcond
63 *
64 */
65
66 /*************************************************************************************
********************************
67 * HEADER FILES
68
*************************************************************************************
*******************************/
69 #include "xmc_ledts.h"
70
71 #if defined(LEDTS0)
72 #include "xmc_scu.h"
73
74 /*************************************************************************************
********************************
75 * MACROS
76
*************************************************************************************
*******************************/
77 #define XMC_LEDTS_CLOCK_NOT_RUNNING 0U
78
79 /*************************************************************************************
********************************
80 * ENUMS
81
*************************************************************************************
*******************************/
82
83 /*************************************************************************************
********************************
84 * DATA STRUCTURES
85
*************************************************************************************
*******************************/
86
87 /*************************************************************************************
********************************
88 * GLOBAL DATA
89
*************************************************************************************
*******************************/
90
91 /*************************************************************************************
********************************
92 * LOCAL/UTILITY ROUTINES
93
*************************************************************************************
*******************************/
94
95 /*************************************************************************************
********************************
96 * API IMPLEMENTATION
97
*************************************************************************************
*******************************/
98
99 /**
100 * Initialization of global register
101 */
102 XMC_LEDTS_STATUS_t XMC_LEDTS_InitGlobal(XMC_LEDTS_t *const ledts, const
XMC_LEDTS_GLOBAL_CONFIG_t *config)
103 {
104 XMC_ASSERT("XMC_LEDTS_InitGlobal:Wrong Module Pointer", XMC_LEDTS_CHECK_KERNEL_PTR(
ledts));
105 XMC_ASSERT("XMC_LEDTS_InitGlobal:Null Pointer", (config != (
XMC_LEDTS_GLOBAL_CONFIG_t *)NULL));
106
107 if (ledts == XMC_LEDTS0)
108 {
109 #if defined(CLOCK_GATING_SUPPORTED)
110 XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_LEDTS0);
111 #endif
112 #if defined(PERIPHERAL_RESET_SUPPORTED)
113 XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_LEDTS0);
114 #endif
115 }
116 #if defined(LEDTS1)
117 else if (ledts == XMC_LEDTS1)
118 {
119 #if defined(CLOCK_GATING_SUPPORTED)
120 XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_LEDTS1);
121 #endif
122 #if defined(PERIPHERAL_RESET_SUPPORTED)
123 XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_LEDTS1);
124 #endif
125 }
126 #endif
127 #if defined(LEDTS2)
128 else if (ledts == XMC_LEDTS2)
129 {
130 #if defined(CLOCK_GATING_SUPPORTED)
131 XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_LEDTS2);
132 #endif
133 #if defined(PERIPHERAL_RESET_SUPPORTED)
134 XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_LEDTS2);
135 #endif
136 }
137 #endif
138 else
139 {
140 XMC_ASSERT("XMC_LEDTS_InitGlobal:Invalid Module Pointer", 0);
141 }
142
143 if ((ledts->GLOBCTL & LEDTS_GLOBCTL_CLK_PS_Msk) != XMC_LEDTS_CLOCK_NOT_RUNNING)
144 {
145 return XMC_LEDTS_STATUS_RUNNING;
146 }
147
148 ledts->GLOBCTL = config->globctl;
149
150 return XMC_LEDTS_STATUS_SUCCESS;
151 }
152
153 /**
154 * Initialization of registers for LED-driving function
155 */
156 XMC_LEDTS_STATUS_t XMC_LEDTS_InitLED(XMC_LEDTS_t *const ledts, const
XMC_LEDTS_LED_CONFIG_t *config)
157 {
158 XMC_ASSERT("XMC_LEDTS_LED_Init:Wrong Module Pointer", XMC_LEDTS_CHECK_KERNEL_PTR(
ledts));
159 XMC_ASSERT("XMC_LEDTS_LED_Init:Null Pointer", (config != (XMC_LEDTS_LED_CONFIG_t *)
NULL));
160
161 if ((ledts->GLOBCTL & LEDTS_GLOBCTL_CLK_PS_Msk) != XMC_LEDTS_CLOCK_NOT_RUNNING)
162 {
163 return XMC_LEDTS_STATUS_RUNNING;
164 }
165
166 ledts->FNCTL &= ~(LEDTS_FNCTL_COLLEV_Msk | LEDTS_FNCTL_NR_LEDCOL_Msk);
167 ledts->FNCTL |= (config->fnctl);
168
169 /* Enable LED function */
170 ledts->GLOBCTL |= LEDTS_GLOBCTL_LD_EN_Msk;
171
172 return XMC_LEDTS_STATUS_SUCCESS;
173 }
174
175 /**
176 * Initialization of registers for basic Touch-Sense control function
177 */
178 XMC_LEDTS_STATUS_t XMC_LEDTS_InitTSBasic(XMC_LEDTS_t *const ledts, const
XMC_LEDTS_TS_CONFIG_BASIC_t *config)
179 {
180 uint32_t reg;
181
182 XMC_ASSERT("XMC_LEDTS_TS_Basic_Init:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
183 XMC_ASSERT("XMC_LEDTS_TS_Basic_Init:Null Pointer", (config != (
XMC_LEDTS_TS_CONFIG_BASIC_t *)NULL));
184
185 if ((ledts->GLOBCTL & LEDTS_GLOBCTL_CLK_PS_Msk) != XMC_LEDTS_CLOCK_NOT_RUNNING)
186 {
187 return XMC_LEDTS_STATUS_RUNNING;
188 }
189
190 reg = ~(LEDTS_FNCTL_ACCCNT_Msk | LEDTS_FNCTL_TSCCMP_Msk | LEDTS_FNCTL_TSCTRR_Msk |
LEDTS_FNCTL_TSCTRSAT_Msk |
191 LEDTS_FNCTL_NR_TSIN_Msk);
192 ledts->FNCTL &= (reg);
193 ledts->FNCTL |= (config->fnctl);
194
195 /* Enable TS function */
196 ledts->GLOBCTL |= LEDTS_GLOBCTL_TS_EN_Msk;
197
198 return XMC_LEDTS_STATUS_SUCCESS;
199 }
200
201 /**
202 * Initialization of registers for advanced Touch-Sense control function
203 */
204 XMC_LEDTS_STATUS_t XMC_LEDTS_InitTSAdvanced (XMC_LEDTS_t *const ledts, const
XMC_LEDTS_TS_CONFIG_ADVANCED_t *config)
205 {
206 uint32_t reg;
207
208 XMC_ASSERT("XMC_LEDTS_TS_Advanced_Init:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
209 XMC_ASSERT("XMC_LEDTS_TS_Advanced_Init:Null Pointer", (config != (
XMC_LEDTS_TS_CONFIG_ADVANCED_t *)NULL));
210
211 if ((ledts->GLOBCTL & LEDTS_GLOBCTL_CLK_PS_Msk) != XMC_LEDTS_CLOCK_NOT_RUNNING)
212 {
213 return XMC_LEDTS_STATUS_RUNNING;
214 }
215
216 reg = ~(LEDTS_GLOBCTL_MASKVAL_Msk | LEDTS_GLOBCTL_FENVAL_Msk);
217 ledts->GLOBCTL &= (reg);
218 ledts->GLOBCTL |= (config->globctl);
219
220 reg = ~(LEDTS_FNCTL_PADT_Msk | LEDTS_FNCTL_PADTSW_Msk | LEDTS_FNCTL_EPULL_Msk |
LEDTS_FNCTL_TSOEXT_Msk);
221 ledts->FNCTL &= (reg);
222 ledts->FNCTL |= (config->fnctl);
223
224 return XMC_LEDTS_STATUS_SUCCESS;
225 }
226
227 /**
228 * Starts LEDTS-counter
229 */
230 void XMC_LEDTS_StartCounter(XMC_LEDTS_t *const ledts, const uint16_t prescaler)
231 {
232 XMC_ASSERT("XMC_LEDTS_Start_Counter:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
233
234 ledts->GLOBCTL |= prescaler << 16U;
235 }
236
237 /**
238 * Stops LEDTS-counter
239 */
240 void XMC_LEDTS_StopCounter(XMC_LEDTS_t *const ledts)
241 {
242 XMC_ASSERT("XMC_LEDTS_Stop_Counter:Wrong Module Pointer", XMC_LEDTS_CHECK_KERNEL_PTR
(ledts));
243
244 ledts->GLOBCTL &= 0x0000FFFF;
245 }
246
247 /**
248 * Reads time interrupt flags
249 */
250 uint32_t XMC_LEDTS_ReadInterruptFlag(XMC_LEDTS_t *const ledts)
251 {
252 XMC_ASSERT("XMC_LEDTS_ReadInterruptFlag:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
253
254 return (ledts->EVFR & 0xF);
255 }
256
257 /**
258 * Set the active pad number
259 */
260 void XMC_LEDTS_SetActivePADNo(XMC_LEDTS_t *const ledts, XMC_LEDTS_NUMBER_TS_INPUT_t
pad_num)
261 {
262 uint32_t reg;
263
264 XMC_ASSERT("XMC_LEDTS_SetActivePADNo:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
265
266 reg = ledts->FNCTL;
267 reg &= ~(LEDTS_FNCTL_PADT_Msk);
268 reg |= (uint32_t)pad_num;
269 ledts->FNCTL = reg;
270 }
271
272 /**
273 * Clears interrupt indication flags
274 */
275 void XMC_LEDTS_ClearInterruptFlag(XMC_LEDTS_t *const ledts, uint32_t interrupt_mask)
276 {
277 XMC_ASSERT("XMC_LEDTS_ClearInterruptFlag:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
278
279 ledts->EVFR = (interrupt_mask << LEDTS_EVFR_CTSF_Pos);
280 }
281
282 /**
283 * Programming of registers to output pattern on an LED column in LED matrix
284 */
285 void XMC_LEDTS_SetLEDLinePattern(XMC_LEDTS_t *const ledts, XMC_LEDTS_LED_COLUMN_t
column, const uint8_t pattern)
286 {
287 uint32_t reg;
288 uint8_t reg_index = ((uint8_t)column) >> 2;
289 uint8_t bit_shift_count = ((uint8_t)column & 0x03) * 8;
290
291 XMC_ASSERT("XMC_LEDTS_Set_LED_Line_Pattern:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
292
293 reg = ledts->LINE[reg_index];
294 reg &= (~(0xff << bit_shift_count));
295 reg |= pattern << bit_shift_count;
296 ledts->LINE[reg_index] = reg;
297
298 }
299
300 /**
301 * Programming of registers to adjust brightness of an LED column in LED matrix
302 */
303 void XMC_LEDTS_SetColumnBrightness(XMC_LEDTS_t *const ledts, XMC_LEDTS_LED_COLUMN_t
column, const uint8_t brightness)
304 {
305 uint32_t reg;
306 uint8_t reg_index = ((uint8_t)column) >> 2;
307 uint8_t bit_shift_count = ((uint8_t)column & 0x03) * 8;
308
309 XMC_ASSERT("XMC_LEDTS_Set_Column_Brightness:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
310
311 reg = ledts->LDCMP[reg_index];
312 reg &= (~(0xff << bit_shift_count));
313 reg |= brightness << bit_shift_count;
314 ledts->LDCMP[reg_index] = reg;
315 }
316
317 /**
318 * Programming of registers to set common oscillation window size for touch-sense
inputs
319 */
320 void XMC_LEDTS_SetCommonOscillationWindow(XMC_LEDTS_t *const ledts, const uint8_t
common_size)
321 {
322 uint32_t reg;
323
324 XMC_ASSERT("XMC_LEDTS_Set_Common_Oscillation_Window:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
325
326 reg = ledts->LDCMP[1];
327 reg &= ~LEDTS_LDCMP1_CMP_LDA_TSCOM_Msk;
328 reg |= (common_size << LEDTS_LDCMP1_CMP_LDA_TSCOM_Pos);
329 ledts->LDCMP[1] = reg;
330 }
331
332 /**
333 * Checking the previous active function or LED column status
334 */
335 uint32_t XMC_LEDTS_ReadFNCOL(XMC_LEDTS_t *const ledts)
336 {
337 uint32_t fncol_read;
338
339 XMC_ASSERT("XMC_LEDTS_Read_FNCOL:Wrong Module Pointer", XMC_LEDTS_CHECK_KERNEL_PTR(
ledts));
340
341 fncol_read = ledts->FNCTL & LEDTS_FNCTL_FNCOL_Msk;
342 fncol_read >>= LEDTS_FNCTL_FNCOL_Pos;
343
344 return fncol_read;
345 }
346
347 /**
348 * Set the number of LED column Enabled
349 */
350 void XMC_LEDTS_SetNumOfLEDColumns(XMC_LEDTS_t *const ledts, uint8_t count)
351 {
352
353 XMC_ASSERT("XMC_LEDTS_SetNumOfLEDColumns:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
354
355 ledts->FNCTL &= ~(LEDTS_FNCTL_NR_LEDCOL_Msk);
356 ledts->FNCTL |= (count << LEDTS_FNCTL_NR_LEDCOL_Pos);
357 }
358
359 /**
360 * Reading recorded number of oscillation counts
361 */
362 uint16_t XMC_LEDTS_ReadTSVAL(XMC_LEDTS_t *const ledts)
363 {
364 uint16_t no_of_oscillations;
365
366 XMC_ASSERT("XMC_LEDTS_Read_TSVAL:Wrong Module Pointer", XMC_LEDTS_CHECK_KERNEL_PTR(
ledts));
367
368 no_of_oscillations = (ledts->TSVAL & 0xFFFF);
369
370 return no_of_oscillations;
371 }
372
373 /**
374 * Programming of registers to adjust the size of oscillation window
375 */
376 void XMC_LEDTS_SetOscillationWindow(XMC_LEDTS_t *const ledts,
XMC_LEDTS_NUMBER_TS_INPUT_t touchpad, const uint8_t size)
377 {
378 uint32_t reg;
379 uint8_t reg_index = ((uint8_t)touchpad) >> 2;
380 uint8_t bit_shift_count = ((uint8_t)touchpad & 0x03) * 8;
381
382 XMC_ASSERT("XMC_LEDTS_Set_Oscillation_Window:Wrong Module Pointer",
XMC_LEDTS_CHECK_KERNEL_PTR(ledts));
383
384 reg = ledts->TSCMP[reg_index];
385 reg &= (~(0xff << bit_shift_count));
386 reg |= size << bit_shift_count;
387 ledts->TSCMP[reg_index] = reg;
388 }
389
390 #endif /* LEDTS0 */
391
392

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy