S3C6410 GPIO配置

6410的GPIO使用


一,每组GPIO的数目:
       #define S3C64XX_GPIO_A_NR (8)
       #define S3C64XX_GPIO_B_NR (7)
       #define S3C64XX_GPIO_C_NR (8)
       #define S3C64XX_GPIO_D_NR (5)
       #define S3C64XX_GPIO_E_NR (5)
       #define S3C64XX_GPIO_F_NR (16)
       #define S3C64XX_GPIO_G_NR (7)
       #define S3C64XX_GPIO_H_NR (10)
       #define S3C64XX_GPIO_I_NR (16)
       #define S3C64XX_GPIO_J_NR (12)
       #define S3C64XX_GPIO_K_NR (16)
       #define S3C64XX_GPIO_L_NR (15)
       #define S3C64XX_GPIO_M_NR (6)
       #define S3C64XX_GPIO_N_NR (16)
       #define S3C64XX_GPIO_O_NR (16)
       #define S3C64XX_GPIO_P_NR (15)
       #define S3C64XX_GPIO_Q_NR (9)
二,每组GPIO的起始号码
    #define S3C64XX_GPIO_NEXT(__gpio) /
    ((__gpio##_START) + (__gpio##_NR) + CONFIG_S3C_GPIO_SPACE + 1)
       用黏贴符号来运算的,以A组的0起始,依次加每组的GPIO个数
     enum s3c_gpio_number {
        S3C64XX_GPIO_A_START = 0,
        S3C64XX_GPIO_B_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_A),
        S3C64XX_GPIO_C_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_B),
        S3C64XX_GPIO_D_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_C),
        S3C64XX_GPIO_E_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_D),
        S3C64XX_GPIO_F_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_E),
        S3C64XX_GPIO_G_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_F),
        S3C64XX_GPIO_H_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_G),
        S3C64XX_GPIO_I_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_H),
        S3C64XX_GPIO_J_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_I),
        S3C64XX_GPIO_K_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_J),
        S3C64XX_GPIO_L_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_K),
        S3C64XX_GPIO_M_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_L),
        S3C64XX_GPIO_N_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_M),
        S3C64XX_GPIO_O_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_N),
        S3C64XX_GPIO_P_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_O),
        S3C64XX_GPIO_Q_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_P),
       };
三,单个GPIO脚的号码
     以单组的起始号
         #define S3C64XX_GPA(_nr) (S3C64XX_GPIO_A_START + (_nr))
         #define S3C64XX_GPB(_nr) (S3C64XX_GPIO_B_START + (_nr))
         #define S3C64XX_GPC(_nr) (S3C64XX_GPIO_C_START + (_nr))
         #define S3C64XX_GPD(_nr) (S3C64XX_GPIO_D_START + (_nr))
         #define S3C64XX_GPE(_nr) (S3C64XX_GPIO_E_START + (_nr))
         #define S3C64XX_GPF(_nr) (S3C64XX_GPIO_F_START + (_nr))
         #define S3C64XX_GPG(_nr) (S3C64XX_GPIO_G_START + (_nr))
         #define S3C64XX_GPH(_nr) (S3C64XX_GPIO_H_START + (_nr))
         #define S3C64XX_GPI(_nr) (S3C64XX_GPIO_I_START + (_nr))
         #define S3C64XX_GPJ(_nr) (S3C64XX_GPIO_J_START + (_nr))
         #define S3C64XX_GPK(_nr) (S3C64XX_GPIO_K_START + (_nr))
         #define S3C64XX_GPL(_nr) (S3C64XX_GPIO_L_START + (_nr))
         #define S3C64XX_GPM(_nr) (S3C64XX_GPIO_M_START + (_nr))
         #define S3C64XX_GPN(_nr) (S3C64XX_GPIO_N_START + (_nr))
         #define S3C64XX_GPO(_nr) (S3C64XX_GPIO_O_START + (_nr))
         #define S3C64XX_GPP(_nr) (S3C64XX_GPIO_P_START + (_nr))
         #define S3C64XX_GPQ(_nr) (S3C64XX_GPIO_Q_START + (_nr))
四,判断GPIO是否有效

     比如:if (gpio_is_valid(S3C64XX_GPB(0)))
      static inline int gpio_is_valid(int number)    
      {                                              
            return ((unsigned)number) < ARCH_NR_GPIOS;   
      }   
      因为定义了#define ARCH_NR_GPIOS (S3C64XX_GPQ(S3C64XX_GPIO_Q_NR) + 1)    
      同样类似的范围定义有:
      #define S3C64XX_GPIO_END (S3C64XX_GPQ(S3C64XX_GPIO_Q_NR) + 1)                                     
      #define S3C_GPIO_END  S3C64XX_GPIO_END    
五,判断GPIO是否被占用
      比如:if(gpio_request(S3C64XX_GPB(0), "GPB")),通过查看该GPIO保存的记录标志是否为NULL来判断。
六,配置GPIO用途
      由于GPIO多复用,所以不管是把它当作GPIO使用时,还是当作中断亦或通讯口,需要配置它的用途。比如:s3c_gpio_cfgpin(S3C64XX_GPB(0), 0x2);根据芯片规格书来配置其端口。所有的这些配置工作在Gpiolib.c (/arch/arm/plat-s3c64xx) 来完成的。
七,上下拉

      有的GPIO口可以内部配置成上拉或者下拉,这样就不需要外部再接电阻连线。配置成上拉时,驱动能力更强。配置上下拉对外部接口来说呈现的只是一种默认的电平,其本身可以对外输出高低由软件控制,就像I2C。
      比如:s3c_gpio_setpull(S3C64XX_GPB(0), S3C_GPIO_PULL_DOWN);
八,配置成外中断
     s3c_gpio_cfgpin(HdPhone_GpioPin, S3C_GPIO_SFN(2));
     set_irq_type(HdPhone_EintPin, IRQ_TYPE_EDGE_BOTH); //中断边沿类型
     具体应用的话还需要用request_irq注册对应的中断处理函数。

八,配置GPIO方向,输入和输出
      比如:gpio_direction_output(S3C64XX_GPL(0), 1);
九,使用GPIO
     比如输出:gpio_set_value(S3C64XX_GPG(1), 1);  或者是输入:gpio_get_value(S3C64XX_GPQ(8))

十,释放GPIO
     比如:gpio_free(S3C64XX_GPF(15));就是把对应GPIO口的控制标志FLAG_REQUESTED清掉,成NULL,之后可以再被其他调用。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值