embedded-hal rust ecosystem diagram

This commit is contained in:
ImplFerris 2025-07-20 08:04:16 +05:30
parent 9064b784c8
commit 41e493a907
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,58 @@
<svg width="500" height="760" xmlns="http://www.w3.org/2000/svg">
<!--
Source: https://github.com/ImplFerris/ImplFerris
Copyright (c) 2025 implrust.com
Licensed under CC BY-SA 4.0
-->
<defs>
<marker id="arrow" markerWidth="8" markerHeight="6" refX="4" refY="3" orient="auto">
<path d="M0,0 L8,3 L0,6 Z" fill="#ba7d18"/>
</marker>
<style>
.box { rx:14; ry:14; stroke:#444; stroke-width:1.8; fill-opacity:1 }
.label { font-family:sans-serif; font-size:16px; fill:#222 }
.sub { font-family:sans-serif; font-size:12px; fill:#222 }
.arrow-label { font-family:sans-serif; font-size:13px; fill:#ba7d18;font-weight:bold }
</style>
</defs>
<!-- Layer 1: Microcontroller container -->
<rect x="100" y="20" width="300" height="160" fill="#ECEFF1" class="box"/>
<text x="250" y="70" text-anchor="middle" class="label">Microcontroller</text>
<!-- SPI Peripheral inside Microcontroller -->
<rect x="150" y="105" width="200" height="50" fill="#AEDFF7" class="box"/>
<text x="250" y="135" text-anchor="middle" class="label">SPI Peripheral</text>
<!-- Arrow 1: down to HAL -->
<line x1="250" y1="180" x2="250" y2="235" stroke="#ba7d18" stroke-width="1.5" marker-end="url(#arrow)"/>
<text x="260" y="210" text-anchor="start" class="arrow-label">Exposes hardware</text>
<!-- Layer 2: HAL (90px tall) -->
<rect x="100" y="240" width="300" height="120" fill="#C8E6C9" class="box"/>
<text x="250" y="280" text-anchor="middle" class="label">HAL</text>
<text x="250" y="305" text-anchor="middle" class="sub">implements SpiBus </text>
<text x="250" y="330" text-anchor="middle" class="sub">(hardware-specific code)</text>
<!-- Arrow 2: down to embedded-hal-bus -->
<line x1="250" y1="360" x2="250" y2="415" stroke="#ba7d18" stroke-width="1.5" marker-end="url(#arrow)"/>
<text x="260" y="390" text-anchor="start" class="arrow-label">Provides SpiBus + CS Pin (OutputPin)</text>
<!-- Layer 3: embeddedhalbus (90px tall) -->
<rect x="100" y="420" width="300" height="120" fill="#FFE082" class="box"/>
<text x="250" y="465" text-anchor="middle" class="label">embeddedhalbus</text>
<text x="250" y="490" text-anchor="middle" class="sub">implements SpiDevice</text>
<text x="250" y="515" text-anchor="middle" class="sub">(platform-independent)</text>
<!-- Arrow 3: down to Driver -->
<line x1="250" y1="540" x2="250" y2="595" stroke="#ba7d18" stroke-width="1.5" marker-end="url(#arrow)"/>
<text x="260" y="570" text-anchor="start" class="arrow-label">Provides SpiDevice (exclusive or shared)</text>
<!-- Layer 4: Driver (90px tall) -->
<rect x="100" y="600" width="300" height="120" fill="#FFCDD2" class="box"/>
<text x="250" y="640" text-anchor="middle" class="label">Driver</text>
<text x="250" y="665" text-anchor="middle" class="sub">uses SpiDevice to control the Device</text>
<text x="250" y="690" text-anchor="middle" class="sub">(platform-independent)</text>
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -42,6 +42,9 @@ Not really. While it's possible to write your own implementation, it's usually u
That's where the embedded-hal-bus crate comes in. It provides ready-to-use wrappers that implement the SpiDevice trait for you. These wrappers handle bus access, chip select control, and optional synchronization between devices.
<img style="display: block; margin: auto;" alt="SPI Single Bus Multiple SPI Device" src="./images/spi-embedded-hal-rust-ecosystem.svg"/>
- If your project only uses one SPI device and doesn't need sharing, you can use the `ExclusiveDevice` struct - it gives exclusive access to the bus for one device.
- But if your project has multiple SPI devices sharing the same bus, you can choose one of the shared access implementations such as `AtomicDevice` or `CriticalSectionDevice`. These manage access to the bus so that each device gets a turn without interfering with the others.