diff --git a/src/adc.rs b/src/adc.rs index 90fb59c7c72..30f3bcf95e6 100644 --- a/src/adc.rs +++ b/src/adc.rs @@ -948,7 +948,10 @@ pub mod continuous { impl AdcMeasurement { pub const INIT: Self = AdcMeasurement(unsafe { - core::mem::transmute([0u8; core::mem::size_of::()]) + core::mem::transmute::< + [u8; core::mem::size_of::()], + adc_digi_output_data_t, + >([0u8; core::mem::size_of::()]) }); pub const fn new() -> Self { diff --git a/src/can.rs b/src/can.rs index 5d7c6ae1be1..a9cd2546fee 100644 --- a/src/can.rs +++ b/src/can.rs @@ -726,27 +726,55 @@ static READ_NOTIFICATION: Notification = Notification::new(); static WRITE_NOTIFICATION: Notification = Notification::new(); static ALERT_NOTIFICATION: Notification = Notification::new(); +/// Twai message flags +#[derive(Debug, EnumSetType)] +pub enum Flags { + /// Message is in Extended Frame Format (29bit ID) + Extended, + /// Message is a Remote Frame (Remote Transmission Request) + Remote, + /// Transmit message using Single Shot Transmission + /// (Message will not be retransmitted upon error or loss of arbitration). + /// Unused for received message. + SingleShot, + /// Transmit message using Self Reception Request + /// (Transmitted message will also received by the same node). + /// Unused for received message. + SelfReception, + /// Message's Data length code is larger than 8. + /// This will break compliance with TWAI + DlcNonComp, + None, +} + pub struct Frame(twai_message_t); impl Frame { - pub fn new(id: u32, extended: bool, data: &[u8]) -> Option { + pub fn new(id: u32, flags: EnumSet, data: &[u8]) -> Option { let dlc = data.len(); if dlc <= 8 { // unions are not very well supported in rust // therefore setting those union flags is quite hairy - let mut flags = twai_message_t__bindgen_ty_1::default(); - - // set bits in an union - if extended { - unsafe { flags.__bindgen_anon_1.set_extd(1) }; + let mut twai_flags = twai_message_t__bindgen_ty_1::default(); + + // Iterate over the flags set and set the corresponding bits in the union + for flag in flags.iter() { + match flag { + Flags::Extended => unsafe { twai_flags.__bindgen_anon_1.set_extd(1) }, + Flags::Remote => unsafe { twai_flags.__bindgen_anon_1.set_rtr(1) }, + Flags::SingleShot => unsafe { twai_flags.__bindgen_anon_1.set_ss(1) }, + Flags::SelfReception => unsafe { twai_flags.__bindgen_anon_1.set_self(1) }, + Flags::DlcNonComp => unsafe { twai_flags.__bindgen_anon_1.set_dlc_non_comp(1) }, + Flags::None => {} + } } let mut payload = [0; 8]; payload[..dlc].copy_from_slice(data); let twai_message = twai_message_t { - __bindgen_anon_1: flags, + __bindgen_anon_1: twai_flags, identifier: id, data_length_code: dlc as u8, data: payload, @@ -828,12 +856,12 @@ impl core::fmt::Display for Frame { impl embedded_hal_0_2::can::Frame for Frame { fn new(id: impl Into, data: &[u8]) -> Option { - let (id, extended) = match id.into() { - embedded_hal_0_2::can::Id::Standard(id) => (id.as_raw() as u32, false), - embedded_hal_0_2::can::Id::Extended(id) => (id.as_raw(), true), + let (id, flags) = match id.into() { + embedded_hal_0_2::can::Id::Standard(id) => (id.as_raw() as u32, Flags::None), + embedded_hal_0_2::can::Id::Extended(id) => (id.as_raw(), Flags::Extended), }; - Self::new(id, extended, data) + Self::new(id, flags.into(), data) } fn new_remote(id: impl Into, dlc: usize) -> Option { @@ -884,12 +912,12 @@ impl embedded_hal_0_2::can::Frame for Frame { impl embedded_can::Frame for Frame { fn new(id: impl Into, data: &[u8]) -> Option { - let (id, extended) = match id.into() { - embedded_can::Id::Standard(id) => (id.as_raw() as u32, false), - embedded_can::Id::Extended(id) => (id.as_raw(), true), + let (id, flags) = match id.into() { + embedded_can::Id::Standard(id) => (id.as_raw() as u32, Flags::None), + embedded_can::Id::Extended(id) => (id.as_raw(), Flags::Extended), }; - Self::new(id, extended, data) + Self::new(id, flags.into(), data) } fn new_remote(id: impl Into, dlc: usize) -> Option { diff --git a/src/gpio.rs b/src/gpio.rs index 7774139fabd..8a5dfa0d58d 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -1089,7 +1089,10 @@ impl<'d, T: Pin, MODE> PinDriver<'d, T, MODE> { let callback: alloc::boxed::Box = alloc::boxed::Box::new(callback); unsafe { - chip::PIN_ISR_HANDLER[self.pin.pin() as usize] = Some(core::mem::transmute(callback)); + chip::PIN_ISR_HANDLER[self.pin.pin() as usize] = Some(core::mem::transmute::< + alloc::boxed::Box, + alloc::boxed::Box, + >(callback)); } Ok(()) diff --git a/src/lib.rs b/src/lib.rs index 8b63af4b359..0f7fea8ecd0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ pub mod ledc; #[cfg(any(all(esp32, esp_idf_eth_use_esp32_emac), esp_idf_eth_use_openeth))] pub mod mac; pub mod modem; -#[cfg(any(esp32, esp32s2, esp32s3))] +#[cfg(any(esp32, esp32s2, esp32s3, esp32c6))] pub mod pcnt; pub mod peripheral; pub mod peripherals; diff --git a/src/peripherals.rs b/src/peripherals.rs index 202e3263d5d..14a63811372 100644 --- a/src/peripherals.rs +++ b/src/peripherals.rs @@ -8,7 +8,7 @@ use crate::ledc; #[cfg(any(all(esp32, esp_idf_eth_use_esp32_emac), esp_idf_eth_use_openeth))] use crate::mac; use crate::modem; -#[cfg(any(esp32, esp32s2, esp32s3))] +#[cfg(any(esp32, esp32s2, esp32s3, esp32c6))] use crate::pcnt; use crate::rmt; use crate::spi; @@ -48,14 +48,14 @@ pub struct Peripherals { pub adc1: adc::ADC1, #[cfg(any(esp32, esp32s2, esp32s3, esp32c3))] pub adc2: adc::ADC2, - // TODO: Check the pulse counter story for c2, h2, c5, c6, and p4 - #[cfg(any(esp32, esp32s2, esp32s3))] + // TODO: Check the pulse counter story for c2, h2, c5, and p4 + #[cfg(any(esp32, esp32s2, esp32s3, esp32c6))] pub pcnt0: pcnt::PCNT0, - #[cfg(any(esp32, esp32s2, esp32s3))] + #[cfg(any(esp32, esp32s2, esp32s3, esp32c6))] pub pcnt1: pcnt::PCNT1, - #[cfg(any(esp32, esp32s2, esp32s3))] + #[cfg(any(esp32, esp32s2, esp32s3, esp32c6))] pub pcnt2: pcnt::PCNT2, - #[cfg(any(esp32, esp32s2, esp32s3))] + #[cfg(any(esp32, esp32s2, esp32s3, esp32c6))] pub pcnt3: pcnt::PCNT3, #[cfg(esp32)] pub pcnt4: pcnt::PCNT4, @@ -144,13 +144,13 @@ impl Peripherals { adc1: adc::ADC1::new(), #[cfg(any(esp32, esp32s2, esp32s3, esp32c3))] adc2: adc::ADC2::new(), - #[cfg(any(esp32, esp32s2, esp32s3))] + #[cfg(any(esp32, esp32s2, esp32s3, esp32c6))] pcnt0: pcnt::PCNT0::new(), - #[cfg(any(esp32, esp32s2, esp32s3))] + #[cfg(any(esp32, esp32s2, esp32s3, esp32c6))] pcnt1: pcnt::PCNT1::new(), - #[cfg(any(esp32, esp32s2, esp32s3))] + #[cfg(any(esp32, esp32s2, esp32s3, esp32c6))] pcnt2: pcnt::PCNT2::new(), - #[cfg(any(esp32, esp32s2, esp32s3))] + #[cfg(any(esp32, esp32s2, esp32s3, esp32c6))] pcnt3: pcnt::PCNT3::new(), #[cfg(esp32)] pcnt4: pcnt::PCNT4::new(), diff --git a/src/rmt.rs b/src/rmt.rs index 8bc92f6b989..286fd94f690 100644 --- a/src/rmt.rs +++ b/src/rmt.rs @@ -868,7 +868,9 @@ impl FixedLengthSignal { .get_mut(index) .ok_or_else(|| EspError::from(ERR_ERANGE).unwrap())?; - Symbol(*item).update(pair.0, pair.1); + let mut symbol = Symbol(*item); + symbol.update(pair.0, pair.1); + *item = symbol.0; Ok(()) } } diff --git a/src/spi.rs b/src/spi.rs index e70c62a5b5a..b541f7c3652 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -40,7 +40,7 @@ use core::cmp::{max, min, Ordering}; use core::future::Future; use core::iter::once; use core::marker::PhantomData; -use core::{ptr, u8}; +use core::ptr; use embassy_sync::mutex::Mutex; use embedded_hal::spi::{SpiBus, SpiDevice}; diff --git a/src/task.rs b/src/task.rs index 252dfa64fcc..68e47264aeb 100644 --- a/src/task.rs +++ b/src/task.rs @@ -524,13 +524,6 @@ impl<'a> Drop for CriticalSectionGuard<'a> { } } -#[cfg(any( - all( - not(any(esp_idf_version_major = "4", esp_idf_version = "5.0")), - esp_idf_esp_task_wdt_en - ), - any(esp_idf_version_major = "4", esp_idf_version = "5.0") -))] pub mod watchdog { //! ## Example //! diff --git a/src/timer.rs b/src/timer.rs index 36d58f940d2..1514427810e 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -398,7 +398,10 @@ impl<'d> TimerDriver<'d> { unsafe { ISR_HANDLERS[(self.group() * timer_idx_t_TIMER_MAX + self.index()) as usize] = - Some(core::mem::transmute(callback)); + Some(core::mem::transmute::< + Box, + Box, + >(callback)); } Ok(()) diff --git a/src/uart.rs b/src/uart.rs index 3b16ba6a065..b9c29ea89c4 100644 --- a/src/uart.rs +++ b/src/uart.rs @@ -217,6 +217,7 @@ pub mod config { #[cfg(esp_idf_soc_uart_support_xtal_clk)] Crystal, /// UART source clock from `XTAL` + #[allow(non_camel_case_types)] #[cfg(esp_idf_soc_uart_support_pll_f80m_clk)] PLL_F80M, /// UART source clock from `REF_TICK` diff --git a/src/ulp.rs b/src/ulp.rs index f838894abe5..c808356ac09 100644 --- a/src/ulp.rs +++ b/src/ulp.rs @@ -21,15 +21,13 @@ impl Default for SleepTimer { esp_idf_ulp_coproc_enabled, esp_idf_ulp_coproc_type_fsm ), - all(esp_idf_version_major = "4", esp32, esp_idf_esp32_ulp_coproc_enabled), + all(esp32, esp_idf_esp32_ulp_coproc_enabled), all( - esp_idf_version_major = "4", esp32s2, esp_idf_esp32s2_ulp_coproc_enabled, not(esp_idf_esp32s2_ulp_coproc_riscv) ), all( - esp_idf_version_major = "4", esp32s3, esp_idf_esp32s3_ulp_coproc_enabled, not(esp_idf_esp32s3_ulp_coproc_riscv) @@ -47,15 +45,13 @@ pub struct Word { esp_idf_ulp_coproc_enabled, esp_idf_ulp_coproc_type_fsm ), - all(esp_idf_version_major = "4", esp32, esp_idf_esp32_ulp_coproc_enabled), + all(esp32, esp_idf_esp32_ulp_coproc_enabled), all( - esp_idf_version_major = "4", esp32s2, esp_idf_esp32s2_ulp_coproc_enabled, not(esp_idf_esp32s2_ulp_coproc_riscv) ), all( - esp_idf_version_major = "4", esp32s3, esp_idf_esp32s3_ulp_coproc_enabled, not(esp_idf_esp32s3_ulp_coproc_riscv) @@ -77,49 +73,25 @@ impl Word { #[cfg(any( all(not(esp_idf_version_major = "4"), esp_idf_ulp_coproc_enabled), - all(esp_idf_version_major = "4", esp32, esp_idf_esp32_ulp_coproc_enabled), - all( - esp_idf_version_major = "4", - esp32s2, - esp_idf_esp32s2_ulp_coproc_enabled - ), - all( - esp_idf_version_major = "4", - esp32s3, - esp_idf_esp32s3_ulp_coproc_enabled - ) + all(esp32, esp_idf_esp32_ulp_coproc_enabled), + all(esp32s2, esp_idf_esp32s2_ulp_coproc_enabled), + all(esp32s3, esp_idf_esp32s3_ulp_coproc_enabled) ))] pub struct UlpDriver<'d>(crate::peripheral::PeripheralRef<'d, ULP>); #[cfg(any( all(not(esp_idf_version_major = "4"), esp_idf_ulp_coproc_enabled), - all(esp_idf_version_major = "4", esp32, esp_idf_esp32_ulp_coproc_enabled), - all( - esp_idf_version_major = "4", - esp32s2, - esp_idf_esp32s2_ulp_coproc_enabled - ), - all( - esp_idf_version_major = "4", - esp32s3, - esp_idf_esp32s3_ulp_coproc_enabled - ) + all(esp32, esp_idf_esp32_ulp_coproc_enabled), + all(esp32s2, esp_idf_esp32s2_ulp_coproc_enabled), + all(esp32s3, esp_idf_esp32s3_ulp_coproc_enabled) ))] unsafe impl<'d> Send for UlpDriver<'d> {} #[cfg(any( all(not(esp_idf_version_major = "4"), esp_idf_ulp_coproc_enabled), - all(esp_idf_version_major = "4", esp32, esp_idf_esp32_ulp_coproc_enabled), - all( - esp_idf_version_major = "4", - esp32s2, - esp_idf_esp32s2_ulp_coproc_enabled - ), - all( - esp_idf_version_major = "4", - esp32s3, - esp_idf_esp32s3_ulp_coproc_enabled - ) + all(esp32, esp_idf_esp32_ulp_coproc_enabled), + all(esp32s2, esp_idf_esp32s2_ulp_coproc_enabled), + all(esp32s3, esp_idf_esp32s3_ulp_coproc_enabled) ))] impl<'d> UlpDriver<'d> { pub fn new( @@ -196,15 +168,13 @@ impl<'d> UlpDriver<'d> { esp_idf_ulp_coproc_enabled, esp_idf_ulp_coproc_type_fsm ), - all(esp_idf_version_major = "4", esp32, esp_idf_esp32_ulp_coproc_enabled), + all(esp32, esp_idf_esp32_ulp_coproc_enabled), all( - esp_idf_version_major = "4", esp32s2, esp_idf_esp32s2_ulp_coproc_enabled, not(esp_idf_esp32s2_ulp_coproc_riscv) ), all( - esp_idf_version_major = "4", esp32s3, esp_idf_esp32s3_ulp_coproc_enabled, not(esp_idf_esp32s3_ulp_coproc_riscv) @@ -305,17 +275,15 @@ impl<'d> UlpDriver<'d> { not(esp_idf_ulp_coproc_type_fsm) ), all( - esp_idf_version_major = "4", esp32s2, esp_idf_esp32s2_ulp_coproc_enabled, esp_idf_esp32s2_ulp_coproc_riscv ), all( - esp_idf_version_major = "4", esp32s3, esp_idf_esp32s3_ulp_coproc_enabled, esp_idf_esp32s3_ulp_coproc_riscv - ) + ), ))] impl<'d> UlpDriver<'d> { pub unsafe fn load(&mut self, program: &[u8]) -> Result<(), esp_idf_sys::EspError> { @@ -364,17 +332,9 @@ crate::impl_peripheral!(ULP); #[cfg(any( all(not(esp_idf_version_major = "4"), esp_idf_ulp_coproc_enabled), - all(esp_idf_version_major = "4", esp32, esp_idf_esp32_ulp_coproc_enabled), - all( - esp_idf_version_major = "4", - esp32s2, - esp_idf_esp32s2_ulp_coproc_enabled - ), - all( - esp_idf_version_major = "4", - esp32s3, - esp_idf_esp32s3_ulp_coproc_enabled - ) + all(esp32, esp_idf_esp32_ulp_coproc_enabled), + all(esp32s2, esp_idf_esp32s2_ulp_coproc_enabled), + all(esp32s3, esp_idf_esp32s3_ulp_coproc_enabled) ))] impl ULP { const RTC_SLOW_MEM: u32 = 0x5000_0000_u32;