diff options
| author | Ulf Lilleengen <[email protected]> | 2021-06-14 11:24:09 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2021-06-14 11:33:11 +0200 |
| commit | ee9f67fa013c703396ddbd76d3fe33b51bd6a8bb (patch) | |
| tree | a301df2d47a5cab13958ad2672de05e7191e29d6 | |
| parent | a2da2a6db2e2bbef6d1031dd7a8461e5643ba711 (diff) | |
Add common types
| -rw-r--r-- | embassy-stm32/src/rcc/f4/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/l0/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/l4/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/types.rs | 94 |
5 files changed, 98 insertions, 4 deletions
diff --git a/embassy-stm32/src/rcc/f4/mod.rs b/embassy-stm32/src/rcc/f4/mod.rs index abd631944..a9e63ccc2 100644 --- a/embassy-stm32/src/rcc/f4/mod.rs +++ b/embassy-stm32/src/rcc/f4/mod.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | pub use super::common::*; | 1 | pub use super::types::*; |
| 2 | use crate::pac; | 2 | use crate::pac; |
| 3 | use crate::peripherals::{self, RCC}; | 3 | use crate::peripherals::{self, RCC}; |
| 4 | use crate::rcc::{get_freqs, set_freqs, Clocks}; | 4 | use crate::rcc::{get_freqs, set_freqs, Clocks}; |
diff --git a/embassy-stm32/src/rcc/l0/mod.rs b/embassy-stm32/src/rcc/l0/mod.rs index ce9c58657..2d51c690f 100644 --- a/embassy-stm32/src/rcc/l0/mod.rs +++ b/embassy-stm32/src/rcc/l0/mod.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | pub use super::common::*; | 1 | pub use super::types::*; |
| 2 | use crate::pac; | 2 | use crate::pac; |
| 3 | use crate::peripherals::{self, CRS, RCC, SYSCFG}; | 3 | use crate::peripherals::{self, CRS, RCC, SYSCFG}; |
| 4 | use crate::rcc::{get_freqs, set_freqs, Clocks}; | 4 | use crate::rcc::{get_freqs, set_freqs, Clocks}; |
diff --git a/embassy-stm32/src/rcc/l4/mod.rs b/embassy-stm32/src/rcc/l4/mod.rs index e8c488e06..c33d9501e 100644 --- a/embassy-stm32/src/rcc/l4/mod.rs +++ b/embassy-stm32/src/rcc/l4/mod.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | pub use super::common::*; | 1 | pub use super::types::*; |
| 2 | use crate::pac; | 2 | use crate::pac; |
| 3 | use crate::peripherals::{self, RCC}; | 3 | use crate::peripherals::{self, RCC}; |
| 4 | use crate::rcc::{get_freqs, set_freqs, Clocks}; | 4 | use crate::rcc::{get_freqs, set_freqs, Clocks}; |
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index b5ca7f40a..9252c4da9 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | use crate::peripherals; | 3 | use crate::peripherals; |
| 4 | use crate::time::Hertz; | 4 | use crate::time::Hertz; |
| 5 | use core::mem::MaybeUninit; | 5 | use core::mem::MaybeUninit; |
| 6 | mod common; | 6 | mod types; |
| 7 | 7 | ||
| 8 | #[derive(Clone, Copy)] | 8 | #[derive(Clone, Copy)] |
| 9 | pub struct Clocks { | 9 | pub struct Clocks { |
diff --git a/embassy-stm32/src/rcc/types.rs b/embassy-stm32/src/rcc/types.rs new file mode 100644 index 000000000..df7917ab3 --- /dev/null +++ b/embassy-stm32/src/rcc/types.rs | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | #![allow(dead_code)] | ||
| 2 | /// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC, | ||
| 3 | /// and with the addition of the init function to configure a system clock. | ||
| 4 | use crate::time::Hertz; | ||
| 5 | |||
| 6 | /// System clock mux source | ||
| 7 | #[derive(Clone, Copy)] | ||
| 8 | pub enum ClockSrc { | ||
| 9 | MSI(MSIRange), | ||
| 10 | PLL(PLLSource, PLLMul, PLLDiv), | ||
| 11 | HSE(Hertz), | ||
| 12 | HSI16, | ||
| 13 | } | ||
| 14 | |||
| 15 | /// MSI Clock Range | ||
| 16 | /// | ||
| 17 | /// These ranges control the frequency of the MSI. Internally, these ranges map | ||
| 18 | /// to the `MSIRANGE` bits in the `RCC_ICSCR` register. | ||
| 19 | #[derive(Clone, Copy)] | ||
| 20 | pub enum MSIRange { | ||
| 21 | /// Around 65.536 kHz | ||
| 22 | Range0, | ||
| 23 | /// Around 131.072 kHz | ||
| 24 | Range1, | ||
| 25 | /// Around 262.144 kHz | ||
| 26 | Range2, | ||
| 27 | /// Around 524.288 kHz | ||
| 28 | Range3, | ||
| 29 | /// Around 1.048 MHz | ||
| 30 | Range4, | ||
| 31 | /// Around 2.097 MHz (reset value) | ||
| 32 | Range5, | ||
| 33 | /// Around 4.194 MHz | ||
| 34 | Range6, | ||
| 35 | } | ||
| 36 | |||
| 37 | impl Default for MSIRange { | ||
| 38 | fn default() -> MSIRange { | ||
| 39 | MSIRange::Range5 | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | /// PLL divider | ||
| 44 | #[derive(Clone, Copy)] | ||
| 45 | pub enum PLLDiv { | ||
| 46 | Div2, | ||
| 47 | Div3, | ||
| 48 | Div4, | ||
| 49 | } | ||
| 50 | |||
| 51 | /// PLL multiplier | ||
| 52 | #[derive(Clone, Copy)] | ||
| 53 | pub enum PLLMul { | ||
| 54 | Mul3, | ||
| 55 | Mul4, | ||
| 56 | Mul6, | ||
| 57 | Mul8, | ||
| 58 | Mul12, | ||
| 59 | Mul16, | ||
| 60 | Mul24, | ||
| 61 | Mul32, | ||
| 62 | Mul48, | ||
| 63 | } | ||
| 64 | |||
| 65 | /// AHB prescaler | ||
| 66 | #[derive(Clone, Copy)] | ||
| 67 | pub enum AHBPrescaler { | ||
| 68 | NotDivided, | ||
| 69 | Div2, | ||
| 70 | Div4, | ||
| 71 | Div8, | ||
| 72 | Div16, | ||
| 73 | Div64, | ||
| 74 | Div128, | ||
| 75 | Div256, | ||
| 76 | Div512, | ||
| 77 | } | ||
| 78 | |||
| 79 | /// APB prescaler | ||
| 80 | #[derive(Clone, Copy)] | ||
| 81 | pub enum APBPrescaler { | ||
| 82 | NotDivided, | ||
| 83 | Div2, | ||
| 84 | Div4, | ||
| 85 | Div8, | ||
| 86 | Div16, | ||
| 87 | } | ||
| 88 | |||
| 89 | /// PLL clock input source | ||
| 90 | #[derive(Clone, Copy)] | ||
| 91 | pub enum PLLSource { | ||
| 92 | HSI16, | ||
| 93 | HSE(Hertz), | ||
| 94 | } | ||
