Add convenience function to read multiple bytes at once

This commit is contained in:
BlackMark 2020-05-15 11:50:58 +02:00
parent 5c3fb99c19
commit ff131d92a1

12
i2c.hpp
View File

@ -1,5 +1,6 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include "hardware.hpp"
@ -30,6 +31,17 @@ struct I2c {
return Driver::template read<LastByte>();
}
template <size_t Bytes>
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<true>();
}
static void stop()
{
Driver::stop();