Skip to content

Commit f48e67c

Browse files
committed
Add support for 180deg rotation (flip)
1 parent 3d43fb7 commit f48e67c

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

src/command.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub enum Command {
2525
RowAddress(u8, u8),
2626
/// Set display start line from 0-63
2727
StartLine(u8),
28-
/// Set horizontal or vertical direction swap and color mode
29-
RemapAndColorDepth(bool, bool, ColorMode),
28+
/// Set horizontal or vertical direction swap, color format/depth and address increment mode
29+
RemapAndColorDepth(bool, bool, ColorMode, AddressIncrementMode),
3030
/// Set multipex ratio from 15-63 (MUX-1)
3131
Multiplex(u8),
3232
/// Scan from COM[n-1] to COM0 (where N is mux ratio)
@@ -65,10 +65,11 @@ impl Command {
6565
Command::ColumnAddress(start, end) => ([0x15, start, end, 0, 0, 0, 0], 3),
6666
Command::RowAddress(start, end) => ([0x75, start, end, 0, 0, 0, 0], 3),
6767
Command::StartLine(line) => ([0xA1 | (0x3F & line), 0, 0, 0, 0, 0, 0], 1),
68-
Command::RemapAndColorDepth(hremap, vremap, cmode) => (
68+
Command::RemapAndColorDepth(hremap, vremap, cmode, addr_inc_mode) => (
6969
[
7070
0xA0,
71-
0x20 | ((vremap as u8) << 4 | (hremap as u8) << 1 | (cmode as u8) << 6),
71+
0x20 | ((vremap as u8) << 4 | (hremap as u8) << 1 | (cmode as u8) << 6)
72+
| (addr_inc_mode as u8),
7273
0,
7374
0,
7475
0,
@@ -178,3 +179,14 @@ pub enum ColorMode {
178179
/// 65k colors per pixel
179180
CM65k = 0x01,
180181
}
182+
183+
/// Address increment mode
184+
#[derive(Debug, Clone, Copy)]
185+
#[allow(dead_code)]
186+
pub enum AddressIncrementMode {
187+
/// Horizontal address increment
188+
Horizontal = 0x00,
189+
190+
/// Vertical address increment
191+
Vertical = 0x01,
192+
}

src/properties.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Container to store and set display properties
22
3-
use crate::command::{ColorMode, Command, VcomhLevel};
3+
use crate::command::{AddressIncrementMode, ColorMode, Command, VcomhLevel};
44
use crate::displayrotation::DisplayRotation;
55
use crate::interface::DisplayInterface;
66

@@ -123,20 +123,40 @@ where
123123

124124
match display_rotation {
125125
DisplayRotation::Rotate0 => {
126-
Command::RemapAndColorDepth(false, false, ColorMode::CM65k)
127-
.send(&mut self.iface)?;
126+
Command::RemapAndColorDepth(
127+
false,
128+
false,
129+
ColorMode::CM65k,
130+
AddressIncrementMode::Horizontal,
131+
)
132+
.send(&mut self.iface)?;
128133
}
129134
DisplayRotation::Rotate90 => {
130-
Command::RemapAndColorDepth(false, false, ColorMode::CM65k)
131-
.send(&mut self.iface)?;
135+
Command::RemapAndColorDepth(
136+
false,
137+
false,
138+
ColorMode::CM65k,
139+
AddressIncrementMode::Vertical,
140+
)
141+
.send(&mut self.iface)?;
132142
}
133143
DisplayRotation::Rotate180 => {
134-
Command::RemapAndColorDepth(false, false, ColorMode::CM65k)
135-
.send(&mut self.iface)?;
144+
Command::RemapAndColorDepth(
145+
true,
146+
true,
147+
ColorMode::CM65k,
148+
AddressIncrementMode::Horizontal,
149+
)
150+
.send(&mut self.iface)?;
136151
}
137152
DisplayRotation::Rotate270 => {
138-
Command::RemapAndColorDepth(false, false, ColorMode::CM65k)
139-
.send(&mut self.iface)?;
153+
Command::RemapAndColorDepth(
154+
false,
155+
false,
156+
ColorMode::CM65k,
157+
AddressIncrementMode::Vertical,
158+
)
159+
.send(&mut self.iface)?;
140160
}
141161
};
142162

0 commit comments

Comments
 (0)