text: (window.webpackJsonp=window.webpackJsonp||[]).push([[202],{1018:function(s,t,a){s.exports=a.p+"assets/img/I2C物理连线示意图.1395a244.png"},1019:function(s,t){s.exports="data:image/png;base64,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"},1020:function(s,t,a){s.exports=a.p+"assets/img/I2C统一服务模式结构图.6f5746d7.png"},185:function(s,t){s.exports="data:image/gif;base64,R0lGODlhGwAWAKUAAPz+/Nze3LS2tHx+fFxaXGRiZERCRBwaHDw6PMTGxAQGBDQ2NKSmpJyenLy+vOTm5HRydDQyNAQCBCwuLCQiJKyurExKTBQSFGRmZFRSVBweHIyKjFxeXNTS1ERGRIyOjOzu7PT29Hx6fCQmJBQWFJSWlAwKDISGhMzOzNTW1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAbABYAAAanQIBwSCwaj8ikcslsOpEQiVRiOgFQlKkEkUqCJgViSDQyBIgJUglJ4QyMh45R4/kcJYN3kXLeb8JGeHpEfEYUf3d5hn2EiIGKe4xDh4BFgouGjpaQhJJClImDk54AoI+in6SmmxgDBQYZAwIaG3l5DAGrRBITFAMNDhUDFhcEtgMEFAoYlUQKCwMMDbYODwnTxxARzUMBAsgFtgYHCOHHrwlP6uvs7UEAOw=="},192:function(s,t){s.exports="data:image/gif;base64,R0lGODlhIwAdAKUJAPz65KyWVEQ2HLyiZPz67LSaXAQCBAwGBMyybPz+/PzqtFRGJGRSLHxuPFxKLHReNPzuxPz69OTGfPzafDwuHBwWDPTWjPzyzIRyRLyiXCQaFCwiFMSqZJyGTKSOVPz23PTalPTSfOzKdPzmrHxmPIx6RGxaNNS2bMyuZPz+9Ew+JJSCTDQqHPTanOTGdBQODNS6dPzy1Pz25PzipNzCfPzqvPzuzPzmpNy+bOzOhAAAAICAgAAAAAAAAAAAAAAAACH5BAEAAAkALAAAAAAjAB0AAAb+wIRwSCwKAQCjcskU2jyZWHPKjCAMBwl1W7xRDAaHgsuNdcDgTJI8zVUMFI2BBWI3aw8wKgAuXexKBFcGDxMTC1gSKYBdLAYVIoY4BwYLY4xCMStgHYaGGGAFa4wSbxSehiEbBht1jDUmWCgTIiYkIRMFYBg2gAQcYIWHwYYOWDQRdjOOFbgTlAYahi6UlmwxJWAeno4GKp7ZBgEyZBIvBgKosQYNniGOGq5UCgyyqJsGBajA7BBUAAPAkEA1AQWYSKjqHYCRrEkLZs5QHdhAcIKLcypGNLkQLkDFCQIYfMQX4MOSFBIofRvp8SMzeUUUGDtw4mPBmh8NGiDhrwhigAwCbYIyUMJmLJoNh4BYpSEiQQFgRH4U8UaAxiEXhrb8mEHDBg42J5wx4MFkgggpK4VdS/BLBQtCFCAywKCB3bt48+q9a4wQBAK60AgeTLjw4AMIAAQQwLix48eQIzseEAQAOw=="},2132:function(s,t,a){"use strict";a.r(t);var n=a(1),e=Object(n.a)({},(function(){var s=this,t=s.$createElement,n=s._self._c||t;return n("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[n("h1",{attrs:{id:"i2c"}},[s._v("I2C"),n("a",{attrs:{name:"ZH-CN_TOPIC_0000001206171515"}})]),s._v(" "),n("ul",[n("li",[n("p",[n("a",{attrs:{href:"#section5361140416"}},[s._v("概述")])])]),s._v(" "),n("li",[n("p",[n("a",{attrs:{href:"#section545869122317"}},[s._v("接口说明")])])]),s._v(" "),n("li",[n("p",[n("a",{attrs:{href:"#section1695201514281"}},[s._v("使用指导")])]),s._v(" "),n("ul",[n("li",[n("a",{attrs:{href:"#section1338373417288"}},[s._v("使用流程")])]),s._v(" "),n("li",[n("a",{attrs:{href:"#section13751110132914"}},[s._v("打开I2C控制器")])]),s._v(" "),n("li",[n("a",{attrs:{href:"#section9202183372916"}},[s._v("进行I2C通信")])]),s._v(" "),n("li",[n("a",{attrs:{href:"#section19481164133018"}},[s._v("关闭I2C控制器")])])])]),s._v(" "),n("li",[n("p",[n("a",{attrs:{href:"#section5302202015300"}},[s._v("使用实例")])])])]),s._v(" "),n("h2",{attrs:{id:"概述"}},[s._v("概述"),n("a",{attrs:{name:"section5361140416"}})]),s._v(" "),n("ul",[n("li",[n("p",[s._v("I2C(Inter Integrated Circuit)总线是由Philips公司开发的一种简单、双向二线制同步串行总线。")])]),s._v(" "),n("li",[n("p",[s._v("I2C以主从方式工作，通常有一个主设备和一个或者多个从设备，主从设备通过SDA(SerialData)串行数据线以及SCL(SerialClock)串行时钟线两根线相连，如"),n("a",{attrs:{href:"#fig1135561232714"}},[s._v("图1 ")]),s._v("所示。")])]),s._v(" "),n("li",[n("p",[s._v("I2C数据的传输必须以一个起始信号作为开始条件，以一个结束信号作为传输的停止条件。数据传输以字节为单位，高位在前，逐个bit进行传输。")])]),s._v(" "),n("li",[n("p",[s._v("I2C总线上的每一个设备都可以作为主设备或者从设备，而且每一个设备都会对应一个唯一的地址，当主设备需要和某一个从设备通信时，通过广播的方式，将从设备地址写到总线上，如果某个从设备符合此地址，将会发出应答信号，建立传输。")])]),s._v(" "),n("li",[n("p",[s._v("I2C接口定义了完成I2C传输的通用方法集合，包括：")]),s._v(" "),n("ul",[n("li",[s._v("I2C控制器管理:  打开或关闭I2C控制器")]),s._v(" "),n("li",[s._v("I2C消息传输：通过消息传输结构体数组进行自定义传输")])]),s._v(" "),n("p",[n("strong",[s._v("图 1")]),s._v("  I2C物理连线示意图"),n("a",{attrs:{name:"fig1135561232714"}}),n("br"),s._v(" "),n("img",{attrs:{src:a(1018),alt:""}})])])]),s._v(" "),n("h2",{attrs:{id:"接口说明"}},[s._v("接口说明"),n("a",{attrs:{name:"section545869122317"}})]),s._v(" "),n("p",[n("strong",[s._v("表 1")]),s._v("  I2C驱动API接口功能介绍")]),s._v(" "),n("p",[n("a",{attrs:{name:"table1731550155318"}}),s._v(" "),n("table",[n("thead",{attrs:{align:"left"}},[n("tr",{attrs:{id:"row4419501537"}},[n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"18.63%",id:"mcps1.2.4.1.1"}},[n("p",{attrs:{id:"p641050105320"}},[n("a",{attrs:{name:"p641050105320"}}),n("a",{attrs:{name:"p641050105320"}}),s._v("功能分类")])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"28.03%",id:"mcps1.2.4.1.2"}},[n("p",{attrs:{id:"p54150165315"}},[n("a",{attrs:{name:"p54150165315"}}),n("a",{attrs:{name:"p54150165315"}}),s._v("接口名")])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"53.339999999999996%",id:"mcps1.2.4.1.3"}},[n("p",{attrs:{id:"p941150145313"}},[n("a",{attrs:{name:"p941150145313"}}),n("a",{attrs:{name:"p941150145313"}}),s._v("描述")])])])]),s._v(" "),n("tbody",[n("tr",{attrs:{id:"row34145016535"}},[n("td",{staticClass:"cellrowborder",attrs:{rowspan:"2",valign:"top",width:"18.63%",headers:"mcps1.2.4.1.1 "}},[n("p",{attrs:{id:"p229610227124"}},[n("a",{attrs:{name:"p229610227124"}}),n("a",{attrs:{name:"p229610227124"}}),s._v("I2C控制器管理接口")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"28.03%",headers:"mcps1.2.4.1.2 "}},[n("p",{attrs:{id:"p19389143041518"}},[n("a",{attrs:{name:"p19389143041518"}}),n("a",{attrs:{name:"p19389143041518"}}),s._v("I2cOpen")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"53.339999999999996%",headers:"mcps1.2.4.1.3 "}},[n("p",{attrs:{id:"p8738101941716"}},[n("a",{attrs:{name:"p8738101941716"}}),n("a",{attrs:{name:"p8738101941716"}}),s._v("打开I2C控制器")])])]),s._v(" "),n("tr",{attrs:{id:"row5632152611414"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",headers:"mcps1.2.4.1.1 "}},[n("p",{attrs:{id:"p143890309153"}},[n("a",{attrs:{name:"p143890309153"}}),n("a",{attrs:{name:"p143890309153"}}),s._v("I2cClose")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",headers:"mcps1.2.4.1.2 "}},[n("p",{attrs:{id:"p573815197171"}},[n("a",{attrs:{name:"p573815197171"}}),n("a",{attrs:{name:"p573815197171"}}),s._v("关闭I2C控制器")])])]),s._v(" "),n("tr",{attrs:{id:"row15108165391412"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"18.63%",headers:"mcps1.2.4.1.1 "}},[n("p",{attrs:{id:"p91084533141"}},[n("a",{attrs:{name:"p91084533141"}}),n("a",{attrs:{name:"p91084533141"}}),s._v("I2c消息传输接口")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"28.03%",headers:"mcps1.2.4.1.2 "}},[n("p",{attrs:{id:"p13901730101511"}},[n("a",{attrs:{name:"p13901730101511"}}),n("a",{attrs:{name:"p13901730101511"}}),s._v("I2cTransfer")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"53.339999999999996%",headers:"mcps1.2.4.1.3 "}},[n("p",{attrs:{id:"p12738111912171"}},[n("a",{attrs:{name:"p12738111912171"}}),n("a",{attrs:{name:"p12738111912171"}}),s._v("自定义传输")])])])])])]),s._v(" "),n("blockquote",[n("p",[n("img",{attrs:{src:a(185),alt:""}}),s._v(" "),n("strong",[s._v("说明：")]),s._v("\n本文涉及的所有接口，仅限内核态使用，不支持在用户态使用。")])]),s._v(" "),n("h2",{attrs:{id:"使用指导"}},[s._v("使用指导"),n("a",{attrs:{name:"section1695201514281"}})]),s._v(" "),n("h3",{attrs:{id:"使用流程"}},[s._v("使用流程"),n("a",{attrs:{name:"section1338373417288"}})]),s._v(" "),n("p",[s._v("使用I2C设备的一般流程如"),n("a",{attrs:{href:"#fig183017194234"}},[s._v("图2")]),s._v("所示。")]),s._v(" "),n("p",[n("strong",[s._v("图 2")]),s._v("  I2C设备使用流程图"),n("a",{attrs:{name:"fig183017194234"}}),n("br"),s._v(" "),n("img",{attrs:{src:a(1019),alt:""}})]),s._v(" "),n("h3",{attrs:{id:"打开i2c控制器"}},[s._v("打开I2C控制器"),n("a",{attrs:{name:"section13751110132914"}})]),s._v(" "),n("p",[s._v("在进行I2C通信前，首先要调用I2cOpen打开I2C控制器。")]),s._v(" "),n("p",[s._v("DevHandle I2cOpen(int16_t number);")]),s._v(" "),n("p",[n("strong",[s._v("表 2")]),s._v("  I2cOpen参数和返回值描述")]),s._v(" "),n("p",[n("a",{attrs:{name:"table7603619123820"}}),s._v(" "),n("table",[n("thead",{attrs:{align:"left"}},[n("tr",{attrs:{id:"row1060351914386"}},[n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20.66%",id:"mcps1.2.3.1.1"}},[n("p",{attrs:{id:"p14603181917382"}},[n("a",{attrs:{name:"p14603181917382"}}),n("a",{attrs:{name:"p14603181917382"}}),n("strong",{attrs:{id:"b16510829133012"}},[n("a",{attrs:{name:"b16510829133012"}}),n("a",{attrs:{name:"b16510829133012"}}),s._v("参数")])])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"79.34%",id:"mcps1.2.3.1.2"}},[n("p",{attrs:{id:"p36031519183819"}},[n("a",{attrs:{name:"p36031519183819"}}),n("a",{attrs:{name:"p36031519183819"}}),n("strong",{attrs:{id:"b65222293309"}},[n("a",{attrs:{name:"b65222293309"}}),n("a",{attrs:{name:"b65222293309"}}),s._v("参数描述")])])])])]),s._v(" "),n("tbody",[n("tr",{attrs:{id:"row1960431983813"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20.66%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p3604719123817"}},[n("a",{attrs:{name:"p3604719123817"}}),n("a",{attrs:{name:"p3604719123817"}}),s._v("number")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"79.34%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p221392414442"}},[n("a",{attrs:{name:"p221392414442"}}),n("a",{attrs:{name:"p221392414442"}}),s._v("I2C控制器号")])])]),s._v(" "),n("tr",{attrs:{id:"row11410612183019"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20.66%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p460381915385"}},[n("a",{attrs:{name:"p460381915385"}}),n("a",{attrs:{name:"p460381915385"}}),n("strong",{attrs:{id:"b4349113243013"}},[n("a",{attrs:{name:"b4349113243013"}}),n("a",{attrs:{name:"b4349113243013"}}),s._v("返回值")])])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"79.34%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p96031619153812"}},[n("a",{attrs:{name:"p96031619153812"}}),n("a",{attrs:{name:"p96031619153812"}}),n("strong",{attrs:{id:"b63502322308"}},[n("a",{attrs:{name:"b63502322308"}}),n("a",{attrs:{name:"b63502322308"}}),s._v("返回值描述")])])])]),s._v(" "),n("tr",{attrs:{id:"row15410111273017"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20.66%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p1060418195389"}},[n("a",{attrs:{name:"p1060418195389"}}),n("a",{attrs:{name:"p1060418195389"}}),s._v("NULL")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"79.34%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p760471912388"}},[n("a",{attrs:{name:"p760471912388"}}),n("a",{attrs:{name:"p760471912388"}}),s._v("打开I2C控制器失败")])])]),s._v(" "),n("tr",{attrs:{id:"row1241081213303"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20.66%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p5604719133811"}},[n("a",{attrs:{name:"p5604719133811"}}),n("a",{attrs:{name:"p5604719133811"}}),s._v("设备句柄")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"79.34%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p3604181933818"}},[n("a",{attrs:{name:"p3604181933818"}}),n("a",{attrs:{name:"p3604181933818"}}),s._v("打开的I2C控制器设备句柄")])])])])])]),s._v(" "),n("p",[s._v("假设系统中存在8个I2C控制器，编号从0到7，那么我们现在获取3号控制器")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v('DevHandle i2cHandle = NULL;  /* I2C控制器句柄 /\n\n/* 打开I2C控制器 */\ni2cHandle = I2cOpen(3);\nif (i2cHandle == NULL) {\n    HDF_LOGE("I2cOpen: failed\\n");\n    return;\n}\n')])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br"),n("span",{staticClass:"line-number"},[s._v("8")]),n("br")])]),n("h3",{attrs:{id:"进行i2c通信"}},[s._v("进行I2C通信"),n("a",{attrs:{name:"section9202183372916"}})]),s._v(" "),n("p",[s._v("消息传输")]),s._v(" "),n("p",[s._v("int32_t I2cTransfer(DevHandle handle, struct I2cMsg *msgs, int16_t count);")]),s._v(" "),n("p",[n("strong",[s._v("表 3")]),s._v("  I2cTransfer参数和返回值描述")]),s._v(" "),n("p",[n("a",{attrs:{name:"table1934414174212"}}),s._v(" "),n("table",[n("thead",{attrs:{align:"left"}},[n("tr",{attrs:{id:"row1134415176216"}},[n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",id:"mcps1.2.3.1.1"}},[n("p",{attrs:{id:"p13295152320217"}},[n("a",{attrs:{name:"p13295152320217"}}),n("a",{attrs:{name:"p13295152320217"}}),n("strong",{attrs:{id:"b17389641205115"}},[n("a",{attrs:{name:"b17389641205115"}}),n("a",{attrs:{name:"b17389641205115"}}),s._v("参数")])])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",id:"mcps1.2.3.1.2"}},[n("p",{attrs:{id:"p1295112352115"}},[n("a",{attrs:{name:"p1295112352115"}}),n("a",{attrs:{name:"p1295112352115"}}),n("strong",{attrs:{id:"b19401541175118"}},[n("a",{attrs:{name:"b19401541175118"}}),n("a",{attrs:{name:"b19401541175118"}}),s._v("参数描述")])])])])]),s._v(" "),n("tbody",[n("tr",{attrs:{id:"row5344101702113"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p19295132382111"}},[n("a",{attrs:{name:"p19295132382111"}}),n("a",{attrs:{name:"p19295132382111"}}),s._v("handle")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p1051172572919"}},[n("a",{attrs:{name:"p1051172572919"}}),n("a",{attrs:{name:"p1051172572919"}}),s._v("I2C控制器设备句柄")])])]),s._v(" "),n("tr",{attrs:{id:"row17344171722117"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p9295122332113"}},[n("a",{attrs:{name:"p9295122332113"}}),n("a",{attrs:{name:"p9295122332113"}}),s._v("msgs")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p202951238218"}},[n("a",{attrs:{name:"p202951238218"}}),n("a",{attrs:{name:"p202951238218"}}),s._v("待传输数据的消息结构体数组")])])]),s._v(" "),n("tr",{attrs:{id:"row45812466213"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p1659246112117"}},[n("a",{attrs:{name:"p1659246112117"}}),n("a",{attrs:{name:"p1659246112117"}}),s._v("count")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p259124622119"}},[n("a",{attrs:{name:"p259124622119"}}),n("a",{attrs:{name:"p259124622119"}}),s._v("消息数组长度")])])]),s._v(" "),n("tr",{attrs:{id:"row04701426105110"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p17295142322113"}},[n("a",{attrs:{name:"p17295142322113"}}),n("a",{attrs:{name:"p17295142322113"}}),n("strong",{attrs:{id:"b2159044145115"}},[n("a",{attrs:{name:"b2159044145115"}}),n("a",{attrs:{name:"b2159044145115"}}),s._v("返回值")])])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p142959232211"}},[n("a",{attrs:{name:"p142959232211"}}),n("a",{attrs:{name:"p142959232211"}}),n("strong",{attrs:{id:"b16160044135114"}},[n("a",{attrs:{name:"b16160044135114"}}),n("a",{attrs:{name:"b16160044135114"}}),s._v("返回值描述")])])])]),s._v(" "),n("tr",{attrs:{id:"row74701226125110"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p929532313211"}},[n("a",{attrs:{name:"p929532313211"}}),n("a",{attrs:{name:"p929532313211"}}),s._v("正整数")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p829512237217"}},[n("a",{attrs:{name:"p829512237217"}}),n("a",{attrs:{name:"p829512237217"}}),s._v("成功传输的消息结构体数目")])])]),s._v(" "),n("tr",{attrs:{id:"row204701126195115"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p12958234217"}},[n("a",{attrs:{name:"p12958234217"}}),n("a",{attrs:{name:"p12958234217"}}),s._v("负数")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p1295192312112"}},[n("a",{attrs:{name:"p1295192312112"}}),n("a",{attrs:{name:"p1295192312112"}}),s._v("执行失败")])])])])])]),s._v(" "),n("p",[s._v("I2C传输消息类型为I2cMsg，每个传输消息结构体表示一次读或写，通过一个消息数组，可以执行若干次的读写组合操作。")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v('int32_t ret;\nuint8_t wbuff[2] = { 0x12, 0x13 };\nuint8_t rbuff[2] = { 0 };\nstruct I2cMsg msgs[2]; /* 自定义传输的消息结构体数组 */\nmsgs[0].buf = wbuff;    /* 写入的数据 */\nmsgs[0].len = 2;        /* 写入数据长度为2 */\nmsgs[0].addr = 0x5A;    /* 写入设备地址为0x5A */\nmsgs[0].flags = 0;      /* 传输标记为0，默认为写 */\nmsgs[1].buf = rbuff;    /* 要读取的数据 */\nmsgs[1].len = 2;        /* 读取数据长度为2 */\nmsgs[1].addr = 0x5A;    /* 读取设备地址为0x5A */\nmsgs[1].flags = I2C_FLAG_READ /* I2C_FLAG_READ置位 */\n/* 进行一次自定义传输，传输的消息个数为2 */\nret = I2cTransfer(i2cHandle, msgs, 2);\nif (ret != 2) {\n    HDF_LOGE("I2cTransfer: failed, ret %d\\n", ret);\n    return;\n}\n')])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br"),n("span",{staticClass:"line-number"},[s._v("8")]),n("br"),n("span",{staticClass:"line-number"},[s._v("9")]),n("br"),n("span",{staticClass:"line-number"},[s._v("10")]),n("br"),n("span",{staticClass:"line-number"},[s._v("11")]),n("br"),n("span",{staticClass:"line-number"},[s._v("12")]),n("br"),n("span",{staticClass:"line-number"},[s._v("13")]),n("br"),n("span",{staticClass:"line-number"},[s._v("14")]),n("br"),n("span",{staticClass:"line-number"},[s._v("15")]),n("br"),n("span",{staticClass:"line-number"},[s._v("16")]),n("br"),n("span",{staticClass:"line-number"},[s._v("17")]),n("br"),n("span",{staticClass:"line-number"},[s._v("18")]),n("br")])]),n("blockquote",[n("p",[n("img",{attrs:{src:a(192),alt:""}}),s._v(" "),n("strong",[s._v("注意：")])]),s._v(" "),n("ul",[n("li",[s._v("I2cMsg结构体中的设备地址不包含读写标志位，读写信息由flags成员变量的读写控制位传递。")]),s._v(" "),n("li",[s._v("本函数不对消息结构体个数count做限制，其最大个数度由具体I2C控制器决定。")]),s._v(" "),n("li",[s._v("本函数也不对每个消息结构体中的数据长度做限制，同样由具体I2C控制器决定。")]),s._v(" "),n("li",[s._v("本函数可能会引起系统休眠，不允许在中断上下文调用")])])]),s._v(" "),n("h3",{attrs:{id:"关闭i2c控制器"}},[s._v("关闭I2C控制器"),n("a",{attrs:{name:"section19481164133018"}})]),s._v(" "),n("p",[s._v("I2C通信完成之后，需要关闭I2C控制器，关闭函数如下所示：")]),s._v(" "),n("p",[s._v("void I2cClose(DevHandle handle);")]),s._v(" "),n("p",[n("strong",[s._v("表 4")]),s._v("  I2cClose参数和返回值描述")]),s._v(" "),n("p",[n("a",{attrs:{name:"table72517953115"}}),s._v(" "),n("table",[n("thead",{attrs:{align:"left"}},[n("tr",{attrs:{id:"row1525793312"}},[n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",id:"mcps1.2.3.1.1"}},[n("p",{attrs:{id:"p115402031153111"}},[n("a",{attrs:{name:"p115402031153111"}}),n("a",{attrs:{name:"p115402031153111"}}),s._v("参数")])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",id:"mcps1.2.3.1.2"}},[n("p",{attrs:{id:"p65406313319"}},[n("a",{attrs:{name:"p65406313319"}}),n("a",{attrs:{name:"p65406313319"}}),s._v("参数描述")])])])]),s._v(" "),n("tbody",[n("tr",{attrs:{id:"row1926109193116"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p105419317318"}},[n("a",{attrs:{name:"p105419317318"}}),n("a",{attrs:{name:"p105419317318"}}),s._v("handle")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p1213245577"}},[n("a",{attrs:{name:"p1213245577"}}),n("a",{attrs:{name:"p1213245577"}}),s._v("I2C控制器设备句柄")])])])])])]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v("I2cClose(i2cHandle); /* 关闭I2C控制器 */\n")])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br")])]),n("h2",{attrs:{id:"使用实例"}},[s._v("使用实例"),n("a",{attrs:{name:"section5302202015300"}})]),s._v(" "),n("p",[s._v("本例程以操作开发板上的I2C设备为例，详细展示I2C接口的完整使用流程。")]),s._v(" "),n("p",[s._v("本例拟对Hi3516DV300某开发板上TouchPad设备进行简单的寄存器读写访问，基本硬件信息如下：")]),s._v(" "),n("ul",[n("li",[n("p",[s._v("SOC：hi3516dv300。")])]),s._v(" "),n("li",[n("p",[s._v("Touch IC：I2C地址为0x38, IC内部寄存器位宽为1字节。")])]),s._v(" "),n("li",[n("p",[s._v("原理图信息：TouchPad设备挂接在3号I2C控制器下；IC的复位管脚为3号GPIO。")])])]),s._v(" "),n("p",[s._v("本例程首先对Touch IC进行复位操作（开发板上电默认会给TouchIC供电，本例程不考虑供电），然后对其内部寄存器进行随机读写，测试I2C通路是否正常。")]),s._v(" "),n("blockquote",[n("p",[n("img",{attrs:{src:a(185),alt:""}}),s._v(" "),n("strong",[s._v("说明：")]),s._v("\n本例程重点在于展示I2C设备访问流程，并验证I2C通路，所以对于设备寄存器读写值不做关注，读写寄存器导致的行为由设备自身决定。")])]),s._v(" "),n("p",[s._v("示例如下：")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v('#include "i2c_if.h"          /* I2C标准接口头文件 */\n#include "gpio_if.h"         /* GPIO标准接口头文件 */\n#include "hdf_log.h"         /* 标准日志打印头文件 */\n#include "osal_io.h"         /* 标准IO读写接口头文件 */\n#include "osal_time.h"       /* 标准延迟&睡眠接口头文件 */\n\n/* 定义一个表示TP设备的结构体，存储i2c及gpio相关硬件信息 */\nstruct TpI2cDevice {\n    uint16_t rstGpio;             /* 复位管脚 */\n    uint16_t busId;               /* I2C总线号 */ \n    uint16_t addr;                /* I2C设备地址 */ \n    uint16_t regLen;              /* 寄存器字节宽度 */ \n    DevHandle i2cHandle;  /* I2C控制器句柄 */ \n};\n\n/* I2C管脚io配置，需要查阅SOC寄存器手册  */\n#define I2C3_DATA_REG_ADDR 0x112f008c /* 3号I2C控制器SDA管脚配置寄存器地址 */\n#define I2C3_CLK_REG_ADDR 0x112f0090  /* 3号I2C控制器SCL管脚配置寄存器地址 */\n#define I2C_REG_CFG 0x5f1             /* 3号I2C控制器SDA及SCL管脚配置值 */\n\nstatic void TpSocIoCfg(void)\n{\n    /* 将3号I2C控制器对应两个管脚的IO功能设置为I2C */\n    OSAL_WRITEL(I2C_REG_CFG, IO_DEVICE_ADDR(I2C3_DATA_REG_ADDR));\n    OSAL_WRITEL(I2C_REG_CFG, IO_DEVICE_ADDR(I2C3_CLK_REG_ADDR));\n}\n\n/* 对TP的复位管脚进行初始化， 拉高维持20ms, 再拉底维持50ms，最后再拉高维持20ms， 完成复位动作 */\nstatic int32_t TestCaseGpioInit(struct TpI2cDevice *tpDevice)\n{\n    int32_t ret;\n\n    /* 设置复位管脚方向为输出 */ \n    ret = GpioSetDir(tpDevice->rstGpio, GPIO_DIR_OUT);\n    if (ret != HDF_SUCCESS) {\n        HDF_LOGE("%s: set rst dir fail!:%d", __func__, ret);\n        return ret;\n    }\n\n    ret = GpioWrite(tpDevice->rstGpio, GPIO_VAL_HIGH);\n    if (ret != HDF_SUCCESS) {\n        HDF_LOGE("%s: set rst hight fail!:%d", __func__, ret);\n        return ret;\n    }\n    OsalMSleep(20);\n\n    ret = GpioWrite(tpDevice->rstGpio, GPIO_VAL_LOW);\n    if (ret != HDF_SUCCESS) {\n        HDF_LOGE("%s: set rst low fail!:%d", __func__, ret);\n        return ret;\n    }\n    OsalMSleep(50);\n\n    ret = GpioWrite(tpDevice->rstGpio, GPIO_VAL_HIGH);\n    if (ret != HDF_SUCCESS) {\n        HDF_LOGE("%s: set rst high fail!:%d", __func__, ret);\n        return ret;\n    }\n    OsalMSleep(20);\n\n    return HDF_SUCCESS;\n}\n\n/* 基于I2cTransfer方法封装一个寄存器读写的辅助函数， 通过flag表示读或写 */\nstatic int TpI2cReadWrite(struct TpI2cDevice *tpDevice, unsigned int regAddr,\n    unsigned char *regData, unsigned int dataLen, uint8_t flag)\n{\n    int index = 0;\n    unsigned char regBuf[4] = {0};\n    struct I2cMsg msgs[2] = {0};\n\n    /* 单双字节寄存器长度适配 */\n    if (tpDevice->regLen == 1) { \n        regBuf[index++] = regAddr & 0xFF;\n    } else {\n        regBuf[index++] = (regAddr >> 8) & 0xFF;\n        regBuf[index++] = regAddr & 0xFF;\n    }\n\n    /* 填充I2cMsg消息结构 */ \n    msgs[0].addr = tpDevice->addr;\n    msgs[0].flags = 0; /* 标记为0，表示写入 */ \n    msgs[0].len = tpDevice->regLen;\n    msgs[0].buf = regBuf;\n\n    msgs[1].addr = tpDevice->addr;\n    msgs[1].flags = (flag == 1) ? I2C_FLAG_READ : 0; /* 添加读标记位，表示读取 */ \n    msgs[1].len = dataLen;\n    msgs[1].buf = regData;\n\n    if (I2cTransfer(tpDevice->i2cHandle, msgs, 2) != 2) {\n        HDF_LOGE("%s: i2c read err", __func__);\n        return HDF_FAILURE;\n    }\n    return HDF_SUCCESS;\n}\n\n/* TP寄存器读函数 */ \nstatic inline int TpI2cReadReg(struct TpI2cDevice *tpDevice, unsigned int regAddr,\n    unsigned char *regData, unsigned int dataLen)\n{\n    return TpI2cReadWrite(tpDevice, regAddr, regData, dataLen, 1);\n}\n\n/* TP寄存器写函数 */ \nstatic inline int TpI2cWriteReg(struct TpI2cDevice *tpDevice, unsigned int regAddr,\n    unsigned char *regData, unsigned int dataLen)\n{\n    return TpI2cReadWrite(tpDevice, regAddr, regData, dataLen, 0);\n}\n\n/* I2C例程总入口 */ \nstatic int32_t TestCaseI2c(void)\n{\n    int32_t i;\n    int32_t ret;\n    unsigned char bufWrite[7] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xA, 0xB, 0xC };\n    unsigned char bufRead[7] = {0};\n    static struct TpI2cDevice tpDevice;\n\n    /* IO管脚功能配置 */\n    TpSocIoCfg();\n\n    /* TP设备信息初始化 */ \n    tpDevice.rstGpio = 3;\n    tpDevice.busId = 3;\n    tpDevice.addr = 0x38;\n    tpDevice.regLen = 1;\n    tpDevice.i2cHandle = NULL;\n\n    /* GPIO管脚初始化 */ \n    ret = TestCaseGpioInit(&tpDevice);\n    if (ret != HDF_SUCCESS) {\n        HDF_LOGE("%s: gpio init fail!:%d", __func__, ret);\n        return ret;\n    }\n\n    /* 打开I2C控制器 */ \n    tpDevice.i2cHandle = I2cOpen(tpDevice.busId);\n    if (tpDevice.i2cHandle == NULL) {\n        HDF_LOGE("%s: Open I2c:%u fail!", __func__, tpDevice.busId);\n        return -1;\n    }\n\n    /* 向TP-IC的0xD5寄存器连续写7字节数据 */ \n    ret = TpI2cWriteReg(&tpDevice, 0xD5, bufWrite, 7);\n    if (ret != HDF_SUCCESS) {\n        HDF_LOGE("%s: tp i2c write reg fail!:%d", __func__, ret);\n        I2cClose(tpDevice.i2cHandle);\n        return -1;\n    }\n    OsalMSleep(10);\n\n    /* 从TP-IC的0xD5寄存器连续读7字节数据 */ \n    ret = TpI2cReadReg(&tpDevice, 0xD5, bufRead, 7);\n    if (ret != HDF_SUCCESS) {\n        HDF_LOGE("%s: tp i2c read reg fail!:%d", __func__, ret);\n        I2cClose(tpDevice.i2cHandle);\n        return -1;\n    }\n\n    HDF_LOGE("%s: tp i2c write&read reg success!", __func__);\n    for (i = 0; i < 7; i++) {\n        HDF_LOGE("%s: bufRead[%d] = 0x%x", __func__, i, bufRead[i]);\n    }\n\n    /* 访问完毕关闭I2C控制器 */ \n    I2cClose(tpDevice.i2cHandle);\n    return ret;\n}\n')])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br"),n("span",{staticClass:"line-number"},[s._v("8")]),n("br"),n("span",{staticClass:"line-number"},[s._v("9")]),n("br"),n("span",{staticClass:"line-number"},[s._v("10")]),n("br"),n("span",{staticClass:"line-number"},[s._v("11")]),n("br"),n("span",{staticClass:"line-number"},[s._v("12")]),n("br"),n("span",{staticClass:"line-number"},[s._v("13")]),n("br"),n("span",{staticClass:"line-number"},[s._v("14")]),n("br"),n("span",{staticClass:"line-number"},[s._v("15")]),n("br"),n("span",{staticClass:"line-number"},[s._v("16")]),n("br"),n("span",{staticClass:"line-number"},[s._v("17")]),n("br"),n("span",{staticClass:"line-number"},[s._v("18")]),n("br"),n("span",{staticClass:"line-number"},[s._v("19")]),n("br"),n("span",{staticClass:"line-number"},[s._v("20")]),n("br"),n("span",{staticClass:"line-number"},[s._v("21")]),n("br"),n("span",{staticClass:"line-number"},[s._v("22")]),n("br"),n("span",{staticClass:"line-number"},[s._v("23")]),n("br"),n("span",{staticClass:"line-number"},[s._v("24")]),n("br"),n("span",{staticClass:"line-number"},[s._v("25")]),n("br"),n("span",{staticClass:"line-number"},[s._v("26")]),n("br"),n("span",{staticClass:"line-number"},[s._v("27")]),n("br"),n("span",{staticClass:"line-number"},[s._v("28")]),n("br"),n("span",{staticClass:"line-number"},[s._v("29")]),n("br"),n("span",{staticClass:"line-number"},[s._v("30")]),n("br"),n("span",{staticClass:"line-number"},[s._v("31")]),n("br"),n("span",{staticClass:"line-number"},[s._v("32")]),n("br"),n("span",{staticClass:"line-number"},[s._v("33")]),n("br"),n("span",{staticClass:"line-number"},[s._v("34")]),n("br"),n("span",{staticClass:"line-number"},[s._v("35")]),n("br"),n("span",{staticClass:"line-number"},[s._v("36")]),n("br"),n("span",{staticClass:"line-number"},[s._v("37")]),n("br"),n("span",{staticClass:"line-number"},[s._v("38")]),n("br"),n("span",{staticClass:"line-number"},[s._v("39")]),n("br"),n("span",{staticClass:"line-number"},[s._v("40")]),n("br"),n("span",{staticClass:"line-number"},[s._v("41")]),n("br"),n("span",{staticClass:"line-number"},[s._v("42")]),n("br"),n("span",{staticClass:"line-number"},[s._v("43")]),n("br"),n("span",{staticClass:"line-number"},[s._v("44")]),n("br"),n("span",{staticClass:"line-number"},[s._v("45")]),n("br"),n("span",{staticClass:"line-number"},[s._v("46")]),n("br"),n("span",{staticClass:"line-number"},[s._v("47")]),n("br"),n("span",{staticClass:"line-number"},[s._v("48")]),n("br"),n("span",{staticClass:"line-number"},[s._v("49")]),n("br"),n("span",{staticClass:"line-number"},[s._v("50")]),n("br"),n("span",{staticClass:"line-number"},[s._v("51")]),n("br"),n("span",{staticClass:"line-number"},[s._v("52")]),n("br"),n("span",{staticClass:"line-number"},[s._v("53")]),n("br"),n("span",{staticClass:"line-number"},[s._v("54")]),n("br"),n("span",{staticClass:"line-number"},[s._v("55")]),n("br"),n("span",{staticClass:"line-number"},[s._v("56")]),n("br"),n("span",{staticClass:"line-number"},[s._v("57")]),n("br"),n("span",{staticClass:"line-number"},[s._v("58")]),n("br"),n("span",{staticClass:"line-number"},[s._v("59")]),n("br"),n("span",{staticClass:"line-number"},[s._v("60")]),n("br"),n("span",{staticClass:"line-number"},[s._v("61")]),n("br"),n("span",{staticClass:"line-number"},[s._v("62")]),n("br"),n("span",{staticClass:"line-number"},[s._v("63")]),n("br"),n("span",{staticClass:"line-number"},[s._v("64")]),n("br"),n("span",{staticClass:"line-number"},[s._v("65")]),n("br"),n("span",{staticClass:"line-number"},[s._v("66")]),n("br"),n("span",{staticClass:"line-number"},[s._v("67")]),n("br"),n("span",{staticClass:"line-number"},[s._v("68")]),n("br"),n("span",{staticClass:"line-number"},[s._v("69")]),n("br"),n("span",{staticClass:"line-number"},[s._v("70")]),n("br"),n("span",{staticClass:"line-number"},[s._v("71")]),n("br"),n("span",{staticClass:"line-number"},[s._v("72")]),n("br"),n("span",{staticClass:"line-number"},[s._v("73")]),n("br"),n("span",{staticClass:"line-number"},[s._v("74")]),n("br"),n("span",{staticClass:"line-number"},[s._v("75")]),n("br"),n("span",{staticClass:"line-number"},[s._v("76")]),n("br"),n("span",{staticClass:"line-number"},[s._v("77")]),n("br"),n("span",{staticClass:"line-number"},[s._v("78")]),n("br"),n("span",{staticClass:"line-number"},[s._v("79")]),n("br"),n("span",{staticClass:"line-number"},[s._v("80")]),n("br"),n("span",{staticClass:"line-number"},[s._v("81")]),n("br"),n("span",{staticClass:"line-number"},[s._v("82")]),n("br"),n("span",{staticClass:"line-number"},[s._v("83")]),n("br"),n("span",{staticClass:"line-number"},[s._v("84")]),n("br"),n("span",{staticClass:"line-number"},[s._v("85")]),n("br"),n("span",{staticClass:"line-number"},[s._v("86")]),n("br"),n("span",{staticClass:"line-number"},[s._v("87")]),n("br"),n("span",{staticClass:"line-number"},[s._v("88")]),n("br"),n("span",{staticClass:"line-number"},[s._v("89")]),n("br"),n("span",{staticClass:"line-number"},[s._v("90")]),n("br"),n("span",{staticClass:"line-number"},[s._v("91")]),n("br"),n("span",{staticClass:"line-number"},[s._v("92")]),n("br"),n("span",{staticClass:"line-number"},[s._v("93")]),n("br"),n("span",{staticClass:"line-number"},[s._v("94")]),n("br"),n("span",{staticClass:"line-number"},[s._v("95")]),n("br"),n("span",{staticClass:"line-number"},[s._v("96")]),n("br"),n("span",{staticClass:"line-number"},[s._v("97")]),n("br"),n("span",{staticClass:"line-number"},[s._v("98")]),n("br"),n("span",{staticClass:"line-number"},[s._v("99")]),n("br"),n("span",{staticClass:"line-number"},[s._v("100")]),n("br"),n("span",{staticClass:"line-number"},[s._v("101")]),n("br"),n("span",{staticClass:"line-number"},[s._v("102")]),n("br"),n("span",{staticClass:"line-number"},[s._v("103")]),n("br"),n("span",{staticClass:"line-number"},[s._v("104")]),n("br"),n("span",{staticClass:"line-number"},[s._v("105")]),n("br"),n("span",{staticClass:"line-number"},[s._v("106")]),n("br"),n("span",{staticClass:"line-number"},[s._v("107")]),n("br"),n("span",{staticClass:"line-number"},[s._v("108")]),n("br"),n("span",{staticClass:"line-number"},[s._v("109")]),n("br"),n("span",{staticClass:"line-number"},[s._v("110")]),n("br"),n("span",{staticClass:"line-number"},[s._v("111")]),n("br"),n("span",{staticClass:"line-number"},[s._v("112")]),n("br"),n("span",{staticClass:"line-number"},[s._v("113")]),n("br"),n("span",{staticClass:"line-number"},[s._v("114")]),n("br"),n("span",{staticClass:"line-number"},[s._v("115")]),n("br"),n("span",{staticClass:"line-number"},[s._v("116")]),n("br"),n("span",{staticClass:"line-number"},[s._v("117")]),n("br"),n("span",{staticClass:"line-number"},[s._v("118")]),n("br"),n("span",{staticClass:"line-number"},[s._v("119")]),n("br"),n("span",{staticClass:"line-number"},[s._v("120")]),n("br"),n("span",{staticClass:"line-number"},[s._v("121")]),n("br"),n("span",{staticClass:"line-number"},[s._v("122")]),n("br"),n("span",{staticClass:"line-number"},[s._v("123")]),n("br"),n("span",{staticClass:"line-number"},[s._v("124")]),n("br"),n("span",{staticClass:"line-number"},[s._v("125")]),n("br"),n("span",{staticClass:"line-number"},[s._v("126")]),n("br"),n("span",{staticClass:"line-number"},[s._v("127")]),n("br"),n("span",{staticClass:"line-number"},[s._v("128")]),n("br"),n("span",{staticClass:"line-number"},[s._v("129")]),n("br"),n("span",{staticClass:"line-number"},[s._v("130")]),n("br"),n("span",{staticClass:"line-number"},[s._v("131")]),n("br"),n("span",{staticClass:"line-number"},[s._v("132")]),n("br"),n("span",{staticClass:"line-number"},[s._v("133")]),n("br"),n("span",{staticClass:"line-number"},[s._v("134")]),n("br"),n("span",{staticClass:"line-number"},[s._v("135")]),n("br"),n("span",{staticClass:"line-number"},[s._v("136")]),n("br"),n("span",{staticClass:"line-number"},[s._v("137")]),n("br"),n("span",{staticClass:"line-number"},[s._v("138")]),n("br"),n("span",{staticClass:"line-number"},[s._v("139")]),n("br"),n("span",{staticClass:"line-number"},[s._v("140")]),n("br"),n("span",{staticClass:"line-number"},[s._v("141")]),n("br"),n("span",{staticClass:"line-number"},[s._v("142")]),n("br"),n("span",{staticClass:"line-number"},[s._v("143")]),n("br"),n("span",{staticClass:"line-number"},[s._v("144")]),n("br"),n("span",{staticClass:"line-number"},[s._v("145")]),n("br"),n("span",{staticClass:"line-number"},[s._v("146")]),n("br"),n("span",{staticClass:"line-number"},[s._v("147")]),n("br"),n("span",{staticClass:"line-number"},[s._v("148")]),n("br"),n("span",{staticClass:"line-number"},[s._v("149")]),n("br"),n("span",{staticClass:"line-number"},[s._v("150")]),n("br"),n("span",{staticClass:"line-number"},[s._v("151")]),n("br"),n("span",{staticClass:"line-number"},[s._v("152")]),n("br"),n("span",{staticClass:"line-number"},[s._v("153")]),n("br"),n("span",{staticClass:"line-number"},[s._v("154")]),n("br"),n("span",{staticClass:"line-number"},[s._v("155")]),n("br"),n("span",{staticClass:"line-number"},[s._v("156")]),n("br"),n("span",{staticClass:"line-number"},[s._v("157")]),n("br"),n("span",{staticClass:"line-number"},[s._v("158")]),n("br"),n("span",{staticClass:"line-number"},[s._v("159")]),n("br"),n("span",{staticClass:"line-number"},[s._v("160")]),n("br"),n("span",{staticClass:"line-number"},[s._v("161")]),n("br"),n("span",{staticClass:"line-number"},[s._v("162")]),n("br"),n("span",{staticClass:"line-number"},[s._v("163")]),n("br"),n("span",{staticClass:"line-number"},[s._v("164")]),n("br"),n("span",{staticClass:"line-number"},[s._v("165")]),n("br"),n("span",{staticClass:"line-number"},[s._v("166")]),n("br"),n("span",{staticClass:"line-number"},[s._v("167")]),n("br"),n("span",{staticClass:"line-number"},[s._v("168")]),n("br"),n("span",{staticClass:"line-number"},[s._v("169")]),n("br"),n("span",{staticClass:"line-number"},[s._v("170")]),n("br")])])])}),[],!1,null,null,null);t.default=e.exports},2133:function(s,t,a){"use strict";a.r(t);var n=a(1),e=Object(n.a)({},(function(){var s=this,t=s.$createElement,n=s._self._c||t;return n("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[n("h1",{attrs:{id:"i2c"}},[s._v("I2C"),n("a",{attrs:{name:"ZH-CN_TOPIC_0000001176922456"}})]),s._v(" "),n("ul",[n("li",[n("a",{attrs:{href:"#section2040078630114257"}},[s._v("概述")])]),s._v(" "),n("li",[n("a",{attrs:{href:"#section752964871810"}},[s._v("接口说明")])]),s._v(" "),n("li",[n("a",{attrs:{href:"#section1085786591114257"}},[s._v("开发步骤")])]),s._v(" "),n("li",[n("a",{attrs:{href:"#section1773332551114257"}},[s._v("开发实例")])])]),s._v(" "),n("h2",{attrs:{id:"概述"}},[s._v("概述"),n("a",{attrs:{name:"section2040078630114257"}})]),s._v(" "),n("p",[s._v("I2C(Inter Integrated Circuit)总线是由Philips公司开发的一种简单、双向二线制同步串行总线,在HDF框架中，I2C模块接口适配模式采用统一服务模式，这需要一个设备服务来作为I2C模块的管理器，统一处理外部访问，这会在配置文件中有所体现。统一服务模式适合于同类型设备对象较多的情况，如I2C可能同时具备十几个控制器，采用独立服务模式需要配置更多的设备节点，且服务会占据内存资源。")]),s._v(" "),n("p",[n("strong",[s._v("图 1")]),s._v("  I2C统一服务模式结构图"),n("a",{attrs:{name:"fig17640124912440"}}),n("br"),s._v(" "),n("img",{attrs:{src:a(1020),alt:""}})]),s._v(" "),n("h2",{attrs:{id:"接口说明"}},[s._v("接口说明"),n("a",{attrs:{name:"section752964871810"}})]),s._v(" "),n("p",[s._v("I2cMethod和I2cLockMethod定义：")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v("struct I2cMethod {\nint32_t (*transfer)(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count);\n};\nstruct I2cLockMethod {//锁机制操作结构体\n    int32_t (*lock)(struct I2cCntlr *cntlr);//加锁\n    void (*unlock)(struct I2cCntlr *cntlr); //解锁\n};\n")])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br")])]),n("p",[n("strong",[s._v("表 1")]),s._v("  I2cMethod结构体成员的回调函数功能说明")]),s._v(" "),n("p",[n("a",{attrs:{name:"table139121605913"}}),s._v(" "),n("table",[n("thead",{attrs:{align:"left"}},[n("tr",{attrs:{id:"row1391101625915"}},[n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20%",id:"mcps1.2.6.1.1"}},[n("p",{attrs:{id:"p11391151619599"}},[n("a",{attrs:{name:"p11391151619599"}}),n("a",{attrs:{name:"p11391151619599"}}),s._v("函数成员")])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20%",id:"mcps1.2.6.1.2"}},[n("p",{attrs:{id:"p1539261618596"}},[n("a",{attrs:{name:"p1539261618596"}}),n("a",{attrs:{name:"p1539261618596"}}),s._v("入参")])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20%",id:"mcps1.2.6.1.3"}},[n("p",{attrs:{id:"p2392416175914"}},[n("a",{attrs:{name:"p2392416175914"}}),n("a",{attrs:{name:"p2392416175914"}}),s._v("出参")])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20%",id:"mcps1.2.6.1.4"}},[n("p",{attrs:{id:"p103926169598"}},[n("a",{attrs:{name:"p103926169598"}}),n("a",{attrs:{name:"p103926169598"}}),s._v("返回值")])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20%",id:"mcps1.2.6.1.5"}},[n("p",{attrs:{id:"p163921316175917"}},[n("a",{attrs:{name:"p163921316175917"}}),n("a",{attrs:{name:"p163921316175917"}}),s._v("功能")])])])]),s._v(" "),n("tbody",[n("tr",{attrs:{id:"row339221695916"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20%",headers:"mcps1.2.6.1.1 "}},[n("p",{attrs:{id:"p1392716195914"}},[n("a",{attrs:{name:"p1392716195914"}}),n("a",{attrs:{name:"p1392716195914"}}),s._v("transfer")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20%",headers:"mcps1.2.6.1.2 "}},[n("p",{attrs:{id:"p193923162593"}},[n("a",{attrs:{name:"p193923162593"}}),n("a",{attrs:{name:"p193923162593"}}),s._v("cntlr：结构体指针，核心层I2C控制器;msgs：结构体指针，用户消息 ;count：uint16_t，消息数量")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20%",headers:"mcps1.2.6.1.3 "}},[n("p",{attrs:{id:"p1539212165594"}},[n("a",{attrs:{name:"p1539212165594"}}),n("a",{attrs:{name:"p1539212165594"}}),s._v("无")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20%",headers:"mcps1.2.6.1.4 "}},[n("p",{attrs:{id:"p139291617594"}},[n("a",{attrs:{name:"p139291617594"}}),n("a",{attrs:{name:"p139291617594"}}),s._v("HDF_STATUS相关状态")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"20%",headers:"mcps1.2.6.1.5 "}},[n("p",{attrs:{id:"p6392121655919"}},[n("a",{attrs:{name:"p6392121655919"}}),n("a",{attrs:{name:"p6392121655919"}}),s._v("传递用户消息")])])])])])]),s._v(" "),n("h2",{attrs:{id:"开发步骤"}},[s._v("开发步骤"),n("a",{attrs:{name:"section1085786591114257"}})]),s._v(" "),n("p",[s._v("I2C模块适配的三个环节是配置属性文件，实例化驱动入口，以及实例化核心层接口函数。")]),s._v(" "),n("ol",[n("li",[n("p",[n("strong",[s._v("实例化驱动入口：")])]),s._v(" "),n("ul",[n("li",[s._v("实例化HdfDriverEntry结构体成员。")]),s._v(" "),n("li",[s._v("调用HDF_INIT将HdfDriverEntry实例化对象注册到HDF框架中。")])])]),s._v(" "),n("li",[n("p",[n("strong",[s._v("配置属性文件：")])]),s._v(" "),n("ul",[n("li",[s._v("在device_info.hcs文件中添加deviceNode描述。")]),s._v(" "),n("li",[s._v("【可选】添加i2c_config.hcs器件属性文件。")])])]),s._v(" "),n("li",[n("p",[n("strong",[s._v("实例化I2C控制器对象：")])]),s._v(" "),n("ul",[n("li",[n("p",[s._v("初始化I2cCntlr成员。")])]),s._v(" "),n("li",[n("p",[s._v("实例化I2cCntlr成员I2cMethod和I2cLockMethod。")]),s._v(" "),n("blockquote",[n("p",[n("img",{attrs:{src:a(185),alt:""}}),s._v(" "),n("strong",[s._v("说明：")]),s._v("\n实例化I2cCntlr成员I2cMethod和I2cLockMethod，详见"),n("a",{attrs:{href:"#section752964871810"}},[s._v("接口说明")]),s._v("。")])])])])]),s._v(" "),n("li",[n("p",[n("strong",[s._v("驱动调试：")])]),s._v(" "),n("p",[s._v("【可选】针对新增驱动程序，建议验证驱动基本功能，例如挂载后的信息反馈，消息传输的成功与否等。")])])]),s._v(" "),n("h2",{attrs:{id:"开发实例"}},[s._v("开发实例"),n("a",{attrs:{name:"section1773332551114257"}})]),s._v(" "),n("p",[s._v("下方将以i2c_hi35xx.c为示例，展示需要厂商提供哪些内容来完整实现设备功能。")]),s._v(" "),n("ol",[n("li",[n("p",[s._v("驱动开发首先需要实例化驱动入口，驱动入口必须为HdfDriverEntry（在 hdf_device_desc.h 中定义）类型的全局变量，且moduleName要和device_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总，形成一个类似数组的段地址空间，方便上层调用。")]),s._v(" "),n("p",[s._v("一般在加载驱动时HDF会先调用Bind函数，再调用Init函数加载该驱动。当Init调用异常时，HDF框架会调用Release释放驱动资源并退出。")]),s._v(" "),n("p",[s._v("I2C驱动入口参考：")]),s._v(" "),n("p",[s._v("I2C模块这种类型的控制器会出现很多个设备挂接的情况，因而在HDF框架中首先会为这类型的设备创建一个管理器对象，并同时对外发布一个管理器服务来统一处理外部访问。这样，用户需要打开某个设备时，会先获取到管理器服务，然后管理器服务根据用户指定参数查找到指定设备。")]),s._v(" "),n("p",[s._v("I2C管理器服务的驱动由核心层实现，厂商不需要关注这部分内容的实现，这个但在实现Init函数的时候需要调用核心层的I2cCntlrAdd函数，它会实现相应功能。")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v('struct HdfDriverEntry g_i2cDriverEntry = {\n    .moduleVersion = 1,\n    .Init = Hi35xxI2cInit,\n    .Release = Hi35xxI2cRelease,\n    .moduleName = "hi35xx_i2c_driver",//【必要且与config.hcs文件里面匹配】\n};\nHDF_INIT(g_i2cDriverEntry);           //调用HDF_INIT将驱动入口注册到HDF框架中\n\n//核心层i2c_core.c 管理器服务的驱动入口\nstruct HdfDriverEntry g_i2cManagerEntry = {\n    .moduleVersion = 1,\n    .Bind = I2cManagerBind,\n    .Init = I2cManagerInit,\n    .Release = I2cManagerRelease,\n    .moduleName = "HDF_PLATFORM_I2C_MANAGER",//这与device_info文件中device0对应\n};\nHDF_INIT(g_i2cManagerEntry);\n')])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br"),n("span",{staticClass:"line-number"},[s._v("8")]),n("br"),n("span",{staticClass:"line-number"},[s._v("9")]),n("br"),n("span",{staticClass:"line-number"},[s._v("10")]),n("br"),n("span",{staticClass:"line-number"},[s._v("11")]),n("br"),n("span",{staticClass:"line-number"},[s._v("12")]),n("br"),n("span",{staticClass:"line-number"},[s._v("13")]),n("br"),n("span",{staticClass:"line-number"},[s._v("14")]),n("br"),n("span",{staticClass:"line-number"},[s._v("15")]),n("br"),n("span",{staticClass:"line-number"},[s._v("16")]),n("br"),n("span",{staticClass:"line-number"},[s._v("17")]),n("br")])])]),s._v(" "),n("li",[n("p",[s._v("完成驱动入口注册之后，下一步请在device_info.hcs文件中添加deviceNode信息，并在i2c_config.hcs中配置器件属性。deviceNode信息与驱动入口注册相关，器件属性值对于厂商驱动的实现以及核心层I2cCntlr相关成员的默认值或限制范围有密切关系。")]),s._v(" "),n("p",[s._v("统一服务模式的特点是device_info文件中第一个设备节点必须为I2C管理器，其各项参数必须如"),n("a",{attrs:{href:"#table96651915911"}},[s._v("表2")]),s._v("设置：")]),s._v(" "),n("p",[n("strong",[s._v("表 2")]),s._v("  统一服务模式的特点")]),s._v(" "),n("p",[n("a",{attrs:{name:"table96651915911"}}),s._v(" "),n("table",[n("thead",{attrs:{align:"left"}},[n("tr",{attrs:{id:"row96618194915"}},[n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",id:"mcps1.2.3.1.1"}},[n("p",{attrs:{id:"p1066119790"}},[n("a",{attrs:{name:"p1066119790"}}),n("a",{attrs:{name:"p1066119790"}}),s._v("成员名")])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",id:"mcps1.2.3.1.2"}},[n("p",{attrs:{id:"p8674191494"}},[n("a",{attrs:{name:"p8674191494"}}),n("a",{attrs:{name:"p8674191494"}}),s._v("值")])])])]),s._v(" "),n("tbody",[n("tr",{attrs:{id:"row767111916914"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p46714196920"}},[n("a",{attrs:{name:"p46714196920"}}),n("a",{attrs:{name:"p46714196920"}}),s._v("moduleName")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p36717191292"}},[n("a",{attrs:{name:"p36717191292"}}),n("a",{attrs:{name:"p36717191292"}}),s._v("固定为 HDF_PLATFORM_I2C_MANAGER")])])]),s._v(" "),n("tr",{attrs:{id:"row16671119392"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p11671019699"}},[n("a",{attrs:{name:"p11671019699"}}),n("a",{attrs:{name:"p11671019699"}}),s._v("serviceName")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p86716195912"}},[n("a",{attrs:{name:"p86716195912"}}),n("a",{attrs:{name:"p86716195912"}}),s._v("固定为 HDF_PLATFORM_I2C_MANAGER")])])]),s._v(" "),n("tr",{attrs:{id:"row17673191911"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p5673191898"}},[n("a",{attrs:{name:"p5673191898"}}),n("a",{attrs:{name:"p5673191898"}}),s._v("policy")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p18677191699"}},[n("a",{attrs:{name:"p18677191699"}}),n("a",{attrs:{name:"p18677191699"}}),s._v("具体配置为1或2取决于是否对用户态可见")])])]),s._v(" "),n("tr",{attrs:{id:"row8675191894"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p12677191913"}},[n("a",{attrs:{name:"p12677191913"}}),n("a",{attrs:{name:"p12677191913"}}),s._v("deviceMatchAttr")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p1567171918915"}},[n("a",{attrs:{name:"p1567171918915"}}),n("a",{attrs:{name:"p1567171918915"}}),s._v("没有使用，可忽略")])])])])])]),s._v(" "),n("p",[s._v("从第二个节点开始配置具体I2C控制器信息，此节点并不表示某一路I2C控制器，而是代表一个资源性质设备，用于描述一类I2C控制器的信息。多个控制器之间相互区分的参数是busID和reg_pbase，这在i2c_config文件中有所体现。")]),s._v(" "),n("ul",[n("li",[n("p",[s._v("device_info.hcs 配置参考。")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v('root {\ndevice_info {\nmatch_attr = "hdf_manager";\n    device_i2c :: device {\n    device0 :: deviceNode {\n        policy = 2;\n        priority = 50;\n        permission = 0644;\n        moduleName = "HDF_PLATFORM_I2C_MANAGER";\n        serviceName = "HDF_PLATFORM_I2C_MANAGER";\n        deviceMatchAttr = "hdf_platform_i2c_manager";\n    }\n    device1 :: deviceNode {\n        policy = 0;                              // 等于0，不需要发布服务\n        priority = 55;                           // 驱动启动优先级\n        permission = 0644;                       // 驱动创建设备节点权限\n        moduleName = "hi35xx_i2c_driver";        //【必要】用于指定驱动名称，需要与期望的驱动Entry中的moduleName一致；\n        serviceName = "HI35XX_I2C_DRIVER";       //【必要】驱动对外发布服务的名称，必须唯一\n        deviceMatchAttr = "hisilicon_hi35xx_i2c";//【必要】用于配置控制器私有数据，要与i2c_config.hcs中对应控制器保持一致\n                                                // 具体的控制器信息在 i2c_config.hcs 中\n    }\n    }\n}\n}\n')])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br"),n("span",{staticClass:"line-number"},[s._v("8")]),n("br"),n("span",{staticClass:"line-number"},[s._v("9")]),n("br"),n("span",{staticClass:"line-number"},[s._v("10")]),n("br"),n("span",{staticClass:"line-number"},[s._v("11")]),n("br"),n("span",{staticClass:"line-number"},[s._v("12")]),n("br"),n("span",{staticClass:"line-number"},[s._v("13")]),n("br"),n("span",{staticClass:"line-number"},[s._v("14")]),n("br"),n("span",{staticClass:"line-number"},[s._v("15")]),n("br"),n("span",{staticClass:"line-number"},[s._v("16")]),n("br"),n("span",{staticClass:"line-number"},[s._v("17")]),n("br"),n("span",{staticClass:"line-number"},[s._v("18")]),n("br"),n("span",{staticClass:"line-number"},[s._v("19")]),n("br"),n("span",{staticClass:"line-number"},[s._v("20")]),n("br"),n("span",{staticClass:"line-number"},[s._v("21")]),n("br"),n("span",{staticClass:"line-number"},[s._v("22")]),n("br"),n("span",{staticClass:"line-number"},[s._v("23")]),n("br"),n("span",{staticClass:"line-number"},[s._v("24")]),n("br")])])]),s._v(" "),n("li",[n("p",[s._v("i2c_config.hcs 配置参考。")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v('root {\nplatform {\n    i2c_config {\n    match_attr = "hisilicon_hi35xx_i2c";//【必要】需要和device_info.hcs中的deviceMatchAttr值一致\n    template i2c_controller {           //模板公共参数，继承该模板的节点如果使用模板中的默认值，则节点字段可以缺省\n        bus = 0;                          //【必要】i2c 识别号\n        reg_pbase = 0x120b0000;           //【必要】物理基地址\n        reg_size = 0xd1;                  //【必要】寄存器位宽\n        irq = 0;                          //【可选】根据厂商需要来使用\n        freq = 400000;                    //【可选】根据厂商需要来使用\n        clk = 50000000;                   //【可选】根据厂商需要来使用\n    }\n    controller_0x120b0000 :: i2c_controller {\n        bus = 0;\n    }\n    controller_0x120b1000 :: i2c_controller {\n        bus = 1;\n        reg_pbase = 0x120b1000;\n    }\n    ...\n    }\n}\n}\n')])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br"),n("span",{staticClass:"line-number"},[s._v("8")]),n("br"),n("span",{staticClass:"line-number"},[s._v("9")]),n("br"),n("span",{staticClass:"line-number"},[s._v("10")]),n("br"),n("span",{staticClass:"line-number"},[s._v("11")]),n("br"),n("span",{staticClass:"line-number"},[s._v("12")]),n("br"),n("span",{staticClass:"line-number"},[s._v("13")]),n("br"),n("span",{staticClass:"line-number"},[s._v("14")]),n("br"),n("span",{staticClass:"line-number"},[s._v("15")]),n("br"),n("span",{staticClass:"line-number"},[s._v("16")]),n("br"),n("span",{staticClass:"line-number"},[s._v("17")]),n("br"),n("span",{staticClass:"line-number"},[s._v("18")]),n("br"),n("span",{staticClass:"line-number"},[s._v("19")]),n("br"),n("span",{staticClass:"line-number"},[s._v("20")]),n("br"),n("span",{staticClass:"line-number"},[s._v("21")]),n("br"),n("span",{staticClass:"line-number"},[s._v("22")]),n("br"),n("span",{staticClass:"line-number"},[s._v("23")]),n("br")])])])])]),s._v(" "),n("li",[n("p",[s._v("完成驱动入口注册之后，最后一步就是以核心层I2cCntlr对象的初始化为核心，包括厂商自定义结构体（传递参数和数据），实例化I2cCntlr成员I2cMethod（让用户可以通过接口来调用驱动底层函数），实现HdfDriverEntry成员函数（Bind，Init，Release）。")]),s._v(" "),n("ul",[n("li",[n("p",[s._v("自定义结构体参考")]),s._v(" "),n("p",[s._v("从驱动的角度看，自定义结构体是参数和数据的载体，而且i2c_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员，其中一些重要数值也会传递给核心层I2cCntlr对象，例如设备号、总线号等。")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v("// 厂商自定义功能结构体\nstruct Hi35xxI2cCntlr {\n    struct I2cCntlr cntlr;            //【必要】是核心层控制对象，具体描述见下面\n    OsalSpinlock spin;                //【必要】厂商需要基于此锁变量对各个 i2c 操作函数实现对应的加锁解锁\n    volatile unsigned char  *regBase; //【必要】寄存器基地址\n    uint16_t regSize;                 //【必要】寄存器位宽\n    int16_t bus;                      //【必要】i2c_config.hcs 文件中可读取具体值\n    uint32_t clk;                     //【可选】厂商自定义\n    uint32_t freq;                    //【可选】厂商自定义\n    uint32_t irq;                     //【可选】厂商自定义\n    uint32_t regBasePhy;              //【必要】寄存器物理基地址\n};\n\n// I2cCntlr是核心层控制器结构体，其中的成员在Init函数中会被赋值\nstruct I2cCntlr {\n    struct OsalMutex lock;\n    void *owner;\n    int16_t busId;\n    void *priv;\n    const struct I2cMethod *ops;\n    const struct I2cLockMethod *lockOps;\n};\n")])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br"),n("span",{staticClass:"line-number"},[s._v("8")]),n("br"),n("span",{staticClass:"line-number"},[s._v("9")]),n("br"),n("span",{staticClass:"line-number"},[s._v("10")]),n("br"),n("span",{staticClass:"line-number"},[s._v("11")]),n("br"),n("span",{staticClass:"line-number"},[s._v("12")]),n("br"),n("span",{staticClass:"line-number"},[s._v("13")]),n("br"),n("span",{staticClass:"line-number"},[s._v("14")]),n("br"),n("span",{staticClass:"line-number"},[s._v("15")]),n("br"),n("span",{staticClass:"line-number"},[s._v("16")]),n("br"),n("span",{staticClass:"line-number"},[s._v("17")]),n("br"),n("span",{staticClass:"line-number"},[s._v("18")]),n("br"),n("span",{staticClass:"line-number"},[s._v("19")]),n("br"),n("span",{staticClass:"line-number"},[s._v("20")]),n("br"),n("span",{staticClass:"line-number"},[s._v("21")]),n("br"),n("span",{staticClass:"line-number"},[s._v("22")]),n("br")])])]),s._v(" "),n("li",[n("p",[s._v("I2cCntlr成员回调函数结构体I2cMethod的实例化，和锁机制回调函数结构体I2cLockMethod实例化,其他成员在Init函数中初始化。")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v("// i2c_hi35xx.c 中的示例\nstatic const struct I2cMethod g_method = {\n    .transfer = Hi35xxI2cTransfer,\n};\n\nstatic const struct I2cLockMethod g_lockOps = {\n    .lock = Hi35xxI2cLock,    //加锁函数\n    .unlock = Hi35xxI2cUnlock,//解锁函数\n};\n")])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br"),n("span",{staticClass:"line-number"},[s._v("8")]),n("br"),n("span",{staticClass:"line-number"},[s._v("9")]),n("br")])])]),s._v(" "),n("li",[n("p",[s._v("init函数参考")]),s._v(" "),n("p",[s._v("入参：")]),s._v(" "),n("p",[s._v("HdfDeviceObject 是整个驱动对外暴露的接口参数，具备 HCS 配置文件的信息。")]),s._v(" "),n("p",[s._v("返回值：")]),s._v(" "),n("p",[s._v("HDF_STATUS相关状态 （下表为部分展示，如需使用其他状态，可见//drivers/framework/include/utils/hdf_base.h中HDF_STATUS 定义）。")]),s._v(" "),n("p",[n("strong",[s._v("表 3")]),s._v("  init函数入参及返回值参考")]),s._v(" "),n("p",[n("a",{attrs:{name:"table1743073181511"}}),s._v(" "),n("table",[n("thead",{attrs:{align:"left"}},[n("tr",{attrs:{id:"row443033171513"}},[n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",id:"mcps1.2.3.1.1"}},[n("p",{attrs:{id:"p34306341517"}},[n("a",{attrs:{name:"p34306341517"}}),n("a",{attrs:{name:"p34306341517"}}),s._v("状态(值)")])]),s._v(" "),n("th",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",id:"mcps1.2.3.1.2"}},[n("p",{attrs:{id:"p1243123101510"}},[n("a",{attrs:{name:"p1243123101510"}}),n("a",{attrs:{name:"p1243123101510"}}),s._v("问题描述")])])])]),s._v(" "),n("tbody",[n("tr",{attrs:{id:"row5431638151"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p1043114319156"}},[n("a",{attrs:{name:"p1043114319156"}}),n("a",{attrs:{name:"p1043114319156"}}),s._v("HDF_ERR_INVALID_OBJECT")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p343173101513"}},[n("a",{attrs:{name:"p343173101513"}}),n("a",{attrs:{name:"p343173101513"}}),s._v("控制器对象非法")])])]),s._v(" "),n("tr",{attrs:{id:"row1243143181516"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p1443118317154"}},[n("a",{attrs:{name:"p1443118317154"}}),n("a",{attrs:{name:"p1443118317154"}}),s._v("HDF_ERR_INVALID_PARAM")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p343113341515"}},[n("a",{attrs:{name:"p343113341515"}}),n("a",{attrs:{name:"p343113341515"}}),s._v("参数非法")])])]),s._v(" "),n("tr",{attrs:{id:"row1943115391516"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p1843143171511"}},[n("a",{attrs:{name:"p1843143171511"}}),n("a",{attrs:{name:"p1843143171511"}}),s._v("HDF_ERR_MALLOC_FAIL")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p943114391515"}},[n("a",{attrs:{name:"p943114391515"}}),n("a",{attrs:{name:"p943114391515"}}),s._v("内存分配失败")])])]),s._v(" "),n("tr",{attrs:{id:"row1443183101514"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p54311031157"}},[n("a",{attrs:{name:"p54311031157"}}),n("a",{attrs:{name:"p54311031157"}}),s._v("HDF_ERR_IO")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p74315311158"}},[n("a",{attrs:{name:"p74315311158"}}),n("a",{attrs:{name:"p74315311158"}}),s._v("I/O 错误")])])]),s._v(" "),n("tr",{attrs:{id:"row3431437158"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p8432332158"}},[n("a",{attrs:{name:"p8432332158"}}),n("a",{attrs:{name:"p8432332158"}}),s._v("HDF_SUCCESS")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p104329391519"}},[n("a",{attrs:{name:"p104329391519"}}),n("a",{attrs:{name:"p104329391519"}}),s._v("传输成功")])])]),s._v(" "),n("tr",{attrs:{id:"row34321136152"}},[n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.1 "}},[n("p",{attrs:{id:"p184325391517"}},[n("a",{attrs:{name:"p184325391517"}}),n("a",{attrs:{name:"p184325391517"}}),s._v("HDF_FAILURE")])]),s._v(" "),n("td",{staticClass:"cellrowborder",attrs:{valign:"top",width:"50%",headers:"mcps1.2.3.1.2 "}},[n("p",{attrs:{id:"p1343220319154"}},[n("a",{attrs:{name:"p1343220319154"}}),n("a",{attrs:{name:"p1343220319154"}}),s._v("传输失败")])])])])])]),s._v(" "),n("p",[s._v("函数说明：")]),s._v(" "),n("p",[s._v("初始化自定义结构体对象，初始化I2cCntlr成员，调用核心层I2cCntlrAdd函数，【可选】接入VFS。")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v("static int32_t Hi35xxI2cInit(struct HdfDeviceObject *device)\n{\n    ...\n    //遍历、解析 i2c_config.hcs 中的所有配置节点，并分别进行初始化，需要调用Hi35xxI2cParseAndInit函数\n    DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) {\n        ret = Hi35xxI2cParseAndInit(device, childNode);//函数定义见下\n    ...\n    }\n    ...\n}\n\nstatic int32_t Hi35xxI2cParseAndInit(struct HdfDeviceObject *device, const struct DeviceResourceNode *node)\n{\n    struct Hi35xxI2cCntlr *hi35xx = NULL;\n    ... \n    hi35xx = (struct Hi35xxI2cCntlr *)OsalMemCalloc(sizeof(*hi35xx));   // 内存分配\n    ... \n    hi35xx->regBase = OsalIoRemap(hi35xx->regBasePhy, hi35xx->regSize); // 地址映射\n    ... \n    Hi35xxI2cCntlrInit(hi35xx);         // 【必要】i2c设备的初始化\n    \n    hi35xx->cntlr.priv = (void *)node;  //【必要】存储设备属性\n    hi35xx->cntlr.busId = hi35xx->bus;  //【必要】初始化I2cCntlr成员busId\n    hi35xx->cntlr.ops = &g_method;      //【必要】I2cMethod的实例化对象的挂载\n    hi35xx->cntlr.lockOps = &g_lockOps; //【必要】I2cLockMethod的实例化对象的挂载\n    (void)OsalSpinInit(&hi35xx->spin);  //【必要】锁的初始化\n    ret = I2cCntlrAdd(&hi35xx->cntlr);  //【必要】调用此函数填充核心层结构体，返回成功信号后驱动才完全接入平台核心层\n    ...\n#ifdef USER_VFS_SUPPORT\n    (void)I2cAddVfsById(hi35xx->cntlr.busId);//【可选】若支持用户级的虚拟文件系统，则接入\n#endif\n    return HDF_SUCCESS;\n__ERR__:                                //不成功的话，需要反向执行初始化相关函数\n    if (hi35xx != NULL) {\n        if (hi35xx->regBase != NULL) {\n            OsalIoUnmap((void *)hi35xx->regBase);\n            hi35xx->regBase = NULL;\n        }\n        OsalMemFree(hi35xx);\n        hi35xx = NULL;\n    }\n    return ret;\n}\n")])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br"),n("span",{staticClass:"line-number"},[s._v("8")]),n("br"),n("span",{staticClass:"line-number"},[s._v("9")]),n("br"),n("span",{staticClass:"line-number"},[s._v("10")]),n("br"),n("span",{staticClass:"line-number"},[s._v("11")]),n("br"),n("span",{staticClass:"line-number"},[s._v("12")]),n("br"),n("span",{staticClass:"line-number"},[s._v("13")]),n("br"),n("span",{staticClass:"line-number"},[s._v("14")]),n("br"),n("span",{staticClass:"line-number"},[s._v("15")]),n("br"),n("span",{staticClass:"line-number"},[s._v("16")]),n("br"),n("span",{staticClass:"line-number"},[s._v("17")]),n("br"),n("span",{staticClass:"line-number"},[s._v("18")]),n("br"),n("span",{staticClass:"line-number"},[s._v("19")]),n("br"),n("span",{staticClass:"line-number"},[s._v("20")]),n("br"),n("span",{staticClass:"line-number"},[s._v("21")]),n("br"),n("span",{staticClass:"line-number"},[s._v("22")]),n("br"),n("span",{staticClass:"line-number"},[s._v("23")]),n("br"),n("span",{staticClass:"line-number"},[s._v("24")]),n("br"),n("span",{staticClass:"line-number"},[s._v("25")]),n("br"),n("span",{staticClass:"line-number"},[s._v("26")]),n("br"),n("span",{staticClass:"line-number"},[s._v("27")]),n("br"),n("span",{staticClass:"line-number"},[s._v("28")]),n("br"),n("span",{staticClass:"line-number"},[s._v("29")]),n("br"),n("span",{staticClass:"line-number"},[s._v("30")]),n("br"),n("span",{staticClass:"line-number"},[s._v("31")]),n("br"),n("span",{staticClass:"line-number"},[s._v("32")]),n("br"),n("span",{staticClass:"line-number"},[s._v("33")]),n("br"),n("span",{staticClass:"line-number"},[s._v("34")]),n("br"),n("span",{staticClass:"line-number"},[s._v("35")]),n("br"),n("span",{staticClass:"line-number"},[s._v("36")]),n("br"),n("span",{staticClass:"line-number"},[s._v("37")]),n("br"),n("span",{staticClass:"line-number"},[s._v("38")]),n("br"),n("span",{staticClass:"line-number"},[s._v("39")]),n("br"),n("span",{staticClass:"line-number"},[s._v("40")]),n("br"),n("span",{staticClass:"line-number"},[s._v("41")]),n("br"),n("span",{staticClass:"line-number"},[s._v("42")]),n("br"),n("span",{staticClass:"line-number"},[s._v("43")]),n("br")])])]),s._v(" "),n("li",[n("p",[s._v("Release 函数参考")]),s._v(" "),n("p",[s._v("入参：")]),s._v(" "),n("p",[s._v("HdfDeviceObject 是整个驱动对外暴露的接口参数，具备 HCS 配置文件的信息。")]),s._v(" "),n("p",[s._v("返回值：")]),s._v(" "),n("p",[s._v("无。")]),s._v(" "),n("p",[s._v("函数说明：")]),s._v(" "),n("p",[s._v("释放内存和删除控制器，该函数需要在驱动入口结构体中赋值给 Release 接口， 当HDF框架调用Init函数初始化驱动失败时，可以调用 Release 释放驱动资源。")]),s._v(" "),n("div",{staticClass:"language- line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[s._v("static void Hi35xxI2cRelease(struct HdfDeviceObject *device)\n{\n    ...\n    //与Hi35xxI2cInit一样，需要将对每个节点分别进行释放\n    DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) {\n        Hi35xxI2cRemoveByNode(childNode);//函数定义见下\n    }\n}\n\nstatic void Hi35xxI2cRemoveByNode(const struct DeviceResourceNode *node)\n{\n    ... \n    //【必要】可以调用 I2cCntlrGet 函数通过设备的 busid 获取 I2cCntlr 对象， 以及调用 I2cCntlrRemove 函数来释放 I2cCntlr 对象的内容\n    cntlr = I2cCntlrGet(bus);\n    if (cntlr != NULL && cntlr->priv == node) {\n        ...\n        I2cCntlrRemove(cntlr); \n        //【必要】解除地址映射，锁和内存的释放\n        hi35xx = (struct Hi35xxI2cCntlr *)cntlr; \n        OsalIoUnmap((void *)hi35xx->regBase);\n        (void)OsalSpinDestroy(&hi35xx->spin);\n        OsalMemFree(hi35xx);\n    }\n    return;\n}\n")])]),s._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[s._v("1")]),n("br"),n("span",{staticClass:"line-number"},[s._v("2")]),n("br"),n("span",{staticClass:"line-number"},[s._v("3")]),n("br"),n("span",{staticClass:"line-number"},[s._v("4")]),n("br"),n("span",{staticClass:"line-number"},[s._v("5")]),n("br"),n("span",{staticClass:"line-number"},[s._v("6")]),n("br"),n("span",{staticClass:"line-number"},[s._v("7")]),n("br"),n("span",{staticClass:"line-number"},[s._v("8")]),n("br"),n("span",{staticClass:"line-number"},[s._v("9")]),n("br"),n("span",{staticClass:"line-number"},[s._v("10")]),n("br"),n("span",{staticClass:"line-number"},[s._v("11")]),n("br"),n("span",{staticClass:"line-number"},[s._v("12")]),n("br"),n("span",{staticClass:"line-number"},[s._v("13")]),n("br"),n("span",{staticClass:"line-number"},[s._v("14")]),n("br"),n("span",{staticClass:"line-number"},[s._v("15")]),n("br"),n("span",{staticClass:"line-number"},[s._v("16")]),n("br"),n("span",{staticClass:"line-number"},[s._v("17")]),n("br"),n("span",{staticClass:"line-number"},[s._v("18")]),n("br"),n("span",{staticClass:"line-number"},[s._v("19")]),n("br"),n("span",{staticClass:"line-number"},[s._v("20")]),n("br"),n("span",{staticClass:"line-number"},[s._v("21")]),n("br"),n("span",{staticClass:"line-number"},[s._v("22")]),n("br"),n("span",{staticClass:"line-number"},[s._v("23")]),n("br"),n("span",{staticClass:"line-number"},[s._v("24")]),n("br"),n("span",{staticClass:"line-number"},[s._v("25")]),n("br")])])])])])])])}),[],!1,null,null,null);t.default=e.exports}}]);