{"id":282781,"date":"2023-09-15T04:05:46","date_gmt":"2023-09-14T20:05:46","guid":{"rendered":"https:\/\/lrxjmw.cn\/jmlqdbhgzyly.html"},"modified":"2023-09-15T04:05:46","modified_gmt":"2023-09-14T20:05:46","slug":"jmlqdbhgzyly","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/jmlqdbhgzyly.html","title":{"rendered":"\u63ed\u79d8Linux SPI\u9a71\u52a8\uff1a\u80cc\u540e\u5de5\u4f5c\u539f\u7406\u4e0e\u5173\u952e\u6280\u672f"},"content":{"rendered":"

\u8fd1\u5e74\u6765linux\u516c\u793e\uff0c\u968f\u7740\u7269\u8054\u7f51\u548c\u5d4c\u5165\u5f0f\u7cfb\u7edf<\/a>\u7684\u5feb\u901f\u53d1\u5c55\uff0cSPI\uff08Serial Peripheral Interface\uff09\u603b\u7ebf\u5df2\u7ecf\u6210\u4e3a\u8fde\u63a5\u5404\u79cd\u5916\u8bbe\u7684\u91cd\u8981\u63a5\u53e3\u4e4b\u4e00\u3002\u5728Linux<\/a>\u7cfb\u7edf\u4e2d\uff0c\u901a\u8fc7SPI\u9a71\u52a8\u53ef\u4ee5\u5b9e\u73b0\u4e0e\u5916\u8bbe\u4e4b\u95f4\u7684\u9ad8\u6548\u6570\u636e\u4f20\u8f93\u3002\u672c\u6587\u5c06\u5e26\u60a8\u6df1\u5165\u4e86\u89e3Linux\u4e0b\u7684SPI\u9a71\u52a8\u4f8b\u7a0b\uff0c\u63ed\u79d8\u5176\u80cc\u540e\u7684\u5de5\u4f5c\u539f\u7406\u548c\u5173\u952e\u6280\u672f\u3002<\/p>\n

\u4e00\u3001\u4ec0\u4e48\u662fSPI\uff1f<\/p>\n

SPI\u662f\u4e00\u79cd\u5168\u53cc\u5de5\u3001\u540c\u6b65\u901a\u4fe1\u534f\u8bae\uff0c\u7528\u4e8e\u5728\u4e3b\u63a7\u82af\u7247\u548c\u5916\u8bbe\u4e4b\u95f4\u8fdb\u884c\u6570\u636e\u4f20\u8f93\u3002\u5b83\u4ee5\u4e3b\u4ece\u65b9\u5f0f\u5de5\u4f5c\uff0c\u901a\u5e38\u7531\u4e00\u4e2a\u4e3b\u8bbe\u5907\u548c\u591a\u4e2a\u4ece\u8bbe\u5907\u7ec4\u6210\u3002\u4e3b\u8bbe\u5907\u901a\u8fc7\u65f6\u949f\u4fe1\u53f7\u63a7\u5236\u6570\u636e\u4f20\u8f93\u7684\u65f6\u5e8f\uff0c\u5e76\u901a\u8fc7\u7247\u9009\u4fe1\u53f7\u9009\u62e9\u4e0e\u4e4b\u901a\u4fe1\u7684\u4ece\u8bbe\u5907\u3002<\/p>\n

\u4e8c\u3001SPI\u9a71\u52a8\u5728Linux\u4e2d\u7684\u4f5c\u7528<\/p>\n

\u5728Linux\u7cfb\u7edf\u4e2d\uff0cSPI\u9a71\u52a8\u8d1f\u8d23\u7ba1\u7406SPI\u603b\u7ebf\u548c\u76f8\u5173\u5916\u8bbe\u4e4b\u95f4\u7684\u901a\u4fe1\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7ec4API\u51fd\u6570\uff0c\u4f7f\u5f97\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u65b9\u4fbf\u5730\u4e0eSPI\u8bbe\u5907\u8fdb\u884c\u4ea4\u4e92\u3002\u901a\u8fc7\u8c03\u7528\u8fd9\u4e9bAPI\u51fd\u6570\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u53d1\u9001\u548c\u63a5\u6536\u6570\u636e\uff0c\u5e76\u5bf9\u76f8\u5173\u53c2\u6570\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n

\u4e09\u3001\u5982\u4f55\u7f16\u5199Linux SPI\u9a71\u52a8\uff1f<\/p>\n

\u7f16\u5199\u4e00\u4e2a\u5b8c\u6574\u7684Linux SPI\u9a71\u52a8\u9700\u8981\u4ee5\u4e0b\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a<\/p>\n

1.\u786e\u5b9a\u786c\u4ef6\u8fde\u63a5\u548c\u8bbe\u5907\u6811\u914d\u7f6e<\/p>\n

\u5728\u5f00\u59cb\u7f16\u5199\u9a71\u52a8\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u5b9aSPI\u603b\u7ebf\u7684\u786c\u4ef6\u8fde\u63a5\uff0c\u5e76\u5728\u8bbe\u5907\u6811\u4e2d\u8fdb\u884c\u76f8\u5e94\u7684\u914d\u7f6e\u3002\u8bbe\u5907\u6811\u662f\u4e00\u79cd\u63cf\u8ff0\u786c\u4ef6\u8bbe\u5907\u53ca\u5176\u8fde\u63a5\u5173\u7cfb\u7684\u6570\u636e\u7ed3\u6784\uff0c\u901a\u8fc7\u5bf9\u8bbe\u5907\u6811\u7684\u914d\u7f6e\uff0c\u53ef\u4ee5\u544a\u8bc9\u5185\u6838\u5982\u4f55\u6b63\u786e\u5730\u521d\u59cb\u5316\u548c\u7ba1\u7406SPI\u603b\u7ebf\u3002<\/p>\n

2.\u6ce8\u518cSPI\u9a71\u52a8<\/p>\n

\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u9a71\u52a8\u7a0b\u5e8f\u9700\u8981\u901a\u8fc7\u8c03\u7528\u76f8\u5173\u51fd\u6570\u6765\u6ce8\u518c\u81ea\u5df1\u3002\u5728SPI\u9a71\u52a8\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528`spi_register_driver()`\u51fd\u6570\u6765\u6ce8\u518c\u9a71\u52a8\uff0c\u5e76\u4f20\u5165\u4e00\u4e2a`spi_driver`\u7ed3\u6784\u4f53\u4f5c\u4e3a\u53c2\u6570\u3002\u8fd9\u4e2a\u7ed3\u6784\u4f53\u4e2d\u5305\u542b\u4e86\u9a71\u52a8\u7a0b\u5e8f\u7684\u56de\u8c03\u51fd\u6570\u7b49\u4fe1\u606f\u3002<\/p>\n

3.\u5b9e\u73b0\u9a71\u52a8\u7a0b\u5e8f\u7684\u56de\u8c03\u51fd\u6570<\/p>\n

SPI\u9a71\u52a8\u7a0b\u5e8f\u9700\u8981\u5b9e\u73b0\u4e00\u7ec4\u56de\u8c03\u51fd\u6570\uff0c\u4ee5\u54cd\u5e94\u4e0d\u540c\u7684\u64cd\u4f5c\u3002\u5176\u4e2d\u6700\u91cd\u8981\u7684\u662f`probe()`\u548c`transfer()`\u51fd\u6570\u3002<\/p>\n

-`probe()`\u51fd\u6570\u7528\u4e8e\u5728\u4e0e\u4ece\u8bbe\u5907\u5efa\u7acb\u901a\u4fe1\u65f6\u8fdb\u884c\u521d\u59cb\u5316\u64cd\u4f5c\u3002\u5b83\u4f1a\u88ab\u5185\u6838\u8c03\u7528\uff0c\u5e76\u4f20\u5165\u4e00\u4e2a\u6307\u5411`spi_device`\u7ed3\u6784\u4f53\u7684\u6307\u9488\u4f5c\u4e3a\u53c2\u6570\u3002\u5728\u8be5\u51fd\u6570\u4e2d\uff0c\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e9b\u521d\u59cb\u5316\u8bbe\u7f6e\uff0c\u5982\u8bbe\u7f6e\u65f6\u949f\u9891\u7387\u3001\u4f20\u8f93\u6a21\u5f0f\u7b49\u3002<\/p>\n

-`transfer()`\u51fd\u6570\u7528\u4e8e\u5b9e\u9645\u7684\u6570\u636e\u4f20\u8f93\u3002\u901a\u8fc7\u8be5\u51fd\u6570linux spi\u9a71\u52a8\u4f8b\u7a0b<\/strong>\uff0c\u53ef\u4ee5\u53d1\u9001\u548c\u63a5\u6536\u6570\u636e\uff0c\u5e76\u5bf9\u76f8\u5173\u53c2\u6570\u8fdb\u884c\u914d\u7f6e\u3002\u5728\u8be5\u51fd\u6570\u4e2d\uff0c\u9700\u8981\u4f7f\u7528`spi_sync_transfer()`\u51fd\u6570\u6765\u5b9e\u73b0\u6570\u636e\u7684\u540c\u6b65\u4f20\u8f93\u3002<\/p>\n

4.\u7f16\u8bd1\u548c\u52a0\u8f7d\u9a71\u52a8<\/p>\n

linux\u9a71\u52a8\u7a0b\u5e8f\u5b9e\u9a8c_linux spi\u9a71\u52a8\u4f8b\u7a0b<\/p>\n

\u5b8c\u6210\u9a71\u52a8\u7a0b\u5e8f\u7684\u7f16\u5199\u540e\uff0c\u9700\u8981\u8fdb\u884c\u7f16\u8bd1\uff0c\u5e76\u5c06\u751f\u6210\u7684\u9a71\u52a8\u6a21\u5757\u52a0\u8f7d\u5230\u5185\u6838\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528`make`\u547d\u4ee4<\/a>\u8fdb\u884c\u7f16\u8bd1\uff0c\u5e76\u4f7f\u7528`insmod`\u547d\u4ee4\u52a0\u8f7d\u9a71\u52a8\u6a21\u5757\u3002<\/p>\n

\u56db\u3001\u6848\u4f8b\u5206\u6790\uff1a\u4f7f\u7528SPI\u9a71\u52a8\u63a7\u5236LCD\u663e\u793a\u5c4f<\/p>\n

\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3Linux\u4e0b\u7684SPI\u9a71\u52a8\uff0c\u6211\u4eec\u4ee5\u63a7\u5236LCD\u663e\u793a\u5c4f\u4e3a\u4f8b\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528SPI\u9a71\u52a8\u5b9e\u73b0\u6570\u636e\u4f20\u8f93\u548c\u663e\u793a\u3002<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728\u8bbe\u5907\u6811\u4e2d\u914d\u7f6eSPI\u603b\u7ebf\u548cLCD\u663e\u793a\u5c4f\u7684\u8fde\u63a5\u5173\u7cfb\u3002\u7136\u540e\uff0c\u7f16\u5199\u4e00\u4e2aSPI\u9a71\u52a8\u7a0b\u5e8f\uff0c\u5b9e\u73b0\u4e0eLCD\u663e\u793a\u5c4f\u7684\u901a\u4fe1\u3002\u5728\u8be5\u9a71\u52a8\u7a0b\u5e8f\u4e2d\uff0c\u901a\u8fc7\u8bbe\u7f6e\u5408\u9002\u7684\u65f6\u949f\u9891\u7387\u548c\u4f20\u8f93\u6a21\u5f0f\uff0c\u53d1\u9001\u50cf\u7d20\u6570\u636e\u5230LCD\u663e\u793a\u5c4f\u4e0a\u5e76\u8fdb\u884c\u663e\u793a\u3002<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4linux spi\u9a71\u52a8\u4f8b\u7a0b<\/strong>\uff0c\u6211\u4eec\u6210\u529f\u5730\u5b9e\u73b0\u4e86\u901a\u8fc7SPI\u9a71\u52a8\u63a7\u5236LCD\u663e\u793a\u5c4f\u7684\u529f\u80fd\u3002\u8fd9\u4e2a\u6848\u4f8b\u5145\u5206\u5c55\u793a\u4e86SPI\u9a71\u52a8\u5728\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\u7684\u91cd\u8981\u4f5c\u7528\u548c\u5e94\u7528\u4ef7\u503c\u3002<\/p>\n

\u4e94\u3001\u5c0f\u7ed3<\/p>\n

\u672c\u6587\u4ecb\u7ecd\u4e86Linux\u4e0b\u7684SPI\u9a71\u52a8\u4f8b\u7a0b\uff0c\u5e76\u8be6\u7ec6\u9610\u8ff0\u4e86\u5176\u5de5\u4f5c\u539f\u7406\u548c\u5173\u952e\u6280\u672f\u3002\u901a\u8fc7\u6df1\u5165\u4e86\u89e3SPI\u534f\u8bae\u548c\u76f8\u5173API\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u597d\u5730\u5e94\u7528\u548c\u5f00\u53d1\u57fa\u4e8eSPI\u603b\u7ebf\u7684\u786c\u4ef6\u8bbe\u5907\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u6709\u6240\u542f\u53d1\uff0c\u5e76\u80fd\u591f\u5728\u60a8\u7684\u5d4c\u5165\u5f0f\u7cfb\u7edf\u5f00\u53d1\u4e2d\u8d77\u5230\u79ef\u6781\u7684\u6307\u5bfc\u4f5c\u7528\u3002<\/p>\n

\u516d\u3001\u53c2\u8003\u8d44\u6599<\/p>\n

[1] Linux SPI\u9a71\u52a8\u6846\u67b6\uff08]()<\/p>\n

[2] Device Tree Documentation\uff08]()<\/p>\n

