1use crate::models::Model;
4
5mod orientation;
6pub(crate) use orientation::MemoryMapping;
7pub use orientation::{InvalidAngleError, Orientation, Rotation};
8
9#[derive(Clone)]
12#[non_exhaustive]
13pub struct ModelOptions {
14 pub color_order: ColorOrder,
16 pub orientation: Orientation,
18 pub invert_colors: ColorInversion,
20 pub refresh_order: RefreshOrder,
22 pub display_size: (u16, u16),
24 pub display_offset: (u16, u16),
26}
27
28impl ModelOptions {
29 pub fn full_size<M: Model>() -> Self {
31 Self {
32 color_order: ColorOrder::default(),
33 orientation: Orientation::default(),
34 invert_colors: ColorInversion::default(),
35 refresh_order: RefreshOrder::default(),
36 display_size: M::FRAMEBUFFER_SIZE,
37 display_offset: (0, 0),
38 }
39 }
40
41 pub fn with_all(display_size: (u16, u16), display_offset: (u16, u16)) -> Self {
43 Self {
44 color_order: ColorOrder::default(),
45 orientation: Orientation::default(),
46 invert_colors: ColorInversion::default(),
47 refresh_order: RefreshOrder::default(),
48 display_size,
49 display_offset,
50 }
51 }
52
53 #[allow(dead_code)]
57 pub(crate) fn display_size(&self) -> (u16, u16) {
58 if self.orientation.rotation.is_horizontal() {
59 self.display_size
60 } else {
61 (self.display_size.1, self.display_size.0)
62 }
63 }
64}
65
66#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
68#[cfg_attr(feature = "defmt", derive(defmt::Format))]
69pub enum ColorInversion {
70 #[default]
72 Normal,
73 Inverted,
75}
76
77#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
79#[cfg_attr(feature = "defmt", derive(defmt::Format))]
80pub enum VerticalRefreshOrder {
81 #[default]
83 TopToBottom,
84 BottomToTop,
86}
87
88impl VerticalRefreshOrder {
89 #[must_use]
91 pub const fn flip(self) -> Self {
92 match self {
93 Self::TopToBottom => Self::BottomToTop,
94 Self::BottomToTop => Self::TopToBottom,
95 }
96 }
97}
98
99#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
101#[cfg_attr(feature = "defmt", derive(defmt::Format))]
102pub enum HorizontalRefreshOrder {
103 #[default]
105 LeftToRight,
106 RightToLeft,
108}
109
110impl HorizontalRefreshOrder {
111 #[must_use]
113 pub const fn flip(self) -> Self {
114 match self {
115 Self::LeftToRight => Self::RightToLeft,
116 Self::RightToLeft => Self::LeftToRight,
117 }
118 }
119}
120
121#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
125#[cfg_attr(feature = "defmt", derive(defmt::Format))]
126pub struct RefreshOrder {
127 pub vertical: VerticalRefreshOrder,
129 pub horizontal: HorizontalRefreshOrder,
131}
132
133impl RefreshOrder {
134 pub const fn new(vertical: VerticalRefreshOrder, horizontal: HorizontalRefreshOrder) -> Self {
136 Self {
137 vertical,
138 horizontal,
139 }
140 }
141
142 #[must_use]
144 pub const fn flip_vertical(self) -> Self {
145 Self {
146 vertical: self.vertical.flip(),
147 ..self
148 }
149 }
150
151 #[must_use]
153 pub const fn flip_horizontal(self) -> Self {
154 Self {
155 horizontal: self.horizontal.flip(),
156 ..self
157 }
158 }
159}
160
161#[derive(Copy, Clone, Debug, PartialEq, Eq)]
163#[cfg_attr(feature = "defmt", derive(defmt::Format))]
164pub enum TearingEffect {
165 Off,
167 Vertical,
169 HorizontalAndVertical,
171}
172
173#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
175#[cfg_attr(feature = "defmt", derive(defmt::Format))]
176pub enum ColorOrder {
177 #[default]
179 Rgb,
180 Bgr,
182}