Skip to content
Open
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
2 changes: 2 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Files:
examples/i2c_bus_scan/build.zig.zon
examples/serial/build.zig.zon
examples/timer/build.zig.zon
examples/gpio/build.zig.zon
examples/blk/build.zig.zon
examples/blk/basic_data.txt
examples/blk/basic_data.h
Expand Down Expand Up @@ -42,6 +43,7 @@ Files:
drivers/timer/bcm2835/config.json
drivers/timer/apb_timer/config.json
drivers/timer/rk3568/config.json
drivers/gpio/imx/config.json
Copyright: UNSW
License: BSD-2-Clause

Expand Down
47 changes: 47 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const DriverClass = struct {
rk3568,
};

const Gpio = enum {
imx,
meson,
};

const Network = enum {
imx,
meson,
Expand Down Expand Up @@ -186,6 +191,35 @@ fn addTimerDriver(
return driver;
}

fn addGpioDriver(
b: *std.Build,
gpio_config_include: LazyPath,
util: *std.Build.Step.Compile,
class: DriverClass.Gpio,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
) *std.Build.Step.Compile {
const driver = addPd(b, .{
.name = b.fmt("driver_gpio_{s}.elf", .{@tagName(class)}),
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.strip = false,
}),
});
const source = b.fmt("drivers/gpio/{s}/gpio.c", .{@tagName(class)});
driver.addCSourceFile(.{
.file = b.path(source),
});
driver.addIncludePath(gpio_config_include);

driver.addIncludePath(b.path("include"));
driver.addIncludePath(b.path("include/microkit"));
driver.linkLibrary(util);

return driver;
}

fn addI2cDriverDevice(
b: *std.Build,
util: *std.Build.Step.Compile,
Expand Down Expand Up @@ -482,6 +516,13 @@ pub fn build(b: *std.Build) !void {
// debug error if you do need a serial config but forgot to pass one in.
const gpu_config_include = LazyPath{ .cwd_relative = gpu_config_include_option };

const gpio_config_include_option = b.option([]const u8, "gpio_config_include", "Include path to gpio config header") orelse "";

// TODO: So ideally this is part of the meta.py file
// for now we have a config file that defines which gpio/irq is assigned to
// all of the driver channels in the gpio driver.
const gpio_config_include = LazyPath{ .cwd_relative = gpio_config_include_option };

// Util libraries
const util = b.addLibrary(.{
.name = "util",
Expand Down Expand Up @@ -698,6 +739,12 @@ pub fn build(b: *std.Build) !void {
libi2c_raw.addIncludePath(libmicrokit_include);
libi2c_raw.linkLibrary(util);
b.installArtifact(libi2c_raw);
// Gpio drivers
inline for (std.meta.fields(DriverClass.Gpio)) |class| {
const driver = addGpioDriver(b, gpio_config_include, util, @enumFromInt(class.value), target, optimize);
driver.linkLibrary(util_putchar_debug);
b.installArtifact(driver);
}

// I2C components
const i2c_virt = addPd(b, .{
Expand Down
39 changes: 39 additions & 0 deletions ci/examples/gpio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
# Copyright 2026, UNSW
# SPDX-License-Identifier: BSD-2-Clause

import asyncio
from pathlib import Path
import sys

sys.path.insert(1, Path(__file__).parents[2].as_posix())

from ci.lib.backends import *
from ci.lib.runner import run_single_example, matrix_product
from ci.common import TestConfig
from ci import common, matrix

TEST_MATRIX = matrix_product(
example=["gpio"],
board=matrix.EXAMPLES["gpio"]["boards_test"],
config=matrix.EXAMPLES["gpio"]["configs"],
build_system=matrix.EXAMPLES["gpio"]["build_systems"],
)


def backend_fn(test_config: TestConfig, loader_img: Path) -> HardwareBackend:
backend = common.backend_fn(test_config, loader_img)
return backend


async def test(backend: HardwareBackend, test_config: TestConfig):
async with asyncio.timeout(60):
await wait_for_output(backend, b" ... is present!\r\n")


if __name__ == "__main__":
run_single_example(
test,
TEST_MATRIX,
backend_fn,
)
11 changes: 10 additions & 1 deletion ci/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: BSD-2-Clause

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Literal, TypedDict

NO_OUTPUT_DEFAULT_TIMEOUT_S: int = 60
Expand All @@ -29,7 +30,7 @@
"hifive_p550": dict(uboot_image_started=b"Starting kernel ..."),
}

EXAMPLES: dict[str, _ExampleMatrixType] = {
EXAMPLES: dict[Literal[str], _ExampleMatrixType] = {
"blk": {
"configs": ["debug", "release"],
"build_systems": ["make", "zig"],
Expand Down Expand Up @@ -89,6 +90,14 @@
"star64",
],
},
"gpio": {
"configs": ["debug", "release", "benchmark"],
"build_systems": ["make", "zig"],
"boards_build": [
"maaxboard",
],
"boards_test": [],
},
"serial": {
"configs": ["debug", "release"],
"build_systems": ["make", "zig"],
Expand Down
26 changes: 26 additions & 0 deletions drivers/gpio/imx/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compatible": [
"fsl,imx8mq-gpio",
"fsl,imx35-gpio"
],
"resources": {
"regions": [
{
"name": "regs",
"perms": "rw",
"size": 65536,
"dt_index": 0
}
],
"irqs": [
{
"dt_index": 0,
"channel_id": 60
},
{
"dt_index": 1,
"channel_id": 61
}
]
}
}
Loading
Loading