[3] Linux Device Drivers, Third Edition, Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartman<\/p>\n

\u4e03\u3001\u58f0\u660e<\/p>\n

\u672c\u6587\u5185\u5bb9\u771f\u5b9e\u53ef\u9760\uff0c\u7ecf\u8fc7\u5c0f\u7f16\u7cbe\u5fc3\u6574\u7406\u548c\u64b0\u5199\uff0c\u672a\u7ecf\u5141\u8bb8\u4e0d\u5f97\u8f6c\u8f7d\u3002\u5982\u6709\u7591\u95ee\uff0c\u8bf7\u5728\u8bc4\u8bba\u533a\u7559\u8a00linux\u73af\u5883\u53d8\u91cf\uff0c\u5c0f\u7f16\u4f1a\u5c3d\u5feb\u56de\u590d\u89e3\u7b54\u3002<\/p>\n

\u516b\u3001\u7248\u6743\u6240\u6709<\/p>\n

\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u7248\u6743\u5f52\u5c0f\u7f16\u6240\u6709\u3002\u672a\u7ecf\u6388\u6743\uff0c\u7981\u6b62\u8f6c\u8f7d\u3002\u5982\u9700\u8f6c\u8f7d\uff0c\u8bf7\u8054\u7cfb\u5c0f\u7f16\u83b7\u5f97\u6388\u6743\u5e76\u6ce8\u660e\u51fa\u5904\u3002<\/p>\n

