#pragma once #include #include #include "hardware.hpp" namespace i2c { template struct I2c { static void init() { Driver::init(); } template static bool start(bool read) { return Driver::template start(read); } static bool write(uint8_t data) { return Driver::write(data); } template static bool writeBytes(const uint8_t *buffer) { for (size_t i = 0; i < Bytes; ++i) { if (!write(buffer[i])) return false; } return true; } template static uint8_t read() { return Driver::template read(); } template static void readBytes(uint8_t *buffer) { static_assert(Bytes > 0, "Must read at least 1 byte"); for (size_t i = 0; i < Bytes - 1; ++i) { buffer[i] = read(); } buffer[Bytes - 1] = read(); } static void stop() { Driver::stop(); } }; } // namespace i2c