LinuxÏ¿ØÖÆGPIOµÄÒªÁì
linuxÏ¿ÉÒÔʹÓá°sysfs½Ó¿Ú¡±¡¢¡°gpio¿â¡±¡¢¡°×°±¸Ê÷¡±ºÍ¡°Ö±½Ó»á¼û¼Ä´æÆ÷¡±4ÖÖÒªÁìÀ´¿ØÖÆgpio£º1¡¢Í¨¹ý/sys/class/gpioĿ¼ÏµÄÎļþ£¬¿ÉÒÔ»á¼ûºÍ¿ØÖÆgpioÒý½Å£»2¡¢¿ªÔ´µÄgpio¿â¿ÉÒÔ¼ò»¯gpioµÄ¿ØÖÆ£¬Ê¹µÃÔÚlinuxϵͳÉϱà³Ì¿ØÖÆgpioÔ½·¢Àû±ã£»3¡¢¿ÉÒÔ±à¼×°±¸Ê÷Îļþ£¬½ç˵gpioµÄÊôÐԺ͹¦Ð§£¬²¢ÔÚϵͳÆô¶¯Ê±¼ÓÔØ×°±¸Ê÷µÈµÈ¡£
LinuxÏ£¬¿ÉÒÔʹÓÃÒÔϼ¸ÖÖÒªÁìÀ´¿ØÖÆGPIO£¨Í¨ÓÃÊäÈëÊä³ö£©£º
Sysfs½Ó¿Ú£ºSysfsÊÇLinuxÄÚºËÌṩµÄÒ»ÖÖÎļþϵͳ½Ó¿Ú£¬ÓÃÓÚÓë×°±¸Çý¶¯³ÌÐò¾ÙÐн»»¥¡£Í¨¹ý/sys/class/gpioĿ¼ÏµÄÎļþ£¬¿ÉÒÔ»á¼ûºÍ¿ØÖÆGPIOÒý½Å¡£Äã¿ÉÒÔʹÓÃShellÏÂÁî»ò±à³ÌÓïÑÔ£¨ÀýÈçPython£©À´¶ÁÈ¡»òдÈëÕâЩÎļþ£¬ÒÔ¿ØÖÆGPIOµÄ״̬¡£
GPIO¿â£ºÓÐһЩ¿ªÔ´µÄGPIO¿â¿ÉÒÔ¼ò»¯GPIOµÄ¿ØÖÆ¡£ÀýÈ磬WiringPi¡¢RPi.GPIOºÍlibgpiodµÈ¿âÌṩÁ˺¯ÊýºÍ½Ó¿Ú£¬Ê¹µÃÔÚLinuxϵͳÉϱà³Ì¿ØÖÆGPIOÔ½·¢Àû±ã¡£Äã¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇóÑ¡ÔñÊʺϵĿ⣬²¢Æ¾Ö¤ÆäÎĵµ¾ÙÐÐ×°ÖúÍʹÓá£
×°±¸Ê÷£¨Device Tree£©£º¹ØÓÚһЩǶÈëʽϵͳ£¬GPIOµÄÓ³ÉäºÍÉèÖÃÐÅϢͨ³£´æ´¢ÔÚ×°±¸Ê÷ÖС£Äã¿ÉÒÔ±à¼×°±¸Ê÷Îļþ£¬½ç˵GPIOµÄÊôÐԺ͹¦Ð§£¬²¢ÔÚϵͳÆô¶¯Ê±¼ÓÔØ×°±¸Ê÷£¬Ê¹µÃGPIOÄܹ»±»×¼È·µØ³õʼ»¯ºÍʹÓá£
Ö±½Ó»á¼û¼Ä´æÆ÷£ºÔÚһЩÌض¨µÄǶÈëʽƽ̨ÉÏ£¬Äã¿ÉÒÔÖ±½Ó»á¼ûGPIOÏà¹ØµÄÎïÀí¼Ä´æÆ÷À´¾ÙÐпØÖÆ¡£ÕâÐèÒª¶ÔÓ²¼þºÍµ×²ãϵͳÓиüÉîÈëµÄÏàʶ£¬Òò´ËÐèÒªÉóÉ÷²Ù×÷¡£
ÐèҪעÖصÄÊÇ£¬GPIOµÄ¿ØÖÆÐèÒªÌØȨȨÏÞ£¨Í¨³£ÊÇroot»ò¾ß±¸ÏìӦȨÏÞµÄÓû§£©²Å»ªÖ´ÐС£ÔÚ±à³ÌÀú³ÌÖУ¬Äã¿ÉÄÜÐèҪʹÓÃÊʵ±µÄȨÏÞ»òÉèÖã¬ÒÔÈ·±£¶ÔGPIO¾ÙÐлá¼ûºÍ¿ØÖÆ¡£
Çë¼Ç×Å£¬ÔÚ²Ù×÷GPIOʱ£¬ÒªÐ¡ÐÄ×èÖ¹¹ýʧ²Ù×÷£¬ÒÔÃâÔì³ÉË𻵻ò²»Á¼Ó°Ïì¡£ÔÚʹÓÃGPIOÇ°£¬½¨ÒéÏÈÏàʶӲ¼þ¹æ¸ñºÍÏà¹ØÎĵµ£¬²¢Æ¾Ö¤×¼È·µÄÒªÁì¾ÙÐпØÖƺͲÙ×÷¡£
ÒÔÉϾÍÊÇLinuxÏ¿ØÖÆGPIOµÄÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