/*
 * 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, packet_usart &usart);

private:
    console_handler(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t stream_rx, uint32_t stream_tx);

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

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

} /* namespace f4ll */

#endif /* LL_CONSOLEHANDLER_H_ */
