add hal or app level clock configuration (#62)

* add hal or app level clock configuration

* fix control flow and typo

* use hal.init(), thanks kuon for the improvement
wch-ch32v003
Matt Knight 2 years ago committed by GitHub
parent e6d6ca7092
commit 6bc3fc094b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -176,6 +176,15 @@ export fn microzig_main() noreturn {
if (info.Fn.calling_convention == .Async) if (info.Fn.calling_convention == .Async)
@compileError("TODO: Embedded event loop not supported yet. Please try again later."); @compileError("TODO: Embedded event loop not supported yet. Please try again later.");
// A hal can export a default init function that runs before main for
// procedures like clock configuration. The user may override and customize
// this functionality by providing their own init function.
// function.
if (@hasDecl(app, "init"))
app.init()
else if (@hasDecl(hal, "init"))
hal.init();
if (@typeInfo(return_type) == .ErrorUnion) { if (@typeInfo(return_type) == .ErrorUnion) {
main() catch |err| { main() catch |err| {
// TODO: // TODO:

@ -160,12 +160,13 @@ pub fn addEmbeddedExecutable(
exe.addPackage(chip_pkg); exe.addPackage(chip_pkg);
exe.addPackage(cpu_pkg); exe.addPackage(cpu_pkg);
if (options.hal_package_path) |hal_package_path| exe.addPackage(.{
exe.addPackage(.{ .name = "hal",
.name = "hal", .source = if (options.hal_package_path) |hal_package_path|
.source = hal_package_path, hal_package_path
.dependencies = &.{pkgs.microzig}, else .{ .path = root_path ++ "core/empty.zig" },
}); .dependencies = &.{pkgs.microzig},
});
switch (backing) { switch (backing) {
.board => |board| { .board => |board| {

Loading…
Cancel
Save