1 /*
2 * Copyright 2013-2016, 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.0. */
33 #define LPC_IOPCTL_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
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_FULLDRIVE_EN (0x1 << 8) /*!< Selects full drive */
72 #define IOPCTL_ANAMUX_EN (0x1 << 9) /*!< Enables analog mux function by setting 0 to bit 7 */
73 #define IOPCTL_PSEDRAIN_EN (0x1 << 10) /*!< Enables pseudo output drain function */
74 #define IOPCTL_INV_EN (0x1 << 11) /*!< Enables invert function on input */
75
76 #if defined(__cplusplus)
77 extern "C" {
78 #endif
79
80 /**
81 * @brief Sets I/O Pad Control pin mux
82 * @param base : The base of IOPCTL peripheral on the chip
83 * @param port : Port to mux
84 * @param pin : Pin to mux
85 * @param modefunc : OR'ed values of type IOPCTL_*
86 * @return Nothing
87 */
IOPCTL_PinMuxSet(IOPCTL_Type * base,uint8_t port,uint8_t pin,uint32_t modefunc)88 __STATIC_INLINE void IOPCTL_PinMuxSet(IOPCTL_Type *base, uint8_t port, uint8_t pin, uint32_t modefunc)
89 {
90 base->PIO[port][pin] = modefunc;
91 }
92
93 /**
94 * @brief Set all I/O Control pin muxing
95 * @param base : The base of IOPCTL peripheral on the chip
96 * @param pinArray : Pointer to array of pin mux selections
97 * @param arrayLength : Number of entries in pinArray
98 * @return Nothing
99 */
IOPCTL_SetPinMuxing(IOPCTL_Type * base,const iopctl_group_t * pinArray,uint32_t arrayLength)100 __STATIC_INLINE void IOPCTL_SetPinMuxing(IOPCTL_Type *base, const iopctl_group_t *pinArray, uint32_t arrayLength)
101 {
102 uint32_t i;
103
104 for (i = 0; i < arrayLength; i++)
105 {
106 IOPCTL_PinMuxSet(base, pinArray[i].port, pinArray[i].pin, pinArray[i].modefunc);
107 }
108 }
109
110 /* @} */
111
112 #if defined(__cplusplus)
113 }
114 #endif
115
116 #endif /* _FSL_IOPCTL_H_ */
117