|
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <meta http-equiv="X-UA-Compatible" content="IE=9"/>
- <meta name="generator" content="Doxygen 1.8.14"/>
- <meta name="viewport" content="width=device-width, initial-scale=1"/>
- <title>uTL: include/utl/com/i2c_bb.h Source File</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="dynsections.js"></script>
- <link href="navtree.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="resize.js"></script>
- <script type="text/javascript" src="navtreedata.js"></script>
- <script type="text/javascript" src="navtree.js"></script>
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- $(document).ready(initResizable);
- /* @license-end */</script>
- <link href="search/search.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="search/searchdata.js"></script>
- <script type="text/javascript" src="search/search.js"></script>
- <link href="doxygen.css" rel="stylesheet" type="text/css" />
- </head>
- <body>
- <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
- <div id="titlearea">
- <table cellspacing="0" cellpadding="0">
- <tbody>
- <tr style="height: 56px;">
- <td id="projectalign" style="padding-left: 0.5em;">
- <div id="projectname">uTL
- </div>
- <div id="projectbrief">micro Template library</div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <!-- end header part -->
- <!-- Generated by Doxygen 1.8.14 -->
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- var searchBox = new SearchBox("searchBox", "search",false,'Search');
- /* @license-end */
- </script>
- <script type="text/javascript" src="menudata.js"></script>
- <script type="text/javascript" src="menu.js"></script>
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- $(function() {
- initMenu('',true,false,'search.php','Search');
- $(document).ready(function() { init_search(); });
- });
- /* @license-end */</script>
- <div id="main-nav"></div>
- </div><!-- top -->
- <div id="side-nav" class="ui-resizable side-nav-resizable">
- <div id="nav-tree">
- <div id="nav-tree-contents">
- <div id="nav-sync" class="sync"></div>
- </div>
- </div>
- <div id="splitbar" style="-moz-user-select:none;"
- class="ui-resizable-handle">
- </div>
- </div>
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- $(document).ready(function(){initNavTree('i2c__bb_8h_source.html','');});
- /* @license-end */
- </script>
- <div id="doc-content">
- <!-- window showing the filter options -->
- <div id="MSearchSelectWindow"
- onmouseover="return searchBox.OnSearchSelectShow()"
- onmouseout="return searchBox.OnSearchSelectHide()"
- onkeydown="return searchBox.OnSearchSelectKey(event)">
- </div>
-
- <!-- iframe showing the search results (closed by default) -->
- <div id="MSearchResultsWindow">
- <iframe src="javascript:void(0)" frameborder="0"
- name="MSearchResults" id="MSearchResults">
- </iframe>
- </div>
-
- <div class="header">
- <div class="headertitle">
- <div class="title">i2c_bb.h</div> </div>
- </div><!--header-->
- <div class="contents">
- <a href="i2c__bb_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> </div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="preprocessor">#ifndef __utl_com_i2c_bb_h__</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#define __utl_com_i2c_bb_h__</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> </div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="preprocessor">#include <<a class="code" href="impl_8h.html">utl/core/impl.h</a>></span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="preprocessor">#include <<a class="code" href="crtp_8h.html">utl/core/crtp.h</a>></span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="preprocessor">#include <<a class="code" href="i2c_8h.html">utl/com/i2c.h</a>></span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> </div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> </div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="keyword">namespace </span><a class="code" href="namespaceutl.html">utl</a> {</div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> </div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> </div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> impl_t></div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html"> 47</a></span>  <span class="keyword">class </span><a class="code" href="classutl_1_1i2c__bb__i.html">i2c_bb_i</a> : <span class="keyword">public</span> <a class="code" href="classutl_1_1i2c__i.html">i2c_i</a><i2c_bb_i<impl_t>> {</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a5c9f28c59f87ebb8a937abb039e11150">_CRTP_IMPL</a>(impl_t);</div><div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#a9932eded730c8f9a7b1d15988082b699"> 49</a></span>  <span class="keyword">friend</span> <a class="code" href="classutl_1_1i2c__i.html">i2c_i<i2c_bb_i<impl_t></a>>;</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span> </div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00052"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#a428c847d950993fa2cd005416edfb720"> 52</a></span>  <span class="keyword">using</span> <a class="code" href="classutl_1_1i2c__bb__i.html">type</a> = <a class="code" href="classutl_1_1i2c__bb__i.html">i2c_bb_i<impl_t></a>; </div><div class="line"><a name="l00053"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#ad2872b7e17116f8379144488fe135052"> 53</a></span>  <span class="keyword">using</span> <a class="code" href="classutl_1_1i2c__bb__i.html#ad2872b7e17116f8379144488fe135052">Sequence</a> = <span class="keyword">typename</span> <a class="code" href="classutl_1_1i2c__i.html#a7e2dde443c6c9bde4a2293beb22950c5">i2c_i<type>::Sequence</a>;</div><div class="line"><a name="l00055"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26d"> 55</a></span>  <span class="keyword">enum class</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26d">SDAMode</a> {</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26daa84cc046d48610b05c21fd3670d0c829">INPUT</a> =0,</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">OUTPUT</a></div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  };</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span> </div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  <span class="keyword">protected</span>:</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#ac2d9b97778a5dd57eb5e6425b4b0833c">~i2c_bb_i</a> () noexcept = default;</div><div class="line"><a name="l00068"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#ab657379ca2e4b3624e2d4520542a9464"> 68</a></span>  <a class="code" href="classutl_1_1i2c__bb__i.html">i2c_bb_i</a> (uint32_t clk) noexcept</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  : <a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a> {1000000/(2*clk)} { }</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span> </div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00085"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922"> 85</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26d">SDAMode</a> mode, <span class="keywordtype">bool</span> st) { <span class="keywordflow">return</span> impl().SDA (mode, st); }</div><div class="line"><a name="l00086"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699"> 86</a></span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (uint8_t st) { impl().SCL (st); } </div><div class="line"><a name="l00087"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1"> 87</a></span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (uint32_t usec) { impl().delay(usec); } </div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span> </div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00095"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#a1f491d6ccadce71fa6cc59eebc74e82f"> 95</a></span>  uint32_t <a class="code" href="classutl_1_1i2c__bb__i.html#a1f491d6ccadce71fa6cc59eebc74e82f">_clock</a> ()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> 1000000/(2*<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>); }</div><div class="line"><a name="l00096"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#aef4db6e89447b2f0921df5b291b86232"> 96</a></span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#aef4db6e89447b2f0921df5b291b86232">_clock</a> (uint32_t c) { <a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a> = 1000000/(2*c); }</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span> </div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a2f4df606609ef7465109990d9fc0f1da">_start</a> (); </div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#ade9235a9d8ccfd7233494631d66ba07e">_stop</a> (); </div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <a class="code" href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">byte_t</a> <a class="code" href="classutl_1_1i2c__bb__i.html#a3a459ded18fe55460ae438e312c22110">_rx_data</a> (<span class="keywordtype">bool</span> ack, <a class="code" href="classutl_1_1i2c__bb__i.html#ad2872b7e17116f8379144488fe135052">Sequence</a> seq);</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  <span class="keywordtype">bool</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a085e38e545049ac64cd745b08e0be18f">_tx_data</a> (<a class="code" href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">byte_t</a> byte, <a class="code" href="classutl_1_1i2c__bb__i.html#ad2872b7e17116f8379144488fe135052">Sequence</a> seq);</div><div class="line"><a name="l00102"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee"> 102</a></span>  uint32_t <a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>; </div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  };</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span> </div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  <span class="comment">/*</span></div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span> <span class="comment"> * ============= User functions ================</span></div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span> <span class="comment"> */</span></div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> impl_t></div><div class="line"><a name="l00115"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#a2f4df606609ef7465109990d9fc0f1da"> 115</a></span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a2f4df606609ef7465109990d9fc0f1da">i2c_bb_i<impl_t>::_start</a> (<span class="keywordtype">void</span>) {</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  <span class="comment">//Initially set pins</span></div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  SDA (SDAMode::OUTPUT, 1);</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  SCL (1);</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  delay (usec_);</div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  SDA (SDAMode::OUTPUT, 0);</div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  delay (usec_);</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  SCL (0); <span class="comment">//Clear Clock</span></div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  }</div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span> </div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> impl_t></div><div class="line"><a name="l00131"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#ade9235a9d8ccfd7233494631d66ba07e"> 131</a></span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#ade9235a9d8ccfd7233494631d66ba07e">i2c_bb_i<impl_t>::_stop</a> (<span class="keywordtype">void</span>) {</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  <span class="comment">//Stop bit Operation</span></div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  SDA (SDAMode::OUTPUT, 0);</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  SCL (0);</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  SCL (1);</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  delay (usec_);</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span>  SDA (SDAMode::OUTPUT, 1);</div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  delay (usec_);</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  }</div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span> </div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> impl_t></div><div class="line"><a name="l00154"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#a3a459ded18fe55460ae438e312c22110"> 154</a></span>  <a class="code" href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">byte_t</a> <a class="code" href="classutl_1_1i2c__bb__i.html#a3a459ded18fe55460ae438e312c22110">i2c_bb_i<impl_t>::_rx_data</a> (<span class="keywordtype">bool</span> ack, <a class="code" href="classutl_1_1i2c__bb__i.html#ad2872b7e17116f8379144488fe135052">Sequence</a> seq) {</div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  <a class="code" href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">byte_t</a> byte {0};</div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  <span class="comment">//Initial conditions</span></div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span>  SCL (0);</div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  SDA (SDAMode::INPUT, 0);</div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span> </div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  <span class="keywordflow">if</span> (seq == Sequence::BYTE || seq == Sequence::BYTEnACK) {</div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  <span class="comment">// read 8 data bits</span></div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=8 ; i!=0 ; --i) {</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  byte <<= 1;</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  SCL (1);</div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  delay (usec_);</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span>  byte |= SDA (SDAMode::INPUT, 0);</div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span>  SCL (0);</div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span>  delay (usec_);</div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  }</div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  }</div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  <span class="keywordflow">if</span> (seq == Sequence::ACK || seq == Sequence::BYTEnACK) {</div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  SDA (SDAMode::OUTPUT, !ack); <span class="comment">//Send (or not) ACK bit</span></div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span>  SCL (1);</div><div class="line"><a name="l00174"></a><span class="lineno"> 174</span>  delay (usec_);</div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span>  SCL (0); <span class="comment">// Keep the bus busy</span></div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span>  SDA (SDAMode::OUTPUT, 0);</div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span>  }</div><div class="line"><a name="l00178"></a><span class="lineno"> 178</span>  <span class="keywordflow">return</span> byte;</div><div class="line"><a name="l00179"></a><span class="lineno"> 179</span>  }</div><div class="line"><a name="l00180"></a><span class="lineno"> 180</span> </div><div class="line"><a name="l00193"></a><span class="lineno"> 193</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> impl_t></div><div class="line"><a name="l00194"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i.html#a085e38e545049ac64cd745b08e0be18f"> 194</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a085e38e545049ac64cd745b08e0be18f">i2c_bb_i<impl_t>::_tx_data</a> (<a class="code" href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">byte_t</a> byte, <a class="code" href="classutl_1_1i2c__bb__i.html#ad2872b7e17116f8379144488fe135052">Sequence</a> seq) {</div><div class="line"><a name="l00195"></a><span class="lineno"> 195</span>  <span class="keywordtype">bool</span> ack {<span class="keyword">false</span>};</div><div class="line"><a name="l00196"></a><span class="lineno"> 196</span>  <span class="comment">//Initial conditions</span></div><div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  SCL (0);</div><div class="line"><a name="l00198"></a><span class="lineno"> 198</span>  SDA (SDAMode::OUTPUT, 0);</div><div class="line"><a name="l00199"></a><span class="lineno"> 199</span> </div><div class="line"><a name="l00200"></a><span class="lineno"> 200</span>  <span class="keywordflow">if</span> (seq == Sequence::BYTE || seq == Sequence::BYTEnACK) {</div><div class="line"><a name="l00201"></a><span class="lineno"> 201</span>  <span class="comment">//Send 8 bit data</span></div><div class="line"><a name="l00202"></a><span class="lineno"> 202</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=8 ; i!=0 ; --i) {</div><div class="line"><a name="l00203"></a><span class="lineno"> 203</span>  <span class="comment">//Send MSB</span></div><div class="line"><a name="l00204"></a><span class="lineno"> 204</span>  SDA (SDAMode::OUTPUT, byte & 0x80);</div><div class="line"><a name="l00205"></a><span class="lineno"> 205</span>  byte <<= 1;</div><div class="line"><a name="l00206"></a><span class="lineno"> 206</span>  SCL (1);</div><div class="line"><a name="l00207"></a><span class="lineno"> 207</span>  delay (usec_);</div><div class="line"><a name="l00208"></a><span class="lineno"> 208</span>  SCL (0);</div><div class="line"><a name="l00209"></a><span class="lineno"> 209</span>  delay (usec_);</div><div class="line"><a name="l00210"></a><span class="lineno"> 210</span>  }</div><div class="line"><a name="l00211"></a><span class="lineno"> 211</span>  }</div><div class="line"><a name="l00212"></a><span class="lineno"> 212</span>  <span class="keywordflow">if</span> (seq == Sequence::ACK || seq == Sequence::BYTEnACK) {</div><div class="line"><a name="l00213"></a><span class="lineno"> 213</span>  <span class="comment">// Get ACK</span></div><div class="line"><a name="l00214"></a><span class="lineno"> 214</span>  SDA (SDAMode::INPUT, 0);</div><div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  SCL (1);</div><div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  delay (usec_);</div><div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  ack = !SDA (SDAMode::INPUT, 0);</div><div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  SCL (0); <span class="comment">// Keep the bus busy</span></div><div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  delay (usec_);</div><div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  SDA (SDAMode::OUTPUT, 0);</div><div class="line"><a name="l00221"></a><span class="lineno"> 221</span>  }</div><div class="line"><a name="l00222"></a><span class="lineno"> 222</span>  <span class="keywordflow">return</span> ack;</div><div class="line"><a name="l00223"></a><span class="lineno"> 223</span>  }</div><div class="line"><a name="l00224"></a><span class="lineno"> 224</span> </div><div class="line"><a name="l00225"></a><span class="lineno"> 225</span> </div><div class="line"><a name="l00233"></a><span class="lineno"> 233</span>  <span class="keyword">template</span><></div><div class="line"><a name="l00234"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html"> 234</a></span>  <span class="keyword">class </span><a class="code" href="classutl_1_1i2c__bb__i.html">i2c_bb_i</a><<a class="code" href="structutl_1_1virtual__tag.html">virtual_tag</a>> : <span class="keyword">public</span> <a class="code" href="classutl_1_1i2c__i.html">i2c_i</a><virtual_tag> {</div><div class="line"><a name="l00235"></a><span class="lineno"> 235</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00236"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#abedad1f30e2c695d47a84dc68ff05897"> 236</a></span>  <span class="keyword">using</span> <a class="code" href="classutl_1_1i2c__i_3_01virtual__tag_01_4.html">type</a> = <a class="code" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html">i2c_bb_i<virtual_tag></a>; </div><div class="line"><a name="l00237"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#af8c7ac3797343e39e7e052ec51aec232"> 237</a></span>  <span class="keyword">using</span> <a class="code" href="classutl_1_1i2c__i_3_01virtual__tag_01_4.html#a260541de452a9a653162b8b109b26c09">Sequence</a> = <span class="keyword">typename</span> <a class="code" href="classutl_1_1i2c__i.html#a7e2dde443c6c9bde4a2293beb22950c5">i2c_i<virtual_tag>::Sequence</a>;</div><div class="line"><a name="l00239"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#af4bc7eeeb830e49046a1033e9c79db7f"> 239</a></span>  <span class="keyword">enum class</span> <a class="code" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#af4bc7eeeb830e49046a1033e9c79db7f">SDAMode</a> {</div><div class="line"><a name="l00240"></a><span class="lineno"> 240</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26daa84cc046d48610b05c21fd3670d0c829">INPUT</a> =0,</div><div class="line"><a name="l00241"></a><span class="lineno"> 241</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">OUTPUT</a></div><div class="line"><a name="l00242"></a><span class="lineno"> 242</span>  };</div><div class="line"><a name="l00243"></a><span class="lineno"> 243</span> </div><div class="line"><a name="l00247"></a><span class="lineno"> 247</span>  <span class="keyword">protected</span>:</div><div class="line"><a name="l00250"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#a0c9341b2a60e9400523de0397c472a76"> 250</a></span>  <a class="code" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#a0c9341b2a60e9400523de0397c472a76">i2c_bb_i</a> (uint32_t clk) noexcept</div><div class="line"><a name="l00251"></a><span class="lineno"> 251</span>  : <a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a> {1000000/(2*clk)} { }</div><div class="line"><a name="l00253"></a><span class="lineno"> 253</span>  <span class="keyword">virtual</span> <a class="code" href="classutl_1_1i2c__bb__i.html#ac2d9b97778a5dd57eb5e6425b4b0833c">~i2c_bb_i</a> () noexcept = default;</div><div class="line"><a name="l00255"></a><span class="lineno"> 255</span> </div><div class="line"><a name="l00259"></a><span class="lineno"> 259</span>  private:</div><div class="line"><a name="l00266"></a><span class="lineno"> 266</span>  virtual <span class="keywordtype">bool</span> <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26d">SDAMode</a> mode, <span class="keywordtype">bool</span> st) =0;</div><div class="line"><a name="l00267"></a><span class="lineno"> 267</span>  virtual <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (<span class="keywordtype">bool</span> st) =0; </div><div class="line"><a name="l00268"></a><span class="lineno"> 268</span>  virtual <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (uint32_t usec) =0; </div><div class="line"><a name="l00269"></a><span class="lineno"> 269</span> </div><div class="line"><a name="l00274"></a><span class="lineno"> 274</span>  private:</div><div class="line"><a name="l00276"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#a0e05ef5f042a1642c9920dd5d7da34b4"> 276</a></span>  uint32_t <a class="code" href="classutl_1_1i2c__bb__i.html#a1f491d6ccadce71fa6cc59eebc74e82f">_clock</a> () const final { <span class="keywordflow">return</span> 1000000/(2*<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>); }</div><div class="line"><a name="l00277"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#a47e0f23aa64714a0a95c579994a84fcc"> 277</a></span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#a47e0f23aa64714a0a95c579994a84fcc">_clock</a> (uint32_t c) <span class="keyword">final</span> { <a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a> = 1000000/(2*c); }</div><div class="line"><a name="l00278"></a><span class="lineno"> 278</span> </div><div class="line"><a name="l00279"></a><span class="lineno"> 279</span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a2f4df606609ef7465109990d9fc0f1da">_start</a> () final;</div><div class="line"><a name="l00280"></a><span class="lineno"> 280</span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#ade9235a9d8ccfd7233494631d66ba07e">_stop</a> () final;</div><div class="line"><a name="l00281"></a><span class="lineno"> 281</span>  <a class="code" href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">byte_t</a> <a class="code" href="classutl_1_1i2c__bb__i.html#a3a459ded18fe55460ae438e312c22110">_rx_data</a> (<span class="keywordtype">bool</span> ack, <a class="code" href="classutl_1_1i2c__bb__i.html#ad2872b7e17116f8379144488fe135052">Sequence</a> seq) final;</div><div class="line"><a name="l00282"></a><span class="lineno"> 282</span>  <span class="keywordtype">bool</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a085e38e545049ac64cd745b08e0be18f">_tx_data</a> (<a class="code" href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">byte_t</a> byte, <a class="code" href="classutl_1_1i2c__bb__i.html#ad2872b7e17116f8379144488fe135052">Sequence</a> seq) final;</div><div class="line"><a name="l00284"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#aa3e73dad28462bf6d8c132ddfeb3a390"> 284</a></span>  uint32_t <a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>;</div><div class="line"><a name="l00286"></a><span class="lineno"> 286</span>  };</div><div class="line"><a name="l00287"></a><span class="lineno"> 287</span> </div><div class="line"><a name="l00293"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#acf1d49b23e9c7b1c42cd43296b8b171c"> 293</a></span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html">i2c_bb_i</a><<a class="code" href="structutl_1_1virtual__tag.html">virtual_tag</a>>::<a class="code" href="classutl_1_1i2c__bb__i.html#a2f4df606609ef7465109990d9fc0f1da">_start</a> (<span class="keywordtype">void</span>) {</div><div class="line"><a name="l00294"></a><span class="lineno"> 294</span>  <span class="comment">//Initially set pins</span></div><div class="line"><a name="l00295"></a><span class="lineno"> 295</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">SDAMode::OUTPUT</a>, 1);</div><div class="line"><a name="l00296"></a><span class="lineno"> 296</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (1);</div><div class="line"><a name="l00297"></a><span class="lineno"> 297</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00298"></a><span class="lineno"> 298</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">SDAMode::OUTPUT</a>, 0);</div><div class="line"><a name="l00299"></a><span class="lineno"> 299</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00300"></a><span class="lineno"> 300</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (0); <span class="comment">//Clear Clock</span></div><div class="line"><a name="l00301"></a><span class="lineno"> 301</span>  }</div><div class="line"><a name="l00302"></a><span class="lineno"> 302</span> </div><div class="line"><a name="l00308"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#acee317f97c201b10680c89ed1a64f694"> 308</a></span>  <span class="keywordtype">void</span> <a class="code" href="classutl_1_1i2c__bb__i.html#ade9235a9d8ccfd7233494631d66ba07e">i2c_bb_i<virtual_tag>::_stop</a> (<span class="keywordtype">void</span>) {</div><div class="line"><a name="l00309"></a><span class="lineno"> 309</span>  <span class="comment">//Stop bit Operation</span></div><div class="line"><a name="l00310"></a><span class="lineno"> 310</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">SDAMode::OUTPUT</a>, 0);</div><div class="line"><a name="l00311"></a><span class="lineno"> 311</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (0);</div><div class="line"><a name="l00312"></a><span class="lineno"> 312</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (1);</div><div class="line"><a name="l00313"></a><span class="lineno"> 313</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00314"></a><span class="lineno"> 314</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">SDAMode::OUTPUT</a>, 1);</div><div class="line"><a name="l00315"></a><span class="lineno"> 315</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00316"></a><span class="lineno"> 316</span>  }</div><div class="line"><a name="l00317"></a><span class="lineno"> 317</span> </div><div class="line"><a name="l00330"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#abb3eda6549482ff538f2b536d67752ed"> 330</a></span>  <a class="code" href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">byte_t</a> <a class="code" href="classutl_1_1i2c__bb__i.html#a3a459ded18fe55460ae438e312c22110">i2c_bb_i<virtual_tag>::_rx_data</a> (<span class="keywordtype">bool</span> ack, <a class="code" href="classutl_1_1i2c__i_3_01virtual__tag_01_4.html#a260541de452a9a653162b8b109b26c09">Sequence</a> seq) {</div><div class="line"><a name="l00331"></a><span class="lineno"> 331</span>  <a class="code" href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">byte_t</a> byte {0};</div><div class="line"><a name="l00332"></a><span class="lineno"> 332</span>  <span class="comment">//Initial conditions</span></div><div class="line"><a name="l00333"></a><span class="lineno"> 333</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (0);</div><div class="line"><a name="l00334"></a><span class="lineno"> 334</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26daa84cc046d48610b05c21fd3670d0c829">SDAMode::INPUT</a>, 0);</div><div class="line"><a name="l00335"></a><span class="lineno"> 335</span> </div><div class="line"><a name="l00336"></a><span class="lineno"> 336</span>  <span class="keywordflow">if</span> (seq == Sequence::BYTE || seq == Sequence::BYTEnACK) {</div><div class="line"><a name="l00337"></a><span class="lineno"> 337</span>  <span class="comment">// read 8 data bits</span></div><div class="line"><a name="l00338"></a><span class="lineno"> 338</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=8 ; i!=0 ; --i) {</div><div class="line"><a name="l00339"></a><span class="lineno"> 339</span>  byte <<= 1;</div><div class="line"><a name="l00340"></a><span class="lineno"> 340</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (1);</div><div class="line"><a name="l00341"></a><span class="lineno"> 341</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00342"></a><span class="lineno"> 342</span>  byte |= <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26daa84cc046d48610b05c21fd3670d0c829">SDAMode::INPUT</a>, 0);</div><div class="line"><a name="l00343"></a><span class="lineno"> 343</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (0);</div><div class="line"><a name="l00344"></a><span class="lineno"> 344</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00345"></a><span class="lineno"> 345</span>  }</div><div class="line"><a name="l00346"></a><span class="lineno"> 346</span>  }</div><div class="line"><a name="l00347"></a><span class="lineno"> 347</span>  <span class="keywordflow">if</span> (seq == Sequence::ACK || seq == Sequence::BYTEnACK) {</div><div class="line"><a name="l00348"></a><span class="lineno"> 348</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">SDAMode::OUTPUT</a>, !ack); <span class="comment">//Send (or not) ACK bit</span></div><div class="line"><a name="l00349"></a><span class="lineno"> 349</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (1);</div><div class="line"><a name="l00350"></a><span class="lineno"> 350</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00351"></a><span class="lineno"> 351</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (0); <span class="comment">// Keep the bus busy</span></div><div class="line"><a name="l00352"></a><span class="lineno"> 352</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">SDAMode::OUTPUT</a>, 0);</div><div class="line"><a name="l00353"></a><span class="lineno"> 353</span>  }</div><div class="line"><a name="l00354"></a><span class="lineno"> 354</span>  <span class="keywordflow">return</span> byte;</div><div class="line"><a name="l00355"></a><span class="lineno"> 355</span>  }</div><div class="line"><a name="l00356"></a><span class="lineno"> 356</span> </div><div class="line"><a name="l00369"></a><span class="lineno"><a class="line" href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#abbc42b60004046048a2ac6fd312188a6"> 369</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classutl_1_1i2c__bb__i.html#a085e38e545049ac64cd745b08e0be18f">i2c_bb_i<virtual_tag>::_tx_data</a> (<a class="code" href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">byte_t</a> byte, <a class="code" href="classutl_1_1i2c__i_3_01virtual__tag_01_4.html#a260541de452a9a653162b8b109b26c09">Sequence</a> seq) {</div><div class="line"><a name="l00370"></a><span class="lineno"> 370</span>  <span class="keywordtype">bool</span> ack {<span class="keyword">false</span>};</div><div class="line"><a name="l00371"></a><span class="lineno"> 371</span>  <span class="comment">//Initial conditions</span></div><div class="line"><a name="l00372"></a><span class="lineno"> 372</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (0);</div><div class="line"><a name="l00373"></a><span class="lineno"> 373</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">SDAMode::OUTPUT</a>, 0);</div><div class="line"><a name="l00374"></a><span class="lineno"> 374</span> </div><div class="line"><a name="l00375"></a><span class="lineno"> 375</span>  <span class="keywordflow">if</span> (seq == Sequence::BYTE || seq == Sequence::BYTEnACK) {</div><div class="line"><a name="l00376"></a><span class="lineno"> 376</span>  <span class="comment">//Send 8 bit data</span></div><div class="line"><a name="l00377"></a><span class="lineno"> 377</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=8 ; i!=0 ; --i) {</div><div class="line"><a name="l00378"></a><span class="lineno"> 378</span>  <span class="comment">//Send MSB</span></div><div class="line"><a name="l00379"></a><span class="lineno"> 379</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">SDAMode::OUTPUT</a>, byte & 0x80);</div><div class="line"><a name="l00380"></a><span class="lineno"> 380</span>  byte <<= 1;</div><div class="line"><a name="l00381"></a><span class="lineno"> 381</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (1);</div><div class="line"><a name="l00382"></a><span class="lineno"> 382</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00383"></a><span class="lineno"> 383</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (0);</div><div class="line"><a name="l00384"></a><span class="lineno"> 384</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00385"></a><span class="lineno"> 385</span>  }</div><div class="line"><a name="l00386"></a><span class="lineno"> 386</span>  }</div><div class="line"><a name="l00387"></a><span class="lineno"> 387</span>  <span class="keywordflow">if</span> (seq == Sequence::ACK || seq == Sequence::BYTEnACK) {</div><div class="line"><a name="l00388"></a><span class="lineno"> 388</span>  <span class="comment">// Get ACK</span></div><div class="line"><a name="l00389"></a><span class="lineno"> 389</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26daa84cc046d48610b05c21fd3670d0c829">SDAMode::INPUT</a>, 0);</div><div class="line"><a name="l00390"></a><span class="lineno"> 390</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (1);</div><div class="line"><a name="l00391"></a><span class="lineno"> 391</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00392"></a><span class="lineno"> 392</span>  ack = !<a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26daa84cc046d48610b05c21fd3670d0c829">SDAMode::INPUT</a>, 0);</div><div class="line"><a name="l00393"></a><span class="lineno"> 393</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">SCL</a> (0); <span class="comment">// Keep the bus busy</span></div><div class="line"><a name="l00394"></a><span class="lineno"> 394</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">delay</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">usec_</a>);</div><div class="line"><a name="l00395"></a><span class="lineno"> 395</span>  <a class="code" href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">SDA</a> (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">SDAMode::OUTPUT</a>, 0);</div><div class="line"><a name="l00396"></a><span class="lineno"> 396</span>  }</div><div class="line"><a name="l00397"></a><span class="lineno"> 397</span>  <span class="keywordflow">return</span> ack;</div><div class="line"><a name="l00398"></a><span class="lineno"> 398</span>  }</div><div class="line"><a name="l00399"></a><span class="lineno"> 399</span> </div><div class="line"><a name="l00401"></a><span class="lineno"> 401</span> } <span class="comment">// namspace utl</span></div><div class="line"><a name="l00402"></a><span class="lineno"> 402</span> </div><div class="line"><a name="l00403"></a><span class="lineno"> 403</span> <span class="preprocessor">#endif // #ifndef __utl_com_i2c_bb_h__</span></div><div class="ttc" id="classutl_1_1i2c__bb__i_html_ad2872b7e17116f8379144488fe135052"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#ad2872b7e17116f8379144488fe135052">utl::i2c_bb_i::Sequence</a></div><div class="ttdeci">typename i2c_i< type >::Sequence Sequence</div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00053">i2c_bb.h:53</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a8bd3726104fc91eb8f283d7ffec71cee"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a8bd3726104fc91eb8f283d7ffec71cee">utl::i2c_bb_i::usec_</a></div><div class="ttdeci">uint32_t usec_</div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00102">i2c_bb.h:102</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26da50a87f0d71f7221582dad4bf507a0f34">utl::i2c_bb_i::SDAMode::OUTPUT</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a2f4df606609ef7465109990d9fc0f1da"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a2f4df606609ef7465109990d9fc0f1da">utl::i2c_bb_i::_start</a></div><div class="ttdeci">void _start()</div><div class="ttdoc">Send start functionality. </div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00115">i2c_bb.h:115</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__i_html"><div class="ttname"><a href="classutl_1_1i2c__i.html">utl::i2c_i</a></div><div class="ttdoc">Abstract base class for i2c bus. </div><div class="ttdef"><b>Definition:</b> <a href="i2c_8h_source.html#l00043">i2c.h:43</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_aa197be76016b82fd6f8b66875430d922"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#aa197be76016b82fd6f8b66875430d922">utl::i2c_bb_i::SDA</a></div><div class="ttdeci">bool SDA(SDAMode mode, bool st)</div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00085">i2c_bb.h:85</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4_html_af4bc7eeeb830e49046a1033e9c79db7f"><div class="ttname"><a href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#af4bc7eeeb830e49046a1033e9c79db7f">utl::i2c_bb_i< virtual_tag >::SDAMode</a></div><div class="ttdeci">SDAMode</div><div class="ttdoc">SDA pin direction enumerator. </div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00239">i2c_bb.h:239</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a5c9f28c59f87ebb8a937abb039e11150"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a5c9f28c59f87ebb8a937abb039e11150">utl::i2c_bb_i::_CRTP_IMPL</a></div><div class="ttdeci">_CRTP_IMPL(impl_t)</div></div>
- <div class="ttc" id="classutl_1_1i2c__i_3_01virtual__tag_01_4_html"><div class="ttname"><a href="classutl_1_1i2c__i_3_01virtual__tag_01_4.html">utl::i2c_i< virtual_tag ></a></div><div class="ttdoc">A virtual base class specialization. </div><div class="ttdef"><b>Definition:</b> <a href="i2c_8h_source.html#l00140">i2c.h:140</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a3a459ded18fe55460ae438e312c22110"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a3a459ded18fe55460ae438e312c22110">utl::i2c_bb_i::_rx_data</a></div><div class="ttdeci">byte_t _rx_data(bool ack, Sequence seq)</div><div class="ttdoc">Receive a byte from the i2c bus. </div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00154">i2c_bb.h:154</a></div></div>
- <div class="ttc" id="crtp_8h_html"><div class="ttname"><a href="crtp_8h.html">crtp.h</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4_html_a47e0f23aa64714a0a95c579994a84fcc"><div class="ttname"><a href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#a47e0f23aa64714a0a95c579994a84fcc">utl::i2c_bb_i< virtual_tag >::_clock</a></div><div class="ttdeci">void _clock(uint32_t c) final</div><div class="ttdoc">set clock frequency of the bus [Hz] </div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00277">i2c_bb.h:277</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a1f491d6ccadce71fa6cc59eebc74e82f"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a1f491d6ccadce71fa6cc59eebc74e82f">utl::i2c_bb_i::_clock</a></div><div class="ttdeci">uint32_t _clock() const</div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00095">i2c_bb.h:95</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_ade9235a9d8ccfd7233494631d66ba07e"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#ade9235a9d8ccfd7233494631d66ba07e">utl::i2c_bb_i::_stop</a></div><div class="ttdeci">void _stop()</div><div class="ttdoc">Send stop functionality. </div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00131">i2c_bb.h:131</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a085e38e545049ac64cd745b08e0be18f"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a085e38e545049ac64cd745b08e0be18f">utl::i2c_bb_i::_tx_data</a></div><div class="ttdeci">bool _tx_data(byte_t byte, Sequence seq)</div><div class="ttdoc">Transmit a byte to the i2c bus. </div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00194">i2c_bb.h:194</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_aef4db6e89447b2f0921df5b291b86232"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#aef4db6e89447b2f0921df5b291b86232">utl::i2c_bb_i::_clock</a></div><div class="ttdeci">void _clock(uint32_t c)</div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00096">i2c_bb.h:96</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a4369b434fde250d503bfdc07d5c6a26d"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26d">utl::i2c_bb_i::SDAMode</a></div><div class="ttdeci">SDAMode</div><div class="ttdoc">SDA pin direction enumerator. </div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00055">i2c_bb.h:55</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a4369b434fde250d503bfdc07d5c6a26daa84cc046d48610b05c21fd3670d0c829"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26daa84cc046d48610b05c21fd3670d0c829">utl::i2c_bb_i::SDAMode::INPUT</a></div></div>
- <div class="ttc" id="namespaceutl_html"><div class="ttname"><a href="namespaceutl.html">utl</a></div><div class="ttdoc">STL&#39;s core language concepts. </div><div class="ttdef"><b>Definition:</b> <a href="__1wire_8h_source.html#l00030">_1wire.h:30</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4_html_a0c9341b2a60e9400523de0397c472a76"><div class="ttname"><a href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html#a0c9341b2a60e9400523de0397c472a76">utl::i2c_bb_i< virtual_tag >::i2c_bb_i</a></div><div class="ttdeci">i2c_bb_i(uint32_t clk) noexcept</div><div class="ttdoc">Constructor. </div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00250">i2c_bb.h:250</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__i_html_a7e2dde443c6c9bde4a2293beb22950c5"><div class="ttname"><a href="classutl_1_1i2c__i.html#a7e2dde443c6c9bde4a2293beb22950c5">utl::i2c_i::Sequence</a></div><div class="ttdeci">Sequence</div><div class="ttdoc">I2C transmit/receive sequence. </div><div class="ttdef"><b>Definition:</b> <a href="i2c_8h_source.html#l00049">i2c.h:49</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4_html"><div class="ttname"><a href="classutl_1_1i2c__bb__i_3_01virtual__tag_01_4.html">utl::i2c_bb_i< virtual_tag ></a></div><div class="ttdoc">A virtual base class interface specialization. Using the private virtual interface we provide the int...</div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00234">i2c_bb.h:234</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html">utl::i2c_bb_i</a></div><div class="ttdoc">A bit banking implementation of i2c bus inherited from i2c_i base class. </div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00047">i2c_bb.h:47</a></div></div>
- <div class="ttc" id="namespaceutl_html_a1427cb5a2b13313147a902173b91e3c1"><div class="ttname"><a href="namespaceutl.html#a1427cb5a2b13313147a902173b91e3c1">utl::byte_t</a></div><div class="ttdeci">uint8_t byte_t</div><div class="ttdoc">8 bits wide </div><div class="ttdef"><b>Definition:</b> <a href="types_8h_source.html#l00031">types.h:31</a></div></div>
- <div class="ttc" id="structutl_1_1virtual__tag_html"><div class="ttname"><a href="structutl_1_1virtual__tag.html">utl::virtual_tag</a></div><div class="ttdoc">virtual support tag type </div><div class="ttdef"><b>Definition:</b> <a href="crtp_8h_source.html#l00040">crtp.h:40</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a18db1fab1be2aafbb2612242df2667f1"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a18db1fab1be2aafbb2612242df2667f1">utl::i2c_bb_i::delay</a></div><div class="ttdeci">void delay(uint32_t usec)</div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00087">i2c_bb.h:87</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__i_3_01virtual__tag_01_4_html_a260541de452a9a653162b8b109b26c09"><div class="ttname"><a href="classutl_1_1i2c__i_3_01virtual__tag_01_4.html#a260541de452a9a653162b8b109b26c09">utl::i2c_i< virtual_tag >::Sequence</a></div><div class="ttdeci">Sequence</div><div class="ttdoc">I2C transmit/receive sequence. </div><div class="ttdef"><b>Definition:</b> <a href="i2c_8h_source.html#l00145">i2c.h:145</a></div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_ac2d9b97778a5dd57eb5e6425b4b0833c"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#ac2d9b97778a5dd57eb5e6425b4b0833c">utl::i2c_bb_i::~i2c_bb_i</a></div><div class="ttdeci">~i2c_bb_i() noexcept=default</div><div class="ttdoc">A default destructor, allow destructor from derived only. </div></div>
- <div class="ttc" id="impl_8h_html"><div class="ttname"><a href="impl_8h.html">impl.h</a></div><div class="ttdoc">Implementation detail main forward header. </div></div>
- <div class="ttc" id="classutl_1_1i2c__bb__i_html_a0c9f7d9fc10ac2ceaef93cb6daf8a699"><div class="ttname"><a href="classutl_1_1i2c__bb__i.html#a0c9f7d9fc10ac2ceaef93cb6daf8a699">utl::i2c_bb_i::SCL</a></div><div class="ttdeci">void SCL(uint8_t st)</div><div class="ttdoc">Implementers&#39;s scl pin function. </div><div class="ttdef"><b>Definition:</b> <a href="i2c__bb_8h_source.html#l00086">i2c_bb.h:86</a></div></div>
- <div class="ttc" id="i2c_8h_html"><div class="ttname"><a href="i2c_8h.html">i2c.h</a></div><div class="ttdoc">An Abstract base class interface for the i2c bus. </div></div>
- </div><!-- fragment --></div><!-- contents -->
- </div><!-- doc-content -->
- <!-- start footer part -->
- <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
- <ul>
- <li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_82754f54d9380477ef02477185c1f103.html">utl</a></li><li class="navelem"><a class="el" href="dir_b2ad3c1a6521a4924fa9194d98c323e2.html">com</a></li><li class="navelem"><a class="el" href="i2c__bb_8h.html">i2c_bb.h</a></li>
- <li class="footer">Generated by
- <a href="http://www.doxygen.org/index.html">
- <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
- </ul>
- </div>
- </body>
- </html>
|