Skip to content

Commit b34b911

Browse files
committed
Fix 90 and 270 degree rotations
1 parent bef331c commit b34b911

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

src/command.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ impl Command {
6868
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)
72-
| (addr_inc_mode as u8),
71+
0x20 | ((vremap as u8) << 4
72+
| (hremap as u8) << 1
73+
| (cmode as u8) << 6
74+
| (addr_inc_mode as u8)),
7375
0,
7476
0,
7577
0,

src/mode/graphics.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,17 @@ where
8383
pub fn flush(&mut self) -> Result<(), ()> {
8484
// Ensure the display buffer is at the origin of the display before we send the full frame
8585
// to prevent accidental offsets
86-
let (display_width, display_height) = self.properties.get_dimensions();
87-
self.properties
88-
.set_draw_area((0, 0), (display_width, display_height))?;
86+
// let (display_width, display_height) = self.properties.get_dimensions();
87+
self.properties.set_draw_area((0, 0), (96, 64))?;
8988

9089
self.properties.draw(&self.buffer)
91-
// self.properties.draw(&[0xff; BUF_SIZE])
9290
}
9391

9492
/// Turn a pixel on or off. A non-zero `value` is treated as on, `0` as off. If the X and Y
9593
/// coordinates are out of the bounds of the display, this method call is a noop.
9694
pub fn set_pixel(&mut self, x: u32, y: u32, value: u16) {
97-
let (display_width, _) = self.properties.get_dimensions();
95+
let display_width = 96;
96+
let display_height = 64;
9897
let display_rotation = self.properties.get_rotation();
9998

10099
let idx = match display_rotation {
@@ -109,7 +108,7 @@ where
109108
if y >= display_width as u32 {
110109
return;
111110
}
112-
((x as usize) * display_width as usize) + (y as usize)
111+
((y as usize) * display_height as usize) + (x as usize)
113112
}
114113
} * 2;
115114

src/properties.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ where
2525
/// Initialise the display in column mode (i.e. a byte walks down a column of 8 pixels) with
2626
/// column 0 on the left and column _(display_width - 1)_ on the right.
2727
pub fn init_column_mode(&mut self) -> Result<(), ()> {
28-
let (_, display_height) = self.get_dimensions();
29-
3028
let display_rotation = self.display_rotation;
3129

3230
Command::DisplayOn(false).send(&mut self.iface)?;
3331
Command::DisplayClockDiv(0x8, 0x0).send(&mut self.iface)?;
34-
Command::Multiplex(display_height - 1).send(&mut self.iface)?;
32+
Command::Multiplex(64 - 1).send(&mut self.iface)?;
3533
Command::DisplayOffset(0).send(&mut self.iface)?;
3634
Command::StartLine(0).send(&mut self.iface)?;
3735

@@ -45,16 +43,6 @@ where
4543
Command::Invert(false).send(&mut self.iface)?;
4644
Command::DisplayOn(true).send(&mut self.iface)?;
4745

48-
// let cmds = [
49-
// 0xA0, 0x72, 0xA1, 0x0, 0xA2, 0x0, 0xA4, 0xA8, 0x3F, 0xAD, 0x8E, 0xB0, 0x0B, 0xB1, 0x31,
50-
// 0xB3, 0xF0, 0x8A, 0x64, 0x8B, 0x78, 0x8C, 0x64, 0xBB, 0x3A, 0xBE, 0x3E, 0x87, 0x06,
51-
// 0x81, 0x91, 0x82, 0x50, 0x83, 0x7D,
52-
// ];
53-
54-
// self.iface.send_commands(&cmds);
55-
56-
Command::DisplayOn(true).send(&mut self.iface)?;
57-
5846
Ok(())
5947
}
6048

@@ -133,7 +121,7 @@ where
133121
}
134122
DisplayRotation::Rotate90 => {
135123
Command::RemapAndColorDepth(
136-
false,
124+
true,
137125
false,
138126
ColorMode::CM65k,
139127
AddressIncrementMode::Vertical,
@@ -152,7 +140,7 @@ where
152140
DisplayRotation::Rotate270 => {
153141
Command::RemapAndColorDepth(
154142
false,
155-
false,
143+
true,
156144
ColorMode::CM65k,
157145
AddressIncrementMode::Vertical,
158146
)

0 commit comments

Comments
 (0)