rust-embedded / embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Apache License 2.0
2.01k stars 201 forks source link

Tracking issue for watchdog traits #360

Open eldruin opened 2 years ago

eldruin commented 2 years ago

The watchdog traits available on the 0.2.x versions have been removed ahead of the 1.0.0 release. See: #357 This issue servers as a tracking issue until we add them back. The open (breaking) problems should be reasonably-well solved and all associated types should have appropriate bounds that enable generic code use.

Timer traits as of the 0.2.7 release:

Relevant issues/PRs:

Please feel free to participate, highlight your current use cases, problems and provide solutions.

Dirbaio commented 2 years ago

What's the use case for a HAL-independent watchdog trait?

HAL-independent drivers for external chips have no use for the watchdog.

Watchdog is something inherently MCU-wide (it forces a whole MCU reset when expired). Therefore, it's something that the main bin crate will do. In the main binary, you know which HAL you're using, so you can just use a HAL-specific API (inherent methods, no trait).

eldruin commented 2 years ago

While not the primary goal of this crate, in my opinion it is also useful if embedded-hal provides unified interfaces across the ecosystem for very common peripherals, where it makes sense. It should be noted that these traits are implemented in many HALs, including all(?) stm32 HALs, atsamd, esp8266 and esp32, so people must have seen some value on them as well.

Dirbaio commented 2 years ago

HALs implement the traits to tick boxes. "The chip has a watchdog and EH has a watchdog trait, so I should impl it". Then users use it because many HALs don't offer an API with inherent methods at all.

There's no HAL independent code out there using the traits.

Also, I would argue the traits are failing at providing a unified API as well: