/*
 * 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_UART_H
#error "this file cannot be included directly"
#endif
#undef INCLUDE_ECXX_PLATFORM_SPECIFIC_UART_H


#ifndef ECXX_PLATFORM_DUMMY_UART_H
#define ECXX_PLATFORM_DUMMY_UART_H


namespace eCxx {


//
// A dummy UART
//
// WARNING : All functions derived from BasicOutputWriter<T> that accept parameters with data types
//           'PGMCharPointer' and 'PGMCharPointerFar' expect the pointers to come from program
//           memory exclusively!
//
// NOTE    : Whenever possible, use the versions that accept near program pointers because those that
//           accept the far program pointers may have more overhead and restrictions.
//
class UART : public BasicOutputWriter<UART> {
    public:
        enum class DataFormat : uint8_t {};

    public:
        inline ~UART() = default;

    public:
        void begin(uint32_t baudrate, DataFormat dataFormat);
        void end();

        bool changeBaudrate(uint32_t baudrate);

        bool canRead() const;
        bool read(uint8_t& value);
        bool peek(uint8_t& value) const;

        bool canWrite() const;
        bool write(uint8_t value);
        void flush();

    private:
        inline UART() = default;
};


} // namespace eCxx


#endif
