diff options
Diffstat (limited to 'src/esp32p4_gpio.zig')
| -rw-r--r-- | src/esp32p4_gpio.zig | 54 |
1 files changed, 8 insertions, 46 deletions
diff --git a/src/esp32p4_gpio.zig b/src/esp32p4_gpio.zig index 92468581..d6c29a36 100644 --- a/src/esp32p4_gpio.zig +++ b/src/esp32p4_gpio.zig @@ -1,5 +1,6 @@ //! ESP32-P4 JP1 GPIO data and its freestanding filesystem. const std = @import("std"); +const ninep = @import("9p.zig"); // JP1: JC-ESP32P4-M3-DEV schematic, sheet 2 "Expand IO": // 01-esp32p4-m3/docs/schematics/2_EXPAND_IO&BAT.png @@ -107,11 +108,7 @@ pub const Header = struct { } }; -pub const E = struct { - pub const NOENT: u16 = 2; - pub const NOTDIR: u16 = 20; - pub const INVAL: u16 = 22; -}; +pub const E = ninep.fs.E; pub const root: u64 = 1; const gpio_node: u64 = 16; @@ -167,43 +164,10 @@ const out_capacity = size: { pub fn Fs(comptime Pads: type) type { return struct { const Self = @This(); - pub const name_capacity = 28; - - pub const Op = enum(u8) { lookup, getattr, setattr, open, read, write, release, readdir }; - - pub const Status = enum(u8) { ok, again, err }; - - pub const Req = struct { - tag: u64, - op: Op, - node: u64, - handle: u32 = 0, - off: u64 = 0, - size: u32 = 0, - data: []const u8 = &.{}, - truncate: bool = false, - }; - - pub const Reply = struct { - tag: u64, - status: Status = .ok, - errno: u16 = 0, - attr: Attr = .{}, - handle: u32 = 0, - written: u32 = 0, - - pub const Attr = struct { - name: []const u8 = "", - node: u64 = 0, - dir: bool = false, - size: u64 = 0, - mode: u16 = 0o600, - }; - - pub fn fail(tag: u64, e: u16) Reply { - return .{ .tag = tag, .status = .err, .errno = e }; - } - }; + pub const Op = ninep.fs.Op; + pub const Status = ninep.fs.Status; + pub const Req = ninep.fs.Req; + pub const Reply = ninep.fs.Reply; // Reply bytes are borrowed until the next handle call. pub const Answer = struct { reply: Reply, bytes: []const u8 = "" }; @@ -484,7 +448,7 @@ fn names(t: *Board, node: u64, skip: u64) ![][]const u8 { test "GPIO: the whole tree costs one buffer, and the table says how big" { try testing.expectEqual(@as(usize, 143), out_capacity); try testing.expectEqual(@as(usize, 143), @sizeOf(Board)); - try testing.expectEqual(@as(usize, 28), Board.name_capacity); + try testing.expectEqual(@as(usize, 28), ninep.board.name_capacity); try testing.expect(Header.text.len > out_capacity); } @@ -511,11 +475,9 @@ test "GPIO: stat and truncation preserve the register value and reads respect of try testing.expectEqualStrings(Header.text[10..22], text.bytes); } -const ninep = @import("9p.zig"); - test "GPIO: a real 9P client reads a pin's value off this tree" { StubPads.reset(); - const Server = ninep.Server(Board, ninep.board_fids); + const Server = ninep.Server(Board, ninep.board); var in: [1024]u8 = undefined; var out: [2048]u8 = undefined; var fsys: Board = .{}; |
