2019-08-05 21:21:14 +02:00
|
|
|
#pragma once
|
2019-08-05 21:43:06 +02:00
|
|
|
|
2019-08-06 21:44:59 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "hardware.hpp"
|
|
|
|
|
|
|
|
namespace i2c {
|
|
|
|
|
|
|
|
template <class Driver>
|
2019-08-05 21:43:06 +02:00
|
|
|
struct I2c {
|
2019-08-06 21:44:59 +02:00
|
|
|
static void init()
|
|
|
|
{
|
|
|
|
Driver::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <uint8_t Addr>
|
|
|
|
static bool start(bool read)
|
|
|
|
{
|
|
|
|
return Driver::template start<Addr>(read);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool write(uint8_t data)
|
|
|
|
{
|
|
|
|
return Driver::write(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <bool LastByte = false>
|
|
|
|
static uint8_t read()
|
|
|
|
{
|
|
|
|
return Driver::template read<LastByte>();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stop()
|
|
|
|
{
|
|
|
|
Driver::stop();
|
|
|
|
}
|
2019-08-05 21:43:06 +02:00
|
|
|
};
|
2019-08-06 21:44:59 +02:00
|
|
|
|
|
|
|
} // namespace i2c
|