/*
 * printf.c
 *
 *  Created on: Sep 5, 2025
 *      Author: sowgro
 */

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "UART.h"
#include "printf.h"

char buffer[120];

int putchar(int value) {
	USART_Write(USART2, (unsigned char *) &value, 1);
	return 1;
}

int puts(const char *string) {
	int n = strlen(string);
	USART_Write(USART2, (unsigned char *) string, n);
	USART_Write(USART2, (unsigned char *) "\n", 1);
	return n + 1;
}

int printf(const char *format, ...) {
	va_list args;
	va_start(args, format);
	int n = vsprintf(buffer, format, args);
	va_end(args);
	USART_Write(USART2, (unsigned char *) buffer, n);
	return n;
}
