1 /*
2  * Copyright 2017 , NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_port.h"
10 
11 /*******************************************************************************
12  * Definitions
13  ******************************************************************************/
14 /* Component ID definition, used by tools. */
15 #ifndef FSL_COMPONENT_ID
16 #define FSL_COMPONENT_ID "platform.drivers.port_ke04"
17 #endif
18 
19 /*******************************************************************************
20  * Variables
21  ******************************************************************************/
22 
23 /*******************************************************************************
24  * Prototypes
25  ******************************************************************************/
26 
27 /*******************************************************************************
28  * Code
29  ******************************************************************************/
30  /*!
31  * brief Selects pin for modules.
32  *
33  * This API is used to select the port pin for the module with multiple port pin
34  * selection. For example the FTM Channel 0 can be mapped to ether PTA0 or PTB2.
35  * Select FTM channel 0 map to PTA0 port pin as:
36  * code
37  * PORT_SetPinSelect(kPORT_FTM0CH0, kPORT_FTM0_CH0_PTA0);
38  * endcode
39  *
40  * @Note: This API doesn't support to select specified ALT for a given port pin.
41  * The ALT feature is automatically selected by hardware according to the
42  * ALT priority:
43  *     Low -----> high:
44  *     Alt1, Alt2, …
45  * when peripheral modules has been enabled.
46  *
47  * If you want to select a specified ALT for a given port pin, please add two more
48  * steps after calling PORT_SetPinSelect:
49  * 1. Enable module or the port control in the module for the ALT you want to select.
50  *   For I2C ALT feature:all port enable is controlled by the module enable, so
51  *   set IICEN in I2CX_C1 to enable the port pins for I2C feature.
52  *   For KBI ALT feature:each port pin is controlled independently by each bit in KBIx_PE.
53  *   set related bit in this register to enable the KBI feature in the port pin.
54  * 2. Make sure there is no module enabled with higher priority than the ALT module feature
55  *  you want to select.
56  *
57  * param module   Modules for pin selection.
58  *        For NMI/RST module are write-once attribute after reset.
59  * param pin   Port pin selection for modules.
60  *
61  */
PORT_SetPinSelect(port_module_t module,port_pin_select_t pin)62 void PORT_SetPinSelect(port_module_t module, port_pin_select_t pin)
63 {
64     if (0UL != (uint32_t)pin)
65     {
66         if (module > kPORT_SWDE)
67         {
68             SIM->PINSEL |= (uint32_t)module;
69         }
70         else
71         {
72             SIM->SOPT |= (uint32_t)module;
73         }
74     }
75     else
76     {
77         if (module > kPORT_SWDE)
78         {
79             SIM->PINSEL &= ~ (uint32_t)module;
80         }
81         else
82         {
83             SIM->SOPT &= ~ (uint32_t)module;
84         }
85     }
86 }
87