uTL
micro Template library
test_i2c_impl.cpp
Go to the documentation of this file.
1 
20 #include <gtest/gtest.h>
21 #include <utl/com/i2c_bb.h>
22 
29 namespace test_i2c {
30  using namespace utl;
31 
32  // implementer class stub
33  class I2C : public i2c_bb_i<I2C> {
34  friend i2c_bb_i<I2C>;
35  void SCL (bool x) { (void)x; } // imaginary SCL pin functionality
36  bool SDA (SDAMode mode, bool x) {
37  (void)mode;
38  (void)x;
39  // always read 0 back (which means always ACK)
40  return 0;
41  }
42  void delay (uint32_t u) {
43  (void)u;
44  // Pseudo-delay
45  for (int i =0 ; i<10 ; ++i)
46  ;
47  }
48 
49  public:
50  I2C (uint32_t clk =100000) noexcept
51  : i2c_bb_i<I2C>(clk) {
52  start();
53  }
54  };
55 
56  TEST(Test_i2c_impl, TestConcept) {
57  I2C i2c {};
58 // EXPECT_EQ(I2c_i<I2C>, true);
59  }
60 
61  TEST(Test_i2c_impl, TestConstruction) {
62  I2C i2c {};
63  EXPECT_EQ(i2c.clock(), 100000UL);
64  }
65 
66  TEST(Test_i2c_impl, TestFunctionality) {
67  I2C i2c {};
68  uint8_t b = 42;
69 
70  i2c.clock(200000UL);
71  //EXPECT_EQ(i2c.clock(), 200000UL);
72 
73  EXPECT_EQ(i2c.tx_data(b), true);
74  EXPECT_EQ(i2c.rx_data(true), 0x00);
75  EXPECT_EQ(i2c.rx_data(false), 0x00);
76  }
77 }
I2C(uint32_t clk=100000) noexcept
TEST(Test_i2c_impl, TestConcept)
SDAMode
SDA pin direction enumerator.
Definition: i2c_bb.h:55
A bit banking implementation of i2c bus inherited from i2c_i base class.
STL&#39;s core language concepts.
Definition: _1wire.h:30
uint32_t clock() const
Definition: i2c.h:87
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:16643
A bit banking implementation of i2c bus inherited from i2c_i base class.
Definition: i2c_bb.h:47