7.4.2. 参数配置

因为 GPIO 是每个系统的必需模块,GPIO 驱动默认会被编译进系统,所以不需要在 scons --menuconfig 菜单中进行使能。

7.4.2.1. GPIO Irq 驱动配置

GPIO 中断注册的功能可以单独使能

在 ZX-RTT 根目录下执行 scons –menuconfig,进入menuconfig的功能配置界面,按如下选择:

Drivers options  --->
    [*] support gpio irq register

7.4.2.2. 目标板 PinMux 配置

具体的配置路径于 zx-rtt\target\$chip\$board\pinmux.c

ZX-RTT 中会把当前单板的所有 PinMux 配置进行集中配置,例如:

struct aic_pinmux aic_pinmux_config[] = {
#ifdef AIC_USING_UART0
    /* uart0 */
    {5, PIN_PULL_DIS, 3, "PA.0"},
    {5, PIN_PULL_DIS, 3, "PA.1"},
#endif
#ifdef AIC_USING_I2C3
    {1, PIN_PULL_DIS, 3, "PA.8"},  // RST
    {1, PIN_PULL_DIS, 3, "PA.9"},  // INT
    {4, PIN_PULL_DIS, 3, "PA.10"}, // SCK
    {4, PIN_PULL_DIS, 3, "PA.11"}, // SDA
#endif
};

void aic_board_pinmux_init(void)
{
    uint32_t i = 0;
    long pin = 0;
    unsigned int g;
    unsigned int p;

    // 统一配置 pin 脚的 function mode/pull bias/drive strength
    for (i=0; i<ARRAY_SIZE(aic_pinmux_config); i++) {
        pin = hal_gpio_name2pin(aic_pinmux_config[i].name);
        if (pin < 0)
            continue;
        g = GPIO_GROUP(pin);
        p = GPIO_GROUP_PIN(pin);
        hal_gpio_set_func(g, p, aic_pinmux_config[i].func);
        hal_gpio_set_bias_pull(g, p, aic_pinmux_config[i].bias);
        hal_gpio_set_drive_strength(g, p, aic_pinmux_config[i].drive);
    }
}

7.4.2.3. GPIO 管脚配置

某些驱动模块需要用到通用 GPIO 管脚,并且不同单板下的管脚还不同。这种情况的配置分为两步:

  1. 首先在 scons --menuconfig 模块驱动的配置中,配置 gpio 名称。例如:

Board options  --->
    [*] Using Gmac0
        gmac0 parameter  --->
            (PE.6) gmac0 phy reset gpio     // 配置 gpio 名称,字符串要遵循实例格式
  1. 在驱动模块初始化时,通过解析字符串得到正确的 gpio pin 编号,并进行配置。例如:

pin = hal_gpio_name2pin(AIC_DEV_GMAC0_PHYRST_GPIO); // 根据 gpio 名称,转换成 gpio id 编号
g = GPIO_GROUP(pin);
p = GPIO_GROUP_PIN(pin);

hal_gpio_direction_output(g, p);                    // 配置 gpio 为输出模式
hal_gpio_clr_output(g, p);                          // 设置 gpio 输出电平
aicos_mdelay(50);
hal_gpio_set_output(g, p);
aicos_mdelay(50);