timer works properly well
This commit is contained in:
34
flake.nix
34
flake.nix
@@ -21,29 +21,37 @@
|
|||||||
gcc
|
gcc
|
||||||
gnumake
|
gnumake
|
||||||
rustup
|
rustup
|
||||||
|
rust-analyzer
|
||||||
cargo-espflash
|
cargo-espflash
|
||||||
espup
|
espup
|
||||||
mosquitto
|
mosquitto
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
echo ">>> ESP32 DevShell (esp-hal only)"
|
echo ">>> ESP32 DevShell (esp-hal only)"
|
||||||
|
|
||||||
if [ ! -d "$HOME/.espup" ]; then
|
if [ ! -d "$HOME/.espup" ]; then
|
||||||
echo "Running espup install..."
|
echo "Running espup install..."
|
||||||
espup install
|
espup install
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Activate Xtensa Rust toolchain
|
# Ensure the real rust-analyzer from Nix is used (not rustup's shim)
|
||||||
export RUSTUP_TOOLCHAIN=esp
|
export PATH=${pkgs.rust-analyzer}/bin:$PATH
|
||||||
|
|
||||||
|
# Keep ESP toolchain binaries on PATH for building/flashing
|
||||||
|
# (do NOT set RUSTUP_TOOLCHAIN=esp globally; that breaks rust-analyzer)
|
||||||
export PATH=$HOME/.rustup/toolchains/esp/bin:$PATH
|
export PATH=$HOME/.rustup/toolchains/esp/bin:$PATH
|
||||||
|
|
||||||
|
# Add GCC/binutils path for xtensa-esp32-elf-gcc
|
||||||
|
export PATH=$HOME/.rustup/toolchains/esp/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin:$PATH
|
||||||
|
|
||||||
|
# Helpers that force the ESP toolchain explicitly when needed
|
||||||
|
alias cargo-esp="RUSTUP_TOOLCHAIN=esp cargo"
|
||||||
|
alias rustc-esp="RUSTUP_TOOLCHAIN=esp rustc"
|
||||||
|
|
||||||
# Add GCC/binutils path for xtensa-esp32-elf-gcc
|
echo "Xtensa Rust toolchain ready."
|
||||||
export PATH=$HOME/.rustup/toolchains/esp/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin:$PATH
|
rustc --version
|
||||||
|
which xtensa-esp32-elf-gcc || echo "⚠️ xtensa-esp32-elf-gcc not found in PATH"
|
||||||
echo "Xtensa Rust toolchain ready."
|
|
||||||
rustc --version
|
|
||||||
which xtensa-esp32-elf-gcc || echo "⚠️ xtensa-esp32-elf-gcc not found in PATH"
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,3 +7,6 @@ build:
|
|||||||
|
|
||||||
flash:
|
flash:
|
||||||
cargo espflash flash --release --monitor
|
cargo espflash flash --release --monitor
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo espflash erase-flash
|
||||||
|
|||||||
@@ -6,11 +6,15 @@
|
|||||||
holding buffers for the duration of a data transfer."
|
holding buffers for the duration of a data transfer."
|
||||||
)]
|
)]
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_time::{Duration, Timer};
|
// use embassy_time::{Duration, Timer};
|
||||||
use esp_backtrace as _;
|
use esp_backtrace as _;
|
||||||
use esp_hal::gpio::{Output, Level, OutputConfig};
|
use esp_hal::{
|
||||||
use esp_hal::clock::CpuClock;
|
clock::CpuClock,
|
||||||
use esp_hal::timer::timg::TimerGroup;
|
gpio::{Level, Output, OutputConfig},
|
||||||
|
timer::Timer,
|
||||||
|
timer::timg::TimerGroup,
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
@@ -28,8 +32,8 @@ async fn main(spawner: Spawner) {
|
|||||||
|
|
||||||
esp_alloc::heap_allocator!(size: 64 * 1024);
|
esp_alloc::heap_allocator!(size: 64 * 1024);
|
||||||
|
|
||||||
let timer0 = TimerGroup::new(peripherals.TIMG1);
|
let timer_group1 = TimerGroup::new(peripherals.TIMG1);
|
||||||
esp_hal_embassy::init(timer0.timer0);
|
let timer0 = timer_group1.timer0;
|
||||||
|
|
||||||
// Initialize GPIO4 as output (starts LOW)
|
// Initialize GPIO4 as output (starts LOW)
|
||||||
let mut gpio4 = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
|
let mut gpio4 = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
|
||||||
@@ -38,12 +42,25 @@ async fn main(spawner: Spawner) {
|
|||||||
loop {
|
loop {
|
||||||
gpio4.set_high();
|
gpio4.set_high();
|
||||||
info!("GPIO4 ON");
|
info!("GPIO4 ON");
|
||||||
Timer::after(Duration::from_secs(1)).await;
|
|
||||||
|
// Start timer for 1 second and block until done
|
||||||
|
let duration = Duration::from_secs(1);
|
||||||
|
timer0.load_value(duration).unwrap();
|
||||||
|
timer0.start();
|
||||||
|
info!("{:?}", duration);
|
||||||
|
|
||||||
|
// Wait until timer completes
|
||||||
|
while !timer0.is_interrupt_set() {}
|
||||||
|
timer0.clear_interrupt();
|
||||||
|
|
||||||
gpio4.set_low();
|
gpio4.set_low();
|
||||||
info!("GPIO4 OFF");
|
info!("GPIO4 OFF");
|
||||||
Timer::after(Duration::from_secs(1)).await;
|
|
||||||
|
// Start timer for 1 second and block until done
|
||||||
|
timer0.load_value(duration).unwrap();
|
||||||
|
timer0.start();
|
||||||
|
|
||||||
|
while !timer0.is_interrupt_set() {}
|
||||||
|
timer0.clear_interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user