aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-11-07 10:06:55 -0800
committerFelipe Balbi <[email protected]>2025-11-07 10:06:55 -0800
commitcb2ac2790f4b037056f9571abeb4d62360199426 (patch)
treef9f163e4340d11ddc54c24ab8cf7624e83f1fd18 /src
parenta71eff2e1cea55b393e793c023b8e51e5cc369a1 (diff)
Reduce number of features
We don't need features for drivers that always exist. Signed-off-by: Felipe Balbi <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/adc.rs155
-rw-r--r--src/clocks.rs9
-rw-r--r--src/gpio.rs2
-rw-r--r--src/interrupt.rs2
-rw-r--r--src/lib.rs59
-rw-r--r--src/lpuart/buffered.rs2
-rw-r--r--src/lpuart/mod.rs2
-rw-r--r--src/ostimer.rs8
-rw-r--r--src/pins.rs1
-rw-r--r--src/rtc.rs28
-rw-r--r--src/uart.rs9
11 files changed, 136 insertions, 141 deletions
diff --git a/src/adc.rs b/src/adc.rs
index f56d744c6..5625330e9 100644
--- a/src/adc.rs
+++ b/src/adc.rs
@@ -1,12 +1,12 @@
1//! ADC driver 1//! ADC driver
2use crate::pac; 2use crate::pac;
3use core::sync::atomic::{AtomicBool, Ordering}; 3use core::sync::atomic::{AtomicBool, Ordering};
4 4
5use crate::pac::adc1::ctrl::{CalAvgs}; 5use crate::pac::adc1::cfg::{HptExdi, Pwrsel, Refsel, Tcmdres, Tprictrl, Tres};
6use crate::pac::adc1::cfg::{Refsel, Pwrsel, Tprictrl, Tres, Tcmdres, HptExdi}; 6use crate::pac::adc1::cmdh1::{Avgs, Cmpen, Next, Sts};
7use crate::pac::adc1::tctrl::{Tcmd, Tpri};
8use crate::pac::adc1::cmdl1::{Adch, Ctype, Mode}; 7use crate::pac::adc1::cmdl1::{Adch, Ctype, Mode};
9use crate::pac::adc1::cmdh1::{Next, Avgs, Sts, Cmpen}; 8use crate::pac::adc1::ctrl::CalAvgs;
9use crate::pac::adc1::tctrl::{Tcmd, Tpri};
10 10
11type Regs = pac::adc1::RegisterBlock; 11type Regs = pac::adc1::RegisterBlock;
12 12
@@ -17,9 +17,7 @@ pub trait Instance {
17} 17}
18 18
19/// Token for ADC1 19/// Token for ADC1
20#[cfg(feature = "adc1")]
21pub type Adc1 = crate::peripherals::ADC1; 20pub type Adc1 = crate::peripherals::ADC1;
22#[cfg(feature = "adc1")]
23impl Instance for crate::peripherals::ADC1 { 21impl Instance for crate::peripherals::ADC1 {
24 #[inline(always)] 22 #[inline(always)]
25 fn ptr() -> *const Regs { 23 fn ptr() -> *const Regs {
@@ -28,7 +26,6 @@ impl Instance for crate::peripherals::ADC1 {
28} 26}
29 27
30// Also implement Instance for the Peri wrapper type 28// Also implement Instance for the Peri wrapper type
31#[cfg(feature = "adc1")]
32impl Instance for embassy_hal_internal::Peri<'_, crate::peripherals::ADC1> { 29impl Instance for embassy_hal_internal::Peri<'_, crate::peripherals::ADC1> {
33 #[inline(always)] 30 #[inline(always)]
34 fn ptr() -> *const Regs { 31 fn ptr() -> *const Regs {
@@ -97,16 +94,15 @@ pub struct ConvResult {
97 pub conv_value: u16, 94 pub conv_value: u16,
98} 95}
99 96
100
101pub struct Adc<I: Instance> { 97pub struct Adc<I: Instance> {
102 _inst: core::marker::PhantomData<I>, 98 _inst: core::marker::PhantomData<I>,
103} 99}
104 100
105impl<I: Instance> Adc<I> { 101impl<I: Instance> Adc<I> {
106 /// initialize ADC 102 /// initialize ADC
107 pub fn new(_inst: impl Instance, config : LpadcConfig) -> Self { 103 pub fn new(_inst: impl Instance, config: LpadcConfig) -> Self {
108 let adc = unsafe { &*I::ptr() }; 104 let adc = unsafe { &*I::ptr() };
109 105
110 /* Reset the module. */ 106 /* Reset the module. */
111 adc.ctrl().modify(|_, w| w.rst().held_in_reset()); 107 adc.ctrl().modify(|_, w| w.rst().held_in_reset());
112 adc.ctrl().modify(|_, w| w.rst().released_from_reset()); 108 adc.ctrl().modify(|_, w| w.rst().released_from_reset());
@@ -124,64 +120,81 @@ impl<I: Instance> Adc<I> {
124 } 120 }
125 121
126 /* Set calibration average mode. */ 122 /* Set calibration average mode. */
127 adc.ctrl().modify(|_, w| w.cal_avgs().variant(config.conversion_average_mode)); 123 adc.ctrl()
128 124 .modify(|_, w| w.cal_avgs().variant(config.conversion_average_mode));
129 adc.cfg().write(|w| unsafe { 125
126 adc.cfg().write(|w| unsafe {
130 let w = if config.enable_analog_preliminary { 127 let w = if config.enable_analog_preliminary {
131 w.pwren().pre_enabled() 128 w.pwren().pre_enabled()
132 } else { 129 } else {
133 w 130 w
134 }; 131 };
135 132
136 w.pudly().bits(config.power_up_delay) 133 w.pudly()
137 .refsel().variant(config.reference_voltage_source) 134 .bits(config.power_up_delay)
138 .pwrsel().variant(config.power_level_mode) 135 .refsel()
139 .tprictrl().variant(match config.trigger_priority_policy { 136 .variant(config.reference_voltage_source)
140 TriggerPriorityPolicy::ConvPreemptSoftlyNotAutoResumed | 137 .pwrsel()
141 TriggerPriorityPolicy::ConvPreemptSoftlyAutoRestarted | 138 .variant(config.power_level_mode)
142 TriggerPriorityPolicy::ConvPreemptSoftlyAutoResumed => Tprictrl::FinishCurrentOnPriority, 139 .tprictrl()
143 TriggerPriorityPolicy::ConvPreemptSubsequentlyNotAutoResumed | 140 .variant(match config.trigger_priority_policy {
144 TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoRestarted | 141 TriggerPriorityPolicy::ConvPreemptSoftlyNotAutoResumed
145 TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoResumed => Tprictrl::FinishSequenceOnPriority, 142 | TriggerPriorityPolicy::ConvPreemptSoftlyAutoRestarted
146 _ => Tprictrl::AbortCurrentOnPriority, 143 | TriggerPriorityPolicy::ConvPreemptSoftlyAutoResumed => {
147 }) 144 Tprictrl::FinishCurrentOnPriority
148 .tres().variant(match config.trigger_priority_policy { 145 }
149 TriggerPriorityPolicy::ConvPreemptImmediatelyAutoRestarted | 146 TriggerPriorityPolicy::ConvPreemptSubsequentlyNotAutoResumed
150 TriggerPriorityPolicy::ConvPreemptSoftlyAutoRestarted | 147 | TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoRestarted
151 TriggerPriorityPolicy::ConvPreemptImmediatelyAutoResumed | 148 | TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoResumed => {
152 TriggerPriorityPolicy::ConvPreemptSoftlyAutoResumed | 149 Tprictrl::FinishSequenceOnPriority
153 TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoRestarted | 150 }
154 TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoResumed => Tres::Enabled, 151 _ => Tprictrl::AbortCurrentOnPriority,
155 _ => Tres::Disabled, 152 })
156 }) 153 .tres()
157 .tcmdres().variant(match config.trigger_priority_policy { 154 .variant(match config.trigger_priority_policy {
158 TriggerPriorityPolicy::ConvPreemptImmediatelyAutoResumed | 155 TriggerPriorityPolicy::ConvPreemptImmediatelyAutoRestarted
159 TriggerPriorityPolicy::ConvPreemptSoftlyAutoResumed | 156 | TriggerPriorityPolicy::ConvPreemptSoftlyAutoRestarted
160 TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoResumed | 157 | TriggerPriorityPolicy::ConvPreemptImmediatelyAutoResumed
161 TriggerPriorityPolicy::TriggerPriorityExceptionDisabled => Tcmdres::Enabled, 158 | TriggerPriorityPolicy::ConvPreemptSoftlyAutoResumed
162 _ => Tcmdres::Disabled, 159 | TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoRestarted
163 }) 160 | TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoResumed => Tres::Enabled,
164 .hpt_exdi().variant(match config.trigger_priority_policy { 161 _ => Tres::Disabled,
165 TriggerPriorityPolicy::TriggerPriorityExceptionDisabled => HptExdi::Disabled, 162 })
166 _ => HptExdi::Enabled, 163 .tcmdres()
167 }) 164 .variant(match config.trigger_priority_policy {
168 }); 165 TriggerPriorityPolicy::ConvPreemptImmediatelyAutoResumed
166 | TriggerPriorityPolicy::ConvPreemptSoftlyAutoResumed
167 | TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoResumed
168 | TriggerPriorityPolicy::TriggerPriorityExceptionDisabled => Tcmdres::Enabled,
169 _ => Tcmdres::Disabled,
170 })
171 .hpt_exdi()
172 .variant(match config.trigger_priority_policy {
173 TriggerPriorityPolicy::TriggerPriorityExceptionDisabled => HptExdi::Disabled,
174 _ => HptExdi::Enabled,
175 })
176 });
169 177
170 if config.enable_conv_pause { 178 if config.enable_conv_pause {
171 adc.pause().modify(|_, w| unsafe { 179 adc.pause().modify(|_, w| unsafe {
172 w.pauseen().enabled() 180 w.pauseen()
173 .pausedly().bits(config.conv_pause_delay) 181 .enabled()
182 .pausedly()
183 .bits(config.conv_pause_delay)
174 }); 184 });
175 } else { 185 } else {
176 adc.pause().write(|w| unsafe { w.bits(0) }); 186 adc.pause().write(|w| unsafe { w.bits(0) });
177 } 187 }
178 188
179 adc.fctrl0().write(|w| unsafe { w.fwmark().bits(config.fifo_watermark) }); 189 adc.fctrl0()
190 .write(|w| unsafe { w.fwmark().bits(config.fifo_watermark) });
180 191
181 // Enable ADC 192 // Enable ADC
182 adc.ctrl().modify(|_, w| w.adcen().enabled()); 193 adc.ctrl().modify(|_, w| w.adcen().enabled());
183 194
184 Self { _inst: core::marker::PhantomData } 195 Self {
196 _inst: core::marker::PhantomData,
197 }
185 } 198 }
186 199
187 pub fn deinit(&self) { 200 pub fn deinit(&self) {
@@ -189,7 +202,6 @@ impl<I: Instance> Adc<I> {
189 adc.ctrl().modify(|_, w| w.adcen().disabled()); 202 adc.ctrl().modify(|_, w| w.adcen().disabled());
190 } 203 }
191 204
192
193 pub fn get_default_config() -> LpadcConfig { 205 pub fn get_default_config() -> LpadcConfig {
194 LpadcConfig { 206 LpadcConfig {
195 enable_in_doze_mode: true, 207 enable_in_doze_mode: true,
@@ -208,13 +220,14 @@ impl<I: Instance> Adc<I> {
208 pub fn do_offset_calibration(&self) { 220 pub fn do_offset_calibration(&self) {
209 let adc = unsafe { &*I::ptr() }; 221 let adc = unsafe { &*I::ptr() };
210 // Enable calibration mode 222 // Enable calibration mode
211 adc.ctrl().modify(|_, w| w.calofs().offset_calibration_request_pending()); 223 adc.ctrl()
224 .modify(|_, w| w.calofs().offset_calibration_request_pending());
212 225
213 // Wait for calibration to complete (polling status register) 226 // Wait for calibration to complete (polling status register)
214 while adc.stat().read().cal_rdy().is_not_set() {} 227 while adc.stat().read().cal_rdy().is_not_set() {}
215 } 228 }
216 229
217 pub fn get_gain_conv_result(&self, mut gain_adjustment: f32) -> u32{ 230 pub fn get_gain_conv_result(&self, mut gain_adjustment: f32) -> u32 {
218 let mut gcra_array = [0u32; 17]; 231 let mut gcra_array = [0u32; 17];
219 let mut gcalr: u32 = 0; 232 let mut gcalr: u32 = 0;
220 233
@@ -234,20 +247,21 @@ impl<I: Instance> Adc<I> {
234 247
235 pub fn do_auto_calibration(&self) { 248 pub fn do_auto_calibration(&self) {
236 let adc = unsafe { &*I::ptr() }; 249 let adc = unsafe { &*I::ptr() };
237 adc.ctrl().modify(|_, w| w.cal_req().calibration_request_pending()); 250 adc.ctrl()
251 .modify(|_, w| w.cal_req().calibration_request_pending());
238 252
239 while adc.gcc0().read().rdy().is_gain_cal_not_valid() {} 253 while adc.gcc0().read().rdy().is_gain_cal_not_valid() {}
240 254
241
242 let mut gcca = adc.gcc0().read().gain_cal().bits() as u32; 255 let mut gcca = adc.gcc0().read().gain_cal().bits() as u32;
243 if gcca & (((0xFFFF >> 0) + 1) >> 1) != 0 { 256 if gcca & (((0xFFFF >> 0) + 1) >> 1) != 0 {
244 gcca |= !0xFFFF; 257 gcca |= !0xFFFF;
245 } 258 }
246 259
247 let gcra = 131072.0 / (131072.0 - gcca as f32); 260 let gcra = 131072.0 / (131072.0 - gcca as f32);
248 261
249 // Write to GCR0 262 // Write to GCR0
250 adc.gcr0().write(|w| unsafe { w.bits(self.get_gain_conv_result(gcra)) }); 263 adc.gcr0()
264 .write(|w| unsafe { w.bits(self.get_gain_conv_result(gcra)) });
251 265
252 adc.gcr0().modify(|_, w| w.rdy().set_bit()); 266 adc.gcr0().modify(|_, w| w.rdy().set_bit());
253 267
@@ -284,15 +298,22 @@ impl<I: Instance> Adc<I> {
284 match index { 298 match index {
285 1 => { 299 1 => {
286 adc.cmdl1().write(|w| { 300 adc.cmdl1().write(|w| {
287 w.adch().variant(config.channel_number) 301 w.adch()
288 .mode().variant(config.conversion_resolution_mode) 302 .variant(config.channel_number)
303 .mode()
304 .variant(config.conversion_resolution_mode)
289 }); 305 });
290 adc.cmdh1().write(|w| unsafe { 306 adc.cmdh1().write(|w| unsafe {
291 w.next().variant(config.chained_next_command_number) 307 w.next()
292 .loop_().bits(config.loop_count) 308 .variant(config.chained_next_command_number)
293 .avgs().variant(config.hardware_average_mode) 309 .loop_()
294 .sts().variant(config.sample_time_mode) 310 .bits(config.loop_count)
295 .cmpen().variant(config.hardware_compare_mode); 311 .avgs()
312 .variant(config.hardware_average_mode)
313 .sts()
314 .variant(config.sample_time_mode)
315 .cmpen()
316 .variant(config.hardware_compare_mode);
296 if config.enable_wait_trigger { 317 if config.enable_wait_trigger {
297 w.wait_trig().enabled(); 318 w.wait_trig().enabled();
298 } 319 }
@@ -371,5 +392,7 @@ pub fn on_interrupt() {
371 392
372pub struct AdcHandler; 393pub struct AdcHandler;
373impl crate::interrupt::typelevel::Handler<crate::interrupt::typelevel::ADC1> for AdcHandler { 394impl crate::interrupt::typelevel::Handler<crate::interrupt::typelevel::ADC1> for AdcHandler {
374 unsafe fn on_interrupt() { on_interrupt(); } 395 unsafe fn on_interrupt() {
396 on_interrupt();
397 }
375} 398}
diff --git a/src/clocks.rs b/src/clocks.rs
index 5336c3efe..95d7ad567 100644
--- a/src/clocks.rs
+++ b/src/clocks.rs
@@ -112,10 +112,10 @@ pub unsafe fn init_fro16k(peripherals: &pac::Peripherals) {
112 let vbat = &peripherals.vbat0; 112 let vbat = &peripherals.vbat0;
113 // Enable FRO16K oscillator 113 // Enable FRO16K oscillator
114 vbat.froctla().modify(|_, w| w.fro_en().set_bit()); 114 vbat.froctla().modify(|_, w| w.fro_en().set_bit());
115 115
116 // Lock the control register 116 // Lock the control register
117 vbat.frolcka().modify(|_, w| w.lock().set_bit()); 117 vbat.frolcka().modify(|_, w| w.lock().set_bit());
118 118
119 // Enable clock outputs to both VSYS and VDD_CORE domains 119 // Enable clock outputs to both VSYS and VDD_CORE domains
120 // Bit 0: clk_16k0 to VSYS domain 120 // Bit 0: clk_16k0 to VSYS domain
121 // Bit 1: clk_16k1 to VDD_CORE domain 121 // Bit 1: clk_16k1 to VDD_CORE domain
@@ -130,7 +130,6 @@ pub unsafe fn enable_adc(peripherals: &pac::Peripherals) {
130pub unsafe fn select_adc_clock(peripherals: &pac::Peripherals) { 130pub unsafe fn select_adc_clock(peripherals: &pac::Peripherals) {
131 // Use FRO_LF_DIV (already running) MUX=0 DIV=0 131 // Use FRO_LF_DIV (already running) MUX=0 DIV=0
132 let mrcc = &peripherals.mrcc0; 132 let mrcc = &peripherals.mrcc0;
133 mrcc.mrcc_adc_clksel() 133 mrcc.mrcc_adc_clksel().write(|w| w.mux().clkroot_func_0());
134 .write(|w| w.mux().clkroot_func_0());
135 mrcc.mrcc_adc_clkdiv().write(|w| unsafe { w.bits(0) }); 134 mrcc.mrcc_adc_clkdiv().write(|w| unsafe { w.bits(0) });
136} \ No newline at end of file 135}
diff --git a/src/gpio.rs b/src/gpio.rs
index 08f375cba..faeefd333 100644
--- a/src/gpio.rs
+++ b/src/gpio.rs
@@ -66,7 +66,7 @@ pub trait PinId {
66} 66}
67 67
68pub mod pins { 68pub mod pins {
69 use super::{pac, AnyPin, PinId}; 69 use super::{AnyPin, PinId, pac};
70 70
71 macro_rules! define_pin { 71 macro_rules! define_pin {
72 ($Name:ident, $port:literal, $pin:literal, $GpioBlk:ident) => { 72 ($Name:ident, $port:literal, $pin:literal, $GpioBlk:ident) => {
diff --git a/src/interrupt.rs b/src/interrupt.rs
index 8226f01ab..d91e6479a 100644
--- a/src/interrupt.rs
+++ b/src/interrupt.rs
@@ -6,8 +6,8 @@ mod generated {
6 embassy_hal_internal::interrupt_mod!(OS_EVENT, LPUART2, RTC, ADC1); 6 embassy_hal_internal::interrupt_mod!(OS_EVENT, LPUART2, RTC, ADC1);
7} 7}
8 8
9pub use generated::interrupt::typelevel;
10pub use generated::interrupt::Priority; 9pub use generated::interrupt::Priority;
10pub use generated::interrupt::typelevel;
11 11
12use crate::pac::Interrupt; 12use crate::pac::Interrupt;
13use core::sync::atomic::{AtomicU16, AtomicU32, Ordering}; 13use core::sync::atomic::{AtomicU16, AtomicU32, Ordering};
diff --git a/src/lib.rs b/src/lib.rs
index eb4727106..518fe01d2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,31 +1,19 @@
1#![no_std] 1#![no_std]
2 2
3pub mod clocks; // still provide clock helpers 3pub mod clocks; // still provide clock helpers
4#[cfg(feature = "gpio")]
5pub mod gpio; 4pub mod gpio;
6pub mod pins; // pin mux helpers 5pub mod pins; // pin mux helpers
7pub mod reset; // reset control helpers 6pub mod reset; // reset control helpers
8 7
8pub mod adc;
9pub mod config; 9pub mod config;
10pub mod interrupt; 10pub mod interrupt;
11pub mod ostimer;
12pub mod uart;
13pub mod lpuart; 11pub mod lpuart;
12pub mod ostimer;
14pub mod rtc; 13pub mod rtc;
15pub mod adc; 14pub mod uart;
16 15
17embassy_hal_internal::peripherals!( 16embassy_hal_internal::peripherals!(LPUART2, OSTIMER0, GPIO, RTC0, ADC1,);
18 #[cfg(feature = "lpuart2")]
19 LPUART2,
20 #[cfg(feature = "ostimer0")]
21 OSTIMER0,
22 #[cfg(feature = "gpio")]
23 GPIO,
24 #[cfg(feature = "rtc0")]
25 RTC0,
26 #[cfg(feature = "adc1")]
27 ADC1,
28);
29 17
30/// Get access to the PAC Peripherals for low-level register access. 18/// Get access to the PAC Peripherals for low-level register access.
31/// This is a lazy-initialized singleton that can be called after init(). 19/// This is a lazy-initialized singleton that can be called after init().
@@ -42,43 +30,32 @@ pub fn pac() -> &'static pac::Peripherals {
42 } 30 }
43} 31}
44 32
45pub use cortex_m_rt; 33#[cfg(feature = "unstable-pac")]
46pub use mcxa276_pac as pac; 34pub use mcxa_pac as pac;
35#[cfg(not(feature = "unstable-pac"))]
36pub(crate) use mcxa_pac as pac;
37
47// Use cortex-m-rt's #[interrupt] attribute directly; PAC does not re-export it. 38// Use cortex-m-rt's #[interrupt] attribute directly; PAC does not re-export it.
48 39
49// Re-export interrupt traits and types 40// Re-export interrupt traits and types
41pub use adc::Adc1 as Adc1Token;
42pub use gpio::{AnyPin, Flex, Gpio as GpioToken, Input, Level, Output, pins::*};
50pub use interrupt::InterruptExt; 43pub use interrupt::InterruptExt;
51#[cfg(feature = "ostimer0")]
52pub use ostimer::Ostimer0 as Ostimer0Token; 44pub use ostimer::Ostimer0 as Ostimer0Token;
53#[cfg(feature = "lpuart2")]
54pub use uart::Lpuart2 as Uart2Token;
55#[cfg(feature = "rtc0")]
56pub use rtc::Rtc0 as Rtc0Token; 45pub use rtc::Rtc0 as Rtc0Token;
57#[cfg(feature = "adc1")] 46pub use uart::Lpuart2 as Uart2Token;
58pub use adc::Adc1 as Adc1Token;
59#[cfg(feature = "gpio")]
60pub use gpio::{pins::*, AnyPin, Flex, Gpio as GpioToken, Input, Level, Output};
61 47
62/// Initialize HAL with configuration (mirrors embassy-imxrt style). Minimal: just take peripherals. 48/// Initialize HAL with configuration (mirrors embassy-imxrt style). Minimal: just take peripherals.
63/// Also applies configurable NVIC priority for the OSTIMER OS_EVENT interrupt (no enabling). 49/// Also applies configurable NVIC priority for the OSTIMER OS_EVENT interrupt (no enabling).
64#[allow(unused_variables)] 50#[allow(unused_variables)]
65pub fn init(cfg: crate::config::Config) -> Peripherals { 51pub fn init(cfg: crate::config::Config) -> Peripherals {
66 let peripherals = Peripherals::take(); 52 let peripherals = Peripherals::take();
67 #[cfg(feature = "ostimer0")] 53 // Apply user-configured priority early; enabling is left to examples/apps
68 { 54 crate::interrupt::OS_EVENT.set_priority(cfg.time_interrupt_priority);
69 // Apply user-configured priority early; enabling is left to examples/apps 55 // Apply user-configured priority early; enabling is left to examples/apps
70 crate::interrupt::OS_EVENT.set_priority(cfg.time_interrupt_priority); 56 crate::interrupt::RTC.set_priority(cfg.rtc_interrupt_priority);
71 } 57 // Apply user-configured priority early; enabling is left to examples/apps
72 #[cfg(feature = "rtc0")] 58 crate::interrupt::ADC1.set_priority(cfg.adc_interrupt_priority);
73 {
74 // Apply user-configured priority early; enabling is left to examples/apps
75 crate::interrupt::RTC.set_priority(cfg.rtc_interrupt_priority);
76 }
77 #[cfg(feature = "adc1")]
78 {
79 // Apply user-configured priority early; enabling is left to examples/apps
80 crate::interrupt::ADC1.set_priority(cfg.adc_interrupt_priority);
81 }
82 peripherals 59 peripherals
83} 60}
84 61
diff --git a/src/lpuart/buffered.rs b/src/lpuart/buffered.rs
index 03673d975..e2382e86d 100644
--- a/src/lpuart/buffered.rs
+++ b/src/lpuart/buffered.rs
@@ -3,8 +3,8 @@ use core::marker::PhantomData;
3use core::sync::atomic::{AtomicBool, Ordering}; 3use core::sync::atomic::{AtomicBool, Ordering};
4use core::task::Poll; 4use core::task::Poll;
5 5
6use embassy_hal_internal::atomic_ring_buffer::RingBuffer;
7use embassy_hal_internal::Peri; 6use embassy_hal_internal::Peri;
7use embassy_hal_internal::atomic_ring_buffer::RingBuffer;
8use embassy_sync::waitqueue::AtomicWaker; 8use embassy_sync::waitqueue::AtomicWaker;
9 9
10use super::*; 10use super::*;
diff --git a/src/lpuart/mod.rs b/src/lpuart/mod.rs
index 431547f86..99f4a4a66 100644
--- a/src/lpuart/mod.rs
+++ b/src/lpuart/mod.rs
@@ -6,7 +6,7 @@ use paste::paste;
6use crate::pac; 6use crate::pac;
7use crate::pac::lpuart0::baud::Sbns as StopBits; 7use crate::pac::lpuart0::baud::Sbns as StopBits;
8use crate::pac::lpuart0::ctrl::{ 8use crate::pac::lpuart0::ctrl::{
9 Idlecfg as IdleConfig, Ilt as IdleType, Pt as Parity, M as DataBits, 9 Idlecfg as IdleConfig, Ilt as IdleType, M as DataBits, Pt as Parity,
10}; 10};
11use crate::pac::lpuart0::modir::{Txctsc as TxCtsConfig, Txctssrc as TxCtsSource}; 11use crate::pac::lpuart0::modir::{Txctsc as TxCtsConfig, Txctssrc as TxCtsSource};
12use crate::pac::lpuart0::stat::Msbf as MsbFirst; 12use crate::pac::lpuart0::stat::Msbf as MsbFirst;
diff --git a/src/ostimer.rs b/src/ostimer.rs
index b9688313a..6a4188db0 100644
--- a/src/ostimer.rs
+++ b/src/ostimer.rs
@@ -493,10 +493,8 @@ pub trait Instance {
493} 493}
494 494
495// Token for OSTIMER0 provided by embassy-hal-internal peripherals macro. 495// Token for OSTIMER0 provided by embassy-hal-internal peripherals macro.
496#[cfg(feature = "ostimer0")]
497pub type Ostimer0 = crate::peripherals::OSTIMER0; 496pub type Ostimer0 = crate::peripherals::OSTIMER0;
498 497
499#[cfg(feature = "ostimer0")]
500impl Instance for crate::peripherals::OSTIMER0 { 498impl Instance for crate::peripherals::OSTIMER0 {
501 #[inline(always)] 499 #[inline(always)]
502 fn ptr() -> *const Regs { 500 fn ptr() -> *const Regs {
@@ -505,7 +503,6 @@ impl Instance for crate::peripherals::OSTIMER0 {
505} 503}
506 504
507// Also implement Instance for the Peri wrapper type 505// Also implement Instance for the Peri wrapper type
508#[cfg(feature = "ostimer0")]
509impl Instance for embassy_hal_internal::Peri<'_, crate::peripherals::OSTIMER0> { 506impl Instance for embassy_hal_internal::Peri<'_, crate::peripherals::OSTIMER0> {
510 #[inline(always)] 507 #[inline(always)]
511 fn ptr() -> *const Regs { 508 fn ptr() -> *const Regs {
@@ -528,11 +525,10 @@ fn gray_to_bin(gray: u64) -> u64 {
528 bin 525 bin
529} 526}
530 527
531#[cfg(feature = "ostimer0")]
532pub mod time_driver { 528pub mod time_driver {
533 use super::{ 529 use super::{
534 bin_to_gray, now_ticks_read, Regs, ALARM_ACTIVE, ALARM_CALLBACK, ALARM_FLAG, 530 ALARM_ACTIVE, ALARM_CALLBACK, ALARM_FLAG, ALARM_TARGET_TIME, EVTIMER_HI_MASK,
535 ALARM_TARGET_TIME, EVTIMER_HI_MASK, EVTIMER_HI_SHIFT, LOW_32_BIT_MASK, 531 EVTIMER_HI_SHIFT, LOW_32_BIT_MASK, Regs, bin_to_gray, now_ticks_read,
536 }; 532 };
537 use crate::pac; 533 use crate::pac;
538 use core::sync::atomic::Ordering; 534 use core::sync::atomic::Ordering;
diff --git a/src/pins.rs b/src/pins.rs
index d46a3e6b3..1d92f9fef 100644
--- a/src/pins.rs
+++ b/src/pins.rs
@@ -57,7 +57,6 @@ pub unsafe fn configure_adc_pins() {
57 .inv0() 57 .inv0()
58 .lk() 58 .lk()
59 .lk0() 59 .lk0()
60
61 }); 60 });
62 core::arch::asm!("dsb sy; isb sy"); 61 core::arch::asm!("dsb sy; isb sy");
63} 62}
diff --git a/src/rtc.rs b/src/rtc.rs
index f83baab5e..5e3dfe6c1 100644
--- a/src/rtc.rs
+++ b/src/rtc.rs
@@ -1,6 +1,6 @@
1//! RTC DateTime driver. 1//! RTC DateTime driver.
2use crate::pac; 2use crate::pac;
3use crate::pac::rtc0::cr::{Um}; 3use crate::pac::rtc0::cr::Um;
4use core::sync::atomic::{AtomicBool, Ordering}; 4use core::sync::atomic::{AtomicBool, Ordering};
5 5
6type Regs = pac::rtc0::RegisterBlock; 6type Regs = pac::rtc0::RegisterBlock;
@@ -13,9 +13,7 @@ pub trait Instance {
13} 13}
14 14
15/// Token for RTC0 15/// Token for RTC0
16#[cfg(feature = "rtc0")]
17pub type Rtc0 = crate::peripherals::RTC0; 16pub type Rtc0 = crate::peripherals::RTC0;
18#[cfg(feature = "rtc0")]
19impl Instance for crate::peripherals::RTC0 { 17impl Instance for crate::peripherals::RTC0 {
20 #[inline(always)] 18 #[inline(always)]
21 fn ptr() -> *const Regs { 19 fn ptr() -> *const Regs {
@@ -24,7 +22,6 @@ impl Instance for crate::peripherals::RTC0 {
24} 22}
25 23
26// Also implement Instance for the Peri wrapper type 24// Also implement Instance for the Peri wrapper type
27#[cfg(feature = "rtc0")]
28impl Instance for embassy_hal_internal::Peri<'_, crate::peripherals::RTC0> { 25impl Instance for embassy_hal_internal::Peri<'_, crate::peripherals::RTC0> {
29 #[inline(always)] 26 #[inline(always)]
30 fn ptr() -> *const Regs { 27 fn ptr() -> *const Regs {
@@ -87,7 +84,6 @@ pub fn convert_datetime_to_seconds(datetime: &RtcDateTime) -> u32 {
87 seconds 84 seconds
88} 85}
89 86
90
91pub fn convert_seconds_to_datetime(seconds: u32) -> RtcDateTime { 87pub fn convert_seconds_to_datetime(seconds: u32) -> RtcDateTime {
92 let mut seconds_remaining = seconds; 88 let mut seconds_remaining = seconds;
93 let mut days = seconds_remaining / SECONDS_IN_A_DAY + 1; 89 let mut days = seconds_remaining / SECONDS_IN_A_DAY + 1;
@@ -166,11 +162,15 @@ impl<I: Instance> Rtc<I> {
166 rtc.cr().modify(|_, w| w.um().variant(config.update_mode)); 162 rtc.cr().modify(|_, w| w.um().variant(config.update_mode));
167 163
168 rtc.tcr().modify(|_, w| unsafe { 164 rtc.tcr().modify(|_, w| unsafe {
169 w.cir().bits(config.compensation_interval) 165 w.cir()
170 .tcr().bits(config.compensation_time) 166 .bits(config.compensation_interval)
167 .tcr()
168 .bits(config.compensation_time)
171 }); 169 });
172 170
173 Self { _inst: core::marker::PhantomData } 171 Self {
172 _inst: core::marker::PhantomData,
173 }
174 } 174 }
175 175
176 pub fn set_datetime(&self, datetime: RtcDateTime) { 176 pub fn set_datetime(&self, datetime: RtcDateTime) {
@@ -178,7 +178,7 @@ impl<I: Instance> Rtc<I> {
178 let seconds = convert_datetime_to_seconds(&datetime); 178 let seconds = convert_datetime_to_seconds(&datetime);
179 rtc.tsr().write(|w| unsafe { w.bits(seconds) }); 179 rtc.tsr().write(|w| unsafe { w.bits(seconds) });
180 } 180 }
181 181
182 pub fn get_datetime(&self) -> RtcDateTime { 182 pub fn get_datetime(&self) -> RtcDateTime {
183 let rtc = unsafe { &*I::ptr() }; 183 let rtc = unsafe { &*I::ptr() };
184 let seconds = rtc.tsr().read().bits(); 184 let seconds = rtc.tsr().read().bits();
@@ -203,7 +203,7 @@ impl<I: Instance> Rtc<I> {
203 } 203 }
204 } 204 }
205 205
206 pub fn get_alarm(&self) -> RtcDateTime{ 206 pub fn get_alarm(&self) -> RtcDateTime {
207 let rtc = unsafe { &*I::ptr() }; 207 let rtc = unsafe { &*I::ptr() };
208 let alarm_seconds = rtc.tar().read().bits(); 208 let alarm_seconds = rtc.tar().read().bits();
209 convert_seconds_to_datetime(alarm_seconds) 209 convert_seconds_to_datetime(alarm_seconds)
@@ -264,7 +264,7 @@ impl<I: Instance> Rtc<I> {
264 ALARM_TRIGGERED.load(Ordering::Relaxed) 264 ALARM_TRIGGERED.load(Ordering::Relaxed)
265 } 265 }
266} 266}
267 267
268pub fn on_interrupt() { 268pub fn on_interrupt() {
269 let rtc = unsafe { &*pac::Rtc0::ptr() }; 269 let rtc = unsafe { &*pac::Rtc0::ptr() };
270 // Check if this is actually a time alarm interrupt 270 // Check if this is actually a time alarm interrupt
@@ -277,5 +277,7 @@ pub fn on_interrupt() {
277 277
278pub struct RtcHandler; 278pub struct RtcHandler;
279impl crate::interrupt::typelevel::Handler<crate::interrupt::typelevel::RTC> for RtcHandler { 279impl crate::interrupt::typelevel::Handler<crate::interrupt::typelevel::RTC> for RtcHandler {
280 unsafe fn on_interrupt() { on_interrupt(); } 280 unsafe fn on_interrupt() {
281} \ No newline at end of file 281 on_interrupt();
282 }
283}
diff --git a/src/uart.rs b/src/uart.rs
index 45b6b2be3..65dd91492 100644
--- a/src/uart.rs
+++ b/src/uart.rs
@@ -15,9 +15,7 @@ pub trait Instance {
15} 15}
16 16
17/// Token for LPUART2 provided by embassy-hal-internal peripherals macro. 17/// Token for LPUART2 provided by embassy-hal-internal peripherals macro.
18#[cfg(feature = "lpuart2")]
19pub type Lpuart2 = crate::peripherals::LPUART2; 18pub type Lpuart2 = crate::peripherals::LPUART2;
20#[cfg(feature = "lpuart2")]
21impl Instance for crate::peripherals::LPUART2 { 19impl Instance for crate::peripherals::LPUART2 {
22 #[inline(always)] 20 #[inline(always)]
23 fn ptr() -> *const Regs { 21 fn ptr() -> *const Regs {
@@ -26,7 +24,6 @@ impl Instance for crate::peripherals::LPUART2 {
26} 24}
27 25
28// Also implement Instance for the Peri wrapper type 26// Also implement Instance for the Peri wrapper type
29#[cfg(feature = "lpuart2")]
30impl Instance for embassy_hal_internal::Peri<'_, crate::peripherals::LPUART2> { 27impl Instance for embassy_hal_internal::Peri<'_, crate::peripherals::LPUART2> {
31 #[inline(always)] 28 #[inline(always)]
32 fn ptr() -> *const Regs { 29 fn ptr() -> *const Regs {
@@ -111,7 +108,7 @@ impl<I: Instance> Uart<I> {
111 cortex_m::asm::delay(3); // Short delay for reset to take effect 108 cortex_m::asm::delay(3); // Short delay for reset to take effect
112 l.global().write(|w| w.rst().no_effect()); 109 l.global().write(|w| w.rst().no_effect());
113 cortex_m::asm::delay(10); // Allow peripheral to stabilize after reset 110 cortex_m::asm::delay(10); // Allow peripheral to stabilize after reset
114 // 2) BAUD 111 // 2) BAUD
115 let (osr, sbr) = compute_osr_sbr(cfg.src_hz, cfg.baud); 112 let (osr, sbr) = compute_osr_sbr(cfg.src_hz, cfg.baud);
116 l.baud().modify(|_, w| { 113 l.baud().modify(|_, w| {
117 let w = match cfg.stop_bits { 114 let w = match cfg.stop_bits {
@@ -145,7 +142,9 @@ impl<I: Instance> Uart<I> {
145 }); 142 });
146 l.water() 143 l.water()
147 .modify(|_, w| unsafe { w.txwater().bits(0).rxwater().bits(0) }); 144 .modify(|_, w| unsafe { w.txwater().bits(0).rxwater().bits(0) });
148 Self { _inst: core::marker::PhantomData } 145 Self {
146 _inst: core::marker::PhantomData,
147 }
149 } 148 }
150 149
151 /// Enable RX interrupts. The caller must ensure an appropriate IRQ handler is installed. 150 /// Enable RX interrupts. The caller must ensure an appropriate IRQ handler is installed.