如下图所示,调试例程里的GPIO程序,109端口对应开发板上的第二个led灯,请问如果要控制另一个灯,怎么找到这个灯的端口号?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
如下图所示,调试例程里的GPIO程序,109端口对应开发板上的第二个led灯,请问如果要控制另一个灯,怎么找到这个灯的端口号?
看一下gpio.c里的函数说明和代码实现,就是一个bank 32个GPIO,从低bank往高排的。
/**
* \brief This function gets the direction of a pin which has been configured
* as an input or an output pin.
*
* \param baseAdd The memory address of the GPIO instance being used.
* \param pinNumber The serial number of the GPIO pin.
* The 144 GPIO pins have serial numbers from 1 to 144.
*
* \return This returns one of the following two values:
* 1> GPIO_DIR_INPUT, if the pin is configured as an input pin.
* 2> GPIO_DIR_OUTPUT, if the pin is configured as an output pin.
unsigned int GPIODirModeGet(unsigned int baseAdd, unsigned int pinNumber)
{
unsigned int dir = GPIO_DIR_INPUT;
unsigned int regNumber = 0;
unsigned int pinOffset = 0;
/*
** Each register contains settings for each pin of two banks. The 32 bits
** represent 16 pins each from the banks. Thus the register number must be
** calculated based on 32 pins boundary.
*/
regNumber = (pinNumber - 1)/32;
/*
** In every register the least significant bits starts with a GPIO number on
** a boundary of 32. Thus the pin offset must be calculated based on 32
** pins boundary. Ex: 'pinNumber' of 1 corresponds to bit 0 in
** 'register_name01'.
*/
pinOffset = (pinNumber - 1) % 32;
dir = (HWREG(baseAdd + GPIO_DIR(regNumber)) & (1 << pinOffset));
return (dir >> pinOffset);