#embedded-hal #embedded-hal-driver #led #button

no-std switch-hal

HAL and basic implementations for input and output switches (buttons, switches, leds, transistors)

8 releases

new 0.4.0 Jun 15, 2021
0.3.3 Jun 15, 2021
0.3.2 Feb 15, 2020
0.2.1 Feb 5, 2020
0.1.1 Feb 4, 2020

#74 in Embedded development

Download history 43/week @ 2021-02-25 68/week @ 2021-03-04 41/week @ 2021-03-11 40/week @ 2021-03-18 77/week @ 2021-03-25 53/week @ 2021-04-01 48/week @ 2021-04-08 46/week @ 2021-04-15 104/week @ 2021-04-22 61/week @ 2021-04-29 51/week @ 2021-05-06 41/week @ 2021-05-13 42/week @ 2021-05-20 241/week @ 2021-05-27 77/week @ 2021-06-03 103/week @ 2021-06-10

316 downloads per month
Used in stm32f3-discovery


287 lines


Rust crates.io crates.io docs.rs

Switch-HAL is a no_std embedded Rust library for working with buttons, switches, LEDs, and transistors. Basically, anything that acts like a switch, whether an input or output.

It is both a driver that uses the embedded-hal::digital traits and is an abstraction in it's own right. It provides a simple, zero-cost, abstraction to clarify the intent of your application code.

Why Switch-HAL? Why not just use raw GPIO?

Did you mean to drive that line high?
Or did you mean to turn that LED off?
Wait a second... is that LED active high?
Where's the schematic?
Okay... cathode is wired to the input line... that means it's active low.

Now repeat this every place in your code where you need to turn that LED on or off.
What happens when the hardware changes?
Using the raw GPIO to set pins high and low will have you making changes all over your code base.

Wouldn't it be nicer if you only had to think about that once, when you initialize your application,
and from then on out, simply called led.on() or led.off().
Having an abstraction at the proper level reduces cognitive load.
Specifying whether a simple peripheral is active high or low in a single place in your application reduces the maintenace burden.



or build a local copy

cargo docs

and open target/doc/switch_hal/index.html in your browser.


Licensed under either of

at your option.

Architectural Decision Records

Major design decisions are tracked in the adr directory.



Adds StatefulOutputSwitch thanks to forkbomb9


Update embedded-hal to 0.2.5


  • Add convenience converter functions into_active_low_switch() and into_active_high_switch()


  • Bug Fix: is_active() was returning the wrong result for Switch<InputPin, ActiveLow>