DEBUG macro in uart.h, enabled by default in makefile

This commit is contained in:
Imbus 2024-03-24 02:28:40 +01:00
parent 3cb2df2468
commit 78e3ddce19
2 changed files with 16 additions and 0 deletions

View file

@ -11,6 +11,9 @@ QEMU_MACHINE_NAME = uno
# Compiler flags # Compiler flags
CFLAGS = -std=c2x -Wall -Wno-array-bounds -mmcu=$(MCU) -DF_CPU=16000000UL -O3 CFLAGS = -std=c2x -Wall -Wno-array-bounds -mmcu=$(MCU) -DF_CPU=16000000UL -O3
# Comment the following line to disable UART debugging (see uart.h)
CFLAGS += -DDEBUG_UART_ENABLED
# Source files # Source files
SRCS = $(wildcard *.c) SRCS = $(wildcard *.c)

13
uart.h
View file

@ -1,7 +1,20 @@
#pragma once #pragma once
// Simple UART library for ATmega328P
// Define DEBUG_UART_ENABLED to enable debug messages
#ifdef DEBUG_UART_ENABLED
#define DEBUG(message) UART_println(message)
#else
#define DEBUG(message) ((void)0) // Define as no operation (NOP)
#endif
#include <stdint.h> #include <stdint.h>
// Initialize UART
void initUART(); void initUART();
// Transmit a byte over UART
void UART_transmit(uint8_t data); void UART_transmit(uint8_t data);
// Print a formatted string over UART
void UART_println(const char* format, ...); void UART_println(const char* format, ...);