Add convenience function to read multiple bytes at once
This commit is contained in:
parent
5c3fb99c19
commit
ff131d92a1
12
i2c.hpp
12
i2c.hpp
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user