Skip to content

Commit 6caa731

Browse files
committed
Regz: Fix embassy stride > 4
1 parent 82c7d8d commit 6caa731

3 files changed

Lines changed: 91 additions & 67 deletions

File tree

port/stmicro/stm32/src/hals/STM32F103/exti.zig

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,37 +69,37 @@ pub fn set_line(line: u4, port: gpio.Port) void {
6969
pub fn set_line_edge(line: u5, edge: TriggerEdge) void {
7070
switch (edge) {
7171
.None => {
72-
EXTI.RTSR.raw &= ~(@as(u32, 1) << line);
73-
EXTI.FTSR.raw &= ~(@as(u32, 1) << line);
72+
EXTI.@"RTSR[0]".raw &= ~(@as(u32, 1) << line);
73+
EXTI.@"FTSR[0]".raw &= ~(@as(u32, 1) << line);
7474
},
7575
.rising => {
76-
EXTI.RTSR.raw |= (@as(u32, 1) << line);
77-
EXTI.FTSR.raw &= ~(@as(u32, 1) << line);
76+
EXTI.@"RTSR[0]".raw |= (@as(u32, 1) << line);
77+
EXTI.@"FTSR[0]".raw &= ~(@as(u32, 1) << line);
7878
},
7979
.falling => {
80-
EXTI.RTSR.raw &= ~(@as(u32, 1) << line);
81-
EXTI.FTSR.raw |= (@as(u32, 1) << line);
80+
EXTI.@"RTSR[0]".raw &= ~(@as(u32, 1) << line);
81+
EXTI.@"FTSR[0]".raw |= (@as(u32, 1) << line);
8282
},
8383
.both => {
84-
EXTI.RTSR.raw |= (@as(u32, 1) << line);
85-
EXTI.FTSR.raw |= (@as(u32, 1) << line);
84+
EXTI.@"RTSR[0]".raw |= (@as(u32, 1) << line);
85+
EXTI.@"FTSR[0]".raw |= (@as(u32, 1) << line);
8686
},
8787
}
8888
}
8989

9090
pub fn set_event(line: u5, enable: bool) void {
9191
if (enable) {
92-
EXTI.EMR.raw |= (@as(u32, 1) << line);
92+
EXTI.@"EMR[0]".raw |= (@as(u32, 1) << line);
9393
} else {
94-
EXTI.EMR.raw &= ~(@as(u32, 1) << line);
94+
EXTI.@"EMR[0]".raw &= ~(@as(u32, 1) << line);
9595
}
9696
}
9797

9898
pub fn set_interrupt(line: u5, enable: bool) void {
9999
if (enable) {
100-
EXTI.IMR.raw |= (@as(u32, 1) << line);
100+
EXTI.@"IMR[0]".raw |= (@as(u32, 1) << line);
101101
} else {
102-
EXTI.IMR.raw &= ~(@as(u32, 1) << line);
102+
EXTI.@"IMR[0]".raw &= ~(@as(u32, 1) << line);
103103
}
104104
}
105105

@@ -111,9 +111,9 @@ pub inline fn software_trigger(line: u5) void {
111111

112112
///check for pending lines (for both events and interrupts)
113113
pub inline fn pending() pendingLine {
114-
return @bitCast(@as(u20, @intCast(EXTI.PR.raw)));
114+
return @bitCast(@as(u20, @intCast(EXTI.@"PR[0]".raw)));
115115
}
116116
///clears all pending lines returned by: `pending()`.
117117
pub inline fn clear_pending(pendings: pendingLine) void {
118-
EXTI.PR.raw = @as(u20, @bitCast(pendings));
118+
EXTI.@"PR[0]".raw = @as(u20, @bitCast(pendings));
119119
}

port/stmicro/stm32/src/hals/STM32L47X/lcd.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const LCD_RAM = extern struct {
2222
COM3H: LCD_COM_H,
2323
};
2424

25-
const ram: *volatile LCD_RAM = @ptrCast(&LCD.RAM_COM);
25+
// LCD RAM is not correctly define in the stm32-data from embassy
26+
// The high segment are inside a reserved space.
27+
const ram: *volatile LCD_RAM = @ptrCast(&LCD.@"RAM_COM[0]");
2628

2729
pub fn init_lcd() void {
2830
LCD.CR.modify(.{

tools/regz/src/embassy.zig

Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -306,32 +306,52 @@ pub fn load_into_db(db: *Database, path: []const u8, device: ?[]const u8) !void
306306
});
307307

308308
for (obj.object.get("items").?.array.items) |item| {
309+
var register_ids: std.ArrayList(Database.RegisterID) = .empty;
310+
defer register_ids.deinit(allocator);
309311
const register_name = item.object.get("name").?.string;
310312
const description: ?[]const u8 = if (item.object.get("description")) |desc| desc.string else null;
311313
const byte_offset = item.object.get("byte_offset").?.integer;
312314
const item_bit_size = if (item.object.get("bit_size")) |v| v.integer else 32;
313-
314-
const register_id = try db.create_register(group_id, .{
315-
.name = register_name,
316-
.description = description,
317-
.offset_bytes = @intCast(byte_offset),
318-
.size_bits = @intCast(item_bit_size),
319-
.count = if (item.object.get("array")) |array| blk: {
320-
if (array.object.get("len")) |count| {
321-
// ensure stride is always 4 for now, assuming that
322-
// it's in bytes
323-
const stride = array.object.get("stride").?.integer;
324-
if (stride != 4) {
325-
std.log.warn("ignoring register array with unsupported stride: {} != 4 for register {s} in {s} in {s}", .{ stride, register_name, key["block/".len..], name });
326-
break :blk null;
315+
const maybe_count: ?u64, const maybe_stride: ?u64 = if (item.object.get("array")) |array| blk: {
316+
if (array.object.get("len")) |count| {
317+
if (array.object.get("stride")) |stride| {
318+
if (stride.integer > 4) {
319+
break :blk .{ @intCast(count.integer), @intCast(stride.integer) };
327320
}
328-
329-
break :blk @intCast(count.integer);
330321
}
322+
break :blk .{ @intCast(count.integer), null };
323+
}
331324

332-
break :blk null;
333-
} else null,
334-
});
325+
break :blk .{ null, null };
326+
} else .{ null, null };
327+
328+
if (maybe_stride) |stride| {
329+
if (maybe_count) |count| {
330+
for (0..count) |id| {
331+
const register_part_name = try std.fmt.allocPrint(allocator, "{s}[{d}]", .{
332+
register_name,
333+
id,
334+
});
335+
const register_id = try db.create_register(group_id, .{
336+
.name = register_part_name,
337+
.description = description,
338+
.offset_bytes = @intCast(byte_offset + (id * stride)),
339+
.size_bits = @intCast(item_bit_size),
340+
.count = null,
341+
});
342+
try register_ids.append(allocator, register_id);
343+
}
344+
}
345+
} else {
346+
const register_id = try db.create_register(group_id, .{
347+
.name = register_name,
348+
.description = description,
349+
.offset_bytes = @intCast(byte_offset),
350+
.size_bits = @intCast(item_bit_size),
351+
.count = maybe_count,
352+
});
353+
try register_ids.append(allocator, register_id);
354+
}
335355

336356
if (item.object.get("fieldset")) |fieldset| blk: {
337357
const fieldset_key = try std.fmt.allocPrint(allocator, "fieldset/{s}", .{fieldset.string});
@@ -356,7 +376,7 @@ pub fn load_into_db(db: *Database, path: []const u8, device: ?[]const u8) !void
356376
// these are evenly spaced and much nicer to work with.
357377

358378
array_count = if (object_map.get("len")) |len| @intCast(len.integer) else null;
359-
array_stride = if (object_map.get("stride")) |stride| @intCast(stride.integer) else null;
379+
array_stride = if (object_map.get("stride")) |field_stride| @intCast(field_stride.integer) else null;
360380

361381
// This category where there is an array of items, but it is given by
362382
// individual offsets as opposed to a count + stride. This is used when strides are
@@ -365,30 +385,32 @@ pub fn load_into_db(db: *Database, path: []const u8, device: ?[]const u8) !void
365385
if (object_map.get("offsets")) |positions| {
366386
for (positions.array.items, 0..) |position, idx| {
367387
const field_name_irregular_stride = try std.fmt.allocPrint(allocator, "{s}[{}]", .{ field_name, idx });
368-
369-
try db.add_register_field(register_id, .{
370-
.name = field_name_irregular_stride,
371-
.description = field_description,
372-
.offset_bits = @intCast(position.integer + bit_offset),
373-
.size_bits = @intCast(bit_size),
374-
.enum_id = enum_id,
375-
.count = null,
376-
.stride = null,
377-
});
388+
for (register_ids.items) |register_id| {
389+
try db.add_register_field(register_id, .{
390+
.name = field_name_irregular_stride,
391+
.description = field_description,
392+
.offset_bits = @intCast(position.integer + bit_offset),
393+
.size_bits = @intCast(bit_size),
394+
.enum_id = enum_id,
395+
.count = null,
396+
.stride = null,
397+
});
398+
}
378399
}
379400
continue :next_field;
380401
}
381402
}
382-
383-
try db.add_register_field(register_id, .{
384-
.name = field_name,
385-
.description = field_description,
386-
.offset_bits = @intCast(bit_offset),
387-
.size_bits = @intCast(bit_size),
388-
.enum_id = enum_id,
389-
.count = array_count,
390-
.stride = array_stride,
391-
});
403+
for (register_ids.items) |register_id| {
404+
try db.add_register_field(register_id, .{
405+
.name = field_name,
406+
.description = field_description,
407+
.offset_bits = @intCast(bit_offset),
408+
.size_bits = @intCast(bit_size),
409+
.enum_id = enum_id,
410+
.count = array_count,
411+
.stride = array_stride,
412+
});
413+
}
392414
},
393415
.array => |arr| {
394416
// This case is for discontinuous fields where the first few bits are
@@ -411,18 +433,19 @@ pub fn load_into_db(db: *Database, path: []const u8, device: ?[]const u8) !void
411433
var array_stride: ?u8 = null;
412434
if (field.object.get("array")) |array| {
413435
array_count = if (array.object.get("len")) |len| @intCast(len.integer) else null;
414-
array_stride = if (array.object.get("stride")) |stride| @intCast(stride.integer) else null;
436+
array_stride = if (array.object.get("stride")) |field_stride| @intCast(field_stride.integer) else null;
437+
}
438+
for (register_ids.items) |register_id| {
439+
try db.add_register_field(register_id, .{
440+
.name = non_contiguous_field_name,
441+
.description = field_description,
442+
.offset_bits = @intCast(bit_offset),
443+
.size_bits = @intCast(bit_size),
444+
.enum_id = enum_id,
445+
.count = array_count,
446+
.stride = array_stride,
447+
});
415448
}
416-
417-
try db.add_register_field(register_id, .{
418-
.name = non_contiguous_field_name,
419-
.description = field_description,
420-
.offset_bits = @intCast(bit_offset),
421-
.size_bits = @intCast(bit_size),
422-
.enum_id = enum_id,
423-
.count = array_count,
424-
.stride = array_stride,
425-
});
426449
}
427450
},
428451
else => |val| {
@@ -603,4 +626,3 @@ const std = @import("std");
603626
const Database = @import("Database.zig");
604627
const Arch = @import("arch.zig").Arch;
605628
const arm = @import("arch/arm.zig");
606-
const FS_Directory = @import("FS_Directory.zig");

0 commit comments

Comments
 (0)