-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
155 additions
and
163 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
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 |
---|---|---|
@@ -1,18 +1,72 @@ | ||
//! Display rotation | ||
|
||
// TODO: Add to prelude | ||
/// Display rotation. | ||
/// | ||
/// Note that 90º and 270º rotations are not supported by | ||
// [`TerminalMode`](../mode/terminal/struct.TerminalMode.html). | ||
#[derive(Clone, Copy)] | ||
pub enum DisplayRotation { | ||
/// No rotation, normal display | ||
Rotate0, | ||
/// Rotate by 90 degress clockwise | ||
Rotate90, | ||
/// Rotate by 180 degress clockwise | ||
Rotate180, | ||
/// Rotate 270 degress clockwise | ||
Rotate270, | ||
// These are not instantiated, so no need to implement Copy | ||
#![allow(missing_copy_implementations)] | ||
|
||
use crate::command::Command; | ||
use display_interface::{DisplayError, WriteOnlyDataCommand}; | ||
|
||
/// A valid display rotation value | ||
pub trait DisplayRotation { | ||
/// Send rotation related configuration | ||
fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError>; | ||
|
||
/// Flip coordinates if necessary | ||
fn transform(x: u8, y: u8) -> (u8, u8); | ||
} | ||
|
||
/// No rotation | ||
pub struct Rotate0; | ||
impl DisplayRotation for Rotate0 { | ||
fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> { | ||
Command::SegmentRemap(true).send(iface)?; | ||
Command::ReverseComDir(true).send(iface)?; | ||
Ok(()) | ||
} | ||
|
||
fn transform(x: u8, y: u8) -> (u8, u8) { | ||
(x, y) | ||
} | ||
} | ||
|
||
/// 90° CW rotation | ||
pub struct Rotate90; | ||
impl DisplayRotation for Rotate90 { | ||
fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> { | ||
Command::SegmentRemap(false).send(iface)?; | ||
Command::ReverseComDir(true).send(iface)?; | ||
Ok(()) | ||
} | ||
|
||
fn transform(x: u8, y: u8) -> (u8, u8) { | ||
(y, x) | ||
} | ||
} | ||
|
||
/// 180° rotation | ||
pub struct Rotate180; | ||
impl DisplayRotation for Rotate180 { | ||
fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> { | ||
Command::SegmentRemap(false).send(iface)?; | ||
Command::ReverseComDir(false).send(iface)?; | ||
Ok(()) | ||
} | ||
|
||
fn transform(x: u8, y: u8) -> (u8, u8) { | ||
(x, y) | ||
} | ||
} | ||
|
||
/// 270° CW rotation | ||
pub struct Rotate270; | ||
impl DisplayRotation for Rotate270 { | ||
fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> { | ||
Command::SegmentRemap(true).send(iface)?; | ||
Command::ReverseComDir(false).send(iface)?; | ||
Ok(()) | ||
} | ||
|
||
fn transform(x: u8, y: u8) -> (u8, u8) { | ||
(y, x) | ||
} | ||
} |
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
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
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
Oops, something went wrong.