{"id":513,"date":"2019-09-23T11:00:38","date_gmt":"2019-09-23T03:00:38","guid":{"rendered":"http:\/\/iqotom.com\/?p=513"},"modified":"2019-11-26T10:29:03","modified_gmt":"2019-11-26T02:29:03","slug":"qotom%e5%b7%a5%e6%8e%a7%e7%94%b5%e8%84%91%e5%ae%89%e8%a3%85gpio-drive","status":"publish","type":"post","link":"http:\/\/iqotom.com\/?p=513","title":{"rendered":"QOTOM\u5de5\u63a7\u7535\u8111\u5b89\u88c5GPIO\u9a71\u52a8"},"content":{"rendered":"\n<p> \u5de5\u63a7\u673a\u578b\u53f7\uff1aQOTOM <a href=\"http:\/\/www.qotom.com\/product\/80.html\">Q350P <\/a>  SIO\u82af\u7247<strong>ITE8786-I<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u95ee\u9898<\/h3>\n\n\n\n<p>Q350P\u5728\u5b89\u88c5ubuntu18.04\u540e\uff0c cat \/<em>sys\/<\/em>kernel\/debug\/gpio \u4e3a\u7a7a \uff0c\u65e0\u6cd5\u4f7f\u7528GPIO\uff0c\u7ecf\u67e5\u662f\u56e0\u4e3a\u7cfb\u7edf\u9ed8\u8ba4\u6ca1\u6709\u5b89\u88c5SIO\u82af\u7247\u9a71\u52a8\uff0c\u8fd9\u91cc\u901a\u8fc7\u5b89\u88c5gpio-it87 drive\u6765\u89e3\u51b3\u3002<br><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"227\" class=\"wp-image-515\" style=\"width: 800px;\" src=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-02.png\" alt=\"\" srcset=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-02.png 649w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-02-300x85.png 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b89\u88c5\u6b65\u9aa4<\/h3>\n\n\n\n<p><strong>1.\u4e0b\u8f7d\u6e90\u4ee3\u7801<\/strong> <a href=\"https:\/\/www.kernel.org\/\">https:\/\/www.kernel.org\/<\/a>  \u8fd9\u91cc\u4f7f\u75284.19.23<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/usr\/src\nroot@tiger:\/usr\/src# ls\nlinux-4.19.23                    linux-headers-4.15.0-45\nlinux-headers-4.15.0-43          linux-headers-4.15.0-45-generic\nlinux-headers-4.15.0-43-generic<\/code><\/pre>\n\n\n\n<p><strong>2.\u67e5\u770bGPIO\u9a71\u52a8\u6e90\u4ee3\u7801<\/strong><\/p>\n\n\n\n<p>Q300P\u4f7f\u7528SIO\u82af\u7247IT8786\uff0c\u8fdb\u5165\u5185\u6838\u6e90\u7801\u6839\u76ee\u5f55<code>\\drivers\\gpio<\/code>\u67e5\u770bgpio-it87.c\u6e90\u4ee3\u7801\uff0c\u53ef\u4ee5\u770b\u5230IT8786_ID\u7684\u578b\u53f7<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#define IT8786_ID\t0x8786\n...\ncase IT8786_ID:\n\tgpio_ba_reg = 0x62;\n\tit87_gpio->io_size = 8;\n\tit87_gpio->output_base = 0xc8;\n\tit87_gpio->simple_base = 0xc0;\n\tit87_gpio->simple_size = 5;\n\tit87_gpio->chip.ngpio = 64;\n\tbreak;<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-vivid-red-color\">\u6ce8\u610f\uff1a\u5982\u679c\u4e0d\u77e5\u9053\u4f7f\u7528\u7684SIO\u578b\u53f7\uff0c\u53ef\u4ee5\u4f7f\u7528dmesg\u8fc7\u6ee4Chip\u65e5\u5fd7\uff0c\u627e\u5230SIO\u82af\u7247\u578b\u53f7\uff0c\u6dfb\u52a0\u8fdb\u6765\u7f16\u8bd1\uff0c\u5185\u6838\u65e5\u5fd7\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pr_err(\"Unknown Chip found, Chip %04x Revision %x\\n\",\n\t\t       chip_type, chip_rev);<\/code><\/pre>\n\n\n\n<p><strong>3.\u914d\u7f6e\u5185\u6838<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@tiger:\/# cd usr\/src\/linux-4.19.23\/\nroot@tiger:\/usr\/src\/linux-4.19.23# make menuconfig\n\n\u9009\u62e9\nDevice Drivers \n> GPIO Support\n> > Port-mapped I\/O GPIO drivers<\/code><\/pre>\n\n\n\n<p>QOTOM Q350P GPIO\u7531TI8786E-1\u82af\u7247\u5904\u7406\uff0c\u627e\u5230gpio drive \u5bf9IT87xx\u8bbe\u7f6e\u4e3a[*] <br>[*]\u4ee3\u8868\u7f16\u8bd1\u5e76\u5b89\u88c5\u5230\u5185\u6838\uff0c[M]\u8868\u793a\u7f16\u8bd1\u4e0d\u5b89\u88c5<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"941\" height=\"418\" src=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-03.png\" alt=\"\" class=\"wp-image-516\" srcset=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-03.png 941w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-03-300x133.png 300w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-03-768x341.png 768w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><figcaption>\u914d\u7f6eGPIO<\/figcaption><\/figure><\/div>\n\n\n\n<p><strong>4.\u7f16\u8bd1\u5e76\u5b89\u88c5\u5185\u6838<\/strong><\/p>\n\n\n\n<ol><li>\u7f16\u8bd1\u5185\u6838\uff0c\u5177\u4f53\u7f16\u8bd1\u65b9\u6cd5\u53ef\u4ee5\u53c2\u8003\u300a<a href=\"http:\/\/iqotom.com\/?p=162\">Ubuntu 18.04\u4e0a\u7f16\u8bd1Linux\u5185\u6838<\/a>\u300b<code>root@tiger:\/usr\/src\/linux-4.19.23# make -j4<\/code><\/li><li> \u7f16\u8bd1\u7ed3\u675f\u540e\uff0c\u6267\u884c\u5b89\u88c5 <br><code>make modules_install<\/code><br><code>make install<\/code><br><code>reboot<\/code><\/li><\/ol>\n\n\n\n<p><strong>5.\u9a8c\u8bc1\u7ed3\u679c<\/strong><\/p>\n\n\n\n<ol><li>\u65b0\u7684\u5185\u6838\u5df2\u7ecf\u80fd\u591f\u8bc6\u522b\u5230GPIO <br><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"197\" class=\"wp-image-517\" style=\"width: 800px;\" src=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-04.png\" alt=\"\" srcset=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-04.png 903w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-04-300x74.png 300w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-04-768x189.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/li><li> \u5728\u7528\u6237\u7a7a\u95f4\u901a\u8fc7sysfs\u63a5\u53e3\u8bbf\u95eegpio\u6b63\u5e38\uff0c\u8bf4\u660e gpio drive \u5b89\u88c5\u6210\u529f<br><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"208\" class=\"wp-image-518\" style=\"width: 800px;\" src=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-05.png\" alt=\"\" srcset=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-05.png 903w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-05-300x78.png 300w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-05-768x200.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\/sys\/class\/gpio\u4f7f\u7528\u8bf4\u660e:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>1\u3001gpio_operation \u901a\u8fc7\/sys\/\u6587\u4ef6\u63a5\u53e3\u64cd\u4f5cIO\u7aef\u53e3 GPIO\u5230\u6587\u4ef6\u7cfb\u7edf\u7684\u6620\u5c04\u3002\n\n2\u3001\u63a7\u5236GPIO\u7684\u76ee\u5f55\u4f4d\u4e8e\/sys\/class\/gpio\u3002\n\n3\u3001\/sys\/class\/gpio\/export \u6587\u4ef6\u7528\u4e8e\u901a\u77e5\u7cfb\u7edf\u9700\u8981\u5bfc\u51fa\u63a7\u5236\u7684GPIO\u5f15\u811a\u7f16\u53f7\u3002\n\n4\u3001\/sys\/class\/gpio\/unexport \u7528\u4e8e\u901a\u77e5\u7cfb\u7edf\u53d6\u6d88\u5bfc\u51fa\u3002\n\n5\u3001\/sys\/class\/gpio\/gpiochipX\u76ee\u5f55\u4fdd\u5b58\u7cfb\u7edf\u4e2dGPIO\u5bc4\u5b58\u5668\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u6bcf\u4e2a\u5bc4\u5b58\u5668\u63a7\u5236\u5f15\u811a\u7684\u8d77\u59cb\u7f16\u53f7base\uff0c\u5bc4\u5b58\u5668\u540d\u79f0label\uff0c\u5f15\u811a\u603b\u6570ngpio\uff0c\u5bfc\u51fa\u4e00\u4e2a\u5f15\u811a\u7684\u64cd\u4f5c\u6b65\u9aa4\u3002\n\n6\u3001\u9996\u5148\u8ba1\u7b97\u6b64\u5f15\u811a\u7f16\u53f7\uff0c\u5f15\u811a\u7f16\u53f7 = \u63a7\u5236\u5f15\u811a\u7684\u5bc4\u5b58\u5668\u57fa\u6570 + \u63a7\u5236\u5f15\u811a\u5bc4\u5b58\u5668\u4f4d\u6570\u3002\n\n7\u3001\u5411\/sys\/class\/gpio\/export\u5199\u5165\u6b64\u7f16\u53f7\uff0c\u6bd4\u598212\u53f7\u5f15\u811a\uff0cecho 12 > \/sys\/class\/gpio\/export\uff0c\u547d\u4ee4\u6210\u529f\u540e\u751f\u6210\/sys\/class\/gpio\/gpio12\u76ee\u5f55\uff0c\u5982\u679c\u6ca1\u6709\u51fa\u73b0\u76f8\u5e94\u7684\u76ee\u5f55\uff0c\u8bf4\u660e\u6b64\u5f15\u811a\u4e0d\u53ef\u5bfc\u51fa\u3002\n\n8\u3001direction\u6587\u4ef6\uff0c\u5b9a\u4e49\u8f93\u5165\u8f93\u51fa\u65b9\u5411\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u547d\u4ee4\u5b9a\u4e49\u4e3a\u8f93\u51fa,direction\u63a5\u53d7\u7684\u53c2\u6570\uff1ain, out, high, low\uff1bhigh\/low\u540c\u65f6\u8bbe\u7f6e\u65b9\u5411\u4e3a\u8f93\u51fa\u3002\n\n9\u3001value\u6587\u4ef6\u662f\u7aef\u53e3\u7684\u6570\u503c\uff0c\u4e3a1\u62160\u3002<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6d4b\u8bd5GPIO:<\/strong><\/h3>\n\n\n\n<p> <strong>1.\u901a\u8fc7\u67e5\u770b\u8bf4\u660e\u4e66\uff0c\u5f97\u77e5\u4f7f\u7528\u7684GPIO\u7aef\u53e3\u4e3a80-87 <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"554\" height=\"128\" src=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-06.png\" alt=\"\" class=\"wp-image-519\" srcset=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-06.png 554w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-06-300x69.png 300w\" sizes=\"(max-width: 554px) 100vw, 554px\" \/><figcaption>gpio pin<\/figcaption><\/figure>\n\n\n\n<p><strong>2. \u627e\u5230\u5bf9\u5e94\u7684gpio\u7f16\u53f7 <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/sys\/kernel\/debug\/gpio\n...\n gpio-504 (it87_gp80           )\n gpio-505 (it87_gp81           )\n gpio-506 (it87_gp82           )\n gpio-507 (it87_gp83           )\n gpio-508 (it87_gp84           )\n gpio-509 (it87_gp85           )\n gpio-510 (it87_gp86           )\n gpio-511 (it87_gp87           )<\/code><\/pre>\n\n\n\n<p><strong>2.\u4f7f\u7528gp87\u7aef\u53e3\uff0c\u8bbe\u7f6e\u8f93\u51fa\u6a21\u5f0f\u4e3a\u8f93\u51fa<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@tiger:\/sys\/class\/gpio# echo 511 > export \nroot@tiger:\/sys\/class\/gpio# echo out > it87_gp87\/direction<\/code><\/pre>\n\n\n\n<p><strong>3.\u6d4b\u8bd5led<\/strong><br> \u9ad8\u7535\u5e73\u7184\u706d <br><code>root@tiger:\/sys\/class\/gpio# echo 1 &gt; it87_gp87\/value <\/code><br> \u4f4e\u7535\u5e73\u70b9\u4eae <br><code>root@tiger:\/sys\/class\/gpio# echo 0 &gt; it87_gp87\/value<\/code><\/p>\n\n\n\n<p> \u9644\u4e0a\u6d4b\u8bd5\u811a\u672c\uff0cled\u95ea\u70c1100\u6b21 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!bin\/sh\n\nCOUNTER=1\necho 511 > \/sys\/class\/gpio\/export\necho out > \/sys\/class\/gpio\/it87_gp87\/direction\nwhile [ \"$COUNTER\" -lt 100 ]; do\n\techo \"gpio test ...:$COUNTER\"\n\techo 1 > \/sys\/class\/gpio\/it87_gp87\/value\n\tsleep 0.3\n\techo 0 > \/sys\/class\/gpio\/it87_gp87\/value\n\tsleep 0.3\n\tCOUNTER=$(($COUNTER+1))\ndone<\/code><\/pre>\n\n\n\n<p> <strong>\u6548\u679c\u56fe \u5982\u4e0b\uff1a<\/strong><br><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"810\" class=\"wp-image-520\" style=\"width: 800px;\" src=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-07.jpg\" alt=\"\" srcset=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-07.jpg 576w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/qotom-gpio-drive-07-296x300.jpg 296w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5de5\u63a7\u673a\u578b\u53f7\uff1aQOTOM Q350P SIO\u82af\u7247ITE8786-I \u95ee\u9898 Q350P\u5728\u5b89\u88c5ubuntu18.04\u2026 <span class=\"read-more\"><a href=\"http:\/\/iqotom.com\/?p=513\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":585,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,5],"tags":[47,7],"_links":{"self":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/513"}],"collection":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=513"}],"version-history":[{"count":9,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/513\/revisions"}],"predecessor-version":[{"id":1693,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/513\/revisions\/1693"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/media\/585"}],"wp:attachment":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=513"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}