Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Jun 16, 2020
1 parent 7529a8c commit 93b15fc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/graphics_i2c_128x32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn main() -> ! {

let interface = I2CDIBuilder::new().init(i2c);
let mut disp: GraphicsMode<_, _> = Builder::new()
.size::<DisplaySize128x32>()
.size(DisplaySize128x32)
.connect(interface)
.into();
disp.init().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/graphics_i2c_72x40.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn main() -> ! {

let interface = I2CDIBuilder::new().init(i2c);
let mut disp: GraphicsMode<_, _> = Builder::new()
.size::<DisplaySize72x40>()
.size(DisplaySize72x40)
.connect(interface)
.into();
disp.init().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//! let interface = I2CDIBuilder::new().init(i2c);
//! Builder::new()
//! .with_rotation(DisplayRotation::Rotate180)
//! .size::<DisplaySize128x32>()
//! .size(DisplaySize128x32)
//! .connect(interface);
//! ```
//!
Expand Down Expand Up @@ -66,8 +66,8 @@ pub struct Builder<DSIZE = DisplaySize128x64>
where
DSIZE: DisplaySize,
{
size: DSIZE,
rotation: DisplayRotation,
_size: core::marker::PhantomData<DSIZE>,
}

impl Default for Builder {
Expand All @@ -80,8 +80,8 @@ impl Builder {
/// Create new builder with a default size of 128 x 64 pixels and no rotation.
pub fn new() -> Self {
Self {
size: DisplaySize128x64,
rotation: DisplayRotation::Rotate0,
_size: core::marker::PhantomData,
}
}
}
Expand All @@ -91,10 +91,10 @@ where
DSIZE: DisplaySize,
{
/// Set the size of the display. Supported sizes are defined by [DisplaySize].
pub fn size<SIZE: DisplaySize>(self) -> Builder<SIZE> {
pub fn size<S: DisplaySize>(self, size: S) -> Builder<S, DROTATION> {
Builder {
size,
rotation: self.rotation,
_size: core::marker::PhantomData,
}
}

Expand All @@ -112,7 +112,7 @@ where
where
I: WriteOnlyDataCommand,
{
DisplayProperties::new(interface, self.rotation)
DisplayProperties::new(interface, self.size, self.rotation)
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/displaysize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub trait DisplaySize {
///
/// See [`Command::ComPinConfig`](../command/enum.Command.html#variant.ComPinConfig)
/// for more information
fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError>;
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError>;
}

/// Size information for the common 128x64 variants
Expand All @@ -43,7 +43,7 @@ impl DisplaySize for DisplaySize128x64 {
const HEIGHT: u8 = 64;
type BufferSize = U1024;

fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(true, false).send(iface)
}
}
Expand All @@ -55,7 +55,7 @@ impl DisplaySize for DisplaySize128x32 {
const HEIGHT: u8 = 32;
type BufferSize = U512;

fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(false, false).send(iface)
}
}
Expand All @@ -67,7 +67,7 @@ impl DisplaySize for DisplaySize96x16 {
const HEIGHT: u8 = 16;
type BufferSize = U192;

fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(false, false).send(iface)
}
}
Expand All @@ -81,7 +81,7 @@ impl DisplaySize for DisplaySize72x40 {
const OFFSETY: u8 = 0;
type BufferSize = U360;

fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(true, false).send(iface)
}
}
Expand All @@ -95,7 +95,7 @@ impl DisplaySize for DisplaySize64x48 {
const OFFSETY: u8 = 0;
type BufferSize = U384;

fn configure(iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(true, false).send(iface)
}
}
13 changes: 8 additions & 5 deletions src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ pub struct DisplayProperties<DI, DSIZE = DisplaySize128x64> {
iface: DI,
display_rotation: DisplayRotation,
addr_mode: AddrMode,
_size: core::marker::PhantomData<DSIZE>,
size: DSIZE,
}

impl<DI, DSIZE> DisplayProperties<DI, DSIZE>
where
DSIZE: DisplaySize,
{
/// Create new DisplayProperties instance
pub fn new(iface: DI, display_rotation: DisplayRotation) -> DisplayProperties<DI, DSIZE> {
pub fn new(
iface: DI,
size: DSIZE,
rotation: DisplayRotation,
) -> DisplayProperties<DI, DSIZE> {
DisplayProperties {
iface,
display_rotation,
addr_mode: AddrMode::Page, // reset value
_size: core::marker::PhantomData,
size,
}
}
}
Expand Down Expand Up @@ -62,10 +66,9 @@ where
Command::ChargePump(true).send(&mut self.iface)?;
Command::AddressMode(mode).send(&mut self.iface)?;

self.size.configure(&mut self.iface)?;
self.set_rotation(display_rotation)?;

DSIZE::configure(&mut self.iface)?;

self.set_brightness(Brightness::default())?;
Command::VcomhDeselect(VcomhLevel::Auto).send(&mut self.iface)?;
Command::AllOn(false).send(&mut self.iface)?;
Expand Down

0 comments on commit 93b15fc

Please sign in to comment.