Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## What version of Zig to use

`0.17.0-dev.1158+1d1193aa7`
`0.17.0-dev.1471+ff10b90bc`

## Getting Started With MicroZig

Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Note: This should be changed if you fork microzig!
.fingerprint = 0x605a83a849186d0f,
.version = "0.15.2",
.minimum_zig_version = "0.17.0-dev.1158+1d1193aa7",
.minimum_zig_version = "0.17.0-dev.1471+ff10b90bc",
.dependencies = .{
.@"build-internals" = .{ .path = "build-internals" },
.core = .{ .path = "core" },
Expand Down
4 changes: 2 additions & 2 deletions core/src/core/arm_semihosting.zig
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub const Debug = struct {
/// NOTE: It is possible for the debugger to request that the application continues by performing an RDI_Execute request or equivalent.
pub fn panic(reason: PanicCodes, subcode: usize) void {
const data = PanicData{
.reason = @intFromEnum(reason) + 0x20000,
.reason = @backingInt(reason) + 0x20000,
.subcode = subcode,
};

Expand Down Expand Up @@ -417,7 +417,7 @@ pub const fs = struct {
.path_len = path.len,
};
const ret = sys_open(&file);
return if (ret < 0) FileError.OpenFail else @enumFromInt(@as(usize, @bitCast(ret)));
return if (ret < 0) FileError.OpenFail else @fromBackingInt(@as(usize, @bitCast(ret)));
}

pub fn remove(path: [:0]const u8) FileError!void {
Expand Down
22 changes: 11 additions & 11 deletions core/src/core/usb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ pub const DescriptorAllocator = struct {
}

pub fn next_ep(self: *@This(), dir: types.Dir) types.Endpoint {
const idx: u1 = @intFromEnum(dir);
const idx: u1 = @backingInt(dir);
const ret = self.next_ep_num[idx];
self.next_ep_num[idx] += 1;
if (self.unique_endpoints)
self.next_ep_num[idx ^ 1] += 1;
return .{ .dir = dir, .num = @enumFromInt(ret) };
return .{ .dir = dir, .num = @fromBackingInt(ret) };
}

pub fn next_itf(self: *@This()) u8 {
Expand Down Expand Up @@ -328,8 +328,8 @@ pub fn DeviceController(config: Config, driver_args: config.DriverArgs()) type {
switch (field_type) {
// Register handler for endpoints
descriptor.Endpoint => {
const ep_dir = @intFromEnum(desc.endpoint.dir);
const ep_num = @intFromEnum(desc.endpoint.num);
const ep_dir = @backingInt(desc.endpoint.dir);
const ep_num = @backingInt(desc.endpoint.num);

if (ep_handler_types[ep_dir][ep_num] != void)
@compileError(std.fmt.comptimePrint(
Expand Down Expand Up @@ -369,8 +369,8 @@ pub fn DeviceController(config: Config, driver_args: config.DriverArgs()) type {
const const_ep_handlers = ep_handlers;

const DriverConfig = @Struct(.@"extern", null, &field_names, &field_types, &field_attrs);
const idx_in = @intFromEnum(types.Dir.In);
const idx_out = @intFromEnum(types.Dir.Out);
const idx_in = @backingInt(types.Dir.In);
const idx_out = @backingInt(types.Dir.Out);
break :blk .{
.device_descriptor = desc_device,
.config_descriptor = extern struct {
Expand Down Expand Up @@ -464,8 +464,8 @@ pub fn DeviceController(config: Config, driver_args: config.DriverArgs()) type {
pub fn on_buffer(self: *@This(), device_itf: *DeviceInterface, comptime ep: types.Endpoint) void {
log.debug("on_buffer {t} {t}", .{ ep.num, ep.dir });

const driver_opt = comptime handlers_ep.drv[@intFromEnum(ep.dir)][@intFromEnum(ep.num)];
const handler = comptime @field(handlers_ep.han, @tagName(ep.dir))[@intFromEnum(ep.num)];
const driver_opt = comptime handlers_ep.drv[@backingInt(ep.dir)][@backingInt(ep.num)];
const handler = comptime @field(handlers_ep.han, @tagName(ep.dir))[@backingInt(ep.num)];

if (comptime ep == types.Endpoint.in(.ep0)) {
// We use this opportunity to finish the delayed
Expand Down Expand Up @@ -513,7 +513,7 @@ pub fn DeviceController(config: Config, driver_args: config.DriverArgs()) type {
fn process_device_setup(self: *@This(), device_itf: *DeviceInterface, setup: *const types.SetupPacket) ?[]const u8 {
switch (setup.request_type.type) {
.Standard => {
const request: types.SetupRequest = @enumFromInt(setup.request);
const request: types.SetupRequest = @fromBackingInt(setup.request);
log.debug("Device setup: {any}", .{request});
switch (request) {
.GetStatus => {
Expand All @@ -525,7 +525,7 @@ pub fn DeviceController(config: Config, driver_args: config.DriverArgs()) type {
.SetConfiguration => self.process_set_config(device_itf, setup.value.into()),
.GetDescriptor => return get_descriptor(setup.value.into()),
.SetFeature => {
const feature: types.FeatureSelector = @enumFromInt(setup.value.into() >> 8);
const feature: types.FeatureSelector = @fromBackingInt(setup.value.into() >> 8);
switch (feature) {
.DeviceRemoteWakeup, .EndpointHalt => {},
// TODO: https://github.com/ZigEmbeddedGroup/microzig/issues/453
Expand Down Expand Up @@ -563,7 +563,7 @@ pub fn DeviceController(config: Config, driver_args: config.DriverArgs()) type {
// Return the appropriate descriptor type as determined by the top 8 bits of the value.
fn get_descriptor(value: u16) ?[]const u8 {
const asBytes = std.mem.asBytes;
const desc_type: descriptor.Type = @enumFromInt(value >> 8);
const desc_type: descriptor.Type = @fromBackingInt(value >> 8);
const desc_idx: u8 = @truncate(value);
log.debug("Request for {any} descriptor {}", .{ desc_type, desc_idx });
return switch (desc_type) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/core/usb/descriptor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ pub const String = struct {
length: u8 = @sizeOf(@This()),
descriptor_type: Type = .String,
lang: types.U16_Le align(1),
} = comptime &.{ .lang = .from(@intFromEnum(lang)) };
} = comptime &.{ .lang = .from(@backingInt(lang)) };
return .{ .data = std.mem.asBytes(ret) };
}

pub fn from_str(comptime string: []const u8) @This() {
@setEvalBranchQuota(10000);
const encoded: []const u8 = std.mem.sliceAsBytes(std.unicode.utf8ToUtf16LeStringLiteral(string));
return .{ .data = &[2]u8{ encoded.len + 2, @intFromEnum(Type.String) } ++ encoded };
return .{ .data = &[2]u8{ encoded.len + 2, @backingInt(Type.String) } ++ encoded };
}
};

Expand Down
2 changes: 1 addition & 1 deletion core/src/core/usb/drivers/CDC.zig
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub fn init(self: *@This(), desc: *const Descriptor, device: *usb.DeviceInterfac
/// Handle class-specific SETUP requests where recipient=Interface
/// Called by DeviceController when the interface number matches this driver.
pub fn class_request(self: *@This(), setup: *const usb.types.SetupPacket) ?[]const u8 {
const mgmt_request: ManagementRequestType = @enumFromInt(setup.request);
const mgmt_request: ManagementRequestType = @fromBackingInt(setup.request);
log.debug("cdc setup: {any} {} {}", .{ mgmt_request, setup.length.into(), setup.value.into() });

return switch (mgmt_request) {
Expand Down
10 changes: 5 additions & 5 deletions core/src/core/usb/drivers/hid.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub const ReportItem = union(enum) {

pub fn local(self: @This()) i32 {
return switch (self) {
inline else => |x| @intFromEnum(x),
inline else => |x| @backingInt(x),
.vendor => |x| x,
};
}
Expand Down Expand Up @@ -275,7 +275,7 @@ pub const ReportItem = union(enum) {
inline else => |payload| blk: {
const data: []const u8 = switch (@TypeOf(payload)) {
void => "",
Collection, UsagePage => encode_int(@intFromEnum(payload)),
Collection, UsagePage => encode_int(@backingInt(payload)),
u31, i32, ?i32 => encode_int(payload),
InputOutput => &.{@bitCast(payload)},
else => |T| @compileError(@typeName(T) ++ " cannot be turned into a HID report"),
Expand Down Expand Up @@ -397,16 +397,16 @@ pub fn InterruptDriver(options: InterruptDriverOptions) type {
log.debug("class_request {any}", .{setup});
switch (setup.request_type.type) {
.Standard => {
const hid_desc_type: usb.descriptor.HID.CsType = @enumFromInt(setup.value.into() >> 8);
const request_code: usb.types.SetupRequest = @enumFromInt(setup.request);
const hid_desc_type: usb.descriptor.HID.CsType = @fromBackingInt(setup.value.into() >> 8);
const request_code: usb.types.SetupRequest = @fromBackingInt(setup.request);

if (request_code == .GetDescriptor and hid_desc_type == .HID)
return std.mem.asBytes(&self.descriptor.hid)
else if (request_code == .GetDescriptor and hid_desc_type == .Report)
return report_descriptor;
},
.Class => {
const hid_request_type: RequestType = @enumFromInt(setup.request);
const hid_request_type: RequestType = @fromBackingInt(setup.request);
switch (hid_request_type) {
.SetIdle => {
// TODO: https://github.com/ZigEmbeddedGroup/microzig/issues/454
Expand Down
4 changes: 2 additions & 2 deletions core/src/core/usb/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ pub const ClassSubclassProtocol = extern struct {
) @This() {
return .{
.class = class,
.subclass = @intFromEnum(subclass),
.protocol = @intFromEnum(protocol),
.subclass = @backingInt(subclass),
.protocol = @backingInt(protocol),
};
}
};
Expand Down
34 changes: 17 additions & 17 deletions core/src/cpus/cortex_m.zig
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub const interrupt = struct {
}

fn assert_not_exception(comptime int: Interrupt) void {
if (@intFromEnum(int) < 0) {
if (@backingInt(int) < 0) {
@compileError("expected interrupt, got exception: " ++ @tagName(int));
}
}
Expand Down Expand Up @@ -327,8 +327,8 @@ pub const interrupt = struct {
/// Note: Although the Priority values are 0 - 15, some platforms may
/// only use the most significant bits.
pub fn set_priority(comptime excpt: Exception, priority: Priority) void {
const num: u2 = @intCast(@intFromEnum(excpt) / 4);
const shift: u5 = @as(u5, @intCast(@intFromEnum(excpt))) % 4 * 8;
const num: u2 = @intCast(@backingInt(excpt) / 4);
const shift: u5 = @as(u5, @intCast(@backingInt(excpt))) % 4 * 8;

// The code below is safe since the switch is compile-time resolved.
// The any SHPRn register which is unavailable on a platform will
Expand All @@ -340,22 +340,22 @@ pub const interrupt = struct {
},
1 => {
ppb.SHPR1.raw &= ~(@as(u32, 0xFF) << shift);
ppb.SHPR1.raw |= @as(u32, @intFromEnum(priority)) << shift;
ppb.SHPR1.raw |= @as(u32, @backingInt(priority)) << shift;
},
2 => {
ppb.SHPR2.raw &= ~(@as(u32, 0xFF) << shift);
ppb.SHPR2.raw |= @as(u32, @intFromEnum(priority)) << shift;
ppb.SHPR2.raw |= @as(u32, @backingInt(priority)) << shift;
},
3 => {
ppb.SHPR3.raw &= ~(@as(u32, 0xFF) << shift);
ppb.SHPR3.raw |= @as(u32, @intFromEnum(priority)) << shift;
ppb.SHPR3.raw |= @as(u32, @backingInt(priority)) << shift;
},
}
}

pub fn get_priority(comptime excpt: Exception) Priority {
const num: u2 = @intCast(@intFromEnum(excpt) / 4);
const shift: u5 = @as(u5, @intCast(@intFromEnum(excpt))) % 4 * 8;
const num: u2 = @intCast(@backingInt(excpt) / 4);
const shift: u5 = @as(u5, @intCast(@backingInt(excpt))) % 4 * 8;

const raw: u8 = (switch (num) {
0 => @compileError("Cannot get the priority for the exception"),
Expand All @@ -364,14 +364,14 @@ pub const interrupt = struct {
3 => ppb.SHPR3.raw,
} >> shift) & 0xFF;

return @enumFromInt(raw);
return @fromBackingInt(raw);
}
};

const nvic = peripherals.nvic;

pub fn is_enabled(comptime int: ExternalInterrupt) bool {
const num: comptime_int = @intFromEnum(int);
const num: comptime_int = @backingInt(int);
switch (cortex_m) {
.cortex_m0,
.cortex_m0plus,
Expand All @@ -392,7 +392,7 @@ pub const interrupt = struct {
}

pub fn enable(comptime int: ExternalInterrupt) void {
const num: comptime_int = @intFromEnum(int);
const num: comptime_int = @backingInt(int);
switch (cortex_m) {
.cortex_m0,
.cortex_m0plus,
Expand All @@ -413,7 +413,7 @@ pub const interrupt = struct {
}

pub fn disable(comptime int: ExternalInterrupt) void {
const num: comptime_int = @intFromEnum(int);
const num: comptime_int = @backingInt(int);
switch (cortex_m) {
.cortex_m0,
.cortex_m0plus,
Expand All @@ -434,7 +434,7 @@ pub const interrupt = struct {
}

pub fn is_pending(comptime int: ExternalInterrupt) bool {
const num: comptime_int = @intFromEnum(int);
const num: comptime_int = @backingInt(int);
switch (cortex_m) {
.cortex_m0,
.cortex_m0plus,
Expand All @@ -455,7 +455,7 @@ pub const interrupt = struct {
}

pub fn set_pending(comptime int: ExternalInterrupt) void {
const num: comptime_int = @intFromEnum(int);
const num: comptime_int = @backingInt(int);
switch (cortex_m) {
.cortex_m0,
.cortex_m0plus,
Expand All @@ -476,7 +476,7 @@ pub const interrupt = struct {
}

pub fn clear_pending(comptime int: ExternalInterrupt) void {
const num: comptime_int = @intFromEnum(int);
const num: comptime_int = @backingInt(int);
switch (cortex_m) {
.cortex_m0,
.cortex_m0plus,
Expand All @@ -497,11 +497,11 @@ pub const interrupt = struct {
}

pub fn set_priority(comptime int: ExternalInterrupt, priority: Priority) void {
nvic.IPR[@intFromEnum(int)] = @intFromEnum(priority);
nvic.IPR[@backingInt(int)] = @backingInt(priority);
}

pub fn get_priority(comptime int: ExternalInterrupt) Priority {
return @enumFromInt(peripherals.nvic.IPR[@intFromEnum(int)]);
return @fromBackingInt(peripherals.nvic.IPR[@backingInt(int)]);
}
};

Expand Down
2 changes: 1 addition & 1 deletion core/src/cpus/cortex_m/m7_utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn init_swo(config: struct {
peripherals.itm.TER[config.stim_port].modify(.{ .STIMENA = 1 });

// Configure Serial Wire Output (SWO):
peripherals.tpiu.SPPR.modify(.{ .TXMODE = @intFromEnum(config.tx_mode) });
peripherals.tpiu.SPPR.modify(.{ .TXMODE = @backingInt(config.tx_mode) });

// SWO output clock = Asynchronous_Reference_Clock/(SWOSCALAR +1)\
// SWOSCALAR = (Asynchronous_Reference_Clock)/(SWO output clock) - 1
Expand Down
2 changes: 1 addition & 1 deletion core/src/cpus/msp430.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const vector_table: VectorTable = vector_table: {
// Apply interrupts
for (@typeInfo(@TypeOf(microzig.options.interrupts)).@"struct".field_names) |field_name| {
const maybe_handler = @field(microzig.options.interrupts, field_name);
tmp.table[@intFromEnum(@field(Interrupt, field_name))] =
tmp.table[@backingInt(@field(Interrupt, field_name))] =
maybe_handler orelse .{ .c = interrupt.unhandled };
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/mmio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ pub fn Mmio(comptime Packed: type) type {
// same as for the .Int case, but casting to and from the u... tag type U of the enum FieldType
const U = enum_info.tag_type;
@field(val, field_name) =
@as(FieldType, @enumFromInt(@as(U, @intFromEnum(@field(val, field_name))) ^
@as(U, @intFromEnum(@as(FieldType, value)))));
@as(FieldType, @fromBackingInt(@as(U, @backingInt(@field(val, field_name)) ^
@as(U, @backingInt(@as(FieldType, value))))));
},
else => |T| {
@compileError("unsupported register field type '" ++ @typeName(T) ++ "'");
Expand Down
2 changes: 1 addition & 1 deletion drivers/src/base/ClockDevice.zig
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub const TestDevice = struct {

pub fn get_time_since_boot_fn(ctx: *anyopaque) mdf.time.Absolute {
const dev: *TestDevice = @ptrCast(@alignCast(ctx));
return @enumFromInt(dev.time);
return @fromBackingInt(dev.time);
}

pub fn sleep_fn(ctx: *anyopaque, time_us: u64) void {
Expand Down
Loading
Loading