Skip to content

Commit 674713d

Browse files
committed
Mark all gpio functions as inline
1 parent 712227e commit 674713d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/gpio.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ where
357357
Index: marker::Index,
358358
{
359359
/// Configures the pin to operate as an input pin
360+
#[inline]
360361
pub fn into_input(self) -> Pin<Gpio, Index, Input> {
361362
// NOTE(unsafe) atomic modify with no side effects
362363
unsafe { (*self.gpio.ptr()).input(self.index.index()) };
@@ -365,6 +366,7 @@ where
365366

366367
/// Convenience method to configure the pin to operate as an input pin
367368
/// and set the internal resistor floating
369+
#[inline]
368370
pub fn into_floating_input(self) -> Pin<Gpio, Index, Input> {
369371
// NOTE(unsafe) atomic modify with no side effects
370372
unsafe {
@@ -376,6 +378,7 @@ where
376378

377379
/// Convenience method to configure the pin to operate as an input pin
378380
/// and set the internal resistor pull-up
381+
#[inline]
379382
pub fn into_pull_up_input(self) -> Pin<Gpio, Index, Input> {
380383
// NOTE(unsafe) atomic modify with no side effects
381384
unsafe {
@@ -387,6 +390,7 @@ where
387390

388391
/// Convenience method to configure the pin to operate as an input pin
389392
/// and set the internal resistor pull-down
393+
#[inline]
390394
pub fn into_pull_down_input(self) -> Pin<Gpio, Index, Input> {
391395
// NOTE(unsafe) atomic modify with no side effects
392396
unsafe {
@@ -397,6 +401,7 @@ where
397401
}
398402

399403
/// Configures the pin to operate as a push-pull output pin
404+
#[inline]
400405
pub fn into_push_pull_output(self) -> Pin<Gpio, Index, Output<PushPull>> {
401406
// NOTE(unsafe) atomic modify with no side effects
402407
unsafe {
@@ -407,6 +412,7 @@ where
407412
}
408413

409414
/// Configures the pin to operate as an open-drain output pin
415+
#[inline]
410416
pub fn into_open_drain_output(self) -> Pin<Gpio, Index, Output<OpenDrain>> {
411417
// NOTE(unsafe) atomic modify with no side effects
412418
unsafe {
@@ -417,6 +423,7 @@ where
417423
}
418424

419425
/// Configures the pin to operate as an alternate function push-pull output pin
426+
#[inline]
420427
pub fn into_af_push_pull<const A: u8>(self) -> Pin<Gpio, Index, Alternate<PushPull, A>>
421428
where
422429
Self: marker::IntoAf<A>,
@@ -431,6 +438,7 @@ where
431438
}
432439

433440
/// Configures the pin to operate as an alternate function open-drain output pin
441+
#[inline]
434442
pub fn into_af_open_drain<const A: u8>(self) -> Pin<Gpio, Index, Alternate<OpenDrain, A>>
435443
where
436444
Self: marker::IntoAf<A>,
@@ -445,6 +453,7 @@ where
445453
}
446454

447455
/// Configures the pin to operate as an analog pin, with disabled schmitt trigger.
456+
#[inline]
448457
pub fn into_analog(self) -> Pin<Gpio, Index, Analog> {
449458
// NOTE(unsafe) atomic modify with no side effects
450459
unsafe {
@@ -510,6 +519,7 @@ where
510519
Mode: marker::OutputSpeed,
511520
{
512521
/// Set pin output slew rate
522+
#[inline]
513523
pub fn set_speed(&mut self, speed: Speed) {
514524
// NOTE(unsafe) atomic modify with no side effects
515525
match speed {
@@ -527,6 +537,7 @@ where
527537
Mode: marker::Active,
528538
{
529539
/// Set the internal pull-up and pull-down resistor
540+
#[inline]
530541
pub fn set_internal_resistor(&mut self, resistor: Resistor) {
531542
// NOTE(unsafe) atomic modify with no side effects
532543
match resistor {
@@ -537,6 +548,7 @@ where
537548
}
538549

539550
/// Enables / disables the internal pull up (Provided for compatibility with other stm32 HALs)
551+
#[inline]
540552
pub fn internal_pull_up(&mut self, on: bool) {
541553
self.set_internal_resistor(match on {
542554
true => Resistor::PullUp,
@@ -552,12 +564,14 @@ where
552564
{
553565
type Error = Infallible;
554566

567+
#[inline]
555568
fn set_high(&mut self) -> Result<(), Self::Error> {
556569
// NOTE(unsafe) atomic write to a stateless register
557570
unsafe { (*self.gpio.ptr()).set_high(self.index.index()) };
558571
Ok(())
559572
}
560573

574+
#[inline]
561575
fn set_low(&mut self) -> Result<(), Self::Error> {
562576
// NOTE(unsafe) atomic write to a stateless register
563577
unsafe { (*self.gpio.ptr()).set_low(self.index.index()) };
@@ -573,10 +587,12 @@ where
573587
{
574588
type Error = Infallible;
575589

590+
#[inline]
576591
fn is_high(&self) -> Result<bool, Self::Error> {
577592
Ok(!self.is_low()?)
578593
}
579594

595+
#[inline]
580596
fn is_low(&self) -> Result<bool, Self::Error> {
581597
// NOTE(unsafe) atomic read with no side effects
582598
Ok(unsafe { (*self.gpio.ptr()).is_low(self.index.index()) })
@@ -588,10 +604,12 @@ where
588604
Gpio: marker::Gpio,
589605
Index: marker::Index,
590606
{
607+
#[inline]
591608
fn is_set_high(&self) -> Result<bool, Self::Error> {
592609
Ok(!self.is_set_low()?)
593610
}
594611

612+
#[inline]
595613
fn is_set_low(&self) -> Result<bool, Self::Error> {
596614
// NOTE(unsafe) atomic read with no side effects
597615
Ok(unsafe { (*self.gpio.ptr()).is_set_low(self.index.index()) })
@@ -635,6 +653,7 @@ where
635653
/// This is also useful for all other [`cortex_m::peripheral::NVIC`] functions.
636654
// TODO(Sh3rm4n): It would be cool to have this either const or have a const function.
637655
// But this is currenlty not possible, because index() is runtime defined.
656+
#[inline]
638657
pub fn interrupt(&self) -> Interrupt {
639658
match self.index.index() {
640659
0 => Interrupt::EXTI0,
@@ -655,6 +674,7 @@ where
655674
}
656675

657676
/// Generate interrupt on rising edge, falling edge, or both
677+
#[inline]
658678
pub fn trigger_on_edge(&mut self, exti: &mut EXTI, edge: Edge) {
659679
const BITWIDTH: u8 = 1;
660680
let index = self.index.index();
@@ -676,6 +696,7 @@ where
676696
///
677697
/// Remeber to also configure the interrupt pin on
678698
/// the SysCfg site, with [`crate::syscfg::SysCfg::select_exti_interrupt_source()`]
699+
#[inline]
679700
pub fn configure_interrupt(&mut self, exti: &mut EXTI, enable: impl Into<Toggle>) {
680701
const BITWIDTH: u8 = 1;
681702

@@ -694,22 +715,26 @@ where
694715
///
695716
/// Remeber to also configure the interrupt pin on
696717
/// the SysCfg site, with [`crate::syscfg::SysCfg::select_exti_interrupt_source()`]
718+
#[inline]
697719
pub fn enable_interrupt(&mut self, exti: &mut EXTI) {
698720
self.configure_interrupt(exti, Toggle::On)
699721
}
700722

701723
/// Disable external interrupts from this pin
724+
#[inline]
702725
pub fn disable_interrupt(&mut self, exti: &mut EXTI) {
703726
self.configure_interrupt(exti, Toggle::Off)
704727
}
705728

706729
/// Clear the interrupt pending bit for this pin
730+
#[inline]
707731
pub fn clear_interrupt(&mut self) {
708732
// SAFETY: Atomic write to register without side-effects.
709733
unsafe { reg_for_cpu!((*EXTI::ptr()), pr).write(|w| w.bits(1 << self.index.index())) };
710734
}
711735

712736
/// Reads the interrupt pending bit for this pin
737+
#[inline]
713738
pub fn is_interrupt_pending(&self) -> bool {
714739
// SAFETY: Atomic write to register without side-effects.
715740
unsafe { reg_for_cpu!((*EXTI::ptr()), pr).read().bits() & (1 << self.index.index()) != 0 }

0 commit comments

Comments
 (0)