Skip to main content

feagi_hal/hal/
serial.rs

1// Copyright 2025 Neuraville Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4/// Serial I/O abstraction for embedded platforms
5pub trait SerialIO {
6    /// Platform-specific error type
7    type Error;
8
9    /// Write bytes to serial port
10    ///
11    /// # Arguments
12    /// * `data` - Bytes to write
13    ///
14    /// # Returns
15    /// Number of bytes written or error
16    fn write(&mut self, data: &[u8]) -> Result<usize, Self::Error>;
17
18    /// Read bytes from serial port (non-blocking)
19    ///
20    /// # Arguments
21    /// * `buffer` - Buffer to read into
22    ///
23    /// # Returns
24    /// Number of bytes read or error
25    fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Self::Error>;
26
27    /// Flush output buffer
28    ///
29    /// # Returns
30    /// Ok(()) or error
31    fn flush(&mut self) -> Result<(), Self::Error>;
32
33    /// Check if data is available to read
34    ///
35    /// # Returns
36    /// True if data is available
37    fn available(&self) -> Result<bool, Self::Error> {
38        // Default implementation - platforms can override
39        Ok(false)
40    }
41}