parent
893a5205e9
commit
66d839b947
@ -1,20 +0,0 @@
|
|||||||
cpp_src = $(wildcard *.cpp)
|
|
||||||
|
|
||||||
cpp_obj = $(cpp_src:.cpp=.o)
|
|
||||||
c_obj = $(c_src:.c=.o)
|
|
||||||
CC = g++
|
|
||||||
CFLAGS = -Wall -pedantic -li2c
|
|
||||||
LDFLAGS =
|
|
||||||
EXEC = runtest
|
|
||||||
|
|
||||||
|
|
||||||
all : $(EXEC)
|
|
||||||
|
|
||||||
$(EXEC): $(cpp_obj) $(c_obj)
|
|
||||||
$(CC) -o $@ $^ $(LDFLAGS)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf $(c_obj) $(cpp_obj) $(EXEC)
|
|
||||||
|
|
||||||
cleanall:
|
|
||||||
rm -rf $(c_obj) $(cpp_obj) $(EXEC)
|
|
@ -1,44 +0,0 @@
|
|||||||
#include "i2c.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
I2C::I2C():i2cPimpl(new i2cImpl()){}
|
|
||||||
|
|
||||||
I2C::~I2C(){}
|
|
||||||
|
|
||||||
uint8_t I2C::readByte(const uint8_t& address, const uint8_t& reg)
|
|
||||||
{
|
|
||||||
return i2cPimpl->readByte(address,reg);
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
uint16_t I2C::readWord(const uint8_t& address, const uint8_t& reg)
|
|
||||||
{
|
|
||||||
return i2cPimpl->readWord(address,reg);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t I2C::writeByte(const uint8_t& address, const uint8_t& data)
|
|
||||||
{
|
|
||||||
return i2cPimpl->writeByte(address,data);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t I2C::writeWord(const uint8_t& address, const uint8_t& reg, const uint8_t& data)
|
|
||||||
{
|
|
||||||
return i2cPimpl->writeWord(address,reg,data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void I2C::writeBuffer(const uint8_t& address, const uint8_t* buffer, uint8_t len)
|
|
||||||
{
|
|
||||||
return i2cPimpl->writeBuffer(address,buffer,len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void I2C::readBuffer(const uint8_t& address, const uint8_t* buffer, uint8_t len)
|
|
||||||
{
|
|
||||||
return i2cPimpl->readBuffer(address,buffer,len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void I2C::throwError(I2C::errors errNo)
|
|
||||||
{
|
|
||||||
i2cPimpl->throwError(errNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
|||||||
#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_
|
|
@ -1,16 +0,0 @@
|
|||||||
#ifndef _I2C_CH0_IMPL_HPP_
|
|
||||||
#define _I2C_CH0_IMPL_HPP_
|
|
||||||
|
|
||||||
#include "i2c.hpp"
|
|
||||||
|
|
||||||
struct I2C_CH0_impl
|
|
||||||
{
|
|
||||||
void writeByte(const uint8_t address, const uint8_t& byte)
|
|
||||||
{
|
|
||||||
std::cout << "write byte [" << byte << "] to address [" << address << "]" << std::endl;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif //_I2C_CH0_IMPL_HPP_
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
#include "i2c_ch0_impl.hpp"
|
|
||||||
#include "i2c.hpp"
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
//using namespace std::placeholders; // for _1, _2, ...
|
|
||||||
std::cout << "structure idea test" << std::endl;
|
|
||||||
|
|
||||||
I2C<I2C_CH0_impl> i2c_ch_0;
|
|
||||||
//hw::I2C<hw::i2c_ch1> i2c_ch_1;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//i2c_ch_0.writeByte(1,1);
|
|
||||||
//i2c_ch_1.writeByte(1,2);
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in new issue