]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/llwu/fsl_llwu_hal.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[qmk_firmware.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_KPSDK_MCUS / TARGET_KPSDK_CODE / hal / llwu / fsl_llwu_hal.c
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  *   of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  *   list of conditions and the following disclaimer in the documentation and/or
13  *   other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  *   contributors may be used to endorse or promote products derived from this
17  *   software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "fsl_llwu_hal.h"
32
33 /*******************************************************************************
34  * Definitions
35  ******************************************************************************/
36
37 /*******************************************************************************
38  * Code
39  ******************************************************************************/
40
41 /*FUNCTION**********************************************************************
42  *
43  * Function Name : LLWU_HAL_SetExternalInputPinMode
44  * Description   : Set external input pin source mode
45  * This function will set the external input pin source mode that will be used
46  * as wake up source.
47  * 
48  *END**************************************************************************/
49 void LLWU_HAL_SetExternalInputPinMode(uint32_t baseAddr,
50                                       llwu_external_pin_modes_t pinMode,
51                                       uint32_t pinNumber)
52 {
53     /* check pin number */
54     assert(pinNumber < FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN);
55
56     switch (pinNumber)
57     {
58     case 0:
59         BW_LLWU_PE1_WUPE0(baseAddr, pinMode);
60         break;
61     case 1:
62         BW_LLWU_PE1_WUPE1(baseAddr, pinMode);
63         break;
64     case 2:
65         BW_LLWU_PE1_WUPE2(baseAddr, pinMode);
66         break;
67     case 3:
68         BW_LLWU_PE1_WUPE3(baseAddr, pinMode);
69         break;
70     case 4:
71         BW_LLWU_PE2_WUPE4(baseAddr, pinMode);
72         break;
73     case 5:
74         BW_LLWU_PE2_WUPE5(baseAddr, pinMode);
75         break;
76     case 6:
77         BW_LLWU_PE2_WUPE6(baseAddr, pinMode);
78         break;
79     case 7:
80         BW_LLWU_PE2_WUPE7(baseAddr, pinMode);
81         break;
82     case 8:
83         BW_LLWU_PE3_WUPE8(baseAddr, pinMode);
84         break;
85     case 9:
86         BW_LLWU_PE3_WUPE9(baseAddr, pinMode);
87         break;
88     case 10:
89         BW_LLWU_PE3_WUPE10(baseAddr, pinMode);
90         break;
91     case 11:
92         BW_LLWU_PE3_WUPE11(baseAddr, pinMode);
93         break;
94     case 12:
95         BW_LLWU_PE4_WUPE12(baseAddr, pinMode);
96         break;
97     case 13:
98         BW_LLWU_PE4_WUPE13(baseAddr, pinMode);
99         break;
100     case 14:
101         BW_LLWU_PE4_WUPE14(baseAddr, pinMode);
102         break;
103     case 15:
104         BW_LLWU_PE4_WUPE15(baseAddr, pinMode);
105         break;
106     default:
107         break;
108     }
109 }
110
111 /*FUNCTION**********************************************************************
112  *
113  * Function Name : LLWU_HAL_GetExternalInputPinMode
114  * Description   : Get external input pin source mode
115  * This function will get the external input pin source mode that will be used
116  * as wake up source.
117  * 
118  *END**************************************************************************/
119 llwu_external_pin_modes_t LLWU_HAL_GetExternalInputPinMode(uint32_t baseAddr,
120                                                            uint32_t pinNumber)
121 {
122     llwu_external_pin_modes_t retValue = (llwu_external_pin_modes_t)0;
123
124     /* check pin number */
125     assert(pinNumber < FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN);
126
127     switch (pinNumber)
128     {
129     case 0:
130         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE1_WUPE0(baseAddr);
131         break;
132     case 1:
133         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE1_WUPE1(baseAddr);
134         break;
135     case 2:
136         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE1_WUPE2(baseAddr);
137         break;
138     case 3:
139         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE1_WUPE3(baseAddr);
140         break;
141     case 4:
142         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE2_WUPE4(baseAddr);
143         break;
144     case 5:
145         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE2_WUPE5(baseAddr);
146         break;
147     case 6:
148         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE2_WUPE6(baseAddr);
149         break;
150     case 7:
151         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE2_WUPE7(baseAddr);
152         break;
153     case 8:
154         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE3_WUPE8(baseAddr);
155         break;
156     case 9:
157         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE3_WUPE9(baseAddr);
158         break;
159     case 10:
160         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE3_WUPE10(baseAddr);
161         break;
162     case 11:
163         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE3_WUPE11(baseAddr);
164         break;
165     case 12:
166         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE4_WUPE12(baseAddr);
167         break;
168     case 13:
169         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE4_WUPE13(baseAddr);
170         break;
171     case 14:
172         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE4_WUPE14(baseAddr);
173         break;
174     case 15:
175         retValue = (llwu_external_pin_modes_t)BR_LLWU_PE4_WUPE15(baseAddr);
176         break;
177     default:
178         retValue = (llwu_external_pin_modes_t)0;
179         break;
180     }
181
182     return retValue;
183 }
184
185 /*FUNCTION**********************************************************************
186  *
187  * Function Name : LLWU_HAL_SetInternalModuleCmd
188  * Description   : Enable/disable internal module source
189  * This function will enable/disable the internal module source mode that will 
190  * be used as wake up source. 
191  * 
192  *END**************************************************************************/
193 void LLWU_HAL_SetInternalModuleCmd(uint32_t baseAddr, uint32_t moduleNumber, bool enable)
194 {
195     /* check module number */
196     assert(moduleNumber < FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE);
197
198     switch (moduleNumber)
199     {
200     case 0:
201         BW_LLWU_ME_WUME0(baseAddr, enable);
202         break;
203     case 1:
204         BW_LLWU_ME_WUME1(baseAddr, enable);
205         break;
206     case 2:
207         BW_LLWU_ME_WUME2(baseAddr, enable);
208         break;
209     case 3:
210         BW_LLWU_ME_WUME3(baseAddr, enable);
211         break;
212     case 4:
213         BW_LLWU_ME_WUME4(baseAddr, enable);
214         break;
215     case 5:
216         BW_LLWU_ME_WUME5(baseAddr, enable);
217         break;
218     case 6:
219         BW_LLWU_ME_WUME6(baseAddr, enable);
220         break;
221     case 7:
222         BW_LLWU_ME_WUME7(baseAddr, enable);
223         break;
224     default:
225         break;
226     }
227 }
228
229 /*FUNCTION**********************************************************************
230  *
231  * Function Name : LLWU_HAL_GetInternalModuleCmd
232  * Description   : Get internal module source enable setting
233  * This function will enable/disable the internal module source mode that will 
234  * be used as wake up source. 
235  * 
236  *END**************************************************************************/
237 bool LLWU_HAL_GetInternalModuleCmd(uint32_t baseAddr, uint32_t moduleNumber)
238 {
239     bool retValue = false;
240
241     /* check module number */
242     assert(moduleNumber < FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE);
243
244     switch (moduleNumber)
245     {
246     case 0:
247         retValue = (bool)BR_LLWU_ME_WUME0(baseAddr);
248         break;
249     case 1:
250         retValue = (bool)BR_LLWU_ME_WUME1(baseAddr);
251         break;
252     case 2:
253         retValue = (bool)BR_LLWU_ME_WUME2(baseAddr);
254         break;
255     case 3:
256         retValue = (bool)BR_LLWU_ME_WUME3(baseAddr);
257         break;
258     case 4:
259         retValue = (bool)BR_LLWU_ME_WUME4(baseAddr);
260         break;
261     case 5:
262         retValue = (bool)BR_LLWU_ME_WUME5(baseAddr);
263         break;
264     case 6:
265         retValue = (bool)BR_LLWU_ME_WUME6(baseAddr);
266         break;
267     case 7:
268         retValue = (bool)BR_LLWU_ME_WUME7(baseAddr);
269         break;
270     default:
271         retValue = false;
272         break;
273     }
274
275     return retValue;
276 }
277
278 /*FUNCTION**********************************************************************
279  *
280  * Function Name : LLWU_HAL_GetExternalPinWakeupFlag
281  * Description   : Get external wakeup source flag
282  * This function will get the external wakeup source flag for specific pin. 
283  * 
284  *END**************************************************************************/
285 bool LLWU_HAL_GetExternalPinWakeupFlag(uint32_t baseAddr, uint32_t pinNumber)
286 {
287     bool retValue = false;
288
289     /* check pin number */
290     assert(pinNumber < FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN);
291
292     switch (pinNumber)
293     {
294     case 0:
295         retValue = (bool)BR_LLWU_F1_WUF0(baseAddr);
296         break;
297     case 1:
298         retValue = (bool)BR_LLWU_F1_WUF1(baseAddr);
299         break;
300     case 2:
301         retValue = (bool)BR_LLWU_F1_WUF2(baseAddr);
302         break;
303     case 3:
304         retValue = (bool)BR_LLWU_F1_WUF3(baseAddr);
305         break;
306     case 4:
307         retValue = (bool)BR_LLWU_F1_WUF4(baseAddr);
308         break;
309     case 5:
310         retValue = (bool)BR_LLWU_F1_WUF5(baseAddr);
311         break;
312     case 6:
313         retValue = (bool)BR_LLWU_F1_WUF6(baseAddr);
314         break;
315     case 7:
316         retValue = (bool)BR_LLWU_F1_WUF7(baseAddr);
317         break;
318     case 8:
319         retValue = (bool)BR_LLWU_F2_WUF8(baseAddr);
320         break;
321     case 9:
322         retValue = (bool)BR_LLWU_F2_WUF9(baseAddr);
323         break;
324     case 10:
325         retValue = (bool)BR_LLWU_F2_WUF10(baseAddr);
326         break;
327     case 11:
328         retValue = (bool)BR_LLWU_F2_WUF11(baseAddr);
329         break;
330     case 12:
331         retValue = (bool)BR_LLWU_F2_WUF12(baseAddr);
332         break;
333     case 13:
334         retValue = (bool)BR_LLWU_F2_WUF13(baseAddr);
335         break;
336     case 14:
337         retValue = (bool)BR_LLWU_F2_WUF14(baseAddr);
338         break;
339     case 15:
340         retValue = (bool)BR_LLWU_F2_WUF15(baseAddr);
341         break;
342     default:
343         retValue = false;
344         break;
345     }
346
347     return retValue;
348 }
349
350 /*FUNCTION**********************************************************************
351  *
352  * Function Name : LLWU_HAL_ClearExternalPinWakeupFlag
353  * Description   : Clear external wakeup source flag
354  * This function will clear the external wakeup source flag for specific pin.
355  * 
356  *END**************************************************************************/
357 void LLWU_HAL_ClearExternalPinWakeupFlag(uint32_t baseAddr, uint32_t pinNumber)
358 {
359     /* check pin number */
360     assert(pinNumber < FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN);
361
362     switch (pinNumber)
363     {
364     case 0:
365         BW_LLWU_F1_WUF0(baseAddr, 1);
366         break;
367     case 1:
368         BW_LLWU_F1_WUF1(baseAddr, 1);
369         break;
370     case 2:
371         BW_LLWU_F1_WUF2(baseAddr, 1);
372         break;
373     case 3:
374         BW_LLWU_F1_WUF3(baseAddr, 1);
375         break;
376     case 4:
377         BW_LLWU_F1_WUF4(baseAddr, 1);
378         break;
379     case 5:
380         BW_LLWU_F1_WUF5(baseAddr, 1);
381         break;
382     case 6:
383         BW_LLWU_F1_WUF6(baseAddr, 1);
384         break;
385     case 7:
386         BW_LLWU_F1_WUF7(baseAddr, 1);
387         break;
388     case 8:
389         BW_LLWU_F2_WUF8(baseAddr, 1);
390         break;
391     case 9:
392         BW_LLWU_F2_WUF9(baseAddr, 1);
393         break;
394     case 10:
395         BW_LLWU_F2_WUF10(baseAddr, 1);
396         break;
397     case 11:
398         BW_LLWU_F2_WUF11(baseAddr, 1);
399         break;
400     case 12:
401         BW_LLWU_F2_WUF12(baseAddr, 1);
402         break;
403     case 13:
404         BW_LLWU_F2_WUF13(baseAddr, 1);
405         break;
406     case 14:
407         BW_LLWU_F2_WUF14(baseAddr, 1);
408         break;
409     case 15:
410         BW_LLWU_F2_WUF15(baseAddr, 1);
411         break;
412     default:
413         break;
414     }
415 }
416
417 /*FUNCTION**********************************************************************
418  *
419  * Function Name : LLWU_HAL_GetInternalModuleWakeupFlag
420  * Description   : Get internal module wakeup source flag
421  * This function will get the internal module wakeup source flag for specific 
422  * module
423  * 
424  *END**************************************************************************/
425 bool LLWU_HAL_GetInternalModuleWakeupFlag(uint32_t baseAddr, uint32_t moduleNumber)
426 {
427     bool retValue = false;
428
429     /* check module number */
430     assert(moduleNumber < FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE);
431
432     switch (moduleNumber)
433     {
434     case 0:
435         retValue = (bool)BR_LLWU_F3_MWUF0(baseAddr);
436         break;
437     case 1:
438         retValue = (bool)BR_LLWU_F3_MWUF1(baseAddr);
439         break;
440     case 2:
441         retValue = (bool)BR_LLWU_F3_MWUF2(baseAddr);
442         break;
443     case 3:
444         retValue = (bool)BR_LLWU_F3_MWUF3(baseAddr);
445         break;
446     case 4:
447         retValue = (bool)BR_LLWU_F3_MWUF4(baseAddr);
448         break;
449     case 5:
450         retValue = (bool)BR_LLWU_F3_MWUF5(baseAddr);
451         break;
452     case 6:
453         retValue = (bool)BR_LLWU_F3_MWUF6(baseAddr);
454         break;
455     case 7:
456         retValue = (bool)BR_LLWU_F3_MWUF7(baseAddr);
457         break;
458     default:
459         retValue = false;
460         break;
461     }
462
463     return retValue;
464 }
465
466 /*FUNCTION**********************************************************************
467  *
468  * Function Name : LLWU_HAL_SetPinFilterMode
469  * Description   : Set pin filter configuration
470  * This function will set the pin filter configuration.
471  * 
472  *END**************************************************************************/
473 void LLWU_HAL_SetPinFilterMode(uint32_t baseAddr,
474                                uint32_t filterNumber, 
475                                llwu_external_pin_filter_mode_t pinFilterMode)
476 {
477     /* check filter and pin number */
478     assert(filterNumber < FSL_FEATURE_LLWU_HAS_PIN_FILTER);
479     assert(pinFilterMode.pinNumber < FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN);
480
481     /* branch to filter number */
482     switch(filterNumber)
483     {
484     case 0:
485         BW_LLWU_FILT1_FILTSEL(baseAddr, pinFilterMode.pinNumber);
486         BW_LLWU_FILT1_FILTE(baseAddr, pinFilterMode.filterMode);
487         break;
488     case 1:
489         BW_LLWU_FILT2_FILTSEL(baseAddr, pinFilterMode.pinNumber);
490         BW_LLWU_FILT2_FILTE(baseAddr, pinFilterMode.filterMode);
491         break;
492     default:
493         break;
494     }
495 }
496
497 /*FUNCTION**********************************************************************
498  *
499  * Function Name : LLWU_HAL_GetPinFilterMode
500  * Description   : Get pin filter configuration.
501  * This function will get the pin filter configuration.
502  * 
503  *END**************************************************************************/
504 void LLWU_HAL_GetPinFilterMode(uint32_t baseAddr,
505                                uint32_t filterNumber, 
506                                llwu_external_pin_filter_mode_t *pinFilterMode)
507 {
508     /* check filter and pin number */
509     assert(filterNumber < FSL_FEATURE_LLWU_HAS_PIN_FILTER);
510     assert(pinFilterMode->pinNumber < FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN);
511
512     /* branch to filter number */
513     switch(filterNumber)
514     {
515     case 0:
516         pinFilterMode->pinNumber = BR_LLWU_FILT1_FILTSEL(baseAddr);
517         pinFilterMode->filterMode = (llwu_filter_modes_t)BR_LLWU_FILT1_FILTE(baseAddr);
518         break;
519     case 1:
520         pinFilterMode->pinNumber = BR_LLWU_FILT2_FILTSEL(baseAddr);
521         pinFilterMode->filterMode = (llwu_filter_modes_t)BR_LLWU_FILT2_FILTE(baseAddr);
522         break;
523     default:
524         break;
525     }
526 }
527
528 /*FUNCTION**********************************************************************
529  *
530  * Function Name : LLWU_HAL_GetFilterDetectFlag
531  * Description   : Get filter detect flag
532  * This function will get the filter detect flag.
533  * 
534  *END**************************************************************************/
535 bool LLWU_HAL_GetFilterDetectFlag(uint32_t baseAddr, uint32_t filterNumber)
536 {
537     bool retValue = false;
538
539     /* check filter and pin number */
540     assert(filterNumber < FSL_FEATURE_LLWU_HAS_PIN_FILTER);
541
542     /* branch to filter number */
543     switch(filterNumber)
544     {
545     case 0:
546         retValue = (bool)BR_LLWU_FILT1_FILTF(baseAddr);
547         break;
548     case 1:
549         retValue = (bool)BR_LLWU_FILT2_FILTF(baseAddr);
550         break;
551     default:
552         retValue = false;
553         break;
554     }
555
556     return retValue;
557 }
558
559 /*FUNCTION**********************************************************************
560  *
561  * Function Name : LLWU_HAL_ClearFilterDetectFlag
562  * Description   : Clear filter detect flag
563  * This function will clear the filter detect flag.
564  * 
565  *END**************************************************************************/
566 void LLWU_HAL_ClearFilterDetectFlag(uint32_t baseAddr, uint32_t filterNumber)
567 {
568     /* check filter and pin number */
569     assert(filterNumber < FSL_FEATURE_LLWU_HAS_PIN_FILTER);
570
571     /* branch to filter number */
572     switch(filterNumber)
573     {
574     case 0:
575         BW_LLWU_FILT1_FILTF(baseAddr, 1);
576         break;
577     case 1:
578         BW_LLWU_FILT2_FILTF(baseAddr, 1);
579         break;
580     default:
581         break;
582     }
583 }
584
585 #if FSL_FEATURE_LLWU_HAS_RESET_ENABLE
586 /*FUNCTION**********************************************************************
587  *
588  * Function Name : LLWU_HAL_SetResetEnableMode
589  * Description   : Set reset enable mode
590  * This function will set the reset enable mode.
591  * 
592  *END**************************************************************************/
593 void LLWU_HAL_SetResetEnableMode(uint32_t baseAddr, llwu_reset_enable_mode_t resetEnableMode)
594 {
595     BW_LLWU_RST_RSTFILT(baseAddr, resetEnableMode.digitalFilterMode);
596     BW_LLWU_RST_LLRSTE(baseAddr, resetEnableMode.lowLeakageMode);
597 }
598
599 /*FUNCTION**********************************************************************
600  *
601  * Function Name : LLWU_HAL_GetResetEnableMode
602  * Description   : Get reset enable mode
603  * This function will get the reset enable mode.
604  * 
605  *END**************************************************************************/
606 void LLWU_HAL_GetResetEnableMode(uint32_t baseAddr, llwu_reset_enable_mode_t *resetEnableMode)
607 {
608     resetEnableMode->digitalFilterMode = (bool)BR_LLWU_RST_RSTFILT(baseAddr);
609     resetEnableMode->lowLeakageMode = (bool)BR_LLWU_RST_LLRSTE(baseAddr);
610 }
611 #endif
612
613 /*******************************************************************************
614  * EOF
615  ******************************************************************************/
616