Skip to content

Commit 0fca22d

Browse files
committed
Change pin_port bitfield to match psel registers
1 parent 0fa9144 commit 0fca22d

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

nrf-hal-common/src/gpio.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ pub enum Port {
4343
Port1,
4444
}
4545

46-
#[cfg(any(feature = "52833", feature = "52840"))]
47-
impl Port {
48-
fn bit(&self) -> bool {
49-
match self {
50-
Port::Port0 => false,
51-
Port::Port1 => true,
52-
}
53-
}
54-
}
55-
5646
// ===============================================================
5747
// Implement Generic Pins for this port, which allows you to use
5848
// other peripherals without having to be completely rust-generic
@@ -85,7 +75,7 @@ impl<MODE> Pin<MODE> {
8575
let port_bits = match port {
8676
Port::Port0 => 0x00,
8777
#[cfg(any(feature = "52833", feature = "52840"))]
88-
Port::Port1 => 0x80,
78+
Port::Port1 => 0x20,
8979
};
9080
Self {
9181
pin_port: pin | port_bits,
@@ -94,15 +84,8 @@ impl<MODE> Pin<MODE> {
9484
}
9585

9686
pub unsafe fn from_psel_bits(psel_bits: u32) -> Self {
97-
let pin = (psel_bits & 0x1f) as u8;
98-
let port = (psel_bits & 0x20) as u8;
99-
let port_bits = match port {
100-
#[cfg(any(feature = "52833", feature = "52840"))]
101-
0x20 => 0x80,
102-
_ => 0x00,
103-
};
10487
Self {
105-
pin_port: pin | port_bits,
88+
pin_port: psel_bits as u8,
10689
_mode: PhantomData,
10790
}
10891
}
@@ -111,7 +94,7 @@ impl<MODE> Pin<MODE> {
11194
pub fn pin(&self) -> u8 {
11295
#[cfg(any(feature = "52833", feature = "52840"))]
11396
{
114-
self.pin_port & 0x7f
97+
self.pin_port & 0x1f
11598
}
11699

117100
#[cfg(not(any(feature = "52833", feature = "52840")))]
@@ -124,7 +107,7 @@ impl<MODE> Pin<MODE> {
124107
pub fn port(&self) -> Port {
125108
#[cfg(any(feature = "52833", feature = "52840"))]
126109
{
127-
if self.pin_port & 0x80 == 0 {
110+
if self.pin_port & 0x20 == 0 {
128111
Port::Port0
129112
} else {
130113
Port::Port1
@@ -139,10 +122,7 @@ impl<MODE> Pin<MODE> {
139122

140123
#[inline]
141124
pub fn psel_bits(&self) -> u32 {
142-
let psel = (self.pin() & 0x1f) as u32;
143-
#[cfg(any(feature = "52833", feature = "52840"))]
144-
let psel = if self.port().bit() { psel | 0x20 } else { psel };
145-
psel
125+
self.pin_port as u32
146126
}
147127

148128
fn block(&self) -> &gpio::RegisterBlock {

0 commit comments

Comments
 (0)