Instead of passing function pointers, we're passing structs with context now. The idea is the same, I/O functions require some struct with a function pointer and some generic memory that only the output device cares about. I/O just calls it. VGA has been reworked to accomodate this change, as well as default outputs being created for low-overhead use (such as interrupt handlers).
50 lines
1.1 KiB
C
50 lines
1.1 KiB
C
/* serial.h
|
|
* Serial Interface
|
|
*
|
|
* Send/receive data via serial ports.
|
|
*/
|
|
#ifndef SERIAL_H
|
|
#define SERIAL_H
|
|
#include "asm.h"
|
|
#include "io.h"
|
|
#include <stdint.h>
|
|
|
|
typedef struct SerialState_s {
|
|
uint16_t port;
|
|
} SerialState_t;
|
|
|
|
extern char_writer_t* default_COM;
|
|
|
|
/**
|
|
* @brief Initialize a serial port for communication
|
|
* @param port The serial port number to initialize
|
|
* @return Status code indicating success or failure
|
|
*/
|
|
int serial_init(uint16_t port);
|
|
|
|
/**
|
|
* @brief Check if there is pending data to receive on the serial port
|
|
* @return Non-zero if data is pending, 0 otherwise
|
|
*/
|
|
int serial_recv_pending();
|
|
|
|
/**
|
|
* @brief Receive a single byte from the serial port
|
|
* @return The received byte as an 8-bit unsigned integer
|
|
*/
|
|
uint8_t serial_recv8(uint16_t port);
|
|
|
|
/**
|
|
* @brief Check if the serial port is ready to send data
|
|
* @return Non-zero if ready to send, 0 otherwise
|
|
*/
|
|
int serial_send_pending(uint16_t port);
|
|
|
|
/**
|
|
* @brief Send a single byte through the serial port
|
|
* @param data The 8-bit data byte to send
|
|
*/
|
|
int serial_send8(uint16_t port, char data);
|
|
|
|
|
|
#endif
|