diff options
| author | Mehmet Ali Anil <[email protected]> | 2023-03-07 10:46:59 +0100 |
|---|---|---|
| committer | Mehmet Ali Anil <[email protected]> | 2023-03-07 23:16:54 +0100 |
| commit | 935633c90b817b15c6c2cf180e107992ad5dd9a6 (patch) | |
| tree | 5e4c33aa5992a7eb941a0920b0c080a624cd15a5 /examples | |
| parent | bc0cb43307c2a46330ce253505203dbc607bcc6c (diff) | |
| parent | 18fe398673f55b07159d01a230910bb9689c1525 (diff) | |
Merge upstream
Diffstat (limited to 'examples')
44 files changed, 344 insertions, 281 deletions
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml index cfdda076e..cc88d92c7 100644 --- a/examples/nrf52840/Cargo.toml +++ b/examples/nrf52840/Cargo.toml | |||
| @@ -6,7 +6,6 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [features] | 7 | [features] |
| 8 | default = ["nightly"] | 8 | default = ["nightly"] |
| 9 | msos-descriptor = ["embassy-usb/msos-descriptor"] | ||
| 10 | nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embedded-io/async", "embassy-net", | 9 | nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embedded-io/async", "embassy-net", |
| 11 | "embassy-lora", "lorawan-device", "lorawan"] | 10 | "embassy-lora", "lorawan-device", "lorawan"] |
| 12 | 11 | ||
| @@ -17,7 +16,7 @@ embassy-executor = { version = "0.1.0", path = "../../embassy-executor", feature | |||
| 17 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } | 16 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } |
| 18 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } | 17 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } |
| 19 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], optional = true } | 18 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], optional = true } |
| 20 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } | 19 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt", "msos-descriptor",], optional = true } |
| 21 | embedded-io = "0.4.0" | 20 | embedded-io = "0.4.0" |
| 22 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx126x", "time", "defmt"], optional = true } | 21 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx126x", "time", "defmt"], optional = true } |
| 23 | 22 | ||
| @@ -36,7 +35,3 @@ rand = { version = "0.8.4", default-features = false } | |||
| 36 | embedded-storage = "0.3.0" | 35 | embedded-storage = "0.3.0" |
| 37 | usbd-hid = "0.6.0" | 36 | usbd-hid = "0.6.0" |
| 38 | serde = { version = "1.0.136", default-features = false } | 37 | serde = { version = "1.0.136", default-features = false } |
| 39 | |||
| 40 | [[bin]] | ||
| 41 | name = "usb_serial_winusb" | ||
| 42 | required-features = ["msos-descriptor"] | ||
diff --git a/examples/nrf52840/src/bin/awaitable_timer.rs b/examples/nrf52840/src/bin/awaitable_timer.rs deleted file mode 100644 index b32af236c..000000000 --- a/examples/nrf52840/src/bin/awaitable_timer.rs +++ /dev/null | |||
| @@ -1,26 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::info; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_nrf::interrupt; | ||
| 8 | use embassy_nrf::timer::Timer; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 10 | |||
| 11 | #[embassy_executor::main] | ||
| 12 | async fn main(_spawner: Spawner) { | ||
| 13 | let p = embassy_nrf::init(Default::default()); | ||
| 14 | let mut t = Timer::new_awaitable(p.TIMER0, interrupt::take!(TIMER0)); | ||
| 15 | // default frequency is 1MHz, so this triggers every second | ||
| 16 | t.cc(0).write(1_000_000); | ||
| 17 | // clear the timer value on cc[0] compare match | ||
| 18 | t.cc(0).short_compare_clear(); | ||
| 19 | t.start(); | ||
| 20 | |||
| 21 | loop { | ||
| 22 | // wait for compare match | ||
| 23 | t.cc(0).wait().await; | ||
| 24 | info!("hardware timer tick"); | ||
| 25 | } | ||
| 26 | } | ||
diff --git a/examples/nrf52840/src/bin/buffered_uart.rs b/examples/nrf52840/src/bin/buffered_uart.rs index ea566f4b2..238695371 100644 --- a/examples/nrf52840/src/bin/buffered_uart.rs +++ b/examples/nrf52840/src/bin/buffered_uart.rs | |||
| @@ -4,12 +4,15 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::buffered_uarte::{BufferedUarte, State}; | 7 | use embassy_nrf::buffered_uarte::{self, BufferedUarte}; |
| 8 | use embassy_nrf::{interrupt, uarte}; | 8 | use embassy_nrf::{bind_interrupts, peripherals, uarte}; |
| 9 | use embedded_io::asynch::{BufRead, Write}; | 9 | use embedded_io::asynch::Write; |
| 10 | use futures::pin_mut; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 12 | bind_interrupts!(struct Irqs { | ||
| 13 | UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>; | ||
| 14 | }); | ||
| 15 | |||
| 13 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
| 14 | async fn main(_spawner: Spawner) { | 17 | async fn main(_spawner: Spawner) { |
| 15 | let p = embassy_nrf::init(Default::default()); | 18 | let p = embassy_nrf::init(Default::default()); |
| @@ -20,25 +23,19 @@ async fn main(_spawner: Spawner) { | |||
| 20 | let mut tx_buffer = [0u8; 4096]; | 23 | let mut tx_buffer = [0u8; 4096]; |
| 21 | let mut rx_buffer = [0u8; 4096]; | 24 | let mut rx_buffer = [0u8; 4096]; |
| 22 | 25 | ||
| 23 | let irq = interrupt::take!(UARTE0_UART0); | 26 | let mut u = BufferedUarte::new( |
| 24 | let mut state = State::new(); | ||
| 25 | // Please note - important to have hardware flow control (https://github.com/embassy-rs/embassy/issues/536) | ||
| 26 | let u = BufferedUarte::new( | ||
| 27 | &mut state, | ||
| 28 | p.UARTE0, | 27 | p.UARTE0, |
| 29 | p.TIMER0, | 28 | p.TIMER0, |
| 30 | p.PPI_CH0, | 29 | p.PPI_CH0, |
| 31 | p.PPI_CH1, | 30 | p.PPI_CH1, |
| 32 | irq, | 31 | p.PPI_GROUP0, |
| 32 | Irqs, | ||
| 33 | p.P0_08, | 33 | p.P0_08, |
| 34 | p.P0_06, | 34 | p.P0_06, |
| 35 | p.P0_07, | ||
| 36 | p.P0_05, | ||
| 37 | config, | 35 | config, |
| 38 | &mut rx_buffer, | 36 | &mut rx_buffer, |
| 39 | &mut tx_buffer, | 37 | &mut tx_buffer, |
| 40 | ); | 38 | ); |
| 41 | pin_mut!(u); | ||
| 42 | 39 | ||
| 43 | info!("uarte initialized!"); | 40 | info!("uarte initialized!"); |
| 44 | 41 | ||
diff --git a/examples/nrf52840/src/bin/i2s_effect.rs b/examples/nrf52840/src/bin/i2s_effect.rs index 52d46e4f9..391514d93 100644 --- a/examples/nrf52840/src/bin/i2s_effect.rs +++ b/examples/nrf52840/src/bin/i2s_effect.rs | |||
| @@ -7,7 +7,7 @@ use core::f32::consts::PI; | |||
| 7 | use defmt::{error, info}; | 7 | use defmt::{error, info}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::i2s::{self, Channels, Config, MasterClock, MultiBuffering, Sample as _, SampleWidth, I2S}; | 9 | use embassy_nrf::i2s::{self, Channels, Config, MasterClock, MultiBuffering, Sample as _, SampleWidth, I2S}; |
| 10 | use embassy_nrf::interrupt; | 10 | use embassy_nrf::{bind_interrupts, peripherals}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | type Sample = i16; | 13 | type Sample = i16; |
| @@ -15,6 +15,10 @@ type Sample = i16; | |||
| 15 | const NUM_BUFFERS: usize = 2; | 15 | const NUM_BUFFERS: usize = 2; |
| 16 | const NUM_SAMPLES: usize = 4; | 16 | const NUM_SAMPLES: usize = 4; |
| 17 | 17 | ||
| 18 | bind_interrupts!(struct Irqs { | ||
| 19 | I2S => i2s::InterruptHandler<peripherals::I2S>; | ||
| 20 | }); | ||
| 21 | |||
| 18 | #[embassy_executor::main] | 22 | #[embassy_executor::main] |
| 19 | async fn main(_spawner: Spawner) { | 23 | async fn main(_spawner: Spawner) { |
| 20 | let p = embassy_nrf::init(Default::default()); | 24 | let p = embassy_nrf::init(Default::default()); |
| @@ -28,15 +32,10 @@ async fn main(_spawner: Spawner) { | |||
| 28 | config.sample_width = SampleWidth::_16bit; | 32 | config.sample_width = SampleWidth::_16bit; |
| 29 | config.channels = Channels::MonoLeft; | 33 | config.channels = Channels::MonoLeft; |
| 30 | 34 | ||
| 31 | let irq = interrupt::take!(I2S); | ||
| 32 | let buffers_out = MultiBuffering::<Sample, NUM_BUFFERS, NUM_SAMPLES>::new(); | 35 | let buffers_out = MultiBuffering::<Sample, NUM_BUFFERS, NUM_SAMPLES>::new(); |
| 33 | let buffers_in = MultiBuffering::<Sample, NUM_BUFFERS, NUM_SAMPLES>::new(); | 36 | let buffers_in = MultiBuffering::<Sample, NUM_BUFFERS, NUM_SAMPLES>::new(); |
| 34 | let mut full_duplex_stream = I2S::master(p.I2S, irq, p.P0_25, p.P0_26, p.P0_27, master_clock, config).full_duplex( | 37 | let mut full_duplex_stream = I2S::new_master(p.I2S, Irqs, p.P0_25, p.P0_26, p.P0_27, master_clock, config) |
| 35 | p.P0_29, | 38 | .full_duplex(p.P0_29, p.P0_28, buffers_out, buffers_in); |
| 36 | p.P0_28, | ||
| 37 | buffers_out, | ||
| 38 | buffers_in, | ||
| 39 | ); | ||
| 40 | 39 | ||
| 41 | let mut modulator = SineOsc::new(); | 40 | let mut modulator = SineOsc::new(); |
| 42 | modulator.set_frequency(8.0, 1.0 / sample_rate as f32); | 41 | modulator.set_frequency(8.0, 1.0 / sample_rate as f32); |
diff --git a/examples/nrf52840/src/bin/i2s_monitor.rs b/examples/nrf52840/src/bin/i2s_monitor.rs index 5ebfd9542..4ed597c0d 100644 --- a/examples/nrf52840/src/bin/i2s_monitor.rs +++ b/examples/nrf52840/src/bin/i2s_monitor.rs | |||
| @@ -5,14 +5,18 @@ | |||
| 5 | use defmt::{debug, error, info}; | 5 | use defmt::{debug, error, info}; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, MasterClock, Sample as _, SampleWidth, I2S}; | 7 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, MasterClock, Sample as _, SampleWidth, I2S}; |
| 8 | use embassy_nrf::interrupt; | ||
| 9 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; | 8 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; |
| 9 | use embassy_nrf::{bind_interrupts, peripherals}; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | type Sample = i16; | 12 | type Sample = i16; |
| 13 | 13 | ||
| 14 | const NUM_SAMPLES: usize = 500; | 14 | const NUM_SAMPLES: usize = 500; |
| 15 | 15 | ||
| 16 | bind_interrupts!(struct Irqs { | ||
| 17 | I2S => i2s::InterruptHandler<peripherals::I2S>; | ||
| 18 | }); | ||
| 19 | |||
| 16 | #[embassy_executor::main] | 20 | #[embassy_executor::main] |
| 17 | async fn main(_spawner: Spawner) { | 21 | async fn main(_spawner: Spawner) { |
| 18 | let p = embassy_nrf::init(Default::default()); | 22 | let p = embassy_nrf::init(Default::default()); |
| @@ -26,10 +30,9 @@ async fn main(_spawner: Spawner) { | |||
| 26 | config.sample_width = SampleWidth::_16bit; | 30 | config.sample_width = SampleWidth::_16bit; |
| 27 | config.channels = Channels::MonoLeft; | 31 | config.channels = Channels::MonoLeft; |
| 28 | 32 | ||
| 29 | let irq = interrupt::take!(I2S); | ||
| 30 | let buffers = DoubleBuffering::<Sample, NUM_SAMPLES>::new(); | 33 | let buffers = DoubleBuffering::<Sample, NUM_SAMPLES>::new(); |
| 31 | let mut input_stream = | 34 | let mut input_stream = |
| 32 | I2S::master(p.I2S, irq, p.P0_25, p.P0_26, p.P0_27, master_clock, config).input(p.P0_29, buffers); | 35 | I2S::new_master(p.I2S, Irqs, p.P0_25, p.P0_26, p.P0_27, master_clock, config).input(p.P0_29, buffers); |
| 33 | 36 | ||
| 34 | // Configure the PWM to use the pins corresponding to the RGB leds | 37 | // Configure the PWM to use the pins corresponding to the RGB leds |
| 35 | let mut pwm = SimplePwm::new_3ch(p.PWM0, p.P0_23, p.P0_22, p.P0_24); | 38 | let mut pwm = SimplePwm::new_3ch(p.PWM0, p.P0_23, p.P0_22, p.P0_24); |
diff --git a/examples/nrf52840/src/bin/i2s_waveform.rs b/examples/nrf52840/src/bin/i2s_waveform.rs index eda930677..f2c1166b1 100644 --- a/examples/nrf52840/src/bin/i2s_waveform.rs +++ b/examples/nrf52840/src/bin/i2s_waveform.rs | |||
| @@ -7,13 +7,17 @@ use core::f32::consts::PI; | |||
| 7 | use defmt::{error, info}; | 7 | use defmt::{error, info}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, MasterClock, Sample as _, SampleWidth, I2S}; | 9 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, MasterClock, Sample as _, SampleWidth, I2S}; |
| 10 | use embassy_nrf::interrupt; | 10 | use embassy_nrf::{bind_interrupts, peripherals}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | type Sample = i16; | 13 | type Sample = i16; |
| 14 | 14 | ||
| 15 | const NUM_SAMPLES: usize = 50; | 15 | const NUM_SAMPLES: usize = 50; |
| 16 | 16 | ||
| 17 | bind_interrupts!(struct Irqs { | ||
| 18 | I2S => i2s::InterruptHandler<peripherals::I2S>; | ||
| 19 | }); | ||
| 20 | |||
| 17 | #[embassy_executor::main] | 21 | #[embassy_executor::main] |
| 18 | async fn main(_spawner: Spawner) { | 22 | async fn main(_spawner: Spawner) { |
| 19 | let p = embassy_nrf::init(Default::default()); | 23 | let p = embassy_nrf::init(Default::default()); |
| @@ -27,10 +31,9 @@ async fn main(_spawner: Spawner) { | |||
| 27 | config.sample_width = SampleWidth::_16bit; | 31 | config.sample_width = SampleWidth::_16bit; |
| 28 | config.channels = Channels::MonoLeft; | 32 | config.channels = Channels::MonoLeft; |
| 29 | 33 | ||
| 30 | let irq = interrupt::take!(I2S); | ||
| 31 | let buffers = DoubleBuffering::<Sample, NUM_SAMPLES>::new(); | 34 | let buffers = DoubleBuffering::<Sample, NUM_SAMPLES>::new(); |
| 32 | let mut output_stream = | 35 | let mut output_stream = |
| 33 | I2S::master(p.I2S, irq, p.P0_25, p.P0_26, p.P0_27, master_clock, config).output(p.P0_28, buffers); | 36 | I2S::new_master(p.I2S, Irqs, p.P0_25, p.P0_26, p.P0_27, master_clock, config).output(p.P0_28, buffers); |
| 34 | 37 | ||
| 35 | let mut waveform = Waveform::new(1.0 / sample_rate as f32); | 38 | let mut waveform = Waveform::new(1.0 / sample_rate as f32); |
| 36 | 39 | ||
diff --git a/examples/nrf52840/src/bin/lora_p2p_report.rs b/examples/nrf52840/src/bin/lora_p2p_report.rs index d512b83f6..e24f0db03 100644 --- a/examples/nrf52840/src/bin/lora_p2p_report.rs +++ b/examples/nrf52840/src/bin/lora_p2p_report.rs | |||
| @@ -11,11 +11,15 @@ use defmt::*; | |||
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_lora::sx126x::*; | 12 | use embassy_lora::sx126x::*; |
| 13 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; | 13 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; |
| 14 | use embassy_nrf::{interrupt, spim}; | 14 | use embassy_nrf::{bind_interrupts, peripherals, spim}; |
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 16 | use lorawan_device::async_device::radio::{Bandwidth, CodingRate, PhyRxTx, RfConfig, SpreadingFactor}; | 16 | use lorawan_device::async_device::radio::{Bandwidth, CodingRate, PhyRxTx, RfConfig, SpreadingFactor}; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 18 | ||
| 19 | bind_interrupts!(struct Irqs { | ||
| 20 | SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>; | ||
| 21 | }); | ||
| 22 | |||
| 19 | #[embassy_executor::main] | 23 | #[embassy_executor::main] |
| 20 | async fn main(_spawner: Spawner) { | 24 | async fn main(_spawner: Spawner) { |
| 21 | let p = embassy_nrf::init(Default::default()); | 25 | let p = embassy_nrf::init(Default::default()); |
| @@ -23,8 +27,7 @@ async fn main(_spawner: Spawner) { | |||
| 23 | spi_config.frequency = spim::Frequency::M16; | 27 | spi_config.frequency = spim::Frequency::M16; |
| 24 | 28 | ||
| 25 | let mut radio = { | 29 | let mut radio = { |
| 26 | let irq = interrupt::take!(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1); | 30 | let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config); |
| 27 | let spim = spim::Spim::new(p.TWISPI1, irq, p.P1_11, p.P1_13, p.P1_12, spi_config); | ||
| 28 | 31 | ||
| 29 | let cs = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard); | 32 | let cs = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard); |
| 30 | let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard); | 33 | let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard); |
diff --git a/examples/nrf52840/src/bin/lora_p2p_sense.rs b/examples/nrf52840/src/bin/lora_p2p_sense.rs index b9768874b..b6f41ffcc 100644 --- a/examples/nrf52840/src/bin/lora_p2p_sense.rs +++ b/examples/nrf52840/src/bin/lora_p2p_sense.rs | |||
| @@ -12,13 +12,17 @@ use defmt::*; | |||
| 12 | use embassy_executor::Spawner; | 12 | use embassy_executor::Spawner; |
| 13 | use embassy_lora::sx126x::*; | 13 | use embassy_lora::sx126x::*; |
| 14 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; | 14 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; |
| 15 | use embassy_nrf::{interrupt, spim}; | 15 | use embassy_nrf::{bind_interrupts, peripherals, spim}; |
| 16 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 16 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 17 | use embassy_sync::pubsub::{PubSubChannel, Publisher}; | 17 | use embassy_sync::pubsub::{PubSubChannel, Publisher}; |
| 18 | use embassy_time::{Duration, Timer}; | 18 | use embassy_time::{Duration, Timer}; |
| 19 | use lorawan_device::async_device::radio::{Bandwidth, CodingRate, PhyRxTx, RfConfig, SpreadingFactor, TxConfig}; | 19 | use lorawan_device::async_device::radio::{Bandwidth, CodingRate, PhyRxTx, RfConfig, SpreadingFactor, TxConfig}; |
| 20 | use {defmt_rtt as _, panic_probe as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _, panic_probe as _}; |
| 21 | 21 | ||
| 22 | bind_interrupts!(struct Irqs { | ||
| 23 | SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>; | ||
| 24 | }); | ||
| 25 | |||
| 22 | // Message bus: queue of 2, 1 subscriber (Lora P2P), 2 publishers (temperature, motion detection) | 26 | // Message bus: queue of 2, 1 subscriber (Lora P2P), 2 publishers (temperature, motion detection) |
| 23 | static MESSAGE_BUS: PubSubChannel<CriticalSectionRawMutex, Message, 2, 1, 2> = PubSubChannel::new(); | 27 | static MESSAGE_BUS: PubSubChannel<CriticalSectionRawMutex, Message, 2, 1, 2> = PubSubChannel::new(); |
| 24 | 28 | ||
| @@ -58,8 +62,7 @@ async fn main(spawner: Spawner) { | |||
| 58 | spi_config.frequency = spim::Frequency::M16; | 62 | spi_config.frequency = spim::Frequency::M16; |
| 59 | 63 | ||
| 60 | let mut radio = { | 64 | let mut radio = { |
| 61 | let irq = interrupt::take!(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1); | 65 | let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config); |
| 62 | let spim = spim::Spim::new(p.TWISPI1, irq, p.P1_11, p.P1_13, p.P1_12, spi_config); | ||
| 63 | 66 | ||
| 64 | let cs = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard); | 67 | let cs = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard); |
| 65 | let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard); | 68 | let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard); |
diff --git a/examples/nrf52840/src/bin/multiprio.rs b/examples/nrf52840/src/bin/multiprio.rs index 25806ae48..851e189ea 100644 --- a/examples/nrf52840/src/bin/multiprio.rs +++ b/examples/nrf52840/src/bin/multiprio.rs | |||
| @@ -57,11 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 60 | use cortex_m_rt::entry; | 63 | use cortex_m_rt::entry; |
| 61 | use defmt::{info, unwrap}; | 64 | use defmt::{info, unwrap}; |
| 62 | use embassy_nrf::executor::{Executor, InterruptExecutor}; | 65 | use embassy_nrf::executor::{Executor, InterruptExecutor}; |
| 63 | use embassy_nrf::interrupt; | 66 | use embassy_nrf::interrupt; |
| 64 | use embassy_nrf::interrupt::InterruptExt; | 67 | use embassy_nrf::pac::Interrupt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 68 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use static_cell::StaticCell; | 69 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 70 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -108,28 +111,35 @@ async fn run_low() { | |||
| 108 | } | 111 | } |
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::SWI1_EGU1>> = StaticCell::new(); | 114 | static EXECUTOR_HIGH: InterruptExecutor = InterruptExecutor::new(); |
| 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::SWI0_EGU0>> = StaticCell::new(); | 115 | static EXECUTOR_MED: InterruptExecutor = InterruptExecutor::new(); |
| 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); | 116 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 117 | ||
| 118 | #[interrupt] | ||
| 119 | unsafe fn SWI1_EGU1() { | ||
| 120 | EXECUTOR_HIGH.on_interrupt() | ||
| 121 | } | ||
| 122 | |||
| 123 | #[interrupt] | ||
| 124 | unsafe fn SWI0_EGU0() { | ||
| 125 | EXECUTOR_MED.on_interrupt() | ||
| 126 | } | ||
| 127 | |||
| 115 | #[entry] | 128 | #[entry] |
| 116 | fn main() -> ! { | 129 | fn main() -> ! { |
| 117 | info!("Hello World!"); | 130 | info!("Hello World!"); |
| 118 | 131 | ||
| 119 | let _p = embassy_nrf::init(Default::default()); | 132 | let _p = embassy_nrf::init(Default::default()); |
| 133 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 120 | 134 | ||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 135 | // High-priority executor: SWI1_EGU1, priority level 6 |
| 122 | let irq = interrupt::take!(SWI1_EGU1); | 136 | unsafe { nvic.set_priority(Interrupt::SWI1_EGU1, 6 << 5) }; |
| 123 | irq.set_priority(interrupt::Priority::P6); | 137 | let spawner = EXECUTOR_HIGH.start(Interrupt::SWI1_EGU1); |
| 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); | ||
| 125 | let spawner = executor.start(); | ||
| 126 | unwrap!(spawner.spawn(run_high())); | 138 | unwrap!(spawner.spawn(run_high())); |
| 127 | 139 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 140 | // Medium-priority executor: SWI0_EGU0, priority level 7 |
| 129 | let irq = interrupt::take!(SWI0_EGU0); | 141 | unsafe { nvic.set_priority(Interrupt::SWI0_EGU0, 7 << 5) }; |
| 130 | irq.set_priority(interrupt::Priority::P7); | 142 | let spawner = EXECUTOR_MED.start(Interrupt::SWI0_EGU0); |
| 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); | ||
| 132 | let spawner = executor.start(); | ||
| 133 | unwrap!(spawner.spawn(run_med())); | 143 | unwrap!(spawner.spawn(run_med())); |
| 134 | 144 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 145 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/nrf52840/src/bin/pdm.rs b/examples/nrf52840/src/bin/pdm.rs index 7388580fb..6b41320ca 100644 --- a/examples/nrf52840/src/bin/pdm.rs +++ b/examples/nrf52840/src/bin/pdm.rs | |||
| @@ -4,16 +4,20 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::interrupt; | 7 | use embassy_nrf::pdm::{self, Config, Pdm}; |
| 8 | use embassy_nrf::pdm::{Config, Pdm}; | 8 | use embassy_nrf::{bind_interrupts, peripherals}; |
| 9 | use embassy_time::{Duration, Timer}; | 9 | use embassy_time::{Duration, Timer}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | bind_interrupts!(struct Irqs { | ||
| 13 | PDM => pdm::InterruptHandler<peripherals::PDM>; | ||
| 14 | }); | ||
| 15 | |||
| 12 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
| 13 | async fn main(_p: Spawner) { | 17 | async fn main(_p: Spawner) { |
| 14 | let p = embassy_nrf::init(Default::default()); | 18 | let p = embassy_nrf::init(Default::default()); |
| 15 | let config = Config::default(); | 19 | let config = Config::default(); |
| 16 | let mut pdm = Pdm::new(p.PDM, interrupt::take!(PDM), p.P0_01, p.P0_00, config); | 20 | let mut pdm = Pdm::new(p.PDM, Irqs, p.P0_01, p.P0_00, config); |
| 17 | 21 | ||
| 18 | loop { | 22 | loop { |
| 19 | pdm.start().await; | 23 | pdm.start().await; |
diff --git a/examples/nrf52840/src/bin/qdec.rs b/examples/nrf52840/src/bin/qdec.rs index 600bba07a..59783d312 100644 --- a/examples/nrf52840/src/bin/qdec.rs +++ b/examples/nrf52840/src/bin/qdec.rs | |||
| @@ -4,16 +4,19 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::interrupt; | ||
| 8 | use embassy_nrf::qdec::{self, Qdec}; | 7 | use embassy_nrf::qdec::{self, Qdec}; |
| 8 | use embassy_nrf::{bind_interrupts, peripherals}; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 10 | ||
| 11 | bind_interrupts!(struct Irqs { | ||
| 12 | QDEC => qdec::InterruptHandler<peripherals::QDEC>; | ||
| 13 | }); | ||
| 14 | |||
| 11 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
| 12 | async fn main(_spawner: Spawner) { | 16 | async fn main(_spawner: Spawner) { |
| 13 | let p = embassy_nrf::init(Default::default()); | 17 | let p = embassy_nrf::init(Default::default()); |
| 14 | let irq = interrupt::take!(QDEC); | ||
| 15 | let config = qdec::Config::default(); | 18 | let config = qdec::Config::default(); |
| 16 | let mut rotary_enc = Qdec::new(p.QDEC, irq, p.P0_31, p.P0_30, config); | 19 | let mut rotary_enc = Qdec::new(p.QDEC, Irqs, p.P0_31, p.P0_30, config); |
| 17 | 20 | ||
| 18 | info!("Turn rotary encoder!"); | 21 | info!("Turn rotary encoder!"); |
| 19 | let mut value = 0; | 22 | let mut value = 0; |
diff --git a/examples/nrf52840/src/bin/qspi.rs b/examples/nrf52840/src/bin/qspi.rs index bdcf710b8..9e8a01f4e 100644 --- a/examples/nrf52840/src/bin/qspi.rs +++ b/examples/nrf52840/src/bin/qspi.rs | |||
| @@ -4,7 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::{assert_eq, info, unwrap}; | 5 | use defmt::{assert_eq, info, unwrap}; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::{interrupt, qspi}; | 7 | use embassy_nrf::qspi::Frequency; |
| 8 | use embassy_nrf::{bind_interrupts, peripherals, qspi}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 10 | ||
| 10 | const PAGE_SIZE: usize = 4096; | 11 | const PAGE_SIZE: usize = 4096; |
| @@ -14,18 +15,23 @@ const PAGE_SIZE: usize = 4096; | |||
| 14 | #[repr(C, align(4))] | 15 | #[repr(C, align(4))] |
| 15 | struct AlignedBuf([u8; 4096]); | 16 | struct AlignedBuf([u8; 4096]); |
| 16 | 17 | ||
| 18 | bind_interrupts!(struct Irqs { | ||
| 19 | QSPI => qspi::InterruptHandler<peripherals::QSPI>; | ||
| 20 | }); | ||
| 21 | |||
| 17 | #[embassy_executor::main] | 22 | #[embassy_executor::main] |
| 18 | async fn main(_spawner: Spawner) { | 23 | async fn main(_spawner: Spawner) { |
| 19 | let p = embassy_nrf::init(Default::default()); | 24 | let p = embassy_nrf::init(Default::default()); |
| 20 | // Config for the MX25R64 present in the nRF52840 DK | 25 | // Config for the MX25R64 present in the nRF52840 DK |
| 21 | let mut config = qspi::Config::default(); | 26 | let mut config = qspi::Config::default(); |
| 27 | config.capacity = 8 * 1024 * 1024; // 8 MB | ||
| 28 | config.frequency = Frequency::M32; | ||
| 22 | config.read_opcode = qspi::ReadOpcode::READ4IO; | 29 | config.read_opcode = qspi::ReadOpcode::READ4IO; |
| 23 | config.write_opcode = qspi::WriteOpcode::PP4IO; | 30 | config.write_opcode = qspi::WriteOpcode::PP4IO; |
| 24 | config.write_page_size = qspi::WritePageSize::_256BYTES; | 31 | config.write_page_size = qspi::WritePageSize::_256BYTES; |
| 25 | 32 | ||
| 26 | let irq = interrupt::take!(QSPI); | 33 | let mut q = qspi::Qspi::new( |
| 27 | let mut q: qspi::Qspi<_, 67108864> = qspi::Qspi::new( | 34 | p.QSPI, Irqs, p.P0_19, p.P0_17, p.P0_20, p.P0_21, p.P0_22, p.P0_23, config, |
| 28 | p.QSPI, irq, p.P0_19, p.P0_17, p.P0_20, p.P0_21, p.P0_22, p.P0_23, config, | ||
| 29 | ); | 35 | ); |
| 30 | 36 | ||
| 31 | let mut id = [1; 3]; | 37 | let mut id = [1; 3]; |
| @@ -52,23 +58,23 @@ async fn main(_spawner: Spawner) { | |||
| 52 | 58 | ||
| 53 | for i in 0..8 { | 59 | for i in 0..8 { |
| 54 | info!("page {:?}: erasing... ", i); | 60 | info!("page {:?}: erasing... ", i); |
| 55 | unwrap!(q.erase(i * PAGE_SIZE).await); | 61 | unwrap!(q.erase(i * PAGE_SIZE as u32).await); |
| 56 | 62 | ||
| 57 | for j in 0..PAGE_SIZE { | 63 | for j in 0..PAGE_SIZE { |
| 58 | buf.0[j] = pattern((j + i * PAGE_SIZE) as u32); | 64 | buf.0[j] = pattern((j as u32 + i * PAGE_SIZE as u32) as u32); |
| 59 | } | 65 | } |
| 60 | 66 | ||
| 61 | info!("programming..."); | 67 | info!("programming..."); |
| 62 | unwrap!(q.write(i * PAGE_SIZE, &buf.0).await); | 68 | unwrap!(q.write(i * PAGE_SIZE as u32, &buf.0).await); |
| 63 | } | 69 | } |
| 64 | 70 | ||
| 65 | for i in 0..8 { | 71 | for i in 0..8 { |
| 66 | info!("page {:?}: reading... ", i); | 72 | info!("page {:?}: reading... ", i); |
| 67 | unwrap!(q.read(i * PAGE_SIZE, &mut buf.0).await); | 73 | unwrap!(q.read(i * PAGE_SIZE as u32, &mut buf.0).await); |
| 68 | 74 | ||
| 69 | info!("verifying..."); | 75 | info!("verifying..."); |
| 70 | for j in 0..PAGE_SIZE { | 76 | for j in 0..PAGE_SIZE { |
| 71 | assert_eq!(buf.0[j], pattern((j + i * PAGE_SIZE) as u32)); | 77 | assert_eq!(buf.0[j], pattern((j as u32 + i * PAGE_SIZE as u32) as u32)); |
| 72 | } | 78 | } |
| 73 | } | 79 | } |
| 74 | 80 | ||
diff --git a/examples/nrf52840/src/bin/qspi_lowpower.rs b/examples/nrf52840/src/bin/qspi_lowpower.rs index 9341a2376..22a5c0c6d 100644 --- a/examples/nrf52840/src/bin/qspi_lowpower.rs +++ b/examples/nrf52840/src/bin/qspi_lowpower.rs | |||
| @@ -6,7 +6,8 @@ use core::mem; | |||
| 6 | 6 | ||
| 7 | use defmt::{info, unwrap}; | 7 | use defmt::{info, unwrap}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::{interrupt, qspi}; | 9 | use embassy_nrf::qspi::Frequency; |
| 10 | use embassy_nrf::{bind_interrupts, peripherals, qspi}; | ||
| 10 | use embassy_time::{Duration, Timer}; | 11 | use embassy_time::{Duration, Timer}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 13 | ||
| @@ -15,14 +16,19 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 15 | #[repr(C, align(4))] | 16 | #[repr(C, align(4))] |
| 16 | struct AlignedBuf([u8; 64]); | 17 | struct AlignedBuf([u8; 64]); |
| 17 | 18 | ||
| 19 | bind_interrupts!(struct Irqs { | ||
| 20 | QSPI => qspi::InterruptHandler<peripherals::QSPI>; | ||
| 21 | }); | ||
| 22 | |||
| 18 | #[embassy_executor::main] | 23 | #[embassy_executor::main] |
| 19 | async fn main(_p: Spawner) { | 24 | async fn main(_p: Spawner) { |
| 20 | let mut p = embassy_nrf::init(Default::default()); | 25 | let mut p = embassy_nrf::init(Default::default()); |
| 21 | let mut irq = interrupt::take!(QSPI); | ||
| 22 | 26 | ||
| 23 | loop { | 27 | loop { |
| 24 | // Config for the MX25R64 present in the nRF52840 DK | 28 | // Config for the MX25R64 present in the nRF52840 DK |
| 25 | let mut config = qspi::Config::default(); | 29 | let mut config = qspi::Config::default(); |
| 30 | config.capacity = 8 * 1024 * 1024; // 8 MB | ||
| 31 | config.frequency = Frequency::M32; | ||
| 26 | config.read_opcode = qspi::ReadOpcode::READ4IO; | 32 | config.read_opcode = qspi::ReadOpcode::READ4IO; |
| 27 | config.write_opcode = qspi::WriteOpcode::PP4IO; | 33 | config.write_opcode = qspi::WriteOpcode::PP4IO; |
| 28 | config.write_page_size = qspi::WritePageSize::_256BYTES; | 34 | config.write_page_size = qspi::WritePageSize::_256BYTES; |
| @@ -31,9 +37,9 @@ async fn main(_p: Spawner) { | |||
| 31 | exit_time: 3, // tRDP = 35uS | 37 | exit_time: 3, // tRDP = 35uS |
| 32 | }); | 38 | }); |
| 33 | 39 | ||
| 34 | let mut q: qspi::Qspi<_, 67108864> = qspi::Qspi::new( | 40 | let mut q = qspi::Qspi::new( |
| 35 | &mut p.QSPI, | 41 | &mut p.QSPI, |
| 36 | &mut irq, | 42 | Irqs, |
| 37 | &mut p.P0_19, | 43 | &mut p.P0_19, |
| 38 | &mut p.P0_17, | 44 | &mut p.P0_17, |
| 39 | &mut p.P0_20, | 45 | &mut p.P0_20, |
diff --git a/examples/nrf52840/src/bin/rng.rs b/examples/nrf52840/src/bin/rng.rs index 647073949..855743f50 100644 --- a/examples/nrf52840/src/bin/rng.rs +++ b/examples/nrf52840/src/bin/rng.rs | |||
| @@ -3,15 +3,19 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_nrf::interrupt; | ||
| 7 | use embassy_nrf::rng::Rng; | 6 | use embassy_nrf::rng::Rng; |
| 7 | use embassy_nrf::{bind_interrupts, peripherals, rng}; | ||
| 8 | use rand::Rng as _; | 8 | use rand::Rng as _; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 10 | ||
| 11 | bind_interrupts!(struct Irqs { | ||
| 12 | RNG => rng::InterruptHandler<peripherals::RNG>; | ||
| 13 | }); | ||
| 14 | |||
| 11 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
| 12 | async fn main(_spawner: Spawner) { | 16 | async fn main(_spawner: Spawner) { |
| 13 | let p = embassy_nrf::init(Default::default()); | 17 | let p = embassy_nrf::init(Default::default()); |
| 14 | let mut rng = Rng::new(p.RNG, interrupt::take!(RNG)); | 18 | let mut rng = Rng::new(p.RNG, Irqs); |
| 15 | 19 | ||
| 16 | // Async API | 20 | // Async API |
| 17 | let mut bytes = [0; 4]; | 21 | let mut bytes = [0; 4]; |
diff --git a/examples/nrf52840/src/bin/saadc.rs b/examples/nrf52840/src/bin/saadc.rs index 7cf588090..ffd9a7f4b 100644 --- a/examples/nrf52840/src/bin/saadc.rs +++ b/examples/nrf52840/src/bin/saadc.rs | |||
| @@ -4,17 +4,21 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::interrupt; | ||
| 8 | use embassy_nrf::saadc::{ChannelConfig, Config, Saadc}; | 7 | use embassy_nrf::saadc::{ChannelConfig, Config, Saadc}; |
| 8 | use embassy_nrf::{bind_interrupts, saadc}; | ||
| 9 | use embassy_time::{Duration, Timer}; | 9 | use embassy_time::{Duration, Timer}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | bind_interrupts!(struct Irqs { | ||
| 13 | SAADC => saadc::InterruptHandler; | ||
| 14 | }); | ||
| 15 | |||
| 12 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
| 13 | async fn main(_p: Spawner) { | 17 | async fn main(_p: Spawner) { |
| 14 | let mut p = embassy_nrf::init(Default::default()); | 18 | let mut p = embassy_nrf::init(Default::default()); |
| 15 | let config = Config::default(); | 19 | let config = Config::default(); |
| 16 | let channel_config = ChannelConfig::single_ended(&mut p.P0_02); | 20 | let channel_config = ChannelConfig::single_ended(&mut p.P0_02); |
| 17 | let mut saadc = Saadc::new(p.SAADC, interrupt::take!(SAADC), config, [channel_config]); | 21 | let mut saadc = Saadc::new(p.SAADC, Irqs, config, [channel_config]); |
| 18 | 22 | ||
| 19 | loop { | 23 | loop { |
| 20 | let mut buf = [0; 1]; | 24 | let mut buf = [0; 1]; |
diff --git a/examples/nrf52840/src/bin/saadc_continuous.rs b/examples/nrf52840/src/bin/saadc_continuous.rs index 2551d15fd..a25e17465 100644 --- a/examples/nrf52840/src/bin/saadc_continuous.rs +++ b/examples/nrf52840/src/bin/saadc_continuous.rs | |||
| @@ -4,14 +4,18 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::interrupt; | ||
| 8 | use embassy_nrf::saadc::{CallbackResult, ChannelConfig, Config, Saadc}; | 7 | use embassy_nrf::saadc::{CallbackResult, ChannelConfig, Config, Saadc}; |
| 9 | use embassy_nrf::timer::Frequency; | 8 | use embassy_nrf::timer::Frequency; |
| 9 | use embassy_nrf::{bind_interrupts, saadc}; | ||
| 10 | use embassy_time::Duration; | 10 | use embassy_time::Duration; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | // Demonstrates both continuous sampling and scanning multiple channels driven by a PPI linked timer | 13 | // Demonstrates both continuous sampling and scanning multiple channels driven by a PPI linked timer |
| 14 | 14 | ||
| 15 | bind_interrupts!(struct Irqs { | ||
| 16 | SAADC => saadc::InterruptHandler; | ||
| 17 | }); | ||
| 18 | |||
| 15 | #[embassy_executor::main] | 19 | #[embassy_executor::main] |
| 16 | async fn main(_p: Spawner) { | 20 | async fn main(_p: Spawner) { |
| 17 | let mut p = embassy_nrf::init(Default::default()); | 21 | let mut p = embassy_nrf::init(Default::default()); |
| @@ -21,7 +25,7 @@ async fn main(_p: Spawner) { | |||
| 21 | let channel_3_config = ChannelConfig::single_ended(&mut p.P0_04); | 25 | let channel_3_config = ChannelConfig::single_ended(&mut p.P0_04); |
| 22 | let mut saadc = Saadc::new( | 26 | let mut saadc = Saadc::new( |
| 23 | p.SAADC, | 27 | p.SAADC, |
| 24 | interrupt::take!(SAADC), | 28 | Irqs, |
| 25 | config, | 29 | config, |
| 26 | [channel_1_config, channel_2_config, channel_3_config], | 30 | [channel_1_config, channel_2_config, channel_3_config], |
| 27 | ); | 31 | ); |
diff --git a/examples/nrf52840/src/bin/spim.rs b/examples/nrf52840/src/bin/spim.rs index 132e01660..9d1843a8f 100644 --- a/examples/nrf52840/src/bin/spim.rs +++ b/examples/nrf52840/src/bin/spim.rs | |||
| @@ -5,9 +5,13 @@ | |||
| 5 | use defmt::{info, unwrap}; | 5 | use defmt::{info, unwrap}; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 7 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
| 8 | use embassy_nrf::{interrupt, spim}; | 8 | use embassy_nrf::{bind_interrupts, peripherals, spim}; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 10 | ||
| 11 | bind_interrupts!(struct Irqs { | ||
| 12 | SPIM3 => spim::InterruptHandler<peripherals::SPI3>; | ||
| 13 | }); | ||
| 14 | |||
| 11 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
| 12 | async fn main(_spawner: Spawner) { | 16 | async fn main(_spawner: Spawner) { |
| 13 | let p = embassy_nrf::init(Default::default()); | 17 | let p = embassy_nrf::init(Default::default()); |
| @@ -16,8 +20,7 @@ async fn main(_spawner: Spawner) { | |||
| 16 | let mut config = spim::Config::default(); | 20 | let mut config = spim::Config::default(); |
| 17 | config.frequency = spim::Frequency::M16; | 21 | config.frequency = spim::Frequency::M16; |
| 18 | 22 | ||
| 19 | let irq = interrupt::take!(SPIM3); | 23 | let mut spim = spim::Spim::new(p.SPI3, Irqs, p.P0_29, p.P0_28, p.P0_30, config); |
| 20 | let mut spim = spim::Spim::new(p.SPI3, irq, p.P0_29, p.P0_28, p.P0_30, config); | ||
| 21 | 24 | ||
| 22 | let mut ncs = Output::new(p.P0_31, Level::High, OutputDrive::Standard); | 25 | let mut ncs = Output::new(p.P0_31, Level::High, OutputDrive::Standard); |
| 23 | 26 | ||
diff --git a/examples/nrf52840/src/bin/spis.rs b/examples/nrf52840/src/bin/spis.rs index fe3b0c53d..77b6e8b64 100644 --- a/examples/nrf52840/src/bin/spis.rs +++ b/examples/nrf52840/src/bin/spis.rs | |||
| @@ -4,17 +4,20 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::interrupt; | ||
| 8 | use embassy_nrf::spis::{Config, Spis}; | 7 | use embassy_nrf::spis::{Config, Spis}; |
| 8 | use embassy_nrf::{bind_interrupts, peripherals, spis}; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 10 | ||
| 11 | bind_interrupts!(struct Irqs { | ||
| 12 | SPIM2_SPIS2_SPI2 => spis::InterruptHandler<peripherals::SPI2>; | ||
| 13 | }); | ||
| 14 | |||
| 11 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
| 12 | async fn main(_spawner: Spawner) { | 16 | async fn main(_spawner: Spawner) { |
| 13 | let p = embassy_nrf::init(Default::default()); | 17 | let p = embassy_nrf::init(Default::default()); |
| 14 | info!("Running!"); | 18 | info!("Running!"); |
| 15 | 19 | ||
| 16 | let irq = interrupt::take!(SPIM2_SPIS2_SPI2); | 20 | let mut spis = Spis::new(p.SPI2, Irqs, p.P0_31, p.P0_29, p.P0_28, p.P0_30, Config::default()); |
| 17 | let mut spis = Spis::new(p.SPI2, irq, p.P0_31, p.P0_29, p.P0_28, p.P0_30, Config::default()); | ||
| 18 | 21 | ||
| 19 | loop { | 22 | loop { |
| 20 | let mut rx_buf = [0_u8; 64]; | 23 | let mut rx_buf = [0_u8; 64]; |
diff --git a/examples/nrf52840/src/bin/temp.rs b/examples/nrf52840/src/bin/temp.rs index b06ac709e..70957548f 100644 --- a/examples/nrf52840/src/bin/temp.rs +++ b/examples/nrf52840/src/bin/temp.rs | |||
| @@ -4,16 +4,19 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::interrupt; | ||
| 8 | use embassy_nrf::temp::Temp; | 7 | use embassy_nrf::temp::Temp; |
| 8 | use embassy_nrf::{bind_interrupts, temp}; | ||
| 9 | use embassy_time::{Duration, Timer}; | 9 | use embassy_time::{Duration, Timer}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | bind_interrupts!(struct Irqs { | ||
| 13 | TEMP => temp::InterruptHandler; | ||
| 14 | }); | ||
| 15 | |||
| 12 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
| 13 | async fn main(_spawner: Spawner) { | 17 | async fn main(_spawner: Spawner) { |
| 14 | let p = embassy_nrf::init(Default::default()); | 18 | let p = embassy_nrf::init(Default::default()); |
| 15 | let irq = interrupt::take!(TEMP); | 19 | let mut temp = Temp::new(p.TEMP, Irqs); |
| 16 | let mut temp = Temp::new(p.TEMP, irq); | ||
| 17 | 20 | ||
| 18 | loop { | 21 | loop { |
| 19 | let value = temp.read().await; | 22 | let value = temp.read().await; |
diff --git a/examples/nrf52840/src/bin/twim.rs b/examples/nrf52840/src/bin/twim.rs index a027cc1e7..959e3a4be 100644 --- a/examples/nrf52840/src/bin/twim.rs +++ b/examples/nrf52840/src/bin/twim.rs | |||
| @@ -8,19 +8,22 @@ | |||
| 8 | 8 | ||
| 9 | use defmt::*; | 9 | use defmt::*; |
| 10 | use embassy_executor::Spawner; | 10 | use embassy_executor::Spawner; |
| 11 | use embassy_nrf::interrupt; | ||
| 12 | use embassy_nrf::twim::{self, Twim}; | 11 | use embassy_nrf::twim::{self, Twim}; |
| 12 | use embassy_nrf::{bind_interrupts, peripherals}; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | const ADDRESS: u8 = 0x50; | 15 | const ADDRESS: u8 = 0x50; |
| 16 | 16 | ||
| 17 | bind_interrupts!(struct Irqs { | ||
| 18 | SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0 => twim::InterruptHandler<peripherals::TWISPI0>; | ||
| 19 | }); | ||
| 20 | |||
| 17 | #[embassy_executor::main] | 21 | #[embassy_executor::main] |
| 18 | async fn main(_spawner: Spawner) { | 22 | async fn main(_spawner: Spawner) { |
| 19 | let p = embassy_nrf::init(Default::default()); | 23 | let p = embassy_nrf::init(Default::default()); |
| 20 | info!("Initializing TWI..."); | 24 | info!("Initializing TWI..."); |
| 21 | let config = twim::Config::default(); | 25 | let config = twim::Config::default(); |
| 22 | let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); | 26 | let mut twi = Twim::new(p.TWISPI0, Irqs, p.P0_03, p.P0_04, config); |
| 23 | let mut twi = Twim::new(p.TWISPI0, irq, p.P0_03, p.P0_04, config); | ||
| 24 | 27 | ||
| 25 | info!("Reading..."); | 28 | info!("Reading..."); |
| 26 | 29 | ||
diff --git a/examples/nrf52840/src/bin/twim_lowpower.rs b/examples/nrf52840/src/bin/twim_lowpower.rs index e30cc9688..0970d3c3c 100644 --- a/examples/nrf52840/src/bin/twim_lowpower.rs +++ b/examples/nrf52840/src/bin/twim_lowpower.rs | |||
| @@ -12,25 +12,28 @@ use core::mem; | |||
| 12 | 12 | ||
| 13 | use defmt::*; | 13 | use defmt::*; |
| 14 | use embassy_executor::Spawner; | 14 | use embassy_executor::Spawner; |
| 15 | use embassy_nrf::interrupt; | ||
| 16 | use embassy_nrf::twim::{self, Twim}; | 15 | use embassy_nrf::twim::{self, Twim}; |
| 16 | use embassy_nrf::{bind_interrupts, peripherals}; | ||
| 17 | use embassy_time::{Duration, Timer}; | 17 | use embassy_time::{Duration, Timer}; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| 19 | 19 | ||
| 20 | const ADDRESS: u8 = 0x50; | 20 | const ADDRESS: u8 = 0x50; |
| 21 | 21 | ||
| 22 | bind_interrupts!(struct Irqs { | ||
| 23 | SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0 => twim::InterruptHandler<peripherals::TWISPI0>; | ||
| 24 | }); | ||
| 25 | |||
| 22 | #[embassy_executor::main] | 26 | #[embassy_executor::main] |
| 23 | async fn main(_p: Spawner) { | 27 | async fn main(_p: Spawner) { |
| 24 | let mut p = embassy_nrf::init(Default::default()); | 28 | let mut p = embassy_nrf::init(Default::default()); |
| 25 | info!("Started!"); | 29 | info!("Started!"); |
| 26 | let mut irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); | ||
| 27 | 30 | ||
| 28 | loop { | 31 | loop { |
| 29 | info!("Initializing TWI..."); | 32 | info!("Initializing TWI..."); |
| 30 | let config = twim::Config::default(); | 33 | let config = twim::Config::default(); |
| 31 | 34 | ||
| 32 | // Create the TWIM instance with borrowed singletons, so they're not consumed. | 35 | // Create the TWIM instance with borrowed singletons, so they're not consumed. |
| 33 | let mut twi = Twim::new(&mut p.TWISPI0, &mut irq, &mut p.P0_03, &mut p.P0_04, config); | 36 | let mut twi = Twim::new(&mut p.TWISPI0, Irqs, &mut p.P0_03, &mut p.P0_04, config); |
| 34 | 37 | ||
| 35 | info!("Reading..."); | 38 | info!("Reading..."); |
| 36 | 39 | ||
diff --git a/examples/nrf52840/src/bin/twis.rs b/examples/nrf52840/src/bin/twis.rs index 54cba9494..aa42b679e 100644 --- a/examples/nrf52840/src/bin/twis.rs +++ b/examples/nrf52840/src/bin/twis.rs | |||
| @@ -6,19 +6,21 @@ | |||
| 6 | 6 | ||
| 7 | use defmt::*; | 7 | use defmt::*; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::interrupt; | ||
| 10 | use embassy_nrf::twis::{self, Command, Twis}; | 9 | use embassy_nrf::twis::{self, Command, Twis}; |
| 10 | use embassy_nrf::{bind_interrupts, peripherals}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | bind_interrupts!(struct Irqs { | ||
| 14 | SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0 => twis::InterruptHandler<peripherals::TWISPI0>; | ||
| 15 | }); | ||
| 16 | |||
| 13 | #[embassy_executor::main] | 17 | #[embassy_executor::main] |
| 14 | async fn main(_spawner: Spawner) { | 18 | async fn main(_spawner: Spawner) { |
| 15 | let p = embassy_nrf::init(Default::default()); | 19 | let p = embassy_nrf::init(Default::default()); |
| 16 | 20 | ||
| 17 | let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); | ||
| 18 | let mut config = twis::Config::default(); | 21 | let mut config = twis::Config::default(); |
| 19 | // Set i2c address | 22 | config.address0 = 0x55; // Set i2c address |
| 20 | config.address0 = 0x55; | 23 | let mut i2c = Twis::new(p.TWISPI0, Irqs, p.P0_03, p.P0_04, config); |
| 21 | let mut i2c = Twis::new(p.TWISPI0, irq, p.P0_03, p.P0_04, config); | ||
| 22 | 24 | ||
| 23 | info!("Listening..."); | 25 | info!("Listening..."); |
| 24 | loop { | 26 | loop { |
diff --git a/examples/nrf52840/src/bin/uart.rs b/examples/nrf52840/src/bin/uart.rs index 600f7a6ef..50d5cab8c 100644 --- a/examples/nrf52840/src/bin/uart.rs +++ b/examples/nrf52840/src/bin/uart.rs | |||
| @@ -4,9 +4,13 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::{interrupt, uarte}; | 7 | use embassy_nrf::{bind_interrupts, peripherals, uarte}; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | bind_interrupts!(struct Irqs { | ||
| 11 | UARTE0_UART0 => uarte::InterruptHandler<peripherals::UARTE0>; | ||
| 12 | }); | ||
| 13 | |||
| 10 | #[embassy_executor::main] | 14 | #[embassy_executor::main] |
| 11 | async fn main(_spawner: Spawner) { | 15 | async fn main(_spawner: Spawner) { |
| 12 | let p = embassy_nrf::init(Default::default()); | 16 | let p = embassy_nrf::init(Default::default()); |
| @@ -14,8 +18,7 @@ async fn main(_spawner: Spawner) { | |||
| 14 | config.parity = uarte::Parity::EXCLUDED; | 18 | config.parity = uarte::Parity::EXCLUDED; |
| 15 | config.baudrate = uarte::Baudrate::BAUD115200; | 19 | config.baudrate = uarte::Baudrate::BAUD115200; |
| 16 | 20 | ||
| 17 | let irq = interrupt::take!(UARTE0_UART0); | 21 | let mut uart = uarte::Uarte::new(p.UARTE0, Irqs, p.P0_08, p.P0_06, config); |
| 18 | let mut uart = uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, config); | ||
| 19 | 22 | ||
| 20 | info!("uarte initialized!"); | 23 | info!("uarte initialized!"); |
| 21 | 24 | ||
diff --git a/examples/nrf52840/src/bin/uart_idle.rs b/examples/nrf52840/src/bin/uart_idle.rs index 6af4f7097..e1f42fa6c 100644 --- a/examples/nrf52840/src/bin/uart_idle.rs +++ b/examples/nrf52840/src/bin/uart_idle.rs | |||
| @@ -4,9 +4,14 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::{interrupt, uarte}; | 7 | use embassy_nrf::peripherals::UARTE0; |
| 8 | use embassy_nrf::{bind_interrupts, uarte}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 10 | ||
| 11 | bind_interrupts!(struct Irqs { | ||
| 12 | UARTE0_UART0 => uarte::InterruptHandler<UARTE0>; | ||
| 13 | }); | ||
| 14 | |||
| 10 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
| 11 | async fn main(_spawner: Spawner) { | 16 | async fn main(_spawner: Spawner) { |
| 12 | let p = embassy_nrf::init(Default::default()); | 17 | let p = embassy_nrf::init(Default::default()); |
| @@ -14,8 +19,7 @@ async fn main(_spawner: Spawner) { | |||
| 14 | config.parity = uarte::Parity::EXCLUDED; | 19 | config.parity = uarte::Parity::EXCLUDED; |
| 15 | config.baudrate = uarte::Baudrate::BAUD115200; | 20 | config.baudrate = uarte::Baudrate::BAUD115200; |
| 16 | 21 | ||
| 17 | let irq = interrupt::take!(UARTE0_UART0); | 22 | let uart = uarte::Uarte::new(p.UARTE0, Irqs, p.P0_08, p.P0_06, config); |
| 18 | let uart = uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, config); | ||
| 19 | let (mut tx, mut rx) = uart.split_with_idle(p.TIMER0, p.PPI_CH0, p.PPI_CH1); | 23 | let (mut tx, mut rx) = uart.split_with_idle(p.TIMER0, p.PPI_CH0, p.PPI_CH1); |
| 20 | 24 | ||
| 21 | info!("uarte initialized!"); | 25 | info!("uarte initialized!"); |
diff --git a/examples/nrf52840/src/bin/uart_split.rs b/examples/nrf52840/src/bin/uart_split.rs index 1adaf53fd..9979a1d53 100644 --- a/examples/nrf52840/src/bin/uart_split.rs +++ b/examples/nrf52840/src/bin/uart_split.rs | |||
| @@ -6,13 +6,17 @@ use defmt::*; | |||
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::peripherals::UARTE0; | 7 | use embassy_nrf::peripherals::UARTE0; |
| 8 | use embassy_nrf::uarte::UarteRx; | 8 | use embassy_nrf::uarte::UarteRx; |
| 9 | use embassy_nrf::{interrupt, uarte}; | 9 | use embassy_nrf::{bind_interrupts, uarte}; |
| 10 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | 10 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 11 | use embassy_sync::channel::Channel; | 11 | use embassy_sync::channel::Channel; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); | 14 | static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); |
| 15 | 15 | ||
| 16 | bind_interrupts!(struct Irqs { | ||
| 17 | UARTE0_UART0 => uarte::InterruptHandler<UARTE0>; | ||
| 18 | }); | ||
| 19 | |||
| 16 | #[embassy_executor::main] | 20 | #[embassy_executor::main] |
| 17 | async fn main(spawner: Spawner) { | 21 | async fn main(spawner: Spawner) { |
| 18 | let p = embassy_nrf::init(Default::default()); | 22 | let p = embassy_nrf::init(Default::default()); |
| @@ -20,8 +24,7 @@ async fn main(spawner: Spawner) { | |||
| 20 | config.parity = uarte::Parity::EXCLUDED; | 24 | config.parity = uarte::Parity::EXCLUDED; |
| 21 | config.baudrate = uarte::Baudrate::BAUD115200; | 25 | config.baudrate = uarte::Baudrate::BAUD115200; |
| 22 | 26 | ||
| 23 | let irq = interrupt::take!(UARTE0_UART0); | 27 | let uart = uarte::Uarte::new(p.UARTE0, Irqs, p.P0_08, p.P0_06, config); |
| 24 | let uart = uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, config); | ||
| 25 | let (mut tx, rx) = uart.split(); | 28 | let (mut tx, rx) = uart.split(); |
| 26 | 29 | ||
| 27 | info!("uarte initialized!"); | 30 | info!("uarte initialized!"); |
diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs index 430468adf..b8a72313a 100644 --- a/examples/nrf52840/src/bin/usb_ethernet.rs +++ b/examples/nrf52840/src/bin/usb_ethernet.rs | |||
| @@ -9,8 +9,9 @@ use embassy_executor::Spawner; | |||
| 9 | use embassy_net::tcp::TcpSocket; | 9 | use embassy_net::tcp::TcpSocket; |
| 10 | use embassy_net::{Stack, StackResources}; | 10 | use embassy_net::{Stack, StackResources}; |
| 11 | use embassy_nrf::rng::Rng; | 11 | use embassy_nrf::rng::Rng; |
| 12 | use embassy_nrf::usb::{Driver, HardwareVbusDetect}; | 12 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; |
| 13 | use embassy_nrf::{interrupt, pac, peripherals}; | 13 | use embassy_nrf::usb::Driver; |
| 14 | use embassy_nrf::{bind_interrupts, pac, peripherals, rng, usb}; | ||
| 14 | use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState}; | 15 | use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState}; |
| 15 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; | 16 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; |
| 16 | use embassy_usb::{Builder, Config, UsbDevice}; | 17 | use embassy_usb::{Builder, Config, UsbDevice}; |
| @@ -18,6 +19,12 @@ use embedded_io::asynch::Write; | |||
| 18 | use static_cell::StaticCell; | 19 | use static_cell::StaticCell; |
| 19 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 21 | ||
| 22 | bind_interrupts!(struct Irqs { | ||
| 23 | USBD => usb::InterruptHandler<peripherals::USBD>; | ||
| 24 | POWER_CLOCK => usb::vbus_detect::InterruptHandler; | ||
| 25 | RNG => rng::InterruptHandler<peripherals::RNG>; | ||
| 26 | }); | ||
| 27 | |||
| 21 | type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; | 28 | type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; |
| 22 | 29 | ||
| 23 | macro_rules! singleton { | 30 | macro_rules! singleton { |
| @@ -46,31 +53,8 @@ async fn net_task(stack: &'static Stack<Device<'static, MTU>>) -> ! { | |||
| 46 | stack.run().await | 53 | stack.run().await |
| 47 | } | 54 | } |
| 48 | 55 | ||
| 49 | #[inline(never)] | ||
| 50 | pub fn test_function() -> (usize, u32, [u32; 2]) { | ||
| 51 | let mut array = [3; 2]; | ||
| 52 | |||
| 53 | let mut index = 0; | ||
| 54 | let mut result = 0; | ||
| 55 | |||
| 56 | for x in [1, 2] { | ||
| 57 | if x == 1 { | ||
| 58 | array[1] = 99; | ||
| 59 | } else { | ||
| 60 | index = if x == 2 { 1 } else { 0 }; | ||
| 61 | |||
| 62 | // grabs value from array[0], not array[1] | ||
| 63 | result = array[index]; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | (index, result, array) | ||
| 68 | } | ||
| 69 | |||
| 70 | #[embassy_executor::main] | 56 | #[embassy_executor::main] |
| 71 | async fn main(spawner: Spawner) { | 57 | async fn main(spawner: Spawner) { |
| 72 | info!("{:?}", test_function()); | ||
| 73 | |||
| 74 | let p = embassy_nrf::init(Default::default()); | 58 | let p = embassy_nrf::init(Default::default()); |
| 75 | let clock: pac::CLOCK = unsafe { mem::transmute(()) }; | 59 | let clock: pac::CLOCK = unsafe { mem::transmute(()) }; |
| 76 | 60 | ||
| @@ -79,9 +63,7 @@ async fn main(spawner: Spawner) { | |||
| 79 | while clock.events_hfclkstarted.read().bits() != 1 {} | 63 | while clock.events_hfclkstarted.read().bits() != 1 {} |
| 80 | 64 | ||
| 81 | // Create the driver, from the HAL. | 65 | // Create the driver, from the HAL. |
| 82 | let irq = interrupt::take!(USBD); | 66 | let driver = Driver::new(p.USBD, Irqs, HardwareVbusDetect::new(Irqs)); |
| 83 | let power_irq = interrupt::take!(POWER_CLOCK); | ||
| 84 | let driver = Driver::new(p.USBD, irq, HardwareVbusDetect::new(power_irq)); | ||
| 85 | 67 | ||
| 86 | // Create embassy-usb Config | 68 | // Create embassy-usb Config |
| 87 | let mut config = Config::new(0xc0de, 0xcafe); | 69 | let mut config = Config::new(0xc0de, 0xcafe); |
| @@ -105,6 +87,7 @@ async fn main(spawner: Spawner) { | |||
| 105 | &mut singleton!([0; 256])[..], | 87 | &mut singleton!([0; 256])[..], |
| 106 | &mut singleton!([0; 256])[..], | 88 | &mut singleton!([0; 256])[..], |
| 107 | &mut singleton!([0; 128])[..], | 89 | &mut singleton!([0; 128])[..], |
| 90 | &mut singleton!([0; 128])[..], | ||
| 108 | ); | 91 | ); |
| 109 | 92 | ||
| 110 | // Our MAC addr. | 93 | // Our MAC addr. |
| @@ -131,7 +114,7 @@ async fn main(spawner: Spawner) { | |||
| 131 | //}); | 114 | //}); |
| 132 | 115 | ||
| 133 | // Generate random seed | 116 | // Generate random seed |
| 134 | let mut rng = Rng::new(p.RNG, interrupt::take!(RNG)); | 117 | let mut rng = Rng::new(p.RNG, Irqs); |
| 135 | let mut seed = [0; 8]; | 118 | let mut seed = [0; 8]; |
| 136 | rng.blocking_fill_bytes(&mut seed); | 119 | rng.blocking_fill_bytes(&mut seed); |
| 137 | let seed = u64::from_le_bytes(seed); | 120 | let seed = u64::from_le_bytes(seed); |
diff --git a/examples/nrf52840/src/bin/usb_hid_keyboard.rs b/examples/nrf52840/src/bin/usb_hid_keyboard.rs index 3d8a114cd..7ccd2946a 100644 --- a/examples/nrf52840/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf52840/src/bin/usb_hid_keyboard.rs | |||
| @@ -10,8 +10,9 @@ use embassy_executor::Spawner; | |||
| 10 | use embassy_futures::join::join; | 10 | use embassy_futures::join::join; |
| 11 | use embassy_futures::select::{select, Either}; | 11 | use embassy_futures::select::{select, Either}; |
| 12 | use embassy_nrf::gpio::{Input, Pin, Pull}; | 12 | use embassy_nrf::gpio::{Input, Pin, Pull}; |
| 13 | use embassy_nrf::usb::{Driver, HardwareVbusDetect}; | 13 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; |
| 14 | use embassy_nrf::{interrupt, pac}; | 14 | use embassy_nrf::usb::Driver; |
| 15 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | ||
| 15 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 16 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 16 | use embassy_sync::signal::Signal; | 17 | use embassy_sync::signal::Signal; |
| 17 | use embassy_usb::class::hid::{HidReaderWriter, ReportId, RequestHandler, State}; | 18 | use embassy_usb::class::hid::{HidReaderWriter, ReportId, RequestHandler, State}; |
| @@ -20,6 +21,11 @@ use embassy_usb::{Builder, Config, Handler}; | |||
| 20 | use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; | 21 | use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; |
| 21 | use {defmt_rtt as _, panic_probe as _}; | 22 | use {defmt_rtt as _, panic_probe as _}; |
| 22 | 23 | ||
| 24 | bind_interrupts!(struct Irqs { | ||
| 25 | USBD => usb::InterruptHandler<peripherals::USBD>; | ||
| 26 | POWER_CLOCK => usb::vbus_detect::InterruptHandler; | ||
| 27 | }); | ||
| 28 | |||
| 23 | static SUSPENDED: AtomicBool = AtomicBool::new(false); | 29 | static SUSPENDED: AtomicBool = AtomicBool::new(false); |
| 24 | 30 | ||
| 25 | #[embassy_executor::main] | 31 | #[embassy_executor::main] |
| @@ -32,9 +38,7 @@ async fn main(_spawner: Spawner) { | |||
| 32 | while clock.events_hfclkstarted.read().bits() != 1 {} | 38 | while clock.events_hfclkstarted.read().bits() != 1 {} |
| 33 | 39 | ||
| 34 | // Create the driver, from the HAL. | 40 | // Create the driver, from the HAL. |
| 35 | let irq = interrupt::take!(USBD); | 41 | let driver = Driver::new(p.USBD, Irqs, HardwareVbusDetect::new(Irqs)); |
| 36 | let power_irq = interrupt::take!(POWER_CLOCK); | ||
| 37 | let driver = Driver::new(p.USBD, irq, HardwareVbusDetect::new(power_irq)); | ||
| 38 | 42 | ||
| 39 | // Create embassy-usb Config | 43 | // Create embassy-usb Config |
| 40 | let mut config = Config::new(0xc0de, 0xcafe); | 44 | let mut config = Config::new(0xc0de, 0xcafe); |
| @@ -50,6 +54,7 @@ async fn main(_spawner: Spawner) { | |||
| 50 | let mut device_descriptor = [0; 256]; | 54 | let mut device_descriptor = [0; 256]; |
| 51 | let mut config_descriptor = [0; 256]; | 55 | let mut config_descriptor = [0; 256]; |
| 52 | let mut bos_descriptor = [0; 256]; | 56 | let mut bos_descriptor = [0; 256]; |
| 57 | let mut msos_descriptor = [0; 256]; | ||
| 53 | let mut control_buf = [0; 64]; | 58 | let mut control_buf = [0; 64]; |
| 54 | let request_handler = MyRequestHandler {}; | 59 | let request_handler = MyRequestHandler {}; |
| 55 | let mut device_handler = MyDeviceHandler::new(); | 60 | let mut device_handler = MyDeviceHandler::new(); |
| @@ -62,6 +67,7 @@ async fn main(_spawner: Spawner) { | |||
| 62 | &mut device_descriptor, | 67 | &mut device_descriptor, |
| 63 | &mut config_descriptor, | 68 | &mut config_descriptor, |
| 64 | &mut bos_descriptor, | 69 | &mut bos_descriptor, |
| 70 | &mut msos_descriptor, | ||
| 65 | &mut control_buf, | 71 | &mut control_buf, |
| 66 | ); | 72 | ); |
| 67 | 73 | ||
diff --git a/examples/nrf52840/src/bin/usb_hid_mouse.rs b/examples/nrf52840/src/bin/usb_hid_mouse.rs index d7c9d55b7..edf634a5e 100644 --- a/examples/nrf52840/src/bin/usb_hid_mouse.rs +++ b/examples/nrf52840/src/bin/usb_hid_mouse.rs | |||
| @@ -7,8 +7,9 @@ use core::mem; | |||
| 7 | use defmt::*; | 7 | use defmt::*; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_futures::join::join; | 9 | use embassy_futures::join::join; |
| 10 | use embassy_nrf::usb::{Driver, HardwareVbusDetect}; | 10 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; |
| 11 | use embassy_nrf::{interrupt, pac}; | 11 | use embassy_nrf::usb::Driver; |
| 12 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | ||
| 12 | use embassy_time::{Duration, Timer}; | 13 | use embassy_time::{Duration, Timer}; |
| 13 | use embassy_usb::class::hid::{HidWriter, ReportId, RequestHandler, State}; | 14 | use embassy_usb::class::hid::{HidWriter, ReportId, RequestHandler, State}; |
| 14 | use embassy_usb::control::OutResponse; | 15 | use embassy_usb::control::OutResponse; |
| @@ -16,6 +17,11 @@ use embassy_usb::{Builder, Config}; | |||
| 16 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; | 17 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 19 | ||
| 20 | bind_interrupts!(struct Irqs { | ||
| 21 | USBD => usb::InterruptHandler<peripherals::USBD>; | ||
| 22 | POWER_CLOCK => usb::vbus_detect::InterruptHandler; | ||
| 23 | }); | ||
| 24 | |||
| 19 | #[embassy_executor::main] | 25 | #[embassy_executor::main] |
| 20 | async fn main(_spawner: Spawner) { | 26 | async fn main(_spawner: Spawner) { |
| 21 | let p = embassy_nrf::init(Default::default()); | 27 | let p = embassy_nrf::init(Default::default()); |
| @@ -26,9 +32,7 @@ async fn main(_spawner: Spawner) { | |||
| 26 | while clock.events_hfclkstarted.read().bits() != 1 {} | 32 | while clock.events_hfclkstarted.read().bits() != 1 {} |
| 27 | 33 | ||
| 28 | // Create the driver, from the HAL. | 34 | // Create the driver, from the HAL. |
| 29 | let irq = interrupt::take!(USBD); | 35 | let driver = Driver::new(p.USBD, Irqs, HardwareVbusDetect::new(Irqs)); |
| 30 | let power_irq = interrupt::take!(POWER_CLOCK); | ||
| 31 | let driver = Driver::new(p.USBD, irq, HardwareVbusDetect::new(power_irq)); | ||
| 32 | 36 | ||
| 33 | // Create embassy-usb Config | 37 | // Create embassy-usb Config |
| 34 | let mut config = Config::new(0xc0de, 0xcafe); | 38 | let mut config = Config::new(0xc0de, 0xcafe); |
| @@ -43,6 +47,7 @@ async fn main(_spawner: Spawner) { | |||
| 43 | let mut device_descriptor = [0; 256]; | 47 | let mut device_descriptor = [0; 256]; |
| 44 | let mut config_descriptor = [0; 256]; | 48 | let mut config_descriptor = [0; 256]; |
| 45 | let mut bos_descriptor = [0; 256]; | 49 | let mut bos_descriptor = [0; 256]; |
| 50 | let mut msos_descriptor = [0; 256]; | ||
| 46 | let mut control_buf = [0; 64]; | 51 | let mut control_buf = [0; 64]; |
| 47 | let request_handler = MyRequestHandler {}; | 52 | let request_handler = MyRequestHandler {}; |
| 48 | 53 | ||
| @@ -54,6 +59,7 @@ async fn main(_spawner: Spawner) { | |||
| 54 | &mut device_descriptor, | 59 | &mut device_descriptor, |
| 55 | &mut config_descriptor, | 60 | &mut config_descriptor, |
| 56 | &mut bos_descriptor, | 61 | &mut bos_descriptor, |
| 62 | &mut msos_descriptor, | ||
| 57 | &mut control_buf, | 63 | &mut control_buf, |
| 58 | ); | 64 | ); |
| 59 | 65 | ||
diff --git a/examples/nrf52840/src/bin/usb_serial.rs b/examples/nrf52840/src/bin/usb_serial.rs index 102d7ea60..9727a4f57 100644 --- a/examples/nrf52840/src/bin/usb_serial.rs +++ b/examples/nrf52840/src/bin/usb_serial.rs | |||
| @@ -7,13 +7,19 @@ use core::mem; | |||
| 7 | use defmt::{info, panic}; | 7 | use defmt::{info, panic}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_futures::join::join; | 9 | use embassy_futures::join::join; |
| 10 | use embassy_nrf::usb::{Driver, HardwareVbusDetect, Instance, VbusDetect}; | 10 | use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect}; |
| 11 | use embassy_nrf::{interrupt, pac}; | 11 | use embassy_nrf::usb::{Driver, Instance}; |
| 12 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | ||
| 12 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 13 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 13 | use embassy_usb::driver::EndpointError; | 14 | use embassy_usb::driver::EndpointError; |
| 14 | use embassy_usb::{Builder, Config}; | 15 | use embassy_usb::{Builder, Config}; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | 17 | ||
| 18 | bind_interrupts!(struct Irqs { | ||
| 19 | USBD => usb::InterruptHandler<peripherals::USBD>; | ||
| 20 | POWER_CLOCK => usb::vbus_detect::InterruptHandler; | ||
| 21 | }); | ||
| 22 | |||
| 17 | #[embassy_executor::main] | 23 | #[embassy_executor::main] |
| 18 | async fn main(_spawner: Spawner) { | 24 | async fn main(_spawner: Spawner) { |
| 19 | let p = embassy_nrf::init(Default::default()); | 25 | let p = embassy_nrf::init(Default::default()); |
| @@ -24,9 +30,7 @@ async fn main(_spawner: Spawner) { | |||
| 24 | while clock.events_hfclkstarted.read().bits() != 1 {} | 30 | while clock.events_hfclkstarted.read().bits() != 1 {} |
| 25 | 31 | ||
| 26 | // Create the driver, from the HAL. | 32 | // Create the driver, from the HAL. |
| 27 | let irq = interrupt::take!(USBD); | 33 | let driver = Driver::new(p.USBD, Irqs, HardwareVbusDetect::new(Irqs)); |
| 28 | let power_irq = interrupt::take!(POWER_CLOCK); | ||
| 29 | let driver = Driver::new(p.USBD, irq, HardwareVbusDetect::new(power_irq)); | ||
| 30 | 34 | ||
| 31 | // Create embassy-usb Config | 35 | // Create embassy-usb Config |
| 32 | let mut config = Config::new(0xc0de, 0xcafe); | 36 | let mut config = Config::new(0xc0de, 0xcafe); |
| @@ -48,6 +52,7 @@ async fn main(_spawner: Spawner) { | |||
| 48 | let mut device_descriptor = [0; 256]; | 52 | let mut device_descriptor = [0; 256]; |
| 49 | let mut config_descriptor = [0; 256]; | 53 | let mut config_descriptor = [0; 256]; |
| 50 | let mut bos_descriptor = [0; 256]; | 54 | let mut bos_descriptor = [0; 256]; |
| 55 | let mut msos_descriptor = [0; 256]; | ||
| 51 | let mut control_buf = [0; 64]; | 56 | let mut control_buf = [0; 64]; |
| 52 | 57 | ||
| 53 | let mut state = State::new(); | 58 | let mut state = State::new(); |
| @@ -58,6 +63,7 @@ async fn main(_spawner: Spawner) { | |||
| 58 | &mut device_descriptor, | 63 | &mut device_descriptor, |
| 59 | &mut config_descriptor, | 64 | &mut config_descriptor, |
| 60 | &mut bos_descriptor, | 65 | &mut bos_descriptor, |
| 66 | &mut msos_descriptor, | ||
| 61 | &mut control_buf, | 67 | &mut control_buf, |
| 62 | ); | 68 | ); |
| 63 | 69 | ||
diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs index 558d4ba60..6da2c2a2f 100644 --- a/examples/nrf52840/src/bin/usb_serial_multitask.rs +++ b/examples/nrf52840/src/bin/usb_serial_multitask.rs | |||
| @@ -6,14 +6,29 @@ use core::mem; | |||
| 6 | 6 | ||
| 7 | use defmt::{info, panic, unwrap}; | 7 | use defmt::{info, panic, unwrap}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::usb::{Driver, HardwareVbusDetect}; | 9 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; |
| 10 | use embassy_nrf::{interrupt, pac, peripherals}; | 10 | use embassy_nrf::usb::Driver; |
| 11 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | ||
| 11 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 12 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 12 | use embassy_usb::driver::EndpointError; | 13 | use embassy_usb::driver::EndpointError; |
| 13 | use embassy_usb::{Builder, Config, UsbDevice}; | 14 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 14 | use static_cell::StaticCell; | 15 | use static_cell::StaticCell; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | 17 | ||
| 18 | bind_interrupts!(struct Irqs { | ||
| 19 | USBD => usb::InterruptHandler<peripherals::USBD>; | ||
| 20 | POWER_CLOCK => usb::vbus_detect::InterruptHandler; | ||
| 21 | }); | ||
| 22 | |||
| 23 | macro_rules! singleton { | ||
| 24 | ($val:expr) => {{ | ||
| 25 | type T = impl Sized; | ||
| 26 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 27 | let (x,) = STATIC_CELL.init(($val,)); | ||
| 28 | x | ||
| 29 | }}; | ||
| 30 | } | ||
| 31 | |||
| 17 | type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; | 32 | type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; |
| 18 | 33 | ||
| 19 | #[embassy_executor::task] | 34 | #[embassy_executor::task] |
| @@ -39,10 +54,9 @@ async fn main(spawner: Spawner) { | |||
| 39 | info!("Enabling ext hfosc..."); | 54 | info!("Enabling ext hfosc..."); |
| 40 | clock.tasks_hfclkstart.write(|w| unsafe { w.bits(1) }); | 55 | clock.tasks_hfclkstart.write(|w| unsafe { w.bits(1) }); |
| 41 | while clock.events_hfclkstarted.read().bits() != 1 {} | 56 | while clock.events_hfclkstarted.read().bits() != 1 {} |
| 57 | |||
| 42 | // Create the driver, from the HAL. | 58 | // Create the driver, from the HAL. |
| 43 | let irq = interrupt::take!(USBD); | 59 | let driver = Driver::new(p.USBD, Irqs, HardwareVbusDetect::new(Irqs)); |
| 44 | let power_irq = interrupt::take!(POWER_CLOCK); | ||
| 45 | let driver = Driver::new(p.USBD, irq, HardwareVbusDetect::new(power_irq)); | ||
| 46 | 60 | ||
| 47 | // Create embassy-usb Config | 61 | // Create embassy-usb Config |
| 48 | let mut config = Config::new(0xc0de, 0xcafe); | 62 | let mut config = Config::new(0xc0de, 0xcafe); |
| @@ -59,34 +73,21 @@ async fn main(spawner: Spawner) { | |||
| 59 | config.device_protocol = 0x01; | 73 | config.device_protocol = 0x01; |
| 60 | config.composite_with_iads = true; | 74 | config.composite_with_iads = true; |
| 61 | 75 | ||
| 62 | struct Resources { | 76 | let state = singleton!(State::new()); |
| 63 | device_descriptor: [u8; 256], | ||
| 64 | config_descriptor: [u8; 256], | ||
| 65 | bos_descriptor: [u8; 256], | ||
| 66 | control_buf: [u8; 64], | ||
| 67 | serial_state: State<'static>, | ||
| 68 | } | ||
| 69 | static RESOURCES: StaticCell<Resources> = StaticCell::new(); | ||
| 70 | let res = RESOURCES.init(Resources { | ||
| 71 | device_descriptor: [0; 256], | ||
| 72 | config_descriptor: [0; 256], | ||
| 73 | bos_descriptor: [0; 256], | ||
| 74 | control_buf: [0; 64], | ||
| 75 | serial_state: State::new(), | ||
| 76 | }); | ||
| 77 | 77 | ||
| 78 | // Create embassy-usb DeviceBuilder using the driver and config. | 78 | // Create embassy-usb DeviceBuilder using the driver and config. |
| 79 | let mut builder = Builder::new( | 79 | let mut builder = Builder::new( |
| 80 | driver, | 80 | driver, |
| 81 | config, | 81 | config, |
| 82 | &mut res.device_descriptor, | 82 | &mut singleton!([0; 256])[..], |
| 83 | &mut res.config_descriptor, | 83 | &mut singleton!([0; 256])[..], |
| 84 | &mut res.bos_descriptor, | 84 | &mut singleton!([0; 256])[..], |
| 85 | &mut res.control_buf, | 85 | &mut singleton!([0; 128])[..], |
| 86 | &mut singleton!([0; 128])[..], | ||
| 86 | ); | 87 | ); |
| 87 | 88 | ||
| 88 | // Create classes on the builder. | 89 | // Create classes on the builder. |
| 89 | let class = CdcAcmClass::new(&mut builder, &mut res.serial_state, 64); | 90 | let class = CdcAcmClass::new(&mut builder, state, 64); |
| 90 | 91 | ||
| 91 | // Build the builder. | 92 | // Build the builder. |
| 92 | let usb = builder.build(); | 93 | let usb = builder.build(); |
diff --git a/examples/nrf52840/src/bin/usb_serial_winusb.rs b/examples/nrf52840/src/bin/usb_serial_winusb.rs index 6561fc3b4..6e4f71a48 100644 --- a/examples/nrf52840/src/bin/usb_serial_winusb.rs +++ b/examples/nrf52840/src/bin/usb_serial_winusb.rs | |||
| @@ -7,8 +7,9 @@ use core::mem; | |||
| 7 | use defmt::{info, panic}; | 7 | use defmt::{info, panic}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_futures::join::join; | 9 | use embassy_futures::join::join; |
| 10 | use embassy_nrf::usb::{Driver, HardwareVbusDetect, Instance, VbusDetect}; | 10 | use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect}; |
| 11 | use embassy_nrf::{interrupt, pac}; | 11 | use embassy_nrf::usb::{Driver, Instance}; |
| 12 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | ||
| 12 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 13 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 13 | use embassy_usb::driver::EndpointError; | 14 | use embassy_usb::driver::EndpointError; |
| 14 | use embassy_usb::msos::{self, windows_version}; | 15 | use embassy_usb::msos::{self, windows_version}; |
| @@ -16,6 +17,11 @@ use embassy_usb::types::InterfaceNumber; | |||
| 16 | use embassy_usb::{Builder, Config}; | 17 | use embassy_usb::{Builder, Config}; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 19 | ||
| 20 | bind_interrupts!(struct Irqs { | ||
| 21 | USBD => usb::InterruptHandler<peripherals::USBD>; | ||
| 22 | POWER_CLOCK => usb::vbus_detect::InterruptHandler; | ||
| 23 | }); | ||
| 24 | |||
| 19 | // This is a randomly generated GUID to allow clients on Windows to find our device | 25 | // This is a randomly generated GUID to allow clients on Windows to find our device |
| 20 | const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"]; | 26 | const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"]; |
| 21 | 27 | ||
| @@ -29,9 +35,7 @@ async fn main(_spawner: Spawner) { | |||
| 29 | while clock.events_hfclkstarted.read().bits() != 1 {} | 35 | while clock.events_hfclkstarted.read().bits() != 1 {} |
| 30 | 36 | ||
| 31 | // Create the driver, from the HAL. | 37 | // Create the driver, from the HAL. |
| 32 | let irq = interrupt::take!(USBD); | 38 | let driver = Driver::new(p.USBD, Irqs, HardwareVbusDetect::new(Irqs)); |
| 33 | let power_irq = interrupt::take!(POWER_CLOCK); | ||
| 34 | let driver = Driver::new(p.USBD, irq, HardwareVbusDetect::new(power_irq)); | ||
| 35 | 39 | ||
| 36 | // Create embassy-usb Config | 40 | // Create embassy-usb Config |
| 37 | let mut config = Config::new(0xc0de, 0xcafe); | 41 | let mut config = Config::new(0xc0de, 0xcafe); |
diff --git a/examples/nrf5340/Cargo.toml b/examples/nrf5340/Cargo.toml index eed493012..e88ddf2f7 100644 --- a/examples/nrf5340/Cargo.toml +++ b/examples/nrf5340/Cargo.toml | |||
| @@ -4,24 +4,13 @@ name = "embassy-nrf5340-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [features] | ||
| 8 | default = ["nightly"] | ||
| 9 | nightly = [ | ||
| 10 | "embassy-executor/nightly", | ||
| 11 | "embassy-nrf/nightly", | ||
| 12 | "embassy-net/nightly", | ||
| 13 | "embassy-nrf/unstable-traits", | ||
| 14 | "embassy-usb", | ||
| 15 | "embedded-io/async", | ||
| 16 | "embassy-net", | ||
| 17 | ] | ||
| 18 | |||
| 19 | [dependencies] | 7 | [dependencies] |
| 20 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 8 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 21 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = [ | 9 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = [ |
| 22 | "defmt", | 10 | "defmt", |
| 23 | ] } | 11 | ] } |
| 24 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = [ | 12 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = [ |
| 13 | "nightly", | ||
| 25 | "defmt", | 14 | "defmt", |
| 26 | "integrated-timers", | 15 | "integrated-timers", |
| 27 | ] } | 16 | ] } |
| @@ -30,6 +19,8 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = [ | |||
| 30 | "defmt-timestamp-uptime", | 19 | "defmt-timestamp-uptime", |
| 31 | ] } | 20 | ] } |
| 32 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = [ | 21 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = [ |
| 22 | "nightly", | ||
| 23 | "unstable-traits", | ||
| 33 | "defmt", | 24 | "defmt", |
| 34 | "nrf5340-app-s", | 25 | "nrf5340-app-s", |
| 35 | "time-driver-rtc1", | 26 | "time-driver-rtc1", |
| @@ -37,16 +28,16 @@ embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = [ | |||
| 37 | "unstable-pac", | 28 | "unstable-pac", |
| 38 | ] } | 29 | ] } |
| 39 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = [ | 30 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = [ |
| 31 | "nightly", | ||
| 40 | "defmt", | 32 | "defmt", |
| 41 | "tcp", | 33 | "tcp", |
| 42 | "dhcpv4", | 34 | "dhcpv4", |
| 43 | "medium-ethernet", | 35 | "medium-ethernet", |
| 44 | ], optional = true } | 36 | ] } |
| 45 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = [ | 37 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = [ |
| 46 | "defmt", | 38 | "defmt", |
| 47 | ], optional = true } | 39 | ] } |
| 48 | embedded-io = "0.4.0" | 40 | embedded-io = { version = "0.4.0", features = [ "async" ]} |
| 49 | |||
| 50 | 41 | ||
| 51 | defmt = "0.3" | 42 | defmt = "0.3" |
| 52 | defmt-rtt = "0.4" | 43 | defmt-rtt = "0.4" |
diff --git a/examples/nrf5340/src/bin/uart.rs b/examples/nrf5340/src/bin/uart.rs index 5f448c2ba..d68539702 100644 --- a/examples/nrf5340/src/bin/uart.rs +++ b/examples/nrf5340/src/bin/uart.rs | |||
| @@ -4,9 +4,14 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::{interrupt, uarte}; | 7 | use embassy_nrf::peripherals::SERIAL0; |
| 8 | use embassy_nrf::{bind_interrupts, uarte}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 10 | ||
| 11 | bind_interrupts!(struct Irqs { | ||
| 12 | SERIAL0 => uarte::InterruptHandler<SERIAL0>; | ||
| 13 | }); | ||
| 14 | |||
| 10 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
| 11 | async fn main(_spawner: Spawner) { | 16 | async fn main(_spawner: Spawner) { |
| 12 | let p = embassy_nrf::init(Default::default()); | 17 | let p = embassy_nrf::init(Default::default()); |
| @@ -14,8 +19,7 @@ async fn main(_spawner: Spawner) { | |||
| 14 | config.parity = uarte::Parity::EXCLUDED; | 19 | config.parity = uarte::Parity::EXCLUDED; |
| 15 | config.baudrate = uarte::Baudrate::BAUD115200; | 20 | config.baudrate = uarte::Baudrate::BAUD115200; |
| 16 | 21 | ||
| 17 | let irq = interrupt::take!(SERIAL0); | 22 | let mut uart = uarte::Uarte::new(p.SERIAL0, Irqs, p.P1_00, p.P1_01, config); |
| 18 | let mut uart = uarte::Uarte::new(p.SERIAL0, irq, p.P1_00, p.P1_01, config); | ||
| 19 | 23 | ||
| 20 | info!("uarte initialized!"); | 24 | info!("uarte initialized!"); |
| 21 | 25 | ||
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 451850d99..e018e18c9 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs | |||
| @@ -65,7 +65,7 @@ async fn main_task(spawner: Spawner) { | |||
| 65 | let seed = u64::from_le_bytes(seed); | 65 | let seed = u64::from_le_bytes(seed); |
| 66 | 66 | ||
| 67 | // Init network stack | 67 | // Init network stack |
| 68 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 68 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); |
| 69 | 69 | ||
| 70 | // Launch network task | 70 | // Launch network task |
| 71 | spawner.spawn(net_task(stack)).unwrap(); | 71 | spawner.spawn(net_task(stack)).unwrap(); |
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs index e1cc45a38..d1e1f8212 100644 --- a/examples/std/src/bin/net_dns.rs +++ b/examples/std/src/bin/net_dns.rs | |||
| @@ -65,7 +65,7 @@ async fn main_task(spawner: Spawner) { | |||
| 65 | let seed = u64::from_le_bytes(seed); | 65 | let seed = u64::from_le_bytes(seed); |
| 66 | 66 | ||
| 67 | // Init network stack | 67 | // Init network stack |
| 68 | let stack: &Stack<_> = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 68 | let stack: &Stack<_> = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); |
| 69 | 69 | ||
| 70 | // Launch network task | 70 | // Launch network task |
| 71 | spawner.spawn(net_task(stack)).unwrap(); | 71 | spawner.spawn(net_task(stack)).unwrap(); |
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index f1923f180..328a0536c 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs | |||
| @@ -62,7 +62,7 @@ async fn main_task(spawner: Spawner) { | |||
| 62 | let seed = u64::from_le_bytes(seed); | 62 | let seed = u64::from_le_bytes(seed); |
| 63 | 63 | ||
| 64 | // Init network stack | 64 | // Init network stack |
| 65 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); | 65 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); |
| 66 | 66 | ||
| 67 | // Launch network task | 67 | // Launch network task |
| 68 | spawner.spawn(net_task(stack)).unwrap(); | 68 | spawner.spawn(net_task(stack)).unwrap(); |
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index d4afbb8f8..89d99b6d3 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml | |||
| @@ -15,5 +15,5 @@ panic-probe = "0.3" | |||
| 15 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } | 15 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 16 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 16 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 17 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 17 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 18 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti"] } | 18 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] } |
| 19 | static_cell = "1.0" | 19 | static_cell = "1.0" |
diff --git a/examples/stm32f0/src/bin/priority.rs b/examples/stm32f0/src/bin/multiprio.rs index 7fed6a773..e0dc8c989 100644 --- a/examples/stm32f0/src/bin/priority.rs +++ b/examples/stm32f0/src/bin/multiprio.rs | |||
| @@ -57,11 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 60 | use cortex_m_rt::entry; | 63 | use cortex_m_rt::entry; |
| 61 | use defmt::*; | 64 | use defmt::*; |
| 62 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | 65 | use embassy_stm32::executor::{Executor, InterruptExecutor}; |
| 63 | use embassy_stm32::interrupt; | 66 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::InterruptExt; | 67 | use embassy_stm32::pac::Interrupt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 68 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use static_cell::StaticCell; | 69 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 70 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -108,27 +111,34 @@ async fn run_low() { | |||
| 108 | } | 111 | } |
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::USART1>> = StaticCell::new(); | 114 | static EXECUTOR_HIGH: InterruptExecutor = InterruptExecutor::new(); |
| 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::USART2>> = StaticCell::new(); | 115 | static EXECUTOR_MED: InterruptExecutor = InterruptExecutor::new(); |
| 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); | 116 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 117 | ||
| 118 | #[interrupt] | ||
| 119 | unsafe fn USART1() { | ||
| 120 | EXECUTOR_HIGH.on_interrupt() | ||
| 121 | } | ||
| 122 | |||
| 123 | #[interrupt] | ||
| 124 | unsafe fn USART2() { | ||
| 125 | EXECUTOR_MED.on_interrupt() | ||
| 126 | } | ||
| 127 | |||
| 115 | #[entry] | 128 | #[entry] |
| 116 | fn main() -> ! { | 129 | fn main() -> ! { |
| 117 | // Initialize and create handle for devicer peripherals | 130 | // Initialize and create handle for devicer peripherals |
| 118 | let _p = embassy_stm32::init(Default::default()); | 131 | let _p = embassy_stm32::init(Default::default()); |
| 132 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 119 | 133 | ||
| 120 | // High-priority executor: USART1, priority level 6 | 134 | // High-priority executor: USART1, priority level 6 |
| 121 | let irq = interrupt::take!(USART1); | 135 | unsafe { nvic.set_priority(Interrupt::USART1, 6 << 4) }; |
| 122 | irq.set_priority(interrupt::Priority::P6); | 136 | let spawner = EXECUTOR_HIGH.start(Interrupt::USART1); |
| 123 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); | ||
| 124 | let spawner = executor.start(); | ||
| 125 | unwrap!(spawner.spawn(run_high())); | 137 | unwrap!(spawner.spawn(run_high())); |
| 126 | 138 | ||
| 127 | // Medium-priority executor: USART2, priority level 7 | 139 | // Medium-priority executor: USART2, priority level 7 |
| 128 | let irq = interrupt::take!(USART2); | 140 | unsafe { nvic.set_priority(Interrupt::USART2, 7 << 4) }; |
| 129 | irq.set_priority(interrupt::Priority::P7); | 141 | let spawner = EXECUTOR_MED.start(Interrupt::USART2); |
| 130 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); | ||
| 131 | let spawner = executor.start(); | ||
| 132 | unwrap!(spawner.spawn(run_med())); | 142 | unwrap!(spawner.spawn(run_med())); |
| 133 | 143 | ||
| 134 | // Low priority executor: runs in thread mode, using WFE/SEV | 144 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index 9e8228a4b..77df51ac7 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs | |||
| @@ -57,11 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 60 | use cortex_m_rt::entry; | 63 | use cortex_m_rt::entry; |
| 61 | use defmt::*; | 64 | use defmt::*; |
| 62 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | 65 | use embassy_stm32::executor::{Executor, InterruptExecutor}; |
| 63 | use embassy_stm32::interrupt; | 66 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::InterruptExt; | 67 | use embassy_stm32::pac::Interrupt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 68 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use static_cell::StaticCell; | 69 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 70 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -108,28 +111,35 @@ async fn run_low() { | |||
| 108 | } | 111 | } |
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new(); | 114 | static EXECUTOR_HIGH: InterruptExecutor = InterruptExecutor::new(); |
| 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new(); | 115 | static EXECUTOR_MED: InterruptExecutor = InterruptExecutor::new(); |
| 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); | 116 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 117 | ||
| 118 | #[interrupt] | ||
| 119 | unsafe fn UART4() { | ||
| 120 | EXECUTOR_HIGH.on_interrupt() | ||
| 121 | } | ||
| 122 | |||
| 123 | #[interrupt] | ||
| 124 | unsafe fn UART5() { | ||
| 125 | EXECUTOR_MED.on_interrupt() | ||
| 126 | } | ||
| 127 | |||
| 115 | #[entry] | 128 | #[entry] |
| 116 | fn main() -> ! { | 129 | fn main() -> ! { |
| 117 | info!("Hello World!"); | 130 | info!("Hello World!"); |
| 118 | 131 | ||
| 119 | let _p = embassy_stm32::init(Default::default()); | 132 | let _p = embassy_stm32::init(Default::default()); |
| 133 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 120 | 134 | ||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 135 | // High-priority executor: UART4, priority level 6 |
| 122 | let irq = interrupt::take!(UART4); | 136 | unsafe { nvic.set_priority(Interrupt::UART4, 6 << 4) }; |
| 123 | irq.set_priority(interrupt::Priority::P6); | 137 | let spawner = EXECUTOR_HIGH.start(Interrupt::UART4); |
| 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); | ||
| 125 | let spawner = executor.start(); | ||
| 126 | unwrap!(spawner.spawn(run_high())); | 138 | unwrap!(spawner.spawn(run_high())); |
| 127 | 139 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 140 | // Medium-priority executor: UART5, priority level 7 |
| 129 | let irq = interrupt::take!(UART5); | 141 | unsafe { nvic.set_priority(Interrupt::UART5, 7 << 4) }; |
| 130 | irq.set_priority(interrupt::Priority::P7); | 142 | let spawner = EXECUTOR_MED.start(Interrupt::UART5); |
| 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); | ||
| 132 | let spawner = executor.start(); | ||
| 133 | unwrap!(spawner.spawn(run_med())); | 143 | unwrap!(spawner.spawn(run_med())); |
| 134 | 144 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 145 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index e2b17bfcb..7a7bab5bb 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml | |||
| @@ -10,7 +10,7 @@ embassy-executor = { version = "0.1.0", path = "../../embassy-executor", feature | |||
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } |
| 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 12 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 13 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"], optional = true } | 13 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } |
| 14 | 14 | ||
| 15 | defmt = "0.3" | 15 | defmt = "0.3" |
| 16 | defmt-rtt = "0.4" | 16 | defmt-rtt = "0.4" |
| @@ -27,9 +27,5 @@ embedded-storage = "0.3.0" | |||
| 27 | micromath = "2.0.0" | 27 | micromath = "2.0.0" |
| 28 | static_cell = "1.0" | 28 | static_cell = "1.0" |
| 29 | 29 | ||
| 30 | [[bin]] | ||
| 31 | name = "usb_ethernet" | ||
| 32 | required-features = ["embassy-net"] | ||
| 33 | |||
| 34 | [profile.release] | 30 | [profile.release] |
| 35 | debug = 2 | 31 | debug = 2 |
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index 9e8228a4b..77df51ac7 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs | |||
| @@ -57,11 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 60 | use cortex_m_rt::entry; | 63 | use cortex_m_rt::entry; |
| 61 | use defmt::*; | 64 | use defmt::*; |
| 62 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | 65 | use embassy_stm32::executor::{Executor, InterruptExecutor}; |
| 63 | use embassy_stm32::interrupt; | 66 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::InterruptExt; | 67 | use embassy_stm32::pac::Interrupt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 68 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use static_cell::StaticCell; | 69 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 70 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -108,28 +111,35 @@ async fn run_low() { | |||
| 108 | } | 111 | } |
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new(); | 114 | static EXECUTOR_HIGH: InterruptExecutor = InterruptExecutor::new(); |
| 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new(); | 115 | static EXECUTOR_MED: InterruptExecutor = InterruptExecutor::new(); |
| 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); | 116 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 117 | ||
| 118 | #[interrupt] | ||
| 119 | unsafe fn UART4() { | ||
| 120 | EXECUTOR_HIGH.on_interrupt() | ||
| 121 | } | ||
| 122 | |||
| 123 | #[interrupt] | ||
| 124 | unsafe fn UART5() { | ||
| 125 | EXECUTOR_MED.on_interrupt() | ||
| 126 | } | ||
| 127 | |||
| 115 | #[entry] | 128 | #[entry] |
| 116 | fn main() -> ! { | 129 | fn main() -> ! { |
| 117 | info!("Hello World!"); | 130 | info!("Hello World!"); |
| 118 | 131 | ||
| 119 | let _p = embassy_stm32::init(Default::default()); | 132 | let _p = embassy_stm32::init(Default::default()); |
| 133 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 120 | 134 | ||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 135 | // High-priority executor: UART4, priority level 6 |
| 122 | let irq = interrupt::take!(UART4); | 136 | unsafe { nvic.set_priority(Interrupt::UART4, 6 << 4) }; |
| 123 | irq.set_priority(interrupt::Priority::P6); | 137 | let spawner = EXECUTOR_HIGH.start(Interrupt::UART4); |
| 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); | ||
| 125 | let spawner = executor.start(); | ||
| 126 | unwrap!(spawner.spawn(run_high())); | 138 | unwrap!(spawner.spawn(run_high())); |
| 127 | 139 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 140 | // Medium-priority executor: UART5, priority level 7 |
| 129 | let irq = interrupt::take!(UART5); | 141 | unsafe { nvic.set_priority(Interrupt::UART5, 7 << 4) }; |
| 130 | irq.set_priority(interrupt::Priority::P7); | 142 | let spawner = EXECUTOR_MED.start(Interrupt::UART5); |
| 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); | ||
| 132 | let spawner = executor.start(); | ||
| 133 | unwrap!(spawner.spawn(run_med())); | 143 | unwrap!(spawner.spawn(run_med())); |
| 134 | 144 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 145 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs index 4a16aac07..db9e18393 100644 --- a/examples/stm32f4/src/bin/usb_ethernet.rs +++ b/examples/stm32f4/src/bin/usb_ethernet.rs | |||
| @@ -100,8 +100,8 @@ async fn main(spawner: Spawner) { | |||
| 100 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); | 100 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); |
| 101 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 101 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 102 | 102 | ||
| 103 | let config = embassy_net::ConfigStrategy::Dhcp; | 103 | let config = embassy_net::Config::Dhcp(Default::default()); |
| 104 | //let config = embassy_net::ConfigStrategy::Static(embassy_net::Config { | 104 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { |
| 105 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 105 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 106 | // dns_servers: Vec::new(), | 106 | // dns_servers: Vec::new(), |
| 107 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 107 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
| @@ -114,12 +114,7 @@ async fn main(spawner: Spawner) { | |||
| 114 | let seed = u64::from_le_bytes(seed); | 114 | let seed = u64::from_le_bytes(seed); |
| 115 | 115 | ||
| 116 | // Init network stack | 116 | // Init network stack |
| 117 | let stack = &*singleton!(Stack::new( | 117 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); |
| 118 | device, | ||
| 119 | config, | ||
| 120 | singleton!(StackResources::<1, 2, 8>::new()), | ||
| 121 | seed | ||
| 122 | )); | ||
| 123 | 118 | ||
| 124 | unwrap!(spawner.spawn(net_task(stack))); | 119 | unwrap!(spawner.spawn(net_task(stack))); |
| 125 | 120 | ||
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index 5627760ef..644c90b1a 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml | |||
| @@ -4,8 +4,6 @@ name = "embassy-stm32l4-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [features] | ||
| 8 | |||
| 9 | [dependencies] | 7 | [dependencies] |
| 10 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 11 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index c0accb0d6..f880328dc 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml | |||
| @@ -4,8 +4,6 @@ name = "embassy-stm32l5-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [features] | ||
| 8 | |||
| 9 | [dependencies] | 7 | [dependencies] |
| 10 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 11 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
