Skip to content

Commit c414d92

Browse files
committed
wip: use ag-lcd
1 parent 1f4cfe8 commit c414d92

File tree

4 files changed

+172
-66
lines changed

4 files changed

+172
-66
lines changed

Cargo.lock

Lines changed: 34 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ rand_core = { version = "0.6.4", features = ["getrandom"] }
4848

4949
mfrc522-01 = { version = "0.1.1", package = "esp-hal-mfrc522", optional = true }
5050
mfrc522-02 = { version = "0.2.1", features = ["embassy-time"], package = "esp-hal-mfrc522", optional = true }
51+
ag-lcd = "0.3.0"
5152

5253
[features]
5354
default = ["esp32c3"]

src/lcd.rs

Lines changed: 136 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,24 @@ pub async fn lcd_task(
3030
wifi_setup_sig: Rc<Signal<NoopRawMutex, ()>>,
3131
) {
3232
#[cfg(feature = "esp32c3")]
33-
let mut bl_pin = lcd_shifter.get_pin_mut(1, true);
34-
35-
#[cfg(feature = "esp32c3")]
36-
let mut options = {
37-
let reg_sel_pin = lcd_shifter.get_pin_mut(2, true);
38-
let e_pin = lcd_shifter.get_pin_mut(3, true);
39-
let d4_pin = lcd_shifter.get_pin_mut(7, false);
40-
let d5_pin = lcd_shifter.get_pin_mut(6, false);
41-
let d6_pin = lcd_shifter.get_pin_mut(5, false);
42-
let d7_pin = lcd_shifter.get_pin_mut(4, false);
43-
44-
hd44780_driver::setup::DisplayOptions4Bit::new(MemoryMap1602::new())
45-
.with_pins(hd44780_driver::bus::FourBitBusPins {
46-
rs: reg_sel_pin,
47-
en: e_pin,
48-
d4: d4_pin,
49-
d5: d5_pin,
50-
d6: d6_pin,
51-
d7: d7_pin,
52-
})
53-
.with_charset(CharsetA02::QUESTION_FALLBACK)
54-
};
33+
let bl_pin = lcd_shifter.get_pin_mut(1, true);
34+
35+
let rs_pin = lcd_shifter.get_pin_mut(2, true);
36+
let en_pin = lcd_shifter.get_pin_mut(3, true);
37+
let d4_pin = lcd_shifter.get_pin_mut(7, false);
38+
let d5_pin = lcd_shifter.get_pin_mut(6, false);
39+
let d6_pin = lcd_shifter.get_pin_mut(5, false);
40+
let d7_pin = lcd_shifter.get_pin_mut(4, false);
41+
let mut lcd: ag_lcd::LcdDisplay<_, _> = ag_lcd::LcdDisplay::new(rs_pin, en_pin, Delay)
42+
.with_half_bus(d4_pin, d5_pin, d6_pin, d7_pin)
43+
.with_display(ag_lcd::Display::On)
44+
.with_blink(ag_lcd::Blink::Off)
45+
.with_cursor(ag_lcd::Cursor::Off)
46+
.with_size(ag_lcd::Size::Dots5x8)
47+
.with_backlight(bl_pin)
48+
.with_cols(16)
49+
.with_lines(ag_lcd::Lines::TwoLines)
50+
.build();
5551

5652
#[cfg(feature = "esp32")]
5753
let mut options = {
@@ -60,40 +56,86 @@ pub async fn lcd_task(
6056
.with_charset(CharsetA02::QUESTION_FALLBACK)
6157
};
6258

63-
let mut delay = Delay;
59+
lcd.clear();
60+
//lcd.backlight_on();
6461

65-
let mut lcd = loop {
66-
match HD44780::new(options, &mut delay) {
67-
Err((opt, e)) => {
68-
log::error!("Error creating CLD driver: {e:?}");
69-
options = opt;
70-
Timer::after_millis(1000).await;
71-
}
72-
Ok(lcd) => break lcd,
73-
}
74-
};
62+
lcd.set_character(
63+
2,
64+
[
65+
0b10010, 0b10000, 0b10010, 0b01000, 0b01111, 0b01000, 0b00001, 0b00011,
66+
],
67+
);
68+
lcd.set_character(
69+
3,
70+
[
71+
0b11011, 0b11011, 0b11011, 0b11011, 0b11011, 0b00000, 0b00000, 0b00000,
72+
],
73+
);
74+
lcd.set_character(
75+
1,
76+
[
77+
0b10101, 0b01010, 0b10101, 0b01010, 0b00100, 0b00111, 0b00111, 0b11100,
78+
],
79+
);
80+
lcd.set_character(
81+
0,
82+
[
83+
0b00001, 0b00010, 0b00100, 0b01100, 0b10010, 0b11001, 0b00010, 0b00100,
84+
],
85+
);
7586

76-
#[cfg(feature = "esp32c3")]
77-
{
78-
_ = bl_pin.set_high();
79-
}
87+
lcd.set_position(0, 0);
88+
lcd.write(0);
8089

81-
#[cfg(feature = "esp32")]
82-
{
83-
_ = lcd.set_backlight(true, &mut delay);
84-
}
90+
lcd.set_position(0, 1);
91+
lcd.write(1);
8592

86-
_ = lcd.clear(&mut delay);
87-
_ = lcd.reset(&mut delay);
88-
_ = lcd.set_display_mode(
89-
DisplayMode {
90-
display: hd44780_driver::Display::On,
91-
cursor_visibility: hd44780_driver::Cursor::Invisible,
92-
cursor_blink: hd44780_driver::CursorBlink::Off,
93-
},
94-
&mut delay,
93+
lcd.set_position(1, 0);
94+
lcd.write(2);
95+
96+
lcd.set_position(1, 1);
97+
lcd.write(3);
98+
99+
Timer::after_millis(1000).await;
100+
lcd.clear();
101+
lcd.set_character(
102+
0,
103+
[
104+
0b00000, 0b00000, 0b01100, 0b01100, 0b01001, 0b00011, 0b00011, 0b00111,
105+
],
95106
);
96-
_ = lcd.clear(&mut delay);
107+
lcd.set_character(
108+
1,
109+
[
110+
0b00000, 0b00000, 0b00110, 0b00110, 0b10010, 0b11000, 0b11000, 0b11100,
111+
],
112+
);
113+
lcd.set_character(
114+
2,
115+
[
116+
0b00111, 0b00011, 0b00011, 0b01001, 0b01100, 0b01100, 0b00000, 0b00000,
117+
],
118+
);
119+
lcd.set_character(
120+
3,
121+
[
122+
0b11100, 0b11000, 0b11000, 0b10010, 0b00110, 0b00110, 0b00000, 0b00000,
123+
],
124+
);
125+
126+
lcd.set_position(0, 0);
127+
lcd.write(0);
128+
129+
lcd.set_position(0, 1);
130+
lcd.write(2);
131+
132+
lcd.set_position(1, 0);
133+
lcd.write(1);
134+
135+
lcd.set_position(1, 1);
136+
lcd.write(3);
137+
138+
/*
97139
let mut lcd_driver: LcdAbstract<80, 16, 2, 3> = LcdAbstract::new();
98140
99141
_ = lcd_driver.print(
@@ -118,8 +160,49 @@ pub async fn lcd_task(
118160
);
119161
_ = lcd_driver.display_on_lcd(&mut lcd, &mut delay);
120162
163+
_ = lcd.clear(&mut delay);
164+
_ = lcd.define_custom_character(
165+
0,
166+
&hd44780_driver::character::CharacterDefinition {
167+
pattern: [
168+
0b00001, 0b00010, 0b00000, 0b00100, 0b00100, 0b00100, 0b11111, 0b11111, 0, 0,
169+
],
170+
cursor: 8,
171+
},
172+
&mut delay,
173+
);
174+
_ = lcd.set_cursor_xy((0, 0), &mut delay);
175+
_ = lcd.write_byte(0, &mut delay);
176+
177+
_ = lcd.define_custom_character(
178+
1,
179+
&hd44780_driver::character::CharacterDefinition {
180+
pattern: [
181+
0b11111, 0b00001, 0b01001, 0b01001, 0b01001, 0b01000, 0b01110, 0b00000, 0, 0,
182+
],
183+
cursor: 8,
184+
},
185+
&mut delay,
186+
);
187+
_ = lcd.set_cursor_xy((0, 1), &mut delay);
188+
_ = lcd.write_byte(1, &mut delay);
189+
190+
_ = lcd.define_custom_character(
191+
2,
192+
&hd44780_driver::character::CharacterDefinition {
193+
pattern: [
194+
0b10010, 0b10000, 0b10010, 0b01000, 0b01111, 0b01000, 0b00001, 0b00011, 0, 0,
195+
],
196+
cursor: 8,
197+
},
198+
&mut delay,
199+
);
200+
_ = lcd.set_cursor_xy((1, 1), &mut delay);
201+
_ = lcd.write_byte(2, &mut delay);
202+
121203
#[cfg(not(feature = "bat_dev_lcd"))]
122-
Timer::after_millis(2500).await;
204+
//Timer::after_millis(2500).await;
205+
Timer::after_millis(25000).await;
123206
124207
_ = lcd_driver.clear_all();
125208
let mut last_update;
@@ -174,6 +257,7 @@ pub async fn lcd_task(
174257
}
175258
}
176259
}
260+
*/
177261
}
178262

179263
#[cfg(feature = "esp32")]

src/utils/buttons.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl ButtonsHandler {
8080
if sleep_state() {
8181
let mut rtc = state.rtc.lock().await;
8282

83-
let timer = TimerWakeupSource::new(core::time::Duration::from_millis(25));
83+
let timer = TimerWakeupSource::new(core::time::Duration::from_millis(100));
8484
rtc.sleep_light(&[&timer]);
8585
}
8686

0 commit comments

Comments
 (0)