Remove embedded-hal 0.2.x impls and deps from esp-hal (#2593)
* Initial remove * update ssd1306 driver version * small docs cleanup * migration guide * changelog entry * update changelog entry (move under `Removed` section) * eh migration guide link * `Wait` trait linking
This commit is contained in:
parent
ef98e2b24f
commit
a00643f22d
@ -41,13 +41,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- Remove more examples. Update doctests. (#2547)
|
- Remove more examples. Update doctests. (#2547)
|
||||||
|
|
||||||
- The `configure` and `configure_for_async` DMA channel functions has been removed (#2403)
|
- The `configure` and `configure_for_async` DMA channel functions has been removed (#2403)
|
||||||
- The DMA channel objects no longer have `tx` and `rx` fields. (#2526)
|
- The DMA channel objects no longer have `tx` and `rx` fields. (#2526)
|
||||||
- `SysTimerAlarms` has been removed, alarms are now part of the `SystemTimer` struct (#2576)
|
- `SysTimerAlarms` has been removed, alarms are now part of the `SystemTimer` struct (#2576)
|
||||||
- `FrozenUnit`, `AnyUnit`, `SpecificUnit`, `SpecificComparator`, `AnyComparator` have been removed from `systimer` (#2576)
|
- `FrozenUnit`, `AnyUnit`, `SpecificUnit`, `SpecificComparator`, `AnyComparator` have been removed from `systimer` (#2576)
|
||||||
- `esp_hal::psram::psram_range` (#2546)
|
- `esp_hal::psram::psram_range` (#2546)
|
||||||
- The `Dma` structure has been removed. (#2545)
|
- The `Dma` structure has been removed. (#2545)
|
||||||
|
- Remove `embedded-hal 0.2.x` impls and deps from `esp-hal` (#2593)
|
||||||
|
|
||||||
## [0.22.0] - 2024-11-20
|
## [0.22.0] - 2024-11-20
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,6 @@ embassy-sync = "0.6.1"
|
|||||||
embassy-usb-driver = { version = "0.1.0", optional = true }
|
embassy-usb-driver = { version = "0.1.0", optional = true }
|
||||||
embassy-usb-synopsys-otg = { version = "0.1.0", optional = true }
|
embassy-usb-synopsys-otg = { version = "0.1.0", optional = true }
|
||||||
embedded-can = "0.4.1"
|
embedded-can = "0.4.1"
|
||||||
embedded-hal-02 = { version = "0.2.7", features = ["unproven"], package = "embedded-hal" }
|
|
||||||
embedded-hal = "1.0.0"
|
embedded-hal = "1.0.0"
|
||||||
embedded-hal-async = "1.0.0"
|
embedded-hal-async = "1.0.0"
|
||||||
embedded-hal-nb = "1.0.0"
|
embedded-hal-nb = "1.0.0"
|
||||||
|
|||||||
@ -158,3 +158,29 @@ is enabled. To retrieve the address and size of the initialized external memory,
|
|||||||
```
|
```
|
||||||
|
|
||||||
The usage of `esp_alloc::psram_allocator!` remains unchanged.
|
The usage of `esp_alloc::psram_allocator!` remains unchanged.
|
||||||
|
|
||||||
|
|
||||||
|
### embedded-hal 0.2.* is not supported anymore.
|
||||||
|
|
||||||
|
As per https://github.com/rust-embedded/embedded-hal/pull/640, our driver no longer implements traits from `embedded-hal 0.2.x`.
|
||||||
|
Analogs of all traits from the above mentioned version are available in `embedded-hal 1.x.x`
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- use embedded_hal_02::can::Frame;
|
||||||
|
+ use embedded_can::Frame;
|
||||||
|
```
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- use embedded_hal_02::digital::v2::OutputPin;
|
||||||
|
- use embedded_hal_02::digital::v2::ToggleableOutputPin;
|
||||||
|
+ use embedded_hal::digital::OutputPin;
|
||||||
|
+ use embedded_hal::digital::StatefulOutputPin;
|
||||||
|
```
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- use embedded_hal_02::serial::{Read, Write};
|
||||||
|
+ use embedded_hal_nb::serial::{Read, Write};
|
||||||
|
```
|
||||||
|
|
||||||
|
You might also want to check the full official `embedded-hal` migration guide:
|
||||||
|
https://github.com/rust-embedded/embedded-hal/blob/master/docs/migrating-from-0.2-to-1.0.md
|
||||||
|
|||||||
@ -343,19 +343,6 @@ impl<'d, ADC1> Adc<'d, ADC1> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, ADCI, PIN> embedded_hal_02::adc::OneShot<ADCI, u16, super::AdcPin<PIN, ADCI>>
|
|
||||||
for Adc<'d, ADCI>
|
|
||||||
where
|
|
||||||
PIN: embedded_hal_02::adc::Channel<ADCI, ID = u8> + super::AdcChannel,
|
|
||||||
ADCI: RegisterAccess,
|
|
||||||
{
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn read(&mut self, pin: &mut super::AdcPin<PIN, ADCI>) -> nb::Result<u16, Self::Error> {
|
|
||||||
self.read_oneshot(pin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod adc_implementation {
|
mod adc_implementation {
|
||||||
crate::analog::adc::impl_adc_interface! {
|
crate::analog::adc::impl_adc_interface! {
|
||||||
ADC1 [
|
ADC1 [
|
||||||
|
|||||||
@ -16,10 +16,6 @@
|
|||||||
//! basic calibration, curve fitting or linear interpolation. The calibration
|
//! basic calibration, curve fitting or linear interpolation. The calibration
|
||||||
//! schemes can be used to improve the accuracy of the ADC readings.
|
//! schemes can be used to improve the accuracy of the ADC readings.
|
||||||
//!
|
//!
|
||||||
//! ## Usage
|
|
||||||
//!
|
|
||||||
//! The ADC driver implements the `embedded-hal@0.2.x` ADC traits.
|
|
||||||
//!
|
|
||||||
//! ## Examples
|
//! ## Examples
|
||||||
//!
|
//!
|
||||||
//! ### Read an analog signal from a pin
|
//! ### Read an analog signal from a pin
|
||||||
@ -108,17 +104,6 @@ pub struct AdcPin<PIN, ADCI, CS = ()> {
|
|||||||
_phantom: PhantomData<ADCI>,
|
_phantom: PhantomData<ADCI>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<PIN, ADCI, CS> embedded_hal_02::adc::Channel<ADCI> for AdcPin<PIN, ADCI, CS>
|
|
||||||
where
|
|
||||||
PIN: embedded_hal_02::adc::Channel<ADCI, ID = u8>,
|
|
||||||
{
|
|
||||||
type ID = u8;
|
|
||||||
|
|
||||||
fn channel() -> Self::ID {
|
|
||||||
PIN::channel()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Configuration for the ADC.
|
/// Configuration for the ADC.
|
||||||
pub struct AdcConfig<ADCI> {
|
pub struct AdcConfig<ADCI> {
|
||||||
#[cfg_attr(not(esp32), allow(unused))]
|
#[cfg_attr(not(esp32), allow(unused))]
|
||||||
@ -256,12 +241,6 @@ macro_rules! impl_adc_interface {
|
|||||||
impl $crate::analog::adc::AdcChannel for crate::gpio::GpioPin<$pin> {
|
impl $crate::analog::adc::AdcChannel for crate::gpio::GpioPin<$pin> {
|
||||||
const CHANNEL: u8 = $channel;
|
const CHANNEL: u8 = $channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl embedded_hal_02::adc::Channel<crate::peripherals::$adc> for crate::gpio::GpioPin<$pin> {
|
|
||||||
type ID = u8;
|
|
||||||
|
|
||||||
fn channel() -> u8 { $channel }
|
|
||||||
}
|
|
||||||
)+
|
)+
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -531,20 +531,6 @@ impl super::AdcCalEfuse for crate::peripherals::ADC2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<ADCI, PIN, CS> embedded_hal_02::adc::OneShot<ADCI, u16, super::AdcPin<PIN, ADCI, CS>>
|
|
||||||
for Adc<'_, ADCI>
|
|
||||||
where
|
|
||||||
PIN: embedded_hal_02::adc::Channel<ADCI, ID = u8> + super::AdcChannel,
|
|
||||||
ADCI: RegisterAccess,
|
|
||||||
CS: super::AdcCalScheme<ADCI>,
|
|
||||||
{
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn read(&mut self, pin: &mut super::AdcPin<PIN, ADCI, CS>) -> nb::Result<u16, Self::Error> {
|
|
||||||
self.read_oneshot(pin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(esp32c2)]
|
#[cfg(esp32c2)]
|
||||||
mod adc_implementation {
|
mod adc_implementation {
|
||||||
crate::analog::adc::impl_adc_interface! {
|
crate::analog::adc::impl_adc_interface! {
|
||||||
|
|||||||
@ -590,20 +590,6 @@ impl super::AdcCalEfuse for crate::peripherals::ADC2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, ADCI, PIN, CS> embedded_hal_02::adc::OneShot<ADCI, u16, AdcPin<PIN, ADCI, CS>>
|
|
||||||
for Adc<'d, ADCI>
|
|
||||||
where
|
|
||||||
PIN: embedded_hal_02::adc::Channel<ADCI, ID = u8> + AdcChannel,
|
|
||||||
ADCI: RegisterAccess,
|
|
||||||
CS: AdcCalScheme<ADCI>,
|
|
||||||
{
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn read(&mut self, pin: &mut AdcPin<PIN, ADCI, CS>) -> nb::Result<u16, Self::Error> {
|
|
||||||
self.read_oneshot(pin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod adc_implementation {
|
mod adc_implementation {
|
||||||
crate::analog::adc::impl_adc_interface! {
|
crate::analog::adc::impl_adc_interface! {
|
||||||
ADC1 [
|
ADC1 [
|
||||||
|
|||||||
@ -13,8 +13,7 @@
|
|||||||
//!
|
//!
|
||||||
//! ## Usage
|
//! ## Usage
|
||||||
//!
|
//!
|
||||||
//! This module implements the blocking [DelayMs] and [DelayUs] traits from
|
//! This module implements the blocking [DelayNs] trait from [embedded-hal].
|
||||||
//! [embedded-hal], both 0.2.x and 1.x.x.
|
|
||||||
//!
|
//!
|
||||||
//! ## Examples
|
//! ## Examples
|
||||||
//! ### Delay for 1 second
|
//! ### Delay for 1 second
|
||||||
@ -28,8 +27,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! [DelayMs]: embedded_hal_02::blocking::delay::DelayMs
|
//! [DelayNs]: https://docs.rs/embedded-hal/1.0.0/embedded_hal/delay/trait.DelayNs.html
|
||||||
//! [DelayUs]: embedded_hal_02::blocking::delay::DelayUs
|
|
||||||
//! [embedded-hal]: https://docs.rs/embedded-hal/1.0.0/embedded_hal/delay/index.html
|
//! [embedded-hal]: https://docs.rs/embedded-hal/1.0.0/embedded_hal/delay/index.html
|
||||||
//! [now]: crate::time::now
|
//! [now]: crate::time::now
|
||||||
|
|
||||||
@ -43,24 +41,6 @@ pub use fugit::MicrosDurationU64;
|
|||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct Delay;
|
pub struct Delay;
|
||||||
|
|
||||||
impl<T> embedded_hal_02::blocking::delay::DelayMs<T> for Delay
|
|
||||||
where
|
|
||||||
T: Into<u32>,
|
|
||||||
{
|
|
||||||
fn delay_ms(&mut self, ms: T) {
|
|
||||||
self.delay_millis(ms.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> embedded_hal_02::blocking::delay::DelayUs<T> for Delay
|
|
||||||
where
|
|
||||||
T: Into<u32>,
|
|
||||||
{
|
|
||||||
fn delay_us(&mut self, us: T) {
|
|
||||||
self.delay_micros(us.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl embedded_hal::delay::DelayNs for Delay {
|
impl embedded_hal::delay::DelayNs for Delay {
|
||||||
fn delay_ns(&mut self, ns: u32) {
|
fn delay_ns(&mut self, ns: u32) {
|
||||||
self.delay_nanos(ns);
|
self.delay_nanos(ns);
|
||||||
|
|||||||
@ -31,6 +31,9 @@
|
|||||||
//! GPIO interrupts. For more information, see the
|
//! GPIO interrupts. For more information, see the
|
||||||
//! [`Io::set_interrupt_handler`].
|
//! [`Io::set_interrupt_handler`].
|
||||||
//!
|
//!
|
||||||
|
//! This driver also implements pin-related traits from [embedded-hal] and
|
||||||
|
//! [Wait](embedded_hal_async::digital::Wait) trait from [embedded-hal-async].
|
||||||
|
//!
|
||||||
//! ## GPIO interconnect
|
//! ## GPIO interconnect
|
||||||
//!
|
//!
|
||||||
//! Sometimes you may want to connect peripherals together without using
|
//! Sometimes you may want to connect peripherals together without using
|
||||||
@ -49,6 +52,7 @@
|
|||||||
//! See the [Inverting TX and RX Pins] example of the UART documentation.
|
//! See the [Inverting TX and RX Pins] example of the UART documentation.
|
||||||
//!
|
//!
|
||||||
//! [embedded-hal]: https://docs.rs/embedded-hal/latest/embedded_hal/
|
//! [embedded-hal]: https://docs.rs/embedded-hal/latest/embedded_hal/
|
||||||
|
//! [embedded-hal-async]: https://docs.rs/embedded-hal-async/latest/embedded_hal_async/index.html
|
||||||
//! [Inverting TX and RX Pins]: crate::uart#inverting-rx-and-tx-pins
|
//! [Inverting TX and RX Pins]: crate::uart#inverting-rx-and-tx-pins
|
||||||
|
|
||||||
use portable_atomic::{AtomicPtr, Ordering};
|
use portable_atomic::{AtomicPtr, Ordering};
|
||||||
@ -2297,175 +2301,6 @@ mod asynch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod embedded_hal_02_impls {
|
|
||||||
use embedded_hal_02::digital::v2 as digital;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
impl<P> digital::InputPin for Input<'_, P>
|
|
||||||
where
|
|
||||||
P: InputPin,
|
|
||||||
{
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.pin.is_high())
|
|
||||||
}
|
|
||||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.pin.is_low())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::OutputPin for Output<'_, P>
|
|
||||||
where
|
|
||||||
P: OutputPin,
|
|
||||||
{
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
||||||
self.pin.set_high();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
||||||
self.pin.set_low();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::StatefulOutputPin for Output<'_, P>
|
|
||||||
where
|
|
||||||
P: OutputPin,
|
|
||||||
{
|
|
||||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.is_set_high())
|
|
||||||
}
|
|
||||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.is_set_low())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::ToggleableOutputPin for Output<'_, P>
|
|
||||||
where
|
|
||||||
P: OutputPin,
|
|
||||||
{
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn toggle(&mut self) -> Result<(), Self::Error> {
|
|
||||||
self.toggle();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::InputPin for OutputOpenDrain<'_, P>
|
|
||||||
where
|
|
||||||
P: InputPin + OutputPin,
|
|
||||||
{
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.pin.is_high())
|
|
||||||
}
|
|
||||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.pin.is_low())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::OutputPin for OutputOpenDrain<'_, P>
|
|
||||||
where
|
|
||||||
P: InputPin + OutputPin,
|
|
||||||
{
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
||||||
self.set_high();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
||||||
self.set_low();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::StatefulOutputPin for OutputOpenDrain<'_, P>
|
|
||||||
where
|
|
||||||
P: InputPin + OutputPin,
|
|
||||||
{
|
|
||||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.is_set_high())
|
|
||||||
}
|
|
||||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.is_set_low())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::ToggleableOutputPin for OutputOpenDrain<'_, P>
|
|
||||||
where
|
|
||||||
P: InputPin + OutputPin,
|
|
||||||
{
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn toggle(&mut self) -> Result<(), Self::Error> {
|
|
||||||
self.toggle();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::InputPin for Flex<'_, P>
|
|
||||||
where
|
|
||||||
P: InputPin + OutputPin,
|
|
||||||
{
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.is_high())
|
|
||||||
}
|
|
||||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.is_low())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::OutputPin for Flex<'_, P>
|
|
||||||
where
|
|
||||||
P: InputPin + OutputPin,
|
|
||||||
{
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
||||||
self.pin.set_output_high(true, private::Internal);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
||||||
self.pin.set_output_high(false, private::Internal);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::StatefulOutputPin for Flex<'_, P>
|
|
||||||
where
|
|
||||||
P: InputPin + OutputPin,
|
|
||||||
{
|
|
||||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.is_set_high())
|
|
||||||
}
|
|
||||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.is_set_low())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> digital::ToggleableOutputPin for Flex<'_, P>
|
|
||||||
where
|
|
||||||
P: InputPin + OutputPin,
|
|
||||||
{
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn toggle(&mut self) -> Result<(), Self::Error> {
|
|
||||||
self.toggle();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod embedded_hal_impls {
|
mod embedded_hal_impls {
|
||||||
use embedded_hal::digital;
|
use embedded_hal::digital;
|
||||||
|
|
||||||
|
|||||||
@ -85,25 +85,6 @@ impl crate::peripheral::Peripheral for NoPin {
|
|||||||
|
|
||||||
impl private::Sealed for NoPin {}
|
impl private::Sealed for NoPin {}
|
||||||
|
|
||||||
impl embedded_hal_02::digital::v2::OutputPin for NoPin {
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl embedded_hal_02::digital::v2::StatefulOutputPin for NoPin {
|
|
||||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl embedded_hal::digital::ErrorType for NoPin {
|
impl embedded_hal::digital::ErrorType for NoPin {
|
||||||
type Error = core::convert::Infallible;
|
type Error = core::convert::Infallible;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,8 +9,7 @@
|
|||||||
//!
|
//!
|
||||||
//! The I2C driver implements a number of third-party traits, with the
|
//! The I2C driver implements a number of third-party traits, with the
|
||||||
//! intention of making the HAL inter-compatible with various device drivers
|
//! intention of making the HAL inter-compatible with various device drivers
|
||||||
//! from the community. This includes the [`embedded-hal`] for both 0.2.x and
|
//! from the community, including the [`embedded-hal`].
|
||||||
//! 1.0.x versions.
|
|
||||||
//!
|
//!
|
||||||
//! ## Examples
|
//! ## Examples
|
||||||
//!
|
//!
|
||||||
@ -35,7 +34,7 @@
|
|||||||
//! }
|
//! }
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
//! [`embedded-hal`]: https://crates.io/crates/embedded-hal
|
//! [`embedded-hal`]: https://docs.rs/embedded-hal/latest/embedded_hal/index.html
|
||||||
|
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
#[cfg(not(esp32))]
|
#[cfg(not(esp32))]
|
||||||
@ -285,44 +284,6 @@ impl<T: Instance, DM: Mode> SetConfig for I2c<'_, DM, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> embedded_hal_02::blocking::i2c::Read for I2c<'_, Blocking, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
|
|
||||||
self.read(address, buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> embedded_hal_02::blocking::i2c::Write for I2c<'_, Blocking, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> {
|
|
||||||
self.write(addr, bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> embedded_hal_02::blocking::i2c::WriteRead for I2c<'_, Blocking, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn write_read(
|
|
||||||
&mut self,
|
|
||||||
address: u8,
|
|
||||||
bytes: &[u8],
|
|
||||||
buffer: &mut [u8],
|
|
||||||
) -> Result<(), Self::Error> {
|
|
||||||
self.write_read(address, bytes, buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, DM: Mode> embedded_hal::i2c::ErrorType for I2c<'_, DM, T> {
|
impl<T, DM: Mode> embedded_hal::i2c::ErrorType for I2c<'_, DM, T> {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,8 +127,8 @@
|
|||||||
//!
|
//!
|
||||||
//! [documentation]: https://docs.esp-rs.org/esp-hal
|
//! [documentation]: https://docs.esp-rs.org/esp-hal
|
||||||
//! [examples]: https://github.com/esp-rs/esp-hal/tree/main/examples
|
//! [examples]: https://github.com/esp-rs/esp-hal/tree/main/examples
|
||||||
//! [embedded-hal]: https://github.com/rust-embedded/embedded-hal/tree/master/embedded-hal
|
//! [embedded-hal]: https://docs.rs/embedded-hal/latest/embedded_hal/
|
||||||
//! [embedded-hal-async]: https://github.com/rust-embedded/embedded-hal/tree/master/embedded-hal-async
|
//! [embedded-hal-async]: https://docs.rs/embedded-hal-async/latest/embedded_hal_async/
|
||||||
//! [xtask]: https://github.com/matklad/cargo-xtask
|
//! [xtask]: https://github.com/matklad/cargo-xtask
|
||||||
//! [esp-generate]: https://github.com/esp-rs/esp-generate
|
//! [esp-generate]: https://github.com/esp-rs/esp-generate
|
||||||
//! [book]: https://docs.esp-rs.org/book/
|
//! [book]: https://docs.esp-rs.org/book/
|
||||||
|
|||||||
@ -421,39 +421,6 @@ impl<'d, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> PwmPin<'d, PWM, OP,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<PWM: PwmPeripheral, const OP: u8, const IS_A: bool> embedded_hal_02::PwmPin
|
|
||||||
for PwmPin<'_, PWM, OP, IS_A>
|
|
||||||
{
|
|
||||||
type Duty = u16;
|
|
||||||
|
|
||||||
/// This only set the timestamp to 0, if you want to disable the PwmPin,
|
|
||||||
/// it must be done on the timer itself.
|
|
||||||
fn disable(&mut self) {
|
|
||||||
self.set_timestamp(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This only set the timestamp to the maximum, if you want to disable the
|
|
||||||
/// PwmPin, it must be done on the timer itself.
|
|
||||||
fn enable(&mut self) {
|
|
||||||
self.set_timestamp(u16::MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the duty of the pin
|
|
||||||
fn get_duty(&self) -> Self::Duty {
|
|
||||||
self.timestamp()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the max duty of the pin
|
|
||||||
fn get_max_duty(&self) -> Self::Duty {
|
|
||||||
self.period()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the duty of the pin
|
|
||||||
fn set_duty(&mut self, duty: Self::Duty) {
|
|
||||||
self.set_timestamp(duty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implement no error type for the PwmPin because the method are infallible
|
/// Implement no error type for the PwmPin because the method are infallible
|
||||||
impl<PWM: PwmPeripheral, const OP: u8, const IS_A: bool> embedded_hal::pwm::ErrorType
|
impl<PWM: PwmPeripheral, const OP: u8, const IS_A: bool> embedded_hal::pwm::ErrorType
|
||||||
for PwmPin<'_, PWM, OP, IS_A>
|
for PwmPin<'_, PWM, OP, IS_A>
|
||||||
|
|||||||
@ -32,10 +32,7 @@
|
|||||||
//! method, which returns a 32-bit unsigned integer.
|
//! method, which returns a 32-bit unsigned integer.
|
||||||
//!
|
//!
|
||||||
//! ## Usage
|
//! ## Usage
|
||||||
//! This driver implements the [Read](embedded_hal_02::blocking::rng::Read)
|
//! The driver implements the traits from the [`rand_core`] crate.
|
||||||
//! trait from the `embedded_hal` crate, allowing you to generate random bytes
|
|
||||||
//! by calling the `read` method. The driver also implements the traits from the
|
|
||||||
//! [`rand_core`] crate.
|
|
||||||
//!
|
//!
|
||||||
//! [`rand_core`]: https://crates.io/crates/rand_core
|
//! [`rand_core`]: https://crates.io/crates/rand_core
|
||||||
//!
|
//!
|
||||||
@ -139,15 +136,6 @@ impl Rng {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl embedded_hal_02::blocking::rng::Read for Rng {
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
fn read(&mut self, buffer: &mut [u8]) -> Result<(), Self::Error> {
|
|
||||||
self.read(buffer);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl rand_core::RngCore for Rng {
|
impl rand_core::RngCore for Rng {
|
||||||
fn next_u32(&mut self) -> u32 {
|
fn next_u32(&mut self) -> u32 {
|
||||||
self.random()
|
self.random()
|
||||||
@ -229,15 +217,6 @@ impl Drop for Trng<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl embedded_hal_02::blocking::rng::Read for Trng<'_> {
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
/// Fills the provided buffer with random bytes.
|
|
||||||
fn read(&mut self, buffer: &mut [u8]) -> Result<(), Self::Error> {
|
|
||||||
self.rng.read(buffer);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implementing RngCore trait from rand_core for `Trng` structure
|
/// Implementing RngCore trait from rand_core for `Trng` structure
|
||||||
impl rand_core::RngCore for Trng<'_> {
|
impl rand_core::RngCore for Trng<'_> {
|
||||||
fn next_u32(&mut self) -> u32 {
|
fn next_u32(&mut self) -> u32 {
|
||||||
|
|||||||
@ -1095,29 +1095,6 @@ impl Rwdt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl embedded_hal_02::watchdog::WatchdogDisable for Rwdt {
|
|
||||||
fn disable(&mut self) {
|
|
||||||
self.disable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl embedded_hal_02::watchdog::WatchdogEnable for Rwdt {
|
|
||||||
type Time = MicrosDurationU64;
|
|
||||||
|
|
||||||
fn start<T>(&mut self, period: T)
|
|
||||||
where
|
|
||||||
T: Into<Self::Time>,
|
|
||||||
{
|
|
||||||
self.set_timeout(RwdtStage::Stage0, period.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl embedded_hal_02::watchdog::Watchdog for Rwdt {
|
|
||||||
fn feed(&mut self) {
|
|
||||||
self.feed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(esp32c2, esp32c3, esp32c6, esp32h2, esp32s3))]
|
#[cfg(any(esp32c2, esp32c3, esp32c6, esp32h2, esp32s3))]
|
||||||
/// Super Watchdog
|
/// Super Watchdog
|
||||||
pub struct Swd;
|
pub struct Swd;
|
||||||
@ -1172,13 +1149,6 @@ impl Default for Swd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(esp32c2, esp32c3, esp32c6, esp32h2, esp32s3))]
|
|
||||||
impl embedded_hal_02::watchdog::WatchdogDisable for Swd {
|
|
||||||
fn disable(&mut self) {
|
|
||||||
self.disable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return reset reason.
|
/// Return reset reason.
|
||||||
pub fn reset_reason(cpu: Cpu) -> Option<SocResetReason> {
|
pub fn reset_reason(cpu: Cpu) -> Option<SocResetReason> {
|
||||||
let reason = crate::rom::rtc_get_reset_reason(cpu as u32);
|
let reason = crate::rom::rtc_get_reset_reason(cpu as u32);
|
||||||
|
|||||||
@ -14,8 +14,6 @@
|
|||||||
//! If all you want to do is to communicate to a single device, and you initiate
|
//! If all you want to do is to communicate to a single device, and you initiate
|
||||||
//! transactions yourself, there are a number of ways to achieve this:
|
//! transactions yourself, there are a number of ways to achieve this:
|
||||||
//!
|
//!
|
||||||
//! - Use the [`FullDuplex`](embedded_hal_02::spi::FullDuplex) trait to
|
|
||||||
//! read/write single bytes at a time,
|
|
||||||
//! - Use the [`SpiBus`](embedded_hal::spi::SpiBus) trait and its associated
|
//! - Use the [`SpiBus`](embedded_hal::spi::SpiBus) trait and its associated
|
||||||
//! functions to initiate transactions with simultaneous reads and writes, or
|
//! functions to initiate transactions with simultaneous reads and writes, or
|
||||||
//! - Use the `ExclusiveDevice` struct from [`embedded-hal-bus`] or `SpiDevice`
|
//! - Use the `ExclusiveDevice` struct from [`embedded-hal-bus`] or `SpiDevice`
|
||||||
@ -30,8 +28,8 @@
|
|||||||
//!
|
//!
|
||||||
//! ## Usage
|
//! ## Usage
|
||||||
//!
|
//!
|
||||||
//! The module implements several third-party traits from embedded-hal@0.2.x,
|
//! The module implements several third-party traits from embedded-hal@1.x.x
|
||||||
//! embedded-hal@1.x.x and embassy-embedded-hal
|
//! and embassy-embedded-hal.
|
||||||
//!
|
//!
|
||||||
//! ## Examples
|
//! ## Examples
|
||||||
//!
|
//!
|
||||||
@ -806,44 +804,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M, T> embedded_hal_02::spi::FullDuplex<u8> for Spi<'_, M, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn read(&mut self) -> nb::Result<u8, Self::Error> {
|
|
||||||
self.read_byte()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send(&mut self, word: u8) -> nb::Result<(), Self::Error> {
|
|
||||||
self.write_byte(word)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<M, T> embedded_hal_02::blocking::spi::Transfer<u8> for Spi<'_, M, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
|
|
||||||
self.transfer(words)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<M, T> embedded_hal_02::blocking::spi::Write<u8> for Spi<'_, M, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
|
|
||||||
self.write_bytes(words)?;
|
|
||||||
self.driver().flush()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod dma {
|
mod dma {
|
||||||
use core::{
|
use core::{
|
||||||
cmp::min,
|
cmp::min,
|
||||||
@ -1805,30 +1765,6 @@ mod dma {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> embedded_hal_02::blocking::spi::Transfer<u8> for SpiDmaBus<'_, Blocking, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
|
|
||||||
self.transfer_in_place(words)?;
|
|
||||||
Ok(words)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> embedded_hal_02::blocking::spi::Write<u8> for SpiDmaBus<'_, Blocking, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
|
|
||||||
self.write(words)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Async functionality
|
/// Async functionality
|
||||||
mod asynch {
|
mod asynch {
|
||||||
use core::{
|
use core::{
|
||||||
@ -2773,7 +2709,7 @@ impl Info {
|
|||||||
|
|
||||||
// Wait for all chunks to complete except the last one.
|
// Wait for all chunks to complete except the last one.
|
||||||
// The function is allowed to return before the bus is idle.
|
// The function is allowed to return before the bus is idle.
|
||||||
// see [embedded-hal flushing](https://docs.rs/embedded-hal/1.0.0-alpha.8/embedded_hal/spi/blocking/index.html#flushing)
|
// see [embedded-hal flushing](https://docs.rs/embedded-hal/1.0.0/embedded_hal/spi/index.html#flushing)
|
||||||
if i < num_chunks {
|
if i < num_chunks {
|
||||||
self.flush()?;
|
self.flush()?;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -211,26 +211,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, UXX> embedded_hal_02::blocking::delay::DelayMs<UXX> for OneShotTimer<'_, T>
|
|
||||||
where
|
|
||||||
T: Timer,
|
|
||||||
UXX: Into<u32>,
|
|
||||||
{
|
|
||||||
fn delay_ms(&mut self, ms: UXX) {
|
|
||||||
self.delay_millis(ms.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, UXX> embedded_hal_02::blocking::delay::DelayUs<UXX> for OneShotTimer<'_, T>
|
|
||||||
where
|
|
||||||
T: Timer,
|
|
||||||
UXX: Into<u32>,
|
|
||||||
{
|
|
||||||
fn delay_us(&mut self, us: UXX) {
|
|
||||||
self.delay_micros(us.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> embedded_hal::delay::DelayNs for OneShotTimer<'_, T>
|
impl<T> embedded_hal::delay::DelayNs for OneShotTimer<'_, T>
|
||||||
where
|
where
|
||||||
T: Timer,
|
T: Timer,
|
||||||
@ -325,37 +305,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> embedded_hal_02::timer::CountDown for PeriodicTimer<'_, T>
|
|
||||||
where
|
|
||||||
T: Timer,
|
|
||||||
{
|
|
||||||
type Time = MicrosDurationU64;
|
|
||||||
|
|
||||||
fn start<Time>(&mut self, timeout: Time)
|
|
||||||
where
|
|
||||||
Time: Into<Self::Time>,
|
|
||||||
{
|
|
||||||
self.start(timeout.into()).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn wait(&mut self) -> nb::Result<(), void::Void> {
|
|
||||||
self.wait()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> embedded_hal_02::timer::Cancel for PeriodicTimer<'_, T>
|
|
||||||
where
|
|
||||||
T: Timer,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn cancel(&mut self) -> Result<(), Self::Error> {
|
|
||||||
self.cancel()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> embedded_hal_02::timer::Periodic for PeriodicTimer<'_, T> where T: Timer {}
|
|
||||||
|
|
||||||
/// An enum of all timer types
|
/// An enum of all timer types
|
||||||
enum AnyTimerInner {
|
enum AnyTimerInner {
|
||||||
/// Timer 0 of the TIMG0 peripheral in blocking mode.
|
/// Timer 0 of the TIMG0 peripheral in blocking mode.
|
||||||
|
|||||||
@ -746,39 +746,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TG> embedded_hal_02::watchdog::WatchdogDisable for Wdt<TG>
|
|
||||||
where
|
|
||||||
TG: TimerGroupInstance,
|
|
||||||
{
|
|
||||||
fn disable(&mut self) {
|
|
||||||
self.disable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<TG> embedded_hal_02::watchdog::WatchdogEnable for Wdt<TG>
|
|
||||||
where
|
|
||||||
TG: TimerGroupInstance,
|
|
||||||
{
|
|
||||||
type Time = MicrosDurationU64;
|
|
||||||
|
|
||||||
fn start<T>(&mut self, period: T)
|
|
||||||
where
|
|
||||||
T: Into<Self::Time>,
|
|
||||||
{
|
|
||||||
self.enable();
|
|
||||||
self.set_timeout(MwdtStage::Stage0, period.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<TG> embedded_hal_02::watchdog::Watchdog for Wdt<TG>
|
|
||||||
where
|
|
||||||
TG: TimerGroupInstance,
|
|
||||||
{
|
|
||||||
fn feed(&mut self) {
|
|
||||||
self.feed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Async functionality of the timer groups.
|
// Async functionality of the timer groups.
|
||||||
mod asynch {
|
mod asynch {
|
||||||
#![allow(unused)] // FIXME(mabez)
|
#![allow(unused)] // FIXME(mabez)
|
||||||
|
|||||||
@ -206,26 +206,6 @@ impl_display! {
|
|||||||
Other => "A different error occurred. The original error may contain more information",
|
Other => "A different error occurred. The original error may contain more information",
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ErrorKind> for embedded_hal_02::can::ErrorKind {
|
|
||||||
fn from(value: ErrorKind) -> Self {
|
|
||||||
match value {
|
|
||||||
ErrorKind::Overrun => embedded_hal_02::can::ErrorKind::Overrun,
|
|
||||||
ErrorKind::Bit => embedded_hal_02::can::ErrorKind::Bit,
|
|
||||||
ErrorKind::Stuff => embedded_hal_02::can::ErrorKind::Stuff,
|
|
||||||
ErrorKind::Crc => embedded_hal_02::can::ErrorKind::Crc,
|
|
||||||
ErrorKind::Form => embedded_hal_02::can::ErrorKind::Form,
|
|
||||||
ErrorKind::Acknowledge => embedded_hal_02::can::ErrorKind::Acknowledge,
|
|
||||||
ErrorKind::Other => embedded_hal_02::can::ErrorKind::Other,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl embedded_hal_02::can::Error for ErrorKind {
|
|
||||||
fn kind(&self) -> embedded_hal_02::can::ErrorKind {
|
|
||||||
(*self).into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ErrorKind> for embedded_can::ErrorKind {
|
impl From<ErrorKind> for embedded_can::ErrorKind {
|
||||||
fn from(value: ErrorKind) -> Self {
|
fn from(value: ErrorKind) -> Self {
|
||||||
match value {
|
match value {
|
||||||
@ -301,18 +281,6 @@ impl StandardId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<StandardId> for embedded_hal_02::can::StandardId {
|
|
||||||
fn from(value: StandardId) -> Self {
|
|
||||||
embedded_hal_02::can::StandardId::new(value.as_raw()).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<embedded_hal_02::can::StandardId> for StandardId {
|
|
||||||
fn from(value: embedded_hal_02::can::StandardId) -> Self {
|
|
||||||
StandardId::new(value.as_raw()).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<StandardId> for embedded_can::StandardId {
|
impl From<StandardId> for embedded_can::StandardId {
|
||||||
fn from(value: StandardId) -> Self {
|
fn from(value: StandardId) -> Self {
|
||||||
embedded_can::StandardId::new(value.as_raw()).unwrap()
|
embedded_can::StandardId::new(value.as_raw()).unwrap()
|
||||||
@ -373,18 +341,6 @@ impl ExtendedId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ExtendedId> for embedded_hal_02::can::ExtendedId {
|
|
||||||
fn from(value: ExtendedId) -> Self {
|
|
||||||
embedded_hal_02::can::ExtendedId::new(value.0).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<embedded_hal_02::can::ExtendedId> for ExtendedId {
|
|
||||||
fn from(value: embedded_hal_02::can::ExtendedId) -> Self {
|
|
||||||
ExtendedId::new(value.as_raw()).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ExtendedId> for embedded_can::ExtendedId {
|
impl From<ExtendedId> for embedded_can::ExtendedId {
|
||||||
fn from(value: ExtendedId) -> Self {
|
fn from(value: ExtendedId) -> Self {
|
||||||
embedded_can::ExtendedId::new(value.0).unwrap()
|
embedded_can::ExtendedId::new(value.0).unwrap()
|
||||||
@ -421,24 +377,6 @@ impl From<ExtendedId> for Id {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Id> for embedded_hal_02::can::Id {
|
|
||||||
fn from(value: Id) -> Self {
|
|
||||||
match value {
|
|
||||||
Id::Standard(id) => embedded_hal_02::can::Id::Standard(id.into()),
|
|
||||||
Id::Extended(id) => embedded_hal_02::can::Id::Extended(id.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<embedded_hal_02::can::Id> for Id {
|
|
||||||
fn from(value: embedded_hal_02::can::Id) -> Self {
|
|
||||||
match value {
|
|
||||||
embedded_hal_02::can::Id::Standard(id) => Id::Standard(id.into()),
|
|
||||||
embedded_hal_02::can::Id::Extended(id) => Id::Extended(id.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Id> for embedded_can::Id {
|
impl From<Id> for embedded_can::Id {
|
||||||
fn from(value: Id) -> Self {
|
fn from(value: Id) -> Self {
|
||||||
match value {
|
match value {
|
||||||
@ -457,7 +395,7 @@ impl From<embedded_can::Id> for Id {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Structure backing the embedded_hal_02::can::Frame/embedded_can::Frame trait.
|
/// Structure backing the `embedded_can::Frame` trait.
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub struct EspTwaiFrame {
|
pub struct EspTwaiFrame {
|
||||||
@ -549,41 +487,6 @@ impl EspTwaiFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl embedded_hal_02::can::Frame for EspTwaiFrame {
|
|
||||||
fn new(id: impl Into<embedded_hal_02::can::Id>, data: &[u8]) -> Option<Self> {
|
|
||||||
Self::new(id.into(), data)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_remote(id: impl Into<embedded_hal_02::can::Id>, dlc: usize) -> Option<Self> {
|
|
||||||
Self::new_remote(id.into(), dlc)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_extended(&self) -> bool {
|
|
||||||
matches!(self.id, Id::Extended(_))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_remote_frame(&self) -> bool {
|
|
||||||
self.is_remote
|
|
||||||
}
|
|
||||||
|
|
||||||
fn id(&self) -> embedded_hal_02::can::Id {
|
|
||||||
self.id.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn dlc(&self) -> usize {
|
|
||||||
self.dlc
|
|
||||||
}
|
|
||||||
|
|
||||||
fn data(&self) -> &[u8] {
|
|
||||||
// Remote frames do not contain data, yet have a value for the dlc so return
|
|
||||||
// an empty slice for remote frames.
|
|
||||||
match self.is_remote {
|
|
||||||
true => &[],
|
|
||||||
false => &self.data[0..self.dlc],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl embedded_can::Frame for EspTwaiFrame {
|
impl embedded_can::Frame for EspTwaiFrame {
|
||||||
fn new(id: impl Into<embedded_can::Id>, data: &[u8]) -> Option<Self> {
|
fn new(id: impl Into<embedded_can::Id>, data: &[u8]) -> Option<Self> {
|
||||||
Self::new(id.into(), data)
|
Self::new(id.into(), data)
|
||||||
@ -1374,16 +1277,6 @@ pub enum EspTwaiError {
|
|||||||
EmbeddedHAL(ErrorKind),
|
EmbeddedHAL(ErrorKind),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl embedded_hal_02::can::Error for EspTwaiError {
|
|
||||||
fn kind(&self) -> embedded_hal_02::can::ErrorKind {
|
|
||||||
if let Self::EmbeddedHAL(kind) = self {
|
|
||||||
(*kind).into()
|
|
||||||
} else {
|
|
||||||
embedded_hal_02::can::ErrorKind::Other
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl embedded_can::Error for EspTwaiError {
|
impl embedded_can::Error for EspTwaiError {
|
||||||
fn kind(&self) -> embedded_can::ErrorKind {
|
fn kind(&self) -> embedded_can::ErrorKind {
|
||||||
if let Self::EmbeddedHAL(kind) = self {
|
if let Self::EmbeddedHAL(kind) = self {
|
||||||
@ -1426,30 +1319,6 @@ unsafe fn copy_to_data_register(dest: *mut u32, src: &[u8]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DM, T> embedded_hal_02::can::Can for Twai<'_, DM, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
DM: crate::Mode,
|
|
||||||
{
|
|
||||||
type Frame = EspTwaiFrame;
|
|
||||||
type Error = EspTwaiError;
|
|
||||||
|
|
||||||
/// Transmit a frame.
|
|
||||||
fn transmit(&mut self, frame: &Self::Frame) -> nb::Result<Option<Self::Frame>, Self::Error> {
|
|
||||||
self.tx.transmit(frame)?;
|
|
||||||
|
|
||||||
// Success in readying packet for transmit. No packets can be replaced in the
|
|
||||||
// transmit buffer so return None in accordance with the
|
|
||||||
// embedded-can/embedded-hal trait.
|
|
||||||
nb::Result::Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return a received frame if there are any available.
|
|
||||||
fn receive(&mut self) -> nb::Result<Self::Frame, Self::Error> {
|
|
||||||
self.rx.receive()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<DM, T> embedded_can::nb::Can for Twai<'_, DM, T>
|
impl<DM, T> embedded_can::nb::Can for Twai<'_, DM, T>
|
||||||
where
|
where
|
||||||
T: Instance,
|
T: Instance,
|
||||||
|
|||||||
@ -1434,62 +1434,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, M> embedded_hal_02::serial::Write<u8> for Uart<'_, M, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
M: Mode,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
|
|
||||||
self.tx.write(word)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flush(&mut self) -> nb::Result<(), Self::Error> {
|
|
||||||
self.tx.flush()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, M> embedded_hal_02::serial::Write<u8> for UartTx<'_, M, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
M: Mode,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
|
|
||||||
self.write_byte(word)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flush(&mut self) -> nb::Result<(), Self::Error> {
|
|
||||||
self.flush_tx()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, M> embedded_hal_02::serial::Read<u8> for Uart<'_, M, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
M: Mode,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn read(&mut self) -> nb::Result<u8, Self::Error> {
|
|
||||||
self.rx.read()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, M> embedded_hal_02::serial::Read<u8> for UartRx<'_, M, T>
|
|
||||||
where
|
|
||||||
T: Instance,
|
|
||||||
M: Mode,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn read(&mut self) -> nb::Result<u8, Self::Error> {
|
|
||||||
self.read_byte()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, M> embedded_hal_nb::serial::ErrorType for Uart<'_, M, T> {
|
impl<T, M> embedded_hal_nb::serial::ErrorType for Uart<'_, M, T> {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -539,58 +539,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M> embedded_hal_02::serial::Read<u8> for UsbSerialJtag<'_, M>
|
|
||||||
where
|
|
||||||
M: Mode,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn read(&mut self) -> nb::Result<u8, Self::Error> {
|
|
||||||
embedded_hal_02::serial::Read::read(&mut self.rx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<M> embedded_hal_02::serial::Read<u8> for UsbSerialJtagRx<'_, M>
|
|
||||||
where
|
|
||||||
M: Mode,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn read(&mut self) -> nb::Result<u8, Self::Error> {
|
|
||||||
self.read_byte()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<M> embedded_hal_02::serial::Write<u8> for UsbSerialJtag<'_, M>
|
|
||||||
where
|
|
||||||
M: Mode,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
|
|
||||||
embedded_hal_02::serial::Write::write(&mut self.tx, word)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flush(&mut self) -> nb::Result<(), Self::Error> {
|
|
||||||
embedded_hal_02::serial::Write::flush(&mut self.tx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<M> embedded_hal_02::serial::Write<u8> for UsbSerialJtagTx<'_, M>
|
|
||||||
where
|
|
||||||
M: Mode,
|
|
||||||
{
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
|
|
||||||
self.write_byte_nb(word)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flush(&mut self) -> nb::Result<(), Self::Error> {
|
|
||||||
self.flush_tx_nb()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<M> embedded_hal_nb::serial::ErrorType for UsbSerialJtag<'_, M>
|
impl<M> embedded_hal_nb::serial::ErrorType for UsbSerialJtag<'_, M>
|
||||||
where
|
where
|
||||||
M: Mode,
|
M: Mode,
|
||||||
|
|||||||
@ -188,9 +188,9 @@ embassy-futures = "0.1.1"
|
|||||||
embassy-sync = "0.6.0"
|
embassy-sync = "0.6.0"
|
||||||
embassy-time = "0.3.2"
|
embassy-time = "0.3.2"
|
||||||
embedded-hal = "1.0.0"
|
embedded-hal = "1.0.0"
|
||||||
embedded-hal-02 = { version = "0.2.7", package = "embedded-hal", features = ["unproven"] }
|
embedded-can = "0.4.1"
|
||||||
embedded-hal-async = "1.0.0"
|
embedded-hal-async = "1.0.0"
|
||||||
embedded-hal-nb = { version = "1.0.0", optional = true }
|
embedded-hal-nb = "1.0.0"
|
||||||
esp-alloc = { path = "../esp-alloc", optional = true }
|
esp-alloc = { path = "../esp-alloc", optional = true }
|
||||||
esp-backtrace = { path = "../esp-backtrace", default-features = false, features = ["exception-handler", "defmt", "semihosting"] }
|
esp-backtrace = { path = "../esp-backtrace", default-features = false, features = ["exception-handler", "defmt", "semihosting"] }
|
||||||
esp-hal = { path = "../esp-hal", features = ["digest"], optional = true }
|
esp-hal = { path = "../esp-hal", features = ["digest"], optional = true }
|
||||||
|
|||||||
@ -146,7 +146,7 @@ mod tests {
|
|||||||
|
|
||||||
fn set<T>(pin: &mut T, state: bool)
|
fn set<T>(pin: &mut T, state: bool)
|
||||||
where
|
where
|
||||||
T: embedded_hal_02::digital::v2::OutputPin,
|
T: embedded_hal::digital::OutputPin,
|
||||||
{
|
{
|
||||||
if state {
|
if state {
|
||||||
pin.set_high().ok();
|
pin.set_high().ok();
|
||||||
@ -157,7 +157,7 @@ mod tests {
|
|||||||
|
|
||||||
fn toggle<T>(pin: &mut T)
|
fn toggle<T>(pin: &mut T)
|
||||||
where
|
where
|
||||||
T: embedded_hal_02::digital::v2::ToggleableOutputPin,
|
T: embedded_hal::digital::StatefulOutputPin,
|
||||||
{
|
{
|
||||||
pin.toggle().ok();
|
pin.toggle().ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use embedded_hal_02::can::Frame;
|
use embedded_can::Frame;
|
||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
twai::{self, filter::SingleStandardFilter, EspTwaiFrame, StandardId, TwaiMode},
|
twai::{self, filter::SingleStandardFilter, EspTwaiFrame, StandardId, TwaiMode},
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use embedded_hal_02::serial::{Read, Write};
|
use embedded_hal_nb::serial::{Read, Write};
|
||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
uart::{self, ClockSource, Uart},
|
uart::{self, ClockSource, Uart},
|
||||||
|
|||||||
@ -17,7 +17,7 @@ esp-hal = { path = "../esp-hal" }
|
|||||||
esp-hal-embassy = { path = "../esp-hal-embassy" }
|
esp-hal-embassy = { path = "../esp-hal-embassy" }
|
||||||
esp-println = { path = "../esp-println", features = ["log"] }
|
esp-println = { path = "../esp-println", features = ["log"] }
|
||||||
lis3dh-async = "0.9.3"
|
lis3dh-async = "0.9.3"
|
||||||
ssd1306 = "0.8.4"
|
ssd1306 = "0.9.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
esp32 = ["esp-backtrace/esp32", "esp-hal/esp32", "esp-hal-embassy/esp32", "esp-println/esp32"]
|
esp32 = ["esp-backtrace/esp32", "esp-hal/esp32", "esp-hal-embassy/esp32", "esp-println/esp32"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user