diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-08-20 15:42:42 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-08-20 15:42:42 +0200 |
| commit | 3457bb9f05ead9436349c7da877e17b803a55a0d (patch) | |
| tree | 4599fa6b7684b6526093b2b65c70280c8f985e02 | |
| parent | de2039fd1dce2ab6a060b5744116373854b35a7d (diff) | |
nrf: make gpiote and time-driver optional via cargo features.
| -rw-r--r-- | embassy-nrf/Cargo.toml | 8 | ||||
| -rw-r--r-- | embassy-nrf/src/lib.rs | 8 | ||||
| -rw-r--r-- | examples/nrf/Cargo.toml | 2 |
3 files changed, 16 insertions, 2 deletions
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index cc3597521..ea7efec19 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml | |||
| @@ -26,9 +26,15 @@ nrf52832 = ["nrf52832-pac"] | |||
| 26 | nrf52833 = ["nrf52833-pac"] | 26 | nrf52833 = ["nrf52833-pac"] |
| 27 | nrf52840 = ["nrf52840-pac"] | 27 | nrf52840 = ["nrf52840-pac"] |
| 28 | 28 | ||
| 29 | # Features starting with `_` are for internal use only. They're not intended | ||
| 30 | # to be enabled by other crates, and are not covered by semver guarantees. | ||
| 31 | _time-driver = ["embassy/time-tick-32768hz"] | ||
| 32 | |||
| 33 | gpiote = [] | ||
| 34 | time-driver-rtc1 = ["_time-driver"] | ||
| 29 | 35 | ||
| 30 | [dependencies] | 36 | [dependencies] |
| 31 | embassy = { version = "0.1.0", path = "../embassy", features = ["time-tick-32768hz"] } | 37 | embassy = { version = "0.1.0", path = "../embassy" } |
| 32 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]} | 38 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]} |
| 33 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } | 39 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } |
| 34 | 40 | ||
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 0de4b4390..0807822ff 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -23,10 +23,12 @@ compile_error!("No chip feature activated. You must activate exactly one of the | |||
| 23 | pub(crate) mod fmt; | 23 | pub(crate) mod fmt; |
| 24 | pub(crate) mod util; | 24 | pub(crate) mod util; |
| 25 | 25 | ||
| 26 | #[cfg(feature = "_time-driver")] | ||
| 26 | mod time_driver; | 27 | mod time_driver; |
| 27 | 28 | ||
| 28 | pub mod buffered_uarte; | 29 | pub mod buffered_uarte; |
| 29 | pub mod gpio; | 30 | pub mod gpio; |
| 31 | #[cfg(feature = "gpiote")] | ||
| 30 | pub mod gpiote; | 32 | pub mod gpiote; |
| 31 | pub mod ppi; | 33 | pub mod ppi; |
| 32 | #[cfg(not(any(feature = "nrf52805", feature = "nrf52820")))] | 34 | #[cfg(not(any(feature = "nrf52805", feature = "nrf52820")))] |
| @@ -98,7 +100,9 @@ pub mod config { | |||
| 98 | pub struct Config { | 100 | pub struct Config { |
| 99 | pub hfclk_source: HfclkSource, | 101 | pub hfclk_source: HfclkSource, |
| 100 | pub lfclk_source: LfclkSource, | 102 | pub lfclk_source: LfclkSource, |
| 103 | #[cfg(feature = "gpiote")] | ||
| 101 | pub gpiote_interrupt_priority: crate::interrupt::Priority, | 104 | pub gpiote_interrupt_priority: crate::interrupt::Priority, |
| 105 | #[cfg(feature = "_time-driver")] | ||
| 102 | pub time_interrupt_priority: crate::interrupt::Priority, | 106 | pub time_interrupt_priority: crate::interrupt::Priority, |
| 103 | } | 107 | } |
| 104 | 108 | ||
| @@ -110,7 +114,9 @@ pub mod config { | |||
| 110 | // xtals if they know they have them. | 114 | // xtals if they know they have them. |
| 111 | hfclk_source: HfclkSource::Internal, | 115 | hfclk_source: HfclkSource::Internal, |
| 112 | lfclk_source: LfclkSource::InternalRC, | 116 | lfclk_source: LfclkSource::InternalRC, |
| 117 | #[cfg(feature = "gpiote")] | ||
| 113 | gpiote_interrupt_priority: crate::interrupt::Priority::P0, | 118 | gpiote_interrupt_priority: crate::interrupt::Priority::P0, |
| 119 | #[cfg(feature = "_time-driver")] | ||
| 114 | time_interrupt_priority: crate::interrupt::Priority::P0, | 120 | time_interrupt_priority: crate::interrupt::Priority::P0, |
| 115 | } | 121 | } |
| 116 | } | 122 | } |
| @@ -164,9 +170,11 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 164 | while r.events_lfclkstarted.read().bits() == 0 {} | 170 | while r.events_lfclkstarted.read().bits() == 0 {} |
| 165 | 171 | ||
| 166 | // Init GPIOTE | 172 | // Init GPIOTE |
| 173 | #[cfg(feature = "gpiote")] | ||
| 167 | gpiote::init(config.gpiote_interrupt_priority); | 174 | gpiote::init(config.gpiote_interrupt_priority); |
| 168 | 175 | ||
| 169 | // init RTC time driver | 176 | // init RTC time driver |
| 177 | #[cfg(feature = "_time-driver")] | ||
| 170 | time_driver::init(config.time_interrupt_priority); | 178 | time_driver::init(config.time_interrupt_priority); |
| 171 | 179 | ||
| 172 | peripherals | 180 | peripherals |
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index f410f89c1..0f932e25c 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml | |||
| @@ -19,7 +19,7 @@ defmt-error = [] | |||
| 19 | [dependencies] | 19 | [dependencies] |
| 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } | 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 22 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "defmt-trace", "nrf52840"] } | 22 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "defmt-trace", "nrf52840", "time-driver-rtc1", "gpiote"] } |
| 23 | 23 | ||
| 24 | defmt = "0.2.0" | 24 | defmt = "0.2.0" |
| 25 | defmt-rtt = "0.2.0" | 25 | defmt-rtt = "0.2.0" |
