Remove OutputOpenDrain (#3029)

* Remove OutputOpenDrain

* Remove input-related functions from Output

* Fix documentation

* Improve docs
This commit is contained in:
Dániel Buga 2025-01-27 17:41:58 +01:00 committed by GitHub
parent 6495130492
commit ce750b5fe4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 343 additions and 580 deletions

View File

@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- SPI: Added support for 3-wire SPI (#2919) - SPI: Added support for 3-wire SPI (#2919)
- Add separate config for Rx and Tx (UART) #2965 - UART: Add separate config for Rx and Tx (#2965)
### Changed ### Changed
@ -25,12 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Rng` and `Trng` now implement `Peripheral<P = Self>` (#2992) - `Rng` and `Trng` now implement `Peripheral<P = Self>` (#2992)
- SPI, UART, I2C: `with_<pin>` functions of peripheral drivers now disconnect the previously assigned pins from the peripheral. (#3012) - SPI, UART, I2C: `with_<pin>` functions of peripheral drivers now disconnect the previously assigned pins from the peripheral. (#3012)
- SPI, UART, I2C: Dropping a driver now disconnects pins from their peripherals. (#3012) - SPI, UART, I2C: Dropping a driver now disconnects pins from their peripherals. (#3012)
- `Async` drivers are no longer `Send` (#2980) - `Async` drivers are no longer `Send` (#2980)
- GPIO drivers now take configuration structs, and their constructors are fallible (#2990) - GPIO drivers now take configuration structs (#2990, #3029)
- `flip-link` feature is now a config option
- `flip-link` feature is now a config option (`ESP_HAL_CONFIG_FLIP_LINK`)
- `flip-link` feature is now a config option (`ESP_HAL_CONFIG_FLIP_LINK`) (#3001) - `flip-link` feature is now a config option (`ESP_HAL_CONFIG_FLIP_LINK`) (#3001)
- Removed features `psram-quad` and `psram-octal` - replaced by `psram` and the `ESP_HAL_CONFIG_PSRAM_MODE` (`quad`/`octal`) (#3001) - Removed features `psram-quad` and `psram-octal` - replaced by `psram` and the `ESP_HAL_CONFIG_PSRAM_MODE` (`quad`/`octal`) (#3001)
@ -44,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed ### Removed
- Removed `Pin`, `RtcPin` and `RtcPinWithResistors` implementations from `Flex` (#2938) - Removed `Pin`, `RtcPin` and `RtcPinWithResistors` implementations from `Flex` (#2938)
- OutputOpenDrain has been removed (#3029)
## [0.23.1] - 2025-01-15 ## [0.23.1] - 2025-01-15

View File

@ -177,15 +177,26 @@ config/config.toml
## GPIO changes ## GPIO changes
GPIO drivers now take configuration structs, and their constructors are fallible. GPIO drivers now take configuration structs.
```diff ```diff
- Input::new(peripherals.GPIO0, Pull::Up); - Input::new(peripherals.GPIO0, Pull::Up);
+ Input::new(peripherals.GPIO0, InputConfig::default().with_pull(Pull::Up)).unwrap(); + Input::new(peripherals.GPIO0, InputConfig::default().with_pull_direction(Pull::Up));
- Output::new(peripherals.GPIO0, Level::Low); - Output::new(peripherals.GPIO0, Level::Low);
+ Output::new(peripherals.GPIO0, OutputConfig::default().with_level(Level::Low)).unwrap(); + Output::new(peripherals.GPIO0, Level::Low, OutputConfig::default());
- OutputOpenDrain::new(peripherals.GPIO0, Level::Low, Pull::Up); ```
+ OutputOpenDrain::new(
+ peripherals.GPIO0, The OutputOpenDrain driver has been removed. You can use `Output` instead with
+ OutputOpenDrainConfig::default().with_level(Level::Low).with_pull(Pull::Up) `DriveMode::OpenDrain`. The input-related methods of `OutputOpenDrain` (`level`,
+ ).unwrap(); `is_high`, `is_low`) are available through the (unstable) `Flex` driver.
```diff
- OutputOpenDrain::new(peripherals.GPIO0, Level::Low);
+ Output::new(
peripherals.GPIO0,
Level::Low,
OutputConfig::default()
.with_drive_mode(DriveMode::OpenDrain),
);
```

View File

@ -17,12 +17,15 @@
//! (such as SPI, UART, I2C, etc.), or can be [`GpioPin::split`] //! (such as SPI, UART, I2C, etc.), or can be [`GpioPin::split`]
//! into peripheral signals for advanced use. //! into peripheral signals for advanced use.
//! //!
//! Pin drivers can be created using [`Flex::new`], [`Input::new`], //! Pin drivers can be created using [`Flex::new`], [`Input::new`] and
//! [`Output::new`] and [`OutputOpenDrain::new`]. //! [`Output::new`].
//! //!
//! Each pin is a different type initially. Internally, `esp-hal` will often //! Output pins can be configured to either push-pull or open-drain (active low)
//! erase their types automatically, but they can also be converted into //! mode, with configurable drive strength and pull-up/pull-down resistors.
//! [`AnyPin`] manually by calling [`Pin::degrade`]. //!
//! Each pin is a different type initially. Internally, `esp-hal` will erase
//! their types automatically, but they can also be converted into [`AnyPin`]
//! manually by calling [`Pin::degrade`].
//! //!
//! The [`Io`] struct can also be used to configure the interrupt handler for //! The [`Io`] struct can also be used to configure the interrupt handler for
//! GPIO interrupts. For more information, see the //! GPIO interrupts. For more information, see the
@ -253,12 +256,6 @@ impl From<Level> for bool {
} }
} }
/// A configuration error.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum ConfigError {}
/// Errors that can occur when configuring a pin to be a wakeup source. /// Errors that can occur when configuring a pin to be a wakeup source.
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)] #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
@ -285,7 +282,7 @@ impl Display for WakeConfigError {
impl core::error::Error for WakeConfigError {} impl core::error::Error for WakeConfigError {}
/// Pull setting for an input. /// Pull setting for a GPIO.
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)] #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Pull { pub enum Pull {
@ -427,12 +424,14 @@ pub trait Pin: Sealed {
/// let [red, blue] = pins; /// let [red, blue] = pins;
/// let mut red = Output::new( /// let mut red = Output::new(
/// red, /// red,
/// OutputConfig::default().with_level(Level::High) /// Level::High,
/// ).unwrap(); /// OutputConfig::default(),
/// );
/// let mut blue = Output::new( /// let mut blue = Output::new(
/// blue, /// blue,
/// OutputConfig::default().with_level(Level::Low) /// Level::Low,
/// ).unwrap(); /// OutputConfig::default(),
/// );
/// ///
/// loop { /// loop {
/// red.toggle(); /// red.toggle();
@ -1075,26 +1074,59 @@ macro_rules! gpio {
}; };
} }
/// The drive mode of the output pin.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DriveMode {
/// Push-pull output.
///
/// The driver actively sets the output voltage level for both high and low
/// logical [`Level`]s.
PushPull,
/// Open drain output.
///
/// The driver actively pulls the output voltage level low for the low
/// logical [`Level`], but leaves the high level floating, which is then
/// determined by external hardware, or internal pull-up/pull-down
/// resistors.
OpenDrain,
}
/// Output pin configuration. /// Output pin configuration.
///
/// This struct is used to configure the drive mode, drive strength, and pull
/// direction of an output pin. By default, the configuration is set to:
/// - Drive mode: [`DriveMode::PushPull`]
/// - Drive strength: [`DriveStrength::_20mA`]
/// - Pull direction: [`Pull::None`] (no pull resistors connected)
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, procmacros::BuilderLite)] #[derive(Debug, Clone, Copy, PartialEq, Eq, procmacros::BuilderLite)]
#[non_exhaustive] #[non_exhaustive]
pub struct OutputConfig { pub struct OutputConfig {
/// Initial output level of the pin. /// Output drive mode.
pub level: Level, pub drive_mode: DriveMode,
/// Pin drive strength.
pub drive_strength: DriveStrength,
/// Pin pull direction.
pub pull: Pull,
} }
impl Default for OutputConfig { impl Default for OutputConfig {
fn default() -> Self { fn default() -> Self {
Self { level: Level::Low } Self {
drive_mode: DriveMode::PushPull,
drive_strength: DriveStrength::_20mA,
pull: Pull::None,
}
} }
} }
/// Push-pull digital output. /// Push-pull digital output.
/// ///
/// This driver configures the GPIO pin to be a push-pull output driver. /// This driver configures the GPIO pin to be an output driver.
/// Push-pull means that the driver actively sets the output voltage level
/// for both high and low logical [`Level`]s.
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Output<'d> { pub struct Output<'d> {
@ -1113,7 +1145,9 @@ impl<'d> Peripheral for Output<'d> {
impl<'d> Output<'d> { impl<'d> Output<'d> {
/// Creates a new GPIO output driver. /// Creates a new GPIO output driver.
/// ///
/// The `initial_output` parameter sets the initial output level of the pin. /// The `initial_level` parameter sets the initial output level of the pin.
/// The `config` parameter sets the drive mode, drive strength, and pull
/// direction of the pin.
/// ///
/// ## Example /// ## Example
/// ///
@ -1132,8 +1166,8 @@ impl<'d> Output<'d> {
/// led.set_high(); /// led.set_high();
/// } /// }
/// ///
/// let config = OutputConfig::default().with_level(Level::High); /// let config = OutputConfig::default();
/// let mut led = Output::new(peripherals.GPIO5, config).unwrap(); /// let mut led = Output::new(peripherals.GPIO5, Level::High, config);
/// let mut delay = Delay::new(); /// let mut delay = Delay::new();
/// ///
/// blink_once(&mut led, &mut delay); /// blink_once(&mut led, &mut delay);
@ -1142,14 +1176,18 @@ impl<'d> Output<'d> {
#[inline] #[inline]
pub fn new( pub fn new(
pin: impl Peripheral<P = impl OutputPin> + 'd, pin: impl Peripheral<P = impl OutputPin> + 'd,
initial_level: Level,
config: OutputConfig, config: OutputConfig,
) -> Result<Self, ConfigError> { ) -> Self {
let mut pin = Flex::new(pin); // Set up the pin
let mut this = Self {
pin: Flex::new(pin),
};
this.set_level(initial_level);
this.apply_config(&config);
this.pin.pin.enable_output(true);
pin.set_level(config.level); this
pin.set_as_output();
Ok(Self { pin })
} }
/// Split the pin into an input and output signal. /// Split the pin into an input and output signal.
@ -1159,8 +1197,8 @@ impl<'d> Output<'d> {
/// ```rust, no_run /// ```rust, no_run
#[doc = crate::before_snippet!()] #[doc = crate::before_snippet!()]
/// # use esp_hal::gpio::{Output, OutputConfig, Level}; /// # use esp_hal::gpio::{Output, OutputConfig, Level};
/// let config = OutputConfig::default().with_level(Level::High); /// # let config = OutputConfig::default();
/// let pin1 = Output::new(peripherals.GPIO1, config).unwrap(); /// let pin1 = Output::new(peripherals.GPIO1, Level::High, config);
/// let (input, output) = pin1.split(); /// let (input, output) = pin1.split();
/// # } /// # }
/// ``` /// ```
@ -1177,10 +1215,10 @@ impl<'d> Output<'d> {
/// ```rust, no_run /// ```rust, no_run
#[doc = crate::before_snippet!()] #[doc = crate::before_snippet!()]
/// # use esp_hal::gpio::{Output, OutputConfig, Level}; /// # use esp_hal::gpio::{Output, OutputConfig, Level};
/// let config = OutputConfig::default().with_level(Level::High); /// # let config = OutputConfig::default();
/// let pin1_gpio = Output::new(peripherals.GPIO1, config).unwrap(); /// let pin1_gpio = Output::new(peripherals.GPIO1, Level::High, config);
/// // Can be passed as an input. /// // Can be passed as an input.
/// let pin1 = pin1_gpio.peripheral_input(); /// let input = pin1_gpio.peripheral_input();
/// # } /// # }
/// ``` /// ```
#[inline] #[inline]
@ -1197,9 +1235,9 @@ impl<'d> Output<'d> {
/// ```rust, no_run /// ```rust, no_run
#[doc = crate::before_snippet!()] #[doc = crate::before_snippet!()]
/// # use esp_hal::gpio::{Output, OutputConfig, Level}; /// # use esp_hal::gpio::{Output, OutputConfig, Level};
/// let config = OutputConfig::default().with_level(Level::High); /// # let config = OutputConfig::default();
/// let pin1_gpio = Output::new(peripherals.GPIO1, config).unwrap(); /// let pin1_gpio = Output::new(peripherals.GPIO1, Level::High, config);
/// let pin1 = pin1_gpio.into_peripheral_output(); /// let output = pin1_gpio.into_peripheral_output();
/// # } /// # }
/// ``` /// ```
#[inline] #[inline]
@ -1209,9 +1247,9 @@ impl<'d> Output<'d> {
} }
/// Change the configuration. /// Change the configuration.
pub fn apply_config(&mut self, config: &OutputConfig) -> Result<(), ConfigError> { #[inline]
self.set_level(config.level); pub fn apply_config(&mut self, config: &OutputConfig) {
Ok(()) self.pin.apply_output_config(config)
} }
/// Set the output as high. /// Set the output as high.
@ -1232,34 +1270,47 @@ impl<'d> Output<'d> {
self.pin.set_level(level) self.pin.set_level(level)
} }
/// Is the output pin set as high? /// Returns whether the pin is set to high level.
///
/// This function reads back the value set using `set_level`, `set_high` or
/// `set_low`. It does not need the input stage to be enabled.
#[inline] #[inline]
pub fn is_set_high(&self) -> bool { pub fn is_set_high(&self) -> bool {
self.output_level() == Level::High self.output_level() == Level::High
} }
/// Is the output pin set as low? /// Returns whether the pin is set to low level.
///
/// This function reads back the value set using `set_level`, `set_high` or
/// `set_low`. It does not need the input stage to be enabled.
#[inline] #[inline]
pub fn is_set_low(&self) -> bool { pub fn is_set_low(&self) -> bool {
self.output_level() == Level::Low self.output_level() == Level::Low
} }
/// What level output is set to /// Returns which level the pin is set to.
///
/// This function reads back the value set using `set_level`, `set_high` or
/// `set_low`. It does not need the input stage to be enabled.
#[inline] #[inline]
pub fn output_level(&self) -> Level { pub fn output_level(&self) -> Level {
self.pin.output_level() self.pin.output_level()
} }
/// Toggle pin output /// Toggles the pin output.
///
/// If the pin was previously set to high, it will be set to low, and vice
/// versa.
#[inline] #[inline]
pub fn toggle(&mut self) { pub fn toggle(&mut self) {
self.pin.toggle(); self.pin.toggle();
} }
/// Configure the [DriveStrength] of the pin /// Converts the pin driver into a [`Flex`] driver.
#[inline] #[inline]
pub fn set_drive_strength(&mut self, strength: DriveStrength) { #[instability::unstable]
self.pin.set_drive_strength(strength); pub fn into_flex(self) -> Flex<'d> {
self.pin
} }
} }
@ -1327,22 +1378,21 @@ impl<'d> Input<'d> {
/// } /// }
/// ///
/// let config = InputConfig::default().with_pull(Pull::Up); /// let config = InputConfig::default().with_pull(Pull::Up);
/// let mut button = Input::new(peripherals.GPIO5, config).unwrap(); /// let mut button = Input::new(peripherals.GPIO5, config);
/// let mut delay = Delay::new(); /// let mut delay = Delay::new();
/// ///
/// print_when_pressed(&mut button, &mut delay); /// print_when_pressed(&mut button, &mut delay);
/// # } /// # }
/// ``` /// ```
#[inline] #[inline]
pub fn new( pub fn new(pin: impl Peripheral<P = impl InputPin> + 'd, config: InputConfig) -> Self {
pin: impl Peripheral<P = impl InputPin> + 'd,
config: InputConfig,
) -> Result<Self, ConfigError> {
let mut pin = Flex::new(pin); let mut pin = Flex::new(pin);
pin.set_as_input(config.pull); pin.pin.enable_output(false);
pin.enable_input(true);
pin.apply_input_config(&config);
Ok(Self { pin }) Self { pin }
} }
/// Returns a peripheral [input][interconnect::InputSignal] connected to /// Returns a peripheral [input][interconnect::InputSignal] connected to
@ -1353,7 +1403,7 @@ impl<'d> Input<'d> {
#[doc = crate::before_snippet!()] #[doc = crate::before_snippet!()]
/// # use esp_hal::gpio::{Input, InputConfig, Pull}; /// # use esp_hal::gpio::{Input, InputConfig, Pull};
/// let config = InputConfig::default().with_pull(Pull::Up); /// let config = InputConfig::default().with_pull(Pull::Up);
/// let pin1_gpio = Input::new(peripherals.GPIO1, config).unwrap(); /// let pin1_gpio = Input::new(peripherals.GPIO1, config);
/// let pin1 = pin1_gpio.peripheral_input(); /// let pin1 = pin1_gpio.peripheral_input();
/// # } /// # }
/// ``` /// ```
@ -1382,9 +1432,8 @@ impl<'d> Input<'d> {
} }
/// Change the configuration. /// Change the configuration.
pub fn apply_config(&mut self, config: &InputConfig) -> Result<(), ConfigError> { pub fn apply_config(&mut self, config: &InputConfig) {
self.pin.set_as_input(config.pull); self.pin.apply_input_config(config)
Ok(())
} }
/// Listen for interrupts. /// Listen for interrupts.
@ -1413,7 +1462,7 @@ impl<'d> Input<'d> {
/// // This example uses a push button that is high when not /// // This example uses a push button that is high when not
/// // pressed and low when pressed. /// // pressed and low when pressed.
/// let config = InputConfig::default().with_pull(Pull::Up); /// let config = InputConfig::default().with_pull(Pull::Up);
/// let mut button = Input::new(peripherals.GPIO5, config).unwrap(); /// let mut button = Input::new(peripherals.GPIO5, config);
/// ///
/// critical_section::with(|cs| { /// critical_section::with(|cs| {
/// // Here we are listening for a low level to demonstrate /// // Here we are listening for a low level to demonstrate
@ -1501,7 +1550,7 @@ impl<'d> Input<'d> {
#[doc = crate::before_snippet!()] #[doc = crate::before_snippet!()]
/// # use esp_hal::gpio::{Input, InputConfig, Pull}; /// # use esp_hal::gpio::{Input, InputConfig, Pull};
/// let config = InputConfig::default().with_pull(Pull::Up); /// let config = InputConfig::default().with_pull(Pull::Up);
/// let pin1 = Input::new(peripherals.GPIO1, config).unwrap(); /// let pin1 = Input::new(peripherals.GPIO1, config);
/// let (input, output) = pin1.split(); /// let (input, output) = pin1.split();
/// # } /// # }
/// ``` /// ```
@ -1520,7 +1569,7 @@ impl<'d> Input<'d> {
#[doc = crate::before_snippet!()] #[doc = crate::before_snippet!()]
/// # use esp_hal::gpio::{Input, InputConfig, Pull}; /// # use esp_hal::gpio::{Input, InputConfig, Pull};
/// let config = InputConfig::default().with_pull(Pull::Up); /// let config = InputConfig::default().with_pull(Pull::Up);
/// let pin1_gpio = Input::new(peripherals.GPIO1, config).unwrap(); /// let pin1_gpio = Input::new(peripherals.GPIO1, config);
/// // Can be passed as an output. /// // Can be passed as an output.
/// let pin1 = pin1_gpio.into_peripheral_output(); /// let pin1 = pin1_gpio.into_peripheral_output();
/// # } /// # }
@ -1530,263 +1579,12 @@ impl<'d> Input<'d> {
pub fn into_peripheral_output(self) -> interconnect::OutputSignal { pub fn into_peripheral_output(self) -> interconnect::OutputSignal {
self.pin.into_peripheral_output() self.pin.into_peripheral_output()
} }
}
/// Open-drain output pin configuration. /// Converts the pin driver into a [`Flex`] driver.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, procmacros::BuilderLite)]
#[non_exhaustive]
pub struct OutputOpenDrainConfig {
/// Initial output level of the pin.
pub level: Level,
/// Initial pull of the pin.
pub pull: Pull,
}
impl Default for OutputOpenDrainConfig {
fn default() -> Self {
Self {
level: Level::Low,
pull: Pull::None,
}
}
}
/// Open drain digital output.
///
/// This driver configures the GPIO pin to be an open drain output driver.
/// Open drain means that the driver actively pulls the output voltage level low
/// for the low logical [`Level`], but leaves the high level floating, which is
/// then determined by external hardware, or internal pull-up/pull-down
/// resistors.
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct OutputOpenDrain<'d> {
pin: Flex<'d>,
}
impl private::Sealed for OutputOpenDrain<'_> {}
impl<'d> Peripheral for OutputOpenDrain<'d> {
type P = Flex<'d>;
unsafe fn clone_unchecked(&self) -> Self::P {
self.pin.clone_unchecked()
}
}
impl<'d> OutputOpenDrain<'d> {
/// Creates a new GPIO output driver.
///
/// The `initial_output` parameter sets the initial output level of the pin.
/// The `pull` parameter configures internal pull-up or pull-down
/// resistors.
///
/// ## Example
///
/// The following example configures `GPIO5` to pulse a LED once. The
/// example assumes that the LED is connected such that it is on when
/// the pin is low.
///
/// ```rust, no_run
#[doc = crate::before_snippet!()]
/// use esp_hal::gpio::{
/// Level, OutputOpenDrain, OutputOpenDrainConfig, Pull,
/// };
/// use esp_hal::delay::Delay;
///
/// fn blink_once(led: &mut OutputOpenDrain<'_>, delay: &mut Delay) {
/// led.set_low();
/// delay.delay_millis(500);
/// led.set_high();
/// }
///
/// let config = OutputOpenDrainConfig::default()
/// .with_level(Level::High)
/// .with_pull(Pull::Up);
/// let mut led = OutputOpenDrain::new(peripherals.GPIO5, config).unwrap();
/// let mut delay = Delay::new();
///
/// blink_once(&mut led, &mut delay);
/// # }
/// ```
#[inline]
pub fn new(
pin: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
config: OutputOpenDrainConfig,
) -> Result<Self, ConfigError> {
let mut pin = Flex::new(pin);
pin.set_level(config.level);
pin.set_as_open_drain(config.pull);
Ok(Self { pin })
}
/// Change the configuration.
pub fn apply_config(&mut self, config: &OutputOpenDrainConfig) -> Result<(), ConfigError> {
self.set_level(config.level);
self.pin.set_as_open_drain(config.pull);
Ok(())
}
/// Split the pin into an input and output signal.
///
/// Peripheral signals allow connecting peripherals together without using
/// external hardware.
/// ```rust, no_run
#[doc = crate::before_snippet!()]
/// # use esp_hal::gpio::{OutputOpenDrain, OutputOpenDrainConfig, Level, Pull};
/// let config = OutputOpenDrainConfig::default()
/// .with_level(Level::High)
/// .with_pull(Pull::Up);
/// let pin1 = OutputOpenDrain::new(
/// peripherals.GPIO1,
/// config,
/// ).unwrap();
/// let (input, output) = pin1.split();
/// # }
/// ```
#[inline] #[inline]
#[instability::unstable] #[instability::unstable]
pub fn split(self) -> (interconnect::InputSignal, interconnect::OutputSignal) { pub fn into_flex(self) -> Flex<'d> {
self.pin.split() self.pin
}
/// Returns a peripheral [input][interconnect::InputSignal] connected to
/// this pin.
///
/// The input signal can be passed to peripherals in place of an input pin.
/// ```rust, no_run
#[doc = crate::before_snippet!()]
/// # use esp_hal::gpio::{OutputOpenDrain, OutputOpenDrainConfig, Level, Pull};
/// let config = OutputOpenDrainConfig::default()
/// .with_level(Level::High)
/// .with_pull(Pull::Up);
/// let pin1_gpio = OutputOpenDrain::new(
/// peripherals.GPIO1,
/// config,
/// ).unwrap();
/// // Can be passed as an input.
/// let pin1 = pin1_gpio.peripheral_input();
/// # }
/// ```
#[inline]
#[instability::unstable]
pub fn peripheral_input(&self) -> interconnect::InputSignal {
self.pin.peripheral_input()
}
/// Turns the pin object into a peripheral
/// [output][interconnect::OutputSignal].
///
/// The output signal can be passed to peripherals in place of an output
/// pin.
/// ```rust, no_run
#[doc = crate::before_snippet!()]
/// # use esp_hal::gpio::{OutputOpenDrain, OutputOpenDrainConfig, Level, Pull};
/// let config = OutputOpenDrainConfig::default()
/// .with_level(Level::High)
/// .with_pull(Pull::Up);
/// let pin1_gpio = OutputOpenDrain::new(
/// peripherals.GPIO1,
/// config,
/// ).unwrap();
/// // Can be passed as an input.
/// let pin1 = pin1_gpio.into_peripheral_output();
/// # }
/// ```
#[inline]
#[instability::unstable]
pub fn into_peripheral_output(self) -> interconnect::OutputSignal {
self.pin.into_peripheral_output()
}
/// Get whether the pin input level is high.
#[inline]
pub fn is_high(&self) -> bool {
self.level() == Level::High
}
/// Get whether the pin input level is low.
#[inline]
pub fn is_low(&self) -> bool {
self.level() == Level::Low
}
/// Get the current pin input level.
#[inline]
pub fn level(&self) -> Level {
self.pin.level()
}
/// Listen for interrupts.
///
/// See [`Input::listen`] for more information and an example.
#[inline]
#[instability::unstable]
pub fn listen(&mut self, event: Event) {
self.pin.listen(event);
}
/// Stop listening for interrupts.
#[inline]
#[instability::unstable]
pub fn unlisten(&mut self) {
self.pin.unlisten();
}
/// Clear the interrupt status bit for this Pin
#[inline]
#[instability::unstable]
pub fn clear_interrupt(&mut self) {
self.pin.clear_interrupt();
}
/// Set the output as high.
#[inline]
pub fn set_high(&mut self) {
self.set_level(Level::High);
}
/// Set the output as low.
#[inline]
pub fn set_low(&mut self) {
self.set_level(Level::Low);
}
/// Set the output level.
#[inline]
pub fn set_level(&mut self, level: Level) {
self.pin.set_level(level);
}
/// Is the output pin set as high?
#[inline]
pub fn is_set_high(&self) -> bool {
self.output_level() == Level::High
}
/// Is the output pin set as low?
#[inline]
pub fn is_set_low(&self) -> bool {
self.output_level() == Level::Low
}
/// What level output is set to
#[inline]
pub fn output_level(&self) -> Level {
self.pin.output_level()
}
/// Toggle pin output
#[inline]
pub fn toggle(&mut self) {
self.pin.toggle()
}
/// Configure the [DriveStrength] of the pin
pub fn set_drive_strength(&mut self, strength: DriveStrength) {
self.pin.set_drive_strength(strength);
} }
} }
@ -1817,6 +1615,21 @@ impl<'d> Flex<'d> {
#[instability::unstable] #[instability::unstable]
pub fn new(pin: impl Peripheral<P = impl Into<AnyPin>> + 'd) -> Self { pub fn new(pin: impl Peripheral<P = impl Into<AnyPin>> + 'd) -> Self {
crate::into_mapped_ref!(pin); crate::into_mapped_ref!(pin);
#[cfg(usb_device)]
disable_usb_pads(pin.number());
GPIO::regs()
.func_out_sel_cfg(pin.number() as usize)
.modify(|_, w| unsafe { w.out_sel().bits(OutputSignal::GPIO as OutputSignalType) });
// Use RMW to not overwrite sleep configuration
io_mux_reg(pin.number()).modify(|_, w| unsafe {
w.mcu_sel().bits(GPIO_FUNCTION as u8);
w.fun_ie().clear_bit();
w.slp_sel().clear_bit()
});
Self { pin } Self { pin }
} }
@ -1842,14 +1655,6 @@ impl<'d> Flex<'d> {
unsafe { AnyPin::steal(self.number()) }.split().0 unsafe { AnyPin::steal(self.number()) }.split().0
} }
/// Set the GPIO to input mode.
#[inline]
#[instability::unstable]
pub fn set_as_input(&mut self, pull: Pull) {
self.pin.init_input(pull);
self.pin.enable_output(false);
}
/// Get whether the pin input level is high. /// Get whether the pin input level is high.
#[inline] #[inline]
#[instability::unstable] #[instability::unstable]
@ -2019,6 +1824,50 @@ impl<'d> Flex<'d> {
self.pin.pull_direction(pull); self.pin.pull_direction(pull);
} }
/// Configure pullup/pulldown resistors.
#[inline]
#[instability::unstable]
pub fn pull_direction(&mut self, pull: Pull) {
self.pin.pull_direction(pull);
}
/// Enable or disable the GPIO pin input buffer.
#[inline]
#[instability::unstable]
pub fn enable_input(&mut self, enable_input: bool) {
self.pin.enable_input(enable_input);
}
/// Applies the given output configuration to the pin.
#[inline]
#[instability::unstable]
pub fn apply_output_config(&mut self, config: &OutputConfig) {
let pull_up = config.pull == Pull::Up;
let pull_down = config.pull == Pull::Down;
#[cfg(esp32)]
crate::soc::gpio::errata36(AnyPin(self.pin.0), pull_up, pull_down);
io_mux_reg(self.number()).modify(|_, w| {
unsafe { w.fun_drv().bits(config.drive_strength as u8) };
w.fun_wpu().bit(pull_up);
w.fun_wpd().bit(pull_down);
w
});
GPIO::regs().pin(self.number() as usize).modify(|_, w| {
w.pad_driver()
.bit(config.drive_mode == DriveMode::OpenDrain)
});
}
/// Applies the given input configuration to the pin.
#[inline]
#[instability::unstable]
pub fn apply_input_config(&mut self, config: &InputConfig) {
self.pin.pull_direction(config.pull);
}
/// Split the pin into an input and output signal. /// Split the pin into an input and output signal.
/// ///
/// Peripheral signals allow connecting peripherals together without using /// Peripheral signals allow connecting peripherals together without using
@ -2337,7 +2186,9 @@ mod asynch {
// We construct the Future first, because its `Drop` implementation // We construct the Future first, because its `Drop` implementation
// is load-bearing if `wait_for` is dropped during the initialization. // is load-bearing if `wait_for` is dropped during the initialization.
let mut future = PinFuture { let mut future = PinFuture {
pin: Flex::new(unsafe { self.pin.clone_unchecked() }), pin: Flex {
pin: unsafe { self.pin.clone_unchecked() },
},
}; };
// Make sure this pin is not being processed by an interrupt handler. // Make sure this pin is not being processed by an interrupt handler.
@ -2585,42 +2436,6 @@ mod embedded_hal_impls {
} }
} }
impl digital::InputPin for OutputOpenDrain<'_> {
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok(Self::is_high(self))
}
fn is_low(&mut self) -> Result<bool, Self::Error> {
Ok(Self::is_low(self))
}
}
impl digital::ErrorType for OutputOpenDrain<'_> {
type Error = core::convert::Infallible;
}
impl digital::OutputPin for OutputOpenDrain<'_> {
fn set_low(&mut self) -> Result<(), Self::Error> {
Self::set_low(self);
Ok(())
}
fn set_high(&mut self) -> Result<(), Self::Error> {
Self::set_high(self);
Ok(())
}
}
impl digital::StatefulOutputPin for OutputOpenDrain<'_> {
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok(Self::is_set_high(self))
}
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
Ok(Self::is_set_low(self))
}
}
#[instability::unstable] #[instability::unstable]
impl digital::InputPin for Flex<'_> { impl digital::InputPin for Flex<'_> {
fn is_high(&mut self) -> Result<bool, Self::Error> { fn is_high(&mut self) -> Result<bool, Self::Error> {

View File

@ -80,8 +80,7 @@
//! let peripherals = esp_hal::init(config); //! let peripherals = esp_hal::init(config);
//! //!
//! // Set GPIO0 as an output, and set its state high initially. //! // Set GPIO0 as an output, and set its state high initially.
//! let config = OutputConfig::default().with_level(Level::High); //! let mut led = Output::new(peripherals.GPIO0, Level::High, OutputConfig::default());
//! let mut led = Output::new(peripherals.GPIO0, config).unwrap();
//! //!
//! let delay = Delay::new(); //! let delay = Delay::new();
//! //!

View File

@ -39,8 +39,8 @@
//! // Set up channels with control and edge signals //! // Set up channels with control and edge signals
//! let ch0 = &u0.channel0; //! let ch0 = &u0.channel0;
//! let config = InputConfig::default().with_pull(Pull::Up); //! let config = InputConfig::default().with_pull(Pull::Up);
//! let pin_a = Input::new(peripherals.GPIO4, config).unwrap(); //! let pin_a = Input::new(peripherals.GPIO4, config);
//! let pin_b = Input::new(peripherals.GPIO5, config).unwrap(); //! let pin_b = Input::new(peripherals.GPIO5, config);
//! let (input_a, _) = pin_a.split(); //! let (input_a, _) = pin_a.split();
//! let (input_b, _) = pin_b.split(); //! let (input_b, _) = pin_b.split();
//! ch0.set_ctrl_signal(input_a.clone()); //! ch0.set_ctrl_signal(input_a.clone());

View File

@ -118,8 +118,11 @@
//! //!
//! const WIDTH: usize = 80; //! const WIDTH: usize = 80;
//! //!
//! let config = OutputConfig::default().with_level(Level::Low); //! let mut out = Output::new(
//! let mut out = Output::new(peripherals.GPIO5, config).unwrap(); //! peripherals.GPIO5,
//! Level::Low,
//! OutputConfig::default(),
//! );
//! //!
//! // Configure frequency based on chip type //! // Configure frequency based on chip type
#![cfg_attr(esp32h2, doc = "let freq = 32.MHz();")] #![cfg_attr(esp32h2, doc = "let freq = 32.MHz();")]

View File

@ -112,7 +112,7 @@ pub enum Error {
/// ///
/// let config = InputConfig::default().with_pull(Pull::None); /// let config = InputConfig::default().with_pull(Pull::None);
/// let mut pin_4 = peripherals.GPIO4; /// let mut pin_4 = peripherals.GPIO4;
/// let pin_4_input = Input::new(&mut pin_4, config).unwrap(); /// let pin_4_input = Input::new(&mut pin_4, config);
/// ///
/// let reason = /// let reason =
/// reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); /// reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);
@ -167,7 +167,7 @@ impl<'a, P: RtcIoWakeupPinType> Ext0WakeupSource<'a, P> {
/// let config = InputConfig::default().with_pull(Pull::None); /// let config = InputConfig::default().with_pull(Pull::None);
/// let mut pin_2 = peripherals.GPIO2; /// let mut pin_2 = peripherals.GPIO2;
/// let mut pin_4 = peripherals.GPIO4; /// let mut pin_4 = peripherals.GPIO4;
/// let pin_4_driver = Input::new(&mut pin_4, config).unwrap(); /// let pin_4_driver = Input::new(&mut pin_4, config);
/// ///
/// let reason = reset_reason(Cpu::ProCpu) /// let reason = reset_reason(Cpu::ProCpu)
/// .unwrap_or(SocResetReason::ChipPowerOn); /// .unwrap_or(SocResetReason::ChipPowerOn);
@ -224,7 +224,7 @@ impl<'a, 'b> Ext1WakeupSource<'a, 'b> {
/// let config = InputConfig::default().with_pull(Pull::None); /// let config = InputConfig::default().with_pull(Pull::None);
/// let mut pin2 = peripherals.GPIO2; /// let mut pin2 = peripherals.GPIO2;
/// let mut pin3 = peripherals.GPIO3; /// let mut pin3 = peripherals.GPIO3;
/// let mut pin2_input = Input::new(&mut pin2, config).unwrap(); /// let mut pin2_input = Input::new(&mut pin2, config);
/// ///
/// let reason = /// let reason =
/// reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); /// reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);

View File

@ -63,8 +63,7 @@ async fn main(_spawner: Spawner) {
static LED_CTRL: StaticCell<Signal<CriticalSectionRawMutex, bool>> = StaticCell::new(); static LED_CTRL: StaticCell<Signal<CriticalSectionRawMutex, bool>> = StaticCell::new();
let led_ctrl_signal = &*LED_CTRL.init(Signal::new()); let led_ctrl_signal = &*LED_CTRL.init(Signal::new());
let config = OutputConfig::default().with_level(Level::Low); let led = Output::new(peripherals.GPIO0, Level::Low, OutputConfig::default());
let led = Output::new(peripherals.GPIO0, config).unwrap();
let _guard = cpu_control let _guard = cpu_control
.start_app_core(unsafe { &mut *addr_of_mut!(APP_CORE_STACK) }, move || { .start_app_core(unsafe { &mut *addr_of_mut!(APP_CORE_STACK) }, move || {

View File

@ -85,8 +85,7 @@ fn main() -> ! {
static LED_CTRL: StaticCell<Signal<CriticalSectionRawMutex, bool>> = StaticCell::new(); static LED_CTRL: StaticCell<Signal<CriticalSectionRawMutex, bool>> = StaticCell::new();
let led_ctrl_signal = &*LED_CTRL.init(Signal::new()); let led_ctrl_signal = &*LED_CTRL.init(Signal::new());
let config = OutputConfig::default().with_level(Level::Low); let led = Output::new(peripherals.GPIO0, Level::Low, OutputConfig::default());
let led = Output::new(peripherals.GPIO0, config).unwrap();
static EXECUTOR_CORE_1: StaticCell<InterruptExecutor<1>> = StaticCell::new(); static EXECUTOR_CORE_1: StaticCell<InterruptExecutor<1>> = StaticCell::new();
let executor_core1 = InterruptExecutor::new(sw_ints.software_interrupt1); let executor_core1 = InterruptExecutor::new(sw_ints.software_interrupt1);

View File

@ -68,13 +68,11 @@ async fn main(spawner: Spawner) {
} }
spawner spawner
.spawn(signal_task( .spawn(signal_task(Output::new(
Output::new( peripherals.GPIO5,
peripherals.GPIO5, Level::Low,
OutputConfig::default().with_level(Level::Low), OutputConfig::default(),
) )))
.unwrap(),
))
.unwrap(); .unwrap();
let mut data: [u32; 48] = [PulseCode::empty(); 48]; let mut data: [u32; 48] = [PulseCode::empty(); 48];

View File

@ -31,8 +31,7 @@ use esp_hal::{
fn main() -> ! { fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let config = OutputConfig::default().with_level(Level::Low); let mut led = Output::new(peripherals.GPIO2, Level::Low, OutputConfig::default());
let mut led = Output::new(peripherals.GPIO2, config).unwrap();
led.set_high(); led.set_high();
let syst = SystemTimer::new(peripherals.SYSTIMER); let syst = SystemTimer::new(peripherals.SYSTIMER);

View File

@ -35,8 +35,7 @@ fn main() -> ! {
let mut io = Io::new(peripherals.IO_MUX); let mut io = Io::new(peripherals.IO_MUX);
io.set_interrupt_handler(handler); io.set_interrupt_handler(handler);
let config = OutputConfig::default().with_level(Level::Low); let mut led = Output::new(peripherals.GPIO2, Level::Low, OutputConfig::default());
let mut led = Output::new(peripherals.GPIO2, config).unwrap();
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] { if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] {
@ -47,7 +46,7 @@ fn main() -> ! {
} }
let config = InputConfig::default().with_pull(Pull::Up); let config = InputConfig::default().with_pull(Pull::Up);
let mut button = Input::new(button, config).unwrap(); let mut button = Input::new(button, config);
critical_section::with(|cs| { critical_section::with(|cs| {
button.listen(Event::FallingEdge); button.listen(Event::FallingEdge);

View File

@ -44,26 +44,13 @@ use esp_println::println;
fn main() -> ! { fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let mut master_sclk = Output::new( let mut master_sclk = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
peripherals.GPIO4,
OutputConfig::default().with_level(Level::Low),
)
.unwrap();
let master_miso = Input::new( let master_miso = Input::new(
peripherals.GPIO5, peripherals.GPIO5,
InputConfig::default().with_pull(Pull::None), InputConfig::default().with_pull(Pull::None),
) );
.unwrap(); let mut master_mosi = Output::new(peripherals.GPIO8, Level::Low, OutputConfig::default());
let mut master_mosi = Output::new( let mut master_cs = Output::new(peripherals.GPIO9, Level::Low, OutputConfig::default());
peripherals.GPIO8,
OutputConfig::default().with_level(Level::Low),
)
.unwrap();
let mut master_cs = Output::new(
peripherals.GPIO9,
OutputConfig::default().with_level(Level::High),
)
.unwrap();
let slave_sclk = peripherals.GPIO0; let slave_sclk = peripherals.GPIO0;
let slave_miso = peripherals.GPIO1; let slave_miso = peripherals.GPIO1;

View File

@ -55,9 +55,9 @@ fn main() -> ! {
let config = InputConfig::default().with_pull(Pull::Down); let config = InputConfig::default().with_pull(Pull::Down);
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] { if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] {
let button = Input::new(peripherals.GPIO0, config).unwrap(); let button = Input::new(peripherals.GPIO0, config);
} else { } else {
let button = Input::new(peripherals.GPIO9, config).unwrap(); let button = Input::new(peripherals.GPIO9, config);
} }
} }

View File

@ -70,9 +70,9 @@ async fn main(_spawner: Spawner) -> ! {
let config = InputConfig::default().with_pull(Pull::Down); let config = InputConfig::default().with_pull(Pull::Down);
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] { if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] {
let button = Input::new(peripherals.GPIO0, config).unwrap(); let button = Input::new(peripherals.GPIO0, config);
} else { } else {
let button = Input::new(peripherals.GPIO9, config).unwrap(); let button = Input::new(peripherals.GPIO9, config);
} }
} }

View File

@ -19,7 +19,7 @@ use esp_hal::gpio::{AnyPin, Input, InputConfig, Level, Output, OutputConfig, Pin
use esp_hal::{ use esp_hal::{
// OutputOpenDrain is here because will be unused otherwise // OutputOpenDrain is here because will be unused otherwise
delay::Delay, delay::Delay,
gpio::{Event, Flex, Io, OutputOpenDrain, OutputOpenDrainConfig}, gpio::{DriveMode, Event, Flex, Io},
handler, handler,
timer::timg::TimerGroup, timer::timg::TimerGroup,
}; };
@ -93,10 +93,8 @@ mod tests {
test_gpio2, test_gpio2,
.. ..
} = ctx; } = ctx;
let mut test_gpio1 = let mut test_gpio1 = Input::new(test_gpio1, InputConfig::default().with_pull(Pull::Down));
Input::new(test_gpio1, InputConfig::default().with_pull(Pull::Down)).unwrap(); let mut test_gpio2 = Output::new(test_gpio2, Level::Low, OutputConfig::default());
let mut test_gpio2 =
Output::new(test_gpio2, OutputConfig::default().with_level(Level::Low)).unwrap();
embassy_futures::select::select( embassy_futures::select::select(
async { async {
loop { loop {
@ -119,8 +117,7 @@ mod tests {
#[test] #[test]
async fn a_pin_can_wait(ctx: Context) { async fn a_pin_can_wait(ctx: Context) {
let mut first = let mut first = Input::new(ctx.test_gpio1, InputConfig::default().with_pull(Pull::Down));
Input::new(ctx.test_gpio1, InputConfig::default().with_pull(Pull::Down)).unwrap();
embassy_futures::select::select( embassy_futures::select::select(
first.wait_for_rising_edge(), first.wait_for_rising_edge(),
@ -133,8 +130,7 @@ mod tests {
#[test] #[test]
fn gpio_input(ctx: Context) { fn gpio_input(ctx: Context) {
let test_gpio1 = let test_gpio1 = Input::new(ctx.test_gpio1, InputConfig::default().with_pull(Pull::Down));
Input::new(ctx.test_gpio1, InputConfig::default().with_pull(Pull::Down)).unwrap();
// `InputPin`: // `InputPin`:
assert_eq!(test_gpio1.is_low(), true); assert_eq!(test_gpio1.is_low(), true);
assert_eq!(test_gpio1.is_high(), false); assert_eq!(test_gpio1.is_high(), false);
@ -143,23 +139,15 @@ mod tests {
#[test] #[test]
async fn waiting_for_level_does_not_hang(ctx: Context) { async fn waiting_for_level_does_not_hang(ctx: Context) {
let mut test_gpio1 = let mut test_gpio1 =
Input::new(ctx.test_gpio1, InputConfig::default().with_pull(Pull::Down)).unwrap(); Input::new(ctx.test_gpio1, InputConfig::default().with_pull(Pull::Down));
let _test_gpio2 = Output::new( let _test_gpio2 = Output::new(ctx.test_gpio2, Level::High, OutputConfig::default());
ctx.test_gpio2,
OutputConfig::default().with_level(Level::High),
)
.unwrap();
test_gpio1.wait_for_high().await; test_gpio1.wait_for_high().await;
} }
#[test] #[test]
fn gpio_output(ctx: Context) { fn gpio_output(ctx: Context) {
let mut test_gpio2 = Output::new( let mut test_gpio2 = Output::new(ctx.test_gpio2, Level::Low, OutputConfig::default());
ctx.test_gpio2,
OutputConfig::default().with_level(Level::Low),
)
.unwrap();
// `StatefulOutputPin`: // `StatefulOutputPin`:
assert_eq!(test_gpio2.is_set_low(), true); assert_eq!(test_gpio2.is_set_low(), true);
@ -179,13 +167,8 @@ mod tests {
#[test] #[test]
fn gpio_output_embedded_hal_1_0(ctx: Context) { fn gpio_output_embedded_hal_1_0(ctx: Context) {
let test_gpio1 = let test_gpio1 = Input::new(ctx.test_gpio1, InputConfig::default().with_pull(Pull::Down));
Input::new(ctx.test_gpio1, InputConfig::default().with_pull(Pull::Down)).unwrap(); let mut test_gpio2 = Output::new(ctx.test_gpio2, Level::Low, OutputConfig::default());
let mut test_gpio2 = Output::new(
ctx.test_gpio2,
OutputConfig::default().with_level(Level::Low),
)
.unwrap();
fn set<T>(pin: &mut T, state: bool) fn set<T>(pin: &mut T, state: bool)
where where
@ -233,12 +216,8 @@ mod tests {
#[cfg(feature = "unstable")] // Interrupts are unstable #[cfg(feature = "unstable")] // Interrupts are unstable
fn gpio_interrupt(ctx: Context) { fn gpio_interrupt(ctx: Context) {
let mut test_gpio1 = let mut test_gpio1 =
Input::new(ctx.test_gpio1, InputConfig::default().with_pull(Pull::Down)).unwrap(); Input::new(ctx.test_gpio1, InputConfig::default().with_pull(Pull::Down));
let mut test_gpio2 = Output::new( let mut test_gpio2 = Output::new(ctx.test_gpio2, Level::Low, OutputConfig::default());
ctx.test_gpio2,
OutputConfig::default().with_level(Level::Low),
)
.unwrap();
critical_section::with(|cs| { critical_section::with(|cs| {
*COUNTER.borrow_ref_mut(cs) = 0; *COUNTER.borrow_ref_mut(cs) = 0;
@ -275,51 +254,54 @@ mod tests {
#[test] #[test]
#[cfg(feature = "unstable")] // delay is unstable #[cfg(feature = "unstable")] // delay is unstable
fn gpio_od(ctx: Context) { fn gpio_od(ctx: Context) {
let config = OutputOpenDrainConfig::default() let input_pull_up = InputConfig::default().with_pull(Pull::Up);
.with_level(Level::High) let input_pull_down = InputConfig::default().with_pull(Pull::Down);
.with_pull(Pull::Up); let input_no_pull = InputConfig::default().with_pull(Pull::None);
let mut test_gpio1 = OutputOpenDrain::new(ctx.test_gpio1, config).unwrap();
let mut test_gpio2 = OutputOpenDrain::new(ctx.test_gpio2, config).unwrap(); let mut output = Output::new(
ctx.test_gpio1,
Level::High,
OutputConfig::default()
.with_drive_mode(DriveMode::OpenDrain)
.with_pull(Pull::None),
);
let mut input = Input::new(ctx.test_gpio2, input_pull_up);
ctx.delay.delay_millis(1); ctx.delay.delay_millis(1);
assert_eq!(test_gpio1.is_high(), true); // With pull up resistor
assert_eq!(test_gpio2.is_high(), true);
test_gpio1.set_low(); assert_eq!(input.level(), Level::High);
test_gpio2.set_high(); output.set_low();
ctx.delay.delay_millis(1); ctx.delay.delay_millis(1);
assert_eq!(input.level(), Level::Low);
assert_eq!(test_gpio1.is_low(), true); output.set_high();
assert_eq!(test_gpio2.is_low(), true);
test_gpio1.set_high();
test_gpio2.set_high();
ctx.delay.delay_millis(1); ctx.delay.delay_millis(1);
assert_eq!(input.level(), Level::High);
assert_eq!(test_gpio1.is_high(), true); // With pull down resistor
assert_eq!(test_gpio2.is_high(), true); input.apply_config(&input_pull_down);
test_gpio1.set_high(); output.set_high();
test_gpio2.set_low();
ctx.delay.delay_millis(1); ctx.delay.delay_millis(1);
assert_eq!(input.level(), Level::Low);
assert_eq!(test_gpio1.is_low(), true); output.set_low();
assert_eq!(test_gpio2.is_low(), true);
test_gpio1.set_high();
test_gpio2.set_high();
ctx.delay.delay_millis(1); ctx.delay.delay_millis(1);
assert_eq!(input.level(), Level::Low);
assert_eq!(test_gpio1.is_high(), true); // With pull up on output
assert_eq!(test_gpio2.is_high(), true); input.apply_config(&input_no_pull);
output.apply_config(
&OutputConfig::default()
.with_drive_mode(DriveMode::OpenDrain)
.with_pull(Pull::Up),
);
test_gpio1.set_low();
test_gpio2.set_low();
ctx.delay.delay_millis(1); ctx.delay.delay_millis(1);
assert_eq!(input.level(), Level::Low);
assert_eq!(test_gpio1.is_low(), true); output.set_high();
assert_eq!(test_gpio2.is_low(), true); ctx.delay.delay_millis(1);
assert_eq!(input.level(), Level::High);
} }
#[test] #[test]
@ -330,7 +312,7 @@ mod tests {
test_gpio1.set_high(); test_gpio1.set_high();
test_gpio1.set_as_output(); test_gpio1.set_as_output();
test_gpio2.set_as_input(Pull::None); test_gpio2.enable_input(true);
ctx.delay.delay_millis(1); ctx.delay.delay_millis(1);
@ -343,7 +325,7 @@ mod tests {
assert_eq!(test_gpio1.is_set_high(), false); assert_eq!(test_gpio1.is_set_high(), false);
assert_eq!(test_gpio2.is_high(), false); assert_eq!(test_gpio2.is_high(), false);
test_gpio1.set_as_input(Pull::None); test_gpio1.enable_input(true);
test_gpio2.set_as_output(); test_gpio2.set_as_output();
ctx.delay.delay_millis(1); ctx.delay.delay_millis(1);
@ -370,9 +352,8 @@ mod tests {
let any_pin2 = ctx.test_gpio1; let any_pin2 = ctx.test_gpio1;
let any_pin3 = ctx.test_gpio2; let any_pin3 = ctx.test_gpio2;
let out_pin = let out_pin = Output::new(any_pin2, Level::High, OutputConfig::default());
Output::new(any_pin2, OutputConfig::default().with_level(Level::High)).unwrap(); let in_pin = Input::new(any_pin3, InputConfig::default().with_pull(Pull::Down));
let in_pin = Input::new(any_pin3, InputConfig::default().with_pull(Pull::Down)).unwrap();
assert_eq!(out_pin.is_set_high(), true); assert_eq!(out_pin.is_set_high(), true);
assert_eq!(in_pin.is_high(), true); assert_eq!(in_pin.is_high(), true);
@ -385,9 +366,8 @@ mod tests {
let any_pin2 = ctx.test_gpio1; let any_pin2 = ctx.test_gpio1;
let any_pin3 = ctx.test_gpio2; let any_pin3 = ctx.test_gpio2;
let out_pin = let out_pin = Output::new(any_pin3, Level::Low, OutputConfig::default());
Output::new(any_pin3, OutputConfig::default().with_level(Level::Low)).unwrap(); let in_pin = Input::new(any_pin2, InputConfig::default().with_pull(Pull::Down));
let in_pin = Input::new(any_pin2, InputConfig::default().with_pull(Pull::Down)).unwrap();
assert_eq!(out_pin.is_set_high(), false); assert_eq!(out_pin.is_set_high(), false);
assert_eq!(in_pin.is_high(), false); assert_eq!(in_pin.is_high(), false);
@ -398,7 +378,7 @@ mod tests {
fn can_configure_rtcio_pins_as_input() { fn can_configure_rtcio_pins_as_input() {
let pin = unsafe { esp_hal::gpio::GpioPin::<37>::steal() }; let pin = unsafe { esp_hal::gpio::GpioPin::<37>::steal() };
_ = Input::new(pin, InputConfig::default().with_pull(Pull::Down)).unwrap(); _ = Input::new(pin, InputConfig::default().with_pull(Pull::Down));
} }
#[test] #[test]
@ -419,7 +399,7 @@ mod tests {
#[embassy_executor::task] #[embassy_executor::task]
async fn test_task(pin: AnyPin) { async fn test_task(pin: AnyPin) {
let mut pin = Input::new(pin, InputConfig::default().with_pull(Pull::Down)).unwrap(); let mut pin = Input::new(pin, InputConfig::default().with_pull(Pull::Down));
// This line must return, even if the executor // This line must return, even if the executor
// is running at a higher priority than the GPIO handler. // is running at a higher priority than the GPIO handler.

View File

@ -41,10 +41,8 @@ pub fn interrupt_handler() {
async fn drive_pins(gpio1: impl Into<AnyPin>, gpio2: impl Into<AnyPin>) -> usize { async fn drive_pins(gpio1: impl Into<AnyPin>, gpio2: impl Into<AnyPin>) -> usize {
let counter = AtomicUsize::new(0); let counter = AtomicUsize::new(0);
let mut test_gpio1 = let mut test_gpio1 = Input::new(gpio1.into(), InputConfig::default().with_pull(Pull::Down));
Input::new(gpio1.into(), InputConfig::default().with_pull(Pull::Down)).unwrap(); let mut test_gpio2 = Output::new(gpio2.into(), Level::Low, OutputConfig::default());
let mut test_gpio2 =
Output::new(gpio2.into(), OutputConfig::default().with_level(Level::Low)).unwrap();
embassy_futures::select::select( embassy_futures::select::select(
async { async {
loop { loop {

View File

@ -7,16 +7,10 @@
#![no_main] #![no_main]
use esp_hal::{ use esp_hal::{
delay::Delay, gpio::NoPin,
dma_buffers, i2s::parallel::{I2sParallel, TxSixteenBits},
gpio::{AnyPin, NoPin, Pin},
i2s::{
master::{DataFormat, I2s, I2sTx, Standard},
parallel::{I2sParallel, TxSixteenBits},
},
peripherals::I2S0, peripherals::I2S0,
time::RateExtU32, time::RateExtU32,
Async,
}; };
use hil_test as _; use hil_test as _;

View File

@ -47,14 +47,14 @@ mod tests {
let unit = ctx.pcnt.unit0; let unit = ctx.pcnt.unit0;
// Setup channel 0 to increment the count when gpio2 does LOW -> HIGH // Setup channel 0 to increment the count when gpio2 does LOW -> HIGH
unit.channel0.set_edge_signal( unit.channel0.set_edge_signal(Input::new(
Input::new(ctx.input, InputConfig::default().with_pull(Pull::Down)).unwrap(), ctx.input,
); InputConfig::default().with_pull(Pull::Down),
));
unit.channel0 unit.channel0
.set_input_mode(EdgeMode::Hold, EdgeMode::Increment); .set_input_mode(EdgeMode::Hold, EdgeMode::Increment);
let mut output = let mut output = Output::new(ctx.output, Level::Low, OutputConfig::default());
Output::new(ctx.output, OutputConfig::default().with_level(Level::Low)).unwrap();
unit.resume(); unit.resume();
@ -86,14 +86,14 @@ mod tests {
let unit = ctx.pcnt.unit1; let unit = ctx.pcnt.unit1;
// Setup channel 0 to increment the count when gpio2 does LOW -> HIGH // Setup channel 0 to increment the count when gpio2 does LOW -> HIGH
unit.channel0.set_edge_signal( unit.channel0.set_edge_signal(Input::new(
Input::new(ctx.input, InputConfig::default().with_pull(Pull::Up)).unwrap(), ctx.input,
); InputConfig::default().with_pull(Pull::Up),
));
unit.channel0 unit.channel0
.set_input_mode(EdgeMode::Increment, EdgeMode::Hold); .set_input_mode(EdgeMode::Increment, EdgeMode::Hold);
let mut output = let mut output = Output::new(ctx.output, Level::High, OutputConfig::default());
Output::new(ctx.output, OutputConfig::default().with_level(Level::High)).unwrap();
unit.resume(); unit.resume();
@ -127,14 +127,14 @@ mod tests {
unit.set_high_limit(Some(3)).unwrap(); unit.set_high_limit(Some(3)).unwrap();
// Setup channel 0 to increment the count when gpio2 does LOW -> HIGH // Setup channel 0 to increment the count when gpio2 does LOW -> HIGH
unit.channel0.set_edge_signal( unit.channel0.set_edge_signal(Input::new(
Input::new(ctx.input, InputConfig::default().with_pull(Pull::Up)).unwrap(), ctx.input,
); InputConfig::default().with_pull(Pull::Up),
));
unit.channel0 unit.channel0
.set_input_mode(EdgeMode::Increment, EdgeMode::Hold); .set_input_mode(EdgeMode::Increment, EdgeMode::Hold);
let mut output = let mut output = Output::new(ctx.output, Level::High, OutputConfig::default());
Output::new(ctx.output, OutputConfig::default().with_level(Level::High)).unwrap();
unit.resume(); unit.resume();
@ -190,14 +190,14 @@ mod tests {
unit.clear(); unit.clear();
// Setup channel 0 to increment the count when gpio2 does LOW -> HIGH // Setup channel 0 to increment the count when gpio2 does LOW -> HIGH
unit.channel0.set_edge_signal( unit.channel0.set_edge_signal(Input::new(
Input::new(ctx.input, InputConfig::default().with_pull(Pull::Up)).unwrap(), ctx.input,
); InputConfig::default().with_pull(Pull::Up),
));
unit.channel0 unit.channel0
.set_input_mode(EdgeMode::Increment, EdgeMode::Hold); .set_input_mode(EdgeMode::Increment, EdgeMode::Hold);
let mut output = let mut output = Output::new(ctx.output, Level::High, OutputConfig::default());
Output::new(ctx.output, OutputConfig::default().with_level(Level::High)).unwrap();
unit.resume(); unit.resume();
@ -257,14 +257,14 @@ mod tests {
unit.clear(); unit.clear();
// Setup channel 0 to decrement the count when gpio2 does LOW -> HIGH // Setup channel 0 to decrement the count when gpio2 does LOW -> HIGH
unit.channel0.set_edge_signal( unit.channel0.set_edge_signal(Input::new(
Input::new(ctx.input, InputConfig::default().with_pull(Pull::Up)).unwrap(), ctx.input,
); InputConfig::default().with_pull(Pull::Up),
));
unit.channel0 unit.channel0
.set_input_mode(EdgeMode::Decrement, EdgeMode::Hold); .set_input_mode(EdgeMode::Decrement, EdgeMode::Hold);
let mut output = let mut output = Output::new(ctx.output, Level::High, OutputConfig::default());
Output::new(ctx.output, OutputConfig::default().with_level(Level::High)).unwrap();
unit.resume(); unit.resume();
@ -315,14 +315,14 @@ mod tests {
let unit = ctx.pcnt.unit2; let unit = ctx.pcnt.unit2;
// Setup channel 1 to increment the count when gpio2 does LOW -> HIGH // Setup channel 1 to increment the count when gpio2 does LOW -> HIGH
unit.channel1.set_edge_signal( unit.channel1.set_edge_signal(Input::new(
Input::new(ctx.input, InputConfig::default().with_pull(Pull::Up)).unwrap(), ctx.input,
); InputConfig::default().with_pull(Pull::Up),
));
unit.channel1 unit.channel1
.set_input_mode(EdgeMode::Increment, EdgeMode::Hold); .set_input_mode(EdgeMode::Increment, EdgeMode::Hold);
let mut output = let mut output = Output::new(ctx.output, Level::High, OutputConfig::default());
Output::new(ctx.output, OutputConfig::default().with_level(Level::High)).unwrap();
unit.resume(); unit.resume();

View File

@ -198,9 +198,9 @@ mod tests {
// Make sure pins have no pullups // Make sure pins have no pullups
let config = InputConfig::default().with_pull(Pull::Down); let config = InputConfig::default().with_pull(Pull::Down);
let _ = Input::new(&mut pin, config).unwrap(); let _ = Input::new(&mut pin, config);
let _ = Input::new(&mut pin_mirror, config).unwrap(); let _ = Input::new(&mut pin_mirror, config);
let _ = Input::new(&mut unconnected_pin, config).unwrap(); let _ = Input::new(&mut unconnected_pin, config);
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(pdma)] { if #[cfg(pdma)] {
@ -230,8 +230,7 @@ mod tests {
#[test] #[test]
fn test_spi_reads_correctly_from_gpio_pin_0(ctx: Context) { fn test_spi_reads_correctly_from_gpio_pin_0(ctx: Context) {
let [pin, pin_mirror, _] = ctx.gpios; let [pin, pin_mirror, _] = ctx.gpios;
let pin_mirror = let pin_mirror = Output::new(pin_mirror, Level::High, OutputConfig::default());
Output::new(pin_mirror, OutputConfig::default().with_level(Level::High)).unwrap();
let spi = ctx.spi.with_sio0(pin).with_dma(ctx.dma_channel); let spi = ctx.spi.with_sio0(pin).with_dma(ctx.dma_channel);
@ -241,8 +240,7 @@ mod tests {
#[test] #[test]
fn test_spi_reads_correctly_from_gpio_pin_1(ctx: Context) { fn test_spi_reads_correctly_from_gpio_pin_1(ctx: Context) {
let [pin, pin_mirror, _] = ctx.gpios; let [pin, pin_mirror, _] = ctx.gpios;
let pin_mirror = let pin_mirror = Output::new(pin_mirror, Level::High, OutputConfig::default());
Output::new(pin_mirror, OutputConfig::default().with_level(Level::High)).unwrap();
let spi = ctx.spi.with_sio1(pin).with_dma(ctx.dma_channel); let spi = ctx.spi.with_sio1(pin).with_dma(ctx.dma_channel);
@ -252,8 +250,7 @@ mod tests {
#[test] #[test]
fn test_spi_reads_correctly_from_gpio_pin_2(ctx: Context) { fn test_spi_reads_correctly_from_gpio_pin_2(ctx: Context) {
let [pin, pin_mirror, _] = ctx.gpios; let [pin, pin_mirror, _] = ctx.gpios;
let pin_mirror = let pin_mirror = Output::new(pin_mirror, Level::High, OutputConfig::default());
Output::new(pin_mirror, OutputConfig::default().with_level(Level::High)).unwrap();
let spi = ctx.spi.with_sio2(pin).with_dma(ctx.dma_channel); let spi = ctx.spi.with_sio2(pin).with_dma(ctx.dma_channel);
@ -263,8 +260,7 @@ mod tests {
#[test] #[test]
fn test_spi_reads_correctly_from_gpio_pin_3(ctx: Context) { fn test_spi_reads_correctly_from_gpio_pin_3(ctx: Context) {
let [pin, pin_mirror, _] = ctx.gpios; let [pin, pin_mirror, _] = ctx.gpios;
let pin_mirror = let pin_mirror = Output::new(pin_mirror, Level::High, OutputConfig::default());
Output::new(pin_mirror, OutputConfig::default().with_level(Level::High)).unwrap();
let spi = ctx.spi.with_sio3(pin).with_dma(ctx.dma_channel); let spi = ctx.spi.with_sio3(pin).with_dma(ctx.dma_channel);
@ -274,8 +270,7 @@ mod tests {
#[test] #[test]
fn test_spi_writes_and_reads_correctly_pin_0(ctx: Context) { fn test_spi_writes_and_reads_correctly_pin_0(ctx: Context) {
let [pin, pin_mirror, _] = ctx.gpios; let [pin, pin_mirror, _] = ctx.gpios;
let pin_mirror = let pin_mirror = Output::new(pin_mirror, Level::High, OutputConfig::default());
Output::new(pin_mirror, OutputConfig::default().with_level(Level::High)).unwrap();
let spi = ctx.spi.with_sio0(pin).with_dma(ctx.dma_channel); let spi = ctx.spi.with_sio0(pin).with_dma(ctx.dma_channel);
@ -285,8 +280,7 @@ mod tests {
#[test] #[test]
fn test_spi_writes_and_reads_correctly_pin_1(ctx: Context) { fn test_spi_writes_and_reads_correctly_pin_1(ctx: Context) {
let [pin, pin_mirror, _] = ctx.gpios; let [pin, pin_mirror, _] = ctx.gpios;
let pin_mirror = let pin_mirror = Output::new(pin_mirror, Level::High, OutputConfig::default());
Output::new(pin_mirror, OutputConfig::default().with_level(Level::High)).unwrap();
let spi = ctx.spi.with_sio1(pin).with_dma(ctx.dma_channel); let spi = ctx.spi.with_sio1(pin).with_dma(ctx.dma_channel);
@ -296,8 +290,7 @@ mod tests {
#[test] #[test]
fn test_spi_writes_and_reads_correctly_pin_2(ctx: Context) { fn test_spi_writes_and_reads_correctly_pin_2(ctx: Context) {
let [pin, pin_mirror, _] = ctx.gpios; let [pin, pin_mirror, _] = ctx.gpios;
let pin_mirror = let pin_mirror = Output::new(pin_mirror, Level::High, OutputConfig::default());
Output::new(pin_mirror, OutputConfig::default().with_level(Level::High)).unwrap();
let spi = ctx.spi.with_sio2(pin).with_dma(ctx.dma_channel); let spi = ctx.spi.with_sio2(pin).with_dma(ctx.dma_channel);
@ -307,8 +300,7 @@ mod tests {
#[test] #[test]
fn test_spi_writes_and_reads_correctly_pin_3(ctx: Context) { fn test_spi_writes_and_reads_correctly_pin_3(ctx: Context) {
let [pin, pin_mirror, _] = ctx.gpios; let [pin, pin_mirror, _] = ctx.gpios;
let pin_mirror = let pin_mirror = Output::new(pin_mirror, Level::High, OutputConfig::default());
Output::new(pin_mirror, OutputConfig::default().with_level(Level::High)).unwrap();
let spi = ctx.spi.with_sio3(pin).with_dma(ctx.dma_channel); let spi = ctx.spi.with_sio3(pin).with_dma(ctx.dma_channel);

View File

@ -37,8 +37,7 @@ mod tests {
let sclk = peripherals.GPIO0; let sclk = peripherals.GPIO0;
let (miso, miso_mirror) = hil_test::common_test_pins!(peripherals); let (miso, miso_mirror) = hil_test::common_test_pins!(peripherals);
let miso_mirror = let miso_mirror = Output::new(miso_mirror, Level::High, OutputConfig::default());
Output::new(miso_mirror, OutputConfig::default().with_level(Level::High)).unwrap();
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(pdma)] { if #[cfg(pdma)] {

View File

@ -115,12 +115,10 @@ mod tests {
} }
} }
let mosi_gpio = let mosi_gpio = Output::new(mosi_pin, Level::Low, OutputConfig::default());
Output::new(mosi_pin, OutputConfig::default().with_level(Level::Low)).unwrap(); let cs_gpio = Output::new(cs_pin, Level::High, OutputConfig::default());
let cs_gpio = Output::new(cs_pin, OutputConfig::default().with_level(Level::High)).unwrap(); let sclk_gpio = Output::new(sclk_pin, Level::Low, OutputConfig::default());
let sclk_gpio = let miso_gpio = Input::new(miso_pin, InputConfig::default().with_pull(Pull::None));
Output::new(sclk_pin, OutputConfig::default().with_level(Level::Low)).unwrap();
let miso_gpio = Input::new(miso_pin, InputConfig::default().with_pull(Pull::None)).unwrap();
let cs = cs_gpio.peripheral_input(); let cs = cs_gpio.peripheral_input();
let sclk = sclk_gpio.peripheral_input(); let sclk = sclk_gpio.peripheral_input();

View File

@ -116,11 +116,8 @@ fn main() -> ! {
let mut vsync_pin = peripherals.GPIO3; let mut vsync_pin = peripherals.GPIO3;
let vsync_must_be_high_during_setup = Output::new( let vsync_must_be_high_during_setup =
&mut vsync_pin, Output::new(&mut vsync_pin, Level::High, OutputConfig::default());
OutputConfig::default().with_level(Level::High),
)
.unwrap();
for &init in INIT_CMDS.iter() { for &init in INIT_CMDS.iter() {
match init { match init {
InitCmd::Cmd(cmd, args) => { InitCmd::Cmd(cmd, args) => {

View File

@ -53,10 +53,9 @@ fn main() -> ! {
let delay = Delay::new(); let delay = Delay::new();
let config = OutputConfig::default().with_level(Level::Low); let mut backlight = Output::new(lcd_backlight, Level::Low, OutputConfig::default());
let mut backlight = Output::new(lcd_backlight, config).unwrap(); let mut reset = Output::new(lcd_reset, Level::Low, OutputConfig::default());
let mut reset = Output::new(lcd_reset, config).unwrap(); let tear_effect = Input::new(lcd_te, InputConfig::default().with_pull(Pull::None));
let tear_effect = Input::new(lcd_te, InputConfig::default().with_pull(Pull::None)).unwrap();
let tx_pins = TxEightBits::new( let tx_pins = TxEightBits::new(
peripherals.GPIO9, peripherals.GPIO9,

View File

@ -33,7 +33,7 @@ fn main() -> ! {
let mut rtc = Rtc::new(peripherals.LPWR); let mut rtc = Rtc::new(peripherals.LPWR);
let mut pin4 = peripherals.GPIO4; let mut pin4 = peripherals.GPIO4;
let ext0_pin = Input::new(&mut pin4, InputConfig::default().with_pull(Pull::None)).unwrap(); let ext0_pin = Input::new(&mut pin4, InputConfig::default().with_pull(Pull::None));
println!("up and runnning!"); println!("up and runnning!");
let reason = reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); let reason = reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);

View File

@ -34,7 +34,7 @@ fn main() -> ! {
let mut pin_2 = peripherals.GPIO2; let mut pin_2 = peripherals.GPIO2;
let mut pin_4 = peripherals.GPIO4; let mut pin_4 = peripherals.GPIO4;
let input = Input::new(&mut pin_4, InputConfig::default().with_pull(Pull::None)).unwrap(); let input = Input::new(&mut pin_4, InputConfig::default().with_pull(Pull::None));
println!("up and runnning!"); println!("up and runnning!");
let reason = reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); let reason = reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);

View File

@ -35,7 +35,7 @@ fn main() -> ! {
let mut pin2 = peripherals.GPIO2; let mut pin2 = peripherals.GPIO2;
let mut pin3 = peripherals.GPIO3; let mut pin3 = peripherals.GPIO3;
let input = Input::new(&mut pin2, InputConfig::default().with_pull(Pull::None)).unwrap(); let input = Input::new(&mut pin2, InputConfig::default().with_pull(Pull::None));
println!("up and runnning!"); println!("up and runnning!");
let reason = reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); let reason = reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);

View File

@ -51,7 +51,7 @@ fn main() -> ! {
if #[cfg(any(feature = "esp32c3", feature = "esp32c2"))] { if #[cfg(any(feature = "esp32c3", feature = "esp32c2"))] {
let mut pin2 = peripherals.GPIO2; let mut pin2 = peripherals.GPIO2;
let mut pin3 = peripherals.GPIO3; let mut pin3 = peripherals.GPIO3;
let _pin2_input = Input::new(&mut pin2, config).unwrap(); let _pin2_input = Input::new(&mut pin2, config);
let wakeup_pins: &mut [(&mut dyn gpio::RtcPinWithResistors, WakeupLevel)] = &mut [ let wakeup_pins: &mut [(&mut dyn gpio::RtcPinWithResistors, WakeupLevel)] = &mut [
(&mut pin2, WakeupLevel::Low), (&mut pin2, WakeupLevel::Low),
@ -60,7 +60,7 @@ fn main() -> ! {
} else if #[cfg(feature = "esp32s3")] { } else if #[cfg(feature = "esp32s3")] {
let mut pin17 = peripherals.GPIO17; let mut pin17 = peripherals.GPIO17;
let mut pin18 = peripherals.GPIO18; let mut pin18 = peripherals.GPIO18;
let _pin17_input = Input::new(&mut pin17, config).unwrap(); let _pin17_input = Input::new(&mut pin17, config);
let wakeup_pins: &mut [(&mut dyn gpio::RtcPin, WakeupLevel)] = &mut [ let wakeup_pins: &mut [(&mut dyn gpio::RtcPin, WakeupLevel)] = &mut [
(&mut pin17, WakeupLevel::Low), (&mut pin17, WakeupLevel::Low),