Rev 1 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 196 | ||
---|---|---|---|
1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
1 | /******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
2 | * File Name : 91x_gpio.c |
2 | * File Name : 91x_gpio.c |
3 | * Author : MCD Application Team |
3 | * Author : MCD Application Team |
- | 4 | * Version : V2.1 |
|
4 | * Date First Issued : 05/18/2006 : Version 1.0 |
5 | * Date : 12/22/2008 |
5 | * Description : This file provides all the GPIO software functions. |
6 | * Description : This file provides all the GPIO firmware functions. |
6 | ******************************************************************************** |
- | |
7 | * History: |
- | |
8 | * 05/22/2007 : Version 1.2 |
- | |
9 | * 05/24/2006 : Version 1.1 |
- | |
10 | * 05/18/2006 : Version 1.0 |
- | |
11 | ******************************************************************************** |
7 | ******************************************************************************** |
12 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
8 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
14 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
15 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
16 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
12 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
17 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
18 | *******************************************************************************/ |
14 | *******************************************************************************/ |
19 | 15 | ||
20 | /* Includes ------------------------------------------------------------------*/ |
16 | /* Includes ------------------------------------------------------------------*/ |
21 | #include "91x_gpio.h" |
17 | #include "91x_gpio.h" |
22 | #include "91x_scu.h" |
18 | #include "91x_scu.h" |
23 | 19 | ||
24 | /* Private typedef -----------------------------------------------------------*/ |
20 | /* Private typedef -----------------------------------------------------------*/ |
25 | /* Private define ------------------------------------------------------------*/ |
21 | /* Private define ------------------------------------------------------------*/ |
26 | 22 | ||
27 | /* Private macro -------------------------------------------------------------*/ |
23 | /* Private macro -------------------------------------------------------------*/ |
28 | /* Private variables ---------------------------------------------------------*/ |
24 | /* Private variables ---------------------------------------------------------*/ |
29 | /* Private function prototypes -----------------------------------------------*/ |
25 | /* Private function prototypes -----------------------------------------------*/ |
30 | static u8 GPIO_GetGPIONumber(GPIO_TypeDef* GPIOx); |
26 | static u8 GPIO_GetGPIONumber(GPIO_TypeDef* GPIOx); |
31 | static u16 GPIO_GetAnaloClearBits(u8 GPIO_ANAChannel); |
27 | static u16 GPIO_GetAnaloClearBits(u8 GPIO_ANAChannel); |
32 | 28 | ||
33 | /* Private functions ---------------------------------------------------------*/ |
29 | /* Private functions ---------------------------------------------------------*/ |
34 | 30 | ||
35 | /******************************************************************************* |
31 | /******************************************************************************* |
36 | * Function Name : GPIO_DeInit |
32 | * Function Name : GPIO_DeInit |
37 | * Description : Deinitializes the GPIOx peripheral registers to their default |
33 | * Description : Deinitializes the GPIOx peripheral registers to their default |
38 | * reset values. |
34 | * reset values. |
39 | * Input : GPIOx: where x can be (0..9) to select the GPIO peripheral. |
35 | * Input : GPIOx: where x can be (0..9) to select the GPIO peripheral. |
40 | * Output : None |
36 | * Output : None |
41 | * Return : None |
37 | * Return : None |
42 | *******************************************************************************/ |
38 | *******************************************************************************/ |
43 | void GPIO_DeInit(GPIO_TypeDef* GPIOx) |
39 | void GPIO_DeInit(GPIO_TypeDef* GPIOx) |
44 | { |
40 | { |
45 | /* Reset the GPIO registers values */ |
41 | /* Reset the GPIO registers values */ |
46 | if(GPIOx == GPIO0) |
42 | if(GPIOx == GPIO0) |
47 | { |
43 | { |
48 | SCU_APBPeriphReset(__GPIO0,ENABLE); |
44 | SCU_APBPeriphReset(__GPIO0,ENABLE); |
49 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
45 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
50 | SCU->GPIOTYPE[0x00] = 0x0000 ; |
46 | SCU->GPIOTYPE[0x00] = 0x0000 ; |
51 | SCU->GPIOOUT[0x00] = 0x0000; |
47 | SCU->GPIOOUT[0x00] = 0x0000; |
52 | SCU->GPIOIN[0x00] = 0x0000; |
48 | SCU->GPIOIN[0x00] = 0x0000; |
53 | } |
49 | } |
54 | 50 | ||
55 | if(GPIOx == GPIO1) |
51 | if(GPIOx == GPIO1) |
56 | { |
52 | { |
57 | SCU_APBPeriphReset(__GPIO1,ENABLE); |
53 | SCU_APBPeriphReset(__GPIO1,ENABLE); |
58 | SCU_APBPeriphReset(__GPIO1,DISABLE); |
54 | SCU_APBPeriphReset(__GPIO1,DISABLE); |
59 | SCU->GPIOTYPE[0x01] = 0x0000 ; |
55 | SCU->GPIOTYPE[0x01] = 0x0000 ; |
60 | SCU->GPIOOUT[0x01] = 0x0000; |
56 | SCU->GPIOOUT[0x01] = 0x0000; |
61 | SCU->GPIOIN[0x01] = 0x0000; |
57 | SCU->GPIOIN[0x01] = 0x0000; |
62 | } |
58 | } |
63 | 59 | ||
64 | if(GPIOx == GPIO2) |
60 | if(GPIOx == GPIO2) |
65 | { |
61 | { |
66 | SCU_APBPeriphReset(__GPIO2,ENABLE); |
62 | SCU_APBPeriphReset(__GPIO2,ENABLE); |
67 | SCU_APBPeriphReset(__GPIO2,DISABLE); |
63 | SCU_APBPeriphReset(__GPIO2,DISABLE); |
68 | SCU->GPIOTYPE[0x02] = 0x0000 ; |
64 | SCU->GPIOTYPE[0x02] = 0x0000 ; |
69 | SCU->GPIOOUT[0x02] = 0x0000; |
65 | SCU->GPIOOUT[0x02] = 0x0000; |
70 | SCU->GPIOIN[0x02] = 0x0000; |
66 | SCU->GPIOIN[0x02] = 0x0000; |
71 | } |
67 | } |
72 | 68 | ||
73 | if(GPIOx == GPIO3) |
69 | if(GPIOx == GPIO3) |
74 | { |
70 | { |
75 | SCU_APBPeriphReset(__GPIO3,ENABLE); |
71 | SCU_APBPeriphReset(__GPIO3,ENABLE); |
76 | SCU_APBPeriphReset(__GPIO3,DISABLE); |
72 | SCU_APBPeriphReset(__GPIO3,DISABLE); |
77 | SCU->GPIOTYPE[0x03] = 0x0000 ; |
73 | SCU->GPIOTYPE[0x03] = 0x0000 ; |
78 | SCU->GPIOOUT[0x03] = 0x0000; |
74 | SCU->GPIOOUT[0x03] = 0x0000; |
79 | SCU->GPIOIN[0x03] = 0x0000; |
75 | SCU->GPIOIN[0x03] = 0x0000; |
80 | } |
76 | } |
81 | 77 | ||
82 | if(GPIOx == GPIO4) |
78 | if(GPIOx == GPIO4) |
83 | { |
79 | { |
84 | SCU_APBPeriphReset(__GPIO4,ENABLE); |
80 | SCU_APBPeriphReset(__GPIO4,ENABLE); |
85 | SCU_APBPeriphReset(__GPIO4,DISABLE); |
81 | SCU_APBPeriphReset(__GPIO4,DISABLE); |
86 | SCU->GPIOTYPE[0x04] = 0x0000 ; |
82 | SCU->GPIOTYPE[0x04] = 0x0000 ; |
87 | SCU->GPIOOUT[0x04] = 0x0000; |
83 | SCU->GPIOOUT[0x04] = 0x0000; |
88 | SCU->GPIOIN[0x04] = 0x0000; |
84 | SCU->GPIOIN[0x04] = 0x0000; |
89 | SCU->GPIOANA = 0x00; |
85 | SCU->GPIOANA = 0x00; |
90 | } |
86 | } |
91 | 87 | ||
92 | if(GPIOx == GPIO5) |
88 | if(GPIOx == GPIO5) |
93 | { |
89 | { |
94 | SCU_APBPeriphReset(__GPIO5,ENABLE); |
90 | SCU_APBPeriphReset(__GPIO5,ENABLE); |
95 | SCU_APBPeriphReset(__GPIO5,DISABLE); |
91 | SCU_APBPeriphReset(__GPIO5,DISABLE); |
96 | SCU->GPIOTYPE[0x05] = 0x0000 ; |
92 | SCU->GPIOTYPE[0x05] = 0x0000 ; |
97 | SCU->GPIOOUT[0x05] = 0x0000; |
93 | SCU->GPIOOUT[0x05] = 0x0000; |
98 | SCU->GPIOIN[0x05] = 0x0000; |
94 | SCU->GPIOIN[0x05] = 0x0000; |
99 | } |
95 | } |
100 | 96 | ||
101 | if(GPIOx == GPIO6) |
97 | if(GPIOx == GPIO6) |
102 | { |
98 | { |
103 | SCU_APBPeriphReset(__GPIO6,ENABLE); |
99 | SCU_APBPeriphReset(__GPIO6,ENABLE); |
104 | SCU_APBPeriphReset(__GPIO6,DISABLE); |
100 | SCU_APBPeriphReset(__GPIO6,DISABLE); |
105 | SCU->GPIOTYPE[0x06] = 0x0000 ; |
101 | SCU->GPIOTYPE[0x06] = 0x0000 ; |
106 | SCU->GPIOOUT[0x06] = 0x0000; |
102 | SCU->GPIOOUT[0x06] = 0x0000; |
107 | SCU->GPIOIN[0x06] = 0x0000; |
103 | SCU->GPIOIN[0x06] = 0x0000; |
108 | } |
104 | } |
109 | 105 | ||
110 | if(GPIOx == GPIO7) |
106 | if(GPIOx == GPIO7) |
111 | { |
107 | { |
112 | SCU_APBPeriphReset(__GPIO7,ENABLE); |
108 | SCU_APBPeriphReset(__GPIO7,ENABLE); |
113 | SCU_APBPeriphReset(__GPIO7,DISABLE); |
109 | SCU_APBPeriphReset(__GPIO7,DISABLE); |
114 | SCU->GPIOTYPE[0x07] = 0x0000; |
110 | SCU->GPIOTYPE[0x07] = 0x0000; |
115 | SCU->GPIOOUT[0x07] = 0x0000; |
111 | SCU->GPIOOUT[0x07] = 0x0000; |
116 | SCU->GPIOIN[0x07] = 0x0000; |
112 | SCU->GPIOIN[0x07] = 0x0000; |
117 | } |
113 | } |
118 | 114 | ||
119 | if(GPIOx == GPIO8) |
115 | if(GPIOx == GPIO8) |
120 | { |
116 | { |
121 | SCU_APBPeriphReset(__GPIO8,ENABLE); |
117 | SCU_APBPeriphReset(__GPIO8,ENABLE); |
122 | SCU_APBPeriphReset(__GPIO8,DISABLE); |
118 | SCU_APBPeriphReset(__GPIO8,DISABLE); |
123 | SCU->GPIOTYPE[0x08] = 0x0000; |
119 | SCU->GPIOTYPE[0x08] = 0x0000; |
124 | SCU->GPIOEMI = 0x00; |
120 | SCU->GPIOEMI = 0x00; |
125 | } |
121 | } |
126 | 122 | ||
127 | if(GPIOx == GPIO9) |
123 | if(GPIOx == GPIO9) |
128 | { |
124 | { |
129 | SCU_APBPeriphReset(__GPIO9,ENABLE); |
125 | SCU_APBPeriphReset(__GPIO9,ENABLE); |
130 | SCU_APBPeriphReset(__GPIO9,DISABLE); |
126 | SCU_APBPeriphReset(__GPIO9,DISABLE); |
131 | SCU->GPIOTYPE[0x09] = 0x0000; |
127 | SCU->GPIOTYPE[0x09] = 0x0000; |
132 | SCU->GPIOEMI = 0x00; |
128 | SCU->GPIOEMI = 0x00; |
133 | } |
129 | } |
134 | } |
130 | } |
135 | /******************************************************************************* |
131 | /******************************************************************************* |
136 | * Function Name : GPIO_Init |
132 | * Function Name : GPIO_Init |
137 | * Description : Initializes the GPIOx peripheral according to the specified |
133 | * Description : Initializes the GPIOx peripheral according to the specified |
138 | * parameters in the GPIO_InitStruct . |
134 | * parameters in the GPIO_InitStruct . |
139 | * Input :- GPIOx: where x can be (0..9) to select the GPIO peripheral. |
135 | * Input :- GPIOx: where x can be (0..9) to select the GPIO peripheral. |
140 | * - GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that |
136 | * - GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that |
141 | * contains the configuration information for the specified GPIO |
137 | * contains the configuration information for the specified GPIO |
142 | * peripheral. |
138 | * peripheral. |
143 | * Output : None |
139 | * Output : None |
144 | * Return : None |
140 | * Return : None |
145 | *******************************************************************************/ |
141 | *******************************************************************************/ |
146 | void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct) |
142 | void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct) |
147 | { |
143 | { |
148 | /* Select pin direction */ |
144 | /* Select pin direction */ |
149 | u8 PinNumber = 0; |
145 | u8 PinNumber = 0; |
150 | u8 Counter = 0; |
146 | u8 Counter = 0; |
151 | u8 GPIO_Number = 0; |
147 | u8 GPIO_Number = 0; |
152 | 148 | ||
153 | GPIO_Number = GPIO_GetGPIONumber(GPIOx); |
149 | GPIO_Number = GPIO_GetGPIONumber(GPIOx); |
154 | 150 | ||
155 | if(GPIO_InitStruct->GPIO_Direction == GPIO_PinOutput) |
151 | if(GPIO_InitStruct->GPIO_Direction == GPIO_PinOutput) |
156 | { |
152 | { |
157 | GPIOx->DDR |= GPIO_InitStruct->GPIO_Pin; |
153 | GPIOx->DDR |= GPIO_InitStruct->GPIO_Pin; |
158 | } |
154 | } |
159 | else |
155 | else |
160 | { |
156 | { |
161 | GPIOx->DDR &= ~GPIO_InitStruct->GPIO_Pin; |
157 | GPIOx->DDR &= ~GPIO_InitStruct->GPIO_Pin; |
162 | } |
158 | } |
163 | 159 | ||
164 | for (Counter = 0; Counter < 8;Counter++) |
160 | for (Counter = 0; Counter < 8;Counter++) |
165 | { |
161 | { |
166 | /*Search pin number*/ |
162 | /*Search pin number*/ |
167 | PinNumber = (GPIO_InitStruct->GPIO_Pin & (1 <<Counter)); |
163 | PinNumber = (GPIO_InitStruct->GPIO_Pin & (1 <<Counter)); |
168 | if((PinNumber >> Counter) == 1) |
164 | if((PinNumber >> Counter) == 1) |
169 | { |
165 | { |
170 | if (GPIO_Number < 8) |
166 | if (GPIO_Number < 8) |
171 | { |
167 | { |
172 | /*Output ALternate 0*/ |
168 | /*Output ALternate 0*/ |
173 | SCU->GPIOOUT[GPIO_Number] &= ~(0x3 <<(Counter *2)); |
169 | SCU->GPIOOUT[GPIO_Number] &= ~(0x3 <<(Counter *2)); |
174 | if(GPIO_InitStruct->GPIO_Alternate == GPIO_OutputAlt1) |
170 | if(GPIO_InitStruct->GPIO_Alternate == GPIO_OutputAlt1) |
175 | { |
171 | { |
176 | /*Output ALternate 1*/ |
172 | /*Output ALternate 1*/ |
177 | SCU->GPIOOUT[GPIO_Number] |= 1 << (Counter *2); |
173 | SCU->GPIOOUT[GPIO_Number] |= 1 << (Counter *2); |
178 | } |
174 | } |
179 | if(GPIO_InitStruct->GPIO_Alternate == GPIO_OutputAlt2) |
175 | if(GPIO_InitStruct->GPIO_Alternate == GPIO_OutputAlt2) |
180 | { |
176 | { |
181 | /*Output ALternate 2*/ |
177 | /*Output ALternate 2*/ |
182 | SCU->GPIOOUT[GPIO_Number] |= 0x2 << (Counter *2); |
178 | SCU->GPIOOUT[GPIO_Number] |= 0x2 << (Counter *2); |
183 | } |
179 | } |
184 | if(GPIO_InitStruct->GPIO_Alternate == GPIO_OutputAlt3) |
180 | if(GPIO_InitStruct->GPIO_Alternate == GPIO_OutputAlt3) |
185 | { |
181 | { |
186 | /*Output ALternate 3*/ |
182 | /*Output ALternate 3*/ |
187 | SCU->GPIOOUT[GPIO_Number] |= 0x3 << (Counter *2); |
183 | SCU->GPIOOUT[GPIO_Number] |= 0x3 << (Counter *2); |
188 | } |
184 | } |
189 | 185 | ||
190 | /*IP Connected disable*/ |
186 | /*IP Connected disable*/ |
191 | SCU->GPIOIN[GPIO_Number] &= ~(0x1 << Counter) ; |
187 | SCU->GPIOIN[GPIO_Number] &= ~(0x1 << Counter) ; |
192 | if(GPIO_InitStruct->GPIO_IPConnected == GPIO_IPConnected_Enable) |
188 | if(GPIO_InitStruct->GPIO_IPInputConnected == GPIO_IPInputConnected_Enable) |
193 | { |
189 | { |
194 | /*IP Connected enable*/ |
190 | /*IP Connected enable*/ |
195 | SCU->GPIOIN[GPIO_Number] |= 0x1 << Counter; |
191 | SCU->GPIOIN[GPIO_Number] |= 0x1 << Counter; |
196 | } |
192 | } |
197 | } |
193 | } |
198 | 194 | ||
199 | /*Type configuration: PushPull or Open Collector*/ |
195 | /*Type configuration: PushPull or Open Collector*/ |
200 | SCU->GPIOTYPE[GPIO_Number] &= ~(0x1 << Counter) ; |
196 | SCU->GPIOTYPE[GPIO_Number] &= ~(0x1 << Counter) ; |
201 | if(GPIO_InitStruct->GPIO_Type == GPIO_Type_OpenCollector) |
197 | if(GPIO_InitStruct->GPIO_Type == GPIO_Type_OpenCollector) |
202 | { |
198 | { |
203 | /*Open Drain configuration*/ |
199 | /*Open Drain configuration*/ |
204 | SCU->GPIOTYPE[GPIO_Number] |= 0x1 << Counter; |
200 | SCU->GPIOTYPE[GPIO_Number] |= 0x1 << Counter; |
205 | } |
201 | } |
206 | } |
202 | } |
207 | } |
203 | } |
208 | } |
204 | } |
209 | 205 | ||
210 | /******************************************************************************* |
206 | /******************************************************************************* |
211 | * Function Name : GPIO_StructInit |
207 | * Function Name : GPIO_StructInit |
212 | * Description : Initialize the GPIO Init Structure parameters |
208 | * Description : Initialize the GPIO Init Structure parameters |
213 | * Input : GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure |
209 | * Input : GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure |
214 | * which will be initialized. |
210 | * which will be initialized. |
215 | * Output : None |
211 | * Output : None |
216 | * Return : None |
212 | * Return : None |
217 | *******************************************************************************/ |
213 | *******************************************************************************/ |
218 | void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct) |
214 | void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct) |
219 | { |
215 | { |
220 | /* Reset GPIO init structure parameters values */ |
216 | /* Reset GPIO init structure parameters values */ |
221 | GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All; |
217 | GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All; |
222 | GPIO_InitStruct->GPIO_Direction = GPIO_PinInput; |
218 | GPIO_InitStruct->GPIO_Direction = GPIO_PinInput; |
223 | GPIO_InitStruct->GPIO_Type = GPIO_Type_PushPull; |
- | |
224 | GPIO_InitStruct->GPIO_IPConnected = GPIO_IPConnected_Disable; |
219 | GPIO_InitStruct->GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
225 | GPIO_InitStruct->GPIO_Alternate = GPIO_InputAlt1; |
220 | GPIO_InitStruct->GPIO_Alternate = GPIO_InputAlt1; |
226 | } |
221 | } |
227 | 222 | ||
228 | /******************************************************************************* |
223 | /******************************************************************************* |
229 | * Function Name : GPIO_ReadBit |
224 | * Function Name : GPIO_ReadBit |
230 | * Description : Reads the specified port pin |
225 | * Description : Reads the specified port pin |
231 | * Input : - GPIOx: where x can be (0..9) to select the GPIO peripheral. |
226 | * Input : - GPIOx: where x can be (0..9) to select the GPIO peripheral. |
232 | * : - GPIO_Pin: the Pin number. This parameter can be GPIO_Pin_x |
227 | * : - GPIO_Pin: the Pin number. This parameter can be GPIO_Pin_x |
233 | * where x can be (0..7). |
228 | * where x can be (0..7). |
234 | * Output : None |
229 | * Output : None |
235 | * Return : The port pin value |
230 | * Return : The port pin value |
236 | *******************************************************************************/ |
231 | *******************************************************************************/ |
237 | u8 GPIO_ReadBit(GPIO_TypeDef* GPIOx, u8 GPIO_Pin) |
232 | u8 GPIO_ReadBit(GPIO_TypeDef* GPIOx, u8 GPIO_Pin) |
238 | { |
233 | { |
239 | if ((((GPIOx->DR[GPIO_Pin<<2])) & GPIO_Pin) != Bit_RESET ) |
234 | if ((((GPIOx->DR[GPIO_Pin<<2])) & GPIO_Pin) != Bit_RESET ) |
240 | { |
235 | { |
241 | return Bit_SET; |
236 | return Bit_SET; |
242 | } |
237 | } |
243 | else |
238 | else |
244 | { |
239 | { |
245 | return Bit_RESET; |
240 | return Bit_RESET; |
246 | } |
241 | } |
247 | } |
242 | } |
248 | 243 | ||
249 | /******************************************************************************* |
244 | /******************************************************************************* |
250 | * Function Name : GPIO_Read |
245 | * Function Name : GPIO_Read |
251 | * Description : Reads the specified GPIO data port |
246 | * Description : Reads the specified GPIO data port |
252 | * Input : - GPIOx: where x can be (0..9) to select the GPIO peripheral. |
247 | * Input : - GPIOx: where x can be (0..9) to select the GPIO peripheral. |
253 | * Output : None |
248 | * Output : None |
254 | * Return : GPIO data port word value. |
249 | * Return : GPIO data port word value. |
255 | *******************************************************************************/ |
250 | *******************************************************************************/ |
256 | u8 GPIO_Read(GPIO_TypeDef* GPIOx) |
251 | u8 GPIO_Read(GPIO_TypeDef* GPIOx) |
257 | { |
252 | { |
258 | return (GPIOx->DR[0x3FC]); |
253 | return (GPIOx->DR[0x3FC]); |
259 | } |
254 | } |
260 | 255 | ||
261 | /******************************************************************************* |
256 | /******************************************************************************* |
262 | * Function Name : GPIO_WriteBit |
257 | * Function Name : GPIO_WriteBit |
263 | * Description : Sets or clears the selected data port bit. |
258 | * Description : Sets or clears the selected data port bit. |
264 | * Input : - GPIOx: where x can be (0..9) to select the GPIO peripheral. |
259 | * Input : - GPIOx: where x can be (0..9) to select the GPIO peripheral. |
265 | * - GPIO_Pin: the Pin number. This parameter can be GPIO_Pin_x |
260 | * - GPIO_Pin: the Pin number. This parameter can be GPIO_Pin_x |
266 | * where x can be (0..7). |
261 | * where x can be (0..7). |
267 | * - BitVal: this parameter specifies the value to be written |
262 | * - BitVal: this parameter specifies the value to be written |
268 | * to the selected bit. |
263 | * to the selected bit. |
269 | * BitVal must be one of the BitAction enum values: |
264 | * BitVal must be one of the BitAction enum values: |
270 | * - Bit_RESET: to clear the port pin |
265 | * - Bit_RESET: to clear the port pin |
271 | * - Bit_SET: to set the port pin |
266 | * - Bit_SET: to set the port pin |
272 | * Output : None |
267 | * Output : None |
273 | * Return : None |
268 | * Return : None |
274 | *******************************************************************************/ |
269 | *******************************************************************************/ |
275 | void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u8 GPIO_Pin, BitAction BitVal) |
270 | void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u8 GPIO_Pin, BitAction BitVal) |
276 | { |
271 | { |
277 | if(BitVal == Bit_SET) |
272 | if(BitVal == Bit_SET) |
278 | { |
273 | { |
279 | GPIOx->DR[GPIO_Pin <<2] = GPIO_Pin; |
274 | GPIOx->DR[GPIO_Pin <<2] = GPIO_Pin; |
280 | } |
275 | } |
281 | else |
276 | else |
282 | { |
277 | { |
283 | GPIOx->DR[GPIO_Pin <<2] = 0x00; |
278 | GPIOx->DR[GPIO_Pin <<2] = 0x00; |
284 | } |
279 | } |
285 | } |
280 | } |
286 | 281 | ||
287 | /******************************************************************************* |
282 | /******************************************************************************* |
288 | * Function Name : GPIO_Write |
283 | * Function Name : GPIO_Write |
289 | * Description : Writes the passed value in the selected data GPIOx port |
284 | * Description : Writes the passed value in the selected data GPIOx port |
290 | * register. |
285 | * register. |
291 | * Input :- GPIOx: where x can be (0..9) to select the GPIO peripheral. |
286 | * Input :- GPIOx: where x can be (0..9) to select the GPIO peripheral. |
292 | * - PortVal: the value to be written to the data port register. |
287 | * - PortVal: the value to be written to the data port register. |
293 | * Output : None |
288 | * Output : None |
294 | * Return : None |
289 | * Return : None |
295 | *******************************************************************************/ |
290 | *******************************************************************************/ |
296 | void GPIO_Write(GPIO_TypeDef* GPIOx, u8 PortVal) |
291 | void GPIO_Write(GPIO_TypeDef* GPIOx, u8 PortVal) |
297 | { |
292 | { |
298 | GPIOx->DR[0x3FC] = PortVal; |
293 | GPIOx->DR[0x3FC] = PortVal; |
299 | } |
294 | } |
300 | 295 | ||
301 | /******************************************************************************* |
296 | /******************************************************************************* |
302 | * Function Name : GPIO_EMIConfig |
297 | * Function Name : GPIO_EMIConfig |
303 | * Description : Enables or disables GPIO 8 and 9 in EMI mode. |
298 | * Description : Enables or disables GPIO 8 and 9 in EMI mode. |
304 | * Input : - NewState: new state of the EMI. |
299 | * Input : - NewState: new state of the EMI. |
305 | * This parameter can be: ENABLE or DISABLE. |
300 | * This parameter can be: ENABLE or DISABLE. |
306 | * Output : None |
301 | * Output : None |
307 | * Return : None |
302 | * Return : None |
308 | *******************************************************************************/ |
303 | *******************************************************************************/ |
309 | void GPIO_EMIConfig(FunctionalState NewState) |
304 | void GPIO_EMIConfig(FunctionalState NewState) |
310 | { |
305 | { |
311 | if(NewState == ENABLE) |
306 | if(NewState == ENABLE) |
312 | { |
307 | { |
313 | SCU->GPIOEMI = 0x01; |
308 | SCU->GPIOEMI = 0x01; |
314 | } |
309 | } |
315 | else |
310 | else |
316 | { |
311 | { |
317 | SCU->GPIOEMI = 0x00; |
312 | SCU->GPIOEMI = 0x00; |
318 | } |
313 | } |
319 | } |
314 | } |
320 | 315 | ||
321 | /******************************************************************************* |
316 | /******************************************************************************* |
322 | * Function Name : GPIO_ANAPinConfig |
317 | * Function Name : GPIO_ANAPinConfig |
323 | * Description : Enables or disables pins from GPIO 4 in Analogue mode. |
318 | * Description : Enables or disables pins from GPIO 4 in Analogue mode. |
324 | * Input :- GPIO_ANAChannel: selects the ADC channel pin. |
319 | * Input :- GPIO_ANAChannel: selects the ADC channel pin. |
325 | * This parameter can be one of the following values: |
320 | * This parameter can be one of the following values: |
326 | * GPIO_ANAChannel0 |
321 | * GPIO_ANAChannel0 |
327 | * GPIO_ANAChannel1 |
322 | * GPIO_ANAChannel1 |
328 | * GPIO_ANAChannel2 |
323 | * GPIO_ANAChannel2 |
329 | * GPIO_ANAChannel3 |
324 | * GPIO_ANAChannel3 |
330 | * GPIO_ANAChannel4 |
325 | * GPIO_ANAChannel4 |
331 | * GPIO_ANAChannel5 |
326 | * GPIO_ANAChannel5 |
332 | * GPIO_ANAChannel6 |
327 | * GPIO_ANAChannel6 |
333 | * GPIO_ANAChannel7 |
328 | * GPIO_ANAChannel7 |
334 | * GPIO_ANAChannelALL |
329 | * GPIO_ANAChannelALL |
335 | * - NewState: new state of the port pin. |
330 | * - NewState: new state of the port pin. |
336 | * This parameter can be: ENABLE or DISABLE. |
331 | * This parameter can be: ENABLE or DISABLE. |
337 | * Output : None |
332 | * Output : None |
338 | * Return : None |
333 | * Return : None |
339 | *******************************************************************************/ |
334 | *******************************************************************************/ |
340 | void GPIO_ANAPinConfig(u8 GPIO_ANAChannel, FunctionalState NewState) |
335 | void GPIO_ANAPinConfig(u8 GPIO_ANAChannel, FunctionalState NewState) |
341 | { |
336 | { |
342 | if(NewState == ENABLE) |
337 | if(NewState == ENABLE) |
343 | { |
338 | { |
344 | SCU->GPIOOUT[4] &= GPIO_GetAnaloClearBits(GPIO_ANAChannel); |
339 | SCU->GPIOOUT[4] &= GPIO_GetAnaloClearBits(GPIO_ANAChannel); |
345 | SCU->GPIOIN[4] &= ~GPIO_ANAChannel; |
340 | SCU->GPIOIN[4] &= ~GPIO_ANAChannel; |
346 | SCU->GPIOANA |= GPIO_ANAChannel; |
341 | SCU->GPIOANA |= GPIO_ANAChannel; |
347 | } |
342 | } |
348 | else |
343 | else |
349 | { |
344 | { |
350 | SCU->GPIOANA &= ~GPIO_ANAChannel; |
345 | SCU->GPIOANA &= ~GPIO_ANAChannel; |
351 | } |
346 | } |
352 | } |
347 | } |
353 | 348 | ||
354 | /******************************************************************************* |
349 | /******************************************************************************* |
355 | * Function Name : GPIO_GetGPIONumber |
350 | * Function Name : GPIO_GetGPIONumber |
356 | * Description : searche the GPIO number. |
351 | * Description : searche the GPIO number. |
357 | * Input : GPIOx: where x can be (0..9) to select the GPIO peripheral. |
352 | * Input : GPIOx: where x can be (0..9) to select the GPIO peripheral. |
358 | * Output : None |
353 | * Output : None |
359 | * Return : GPIO number |
354 | * Return : GPIO number |
360 | *******************************************************************************/ |
355 | *******************************************************************************/ |
361 | u8 GPIO_GetGPIONumber(GPIO_TypeDef* GPIOx) |
356 | u8 GPIO_GetGPIONumber(GPIO_TypeDef* GPIOx) |
362 | { |
357 | { |
363 | if(GPIOx == GPIO1) |
358 | if(GPIOx == GPIO1) |
364 | { |
359 | { |
365 | return 1; |
360 | return 1; |
366 | } |
361 | } |
367 | if(GPIOx == GPIO2) |
362 | if(GPIOx == GPIO2) |
368 | { |
363 | { |
369 | return 2; |
364 | return 2; |
370 | } |
365 | } |
371 | if(GPIOx == GPIO3) |
366 | if(GPIOx == GPIO3) |
372 | { |
367 | { |
373 | return 3; |
368 | return 3; |
374 | } |
369 | } |
375 | if(GPIOx == GPIO4) |
370 | if(GPIOx == GPIO4) |
376 | { |
371 | { |
377 | return 4; |
372 | return 4; |
378 | } |
373 | } |
379 | if(GPIOx == GPIO5) |
374 | if(GPIOx == GPIO5) |
380 | { |
375 | { |
381 | return 5; |
376 | return 5; |
382 | } |
377 | } |
383 | if(GPIOx == GPIO6) |
378 | if(GPIOx == GPIO6) |
384 | { |
379 | { |
385 | return 6; |
380 | return 6; |
386 | } |
381 | } |
387 | if(GPIOx == GPIO7) |
382 | if(GPIOx == GPIO7) |
388 | { |
383 | { |
389 | return 7; |
384 | return 7; |
390 | } |
385 | } |
391 | if(GPIOx == GPIO8) |
386 | if(GPIOx == GPIO8) |
392 | { |
387 | { |
393 | return 8; |
388 | return 8; |
394 | } |
389 | } |
395 | if(GPIOx == GPIO9) |
390 | if(GPIOx == GPIO9) |
396 | { |
391 | { |
397 | return 9; |
392 | return 9; |
398 | } |
393 | } |
399 | return 0; |
394 | return 0; |
400 | } |
395 | } |
401 | /******************************************************************************* |
396 | /******************************************************************************* |
402 | * Function Name : GPIO_GetAnaloClearBits |
397 | * Function Name : GPIO_GetAnaloClearBits |
403 | * Description : Clear the corresponding bits in the SCU_OUT register. |
398 | * Description : Clear the corresponding bits in the SCU_OUT register. |
404 | * Input : GPIO_ANAChannel: selects the ADC channel pin. |
399 | * Input : GPIO_ANAChannel: selects the ADC channel pin. |
405 | * This parameter can be one of the following values: |
400 | * This parameter can be one of the following values: |
406 | * GPIO_ANAChannel0 |
401 | * GPIO_ANAChannel0 |
407 | * GPIO_ANAChannel1 |
402 | * GPIO_ANAChannel1 |
408 | * GPIO_ANAChannel2 |
403 | * GPIO_ANAChannel2 |
409 | * GPIO_ANAChannel3 |
404 | * GPIO_ANAChannel3 |
410 | * GPIO_ANAChannel4 |
405 | * GPIO_ANAChannel4 |
411 | * GPIO_ANAChannel5 |
406 | * GPIO_ANAChannel5 |
412 | * GPIO_ANAChannel6 |
407 | * GPIO_ANAChannel6 |
413 | * GPIO_ANAChannel7 |
408 | * GPIO_ANAChannel7 |
414 | * GPIO_ANAChannelALL |
409 | * GPIO_ANAChannelALL |
415 | * Output : None |
410 | * Output : None |
416 | * Return : reset value in SCU_OUT register |
411 | * Return : reset value in SCU_OUT register |
417 | *******************************************************************************/ |
412 | *******************************************************************************/ |
418 | u16 GPIO_GetAnaloClearBits(u8 GPIO_ANAChannel) |
413 | u16 GPIO_GetAnaloClearBits(u8 GPIO_ANAChannel) |
419 | { |
414 | { |
420 | if(GPIO_ANAChannel == GPIO_ANAChannel0) |
415 | if(GPIO_ANAChannel == GPIO_ANAChannel0) |
421 | { |
416 | { |
422 | return 0xFFFC; |
417 | return 0xFFFC; |
423 | } |
418 | } |
424 | if(GPIO_ANAChannel == GPIO_ANAChannel1) |
419 | if(GPIO_ANAChannel == GPIO_ANAChannel1) |
425 | { |
420 | { |
426 | return 0xFFF3; |
421 | return 0xFFF3; |
427 | } |
422 | } |
428 | if(GPIO_ANAChannel == GPIO_ANAChannel2) |
423 | if(GPIO_ANAChannel == GPIO_ANAChannel2) |
429 | { |
424 | { |
430 | return 0xFFCF; |
425 | return 0xFFCF; |
431 | } |
426 | } |
432 | if(GPIO_ANAChannel == GPIO_ANAChannel3) |
427 | if(GPIO_ANAChannel == GPIO_ANAChannel3) |
433 | { |
428 | { |
434 | return 0xFF3F; |
429 | return 0xFF3F; |
435 | } |
430 | } |
436 | if(GPIO_ANAChannel == GPIO_ANAChannel4) |
431 | if(GPIO_ANAChannel == GPIO_ANAChannel4) |
437 | { |
432 | { |
438 | return 0xFCFF; |
433 | return 0xFCFF; |
439 | } |
434 | } |
440 | if(GPIO_ANAChannel == GPIO_ANAChannel5) |
435 | if(GPIO_ANAChannel == GPIO_ANAChannel5) |
441 | { |
436 | { |
442 | return 0xF3FF; |
437 | return 0xF3FF; |
443 | } |
438 | } |
444 | if(GPIO_ANAChannel == GPIO_ANAChannel6) |
439 | if(GPIO_ANAChannel == GPIO_ANAChannel6) |
445 | { |
440 | { |
446 | return 0xCFFF; |
441 | return 0xCFFF; |
447 | } |
442 | } |
448 | if(GPIO_ANAChannel == GPIO_ANAChannel7) |
443 | if(GPIO_ANAChannel == GPIO_ANAChannel7) |
449 | { |
444 | { |
450 | return 0x3FFF; |
445 | return 0x3FFF; |
451 | } |
446 | } |
452 | /*Default vaule: return GPIO_ANAChannelALL*/ |
447 | /*Default vaule: return GPIO_ANAChannelALL*/ |
453 | return 0x0000; |
448 | return 0x0000; |
454 | } |
449 | } |
455 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
450 | /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ |
456 | 451 | ||
457 | 452 |