配置时钟:
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
CMU_ClockEnable(cmuClock_HFPER, true); /* Enable GPIO in CMU */ CMU_ClockEnable(cmuClock_GPIO, true);
配置为输入:
void GPIO_PinModeSet(GPIO_Port_TypeDef port,
unsigned int pin,
GPIO_Mode_TypeDef mode,
unsigned int out)
/* Configure PB9 and PB10 as input */ GPIO_PinModeSet(gpioPortB, 9, gpioModeInput, 0); GPIO_PinModeSet(gpioPortB, 10, gpioModeInput, 0);
配置为输出:
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out) GPIO_PinModeSet(ledArray[ledNo].port, ledArray[ledNo].pin, gpioModePushPull, 0);
配置为中断输入:
先配置为输入,再配置中断
GPIO_IntConfig(GPIO_Port_TypeDef port, unsigned int pin, bool risingEdge, bool fallingEdge, bool enable) /* Set falling edge interrupt for both ports */ GPIO_IntConfig(gpioPortB, 9, false, true, true); GPIO_IntConfig(gpioPortB, 10, false, true, true);