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_ke02"
17 #endif
18 #define PORT_PINNUMS_EACHPORT (8U)   /* PORT pin numbers in each PTA/PTB etc. */
19 #define PORT_NUM_EACH_PULLUPREG (4U) /* The port numbers in each pull up register. */
20 
21 /*******************************************************************************
22  * Variables
23  ******************************************************************************/
24 
25 /*******************************************************************************
26  * Prototypes
27  ******************************************************************************/
28 
29 /*******************************************************************************
30  * Code
31  ******************************************************************************/
32 /*!
33  * brief Enables or disables the port pull up.
34  *
35  * param base   PORT peripheral base pointer.
36  * param port   PORT type, such as PTA/PTB/PTC etc, see "port_type_t".
37  * param num    PORT Pin number, such as 0, 1, 2....
38  *               There are seven pins not exists in this device:
39  *               PTG: PTG4, PTG5, PTG6, PTG7. PTH: PTH3, PTH4, PTH5.
40  *               so, when set PTG, and PTH, please don't set the pins mentioned above.
41  *               Please take refer to the reference manual.
42  * param enable  Enable or disable the pull up feature switch.
43  */
PORT_SetPinPullUpEnable(PORT_Type * base,port_type_t port,uint8_t num,bool enable)44 void PORT_SetPinPullUpEnable(PORT_Type *base, port_type_t port, uint8_t num, bool enable)
45 {
46     if (enable)
47     {
48         /* Enable the pull up */
49         if (port < kPORT_PTE)
50         {
51             base->PUEL |= (1UL << (PORT_PINNUMS_EACHPORT * (uint32_t)port + (uint32_t)num));
52         }
53         else
54         {
55             base->PUEH |= (1UL << (PORT_PINNUMS_EACHPORT * ((uint32_t)port - PORT_NUM_EACH_PULLUPREG) + (uint32_t)num));
56         }
57     }
58     else
59     {
60         /* Disable the pull up */
61         if (port < kPORT_PTE)
62         {
63             base->PUEL &= ~(1UL << (PORT_PINNUMS_EACHPORT * (uint32_t)port + (uint32_t)num));
64         }
65         else
66         {
67             base->PUEH &=
68                 ~(1UL << (PORT_PINNUMS_EACHPORT * ((uint32_t)port - PORT_NUM_EACH_PULLUPREG) + (uint32_t)num));
69         }
70     }
71 }
72 
PORT_SetPinSelect(port_module_t module,port_pin_select_t pin)73 void PORT_SetPinSelect(port_module_t module, port_pin_select_t pin)
74 {
75     if ((uint32_t)pin != 0U)
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     else
87     {
88         if (module > kPORT_SWDE)
89         {
90             SIM->PINSEL &= ~(uint32_t)module;
91         }
92         else
93         {
94             SIM->SOPT &= ~(uint32_t)module;
95         }
96     }
97 }
98