Compare commits
2 Commits
5c3fb99c19
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 8af5afd00d | |||
| ff131d92a1 |
23
i2c.hpp
23
i2c.hpp
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "hardware.hpp"
|
||||
@@ -24,12 +25,34 @@ struct I2c {
|
||||
return Driver::write(data);
|
||||
}
|
||||
|
||||
template <size_t Bytes>
|
||||
static bool writeBytes(const uint8_t *buffer)
|
||||
{
|
||||
for (size_t i = 0; i < Bytes; ++i) {
|
||||
if (!write(buffer[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <bool LastByte = false>
|
||||
static uint8_t read()
|
||||
{
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user