summaryrefslogtreecommitdiff
path: root/project/Core/Src/Homework/printf.c
blob: 60605f831d4cafc00a38285d9a5e1518109b44cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
 * 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 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;
}