parent
2d01b49bbf
commit
66ce6a2812
@ -0,0 +1,20 @@
|
||||
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)
|
@ -0,0 +1,67 @@
|
||||
#ifndef _I2C_HPP_
|
||||
#define _I2C_HPP_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace hw
|
||||
{
|
||||
// i2c channels
|
||||
enum i2c_ch
|
||||
{
|
||||
i2c_ch0,
|
||||
i2c_ch1
|
||||
};
|
||||
|
||||
//
|
||||
// template
|
||||
//
|
||||
|
||||
template<i2c_ch>
|
||||
class I2C
|
||||
{
|
||||
public:
|
||||
I2C();
|
||||
void writeByte(uint8_t address, uint8_t byte);
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
// implementation CH0
|
||||
//
|
||||
|
||||
template<>
|
||||
I2C<i2c_ch0>::I2C()
|
||||
{
|
||||
std::cout << "i2c_ch0 has been created" << std::endl;
|
||||
}
|
||||
|
||||
template<>
|
||||
void I2C<i2c_ch0>::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()
|
||||
{
|
||||
std::cout << "i2c_ch1 has been created" << std::endl;
|
||||
}
|
||||
|
||||
template<>
|
||||
void I2C<i2c_ch1>::writeByte(uint8_t address, uint8_t byte)
|
||||
{
|
||||
|
||||
std::cout << "wrtiteByte() of i2c CH1 has been called!" << std::endl;
|
||||
}
|
||||
|
||||
}; // namespace hw
|
||||
|
||||
#endif // _I2C_HPP_
|
@ -0,0 +1,24 @@
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
|
||||
|
||||
#include "i2c.hpp"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//using namespace std::placeholders; // for _1, _2, ...
|
||||
//std::cout << "callback_example" << std::endl;
|
||||
|
||||
hw::I2C<hw::i2c_ch0> 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;
|
||||
}
|
Binary file not shown.
Loading…
Reference in new issue