nrf/gpiote: make number() public, change to usize
This commit is contained in:
parent
90f599bc2f
commit
646be40ac5
@ -1,15 +1,11 @@
|
|||||||
use core::convert::Infallible;
|
use core::convert::Infallible;
|
||||||
use core::future::Future;
|
use core::future::Future;
|
||||||
use core::intrinsics::transmute;
|
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use core::mem::{self, ManuallyDrop};
|
|
||||||
use core::ops::Deref;
|
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
use core::ptr;
|
|
||||||
use core::task::{Context, Poll};
|
use core::task::{Context, Poll};
|
||||||
use embassy::interrupt::InterruptExt;
|
use embassy::interrupt::InterruptExt;
|
||||||
use embassy::traits::gpio::{WaitForHigh, WaitForLow};
|
use embassy::traits::gpio::{WaitForHigh, WaitForLow};
|
||||||
use embassy::util::{AtomicWaker, PeripheralBorrow, Signal};
|
use embassy::util::AtomicWaker;
|
||||||
use embassy_extras::impl_unborrow;
|
use embassy_extras::impl_unborrow;
|
||||||
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
|
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
|
||||||
use futures::future::poll_fn;
|
use futures::future::poll_fn;
|
||||||
@ -19,7 +15,6 @@ use crate::gpio::{AnyPin, Input, Output, Pin as GpioPin, Port, Pull};
|
|||||||
use crate::pac;
|
use crate::pac;
|
||||||
use crate::pac::generic::Reg;
|
use crate::pac::generic::Reg;
|
||||||
use crate::pac::gpiote::_TASKS_OUT;
|
use crate::pac::gpiote::_TASKS_OUT;
|
||||||
use crate::pac::p0 as pac_gpio;
|
|
||||||
use crate::{interrupt, peripherals};
|
use crate::{interrupt, peripherals};
|
||||||
|
|
||||||
#[cfg(not(feature = "51"))]
|
#[cfg(not(feature = "51"))]
|
||||||
@ -32,9 +27,9 @@ pub const PIN_COUNT: usize = 48;
|
|||||||
#[cfg(not(any(feature = "52833", feature = "52840")))]
|
#[cfg(not(any(feature = "52833", feature = "52840")))]
|
||||||
pub const PIN_COUNT: usize = 32;
|
pub const PIN_COUNT: usize = 32;
|
||||||
|
|
||||||
const NEW_AWR: AtomicWaker = AtomicWaker::new();
|
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||||
static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AWR; CHANNEL_COUNT];
|
static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT];
|
||||||
static PORT_WAKERS: [AtomicWaker; PIN_COUNT] = [NEW_AWR; PIN_COUNT];
|
static PORT_WAKERS: [AtomicWaker; PIN_COUNT] = [NEW_AW; PIN_COUNT];
|
||||||
|
|
||||||
pub enum InputChannelPolarity {
|
pub enum InputChannelPolarity {
|
||||||
None,
|
None,
|
||||||
@ -135,7 +130,7 @@ pub struct InputChannel<'d, C: Channel, T: GpioPin> {
|
|||||||
impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> {
|
impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
let num = self.ch.number() as usize;
|
let num = self.ch.number();
|
||||||
g.config[num].write(|w| w.mode().disabled());
|
g.config[num].write(|w| w.mode().disabled());
|
||||||
g.intenclr.write(|w| unsafe { w.bits(1 << num) });
|
g.intenclr.write(|w| unsafe { w.bits(1 << num) });
|
||||||
}
|
}
|
||||||
@ -149,7 +144,7 @@ impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
|
|||||||
polarity: InputChannelPolarity,
|
polarity: InputChannelPolarity,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
let num = ch.number() as usize;
|
let num = ch.number();
|
||||||
|
|
||||||
g.config[num].write(|w| {
|
g.config[num].write(|w| {
|
||||||
match polarity {
|
match polarity {
|
||||||
@ -173,7 +168,7 @@ impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
|
|||||||
|
|
||||||
pub async fn wait(&self) {
|
pub async fn wait(&self) {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
let num = self.ch.number() as usize;
|
let num = self.ch.number();
|
||||||
|
|
||||||
// Enable interrupt
|
// Enable interrupt
|
||||||
g.events_in[num].reset();
|
g.events_in[num].reset();
|
||||||
@ -212,7 +207,7 @@ pub struct OutputChannel<'d, C: Channel, T: GpioPin> {
|
|||||||
impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
|
impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
let num = self.ch.number() as usize;
|
let num = self.ch.number();
|
||||||
g.config[num].write(|w| w.mode().disabled());
|
g.config[num].write(|w| w.mode().disabled());
|
||||||
g.intenclr.write(|w| unsafe { w.bits(1 << num) });
|
g.intenclr.write(|w| unsafe { w.bits(1 << num) });
|
||||||
}
|
}
|
||||||
@ -226,7 +221,7 @@ impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
|
|||||||
polarity: OutputChannelPolarity,
|
polarity: OutputChannelPolarity,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
let num = ch.number() as usize;
|
let num = ch.number();
|
||||||
|
|
||||||
g.config[num].write(|w| {
|
g.config[num].write(|w| {
|
||||||
w.mode().task();
|
w.mode().task();
|
||||||
@ -253,41 +248,41 @@ impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
|
|||||||
/// Triggers `task out` (as configured with task_out_polarity, defaults to Toggle).
|
/// Triggers `task out` (as configured with task_out_polarity, defaults to Toggle).
|
||||||
pub fn out(&self) {
|
pub fn out(&self) {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
g.tasks_out[self.ch.number() as usize].write(|w| unsafe { w.bits(1) });
|
g.tasks_out[self.ch.number()].write(|w| unsafe { w.bits(1) });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Triggers `task set` (set associated pin high).
|
/// Triggers `task set` (set associated pin high).
|
||||||
#[cfg(not(feature = "51"))]
|
#[cfg(not(feature = "51"))]
|
||||||
pub fn set(&self) {
|
pub fn set(&self) {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
g.tasks_set[self.ch.number() as usize].write(|w| unsafe { w.bits(1) });
|
g.tasks_set[self.ch.number()].write(|w| unsafe { w.bits(1) });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Triggers `task clear` (set associated pin low).
|
/// Triggers `task clear` (set associated pin low).
|
||||||
#[cfg(not(feature = "51"))]
|
#[cfg(not(feature = "51"))]
|
||||||
pub fn clear(&self) {
|
pub fn clear(&self) {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
g.tasks_clr[self.ch.number() as usize].write(|w| unsafe { w.bits(1) });
|
g.tasks_clr[self.ch.number()].write(|w| unsafe { w.bits(1) });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns reference to task_out endpoint for PPI.
|
/// Returns reference to task_out endpoint for PPI.
|
||||||
pub fn task_out(&self) -> &Reg<u32, _TASKS_OUT> {
|
pub fn task_out(&self) -> &Reg<u32, _TASKS_OUT> {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
&g.tasks_out[self.ch.number() as usize]
|
&g.tasks_out[self.ch.number()]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns reference to task_clr endpoint for PPI.
|
/// Returns reference to task_clr endpoint for PPI.
|
||||||
#[cfg(not(feature = "51"))]
|
#[cfg(not(feature = "51"))]
|
||||||
pub fn task_clr(&self) -> &Reg<u32, _TASKS_CLR> {
|
pub fn task_clr(&self) -> &Reg<u32, _TASKS_CLR> {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
&g.tasks_clr[self.ch.number() as usize]
|
&g.tasks_clr[self.ch.number()]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns reference to task_set endpoint for PPI.
|
/// Returns reference to task_set endpoint for PPI.
|
||||||
#[cfg(not(feature = "51"))]
|
#[cfg(not(feature = "51"))]
|
||||||
pub fn task_set(&self) -> &Reg<u32, _TASKS_SET> {
|
pub fn task_set(&self) -> &Reg<u32, _TASKS_SET> {
|
||||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||||
&g.tasks_set[self.ch.number() as usize]
|
&g.tasks_set[self.ch.number()]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,15 +365,14 @@ impl<'a> Future for PortInputFuture<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod sealed {
|
mod sealed {
|
||||||
pub trait Channel {
|
pub trait Channel {}
|
||||||
fn number(&self) -> u8;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Channel: sealed::Channel + Sized {
|
pub trait Channel: sealed::Channel + Sized {
|
||||||
|
fn number(&self) -> usize;
|
||||||
fn degrade(self) -> AnyChannel {
|
fn degrade(self) -> AnyChannel {
|
||||||
AnyChannel {
|
AnyChannel {
|
||||||
number: self.number(),
|
number: self.number() as u8,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,21 +381,21 @@ pub struct AnyChannel {
|
|||||||
number: u8,
|
number: u8,
|
||||||
}
|
}
|
||||||
impl_unborrow!(AnyChannel);
|
impl_unborrow!(AnyChannel);
|
||||||
impl Channel for AnyChannel {}
|
impl sealed::Channel for AnyChannel {}
|
||||||
impl sealed::Channel for AnyChannel {
|
impl Channel for AnyChannel {
|
||||||
fn number(&self) -> u8 {
|
fn number(&self) -> usize {
|
||||||
self.number
|
self.number as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_channel {
|
macro_rules! impl_channel {
|
||||||
($type:ident, $number:expr) => {
|
($type:ident, $number:expr) => {
|
||||||
impl sealed::Channel for peripherals::$type {
|
impl sealed::Channel for peripherals::$type {}
|
||||||
fn number(&self) -> u8 {
|
impl Channel for peripherals::$type {
|
||||||
$number
|
fn number(&self) -> usize {
|
||||||
|
$number as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Channel for peripherals::$type {}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user