rt-thread-official/bsp/swm320-lq100/Libraries/SWM320_StdPeriph_Driver/SWM320_gpio.c

280 lines
11 KiB
C
Raw Normal View History

2018-12-24 17:17:27 +08:00
/******************************************************************************************************************************************
* <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: SWM320_gpio.c
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: SWM320<EFBFBD><EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>: http://www.synwit.com.cn/e/tool/gbook/?bid=1
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: V1.1.0 2017<EFBFBD><EFBFBD>10<EFBFBD><EFBFBD>25<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼:
*
*
*******************************************************************************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION
* REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE
* FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
* -ECTION WITH THEIR PRODUCTS.
*
* COPYRIGHT 2012 Synwit Technology
*******************************************************************************************************************************************/
#include "SWM320.h"
#include "SWM320_gpio.h"
/******************************************************************************************************************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: GPIO_Init()
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD>ų<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>©<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: GPIO_TypeDef * GPIOx ָ<EFBFBD><EFBFBD>GPIO<EFBFBD>˿ڣ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIOA<EFBFBD><EFBFBD>GPIOB<EFBFBD><EFBFBD>GPIOC<EFBFBD><EFBFBD>GPIOM<EFBFBD><EFBFBD>GPION<EFBFBD><EFBFBD>GPIOP
* uint32_t n ָ<EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>PIN0<EFBFBD><EFBFBD>PIN1<EFBFBD><EFBFBD>PIN2<EFBFBD><EFBFBD>... ... PIN22<EFBFBD><EFBFBD>PIN23
* uint32_t dir <EFBFBD><EFBFBD><EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0 <EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* uint32_t pull_up <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0 <EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* uint32_t pull_down <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0 <EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
******************************************************************************************************************************************/
void GPIO_Init(GPIO_TypeDef *GPIOx, uint32_t n, uint32_t dir, uint32_t pull_up, uint32_t pull_down)
{
switch ((uint32_t)GPIOx)
{
case ((uint32_t)GPIOA):
SYS->CLKEN |= (0x01 << SYS_CLKEN_GPIOA_Pos);
PORT_Init(PORTA, n, 0, 1); //PORTA.PINn<4E><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪGPIO<49><4F><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA>
if (dir == 1)
{
GPIOA->DIR |= (0x01 << n);
}
else
{
GPIOA->DIR &= ~(0x01 << n);
}
if (pull_up == 1)
PORT->PORTA_PULLU |= (0x01 << n);
else
PORT->PORTA_PULLU &= ~(0x01 << n);
break;
case ((uint32_t)GPIOB):
SYS->CLKEN |= (0x01 << SYS_CLKEN_GPIOB_Pos);
PORT_Init(PORTB, n, 0, 1); //PORTB.PINn<4E><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪGPIO<49><4F><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA>
if (dir == 1)
{
GPIOB->DIR |= (0x01 << n);
}
else
{
GPIOB->DIR &= ~(0x01 << n);
}
if (pull_down == 1)
PORT->PORTB_PULLD |= (0x01 << n);
else
PORT->PORTB_PULLD &= ~(0x01 << n);
break;
case ((uint32_t)GPIOC):
SYS->CLKEN |= (0x01 << SYS_CLKEN_GPIOC_Pos);
PORT_Init(PORTC, n, 0, 1); //PORTC.PINn<4E><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪGPIO<49><4F><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA>
if (dir == 1)
{
GPIOC->DIR |= (0x01 << n);
}
else
{
GPIOC->DIR &= ~(0x01 << n);
}
if (pull_up == 1)
PORT->PORTC_PULLU |= (0x01 << n);
else
PORT->PORTC_PULLU &= ~(0x01 << n);
break;
case ((uint32_t)GPIOM):
SYS->CLKEN |= (0x01 << SYS_CLKEN_GPIOM_Pos);
PORT_Init(PORTM, n, 0, 1); //PORTM.PINn<4E><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪGPIO<49><4F><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA>
if (dir == 1)
{
GPIOM->DIR |= (0x01 << n);
}
else
{
GPIOM->DIR &= ~(0x01 << n);
}
if (pull_up == 1)
PORT->PORTM_PULLU |= (0x01 << n);
else
PORT->PORTM_PULLU &= ~(0x01 << n);
break;
case ((uint32_t)GPION):
SYS->CLKEN |= (0x01 << SYS_CLKEN_GPION_Pos);
PORT_Init(PORTN, n, 0, 1); //PORTN.PINn<4E><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪGPIO<49><4F><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA>
if (dir == 1)
{
GPION->DIR |= (0x01 << n);
}
else
{
GPION->DIR &= ~(0x01 << n);
}
if (pull_down == 1)
PORT->PORTN_PULLD |= (0x01 << n);
else
PORT->PORTN_PULLD &= ~(0x01 << n);
break;
case ((uint32_t)GPIOP):
SYS->CLKEN |= (0x01 << SYS_CLKEN_GPIOP_Pos);
PORT_Init(PORTP, n, 0, 1); //PORTP.PINn<4E><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪGPIO<49><4F><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA>
if (dir == 1)
{
GPIOP->DIR |= (0x01 << n);
}
else
{
GPIOP->DIR &= ~(0x01 << n);
}
if (pull_up == 1)
PORT->PORTP_PULLU |= (0x01 << n);
else
PORT->PORTP_PULLU &= ~(0x01 << n);
break;
}
}
/******************************************************************************************************************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: GPIO_SetBit()
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>ƽ<EFBFBD>ø<EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: GPIO_TypeDef * GPIOx ָ<EFBFBD><EFBFBD>GPIO<EFBFBD>˿ڣ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIOA<EFBFBD><EFBFBD>GPIOB<EFBFBD><EFBFBD>GPIOC<EFBFBD><EFBFBD>GPIOM<EFBFBD><EFBFBD>GPION<EFBFBD><EFBFBD>GPIOP
* uint32_t n ָ<EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>PIN0<EFBFBD><EFBFBD>PIN1<EFBFBD><EFBFBD>PIN2<EFBFBD><EFBFBD>... ... PIN22<EFBFBD><EFBFBD>PIN23
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
******************************************************************************************************************************************/
void GPIO_SetBit(GPIO_TypeDef *GPIOx, uint32_t n)
{
GPIOx->DATA |= (0x01 << n);
}
/******************************************************************************************************************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: GPIO_ClrBit()
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>ƽ<EFBFBD>õ<EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: GPIO_TypeDef * GPIOx ָ<EFBFBD><EFBFBD>GPIO<EFBFBD>˿ڣ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIOA<EFBFBD><EFBFBD>GPIOB<EFBFBD><EFBFBD>GPIOC<EFBFBD><EFBFBD>GPIOM<EFBFBD><EFBFBD>GPION<EFBFBD><EFBFBD>GPIOP
* uint32_t n ָ<EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>PIN0<EFBFBD><EFBFBD>PIN1<EFBFBD><EFBFBD>PIN2<EFBFBD><EFBFBD>... ... PIN22<EFBFBD><EFBFBD>PIN23
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
******************************************************************************************************************************************/
void GPIO_ClrBit(GPIO_TypeDef *GPIOx, uint32_t n)
{
GPIOx->DATA &= ~(0x01 << n);
}
/******************************************************************************************************************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: GPIO_InvBit()
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>ƽ<EFBFBD><EFBFBD>ת
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: GPIO_TypeDef * GPIOx ָ<EFBFBD><EFBFBD>GPIO<EFBFBD>˿ڣ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIOA<EFBFBD><EFBFBD>GPIOB<EFBFBD><EFBFBD>GPIOC<EFBFBD><EFBFBD>GPIOM<EFBFBD><EFBFBD>GPION<EFBFBD><EFBFBD>GPIOP
* uint32_t n ָ<EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>PIN0<EFBFBD><EFBFBD>PIN1<EFBFBD><EFBFBD>PIN2<EFBFBD><EFBFBD>... ... PIN22<EFBFBD><EFBFBD>PIN23
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
******************************************************************************************************************************************/
void GPIO_InvBit(GPIO_TypeDef *GPIOx, uint32_t n)
{
GPIOx->DATA ^= (0x01 << n);
}
/******************************************************************************************************************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: GPIO_GetBit()
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĵ<EFBFBD>ƽ״̬
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: GPIO_TypeDef * GPIOx ָ<EFBFBD><EFBFBD>GPIO<EFBFBD>˿ڣ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIOA<EFBFBD><EFBFBD>GPIOB<EFBFBD><EFBFBD>GPIOC<EFBFBD><EFBFBD>GPIOM<EFBFBD><EFBFBD>GPION<EFBFBD><EFBFBD>GPIOP
* uint32_t n ָ<EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>PIN0<EFBFBD><EFBFBD>PIN1<EFBFBD><EFBFBD>PIN2<EFBFBD><EFBFBD>... ... PIN22<EFBFBD><EFBFBD>PIN23
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĵ<EFBFBD>ƽ״̬ 0 <EFBFBD>͵<EFBFBD>ƽ 1 <EFBFBD>ߵ<EFBFBD>ƽ
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
******************************************************************************************************************************************/
uint32_t GPIO_GetBit(GPIO_TypeDef *GPIOx, uint32_t n)
{
return ((GPIOx->DATA >> n) & 0x01);
}
/******************************************************************************************************************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: GPIO_SetBits()
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>n<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĵ<EFBFBD>ƽ<EFBFBD>ø<EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: GPIO_TypeDef * GPIOx ָ<EFBFBD><EFBFBD>GPIO<EFBFBD>˿ڣ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIOA<EFBFBD><EFBFBD>GPIOB<EFBFBD><EFBFBD>GPIOC<EFBFBD><EFBFBD>GPIOM<EFBFBD><EFBFBD>GPION<EFBFBD><EFBFBD>GPIOP
* uint32_t n ָ<EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>PIN0<EFBFBD><EFBFBD>PIN1<EFBFBD><EFBFBD>PIN2<EFBFBD><EFBFBD>... ... PIN22<EFBFBD><EFBFBD>PIN23
* uint32_t w ָ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>ƽ<EFBFBD>øߵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĸ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
******************************************************************************************************************************************/
void GPIO_SetBits(GPIO_TypeDef *GPIOx, uint32_t n, uint32_t w)
{
uint32_t bits;
bits = 0xFFFFFF >> (24 - w);
GPIOx->DATA |= (bits << n);
}
/******************************************************************************************************************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: GPIO_ClrBits()
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>n<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĵ<EFBFBD>ƽ<EFBFBD>õ<EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: GPIO_TypeDef * GPIOx ָ<EFBFBD><EFBFBD>GPIO<EFBFBD>˿ڣ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIOA<EFBFBD><EFBFBD>GPIOB<EFBFBD><EFBFBD>GPIOC<EFBFBD><EFBFBD>GPIOM<EFBFBD><EFBFBD>GPION<EFBFBD><EFBFBD>GPIOP
* uint32_t n ָ<EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>PIN0<EFBFBD><EFBFBD>PIN1<EFBFBD><EFBFBD>PIN2<EFBFBD><EFBFBD>... ... PIN22<EFBFBD><EFBFBD>PIN23
* uint32_t w ָ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>ƽ<EFBFBD>õ͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĸ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
******************************************************************************************************************************************/
void GPIO_ClrBits(GPIO_TypeDef *GPIOx, uint32_t n, uint32_t w)
{
uint32_t bits;
bits = 0xFFFFFF >> (24 - w);
GPIOx->DATA &= ~(bits << n);
}
/******************************************************************************************************************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: GPIO_InvBits()
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>n<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĵ<EFBFBD>ƽ<EFBFBD><EFBFBD>ת
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: GPIO_TypeDef * GPIOx ָ<EFBFBD><EFBFBD>GPIO<EFBFBD>˿ڣ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIOA<EFBFBD><EFBFBD>GPIOB<EFBFBD><EFBFBD>GPIOC<EFBFBD><EFBFBD>GPIOM<EFBFBD><EFBFBD>GPION<EFBFBD><EFBFBD>GPIOP
* uint32_t n ָ<EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>PIN0<EFBFBD><EFBFBD>PIN1<EFBFBD><EFBFBD>PIN2<EFBFBD><EFBFBD>... ... PIN22<EFBFBD><EFBFBD>PIN23
* uint32_t w ָ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>ƽ<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĸ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
******************************************************************************************************************************************/
void GPIO_InvBits(GPIO_TypeDef *GPIOx, uint32_t n, uint32_t w)
{
uint32_t bits;
bits = 0xFFFFFF >> (24 - w);
GPIOx->DATA ^= (bits << n);
}
/******************************************************************************************************************************************
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: GPIO_GetBits()
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>n<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĵ<EFBFBD>ƽ״̬
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: GPIO_TypeDef * GPIOx ָ<EFBFBD><EFBFBD>GPIO<EFBFBD>˿ڣ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIOA<EFBFBD><EFBFBD>GPIOB<EFBFBD><EFBFBD>GPIOC<EFBFBD><EFBFBD>GPIOM<EFBFBD><EFBFBD>GPION<EFBFBD><EFBFBD>GPIOP
* uint32_t n ָ<EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD>Чֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>PIN0<EFBFBD><EFBFBD>PIN1<EFBFBD><EFBFBD>PIN2<EFBFBD><EFBFBD>... ... PIN22<EFBFBD><EFBFBD>PIN23
* uint32_t w ָ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>ƽ<EFBFBD>øߵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĸ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>n<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĵ<EFBFBD>ƽ״̬ 0 <EFBFBD>͵<EFBFBD>ƽ 1 <EFBFBD>ߵ<EFBFBD>ƽ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ĵ<EFBFBD>0λ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>n<EFBFBD>ĵ<EFBFBD>ƽ״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ĵ<EFBFBD>1λ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>n+1<EFBFBD>ĵ<EFBFBD>ƽ״̬... ...<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>n+w<EFBFBD>ĵ<EFBFBD>ƽ״̬
* ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD>
******************************************************************************************************************************************/
uint32_t GPIO_GetBits(GPIO_TypeDef *GPIOx, uint32_t n, uint32_t w)
{
uint32_t bits;
bits = 0xFFFFFF >> (24 - w);
return ((GPIOx->DATA >> n) & bits);
}