From a49fad973077dffd5fa0b392720295ad033f076e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Quei=C3=9Fner?= Date: Sun, 25 Jun 2023 20:03:59 +0200 Subject: [PATCH] Runs zig fmt (#133) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Felix "xq" Queißner --- src/core/experimental/gpio.zig | 2 +- src/core/usb.zig | 14 +++++------ src/core/usb/hid.zig | 46 +++++++++++++++++----------------- src/modules/cpus/cortex-m.zig | 6 ++--- src/modules/cpus/riscv32.zig | 4 +-- src/start.zig | 4 +-- test/programs/uart-sync.zig | 6 ++--- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/core/experimental/gpio.zig b/src/core/experimental/gpio.zig index e7ec33ae..bddaf109 100644 --- a/src/core/experimental/gpio.zig +++ b/src/core/experimental/gpio.zig @@ -16,7 +16,7 @@ pub const State = enum(u1) { high = 1, pub fn value(self: State) u1 { - return @enumToInt(self); + return @intFromEnum(self); } }; diff --git a/src/core/usb.zig b/src/core/usb.zig index 7e2d1835..7c6d24b3 100644 --- a/src/core/usb.zig +++ b/src/core/usb.zig @@ -502,11 +502,11 @@ pub const Dir = enum(u8) { In = 0x80, pub inline fn endpoint(self: @This(), num: u8) u8 { - return num | @enumToInt(self); + return num | @intFromEnum(self); } pub inline fn of_endpoint_addr(addr: u8) @This() { - return if (addr & @enumToInt(@This().In) != 0) @This().In else @This().Out; + return if (addr & @intFromEnum(@This().In) != 0) @This().In else @This().Out; } }; @@ -531,7 +531,7 @@ pub const EndpointDescriptor = packed struct { pub fn serialize(self: *const @This()) [7]u8 { var out: [7]u8 = undefined; out[0] = 7; // length - out[1] = @enumToInt(self.descriptor_type); + out[1] = @intFromEnum(self.descriptor_type); out[2] = self.endpoint_address; out[3] = self.attributes; out[4] = @intCast(u8, self.max_packet_size & 0xff); @@ -567,7 +567,7 @@ pub const InterfaceDescriptor = packed struct { pub fn serialize(self: *const @This()) [9]u8 { var out: [9]u8 = undefined; out[0] = 9; // length - out[1] = @enumToInt(self.descriptor_type); + out[1] = @intFromEnum(self.descriptor_type); out[2] = self.interface_number; out[3] = self.alternate_setting; out[4] = self.num_endpoints; @@ -611,7 +611,7 @@ pub const ConfigurationDescriptor = packed struct { pub fn serialize(self: *const @This()) [9]u8 { var out: [9]u8 = undefined; out[0] = 9; // length - out[1] = @enumToInt(self.descriptor_type); + out[1] = @intFromEnum(self.descriptor_type); out[2] = @intCast(u8, self.total_length & 0xff); out[3] = @intCast(u8, (self.total_length >> 8) & 0xff); out[4] = self.num_interfaces; @@ -659,7 +659,7 @@ pub const DeviceDescriptor = packed struct { pub fn serialize(self: *const @This()) [18]u8 { var out: [18]u8 = undefined; out[0] = 18; // length - out[1] = @enumToInt(self.descriptor_type); + out[1] = @intFromEnum(self.descriptor_type); out[2] = @intCast(u8, self.bcd_usb & 0xff); out[3] = @intCast(u8, (self.bcd_usb >> 8) & 0xff); out[4] = self.device_class; @@ -706,7 +706,7 @@ pub const DeviceQualifierDescriptor = packed struct { pub fn serialize(self: *const @This()) [10]u8 { var out: [10]u8 = undefined; out[0] = 10; // length - out[1] = @enumToInt(self.descriptor_type); + out[1] = @intFromEnum(self.descriptor_type); out[2] = @intCast(u8, self.bcd_usb & 0xff); out[3] = @intCast(u8, (self.bcd_usb >> 8) & 0xff); out[4] = self.device_class; diff --git a/src/core/usb/hid.zig b/src/core/usb/hid.zig index 4993f6ca..758e1c18 100644 --- a/src/core/usb/hid.zig +++ b/src/core/usb/hid.zig @@ -104,12 +104,12 @@ pub const HidDescriptor = packed struct { pub fn serialize(self: *const @This()) [9]u8 { var out: [9]u8 = undefined; out[0] = 9; // length - out[1] = @enumToInt(self.descriptor_type); + out[1] = @intFromEnum(self.descriptor_type); out[2] = @intCast(u8, self.bcd_hid & 0xff); out[3] = @intCast(u8, (self.bcd_hid >> 8) & 0xff); out[4] = self.country_code; out[5] = self.num_descriptors; - out[6] = @enumToInt(self.report_type); + out[6] = @intFromEnum(self.report_type); out[7] = @intCast(u8, self.report_length & 0xff); out[8] = @intCast(u8, (self.report_length >> 8) & 0xff); return out; @@ -313,17 +313,17 @@ pub fn hid_report_item( pub fn hid_collection(data: CollectionItem) [2]u8 { return hid_report_item( 1, - @enumToInt(ReportItemTypes.Main), - @enumToInt(ReportItemMainGroup.Collection), - std.mem.toBytes(@enumToInt(data)), + @intFromEnum(ReportItemTypes.Main), + @intFromEnum(ReportItemMainGroup.Collection), + std.mem.toBytes(@intFromEnum(data)), ); } pub fn hid_input(data: u8) [2]u8 { return hid_report_item( 1, - @enumToInt(ReportItemTypes.Main), - @enumToInt(ReportItemMainGroup.Input), + @intFromEnum(ReportItemTypes.Main), + @intFromEnum(ReportItemMainGroup.Input), std.mem.toBytes(data), ); } @@ -331,8 +331,8 @@ pub fn hid_input(data: u8) [2]u8 { pub fn hid_output(data: u8) [2]u8 { return hid_report_item( 1, - @enumToInt(ReportItemTypes.Main), - @enumToInt(ReportItemMainGroup.Output), + @intFromEnum(ReportItemTypes.Main), + @intFromEnum(ReportItemMainGroup.Output), std.mem.toBytes(data), ); } @@ -340,8 +340,8 @@ pub fn hid_output(data: u8) [2]u8 { pub fn hid_collection_end() [1]u8 { return hid_report_item( 0, - @enumToInt(ReportItemTypes.Main), - @enumToInt(ReportItemMainGroup.CollectionEnd), + @intFromEnum(ReportItemTypes.Main), + @intFromEnum(ReportItemMainGroup.CollectionEnd), .{}, ); } @@ -352,8 +352,8 @@ pub fn hid_collection_end() [1]u8 { pub fn hid_usage_page(comptime n: u2, usage: [n]u8) [n + 1]u8 { return hid_report_item( n, - @enumToInt(ReportItemTypes.Global), - @enumToInt(GlobalItem.UsagePage), + @intFromEnum(ReportItemTypes.Global), + @intFromEnum(GlobalItem.UsagePage), usage, ); } @@ -361,8 +361,8 @@ pub fn hid_usage_page(comptime n: u2, usage: [n]u8) [n + 1]u8 { pub fn hid_logical_min(comptime n: u2, data: [n]u8) [n + 1]u8 { return hid_report_item( n, - @enumToInt(ReportItemTypes.Global), - @enumToInt(GlobalItem.LogicalMin), + @intFromEnum(ReportItemTypes.Global), + @intFromEnum(GlobalItem.LogicalMin), data, ); } @@ -370,8 +370,8 @@ pub fn hid_logical_min(comptime n: u2, data: [n]u8) [n + 1]u8 { pub fn hid_logical_max(comptime n: u2, data: [n]u8) [n + 1]u8 { return hid_report_item( n, - @enumToInt(ReportItemTypes.Global), - @enumToInt(GlobalItem.LogicalMax), + @intFromEnum(ReportItemTypes.Global), + @intFromEnum(GlobalItem.LogicalMax), data, ); } @@ -379,8 +379,8 @@ pub fn hid_logical_max(comptime n: u2, data: [n]u8) [n + 1]u8 { pub fn hid_report_size(comptime n: u2, data: [n]u8) [n + 1]u8 { return hid_report_item( n, - @enumToInt(ReportItemTypes.Global), - @enumToInt(GlobalItem.ReportSize), + @intFromEnum(ReportItemTypes.Global), + @intFromEnum(GlobalItem.ReportSize), data, ); } @@ -388,8 +388,8 @@ pub fn hid_report_size(comptime n: u2, data: [n]u8) [n + 1]u8 { pub fn hid_report_count(comptime n: u2, data: [n]u8) [n + 1]u8 { return hid_report_item( n, - @enumToInt(ReportItemTypes.Global), - @enumToInt(GlobalItem.ReportCount), + @intFromEnum(ReportItemTypes.Global), + @intFromEnum(GlobalItem.ReportCount), data, ); } @@ -400,8 +400,8 @@ pub fn hid_report_count(comptime n: u2, data: [n]u8) [n + 1]u8 { pub fn hid_usage(comptime n: u2, data: [n]u8) [n + 1]u8 { return hid_report_item( n, - @enumToInt(ReportItemTypes.Local), - @enumToInt(LocalItem.Usage), + @intFromEnum(ReportItemTypes.Local), + @intFromEnum(LocalItem.Usage), data, ); } diff --git a/src/modules/cpus/cortex-m.zig b/src/modules/cpus/cortex-m.zig index f6f92bcc..a9ad3fa6 100644 --- a/src/modules/cpus/cortex-m.zig +++ b/src/modules/cpus/cortex-m.zig @@ -5,7 +5,7 @@ const root = @import("root"); pub const regs = struct { // Interrupt Control and State Register - pub const ICSR = @intToPtr(*volatile mmio.Mmio(packed struct { + pub const ICSR = @ptrFromInt(*volatile mmio.Mmio(packed struct { VECTACTIVE: u9, reserved0: u2, RETTOBASE: u1, @@ -82,7 +82,7 @@ pub const startup_logic = struct { { const bss_start = @ptrCast([*]u8, µzig_bss_start); const bss_end = @ptrCast([*]u8, µzig_bss_end); - const bss_len = @ptrToInt(bss_end) - @ptrToInt(bss_start); + const bss_len = @intFromPtr(bss_end) - @intFromPtr(bss_start); @memset(bss_start[0..bss_len], 0); } @@ -91,7 +91,7 @@ pub const startup_logic = struct { { const data_start = @ptrCast([*]u8, µzig_data_start); const data_end = @ptrCast([*]u8, µzig_data_end); - const data_len = @ptrToInt(data_end) - @ptrToInt(data_start); + const data_len = @intFromPtr(data_end) - @intFromPtr(data_start); const data_src = @ptrCast([*]const u8, µzig_data_load_start); @memcpy(data_start[0..data_len], data_src[0..data_len]); diff --git a/src/modules/cpus/riscv32.zig b/src/modules/cpus/riscv32.zig index d788df07..e0059047 100644 --- a/src/modules/cpus/riscv32.zig +++ b/src/modules/cpus/riscv32.zig @@ -59,7 +59,7 @@ pub const startup_logic = struct { { const bss_start = @ptrCast([*]u8, µzig_bss_start); const bss_end = @ptrCast([*]u8, µzig_bss_end); - const bss_len = @ptrToInt(bss_end) - @ptrToInt(bss_start); + const bss_len = @intFromPtr(bss_end) - @intFromPtr(bss_start); @memset(bss_start[0..bss_len], 0); } @@ -68,7 +68,7 @@ pub const startup_logic = struct { { const data_start = @ptrCast([*]u8, µzig_data_start); const data_end = @ptrCast([*]u8, µzig_data_end); - const data_len = @ptrToInt(data_end) - @ptrToInt(data_start); + const data_len = @intFromPtr(data_end) - @intFromPtr(data_start); const data_src = @ptrCast([*]const u8, µzig_data_load_start); @memcpy(data_start[0..data_len], data_src[0..data_len]); diff --git a/src/start.zig b/src/start.zig index 97c6dc10..69cf81a4 100644 --- a/src/start.zig +++ b/src/start.zig @@ -141,7 +141,7 @@ pub fn initialize_system_memories() void { { const bss_start = @ptrCast([*]u8, §ions.microzig_bss_start); const bss_end = @ptrCast([*]u8, §ions.microzig_bss_end); - const bss_len = @ptrToInt(bss_end) - @ptrToInt(bss_start); + const bss_len = @intFromPtr(bss_end) - @intFromPtr(bss_start); @memset(bss_start[0..bss_len], 0); } @@ -150,7 +150,7 @@ pub fn initialize_system_memories() void { { const data_start = @ptrCast([*]u8, §ions.microzig_data_start); const data_end = @ptrCast([*]u8, §ions.microzig_data_end); - const data_len = @ptrToInt(data_end) - @ptrToInt(data_start); + const data_len = @intFromPtr(data_end) - @intFromPtr(data_start); const data_src = @ptrCast([*]const u8, §ions.microzig_data_load_start); @memcpy(data_start[0..data_len], data_src[0..data_len]); diff --git a/test/programs/uart-sync.zig b/test/programs/uart-sync.zig index 019b328c..7d583675 100644 --- a/test/programs/uart-sync.zig +++ b/test/programs/uart-sync.zig @@ -8,12 +8,12 @@ const cfg = if (micro.config.has_board) .uart_idx = 1, .pins = .{}, }, - .@"STM32F3DISCOVERY" => .{ + .STM32F3DISCOVERY => .{ .led_pin = micro.Pin("LD3"), .uart_idx = 1, .pins = .{}, }, - .@"STM32F4DISCOVERY" => .{ + .STM32F4DISCOVERY => .{ .led_pin = micro.Pin("LD5"), .uart_idx = 2, .pins = .{ .tx = micro.Pin("PA2"), .rx = micro.Pin("PA3") }, @@ -32,7 +32,7 @@ const cfg = if (micro.config.has_board) } else switch (micro.config.chip_name) { .@"NXP LPC1768" => .{ .led_pin = micro.Pin("P1.18"), .uart_idx = 1, .pins = .{} }, - .@"GD32VF103x8" => .{ .led_pin = micro.Pin("PA2"), .uart_idx = 1, .pins = .{} }, + .GD32VF103x8 => .{ .led_pin = micro.Pin("PA2"), .uart_idx = 1, .pins = .{} }, else => @compileError("unknown chip"), };