Fix broken rebase

make clippy happy

fix the ulp build

Remove embedded-svc dependency

no-alloc
This commit is contained in:
ivmarkov 2022-09-17 20:08:56 +03:00 committed by Ivan Markov
parent 0e35a694c4
commit a8c26ed5c0
5 changed files with 37 additions and 68 deletions

View File

@ -29,7 +29,6 @@ embassy-time-timer11 = ["embassy-time"]
nb = "0.1.2"
embedded-hal = "=1.0.0-alpha.8"
embedded-hal-0-2 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"] }
embedded-svc = { version = "0.22", optional = true, default-features = false }
esp-idf-sys = { version = "0.31.9", optional = true, default-features = false, features = ["native"] }
critical-section = { version = "1.1", optional = true }
embassy-time = { version = "0.1", optional = true, features = ["tick-hz-1_000_000"], git = "https://github.com/embassy-rs/embassy" }

View File

@ -261,7 +261,7 @@ impl<'d, ADC: Adc> AdcDriver<'d, ADC> {
) -> Result<u16, EspError> {
let measurement = unsafe { hall_sensor_read() };
Ok(self.raw_to_voltage(measurement, adc_atten_t_ADC_ATTEN_DB_0)?)
self.raw_to_voltage(measurement, adc_atten_t_ADC_ATTEN_DB_0)
}
fn read_internal(
@ -395,6 +395,7 @@ impl<'d> embedded_hal_0_2::adc::OneShot<ADC1, u16, crate::hall::HallSensor>
}
}
#[cfg(not(feature = "riscv-ulp-hal"))]
fn to_nb_err(err: EspError) -> nb::Error<EspError> {
if err.code() == ESP_ERR_INVALID_STATE as i32 {
nb::Error::WouldBlock

View File

@ -1085,14 +1085,14 @@ pub(crate) unsafe fn rtc_reset_pin(pin: i32) -> Result<(), EspError> {
Ok(())
}
unsafe fn reset_pin(pin: i32, mode: gpio_mode_t) -> Result<(), EspError> {
unsafe fn reset_pin(_pin: i32, _mode: gpio_mode_t) -> Result<(), EspError> {
#[cfg(not(feature = "riscv-ulp-hal"))]
let res = {
#[cfg(feature = "alloc")]
unsubscribe_pin(pin)?;
unsubscribe_pin(_pin)?;
esp!(gpio_reset_pin(pin))?;
esp!(gpio_set_direction(pin, mode))?;
esp!(gpio_reset_pin(_pin))?;
esp!(gpio_set_direction(_pin, _mode))?;
Ok(())
};

View File

@ -220,52 +220,6 @@ pub fn free<R>(f: impl FnOnce() -> R) -> R {
f()
}
<<<<<<< HEAD
/// A raw mutex based on critical sections
pub struct RawMutex(CriticalSection);
impl RawMutex {
#[inline(always)]
#[link_section = ".iram1.interrupt_mutex_new"]
pub const fn new() -> Self {
Self(CriticalSection::new())
}
#[inline(always)]
#[link_section = ".iram1.interrupt_mutex_lock"]
pub fn lock(&self) {
enter(&self.0);
}
#[inline(always)]
#[link_section = ".iram1.interrupt_mutex_unlock"]
#[allow(clippy::missing_safety_doc)]
pub unsafe fn unlock(&self) {
exit(&self.0);
}
}
unsafe impl Sync for RawMutex {}
unsafe impl Send for RawMutex {}
pub type Mutex<T> = embedded_svc::utils::mutex::Mutex<RawMutex, T>;
impl embedded_svc::mutex::RawMutex for RawMutex {
#[cfg(feature = "nightly")] // Remove "nightly" condition once 1.64 is out
#[allow(clippy::declare_interior_mutable_const)]
const INIT: Self = RawMutex::new();
fn new() -> Self {
RawMutex::new()
}
unsafe fn lock(&self) {
RawMutex::lock(self);
}
unsafe fn unlock(&self) {
RawMutex::unlock(self);
=======
#[cfg(feature = "critical-section-interrupt")]
mod critical_section {
static CS: super::CriticalSection = super::CriticalSection::new();
@ -282,6 +236,5 @@ mod critical_section {
unsafe fn release(_token: ()) {
super::exit(&CS);
}
>>>>>>> d7fd24a303... Remove embedded-svc dep, compat with critical-section, modem and mac peripherals
}
}

View File

@ -2,6 +2,12 @@ use esp_idf_sys::*;
use crate::peripheral::{Peripheral, PeripheralRef};
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "alloc")]
use alloc::boxed::Box;
pub type TimerConfig = config::Config;
/// Timer configuration
@ -163,6 +169,7 @@ where
///
/// Care should be taken not to call STD, libc or FreeRTOS APIs (except for a few allowed ones)
/// in the callback passed to this function, as it is executed in an ISR context.
#[cfg(feature = "alloc")]
pub unsafe fn subscribe(&mut self, callback: impl FnMut() + 'static) -> Result<(), EspError> {
self.unsubscribe()?;
@ -190,14 +197,27 @@ where
Ok(())
}
#[cfg(feature = "alloc")]
pub fn unsubscribe(&mut self) -> Result<(), EspError> {
unsafe {
unsubscribe_timer(TIMER::group(), TIMER::index())?;
let subscribed = ISR_HANDLERS
[(TIMER::group() * timer_group_t_TIMER_GROUP_MAX + TIMER::index()) as usize]
.is_some();
if subscribed {
esp!(timer_disable_intr(TIMER::group(), TIMER::index()))?;
esp!(timer_isr_callback_remove(TIMER::group(), TIMER::index()))?;
ISR_HANDLERS
[(TIMER::group() * timer_group_t_TIMER_GROUP_MAX + TIMER::index()) as usize] =
None;
}
}
Ok(())
}
#[cfg(feature = "alloc")]
unsafe extern "C" fn handle_isr(unsafe_callback: *mut c_types::c_void) -> bool {
crate::interrupt::with_isr_yield_signal(move || {
UnsafeCallback::from_ptr(unsafe_callback).call();
@ -207,28 +227,21 @@ where
impl<'d, TIMER: Timer> Drop for TimerDriver<'d, TIMER> {
fn drop(&mut self) {
#[cfg(feature = "alloc")]
{
self.unsubscribe().unwrap();
}
esp!(unsafe { timer_deinit(TIMER::group(), TIMER::index()) }).unwrap();
}
}
unsafe impl<'d, TIMER: Timer> Send for TimerDriver<'d, TIMER> {}
unsafe fn unsubscribe_timer(group: timer_group_t, index: timer_idx_t) -> Result<(), EspError> {
let subscribed =
ISR_HANDLERS[(group * timer_group_t_TIMER_GROUP_MAX + index) as usize].is_some();
if subscribed {
esp!(timer_disable_intr(group, index))?;
esp!(timer_isr_callback_remove(group, index))?;
ISR_HANDLERS[(group * timer_group_t_TIMER_GROUP_MAX + index) as usize] = None;
}
Ok(())
}
#[cfg(feature = "alloc")]
struct UnsafeCallback(*mut Box<dyn FnMut() + 'static>);
#[cfg(feature = "alloc")]
impl UnsafeCallback {
#[allow(clippy::type_complexity)]
pub fn from(boxed: &mut Box<Box<dyn FnMut() + 'static>>) -> Self {
@ -270,10 +283,12 @@ macro_rules! impl_timer {
#[allow(clippy::type_complexity)]
#[cfg(esp32c3)]
#[cfg(feature = "alloc")]
static mut ISR_HANDLERS: [Option<Box<Box<dyn FnMut()>>>; 2] = [None, None];
#[allow(clippy::type_complexity)]
#[cfg(not(esp32c3))]
#[cfg(feature = "alloc")]
static mut ISR_HANDLERS: [Option<Box<Box<dyn FnMut()>>>; 4] = [None, None, None, None];
impl_timer!(TIMER00: timer_group_t_TIMER_GROUP_0, timer_idx_t_TIMER_0);
@ -319,6 +334,7 @@ mod embassy_time {
initialized: AtomicBool,
cs_mutex: crate::cs::CriticalSection,
cs_inter: crate::interrupt::CriticalSection,
#[allow(clippy::type_complexity)]
callback: Cell<(fn(*mut ()), *mut ())>,
}