#include "putil.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>

#define MAX_PRINTF_BUFFER (256)

UART_HandleTypeDef* huart_inst = NULL;

int p_printf(const char* fmt, ...)
{
	size_t size_str = strlen(fmt);
	if (size_str >= MAX_PRINTF_BUFFER)
	{
		return -1;
	}
	uint8_t printf_buffer[MAX_PRINTF_BUFFER];
	memset(printf_buffer, '\0', MAX_PRINTF_BUFFER);
	va_list args;
	va_start(args, fmt);
	vsprintf((char*)printf_buffer, fmt, args);
	va_end(args);
	HAL_UART_Transmit(huart_inst, printf_buffer, strlen(printf_buffer), 100);
	return 0;


}
void p_uart_init(UART_HandleTypeDef* huart)
{
	huart_inst = huart;
}
