Skip to content

Commit 6ee06d1

Browse files
committed
Seal RccExt and FlashExt traits and improve documentation
1 parent e082eca commit 6ee06d1

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4848
0-clause as MIT conditions had to be met anyways. (🧂 IANAL). ([#309])
4949
- Renamed `Serial::raw_read` to `Serial::read_data_register`. ([#281])
5050
- Timer error type `AlreadyCancled` is no longer public constructable. ([#281])
51+
- Seal `FlashExt` and `RccExt` traits. These are no longer implementable by
52+
a user of this crate. ([#281])
5153
- Move ADC from a macro to a generic implementation, meaning that
5254
it is possible to obtain an ADC instance via `Adc::new` instead of
5355
`Adc::adc1`. ([#281])

src/flash.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
55
use crate::pac::{flash, FLASH};
66

7-
/// Extension trait to constrain the FLASH peripheral
8-
pub trait FlashExt {
9-
/// Constrains the FLASH peripheral to play nicely with the other abstractions
7+
impl crate::private::Sealed for FLASH {}
8+
9+
/// Extension trait to constrain the [`FLASH`] peripheral
10+
pub trait FlashExt: crate::private::Sealed {
11+
/// Constrains the [`FLASH`] peripheral.
12+
///
13+
/// Consumes the [`pac::FLASH`] peripheral and converts it to a [`HAL`] internal type
14+
/// constraining it's public access surface to fit the design of the [`HAL`].
15+
///
16+
/// [`pac::FLASH`]: `crate::pac::FLASH`
17+
/// [`HAL`]: `crate`
1018
fn constrain(self) -> Parts;
1119
}
1220

@@ -31,7 +39,7 @@ pub struct ACR {
3139

3240
impl ACR {
3341
pub(crate) fn acr(&mut self) -> &flash::ACR {
34-
// NOTE(unsafe) this proxy grants exclusive access to this register
42+
// SAFETY: This proxy grants exclusive access to this register
3543
unsafe { &(*FLASH::ptr()).acr }
3644
}
3745
}

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@
44
`stm32f3xx-hal` contains a multi device hardware abstraction on top of the
55
peripheral access API for the STMicro [STM32F3][stm] series microcontrollers.
66
7+
## Philosophie
8+
9+
HAL (meaning **H**ardware **A**bstraction **L**ayer) is a generic term used in many contexts,
10+
but in the specific context of this crate, it is meant to abstract away the control exposed
11+
by the devices "[peripheral access crate](`crate::pac`)" to simplify initialization routines,
12+
with a robust interface avoiding miss-configurations while still not abstracting to much away.
13+
14+
Also this crate's goal is to integrate well with the rest of the rust embedded ecosystem,
15+
for example by implementing the [`embedded_hal`] traits or using crates, like [`embedded_time`],
16+
or [`rtcc`].
17+
718
[stm]: https://www.st.com/en/microcontrollers-microprocessors/stm32f3-series.html
819
9-
## Basic Usagee
20+
## Basic Usage
1021
1122
```rust
1223
#![no_std]

src/rcc.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,17 @@ use core::convert::TryInto;
6666
use crate::flash::ACR;
6767
use crate::time::rate::*;
6868

69-
/// Extension trait that constrains the `RCC` peripheral
70-
pub trait RccExt {
71-
/// Constrains the `RCC` peripheral so it plays nicely with the other abstractions
69+
impl crate::private::Sealed for RCC {}
70+
71+
/// Extension trait that constrains the []`RCC`] peripheral
72+
pub trait RccExt: crate::private::Sealed {
73+
/// Constrains the [`RCC`] peripheral.
74+
///
75+
/// Consumes the [`pac::RCC`] peripheral and converts it to a [`HAL`] internal type
76+
/// constraining it's public access surface to fit the design of the `HAL`.
77+
///
78+
/// [`pac::RCC`]: `crate::pac::RCC`
79+
/// [`HAL`]: `crate`
7280
fn constrain(self) -> Rcc;
7381
}
7482

@@ -88,9 +96,8 @@ impl RccExt for RCC {
8896

8997
/// Constrained RCC peripheral
9098
///
91-
/// An instance of this struct is acquired by calling the
92-
/// [`constrain`](RccExt::constrain) function on the
93-
/// [`RCC`](crate::pac::RCC) struct.
99+
/// An instance of this struct is acquired by calling the [`constrain`](RccExt::constrain) function
100+
/// on the [`RCC`](crate::pac::RCC) struct.
94101
///
95102
/// ```
96103
/// let dp = pac::Peripherals::take().unwrap();

0 commit comments

Comments
 (0)