mini_oled/interface/mod.rs
1//! # Communication Interface
2//!
3//! This module defines the `CommunicationInterface` trait and provides implementations for I2C and ~~SPI~~ (planned).
4//! It abstracts the underlying hardware communication details.
5//!
6//! ## Example
7//!
8//! Creating an I2C interface.
9//!
10//! ```rust,ignore
11//! use mini_oled::interface::i2c::I2cInterface;
12//!
13//! // let i2c = ...; // Your embedded-hal I2C driver
14//! let interface = I2cInterface::new(i2c, 0x3C);
15//! ```
16
17use crate::{command::CommandBuffer, error::MiniOledError};
18
19pub mod i2c;
20pub mod spi;
21
22/// Trait representing the communication interface with the display.
23///
24/// This trait is implemented by `I2cInterface` and `SPIInterface`.
25pub trait CommunicationInterface {
26 /// Initialize the communication device.
27 ///
28 /// # Returns
29 ///
30 /// `Ok(())` on success, or a `MiniOledError` on failure.
31 fn init(&mut self) -> Result<(), MiniOledError>;
32
33 /// Send a command buffer to the device.
34 ///
35 /// # Arguments
36 ///
37 /// * `buf` - The command buffer to send.
38 ///
39 /// # Returns
40 ///
41 /// `Ok(())` on success, or a `MiniOledError` on failure.
42 fn write_command<const N: usize>(
43 &mut self,
44 buf: &CommandBuffer<N>,
45 ) -> Result<(), MiniOledError>;
46
47 /// Send data to the device.
48 ///
49 /// # Arguments
50 ///
51 /// * `buf` - The data buffer to send.
52 ///
53 /// # Returns
54 ///
55 /// `Ok(())` on success, or a `MiniOledError` on failure.
56 fn write_data(&mut self, buf: &[u8]) -> Result<(), MiniOledError>;
57}