Skip to content

Commit bf0812f

Browse files
authored
esp-hal = 1.0.0-beta.0 (#14)
1 parent 5209f40 commit bf0812f

File tree

8 files changed

+165
-129
lines changed

8 files changed

+165
-129
lines changed

Cargo.lock

+104-80
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ esp-backtrace = { version = "0.15.0", features = [
1010
"panic-handler",
1111
"defmt",
1212
] }
13-
esp-hal = { version = "0.23.1", features = ["esp32s3", "defmt"] }
14-
esp-alloc = { version = "0.6.0" }
13+
esp-hal = { version = "1.0.0-beta.0", features = ["esp32s3", "defmt", "unstable"] }
14+
esp-alloc = { version = "0.7.0" }
1515
embassy-net = { version = "0.6.0", features = [
1616
"tcp",
1717
"udp",
@@ -22,7 +22,7 @@ embassy-net = { version = "0.6.0", features = [
2222
] }
2323

2424
mipidsi = { version = "0.9.0" }
25-
esp-wifi = { version = "0.12.0", features = [
25+
esp-wifi = { version = "0.13.0", features = [
2626
"esp32s3",
2727
"serde",
2828
"wifi",
@@ -36,7 +36,7 @@ embassy-executor = { version = "0.7.0", features = [
3636
"defmt",
3737
] }
3838
embassy-time = { version = "0.4.0", features = ["defmt"] }
39-
esp-hal-embassy = { version = "0.6.0", features = ["esp32s3", "defmt"] }
39+
esp-hal-embassy = { version = "0.7.0", features = ["esp32s3", "defmt"] }
4040
rust-mqtt = { version = "0.3.0", default-features = false, features = [
4141
"defmt",
4242
] }

src/display.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use embedded_text::alignment::HorizontalAlignment;
99
use embedded_text::style::{HeightMode, TextBoxStyleBuilder};
1010
use embedded_text::TextBox;
1111
use esp_hal::delay::Delay;
12-
use esp_hal::gpio::{GpioPin, Level, Output};
12+
use esp_hal::gpio::{GpioPin, Level, Output, OutputConfig};
1313
use mipidsi::interface::{Generic8BitBus, ParallelError, ParallelInterface};
1414
use mipidsi::models::ST7789;
1515
use mipidsi::options::{ColorInversion, Orientation, Rotation};
@@ -68,25 +68,25 @@ pub struct DisplayPeripherals {
6868

6969
impl Display<'_> {
7070
pub fn new(p: DisplayPeripherals) -> Result<Self, Error> {
71-
let backlight = Output::new(p.backlight, Level::Low);
71+
let backlight = Output::new(p.backlight, Level::Low, OutputConfig::default());
7272

73-
let dc = Output::new(p.dc, Level::Low);
74-
let mut cs = Output::new(p.cs, Level::Low);
75-
let rst = Output::new(p.rst, Level::Low);
76-
let wr = Output::new(p.wr, Level::Low);
77-
let mut rd = Output::new(p.rd, Level::Low);
73+
let dc = Output::new(p.dc, Level::Low, OutputConfig::default());
74+
let mut cs = Output::new(p.cs, Level::Low, OutputConfig::default());
75+
let rst = Output::new(p.rst, Level::Low, OutputConfig::default());
76+
let wr = Output::new(p.wr, Level::Low, OutputConfig::default());
77+
let mut rd = Output::new(p.rd, Level::Low, OutputConfig::default());
7878

7979
cs.set_low();
8080
rd.set_high();
8181

82-
let d0 = Output::new(p.d0, Level::Low);
83-
let d1 = Output::new(p.d1, Level::Low);
84-
let d2 = Output::new(p.d2, Level::Low);
85-
let d3 = Output::new(p.d3, Level::Low);
86-
let d4 = Output::new(p.d4, Level::Low);
87-
let d5 = Output::new(p.d5, Level::Low);
88-
let d6 = Output::new(p.d6, Level::Low);
89-
let d7 = Output::new(p.d7, Level::Low);
82+
let d0 = Output::new(p.d0, Level::Low, OutputConfig::default());
83+
let d1 = Output::new(p.d1, Level::Low, OutputConfig::default());
84+
let d2 = Output::new(p.d2, Level::Low, OutputConfig::default());
85+
let d3 = Output::new(p.d3, Level::Low, OutputConfig::default());
86+
let d4 = Output::new(p.d4, Level::Low, OutputConfig::default());
87+
let d5 = Output::new(p.d5, Level::Low, OutputConfig::default());
88+
let d6 = Output::new(p.d6, Level::Low, OutputConfig::default());
89+
let d7 = Output::new(p.d7, Level::Low, OutputConfig::default());
9090

9191
let bus = Generic8BitBus::new((d0, d1, d2, d3, d4, d5, d6, d7));
9292

src/main.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use embassy_time::{Duration, Timer};
1616
use esp_alloc::heap_allocator;
1717
use esp_hal::{
1818
clock::CpuClock,
19-
gpio::{Level, Output},
19+
gpio::{Level, Output, OutputConfig},
2020
ram,
2121
timer::timg::TimerGroup,
2222
};
@@ -73,10 +73,10 @@ async fn main_fallible(spawner: Spawner, boot_count: u32) -> Result<(), Error> {
7373
let peripherals = esp_hal::init(esp_hal::Config::default().with_cpu_clock(CpuClock::_160MHz));
7474

7575
// This IO15 must be set to HIGH, otherwise nothing will be displayed when USB is not connected.
76-
let mut power_pin = Output::new(peripherals.GPIO15, Level::Low);
76+
let mut power_pin = Output::new(peripherals.GPIO15, Level::Low, OutputConfig::default());
7777
power_pin.set_high();
7878

79-
heap_allocator!(72 * 1024);
79+
heap_allocator!(size: 72 * 1024);
8080

8181
let timg0 = TimerGroup::new(peripherals.TIMG0);
8282
let timg1 = TimerGroup::new(peripherals.TIMG1);
@@ -159,7 +159,8 @@ async fn main_fallible(spawner: Spawner, boot_count: u32) -> Result<(), Error> {
159159

160160
let deep_sleep_duration = Duration::from_secs(DEEP_SLEEP_DURATION_SECONDS);
161161
info!("Enter deep sleep for {}s", DEEP_SLEEP_DURATION_SECONDS);
162-
enter_deep(peripherals.GPIO14, peripherals.LPWR, deep_sleep_duration);
162+
let mut wake_up_btn_pin = peripherals.GPIO14;
163+
enter_deep(&mut wake_up_btn_pin, peripherals.LPWR, deep_sleep_duration);
163164
}
164165

165166
#[derive(Debug, defmt::Format)]

src/relay_task.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use defmt::info;
22
use embassy_time::{Duration, Timer};
3-
use esp_hal::gpio::{GpioPin, Level, Output};
3+
use esp_hal::gpio::{GpioPin, Level, Output, OutputConfig};
44

55
use crate::ENABLE_PUMP;
66

@@ -10,7 +10,7 @@ const PUMP_INTERVAL: Duration = Duration::from_secs(10);
1010
pub async fn relay_task(pin: GpioPin<2>) {
1111
info!("Created a relay task");
1212
// Configure GPIO pin for relay (using GPIO2)
13-
let mut dht_pin = Output::new(pin, Level::Low);
13+
let mut dht_pin = Output::new(pin, Level::Low, OutputConfig::default());
1414

1515
loop {
1616
let start_pump = ENABLE_PUMP.wait().await;

src/sensors_task.rs

+27-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use esp_hal::{
88
RegisterAccess,
99
},
1010
delay::Delay,
11-
gpio::{GpioPin, Input, Level, Output, OutputOpenDrain, Pull},
11+
gpio::{DriveMode, GpioPin, Input, InputConfig, Level, Output, OutputConfig, Pull},
1212
peripherals::{ADC1, ADC2},
13+
Blocking,
1314
};
1415

1516
use crate::{
@@ -55,10 +56,15 @@ pub async fn sensor_task(
5556
.enable_pin_with_cal::<GpioPin<4>, AdcCalLine<ADC1>>(p.battery_pin, Attenuation::_11dB);
5657
let mut adc1 = Adc::new(p.adc1, adc1_config);
5758

58-
let moisture_input_pin = Input::new(p.moisture_digital_pin, esp_hal::gpio::Pull::None);
59+
let moisture_input_pin = Input::new(
60+
p.moisture_digital_pin,
61+
InputConfig::default().with_pull(Pull::None),
62+
);
5963

60-
let mut moisture_power_pin = Output::new(p.moisture_power_pin, Level::Low);
61-
let mut water_level_power_pin = Output::new(p.water_level_power_pin, Level::Low);
64+
let mut moisture_power_pin =
65+
Output::new(p.moisture_power_pin, Level::Low, OutputConfig::default());
66+
let mut water_level_power_pin =
67+
Output::new(p.water_level_power_pin, Level::Low, OutputConfig::default());
6268

6369
loop {
6470
// Collect samples for each sensor type
@@ -79,10 +85,17 @@ pub async fn sensor_task(
7985
info!("Reading sensor data {}/{}", (i + 1), SENSOR_SAMPLE_COUNT);
8086

8187
{
82-
let dht11_pin =
83-
OutputOpenDrain::new(&mut p.dht11_digital_pin, Level::High, Pull::None);
84-
let mut dht11_sensor: Dht11<OutputOpenDrain<'_>, Delay> =
85-
Dht11::new(dht11_pin, delay);
88+
let mut dht11_pin = Output::new(
89+
&mut p.dht11_digital_pin,
90+
Level::High,
91+
OutputConfig::default()
92+
.with_drive_mode(DriveMode::OpenDrain)
93+
.with_pull(Pull::None),
94+
)
95+
.into_flex();
96+
dht11_pin.enable_input(true);
97+
98+
let mut dht11_sensor = Dht11::new(dht11_pin, delay);
8699

87100
// DHT11 needs a longer initial delay
88101
Timer::after(Duration::from_millis(DHT11_WARMUP_DELAY_MILLISECONDS)).await;
@@ -179,15 +192,19 @@ pub async fn sensor_task(
179192
moisture_power_pin.set_low();
180193
water_level_power_pin.set_low();
181194
// Force the pin into an explicit low-power state after the sensor is dropped
182-
Output::new(&mut p.dht11_digital_pin, Level::Low);
195+
Output::new(
196+
&mut p.dht11_digital_pin,
197+
Level::Low,
198+
OutputConfig::default(),
199+
);
183200

184201
Timer::after(sampling_period).await;
185202
}
186203
}
187204

188205
/// Sample an ADC pin and return the value
189206
async fn sample_adc<PIN, ADCI, ADCC>(
190-
adc: &mut Adc<'_, ADCI>,
207+
adc: &mut Adc<'_, ADCI, Blocking>,
191208
pin: &mut AdcPin<PIN, ADCI, ADCC>,
192209
) -> Option<u16>
193210
where

src/sleep.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
use defmt::info;
22
use embassy_time::Duration;
33
use esp_hal::gpio::RtcPin;
4-
use esp_hal::peripheral::Peripheral;
54
use esp_hal::peripherals::LPWR;
65
use esp_hal::rtc_cntl::sleep::{RtcSleepConfig, RtcioWakeupSource, TimerWakeupSource, WakeupLevel};
76
use esp_hal::rtc_cntl::Rtc;
87

98
/// Enter deep sleep mode for the specified duration.
10-
pub fn enter_deep(
11-
wakeup_pin: impl Peripheral<P = impl RtcPin>,
12-
rtc_cntl: LPWR,
13-
interval: Duration,
14-
) -> ! {
15-
let wakeup_pins: &mut [(&mut dyn RtcPin, WakeupLevel)] =
16-
&mut [(&mut *wakeup_pin.into_ref(), WakeupLevel::Low)];
9+
pub fn enter_deep(wakeup_pin: &mut dyn RtcPin, rtc_cntl: LPWR, interval: Duration) -> ! {
10+
let wakeup_pins: &mut [(&mut dyn RtcPin, WakeupLevel)] = &mut [(wakeup_pin, WakeupLevel::Low)];
1711
let ext0 = RtcioWakeupSource::new(wakeup_pins);
1812

1913
let wakeup_source_timer = TimerWakeupSource::new(interval.into());

src/wifi.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use core::str::FromStr;
22
use defmt::{error, info};
33
use embassy_executor::Spawner;
4-
use embassy_net::{Stack, StackResources};
4+
use embassy_net::{Runner, Stack, StackResources};
55
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, signal::Signal};
66
use embassy_time::{Duration, Timer};
77
use esp_hal::{
88
peripherals::{self, RNG},
99
rng::Rng,
1010
};
1111
use esp_wifi::wifi::{
12-
ClientConfiguration, Configuration, WifiController, WifiDevice, WifiError, WifiEvent,
13-
WifiStaDevice, WifiState,
12+
ClientConfiguration, Configuration, WifiController, WifiDevice, WifiError, WifiEvent, WifiState,
1413
};
1514
use heapless::String;
1615
use static_cell::StaticCell;
@@ -35,8 +34,9 @@ pub async fn connect_to_wifi(
3534
static INIT: StaticCell<esp_wifi::EspWifiController<'static>> = StaticCell::new();
3635
let init = INIT.init(esp_wifi::init(timer, rng, radio_clocks).unwrap());
3736

38-
let (wifi_interface, controller) =
39-
esp_wifi::wifi::new_with_mode(init, wifi, WifiStaDevice).unwrap();
37+
let (controller, interfaces) = esp_wifi::wifi::new(init, wifi).unwrap();
38+
39+
let wifi_interface = interfaces.sta;
4040

4141
// initialize network stack
4242
let mut dhcp_config = embassy_net::DhcpConfig::default();
@@ -73,7 +73,7 @@ pub async fn connect_to_wifi(
7373
}
7474

7575
#[embassy_executor::task]
76-
async fn net_task(mut runner: embassy_net::Runner<'static, WifiDevice<'static, WifiStaDevice>>) {
76+
async fn net_task(mut runner: Runner<'static, WifiDevice<'static>>) {
7777
runner.run().await
7878
}
7979

0 commit comments

Comments
 (0)