Skip to content

Commit 52f1014

Browse files
committed
Update almost all rp2xxx examples
- Update uart Writer and Reader to writergate
1 parent e94cce5 commit 52f1014

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+243
-108
lines changed

core/src/core/usb.zig

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub fn validate_controller(T: type) void {
231231
/// Responds to host requests and dispatches to the appropriate drivers.
232232
/// When this type is build (at comptime), it builds descriptor and handler tables based on the
233233
/// provided config.
234-
pub fn DeviceController(config: Config, driver_args: config.DriverArgs()) type {
234+
pub fn DeviceController(comptime config: Config, comptime driver_args: config.DriverArgs()) type {
235235
std.debug.assert(config.configurations.len == 1);
236236

237237
return struct {
@@ -347,11 +347,9 @@ pub fn DeviceController(config: Config, driver_args: config.DriverArgs()) type {
347347
field_attrs[drv_id] = .{ .default_value_ptr = &descriptors };
348348
}
349349

350-
// Finally, bind the handler functions based on the data collected above.
351-
const Tuple = std.meta.Tuple;
352350
// Create a tuple with the appropriate types
353-
const ep_handlers_types: [2]type = .{ Tuple(&ep_handler_types[0]), Tuple(&ep_handler_types[1]) };
354-
var ep_handlers: Tuple(&ep_handlers_types) = undefined;
351+
const ep_handlers_types: [2]type = .{ @Tuple(&ep_handler_types[0]), @Tuple(&ep_handler_types[1]) };
352+
var ep_handlers: @Tuple(&ep_handlers_types) = undefined;
355353
// Iterate over all IN and OUT endpoints and bind the handler for any that are set.
356354
for (&ep_handler_types, &ep_handler_names, &ep_handler_drivers, 0..) |htypes, hnames, hdrivers, dir| {
357355
for (&htypes, &hnames, &hdrivers, 0..) |T, name, drv_id, ep| {
@@ -363,25 +361,34 @@ pub fn DeviceController(config: Config, driver_args: config.DriverArgs()) type {
363361
const DriverConfig = @Struct(.@"extern", null, &field_names, &field_types, &field_attrs);
364362
const idx_in = @intFromEnum(types.Dir.In);
365363
const idx_out = @intFromEnum(types.Dir.Out);
364+
365+
const ConfigDescriptor = extern struct {
366+
first: descriptor.Configuration,
367+
drv: DriverConfig,
368+
};
369+
const Handlers_EP = struct {
370+
In: ep_handlers_types[idx_in],
371+
Out: ep_handlers_types[idx_out],
372+
};
366373
break :blk .{
367374
.device_descriptor = desc_device,
368-
.config_descriptor = extern struct {
369-
first: descriptor.Configuration = .{
375+
.config_descriptor = ConfigDescriptor{
376+
.first = .{
370377
.total_length = .from(size),
371378
.num_interfaces = alloc.next_itf_num,
372379
.configuration_value = 1,
373380
.configuration_s = configuration_s,
374381
.attributes = config0.attributes,
375382
.max_current = .from_ma(config0.max_current_ma),
376383
},
377-
drv: DriverConfig = .{},
378-
}{},
384+
.drv = .{},
385+
},
379386
.string_descriptors = alloc.string_descriptors(config.language),
380387
.handlers_itf = itf_handlers,
381-
.handlers_ep = struct {
382-
In: ep_handlers_types[idx_in] = ep_handlers[idx_in],
383-
Out: ep_handlers_types[idx_out] = ep_handlers[idx_out],
384-
}{},
388+
.handlers_ep = Handlers_EP{
389+
.In = ep_handlers[idx_in],
390+
.Out = ep_handlers[idx_out],
391+
},
385392
.drivers_ep = ep_handler_drivers,
386393
.DriverAlloc = @Struct(
387394
.auto,

core/src/cpus/cortex_m.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ const Core = enum {
1616
cortex_m7,
1717
};
1818

19-
const cortex_m = std.meta.stringToEnum(Core, microzig.config.cpu_name) orelse
19+
const cortex_m = if (@hasField(Core, microzig.config.cpu_name))
20+
@field(Core, microzig.config.cpu_name)
21+
else
2022
@compileError(std.fmt.comptimePrint("Unrecognized Cortex-M core name: {s}", .{microzig.config.cpu_name}));
2123

2224
/// Segger's RTT support
@@ -81,7 +83,7 @@ pub const ExternalInterrupt = blk: {
8183
}
8284
}
8385

84-
break :blk @Enum(u8, .exhaustive, field_names, field_values);
86+
break :blk @Enum(u8, .exhaustive, &field_names, &field_values);
8587
};
8688

8789
/// Machine exceptions.

drivers/base/DateTime.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ pub const Timezone = enum(i16) {
343343
/// * `separator` - An optional separator to add between the hours and minutes
344344
/// defaults to ":" if null
345345
pub fn to_string(self: Timezone, out_string: []u8, separator: ?[]const u8) Error!usize {
346-
if (out_string.len < 5 + (separator orelse ":").len) return error.NotEnoughSpace;
346+
if (out_string.len < 5 + if (separator) |sep| sep.len else 1) return error.NotEnoughSpace;
347347

348348
const minus = @intFromEnum(self) < 0;
349349

examples/espressif/esp/build.zig.zon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.{
22
.name = .examples_espressif_esp,
33
.fingerprint = 0xa568458fa3375cb1,
4+
.minimum_zig_version = "0.16.0",
45
.version = "0.0.0",
56
.dependencies = .{
67
.microzig = .{ .path = "../../.." },

examples/raspberrypi/rp2xxx/build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub fn build(b: *std.Build) void {
7272
.{ .name = "pwm", .file = "src/pwm.zig" },
7373
.{ .name = "uart-echo", .file = "src/uart_echo.zig" },
7474
.{ .name = "uart-log", .file = "src/uart_log.zig" },
75+
.{ .name = "uart-reader-writer", .file = "src/uart_reader_writer.zig" },
7576
.{ .name = "rtt-log", .file = "src/rtt_log.zig", .works_with_riscv = false },
7677
.{ .name = "spi-master", .file = "src/spi_master.zig" },
7778
.{ .name = "spi-slave", .file = "src/spi_slave.zig" },

examples/raspberrypi/rp2xxx/build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.{
22
.name = .examples_raspberrypi_rp2xxx,
33
.fingerprint = 0xffa4bfa151162a57,
4-
.minimum_zig_version = "0.15.1",
4+
.minimum_zig_version = "0.16.0",
55
.version = "0.0.0",
66
.dependencies = .{
77
.microzig = .{ .path = "../../.." },

examples/raspberrypi/rp2xxx/src/adc.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn main() !void {
2020
uart.apply(.{
2121
.clock_config = rp2xxx.clock_config,
2222
});
23-
rp2xxx.uart.init_logger(uart);
23+
rp2xxx.uart.init_logger(uart, &.{});
2424

2525
adc.apply(.{
2626
.temp_sensor_enabled = true,

examples/raspberrypi/rp2xxx/src/allocator.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn main() !void {
5555

5656
// --- Set up Logger -----------------------------
5757

58-
hal.uart.init_logger(uart);
58+
hal.uart.init_logger(uart, &.{});
5959

6060
time.sleep_ms(1000);
6161

examples/raspberrypi/rp2xxx/src/board_id.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn main() !void {
2626
uart.apply(.{
2727
.clock_config = rp2xxx.clock_config,
2828
});
29-
rp2xxx.uart.init_logger(uart);
29+
rp2xxx.uart.init_logger(uart, &.{});
3030

3131
while (true) {
3232
log.info("unique board id: {x}", .{rp2xxx.get_board_id()});

examples/raspberrypi/rp2xxx/src/cyw43.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn main() !void {
2727
uart.apply(.{
2828
.clock_config = rp2xxx.clock_config,
2929
});
30-
rp2xxx.uart.init_logger(uart);
30+
rp2xxx.uart.init_logger(uart, &.{});
3131

3232
// init cyw43
3333
var wifi = try wifi_driver.init(.{});

0 commit comments

Comments
 (0)