diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-03-06 00:41:47 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-03-06 00:41:47 +0100 |
| commit | 18fe398673f55b07159d01a230910bb9689c1525 (patch) | |
| tree | 85c92ef10298ccaedec58c0582af1bf05753192e /examples | |
| parent | 403a83e08da67ebb20d04b1675a34c12752a94fc (diff) | |
| parent | f5e09a8f4a6d7b1bd6723c60915cb9f29cf352f7 (diff) | |
Merge pull request #1224 from embassy-rs/interrupt-binding
nrf: new interrupt binding traits/macro
Diffstat (limited to 'examples')
31 files changed, 225 insertions, 157 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 5b934b7d6..238695371 100644 --- a/examples/nrf52840/src/bin/buffered_uart.rs +++ b/examples/nrf52840/src/bin/buffered_uart.rs | |||
| @@ -4,11 +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; | 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::Write; | 9 | use embedded_io::asynch::Write; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | bind_interrupts!(struct Irqs { | ||
| 13 | UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>; | ||
| 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()); |
| @@ -19,14 +23,13 @@ async fn main(_spawner: Spawner) { | |||
| 19 | let mut tx_buffer = [0u8; 4096]; | 23 | let mut tx_buffer = [0u8; 4096]; |
| 20 | let mut rx_buffer = [0u8; 4096]; | 24 | let mut rx_buffer = [0u8; 4096]; |
| 21 | 25 | ||
| 22 | let irq = interrupt::take!(UARTE0_UART0); | ||
| 23 | let mut u = BufferedUarte::new( | 26 | let mut u = BufferedUarte::new( |
| 24 | p.UARTE0, | 27 | p.UARTE0, |
| 25 | p.TIMER0, | 28 | p.TIMER0, |
| 26 | p.PPI_CH0, | 29 | p.PPI_CH0, |
| 27 | p.PPI_CH1, | 30 | p.PPI_CH1, |
| 28 | p.PPI_GROUP0, | 31 | p.PPI_GROUP0, |
| 29 | irq, | 32 | Irqs, |
| 30 | p.P0_08, | 33 | p.P0_08, |
| 31 | p.P0_06, | 34 | p.P0_06, |
| 32 | config, | 35 | config, |
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/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 21a10940d..9e8a01f4e 100644 --- a/examples/nrf52840/src/bin/qspi.rs +++ b/examples/nrf52840/src/bin/qspi.rs | |||
| @@ -5,7 +5,7 @@ | |||
| 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::qspi::Frequency; | 7 | use embassy_nrf::qspi::Frequency; |
| 8 | use embassy_nrf::{interrupt, qspi}; | 8 | use embassy_nrf::{bind_interrupts, peripherals, qspi}; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 10 | ||
| 11 | const PAGE_SIZE: usize = 4096; | 11 | const PAGE_SIZE: usize = 4096; |
| @@ -15,6 +15,10 @@ const PAGE_SIZE: usize = 4096; | |||
| 15 | #[repr(C, align(4))] | 15 | #[repr(C, align(4))] |
| 16 | struct AlignedBuf([u8; 4096]); | 16 | struct AlignedBuf([u8; 4096]); |
| 17 | 17 | ||
| 18 | bind_interrupts!(struct Irqs { | ||
| 19 | QSPI => qspi::InterruptHandler<peripherals::QSPI>; | ||
| 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()); |
| @@ -26,9 +30,8 @@ async fn main(_spawner: Spawner) { | |||
| 26 | config.write_opcode = qspi::WriteOpcode::PP4IO; | 30 | config.write_opcode = qspi::WriteOpcode::PP4IO; |
| 27 | config.write_page_size = qspi::WritePageSize::_256BYTES; | 31 | config.write_page_size = qspi::WritePageSize::_256BYTES; |
| 28 | 32 | ||
| 29 | let irq = interrupt::take!(QSPI); | ||
| 30 | let mut q = qspi::Qspi::new( | 33 | let mut q = qspi::Qspi::new( |
| 31 | p.QSPI, irq, p.P0_19, p.P0_17, p.P0_20, p.P0_21, p.P0_22, p.P0_23, config, | 34 | p.QSPI, Irqs, p.P0_19, p.P0_17, p.P0_20, p.P0_21, p.P0_22, p.P0_23, config, |
| 32 | ); | 35 | ); |
| 33 | 36 | ||
| 34 | let mut id = [1; 3]; | 37 | let mut id = [1; 3]; |
diff --git a/examples/nrf52840/src/bin/qspi_lowpower.rs b/examples/nrf52840/src/bin/qspi_lowpower.rs index 20c903914..22a5c0c6d 100644 --- a/examples/nrf52840/src/bin/qspi_lowpower.rs +++ b/examples/nrf52840/src/bin/qspi_lowpower.rs | |||
| @@ -7,7 +7,7 @@ use core::mem; | |||
| 7 | use defmt::{info, unwrap}; | 7 | use defmt::{info, unwrap}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::qspi::Frequency; | 9 | use embassy_nrf::qspi::Frequency; |
| 10 | use embassy_nrf::{interrupt, qspi}; | 10 | use embassy_nrf::{bind_interrupts, peripherals, qspi}; |
| 11 | use embassy_time::{Duration, Timer}; | 11 | use embassy_time::{Duration, Timer}; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| @@ -16,10 +16,13 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 16 | #[repr(C, align(4))] | 16 | #[repr(C, align(4))] |
| 17 | struct AlignedBuf([u8; 64]); | 17 | struct AlignedBuf([u8; 64]); |
| 18 | 18 | ||
| 19 | bind_interrupts!(struct Irqs { | ||
| 20 | QSPI => qspi::InterruptHandler<peripherals::QSPI>; | ||
| 21 | }); | ||
| 22 | |||
| 19 | #[embassy_executor::main] | 23 | #[embassy_executor::main] |
| 20 | async fn main(_p: Spawner) { | 24 | async fn main(_p: Spawner) { |
| 21 | let mut p = embassy_nrf::init(Default::default()); | 25 | let mut p = embassy_nrf::init(Default::default()); |
| 22 | let mut irq = interrupt::take!(QSPI); | ||
| 23 | 26 | ||
| 24 | loop { | 27 | loop { |
| 25 | // Config for the MX25R64 present in the nRF52840 DK | 28 | // Config for the MX25R64 present in the nRF52840 DK |
| @@ -36,7 +39,7 @@ async fn main(_p: Spawner) { | |||
| 36 | 39 | ||
| 37 | let mut q = qspi::Qspi::new( | 40 | let mut q = qspi::Qspi::new( |
| 38 | &mut p.QSPI, | 41 | &mut p.QSPI, |
| 39 | &mut irq, | 42 | Irqs, |
| 40 | &mut p.P0_19, | 43 | &mut p.P0_19, |
| 41 | &mut p.P0_17, | 44 | &mut p.P0_17, |
| 42 | &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 979780896..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 { |
| @@ -56,9 +63,7 @@ async fn main(spawner: Spawner) { | |||
| 56 | while clock.events_hfclkstarted.read().bits() != 1 {} | 63 | while clock.events_hfclkstarted.read().bits() != 1 {} |
| 57 | 64 | ||
| 58 | // Create the driver, from the HAL. | 65 | // Create the driver, from the HAL. |
| 59 | let irq = interrupt::take!(USBD); | 66 | let driver = Driver::new(p.USBD, Irqs, HardwareVbusDetect::new(Irqs)); |
| 60 | let power_irq = interrupt::take!(POWER_CLOCK); | ||
| 61 | let driver = Driver::new(p.USBD, irq, HardwareVbusDetect::new(power_irq)); | ||
| 62 | 67 | ||
| 63 | // Create embassy-usb Config | 68 | // Create embassy-usb Config |
| 64 | let mut config = Config::new(0xc0de, 0xcafe); | 69 | let mut config = Config::new(0xc0de, 0xcafe); |
| @@ -82,6 +87,7 @@ async fn main(spawner: Spawner) { | |||
| 82 | &mut singleton!([0; 256])[..], | 87 | &mut singleton!([0; 256])[..], |
| 83 | &mut singleton!([0; 256])[..], | 88 | &mut singleton!([0; 256])[..], |
| 84 | &mut singleton!([0; 128])[..], | 89 | &mut singleton!([0; 128])[..], |
| 90 | &mut singleton!([0; 128])[..], | ||
| 85 | ); | 91 | ); |
| 86 | 92 | ||
| 87 | // Our MAC addr. | 93 | // Our MAC addr. |
| @@ -108,7 +114,7 @@ async fn main(spawner: Spawner) { | |||
| 108 | //}); | 114 | //}); |
| 109 | 115 | ||
| 110 | // Generate random seed | 116 | // Generate random seed |
| 111 | let mut rng = Rng::new(p.RNG, interrupt::take!(RNG)); | 117 | let mut rng = Rng::new(p.RNG, Irqs); |
| 112 | let mut seed = [0; 8]; | 118 | let mut seed = [0; 8]; |
| 113 | rng.blocking_fill_bytes(&mut seed); | 119 | rng.blocking_fill_bytes(&mut seed); |
| 114 | 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/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 | ||
