Micro template library A library for building device drivers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

117 lines
16 KiB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.14"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>uTL: test/tests/test_i2c_impl.cpp Source File</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="resize.js"></script>
  14. <script type="text/javascript" src="navtreedata.js"></script>
  15. <script type="text/javascript" src="navtree.js"></script>
  16. <script type="text/javascript">
  17. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  18. $(document).ready(initResizable);
  19. /* @license-end */</script>
  20. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  21. <script type="text/javascript" src="search/searchdata.js"></script>
  22. <script type="text/javascript" src="search/search.js"></script>
  23. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  24. </head>
  25. <body>
  26. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  27. <div id="titlearea">
  28. <table cellspacing="0" cellpadding="0">
  29. <tbody>
  30. <tr style="height: 56px;">
  31. <td id="projectalign" style="padding-left: 0.5em;">
  32. <div id="projectname">uTL
  33. </div>
  34. <div id="projectbrief">micro Template library</div>
  35. </td>
  36. </tr>
  37. </tbody>
  38. </table>
  39. </div>
  40. <!-- end header part -->
  41. <!-- Generated by Doxygen 1.8.14 -->
  42. <script type="text/javascript">
  43. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  44. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  45. /* @license-end */
  46. </script>
  47. <script type="text/javascript" src="menudata.js"></script>
  48. <script type="text/javascript" src="menu.js"></script>
  49. <script type="text/javascript">
  50. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  51. $(function() {
  52. initMenu('',true,false,'search.php','Search');
  53. $(document).ready(function() { init_search(); });
  54. });
  55. /* @license-end */</script>
  56. <div id="main-nav"></div>
  57. </div><!-- top -->
  58. <div id="side-nav" class="ui-resizable side-nav-resizable">
  59. <div id="nav-tree">
  60. <div id="nav-tree-contents">
  61. <div id="nav-sync" class="sync"></div>
  62. </div>
  63. </div>
  64. <div id="splitbar" style="-moz-user-select:none;"
  65. class="ui-resizable-handle">
  66. </div>
  67. </div>
  68. <script type="text/javascript">
  69. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  70. $(document).ready(function(){initNavTree('test__i2c__impl_8cpp_source.html','');});
  71. /* @license-end */
  72. </script>
  73. <div id="doc-content">
  74. <!-- window showing the filter options -->
  75. <div id="MSearchSelectWindow"
  76. onmouseover="return searchBox.OnSearchSelectShow()"
  77. onmouseout="return searchBox.OnSearchSelectHide()"
  78. onkeydown="return searchBox.OnSearchSelectKey(event)">
  79. </div>
  80. <!-- iframe showing the search results (closed by default) -->
  81. <div id="MSearchResultsWindow">
  82. <iframe src="javascript:void(0)" frameborder="0"
  83. name="MSearchResults" id="MSearchResults">
  84. </iframe>
  85. </div>
  86. <div class="header">
  87. <div class="headertitle">
  88. <div class="title">test_i2c_impl.cpp</div> </div>
  89. </div><!--header-->
  90. <div class="contents">
  91. <a href="test__i2c__impl_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;</div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="gtest_8h.html">gtest/gtest.h</a>&gt;</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="i2c__bb_8h.html">utl/com/i2c_bb.h</a>&gt;</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;</div><div class="line"><a name="l00029"></a><span class="lineno"><a class="line" href="namespacetest__i2c.html"> 29</a></span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacetest__i2c.html">test_i2c</a> {</div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160; <span class="keyword">using namespace </span><a class="code" href="namespaceutl.html">utl</a>;</div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160;</div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160; <span class="comment">// implementer class stub</span></div><div class="line"><a name="l00033"></a><span class="lineno"><a class="line" href="classtest__i2c_1_1_i2_c.html"> 33</a></span>&#160; <span class="keyword">class </span><a class="code" href="classtest__i2c_1_1_i2_c.html">I2C</a> : <span class="keyword">public</span> <a class="code" href="classutl_1_1i2c__bb__i.html">i2c_bb_i</a>&lt;I2C&gt; {</div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160; <span class="keyword">friend</span> <a class="code" href="classutl_1_1i2c__bb__i.html">i2c_bb_i&lt;I2C&gt;</a>;</div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>&#160; <span class="keywordtype">void</span> SCL (<span class="keywordtype">bool</span> x) { (void)x; } <span class="comment">// imaginary SCL pin functionality</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>&#160; <span class="keywordtype">bool</span> SDA (<a class="code" href="classutl_1_1i2c__bb__i.html#a4369b434fde250d503bfdc07d5c6a26d">SDAMode</a> mode, <span class="keywordtype">bool</span> x) {</div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160; (void)mode;</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span>&#160; (void)x;</div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160; <span class="comment">// always read 0 back (which means always ACK)</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160; <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160; }</div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160; <span class="keywordtype">void</span> delay (uint32_t u) {</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160; (void)u;</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160; <span class="comment">// Pseudo-delay</span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i =0 ; i&lt;10 ; ++i)</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>&#160; ;</div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>&#160; }</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00050"></a><span class="lineno"><a class="line" href="classtest__i2c_1_1_i2_c.html#accd54d8b7f168eece3d462194964f967"> 50</a></span>&#160; <a class="code" href="classtest__i2c_1_1_i2_c.html#accd54d8b7f168eece3d462194964f967">I2C</a> (uint32_t clk =100000) noexcept</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; : <a class="code" href="classutl_1_1i2c__bb__i.html">i2c_bb_i</a>&lt;<a class="code" href="classtest__i2c_1_1_i2_c.html">I2C</a>&gt;(clk) {</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160; start();</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160; }</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160; };</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno"><a class="line" href="namespacetest__i2c.html#a04c34c5bd7848008eb6803be850b2296"> 56</a></span>&#160; <a class="code" href="namespacetest__i2c.html#a04c34c5bd7848008eb6803be850b2296">TEST</a>(Test_i2c_impl, TestConcept) {</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160; <a class="code" href="classtest__i2c_1_1_i2_c.html">I2C</a> i2c {};</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>&#160;<span class="comment">// EXPECT_EQ(I2c_i&lt;I2C&gt;, true);</span></div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>&#160; }</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160;</div><div class="line"><a name="l00061"></a><span class="lineno"><a class="line" href="namespacetest__i2c.html#a74c8554cb3a4c7bd022cd854feb06688"> 61</a></span>&#160; <a class="code" href="namespacetest__i2c.html#a04c34c5bd7848008eb6803be850b2296">TEST</a>(Test_i2c_impl, TestConstruction) {</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160; <a class="code" href="classtest__i2c_1_1_i2_c.html">I2C</a> i2c {};</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160; <a class="code" href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a>(i2c.clock(), 100000UL);</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160; }</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160;</div><div class="line"><a name="l00066"></a><span class="lineno"><a class="line" href="namespacetest__i2c.html#aee88e63fc24ad87c0987c6f207dd20fa"> 66</a></span>&#160; <a class="code" href="namespacetest__i2c.html#a04c34c5bd7848008eb6803be850b2296">TEST</a>(Test_i2c_impl, TestFunctionality) {</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160; <a class="code" href="classtest__i2c_1_1_i2_c.html">I2C</a> i2c {};</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160; uint8_t b = 42;</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160;</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160; i2c.<a class="code" href="classutl_1_1i2c__i.html#aac5fed816701cc4543acd717ec804ac0">clock</a>(200000UL);</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160; <span class="comment">//EXPECT_EQ(i2c.clock(), 200000UL);</span></div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160;</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160; <a class="code" href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a>(i2c.tx_data(b), <span class="keyword">true</span>);</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>&#160; <a class="code" href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a>(i2c.rx_data(<span class="keyword">true</span>), 0x00);</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>&#160; <a class="code" href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a>(i2c.rx_data(<span class="keyword">false</span>), 0x00);</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>&#160; }</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160;}</div><div class="ttc" id="classtest__i2c_1_1_i2_c_html_accd54d8b7f168eece3d462194964f967"><div class="ttname"><a href="classtest__i2c_1_1_i2_c.html#accd54d8b7f168eece3d462194964f967">test_i2c::I2C::I2C</a></div><div class="ttdeci">I2C(uint32_t clk=100000) noexcept</div><div class="ttdef"><b>Definition:</b> <a href="test__i2c__impl_8cpp_source.html#l00050">test_i2c_impl.cpp:50</a></div></div>
  92. <div class="ttc" id="namespacetest__i2c_html"><div class="ttname"><a href="namespacetest__i2c.html">test_i2c</a></div><div class="ttdef"><b>Definition:</b> <a href="test__i2c__impl_8cpp_source.html#l00029">test_i2c_impl.cpp:29</a></div></div>
  93. <div class="ttc" id="namespacetest__i2c_html_a04c34c5bd7848008eb6803be850b2296"><div class="ttname"><a href="namespacetest__i2c.html#a04c34c5bd7848008eb6803be850b2296">test_i2c::TEST</a></div><div class="ttdeci">TEST(Test_i2c_impl, TestConcept)</div><div class="ttdef"><b>Definition:</b> <a href="test__i2c__impl_8cpp_source.html#l00056">test_i2c_impl.cpp:56</a></div></div>
  94. <div class="ttc" id="gtest_8h_html"><div class="ttname"><a href="gtest_8h.html">gtest.h</a></div></div>
  95. <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&lt; I2C &gt;::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>
  96. <div class="ttc" id="i2c__bb_8h_html"><div class="ttname"><a href="i2c__bb_8h.html">i2c_bb.h</a></div><div class="ttdoc">A bit banking implementation of i2c bus inherited from i2c_i base class. </div></div>
  97. <div class="ttc" id="namespaceutl_html"><div class="ttname"><a href="namespaceutl.html">utl</a></div><div class="ttdoc">STL&amp;#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>
  98. <div class="ttc" id="classutl_1_1i2c__i_html_aac5fed816701cc4543acd717ec804ac0"><div class="ttname"><a href="classutl_1_1i2c__i.html#aac5fed816701cc4543acd717ec804ac0">utl::i2c_i::clock</a></div><div class="ttdeci">uint32_t clock() const</div><div class="ttdef"><b>Definition:</b> <a href="i2c_8h_source.html#l00087">i2c.h:87</a></div></div>
  99. <div class="ttc" id="gtest_8h_html_a4159019abda84f5366acdb7604ff220a"><div class="ttname"><a href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a></div><div class="ttdeci">#define EXPECT_EQ(val1, val2)</div><div class="ttdef"><b>Definition:</b> <a href="gtest_8h_source.html#l16643">gtest.h:16643</a></div></div>
  100. <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>
  101. <div class="ttc" id="classtest__i2c_1_1_i2_c_html"><div class="ttname"><a href="classtest__i2c_1_1_i2_c.html">test_i2c::I2C</a></div><div class="ttdef"><b>Definition:</b> <a href="test__i2c__impl_8cpp_source.html#l00033">test_i2c_impl.cpp:33</a></div></div>
  102. </div><!-- fragment --></div><!-- contents -->
  103. </div><!-- doc-content -->
  104. <!-- start footer part -->
  105. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  106. <ul>
  107. <li class="navelem"><a class="el" href="dir_13e138d54eb8818da29c3992edef070a.html">test</a></li><li class="navelem"><a class="el" href="dir_d84abbe486a7f5f39e3c9088ffc1760a.html">tests</a></li><li class="navelem"><a class="el" href="test__i2c__impl_8cpp.html">test_i2c_impl.cpp</a></li>
  108. <li class="footer">Generated by
  109. <a href="http://www.doxygen.org/index.html">
  110. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  111. </ul>
  112. </div>
  113. </body>
  114. </html>