Skip to content

Commit

Permalink
Make DCS command constructors const.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdolgov committed Jan 19, 2024
1 parent 9fbaca7 commit 7baca43
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions mipidsi/src/dcs/set_address_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ pub struct SetAddressMode(u8);

impl SetAddressMode {
/// Creates a new Set Address Mode command.
pub fn new(
pub const fn new(
color_order: ColorOrder,
orientation: Orientation,
refresh_order: RefreshOrder,
) -> Self {
Self::default()
Self(0)
.with_color_order(color_order)
.with_orientation(orientation)
.with_refresh_order(refresh_order)
}

/// Returns this Madctl with [ColorOrder] set to new value
#[must_use]
pub fn with_color_order(self, color_order: ColorOrder) -> Self {
pub const fn with_color_order(self, color_order: ColorOrder) -> Self {
let mut result = self;
match color_order {
ColorOrder::Rgb => result.0 &= 0b1111_0111,
Expand All @@ -38,7 +38,7 @@ impl SetAddressMode {

/// Returns this Madctl with [Orientation] set to new value
#[must_use]
pub fn with_orientation(self, orientation: Orientation) -> Self {
pub const fn with_orientation(self, orientation: Orientation) -> Self {
let mut result = self;
let value = match orientation {
Orientation::Portrait(false) => 0b0000_0000,
Expand All @@ -57,7 +57,7 @@ impl SetAddressMode {

/// Returns this Madctl with [RefreshOrder] set to new value
#[must_use]
pub fn with_refresh_order(self, refresh_order: RefreshOrder) -> Self {
pub const fn with_refresh_order(self, refresh_order: RefreshOrder) -> Self {
let mut result = self;
let value = match (refresh_order.vertical, refresh_order.horizontal) {
(VerticalRefreshOrder::TopToBottom, HorizontalRefreshOrder::LeftToRight) => 0b0000_0000,
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/dcs/set_column_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct SetColumnAddress {

impl SetColumnAddress {
/// Creates a new Set Column Address command.
pub fn new(start_column: u16, end_column: u16) -> Self {
pub const fn new(start_column: u16, end_column: u16) -> Self {
Self {
start_column,
end_column,
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/dcs/set_page_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct SetPageAddress {

impl SetPageAddress {
/// Creates a new Set Page Address command.
pub fn new(start_row: u16, end_row: u16) -> Self {
pub const fn new(start_row: u16, end_row: u16) -> Self {
Self { start_row, end_row }
}
}
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/dcs/set_pixel_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct SetPixelFormat(PixelFormat);

impl SetPixelFormat {
/// Creates a new Set Pixel Format command.
pub fn new(pixel_format: PixelFormat) -> Self {
pub const fn new(pixel_format: PixelFormat) -> Self {
Self(pixel_format)
}
}
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/dcs/set_scroll_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl SetScrollArea {
/// Creates a new Set Scroll Area command.
///
/// VSA should default to the display's height (or width) framebuffer size.
pub fn new(tfa: u16, vsa: u16, bfa: u16) -> Self {
pub const fn new(tfa: u16, vsa: u16, bfa: u16) -> Self {
Self { tfa, vsa, bfa }
}
}
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/dcs/set_scroll_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct SetScrollStart(u16);

impl SetScrollStart {
/// Creates a new Set Scroll Start command.
pub fn new(offset: u16) -> Self {
pub const fn new(offset: u16) -> Self {
Self(offset)
}
}
Expand Down

0 comments on commit 7baca43

Please sign in to comment.