ULP compatibility for degrading and StatefulPin

This commit is contained in:
ivmarkov 2021-12-06 10:59:55 +02:00
parent 6ecb5fe04d
commit 241e97a6fa
4 changed files with 33 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "esp-idf-hal"
version = "0.29.0"
version = "0.29.1"
authors = ["sapir <yasapir@gmail.com>", "Ivan Markov <ivan.markov@gmail.com>"]
edition = "2018"
resolver = "2"

View File

@ -237,6 +237,7 @@ macro_rules! impl_hal_output_pin {
}
impl embedded_hal::digital::v2::StatefulOutputPin for $pxi<$mode> {
#[cfg(not(feature = "ulp"))]
fn is_set_high(&self) -> Result<bool, Self::Error> {
let pin = $pxi::<$mode>::runtime_pin() as u32;
@ -254,6 +255,11 @@ macro_rules! impl_hal_output_pin {
Ok(is_set_high)
}
#[cfg(feature = "ulp")]
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(unsafe { gpio_get_output_level($pxi::<$mode>::runtime_pin()) } != 0)
}
fn is_set_low(&self) -> Result<bool, Self::Error> {
Ok(!self.is_set_high()?)
}
@ -524,6 +530,16 @@ macro_rules! impl_rtc {
fn runtime_pin() -> i32 {
$rtc
}
/// Degrades a concrete pin (e.g. [`Gpio1`]) to a generic pin
/// struct that can also be used with periphals.
pub fn degrade(self) -> GpioPin<MODE> {
GpioPin::new($pin)
}
pub fn into_unknown(self) -> $pxi<Unknown> {
$pxi { _mode: PhantomData }
}
}
impl<MODE> RTCPin for $pxi<MODE>

View File

@ -17,6 +17,7 @@ pub fn get_ccount() -> u32 {
#[allow(unused_assignments)]
let mut ccount = 0;
#[allow(deprecated)]
unsafe {
llvm_asm!("rdcycle $0" : "=r"(ccount) : : : "volatile");
}

View File

@ -172,3 +172,18 @@ pub unsafe fn gpio_set_level(gpio_num: i32, level: u8) {
);
}
}
#[inline(always)]
pub unsafe fn gpio_get_output_level(gpio_num: i32) -> u8 {
if (reg_get_field(
RTC_GPIO_OUT_W1TS_REG,
RTC_GPIO_OUT_DATA_W1TS_S,
RTC_GPIO_OUT_DATA_W1TS_V,
) & bit(gpio_num as u32))
!= 0
{
1
} else {
0
}
}