/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#ifndef INCLUDE_ECXX_PLATFORM_SPECIFIC_TWIMASTER_H
#error "this file cannot be included directly"
#endif
#undef INCLUDE_ECXX_PLATFORM_SPECIFIC_TWIMASTER_H


#ifndef ECXX_PLATFORM_DUMMY_TWIMASTER_H
#define ECXX_PLATFORM_DUMMY_TWIMASTER_H


namespace eCxx {


//
// A dummy TWI-master
//
// WARNING : All functions derived from BasicOutputWriter<> that accept 'PGMCharPointer' and 'PGMCharPointerFar'
//           as their parameters expect the pointers to come from program memory exclusively!
//
// NOTE    : Whenever possible, use the near program pointer because the far one has more overhead and restrictions.
//
class TWIMaster : public BasicOutputWriter<TWIMaster> {
    public:
        using TWIResultCode = eCxx::TWIResultCode;

        static constexpr decltype(eCxx::DefaultTWIFrequency) DefaultTWIFrequency = eCxx::DefaultTWIFrequency;

    public:
        inline ~TWIMaster() = default;

    public:
        void begin(uint32_t frequency = DefaultTWIFrequency);
        void end();

        void beginTransmission(uint8_t slaveAddress);
        bool write(uint8_t value);
        bool write(const void* data, uint8_t len);
        TWIResultCode endTransmission();

        uint8_t requestFrom(uint8_t slaveAddress, uint8_t len);
        bool canRead() const;
        bool read(uint8_t& value);
        bool peek(uint8_t& value) const;

    private:
        inline TWIMaster() = default;
};


} // namespace eCxx


#endif
