summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authortaitep <taitep@taitep.se>2026-01-29 21:27:36 +0100
committertaitep <taitep@taitep.se>2026-01-29 21:27:36 +0100
commit4f32bbc46a48276bba949364dc44d532c19dae78 (patch)
tree8f54108788735efff25a4a9549bedbe7967d3c7b /include
parent25bec21f20208a9369656a337cf5325e7b3a5a8d (diff)
i think i managed to make a working uart driver for the new interface??HEADmain
Diffstat (limited to 'include')
-rw-r--r--include/uart.h53
1 files changed, 26 insertions, 27 deletions
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 <stdbool.h>
+#include <stdint.h>
+
#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);