Skip to content

Commit 1e0e480

Browse files
authored
zig fmt everything/test in ci (ZigEmbeddedGroup#494)
1 parent 5b08b0a commit 1e0e480

File tree

18 files changed

+547
-565
lines changed

18 files changed

+547
-565
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ env:
1010
ZIG_VERSION: 0.14.0
1111

1212
jobs:
13+
formatting-check:
14+
name: Formatting check
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Setup Zig
20+
uses: mlugg/setup-zig@v1
21+
with:
22+
version: ${{ env.ZIG_VERSION }}
23+
- name: Run zig fmt
24+
run: zig fmt --check .
25+
1326
unit-test-regz:
1427
name: Unit Test Regz
1528
continue-on-error: true

core/src/core/experimental/spi.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ pub const DeviceConfig = struct {
137137
};
138138

139139
pub const InitError = error{
140-
// TODO: add common options
141-
};
140+
// TODO: add common options
141+
};
142142

143143
pub const WriteError = error{};
144144
pub const ReadError = error{

core/src/cpus/cortex_m.zig

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub const ExternalInterrupt = blk: {
3838
// Note: The value of each field is the interrupt number (VTOR offset),
3939
// not the offset into the whole vector table.
4040

41-
const vector_info = @typeInfo(Interrupt).@"enum";
41+
const vector_info = @typeInfo(Interrupt).@"enum";
4242
const vector_fields = vector_info.fields;
4343
var result_len: usize = 0;
4444

@@ -74,7 +74,7 @@ pub const Exception = blk: {
7474
// Note: The value of each field is the index into the whole
7575
// vector table, not the negative offset from VTOR.
7676

77-
const vector_info = @typeInfo(Interrupt).@"enum";
77+
const vector_info = @typeInfo(Interrupt).@"enum";
7878
const vector_fields = vector_info.fields;
7979
var result_len: usize = 0;
8080

@@ -106,7 +106,6 @@ pub const Exception = blk: {
106106
};
107107

108108
pub const interrupt = struct {
109-
110109
pub const Priority = enum(u8) {
111110
lowest = 0,
112111
highest = 15,
@@ -136,15 +135,11 @@ pub const interrupt = struct {
136135
}
137136

138137
pub const exception = struct {
139-
140138
const ppb = microzig.chip.peripherals.PPB;
141139

142140
pub fn is_enabled(comptime excpt: Exception) bool {
143141
switch (cortex_m) {
144-
.cortex_m3,
145-
.cortex_m4,
146-
.cortex_m7
147-
=> {
142+
.cortex_m3, .cortex_m4, .cortex_m7 => {
148143
const raw = ppb.SHCSR.raw;
149144
switch (excpt) {
150145
.UsageFault => return (raw & 0x0004_0000) != 0,
@@ -171,10 +166,7 @@ pub const interrupt = struct {
171166

172167
pub fn enable(comptime excpt: Exception) void {
173168
switch (cortex_m) {
174-
.cortex_m3,
175-
.cortex_m4,
176-
.cortex_m7
177-
=> {
169+
.cortex_m3, .cortex_m4, .cortex_m7 => {
178170
switch (excpt) {
179171
.UsageFault => ppb.SHCSR.raw |= 0x0004_0000,
180172
.BusFault => ppb.SHCSR.raw |= 0x0002_0000,
@@ -195,14 +187,11 @@ pub const interrupt = struct {
195187
},
196188
else => @compileError("not supported on this platform"),
197189
}
198-
}
190+
}
199191

200192
pub fn disable(comptime excpt: Exception) void {
201193
switch (cortex_m) {
202-
.cortex_m3,
203-
.cortex_m4,
204-
.cortex_m7
205-
=> {
194+
.cortex_m3, .cortex_m4, .cortex_m7 => {
206195
switch (excpt) {
207196
.UsageFault => ppb.SHCSR.raw &= ~@as(u32, 0x0004_0000),
208197
.BusFault => ppb.SHCSR.raw &= ~@as(u32, 0x0002_0000),
@@ -232,10 +221,7 @@ pub const interrupt = struct {
232221
if (excpt == .SVCALL) return (ppb.SHCSR.raw & 0x0000_8000) != 0;
233222
@compileError("not supported on this platform");
234223
},
235-
.cortex_m3,
236-
.cortex_m4,
237-
.cortex_m7
238-
=> {
224+
.cortex_m3, .cortex_m4, .cortex_m7 => {
239225
const raw = ppb.SHCSR.raw;
240226
switch (excpt) {
241227
.SVCall => return (raw & 0x0000_8000) != 0,
@@ -270,10 +256,7 @@ pub const interrupt = struct {
270256
if (excpt == .SVCALL) ppb.SHCSR.raw |= 0x0000_8000;
271257
@compileError("not supported on this platform");
272258
},
273-
.cortex_m3,
274-
.cortex_m4,
275-
.cortex_m7
276-
=> {
259+
.cortex_m3, .cortex_m4, .cortex_m7 => {
277260
switch (excpt) {
278261
.SVCall => ppb.SHCSR.raw |= 0x0000_8000,
279262
.BusFault => ppb.SHCSR.raw |= 0x0000_4000,
@@ -306,10 +289,7 @@ pub const interrupt = struct {
306289
if (excpt == .SVCALL) ppb.SHCSR.raw &= ~@as(u32, 0x0000_8000);
307290
@compileError("not supported on this platform");
308291
},
309-
.cortex_m3,
310-
.cortex_m4,
311-
.cortex_m7
312-
=> {
292+
.cortex_m3, .cortex_m4, .cortex_m7 => {
313293
switch (excpt) {
314294
.SVCall => ppb.SHCSR.raw &= ~@as(u32, 0x0000_8000),
315295
.BusFault => ppb.SHCSR.raw &= ~@as(u32, 0x0000_4000),
@@ -357,7 +337,7 @@ pub const interrupt = struct {
357337
ppb.SHPR2.raw &= ~(@as(u32, 0xFF) << shift);
358338
ppb.SHPR2.raw |= @as(u32, @intFromEnum(priority)) << shift;
359339
},
360-
3 => {
340+
3 => {
361341
ppb.SHPR3.raw &= ~(@as(u32, 0xFF) << shift);
362342
ppb.SHPR3.raw |= @as(u32, @intFromEnum(priority)) << shift;
363343
},

core/src/mmio.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const std = @import("std");
22
const assert = std.debug.assert;
33

44
pub fn Mmio(comptime PackedT: type) type {
5-
65
@setEvalBranchQuota(2_000);
76

87
const size = @bitSizeOf(PackedT);

core/test/programs/uart-sync.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ pub fn main() !void {
6767
fn blinkError(led: anytype, err: microzig.uart.InitError) void {
6868
var blinks: u3 =
6969
switch (err) {
70-
error.UnsupportedBaudRate => 1,
71-
error.UnsupportedParity => 2,
72-
error.UnsupportedStopBitCount => 3,
73-
error.UnsupportedWordSize => 4,
74-
};
70+
error.UnsupportedBaudRate => 1,
71+
error.UnsupportedParity => 2,
72+
error.UnsupportedStopBitCount => 3,
73+
error.UnsupportedWordSize => 4,
74+
};
7575

7676
while (blinks > 0) : (blinks -= 1) {
7777
led.setToHigh();

examples/raspberrypi/rp2xxx/src/interrupts.zig

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,16 @@ const chip = rp2xxx.compatibility.chip;
1515
const timer = if (chip == .RP2040) peripherals.TIMER else peripherals.TIMER0;
1616
const timer_irq = if (chip == .RP2040) .TIMER_IRQ_0 else .TIMER0_IRQ_0;
1717

18-
1918
pub const rp2040_options: microzig.Options = .{
2019
.log_level = .debug,
2120
.logFn = rp2xxx.uart.logFn,
22-
.interrupts = .{
23-
.TIMER_IRQ_0 = .{ .c = timer_interrupt }
24-
},
21+
.interrupts = .{ .TIMER_IRQ_0 = .{ .c = timer_interrupt } },
2522
};
2623

2724
pub const rp2350_options: microzig.Options = .{
2825
.log_level = .debug,
2926
.logFn = rp2xxx.uart.logFn,
30-
.interrupts = .{
31-
.TIMER0_IRQ_0= .{ .c = timer_interrupt }
32-
},
27+
.interrupts = .{ .TIMER0_IRQ_0 = .{ .c = timer_interrupt } },
3328
};
3429

3530
pub const microzig_options = if (chip == .RP2040) rp2040_options else rp2350_options;

port/raspberrypi/rp2xxx/patches/rp2350.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ pub const patches: []const Patch = &.{
6464
.{ .set_enum_type = .{ .of = "types.peripherals.PADS_BANK0.GPIO45.DRIVE", .to = "types.peripherals.PADS_BANK0.DriveStrength" } },
6565
.{ .set_enum_type = .{ .of = "types.peripherals.PADS_BANK0.GPIO46.DRIVE", .to = "types.peripherals.PADS_BANK0.DriveStrength" } },
6666
.{ .set_enum_type = .{ .of = "types.peripherals.PADS_BANK0.GPIO47.DRIVE", .to = "types.peripherals.PADS_BANK0.DriveStrength" } },
67-
.{
68-
.add_enum = .{
67+
.{ .add_enum = .{
6968
.parent = "types.peripherals.USB_DPRAM",
7069
.@"enum" = .{
7170
.name = "EndpointType",

port/raspberrypi/rp2xxx/src/cpus/hazard3.zig

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub const interrupt = struct {
5858
csr.mstatus.clear(.{ .mie = 1 });
5959
}
6060

61-
pub const core = struct {
61+
pub const core = struct {
6262
pub fn is_enabled(comptime int: CoreInterrupt) bool {
6363
return csr.mie.read() & (1 << @intFromEnum(int)) != 0;
6464
}
@@ -258,7 +258,7 @@ pub const startup_logic = struct {
258258
@panic("unhandled core interrupt");
259259
}
260260

261-
pub export fn _vector_table() align(64) linksection("core_vectors") callconv(.naked) noreturn {
261+
pub export fn _vector_table() align(64) linksection("core_vectors") callconv(.naked) noreturn {
262262
comptime {
263263
// NOTE: using the union variant .naked here is fine because both variants have the same layout
264264
@export(if (microzig_options.interrupts.Exception) |handler| handler.naked else &unhandled_interrupt, .{ .name = "_exception_handler" });
@@ -301,7 +301,8 @@ pub const startup_logic = struct {
301301
// If it is not here the compiler fails to generate
302302
// the code that saves and restores the registers.
303303

304-
var x: i32 = 0; x += 1;
304+
var x: i32 = 0;
305+
x += 1;
305306
}
306307

307308
if (interrupt.has_ram_vectors()) {
@@ -321,9 +322,7 @@ pub const startup_logic = struct {
321322
\\
322323
\\no_more_irqs:
323324
);
324-
}
325-
else
326-
{
325+
} else {
327326
asm volatile (
328327
\\csrrsi a0, 0xbe4, 1
329328
\\bltz a0, no_more_irqs

0 commit comments

Comments
 (0)