diff options
Diffstat (limited to 'examples/nrf52840/src/bin')
| -rw-r--r-- | examples/nrf52840/src/bin/ethernet_enc28j60.rs | 2 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/rtc.rs | 56 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/sixlowpan.rs | 2 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/uart_split.rs | 2 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/usb_ethernet.rs | 2 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/usb_serial.rs | 6 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/usb_serial_multitask.rs | 2 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/usb_serial_winusb.rs | 6 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/wifi_esp_hosted.rs | 2 |
9 files changed, 66 insertions, 14 deletions
diff --git a/examples/nrf52840/src/bin/ethernet_enc28j60.rs b/examples/nrf52840/src/bin/ethernet_enc28j60.rs index 3bb255a72..e59afd37f 100644 --- a/examples/nrf52840/src/bin/ethernet_enc28j60.rs +++ b/examples/nrf52840/src/bin/ethernet_enc28j60.rs | |||
| @@ -25,7 +25,7 @@ bind_interrupts!(struct Irqs { | |||
| 25 | async fn net_task( | 25 | async fn net_task( |
| 26 | mut runner: embassy_net::Runner< | 26 | mut runner: embassy_net::Runner< |
| 27 | 'static, | 27 | 'static, |
| 28 | Enc28j60<ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static>, Delay>, Output<'static>>, | 28 | Enc28j60<ExclusiveDevice<Spim<'static>, Output<'static>, Delay>, Output<'static>>, |
| 29 | >, | 29 | >, |
| 30 | ) -> ! { | 30 | ) -> ! { |
| 31 | runner.run().await | 31 | runner.run().await |
diff --git a/examples/nrf52840/src/bin/rtc.rs b/examples/nrf52840/src/bin/rtc.rs new file mode 100644 index 000000000..9d475df7f --- /dev/null +++ b/examples/nrf52840/src/bin/rtc.rs | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | ||
| 8 | use embassy_nrf::interrupt; | ||
| 9 | use embassy_nrf::rtc::Rtc; | ||
| 10 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 11 | use embassy_sync::blocking_mutex::Mutex; | ||
| 12 | use portable_atomic::AtomicU64; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | |||
| 15 | // 64 bit counter which will never overflow. | ||
| 16 | static TICK_COUNTER: AtomicU64 = AtomicU64::new(0); | ||
| 17 | static RTC: Mutex<CriticalSectionRawMutex, RefCell<Option<Rtc<'static>>>> = Mutex::new(RefCell::new(None)); | ||
| 18 | |||
| 19 | #[embassy_executor::main] | ||
| 20 | async fn main(_spawner: Spawner) { | ||
| 21 | defmt::println!("nRF52840 RTC example"); | ||
| 22 | let p = embassy_nrf::init(Default::default()); | ||
| 23 | let mut led = Output::new(p.P0_13, Level::High, OutputDrive::Standard); | ||
| 24 | // Counter resolution is 125 ms. | ||
| 25 | let mut rtc = Rtc::new(p.RTC0, (1 << 12) - 1).unwrap(); | ||
| 26 | rtc.enable_interrupt(embassy_nrf::rtc::Interrupt::Tick, true); | ||
| 27 | rtc.enable_event(embassy_nrf::rtc::Interrupt::Tick); | ||
| 28 | rtc.enable(); | ||
| 29 | RTC.lock(|r| { | ||
| 30 | let mut rtc_borrow = r.borrow_mut(); | ||
| 31 | *rtc_borrow = Some(rtc); | ||
| 32 | }); | ||
| 33 | |||
| 34 | let mut last_counter_val = 0; | ||
| 35 | loop { | ||
| 36 | let current = TICK_COUNTER.load(core::sync::atomic::Ordering::Relaxed); | ||
| 37 | if current != last_counter_val { | ||
| 38 | led.toggle(); | ||
| 39 | last_counter_val = current; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | #[interrupt] | ||
| 45 | fn RTC0() { | ||
| 46 | // For 64-bit, we do not need to worry about overflowing, at least not for realistic program | ||
| 47 | // lifetimes. | ||
| 48 | TICK_COUNTER.fetch_add(1, core::sync::atomic::Ordering::Relaxed); | ||
| 49 | RTC.lock(|r| { | ||
| 50 | let mut rtc_borrow = r.borrow_mut(); | ||
| 51 | rtc_borrow | ||
| 52 | .as_mut() | ||
| 53 | .unwrap() | ||
| 54 | .reset_event(embassy_nrf::rtc::Interrupt::Tick); | ||
| 55 | }); | ||
| 56 | } | ||
diff --git a/examples/nrf52840/src/bin/sixlowpan.rs b/examples/nrf52840/src/bin/sixlowpan.rs index 00a597366..12e385e01 100644 --- a/examples/nrf52840/src/bin/sixlowpan.rs +++ b/examples/nrf52840/src/bin/sixlowpan.rs | |||
| @@ -21,7 +21,7 @@ bind_interrupts!(struct Irqs { | |||
| 21 | }); | 21 | }); |
| 22 | 22 | ||
| 23 | #[embassy_executor::task] | 23 | #[embassy_executor::task] |
| 24 | async fn ieee802154_task(runner: net::Runner<'static, peripherals::RADIO>) -> ! { | 24 | async fn ieee802154_task(runner: net::Runner<'static>) -> ! { |
| 25 | runner.run().await | 25 | runner.run().await |
| 26 | } | 26 | } |
| 27 | 27 | ||
diff --git a/examples/nrf52840/src/bin/uart_split.rs b/examples/nrf52840/src/bin/uart_split.rs index 51af90727..d75143126 100644 --- a/examples/nrf52840/src/bin/uart_split.rs +++ b/examples/nrf52840/src/bin/uart_split.rs | |||
| @@ -52,7 +52,7 @@ async fn main(spawner: Spawner) { | |||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | #[embassy_executor::task] | 54 | #[embassy_executor::task] |
| 55 | async fn reader(mut rx: UarteRx<'static, UARTE0>) { | 55 | async fn reader(mut rx: UarteRx<'static>) { |
| 56 | let mut buf = [0; 8]; | 56 | let mut buf = [0; 8]; |
| 57 | loop { | 57 | loop { |
| 58 | info!("reading..."); | 58 | info!("reading..."); |
diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs index 87aa4c6c5..a75b967b4 100644 --- a/examples/nrf52840/src/bin/usb_ethernet.rs +++ b/examples/nrf52840/src/bin/usb_ethernet.rs | |||
| @@ -22,7 +22,7 @@ bind_interrupts!(struct Irqs { | |||
| 22 | RNG => rng::InterruptHandler<peripherals::RNG>; | 22 | RNG => rng::InterruptHandler<peripherals::RNG>; |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; | 25 | type MyDriver = Driver<'static, HardwareVbusDetect>; |
| 26 | 26 | ||
| 27 | const MTU: usize = 1514; | 27 | const MTU: usize = 1514; |
| 28 | 28 | ||
diff --git a/examples/nrf52840/src/bin/usb_serial.rs b/examples/nrf52840/src/bin/usb_serial.rs index 8d05df791..e7c2d0854 100644 --- a/examples/nrf52840/src/bin/usb_serial.rs +++ b/examples/nrf52840/src/bin/usb_serial.rs | |||
| @@ -5,7 +5,7 @@ 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}; | 7 | use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect}; |
| 8 | use embassy_nrf::usb::{Driver, Instance}; | 8 | use embassy_nrf::usb::Driver; |
| 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; |
| @@ -89,9 +89,7 @@ impl From<EndpointError> for Disconnected { | |||
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | async fn echo<'d, T: Instance + 'd, P: VbusDetect + 'd>( | 92 | async fn echo<'d, V: VbusDetect + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, V>>) -> Result<(), Disconnected> { |
| 93 | class: &mut CdcAcmClass<'d, Driver<'d, T, P>>, | ||
| 94 | ) -> Result<(), Disconnected> { | ||
| 95 | let mut buf = [0; 64]; | 93 | let mut buf = [0; 64]; |
| 96 | loop { | 94 | loop { |
| 97 | let n = class.read_packet(&mut buf).await?; | 95 | let n = class.read_packet(&mut buf).await?; |
diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs index 00a91a233..b6a983854 100644 --- a/examples/nrf52840/src/bin/usb_serial_multitask.rs +++ b/examples/nrf52840/src/bin/usb_serial_multitask.rs | |||
| @@ -17,7 +17,7 @@ bind_interrupts!(struct Irqs { | |||
| 17 | CLOCK_POWER => usb::vbus_detect::InterruptHandler; | 17 | CLOCK_POWER => usb::vbus_detect::InterruptHandler; |
| 18 | }); | 18 | }); |
| 19 | 19 | ||
| 20 | type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; | 20 | type MyDriver = Driver<'static, HardwareVbusDetect>; |
| 21 | 21 | ||
| 22 | #[embassy_executor::task] | 22 | #[embassy_executor::task] |
| 23 | async fn usb_task(mut device: UsbDevice<'static, MyDriver>) { | 23 | async fn usb_task(mut device: UsbDevice<'static, MyDriver>) { |
diff --git a/examples/nrf52840/src/bin/usb_serial_winusb.rs b/examples/nrf52840/src/bin/usb_serial_winusb.rs index 8a20ce673..e30e08a01 100644 --- a/examples/nrf52840/src/bin/usb_serial_winusb.rs +++ b/examples/nrf52840/src/bin/usb_serial_winusb.rs | |||
| @@ -5,7 +5,7 @@ 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}; | 7 | use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect}; |
| 8 | use embassy_nrf::usb::{Driver, Instance}; | 8 | use embassy_nrf::usb::Driver; |
| 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; |
| @@ -108,9 +108,7 @@ impl From<EndpointError> for Disconnected { | |||
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | async fn echo<'d, T: Instance + 'd, P: VbusDetect + 'd>( | 111 | async fn echo<'d, V: VbusDetect + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, V>>) -> Result<(), Disconnected> { |
| 112 | class: &mut CdcAcmClass<'d, Driver<'d, T, P>>, | ||
| 113 | ) -> Result<(), Disconnected> { | ||
| 114 | let mut buf = [0; 64]; | 112 | let mut buf = [0; 64]; |
| 115 | loop { | 113 | loop { |
| 116 | let n = class.read_packet(&mut buf).await?; | 114 | let n = class.read_packet(&mut buf).await?; |
diff --git a/examples/nrf52840/src/bin/wifi_esp_hosted.rs b/examples/nrf52840/src/bin/wifi_esp_hosted.rs index 2dd9abfaa..1bc35746a 100644 --- a/examples/nrf52840/src/bin/wifi_esp_hosted.rs +++ b/examples/nrf52840/src/bin/wifi_esp_hosted.rs | |||
| @@ -27,7 +27,7 @@ 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, peripherals::SPI3>, Output<'static>, Delay>, | 30 | ExclusiveDevice<Spim<'static>, Output<'static>, Delay>, |
| 31 | Input<'static>, | 31 | Input<'static>, |
| 32 | Output<'static>, | 32 | Output<'static>, |
| 33 | >, | 33 | >, |
