Skip to content
Closed
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
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub fn build(b: *Build) void {
builder.addRule(.{ .builtin = .no_hidden_allocations }, .{});
builder.addRule(.{ .builtin = .no_deprecated }, .{});
builder.addRule(.{ .builtin = .no_literal_only_bool_expression }, .{});
builder.addRule(.{ .builtin = .no_redundant_comptime }, .{});
builder.addRule(.{ .builtin = .require_fmt }, .{});
builder.addRule(.{ .builtin = .switch_case_ordering }, .{});

Expand Down
2 changes: 1 addition & 1 deletion core/src/core/mem.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");

pub fn EndianInt(comptime T: type, e: std.lang.Endian) type {
pub fn EndianInt(T: type, e: std.lang.Endian) type {
return packed struct(T) {
raw: T,

Expand Down
10 changes: 5 additions & 5 deletions core/src/cpus/cortex_m.zig
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ pub const atomic = struct {
};

/// Atomic add
pub fn add(comptime T: type, ptr: *T, delta: T) T {
pub fn add(T: type, ptr: *T, delta: T) T {
if (has_native_atomics) {
return @atomicRmw(T, ptr, .Add, delta, .monotonic);
} else {
Expand All @@ -563,7 +563,7 @@ pub const atomic = struct {
}

/// Atomic load
pub fn load(comptime T: type, ptr: *const T, comptime ordering: std.lang.AtomicOrder) T {
pub fn load(T: type, ptr: *const T, comptime ordering: std.lang.AtomicOrder) T {
if (has_native_atomics) {
return @atomicLoad(T, ptr, ordering);
} else {
Expand All @@ -575,7 +575,7 @@ pub const atomic = struct {
}

/// Atomic store
pub fn store(comptime T: type, ptr: *T, value: T, comptime ordering: std.lang.AtomicOrder) void {
pub fn store(T: type, ptr: *T, value: T, comptime ordering: std.lang.AtomicOrder) void {
if (has_native_atomics) {
@atomicStore(T, ptr, value, ordering);
} else {
Expand All @@ -588,7 +588,7 @@ pub const atomic = struct {

/// Atomic compare and swap
pub fn cmpxchg(
comptime T: type,
T: type,
ptr: *T,
expected_value: T,
new_value: T,
Expand All @@ -612,7 +612,7 @@ pub const atomic = struct {

/// Atomic read-modify-write
pub fn rmw(
comptime T: type,
T: type,
ptr: *T,
comptime op: std.lang.AtomicRmwOp,
operand: T,
Expand Down
2 changes: 1 addition & 1 deletion core/src/mmio.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const std = @import("std");
const assert = std.debug.assert;

pub fn Mmio(comptime Packed: type) type {
pub fn Mmio(Packed: type) type {
@setEvalBranchQuota(2_000);

const size = @bitSizeOf(Packed);
Expand Down
4 changes: 2 additions & 2 deletions core/src/utilities.zig
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub inline fn initialize_system_memories(which: enum {

/// A helper class that allows operating on a slice of slices
/// with similar operations to those of a slice.
pub fn SliceVector(comptime Slice: type) type {
pub fn SliceVector(Slice: type) type {
const type_info = @typeInfo(Slice);
if (type_info != .pointer)
@compileError("Slice must have a slice type!");
Expand Down Expand Up @@ -519,7 +519,7 @@ pub const end_of_stack: *const anyopaque = blk: switch (microzig.config.stack) {
/// A naive circular buffer implementation. At time of writing, it's intended
/// to fill in where the deleted std.fifo.LinearFifo was used, so the API might
/// seem unfinished.
pub fn CircularBuffer(comptime T: type, comptime len: usize) type {
pub fn CircularBuffer(T: type, comptime len: usize) type {
return struct {
items: [len]T,
start: usize,
Expand Down
2 changes: 1 addition & 1 deletion drivers/src/input/keyboard_matrix.zig
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub const Key = enum(u16) {
};
};

inline fn busyloop(comptime N: comptime_int) void {
inline fn busyloop(N: comptime_int) void {
for (0..N) |_| {
// wait some cycles so the physics does its magic and convey
// the electrons
Expand Down
2 changes: 1 addition & 1 deletion drivers/src/sensor/HTS221.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub const HTS221 = struct {
// internal read buffer
read_buffer: [2]u8 = .{ 0, 0 },

fn read_register(self: *@This(), comptime Regs: type, reg: RegsAddr) InterfaceError!Regs {
fn read_register(self: *@This(), Regs: type, reg: RegsAddr) InterfaceError!Regs {
const raw = try self.read_one_byte(reg);
return @as(Regs, @bitCast(raw));
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/src/stepper/stepper.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub const DRV8825 = struct {
const MS_TABLE = [_]u3{ 0b000, 0b001, 0b010, 0b011, 0b100, 0b111 };
};

pub fn Stepper(comptime Driver: type) type {
pub fn Stepper(Driver: type) type {
return struct {
const Self = @This();
pub const SpeedProfile = union(enum) {
Expand Down
2 changes: 1 addition & 1 deletion examples/microchip/atmega/src/blinky.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn main() void {
}
}

pub fn busy_sleep(comptime limit: comptime_int) void {
pub fn busy_sleep(limit: comptime_int) void {
if (limit <= 0) @compileError("limit must be positive!");

const outer = std.math.divCeil(comptime_int, limit, std.math.maxInt(u16)) catch unreachable;
Expand Down
2 changes: 1 addition & 1 deletion examples/microchip/atmega/src/spi_flash_w25q.zig
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ fn write_hex_u24(val: u24) void {
write_hex_u8(@truncate(val));
}

pub fn busy_sleep(comptime limit: comptime_int) void {
pub fn busy_sleep(limit: comptime_int) void {
if (limit <= 0) @compileError("limit must be positive!");

const outer = std.math.divCeil(comptime_int, limit, std.math.maxInt(u16)) catch unreachable;
Expand Down
2 changes: 1 addition & 1 deletion examples/microchip/attiny/src/blinky.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn main() void {
}
}

pub fn busy_sleep(comptime limit: comptime_int) void {
pub fn busy_sleep(limit: comptime_int) void {
if (limit <= 0) @compileError("limit must be non-negative!");

comptime var bits = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/microchip/attiny/src/blinky84.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn main() void {
}
}

pub fn busy_sleep(comptime limit: comptime_int) void {
pub fn busy_sleep(limit: comptime_int) void {
if (limit <= 0) @compileError("limit must be non-negative!");

comptime var bits = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/nxp/lpc/src/blinky.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const PatchedGpio = extern struct {
}
};

pub fn busy_sleep(comptime limit: comptime_int) void {
pub fn busy_sleep(limit: comptime_int) void {
if (limit <= 0) @compileError("limit must be non-negative!");

comptime var bits = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/texasinstruments/msp430/src/blinky.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn main() void {
}
}

pub fn busy_sleep(comptime limit: comptime_int) void {
pub fn busy_sleep(limit: comptime_int) void {
if (limit <= 0) @compileError("limit must be non-negative!");

comptime var bits = 0;
Expand Down
4 changes: 2 additions & 2 deletions modules/bounded-array/src/bounded_array.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const testing = std.testing;
/// var slice = a.slice(); // a slice of the 64-byte array
/// var a_clone = a; // creates a copy - the structure doesn't use any internal pointers
/// ```
pub fn BoundedArray(comptime T: type, comptime buffer_capacity: usize) type {
pub fn BoundedArray(T: type, comptime buffer_capacity: usize) type {
return BoundedArrayAligned(T, @alignOf(T), buffer_capacity);
}

Expand All @@ -33,7 +33,7 @@ pub fn BoundedArray(comptime T: type, comptime buffer_capacity: usize) type {
// try testing.expectEqual(@as(u16, 65535), b[0]);
/// ```
pub fn BoundedArrayAligned(
comptime T: type,
T: type,
comptime alignment: u29,
comptime buffer_capacity: usize,
) type {
Expand Down
2 changes: 1 addition & 1 deletion modules/freertos/src/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn check_true(rc: BaseType) bool {
}

/// Convert a nullable C handle to a Zig optional, returning OutOfMemory if null.
pub fn check_handle(comptime T: type, handle: T) Error!T {
pub fn check_handle(T: type, handle: T) Error!T {
if (handle == null) return error.OutOfMemory;
return handle;
}
6 changes: 3 additions & 3 deletions modules/freertos/src/queue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub const ISR_Result = struct {
};

/// Result from an ISR receive operation.
pub fn IsrReceiveResult(comptime T: type) type {
pub fn IsrReceiveResult(T: type) type {
return struct {
/// The received item.
item: T,
Expand All @@ -41,7 +41,7 @@ pub fn IsrReceiveResult(comptime T: type) type {
// ── Generic Queue ───────────────────────────────────────────────────────

/// A type-safe FreeRTOS queue holding items of type `T`.
pub fn Queue(comptime T: type) type {
pub fn Queue(T: type) type {
return struct {
const Self = @This();
/// Underlying FreeRTOS C handle. Use `freertos.c` for direct C API access.
Expand Down Expand Up @@ -166,6 +166,6 @@ pub fn Queue(comptime T: type) type {
// ── Top-Level Convenience ───────────────────────────────────────────────

/// Create a new queue holding items of type `T` with the given capacity.
pub fn create(comptime T: type, length: u32) Error!Queue(T) {
pub fn create(T: type, length: u32) Error!Queue(T) {
return Queue(T).create(length);
}
2 changes: 1 addition & 1 deletion modules/rtt/src/lock.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const builtin = @import("builtin");

/// A generic struct that provides exclusive access to the RTT control block
pub fn GenericLock(
comptime Context: type,
Context: type,
comptime lock_fn: fn (context: Context) void,
comptime unlock_fn: fn (context: Context) void,
) type {
Expand Down
8 changes: 4 additions & 4 deletions port/espressif/esp/src/hal/atomic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ const microzig = @import("microzig");

const largest_atomic_size = @sizeOf(usize);

inline fn atomic_store(comptime T: type, ptr: *volatile T, val: T, _: i32) void {
inline fn atomic_store(T: type, ptr: *volatile T, val: T, _: i32) void {
if (@sizeOf(T) > largest_atomic_size) {
@compileError("only supports types with a size of less than 4");
}

ptr.* = val;
}

inline fn atomic_load(comptime T: type, ptr: *volatile T, _: i32) T {
inline fn atomic_load(T: type, ptr: *volatile T, _: i32) T {
if (@sizeOf(T) > largest_atomic_size) {
@compileError("only supports types with a size of less than 4");
}

return ptr.*;
}

inline fn atomic_rmw(comptime T: type, ptr: *volatile T, val: T, _: i32, comptime op: std.lang.AtomicRmwOp) T {
inline fn atomic_rmw(T: type, ptr: *volatile T, val: T, _: i32, comptime op: std.lang.AtomicRmwOp) T {
const cs = microzig.interrupt.enter_critical_section();
defer cs.leave();

Expand All @@ -42,7 +42,7 @@ inline fn atomic_rmw(comptime T: type, ptr: *volatile T, val: T, _: i32, comptim
return tmp;
}

inline fn atomic_compare_exchange(comptime T: type, ptr: *volatile T, expected: *T, desired: T, _: i32, _: i32) bool {
inline fn atomic_compare_exchange(T: type, ptr: *volatile T, expected: *T, desired: T, _: i32, _: i32) bool {
const cs = microzig.interrupt.enter_critical_section();
defer cs.leave();

Expand Down
4 changes: 2 additions & 2 deletions port/espressif/esp/src/hal/uart.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const peripherals = microzig.chip.peripherals;

// TODO: chip independent. currently specific to esp32c3.

fn reg(comptime index: comptime_int) @TypeOf(@field(peripherals, std.fmt.comptimePrint("UART{}", .{index}))) {
fn reg(index: comptime_int) @TypeOf(@field(peripherals, std.fmt.comptimePrint("UART{}", .{index}))) {
return @field(peripherals, std.fmt.comptimePrint("UART{}", .{index}));
}

pub fn write(comptime index: comptime_int, slice: []const u8) void {
pub fn write(index: comptime_int, slice: []const u8) void {
const r = reg(index);
for (slice) |c| {
while (r.STATUS.read().TXFIFO_CNT > 8) {}
Expand Down
8 changes: 4 additions & 4 deletions port/gigadevice/gd32/src/hals/GD32VF103.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ fn set_reg_field(reg: anytype, comptime field_name: anytype, value: anytype) voi
}

pub const gpio = struct {
pub fn set_output(comptime pin: type) void {
pub fn set_output(pin: type) void {
_ = pin;
// TODO: check if pin is already configured as output
}
pub fn set_input(comptime pin: type) void {
pub fn set_input(pin: type) void {
_ = pin;
// TODO: check if pin is already configured as input
}

pub fn read(comptime pin: type) microzig.gpio.State {
pub fn read(pin: type) microzig.gpio.State {
_ = pin;
// TODO: check if pin is configured as input
return .low;
}

pub fn write(comptime pin: type, state: microzig.gpio.State) void {
pub fn write(pin: type, state: microzig.gpio.State) void {
_ = pin;
_ = state;
// TODO: check if pin is configured as output
Expand Down
4 changes: 2 additions & 2 deletions port/microchip/attiny/src/hals/attiny85/progmem.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn Table(comptime T: type, comptime len: usize, comptime values: [len]T) type {
pub fn Table(T: type, comptime len: usize, comptime values: [len]T) type {
return struct {
pub const data linksection(".progmem.data") = values;

Expand All @@ -8,7 +8,7 @@ pub fn Table(comptime T: type, comptime len: usize, comptime values: [len]T) typ
};
}

pub inline fn read(comptime T: type, ptr: *const T) T {
pub inline fn read(T: type, ptr: *const T) T {
return ptr.*;
}

Expand Down
10 changes: 5 additions & 5 deletions port/nxp/lpc/src/hals/LPC176x5x.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,28 @@ pub fn parse_pin(comptime spec: []const u8) type {
};
}

pub fn route_pin(comptime pin: type, function: PinTarget) void {
pub fn route_pin(pin: type, function: PinTarget) void {
var val = pin.regs.pinsel_reg.read();
@field(val, pin.regs.pinsel_field) = @backingInt(function);
pin.regs.pinsel_reg.write(val);
}

pub const gpio = struct {
pub fn set_output(comptime pin: type) void {
pub fn set_output(pin: type) void {
pin.regs.dir.raw |= pin.gpio_mask;
}
pub fn set_input(comptime pin: type) void {
pub fn set_input(pin: type) void {
pin.regs.dir.raw &= ~pin.gpio_mask;
}

pub fn read(comptime pin: type) microzig.gpio.State {
pub fn read(pin: type) microzig.gpio.State {
return if ((pin.regs.pin.raw & pin.gpio_mask) != 0)
microzig.gpio.State.high
else
microzig.gpio.State.low;
}

pub fn write(comptime pin: type, state: microzig.gpio.State) void {
pub fn write(pin: type, state: microzig.gpio.State) void {
if (state == .high) {
pin.regs.set.raw = pin.gpio_mask;
} else {
Expand Down
2 changes: 1 addition & 1 deletion port/nxp/mcx/src/mcxn947/scripts/generate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn print_fields(comptime ty: []const u8, comptime suffix_: ?[]const u8) []Fi

/// For a given packed structure `T`, this function returns
/// the bit index its the field named `field_name`.
fn get_field_offset(comptime T: type, comptime field_name: []const u8) u8 {
fn get_field_offset(T: type, comptime field_name: []const u8) u8 {
std.debug.assert(@typeInfo(T) == .@"struct");
std.debug.assert(std.meta.containerLayout(T) == .@"packed");
std.debug.assert(std.meta.fieldIndex(T, field_name) != null);
Expand Down
2 changes: 1 addition & 1 deletion port/raspberrypi/rp2xxx/src/hal/adc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub fn set_temp_sensor_enabled(enable: bool) void {
}

/// T must be floating point.
pub fn temp_sensor_result_to_celcius(comptime T: type, comptime vref: T, result: u12) T {
pub fn temp_sensor_result_to_celcius(T: type, comptime vref: T, result: u12) T {
// TODO: consider fixed-point
const raw = @as(T, @floatFromInt(result));
const voltage: T = vref * raw / 0x0fff;
Expand Down
Loading
Loading