feat: I2C (host mode) driver implementation and host unit tests #81

Closed
opened 2026-07-23 12:02:53 +00:00 by hoogv · 0 comments
Owner

Description

Adds hal/mss/i2c_host/hal_i2c_host.c/.h — the I2C driver: prescaler/clock derivation (TRM-derived module-clock search + ICCL/ICCH split), blocking write/read with per-byte and transfer-complete poll loops, NACK/arbitration-lost error reporting, and the IRQ handler decoding ICSTR to a weak, application-overridable hal_i2c_host_irq_handler() hook.

Use Case / Rationale

As a firmware developer, I need a hal_i2c_host_* API for blocking I2C transfers and clock configuration, following the same driver pattern established by GPIO (#75), ESM (#77), and UART (#79).

As a QMS reviewer, I need the clock-prescaler derivation cross-checked against an independent source, the same rigor already applied to UART's baud formula.

User Stories

  • As a developer, I want hal_i2c_host_init() to derive ICPSC/ICCLKL/ICCLKH from a peripheral clock and target SCL frequency instead of hand-computing the TRM formula myself.
  • As a developer, I want hal_i2c_host_write_blocking()/hal_i2c_host_read_blocking() to report NACK/arbitration-lost/timeout distinctly rather than a generic failure.
  • As a QMS reviewer, I want a host-native Catch2 test suite (testing/mss/unit/hal_functionality/test_i2c_host.c) covering the clock derivation, both transfer directions, and error paths, runnable in CI without target hardware.

Acceptance Criteria

  • hal/mss/i2c_host/hal_i2c_host.c/.h implemented against this project's current hal/registers/component/i2c.h/instance/i2c.h
  • testing/mss/unit/hal_functionality/test_i2c_host.c passes under ctest
  • Sanity-checked by deliberately breaking the clock-divisor formula and confirming the test suite catches it, then reverting

Functional Impact

None — self-contained addition alongside the already-landed GPIO/ESM/UART drivers.

Regulatory Impact

None

QMS Impact

None

Risk Impact

No — existing risk coverage sufficient.

Relates to #4, relates to #75, relates to #77, relates to #79

### Description Adds `hal/mss/i2c_host/hal_i2c_host.c`/`.h` — the I2C driver: prescaler/clock derivation (TRM-derived module-clock search + ICCL/ICCH split), blocking write/read with per-byte and transfer-complete poll loops, NACK/arbitration-lost error reporting, and the IRQ handler decoding `ICSTR` to a weak, application-overridable `hal_i2c_host_irq_handler()` hook. ### Use Case / Rationale As a firmware developer, I need a `hal_i2c_host_*` API for blocking I2C transfers and clock configuration, following the same driver pattern established by GPIO (#75), ESM (#77), and UART (#79). As a QMS reviewer, I need the clock-prescaler derivation cross-checked against an independent source, the same rigor already applied to UART's baud formula. ### User Stories - As a developer, I want `hal_i2c_host_init()` to derive `ICPSC`/`ICCLKL`/`ICCLKH` from a peripheral clock and target SCL frequency instead of hand-computing the TRM formula myself. - As a developer, I want `hal_i2c_host_write_blocking()`/`hal_i2c_host_read_blocking()` to report NACK/arbitration-lost/timeout distinctly rather than a generic failure. - As a QMS reviewer, I want a host-native Catch2 test suite (`testing/mss/unit/hal_functionality/test_i2c_host.c`) covering the clock derivation, both transfer directions, and error paths, runnable in CI without target hardware. ### Acceptance Criteria - [x] `hal/mss/i2c_host/hal_i2c_host.c`/`.h` implemented against this project's current `hal/registers/component/i2c.h`/`instance/i2c.h` - [x] `testing/mss/unit/hal_functionality/test_i2c_host.c` passes under `ctest` - [x] Sanity-checked by deliberately breaking the clock-divisor formula and confirming the test suite catches it, then reverting ### Functional Impact None — self-contained addition alongside the already-landed GPIO/ESM/UART drivers. ### Regulatory Impact None ### QMS Impact None ### Risk Impact No — existing risk coverage sufficient. ### Related Issues / PRs Relates to #4, relates to #75, relates to #77, relates to #79
hoogv closed this issue 2026-07-23 12:41:40 +00:00
hoogv added this to the Development project 2026-07-23 13:31:25 +00:00
hoogv self-assigned this 2026-07-23 13:32:15 +00:00
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
opendutchsolutions.public/hal_awr6843#81
No description provided.