1 /*
2  * Copyright 2023-2024 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef FSL_IOPCTL_H_
10 #define FSL_IOPCTL_H_
11 
12 #include "fsl_common.h"
13 
14 /*!
15  * @addtogroup iopctl_driver
16  * @{
17  */
18 
19 /*! @file */
20 
21 /*******************************************************************************
22  * Definitions
23  ******************************************************************************/
24 
25 /* Component ID definition, used by tools. */
26 #ifndef FSL_COMPONENT_ID
27 #define FSL_COMPONENT_ID "platform.drivers.lpc_iopctl"
28 #endif
29 
30 /*! @name Driver version */
31 /*@{*/
32 /*! @brief IOPCTL driver version 2.0.2. */
33 #define LPC_IOPCTL_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
34 /*@}*/
35 
36 /**
37  * @brief Array of IOPCTL pin definitions passed to IOPCTL_SetPinMuxing() must be in this format
38  */
39 typedef struct _iopctl_group
40 {
41     uint32_t port : 8;      /* Pin port */
42     uint32_t pin : 32;      /* Pin number */
43     uint32_t modefunc : 12; /* Function and mode */
44 } iopctl_group_t;
45 
46 /**
47  * @brief IOPCTL function and mode selection definitions
48  * @note See the User Manual for specific modes and functions supported by the various pins.
49  */
50 #define IOPCTL_FUNC0        0x0         /*!< Selects pin function 0 */
51 #define IOPCTL_FUNC1        0x1         /*!< Selects pin function 1 */
52 #define IOPCTL_FUNC2        0x2         /*!< Selects pin function 2 */
53 #define IOPCTL_FUNC3        0x3         /*!< Selects pin function 3 */
54 #define IOPCTL_FUNC4        0x4         /*!< Selects pin function 4 */
55 #define IOPCTL_FUNC5        0x5         /*!< Selects pin function 5 */
56 #define IOPCTL_FUNC6        0x6         /*!< Selects pin function 6 */
57 #define IOPCTL_FUNC7        0x7         /*!< Selects pin function 7 */
58 #define IOPCTL_FUNC8        0x8         /*!< Selects pin function 8 */
59 #define IOPCTL_FUNC9        0x9         /*!< Selects pin function 9 */
60 #define IOPCTL_FUNC10       0xA         /*!< Selects pin function 10 */
61 #define IOPCTL_FUNC11       0xB         /*!< Selects pin function 11 */
62 #define IOPCTL_FUNC12       0xC         /*!< Selects pin function 12 */
63 #define IOPCTL_FUNC13       0xD         /*!< Selects pin function 13 */
64 #define IOPCTL_FUNC14       0xE         /*!< Selects pin function 14 */
65 #define IOPCTL_FUNC15       0xF         /*!< Selects pin function 15 */
66 #define IOPCTL_PUPD_EN      (0x1 << 4)  /*!< Enables Pullup / Pulldown */
67 #define IOPCTL_PULLDOWN_EN  (0x0 << 5)  /*!< Selects pull-down function */
68 #define IOPCTL_PULLUP_EN    (0x1 << 5)  /*!< Selects pull-up function */
69 #define IOPCTL_INBUF_EN     (0x1 << 6)  /*!< Enables buffer function  on input */
70 #define IOPCTL_SLEW_RATE    (0x0 << 7)  /*!< Slew Rate Control */
71 #define IOPCTL_ANAMUX_EN    (0x1 << 9)  /*!< Enables analog mux function by setting 0 to bit 7 */
72 #define IOPCTL_PSEDRAIN_EN  (0x1 << 10) /*!< Enables pseudo output drain function */
73 #define IOPCTL_INV_EN       (0x1 << 11) /*!< Enables invert function on input */
74 #define IOPCTL_DRIVE_100OHM (0x0 << 12) /*!< Selects transmitter current drive 100ohm */
75 #define IOPCTL_DRIVE_66OHM  (0x1 << 12) /*!< Selects transmitter current drive 66ohm */
76 #define IOPCTL_DRIVE_50OHM  (0x2 << 12) /*!< Selects transmitter current drive 50ohm */
77 #define IOPCTL_DRIVE_33OHM  (0x3 << 12) /*!< Selects transmitter current drive 33ohm */
78 
79 #if defined(__cplusplus)
80 extern "C" {
81 #endif
82 
83 /**
84  * @brief   Sets I/O Pad Control pin mux
85  * @param   port        : Port to mux
86  * @param   pin         : Pin to mux
87  * @param   modefunc    : OR'ed values of type IOPCTL_*
88  * @return  Nothing
89  */
IOPCTL_PinMuxSet(uint8_t port,uint8_t pin,uint32_t modefunc)90 __STATIC_INLINE void IOPCTL_PinMuxSet(uint8_t port, uint8_t pin, uint32_t modefunc)
91 {
92     uint32_t pioBase = 0U;
93 
94     if (port >= 8U) /* IOPCTL_VDD1 */
95     {
96         pioBase = (uint32_t)IOPCTL1 + (uint32_t)((port - 8U) * 32U + pin) * 4UL;
97     }
98     else if (port >= 4U) /* IOPCTL_VDDN */
99     {
100         pioBase = (uint32_t)IOPCTL2 + (uint32_t)((port - 4U) * 32U + pin) * 4UL;
101     }
102     else /* IOPCTL_VDD2 */
103     {
104 #if defined(MIMXRT798S_hifi1_SERIES) || defined(MIMXRT798S_cm33_core1_SERIES) || defined(MIMXRT758S_hifi1_SERIES) || \
105     defined(MIMXRT758S_cm33_core1_SERIES) || defined(MIMXRT735S_hifi1_SERIES) || defined(MIMXRT735S_cm33_core1_SERIES)
106         assert(false);
107 #else
108         pioBase = (uint32_t)IOPCTL0 + (uint32_t)(port * 32U + pin) * 4UL;
109 #endif
110     }
111 
112     *((volatile uint32_t *)pioBase) = modefunc;
113 }
114 
115 /**
116  * @brief   Set all I/O Control pin muxing
117  * @param   pinArray    : Pointer to array of pin mux selections
118  * @param   arrayLength : Number of entries in pinArray
119  * @return  Nothing
120  */
IOPCTL_SetPinMuxing(const iopctl_group_t * pinArray,uint32_t arrayLength)121 __STATIC_INLINE void IOPCTL_SetPinMuxing(const iopctl_group_t *pinArray, uint32_t arrayLength)
122 {
123     uint32_t i;
124 
125     for (i = 0U; i < arrayLength; i++)
126     {
127         IOPCTL_PinMuxSet(pinArray[i].port, pinArray[i].pin, pinArray[i].modefunc);
128     }
129 }
130 
131 /* @} */
132 
133 #if defined(__cplusplus)
134 }
135 #endif
136 
137 #endif /* FSL_IOPCTL_H_ */
138