Skip to content

Commit

Permalink
Add convenient I/O functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ReimuNotMoe committed Jan 2, 2021
1 parent 8cac2d2 commit f18567c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions I2CC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once

#include <string>
#include <vector>
#include <system_error>

#include <unistd.h>
Expand Down Expand Up @@ -94,6 +95,22 @@ namespace YukiWorkshop {
}
}

std::vector<uint8_t> read_data(uint8_t reg_addr, uint8_t len) {
std::vector<uint8_t> ret(len);
read_data(reg_addr, ret.data(), len);
return ret;
}

template<typename T>
void write_data(uint8_t reg_addr, const std::vector<T>& buf) {
write_data(reg_addr, buf.data(), buf.size() * sizeof(T));
}

template<typename T>
void write_data(uint8_t reg_addr, const T& buf) {
write_data(reg_addr, buf.data(), buf.size());
}

uint8_t read_u8(uint8_t reg_addr) {
auto rc = i2c_smbus_read_byte_data(fd_, reg_addr);
if (rc < 0) {
Expand Down

0 comments on commit f18567c

Please sign in to comment.