\u4ee5\u4e0a\u662f\u5173\u4e8eLinux SPI\u9a71\u52a8\u4f8b\u7a0b\u7684\u8be6\u7ec6\u4ecb\u7ecd\u3002\u5e0c\u671b\u672c\u6587\u80fd\u591f\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff0c\u5e76\u4e3a\u60a8\u5728\u5d4c\u5165\u5f0f\u7cfb\u7edf\u5f00\u53d1\u4e2d\u7684SPI\u9a71\u52a8\u5e94\u7528\u63d0\u4f9b\u4e00\u4e9b\u6307\u5bfc\u548c\u542f\u793a\u3002\u611f\u8c22\u60a8\u7684\u9605\u8bfb\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

\u672c\u6587\u5c06\u5e26\u60a8\u6df1\u5165\u4e86\u89e3Linux\u4e0b\u7684SPI\u9a71\u52a8\u4f8b\u7a0b\uff0c\u63ed\u79d8\u5176\u80cc\u540e\u7684\u5de5\u4f5c\u539f\u7406\u548c\u5173\u952e\u6280\u672f\u3002\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u9a71\u52a8\u7a0b\u5e8f\u9700\u8981\u901a\u8fc7\u8c03\u7528\u76f8\u5173\u51fd\u6570\u6765\u6ce8\u518c\u81ea\u5df1\u3002\u5b8c\u6210\u9a71\u52a8\u7a0b\u5e8f\u7684\u7f16\u5199\u540e\uff0c\u9700\u8981\u8fdb\u884c\u7f16\u8bd1\uff0c\u5e76\u5c06\u751f\u6210\u7684\u9a71\u52a8\u6a21\u5757\u52a0\u8f7d\u5230\u5185\u6838\u4e2d\u3002\u672c\u6587\u4ecb\u7ecd\u4e86Linux\u4e0b\u7684SPI\u9a71\u52a8\u4f8b\u7a0b\uff0c\u5e76\u8be6\u7ec6\u9610\u8ff0\u4e86\u5176\u5de5\u4f5c\u539f\u7406\u548c\u5173\u952e\u6280\u672f\u3002\u901a\u8fc7\u6df1\u5165\u4e86\u89e3SPI\u534f\u8bae\u548c\u76f8\u5173API\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u597d\u5730\u5e94\u7528\u548c\u5f00\u53d1\u57fa\u4e8eSPI\u603b\u7ebf\u7684\u786c\u4ef6\u8bbe\u5907\u3002SPI\u9a71\u52a8\u4f8b\u7a0b\u7684\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n","protected":false},"author":1,"featured_media":282782,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-282781","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/282781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=282781"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/282781\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/282782"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=282781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=282781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=282781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}