Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

drivers: `I2C_Device.Address.check_reserved` rejects 0x08-0x0F and accepts 0x04-0x07 (HighSpeedMaster range is off by one bit)

Đang mở Phù hợp với người mới
#1,085 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
69/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
zig
Lĩnh vực
embedded-iot

Hướng nghiên cứu

Bắt đầu tại drivers/src/base/I2C_Device.zig, ở Address.check_reserved, rồi đọc bảng kiểm thử hiện có trong cùng tệp. Issue nêu các dải địa chỉ sai và được mong đợi, cùng cách tái hiện chỉ trên host. Cập nhật kiểm tra dải địa chỉ và các kỳ vọng trong kiểm thử, sau đó chạy cách tái hiện hoặc zig build test từ drivers/; hoàn tất khi 0x04–0x07 bị từ chối và 0x08–0x0F được chấp nhận.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

Address.check_reserved (drivers/src/base/I2C_Device.zig:55 on master) returns
error.HighSpeedMaster for 0b0001000...0b0001111 (0x08-0x0F). The Hs-mode
controller code is 0000 1XX, i.e. 0x04-0x07 — the page the doc comment links
(https://www.i2c-bus.org/addressing/ lists 00001XX X as "High-Speed Master
Code"), and the doc comment itself: "Reserved addresses are ones that match
0b0000XXX or 0b1111XXX"
. So:

  • 0x08-0x0F, ordinary 7-bit addresses, are refused. Through the rp2xxx HAL every
    read (.dont_allow_reserved) returns error.IllegalAddress for them before
    anything reaches the bus. A bus scan that starts at 0x08 (the usual first
    address) sees an error rather than a NACK at its first address. The same check runs
    in the nrf5x, stm32 (i2c_v2) and espressif HALs. Real parts live at these
    addresses. One is the AK09916 magnetometer at 0x0C: the in-tree ICM_20948
    driver names it MAG_ADDRESS = 0x0C. That driver reaches it through the ICM's own
    aux I2C master, so it is unaffected, but on a board that wires the AK09916 straight
    to the host bus the HAL refuses its address.
  • 0x04-0x07, the reserved Hs-mode codes, are accepted.

It is a regression from #648 (c058aa4, 2025-08-16). The bool version it
replaced was ((value & 0x78) == 0) or ((value & 0x78) == 0x78), which was right.
When that became a switch, 0000 1XX was written as 0001 XXX, and the new test table
encoded the same values (0x08 and 0x0F expect HighSpeedMaster).

Versions
tree toolchain result
microzig 0.15.1 release (mz_drivers-0.0.1-bvRa3F…) zig 0.15.2 reproduces (rc=1)
microzig master f36d59fb7b22 (tag 0.17.17, 2026-10-10) zig 0.17.0 reproduces (rc=1)
master + the fix below zig 0.17.0 fixed (rc=0)
Repro (host-only, no hardware)

repro.zig:

const std = @import("std");
const Address = @import("I2C_Device").Address;

fn reserved(a: u7) bool {
    const addr: Address = @enumFromInt(a);
    addr.check_reserved() catch return true;
    return false;
}

test "0x04-0x07 (0000 1XX, Hs-mode controller code) are reserved" {
    for ([_]u7{ 0x04, 0x05, 0x06, 0x07 }) |a| try std.testing.expect(reserved(a));
}

test "0x08-0x0F are ordinary addresses" {
    for ([_]u7{ 0x08, 0x09, 0x0C, 0x0F }) |a| try std.testing.expect(!reserved(a));
}
zig test repro.zig --dep I2C_Device -Mroot=repro.zig -MI2C_Device=<microzig>/drivers/src/base/I2C_Device.zig

Expected: both tests pass.
Actual (master f36d59f, zig 0.17.0):

1/2 repro.test.0x04-0x07 (0000 1XX, Hs-mode controller code) are reserved...0x04 accepted, expected reserved
FAIL (TestUnexpectedResult)
2/2 repro.test.0x08-0x0F are ordinary addresses...0x08 rejected, expected usable
FAIL (TestUnexpectedResult)
0 passed; 0 skipped; 2 failed.
Fix

One switch arm, plus the two test-table rows that encoded the wrong range:

-            0b0001000...0b0001111 => return Address.Error.HighSpeedMaster,
+            0b0000100...0b0000111 => return Address.Error.HighSpeedMaster,

and the existing test in the same file now expects HighSpeedMaster at 0x04/0x07 and
"valid" at 0x08/0x0F. With the patch, zig build test in drivers/ gives
123/123 tests passed (rc=0), the same count as unpatched master. The repro above
passes.

Behaviour change worth a line in the release notes: callers that pass 0x04-0x07
with .dont_allow_reserved / .allow_general now get IllegalAddress, and
0x08-0x0F start working.

I have the patch ready and can open it as a PR if you'd like.

Ngôn ngữ chính
Zig
Star
2.3k
Fork
198
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
37

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ZigEmbeddedGroup/microzig

Tất cả issue của ZigEmbeddedGroup/microzig

Issue tương tự

Thêm issue về Embedded & IoT

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.