Fix LCD1602 blank display: HD44780 timing, pinmap switch, contrast hint.

Match LiquidCrystal_I2C init delays; add Map button for alternate PCF8574 wiring; warn about blue contrast pot.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-23 14:30:21 +08:00
parent e3f4ea89ff
commit 8ad00d8718
6 changed files with 157 additions and 70 deletions

View File

@@ -14,16 +14,19 @@ static constexpr uint32_t COL_ON = 0x1B5E4A;
static constexpr uint32_t COL_ACCENT = 0x7CDBFF;
static constexpr uint32_t COL_DIM = 0x3A4656;
static constexpr uint32_t COL_ERR = 0xC62828;
static constexpr uint32_t COL_WARN = 0xFFB74D;
static lv_obj_t *lbl_title;
static lv_obj_t *lbl_pin;
static lv_obj_t *lbl_status;
static lv_obj_t *lbl_hint;
static lv_obj_t *lbl_line0;
static lv_obj_t *lbl_line1;
static lv_obj_t *btn_demo;
static lv_obj_t *lbl_demo;
static lv_obj_t *btn_hello;
static lv_obj_t *btn_clear;
static lv_obj_t *btn_map;
static lv_obj_t *lbl_map;
static lv_obj_t *btn_bl;
static lv_obj_t *lbl_bl;
@@ -72,7 +75,8 @@ void ui_refresh_lcd() {
if (lbl_status) {
if (lcd_ok()) {
lv_label_set_text_fmt(lbl_status, "OK addr 0x%02X", lcd_addr());
lv_label_set_text_fmt(lbl_status, "OK 0x%02X map%u", lcd_addr(),
(unsigned)lcd_pinmap());
lv_obj_set_style_text_color(lbl_status, lv_color_hex(COL_ON), 0);
} else {
lv_label_set_text(lbl_status, "FAIL no PCF8574");
@@ -91,6 +95,9 @@ void ui_refresh_lcd() {
(unsigned)(g_demo_idx % lcd_demo_count() + 1),
(unsigned)lcd_demo_count());
}
if (lbl_map) {
lv_label_set_text_fmt(lbl_map, "Map %u", (unsigned)lcd_pinmap());
}
}
static void on_demo(lv_event_t *e) {
@@ -112,11 +119,14 @@ static void on_hello(lv_event_t *e) {
ui_refresh_lcd();
}
static void on_clear(lv_event_t *e) {
static void on_map(lv_event_t *e) {
if (lv_event_get_code(e) != LV_EVENT_CLICKED) {
return;
}
lcd_clear();
lcd_set_pinmap((uint8_t)(lcd_pinmap() + 1));
lcd_set_backlight(true);
lcd_set_line(0, "Hello World!");
lcd_set_line(1, "try Map / pot");
ui_refresh_lcd();
}
@@ -137,48 +147,53 @@ void ui_create() {
lv_label_set_text(lbl_title, "LCD1602A");
lv_obj_set_style_text_color(lbl_title, lv_color_hex(COL_INK), 0);
lv_obj_set_style_text_font(lbl_title, &lv_font_montserrat_28, 0);
lv_obj_align(lbl_title, LV_ALIGN_TOP_MID, 0, 4);
lv_obj_align(lbl_title, LV_ALIGN_TOP_MID, 0, 2);
lbl_pin = lv_label_create(scr);
lv_label_set_text_fmt(lbl_pin, "I2C SDA%d SCL%d PCF8574", LCD_I2C_SDA_PIN,
LCD_I2C_SCL_PIN);
lv_obj_set_style_text_color(lbl_pin, lv_color_hex(COL_MUTED), 0);
lv_obj_set_style_text_font(lbl_pin, &lv_font_montserrat_14, 0);
lv_obj_align(lbl_pin, LV_ALIGN_TOP_MID, 0, 36);
lv_obj_align(lbl_pin, LV_ALIGN_TOP_MID, 0, 32);
lbl_status = lv_label_create(scr);
lv_label_set_text(lbl_status, "...");
lv_obj_set_style_text_font(lbl_status, &lv_font_montserrat_14, 0);
lv_obj_align(lbl_status, LV_ALIGN_TOP_MID, 0, 54);
lv_obj_align(lbl_status, LV_ALIGN_TOP_MID, 0, 50);
lbl_hint = lv_label_create(scr);
lv_label_set_text(lbl_hint, "Blank? turn BLUE pot on backpack");
lv_obj_set_style_text_color(lbl_hint, lv_color_hex(COL_WARN), 0);
lv_obj_set_style_text_font(lbl_hint, &lv_font_montserrat_14, 0);
lv_obj_align(lbl_hint, LV_ALIGN_TOP_MID, 0, 68);
lbl_line0 = lv_label_create(scr);
lv_label_set_text(lbl_line0, "[ ]");
lv_obj_set_style_text_color(lbl_line0, lv_color_hex(COL_ACCENT), 0);
lv_obj_set_style_text_font(lbl_line0, &lv_font_montserrat_18, 0);
lv_obj_align(lbl_line0, LV_ALIGN_TOP_MID, 0, 78);
lv_obj_align(lbl_line0, LV_ALIGN_TOP_MID, 0, 90);
lbl_line1 = lv_label_create(scr);
lv_label_set_text(lbl_line1, "[ ]");
lv_obj_set_style_text_color(lbl_line1, lv_color_hex(COL_ACCENT), 0);
lv_obj_set_style_text_font(lbl_line1, &lv_font_montserrat_18, 0);
lv_obj_align(lbl_line1, LV_ALIGN_TOP_MID, 0, 104);
lv_obj_align(lbl_line1, LV_ALIGN_TOP_MID, 0, 116);
const int16_t gap = 8;
const int16_t bw = (UI_HOR_RES - 48 - gap) / 2;
const int16_t bx0 = 24;
const int16_t row0 = 140;
const int16_t row1 = 188;
const int16_t row0 = 148;
const int16_t row1 = 196;
btn_demo = make_btn(scr, "Demo", bx0, row0, bw, 40, on_demo, &lbl_demo);
btn_hello = make_btn(scr, "Hello", bx0 + bw + gap, row0, bw, 40, on_hello,
nullptr);
btn_clear =
make_btn(scr, "Clear", bx0, row1, bw, 40, on_clear, nullptr);
btn_map = make_btn(scr, "Map 0", bx0, row1, bw, 40, on_map, &lbl_map);
btn_bl = make_btn(scr, "BL OFF", bx0 + bw + gap, row1, bw, 40, on_bl, &lbl_bl);
(void)btn_demo;
(void)btn_hello;
(void)btn_clear;
(void)btn_map;
ui_refresh_lcd();
}