From 4f32bbc46a48276bba949364dc44d532c19dae78 Mon Sep 17 00:00:00 2001 From: taitep Date: Thu, 29 Jan 2026 21:27:36 +0100 Subject: i think i managed to make a working uart driver for the new interface?? --- include/uart.h | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'include/uart.h') diff --git a/include/uart.h b/include/uart.h index 76f4b34..7b414ca 100644 --- a/include/uart.h +++ b/include/uart.h @@ -1,30 +1,29 @@ #pragma once +#include +#include + #define UART_BASE 0x10000 -#define UART_DATA *(volatile char *)(UART_BASE + 0) -#define UART_STATUS *(volatile char *)(UART_BASE + 1) -#define UART_TX_READY 0b01 -#define UART_RX_READY 0b10 - -static inline int uart_rx_ready() { return (UART_STATUS & UART_RX_READY) != 0; } -static inline int uart_tx_ready() { return (UART_STATUS & UART_TX_READY) != 0; } - -static inline void uart_putc(char c) { - while (!uart_tx_ready()) - ; - UART_DATA = c; -} - -static inline void uart_puts(const char *s) { - while (*s) { - uart_putc(*s++); - } -} - -static inline char uart_getc_nonblocking() { return UART_DATA; } - -static inline char uart_getc() { - while (!uart_rx_ready()) - ; - return UART_DATA; -} +#define UART_REG(offset) *(volatile uint32_t *)(UART_BASE + offset) +#define UART_TXDATA UART_REG(0x00) +#define UART_RXDATA UART_REG(0x04) +#define UART_TXCTRL UART_REG(0x08) +#define UART_RXCTRL UART_REG(0x0c) +#define UART_IE UART_REG(0x10) +#define UART_IP UART_REG(0x14) +#define UART_DIV UART_REG(0x18) + +#define UART_TXDATA_FULL 0x80000000 +#define UART_RXDATA_EMPTY 0x80000000 + +#define UART_TXCTRL_TXEN 1 +#define UART_RXCTRL_RXEN 1 + +void uart_init(void); + +bool uart_tx_ready(void); + +void uart_putc(char c); +void uart_puts(const char *s); + +char uart_getc(void); -- cgit v1.2.3