Undoing unnecessary changes

This commit is contained in:
Dion Dokter
2021-10-12 11:43:57 +02:00
parent 995cd01cbc
commit 2c2c284482
14 changed files with 90 additions and 151 deletions

View File

@ -22,18 +22,6 @@ pub const PIN_COUNT: usize = 48;
#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
pub const PIN_COUNT: usize = 32;
#[cfg(not(feature = "nrf9160"))]
pub(crate) use pac::P0;
#[cfg(feature = "nrf9160")]
pub(crate) use pac::P0_NS as P0;
#[cfg(not(feature = "nrf9160"))]
pub(crate) use pac::P1;
#[cfg(not(feature = "nrf9160"))]
pub(crate) use pac::GPIOTE;
#[cfg(feature = "nrf9160")]
pub(crate) use pac::GPIOTE1_NS as GPIOTE;
const NEW_AW: AtomicWaker = AtomicWaker::new();
static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT];
static PORT_WAKERS: [AtomicWaker; PIN_COUNT] = [NEW_AW; PIN_COUNT];
@ -54,9 +42,9 @@ pub enum OutputChannelPolarity {
pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
#[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
let ports = unsafe { &[&*P0::ptr(), &*P1::ptr()] };
let ports = unsafe { &[&*pac::P0::ptr(), &*pac::P1::ptr()] };
#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
let ports = unsafe { &[&*P0::ptr()] };
let ports = unsafe { &[&*pac::P0::ptr()] };
for &p in ports {
// Enable latched detection
@ -76,7 +64,7 @@ pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
irq.set_priority(irq_prio);
irq.enable();
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
g.events_port.write(|w| w);
g.intenset.write(|w| w.port().set());
}
@ -94,7 +82,7 @@ fn GPIOTE1() {
}
unsafe fn handle_gpiote_interrupt() {
let g = &*GPIOTE::ptr();
let g = &*pac::GPIOTE::ptr();
for i in 0..CHANNEL_COUNT {
if g.events_in[i].read().bits() != 0 {
@ -107,9 +95,9 @@ unsafe fn handle_gpiote_interrupt() {
g.events_port.write(|w| w);
#[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
let ports = &[&*P0::ptr(), &*P1::ptr()];
let ports = &[&*pac::P0::ptr(), &*pac::P1::ptr()];
#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
let ports = &[&*P0::ptr()];
let ports = &[&*pac::P0::ptr()];
for (port, &p) in ports.iter().enumerate() {
let bits = p.latch.read().bits();
@ -146,7 +134,7 @@ pub struct InputChannel<'d, C: Channel, T: GpioPin> {
impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> {
fn drop(&mut self) {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
let num = self.ch.number();
g.config[num].write(|w| w.mode().disabled());
g.intenclr.write(|w| unsafe { w.bits(1 << num) });
@ -155,7 +143,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> {
impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
pub fn new(ch: C, pin: Input<'d, T>, polarity: InputChannelPolarity) -> Self {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
let num = ch.number();
g.config[num].write(|w| {
@ -179,7 +167,7 @@ impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
}
pub async fn wait(&self) {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
let num = self.ch.number();
// Enable interrupt
@ -200,7 +188,7 @@ impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
/// Returns the IN event, for use with PPI.
pub fn event_in(&self) -> Event {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
Event::from_reg(&g.events_in[self.ch.number()])
}
}
@ -225,7 +213,7 @@ pub struct OutputChannel<'d, C: Channel, T: GpioPin> {
impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
fn drop(&mut self) {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
let num = self.ch.number();
g.config[num].write(|w| w.mode().disabled());
g.intenclr.write(|w| unsafe { w.bits(1 << num) });
@ -234,7 +222,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
pub fn new(ch: C, pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
let num = ch.number();
g.config[num].write(|w| {
@ -261,41 +249,41 @@ impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
/// Triggers `task out` (as configured with task_out_polarity, defaults to Toggle).
pub fn out(&self) {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
g.tasks_out[self.ch.number()].write(|w| unsafe { w.bits(1) });
}
/// Triggers `task set` (set associated pin high).
#[cfg(not(feature = "nrf51"))]
pub fn set(&self) {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
g.tasks_set[self.ch.number()].write(|w| unsafe { w.bits(1) });
}
/// Triggers `task clear` (set associated pin low).
#[cfg(not(feature = "nrf51"))]
pub fn clear(&self) {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
g.tasks_clr[self.ch.number()].write(|w| unsafe { w.bits(1) });
}
/// Returns the OUT task, for use with PPI.
pub fn task_out(&self) -> Task {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
Task::from_reg(&g.tasks_out[self.ch.number()])
}
/// Returns the CLR task, for use with PPI.
#[cfg(not(feature = "nrf51"))]
pub fn task_clr(&self) -> Task {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
Task::from_reg(&g.tasks_clr[self.ch.number()])
}
/// Returns the SET task, for use with PPI.
#[cfg(not(feature = "nrf51"))]
pub fn task_set(&self) -> Task {
let g = unsafe { &*GPIOTE::ptr() };
let g = unsafe { &*pac::GPIOTE::ptr() };
Task::from_reg(&g.tasks_set[self.ch.number()])
}
}