1 /**
2 ******************************************************************************
3 * @file rtl8721dlp_pinmap.c
4 * @author
5 * @version V1.0.0
6 * @date 2016-05-17
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of pin control:
9 * - pinmux
10 * - active pad pull up & pull down
11 * - sleep pad pull up & pull down
12 ******************************************************************************
13 * @attention
14 *
15 * This module is a confidential and proprietary property of RealTek and
16 * possession or use of this module requires written permission of RealTek.
17 *
18 * Copyright(c) 2015, Realtek Semiconductor Corporation. All rights reserved.
19 ******************************************************************************
20 */
21
22 #include "ameba_soc.h"
23
24 extern const PMAP_TypeDef pmap_func[];
25 extern const PMAP_TypeDef pmap_func_sleep[];
26
27 CONFIG_FW_CRITICAL_CODE_SECTION
pinmap_touchpin(u32 PinName)28 static u32 pinmap_touchpin(u32 PinName)
29 {
30 if ((PinName == _PB_4) || (PinName == _PB_5) ||
31 (PinName == _PB_6) || (PinName == _PB_7)) {
32 return TRUE;
33 }
34
35 return FALSE;
36 }
37
38 /**
39 * @brief Config all pins to the right function and pull state based on pmap_func table.
40 * @note should set pmap_func. Function & FuncPuPd corectly based on your board.
41 * @retval None
42 */
43 CONFIG_FW_CRITICAL_CODE_SECTION
pinmap_init(void)44 void pinmap_init(void)
45 {
46 int i = 0;
47 u32 dslp_wakeup = SOCPS_DsleepWakeStatusGet();
48
49 for (;;) {
50 /* Check if search to end */
51 if (pmap_func[i].PinName == _PNC) {
52 break;
53 }
54
55 /* keep active level when GPIO_PuPd_KEEP */
56 if (pmap_func[i].FuncPuPd == GPIO_PuPd_KEEP)
57 goto next;
58
59 if (dslp_wakeup) {
60 /* low power pin, dont pull low power pins ex. keyscan */
61 if (pmap_func[i].LowPowerPin)
62 goto next;
63
64 /* touch pin, dont pull captouch enabled pin */
65 if (pinmap_touchpin(pmap_func[i].PinName) == TRUE) {
66 if (CapTouch_GetChStatus(CAPTOUCH_DEV, (pmap_func[i].PinName - _PB_4))) {
67 goto next;
68 }
69 }
70 }
71
72 /* active PuPd set */
73 if (pmap_func[i].FuncPuPd == GPIO_PuPd_SHUTDOWN) {
74 PAD_CMD(pmap_func[i].PinName, DISABLE);
75 } else {
76 PAD_PullCtrl(pmap_func[i].PinName, pmap_func[i].FuncPuPd);
77 }
78
79 next:
80 i++;
81 }
82 }
83
84 /**
85 * @brief Config all pins to the right pull state based on pmap_func table before soc sleep.
86 * @note should set pmap_func.SleepPuPd corectly based on your board.
87 * @retval None
88 */
89 CONFIG_FW_CRITICAL_CODE_SECTION
pinmap_sleep(void)90 void pinmap_sleep(void)
91 {
92 int i = 0;
93 int PinName = 0;
94
95 for (;;) {
96 /* Check if search to end */
97 if (pmap_func_sleep[i].PinName == _PNC) {
98 break;
99 }
100
101 /* keep active level when GPIO_PuPd_KEEP */
102 if (pmap_func_sleep[i].SleepPuPd == GPIO_PuPd_KEEP)
103 goto next;
104 PinName = pmap_func_sleep[i].PinName;
105
106 /* sleep PuPd set */
107 if (pmap_func_sleep[i].SleepPuPd == GPIO_PuPd_SHUTDOWN) {
108 PAD_CMD(PinName, DISABLE);
109 } else {
110 PAD_CMD(PinName, ENABLE);
111 PAD_PullCtrl(PinName, pmap_func_sleep[i].SleepPuPd);
112 //DBG_8195A("%08x: %08x\n", &(PINMUX->PADCTR[pmap_func[i].PinName]), (PINMUX->PADCTR[pmap_func[i].PinName]));
113 }
114
115 next:
116 i++;
117 }
118 }
119
120 /**
121 * @brief Config all pins to the right pull state based on pmap_func table before soc deep sleep.
122 * @note should set pmap_func.DSleepPuPd corectly based on your board.
123 * @retval None
124 */
125 CONFIG_FW_CRITICAL_CODE_SECTION
pinmap_deepsleep(void)126 void pinmap_deepsleep(void)
127 {
128 int i = 0;
129
130 for (;;) {
131 /* Check if search to end */
132 if (pmap_func[i].PinName == _PNC) {
133 break;
134 }
135
136 /* keep active level when GPIO_PuPd_NOPULL */
137 if (pmap_func[i].DSleepPuPd == GPIO_PuPd_KEEP)
138 goto next;
139
140 /* sleep PuPd set */
141 if (pmap_func[i].DSleepPuPd == GPIO_PuPd_SHUTDOWN)
142 PAD_CMD(pmap_func[i].PinName, DISABLE);
143 else
144 PAD_PullCtrl(pmap_func[i].PinName, pmap_func[i].DSleepPuPd);
145
146 next:
147 i++;
148 }
149 }
150
151
152 /**
153 * @brief Config all pins to the right pull state based on pmap_func table after soc wakeup from sleep.
154 * @note should set pmap_func.FuncPuPd corectly based on your board.
155 * @retval None
156 */
157 CONFIG_FW_CRITICAL_CODE_SECTION
pinmap_wake(void)158 void pinmap_wake(void)
159 {
160 int i = 0;
161 int PinName = 0;
162
163 for (;;) {
164 /* Check if search to end */
165 if (pmap_func_sleep[i].PinName == _PNC) {
166 break;
167 }
168
169 /* pupd not change when sleep */
170 if (pmap_func_sleep[i].SleepPuPd == GPIO_PuPd_KEEP)
171 goto next;
172 PinName = pmap_func_sleep[i].PinName;
173
174 /* active PuPd set */
175 if (pmap_func[PinName].FuncPuPd == GPIO_PuPd_SHUTDOWN) {
176 PAD_CMD(PinName, DISABLE);
177 } else {
178 PAD_PullCtrl(PinName, pmap_func[PinName].FuncPuPd);
179 }
180
181 next:
182 i++;
183 }
184 }
185
186 /******************* (C) COPYRIGHT 2016 Realtek Semiconductor *****END OF FILE****/
187