15#include "soft_i2c_slave.h"
19 : _sda(sda), _scl(scl), _init(false), _pullup(pullup),
22 _idle (*this), _read_addr (*this), _write_ack (*this),
23 _read_data (*this), _write_data(*this), _read_ack (*this)
29soft_i2c_slave::~soft_i2c_slave() {
32 _sda.gpioMode(GPIO::INPUT);
33 _scl.gpioMode(GPIO::INPUT);
38void soft_i2c_slave::set_callbacks(
39 std::function<
bool(uint16_t index, uint8_t data)> receive,
40 std::function<uint8_t(uint16_t index)> transmit,
41 std::function<
void()> stop) {
47void soft_i2c_slave::init() {
48 uint16_t mode = GPIO::INPUT |
49 GPIO::OUTPUT_OPEN_DRAIN |
58 _sda.gpioAttachIrq(GPIO::FALLING | GPIO::RISING, [
this]() {
60 if (!_scl.gpioRead())
return;
61 _sda.gpioRead() ? _state->stop() : _state->start();
64 _scl.gpioAttachIrq(GPIO::FALLING | GPIO::RISING, [
this]() {
66 if (_scl.gpioRead()) {
67 _sda.gpioRead() ? _state->high() : _state->low();
69 _state->scl_falling();