Skip to content

Commit

Permalink
Merge branch 'esp-rs:master' into feature/expose-c-api-cs-pre-trans-d…
Browse files Browse the repository at this point in the history
…elay-in-spi-driver
  • Loading branch information
vpochapuis authored May 1, 2024
2 parents f047c62 + 26b5db8 commit c1b1464
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 94 deletions.
5 changes: 4 additions & 1 deletion src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,10 @@ pub mod continuous {

impl AdcMeasurement {
pub const INIT: Self = AdcMeasurement(unsafe {
core::mem::transmute([0u8; core::mem::size_of::<adc_digi_output_data_t>()])
core::mem::transmute::<
[u8; core::mem::size_of::<adc_digi_output_data_t>()],
adc_digi_output_data_t,
>([0u8; core::mem::size_of::<adc_digi_output_data_t>()])
});

pub const fn new() -> Self {
Expand Down
58 changes: 43 additions & 15 deletions src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
pub fn new(id: u32, flags: EnumSet<Flags>, data: &[u8]) -> Option<Self> {
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,
Expand Down Expand Up @@ -828,12 +856,12 @@ impl core::fmt::Display for Frame {

impl embedded_hal_0_2::can::Frame for Frame {
fn new(id: impl Into<embedded_hal_0_2::can::Id>, data: &[u8]) -> Option<Self> {
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<embedded_hal_0_2::can::Id>, dlc: usize) -> Option<Self> {
Expand Down Expand Up @@ -884,12 +912,12 @@ impl embedded_hal_0_2::can::Frame for Frame {

impl embedded_can::Frame for Frame {
fn new(id: impl Into<embedded_can::Id>, data: &[u8]) -> Option<Self> {
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<embedded_can::Id>, dlc: usize) -> Option<Self> {
Expand Down
5 changes: 4 additions & 1 deletion src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,10 @@ impl<'d, T: Pin, MODE> PinDriver<'d, T, MODE> {

let callback: alloc::boxed::Box<dyn FnMut() + Send + 'd> = 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<dyn FnMut() + Send>,
alloc::boxed::Box<dyn FnMut() + Send>,
>(callback));
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion src/rmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,9 @@ impl<const N: usize> FixedLengthSignal<N> {
.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(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
7 changes: 0 additions & 7 deletions src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down
5 changes: 4 additions & 1 deletion src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn FnMut() + Send>,
Box<dyn FnMut() + Send>,
>(callback));
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
72 changes: 16 additions & 56 deletions src/ulp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c1b1464

Please sign in to comment.