/*
* © 2023, Neil McKechnie. All rights reserved.
*
* This file is part of DCC++EX API
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* It is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see .
*/
/*
* The purpose of this module is to provide an interface to the DCC
* I2CManager that is compatible with code written for the Arduino
* 'Wire' interface.
*
* To use it, just replace
* #include "Wire.h" or #include
* with
* #include "IO_Wire.h"
*
* Note that the CS only supports I2C master mode, so the calls related to
* slave mode are not implemented here.
*
*/
#ifndef IO_WIRE
#define IO_WIRE
#include "IODevice.h"
#ifndef I2C_USE_WIRE
class IO_Wire : public IODevice, public Stream {
public:
IO_Wire() {
addDevice(this);
};
void begin() {
I2CManager.begin();
}
void setClock(uint32_t speed) {
I2CManager.setClock(speed);
}
void beginTransmission(uint8_t address) {
i2cAddress = address;
outputLength = 0;
}
size_t write(byte value) override {
if (outputLength < sizeof(outputBuffer)) {
outputBuffer[outputLength++] = value;
return 1;
} else
return 0;
}
size_t write(const uint8_t *buffer, size_t size) override {
for (size_t i=0; i
#endif
#endif