35 lines
541 B
C++
35 lines
541 B
C++
|
|
#pragma once
|
|
|
|
#include <inttypes.h>
|
|
#include "util.hpp"
|
|
|
|
struct SoftTWI {
|
|
|
|
constexpr SoftTWI::SoftTWI(unsigned sda, unsigned scl)
|
|
: _sda(sda)
|
|
, _scl(scl) {
|
|
}
|
|
|
|
unsigned write(const uint8_t*, unsigned);
|
|
void read(uint8_t*, unsigned, bool=false);
|
|
uint8_t read(bool=true);
|
|
bool write(uint8_t);
|
|
void end();
|
|
|
|
inline bool start_read(uint8_t addr) {
|
|
return start((addr << 1) | 1);
|
|
}
|
|
|
|
inline bool start_write(uint8_t addr) {
|
|
return start(addr << 1);
|
|
}
|
|
|
|
private:
|
|
unsigned _sda;
|
|
unsigned _scl;
|
|
|
|
bool start(uint8_t addr);
|
|
};
|
|
|