test_i2c_impl.cpp
Go to the documentation of this file.
#include <gtest/gtest.h>
#include <utl/com/i2c_bb.h>
namespace test_i2c {
using namespace utl;
// implementer class stub
class I2C : public i2c_bb_i<I2C> {
friend i2c_bb_i<I2C>;
void SCL (bool x) { (void)x; } // imaginary SCL pin functionality
bool SDA (SDAMode mode, bool x) {
(void)mode;
(void)x;
// always read 0 back (which means always ACK)
return 0;
}
void delay (uint32_t u) {
(void)u;
// Pseudo-delay
for (int i =0 ; i<10 ; ++i)
;
}
public:
I2C (uint32_t clk =100000) noexcept
: i2c_bb_i<I2C>(clk) {
start();
}
};
TEST(Test_i2c_impl, TestConcept) {
I2C i2c {};
// EXPECT_EQ(I2c_i<I2C>, true);
}
TEST(Test_i2c_impl, TestConstruction) {
I2C i2c {};
EXPECT_EQ(i2c.clock(), 100000UL);
}
TEST(Test_i2c_impl, TestFunctionality) {
I2C i2c {};
uint8_t b = 42;
i2c.clock(200000UL);
//EXPECT_EQ(i2c.clock(), 200000UL);
EXPECT_EQ(i2c.tx_data(b), true);
EXPECT_EQ(i2c.rx_data(true), 0x00);
EXPECT_EQ(i2c.rx_data(false), 0x00);
}
}
test_i2c::I2C::I2C
I2C(uint32_t clk=100000) noexcept
Definition: test_i2c_impl.cpp:50
test_i2c
Definition: test_i2c_impl.cpp:29
test_i2c::TEST
TEST(Test_i2c_impl, TestConcept)
Definition: test_i2c_impl.cpp:56
gtest.h
utl::i2c_bb_i< I2C >::SDAMode
SDAMode
SDA pin direction enumerator.
Definition: i2c_bb.h:55
i2c_bb.h
A bit banking implementation of i2c bus inherited from i2c_i base class.
utl
STL&#39;s core language concepts.
Definition: _1wire.h:30
utl::i2c_i::clock
uint32_t clock() const
Definition: i2c.h:87
EXPECT_EQ
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:16643
utl::i2c_bb_i
A bit banking implementation of i2c bus inherited from i2c_i base class.
Definition: i2c_bb.h:47
test_i2c::I2C
Definition: test_i2c_impl.cpp:33