1 /*
2  * @brief LPC15xx IOCON driver
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2013
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products.  This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __IOCON_15XX_H_
33 #define __IOCON_15XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /** @defgroup IOCON_15XX CHIP: LPC15xx IO Control driver
40  * @ingroup CHIP_15XX_Drivers
41  * @{
42  */
43 
44 /**
45  * @brief LPC15XX IO Configuration Unit register block structure
46  */
47 typedef struct {			/*!< LPC15XX IOCON Structure */
48 	__IO uint32_t  PIO[3][32];
49 } LPC_IOCON_T;
50 
51 /**
52  * @brief Array of IOCON pin definitions passed to Chip_IOCON_SetPinMuxing() must be in this format
53  */
54 typedef struct {
55 	uint32_t port : 8;			/* Pin port */
56 	uint32_t pin : 8;			/* Pin number */
57 	uint32_t modefunc : 16;		/* Function and mode */
58 } PINMUX_GRP_T;
59 
60 /**
61  * IOCON function and mode selection definitions
62  * See the User Manual for specific modes and functions supported by the
63  * various LPC15XX pins.
64  */
65 #define IOCON_FUNC0             0x0				/*!< Selects pin function 0 */
66 #define IOCON_FUNC1             0x1				/*!< Selects pin function 1 */
67 #define IOCON_FUNC2             0x2				/*!< Selects pin function 2 */
68 #define IOCON_MODE_INACT        (0x0 << 3)		/*!< No addition pin function */
69 #define IOCON_MODE_PULLDOWN     (0x1 << 3)		/*!< Selects pull-down function */
70 #define IOCON_MODE_PULLUP       (0x2 << 3)		/*!< Selects pull-up function */
71 #define IOCON_MODE_REPEATER     (0x3 << 3)		/*!< Selects pin repeater function */
72 #define IOCON_HYS_EN            (0x1 << 5)		/*!< Enables hysteresis */
73 #define IOCON_INV_EN            (0x1 << 6)		/*!< Enables invert function on input */
74 #define IOCON_ADMODE_EN         (0x0 << 7)		/*!< Enables analog input function (analog pins only) */
75 #define IOCON_DIGMODE_EN        (0x1 << 7)		/*!< Enables digital function (analog pins only) */
76 #define IOCON_SFI2C_EN          (0x0 << 8)		/*!< I2C standard mode/fast-mode */
77 #define IOCON_STDI2C_EN         (0x1 << 8)		/*!< I2C standard I/O functionality */
78 #define IOCON_FASTI2C_EN        (0x2 << 8)		/*!< I2C Fast-mode Plus */
79 #define IOCON_OPENDRAIN_EN      (0x1 << 10)		/*!< Enables open-drain function */
80 #define IOCON_S_MODE_0CLK       (0x0 << 11)		/*!< Bypass input filter */
81 #define IOCON_S_MODE_1CLK       (0x1 << 11)		/*!< Input pulses shorter than 1 filter clock are rejected */
82 #define IOCON_S_MODE_2CLK       (0x2 << 11)		/*!< Input pulses shorter than 2 filter clock2 are rejected */
83 #define IOCON_S_MODE_3CLK       (0x3 << 11)		/*!< Input pulses shorter than 3 filter clock2 are rejected */
84 #define IOCON_S_MODE(clks)      ((clks) << 11)	/*!< Select clocks for digital input filter mode */
85 #define IOCON_CLKDIV(div)       ((div) << 13)	/*!< Select peripheral clock divider for input filter sampling clock, 2^n, n=0-6 */
86 
87 /**
88  * @brief	Sets I/O Control pin mux
89  * @param	pIOCON		: The base of IOCON peripheral on the chip
90  * @param	port		: GPIO port to mux
91  * @param	pin			: GPIO pin to mux
92  * @param	modefunc	: OR'ed values or type IOCON_*
93  * @return	Nothing
94  */
Chip_IOCON_PinMuxSet(LPC_IOCON_T * pIOCON,uint8_t port,uint8_t pin,uint32_t modefunc)95 STATIC INLINE void Chip_IOCON_PinMuxSet(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint32_t modefunc)
96 {
97 	pIOCON->PIO[port][pin] = modefunc;
98 }
99 
100 /**
101  * @brief	I/O Control pin mux
102  * @param	pIOCON	: The base of IOCON peripheral on the chip
103  * @param	port	: GPIO port to mux
104  * @param	pin		: GPIO pin to mux
105  * @param	mode	: OR'ed values or type IOCON_*
106  * @param	func	: Pin function, value of type IOCON_FUNC?
107  * @return	Nothing
108  */
Chip_IOCON_PinMux(LPC_IOCON_T * pIOCON,uint8_t port,uint8_t pin,uint16_t mode,uint8_t func)109 STATIC INLINE void Chip_IOCON_PinMux(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint16_t mode, uint8_t func)
110 {
111 	Chip_IOCON_PinMuxSet(pIOCON, port, pin, (uint32_t) (mode | func));
112 }
113 
114 /**
115  * @brief	Set all I/O Control pin muxing
116  * @param	pIOCON	    : The base of IOCON peripheral on the chip
117  * @param	pinArray    : Pointer to array of pin mux selections
118  * @param	arrayLength : Number of entries in pinArray
119  * @return	Nothing
120  */
121 void Chip_IOCON_SetPinMuxing(LPC_IOCON_T *pIOCON, const PINMUX_GRP_T *pinArray, uint32_t arrayLength);
122 
123 /**
124  * @}
125  */
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif /* __IOCON_15XX_H_ */
132