1 /**
2   ******************************************************************************
3   * @file    rtl8721d_pinmux.h
4   * @author
5   * @version V1.0.0
6   * @date    2016-05-17
7   * @brief   This file contains all the functions prototypes for the pinmux firmware
8   *          library.
9   ******************************************************************************
10   * @attention
11   *
12   * This module is a confidential and proprietary property of RealTek and
13   * possession or use of this module requires written permission of RealTek.
14   *
15   * Copyright(c) 2016, Realtek Semiconductor Corporation. All rights reserved.
16   ******************************************************************************
17   */
18 
19 #ifndef _HAL_8721D_PINMUX_
20 #define _HAL_8721D_PINMUX_
21 
22 /** @addtogroup AmebaD_Platform
23   * @{
24   */
25 
26 /** @defgroup PIN
27   * @brief PIN driver modules
28   * @{
29   */
30 
31 /** @defgroup PINMUX
32   * @brief PINMUX modules
33   * @{
34   */
35 
36 /** @addtogroup PINMUX
37   * @verbatim
38   *****************************************************************************************
39   * Introduction
40   *****************************************************************************************
41   *		-Every GPIO pin can be set to some function based on pinmux spec.
42   *		-Every GPIO pin can set internal pull-up, pull-down based on pinmux spec.
43   *
44   *====================================================================
45   * pad control Spec.
46   *====================================================================
47   *		-[31:16]		reserved
48   *		-[15]			pad shut down enable
49   *		-[14]			H3L1 for SDIO pad, other pad reserved
50   *		-[13]			pull resistor selection
51   *		-[12]			schmitt trigger enable
52   *		-[11:10]		pad driving strength
53   *		-[9]			pull down resistor enable
54   *		-[8]			pull up resistor enable
55   *		-[7:5]			reserved for function id extend
56   *		-[4:0]			function id
57   *
58   *****************************************************************************************
59   * How to use Pinmux
60   *****************************************************************************************
61   *		1. Set the Internal pad function type for  each pin using the follwoing function:
62   *			Pinmux_Config(u8 PinName, u32 PinFunc)
63   *
64   *		2. Set the Internal pad pull type for each pin using the follwoing function:
65   *			PAD_PullCtrl(u8 PinName, u8 PullType)
66   *
67   *****************************************************************************************
68   * @endverbatim
69   */
70 
71 /* Exported constants --------------------------------------------------------*/
72 
73 /** @defgroup PINMUX_Exported_Constants PINMUX Exported Constants
74   * @{
75   */
76 
77 /** @defgroup PINMUX_Pin_Name_definitions
78   * @note: Pin_Name = (((port)<<5)|(pin))
79   * @{
80   */
81 #define _PA_0		(0x00)	//0x400
82 #define _PA_1		(0x01)	//0x404
83 #define _PA_2		(0x02)	//0x408
84 #define _PA_3		(0x03)	//0x40C
85 #define _PA_4		(0x04)	//0x410
86 #define _PA_5		(0x05)	//0x414
87 #define _PA_6		(0x06)	//0x418
88 #define _PA_7		(0x07)	//0x41C
89 #define _PA_8		(0x08)	//0x420
90 #define _PA_9		(0x09)	//0x424
91 #define _PA_10		(0x0A)	//0x428
92 #define _PA_11		(0x0B)	//0x42C
93 #define _PA_12		(0x0C)	//0x430
94 #define _PA_13		(0x0D)	//0x434
95 #define _PA_14		(0x0E)	//0x438
96 #define _PA_15		(0x0F)	//0x43C
97 #define _PA_16		(0x10)	//0x440
98 #define _PA_17		(0x11)	//0x444
99 #define _PA_18		(0x12)	//0x448
100 #define _PA_19		(0x13)	//0x44C
101 #define _PA_20		(0x14)	//0x450
102 #define _PA_21		(0x15)	//0x454
103 #define _PA_22		(0x16)	//0x458
104 #define _PA_23		(0x17)	//0x45C
105 #define _PA_24		(0x18)	//0x460
106 #define _PA_25		(0x19)	//0x464
107 #define _PA_26		(0x1A)	//0x468
108 #define _PA_27		(0x1B)	//0x46C
109 #define _PA_28		(0x1C)	//0x470
110 #define _PA_29		(0x1D)	//0x474
111 #define _PA_30		(0x1E)	//0x478
112 #define _PA_31		(0x1F)	//0x47C
113 
114 #define _PB_0		(0x20)	//0x480
115 #define _PB_1		(0x21)	//0x484
116 #define _PB_2		(0x22)	//0x488
117 #define _PB_3		(0x23)	//0x48C
118 #define _PB_4		(0x24)	//0x490
119 #define _PB_5		(0x25)	//0x494
120 #define _PB_6		(0x26)	//0x498
121 #define _PB_7		(0x27)	//0x49C
122 #define _PB_8		(0x28)	//0x4A0
123 #define _PB_9		(0x29)	//0x4A4
124 #define _PB_10		(0x2A)	//0x4A8
125 #define _PB_11		(0x2B)	//0x4AC
126 #define _PB_12		(0x2C)	//0x4B0
127 #define _PB_13		(0x2D)	//0x4B4
128 #define _PB_14		(0x2E)	//0x4B8
129 #define _PB_15		(0x2F)	//0x4Bc
130 #define _PB_16		(0x30)	//0x4C0
131 #define _PB_17		(0x31)	//0x4C4
132 #define _PB_18		(0x32)	//0x4C8
133 #define _PB_19		(0x33)	//0x4CC
134 #define _PB_20		(0x34)	//0x4D0
135 #define _PB_21		(0x35)	//0x4D4
136 #define _PB_22		(0x36)	//0x4D8
137 #define _PB_23		(0x37)	//0x4DC
138 #define _PB_24		(0x38)	//0x4E0
139 #define _PB_25		(0x39)	//0x4E4
140 #define _PB_26		(0x3A)	//0x4E8
141 #define _PB_27		(0x3B)	//0x4EC
142 #define _PB_28		(0x3C)	//0x4F0
143 #define _PB_29		(0x3D)	//0x4F4
144 #define _PB_30		(0x3E)	//0x4F8
145 #define _PB_31		(0x3F)	//0x4FC
146 
147 #define _PNC		(0xFFFFFFFF)
148 /**
149   * @}
150   */
151 
152 /** @defgroup PINMUX_Port_And_Pin_definitions
153   * @{
154   */
155 #define PORT_NUM(pin)	((pin>>5) & 0x03)
156 #define PIN_NUM(pin)		(pin & 0x1f)
157 /**
158   * @}
159   */
160 
161 /** @defgroup PINMUX_PAD_Control_definitions
162   * @{
163   */
164 #define PAD_BIT_SHUT_DWON					BIT(15)
165 #define PAD_BIT_SDIO_H3L1					BIT(14)
166 #define PAD_BIT_PULL_RESISTOR_SEL			BIT(13)
167 #define PAD_BIT_SCHMITT_TRIGGER_EN		BIT(12)
168 #define PAD_BIT_PULL_RESISTOR_SMALL		BIT(11) /* for PAD C/F/G */
169 #define PAD_BIT_SHIFT_DRIVING_STRENGTH	10
170 #define PAD_BIT_MASK_DRIVING_STRENGTH	0x03
171 #define PAD_BIT_PULL_DOWN_RESISTOR_EN	BIT(9)
172 #define PAD_BIT_PULL_UP_RESISTOR_EN		BIT(8)
173 #define PAD_BIT_SHIFT_FUNCTION_ID			0
174 #define PAD_BIT_MASK_FUNCTION_ID			0x1F
175 /**
176   * @}
177   */
178 
179 /** @defgroup GPIO_Pull_Resistor_definitions
180   * @{
181   */
182 #define GPIO_Resistor_LARGE		0x00 /*!< GPIO Resistor LARGE */
183 #define GPIO_Resistor_SMALL		0x01 /*!< GPIO Resistor SMALL */
184 /**
185   * @}
186   */
187 
188 /** @defgroup PINMUX_Function_definitions
189   * @{
190   */
191 #define PINMUX_FUNCTION_GPIO				(0)
192 #define PINMUX_FUNCTION_UART				(1)
193 
194 #define PINMUX_FUNCTION_UART_RTSCTS		(2)
195 #define PINMUX_FUNCTION_LOGUART			(2)
196 
197 #define PINMUX_FUNCTION_SPIM				(3)
198 #define PINMUX_FUNCTION_SPIS				(3)
199 
200 #define PINMUX_FUNCTION_RTC				(4)
201 #define PINMUX_FUNCTION_TIMINPUT			(4)
202 #define PINMUX_FUNCTION_EXT32K			(28)
203 #define PINMUX_FUNCTION_RTCOUT			(28)
204 #define PINMUX_FUNCTION_TIMINPUT_HS		(22)
205 
206 #define PINMUX_FUNCTION_IR					(5)
207 #define PINMUX_FUNCTION_SPIF				(6)
208 #define PINMUX_FUNCTION_I2C				(7)
209 
210 #define PINMUX_FUNCTION_SDIOD				(8)
211 #define PINMUX_FUNCTION_SDIOH				(8)
212 
213 #define PINMUX_FUNCTION_PWM				(9)
214 #define PINMUX_FUNCTION_PWM_HS			(9)
215 #define PINMUX_FUNCTION_PWM_LP			(10)
216 #define PINMUX_FUNCTION_SWD				(11)
217 
218 #define PINMUX_FUNCTION_I2S				(12)
219 #define PINMUX_FUNCTION_DMIC				(12)
220 
221 #define PINMUX_FUNCTION_KEYSCAN_ROW		(29)
222 #define PINMUX_FUNCTION_KEYSCAN_COL		(30)
223 #define PINMUX_FUNCTION_LCD				(13)
224 #define PINMUX_FUNCTION_USB				(14)
225 #define PINMUX_FUNCTION_QDEC				(15)
226 #define PINMUX_FUNCTION_SGPIO				(16)
227 #define PINMUX_FUNCTION_RFE				(18)
228 #define PINMUX_FUNCTION_BTCOEX			(19)
229 
230 #define PINMUX_FUNCTION_WIFIFW			(20)
231 #define PINMUX_FUNCTION_EXT_PCM			(20)
232 #define PINMUX_FUNCTION_BB_PIN			(21)
233 #define PINMUX_FUNCTION_SIC				(22)
234 #define PINMUX_FUNCTION_WAKEUP			(31)
235 #define PINMUX_FUNCTION_DBGPORT			(23)
236 #define PINMUX_FUNCTION_BBDBG				(25)
237 
238 /**
239   * @}
240   */
241 
242 /** @defgroup PINMUX_Peripheral_Location_definitions
243   * @note just used by function PINMUX_Ctrl
244   * @{
245   */
246 #define PINMUX_S0		(0)
247 #define PINMUX_S1		(1)
248 #define PINMUX_S2		(2)
249 #define PINMUX_S3		(3)
250 /**
251   * @}
252   */
253 
254 /** @defgroup PINMUX_PAD_DrvStrength_definitions
255   * @{
256   */
257 #define PAD_DRV_STRENGTH_0			(0x00000000 << 9)
258 #define PAD_DRV_STRENGTH_1			(0x00000001 << 9)
259 #define PAD_DRV_STRENGTH_2			(0x00000002 << 9)
260 #define PAD_DRV_STRENGTH_3			(0x00000003 << 9)
261 #define PAD_DRV_STRENGTH_4			(0x00000004 << 9)
262 #define PAD_DRV_STRENGTH_5			(0x00000005 << 9)
263 #define PAD_DRV_STRENGTH_6			(0x00000006 << 9)
264 #define PAD_DRV_STRENGTH_7			(0x00000007 << 9)
265 /**
266   * @}
267   */
268 
269 /**
270   * @}
271   */
272 
273 /** @defgroup PINMUX_Exported_Functions PINMUX Exported Functions
274   * @{
275   */
276 _LONG_CALL_ void PAD_CMD(u8 PinName, u8 NewStatus);
277 _LONG_CALL_ void PAD_DrvStrength(u8 PinName, u32 DrvStrength);
278 _LONG_CALL_ void PAD_PullCtrl(u8 PinName, u8 PullType);
279 _LONG_CALL_ void Pinmux_Config(u8 PinName, u32 PinFunc);
280 _LONG_CALL_ u32 Pinmux_ConfigGet(u8 PinName);
281 _LONG_CALL_ void Pinmux_UartLogCtrl(u32  PinLocation, BOOL   Operation);
282 _LONG_CALL_ void Pinmux_SpicCtrl(u32  PinLocation, BOOL Operation);
283 /**
284   *  @brief Set the Internal pad Resistor type.
285   *  @param PinName : value of @ref PINMUX_Pin_Name_definitions.
286   *  @param PullType : the pull type for the pin.This parameter can be one of the following values:
287   *		 @arg GPIO_Resistor_LARGE
288   *		 @arg GPIO_Resistor_SMALL
289   *  @retval None
290   *  @note Just for PAD C/F/G:
291   *  @note PA[12]/PA[13]/PA[14]/PA[15]/PA[16]/PA[17]/PA[18]/PA[19]/PA[20]/PA[21]/PA[25]/PA[26] 4.7K/50K
292   *  @note PA[29]/PA[30]/PA[31] 4.7K/10K
293   */
PAD_ResistorCtrl(u8 PinName,u8 RType)294 static inline void PAD_ResistorCtrl(u8 PinName, u8 RType)
295 {
296 	u32 Temp = 0;
297 
298 	/* get PADCTR */
299 	Temp = PINMUX->PADCTR[PinName];
300 
301 	/* set resistor small */
302 	Temp |= PAD_BIT_PULL_RESISTOR_SMALL; /* by default is small */
303 
304 	/* set large if needed */
305 	if (RType == GPIO_Resistor_LARGE) {
306 		Temp &= ~PAD_BIT_PULL_RESISTOR_SMALL;
307 	}
308 
309 	/* set PADCTR register */
310 	PINMUX->PADCTR[PinName] = Temp;
311 }
312 
313 
314 /**
315   *  @brief Turn off pinmux SWD function.
316   *  @retval None
317   */
Pinmux_Swdoff(void)318 static inline void Pinmux_Swdoff(void)
319 {
320 	u32 Temp = 0;
321 
322 	Temp = HAL_READ32(SYSTEM_CTRL_BASE_LP, REG_SWD_PMUX_EN);
323 	Temp &= (~BIT_LSYS_SWD_PMUX_EN);
324 	HAL_WRITE32(SYSTEM_CTRL_BASE_LP, REG_SWD_PMUX_EN, Temp);
325 }
326 
327 
328 /**
329   * @}
330   */
331 
332 /**
333   * @}
334   */
335 
336 /**
337   * @}
338   */
339 
340 /* Other definations --------------------------------------------------------*/
341 #define FLASH_S0_CS_GPIO		_PB_18
342 #define FLASH_S1_CS_GPIO		_PB_16
343 
344 
345 
346 #endif   //_HAL_8721D_PINMUX_
347 /******************* (C) COPYRIGHT 2016 Realtek Semiconductor *****END OF FILE****/
348 
349