您好!
是否有人可以分享使用 PDK GPIO 驱动程序切换 GPIO 和配置 GPIO 中断的简单步骤。
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.
您好!
是否有人可以分享使用 PDK GPIO 驱动程序切换 GPIO 和配置 GPIO 中断的简单步骤。
切换 GPIO 引脚
要使用 GPIO 驱动程序切换 GPIO 引脚、请执行以下步骤:
1、引脚复用
确保您使用的引脚设置为 GPIO 模式。 您可以使用来自电路板库的以下 API。
Board_pinmuxSetReg(SOC_DOMAIN, OFFSET, MODE);
2. 设置基地址
根据 GPIO 实例所在的域设置基址。
GPIO_socGetInitCfg(Port, &gpio_cfg); gpio_cfg.baseAddr = CSL_xxxx_GPIO0_BASE; GPIO_socSetInitCfg(Port, &gpio_cfg); Where Port is GPIO instance in the given domain
GPIO 初始化
执行 GPIO 初始化。 在调用 GPIO 初始化之前、请确保定义了以下结构。
GPIO_PinConfig gpioPinConfigs[] = { PIN | DIR, PIN | DIR, …. …. };
其中 PIN 应为十六进制值0xABCD
其中 AB 代表端口号、CD 代表引脚编号。 例如、对于配置 WKUP_GPIO0_16:Pin = 0x0010且 DIR = GPIO_CFG_OUTPUT 或 GPIO_CFG_INPUT
GPIO_CallbackFxn gpioCallbackFunctions[] = { NULL, NULL };
您可以使用此结构设置回调函数、但对于此用例、我们可以将其保留为 NULL
GPIO_v0_Config{ GPIO_PinConfig *pinConfigs; /*! Pointer to the board's PinConfig array */ GPIO_CallbackFxn *callbacks; /*! Pointer to the board's callback array */ uint32_t numberOfPinConfigs; /*! Number of pin configs defined */ uint32_t numberOfCallbacks; /*! Number of callbacks defined */ /*! Interrupt priority used for call back interrupts. Setting ~0 will * configure the lowest possible priority */ uint32_t intPriority; }
调用 GPIO_init();
4.调用 GPIO_write (PIN_INDEX、0/1);以更改 GPIO 的状态
在这里、PIN_INDEX 是 要更改其状态的 gpioPinConfigs 结构的索引。
配置 GPIO 中断
gpio_cfg.baseAddr = CSL_xxxx_GPIO0_BASE; intCfg = gpio_cfg.intCfg; bankNum = PinNumber/16; intCfg[PinNumber].intNum = IntRTR_OUTPUT_0 + bankNum; intCfg[PinNumber].intcMuxNum = INVALID_INTC_MUX_NUM; intCfg[PinNumber].intcMuxInEvent = 0; intCfg[PinNumber].intcMuxOutEvent = 0;
其中 PIN_INDEX 是 要更改其状态的 gpioPinConfigs 结构的索引。