diff options
| author | xoviat <[email protected]> | 2023-08-22 16:58:43 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-08-22 16:58:43 -0500 |
| commit | 7d6edd7b15d2209ac0b96ff8814ecefce2964e36 (patch) | |
| tree | 7988a9b46855ac187a92cbfc5f38cbbbff695e8d /examples/nrf52840 | |
| parent | 9e3266b74554ea397bdd963ff12a26aa51e77b63 (diff) | |
| parent | 7bff2ebab3b36cc922505e9db961840109c509ed (diff) | |
Merge branch 'main' of https://github.com/embassy-rs/embassy into rtc-lp
Diffstat (limited to 'examples/nrf52840')
| -rw-r--r-- | examples/nrf52840/Cargo.toml | 10 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/channel.rs | 2 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/channel_sender_receiver.rs | 2 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/ethernet_enc28j60.rs | 124 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/uart_split.rs | 2 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/wifi_esp_hosted.rs | 6 |
6 files changed, 139 insertions, 7 deletions
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml index 15fe22d3a..2ce44b516 100644 --- a/examples/nrf52840/Cargo.toml +++ b/examples/nrf52840/Cargo.toml | |||
| @@ -12,12 +12,14 @@ nightly = [ | |||
| 12 | "embassy-nrf/nightly", | 12 | "embassy-nrf/nightly", |
| 13 | "embassy-net/nightly", | 13 | "embassy-net/nightly", |
| 14 | "embassy-net-esp-hosted", | 14 | "embassy-net-esp-hosted", |
| 15 | "embassy-net-enc28j60", | ||
| 15 | "embassy-nrf/unstable-traits", | 16 | "embassy-nrf/unstable-traits", |
| 16 | "embassy-time/nightly", | 17 | "embassy-time/nightly", |
| 17 | "embassy-time/unstable-traits", | 18 | "embassy-time/unstable-traits", |
| 18 | "static_cell/nightly", | 19 | "static_cell/nightly", |
| 19 | "embassy-usb", | 20 | "embassy-usb", |
| 20 | "embedded-io-async", | 21 | "embedded-io-async", |
| 22 | "embedded-hal-bus/async", | ||
| 21 | "embassy-net", | 23 | "embassy-net", |
| 22 | "embassy-lora", | 24 | "embassy-lora", |
| 23 | "lora-phy", | 25 | "lora-phy", |
| @@ -40,6 +42,7 @@ lora-phy = { version = "1", optional = true } | |||
| 40 | lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"], optional = true } | 42 | lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"], optional = true } |
| 41 | lorawan = { version = "0.7.3", default-features = false, features = ["default-crypto"], optional = true } | 43 | lorawan = { version = "0.7.3", default-features = false, features = ["default-crypto"], optional = true } |
| 42 | embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"], optional = true } | 44 | embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"], optional = true } |
| 45 | embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"], optional = true } | ||
| 43 | 46 | ||
| 44 | defmt = "0.3" | 47 | defmt = "0.3" |
| 45 | defmt-rtt = "0.4" | 48 | defmt-rtt = "0.4" |
| @@ -54,9 +57,14 @@ rand = { version = "0.8.4", default-features = false } | |||
| 54 | embedded-storage = "0.3.0" | 57 | embedded-storage = "0.3.0" |
| 55 | usbd-hid = "0.6.0" | 58 | usbd-hid = "0.6.0" |
| 56 | serde = { version = "1.0.136", default-features = false } | 59 | serde = { version = "1.0.136", default-features = false } |
| 57 | embedded-hal-async = { version = "0.2.0-alpha.2", optional = true } | 60 | embedded-hal = { version = "1.0.0-rc.1" } |
| 61 | embedded-hal-async = { version = "1.0.0-rc.1", optional = true } | ||
| 62 | embedded-hal-bus = { version = "0.1.0-rc.1" } | ||
| 58 | num-integer = { version = "0.1.45", default-features = false } | 63 | num-integer = { version = "0.1.45", default-features = false } |
| 59 | microfft = "0.5.0" | 64 | microfft = "0.5.0" |
| 60 | 65 | ||
| 61 | [profile.release] | 66 | [profile.release] |
| 62 | debug = 2 | 67 | debug = 2 |
| 68 | |||
| 69 | [patch.crates-io] | ||
| 70 | lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"} \ No newline at end of file | ||
diff --git a/examples/nrf52840/src/bin/channel.rs b/examples/nrf52840/src/bin/channel.rs index d782a79e7..bd9c909da 100644 --- a/examples/nrf52840/src/bin/channel.rs +++ b/examples/nrf52840/src/bin/channel.rs | |||
| @@ -35,7 +35,7 @@ async fn main(spawner: Spawner) { | |||
| 35 | unwrap!(spawner.spawn(my_task())); | 35 | unwrap!(spawner.spawn(my_task())); |
| 36 | 36 | ||
| 37 | loop { | 37 | loop { |
| 38 | match CHANNEL.recv().await { | 38 | match CHANNEL.receive().await { |
| 39 | LedState::On => led.set_high(), | 39 | LedState::On => led.set_high(), |
| 40 | LedState::Off => led.set_low(), | 40 | LedState::Off => led.set_low(), |
| 41 | } | 41 | } |
diff --git a/examples/nrf52840/src/bin/channel_sender_receiver.rs b/examples/nrf52840/src/bin/channel_sender_receiver.rs index fcccdaed5..ec4f1d800 100644 --- a/examples/nrf52840/src/bin/channel_sender_receiver.rs +++ b/examples/nrf52840/src/bin/channel_sender_receiver.rs | |||
| @@ -33,7 +33,7 @@ async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedSta | |||
| 33 | let mut led = Output::new(led, Level::Low, OutputDrive::Standard); | 33 | let mut led = Output::new(led, Level::Low, OutputDrive::Standard); |
| 34 | 34 | ||
| 35 | loop { | 35 | loop { |
| 36 | match receiver.recv().await { | 36 | match receiver.receive().await { |
| 37 | LedState::On => led.set_high(), | 37 | LedState::On => led.set_high(), |
| 38 | LedState::Off => led.set_low(), | 38 | LedState::Off => led.set_low(), |
| 39 | } | 39 | } |
diff --git a/examples/nrf52840/src/bin/ethernet_enc28j60.rs b/examples/nrf52840/src/bin/ethernet_enc28j60.rs new file mode 100644 index 000000000..d1b796fab --- /dev/null +++ b/examples/nrf52840/src/bin/ethernet_enc28j60.rs | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_net::tcp::TcpSocket; | ||
| 8 | use embassy_net::{Stack, StackResources}; | ||
| 9 | use embassy_net_enc28j60::Enc28j60; | ||
| 10 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | ||
| 11 | use embassy_nrf::rng::Rng; | ||
| 12 | use embassy_nrf::spim::Spim; | ||
| 13 | use embassy_nrf::{bind_interrupts, peripherals, spim}; | ||
| 14 | use embassy_time::Delay; | ||
| 15 | use embedded_hal_bus::spi::ExclusiveDevice; | ||
| 16 | use embedded_io_async::Write; | ||
| 17 | use static_cell::make_static; | ||
| 18 | use {defmt_rtt as _, panic_probe as _}; | ||
| 19 | |||
| 20 | bind_interrupts!(struct Irqs { | ||
| 21 | SPIM3 => spim::InterruptHandler<peripherals::SPI3>; | ||
| 22 | RNG => embassy_nrf::rng::InterruptHandler<peripherals::RNG>; | ||
| 23 | }); | ||
| 24 | |||
| 25 | #[embassy_executor::task] | ||
| 26 | async fn net_task( | ||
| 27 | stack: &'static Stack< | ||
| 28 | Enc28j60< | ||
| 29 | ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static, peripherals::P0_15>, Delay>, | ||
| 30 | Output<'static, peripherals::P0_13>, | ||
| 31 | >, | ||
| 32 | >, | ||
| 33 | ) -> ! { | ||
| 34 | stack.run().await | ||
| 35 | } | ||
| 36 | |||
| 37 | #[embassy_executor::main] | ||
| 38 | async fn main(spawner: Spawner) { | ||
| 39 | let p = embassy_nrf::init(Default::default()); | ||
| 40 | info!("running!"); | ||
| 41 | |||
| 42 | let eth_sck = p.P0_20; | ||
| 43 | let eth_mosi = p.P0_22; | ||
| 44 | let eth_miso = p.P0_24; | ||
| 45 | let eth_cs = p.P0_15; | ||
| 46 | let eth_rst = p.P0_13; | ||
| 47 | let _eth_irq = p.P0_12; | ||
| 48 | |||
| 49 | let mut config = spim::Config::default(); | ||
| 50 | config.frequency = spim::Frequency::M16; | ||
| 51 | let spi = spim::Spim::new(p.SPI3, Irqs, eth_sck, eth_miso, eth_mosi, config); | ||
| 52 | let cs = Output::new(eth_cs, Level::High, OutputDrive::Standard); | ||
| 53 | let spi = ExclusiveDevice::new(spi, cs, Delay); | ||
| 54 | |||
| 55 | let rst = Output::new(eth_rst, Level::High, OutputDrive::Standard); | ||
| 56 | let mac_addr = [2, 3, 4, 5, 6, 7]; | ||
| 57 | let device = Enc28j60::new(spi, Some(rst), mac_addr); | ||
| 58 | |||
| 59 | let config = embassy_net::Config::dhcpv4(Default::default()); | ||
| 60 | // let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { | ||
| 61 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | ||
| 62 | // dns_servers: Vec::new(), | ||
| 63 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | ||
| 64 | // }); | ||
| 65 | |||
| 66 | // Generate random seed | ||
| 67 | let mut rng = Rng::new(p.RNG, Irqs); | ||
| 68 | let mut seed = [0; 8]; | ||
| 69 | rng.blocking_fill_bytes(&mut seed); | ||
| 70 | let seed = u64::from_le_bytes(seed); | ||
| 71 | |||
| 72 | // Init network stack | ||
| 73 | let stack = &*make_static!(Stack::new( | ||
| 74 | device, | ||
| 75 | config, | ||
| 76 | make_static!(StackResources::<2>::new()), | ||
| 77 | seed | ||
| 78 | )); | ||
| 79 | |||
| 80 | unwrap!(spawner.spawn(net_task(stack))); | ||
| 81 | |||
| 82 | // And now we can use it! | ||
| 83 | |||
| 84 | let mut rx_buffer = [0; 4096]; | ||
| 85 | let mut tx_buffer = [0; 4096]; | ||
| 86 | let mut buf = [0; 4096]; | ||
| 87 | |||
| 88 | loop { | ||
| 89 | let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer); | ||
| 90 | socket.set_timeout(Some(embassy_time::Duration::from_secs(10))); | ||
| 91 | |||
| 92 | info!("Listening on TCP:1234..."); | ||
| 93 | if let Err(e) = socket.accept(1234).await { | ||
| 94 | warn!("accept error: {:?}", e); | ||
| 95 | continue; | ||
| 96 | } | ||
| 97 | |||
| 98 | info!("Received connection from {:?}", socket.remote_endpoint()); | ||
| 99 | |||
| 100 | loop { | ||
| 101 | let n = match socket.read(&mut buf).await { | ||
| 102 | Ok(0) => { | ||
| 103 | warn!("read EOF"); | ||
| 104 | break; | ||
| 105 | } | ||
| 106 | Ok(n) => n, | ||
| 107 | Err(e) => { | ||
| 108 | warn!("read error: {:?}", e); | ||
| 109 | break; | ||
| 110 | } | ||
| 111 | }; | ||
| 112 | |||
| 113 | info!("rxd {:02x}", &buf[..n]); | ||
| 114 | |||
| 115 | match socket.write_all(&buf[..n]).await { | ||
| 116 | Ok(()) => {} | ||
| 117 | Err(e) => { | ||
| 118 | warn!("write error: {:?}", e); | ||
| 119 | break; | ||
| 120 | } | ||
| 121 | }; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | } | ||
diff --git a/examples/nrf52840/src/bin/uart_split.rs b/examples/nrf52840/src/bin/uart_split.rs index 9979a1d53..b748bfcd8 100644 --- a/examples/nrf52840/src/bin/uart_split.rs +++ b/examples/nrf52840/src/bin/uart_split.rs | |||
| @@ -46,7 +46,7 @@ async fn main(spawner: Spawner) { | |||
| 46 | // back out the buffer we receive from the read | 46 | // back out the buffer we receive from the read |
| 47 | // task. | 47 | // task. |
| 48 | loop { | 48 | loop { |
| 49 | let buf = CHANNEL.recv().await; | 49 | let buf = CHANNEL.receive().await; |
| 50 | info!("writing..."); | 50 | info!("writing..."); |
| 51 | unwrap!(tx.write(&buf).await); | 51 | unwrap!(tx.write(&buf).await); |
| 52 | } | 52 | } |
diff --git a/examples/nrf52840/src/bin/wifi_esp_hosted.rs b/examples/nrf52840/src/bin/wifi_esp_hosted.rs index e3b80d821..a60822fd9 100644 --- a/examples/nrf52840/src/bin/wifi_esp_hosted.rs +++ b/examples/nrf52840/src/bin/wifi_esp_hosted.rs | |||
| @@ -11,7 +11,7 @@ use embassy_nrf::rng::Rng; | |||
| 11 | use embassy_nrf::spim::{self, Spim}; | 11 | use embassy_nrf::spim::{self, Spim}; |
| 12 | use embassy_nrf::{bind_interrupts, peripherals}; | 12 | use embassy_nrf::{bind_interrupts, peripherals}; |
| 13 | use embassy_time::Delay; | 13 | use embassy_time::Delay; |
| 14 | use embedded_hal_async::spi::ExclusiveDevice; | 14 | use embedded_hal_bus::spi::ExclusiveDevice; |
| 15 | use embedded_io_async::Write; | 15 | use embedded_io_async::Write; |
| 16 | use static_cell::make_static; | 16 | use static_cell::make_static; |
| 17 | use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _}; | 17 | use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _}; |
| @@ -72,8 +72,8 @@ async fn main(spawner: Spawner) { | |||
| 72 | 72 | ||
| 73 | unwrap!(spawner.spawn(wifi_task(runner))); | 73 | unwrap!(spawner.spawn(wifi_task(runner))); |
| 74 | 74 | ||
| 75 | control.init().await; | 75 | unwrap!(control.init().await); |
| 76 | control.join(WIFI_NETWORK, WIFI_PASSWORD).await; | 76 | unwrap!(control.connect(WIFI_NETWORK, WIFI_PASSWORD).await); |
| 77 | 77 | ||
| 78 | let config = embassy_net::Config::dhcpv4(Default::default()); | 78 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 79 | // let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { | 79 | // let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
