Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Run zig fmt
if: matrix.os == 'Linux'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
zig-out/**
zig-cache/**
.zig-cache/**
zig-pkg/**
6 changes: 3 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
.name = .drivercom,
.version = "0.5.6",
.fingerprint = 0xc1b53adfd36fc2f0,
.minimum_zig_version = "0.15.1",
.minimum_zig_version = "0.16.0",
.dependencies = .{
.mmc_api = .{
.url = "https://github.com/pmotionf/mmc-api/archive/a5ae477.tar.gz",
.hash = "mmc_api-0.0.0-P5raR6PqMQCNhJYdOKmP5vgSpJLyTbLIj2jvfAqWlh9A",
.url = "https://github.com/pmotionf/mmc-api/archive/0a212c9.tar.gz",
.hash = "mmc_api-0.0.0-P5raR6pjMgCpq795vTCW5EnQ4eIrbLpCvA8SRw_8GS9Z",
},
},
.paths = .{
Expand Down
4 changes: 4 additions & 0 deletions src/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,7 @@ test migrate {

try std.testing.expectEqualDeep(new, migrated);
}

test {
std.testing.refAllDecls(@This());
}
23 changes: 14 additions & 9 deletions src/Log.zig
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,16 @@ pub const Status = enum(u2) {
};

pub const Tag: type = b: {
var result: std.builtin.Type.Enum = .{
.tag_type = u5,
.fields = &.{},
.decls = &.{},
.is_exhaustive = true,
};
var tag_value: u5 = 0;
result.fields = result.fields ++ unwrapConfig(Config, &tag_value, "");
break :b @Type(.{ .@"enum" = result });
const tag_type = u5;
var tag_value: tag_type = 0;
const enum_fields = unwrapConfig(Config, &tag_value, "");
var field_names: [enum_fields.len][]const u8 = undefined;
var field_values: [enum_fields.len]tag_type = undefined;
for (enum_fields, 0..) |field, i| {
field_names[i] = field.name;
field_values[i] = field.value;
}
break :b @Enum(tag_type, .exhaustive, &field_names, &field_values);
};

pub const TagKind = enum {
Expand Down Expand Up @@ -507,3 +508,7 @@ fn unwrapConfig(
}
return result;
}

test {
std.testing.refAllDecls(@This());
}
5 changes: 2 additions & 3 deletions src/drivercom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ pub const DriverMessage = enum(u16) {
clear_carrier_info,
};

pub const CarrierState =
@Type(@typeInfo(@import("mmc_api").cclink.Wr.Carrier.State));
pub const CarrierState = @import("mmc_api").cclink.Wr.Carrier.State;

test {
std.testing.refAllDeclsRecursive(@This());
std.testing.refAllDecls(@This());
}
35 changes: 15 additions & 20 deletions src/message.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub const Message = packed struct {

log_start: void,
log_stop: void,
log_status: packed struct {
log_status: packed struct(u64) {
status: Log.Status,
_: u30 = 0,
cycles_completed: u32,
Expand Down Expand Up @@ -59,7 +59,7 @@ pub const Message = packed struct {
_: u10 = 0,
},
log_get_start: void,
log_set_start: packed struct {
log_set_start: packed struct(u64) {
carrier_1: u12,
kind: Log.Start,
_: u1 = 0,
Expand All @@ -77,7 +77,7 @@ pub const Message = packed struct {
hall_sensor_6: bool = false,
_2: u2 = 0,
},
log_get: packed struct {
log_get: packed struct(u64) {
cycle: u24,
data: Log.Tag,
id: u3,
Expand Down Expand Up @@ -191,32 +191,23 @@ pub const Message = packed struct {
};

pub const Kind = b: {
var result: std.builtin.Type.Enum = .{
.tag_type = u16,
.fields = &.{},
.decls = &.{},
.is_exhaustive = false,
};

const ti = @typeInfo(Payload).@"union";
var val: u16 = 1;
for (ti.fields) |field| {
const tag_type = u16;
var field_names: [ti.fields.len - 1][]const u8 = undefined;
var field_values: [ti.fields.len - 1]tag_type = undefined;
var val: tag_type = 1;
for (ti.fields, 0..) |field, i| {
if (std.mem.eql(u8, "u8", field.name)) continue;
if (std.mem.eql(u8, "config_get", field.name)) {
val = 0x10;
} else if (std.mem.eql(u8, "log_start", field.name)) {
val = 0x100;
}
result.fields = result.fields ++ .{
std.builtin.Type.EnumField{
.name = field.name,
.value = val,
},
};
field_names[i] = field.name;
field_values[i] = val;
val += 1;
}

break :b @Type(.{ .@"enum" = result });
break :b @Enum(tag_type, .nonexhaustive, &field_names, &field_values);
};

pub fn PayloadType(comptime kind: Kind) type {
Expand Down Expand Up @@ -286,3 +277,7 @@ comptime {
// const field_ti = @typeInfo(field.type);
}
}

test {
std.testing.refAllDecls(@This());
}
Loading