ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

LinuxÏÂGPIOÇý¶¯Ïê½âÎÄÕÂ(Ò»)
2014-11-24 11:39:33 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:2´Î
Tags£ºLinux GPIO Çý¶¯ Ïê½â ÎÄÕÂ

***************************************************************************


×¢Ò⣺ÔÚ/arch/arm/mach-s3c2410/include/mach/gpio-fns.hÔ´´úÂëÖÐÓÐÈçÏÂ˵Ã÷£º


16/* These functions are in the to-be-removed category and it is strongly
17 * encouraged not to use these in new code. They will be marked deprecated
18 * very soon.
19 *
20 * Most of the functionality can be either replaced by the gpiocfg calls
21 * for the s3c platform or by the generic GPIOlib API.
22 *
23 * As of 2.6.35-rc, these will be removed, with the few drivers using them
24 * either replaced or given a wrapper until the calls can be removed.
25*/



¸ÃÍ·Îļþ°üÀ¨£º


static inline void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int cfg)


¸Ãº¯ÊýÖ±½ÓʹÓÃ


linux/arch/arm/plat-s3c/gpio-config.cÖеÄ


int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)


¼´¿É



***************************************************************************



Ê×ÏÈ¿´Ò»ÏÂÉ豸³õʼ»¯³ÌÐò£º


85 /*
86 * É豸³õʼ»¯
87 */

88 static int __init dev_init(void)
89 {
90 int ret;
91 int i;
92 for (i = 0; i < 4; i++) {
93 //ÉèÖà LED ¶ÔÓ¦µÄ¶Ë¿Ú¼Ä´æÆ÷ΪÊä³ö(OUTPUT)
94
if (s3c_gpio_cfgpin(led_table[i], led_cfg_table[i])<0)


printk(KERN_INFO "config pin %d failed", i);



95 printk(KERN_INFO "config pin %d failed", i);

95 //ÉèÖà LED ¶ÔÓ¦µÄ¶Ë¿Ú¼Ä´æÆ÷ΪµÍµçƽÊä³ö£¬ÔÚÄ£¿é¼ÓÔØ> ½áÊøºó£¬Ëĸö LED Ó¦¸ÃÊÇÈ«²¿¶¼ÊÇ·¢¹â
96 ״̬
97 s3c2410_gpio_setpin(led_table[i], 0);
98 }
99 ret = misc_register(&misc); //×¢²áÉ豸
100 printk (DEVICE_NAME"/tinitialized/n"); //´òÓ¡³õʼ»¯ÐÅÏ¢
101 return ret;
102 }



¿ÉÒÔ¿´µ½£¬ÕâÀïÉæ¼°µ½Á½¸öº¯Êý£¬·Ö±ðÊÇs3c2410_gpio_cfgpin,s3c2410_gpio_setpin£¬ÕâÁ½¸öº¯Êý·Ö±ð¶ÔËĸöLED½øÐÐÅäÖ㬴Ӻ¯ÊýÃûÀ´¿´£¬cfgpin¶ÔÒý½Å¼Ä´æÆ÷״̬½øÐÐÅäÖ㬶øsetpinÓ¦¸ÃÊǶԼĴæÆ÷Êý¾ÝÖµ½øÐÐÅäÖã¬ÎÒÃÇÔÚ·ÖÎöº¯Êý֮ǰÏÈŪÇå³þ´«ÈëµÄ²ÎÊýµ½µ×ÊÇʲô¡£


led_table[i]
28 //LED ¶ÔÓ¦µÄ GPIO ¶Ë¿ÚÁбí
29 static unsigned long led_table [] = {
30 S3C2410_GPB(5),
31 S3C2410_GPB(6),
32 S3C2410_GPB(7),
33 S3C2410_GPB(8),
34 };


ÕâÀïS3C2410_GPBºê¶¨ÒåÔÚmach/gpio-nrs.hÖÐ
/* GPIO bank sizes */
#define S3C2410_GPIO_A_NR (32)
#define S3C2410_GPIO_B_NR (32)
#define S3C2410_GPIO_C_NR (32)
#define S3C2410_GPIO_D_NR (32)
#define S3C2410_GPIO_E_NR (32)
#define S3C2410_GPIO_F_NR (32)
#define S3C2410_GPIO_G_NR (32)
#define S3C2410_GPIO_H_NR (32)
#define S3C2410_GPIO_J_NR (32) /* technically 16. */
#define S3C2410_GPIO_K_NR (32) /* technically 16. */
#define S3C2410_GPIO_L_NR (32) /* technically 15. */
#define S3C2410_GPIO_M_NR (32) /* technically 2. */



#if CONFIG_S3C_GPIO_SPACE != 0
#error CONFIG_S3C_GPIO_SPACE cannot be zero at the moment
#endif



#define S3C2410_GPIO_NEXT(__gpio) /
((__gpio##_START) + (__gpio##_NR) + CONFIG_S3C_GPIO_SPACE + 0)



//ÕâÀïµÄCONFIG_S3C_GPIO_SPACÊÇÄÚºËÅäÖÃÑ¡ÏÔÚ.configÖпÉÒÔÕÒµ½£¬ÎÒµÄÅäÖÃΪ£º


CONFIG_S3C_GPIO_SPACE = 0



enum s3c_gpio_number {
S3C2410_GPIO_A_START = 0,
S3C2410_GPIO_B_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_A),
S3C2410_GPIO_C_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_B),
S3C2410_GPIO_D_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_C),
S3C2410_GPIO_E_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_D),
S3C2410_GPIO_F_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_E),
S3C2410_GPIO_G_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_F),
S3C2410_GPIO_H_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_G),
S3C2410_GPIO_J_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_H),
S3C2410_GPIO_K_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_J),
S3C2410_GPIO_L_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_K),
S3C2410_GPIO_M_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_L),
};


#define S3C2410_GPB(_nr) (S3C2410_GPIO_B_START + (_nr))


Òò´Ë£¬ÒÔS3C2410_GPB(5)ΪÀý£¬ÆäºêÕ¹¿ªÎª£º


S3C2410_GPIO_NEXT(S3C2410_GPIO_A) +

Ê×Ò³ ÉÏÒ»Ò³ 1 2 3 4 ÏÂÒ»Ò³ βҳ 1/4/4
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£º±àÒëAndroid 2.3.1 Ô´´úÂëÐĵà ÏÂһƪ£ºLinux 0.12ÖÐbreadº¯ÊýÁ÷³Ì

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Spring Boot Java£º (2025-12-26 16:20:19)
¡¤Spring Boot¤ÇHello (2025-12-26 16:20:15)
¡¤Spring ¤Î»ù±¾¤«¤éŒ (2025-12-26 16:20:12)
¡¤C++Ä£°å (template) (2025-12-26 15:49:49)
¡¤C ÓïÑÔÖÐÄ£°åµÄ¼¸ÖÖ (2025-12-26 15:49:47)