Skip to content
Back to skills

Embedded Hal Knowledge Patch

ASecurity

embedded-hal

  • 25 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 1, 2026
developmentrustgogitapi

Works with

  • api

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill embedded-hal-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Embedded Hal Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Embedded Hal Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-embedded-hal-knowledge-patch/badge)](https://www.skillsdirectory.com/skills/nevaberry-embedded-hal-knowledge-patch)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: embedded-hal-knowledge-patch
description: embedded-hal
version: "1.0.0"
license: MIT
metadata:
  author: Nevaberry
---


# embedded-hal compatibility guidance

Load this skill when migrating peripheral trait imports or implementing generic
drivers, peripheral transactions, or shared bus access with the embedded-hal crates.

## Reference index

| Reference | Topics |
| --- | --- |
| [Trait migration and peripheral APIs](references/trait-migration.md) | Import paths, digital pins and waits, delays, PWM, removed traits, errors, reference blanket implementations, Rust requirements |
| [SPI and I2C transactions](references/transactions.md) | Device transactions, raw bus completion, I2C defaults, buffer slices, transaction examples |
| [Bus adapters and sharing](references/bus-sharing.md) | Dedicated and shared buses, atomic support, reference-counted handles, bus errors, Rust requirement |

## Breaking changes and migration

### Choose the trait crate and import path

Blocking traits live directly under their peripheral modules, for example
`embedded_hal::i2c::I2c`; the old `::blocking` path segment was removed.

Use `embedded-hal-async` for native async traits and `embedded-hal-nb` for
nonblocking traits.

### Update digital pin receivers and toggling

`InputPin::is_high()` and `is_low()`, and `StatefulOutputPin::is_set_high()`
and `is_set_low()`, take `&mut self`.

Use `StatefulOutputPin::toggle()` in place of the removed
`ToggleableOutputPin` trait.

### Consolidate I2C operations

The blocking and async `I2c` traits consolidate the old separate traits around
`transaction()`, which supplies defaults for `read()`, `write()`, and
`write_read()`. Use buffer slices in place of the removed iterator-based methods.

### Replace the old PWM traits

The old `Pwm` and `PwmPin` traits were removed. Generic drivers can use
`pwm::SetDutyCycle` for duty-cycle control and read the limit with
`max_duty_cycle()`.

### Locate relocated traits and recognize removals

Blocking and async UART byte streams use `embedded-io`. CAN traits live in
`embedded-can`.

The core HAL removed these peripheral traits:

- ADC `OneShot` and `Channel`.
- `IoPin`.
- `capture::Capture` and `qei::Qei`.
- `timer::{Cancel, CountDown, Periodic}`.
- `watchdog::{Disable, Enable, Watchdog}`.

### Check crate-specific Rust requirements

| Crate | Minimum Rust version |
| --- | --- |
| `embedded-hal` | 1.60.0 |
| `embedded-hal-async` | 1.75 on stable; uses native async trait methods |
| `embedded-hal-bus` | 1.81 |

## SPI and I2C quick reference

### Keep chip select asserted for a device transaction

A driver that selects its peripheral with chip select can take a `SpiDevice`.
Its `transaction()` holds the bus and keeps chip select asserted across a slice
of operations.

```rust
use embedded_hal::spi::{Operation, SpiDevice};

fn read_register<S: SpiDevice<u8>>(
    device: &mut S,
    command: u8,
    turnaround_ns: u32,
    data: &mut [u8],
) -> Result<(), S::Error> {
    device.transaction(&mut [
        Operation::Write(&[command]),
        Operation::DelayNs(turnaround_ns),
        Operation::Read(data),
    ])
}
```

### Wait for raw SPI completion

A `SpiBus` operation can return before the hardware finishes clocking out data.
Call `flush()` to wait for completion before deasserting a manually controlled
chip-select pin.

### Use an I2C transaction

```rust
use embedded_hal::i2c::{I2c, Operation};

fn read_register<I: I2c>(
    bus: &mut I,
    address: u8,
    register: u8,
    data: &mut [u8],
) -> Result<(), I::Error> {
    bus.transaction(address, &mut [Operation::Write(&[register]), Operation::Read(data)])
}
```

## Peripheral and generic-driver quick reference

### Wait for an interrupt pin asynchronously

A generic async driver can bound its interrupt pin by
`embedded_hal_async::digital::Wait`. Use `irq.wait_for_high().await?` or
`irq.wait_for_low().await?` to wait for the peripheral to signal readiness.

### Use infallible nanosecond delays

Blocking and async delay providers implement `delay::DelayNs` with an infallible
`delay_ns(u32)` method that supplies defaults for `delay_us()` and `delay_ms()`.
SPI transaction delays in both crates use `Operation::DelayNs(u32)`.

### Classify errors portably

HALs can keep their own `Debug` error types and implement the peripheral's
`Error::kind()` so generic drivers can handle common failures through `ErrorKind`.
Map failures outside the defined categories to `Other`, the only digital error
kind in 1.0.

### Use reference blanket implementations

The core, async, and nonblocking crates support `?Sized` in their reference
blanket implementations. For an object-safe trait, a value such as
`&mut dyn InputPin<Error = E>` also satisfies an `InputPin` generic bound.

## Bus adapter quick reference

### Choose a dedicated or shared adapter

`embedded-hal-bus` supplies `spi::ExclusiveDevice` for a dedicated bus and
mutex-backed adapters for sharing a bus.

### Enable atomic support where required

`AtomicDevice` requires the `portable-atomic` feature on `thumbv6m-none-eabi`
and other targets without atomic compare-and-swap.

### Give each device a shared bus handle

Enable `alloc` to use `embedded_hal_bus::i2c::RcDevice` or
`embedded_hal_bus::spi::RcDevice`. These reference-counted equivalents of
`RefCellDevice` let each device own a handle to the shared bus.

### Use bus errors in no_std builds

Bus error types that previously implemented `std::error::Error` behind `std`
now implement `core::error::Error` in `no_std` builds as well.

See [Bus adapters and sharing](references/bus-sharing.md) for the supplied
dependency configurations and their version attribution.

Files in this skill

  • SKILL.md5.5 KB
  • coverage.json422 B
  • references/bus-sharing.md1.2 KB
  • references/trait-migration.md2.5 KB
  • references/transactions.md1.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.