diff options
| author | Raul Alimbekov <[email protected]> | 2025-12-16 09:05:22 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-16 09:05:22 +0300 |
| commit | c9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch) | |
| tree | 6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /examples/nrf52840/src/bin | |
| parent | cde24a3ef1117653ba5ed4184102b33f745782fb (diff) | |
| parent | 5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff) | |
Merge branch 'main' into main
Diffstat (limited to 'examples/nrf52840/src/bin')
21 files changed, 167 insertions, 143 deletions
diff --git a/examples/nrf52840/src/bin/channel_sender_receiver.rs b/examples/nrf52840/src/bin/channel_sender_receiver.rs index 09050db68..de694eaa0 100644 --- a/examples/nrf52840/src/bin/channel_sender_receiver.rs +++ b/examples/nrf52840/src/bin/channel_sender_receiver.rs | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::unwrap; | 4 | use defmt::unwrap; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive}; | ||
| 7 | use embassy_nrf::Peri; | 6 | use embassy_nrf::Peri; |
| 7 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive}; | ||
| 8 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | 8 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; |
| 9 | use embassy_sync::channel::{Channel, Receiver, Sender}; | 9 | use embassy_sync::channel::{Channel, Receiver, Sender}; |
| 10 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
diff --git a/examples/nrf52840/src/bin/egu.rs b/examples/nrf52840/src/bin/egu.rs index 8bf712697..36eba8084 100644 --- a/examples/nrf52840/src/bin/egu.rs +++ b/examples/nrf52840/src/bin/egu.rs | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 8 | use embassy_nrf::egu::{Egu, TriggerNumber}; | 8 | use embassy_nrf::egu::{Egu, TriggerNumber}; |
| 9 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; | 9 | use embassy_nrf::gpio::{Level, OutputDrive, Pull}; |
| 10 | use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity, OutputChannel, OutputChannelPolarity}; | 10 | use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity, OutputChannel, OutputChannelPolarity}; |
| 11 | use embassy_nrf::peripherals::{PPI_CH0, PPI_CH1, PPI_CH2}; | 11 | use embassy_nrf::peripherals::{PPI_CH0, PPI_CH1, PPI_CH2}; |
| 12 | use embassy_nrf::ppi::Ppi; | 12 | use embassy_nrf::ppi::Ppi; |
| @@ -17,12 +17,15 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 17 | async fn main(_spawner: Spawner) { | 17 | async fn main(_spawner: Spawner) { |
| 18 | let p = embassy_nrf::init(Default::default()); | 18 | let p = embassy_nrf::init(Default::default()); |
| 19 | 19 | ||
| 20 | let led1 = Output::new(p.P0_13, Level::High, OutputDrive::Standard); | ||
| 21 | let btn1 = Input::new(p.P0_11, Pull::Up); | ||
| 22 | |||
| 23 | let mut egu1 = Egu::new(p.EGU0); | 20 | let mut egu1 = Egu::new(p.EGU0); |
| 24 | let led1 = OutputChannel::new(p.GPIOTE_CH0, led1, OutputChannelPolarity::Toggle); | 21 | let led1 = OutputChannel::new( |
| 25 | let btn1 = InputChannel::new(p.GPIOTE_CH1, btn1, InputChannelPolarity::LoToHi); | 22 | p.GPIOTE_CH0, |
| 23 | p.P0_13, | ||
| 24 | Level::High, | ||
| 25 | OutputDrive::Standard, | ||
| 26 | OutputChannelPolarity::Toggle, | ||
| 27 | ); | ||
| 28 | let btn1 = InputChannel::new(p.GPIOTE_CH1, p.P0_11, Pull::Up, InputChannelPolarity::LoToHi); | ||
| 26 | 29 | ||
| 27 | let trigger0 = egu1.trigger(TriggerNumber::Trigger0); | 30 | let trigger0 = egu1.trigger(TriggerNumber::Trigger0); |
| 28 | let trigger1 = egu1.trigger(TriggerNumber::Trigger1); | 31 | let trigger1 = egu1.trigger(TriggerNumber::Trigger1); |
diff --git a/examples/nrf52840/src/bin/ethernet_enc28j60.rs b/examples/nrf52840/src/bin/ethernet_enc28j60.rs index e59afd37f..5a988d89b 100644 --- a/examples/nrf52840/src/bin/ethernet_enc28j60.rs +++ b/examples/nrf52840/src/bin/ethernet_enc28j60.rs | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_net::tcp::TcpSocket; | ||
| 7 | use embassy_net::StackResources; | 6 | use embassy_net::StackResources; |
| 7 | use embassy_net::tcp::TcpSocket; | ||
| 8 | use embassy_net_enc28j60::Enc28j60; | 8 | use embassy_net_enc28j60::Enc28j60; |
| 9 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 9 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
| 10 | use embassy_nrf::rng::Rng; | 10 | use embassy_nrf::rng::Rng; |
diff --git a/examples/nrf52840/src/bin/gpiote_channel.rs b/examples/nrf52840/src/bin/gpiote_channel.rs index dcfe7723a..e358779b2 100644 --- a/examples/nrf52840/src/bin/gpiote_channel.rs +++ b/examples/nrf52840/src/bin/gpiote_channel.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::info; | 4 | use defmt::info; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_nrf::gpio::{Input, Pull}; | 6 | use embassy_nrf::gpio::Pull; |
| 7 | use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; | 7 | use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| @@ -12,26 +12,10 @@ async fn main(_spawner: Spawner) { | |||
| 12 | let p = embassy_nrf::init(Default::default()); | 12 | let p = embassy_nrf::init(Default::default()); |
| 13 | info!("Starting!"); | 13 | info!("Starting!"); |
| 14 | 14 | ||
| 15 | let ch1 = InputChannel::new( | 15 | let mut ch1 = InputChannel::new(p.GPIOTE_CH0, p.P0_11, Pull::Up, InputChannelPolarity::HiToLo); |
| 16 | p.GPIOTE_CH0, | 16 | let mut ch2 = InputChannel::new(p.GPIOTE_CH1, p.P0_12, Pull::Up, InputChannelPolarity::LoToHi); |
| 17 | Input::new(p.P0_11, Pull::Up), | 17 | let mut ch3 = InputChannel::new(p.GPIOTE_CH2, p.P0_24, Pull::Up, InputChannelPolarity::Toggle); |
| 18 | InputChannelPolarity::HiToLo, | 18 | let mut ch4 = InputChannel::new(p.GPIOTE_CH3, p.P0_25, Pull::Up, InputChannelPolarity::Toggle); |
| 19 | ); | ||
| 20 | let ch2 = InputChannel::new( | ||
| 21 | p.GPIOTE_CH1, | ||
| 22 | Input::new(p.P0_12, Pull::Up), | ||
| 23 | InputChannelPolarity::LoToHi, | ||
| 24 | ); | ||
| 25 | let ch3 = InputChannel::new( | ||
| 26 | p.GPIOTE_CH2, | ||
| 27 | Input::new(p.P0_24, Pull::Up), | ||
| 28 | InputChannelPolarity::Toggle, | ||
| 29 | ); | ||
| 30 | let ch4 = InputChannel::new( | ||
| 31 | p.GPIOTE_CH3, | ||
| 32 | Input::new(p.P0_25, Pull::Up), | ||
| 33 | InputChannelPolarity::Toggle, | ||
| 34 | ); | ||
| 35 | 19 | ||
| 36 | let button1 = async { | 20 | let button1 = async { |
| 37 | loop { | 21 | loop { |
diff --git a/examples/nrf52840/src/bin/i2s_effect.rs b/examples/nrf52840/src/bin/i2s_effect.rs index 9eadeb4e4..c31b78614 100644 --- a/examples/nrf52840/src/bin/i2s_effect.rs +++ b/examples/nrf52840/src/bin/i2s_effect.rs | |||
| @@ -5,7 +5,7 @@ use core::f32::consts::PI; | |||
| 5 | 5 | ||
| 6 | use defmt::{error, info}; | 6 | use defmt::{error, info}; |
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 8 | use embassy_nrf::i2s::{self, Channels, Config, MasterClock, MultiBuffering, Sample as _, SampleWidth, I2S}; | 8 | use embassy_nrf::i2s::{self, Channels, Config, I2S, MasterClock, MultiBuffering, Sample as _, SampleWidth}; |
| 9 | use embassy_nrf::{bind_interrupts, peripherals}; | 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 | ||
| @@ -102,11 +102,7 @@ impl SineOsc { | |||
| 102 | 102 | ||
| 103 | #[inline] | 103 | #[inline] |
| 104 | fn abs(value: f32) -> f32 { | 104 | fn abs(value: f32) -> f32 { |
| 105 | if value < 0.0 { | 105 | if value < 0.0 { -value } else { value } |
| 106 | -value | ||
| 107 | } else { | ||
| 108 | value | ||
| 109 | } | ||
| 110 | } | 106 | } |
| 111 | 107 | ||
| 112 | #[inline] | 108 | #[inline] |
diff --git a/examples/nrf52840/src/bin/i2s_monitor.rs b/examples/nrf52840/src/bin/i2s_monitor.rs index 799be351f..a54659101 100644 --- a/examples/nrf52840/src/bin/i2s_monitor.rs +++ b/examples/nrf52840/src/bin/i2s_monitor.rs | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::{debug, error, info}; | 4 | use defmt::{debug, error, info}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, MasterClock, Sample as _, SampleWidth, I2S}; | 6 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, I2S, MasterClock, Sample as _, SampleWidth}; |
| 7 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; | 7 | use embassy_nrf::pwm::{DutyCycle, Prescaler, SimplePwm}; |
| 8 | use embassy_nrf::{bind_interrupts, peripherals}; | 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 | ||
| @@ -34,7 +34,7 @@ async fn main(_spawner: Spawner) { | |||
| 34 | I2S::new_master(p.I2S, Irqs, p.P0_25, p.P0_26, p.P0_27, master_clock, config).input(p.P0_29, buffers); | 34 | I2S::new_master(p.I2S, Irqs, p.P0_25, p.P0_26, p.P0_27, master_clock, config).input(p.P0_29, buffers); |
| 35 | 35 | ||
| 36 | // Configure the PWM to use the pins corresponding to the RGB leds | 36 | // Configure the PWM to use the pins corresponding to the RGB leds |
| 37 | let mut pwm = SimplePwm::new_3ch(p.PWM0, p.P0_23, p.P0_22, p.P0_24); | 37 | let mut pwm = SimplePwm::new_3ch(p.PWM0, p.P0_23, p.P0_22, p.P0_24, &Default::default()); |
| 38 | pwm.set_prescaler(Prescaler::Div1); | 38 | pwm.set_prescaler(Prescaler::Div1); |
| 39 | pwm.set_max_duty(255); | 39 | pwm.set_max_duty(255); |
| 40 | 40 | ||
| @@ -47,9 +47,8 @@ async fn main(_spawner: Spawner) { | |||
| 47 | let rgb = rgb_from_rms(rms); | 47 | let rgb = rgb_from_rms(rms); |
| 48 | 48 | ||
| 49 | debug!("RMS: {}, RGB: {:?}", rms, rgb); | 49 | debug!("RMS: {}, RGB: {:?}", rms, rgb); |
| 50 | for i in 0..3 { | 50 | let duties = rgb.map(|byte| DutyCycle::normal(u16::from(byte))); |
| 51 | pwm.set_duty(i, rgb[i].into()); | 51 | pwm.set_all_duties([duties[0], duties[1], duties[2], DutyCycle::normal(0)]); |
| 52 | } | ||
| 53 | 52 | ||
| 54 | if let Err(err) = input_stream.receive().await { | 53 | if let Err(err) = input_stream.receive().await { |
| 55 | error!("{}", err); | 54 | error!("{}", err); |
diff --git a/examples/nrf52840/src/bin/i2s_waveform.rs b/examples/nrf52840/src/bin/i2s_waveform.rs index 137d82840..ce7a68d3a 100644 --- a/examples/nrf52840/src/bin/i2s_waveform.rs +++ b/examples/nrf52840/src/bin/i2s_waveform.rs | |||
| @@ -5,7 +5,7 @@ use core::f32::consts::PI; | |||
| 5 | 5 | ||
| 6 | use defmt::{error, info}; | 6 | use defmt::{error, info}; |
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 8 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, MasterClock, Sample as _, SampleWidth, I2S}; | 8 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, I2S, MasterClock, Sample as _, SampleWidth}; |
| 9 | use embassy_nrf::{bind_interrupts, peripherals}; | 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 | ||
| @@ -140,11 +140,7 @@ impl SineOsc { | |||
| 140 | 140 | ||
| 141 | #[inline] | 141 | #[inline] |
| 142 | fn abs(value: f32) -> f32 { | 142 | fn abs(value: f32) -> f32 { |
| 143 | if value < 0.0 { | 143 | if value < 0.0 { -value } else { value } |
| 144 | -value | ||
| 145 | } else { | ||
| 146 | value | ||
| 147 | } | ||
| 148 | } | 144 | } |
| 149 | 145 | ||
| 150 | #[inline] | 146 | #[inline] |
diff --git a/examples/nrf52840/src/bin/multiprio.rs b/examples/nrf52840/src/bin/multiprio.rs index 4d9b986d4..dc566adee 100644 --- a/examples/nrf52840/src/bin/multiprio.rs +++ b/examples/nrf52840/src/bin/multiprio.rs | |||
| @@ -113,12 +113,12 @@ static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); | |||
| 113 | 113 | ||
| 114 | #[interrupt] | 114 | #[interrupt] |
| 115 | unsafe fn EGU1_SWI1() { | 115 | unsafe fn EGU1_SWI1() { |
| 116 | EXECUTOR_HIGH.on_interrupt() | 116 | unsafe { EXECUTOR_HIGH.on_interrupt() } |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | #[interrupt] | 119 | #[interrupt] |
| 120 | unsafe fn EGU0_SWI0() { | 120 | unsafe fn EGU0_SWI0() { |
| 121 | EXECUTOR_MED.on_interrupt() | 121 | unsafe { EXECUTOR_MED.on_interrupt() } |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | #[entry] | 124 | #[entry] |
diff --git a/examples/nrf52840/src/bin/ppi.rs b/examples/nrf52840/src/bin/ppi.rs index 129ad06e7..177f6a06d 100644 --- a/examples/nrf52840/src/bin/ppi.rs +++ b/examples/nrf52840/src/bin/ppi.rs | |||
| @@ -5,7 +5,7 @@ use core::future::pending; | |||
| 5 | 5 | ||
| 6 | use defmt::info; | 6 | use defmt::info; |
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 8 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; | 8 | use embassy_nrf::gpio::{Level, OutputDrive, Pull}; |
| 9 | use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity}; | 9 | use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity}; |
| 10 | use embassy_nrf::ppi::Ppi; | 10 | use embassy_nrf::ppi::Ppi; |
| 11 | use gpiote::{OutputChannel, OutputChannelPolarity}; | 11 | use gpiote::{OutputChannel, OutputChannelPolarity}; |
| @@ -16,36 +16,24 @@ async fn main(_spawner: Spawner) { | |||
| 16 | let p = embassy_nrf::init(Default::default()); | 16 | let p = embassy_nrf::init(Default::default()); |
| 17 | info!("Starting!"); | 17 | info!("Starting!"); |
| 18 | 18 | ||
| 19 | let button1 = InputChannel::new( | 19 | let button1 = InputChannel::new(p.GPIOTE_CH0, p.P0_11, Pull::Up, InputChannelPolarity::HiToLo); |
| 20 | p.GPIOTE_CH0, | 20 | let button2 = InputChannel::new(p.GPIOTE_CH1, p.P0_12, Pull::Up, InputChannelPolarity::HiToLo); |
| 21 | Input::new(p.P0_11, Pull::Up), | 21 | let button3 = InputChannel::new(p.GPIOTE_CH2, p.P0_24, Pull::Up, InputChannelPolarity::HiToLo); |
| 22 | InputChannelPolarity::HiToLo, | 22 | let button4 = InputChannel::new(p.GPIOTE_CH3, p.P0_25, Pull::Up, InputChannelPolarity::HiToLo); |
| 23 | ); | ||
| 24 | let button2 = InputChannel::new( | ||
| 25 | p.GPIOTE_CH1, | ||
| 26 | Input::new(p.P0_12, Pull::Up), | ||
| 27 | InputChannelPolarity::HiToLo, | ||
| 28 | ); | ||
| 29 | let button3 = InputChannel::new( | ||
| 30 | p.GPIOTE_CH2, | ||
| 31 | Input::new(p.P0_24, Pull::Up), | ||
| 32 | InputChannelPolarity::HiToLo, | ||
| 33 | ); | ||
| 34 | let button4 = InputChannel::new( | ||
| 35 | p.GPIOTE_CH3, | ||
| 36 | Input::new(p.P0_25, Pull::Up), | ||
| 37 | InputChannelPolarity::HiToLo, | ||
| 38 | ); | ||
| 39 | 23 | ||
| 40 | let led1 = OutputChannel::new( | 24 | let led1 = OutputChannel::new( |
| 41 | p.GPIOTE_CH4, | 25 | p.GPIOTE_CH4, |
| 42 | Output::new(p.P0_13, Level::Low, OutputDrive::Standard), | 26 | p.P0_13, |
| 27 | Level::Low, | ||
| 28 | OutputDrive::Standard, | ||
| 43 | OutputChannelPolarity::Toggle, | 29 | OutputChannelPolarity::Toggle, |
| 44 | ); | 30 | ); |
| 45 | 31 | ||
| 46 | let led2 = OutputChannel::new( | 32 | let led2 = OutputChannel::new( |
| 47 | p.GPIOTE_CH5, | 33 | p.GPIOTE_CH5, |
| 48 | Output::new(p.P0_14, Level::Low, OutputDrive::Standard), | 34 | p.P0_14, |
| 35 | Level::Low, | ||
| 36 | OutputDrive::Standard, | ||
| 49 | OutputChannelPolarity::Toggle, | 37 | OutputChannelPolarity::Toggle, |
| 50 | ); | 38 | ); |
| 51 | 39 | ||
diff --git a/examples/nrf52840/src/bin/pwm.rs b/examples/nrf52840/src/bin/pwm.rs index a5bb1347a..02f9b4191 100644 --- a/examples/nrf52840/src/bin/pwm.rs +++ b/examples/nrf52840/src/bin/pwm.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; | 6 | use embassy_nrf::pwm::{DutyCycle, Prescaler, SimplePwm}; |
| 7 | use embassy_time::Timer; | 7 | use embassy_time::Timer; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| @@ -71,7 +71,7 @@ static DUTY: [u16; 1024] = [ | |||
| 71 | #[embassy_executor::main] | 71 | #[embassy_executor::main] |
| 72 | async fn main(_spawner: Spawner) { | 72 | async fn main(_spawner: Spawner) { |
| 73 | let p = embassy_nrf::init(Default::default()); | 73 | let p = embassy_nrf::init(Default::default()); |
| 74 | let mut pwm = SimplePwm::new_4ch(p.PWM0, p.P0_13, p.P0_14, p.P0_16, p.P0_15); | 74 | let mut pwm = SimplePwm::new_4ch(p.PWM0, p.P0_13, p.P0_14, p.P0_16, p.P0_15, &Default::default()); |
| 75 | pwm.set_prescaler(Prescaler::Div1); | 75 | pwm.set_prescaler(Prescaler::Div1); |
| 76 | pwm.set_max_duty(32767); | 76 | pwm.set_max_duty(32767); |
| 77 | info!("pwm initialized!"); | 77 | info!("pwm initialized!"); |
| @@ -79,10 +79,12 @@ async fn main(_spawner: Spawner) { | |||
| 79 | let mut i = 0; | 79 | let mut i = 0; |
| 80 | loop { | 80 | loop { |
| 81 | i += 1; | 81 | i += 1; |
| 82 | pwm.set_duty(0, DUTY[i % 1024]); | 82 | pwm.set_all_duties([ |
| 83 | pwm.set_duty(1, DUTY[(i + 256) % 1024]); | 83 | DutyCycle::normal(DUTY[i % 1024]), |
| 84 | pwm.set_duty(2, DUTY[(i + 512) % 1024]); | 84 | DutyCycle::normal(DUTY[(i + 256) % 1024]), |
| 85 | pwm.set_duty(3, DUTY[(i + 768) % 1024]); | 85 | DutyCycle::normal(DUTY[(i + 512) % 1024]), |
| 86 | DutyCycle::normal(DUTY[(i + 768) % 1024]), | ||
| 87 | ]); | ||
| 86 | Timer::after_millis(3).await; | 88 | Timer::after_millis(3).await; |
| 87 | } | 89 | } |
| 88 | } | 90 | } |
diff --git a/examples/nrf52840/src/bin/pwm_sequence_ppi.rs b/examples/nrf52840/src/bin/pwm_sequence_ppi.rs index 60ea712b5..fff7decb2 100644 --- a/examples/nrf52840/src/bin/pwm_sequence_ppi.rs +++ b/examples/nrf52840/src/bin/pwm_sequence_ppi.rs | |||
| @@ -5,7 +5,7 @@ use core::future::pending; | |||
| 5 | 5 | ||
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 8 | use embassy_nrf::gpio::{Input, Pull}; | 8 | use embassy_nrf::gpio::Pull; |
| 9 | use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; | 9 | use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; |
| 10 | use embassy_nrf::ppi::Ppi; | 10 | use embassy_nrf::ppi::Ppi; |
| 11 | use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer}; | 11 | use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer}; |
| @@ -30,17 +30,9 @@ async fn main(_spawner: Spawner) { | |||
| 30 | // pwm.stop() deconfigures pins, and then the task_start_seq0 task cant work | 30 | // pwm.stop() deconfigures pins, and then the task_start_seq0 task cant work |
| 31 | // so its going to have to start running in order load the configuration | 31 | // so its going to have to start running in order load the configuration |
| 32 | 32 | ||
| 33 | let button1 = InputChannel::new( | 33 | let button1 = InputChannel::new(p.GPIOTE_CH0, p.P0_11, Pull::Up, InputChannelPolarity::HiToLo); |
| 34 | p.GPIOTE_CH0, | ||
| 35 | Input::new(p.P0_11, Pull::Up), | ||
| 36 | InputChannelPolarity::HiToLo, | ||
| 37 | ); | ||
| 38 | 34 | ||
| 39 | let button2 = InputChannel::new( | 35 | let button2 = InputChannel::new(p.GPIOTE_CH1, p.P0_12, Pull::Up, InputChannelPolarity::HiToLo); |
| 40 | p.GPIOTE_CH1, | ||
| 41 | Input::new(p.P0_12, Pull::Up), | ||
| 42 | InputChannelPolarity::HiToLo, | ||
| 43 | ); | ||
| 44 | 36 | ||
| 45 | // messing with the pwm tasks is ill advised | 37 | // messing with the pwm tasks is ill advised |
| 46 | // Times::Ininite and Times even are seq0, Times odd is seq1 | 38 | // Times::Ininite and Times even are seq0, Times odd is seq1 |
diff --git a/examples/nrf52840/src/bin/pwm_servo.rs b/examples/nrf52840/src/bin/pwm_servo.rs index d772d2f5d..93cb984e6 100644 --- a/examples/nrf52840/src/bin/pwm_servo.rs +++ b/examples/nrf52840/src/bin/pwm_servo.rs | |||
| @@ -3,14 +3,14 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; | 6 | use embassy_nrf::pwm::{DutyCycle, Prescaler, SimplePwm}; |
| 7 | use embassy_time::Timer; | 7 | use embassy_time::Timer; |
| 8 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 9 | ||
| 10 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| 11 | async fn main(_spawner: Spawner) { | 11 | async fn main(_spawner: Spawner) { |
| 12 | let p = embassy_nrf::init(Default::default()); | 12 | let p = embassy_nrf::init(Default::default()); |
| 13 | let mut pwm = SimplePwm::new_1ch(p.PWM0, p.P0_05); | 13 | let mut pwm = SimplePwm::new_1ch(p.PWM0, p.P0_05, &Default::default()); |
| 14 | // sg90 microervo requires 50hz or 20ms period | 14 | // sg90 microervo requires 50hz or 20ms period |
| 15 | // set_period can only set down to 125khz so we cant use it directly | 15 | // set_period can only set down to 125khz so we cant use it directly |
| 16 | // Div128 is 125khz or 0.000008s or 0.008ms, 20/0.008 is 2500 is top | 16 | // Div128 is 125khz or 0.000008s or 0.008ms, 20/0.008 is 2500 is top |
| @@ -24,23 +24,23 @@ async fn main(_spawner: Spawner) { | |||
| 24 | loop { | 24 | loop { |
| 25 | info!("45 deg"); | 25 | info!("45 deg"); |
| 26 | // poor mans inverting, subtract our value from max_duty | 26 | // poor mans inverting, subtract our value from max_duty |
| 27 | pwm.set_duty(0, 2500 - 156); | 27 | pwm.set_duty(0, DutyCycle::normal(2500 - 156)); |
| 28 | Timer::after_millis(5000).await; | 28 | Timer::after_millis(5000).await; |
| 29 | 29 | ||
| 30 | info!("90 deg"); | 30 | info!("90 deg"); |
| 31 | pwm.set_duty(0, 2500 - 187); | 31 | pwm.set_duty(0, DutyCycle::normal(2500 - 187)); |
| 32 | Timer::after_millis(5000).await; | 32 | Timer::after_millis(5000).await; |
| 33 | 33 | ||
| 34 | info!("135 deg"); | 34 | info!("135 deg"); |
| 35 | pwm.set_duty(0, 2500 - 218); | 35 | pwm.set_duty(0, DutyCycle::normal(2500 - 218)); |
| 36 | Timer::after_millis(5000).await; | 36 | Timer::after_millis(5000).await; |
| 37 | 37 | ||
| 38 | info!("180 deg"); | 38 | info!("180 deg"); |
| 39 | pwm.set_duty(0, 2500 - 250); | 39 | pwm.set_duty(0, DutyCycle::normal(2500 - 250)); |
| 40 | Timer::after_millis(5000).await; | 40 | Timer::after_millis(5000).await; |
| 41 | 41 | ||
| 42 | info!("0 deg"); | 42 | info!("0 deg"); |
| 43 | pwm.set_duty(0, 2500 - 125); | 43 | pwm.set_duty(0, DutyCycle::normal(2500 - 125)); |
| 44 | Timer::after_millis(5000).await; | 44 | Timer::after_millis(5000).await; |
| 45 | } | 45 | } |
| 46 | } | 46 | } |
diff --git a/examples/nrf52840/src/bin/raw_spawn.rs b/examples/nrf52840/src/bin/raw_spawn.rs index b80954408..783be763d 100644 --- a/examples/nrf52840/src/bin/raw_spawn.rs +++ b/examples/nrf52840/src/bin/raw_spawn.rs | |||
| @@ -5,8 +5,8 @@ use core::mem; | |||
| 5 | 5 | ||
| 6 | use cortex_m_rt::entry; | 6 | use cortex_m_rt::entry; |
| 7 | use defmt::{info, unwrap}; | 7 | use defmt::{info, unwrap}; |
| 8 | use embassy_executor::raw::TaskStorage; | ||
| 9 | use embassy_executor::Executor; | 8 | use embassy_executor::Executor; |
| 9 | use embassy_executor::raw::TaskStorage; | ||
| 10 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
| 11 | use static_cell::StaticCell; | 11 | use static_cell::StaticCell; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -48,5 +48,5 @@ fn main() -> ! { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | unsafe fn make_static<T>(t: &T) -> &'static T { | 50 | unsafe fn make_static<T>(t: &T) -> &'static T { |
| 51 | mem::transmute(t) | 51 | unsafe { mem::transmute(t) } |
| 52 | } | 52 | } |
diff --git a/examples/nrf52840/src/bin/rtc.rs b/examples/nrf52840/src/bin/rtc.rs index 9d475df7f..56a0c25f4 100644 --- a/examples/nrf52840/src/bin/rtc.rs +++ b/examples/nrf52840/src/bin/rtc.rs | |||
| @@ -7,8 +7,8 @@ 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; | 8 | use embassy_nrf::interrupt; |
| 9 | use embassy_nrf::rtc::Rtc; | 9 | use embassy_nrf::rtc::Rtc; |
| 10 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 11 | use embassy_sync::blocking_mutex::Mutex; | 10 | use embassy_sync::blocking_mutex::Mutex; |
| 11 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 12 | use portable_atomic::AtomicU64; | 12 | use portable_atomic::AtomicU64; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs index a75b967b4..14a1004d7 100644 --- a/examples/nrf52840/src/bin/usb_ethernet.rs +++ b/examples/nrf52840/src/bin/usb_ethernet.rs | |||
| @@ -3,11 +3,11 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_net::tcp::TcpSocket; | ||
| 7 | use embassy_net::StackResources; | 6 | use embassy_net::StackResources; |
| 7 | use embassy_net::tcp::TcpSocket; | ||
| 8 | use embassy_nrf::rng::Rng; | 8 | use embassy_nrf::rng::Rng; |
| 9 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; | ||
| 10 | use embassy_nrf::usb::Driver; | 9 | use embassy_nrf::usb::Driver; |
| 10 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; | ||
| 11 | use embassy_nrf::{bind_interrupts, pac, peripherals, rng, usb}; | 11 | use embassy_nrf::{bind_interrupts, pac, peripherals, rng, usb}; |
| 12 | use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState}; | 12 | use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState}; |
| 13 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; | 13 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; |
diff --git a/examples/nrf52840/src/bin/usb_hid_keyboard.rs b/examples/nrf52840/src/bin/usb_hid_keyboard.rs index 5a9dc90a2..7b7303526 100644 --- a/examples/nrf52840/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf52840/src/bin/usb_hid_keyboard.rs | |||
| @@ -1,19 +1,21 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::sync::atomic::{AtomicBool, Ordering}; | 4 | use core::sync::atomic::{AtomicBool, AtomicU8, Ordering}; |
| 5 | 5 | ||
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 8 | use embassy_futures::join::join; | 8 | use embassy_futures::join::join; |
| 9 | use embassy_futures::select::{select, Either}; | 9 | use embassy_futures::select::{Either, select}; |
| 10 | use embassy_nrf::gpio::{Input, Pull}; | 10 | use embassy_nrf::gpio::{Input, Pull}; |
| 11 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; | ||
| 12 | use embassy_nrf::usb::Driver; | 11 | use embassy_nrf::usb::Driver; |
| 12 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; | ||
| 13 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | 13 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; |
| 14 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 14 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 15 | use embassy_sync::signal::Signal; | 15 | use embassy_sync::signal::Signal; |
| 16 | use embassy_usb::class::hid::{HidReaderWriter, ReportId, RequestHandler, State}; | 16 | use embassy_usb::class::hid::{ |
| 17 | HidBootProtocol, HidProtocolMode, HidReaderWriter, HidSubclass, ReportId, RequestHandler, State, | ||
| 18 | }; | ||
| 17 | use embassy_usb::control::OutResponse; | 19 | use embassy_usb::control::OutResponse; |
| 18 | use embassy_usb::{Builder, Config, Handler}; | 20 | use embassy_usb::{Builder, Config, Handler}; |
| 19 | use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; | 21 | use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; |
| @@ -26,6 +28,8 @@ bind_interrupts!(struct Irqs { | |||
| 26 | 28 | ||
| 27 | static SUSPENDED: AtomicBool = AtomicBool::new(false); | 29 | static SUSPENDED: AtomicBool = AtomicBool::new(false); |
| 28 | 30 | ||
| 31 | static HID_PROTOCOL_MODE: AtomicU8 = AtomicU8::new(HidProtocolMode::Boot as u8); | ||
| 32 | |||
| 29 | #[embassy_executor::main] | 33 | #[embassy_executor::main] |
| 30 | async fn main(_spawner: Spawner) { | 34 | async fn main(_spawner: Spawner) { |
| 31 | let p = embassy_nrf::init(Default::default()); | 35 | let p = embassy_nrf::init(Default::default()); |
| @@ -45,6 +49,10 @@ async fn main(_spawner: Spawner) { | |||
| 45 | config.max_power = 100; | 49 | config.max_power = 100; |
| 46 | config.max_packet_size_0 = 64; | 50 | config.max_packet_size_0 = 64; |
| 47 | config.supports_remote_wakeup = true; | 51 | config.supports_remote_wakeup = true; |
| 52 | config.composite_with_iads = false; | ||
| 53 | config.device_class = 0; | ||
| 54 | config.device_sub_class = 0; | ||
| 55 | config.device_protocol = 0; | ||
| 48 | 56 | ||
| 49 | // Create embassy-usb DeviceBuilder using the driver and config. | 57 | // Create embassy-usb DeviceBuilder using the driver and config. |
| 50 | // It needs some buffers for building the descriptors. | 58 | // It needs some buffers for building the descriptors. |
| @@ -74,6 +82,8 @@ async fn main(_spawner: Spawner) { | |||
| 74 | request_handler: None, | 82 | request_handler: None, |
| 75 | poll_ms: 60, | 83 | poll_ms: 60, |
| 76 | max_packet_size: 64, | 84 | max_packet_size: 64, |
| 85 | hid_subclass: HidSubclass::Boot, | ||
| 86 | hid_boot_protocol: HidBootProtocol::Keyboard, | ||
| 77 | }; | 87 | }; |
| 78 | let hid = HidReaderWriter::<_, 1, 8>::new(&mut builder, &mut state, config); | 88 | let hid = HidReaderWriter::<_, 1, 8>::new(&mut builder, &mut state, config); |
| 79 | 89 | ||
| @@ -106,6 +116,11 @@ async fn main(_spawner: Spawner) { | |||
| 106 | if SUSPENDED.load(Ordering::Acquire) { | 116 | if SUSPENDED.load(Ordering::Acquire) { |
| 107 | info!("Triggering remote wakeup"); | 117 | info!("Triggering remote wakeup"); |
| 108 | remote_wakeup.signal(()); | 118 | remote_wakeup.signal(()); |
| 119 | } else if HID_PROTOCOL_MODE.load(Ordering::Relaxed) == HidProtocolMode::Boot as u8 { | ||
| 120 | match writer.write(&[0, 0, 4, 0, 0, 0, 0, 0]).await { | ||
| 121 | Ok(()) => {} | ||
| 122 | Err(e) => warn!("Failed to send boot report: {:?}", e), | ||
| 123 | }; | ||
| 109 | } else { | 124 | } else { |
| 110 | let report = KeyboardReport { | 125 | let report = KeyboardReport { |
| 111 | keycodes: [4, 0, 0, 0, 0, 0], | 126 | keycodes: [4, 0, 0, 0, 0, 0], |
| @@ -121,16 +136,23 @@ async fn main(_spawner: Spawner) { | |||
| 121 | 136 | ||
| 122 | button.wait_for_high().await; | 137 | button.wait_for_high().await; |
| 123 | info!("RELEASED"); | 138 | info!("RELEASED"); |
| 124 | let report = KeyboardReport { | 139 | if HID_PROTOCOL_MODE.load(Ordering::Relaxed) == HidProtocolMode::Boot as u8 { |
| 125 | keycodes: [0, 0, 0, 0, 0, 0], | 140 | match writer.write(&[0, 0, 0, 0, 0, 0, 0, 0]).await { |
| 126 | leds: 0, | 141 | Ok(()) => {} |
| 127 | modifier: 0, | 142 | Err(e) => warn!("Failed to send boot report: {:?}", e), |
| 128 | reserved: 0, | 143 | }; |
| 129 | }; | 144 | } else { |
| 130 | match writer.write_serialize(&report).await { | 145 | let report = KeyboardReport { |
| 131 | Ok(()) => {} | 146 | keycodes: [0, 0, 0, 0, 0, 0], |
| 132 | Err(e) => warn!("Failed to send report: {:?}", e), | 147 | leds: 0, |
| 133 | }; | 148 | modifier: 0, |
| 149 | reserved: 0, | ||
| 150 | }; | ||
| 151 | match writer.write_serialize(&report).await { | ||
| 152 | Ok(()) => {} | ||
| 153 | Err(e) => warn!("Failed to send report: {:?}", e), | ||
| 154 | }; | ||
| 155 | } | ||
| 134 | } | 156 | } |
| 135 | }; | 157 | }; |
| 136 | 158 | ||
| @@ -156,6 +178,18 @@ impl RequestHandler for MyRequestHandler { | |||
| 156 | OutResponse::Accepted | 178 | OutResponse::Accepted |
| 157 | } | 179 | } |
| 158 | 180 | ||
| 181 | fn get_protocol(&self) -> HidProtocolMode { | ||
| 182 | let protocol = HidProtocolMode::from(HID_PROTOCOL_MODE.load(Ordering::Relaxed)); | ||
| 183 | info!("The current HID protocol mode is: {}", protocol); | ||
| 184 | protocol | ||
| 185 | } | ||
| 186 | |||
| 187 | fn set_protocol(&mut self, protocol: HidProtocolMode) -> OutResponse { | ||
| 188 | info!("Switching to HID protocol mode: {}", protocol); | ||
| 189 | HID_PROTOCOL_MODE.store(protocol as u8, Ordering::Relaxed); | ||
| 190 | OutResponse::Accepted | ||
| 191 | } | ||
| 192 | |||
| 159 | fn set_idle_ms(&mut self, id: Option<ReportId>, dur: u32) { | 193 | fn set_idle_ms(&mut self, id: Option<ReportId>, dur: u32) { |
| 160 | info!("Set idle rate for {:?} to {:?}", id, dur); | 194 | info!("Set idle rate for {:?} to {:?}", id, dur); |
| 161 | } | 195 | } |
| @@ -210,7 +244,9 @@ impl Handler for MyDeviceHandler { | |||
| 210 | 244 | ||
| 211 | fn suspended(&mut self, suspended: bool) { | 245 | fn suspended(&mut self, suspended: bool) { |
| 212 | if suspended { | 246 | if suspended { |
| 213 | info!("Device suspended, the Vbus current limit is 500µA (or 2.5mA for high-power devices with remote wakeup enabled)."); | 247 | info!( |
| 248 | "Device suspended, the Vbus current limit is 500µA (or 2.5mA for high-power devices with remote wakeup enabled)." | ||
| 249 | ); | ||
| 214 | SUSPENDED.store(true, Ordering::Release); | 250 | SUSPENDED.store(true, Ordering::Release); |
| 215 | } else { | 251 | } else { |
| 216 | SUSPENDED.store(false, Ordering::Release); | 252 | SUSPENDED.store(false, Ordering::Release); |
diff --git a/examples/nrf52840/src/bin/usb_hid_mouse.rs b/examples/nrf52840/src/bin/usb_hid_mouse.rs index 80cda70e3..6bee4546b 100644 --- a/examples/nrf52840/src/bin/usb_hid_mouse.rs +++ b/examples/nrf52840/src/bin/usb_hid_mouse.rs | |||
| @@ -1,14 +1,18 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::sync::atomic::{AtomicU8, Ordering}; | ||
| 5 | |||
| 4 | use defmt::*; | 6 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 6 | use embassy_futures::join::join; | 8 | use embassy_futures::join::join; |
| 7 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; | ||
| 8 | use embassy_nrf::usb::Driver; | 9 | use embassy_nrf::usb::Driver; |
| 10 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; | ||
| 9 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | 11 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; |
| 10 | use embassy_time::Timer; | 12 | use embassy_time::Timer; |
| 11 | use embassy_usb::class::hid::{HidWriter, ReportId, RequestHandler, State}; | 13 | use embassy_usb::class::hid::{ |
| 14 | HidBootProtocol, HidProtocolMode, HidSubclass, HidWriter, ReportId, RequestHandler, State, | ||
| 15 | }; | ||
| 12 | use embassy_usb::control::OutResponse; | 16 | use embassy_usb::control::OutResponse; |
| 13 | use embassy_usb::{Builder, Config}; | 17 | use embassy_usb::{Builder, Config}; |
| 14 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; | 18 | use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; |
| @@ -19,6 +23,8 @@ bind_interrupts!(struct Irqs { | |||
| 19 | CLOCK_POWER => usb::vbus_detect::InterruptHandler; | 23 | CLOCK_POWER => usb::vbus_detect::InterruptHandler; |
| 20 | }); | 24 | }); |
| 21 | 25 | ||
| 26 | static HID_PROTOCOL_MODE: AtomicU8 = AtomicU8::new(HidProtocolMode::Boot as u8); | ||
| 27 | |||
| 22 | #[embassy_executor::main] | 28 | #[embassy_executor::main] |
| 23 | async fn main(_spawner: Spawner) { | 29 | async fn main(_spawner: Spawner) { |
| 24 | let p = embassy_nrf::init(Default::default()); | 30 | let p = embassy_nrf::init(Default::default()); |
| @@ -37,6 +43,10 @@ async fn main(_spawner: Spawner) { | |||
| 37 | config.serial_number = Some("12345678"); | 43 | config.serial_number = Some("12345678"); |
| 38 | config.max_power = 100; | 44 | config.max_power = 100; |
| 39 | config.max_packet_size_0 = 64; | 45 | config.max_packet_size_0 = 64; |
| 46 | config.composite_with_iads = false; | ||
| 47 | config.device_class = 0; | ||
| 48 | config.device_sub_class = 0; | ||
| 49 | config.device_protocol = 0; | ||
| 40 | 50 | ||
| 41 | // Create embassy-usb DeviceBuilder using the driver and config. | 51 | // Create embassy-usb DeviceBuilder using the driver and config. |
| 42 | // It needs some buffers for building the descriptors. | 52 | // It needs some buffers for building the descriptors. |
| @@ -63,6 +73,8 @@ async fn main(_spawner: Spawner) { | |||
| 63 | request_handler: Some(&mut request_handler), | 73 | request_handler: Some(&mut request_handler), |
| 64 | poll_ms: 60, | 74 | poll_ms: 60, |
| 65 | max_packet_size: 8, | 75 | max_packet_size: 8, |
| 76 | hid_subclass: HidSubclass::Boot, | ||
| 77 | hid_boot_protocol: HidBootProtocol::Mouse, | ||
| 66 | }; | 78 | }; |
| 67 | 79 | ||
| 68 | let mut writer = HidWriter::<_, 5>::new(&mut builder, &mut state, config); | 80 | let mut writer = HidWriter::<_, 5>::new(&mut builder, &mut state, config); |
| @@ -80,16 +92,26 @@ async fn main(_spawner: Spawner) { | |||
| 80 | Timer::after_millis(500).await; | 92 | Timer::after_millis(500).await; |
| 81 | 93 | ||
| 82 | y = -y; | 94 | y = -y; |
| 83 | let report = MouseReport { | 95 | |
| 84 | buttons: 0, | 96 | if HID_PROTOCOL_MODE.load(Ordering::Relaxed) == HidProtocolMode::Boot as u8 { |
| 85 | x: 0, | 97 | let buttons = 0u8; |
| 86 | y, | 98 | let x = 0i8; |
| 87 | wheel: 0, | 99 | match writer.write(&[buttons, x as u8, y as u8]).await { |
| 88 | pan: 0, | 100 | Ok(()) => {} |
| 89 | }; | 101 | Err(e) => warn!("Failed to send boot report: {:?}", e), |
| 90 | match writer.write_serialize(&report).await { | 102 | } |
| 91 | Ok(()) => {} | 103 | } else { |
| 92 | Err(e) => warn!("Failed to send report: {:?}", e), | 104 | let report = MouseReport { |
| 105 | buttons: 0, | ||
| 106 | x: 0, | ||
| 107 | y, | ||
| 108 | wheel: 0, | ||
| 109 | pan: 0, | ||
| 110 | }; | ||
| 111 | match writer.write_serialize(&report).await { | ||
| 112 | Ok(()) => {} | ||
| 113 | Err(e) => warn!("Failed to send report: {:?}", e), | ||
| 114 | } | ||
| 93 | } | 115 | } |
| 94 | } | 116 | } |
| 95 | }; | 117 | }; |
| @@ -112,6 +134,18 @@ impl RequestHandler for MyRequestHandler { | |||
| 112 | OutResponse::Accepted | 134 | OutResponse::Accepted |
| 113 | } | 135 | } |
| 114 | 136 | ||
| 137 | fn get_protocol(&self) -> HidProtocolMode { | ||
| 138 | let protocol = HidProtocolMode::from(HID_PROTOCOL_MODE.load(Ordering::Relaxed)); | ||
| 139 | info!("The current HID protocol mode is: {}", protocol); | ||
| 140 | protocol | ||
| 141 | } | ||
| 142 | |||
| 143 | fn set_protocol(&mut self, protocol: HidProtocolMode) -> OutResponse { | ||
| 144 | info!("Switching to HID protocol mode: {}", protocol); | ||
| 145 | HID_PROTOCOL_MODE.store(protocol as u8, Ordering::Relaxed); | ||
| 146 | OutResponse::Accepted | ||
| 147 | } | ||
| 148 | |||
| 115 | fn set_idle_ms(&mut self, id: Option<ReportId>, dur: u32) { | 149 | fn set_idle_ms(&mut self, id: Option<ReportId>, dur: u32) { |
| 116 | info!("Set idle rate for {:?} to {:?}", id, dur); | 150 | info!("Set idle rate for {:?} to {:?}", id, dur); |
| 117 | } | 151 | } |
diff --git a/examples/nrf52840/src/bin/usb_serial.rs b/examples/nrf52840/src/bin/usb_serial.rs index e7c2d0854..469002bc7 100644 --- a/examples/nrf52840/src/bin/usb_serial.rs +++ b/examples/nrf52840/src/bin/usb_serial.rs | |||
| @@ -4,8 +4,8 @@ | |||
| 4 | use defmt::{info, panic}; | 4 | use defmt::{info, panic}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_futures::join::join; | 6 | use embassy_futures::join::join; |
| 7 | use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect}; | ||
| 8 | use embassy_nrf::usb::Driver; | 7 | use embassy_nrf::usb::Driver; |
| 8 | use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect}; | ||
| 9 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | 9 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; |
| 10 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 10 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 11 | use embassy_usb::driver::EndpointError; | 11 | use embassy_usb::driver::EndpointError; |
diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs index b6a983854..67b2bccbb 100644 --- a/examples/nrf52840/src/bin/usb_serial_multitask.rs +++ b/examples/nrf52840/src/bin/usb_serial_multitask.rs | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::{info, panic, unwrap}; | 4 | use defmt::{info, panic, unwrap}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; | ||
| 7 | use embassy_nrf::usb::Driver; | 6 | use embassy_nrf::usb::Driver; |
| 7 | use embassy_nrf::usb::vbus_detect::HardwareVbusDetect; | ||
| 8 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | 8 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; |
| 9 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 9 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 10 | use embassy_usb::driver::EndpointError; | 10 | use embassy_usb::driver::EndpointError; |
diff --git a/examples/nrf52840/src/bin/usb_serial_winusb.rs b/examples/nrf52840/src/bin/usb_serial_winusb.rs index e30e08a01..cd4d5bca1 100644 --- a/examples/nrf52840/src/bin/usb_serial_winusb.rs +++ b/examples/nrf52840/src/bin/usb_serial_winusb.rs | |||
| @@ -4,8 +4,8 @@ | |||
| 4 | use defmt::{info, panic}; | 4 | use defmt::{info, panic}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_futures::join::join; | 6 | use embassy_futures::join::join; |
| 7 | use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect}; | ||
| 8 | use embassy_nrf::usb::Driver; | 7 | use embassy_nrf::usb::Driver; |
| 8 | use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect}; | ||
| 9 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; | 9 | use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; |
| 10 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 10 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 11 | use embassy_usb::driver::EndpointError; | 11 | use embassy_usb::driver::EndpointError; |
diff --git a/examples/nrf52840/src/bin/wifi_esp_hosted.rs b/examples/nrf52840/src/bin/wifi_esp_hosted.rs index 1bc35746a..2f9c06b56 100644 --- a/examples/nrf52840/src/bin/wifi_esp_hosted.rs +++ b/examples/nrf52840/src/bin/wifi_esp_hosted.rs | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::{info, unwrap, warn}; | 4 | use defmt::{info, unwrap, warn}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_net::tcp::TcpSocket; | ||
| 7 | use embassy_net::StackResources; | 6 | use embassy_net::StackResources; |
| 7 | use embassy_net::tcp::TcpSocket; | ||
| 8 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; | 8 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; |
| 9 | use embassy_nrf::rng::Rng; | 9 | use embassy_nrf::rng::Rng; |
| 10 | use embassy_nrf::spim::{self, Spim}; | 10 | use embassy_nrf::spim::{self, Spim}; |
| @@ -27,14 +27,12 @@ bind_interrupts!(struct Irqs { | |||
| 27 | async fn wifi_task( | 27 | async fn wifi_task( |
| 28 | runner: hosted::Runner< | 28 | runner: hosted::Runner< |
| 29 | 'static, | 29 | 'static, |
| 30 | ExclusiveDevice<Spim<'static>, Output<'static>, Delay>, | 30 | hosted::SpiInterface<ExclusiveDevice<Spim<'static>, Output<'static>, Delay>, Input<'static>>, |
| 31 | Input<'static>, | ||
| 32 | Output<'static>, | 31 | Output<'static>, |
| 33 | >, | 32 | >, |
| 34 | ) -> ! { | 33 | ) -> ! { |
| 35 | runner.run().await | 34 | runner.run().await |
| 36 | } | 35 | } |
| 37 | |||
| 38 | #[embassy_executor::task] | 36 | #[embassy_executor::task] |
| 39 | async fn net_task(mut runner: embassy_net::Runner<'static, hosted::NetDriver<'static>>) -> ! { | 37 | async fn net_task(mut runner: embassy_net::Runner<'static, hosted::NetDriver<'static>>) -> ! { |
| 40 | runner.run().await | 38 | runner.run().await |
| @@ -60,15 +58,11 @@ async fn main(spawner: Spawner) { | |||
| 60 | let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config); | 58 | let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config); |
| 61 | let spi = ExclusiveDevice::new(spi, cs, Delay); | 59 | let spi = ExclusiveDevice::new(spi, cs, Delay); |
| 62 | 60 | ||
| 61 | let iface = hosted::SpiInterface::new(spi, handshake, ready); | ||
| 62 | |||
| 63 | static ESP_STATE: StaticCell<embassy_net_esp_hosted::State> = StaticCell::new(); | 63 | static ESP_STATE: StaticCell<embassy_net_esp_hosted::State> = StaticCell::new(); |
| 64 | let (device, mut control, runner) = embassy_net_esp_hosted::new( | 64 | let (device, mut control, runner) = |
| 65 | ESP_STATE.init(embassy_net_esp_hosted::State::new()), | 65 | embassy_net_esp_hosted::new(ESP_STATE.init(embassy_net_esp_hosted::State::new()), iface, reset).await; |
| 66 | spi, | ||
| 67 | handshake, | ||
| 68 | ready, | ||
| 69 | reset, | ||
| 70 | ) | ||
| 71 | .await; | ||
| 72 | 66 | ||
| 73 | spawner.spawn(unwrap!(wifi_task(runner))); | 67 | spawner.spawn(unwrap!(wifi_task(runner))); |
| 74 | 68 | ||
