Skip to content

Commit 0d9dc8f

Browse files
committed
B1Display: Cleanup
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent c968f3f commit 0d9dc8f

File tree

4 files changed

+86
-56
lines changed

4 files changed

+86
-56
lines changed

b1display/src/main.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use cortex_m::delay::Delay;
99
use defmt_rtt as _;
1010
use embedded_hal::digital::v2::{InputPin, OutputPin};
1111

12-
use rp2040_hal::gpio::bank0::Gpio18;
1312
use rp2040_hal::gpio::{Output, Pin, PushPull};
1413
//#[cfg(debug_assertions)]
1514
//use panic_probe as _;
@@ -19,7 +18,7 @@ use embedded_graphics::pixelcolor::Rgb565;
1918
use embedded_graphics::prelude::*;
2019
use embedded_graphics::primitives::*;
2120
use embedded_hal::blocking::spi;
22-
use st7306_lcd::{Orientation, ST7306};
21+
use st7306_lcd::ST7306;
2322

2423
// Provide an alias for our BSP so we can switch targets quickly.
2524
// Uncomment the BSP you included in Cargo.toml, the rest of the code does not need to change.
@@ -29,9 +28,8 @@ use lotus_inputmodules::lotus_lcd_hal as bsp;
2928

3029
use bsp::hal::{
3130
clocks::{init_clocks_and_plls, Clock},
32-
pac,
31+
gpio, pac,
3332
sio::Sio,
34-
gpio,
3533
usb,
3634
watchdog::Watchdog,
3735
Timer,
@@ -151,30 +149,35 @@ fn main() -> ! {
151149
Pin<gpio::bank0::Gpio21, Output<PushPull>>,
152150
25,
153151
200,
154-
> = ST7306::new(spi, dc, cs, rst, false, 300, 460);
152+
> = ST7306::new(spi, dc, cs, rst, false, 300, 400);
155153
disp.init(&mut delay).unwrap();
156154

157-
disp.clear(Rgb565::BLACK).unwrap();
155+
// TODO: Seems broken
156+
//disp.clear(Rgb565::WHITE).unwrap();
157+
Rectangle::new(Point::new(0, 0), Size::new(300, 400))
158+
.into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
159+
.draw(&mut disp)
160+
.unwrap();
158161

159162
let logo_rect = draw_logo(&mut disp).unwrap();
160163
Rectangle::new(Point::new(10, 10), Size::new(10, 10))
161-
.into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
164+
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
162165
.draw(&mut disp)
163166
.unwrap();
164167
Rectangle::new(Point::new(20, 20), Size::new(10, 10))
165-
.into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
168+
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
166169
.draw(&mut disp)
167170
.unwrap();
168171
Rectangle::new(Point::new(30, 30), Size::new(10, 10))
169-
.into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
172+
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
170173
.draw(&mut disp)
171174
.unwrap();
172175
Rectangle::new(Point::new(40, 40), Size::new(10, 10))
173-
.into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
176+
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
174177
.draw(&mut disp)
175178
.unwrap();
176179
Rectangle::new(Point::new(50, 50), Size::new(10, 10))
177-
.into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
180+
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
178181
.draw(&mut disp)
179182
.unwrap();
180183
draw_text(
@@ -235,11 +238,11 @@ fn main() -> ! {
235238
Ok(count) => {
236239
if let Some(command) = parse_command(count, &buf) {
237240
if let Command::Sleep(go_sleeping) = command {
238-
handle_sleep(host_sleeping, &mut state, &mut delay, &mut disp);
241+
handle_sleep(go_sleeping, &mut state, &mut delay, &mut disp);
239242
} else if let SleepState::Awake = state.sleeping {
240243
// While sleeping no command is handled, except waking up
241244
//handle_command(&command, &mut disp, logo_rect);
242-
if let Some(response) = handle_command(&command, &mut disp, logo_rect) {
245+
if let Some(response) = handle_command(&command, logo_rect, &mut disp) {
243246
let _ = serial.write(&response);
244247
};
245248
}
@@ -266,10 +269,9 @@ fn handle_sleep<SPI, DC, CS, RST, const COLS: usize, const ROWS: usize>(
266269
(SleepState::Awake, false) => (),
267270
(SleepState::Awake, true) => {
268271
state.sleeping = SleepState::Sleeping;
269-
//state.grid = display_sleep();
270272

271-
// Turn off backlight
272-
disp.on_off(false);
273+
// Turn off display
274+
disp.on_off(false).unwrap();
273275

274276
// TODO: Power Display controller down
275277

@@ -281,8 +283,10 @@ fn handle_sleep<SPI, DC, CS, RST, const COLS: usize, const ROWS: usize>(
281283
// Restore back grid before sleeping
282284
state.sleeping = SleepState::Awake;
283285

286+
// Turn display back on
287+
disp.on_off(true).unwrap();
288+
284289
// TODO: Power display controller back on
285-
disp.on_off(true);
286290
}
287291
}
288292
}

control.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ def main():
105105
help="Get device version", action="store_true")
106106
parser.add_argument("--serial-dev", help="Change the serial dev. Probably /dev/ttyACM0 on Linux, COM0 on Windows",
107107
default='/dev/ttyACM0')
108+
109+
parser.add_argument(
110+
"--disp-str", help="Display a string on the LCD Display", type=str)
111+
parser.add_argument("--display-on", help="Control display power",
112+
action=argparse.BooleanOptionalAction)
113+
parser.add_argument("--invert-screen", help="Invert display",
114+
action=argparse.BooleanOptionalAction)
115+
108116
args = parser.parse_args()
109117

110118
if args.serial_dev is not None:
@@ -179,6 +187,12 @@ def main():
179187
show_string(args.string)
180188
elif args.symbols is not None:
181189
show_symbols(args.symbols)
190+
elif args.disp_str is not None:
191+
display_string(args.disp_str)
192+
elif args.display_on is not None:
193+
display_on_cmd(args.display_on)
194+
elif args.invert_screen is not None:
195+
invert_screen_cmd(args.invert_screen)
182196
elif args.version:
183197
version = get_version()
184198
print(f"Device version: {version}")
@@ -922,6 +936,23 @@ def gui():
922936

923937
window.close()
924938

939+
940+
def display_string(disp_str):
941+
b = [ord(x) for x in disp_str]
942+
command = FWK_MAGIC + [0x09, len(disp_str)] + b
943+
send_command(command)
944+
945+
946+
def display_on_cmd(on):
947+
command = FWK_MAGIC + [0x014, int(on)]
948+
send_command(command)
949+
950+
951+
def invert_screen_cmd(invert):
952+
command = FWK_MAGIC + [0x015, int(invert)]
953+
send_command(command)
954+
955+
925956
# 5x6 symbol font. Leaves 2 pixels on each side empty
926957
# We can leave one row empty below and then the display fits 5 of these digits.
927958

lotus-inputmodules/src/control.rs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
use rp2040_hal::rom_data::reset_to_usb_boot;
22

3+
use crate::serialnum::{device_release, is_pre_release};
4+
35
#[cfg(feature = "b1display")]
46
use crate::graphics::*;
57
#[cfg(feature = "b1display")]
68
use core::fmt::{Debug, Write};
79
#[cfg(feature = "b1display")]
810
use embedded_graphics::{
911
pixelcolor::Rgb565,
10-
prelude::{DrawTarget, Point, RgbColor},
12+
prelude::{Point, RgbColor},
1113
primitives::Rectangle,
1214
};
1315
#[cfg(feature = "b1display")]
16+
use embedded_hal::blocking::spi;
17+
#[cfg(feature = "b1display")]
18+
use embedded_hal::digital::v2::OutputPin;
19+
#[cfg(feature = "b1display")]
1420
use heapless::String;
15-
use rp2040_hal::{
16-
gpio::{bank0::*, Output, Pin, PushPull},
17-
pac::SPI0,
18-
spi::Enabled,
19-
usb::UsbBus,
20-
Spi,
21-
};
21+
#[cfg(feature = "b1display")]
2222
use st7306_lcd::{instruction::Instruction, ST7306};
23-
use tinybmp::Bmp;
24-
use usbd_serial::SerialPort;
2523

2624
#[cfg(feature = "ledmatrix")]
2725
use crate::games::pong;
@@ -31,14 +29,10 @@ use crate::games::snake;
3129
use crate::matrix::*;
3230
#[cfg(feature = "ledmatrix")]
3331
use crate::patterns::*;
34-
use crate::serialnum::{device_release, is_pre_release};
3532

3633
#[cfg(feature = "c1minimal")]
3734
use smart_leds::{SmartLedsWrite, RGB8};
3835

39-
const WIDTH: usize = 300;
40-
const HEIGHT: usize = 400;
41-
4236
pub enum _CommandVals {
4337
_Brightness = 0x00,
4438
_Pattern = 0x01,
@@ -408,10 +402,17 @@ pub fn handle_command(
408402
}
409403

410404
#[cfg(feature = "b1display")]
411-
pub fn handle_command<D>(command: &Command, disp: &mut D, logo_rect: Rectangle) -> Option<[u8; 32]>
405+
pub fn handle_command<SPI, DC, CS, RST, const COLS: usize, const ROWS: usize>(
406+
command: &Command,
407+
logo_rect: Rectangle,
408+
disp: &mut ST7306<SPI, DC, CS, RST, COLS, ROWS>,
409+
) -> Option<[u8; 32]>
412410
where
413-
D: DrawTarget<Color = Rgb565>,
414-
<D as DrawTarget>::Error: Debug,
411+
SPI: spi::Write<u8>,
412+
DC: OutputPin,
413+
CS: OutputPin,
414+
RST: OutputPin,
415+
<SPI as spi::Write<u8>>::Error: Debug,
415416
{
416417
match command {
417418
Command::BootloaderReset => {
@@ -428,7 +429,7 @@ where
428429
clear_text(
429430
disp,
430431
Point::new(LOGO_OFFSET_X, LOGO_OFFSET_Y + logo_rect.size.height as i32),
431-
Rgb565::WHITE
432+
Rgb565::WHITE,
432433
)
433434
.unwrap();
434435

@@ -440,25 +441,19 @@ where
440441
.unwrap();
441442
None
442443
}
443-
//Command::DisplayOn(on) => {
444-
// disp.on_off(*on);
445-
// None
446-
// //if *on {
447-
// // disp.write_command(Instruction::DISPON, &[]).unwrap();
448-
// //} else {
449-
// // disp.write_command(Instruction::DISPOFF, &[]).unwrap();
450-
// //}
451-
//}
452-
//Command::InvertScreen(invert) => {
453-
// if *invert {
454-
// //let _ = serial.write("INVON\n\r".as_bytes());
455-
// disp.write_command(Instruction::INVON, &[]).unwrap();
456-
// } else {
457-
// //let _ = serial.write("INVOFF\n\r".as_bytes());
458-
// disp.write_command(Instruction::INVOFF, &[]).unwrap();
459-
// }
460-
//}
461-
_ => return handle_generic_command(command),
444+
Command::DisplayOn(on) => {
445+
disp.on_off(*on).unwrap();
446+
None
447+
}
448+
Command::InvertScreen(invert) => {
449+
if *invert {
450+
disp.write_command(Instruction::INVON, &[]).unwrap();
451+
} else {
452+
disp.write_command(Instruction::INVOFF, &[]).unwrap();
453+
}
454+
None
455+
}
456+
_ => handle_generic_command(command),
462457
}
463458
}
464459

lotus-inputmodules/src/graphics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ where
3232
D: DrawTarget<Color = Rgb565>,
3333
{
3434
let text = Text::new(
35-
&target_text,
35+
target_text,
3636
Point::new(30, 30) + offset,
37-
MonoTextStyle::new(&FONT_9X15, Rgb565::WHITE),
37+
MonoTextStyle::new(&FONT_9X15, Rgb565::BLACK),
3838
);
3939

4040
text.draw(target)?;

0 commit comments

Comments
 (0)