1. 程式人生 > >全志R16平臺的GPIO操作

全志R16平臺的GPIO操作

全志R16初始化LCD遇到的GPIO操作

1.首先要用script_get_item( "lcd0_para", "lcd_spi_cs", &m_spi_cs_info );獲取到在sys_config,fex的gpio,

2.第二步如下gpio_mux_gpio(&m_spi_cs_info );這一步可參考r16的R16_pinctl使用說明.

static int gpio_mux_gpio( script_item_u *info )
{
	u32 config;
	int ret;
	struct gpio_config pin_cfg;
	char   pin_name[32];
        pin_cfg.gpio = info->gpio.gpio;
        pin_cfg.mul_sel = info->gpio.mul_sel;
        pin_cfg.pull = info->gpio.pull;
        pin_cfg.drv_level = info->gpio.drv_level;
        pin_cfg.data = info->gpio.data;
        //config
	sunxi_gpio_to_name(pin_cfg.gpio, pin_name);
        config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC, pin_cfg.mul_sel);
        pin_config_set(SUNXI_PINCTRL, pin_name, config);
        if (pin_cfg.pull != GPIO_PULL_DEFAULT) {
		config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_PUD, pin_cfg.pull);
		pin_config_set(SUNXI_PINCTRL, pin_name, config);
	}
	if (pin_cfg.drv_level != GPIO_DRVLVL_DEFAULT) {
		config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_DRV, pin_cfg.drv_level);
		pin_config_set(SUNXI_PINCTRL, pin_name, config);
	}
	if (pin_cfg.data != GPIO_DATA_DEFAULT) {
		config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_DAT, pin_cfg.data);
		pin_config_set(SUNXI_PINCTRL, pin_name, config);
	}
	return 0;
}

3.第三步:
 ret = gpio_request( m_spi_cs_info.gpio.gpio, NULL );
        pr_info( "gpio request lcd spi cs ret = %d, %d\n", m_spi_cs_info.gpio.gpio, ret );
4.第四步就是設定gpio為輸出,和拉高拉低
   gpio_direction_output( m_spi_cs_info.gpio.gpio, 1 );
 __gpio_set_value( m_spi_cs_info.gpio.gpio, 1 );