Skip to content

Commit

Permalink
Runs zig fmt (#133)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix "xq" Queißner <[email protected]>
  • Loading branch information
ikskuh and Felix "xq" Queißner authored Jun 25, 2023
1 parent 39bf0b5 commit a49fad9
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/core/experimental/gpio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const State = enum(u1) {
high = 1,

pub fn value(self: State) u1 {
return @enumToInt(self);
return @intFromEnum(self);
}
};

Expand Down
14 changes: 7 additions & 7 deletions src/core/usb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
46 changes: 23 additions & 23 deletions src/core/usb/hid.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -313,35 +313,35 @@ 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),
);
}

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),
);
}

pub fn hid_collection_end() [1]u8 {
return hid_report_item(
0,
@enumToInt(ReportItemTypes.Main),
@enumToInt(ReportItemMainGroup.CollectionEnd),
@intFromEnum(ReportItemTypes.Main),
@intFromEnum(ReportItemMainGroup.CollectionEnd),
.{},
);
}
Expand All @@ -352,44 +352,44 @@ 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,
);
}

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,
);
}

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,
);
}

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,
);
}

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,
);
}
Expand All @@ -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,
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/cpus/cortex-m.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -82,7 +82,7 @@ pub const startup_logic = struct {
{
const bss_start = @ptrCast([*]u8, &microzig_bss_start);
const bss_end = @ptrCast([*]u8, &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);
}
Expand All @@ -91,7 +91,7 @@ pub const startup_logic = struct {
{
const data_start = @ptrCast([*]u8, &microzig_data_start);
const data_end = @ptrCast([*]u8, &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, &microzig_data_load_start);

@memcpy(data_start[0..data_len], data_src[0..data_len]);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/cpus/riscv32.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub const startup_logic = struct {
{
const bss_start = @ptrCast([*]u8, &microzig_bss_start);
const bss_end = @ptrCast([*]u8, &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);
}
Expand All @@ -68,7 +68,7 @@ pub const startup_logic = struct {
{
const data_start = @ptrCast([*]u8, &microzig_data_start);
const data_end = @ptrCast([*]u8, &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, &microzig_data_load_start);

@memcpy(data_start[0..data_len], data_src[0..data_len]);
Expand Down
4 changes: 2 additions & 2 deletions src/start.zig
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn initialize_system_memories() void {
{
const bss_start = @ptrCast([*]u8, &sections.microzig_bss_start);
const bss_end = @ptrCast([*]u8, &sections.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);
}
Expand All @@ -150,7 +150,7 @@ pub fn initialize_system_memories() void {
{
const data_start = @ptrCast([*]u8, &sections.microzig_data_start);
const data_end = @ptrCast([*]u8, &sections.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, &sections.microzig_data_load_start);

@memcpy(data_start[0..data_len], data_src[0..data_len]);
Expand Down
6 changes: 3 additions & 3 deletions test/programs/uart-sync.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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") },
Expand All @@ -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"),
};

Expand Down

0 comments on commit a49fad9

Please sign in to comment.