1 /*
2  * Copyright 2017-2021, 2023 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef FSL_IOCON_H_
10 #define FSL_IOCON_H_
11 
12 #include "fsl_common.h"
13 
14 /*!
15  * @addtogroup lpc_iocon
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_iocon_lite"
28 #endif
29 
30 /*! @name Driver version */
31 /*! @{ */
32 /*! @brief IOCON driver version 2.0.2. */
33 #define LPC_IOCON_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
34 /*! @} */
35 
36 /**
37  * @brief Array of IOCON pin definitions passed to IOCON_SetPinMuxing() must be in this format
38  */
39 typedef struct _iocon_group
40 {
41     uint32_t ionumber : 8;  /* IO number */
42     uint32_t modefunc : 24; /* Function and mode */
43 } iocon_group_t;
44 
45 /**
46  * @brief IOCON function and mode selection definitions
47  * @note See the User Manual for specific modes and functions supported by the various pins.
48  */
49 #if defined(IOCON_PIO_MODE_SHIFT)
50 #define IOCON_MODE_INACT    (0x0 << IOCON_PIO_MODE_SHIFT) /*!< No addition pin function */
51 #define IOCON_MODE_PULLDOWN (0x1 << IOCON_PIO_MODE_SHIFT) /*!< Selects pull-down function */
52 #define IOCON_MODE_PULLUP   (0x2 << IOCON_PIO_MODE_SHIFT) /*!< Selects pull-up function */
53 #define IOCON_MODE_REPEATER (0x3 << IOCON_PIO_MODE_SHIFT) /*!< Selects pin repeater function */
54 #endif
55 #if defined(IOCON_PIO_HYS_SHIFT)
56 #define IOCON_HYS_EN (0x1 << IOCON_PIO_HYS_SHIFT) /*!< Enables hysteresis */
57 #endif
58 #if defined(IOCON_PIO_INV_SHIFT)
59 #define IOCON_INV_EN (0x1 << IOCON_PIO_INV_SHIFT) /*!< Enables invert function on input */
60 #endif
61 #if defined(IOCON_PIO_I2CMODE_SHIFT)
62 #define IOCON_STDI2C_EN (0x0 << IOCON_PIO_I2CMODE_SHIFT) /*!< I2C standard mode/fast-mode */
63 #define IOCON_STDGPIO_EN                                                                                           \
64     (0x1 << IOCON_PIO_I2CMODE_SHIFT) /*!< Standard GPIO functionality. Requires external pull-up for GPIO output \ \
65                                          function */
66 #define IOCON_FASTI2C_EN (0x2 << IOCON_PIO_I2CMODE_SHIFT) /*!< I2C Fast-mode Plus */
67 #endif
68 #if defined(IOCON_PIO_OD_SHIFT)
69 #define IOCON_OPENDRAIN_EN (0x1 << IOCON_PIO_OD_SHIFT) /*!< Enables open-drain function */
70 #endif
71 #if defined(IOCON_PIO_S_MODE_SHIFT)
72 #define IOCON_S_MODE_0CLK (0x0 << IOCON_PIO_S_MODE_SHIFT) /*!< Bypass input filter */
73 #define IOCON_S_MODE_1CLK                                                                        \
74     (0x1 << IOCON_PIO_S_MODE_SHIFT) /*!< Input pulses shorter than 1 filter clock are rejected \ \
75                                      */
76 #define IOCON_S_MODE_2CLK                                                                         \
77     (0x2 << IOCON_PIO_S_MODE_SHIFT) /*!< Input pulses shorter than 2 filter clock2 are rejected \ \
78                                      */
79 #define IOCON_S_MODE_3CLK                                                                         \
80     (0x3 << IOCON_PIO_S_MODE_SHIFT) /*!< Input pulses shorter than 3 filter clock2 are rejected \ \
81                                      */
82 #endif
83 #if defined(IOCON_PIO_CLK_DIV_SHIFT)
84 #define IOCON_CLKDIV(div) \
85     ((div)                \
86      << IOCON_PIO_CLK_DIV_SHIFT) /*!< Select peripheral clock divider for input filter sampling clock, 2^n, n=0-6 */
87 #endif
88 #if defined(IOCON_PIO_DACMODE_SHIFT)
89 #define IOCON_DAC_MODE_EN (0x1 << IOCON_PIO_DACMODE_SHIFT) /*!< DAC mode enable */
90 #endif
91 #if defined(__cplusplus)
92 extern "C" {
93 #endif
94 
95 /**
96  * @brief   Sets I/O Control pin mux
97  * @param   base        : The base of IOCON peripheral on the chip
98  * @param   ionumber    : GPIO number to mux
99  * @param   modefunc    : OR'ed values of type IOCON_*
100  * @return  Nothing
101  */
IOCON_PinMuxSet(IOCON_Type * base,uint8_t ionumber,uint32_t modefunc)102 __STATIC_INLINE void IOCON_PinMuxSet(IOCON_Type *base, uint8_t ionumber, uint32_t modefunc)
103 {
104     base->PIO[ionumber] = modefunc;
105 }
106 
107 /**
108  * @brief   Set all I/O Control pin muxing
109  * @param   base        : The base of IOCON peripheral on the chip
110  * @param   pinArray    : Pointer to array of pin mux selections
111  * @param   arrayLength : Number of entries in pinArray
112  * @return  Nothing
113  */
IOCON_SetPinMuxing(IOCON_Type * base,const iocon_group_t * pinArray,uint32_t arrayLength)114 __STATIC_INLINE void IOCON_SetPinMuxing(IOCON_Type *base, const iocon_group_t *pinArray, uint32_t arrayLength)
115 {
116     uint32_t i;
117 
118     for (i = 0; i < arrayLength; i++)
119     {
120         IOCON_PinMuxSet(base, (uint8_t)pinArray[i].ionumber, pinArray[i].modefunc);
121     }
122 }
123 
124 /*! @} */
125 
126 #if defined(__cplusplus)
127 }
128 #endif
129 
130 #endif /* FSL_IOCON_H_ */
131