소스 검색

Hide the S1D13700 cursor, sharpen text, add DRM backlight

A memory write turns the controller's cursor on regardless of the DISP ON
attributes, leaving a block at the last write position on the panel. Re-send
DISP ON after any update that wrote VRAM while the display is on, model the
behaviour in the simulator and test it.

Draw text without antialiasing, since gray edges smear at 2 bpp, and use
Verdana and Andale Mono with Liberation fallbacks. Give the log 10 px lines
for Polish accents, 7 rows.

Register a radio-backlight device in the DRM driver for the P1.0 pin,
driven from the flush worker.

Update the report and README after the first runs on the real panel,
including the test rig and ways to simulate keys.
k4be 2 주 전
부모
커밋
de2d6bf0a3
7개의 변경된 파일과 149개의 추가작업 그리고 10개의 파일을 삭제
  1. 39 4
      README.md
  2. 20 3
      driver/s1d13700_core.c
  3. 1 0
      driver/s1d13700_core.h
  4. 76 3
      driver/s1d13700_drm.c
  5. 4 0
      sim/s1d13700_sim.c
  6. 1 0
      sim/s1d13700_sim.h
  7. 8 0
      tests/test_panel.c

+ 39 - 4
README.md

@@ -1,7 +1,8 @@
 # Linux port
 
 Replaces the LPC1114 firmware: the panel and keys hang off I²C expanders on the
-Linux board. Nothing here has run on real hardware yet.
+Linux board. The panel runs on real hardware through `radio-i2c`; the DRM
+driver, keys and overlay have not run yet.
 
 | Path | What |
 |---|---|
@@ -39,6 +40,42 @@ Real panel through i2c-dev, for bring-up or on a kernel too old for the driver:
 `--bus` must name a known adapter; motherboard and display buses are always
 refused. Only use the bus number of the adapter the panel is wired to.
 
+Text uses Verdana and Andale Mono (Microsoft core fonts) if installed, otherwise
+Liberation Sans and Mono, drawn without antialiasing.
+
+### Test rig on the development PC
+
+The panel hangs off an ATmega8U2 i2c-tiny-usb bridge. Load the driver for
+400 kHz (its default, `delay=10`, is only 50 kHz), then find the bus number:
+
+    sudo modprobe -r i2c_tiny_usb; sudo modprobe i2c_tiny_usb delay=1
+    grep -l i2c-tiny-usb /sys/bus/i2c/devices/i2c-*/name
+
+To try the keys without touching the real player, run the fake MPD and point
+the panel at it:
+
+    tests/fake_mpd.py 6601 build/mpd-commands.log 5 &
+    build/radio-i2c --bus 11 --host localhost --port 6601
+
+Never scan or use the other buses on this PC: some reach the CPU regulators.
+
+### Simulating keys
+
+The panel frontends read keys from evdev only: the device named `radio-keys`,
+or whatever `--input` names. On the PC without the U2 keypad:
+
+- **PC keyboard:** `--input /dev/input/by-id/<keyboard>-event-kbd` (needs read
+  access, group `input`). Arrows and Esc map directly; the media keys of a
+  multimedia keyboard map to Prev/Next/Stop if they send `KEY_PREVIOUSSONG`,
+  `KEY_NEXTSONG`, `KEY_STOPCD`. Play, Pause, OK, Menu and List have no
+  ordinary key. The keyboard keeps typing into the focused window too.
+- **Virtual device:** with `CONFIG_INPUT_UINPUT`, create a device named
+  `radio-keys` (for example `evemu-device` or python-evdev's `UInput`) and send
+  the codes in `app/platform_linux.c`. `radio-i2c` finds it without `--input`.
+  The development kernel has uinput disabled.
+- **Window:** `build/radio-gtk` has every key as a button and shortcut, but
+  draws on the simulated panel only.
+
 ## Wiring
 
 **U1, TCA9539 at 0x74** (A1=L, A0=L), raw I²C client of the panel code
@@ -72,7 +109,5 @@ internal ones). `INT` goes to a host GPIO with a pull-up.
 
 ## To confirm on hardware
 
-- The TCA9539 stays in the register pair across a long write (the whole stream depends on it)
-- Panel size: 240×160 is assumed; `--pattern geometry` shows the real one
 - TC/R (`--tcr`) for frame rate; 162 comes from the AVR project's 2 bpp setup
-- Pixel polarity (white = level 0 here)
+- The DRM driver, keys (`evtest`) and the overlay

+ 20 - 3
driver/s1d13700_core.c

@@ -12,6 +12,9 @@
 /* Bytes one LCD write can need: A0 settle pair + WR low pair + WR high pair */
 #define MAX_WRITE_BYTES		6u
 
+/* DISP ON/OFF attributes: SAD1 on, other blocks and the cursor off */
+#define DISP_ATTR		0x04
+
 /* ---- Transport --------------------------------------------------------- */
 
 static void tx_reset(struct s1d_panel *p)
