Remove a bunch of generic params from GpioPin (#553)
This commit is contained in:
parent
caec716c35
commit
02c7e38cf5
@ -42,7 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Breaking
|
### Breaking
|
||||||
|
|
||||||
- As part of the refactoring in #537, the public GPIO type has changed.
|
- Significantly simplified user-facing GPIO pin types. (#553)
|
||||||
|
|
||||||
## [0.9.0] - 2023-05-02
|
## [0.9.0] - 2023-05-02
|
||||||
|
|
||||||
|
|||||||
@ -202,7 +202,7 @@ pub trait OutputPin: Pin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub trait InteruptStatusRegisterAccess {
|
pub trait InterruptStatusRegisterAccess {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32;
|
fn pro_cpu_interrupt_status_read() -> u32;
|
||||||
|
|
||||||
fn pro_cpu_nmi_status_read() -> u32;
|
fn pro_cpu_nmi_status_read() -> u32;
|
||||||
@ -217,29 +217,29 @@ pub trait InteruptStatusRegisterAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct InteruptStatusRegisterAccessBank0;
|
pub struct InterruptStatusRegisterAccessBank0;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct InteruptStatusRegisterAccessBank1;
|
pub struct InterruptStatusRegisterAccessBank1;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub trait InterruptStatusRegisters<RegisterAccess>
|
pub trait InterruptStatusRegisters<RegisterAccess>
|
||||||
where
|
where
|
||||||
RegisterAccess: InteruptStatusRegisterAccess,
|
RegisterAccess: InterruptStatusRegisterAccess,
|
||||||
{
|
{
|
||||||
fn pro_cpu_interrupt_status_read(&self) -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
RegisterAccess::pro_cpu_interrupt_status_read()
|
RegisterAccess::pro_cpu_interrupt_status_read()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pro_cpu_nmi_status_read(&self) -> u32 {
|
fn pro_cpu_nmi_status_read() -> u32 {
|
||||||
RegisterAccess::pro_cpu_nmi_status_read()
|
RegisterAccess::pro_cpu_nmi_status_read()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app_cpu_interrupt_status_read(&self) -> u32 {
|
fn app_cpu_interrupt_status_read() -> u32 {
|
||||||
RegisterAccess::app_cpu_interrupt_status_read()
|
RegisterAccess::app_cpu_interrupt_status_read()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app_cpu_nmi_status_read(&self) -> u32 {
|
fn app_cpu_nmi_status_read() -> u32 {
|
||||||
RegisterAccess::app_cpu_nmi_status_read()
|
RegisterAccess::app_cpu_nmi_status_read()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -470,48 +470,30 @@ impl PinType for InputOnlyAnalogPinType {}
|
|||||||
impl IsInputPin for InputOnlyAnalogPinType {}
|
impl IsInputPin for InputOnlyAnalogPinType {}
|
||||||
impl IsAnalogPin for InputOnlyAnalogPinType {}
|
impl IsAnalogPin for InputOnlyAnalogPinType {}
|
||||||
|
|
||||||
pub struct GpioPin<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8>
|
pub struct GpioPin<MODE, const GPIONUM: u8> {
|
||||||
where
|
|
||||||
RA: BankGpioRegisterAccess,
|
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
PINTYPE: PinType,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
|
||||||
_mode: PhantomData<MODE>,
|
_mode: PhantomData<MODE>,
|
||||||
_pintype: PhantomData<PINTYPE>,
|
|
||||||
_reg_access: PhantomData<RA>,
|
|
||||||
_ira: PhantomData<IRA>,
|
|
||||||
_signals: PhantomData<SIG>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal::digital::v2::InputPin
|
impl<MODE, const GPIONUM: u8> embedded_hal::digital::v2::InputPin for GpioPin<Input<MODE>, GPIONUM>
|
||||||
for GpioPin<Input<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
PINTYPE: PinType,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
type Error = Infallible;
|
type Error = Infallible;
|
||||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||||
Ok(RA::read_input() & (1 << (GPIONUM % 32)) != 0)
|
Ok(<Self as GpioProperties>::Bank::read_input() & (1 << (GPIONUM % 32)) != 0)
|
||||||
}
|
}
|
||||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||||
Ok(!self.is_high()?)
|
Ok(!self.is_high()?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal::digital::v2::InputPin
|
impl<const GPIONUM: u8> embedded_hal::digital::v2::InputPin for GpioPin<Output<OpenDrain>, GPIONUM>
|
||||||
for GpioPin<Output<OpenDrain>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
PINTYPE: PinType,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
type Error = Infallible;
|
type Error = Infallible;
|
||||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||||
Ok(RA::read_input() & (1 << (GPIONUM % 32)) != 0)
|
Ok(<Self as GpioProperties>::Bank::read_input() & (1 << (GPIONUM % 32)) != 0)
|
||||||
}
|
}
|
||||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||||
Ok(!self.is_high()?)
|
Ok(!self.is_high()?)
|
||||||
@ -519,55 +501,38 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "eh1")]
|
#[cfg(feature = "eh1")]
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal_1::digital::ErrorType
|
impl<MODE, const GPIONUM: u8> embedded_hal_1::digital::ErrorType for GpioPin<Input<MODE>, GPIONUM>
|
||||||
for GpioPin<Input<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
PINTYPE: PinType,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
type Error = Infallible;
|
type Error = Infallible;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "eh1")]
|
#[cfg(feature = "eh1")]
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal_1::digital::InputPin
|
impl<MODE, const GPIONUM: u8> embedded_hal_1::digital::InputPin for GpioPin<Input<MODE>, GPIONUM>
|
||||||
for GpioPin<Input<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
PINTYPE: PinType,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||||
Ok(RA::read_input() & (1 << (GPIONUM % 32)) != 0)
|
Ok(<Self as GpioProperties>::Bank::read_input() & (1 << (GPIONUM % 32)) != 0)
|
||||||
}
|
}
|
||||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||||
Ok(!self.is_high()?)
|
Ok(!self.is_high()?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> GpioPin<MODE, RA, IRA, PINTYPE, SIG, GPIONUM>
|
impl<MODE, const GPIONUM: u8> GpioPin<MODE, GPIONUM>
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
PINTYPE: PinType,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
pub(crate) fn new() -> Self {
|
pub(crate) fn new() -> Self {
|
||||||
Self {
|
Self { _mode: PhantomData }
|
||||||
_mode: PhantomData,
|
|
||||||
_pintype: PhantomData,
|
|
||||||
_reg_access: PhantomData,
|
|
||||||
_ira: PhantomData,
|
|
||||||
_signals: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_input(&self, pull_down: bool, pull_up: bool) {
|
fn init_input(&self, pull_down: bool, pull_up: bool) {
|
||||||
let gpio = unsafe { &*GPIO::PTR };
|
let gpio = unsafe { &*GPIO::PTR };
|
||||||
|
|
||||||
RA::write_out_en_clear(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_out_en_clear(1 << (GPIONUM % 32));
|
||||||
gpio.func_out_sel_cfg[GPIONUM as usize]
|
gpio.func_out_sel_cfg[GPIONUM as usize]
|
||||||
.modify(|_, w| unsafe { w.out_sel().bits(OutputSignal::GPIO as OutputSignalType) });
|
.modify(|_, w| unsafe { w.out_sel().bits(OutputSignal::GPIO as OutputSignalType) });
|
||||||
|
|
||||||
@ -597,47 +562,25 @@ where
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_floating_input(self) -> GpioPin<Input<Floating>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
pub fn into_floating_input(self) -> GpioPin<Input<Floating>, GPIONUM> {
|
||||||
self.init_input(false, false);
|
self.init_input(false, false);
|
||||||
GpioPin {
|
GpioPin { _mode: PhantomData }
|
||||||
_mode: PhantomData,
|
|
||||||
_pintype: PhantomData,
|
|
||||||
_reg_access: PhantomData,
|
|
||||||
_ira: PhantomData,
|
|
||||||
_signals: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_pull_up_input(self) -> GpioPin<Input<PullUp>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
pub fn into_pull_up_input(self) -> GpioPin<Input<PullUp>, GPIONUM> {
|
||||||
self.init_input(false, true);
|
self.init_input(false, true);
|
||||||
GpioPin {
|
GpioPin { _mode: PhantomData }
|
||||||
_mode: PhantomData,
|
|
||||||
_pintype: PhantomData,
|
|
||||||
_reg_access: PhantomData,
|
|
||||||
_ira: PhantomData,
|
|
||||||
_signals: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_pull_down_input(self) -> GpioPin<Input<PullDown>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
pub fn into_pull_down_input(self) -> GpioPin<Input<PullDown>, GPIONUM> {
|
||||||
self.init_input(true, false);
|
self.init_input(true, false);
|
||||||
GpioPin {
|
GpioPin { _mode: PhantomData }
|
||||||
_mode: PhantomData,
|
|
||||||
_pintype: PhantomData,
|
|
||||||
_reg_access: PhantomData,
|
|
||||||
_ira: PhantomData,
|
|
||||||
_signals: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> InputPin
|
impl<MODE, const GPIONUM: u8> InputPin for GpioPin<MODE, GPIONUM>
|
||||||
for GpioPin<MODE, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
PINTYPE: PinType,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn set_to_input(&mut self) -> &mut Self {
|
fn set_to_input(&mut self) -> &mut Self {
|
||||||
self.init_input(false, false);
|
self.init_input(false, false);
|
||||||
@ -652,7 +595,7 @@ where
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
fn is_input_high(&self) -> bool {
|
fn is_input_high(&self) -> bool {
|
||||||
RA::read_input() & (1 << (GPIONUM % 32)) != 0
|
<Self as GpioProperties>::Bank::read_input() & (1 << (GPIONUM % 32)) != 0
|
||||||
}
|
}
|
||||||
fn connect_input_to_peripheral_with_options(
|
fn connect_input_to_peripheral_with_options(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -664,7 +607,10 @@ where
|
|||||||
GPIO_FUNCTION
|
GPIO_FUNCTION
|
||||||
} else {
|
} else {
|
||||||
let mut res = GPIO_FUNCTION;
|
let mut res = GPIO_FUNCTION;
|
||||||
for (i, input_signal) in SIG::input_signals().iter().enumerate() {
|
for (i, input_signal) in <Self as GpioProperties>::Signals::input_signals()
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
if let Some(input_signal) = input_signal {
|
if let Some(input_signal) = input_signal {
|
||||||
if *input_signal == signal {
|
if *input_signal == signal {
|
||||||
res = match i {
|
res = match i {
|
||||||
@ -707,13 +653,9 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> Pin
|
impl<MODE, const GPIONUM: u8> Pin for GpioPin<MODE, GPIONUM>
|
||||||
for GpioPin<MODE, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
PINTYPE: PinType,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn number(&self) -> u8 {
|
fn number(&self) -> u8 {
|
||||||
GPIONUM
|
GPIONUM
|
||||||
@ -773,23 +715,31 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clear_interrupt(&mut self) {
|
fn clear_interrupt(&mut self) {
|
||||||
RA::write_interrupt_status_clear(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_interrupt_status_clear(1 << (GPIONUM % 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_pcore_interrupt_set(&self) -> bool {
|
fn is_pcore_interrupt_set(&self) -> bool {
|
||||||
(IRA::pro_cpu_interrupt_status_read() & (1 << (GPIONUM % 32))) != 0
|
(<Self as GpioProperties>::InterruptStatus::pro_cpu_interrupt_status_read()
|
||||||
|
& (1 << (GPIONUM % 32)))
|
||||||
|
!= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_pcore_non_maskable_interrupt_set(&self) -> bool {
|
fn is_pcore_non_maskable_interrupt_set(&self) -> bool {
|
||||||
(IRA::pro_cpu_nmi_status_read() & (1 << (GPIONUM % 32))) != 0
|
(<Self as GpioProperties>::InterruptStatus::pro_cpu_nmi_status_read()
|
||||||
|
& (1 << (GPIONUM % 32)))
|
||||||
|
!= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_acore_interrupt_set(&self) -> bool {
|
fn is_acore_interrupt_set(&self) -> bool {
|
||||||
(IRA::app_cpu_interrupt_status_read() & (1 << (GPIONUM % 32))) != 0
|
(<Self as GpioProperties>::InterruptStatus::app_cpu_interrupt_status_read()
|
||||||
|
& (1 << (GPIONUM % 32)))
|
||||||
|
!= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_acore_non_maskable_interrupt_set(&self) -> bool {
|
fn is_acore_non_maskable_interrupt_set(&self) -> bool {
|
||||||
(IRA::app_cpu_nmi_status_read() & (1 << (GPIONUM % 32))) != 0
|
(<Self as GpioProperties>::InterruptStatus::app_cpu_nmi_status_read()
|
||||||
|
& (1 << (GPIONUM % 32)))
|
||||||
|
!= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable_hold(&mut self, _on: bool) {
|
fn enable_hold(&mut self, _on: bool) {
|
||||||
@ -797,48 +747,42 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal::digital::v2::OutputPin
|
impl<MODE, const GPIONUM: u8> embedded_hal::digital::v2::OutputPin
|
||||||
for GpioPin<Output<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
for GpioPin<Output<MODE>, GPIONUM>
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
type Error = Infallible;
|
type Error = Infallible;
|
||||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||||
RA::write_output_set(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_output_set(1 << (GPIONUM % 32));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||||
RA::write_output_clear(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_output_clear(1 << (GPIONUM % 32));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal::digital::v2::StatefulOutputPin
|
impl<MODE, const GPIONUM: u8> embedded_hal::digital::v2::StatefulOutputPin
|
||||||
for GpioPin<Output<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
for GpioPin<Output<MODE>, GPIONUM>
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
||||||
Ok(RA::read_output() & (1 << (GPIONUM % 32)) != 0)
|
Ok(<Self as GpioProperties>::Bank::read_output() & (1 << (GPIONUM % 32)) != 0)
|
||||||
}
|
}
|
||||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
||||||
Ok(!self.is_set_high()?)
|
Ok(!self.is_set_high()?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal::digital::v2::ToggleableOutputPin
|
impl<MODE, const GPIONUM: u8> embedded_hal::digital::v2::ToggleableOutputPin
|
||||||
for GpioPin<Output<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
for GpioPin<Output<MODE>, GPIONUM>
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
type Error = Infallible;
|
type Error = Infallible;
|
||||||
fn toggle(&mut self) -> Result<(), Self::Error> {
|
fn toggle(&mut self) -> Result<(), Self::Error> {
|
||||||
@ -852,47 +796,39 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "eh1")]
|
#[cfg(feature = "eh1")]
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal_1::digital::ErrorType
|
impl<MODE, const GPIONUM: u8> embedded_hal_1::digital::ErrorType for GpioPin<Output<MODE>, GPIONUM>
|
||||||
for GpioPin<Output<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
type Error = Infallible;
|
type Error = Infallible;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "eh1")]
|
#[cfg(feature = "eh1")]
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal_1::digital::OutputPin
|
impl<MODE, const GPIONUM: u8> embedded_hal_1::digital::OutputPin for GpioPin<Output<MODE>, GPIONUM>
|
||||||
for GpioPin<Output<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||||
RA::write_output_clear(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_output_clear(1 << (GPIONUM % 32));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||||
RA::write_output_set(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_output_set(1 << (GPIONUM % 32));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "eh1")]
|
#[cfg(feature = "eh1")]
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal_1::digital::StatefulOutputPin
|
impl<MODE, const GPIONUM: u8> embedded_hal_1::digital::StatefulOutputPin
|
||||||
for GpioPin<Output<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
for GpioPin<Output<MODE>, GPIONUM>
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
||||||
Ok(RA::read_output() & (1 << (GPIONUM % 32)) != 0)
|
Ok(<Self as GpioProperties>::Bank::read_output() & (1 << (GPIONUM % 32)) != 0)
|
||||||
}
|
}
|
||||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
||||||
Ok(!self.is_set_high()?)
|
Ok(!self.is_set_high()?)
|
||||||
@ -900,13 +836,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "eh1")]
|
#[cfg(feature = "eh1")]
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> embedded_hal_1::digital::ToggleableOutputPin
|
impl<MODE, const GPIONUM: u8> embedded_hal_1::digital::ToggleableOutputPin
|
||||||
for GpioPin<Output<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
for GpioPin<Output<MODE>, GPIONUM>
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn toggle(&mut self) -> Result<(), Self::Error> {
|
fn toggle(&mut self) -> Result<(), Self::Error> {
|
||||||
use embedded_hal_1::digital::{OutputPin as _, StatefulOutputPin as _};
|
use embedded_hal_1::digital::{OutputPin as _, StatefulOutputPin as _};
|
||||||
@ -918,154 +852,112 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> crate::peripheral::Peripheral
|
impl<MODE, const GPIONUM: u8> crate::peripheral::Peripheral for GpioPin<MODE, GPIONUM>
|
||||||
for GpioPin<MODE, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
PINTYPE: PinType,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
type P = GpioPin<MODE, RA, IRA, PINTYPE, SIG, GPIONUM>;
|
type P = GpioPin<MODE, GPIONUM>;
|
||||||
|
|
||||||
unsafe fn clone_unchecked(&mut self) -> Self::P {
|
unsafe fn clone_unchecked(&mut self) -> Self::P {
|
||||||
core::ptr::read(self as *const _)
|
core::ptr::read(self as *const _)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> crate::peripheral::sealed::Sealed
|
impl<MODE, const GPIONUM: u8> crate::peripheral::sealed::Sealed for GpioPin<MODE, GPIONUM> where
|
||||||
for GpioPin<MODE, RA, IRA, PINTYPE, SIG, GPIONUM>
|
Self: GpioProperties
|
||||||
where
|
|
||||||
RA: BankGpioRegisterAccess,
|
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
PINTYPE: PinType,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<RA, IRA, PINTYPE, SIG, const GPIONUM: u8>
|
impl<const GPIONUM: u8> From<GpioPin<Unknown, GPIONUM>> for GpioPin<Input<Floating>, GPIONUM>
|
||||||
From<GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>>
|
|
||||||
for GpioPin<Input<Floating>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
GpioPin<Unknown, GPIONUM>: GpioProperties,
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn from(
|
fn from(pin: GpioPin<Unknown, GPIONUM>) -> GpioPin<Input<Floating>, GPIONUM> {
|
||||||
pin: GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>,
|
|
||||||
) -> GpioPin<Input<Floating>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
|
||||||
pin.into_floating_input()
|
pin.into_floating_input()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<RA, IRA, PINTYPE, SIG, const GPIONUM: u8>
|
impl<const GPIONUM: u8> From<GpioPin<Unknown, GPIONUM>> for GpioPin<Input<PullUp>, GPIONUM>
|
||||||
From<GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>>
|
|
||||||
for GpioPin<Input<PullUp>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
GpioPin<Unknown, GPIONUM>: GpioProperties,
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn from(
|
fn from(pin: GpioPin<Unknown, GPIONUM>) -> GpioPin<Input<PullUp>, GPIONUM> {
|
||||||
pin: GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>,
|
|
||||||
) -> GpioPin<Input<PullUp>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
|
||||||
pin.into_pull_up_input()
|
pin.into_pull_up_input()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<RA, IRA, PINTYPE, SIG, const GPIONUM: u8>
|
impl<const GPIONUM: u8> From<GpioPin<Unknown, GPIONUM>> for GpioPin<Input<PullDown>, GPIONUM>
|
||||||
From<GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>>
|
|
||||||
for GpioPin<Input<PullDown>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsInputPin,
|
||||||
PINTYPE: IsInputPin,
|
GpioPin<Unknown, GPIONUM>: GpioProperties,
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn from(
|
fn from(pin: GpioPin<Unknown, GPIONUM>) -> GpioPin<Input<PullDown>, GPIONUM> {
|
||||||
pin: GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>,
|
|
||||||
) -> GpioPin<Input<PullDown>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
|
||||||
pin.into_pull_down_input()
|
pin.into_pull_down_input()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<RA, IRA, PINTYPE, SIG, const GPIONUM: u8>
|
impl<const GPIONUM: u8> From<GpioPin<Unknown, GPIONUM>> for GpioPin<Output<PushPull>, GPIONUM>
|
||||||
From<GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>>
|
|
||||||
for GpioPin<Output<PushPull>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
GpioPin<Unknown, GPIONUM>: GpioProperties,
|
||||||
SIG: GpioSignal,
|
<GpioPin<Unknown, GPIONUM> as GpioProperties>::PinType: IsOutputPin,
|
||||||
{
|
{
|
||||||
fn from(
|
fn from(pin: GpioPin<Unknown, GPIONUM>) -> GpioPin<Output<PushPull>, GPIONUM> {
|
||||||
pin: GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>,
|
|
||||||
) -> GpioPin<Output<PushPull>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
|
||||||
pin.into_push_pull_output()
|
pin.into_push_pull_output()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<RA, IRA, PINTYPE, SIG, const GPIONUM: u8>
|
impl<const GPIONUM: u8> From<GpioPin<Unknown, GPIONUM>> for GpioPin<Output<OpenDrain>, GPIONUM>
|
||||||
From<GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>>
|
|
||||||
for GpioPin<Output<OpenDrain>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
GpioPin<Unknown, GPIONUM>: GpioProperties,
|
||||||
SIG: GpioSignal,
|
<GpioPin<Unknown, GPIONUM> as GpioProperties>::PinType: IsOutputPin,
|
||||||
{
|
{
|
||||||
fn from(
|
fn from(pin: GpioPin<Unknown, GPIONUM>) -> GpioPin<Output<OpenDrain>, GPIONUM> {
|
||||||
pin: GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>,
|
|
||||||
) -> GpioPin<Output<OpenDrain>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
|
||||||
pin.into_open_drain_output()
|
pin.into_open_drain_output()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<RA, IRA, PINTYPE, SIG, const GPIONUM: u8>
|
impl<const GPIONUM: u8> From<GpioPin<Unknown, GPIONUM>> for GpioPin<Alternate<AF1>, GPIONUM>
|
||||||
From<GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>>
|
|
||||||
for GpioPin<Alternate<AF1>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
GpioPin<Unknown, GPIONUM>: GpioProperties,
|
||||||
SIG: GpioSignal,
|
<GpioPin<Unknown, GPIONUM> as GpioProperties>::PinType: IsOutputPin,
|
||||||
{
|
{
|
||||||
fn from(
|
fn from(pin: GpioPin<Unknown, GPIONUM>) -> GpioPin<Alternate<AF1>, GPIONUM> {
|
||||||
pin: GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>,
|
|
||||||
) -> GpioPin<Alternate<AF1>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
|
||||||
pin.into_alternate_1()
|
pin.into_alternate_1()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<RA, IRA, PINTYPE, SIG, const GPIONUM: u8>
|
impl<const GPIONUM: u8> From<GpioPin<Unknown, GPIONUM>> for GpioPin<Alternate<AF2>, GPIONUM>
|
||||||
From<GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>>
|
|
||||||
for GpioPin<Alternate<AF2>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
GpioPin<Unknown, GPIONUM>: GpioProperties,
|
||||||
SIG: GpioSignal,
|
<GpioPin<Unknown, GPIONUM> as GpioProperties>::PinType: IsOutputPin,
|
||||||
{
|
{
|
||||||
fn from(
|
fn from(pin: GpioPin<Unknown, GPIONUM>) -> GpioPin<Alternate<AF2>, GPIONUM> {
|
||||||
pin: GpioPin<Unknown, RA, IRA, PINTYPE, SIG, GPIONUM>,
|
|
||||||
) -> GpioPin<Alternate<AF2>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
|
||||||
pin.into_alternate_2()
|
pin.into_alternate_2()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> GpioPin<MODE, RA, IRA, PINTYPE, SIG, GPIONUM>
|
impl<MODE, const GPIONUM: u8> GpioPin<MODE, GPIONUM>
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn init_output(&self, alternate: AlternateFunction, open_drain: bool) {
|
fn init_output(&self, alternate: AlternateFunction, open_drain: bool) {
|
||||||
let gpio = unsafe { &*GPIO::PTR };
|
let gpio = unsafe { &*GPIO::PTR };
|
||||||
|
|
||||||
RA::write_out_en_set(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_out_en_set(1 << (GPIONUM % 32));
|
||||||
gpio.pin[GPIONUM as usize].modify(|_, w| w.pad_driver().bit(open_drain));
|
gpio.pin[GPIONUM as usize].modify(|_, w| w.pad_driver().bit(open_drain));
|
||||||
|
|
||||||
gpio.func_out_sel_cfg[GPIONUM as usize]
|
gpio.func_out_sel_cfg[GPIONUM as usize]
|
||||||
@ -1096,62 +988,31 @@ where
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_push_pull_output(
|
pub fn into_push_pull_output(self) -> GpioPin<Output<PushPull>, GPIONUM> {
|
||||||
self,
|
|
||||||
) -> GpioPin<Output<PushPull>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
|
||||||
self.init_output(GPIO_FUNCTION, false);
|
self.init_output(GPIO_FUNCTION, false);
|
||||||
GpioPin {
|
GpioPin { _mode: PhantomData }
|
||||||
_mode: PhantomData,
|
|
||||||
_pintype: PhantomData,
|
|
||||||
_reg_access: PhantomData,
|
|
||||||
_ira: PhantomData,
|
|
||||||
_signals: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_open_drain_output(
|
pub fn into_open_drain_output(self) -> GpioPin<Output<OpenDrain>, GPIONUM> {
|
||||||
self,
|
|
||||||
) -> GpioPin<Output<OpenDrain>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
|
||||||
self.init_output(GPIO_FUNCTION, true);
|
self.init_output(GPIO_FUNCTION, true);
|
||||||
GpioPin {
|
GpioPin { _mode: PhantomData }
|
||||||
_mode: PhantomData,
|
|
||||||
_pintype: PhantomData,
|
|
||||||
_reg_access: PhantomData,
|
|
||||||
_ira: PhantomData,
|
|
||||||
_signals: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_alternate_1(self) -> GpioPin<Alternate<AF1>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
pub fn into_alternate_1(self) -> GpioPin<Alternate<AF1>, GPIONUM> {
|
||||||
self.init_output(AlternateFunction::Function1, false);
|
self.init_output(AlternateFunction::Function1, false);
|
||||||
GpioPin {
|
GpioPin { _mode: PhantomData }
|
||||||
_mode: PhantomData,
|
|
||||||
_pintype: PhantomData,
|
|
||||||
_reg_access: PhantomData,
|
|
||||||
_ira: PhantomData,
|
|
||||||
_signals: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_alternate_2(self) -> GpioPin<Alternate<AF2>, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
pub fn into_alternate_2(self) -> GpioPin<Alternate<AF2>, GPIONUM> {
|
||||||
self.init_output(AlternateFunction::Function2, false);
|
self.init_output(AlternateFunction::Function2, false);
|
||||||
GpioPin {
|
GpioPin { _mode: PhantomData }
|
||||||
_mode: PhantomData,
|
|
||||||
_pintype: PhantomData,
|
|
||||||
_reg_access: PhantomData,
|
|
||||||
_ira: PhantomData,
|
|
||||||
_signals: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> OutputPin
|
impl<MODE, const GPIONUM: u8> OutputPin for GpioPin<MODE, GPIONUM>
|
||||||
for GpioPin<MODE, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsOutputPin,
|
||||||
PINTYPE: IsOutputPin,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
fn set_to_open_drain_output(&mut self) -> &mut Self {
|
fn set_to_open_drain_output(&mut self) -> &mut Self {
|
||||||
self.init_output(GPIO_FUNCTION, true);
|
self.init_output(GPIO_FUNCTION, true);
|
||||||
@ -1165,18 +1026,18 @@ where
|
|||||||
|
|
||||||
fn enable_output(&mut self, on: bool) -> &mut Self {
|
fn enable_output(&mut self, on: bool) -> &mut Self {
|
||||||
if on {
|
if on {
|
||||||
RA::write_out_en_set(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_out_en_set(1 << (GPIONUM % 32));
|
||||||
} else {
|
} else {
|
||||||
RA::write_out_en_clear(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_out_en_clear(1 << (GPIONUM % 32));
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_output_high(&mut self, high: bool) -> &mut Self {
|
fn set_output_high(&mut self, high: bool) -> &mut Self {
|
||||||
if high {
|
if high {
|
||||||
RA::write_output_set(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_output_set(1 << (GPIONUM % 32));
|
||||||
} else {
|
} else {
|
||||||
RA::write_output_clear(1 << (GPIONUM % 32));
|
<Self as GpioProperties>::Bank::write_output_clear(1 << (GPIONUM % 32));
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -1217,7 +1078,10 @@ where
|
|||||||
GPIO_FUNCTION
|
GPIO_FUNCTION
|
||||||
} else {
|
} else {
|
||||||
let mut res = GPIO_FUNCTION;
|
let mut res = GPIO_FUNCTION;
|
||||||
for (i, output_signal) in SIG::output_signals().iter().enumerate() {
|
for (i, output_signal) in <Self as GpioProperties>::Signals::output_signals()
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
if let Some(output_signal) = output_signal {
|
if let Some(output_signal) = output_signal {
|
||||||
if *output_signal == signal {
|
if *output_signal == signal {
|
||||||
res = match i {
|
res = match i {
|
||||||
@ -1274,23 +1138,15 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> GpioPin<MODE, RA, IRA, PINTYPE, SIG, GPIONUM>
|
impl<MODE, const GPIONUM: u8> GpioPin<MODE, GPIONUM>
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
<Self as GpioProperties>::PinType: IsAnalogPin,
|
||||||
PINTYPE: IsAnalogPin,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
pub fn into_analog(self) -> GpioPin<Analog, RA, IRA, PINTYPE, SIG, GPIONUM> {
|
pub fn into_analog(self) -> GpioPin<Analog, GPIONUM> {
|
||||||
crate::soc::gpio::internal_into_analog(GPIONUM);
|
crate::soc::gpio::internal_into_analog(GPIONUM);
|
||||||
|
|
||||||
GpioPin {
|
GpioPin { _mode: PhantomData }
|
||||||
_mode: PhantomData,
|
|
||||||
_pintype: PhantomData,
|
|
||||||
_reg_access: PhantomData,
|
|
||||||
_ira: PhantomData,
|
|
||||||
_signals: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1444,6 +1300,13 @@ impl IO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait GpioProperties {
|
||||||
|
type Bank: BankGpioRegisterAccess;
|
||||||
|
type InterruptStatus: InterruptStatusRegisterAccess;
|
||||||
|
type Signals: GpioSignal;
|
||||||
|
type PinType: PinType;
|
||||||
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! gpio {
|
macro_rules! gpio {
|
||||||
@ -1478,6 +1341,13 @@ macro_rules! gpio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(
|
$(
|
||||||
|
impl<MODE> crate::gpio::GpioProperties for GpioPin<MODE, $gpionum> {
|
||||||
|
type Bank = crate::gpio::[< Bank $bank GpioRegisterAccess >];
|
||||||
|
type InterruptStatus = crate::gpio::[< InterruptStatusRegisterAccessBank $bank >];
|
||||||
|
type Signals = [< Gpio $gpionum Signals >];
|
||||||
|
type PinType = crate::gpio::[<$type PinType>];
|
||||||
|
}
|
||||||
|
|
||||||
pub struct [<Gpio $gpionum Signals>] {}
|
pub struct [<Gpio $gpionum Signals>] {}
|
||||||
|
|
||||||
impl crate::gpio::GpioSignal for [<Gpio $gpionum Signals>] {
|
impl crate::gpio::GpioSignal for [<Gpio $gpionum Signals>] {
|
||||||
@ -1510,12 +1380,12 @@ macro_rules! gpio {
|
|||||||
|
|
||||||
pub struct Pins {
|
pub struct Pins {
|
||||||
$(
|
$(
|
||||||
pub [< gpio $gpionum >] : GpioPin<Unknown, [< Bank $bank GpioRegisterAccess >], $crate::gpio::[< InteruptStatusRegisterAccessBank $bank >], [< $type PinType >], [<Gpio $gpionum Signals>], $gpionum>,
|
pub [< gpio $gpionum >] : GpioPin<Unknown, $gpionum>,
|
||||||
)+
|
)+
|
||||||
}
|
}
|
||||||
|
|
||||||
$(
|
$(
|
||||||
pub type [<Gpio $gpionum >]<MODE> = GpioPin<MODE, [< Bank $bank GpioRegisterAccess >], $crate::gpio::[< InteruptStatusRegisterAccessBank $bank >], [< $type PinType >], [<Gpio $gpionum Signals>], $gpionum>;
|
pub type [<Gpio $gpionum >]<MODE> = GpioPin<MODE, $gpionum>;
|
||||||
)+
|
)+
|
||||||
|
|
||||||
pub(crate) enum ErasedPin<MODE> {
|
pub(crate) enum ErasedPin<MODE> {
|
||||||
@ -1760,13 +1630,10 @@ mod asynch {
|
|||||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||||
static PIN_WAKERS: [AtomicWaker; NUM_PINS] = [NEW_AW; NUM_PINS];
|
static PIN_WAKERS: [AtomicWaker; NUM_PINS] = [NEW_AW; NUM_PINS];
|
||||||
|
|
||||||
impl<MODE, RA, IRA, PINTYPE, SIG, const GPIONUM: u8> Wait
|
impl<MODE, const GPIONUM: u8> Wait for GpioPin<Input<MODE>, GPIONUM>
|
||||||
for GpioPin<Input<MODE>, RA, IRA, PINTYPE, SIG, GPIONUM>
|
|
||||||
where
|
where
|
||||||
RA: BankGpioRegisterAccess,
|
Self: GpioProperties,
|
||||||
PINTYPE: IsInputPin,
|
<Self as GpioProperties>::PinType: IsInputPin,
|
||||||
IRA: InteruptStatusRegisterAccess,
|
|
||||||
SIG: GpioSignal,
|
|
||||||
{
|
{
|
||||||
async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
|
async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
|
||||||
PinFuture::new(self, Event::HighLevel).await
|
PinFuture::new(self, Event::HighLevel).await
|
||||||
@ -1828,23 +1695,25 @@ mod asynch {
|
|||||||
unsafe fn GPIO() {
|
unsafe fn GPIO() {
|
||||||
let mut intrs = match crate::get_core() {
|
let mut intrs = match crate::get_core() {
|
||||||
crate::Cpu::ProCpu => {
|
crate::Cpu::ProCpu => {
|
||||||
InteruptStatusRegisterAccessBank0::pro_cpu_interrupt_status_read() as u64
|
InterruptStatusRegisterAccessBank0::pro_cpu_interrupt_status_read() as u64
|
||||||
}
|
}
|
||||||
#[cfg(multi_core)]
|
#[cfg(multi_core)]
|
||||||
crate::Cpu::AppCpu => {
|
crate::Cpu::AppCpu => {
|
||||||
InteruptStatusRegisterAccessBank0::app_cpu_interrupt_status_read() as u64
|
InterruptStatusRegisterAccessBank0::app_cpu_interrupt_status_read() as u64
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(esp32, esp32s2, esp32s3))]
|
#[cfg(any(esp32, esp32s2, esp32s3))]
|
||||||
match crate::get_core() {
|
match crate::get_core() {
|
||||||
crate::Cpu::ProCpu => {
|
crate::Cpu::ProCpu => {
|
||||||
intrs |= (InteruptStatusRegisterAccessBank1::pro_cpu_interrupt_status_read() as u64)
|
intrs |= (InterruptStatusRegisterAccessBank1::pro_cpu_interrupt_status_read()
|
||||||
|
as u64)
|
||||||
<< 32
|
<< 32
|
||||||
}
|
}
|
||||||
#[cfg(multi_core)]
|
#[cfg(multi_core)]
|
||||||
crate::Cpu::AppCpu => {
|
crate::Cpu::AppCpu => {
|
||||||
intrs |= (InteruptStatusRegisterAccessBank1::app_cpu_interrupt_status_read() as u64)
|
intrs |= (InterruptStatusRegisterAccessBank1::app_cpu_interrupt_status_read()
|
||||||
|
as u64)
|
||||||
<< 32
|
<< 32
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,15 +3,10 @@ use paste::paste;
|
|||||||
use crate::{
|
use crate::{
|
||||||
gpio::{
|
gpio::{
|
||||||
AlternateFunction,
|
AlternateFunction,
|
||||||
Bank0GpioRegisterAccess,
|
|
||||||
Bank1GpioRegisterAccess,
|
|
||||||
GpioPin,
|
GpioPin,
|
||||||
InputOnlyAnalogPinType,
|
InterruptStatusRegisterAccess,
|
||||||
InputOutputAnalogPinType,
|
InterruptStatusRegisterAccessBank0,
|
||||||
InputOutputPinType,
|
InterruptStatusRegisterAccessBank1,
|
||||||
InteruptStatusRegisterAccess,
|
|
||||||
InteruptStatusRegisterAccessBank0,
|
|
||||||
InteruptStatusRegisterAccessBank1,
|
|
||||||
Unknown,
|
Unknown,
|
||||||
},
|
},
|
||||||
peripherals::GPIO,
|
peripherals::GPIO,
|
||||||
@ -722,7 +717,7 @@ crate::gpio::analog! {
|
|||||||
(27, 17, touch_pad7, mux_sel, fun_sel, fun_ie, rue, rde )
|
(27, 17, touch_pad7, mux_sel, fun_sel, fun_ie, rue, rde )
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank0 {
|
impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank0 {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
||||||
}
|
}
|
||||||
@ -740,7 +735,7 @@ impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank0 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank1 {
|
impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank1 {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
unsafe { &*GPIO::PTR }.pcpu_int1.read().bits()
|
unsafe { &*GPIO::PTR }.pcpu_int1.read().bits()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,12 +3,9 @@ use paste::paste;
|
|||||||
use crate::{
|
use crate::{
|
||||||
gpio::{
|
gpio::{
|
||||||
AlternateFunction,
|
AlternateFunction,
|
||||||
Bank0GpioRegisterAccess,
|
|
||||||
GpioPin,
|
GpioPin,
|
||||||
InputOutputAnalogPinType,
|
InterruptStatusRegisterAccess,
|
||||||
InputOutputPinType,
|
InterruptStatusRegisterAccessBank0,
|
||||||
InteruptStatusRegisterAccess,
|
|
||||||
InteruptStatusRegisterAccessBank0,
|
|
||||||
Unknown,
|
Unknown,
|
||||||
},
|
},
|
||||||
peripherals::GPIO,
|
peripherals::GPIO,
|
||||||
@ -165,7 +162,7 @@ crate::gpio::analog! {
|
|||||||
4
|
4
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank0 {
|
impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank0 {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,12 +3,9 @@ use paste::paste;
|
|||||||
use crate::{
|
use crate::{
|
||||||
gpio::{
|
gpio::{
|
||||||
AlternateFunction,
|
AlternateFunction,
|
||||||
Bank0GpioRegisterAccess,
|
|
||||||
GpioPin,
|
GpioPin,
|
||||||
InputOutputAnalogPinType,
|
InterruptStatusRegisterAccess,
|
||||||
InputOutputPinType,
|
InterruptStatusRegisterAccessBank0,
|
||||||
InteruptStatusRegisterAccess,
|
|
||||||
InteruptStatusRegisterAccessBank0,
|
|
||||||
Unknown,
|
Unknown,
|
||||||
},
|
},
|
||||||
peripherals::GPIO,
|
peripherals::GPIO,
|
||||||
@ -200,7 +197,7 @@ crate::gpio::analog! {
|
|||||||
5
|
5
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank0 {
|
impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank0 {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,12 +3,9 @@ use paste::paste;
|
|||||||
use crate::{
|
use crate::{
|
||||||
gpio::{
|
gpio::{
|
||||||
AlternateFunction,
|
AlternateFunction,
|
||||||
Bank0GpioRegisterAccess,
|
|
||||||
GpioPin,
|
GpioPin,
|
||||||
InputOutputAnalogPinType,
|
InterruptStatusRegisterAccess,
|
||||||
InputOutputPinType,
|
InterruptStatusRegisterAccessBank0,
|
||||||
InteruptStatusRegisterAccess,
|
|
||||||
InteruptStatusRegisterAccessBank0,
|
|
||||||
Unknown,
|
Unknown,
|
||||||
},
|
},
|
||||||
peripherals::GPIO,
|
peripherals::GPIO,
|
||||||
@ -282,7 +279,7 @@ crate::gpio::analog! {
|
|||||||
7
|
7
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank0 {
|
impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank0 {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,12 +3,9 @@ use paste::paste;
|
|||||||
use crate::{
|
use crate::{
|
||||||
gpio::{
|
gpio::{
|
||||||
AlternateFunction,
|
AlternateFunction,
|
||||||
Bank0GpioRegisterAccess,
|
|
||||||
GpioPin,
|
GpioPin,
|
||||||
InputOutputAnalogPinType,
|
InterruptStatusRegisterAccess,
|
||||||
InputOutputPinType,
|
InterruptStatusRegisterAccessBank0,
|
||||||
InteruptStatusRegisterAccess,
|
|
||||||
InteruptStatusRegisterAccessBank0,
|
|
||||||
Unknown,
|
Unknown,
|
||||||
},
|
},
|
||||||
peripherals::GPIO,
|
peripherals::GPIO,
|
||||||
@ -257,7 +254,7 @@ crate::gpio::analog! {
|
|||||||
5
|
5
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank0 {
|
impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank0 {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,14 +3,10 @@ use paste::paste;
|
|||||||
use crate::{
|
use crate::{
|
||||||
gpio::{
|
gpio::{
|
||||||
AlternateFunction,
|
AlternateFunction,
|
||||||
Bank0GpioRegisterAccess,
|
|
||||||
Bank1GpioRegisterAccess,
|
|
||||||
GpioPin,
|
GpioPin,
|
||||||
InputOutputAnalogPinType,
|
InterruptStatusRegisterAccess,
|
||||||
InputOutputPinType,
|
InterruptStatusRegisterAccessBank0,
|
||||||
InteruptStatusRegisterAccess,
|
InterruptStatusRegisterAccessBank1,
|
||||||
InteruptStatusRegisterAccessBank0,
|
|
||||||
InteruptStatusRegisterAccessBank1,
|
|
||||||
Unknown,
|
Unknown,
|
||||||
},
|
},
|
||||||
peripherals::GPIO,
|
peripherals::GPIO,
|
||||||
@ -384,7 +380,7 @@ crate::gpio::analog! {
|
|||||||
(21, 21, rtc_pad21, mux_sel, fun_sel, fun_ie, rue, rde)
|
(21, 21, rtc_pad21, mux_sel, fun_sel, fun_ie, rue, rde)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank0 {
|
impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank0 {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
||||||
}
|
}
|
||||||
@ -394,7 +390,7 @@ impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank0 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank1 {
|
impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank1 {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
unsafe { &*GPIO::PTR }.pcpu_int1.read().bits()
|
unsafe { &*GPIO::PTR }.pcpu_int1.read().bits()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,14 +3,10 @@ use paste::paste;
|
|||||||
use crate::{
|
use crate::{
|
||||||
gpio::{
|
gpio::{
|
||||||
AlternateFunction,
|
AlternateFunction,
|
||||||
Bank0GpioRegisterAccess,
|
|
||||||
Bank1GpioRegisterAccess,
|
|
||||||
GpioPin,
|
GpioPin,
|
||||||
InputOutputAnalogPinType,
|
InterruptStatusRegisterAccess,
|
||||||
InputOutputPinType,
|
InterruptStatusRegisterAccessBank0,
|
||||||
InteruptStatusRegisterAccess,
|
InterruptStatusRegisterAccessBank1,
|
||||||
InteruptStatusRegisterAccessBank0,
|
|
||||||
InteruptStatusRegisterAccessBank1,
|
|
||||||
Unknown,
|
Unknown,
|
||||||
},
|
},
|
||||||
peripherals::GPIO,
|
peripherals::GPIO,
|
||||||
@ -341,7 +337,7 @@ crate::gpio::analog! {
|
|||||||
|
|
||||||
// Whilst the S3 is a dual core chip, it shares the enable registers between
|
// Whilst the S3 is a dual core chip, it shares the enable registers between
|
||||||
// cores so treat it as a single core device
|
// cores so treat it as a single core device
|
||||||
impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank0 {
|
impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank0 {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
unsafe { &*GPIO::PTR }.pcpu_int.read().bits()
|
||||||
}
|
}
|
||||||
@ -351,7 +347,7 @@ impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank0 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InteruptStatusRegisterAccess for InteruptStatusRegisterAccessBank1 {
|
impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank1 {
|
||||||
fn pro_cpu_interrupt_status_read() -> u32 {
|
fn pro_cpu_interrupt_status_read() -> u32 {
|
||||||
unsafe { &*GPIO::PTR }.pcpu_int1.read().bits()
|
unsafe { &*GPIO::PTR }.pcpu_int1.read().bits()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user