Skip to content

Commit 2dd5f23

Browse files
committed
Fix tests and examples
1 parent 1cd75f9 commit 2dd5f23

File tree

12 files changed

+86
-90
lines changed

12 files changed

+86
-90
lines changed

examples/src/bin/embassy_rmt_rx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use embassy_executor::Spawner;
1313
use embassy_time::{Duration, Timer};
1414
use esp_backtrace as _;
1515
use esp_hal::{
16-
gpio::{GpioPin, Io, Level, Output},
16+
gpio::{Io, Level, Output},
1717
prelude::*,
1818
rmt::{asynch::RxChannelAsync, PulseCode, Rmt, RxChannelConfig, RxChannelCreatorAsync},
1919
timer::timg::TimerGroup,
@@ -26,7 +26,7 @@ const WIDTH: usize = 80;
2626
compile_error!("Run this example in release mode");
2727

2828
#[embassy_executor::task]
29-
async fn signal_task(mut pin: Output<'static, GpioPin<5>>) {
29+
async fn signal_task(mut pin: Output<'static>) {
3030
loop {
3131
for _ in 0..10 {
3232
pin.toggle();

examples/src/bin/gpio_interrupt.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@ use critical_section::Mutex;
1717
use esp_backtrace as _;
1818
use esp_hal::{
1919
delay::Delay,
20-
gpio::{Event, GpioPin, Input, Io, Level, Output, Pull},
20+
gpio::{Event, Input, Io, Level, Output, Pull},
2121
macros::ram,
2222
prelude::*,
2323
};
2424

25-
cfg_if::cfg_if! {
26-
if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] {
27-
const BUTTON_PIN: u8 = 0;
28-
} else {
29-
const BUTTON_PIN: u8 = 9;
30-
}
31-
}
32-
33-
static BUTTON: Mutex<RefCell<Option<Input<GpioPin<BUTTON_PIN>>>>> = Mutex::new(RefCell::new(None));
25+
static BUTTON: Mutex<RefCell<Option<Input>>> = Mutex::new(RefCell::new(None));
3426

3527
#[entry]
3628
fn main() -> ! {

examples/src/bin/spi_slave_dma.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use esp_hal::{
3434
delay::Delay,
3535
dma::{Dma, DmaPriority},
3636
dma_buffers,
37-
gpio::{GpioPin, Input, Io, Level, Output, Pull},
37+
gpio::{Input, Io, Level, Output, Pull},
3838
prelude::*,
3939
spi::{
4040
slave::{prelude::*, Spi},
@@ -48,17 +48,16 @@ fn main() -> ! {
4848
let peripherals = esp_hal::init(esp_hal::Config::default());
4949

5050
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
51-
let slave_sclk = io.pins.gpio0;
51+
5252
let mut master_sclk = Output::new(io.pins.gpio4, Level::Low);
53-
let slave_miso = io.pins.gpio1;
5453
let master_miso = Input::new(io.pins.gpio5, Pull::None);
55-
let slave_mosi = io.pins.gpio2;
5654
let mut master_mosi = Output::new(io.pins.gpio8, Level::Low);
55+
let mut master_cs = Output::new(io.pins.gpio9, Level::High);
56+
57+
let slave_sclk = io.pins.gpio0;
58+
let slave_miso = io.pins.gpio1;
59+
let slave_mosi = io.pins.gpio2;
5760
let slave_cs = io.pins.gpio3;
58-
let mut master_cs = Output::new(io.pins.gpio9, Level::Low);
59-
master_cs.set_high();
60-
master_sclk.set_low();
61-
master_mosi.set_low();
6261

6362
let dma = Dma::new(peripherals.DMA);
6463
cfg_if::cfg_if! {
@@ -189,10 +188,10 @@ fn main() -> ! {
189188
fn bitbang_master(
190189
master_send: &[u8],
191190
master_receive: &mut [u8],
192-
master_cs: &mut Output<GpioPin<9>>,
193-
master_mosi: &mut Output<GpioPin<8>>,
194-
master_sclk: &mut Output<GpioPin<4>>,
195-
master_miso: &Input<GpioPin<5>>,
191+
master_cs: &mut Output,
192+
master_mosi: &mut Output,
193+
master_sclk: &mut Output,
194+
master_miso: &Input,
196195
) {
197196
// Bit-bang out the contents of master_send and read into master_receive
198197
// as quickly as manageable. MSB first. Mode 0, so sampled on the rising

hil-test/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ macro_rules! common_test_pins {
4949
cfg_if::cfg_if! {
5050
if #[cfg(any(esp32s2, esp32s3))] {
5151
($io.pins.gpio9, $io.pins.gpio10)
52-
}
53-
else {
52+
} else {
5453
($io.pins.gpio2, $io.pins.gpio3)
5554
}
5655
}

hil-test/tests/aes_dma.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use esp_hal::{
1414
dma::{Dma, DmaPriority},
1515
dma_buffers,
1616
peripherals::Peripherals,
17-
prelude::*,
1817
};
1918
use hil_test as _;
2019

hil-test/tests/delay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod tests {
2020

2121
#[init]
2222
fn init() -> Context {
23-
let peripherals = esp_hal::init(esp_hal::Config::default());
23+
let _peripherals = esp_hal::init(esp_hal::Config::default());
2424
let delay = Delay::new();
2525

2626
Context { delay }

hil-test/tests/get_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ mod tests {
6161
#[test]
6262
#[timeout(3)]
6363
fn test_current_time_construct_timg0(ctx: Context) {
64-
time_moves_forward_during(ctx, |ctx| {
64+
time_moves_forward_during(ctx, |_| {
6565
// construct the timer in between calls to current_time
6666
let _ = esp_hal::timer::timg::TimerGroup::new(unsafe {
6767
esp_hal::peripherals::TIMG0::steal()

hil-test/tests/gpio.rs

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ use core::cell::RefCell;
1515
use critical_section::Mutex;
1616
use esp_hal::{
1717
delay::Delay,
18-
gpio::{AnyPin, GpioPin, Input, Io, Level, Output, Pull},
18+
gpio::{AnyPin, ErasedPin, Input, Io, Level, Output, Pin, Pull},
1919
macros::handler,
2020
timer::timg::TimerGroup,
2121
InterruptConfigurable,
2222
};
2323
use hil_test as _;
2424

2525
static COUNTER: Mutex<RefCell<u32>> = Mutex::new(RefCell::new(0));
26-
static INPUT_PIN: Mutex<RefCell<Option<Input<'static>>>> = Mutex::new(RefCell::new(None));
26+
static INPUT_PIN: Mutex<RefCell<Option<Input>>> = Mutex::new(RefCell::new(None));
2727

28-
struct Context<'d> {
29-
test_gpio1: Input<'d>,
30-
test_gpio2: Output<'d>,
28+
struct Context {
29+
test_gpio1: ErasedPin,
30+
test_gpio2: ErasedPin,
3131
delay: Delay,
3232
}
3333

@@ -53,7 +53,7 @@ mod tests {
5353
use super::*;
5454

5555
#[init]
56-
fn init() -> Context<'static> {
56+
fn init() -> Context {
5757
let peripherals = esp_hal::init(esp_hal::Config::default());
5858

5959
let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@@ -67,20 +67,22 @@ mod tests {
6767
esp_hal_embassy::init(timg0.timer0);
6868

6969
Context {
70-
test_gpio1: Input::new(gpio1, Pull::Down),
71-
test_gpio2: Output::new(gpio2, Level::Low),
70+
test_gpio1: gpio1.degrade(),
71+
test_gpio2: gpio2.degrade(),
7272
delay,
7373
}
7474
}
7575

7676
#[test]
77-
async fn test_async_edge(ctx: Context<'static>) {
77+
async fn test_async_edge(ctx: Context) {
7878
let counter = AtomicUsize::new(0);
7979
let Context {
80-
mut test_gpio1,
81-
mut test_gpio2,
80+
test_gpio1,
81+
test_gpio2,
8282
..
8383
} = ctx;
84+
let mut test_gpio1 = Input::new(test_gpio1, Pull::Down);
85+
let mut test_gpio2 = Output::new(test_gpio2, Level::Low);
8486
embassy_futures::select::select(
8587
async {
8688
loop {
@@ -102,8 +104,8 @@ mod tests {
102104
}
103105

104106
#[test]
105-
async fn test_a_pin_can_wait(_ctx: Context<'static>) {
106-
let mut first = Input::new(unsafe { GpioPin::<0>::steal() }, Pull::Down);
107+
async fn test_a_pin_can_wait(ctx: Context) {
108+
let mut first = Input::new(ctx.test_gpio1, Pull::Down);
107109

108110
embassy_futures::select::select(
109111
first.wait_for_rising_edge(),
@@ -115,69 +117,74 @@ mod tests {
115117
}
116118

117119
#[test]
118-
fn test_gpio_input(ctx: Context<'static>) {
120+
fn test_gpio_input(ctx: Context) {
121+
let test_gpio1 = Input::new(ctx.test_gpio1, Pull::Down);
119122
// `InputPin`:
120-
assert_eq!(ctx.test_gpio1.is_low(), true);
121-
assert_eq!(ctx.test_gpio1.is_high(), false);
123+
assert_eq!(test_gpio1.is_low(), true);
124+
assert_eq!(test_gpio1.is_high(), false);
122125
}
123126

124127
#[test]
125-
fn test_gpio_output(mut ctx: Context<'static>) {
128+
fn test_gpio_output(ctx: Context) {
129+
let mut test_gpio2 = Output::new(ctx.test_gpio2, Level::Low);
130+
126131
// `StatefulOutputPin`:
127-
assert_eq!(ctx.test_gpio2.is_set_low(), true);
128-
assert_eq!(ctx.test_gpio2.is_set_high(), false);
129-
ctx.test_gpio2.set_high();
130-
assert_eq!(ctx.test_gpio2.is_set_low(), false);
131-
assert_eq!(ctx.test_gpio2.is_set_high(), true);
132+
assert_eq!(test_gpio2.is_set_low(), true);
133+
assert_eq!(test_gpio2.is_set_high(), false);
134+
test_gpio2.set_high();
135+
assert_eq!(test_gpio2.is_set_low(), false);
136+
assert_eq!(test_gpio2.is_set_high(), true);
132137

133138
// `ToggleableOutputPin`:
134-
ctx.test_gpio2.toggle();
135-
assert_eq!(ctx.test_gpio2.is_set_low(), true);
136-
assert_eq!(ctx.test_gpio2.is_set_high(), false);
137-
ctx.test_gpio2.toggle();
138-
assert_eq!(ctx.test_gpio2.is_set_low(), false);
139-
assert_eq!(ctx.test_gpio2.is_set_high(), true);
139+
test_gpio2.toggle();
140+
assert_eq!(test_gpio2.is_set_low(), true);
141+
assert_eq!(test_gpio2.is_set_high(), false);
142+
test_gpio2.toggle();
143+
assert_eq!(test_gpio2.is_set_low(), false);
144+
assert_eq!(test_gpio2.is_set_high(), true);
140145
}
141146

142147
#[test]
143-
fn test_gpio_interrupt(mut ctx: Context<'static>) {
148+
fn test_gpio_interrupt(ctx: Context) {
149+
let mut test_gpio1 = Input::new(ctx.test_gpio1, Pull::Down);
150+
let mut test_gpio2 = Output::new(ctx.test_gpio2, Level::Low);
151+
144152
critical_section::with(|cs| {
145153
*COUNTER.borrow_ref_mut(cs) = 0;
146-
ctx.test_gpio1.listen(Event::AnyEdge);
147-
INPUT_PIN.borrow_ref_mut(cs).replace(ctx.test_gpio1);
154+
test_gpio1.listen(Event::AnyEdge);
155+
INPUT_PIN.borrow_ref_mut(cs).replace(test_gpio1);
148156
});
149-
ctx.test_gpio2.set_high();
157+
test_gpio2.set_high();
150158
ctx.delay.delay_millis(1);
151-
ctx.test_gpio2.set_low();
159+
test_gpio2.set_low();
152160
ctx.delay.delay_millis(1);
153-
ctx.test_gpio2.set_high();
161+
test_gpio2.set_high();
154162
ctx.delay.delay_millis(1);
155-
ctx.test_gpio2.set_low();
163+
test_gpio2.set_low();
156164
ctx.delay.delay_millis(1);
157-
ctx.test_gpio2.set_high();
165+
test_gpio2.set_high();
158166
ctx.delay.delay_millis(1);
159-
ctx.test_gpio2.set_low();
167+
test_gpio2.set_low();
160168
ctx.delay.delay_millis(1);
161-
ctx.test_gpio2.set_high();
169+
test_gpio2.set_high();
162170
ctx.delay.delay_millis(1);
163-
ctx.test_gpio2.set_low();
171+
test_gpio2.set_low();
164172
ctx.delay.delay_millis(1);
165-
ctx.test_gpio2.set_high();
173+
test_gpio2.set_high();
166174
ctx.delay.delay_millis(1);
167175

168176
let count = critical_section::with(|cs| *COUNTER.borrow_ref(cs));
169177
assert_eq!(count, 9);
170178

171-
ctx.test_gpio1 = critical_section::with(|cs| INPUT_PIN.borrow_ref_mut(cs).take().unwrap());
172-
ctx.test_gpio1.unlisten();
179+
let mut test_gpio1 =
180+
critical_section::with(|cs| INPUT_PIN.borrow_ref_mut(cs).take().unwrap());
181+
test_gpio1.unlisten();
173182
}
174183

175184
#[test]
176-
fn test_gpio_od(ctx: Context<'static>) {
177-
let mut test_gpio1 =
178-
OutputOpenDrain::new(unsafe { TestGpio1::steal() }, Level::High, Pull::Up);
179-
let mut test_gpio2 =
180-
OutputOpenDrain::new(unsafe { TestGpio2::steal() }, Level::High, Pull::Up);
185+
fn test_gpio_od(ctx: Context) {
186+
let mut test_gpio1 = OutputOpenDrain::new(ctx.test_gpio1, Level::High, Pull::Up);
187+
let mut test_gpio2 = OutputOpenDrain::new(ctx.test_gpio2, Level::High, Pull::Up);
181188

182189
ctx.delay.delay_millis(1);
183190

@@ -221,9 +228,9 @@ mod tests {
221228
}
222229

223230
#[test]
224-
fn test_gpio_flex(ctx: Context<'static>) {
225-
let mut test_gpio1 = Flex::new(unsafe { TestGpio1::steal() });
226-
let mut test_gpio2 = Flex::new(unsafe { TestGpio2::steal() });
231+
fn test_gpio_flex(ctx: Context) {
232+
let mut test_gpio1 = Flex::new(ctx.test_gpio1);
233+
let mut test_gpio2 = Flex::new(ctx.test_gpio2);
227234

228235
test_gpio1.set_high();
229236
test_gpio1.set_as_output();
@@ -263,9 +270,9 @@ mod tests {
263270
// Tests touch pin (GPIO2) as AnyPin and Output
264271
// https://github.com/esp-rs/esp-hal/issues/1943
265272
#[test]
266-
fn test_gpio_touch_anypin_output() {
267-
let any_pin2 = AnyPin::new(unsafe { TestGpio1::steal() });
268-
let any_pin3 = AnyPin::new(unsafe { TestGpio2::steal() });
273+
fn test_gpio_touch_anypin_output(ctx: Context) {
274+
let any_pin2 = AnyPin::new(ctx.test_gpio1);
275+
let any_pin3 = AnyPin::new(ctx.test_gpio2);
269276

270277
let out_pin = Output::new(any_pin2, Level::High);
271278
let in_pin = Input::new(any_pin3, Pull::Down);
@@ -277,9 +284,9 @@ mod tests {
277284
// Tests touch pin (GPIO2) as AnyPin and Input
278285
// https://github.com/esp-rs/esp-hal/issues/1943
279286
#[test]
280-
fn test_gpio_touch_anypin_input() {
281-
let any_pin2 = AnyPin::new(unsafe { TestGpio1::steal() });
282-
let any_pin3 = AnyPin::new(unsafe { TestGpio2::steal() });
287+
fn test_gpio_touch_anypin_input(ctx: Context) {
288+
let any_pin2 = AnyPin::new(ctx.test_gpio1);
289+
let any_pin3 = AnyPin::new(ctx.test_gpio2);
283290

284291
let out_pin = Output::new(any_pin3, Level::Low);
285292
let in_pin = Input::new(any_pin2, Pull::Down);

hil-test/tests/qspi_write_read.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use esp_hal::{
1818
dma::{Channel, Dma, DmaPriority, DmaRxBuf, DmaTxBuf},
1919
dma_buffers,
20-
gpio::{AnyPin, Io, Level, Output},
20+
gpio::{ErasedPin, Io, Level, Output},
2121
prelude::*,
2222
spi::{
2323
master::{Address, Command, Spi, SpiDma},
@@ -106,7 +106,7 @@ mod tests {
106106
let (mosi, mosi_mirror) = hil_test::common_test_pins!(io);
107107

108108
let mosi = mosi.degrade();
109-
let mosi_mirror = AnyOutput::new(mosi_mirror, Level::High);
109+
let mosi_mirror = Output::new(mosi_mirror, Level::High);
110110

111111
let dma = Dma::new(peripherals.DMA);
112112

hil-test/tests/spi_full_duplex_dma_async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use embedded_hal_async::spi::SpiBus;
2424
use esp_hal::{
2525
dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf},
2626
dma_buffers,
27-
gpio::{ErasedPin, GpioPin, Io, Level, Output, Pull},
27+
gpio::{ErasedPin, Io, Level, Output, Pull},
2828
pcnt::{
2929
channel::{EdgeMode, PcntInputConfig, PcntSource},
3030
unit::Unit,

0 commit comments

Comments
 (0)