From ff131d92a1b8e92efc2ae24306d7b7cac3cfb28a Mon Sep 17 00:00:00 2001 From: BlackMark Date: Fri, 15 May 2020 11:50:58 +0200 Subject: [PATCH] Add convenience function to read multiple bytes at once --- i2c.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/i2c.hpp b/i2c.hpp index 00ada38..0b48f40 100644 --- a/i2c.hpp +++ b/i2c.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include "hardware.hpp" @@ -30,6 +31,17 @@ struct I2c { 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();