mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 14:44:42 +00:00
GPIO: Use Level enum instead of plain bool in constructors (#1574)
* GPIO: Use Level enum instead of plain bool in constructors * changelog
This commit is contained in:
parent
c6ffbb6c9d
commit
60d39e9f33
@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Refactoring of GPIO module, have drivers for Input,Output,OutputOpenDrain, all drivers setup their GPIOs correctly (#1542)
|
- Refactoring of GPIO module, have drivers for Input,Output,OutputOpenDrain, all drivers setup their GPIOs correctly (#1542)
|
||||||
- DMA transactions are now found in the `dma` module (#1550)
|
- DMA transactions are now found in the `dma` module (#1550)
|
||||||
- Remove unnecessary generics from PARL_IO driver (#1545)
|
- Remove unnecessary generics from PARL_IO driver (#1545)
|
||||||
|
- Use `Level enum` in GPIO constructors instead of plain bools (#1574)
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@
|
|||||||
//! ## Example
|
//! ## Example
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
//! let mut led = io.pins.gpio1.into_push_pull_output();
|
//! let mut led = io.pins.gpio1;
|
||||||
//! let button = io.pins.gpio9.into_pull_down_input();
|
//! let button = io.pins.gpio9;
|
||||||
//!
|
//!
|
||||||
//! // setup ETM
|
//! // setup ETM
|
||||||
//! let gpio_ext = GpioEtmChannels::new(peripherals.GPIO_SD);
|
//! let gpio_ext = GpioEtmChannels::new(peripherals.GPIO_SD);
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
//! GpioEtmOutputConfig {
|
//! GpioEtmOutputConfig {
|
||||||
//! open_drain: false,
|
//! open_drain: false,
|
||||||
//! pull: Pull::None,
|
//! pull: Pull::None,
|
||||||
//! initial_state: false,
|
//! initial_state: Level::Low,
|
||||||
//! },
|
//! },
|
||||||
//! );
|
//! );
|
||||||
//! let button_event = gpio_ext
|
//! let button_event = gpio_ext
|
||||||
@ -37,7 +37,7 @@
|
|||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
gpio::Pull,
|
gpio::{Level, Pull},
|
||||||
peripheral::{Peripheral, PeripheralRef},
|
peripheral::{Peripheral, PeripheralRef},
|
||||||
private,
|
private,
|
||||||
};
|
};
|
||||||
@ -252,7 +252,7 @@ pub struct GpioEtmOutputConfig {
|
|||||||
/// Only used when open-drain
|
/// Only used when open-drain
|
||||||
pub pull: Pull,
|
pub pull: Pull,
|
||||||
/// Initial pin state
|
/// Initial pin state
|
||||||
pub initial_state: bool,
|
pub initial_state: Level,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GpioEtmOutputConfig {
|
impl Default for GpioEtmOutputConfig {
|
||||||
@ -260,7 +260,7 @@ impl Default for GpioEtmOutputConfig {
|
|||||||
Self {
|
Self {
|
||||||
open_drain: false,
|
open_drain: false,
|
||||||
pull: Pull::None,
|
pull: Pull::None,
|
||||||
initial_state: false,
|
initial_state: Level::Low,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,7 +285,7 @@ impl<const C: u8> GpioEtmTaskChannel<C> {
|
|||||||
{
|
{
|
||||||
crate::into_ref!(pin);
|
crate::into_ref!(pin);
|
||||||
|
|
||||||
pin.set_output_high(pin_config.initial_state, private::Internal);
|
pin.set_output_high(pin_config.initial_state.into(), private::Internal);
|
||||||
if pin_config.open_drain {
|
if pin_config.open_drain {
|
||||||
pin.internal_pull_down(pin_config.pull == Pull::Down, private::Internal);
|
pin.internal_pull_down(pin_config.pull == Pull::Down, private::Internal);
|
||||||
pin.internal_pull_up(pin_config.pull == Pull::Up, private::Internal);
|
pin.internal_pull_up(pin_config.pull == Pull::Up, private::Internal);
|
||||||
@ -309,7 +309,7 @@ impl<const C: u8> GpioEtmTaskChannel<C> {
|
|||||||
{
|
{
|
||||||
crate::into_ref!(pin);
|
crate::into_ref!(pin);
|
||||||
|
|
||||||
pin.set_output_high(pin_config.initial_state, private::Internal);
|
pin.set_output_high(pin_config.initial_state.into(), private::Internal);
|
||||||
if pin_config.open_drain {
|
if pin_config.open_drain {
|
||||||
pin.internal_pull_down(pin_config.pull == Pull::Down, private::Internal);
|
pin.internal_pull_down(pin_config.pull == Pull::Down, private::Internal);
|
||||||
pin.internal_pull_up(pin_config.pull == Pull::Up, private::Internal);
|
pin.internal_pull_up(pin_config.pull == Pull::Up, private::Internal);
|
||||||
@ -333,7 +333,7 @@ impl<const C: u8> GpioEtmTaskChannel<C> {
|
|||||||
{
|
{
|
||||||
crate::into_ref!(pin);
|
crate::into_ref!(pin);
|
||||||
|
|
||||||
pin.set_output_high(pin_config.initial_state, private::Internal);
|
pin.set_output_high(pin_config.initial_state.into(), private::Internal);
|
||||||
if pin_config.open_drain {
|
if pin_config.open_drain {
|
||||||
pin.internal_pull_down(pin_config.pull == Pull::Down, private::Internal);
|
pin.internal_pull_down(pin_config.pull == Pull::Down, private::Internal);
|
||||||
pin.internal_pull_up(pin_config.pull == Pull::Up, private::Internal);
|
pin.internal_pull_up(pin_config.pull == Pull::Up, private::Internal);
|
||||||
|
@ -1557,10 +1557,10 @@ where
|
|||||||
{
|
{
|
||||||
/// Create GPIO output driver for a [GpioPin] with the provided level
|
/// Create GPIO output driver for a [GpioPin] with the provided level
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(pin: impl crate::peripheral::Peripheral<P = P> + 'd, initial_output: bool) -> Self {
|
pub fn new(pin: impl crate::peripheral::Peripheral<P = P> + 'd, initial_output: Level) -> Self {
|
||||||
crate::into_ref!(pin);
|
crate::into_ref!(pin);
|
||||||
|
|
||||||
pin.set_output_high(initial_output, private::Internal);
|
pin.set_output_high(initial_output.into(), private::Internal);
|
||||||
pin.set_to_push_pull_output(private::Internal);
|
pin.set_to_push_pull_output(private::Internal);
|
||||||
|
|
||||||
Self { pin }
|
Self { pin }
|
||||||
@ -1683,11 +1683,11 @@ where
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
pin: impl crate::peripheral::Peripheral<P = P> + 'd,
|
pin: impl crate::peripheral::Peripheral<P = P> + 'd,
|
||||||
initial_output: bool,
|
initial_output: Level,
|
||||||
pull: Pull,
|
pull: Pull,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
crate::into_ref!(pin);
|
crate::into_ref!(pin);
|
||||||
pin.set_output_high(initial_output, private::Internal);
|
pin.set_output_high(initial_output.into(), private::Internal);
|
||||||
pin.set_to_open_drain_output(private::Internal);
|
pin.set_to_open_drain_output(private::Internal);
|
||||||
pin.internal_pull_down(pull == Pull::Down, private::Internal);
|
pin.internal_pull_down(pull == Pull::Down, private::Internal);
|
||||||
pin.internal_pull_up(pull == Pull::Up, private::Internal);
|
pin.internal_pull_up(pull == Pull::Up, private::Internal);
|
||||||
@ -1785,11 +1785,11 @@ impl<'d> AnyOutput<'d> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn new<P: OutputPin + CreateErasedPin>(
|
pub fn new<P: OutputPin + CreateErasedPin>(
|
||||||
pin: impl crate::peripheral::Peripheral<P = P> + 'd,
|
pin: impl crate::peripheral::Peripheral<P = P> + 'd,
|
||||||
initial_output: bool,
|
initial_output: Level,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
crate::into_ref!(pin);
|
crate::into_ref!(pin);
|
||||||
|
|
||||||
pin.set_output_high(initial_output, private::Internal);
|
pin.set_output_high(initial_output.into(), private::Internal);
|
||||||
pin.set_to_push_pull_output(private::Internal);
|
pin.set_to_push_pull_output(private::Internal);
|
||||||
|
|
||||||
let pin = pin.erased_pin(private::Internal);
|
let pin = pin.erased_pin(private::Internal);
|
||||||
@ -1912,11 +1912,11 @@ impl<'d> AnyOutputOpenDrain<'d> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn new<P: OutputPin + InputPin + CreateErasedPin>(
|
pub fn new<P: OutputPin + InputPin + CreateErasedPin>(
|
||||||
pin: impl crate::peripheral::Peripheral<P = P> + 'd,
|
pin: impl crate::peripheral::Peripheral<P = P> + 'd,
|
||||||
initial_output: bool,
|
initial_output: Level,
|
||||||
pull: Pull,
|
pull: Pull,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
crate::into_ref!(pin);
|
crate::into_ref!(pin);
|
||||||
pin.set_output_high(initial_output, private::Internal);
|
pin.set_output_high(initial_output.into(), private::Internal);
|
||||||
pin.internal_pull_down(pull == Pull::Down, private::Internal);
|
pin.internal_pull_down(pull == Pull::Down, private::Internal);
|
||||||
pin.internal_pull_up(pull == Pull::Up, private::Internal);
|
pin.internal_pull_up(pull == Pull::Up, private::Internal);
|
||||||
pin.set_to_open_drain_output(private::Internal);
|
pin.set_to_open_drain_output(private::Internal);
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
//! let mut channel = rmt
|
//! let mut channel = rmt
|
||||||
//! .channel0
|
//! .channel0
|
||||||
//! .configure(
|
//! .configure(
|
||||||
//! io.pins.gpio1.into_push_pull_output(),
|
//! io.pins.gpio1,
|
||||||
//! TxChannelConfig {
|
//! TxChannelConfig {
|
||||||
//! clk_divider: 1,
|
//! clk_divider: 1,
|
||||||
//! idle_output_level: false,
|
//! idle_output_level: false,
|
||||||
|
@ -15,43 +15,22 @@
|
|||||||
//!
|
//!
|
||||||
//! ## Example
|
//! ## Example
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! const CODE: &[u8] = &[
|
|
||||||
//! 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00,
|
|
||||||
//! 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00,
|
|
||||||
//! 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13,
|
|
||||||
//! 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
|
|
||||||
//! 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00,
|
|
||||||
//! 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00,
|
|
||||||
//! 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13,
|
|
||||||
//! 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
|
|
||||||
//! 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x05,
|
|
||||||
//! 0x04, 0x85, 0x45, 0x23, 0x00, 0xb5, 0x00, 0xb7, 0x26, 0x0b, 0x60, 0xa1, 0x06, 0x37, 0x26,
|
|
||||||
//! 0x0b, 0x60, 0x11, 0x06, 0x09, 0x47, 0x18, 0xc2, 0xb7, 0x47, 0x0f, 0x00, 0x93, 0x87, 0x07,
|
|
||||||
//! 0x24, 0xfd, 0x17, 0xfd, 0xff, 0x85, 0x05, 0x23, 0x00, 0xb5, 0x00, 0x98, 0xc2, 0xb7, 0x47,
|
|
||||||
//! 0x0f, 0x00, 0x93, 0x87, 0x07, 0x24, 0xfd, 0x17, 0xfd, 0xff, 0xf9, 0xbf, 0x00, 0x00, 0x00,
|
|
||||||
//! 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
//! ];
|
|
||||||
//!
|
|
||||||
//! // configure GPIO 1 as LP output pin
|
//! // configure GPIO 1 as LP output pin
|
||||||
//! let mut lp_pin = io.pins.gpio1.into_low_power();
|
//! let lp_pin = LowPowerOutput::new(io.pins.gpio1);
|
||||||
//! lp_pin.output_enable(true);
|
|
||||||
//!
|
//!
|
||||||
//! let mut lp_core = esp_hal::lp_core::LpCore::new(peripherals.LP_CORE);
|
//! let mut lp_core = esp_hal::lp_core::LpCore::new(peripherals.LP_CORE);
|
||||||
//! lp_core.stop();
|
//! lp_core.stop();
|
||||||
//! println!("lp core stopped");
|
//! println!("lp core stopped");
|
||||||
//!
|
//!
|
||||||
//! // copy code to LP ram
|
//! // load code to LP core
|
||||||
//! let lp_ram = 0x5000_0000 as *mut u8;
|
//! let lp_core_code =
|
||||||
//! unsafe {
|
//! load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/blinky");
|
||||||
//! core::ptr::copy_nonoverlapping(CODE as *const _ as *const u8, lp_ram, CODE.len());
|
|
||||||
//! }
|
|
||||||
//! println!("copied code (len {})", CODE.len());
|
|
||||||
//!
|
//!
|
||||||
//! // start LP core
|
//! // start LP core
|
||||||
//! lp_core.run(lp_core::LpCoreWakeupSource::HpCpu);
|
//! lp_core.run(lp_core::LpCoreWakeupSource::HpCpu);
|
||||||
//! println!("lpcore run");
|
//! println!("lpcore run");
|
||||||
//!
|
//!
|
||||||
//! let data = (0x500000c0) as *mut u32;
|
//! let data = (0x5000_2000) as *mut u32;
|
||||||
//! loop {
|
//! loop {
|
||||||
//! print!("Current {:x} \u{000d}", unsafe {
|
//! print!("Current {:x} \u{000d}", unsafe {
|
||||||
//! data.read_volatile()
|
//! data.read_volatile()
|
||||||
|
@ -11,7 +11,7 @@ use esp_backtrace as _;
|
|||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
clock::ClockControl,
|
clock::ClockControl,
|
||||||
delay::Delay,
|
delay::Delay,
|
||||||
gpio::{Io, Output},
|
gpio::{Io, Level, Output},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
system::SystemControl,
|
system::SystemControl,
|
||||||
@ -25,7 +25,7 @@ fn main() -> ! {
|
|||||||
|
|
||||||
// Set GPIO0 as an output, and set its state high initially.
|
// Set GPIO0 as an output, and set its state high initially.
|
||||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
let mut led = Output::new(io.pins.gpio0, true);
|
let mut led = Output::new(io.pins.gpio0, Level::High);
|
||||||
|
|
||||||
// Initialize the Delay peripheral, and use it to toggle the LED state in a
|
// Initialize the Delay peripheral, and use it to toggle the LED state in a
|
||||||
// loop.
|
// loop.
|
||||||
|
@ -14,7 +14,7 @@ use esp_backtrace as _;
|
|||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
clock::ClockControl,
|
clock::ClockControl,
|
||||||
delay::Delay,
|
delay::Delay,
|
||||||
gpio::{AnyInput, AnyOutput, Io, Pull},
|
gpio::{AnyInput, AnyOutput, Io, Level, Pull},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
system::SystemControl,
|
system::SystemControl,
|
||||||
@ -29,9 +29,9 @@ fn main() -> ! {
|
|||||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
|
|
||||||
// Set LED GPIOs as an output:
|
// Set LED GPIOs as an output:
|
||||||
let led1 = AnyOutput::new(io.pins.gpio2, false);
|
let led1 = AnyOutput::new(io.pins.gpio2, Level::Low);
|
||||||
let led2 = AnyOutput::new(io.pins.gpio4, false);
|
let led2 = AnyOutput::new(io.pins.gpio4, Level::Low);
|
||||||
let led3 = AnyOutput::new(io.pins.gpio5, false);
|
let led3 = AnyOutput::new(io.pins.gpio5, Level::Low);
|
||||||
|
|
||||||
// Use boot button as an input:
|
// Use boot button as an input:
|
||||||
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))]
|
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))]
|
||||||
|
@ -20,7 +20,7 @@ use esp_hal::{
|
|||||||
cpu_control::{CpuControl, Stack},
|
cpu_control::{CpuControl, Stack},
|
||||||
embassy::{self, executor::Executor},
|
embassy::{self, executor::Executor},
|
||||||
get_core,
|
get_core,
|
||||||
gpio::{AnyOutput, Io},
|
gpio::{AnyOutput, Io, Level},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
system::SystemControl,
|
system::SystemControl,
|
||||||
@ -66,7 +66,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 led = AnyOutput::new(io.pins.gpio0, false);
|
let led = AnyOutput::new(io.pins.gpio0, Level::Low);
|
||||||
|
|
||||||
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 || {
|
||||||
|
@ -19,7 +19,7 @@ use esp_hal::{
|
|||||||
cpu_control::{CpuControl, Stack},
|
cpu_control::{CpuControl, Stack},
|
||||||
embassy::{self, executor::InterruptExecutor},
|
embassy::{self, executor::InterruptExecutor},
|
||||||
get_core,
|
get_core,
|
||||||
gpio::{AnyOutput, Io},
|
gpio::{AnyOutput, Io, Level},
|
||||||
interrupt::Priority,
|
interrupt::Priority,
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
@ -85,7 +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 led = AnyOutput::new(io.pins.gpio0, false);
|
let led = AnyOutput::new(io.pins.gpio0, Level::Low);
|
||||||
|
|
||||||
static EXECUTOR_CORE_1: StaticCell<InterruptExecutor<1>> = StaticCell::new();
|
static EXECUTOR_CORE_1: StaticCell<InterruptExecutor<1>> = StaticCell::new();
|
||||||
let executor_core1 =
|
let executor_core1 =
|
||||||
|
@ -13,7 +13,7 @@ use esp_backtrace as _;
|
|||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
clock::ClockControl,
|
clock::ClockControl,
|
||||||
embassy::{self},
|
embassy::{self},
|
||||||
gpio::{Gpio5, Io, Output},
|
gpio::{Gpio5, Io, Level, Output},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
rmt::{asynch::RxChannelAsync, PulseCode, Rmt, RxChannelConfig, RxChannelCreatorAsync},
|
rmt::{asynch::RxChannelAsync, PulseCode, Rmt, RxChannelConfig, RxChannelCreatorAsync},
|
||||||
@ -75,7 +75,7 @@ async fn main(spawner: Spawner) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
spawner
|
spawner
|
||||||
.spawn(signal_task(Output::new(io.pins.gpio5, false)))
|
.spawn(signal_task(Output::new(io.pins.gpio5, Level::Low)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut data = [PulseCode {
|
let mut data = [PulseCode {
|
||||||
|
@ -11,6 +11,7 @@ use esp_hal::{
|
|||||||
gpio::{
|
gpio::{
|
||||||
etm::{GpioEtmChannels, GpioEtmOutputConfig},
|
etm::{GpioEtmChannels, GpioEtmOutputConfig},
|
||||||
Io,
|
Io,
|
||||||
|
Level,
|
||||||
Pull,
|
Pull,
|
||||||
},
|
},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
@ -37,7 +38,7 @@ fn main() -> ! {
|
|||||||
GpioEtmOutputConfig {
|
GpioEtmOutputConfig {
|
||||||
open_drain: false,
|
open_drain: false,
|
||||||
pull: Pull::None,
|
pull: Pull::None,
|
||||||
initial_state: true,
|
initial_state: Level::High,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ use esp_hal::{
|
|||||||
gpio::{
|
gpio::{
|
||||||
etm::{GpioEtmChannels, GpioEtmInputConfig, GpioEtmOutputConfig},
|
etm::{GpioEtmChannels, GpioEtmInputConfig, GpioEtmOutputConfig},
|
||||||
Io,
|
Io,
|
||||||
|
Level,
|
||||||
Pull,
|
Pull,
|
||||||
},
|
},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
@ -34,7 +35,7 @@ fn main() -> ! {
|
|||||||
GpioEtmOutputConfig {
|
GpioEtmOutputConfig {
|
||||||
open_drain: false,
|
open_drain: false,
|
||||||
pull: Pull::None,
|
pull: Pull::None,
|
||||||
initial_state: false,
|
initial_state: Level::Low,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
let button_event = gpio_ext
|
let button_event = gpio_ext
|
||||||
|
@ -15,7 +15,7 @@ use esp_backtrace as _;
|
|||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
clock::ClockControl,
|
clock::ClockControl,
|
||||||
delay::Delay,
|
delay::Delay,
|
||||||
gpio::{self, Event, Input, Io, Output, Pull},
|
gpio::{self, Event, Input, Io, Level, Output, Pull},
|
||||||
macros::ram,
|
macros::ram,
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
@ -36,7 +36,7 @@ fn main() -> ! {
|
|||||||
// Set GPIO2 as an output, and set its state high initially.
|
// Set GPIO2 as an output, and set its state high initially.
|
||||||
let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
io.set_interrupt_handler(handler);
|
io.set_interrupt_handler(handler);
|
||||||
let mut led = Output::new(io.pins.gpio2, false);
|
let mut led = Output::new(io.pins.gpio2, Level::Low);
|
||||||
|
|
||||||
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))]
|
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))]
|
||||||
let button = io.pins.gpio0;
|
let button = io.pins.gpio0;
|
||||||
|
@ -28,7 +28,7 @@ use esp_hal::{
|
|||||||
delay::Delay,
|
delay::Delay,
|
||||||
dma::{Dma, DmaPriority},
|
dma::{Dma, DmaPriority},
|
||||||
dma_buffers,
|
dma_buffers,
|
||||||
gpio::{Io, Output},
|
gpio::{Io, Level, Output},
|
||||||
lcd_cam::{
|
lcd_cam::{
|
||||||
lcd::i8080::{Config, TxEightBits, I8080},
|
lcd::i8080::{Config, TxEightBits, I8080},
|
||||||
LcdCam,
|
LcdCam,
|
||||||
@ -67,8 +67,8 @@ fn main() -> ! {
|
|||||||
|
|
||||||
let delay = Delay::new(&clocks);
|
let delay = Delay::new(&clocks);
|
||||||
|
|
||||||
let mut backlight = Output::new(lcd_backlight, false);
|
let mut backlight = Output::new(lcd_backlight, Level::Low);
|
||||||
let mut reset = Output::new(lcd_reset, false);
|
let mut reset = Output::new(lcd_reset, Level::Low);
|
||||||
|
|
||||||
let tx_pins = TxEightBits::new(
|
let tx_pins = TxEightBits::new(
|
||||||
io.pins.gpio9,
|
io.pins.gpio9,
|
||||||
|
@ -37,7 +37,7 @@ use esp_backtrace as _;
|
|||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
clock::ClockControl,
|
clock::ClockControl,
|
||||||
delay::Delay,
|
delay::Delay,
|
||||||
gpio::{self, Io, Output},
|
gpio::{self, Io, Level, Output},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
spi::{master::Spi, SpiMode},
|
spi::{master::Spi, SpiMode},
|
||||||
@ -63,19 +63,20 @@ fn main() -> ! {
|
|||||||
gpio::NO_PIN,
|
gpio::NO_PIN,
|
||||||
);
|
);
|
||||||
let spi_bus = RefCell::new(spi_bus);
|
let spi_bus = RefCell::new(spi_bus);
|
||||||
let mut spi_device_1 = RefCellDevice::new_no_delay(&spi_bus, Output::new(io.pins.gpio5, false));
|
let mut spi_device_1 =
|
||||||
|
RefCellDevice::new_no_delay(&spi_bus, Output::new(io.pins.gpio5, Level::Low));
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(feature = "esp32")] {
|
if #[cfg(feature = "esp32")] {
|
||||||
let mut spi_device_2 =
|
let mut spi_device_2 =
|
||||||
RefCellDevice::new_no_delay(&spi_bus, Output::new(io.pins.gpio13, false));
|
RefCellDevice::new_no_delay(&spi_bus, Output::new(io.pins.gpio13, Level::Low));
|
||||||
let mut spi_device_3 =
|
let mut spi_device_3 =
|
||||||
RefCellDevice::new_no_delay(&spi_bus, Output::new(io.pins.gpio14,false));
|
RefCellDevice::new_no_delay(&spi_bus, Output::new(io.pins.gpio14, Level::Low));
|
||||||
} else {
|
} else {
|
||||||
let mut spi_device_2 =
|
let mut spi_device_2 =
|
||||||
RefCellDevice::new_no_delay(&spi_bus, Output::new(io.pins.gpio6,false));
|
RefCellDevice::new_no_delay(&spi_bus, Output::new(io.pins.gpio6, Level::Low));
|
||||||
let mut spi_device_3 =
|
let mut spi_device_3 =
|
||||||
RefCellDevice::new_no_delay(&spi_bus, Output::new(io.pins.gpio7, false));
|
RefCellDevice::new_no_delay(&spi_bus, Output::new(io.pins.gpio7, Level::Low));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ use esp_hal::{
|
|||||||
delay::Delay,
|
delay::Delay,
|
||||||
dma::{Dma, DmaPriority},
|
dma::{Dma, DmaPriority},
|
||||||
dma_buffers,
|
dma_buffers,
|
||||||
gpio::{Input, Io, Output, Pull},
|
gpio::{Input, Io, Level, Output, Pull},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
spi::{
|
spi::{
|
||||||
@ -53,13 +53,13 @@ fn main() -> ! {
|
|||||||
|
|
||||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
let slave_sclk = io.pins.gpio0;
|
let slave_sclk = io.pins.gpio0;
|
||||||
let mut master_sclk = Output::new(io.pins.gpio4, false);
|
let mut master_sclk = Output::new(io.pins.gpio4, Level::Low);
|
||||||
let slave_miso = io.pins.gpio1;
|
let slave_miso = io.pins.gpio1;
|
||||||
let master_miso = Input::new(io.pins.gpio5, Pull::None);
|
let master_miso = Input::new(io.pins.gpio5, Pull::None);
|
||||||
let slave_mosi = io.pins.gpio2;
|
let slave_mosi = io.pins.gpio2;
|
||||||
let mut master_mosi = Output::new(io.pins.gpio8, false);
|
let mut master_mosi = Output::new(io.pins.gpio8, Level::Low);
|
||||||
let slave_cs = io.pins.gpio3;
|
let slave_cs = io.pins.gpio3;
|
||||||
let mut master_cs = Output::new(io.pins.gpio9, false);
|
let mut master_cs = Output::new(io.pins.gpio9, Level::Low);
|
||||||
master_cs.set_high();
|
master_cs.set_high();
|
||||||
master_sclk.set_low();
|
master_sclk.set_low();
|
||||||
master_mosi.set_low();
|
master_mosi.set_low();
|
||||||
|
@ -18,7 +18,7 @@ use esp_hal::{
|
|||||||
clock::ClockControl,
|
clock::ClockControl,
|
||||||
delay::Delay,
|
delay::Delay,
|
||||||
embassy,
|
embassy,
|
||||||
gpio::{Gpio2, Gpio4, GpioPin, Input, Io, Output, Pull},
|
gpio::{Gpio2, Gpio4, GpioPin, Input, Io, Level, Output, Pull},
|
||||||
macros::handler,
|
macros::handler,
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
system::SystemControl,
|
system::SystemControl,
|
||||||
@ -50,7 +50,7 @@ impl<'d> Context<'d> {
|
|||||||
|
|
||||||
Context {
|
Context {
|
||||||
io2: Input::new(io.pins.gpio2, Pull::Down),
|
io2: Input::new(io.pins.gpio2, Pull::Down),
|
||||||
io4: Output::new(io.pins.gpio4, false),
|
io4: Output::new(io.pins.gpio4, Level::Low),
|
||||||
delay,
|
delay,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,8 +184,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gpio_od(ctx: Context<'static>) {
|
fn test_gpio_od(ctx: Context<'static>) {
|
||||||
let mut io2 = OutputOpenDrain::new(unsafe { GpioPin::<2>::steal() }, true, Pull::Up);
|
let mut io2 = OutputOpenDrain::new(unsafe { GpioPin::<2>::steal() }, Level::High, Pull::Up);
|
||||||
let mut io4 = OutputOpenDrain::new(unsafe { GpioPin::<4>::steal() }, true, Pull::Up);
|
let mut io4 = OutputOpenDrain::new(unsafe { GpioPin::<4>::steal() }, Level::High, Pull::Up);
|
||||||
|
|
||||||
ctx.delay.delay_millis(1);
|
ctx.delay.delay_millis(1);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user