Skip to content

Commit

Permalink
Remove SPI3 from variants. Clarify module guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
David-OConnor committed May 1, 2021
1 parent 7a4fd42 commit 12a3802
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,19 @@ PRs are encouraged. Documenting each step using reference manuals is encouraged,
Most peripheral modules use the following format:

- Enums for various config settings, that implement `#[repr(u8)]` for their associated register values
- A peripheral struct that owns the reg block, and has fields for config. This struct includes
- A peripheral struct that has public fields for config. This struct also includes
a private `regs` field that is the appropriate reg block. Where possible, this is defined generically
in the implementation, eg:
`U: Deref<Target = pac::usart1::RegisterBlock>,`. [Reference the stm32-rs-nightlies Githug](https://github.com/stm32-rs/stm32-rs-nightlies)
`U: Deref<Target = pac::usart1::RegisterBlock>,`. Reference the [stm32-rs-nightlies Github](https://github.com/stm32-rs/stm32-rs-nightlies)
to identify when we can take advantage of this.
- If config fields are complicated, we use a separate Config struct owned by the peripheral struct.
This Config struct impls `Default`.
- If config fields are complicated, we use a separate `PeriphConfig` struct owned by the peripheral struct.
This struct impls `Default`.
- A constructor named `new` that performs setup code, including RCC peripheral enable and reset
- `enable_interrupt` and `clear_interrupt` functions
- `embedded-hal` implementations as required, that call native methods as applicable. Note that
we design our APIs based on STM32 capabilities, and apply EH traits as applicable.
- `enable_interrupt` and `clear_interrupt` functions, which accept an enum of interrupt type
- `embedded-hal` implementations as required, that call native methods. Note that
we design APIs based on STM32 capabilities, and apply EH traits as applicable.
- When available, base setup and usage steps on instructions provided in Reference Manuals.
These steps are copy+pasted in comments before the code that performs each one.


## Errata
Expand Down
6 changes: 3 additions & 3 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum Error {
pub enum SpiDevice {
One,
Two,
#[cfg(not(any(feature = "f3x4", feature = "g0")))]
Three,
}

Expand Down Expand Up @@ -146,18 +147,17 @@ where
clocks: &C,
rcc: &mut RCC,
) -> Self {
// l4x3 and L5 support SPI3, but have an inconsitent naming convention for enabling rcc.
// (ie `sp3en` instead of `spi3en`.)
match device {
SpiDevice::One => {
rcc_en_reset!(apb2, spi1, rcc);
}
SpiDevice::Two => {
rcc_en_reset!(apb1, spi2, rcc);
}
#[cfg(not(any(feature = "f3x4", feature = "g0")))]
SpiDevice::Three => {
cfg_if! {
// Note the difference of `sp3en` mixed with `spi3rst`.
// Note `sp3en` mixed with `spi3rst`; why we can't use the usual macro.
if #[cfg(any(feature = "l4x3", feature = "l5"))] {
rcc.apb1enr1.modify(|_, w| w.sp3en().set_bit());
rcc.apb1rstr1.modify(|_, w| w.spi3rst().set_bit());
Expand Down

0 comments on commit 12a3802

Please sign in to comment.