📄 stm32f10x_gpio.lst
字号:
183 pinmask = ((u32)0x0F) << pos;
184 tmpreg &= ~pinmask;
185
186 /* Write the mode configuration in the corresponding bits */
187 tmpreg |= (currentmode << pos);
188
189 /* Reset the corresponding ODR bit */
190 if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
191 {
192 GPIOx->BRR = (((u32)0x01) << (pinpos + 0x08));
193 }
194 /* Set the corresponding ODR bit */
195 if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
196 {
197 GPIOx->BSRR = (((u32)0x01) << (pinpos + 0x08));
198 }
199 }
200 }
201 GPIOx->CRH = tmpreg;
202 }
203 }
204
205 /*******************************************************************************
206 * Function Name : GPIO_StructInit
207 * Description : Fills each GPIO_InitStruct member with its default value.
208 * Input : - GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure
209 * which will be initialized.
210 * Output : None
211 * Return : None
212 *******************************************************************************/
213 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
214 {
215 /* Reset GPIO init structure parameters values */
216 GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
217 GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
218 GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;
219 }
220
221 /*******************************************************************************
222 * Function Name : GPIO_ReadInputDataBit
223 * Description : Reads the specified input port pin.
224 * Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
225 * : - GPIO_Pin: specifies the port bit to read.
226 * This parameter can be GPIO_Pin_x where x can be (0..15).
227 * Output : None
228 * Return : The input port pin value.
229 *******************************************************************************/
230 u8 GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
231 {
232 u8 bitstatus = 0x00;
233
234 /* Check the parameters */
235 assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
236
237 if ((GPIOx->IDR & GPIO_Pin) != (u32)Bit_RESET)
238 {
239 bitstatus = (u8)Bit_SET;
240 }
241 else
242 {
243 bitstatus = (u8)Bit_RESET;
244 }
245 return bitstatus;
246 }
247
248 /*******************************************************************************
249 * Function Name : GPIO_ReadInputData
250 * Description : Reads the specified GPIO input data port.
251 * Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
252 * Output : None
253 * Return : GPIO input data port value.
254 *******************************************************************************/
255 u16 GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
256 {
257 return ((u16)GPIOx->IDR);
258 }
259
260 /*******************************************************************************
261 * Function Name : GPIO_ReadOutputDataBit
262 * Description : Reads the specified output data port bit.
263 * Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
264 * : - GPIO_Pin: specifies the port bit to read.
265 * This parameter can be GPIO_Pin_x where x can be (0..15).
266 * Output : None
267 * Return : The output port pin value.
268 *******************************************************************************/
269 u8 GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
270 {
271 u8 bitstatus = 0x00;
272
273 /* Check the parameters */
274 assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
275
276 if ((GPIOx->ODR & GPIO_Pin) != (u32)Bit_RESET)
277 {
278 bitstatus = (u8)Bit_SET;
279 }
280 else
281 {
282 bitstatus = (u8)Bit_RESET;
283 }
284 return bitstatus;
285 }
286
287 /*******************************************************************************
288 * Function Name : GPIO_ReadOutputData
289 * Description : Reads the specified GPIO output data port.
290 * Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
291 * Output : None
292 * Return : GPIO output data port value.
293 *******************************************************************************/
294 u16 GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
295 {
296 return ((u16)GPIOx->ODR);
297 }
298
299 /*******************************************************************************
300 * Function Name : GPIO_SetBits
301 * Description : Sets the selected data port bits.
302 * Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
303 * - GPIO_Pin: specifies the port bits to be written.
304 * This parameter can be any combination of GPIO_Pin_x where
305 * x can be (0..15).
306 * Output : None
307 * Return : None
308 *******************************************************************************/
309 void GPIO_SetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
310 {
311 /* Check the parameters */
312 assert_param(IS_GPIO_PIN(GPIO_Pin));
313 GPIOx->BSRR = GPIO_Pin;
314 }
315
316 /*******************************************************************************
317 * Function Name : GPIO_ResetBits
318 * Description : Clears the selected data port bits.
319 * Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
320 * - GPIO_Pin: specifies the port bits to be written.
321 * This parameter can be any combination of GPIO_Pin_x where
322 * x can be (0..15).
323 * Output : None
324 * Return : None
325 *******************************************************************************/
326 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
327 {
328 /* Check the parameters */
329 assert_param(IS_GPIO_PIN(GPIO_Pin));
330 GPIOx->BRR = GPIO_Pin;
331 }
332
333 /*******************************************************************************
334 * Function Name : GPIO_WriteBit
335 * Description : Sets or clears the selected data port bit.
336 * Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
337 * - GPIO_Pin: specifies the port bit to be written.
338 * This parameter can be one of GPIO_Pin_x where x can be (0..15).
339 * - BitVal: specifies the value to be written to the selected bit.
340 * This parameter can be one of the BitAction enum values:
341 * - Bit_RESET: to clear the port pin
342 * - Bit_SET: to set the port pin
343 * Output : None
344 * Return : None
345 *******************************************************************************/
346 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin, BitAction BitVal)
347 {
348 /* Check the parameters */
349 assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
350 assert_param(IS_GPIO_BIT_ACTION(BitVal));
351
352 if (BitVal != Bit_RESET)
353 {
354 GPIOx->BSRR = GPIO_Pin;
355 }
356 else
357 {
358 GPIOx->BRR = GPIO_Pin;
359 }
360 }
361
362 /*******************************************************************************
363 * Function Name : GPIO_Write
364 * Description : Writes data to the specified GPIO data port.
365 * Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
366 * - PortVal: specifies the value to be written to the port output
367 * data register.
368 * Output : None
369 * Return : None
370 *******************************************************************************/
371 void GPIO_Write(GPIO_TypeDef* GPIOx, u16 PortVal)
372 {
373 GPIOx->ODR = PortVal;
374 }
375
376 /*******************************************************************************
377 * Function Name : GPIO_PinLockConfig
378 * Description : Locks GPIO Pins configuration registers.
379 * Input : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
380 * - GPIO_Pin: specifies the port bit to be written.
381 * This parameter can be any combination of GPIO_Pin_x where
382 * x can be (0..15).
383 * Output : None
384 * Return : None
385 *******************************************************************************/
386 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
387 {
388 u32 tmp = 0x00010000;
389
390 /* Check the parameters */
391 assert_param(IS_GPIO_PIN(GPIO_Pin));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -