Skip to content

Commit f86431f

Browse files
orangecmstherealprof
authored andcommitted
portability: add reference to embedded-hal docs
Same as in src/start/registers.md, for every occurrence. Signed-off-by: Daniel Maslowski <[email protected]>
1 parent 7ee77f7 commit f86431f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/portability/index.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ A common way to equalize such differences is via a layer called Hardware Abstrac
1414

1515
Embedded systems are a bit special in this regard since we typically do not have operating systems and user installable software but firmware images which are compiled as a whole as well as a number of other constraints. So while the traditional approach as defined by Wikipedia could potentially work it is likely not the most productive approach to ensure portability.
1616

17-
How do we do this in Rust? Enter **embedded-hal**...
17+
How do we do this in Rust? Enter **[embedded-hal]**...
1818

19-
## What is embedded-hal?
19+
## What is [embedded-hal]?
2020

2121
In a nutshell it is a set of traits which define implementation contracts between **HAL implementations**, **drivers** and **applications (or firmwares)**. Those contracts include both capabilities (i.e. if a trait is implemented for a certain type, the **HAL implementation** provides a certain capability) and methods (i.e. if you can construct a type implementing a trait it is guaranteed that you have the methods specified in the trait available).
2222

2323
A typical layering might look like this:
2424

2525
![](../assets/rust_layers.svg)
2626

27-
Some of the defined traits in **embedded-hal** are:
27+
Some of the defined traits in **[embedded-hal]** are:
2828
* GPIO (input and output pins)
2929
* Serial communication
3030
* I2C
3131
* SPI
3232
* Timers/Countdowns
3333
* Analog Digital Conversion
3434

35-
The main reason for having the **embedded-hal** traits and crates implementing and using them is to keep complexity in check. If you consider that an application might have to implement the use of the peripheral in the hardware as well as the application and potentially drivers for additional hardware components, then it should be easy to see that the re-usability is very limited. Expressed mathematically, if **M** is the number of peripheral HAL implementations and **N** the number of drivers then if we were to reinvent the wheel for every application then we would end up with **M*N** implementations while by using the *API* provided by the **embedded-hal** traits will make the implementation complexity approach **M+N**. Of course there're additional benefits to be had, such as less trial-and-error due to a well-defined and ready-to-use APIs.
35+
The main reason for having the **embedded-hal** traits and crates implementing and using them is to keep complexity in check. If you consider that an application might have to implement the use of the peripheral in the hardware as well as the application and potentially drivers for additional hardware components, then it should be easy to see that the re-usability is very limited. Expressed mathematically, if **M** is the number of peripheral HAL implementations and **N** the number of drivers then if we were to reinvent the wheel for every application then we would end up with **M*N** implementations while by using the *API* provided by the **[embedded-hal]** traits will make the implementation complexity approach **M+N**. Of course there're additional benefits to be had, such as less trial-and-error due to a well-defined and ready-to-use APIs.
3636

37-
## Users of the embedded-hal
37+
## Users of the [embedded-hal]
3838

3939
As said above there are three main users of the HAL:
4040

@@ -43,7 +43,7 @@ As said above there are three main users of the HAL:
4343
A HAL implementation provides the interfacing between the hardware and the users of the HAL traits. Typical implementations consist of three parts:
4444
* One or more hardware specific types
4545
* Functions to create and initialize such a type, often providing various configuration options (speed, operation mode, use pins, etc.)
46-
* one or more `trait` `impl` of **embedded-hal** traits for that type
46+
* one or more `trait` `impl` of **[embedded-hal]** traits for that type
4747

4848
Such a **HAL implementation** can come in various flavours:
4949
* Via low-level hardware access, e.g. via registers
@@ -53,10 +53,12 @@ Such a **HAL implementation** can come in various flavours:
5353

5454
### Driver
5555

56-
A driver implements a set of custom functionality for an internal or external component, connected to a peripheral implementing the embedded-hal traits. Typical examples for such drivers include various sensors (temperature, magnetometer, accelerometer, light), display devices (LED arrays, LCD displays) and actuators (motors, transmitters).
56+
A driver implements a set of custom functionality for an internal or external component, connected to a peripheral implementing the [embedded-hal] traits. Typical examples for such drivers include various sensors (temperature, magnetometer, accelerometer, light), display devices (LED arrays, LCD displays) and actuators (motors, transmitters).
5757

58-
A driver has to be initialized with an instance of type that implements a certain `trait` of the embedded-hal which is ensured via trait bound and provides its own type instance with a custom set of methods allowing to interact with the driven device.
58+
A driver has to be initialized with an instance of type that implements a certain `trait` of the [embedded-hal] which is ensured via trait bound and provides its own type instance with a custom set of methods allowing to interact with the driven device.
5959

6060
### Application
6161

6262
The application binds the various parts together and ensures that the desired functionality is achieved. When porting between different systems, this is the part which requires the most adaptation efforts, since the application needs to correctly initialize the real hardware via the HAL implementation and the initialisation of different hardware differs, sometimes drastically so. Also the user choice often plays a big role, since components can be physically connected to different terminals, hardware buses sometimes need external hardware to match the configuration or there are different trade-offs to be made in the use of internal peripherals (e.g. multiple timers with different capabilities are available or peripherals conflict with others).
63+
64+
[embedded-hal]: https://crates.io/crates/embedded-hal

0 commit comments

Comments
 (0)