Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DSI related traits and data structures. #1

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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