stm32库函数之GPIO | 您所在的位置:网站首页 › gpio_otype_pp › stm32库函数之GPIO |
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
{
/*初始化各个变量*/
uint32_t currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00;
uint32_t tmpreg = 0x00, pinmask = 0x00;
//currentmode 用于存放临时的GPIO_Mode、GPIO_Speed的数据
//currentpin 用于存放配置的引脚位
//pinpos 用于存放当前操作的引脚号
//pos 存放当前操作的引脚位
//tmreg 当前的CIR
//pinmask
//判断参数
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin)); //读取并保存配置的GPIO_Mode的数据并且只取它的低4位(参考CRL、CRH寄存器就理解了),屏蔽掉高4位 currentmode = ((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x0F); if ((((uint32_t)GPIO_OInitStruct->GPIO_Mode) & ((uint32_t)0x10)) != 0x00) //判断是否为输出模式(根据那8种模式的定义可知,输出模式的值分别为:0x14、0x10、0x1C、0x18) { //判断参数 assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed)); //将配置的GPIO_Speed信息放入currentmode低二位 currentmode |= (uint32_t)GPIO_InitStruct->GPIO_Speed; } if (((uint32_t)GPIO_InitStruct->GPIO_Pin & ((uint32_t)0x00FF)) != 0x00) //判断引脚是否有定义,并且端口号为0~7 { tmpreg = GPIOx->CRL;//读出CRL寄存器中的值,并保存 //循环低八位引脚 for (pinpos = 0x00; pinpos < 0x08; pinpos++) { //当前是那个引脚,那个位置1 pos = ((uint32_t)0x01) |
CopyRight 2018-2019 实验室设备网 版权所有 |