Skip to content

Commit

Permalink
Merge pull request #1 from romixlab/master
Browse files Browse the repository at this point in the history
Add DSI related traits and data structures.
  • Loading branch information
richardeoin authored Jan 17, 2024
2 parents f0e9ad9 + e468dab commit 256921b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/dsi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
pub trait DsiHostCtrlIo {
type Error;

fn write(&mut self, command: DsiWriteCommand) -> Result<(), Self::Error>;
fn read(&mut self, command: DsiReadCommand, buf: &mut [u8]) -> Result<(), Self::Error>;
}

#[repr(u8)]
#[derive(Debug)]
pub enum DsiReadCommand {
DcsShort { arg: u8 } = 0x06,

// xx x101 0-7 arguments
GenericShortP0 = 0x04,
GenericShortP1 { arg0: u8 } = 0x14,
GenericShortP2 { arg0: u8, arg1: u8 } = 0x24,
}

impl DsiReadCommand {
pub fn discriminant(&self) -> u8 {
// SAFETY: Because `Self` is marked `repr(u8)`, its layout is a `repr(C)` `union`
// between `repr(C)` structs, each of which has the `u8` discriminant as its first
// field, so we can read the discriminant without offsetting the pointer.
unsafe { *<*const _>::from(self).cast::<u8>() }
}
}

#[repr(u8)]
#[derive(Debug)]
pub enum DsiWriteCommand<'i> {
DcsShortP0 { arg: u8 } = 0x5,
DcsShortP1 { arg: u8, data: u8 } = 0x15,
DcsLongWrite { arg: u8, data: &'i [u8] } = 0x39,

GenericShortP0 = 0x03,
GenericShortP1 = 0x13,
GenericShortP2 = 0x23,
GenericLongWrite { arg: u8, data: &'i [u8] } = 0x29,

SetMaximumReturnPacketSize(u16) = 0x37,
}

impl<'i> DsiWriteCommand<'i> {
pub fn discriminant(&self) -> u8 {
// SAFETY: Because `Self` is marked `repr(u8)`, its layout is a `repr(C)` `union`
// between `repr(C)` structs, each of which has the `u8` discriminant as its first
// field, so we can read the discriminant without offsetting the pointer.
unsafe { *<*const _>::from(self).cast::<u8>() }
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
//! conditions.
#![no_std]

pub mod dsi;

/// A word type for the display memory buffer
pub trait PixelWord: Copy {}
impl PixelWord for u8 {}
Expand Down

0 comments on commit 256921b

Please sign in to comment.