1 /*
2  * @brief LPC15xx Switch Matrix driver
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2014
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 __SWM_15XX_H_
33 #define __SWM_15XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /** @defgroup SWM_15XX CHIP: LPC15xx Switch Matrix Driver
40  * @ingroup CHIP_15XX_Drivers
41  * @{
42  */
43 
44 /**
45  * @brief LPC15XX Switch Matrix register block structure
46  */
47 typedef struct {
48 	__IO uint32_t PINASSIGN[16];	/*!< Pin Assignment register array */
49 	__I  uint32_t RESERVED0[96];
50 	__IO uint32_t PINENABLE[2];		/*!< fixed pin enable/disable registers */
51 } LPC_SWM_T;
52 
53 /**
54  * @brief LPC15XX Switch Matrix Movable pins
55  */
56 typedef enum CHIP_SWM_PIN_MOVABLE  {
57 	SWM_UART0_TXD_O         = 0x00,		/*!< PINASSIGN0 - UART0 TXD Output */
58 	SWM_UART0_RXD_I         = 0x01,		/*!< PINASSIGN0 - UART0 RXD Input */
59 	SWM_UART0_RTS_O         = 0x02,		/*!< PINASSIGN0 - UART0 RTS Output */
60 	SWM_UART0_CTS_I         = 0x03,		/*!< PINASSIGN0 - UART0 CTS Input */
61 	SWM_UART0_SCLK_IO       = 0x10,		/*!< PINASSIGN1 - UART0 SCLK I/O */
62 	SWM_UART1_TXD_O         = 0x11,		/*!< PINASSIGN1 - UART1 TXD Output */
63 	SWM_UART1_RXD_I         = 0x12,		/*!< PINASSIGN1 - UART1 RXD Input */
64 	SWM_UART1_RTS_O         = 0x13,		/*!< PINASSIGN1 - UART1 RTS Output */
65 	SWM_UART1_CTS_I         = 0x20,		/*!< PINASSIGN2 - UART1 CTS Input */
66 	SWM_UART1_SCLK_IO       = 0x21,		/*!< PINASSIGN2 - UART1 SCLK I/O */
67 	SWM_UART2_TXD_O         = 0x22,		/*!< PINASSIGN2 - UART2 TXD Output */
68 	SWM_UART2_RXD_I         = 0x23,		/*!< PINASSIGN2 - UART2 RXD Input */
69 	SWM_UART2_SCLK_IO       = 0x30,		/*!< PINASSIGN3 - UART2 SCLK I/O */
70 	SWM_SSP0_SCK_IO         = 0x31,		/*!< PINASSIGN3 - SSP0 SCK I/O */
71 	SWM_SPI0_SCK_IO         = SWM_SSP0_SCK_IO,
72 	SWM_SSP0_MOSI_IO        = 0x32,		/*!< PINASSIGN3 - SSP0 MOSI I/O */
73 	SWM_SPI0_MOSI_IO        = SWM_SSP0_MOSI_IO,
74 	SWM_SSP0_MISO_IO        = 0x33,		/*!< PINASSIGN3 - SSP0 MISO I/O */
75 	SWM_SPI0_MISO_IO        = SWM_SSP0_MISO_IO,
76 	SWM_SSP0_SSELSN_0_IO    = 0x40,
77 	SWM_SPI0_SSELSN_0_IO    = SWM_SSP0_SSELSN_0_IO,
78 	SWM_SSP0_SSELSN_1_IO    = 0x41,
79 	SWM_SPI0_SSELSN_1_IO    = SWM_SSP0_SSELSN_1_IO,
80 	SWM_SSP0_SSELSN_2_IO    = 0x42,
81 	SWM_SPI0_SSELSN_2_IO    = SWM_SSP0_SSELSN_2_IO,
82 	SWM_SSP0_SSELSN_3_IO    = 0x43,
83 	SWM_SPI0_SSELSN_3_IO    = SWM_SSP0_SSELSN_3_IO,
84 	SWM_SSP1_SCK_IO         = 0x50,		/*!< PINASSIGN5 - SPI1 SCK I/O */
85 	SWM_SPI1_SCK_IO         = SWM_SSP1_SCK_IO,
86 	SWM_SSP1_MOSI_IO        = 0x51,		/*!< PINASSIGN5 - SPI1 MOSI I/O */
87 	SWM_SPI1_MOSI_IO        = SWM_SSP1_MOSI_IO,
88 	SWM_SSP1_MISO_IO        = 0x52,		/*!< PINASSIGN5 - SPI1 MISO I/O */
89 	SWM_SPI1_MISO_IO        = SWM_SSP1_MISO_IO,
90 	SWM_SSP1_SSELSN_0_IO    = 0x53,		/*!< PINASSIGN5 - SPI1 SSEL I/O */
91 	SWM_SPI1_SSELSN_0_IO    = SWM_SSP1_SSELSN_0_IO,
92 	SWM_SSP1_SSELSN_1_IO    = 0x60,
93 	SWM_SPI1_SSELSN_1_IO    = SWM_SSP1_SSELSN_1_IO,
94 	SWM_CAN_TD1_O           = 0x61,
95 	SWM_CAN_RD1_I           = 0x62,
96 	SWM_USB_VBUS_I          = 0x70,
97 	SWM_SCT0_OUT0_O         = 0x71,
98 	SWM_SCT0_OUT1_O         = 0x72,
99 	SWM_SCT0_OUT2_O         = 0x73,
100 	SWM_SCT1_OUT0_O         = 0x80,
101 	SWM_SCT1_OUT1_O         = 0x81,
102 	SWM_SCT1_OUT2_O         = 0x82,
103 	SWM_SCT2_OUT0_O         = 0x83,
104 	SWM_SCT2_OUT1_O         = 0x90,
105 	SWM_SCT2_OUT2_O         = 0x91,
106 	SWM_SCT3_OUT0_O         = 0x92,
107 	SWM_SCT3_OUT1_O         = 0x93,
108 	SWM_SCT3_OUT2_O         = 0xA0,
109 	SWM_SCT_ABORT0_I        = 0xA1,
110 	SWM_SCT_ABORT1_I        = 0xA2,
111 	SWM_ADC0_PIN_TRIG0_I    = 0xA3,
112 	SWM_ADC0_PIN_TRIG1_I    = 0xB0,
113 	SWM_ADC1_PIN_TRIG0_I    = 0xB1,
114 	SWM_ADC1_PIN_TRIG1_I    = 0xB2,
115 	SWM_DAC_PIN_TRIG_I      = 0xB3,
116 	SWM_DAC_SHUTOFF_I       = 0xC0,
117 	SWM_ACMP0_OUT_O         = 0xC1,
118 	SWM_ACMP1_OUT_O         = 0xC2,
119 	SWM_ACMP2_OUT_O         = 0xC3,
120 	SWM_ACMP3_OUT_O         = 0xD0,
121 	SWM_CLK_OUT_O           = 0xD1,
122 	SWM_ROSC0_O             = 0xD2,
123 	SWM_ROSC_RST0_I         = 0xD3,
124 	SWM_USB_FRAME_TOG_O     = 0xE0,
125 	SWM_QEI0_PHA_I          = 0xE1,
126 	SWM_QEI0_PHB_I          = 0xE2,
127 	SWM_QEI0_IDX_I          = 0xE3,
128 	SWM_GPIO_INT_BMATCH_O   = 0xF0,
129 	SWM_SWO_O               = 0xF1,
130 } CHIP_SWM_PIN_MOVABLE_T;
131 
132 /**
133  * @brief LPC15XX Switch Matrix Fixed pins
134  */
135 typedef enum CHIP_SWM_PIN_FIXED    {
136 	SWM_FIXED_ADC0_0    = 0x00,	/*!< ADC0_0 fixed pin enable/disable on pin P0_8 */
137 	SWM_FIXED_ADC0_1    = 0x01,	/*!< ADC0_1 fixed pin enable/disable on pin P0_7 */
138 	SWM_FIXED_ADC0_2    = 0x02,	/*!< ADC0_2 fixed pin enable/disable on pin P0_6 */
139 	SWM_FIXED_ADC0_3    = 0x03,	/*!< ADC0_3 fixed pin enable/disable on pin P0_5 */
140 	SWM_FIXED_ADC0_4    = 0x04,	/*!< ADC0_4 fixed pin enable/disable on pin P0_4 */
141 	SWM_FIXED_ADC0_5    = 0x05,	/*!< ADC0_5 fixed pin enable/disable on pin P0_3 */
142 	SWM_FIXED_ADC0_6    = 0x06,	/*!< ADC0_6 fixed pin enable/disable on pin P0_2 */
143 	SWM_FIXED_ADC0_7    = 0x07,	/*!< ADC0_7 fixed pin enable/disable on pin P0_1 */
144 	SWM_FIXED_ADC0_8    = 0x08,	/*!< ADC0_8 fixed pin enable/disable on pin P1_0 */
145 	SWM_FIXED_ADC0_9    = 0x09,	/*!< ADC0_9 fixed pin enable/disable on pin P0_31 */
146 	SWM_FIXED_ADC0_10   = 0x0A,	/*!< ADC0_10 fixed pin enable/disable on pin P0_0 */
147 	SWM_FIXED_ADC0_11   = 0x0B,	/*!< ADC0_11 fixed pin enable/disable on pin P0_30 */
148 	SWM_FIXED_ADC1_0    = 0x0C,	/*!< ADC1_0 fixed pin enable/disable/disable on pin P1_1 */
149 	SWM_FIXED_ADC1_1    = 0x0D,	/*!< ADC1_1 fixed pin enable/disable on pin P0_9 */
150 	SWM_FIXED_ADC1_2    = 0x0E,	/*!< ADC1_2 fixed pin enable/disable on pin P0_10 */
151 	SWM_FIXED_ADC1_3    = 0x0F,	/*!< ADC1_3 fixed pin enable/disable on pin P0_11 */
152 	SWM_FIXED_ADC1_4    = 0x10,	/*!< ADC1_4 fixed pin enable/disable on pin P1_2 */
153 	SWM_FIXED_ADC1_5    = 0x11,	/*!< ADC1_5 fixed pin enable/disable on pin P1_3 */
154 	SWM_FIXED_ADC1_6    = 0x12,	/*!< ADC1_6 fixed pin enable/disable on pin P0_13 */
155 	SWM_FIXED_ADC1_7    = 0x13,	/*!< ADC1_7 fixed pin enable/disable on pin P0_14 */
156 	SWM_FIXED_ADC1_8    = 0x14,	/*!< ADC1_8 fixed pin enable/disable on pin P0_15 */
157 	SWM_FIXED_ADC1_9    = 0x15,	/*!< ADC1_9 fixed pin enable/disable on pin P0_16 */
158 	SWM_FIXED_ADC1_10   = 0x16,	/*!< ADC1_10 fixed pin enable/disable on pin P1_4 */
159 	SWM_FIXED_ADC1_11   = 0x17,	/*!< ADC1_11 fixed pin enable/disable on pin P1_5 */
160 	SWM_FIXED_DAC_OUT   = 0x18,	/*!< DAC_OUT fixed pin enable/disable on pin P0_12 */
161 	SWM_FIXED_ACMP_I1   = 0x19,	/*!< ACMP input 1 (common input) fixed pin enable/disable on pin P0_27 */
162 	SWM_FIXED_ACMP_I2   = 0x1A,	/*!< ACMP input 1 (common input) fixed pin enable/disable on pin P1_6 */
163 	SWM_FIXED_ACMP0_I3  = 0x1B,	/*!< ACMP comparator 0 input 3 fixed pin enable/disable on pin P0_26 */
164 	SWM_FIXED_ACMP0_I4  = 0x1C,	/*!< ACMP comparator 0 input 4 fixed pin enable/disable on pin P0_25 */
165 	SWM_FIXED_ACMP1_I3  = 0x1D,	/*!< ACMP comparator 1 input 3 fixed pin enable/disable on pin P0_28 */
166 	SWM_FIXED_ACMP1_I4  = 0x1E,	/*!< ACMP comparator 1 input 4 fixed pin enable/disable on pin P1_10 */
167 	SWM_FIXED_ACMP2_I3  = 0x1F,	/*!< ACMP comparator 2 input 3 fixed pin enable/disable on pin P0_29 */
168 	SWM_FIXED_ACMP2_I4  = 0x80,	/*!< ACMP comparator 2 input 4 fixed pin enable/disable on pin P1_9 */
169 	SWM_FIXED_ACMP3_I3  = 0x81,	/*!< ACMP comparator 3 input 3 fixed pin enable/disable on pin P1_8 */
170 	SWM_FIXED_ACMP3_I4  = 0x82,	/*!< ACMP comparator 3 input 4 fixed pin enable/disable on pin P1_7 */
171 	SWM_FIXED_I2C0_SDA  = 0x83,	/*!< I2C0_SDA fixed pin enable/disable on pin P0_23 */
172 	SWM_FIXED_I2C0_SCL  = 0x84,	/*!< I2C0_SCL fixed pin enable/disable on pin P0_22 */
173 	SWM_FIXED_SCT0_OUT3 = 0x85,	/*!< SCT0_OUT3 fixed pin enable/disable on pin P0_0 */
174 	SWM_FIXED_SCT0_OUT4 = 0x86,	/*!< SCT0_OUT4 fixed pin enable/disable on pin P0_1 */
175 	SWM_FIXED_SCT0_OUT5 = 0x87,	/*!< SCT0_OUT5 fixed pin enable/disable on pin P0_18 */
176 	SWM_FIXED_SCT0_OUT6 = 0x88,	/*!< SCT0_OUT6 fixed pin enable/disable on pin P0_24 */
177 	SWM_FIXED_SCT0_OUT7 = 0x89,	/*!< SCT0_OUT7 fixed pin enable/disable on pin P1_14 */
178 	SWM_FIXED_SCT1_OUT3 = 0x8A,	/*!< SCT1_OUT3 fixed pin enable/disable on pin P0_2 */
179 	SWM_FIXED_SCT1_OUT4 = 0x8B,	/*!< SCT1_OUT4 fixed pin enable/disable on pin P0_3 */
180 	SWM_FIXED_SCT1_OUT5 = 0x8C,	/*!< SCT1_OUT5 fixed pin enable/disable on pin P0_14 */
181 	SWM_FIXED_SCT1_OUT6 = 0x8D,	/*!< SCT1_OUT6 fixed pin enable/disable on pin P0_20 */
182 	SWM_FIXED_SCT1_OUT7 = 0x8E,	/*!< SCT1_OUT7 fixed pin enable/disable on pin P1_17 */
183 	SWM_FIXED_SCT2_OUT3 = 0x8F,	/*!< SCT2_OUT3 fixed pin enable/disable on pin P0_6 */
184 	SWM_FIXED_SCT2_OUT4 = 0x90,	/*!< SCT2_OUT4 fixed pin enable/disable on pin P0_29 */
185 	SWM_FIXED_SCT2_OUT5 = 0x91,	/*!< SCT2_OUT5 fixed pin enable/disable on pin P1_20 */
186 	SWM_FIXED_SCT3_OUT3 = 0x92,	/*!< SCT3_OUT3 fixed pin enable/disable on pin P0_26 */
187 	SWM_FIXED_SCT3_OUT4 = 0x93,	/*!< SCT3_OUT4 fixed pin enable/disable on pin P1_8 */
188 	SWM_FIXED_SCT3_OUT5 = 0x94,	/*!< SCT3_OUT5 fixed pin enable/disable on pin P1_24 */
189 	SWM_FIXED_RESETN    = 0x95,	/*!< RESETN fixed pin enable/disable on pin P0_21 */
190 	SWM_FIXED_SWCLK_TCK = 0x96,	/*!< SWCLK_TCK fixed pin enable/disable on pin P0_19 */
191 	SWM_FIXED_SWDIO     = 0x97,	/*!< SWDIO fixed pin enable/disable on pin P0_20 */
192 } CHIP_SWM_PIN_FIXED_T;
193 
194 /**
195  * @brief	Initialize the SWM module
196  * @return	Nothing
197  * @note	This function only enables the SWM clock.
198  */
Chip_SWM_Init(void)199 STATIC INLINE void Chip_SWM_Init(void)
200 {
201 	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
202 }
203 
204 /**
205  * @brief	Deinitialise the SWM module
206  * @return	Nothing
207  * @note	This function only disables the SWM clock.
208  */
Chip_SWM_Deinit(void)209 STATIC INLINE void Chip_SWM_Deinit(void)
210 {
211 	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
212 }
213 
214 /**
215  * @brief	Assign movable pin function to physical pin in Switch Matrix
216  * @param	movable	: Movable pin function
217  * @param	assign	: Physical pin to be assigned
218  * @return	Nothing
219  */
220 void Chip_SWM_MovablePinAssign(CHIP_SWM_PIN_MOVABLE_T movable, uint8_t assign);
221 
222 /**
223  * @brief	Assign movable pin function to port and pin in the Switch Matrix
224  * @param	movable	: Movable pin function
225  * @param	port	: Port number
226  * @param	pin		: Pin number
227  * @return	Nothing
228  * @note	This function does the same thing as Chip_SWM_MovablePinAssign()
229  *			except works with a port and pin number instead of a physical
230  *			pin number.
231  */
Chip_SWM_MovablePortPinAssign(CHIP_SWM_PIN_MOVABLE_T movable,uint8_t port,uint8_t pin)232 STATIC INLINE void Chip_SWM_MovablePortPinAssign(CHIP_SWM_PIN_MOVABLE_T movable, uint8_t port, uint8_t pin)
233 {
234 	Chip_SWM_MovablePinAssign(movable, ((port * 32) + pin));
235 }
236 
237 /**
238  * @brief	Enables a fixed function pin in the Switch Matrix
239  * @param	pin	: Pin to be enabled
240  * @return	Nothing
241  */
242 void Chip_SWM_EnableFixedPin(CHIP_SWM_PIN_FIXED_T pin);
243 
244 /**
245  * @brief	Disables a fixed function pin in the Switch Matrix
246  * @param	pin	: Pin to be disabled
247  * @return	Nothing
248  */
249 void Chip_SWM_DisableFixedPin(CHIP_SWM_PIN_FIXED_T pin);
250 
251 /**
252  * @brief	Enables or disables a fixed function pin in the Switch Matrix
253  * @param	pin		: Pin to be enabled or disabled
254  * @param	enable	: True to enable the pin, False to disable the pin
255  * @return	Nothing
256  */
257 void Chip_SWM_FixedPinEnable(CHIP_SWM_PIN_FIXED_T pin, bool enable);
258 
259 /**
260  * @brief	Tests whether a fixed function pin is enabled or disabled in the Switch Matrix
261  * @param	pin	: The pin to test whether it is enabled or disabled
262  * @return	True if the pin is enabled, False if disabled
263  */
264 bool Chip_SWM_IsFixedPinEnabled(CHIP_SWM_PIN_FIXED_T pin);
265 
266 /**
267  * @}
268  */
269 
270 #ifdef __cplusplus
271 }
272 #endif
273 
274 #endif /* __SWM_15XX_H_ */
275