#include "stm32g4xx_hal.h"
#include "hal_callback.h"
#include "terminal_usartbridge.h"
#include "uart_bridge.h"
#include <stdio.h>

// -------------------------------------------------------------------------- //
//                                  UART                                      //
// -------------------------------------------------------------------------- //

void UART_RxCpltCallback(UART_HandleTypeDef *huart);    
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    switch((uint32_t)huart->Instance)
    {
        case USART3_BASE :  // HAL USART Terminal
            HAL_UART_RxCpltCallbackTerminal();
        break;

        case USART2_BASE :
            usart_bridge_rx_cb();
        break;
        
        default : break;
    }
}

void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
    switch((uint32_t)huart->Instance)
    {
        case USART3_BASE :  // HAL USART Terminal
            HAL_UART_RxCpltCallbackTerminal();
        break;

        case USART2_BASE :
            usart_bridge_rx_cb();
        break;
        
        default : break;
    }
}

//__weak void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)

// -------------------------------------------------------------------------- //
//                                  TIM                                      //
// -------------------------------------------------------------------------- //

//
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
    static int cnt = 0;

    switch((uint32_t)htim->Instance)
    {
        case TIM2_BASE :
            printf("Encoder: %d\r\n", cnt++);
        break;
          
        default : break;
    }
}