-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from romixlab/master
Add DSI related traits and data structures.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters