/**
  ******************************************************************************
  * @file    SHAL_TIM.h
  * @author  Luca Lizaranzu
  * @brief   Relating to SHAL_UART and USART object abstractions
  ******************************************************************************
  */

#ifndef SHMINGO_HAL_SHAL_UART_H
#define SHMINGO_HAL_SHAL_UART_H

#include "SHAL_UART_REG.h"
#include "SHAL_UART_TYPES.h"

class SHAL_UART{

    friend class UARTManager;
public:

    void init(UART_Pair_Key pair);

    //begins Tx and Usart TODO either modify this function or add a new one that supports Rx
    void begin(uint32_t baudRate, SHAL_USART_Word_Length wordLength) const volatile;

    //Sends a string
    void sendString(const char* s) const volatile;

    void sendChar(char c) const volatile;

private:

    SHAL_UART() = default; //Initializer for array

    //Creates a SHAL_UART based on a pair of two valid U(S)ART pins

    UART_Pair_Key m_key = UART_Pair_Key::INVALID;

};


#define UART(num) UARTManager::get(num)

class UARTManager{

public:

    static SHAL_UART& get(uint8_t uart);

    UARTManager() = delete;

private:

    inline static SHAL_UART m_UARTs[NUM_USART_LINES] = {};

};

#endif //SHMINGO_HAL_SHAL_UART_H