@@ -266,19 +269,22 @@ int s1d_panel_init(struct s1d_panel *p)
 	clear_vram(p);
 
 	cmd(p, S1D_CMD_DISP_ON);
-	param(p, 0x04);				/* SAD1 on, others and cursor off */
+	param(p, DISP_ATTR);
 
 	tx_flush(p);
-	if (!p->err)
+	if (!p->err) {
 		p->force_full = false;
+		p->display_on = true;
+	}
 	return take_error(p);
 }
 
 int s1d_panel_display(struct s1d_panel *p, bool on)
 {
 	cmd(p, on ? S1D_CMD_DISP_ON : S1D_CMD_DISP_OFF);
-	param(p, 0x04);
+	param(p, DISP_ATTR);
 	tx_flush(p);
+	p->display_on = on;
 	return take_error(p);
 }
 
@@ -415,6 +421,7 @@ int s1d_panel_update(struct s1d_panel *p, const uint8_t *next,
 		     unsigned int y0, unsigned int y1)
 {
 	bool full = p->force_full;
+	unsigned long writes = p->stats.writes;
 	unsigned int y;
 
 	if (full) {
@@ -441,6 +448,16 @@ int s1d_panel_update(struct s1d_panel *p, const uint8_t *next,
 		y = band_end;
 	}
 
+	/*
+	 * A memory write turns the cursor on even when the attributes say off
+	 * (HW Functional Spec, REG[0Ah] note), leaving a block at the last
+	 * write position. Re-sending the attributes hides it again.
+	 */
+	if (p->stats.writes != writes && p->display_on) {
+		cmd(p, S1D_CMD_DISP_ON);
+		param(p, DISP_ATTR);
+	}
+
 	tx_flush(p);
 	if (full && !p->err)
 		p->force_full = false;

+ 1 - 0
driver/s1d13700_core.h

@@ -111,6 +111,7 @@ struct s1d_panel {
 	uint8_t p1_sent;	/* last control byte the expander acknowledged */
 	bool vertical;		/* cursor direction currently programmed */
 	bool backlight;		/* S1D_P1_BL level to keep driving */
+	bool display_on;	/* DISP ON sent; re-sent after writes, see update */
 	bool force_full;	/* shadow cannot be trusted: rewrite everything */
 	int err;		/* first transport error of the current operation */
 

+ 76 - 3
driver/s1d13700_drm.c

@@ -13,6 +13,7 @@
  *
  * Needs a recent kernel (written against 6.18).
  */
+#include <linux/backlight.h>
 #include <linux/debugfs.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
@@ -86,9 +87,10 @@ struct s1d_device {
 
 	struct delayed_work flush_work;
 
-	struct mutex lock;	/* protects pending_frame, dirty_y0, dirty_y1 */
+	struct mutex lock;	/* protects pending_frame, dirty_*, bl_on */
 	u8 *pending_frame;
 	unsigned int dirty_y0, dirty_y1;
+	bool bl_on;		/* requested; the worker drives the pin */
 };
 
 static struct s1d_device *to_s1d(struct drm_device *drm)
@@ -125,9 +127,11 @@ static void s1d_flush_work(struct work_struct *work)
 	struct s1d_device *s = container_of(to_delayed_work(work), struct s1d_device,
 					    flush_work);
 	unsigned int stride = s->panel.stride, y0, y1;
+	bool bl_on;
 	int idx, ret;
 
 	mutex_lock(&s->lock);
+	bl_on = s->bl_on;
 	y0 = s->dirty_y0;
 	y1 = s->dirty_y1;
 	s->dirty_y0 = s->cfg.height;
@@ -137,11 +141,20 @@ static void s1d_flush_work(struct work_struct *work)
 		       (y1 - y0) * stride);
 	mutex_unlock(&s->lock);
 
-	if (y1 <= y0)
-		return;
 	if (!drm_dev_enter(&s->drm, &idx))
 		return;
 
+	/* before the first init this only records the level for init */
+	if (bl_on != s->panel.backlight) {
+		ret = s1d_panel_backlight(&s->panel, bl_on);
+		if (ret)
+			drm_err_ratelimited(&s->drm, "backlight failed: %d\n", ret);
+	}
+	if (y1 <= y0) {
+		drm_dev_exit(idx);
+		return;
+	}
+
 	ret = s->panel_ready ? 0 : s1d_panel_init(&s->panel);
 	if (!ret) {
 		s->panel_ready = true;
@@ -275,6 +288,11 @@ static void s1d_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_stat
 	if (s->panel_ready && !s1d_panel_display(&s->panel, true))
 		goto out;
 
+	/* init drives the backlight pin too, so give it the current request */
+	mutex_lock(&s->lock);
+	s->panel.backlight = s->bl_on;
+	mutex_unlock(&s->lock);
+
 	/* VRAM is cleared by init, so the shadow and work frame start at zero */
 	ret = s1d_panel_init(&s->panel);
 	if (ret)
@@ -418,6 +436,57 @@ static int s1d_kms_init(struct s1d_device *s)
 	return 0;
 }
 
+/* ---- backlight ---------------------------------------------------------- */
+
+/* The panel belongs to the worker, so only record the request and kick it */
+static int s1d_bl_update(struct backlight_device *bd)
+{
+	struct s1d_device *s = bl_get_data(bd);
+
+	mutex_lock(&s->lock);
+	s->bl_on = backlight_get_brightness(bd) > 0;
+	mutex_unlock(&s->lock);
+	mod_delayed_work(system_long_wq, &s->flush_work, 0);
+	return 0;
+}
+
+static const struct backlight_ops s1d_bl_ops = {
+	.options = BL_CORE_SUSPENDRESUME,
+	.update_status = s1d_bl_update,
+};
+
+static void s1d_cancel_work(void *data)
+{
+	struct s1d_device *s = data;
+
+	cancel_delayed_work_sync(&s->flush_work);
+}
+
+static int s1d_backlight_init(struct s1d_device *s)
+{
+	const struct backlight_properties props = {
+		.type = BACKLIGHT_RAW,
+		.max_brightness = 1,
+		.brightness = 1,
+	};
+	struct backlight_device *bd;
+	int ret;
+
+	/*
+	 * devm undoes in reverse: this runs after the backlight is gone, so a
+	 * brightness write during unbind cannot leave work behind.
+	 */
+	ret = devm_add_action_or_reset(&s->client->dev, s1d_cancel_work, s);
+	if (ret)
+		return ret;
+
+	s->bl_on = true;
+	/* the name the frontends look for by default */
+	bd = devm_backlight_device_register(&s->client->dev, "radio-backlight",
+					    &s->client->dev, s, &s1d_bl_ops, &props);
+	return PTR_ERR_OR_ZERO(bd);
+}
+
 static void s1d_debugfs_init(struct s1d_device *s)
 {
 	struct dentry *d = s->client->debugfs;
@@ -488,6 +557,10 @@ static int s1d_probe(struct i2c_client *client)
 	if (ret)
 		return dev_err_probe(dev, ret, "KMS init failed\n");
 
+	ret = s1d_backlight_init(s);
+	if (ret)
+		return dev_err_probe(dev, ret, "backlight registration failed\n");
+
 	i2c_set_clientdata(client, s);
 
 	ret = drm_dev_register(&s->drm, 0);

+ 4 - 0
sim/s1d13700_sim.c

@@ -96,6 +96,7 @@ static void latch_data(struct s1d_sim *s, uint8_t d)
 
 	if (s->cmd == S1D_CMD_MWRITE) {
 		s->vram[s->cursor & 0x7fff] = d;
+		s->cursor_on = true;
 		s->cursor = (unsigned int)((int)s->cursor + s->step) & 0xffff;
 		return;
 	}
@@ -125,9 +126,12 @@ static void latch_data(struct s1d_sim *s, uint8_t d)
 	case S1D_CMD_DISP_ON:
 		s->display_on = true;
 		s->disp_flags = s->params[0];
+		s->cursor_on = s->params[0] & 3;
 		break;
 	case S1D_CMD_DISP_OFF:
 		s->display_on = false;
+		s->disp_flags = s->params[0];
+		s->cursor_on = s->params[0] & 3;
 		break;
 	default:
 		break;

+ 1 - 0
sim/s1d13700_sim.h

@@ -40,6 +40,7 @@ struct s1d_sim {
 	bool configured;
 	bool display_on;
 	uint8_t disp_flags;
+	bool cursor_on;			/* memory writes force it on (REG[0Ah] note) */
 
 	struct s1d_sim_faults faults;
 	unsigned long latches;

+ 8 - 0
tests/test_panel.c

@@ -206,6 +206,7 @@ static void test_random_updates(unsigned int bpp, size_t tx_cap)
 					frame[yy * r.panel.stride + xx] = solid ? v : rand();
 		}
 		CHECK(s1d_panel_update(&r.panel, frame, 0, H) == 0);
+		CHECK(!r.sim.cursor_on);
 		if (!vram_matches(&r, frame)) {
 			printf("FAIL random bpp=%u round=%u\n", bpp, round);
 			failures++;
@@ -352,6 +353,13 @@ static void test_sim_render(void)
 	CHECK(!s1d_sim_render(&r.sim, 320, H, levels));
 	CHECK(s1d_panel_display(&r.panel, false) == 0);
 	CHECK(!s1d_sim_render(&r.sim, W, H, levels));
+
+	/* an update while blanked must not switch the display back on */
+	frame[1] = 0x1b;
+	CHECK(s1d_panel_update(&r.panel, frame, 0, H) == 0);
+	CHECK(!r.sim.display_on);
+	CHECK(s1d_panel_display(&r.panel, true) == 0);
+	CHECK(r.sim.display_on && !r.sim.cursor_on);
 }
 
 /* The fault detector itself must fire, or a clean result proves nothing. */