Skip to content

Expose DelayHelper as a public timing API in the Iot.Device namespace#2585

Draft
raffaeler with Copilot wants to merge 3 commits into
mainfrom
copilot/make-delayhelper-part-of-system-device-gpio
Draft

Expose DelayHelper as a public timing API in the Iot.Device namespace#2585
raffaeler with Copilot wants to merge 3 commits into
mainfrom
copilot/make-delayhelper-part-of-system-device-gpio

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Binding authors had no public high-precision wait primitive in the .NET IoT libraries and were forced to roll their own. Per the issue triage, DelayHelper is promoted to public API in Iot.Device.Bindings, with the millisecond overload kept out of the public surface.

Changes

  • DelayHelpernamespace Iot.Device, made public (DelayHelper.cs, ClassVisibility.cs). Delay(TimeSpan, bool) and DelayMicroseconds(int, bool) are the public surface.
  • DelayMilliseconds stays out of the shipped API. It compiles as internal in the packaged build (guarded by #if BUILDING_IOT_DEVICE_BINDINGS) and remains public in standalone device builds, where Common is a separate assembly — so existing callers keep working. Millisecond-scale waits should prefer Thread.Sleep.
  • Caller fix-up: all existing callers under Iot.Device.* resolve the type via the enclosing namespace unchanged; only SoftwarePwmChannel (in System.Device.Pwm.Drivers) needed an added using Iot.Device;.
  • Tests: added DelayHelperTest covering the guaranteed lower-bound wait for Delay and DelayMicroseconds.

Usage

using Iot.Device;

_controller.Write(_trigger, PinValue.High);
DelayHelper.DelayMicroseconds(10, allowThreadYield: true);
_controller.Write(_trigger, PinValue.Low);

Notes for reviewers

  • The namespace follows @Ellerbach's triage note (Iot.Device); the package location and internal-milliseconds constraint follow @krwq's. Confirm this split is the intended final shape.
  • Renaming Iot.Device.CommonIot.Device (mentioned in triage for the weather helper) is intentionally out of scope here.

@dotnet-policy-service dotnet-policy-service Bot added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Jul 1, 2026
Copilot AI changed the title [WIP] Add DelayHelper API to System.Device.Gpio Expose DelayHelper as a public timing API in the Iot.Device namespace Jul 1, 2026
Copilot AI requested a review from raffaeler July 1, 2026 14:37
using System.Threading;

namespace System.Device
namespace Iot.Device

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot changing the namespace without moving the helper in the other assembly raise a problem in terms of binary compatibility for the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — once Iot.Device.DelayHelper ships as public API of Iot.Device.Bindings, it's locked into that assembly. It can't be forwarded to System.Device.Gpio later (the dependency runs the other way, and the namespace differs), so honoring the original issue ("part of System.Device.Gpio") would then be a binary-breaking change.

The clean fix is to give it its permanent home now, before it's public: move DelayHelper into the System.Device.Gpio project with the System.Device namespace (where it already lives today), and drop the namespace change to Iot.Device. That does conflict with the earlier triage note to keep it in Iot.Device.Bindings, so I don't want to move assemblies unilaterally.

Which assembly should be the final home — System.Device.Gpio (matches the issue, avoids the compat trap) or Iot.Device.Bindings (earlier triage)? I'll implement whichever you confirm.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raffaeler As we don't have any plans in moving stuff from Iot.Device.Bindings to System.Device in the near future, I guess the Iot.Device namespace is the better one for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make DelayHelper or similar API part of System.Device.Gpio

3 participants