/*
 * ll_consolehandler.h
 *
 *  Created on: Nov 7, 2019
 *      Author: abody
 */

#ifndef LL_CONSOLEHANDLER_H_
#define LL_CONSOLEHANDLER_H_

#include <f4ll/packet_usart.h>
#include <f4ll/singleton.h>

namespace f4ll {

class console_handler : public usart_core, public singleton<console_handler>
{
    friend class singleton<console_handler>;

public:
    void PrintStats(uint8_t id, PacketUsart &usart);

private:
    console_handler(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t streamRx, uint32_t streamTx);

    // LL_UsartCore pure virtual function implementations
    virtual void receiver_idle(void);
    virtual void transmission_complete(void);
    virtual void framing_error(void);
    virtual void overrun(void);
    virtual void rx_dma_transfer_complete(void);
    virtual void rx_dma_half_transfer(void);
    virtual void rx_dma_error(dma_helper::dma_error_type reason);
    virtual void tx_dma_transfer_complete(void);
    virtual void tx_dma_half_transfer(void);
    virtual void tx_dma_error(dma_helper::dma_error_type reason);

    char m_buffer[128];
    uint16_t m_used = 0;
};

} /* namespace f4ll */

#endif /* LL_CONSOLEHANDLER_H_ */
