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.
88 lines
1.3 KiB
88 lines
1.3 KiB
#ifndef _I2C_HPP_
|
|
#define _I2C_HPP_
|
|
|
|
#include <stdint.h>
|
|
#include <unistd.h>
|
|
#include <iostream>
|
|
#include <memory>
|
|
|
|
#if 0
|
|
// i2c channels
|
|
enum i2c_ch
|
|
{
|
|
i2c_ch0,
|
|
i2c_ch1
|
|
};
|
|
#endif
|
|
|
|
//
|
|
// template
|
|
//
|
|
|
|
template<typename impl_T>
|
|
class I2C
|
|
{
|
|
public:
|
|
I2C();
|
|
void writeByte(const uint8_t& address, const uint8_t& byte)
|
|
{
|
|
pimpl->writeByte(address, byte);
|
|
}
|
|
private:
|
|
//struct pimpl_T;
|
|
std::unique_ptr<impl_T> pimpl;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename impl_>
|
|
I2C::I2C():pimpl(new impl()){}
|
|
|
|
template<typename impl_>
|
|
I2C::~I2C(){}
|
|
|
|
template<typename impl_>
|
|
void I2C::readByte(const uint8_t& address, const uint8_t& reg)
|
|
{
|
|
return pimpl->writeByte(address,byte);
|
|
}
|
|
|
|
#if 0
|
|
//
|
|
// implementation CH0
|
|
//
|
|
|
|
|
|
template<>
|
|
I2C<>::I2C()
|
|
{
|
|
|
|
}
|
|
|
|
template<>
|
|
void I2C<i2c_ch0, I2C_CH0_pimpl>::writeByte(uint8_t address, uint8_t byte)
|
|
{
|
|
std::cout << "wrtiteByte() of i2c CH0 has been called!" << std::endl;
|
|
}
|
|
|
|
//
|
|
// implementation CH1
|
|
//
|
|
|
|
template<>
|
|
I2C<i2c_ch1, I2C_CH1_pimpl>::I2C()
|
|
{
|
|
std::cout << "i2c_ch1 has been created" << std::endl;
|
|
}
|
|
|
|
template<>
|
|
void I2C<i2c_ch1, I2C_CH1_pimpl>::writeByte(uint8_t address, uint8_t byte)
|
|
{
|
|
|
|
std::cout << "wrtiteByte() of i2c CH1 has been called!" << std::endl;
|
|
}
|
|
#endif
|
|
|
|
#endif // _I2C_HPP_
|