/*
{{copyright}} 
*/

/*
{{version}} 
*/

/*
{{license}} 
*/

#pragma once

#include "ICommBus.h"

#include <chrono>
#include <expected>
#include <span>

namespace sdi_uToolBox::comm
{
//--------------------------------------------------------------
class I2CBus : public ICommBus
{
  public:
  using ReadBuf    = std::span<uint8_t>;
  using WriteBuf   = std::span<const uint8_t>;
  using Timeout    = std::chrono::milliseconds;
  using ReturnType = std::expected<size_t, ReturnStatus>;

  public:
  I2CBus()                          = default;     // Default constructor
  virtual ~I2CBus() override        = default;     // Default destructor
  I2CBus(const I2CBus &)            = delete;      // Copy constructor
  I2CBus(I2CBus &&)                 = delete;      // Move constructor
  I2CBus &operator=(const I2CBus &) = delete;      // Copy assignment operator
  I2CBus &operator=(I2CBus &&)      = delete;      // Move assignment operator

  virtual ReturnType   write(uint8_t address, WriteBuf buf, Timeout timeout) const = 0;     // Write data to I2C device
  virtual ReturnType   read(uint8_t address, ReadBuf buf, Timeout timeout) const   = 0;     // Read data from I2C device
  virtual ReturnStatus isDeviceReady(uint8_t address) const                        = 0;     // Check if I2C device is ready
};
//--------------------------------------------------------------
}     // namespace sdi_uToolBox::comm