summaryrefslogtreecommitdiff
path: root/src/esp32p4.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
committerGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
commit6d8da8721141284cf33bb901168b26135893eb86 (patch)
tree791d63401d4e85fbca1d597a8ce0326e70efd545 /src/esp32p4.zig
parentefd43a3a2cf03bb741366331158b368abf9ac583 (diff)
parentbf6810a8f9d6cc82050e7d9c0cfb06358301b574 (diff)
downloadpardes-6d8da8721141284cf33bb901168b26135893eb86.tar.gz
pardes-6d8da8721141284cf33bb901168b26135893eb86.zip
Merge latest upstream into the macOS branch for Zig 0.17
Retain the macOS branch history and local Acme selection color while adopting upstream's current core and platform changes. Pin Zig and ZLS to 0.17.0, and fetch the existing zstbi compatibility commit through upstream after its original fork was removed.
Diffstat (limited to 'src/esp32p4.zig')
-rw-r--r--src/esp32p4.zig86
1 files changed, 32 insertions, 54 deletions
diff --git a/src/esp32p4.zig b/src/esp32p4.zig
index 0d532e1e..683d19e1 100644
--- a/src/esp32p4.zig
+++ b/src/esp32p4.zig
@@ -32,6 +32,7 @@ const std = @import("std");
const builtin = @import("builtin");
const pardes = @import("pardes.zig");
const vaxis = @import("vaxis");
+const vaxis_input = @import("vaxis_input.zig");
// ------------------------------------------------------------------ what a freestanding root owes
//
@@ -133,19 +134,19 @@ pub const GpioFn = *const fn (ctx: ?*anyopaque, pin: u16, was: *u8, now: *u8) ca
var host_alloc: Allocator = undefined;
fn hostAlloc(_: *anyopaque, len: usize, alignment: std.mem.Alignment, _: usize) ?[*]u8 {
- return host_alloc.alloc(host_alloc.ctx, len, @intFromEnum(alignment));
+ return host_alloc.alloc(host_alloc.ctx, len, @backingInt(alignment));
}
fn hostResize(_: *anyopaque, mem: []u8, alignment: std.mem.Alignment, new_len: usize, _: usize) bool {
- return host_alloc.resize(host_alloc.ctx, mem.ptr, mem.len, @intFromEnum(alignment), new_len);
+ return host_alloc.resize(host_alloc.ctx, mem.ptr, mem.len, @backingInt(alignment), new_len);
}
fn hostRemap(_: *anyopaque, mem: []u8, alignment: std.mem.Alignment, new_len: usize, _: usize) ?[*]u8 {
- return if (host_alloc.resize(host_alloc.ctx, mem.ptr, mem.len, @intFromEnum(alignment), new_len)) mem.ptr else null;
+ return if (host_alloc.resize(host_alloc.ctx, mem.ptr, mem.len, @backingInt(alignment), new_len)) mem.ptr else null;
}
fn hostFree(_: *anyopaque, mem: []u8, alignment: std.mem.Alignment, _: usize) void {
- host_alloc.free(host_alloc.ctx, mem.ptr, mem.len, @intFromEnum(alignment));
+ host_alloc.free(host_alloc.ctx, mem.ptr, mem.len, @backingInt(alignment));
}
const host_vtable: std.mem.Allocator.VTable = .{
@@ -394,7 +395,7 @@ fn apply(c: *pardes.Pardes, ev: vaxis.Event) void {
// text at all, so a line break inside a paste arrives as a bare CR (Key.enter) or, from
// a terminal that does not translate them, as ctrl+j.
const text = key.text orelse "";
- const cp = mapKey(effCp(key));
+ const cp = vaxis_input.mapKey(vaxis_input.effCp(key));
const bytes: []const u8 = if (text.len > 0)
text
else if (cp == pardes.Key.tab)
@@ -406,7 +407,7 @@ fn apply(c: *pardes.Pardes, ev: vaxis.Event) void {
if (bytes.len > 0) paste_buf.appendSlice(gpa(), bytes) catch {};
} else {
c.update(.{ .key = .{
- .cp = mapKey(effCp(key)),
+ .cp = vaxis_input.mapKey(vaxis_input.effCp(key)),
.text = key.text orelse "",
.ctrl = key.mods.ctrl,
.alt = key.mods.alt,
@@ -446,18 +447,21 @@ fn apply(c: *pardes.Pardes, ev: vaxis.Event) void {
else => null,
};
if (button) |b| {
- c.update(.{ .mouse = .{
- .button = b,
- .kind = switch (m.type) {
- .press => .press,
- .release => .release,
- .motion => .motion,
- .drag => .drag,
+ c.update(.{
+ .mouse = .{
+ .button = b,
+ .kind = switch (m.type) {
+ .press => .press,
+ .release => .release,
+ .motion => .motion,
+ .drag => .drag,
+ },
+ // Before the first cell (a drag past the edge): the edge.
+ .col = @intCast(@max(0, m.col)),
+ .row = @intCast(@max(0, m.row)),
+ .ctrl = m.mods.ctrl,
},
- .col = @intCast(m.col),
- .row = @intCast(m.row),
- .ctrl = m.mods.ctrl,
- } });
+ });
dirty = true;
}
},
@@ -504,7 +508,7 @@ fn apply(c: *pardes.Pardes, ev: vaxis.Event) void {
c.update(.pointer_leave);
dirty = true;
},
- .focus_in, .mouse_leave => {},
+ .focus_in, .mouse_leave, .cursor_position => {},
// Capability replies. vaxis's own Loop sets these fields directly (`Loop.zig:377-403`);
// with no Loop, this is where they land. DA1 is the terminator: every terminal answers it
// last, so it is the signal that the whole handshake is in and the detected features can be
@@ -529,35 +533,6 @@ fn apply(c: *pardes.Pardes, ev: vaxis.Event) void {
}
}
-/// The effective codepoint the way vaxis's own `Key.matches` sees it: a single-character `text`
-/// wins, because the terminal has already resolved shift; otherwise the shifted codepoint.
-fn effCp(key: vaxis.Key) u21 {
- if (key.text) |t| {
- const view = std.unicode.Utf8View.init(t) catch return key.codepoint;
- var it = view.iterator();
- if (it.nextCodepoint()) |cp| {
- if (it.nextCodepoint() == null) return cp;
- }
- }
- return key.shifted_codepoint orelse key.codepoint;
-}
-
-/// vaxis functional-key codepoints -> core constants. The ASCII ones already coincide, so
-/// enter/tab/escape/backspace pass straight through.
-fn mapKey(cp: u21) u21 {
- return switch (cp) {
- vaxis.Key.up => pardes.Key.up,
- vaxis.Key.down => pardes.Key.down,
- vaxis.Key.left => pardes.Key.left,
- vaxis.Key.right => pardes.Key.right,
- vaxis.Key.home => pardes.Key.home,
- vaxis.Key.end => pardes.Key.end,
- vaxis.Key.page_up => pardes.Key.page_up,
- vaxis.Key.page_down => pardes.Key.page_down,
- vaxis.Key.delete => pardes.Key.delete,
- else => cp,
- };
-}
export fn pardes_esp32p4_tick(now_ms: u64) callconv(.c) void {
const c = core orelse return;
last_now_ms = now_ms;
@@ -572,10 +547,9 @@ export fn pardes_esp32p4_tick(now_ms: u64) callconv(.c) void {
dirty = true;
}
}
- if (c.animationActive()) {
- c.update(.tick);
- dirty = true;
- }
+ // The core steps its own animations by this clock (`Host.now`).
+ c.advance(now_ms * std.time.ns_per_ms);
+ if (c.needs_frame) dirty = true;
}
/// How long a lone ESC waits for a second byte before it counts as the Escape key.
@@ -590,7 +564,7 @@ var esc_held_at: ?u64 = null;
export fn pardes_esp32p4_wants_frame() callconv(.c) bool {
const c = core orelse return false;
- return dirty or c.animationActive();
+ return dirty or c.needs_frame;
}
export fn pardes_esp32p4_render() callconv(.c) u32 {
@@ -607,10 +581,14 @@ export fn pardes_esp32p4_quit() callconv(.c) bool {
// ------------------------------------------------------------------------------------ the host
-const pardes_host: pardes.Host.VTable = .{ .present = present, .gpio_toggle = gpioToggle };
+const pardes_host: pardes.Host.VTable = .{ .now = boardNow, .present = present, .gpio_toggle = gpioToggle };
+
+fn boardNow(_: ?*anyopaque) u64 {
+ return last_now_ms * std.time.ns_per_ms;
+}
/// The `Gpio` word's one seam to the board. Nothing here knows what a pad is; it forwards, and
-/// answers false when the firmware brought none, which is what puts "gpio: NoPads" on the message
+/// answers false when the firmware brought none, which is what puts "gpio: no pads" on the message
/// row rather than a trap.
fn gpioToggle(_: ?*anyopaque, pin: u16, was: *u8, now: *u8) bool {
const f = host_gpio orelse return false;