diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-06-02 01:30:07 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-06-02 01:32:19 +0200 |
| commit | dff03ecfc74d6af716637888338ebfa99ab7a027 (patch) | |
| tree | c06bf2b0a2e6657c3427c956dbd27a4e45211aaa | |
| parent | a0c5f7137fe0c45b8db0aad2a116aea91e6a93f7 (diff) | |
Move examples to a subdirectory
| -rw-r--r-- | .github/workflows/rust.yml | 16 | ||||
| -rw-r--r-- | .vscode/settings.json | 4 | ||||
| -rw-r--r-- | Cargo.example.toml | 9 | ||||
| -rw-r--r-- | embassy-std-examples/Cargo.toml | 14 | ||||
| -rw-r--r-- | examples/nrf/.cargo/config.toml (renamed from embassy-nrf-examples/.cargo/config.toml) | 0 | ||||
| -rw-r--r-- | examples/nrf/Cargo.toml (renamed from embassy-nrf-examples/Cargo.toml) | 6 | ||||
| -rw-r--r-- | examples/nrf/build.rs (renamed from embassy-nrf-examples/build.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/memory.x (renamed from embassy-nrf-examples/memory.x) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/blinky.rs (renamed from embassy-nrf-examples/src/bin/blinky.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/buffered_uart.rs (renamed from embassy-nrf-examples/src/bin/buffered_uart.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/executor_fairness_test.rs (renamed from embassy-nrf-examples/src/bin/executor_fairness_test.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/gpiote_channel.rs (renamed from embassy-nrf-examples/src/bin/gpiote_channel.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/gpiote_port.rs (renamed from embassy-nrf-examples/src/bin/gpiote_port.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/multiprio.rs (renamed from embassy-nrf-examples/src/bin/multiprio.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/ppi.rs (renamed from embassy-nrf-examples/src/bin/ppi.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/pwm.rs (renamed from embassy-nrf-examples/src/bin/pwm.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/qspi.rs (renamed from embassy-nrf-examples/src/bin/qspi.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/qspi_lowpower.rs (renamed from embassy-nrf-examples/src/bin/qspi_lowpower.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/raw_spawn.rs (renamed from embassy-nrf-examples/src/bin/raw_spawn.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/spim.rs (renamed from embassy-nrf-examples/src/bin/spim.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/timer.rs (renamed from embassy-nrf-examples/src/bin/timer.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/twim.rs (renamed from embassy-nrf-examples/src/bin/twim.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/twim_lowpower.rs (renamed from embassy-nrf-examples/src/bin/twim_lowpower.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/uart.rs (renamed from embassy-nrf-examples/src/bin/uart.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/bin/uart_idle.rs (renamed from embassy-nrf-examples/src/bin/uart_idle.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf/src/example_common.rs (renamed from embassy-nrf-examples/src/example_common.rs) | 0 | ||||
| -rw-r--r-- | examples/rp/.cargo/config.toml (renamed from embassy-rp-examples/.cargo/config.toml) | 0 | ||||
| -rw-r--r-- | examples/rp/Cargo.toml (renamed from embassy-rp-examples/Cargo.toml) | 4 | ||||
| -rw-r--r-- | examples/rp/build.rs (renamed from embassy-rp-examples/build.rs) | 0 | ||||
| -rw-r--r-- | examples/rp/memory.x (renamed from embassy-rp-examples/memory.x) | 0 | ||||
| -rw-r--r-- | examples/rp/src/bin/blinky.rs (renamed from embassy-rp-examples/src/bin/blinky.rs) | 0 | ||||
| -rw-r--r-- | examples/rp/src/bin/button.rs (renamed from embassy-rp-examples/src/bin/button.rs) | 0 | ||||
| -rw-r--r-- | examples/rp/src/bin/uart.rs (renamed from embassy-rp-examples/src/bin/uart.rs) | 0 | ||||
| -rw-r--r-- | examples/rp/src/example_common.rs (renamed from embassy-rp-examples/src/example_common.rs) | 0 | ||||
| -rw-r--r-- | examples/std/Cargo.toml | 21 | ||||
| -rw-r--r-- | examples/std/src/bin/net.rs | 103 | ||||
| -rw-r--r-- | examples/std/src/bin/serial.rs (renamed from embassy-std-examples/src/bin/serial.rs) | 0 | ||||
| -rw-r--r-- | examples/std/src/bin/tick.rs (renamed from embassy-std-examples/src/bin/tick.rs) | 0 | ||||
| -rw-r--r-- | examples/std/src/serial_port.rs (renamed from embassy-std-examples/src/serial_port.rs) | 0 | ||||
| -rw-r--r-- | examples/std/src/tuntap.rs | 225 | ||||
| -rw-r--r-- | examples/stm32f4/.cargo/config.toml (renamed from embassy-stm32-examples/.cargo/config.toml) | 0 | ||||
| -rw-r--r-- | examples/stm32f4/Cargo.toml (renamed from embassy-stm32-examples/Cargo.toml) | 8 | ||||
| -rw-r--r-- | examples/stm32f4/build.rs (renamed from embassy-stm32-examples/build.rs) | 0 | ||||
| -rw-r--r-- | examples/stm32f4/memory.x (renamed from embassy-stm32-examples/memory.x) | 0 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/blinky.rs (renamed from embassy-stm32-examples/src/bin/blinky.rs) | 0 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/button.rs (renamed from embassy-stm32-examples/src/bin/button.rs) | 0 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/button_exti.rs (renamed from embassy-stm32-examples/src/bin/button_exti.rs) | 0 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/spi.rs (renamed from embassy-stm32-examples/src/bin/spi.rs) | 0 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/usart.rs (renamed from embassy-stm32-examples/src/bin/usart.rs) | 0 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/usart_dma.rs (renamed from embassy-stm32-examples/src/bin/usart_dma.rs) | 0 | ||||
| -rw-r--r-- | examples/stm32f4/src/example_common.rs (renamed from embassy-stm32-examples/src/example_common.rs) | 0 |
51 files changed, 374 insertions, 36 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 542107005..3fdc10ab2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml | |||
| @@ -26,12 +26,10 @@ jobs: | |||
| 26 | - package: embassy | 26 | - package: embassy |
| 27 | target: thumbv6m-none-eabi | 27 | target: thumbv6m-none-eabi |
| 28 | features: defmt | 28 | features: defmt |
| 29 | - package: embassy-std-examples | 29 | |
| 30 | target: x86_64-unknown-linux-gnu | 30 | - package: examples/std |
| 31 | - package: embassy-net-examples | ||
| 32 | target: x86_64-unknown-linux-gnu | 31 | target: x86_64-unknown-linux-gnu |
| 33 | - package: embassy-nrf-examples | 32 | |
| 34 | target: thumbv7em-none-eabi | ||
| 35 | - package: embassy-nrf | 33 | - package: embassy-nrf |
| 36 | target: thumbv7em-none-eabi | 34 | target: thumbv7em-none-eabi |
| 37 | features: nrf52805 | 35 | features: nrf52805 |
| @@ -59,8 +57,12 @@ jobs: | |||
| 59 | - package: embassy-nrf | 57 | - package: embassy-nrf |
| 60 | target: thumbv7em-none-eabi | 58 | target: thumbv7em-none-eabi |
| 61 | features: nrf52840,defmt | 59 | features: nrf52840,defmt |
| 62 | - package: embassy-rp-examples | 60 | - package: examples/nrf |
| 61 | target: thumbv7em-none-eabi | ||
| 62 | |||
| 63 | - package: examples/rp | ||
| 63 | target: thumbv6m-none-eabi | 64 | target: thumbv6m-none-eabi |
| 65 | |||
| 64 | - package: embassy-stm32 | 66 | - package: embassy-stm32 |
| 65 | target: thumbv7em-none-eabi | 67 | target: thumbv7em-none-eabi |
| 66 | features: stm32f411ce,defmt | 68 | features: stm32f411ce,defmt |
| @@ -76,7 +78,7 @@ jobs: | |||
| 76 | - package: embassy-stm32 | 78 | - package: embassy-stm32 |
| 77 | target: thumbv6m-none-eabi | 79 | target: thumbv6m-none-eabi |
| 78 | features: stm32l053r8,defmt | 80 | features: stm32l053r8,defmt |
| 79 | - package: embassy-stm32-examples | 81 | - package: examples/stm32f4 |
| 80 | target: thumbv7em-none-eabi | 82 | target: thumbv7em-none-eabi |
| 81 | 83 | ||
| 82 | steps: | 84 | steps: |
diff --git a/.vscode/settings.json b/.vscode/settings.json index ca242662b..4c6c3bece 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | "editor.formatOnSave": true, | 3 | "editor.formatOnSave": true, |
| 4 | "rust-analyzer.checkOnSave.allFeatures": false, | 4 | "rust-analyzer.checkOnSave.allFeatures": false, |
| 5 | "rust-analyzer.checkOnSave.allTargets": false, | 5 | "rust-analyzer.checkOnSave.allTargets": false, |
| 6 | "rust-analyzer.cargo.target": "thumbv7em-none-eabi", | 6 | //"rust-analyzer.cargo.target": "thumbv7em-none-eabi", |
| 7 | "rust-analyzer.checkOnSave.target": "thumbv7em-none-eabi", | 7 | //"rust-analyzer.checkOnSave.target": "thumbv7em-none-eabi", |
| 8 | "rust-analyzer.procMacro.enable": true, | 8 | "rust-analyzer.procMacro.enable": true, |
| 9 | "rust-analyzer.cargo.loadOutDirsFromCheck": true, | 9 | "rust-analyzer.cargo.loadOutDirsFromCheck": true, |
| 10 | "files.watcherExclude": { | 10 | "files.watcherExclude": { |
diff --git a/Cargo.example.toml b/Cargo.example.toml index 010487b51..da3a80299 100644 --- a/Cargo.example.toml +++ b/Cargo.example.toml | |||
| @@ -25,20 +25,21 @@ members = [ | |||
| 25 | 25 | ||
| 26 | # nRF | 26 | # nRF |
| 27 | #"embassy-nrf", | 27 | #"embassy-nrf", |
| 28 | #"embassy-nrf-examples", | 28 | #"examples/nrf", |
| 29 | 29 | ||
| 30 | # stm32 | 30 | # stm32 |
| 31 | #"embassy-stm32", | 31 | #"embassy-stm32", |
| 32 | #"embassy-stm32-examples", | ||
| 33 | #"stm32-metapac", | 32 | #"stm32-metapac", |
| 33 | # uncomment ONLY ONE example crate. | ||
| 34 | #"examples/stm32f4", | ||
| 34 | 35 | ||
| 35 | # rp2040 | 36 | # rp2040 |
| 36 | #"embassy-rp", | 37 | #"embassy-rp", |
| 37 | #"embassy-rp-examples", | 38 | #"examples/rp2040", |
| 38 | 39 | ||
| 39 | # std | 40 | # std |
| 40 | #"embassy-std", | 41 | #"embassy-std", |
| 41 | #"embassy-std-examples", | 42 | #"examples/std", |
| 42 | ] | 43 | ] |
| 43 | 44 | ||
| 44 | [profile.dev] | 45 | [profile.dev] |
diff --git a/embassy-std-examples/Cargo.toml b/embassy-std-examples/Cargo.toml deleted file mode 100644 index 0998899c8..000000000 --- a/embassy-std-examples/Cargo.toml +++ /dev/null | |||
| @@ -1,14 +0,0 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] | ||
| 3 | edition = "2018" | ||
| 4 | name = "embassy-std-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | async-io = "1.3.1" | ||
| 9 | embassy = { version = "0.1.0", path = "../embassy", features = ["log"] } | ||
| 10 | embassy-std = { version = "0.1.0", path = "../embassy-std" } | ||
| 11 | env_logger = "0.8.2" | ||
| 12 | futures = { version = "0.3.8", default-features = false, features = ["async-await"] } | ||
| 13 | log = "0.4.11" | ||
| 14 | nix = "0.19.1" | ||
diff --git a/embassy-nrf-examples/.cargo/config.toml b/examples/nrf/.cargo/config.toml index 58ac3debd..58ac3debd 100644 --- a/embassy-nrf-examples/.cargo/config.toml +++ b/examples/nrf/.cargo/config.toml | |||
diff --git a/embassy-nrf-examples/Cargo.toml b/examples/nrf/Cargo.toml index 4cec37522..fa1dab360 100644 --- a/embassy-nrf-examples/Cargo.toml +++ b/examples/nrf/Cargo.toml | |||
| @@ -17,9 +17,9 @@ defmt-error = [] | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | [dependencies] | 19 | [dependencies] |
| 20 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] } | 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-traits = { version = "0.1.0", path = "../embassy-traits", features = ["defmt"] } | 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 22 | embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt", "defmt-trace", "nrf52840"] } | 22 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "defmt-trace", "nrf52840"] } |
| 23 | 23 | ||
| 24 | defmt = "0.2.0" | 24 | defmt = "0.2.0" |
| 25 | defmt-rtt = "0.2.0" | 25 | defmt-rtt = "0.2.0" |
diff --git a/embassy-nrf-examples/build.rs b/examples/nrf/build.rs index d534cc3df..d534cc3df 100644 --- a/embassy-nrf-examples/build.rs +++ b/examples/nrf/build.rs | |||
diff --git a/embassy-nrf-examples/memory.x b/examples/nrf/memory.x index 9b04edec0..9b04edec0 100644 --- a/embassy-nrf-examples/memory.x +++ b/examples/nrf/memory.x | |||
diff --git a/embassy-nrf-examples/src/bin/blinky.rs b/examples/nrf/src/bin/blinky.rs index 8f12cfda9..8f12cfda9 100644 --- a/embassy-nrf-examples/src/bin/blinky.rs +++ b/examples/nrf/src/bin/blinky.rs | |||
diff --git a/embassy-nrf-examples/src/bin/buffered_uart.rs b/examples/nrf/src/bin/buffered_uart.rs index c800e64fc..c800e64fc 100644 --- a/embassy-nrf-examples/src/bin/buffered_uart.rs +++ b/examples/nrf/src/bin/buffered_uart.rs | |||
diff --git a/embassy-nrf-examples/src/bin/executor_fairness_test.rs b/examples/nrf/src/bin/executor_fairness_test.rs index 797be4335..797be4335 100644 --- a/embassy-nrf-examples/src/bin/executor_fairness_test.rs +++ b/examples/nrf/src/bin/executor_fairness_test.rs | |||
diff --git a/embassy-nrf-examples/src/bin/gpiote_channel.rs b/examples/nrf/src/bin/gpiote_channel.rs index 9800aed98..9800aed98 100644 --- a/embassy-nrf-examples/src/bin/gpiote_channel.rs +++ b/examples/nrf/src/bin/gpiote_channel.rs | |||
diff --git a/embassy-nrf-examples/src/bin/gpiote_port.rs b/examples/nrf/src/bin/gpiote_port.rs index 4a7951cd3..4a7951cd3 100644 --- a/embassy-nrf-examples/src/bin/gpiote_port.rs +++ b/examples/nrf/src/bin/gpiote_port.rs | |||
diff --git a/embassy-nrf-examples/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs index 79fa029b3..79fa029b3 100644 --- a/embassy-nrf-examples/src/bin/multiprio.rs +++ b/examples/nrf/src/bin/multiprio.rs | |||
diff --git a/embassy-nrf-examples/src/bin/ppi.rs b/examples/nrf/src/bin/ppi.rs index 717604b9e..717604b9e 100644 --- a/embassy-nrf-examples/src/bin/ppi.rs +++ b/examples/nrf/src/bin/ppi.rs | |||
diff --git a/embassy-nrf-examples/src/bin/pwm.rs b/examples/nrf/src/bin/pwm.rs index d2874a29b..d2874a29b 100644 --- a/embassy-nrf-examples/src/bin/pwm.rs +++ b/examples/nrf/src/bin/pwm.rs | |||
diff --git a/embassy-nrf-examples/src/bin/qspi.rs b/examples/nrf/src/bin/qspi.rs index 6e49887a4..6e49887a4 100644 --- a/embassy-nrf-examples/src/bin/qspi.rs +++ b/examples/nrf/src/bin/qspi.rs | |||
diff --git a/embassy-nrf-examples/src/bin/qspi_lowpower.rs b/examples/nrf/src/bin/qspi_lowpower.rs index ece3243b6..ece3243b6 100644 --- a/embassy-nrf-examples/src/bin/qspi_lowpower.rs +++ b/examples/nrf/src/bin/qspi_lowpower.rs | |||
diff --git a/embassy-nrf-examples/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs index 78de7b100..78de7b100 100644 --- a/embassy-nrf-examples/src/bin/raw_spawn.rs +++ b/examples/nrf/src/bin/raw_spawn.rs | |||
diff --git a/embassy-nrf-examples/src/bin/spim.rs b/examples/nrf/src/bin/spim.rs index c42cc6015..c42cc6015 100644 --- a/embassy-nrf-examples/src/bin/spim.rs +++ b/examples/nrf/src/bin/spim.rs | |||
diff --git a/embassy-nrf-examples/src/bin/timer.rs b/examples/nrf/src/bin/timer.rs index 43f6d76ce..43f6d76ce 100644 --- a/embassy-nrf-examples/src/bin/timer.rs +++ b/examples/nrf/src/bin/timer.rs | |||
diff --git a/embassy-nrf-examples/src/bin/twim.rs b/examples/nrf/src/bin/twim.rs index 537cea160..537cea160 100644 --- a/embassy-nrf-examples/src/bin/twim.rs +++ b/examples/nrf/src/bin/twim.rs | |||
diff --git a/embassy-nrf-examples/src/bin/twim_lowpower.rs b/examples/nrf/src/bin/twim_lowpower.rs index 1cd66a18e..1cd66a18e 100644 --- a/embassy-nrf-examples/src/bin/twim_lowpower.rs +++ b/examples/nrf/src/bin/twim_lowpower.rs | |||
diff --git a/embassy-nrf-examples/src/bin/uart.rs b/examples/nrf/src/bin/uart.rs index e65e2fe51..e65e2fe51 100644 --- a/embassy-nrf-examples/src/bin/uart.rs +++ b/examples/nrf/src/bin/uart.rs | |||
diff --git a/embassy-nrf-examples/src/bin/uart_idle.rs b/examples/nrf/src/bin/uart_idle.rs index dc2c73433..dc2c73433 100644 --- a/embassy-nrf-examples/src/bin/uart_idle.rs +++ b/examples/nrf/src/bin/uart_idle.rs | |||
diff --git a/embassy-nrf-examples/src/example_common.rs b/examples/nrf/src/example_common.rs index 54d633837..54d633837 100644 --- a/embassy-nrf-examples/src/example_common.rs +++ b/examples/nrf/src/example_common.rs | |||
diff --git a/embassy-rp-examples/.cargo/config.toml b/examples/rp/.cargo/config.toml index 1bbbe97da..1bbbe97da 100644 --- a/embassy-rp-examples/.cargo/config.toml +++ b/examples/rp/.cargo/config.toml | |||
diff --git a/embassy-rp-examples/Cargo.toml b/examples/rp/Cargo.toml index 2cee99bc5..71b48129f 100644 --- a/embassy-rp-examples/Cargo.toml +++ b/examples/rp/Cargo.toml | |||
| @@ -17,8 +17,8 @@ defmt-error = [] | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | [dependencies] | 19 | [dependencies] |
| 20 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] } | 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-rp = { version = "0.1.0", path = "../embassy-rp", features = ["defmt", "defmt-trace"] } | 21 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "defmt-trace"] } |
| 22 | rp2040-pac2 = { git = "https://github.com/Dirbaio/rp2040-pac", rev="254f4677937801155ca3cb17c7bb9d38eb62683e" } | 22 | rp2040-pac2 = { git = "https://github.com/Dirbaio/rp2040-pac", rev="254f4677937801155ca3cb17c7bb9d38eb62683e" } |
| 23 | atomic-polyfill = { version = "0.1.1" } | 23 | atomic-polyfill = { version = "0.1.1" } |
| 24 | 24 | ||
diff --git a/embassy-rp-examples/build.rs b/examples/rp/build.rs index d534cc3df..d534cc3df 100644 --- a/embassy-rp-examples/build.rs +++ b/examples/rp/build.rs | |||
diff --git a/embassy-rp-examples/memory.x b/examples/rp/memory.x index aba861aae..aba861aae 100644 --- a/embassy-rp-examples/memory.x +++ b/examples/rp/memory.x | |||
diff --git a/embassy-rp-examples/src/bin/blinky.rs b/examples/rp/src/bin/blinky.rs index e42999912..e42999912 100644 --- a/embassy-rp-examples/src/bin/blinky.rs +++ b/examples/rp/src/bin/blinky.rs | |||
diff --git a/embassy-rp-examples/src/bin/button.rs b/examples/rp/src/bin/button.rs index c4d942ff5..c4d942ff5 100644 --- a/embassy-rp-examples/src/bin/button.rs +++ b/examples/rp/src/bin/button.rs | |||
diff --git a/embassy-rp-examples/src/bin/uart.rs b/examples/rp/src/bin/uart.rs index 8b5f2a53b..8b5f2a53b 100644 --- a/embassy-rp-examples/src/bin/uart.rs +++ b/examples/rp/src/bin/uart.rs | |||
diff --git a/embassy-rp-examples/src/example_common.rs b/examples/rp/src/example_common.rs index f7c4ef57a..f7c4ef57a 100644 --- a/embassy-rp-examples/src/example_common.rs +++ b/examples/rp/src/example_common.rs | |||
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml new file mode 100644 index 000000000..04e89269d --- /dev/null +++ b/examples/std/Cargo.toml | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] | ||
| 3 | edition = "2018" | ||
| 4 | name = "embassy-std-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | embassy = { version = "0.1.0", path = "../../embassy", features = ["log"] } | ||
| 9 | embassy-std = { version = "0.1.0", path = "../../embassy-std" } | ||
| 10 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features=["std", "log", "medium-ethernet", "tcp", "dhcpv4"] } | ||
| 11 | smoltcp = { git = "https://github.com/smoltcp-rs/smoltcp", rev="ec59aba5e10cf91df0c9253d9c2aca4dd143d2ff", default-features = false } | ||
| 12 | |||
| 13 | async-io = "1.3.1" | ||
| 14 | env_logger = "0.8.2" | ||
| 15 | futures = { version = "0.3.8", default-features = false, features = ["async-await"] } | ||
| 16 | log = "0.4.11" | ||
| 17 | nix = "0.21.0" | ||
| 18 | libc = "0.2.81" | ||
| 19 | clap = { version = "3.0.0-beta.2", features = ["derive"] } | ||
| 20 | rand_core = { version = "0.6.0", features = ["std"] } | ||
| 21 | heapless = { version = "0.5.6", default-features = false } | ||
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs new file mode 100644 index 000000000..5a726e5d2 --- /dev/null +++ b/examples/std/src/bin/net.rs | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | #![feature(type_alias_impl_trait)] | ||
| 2 | #![feature(min_type_alias_impl_trait)] | ||
| 3 | #![feature(impl_trait_in_bindings)] | ||
| 4 | #![allow(incomplete_features)] | ||
| 5 | |||
| 6 | use clap::{AppSettings, Clap}; | ||
| 7 | use embassy::executor::Spawner; | ||
| 8 | use embassy::io::AsyncWriteExt; | ||
| 9 | use embassy::util::Forever; | ||
| 10 | use embassy_net::*; | ||
| 11 | use embassy_std::Executor; | ||
| 12 | use heapless::Vec; | ||
| 13 | use log::*; | ||
| 14 | |||
| 15 | #[path = "../tuntap.rs"] | ||
| 16 | mod tuntap; | ||
| 17 | |||
| 18 | use crate::tuntap::TunTapDevice; | ||
| 19 | |||
| 20 | static DEVICE: Forever<TunTapDevice> = Forever::new(); | ||
| 21 | static CONFIG: Forever<DhcpConfigurator> = Forever::new(); | ||
| 22 | |||
| 23 | #[derive(Clap)] | ||
| 24 | #[clap(version = "1.0")] | ||
| 25 | #[clap(setting = AppSettings::ColoredHelp)] | ||
| 26 | struct Opts { | ||
| 27 | /// TAP device name | ||
| 28 | #[clap(long, default_value = "tap0")] | ||
| 29 | tap: String, | ||
| 30 | } | ||
| 31 | |||
| 32 | #[embassy::task] | ||
| 33 | async fn net_task() { | ||
| 34 | embassy_net::run().await | ||
| 35 | } | ||
| 36 | |||
| 37 | #[embassy::task] | ||
| 38 | async fn main_task(spawner: Spawner) { | ||
| 39 | let opts: Opts = Opts::parse(); | ||
| 40 | |||
| 41 | // Init network device | ||
| 42 | let device = TunTapDevice::new(&opts.tap).unwrap(); | ||
| 43 | |||
| 44 | // Static IP configuration | ||
| 45 | let config = StaticConfigurator::new(Config { | ||
| 46 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | ||
| 47 | dns_servers: Vec::new(), | ||
| 48 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), | ||
| 49 | }); | ||
| 50 | |||
| 51 | // DHCP configruation | ||
| 52 | let config = DhcpConfigurator::new(); | ||
| 53 | |||
| 54 | // Init network stack | ||
| 55 | embassy_net::init(DEVICE.put(device), CONFIG.put(config)); | ||
| 56 | |||
| 57 | // Launch network task | ||
| 58 | spawner.spawn(net_task()).unwrap(); | ||
| 59 | |||
| 60 | // Then we can use it! | ||
| 61 | let mut rx_buffer = [0; 4096]; | ||
| 62 | let mut tx_buffer = [0; 4096]; | ||
| 63 | let mut socket = TcpSocket::new(&mut rx_buffer, &mut tx_buffer); | ||
| 64 | |||
| 65 | socket.set_timeout(Some(embassy_net::SmolDuration::from_secs(10))); | ||
| 66 | |||
| 67 | let remote_endpoint = (Ipv4Address::new(192, 168, 69, 74), 8000); | ||
| 68 | info!("connecting to {:?}...", remote_endpoint); | ||
| 69 | let r = socket.connect(remote_endpoint).await; | ||
| 70 | if let Err(e) = r { | ||
| 71 | warn!("connect error: {:?}", e); | ||
| 72 | return; | ||
| 73 | } | ||
| 74 | info!("connected!"); | ||
| 75 | loop { | ||
| 76 | let r = socket.write_all(b"Hello!\n").await; | ||
| 77 | if let Err(e) = r { | ||
| 78 | warn!("write error: {:?}", e); | ||
| 79 | return; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | #[no_mangle] | ||
| 85 | fn _embassy_rand(buf: &mut [u8]) { | ||
| 86 | use rand_core::{OsRng, RngCore}; | ||
| 87 | OsRng.fill_bytes(buf); | ||
| 88 | } | ||
| 89 | |||
| 90 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 91 | |||
| 92 | fn main() { | ||
| 93 | env_logger::builder() | ||
| 94 | .filter_level(log::LevelFilter::Debug) | ||
| 95 | .filter_module("async_io", log::LevelFilter::Info) | ||
| 96 | .format_timestamp_nanos() | ||
| 97 | .init(); | ||
| 98 | |||
| 99 | let executor = EXECUTOR.put(Executor::new()); | ||
| 100 | executor.run(|spawner| { | ||
| 101 | spawner.spawn(main_task(spawner)).unwrap(); | ||
| 102 | }); | ||
| 103 | } | ||
diff --git a/embassy-std-examples/src/bin/serial.rs b/examples/std/src/bin/serial.rs index 1b22dc0de..1b22dc0de 100644 --- a/embassy-std-examples/src/bin/serial.rs +++ b/examples/std/src/bin/serial.rs | |||
diff --git a/embassy-std-examples/src/bin/tick.rs b/examples/std/src/bin/tick.rs index 6f30edb34..6f30edb34 100644 --- a/embassy-std-examples/src/bin/tick.rs +++ b/examples/std/src/bin/tick.rs | |||
diff --git a/embassy-std-examples/src/serial_port.rs b/examples/std/src/serial_port.rs index 7ac1b1edb..7ac1b1edb 100644 --- a/embassy-std-examples/src/serial_port.rs +++ b/examples/std/src/serial_port.rs | |||
diff --git a/examples/std/src/tuntap.rs b/examples/std/src/tuntap.rs new file mode 100644 index 000000000..dd453deb3 --- /dev/null +++ b/examples/std/src/tuntap.rs | |||
| @@ -0,0 +1,225 @@ | |||
| 1 | use async_io::Async; | ||
| 2 | use libc; | ||
| 3 | use log::*; | ||
| 4 | use smoltcp::wire::EthernetFrame; | ||
| 5 | use std::io; | ||
| 6 | use std::io::{Read, Write}; | ||
| 7 | use std::os::unix::io::{AsRawFd, RawFd}; | ||
| 8 | |||
| 9 | pub const SIOCGIFMTU: libc::c_ulong = 0x8921; | ||
| 10 | pub const SIOCGIFINDEX: libc::c_ulong = 0x8933; | ||
| 11 | pub const ETH_P_ALL: libc::c_short = 0x0003; | ||
| 12 | pub const TUNSETIFF: libc::c_ulong = 0x400454CA; | ||
| 13 | pub const IFF_TUN: libc::c_int = 0x0001; | ||
| 14 | pub const IFF_TAP: libc::c_int = 0x0002; | ||
| 15 | pub const IFF_NO_PI: libc::c_int = 0x1000; | ||
| 16 | |||
| 17 | #[repr(C)] | ||
| 18 | #[derive(Debug)] | ||
| 19 | struct ifreq { | ||
| 20 | ifr_name: [libc::c_char; libc::IF_NAMESIZE], | ||
| 21 | ifr_data: libc::c_int, /* ifr_ifindex or ifr_mtu */ | ||
| 22 | } | ||
| 23 | |||
| 24 | fn ifreq_for(name: &str) -> ifreq { | ||
| 25 | let mut ifreq = ifreq { | ||
| 26 | ifr_name: [0; libc::IF_NAMESIZE], | ||
| 27 | ifr_data: 0, | ||
| 28 | }; | ||
| 29 | for (i, byte) in name.as_bytes().iter().enumerate() { | ||
| 30 | ifreq.ifr_name[i] = *byte as libc::c_char | ||
| 31 | } | ||
| 32 | ifreq | ||
| 33 | } | ||
| 34 | |||
| 35 | fn ifreq_ioctl( | ||
| 36 | lower: libc::c_int, | ||
| 37 | ifreq: &mut ifreq, | ||
| 38 | cmd: libc::c_ulong, | ||
| 39 | ) -> io::Result<libc::c_int> { | ||
| 40 | unsafe { | ||
| 41 | let res = libc::ioctl(lower, cmd as _, ifreq as *mut ifreq); | ||
| 42 | if res == -1 { | ||
| 43 | return Err(io::Error::last_os_error()); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | Ok(ifreq.ifr_data) | ||
| 48 | } | ||
| 49 | |||
| 50 | #[derive(Debug)] | ||
| 51 | pub struct TunTap { | ||
| 52 | fd: libc::c_int, | ||
| 53 | ifreq: ifreq, | ||
| 54 | mtu: usize, | ||
| 55 | } | ||
| 56 | |||
| 57 | impl AsRawFd for TunTap { | ||
| 58 | fn as_raw_fd(&self) -> RawFd { | ||
| 59 | self.fd | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | impl TunTap { | ||
| 64 | pub fn new(name: &str) -> io::Result<TunTap> { | ||
| 65 | unsafe { | ||
| 66 | let fd = libc::open( | ||
| 67 | "/dev/net/tun\0".as_ptr() as *const libc::c_char, | ||
| 68 | libc::O_RDWR | libc::O_NONBLOCK, | ||
| 69 | ); | ||
| 70 | if fd == -1 { | ||
| 71 | return Err(io::Error::last_os_error()); | ||
| 72 | } | ||
| 73 | |||
| 74 | let mut ifreq = ifreq_for(name); | ||
| 75 | ifreq.ifr_data = IFF_TAP | IFF_NO_PI; | ||
| 76 | ifreq_ioctl(fd, &mut ifreq, TUNSETIFF)?; | ||
| 77 | |||
| 78 | let socket = libc::socket(libc::AF_INET, libc::SOCK_DGRAM, libc::IPPROTO_IP); | ||
| 79 | if socket == -1 { | ||
| 80 | return Err(io::Error::last_os_error()); | ||
| 81 | } | ||
| 82 | |||
| 83 | let ip_mtu = ifreq_ioctl(socket, &mut ifreq, SIOCGIFMTU); | ||
| 84 | libc::close(socket); | ||
| 85 | let ip_mtu = ip_mtu? as usize; | ||
| 86 | |||
| 87 | // SIOCGIFMTU returns the IP MTU (typically 1500 bytes.) | ||
| 88 | // smoltcp counts the entire Ethernet packet in the MTU, so add the Ethernet header size to it. | ||
| 89 | let mtu = ip_mtu + EthernetFrame::<&[u8]>::header_len(); | ||
| 90 | |||
| 91 | Ok(TunTap { fd, mtu, ifreq }) | ||
| 92 | } | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | impl Drop for TunTap { | ||
| 97 | fn drop(&mut self) { | ||
| 98 | unsafe { | ||
| 99 | libc::close(self.fd); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | impl io::Read for TunTap { | ||
| 105 | fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||
| 106 | let len = unsafe { libc::read(self.fd, buf.as_mut_ptr() as *mut libc::c_void, buf.len()) }; | ||
| 107 | if len == -1 { | ||
| 108 | Err(io::Error::last_os_error()) | ||
| 109 | } else { | ||
| 110 | Ok(len as usize) | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | impl io::Write for TunTap { | ||
| 116 | fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | ||
| 117 | let len = unsafe { libc::write(self.fd, buf.as_ptr() as *mut libc::c_void, buf.len()) }; | ||
| 118 | if len == -1 { | ||
| 119 | Err(io::Error::last_os_error()) | ||
| 120 | } else { | ||
| 121 | Ok(len as usize) | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | fn flush(&mut self) -> io::Result<()> { | ||
| 126 | Ok(()) | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | pub struct TunTapDevice { | ||
| 131 | device: Async<TunTap>, | ||
| 132 | waker: Option<Waker>, | ||
| 133 | } | ||
| 134 | |||
| 135 | impl TunTapDevice { | ||
| 136 | pub fn new(name: &str) -> io::Result<TunTapDevice> { | ||
| 137 | Ok(Self { | ||
| 138 | device: Async::new(TunTap::new(name)?)?, | ||
| 139 | waker: None, | ||
| 140 | }) | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | use core::task::Waker; | ||
| 145 | use embassy_net::{DeviceCapabilities, LinkState, Packet, PacketBox, PacketBoxExt, PacketBuf}; | ||
| 146 | use std::task::Context; | ||
| 147 | |||
| 148 | impl crate::Device for TunTapDevice { | ||
| 149 | fn is_transmit_ready(&mut self) -> bool { | ||
| 150 | true | ||
| 151 | } | ||
| 152 | |||
| 153 | fn transmit(&mut self, pkt: PacketBuf) { | ||
| 154 | // todo handle WouldBlock | ||
| 155 | match self.device.get_mut().write(&pkt) { | ||
| 156 | Ok(_) => {} | ||
| 157 | Err(e) if e.kind() == io::ErrorKind::WouldBlock => { | ||
| 158 | info!("transmit WouldBlock"); | ||
| 159 | } | ||
| 160 | Err(e) => panic!("transmit error: {:?}", e), | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | fn receive(&mut self) -> Option<PacketBuf> { | ||
| 165 | let mut pkt = PacketBox::new(Packet::new()).unwrap(); | ||
| 166 | loop { | ||
| 167 | match self.device.get_mut().read(&mut pkt[..]) { | ||
| 168 | Ok(n) => { | ||
| 169 | return Some(pkt.slice(0..n)); | ||
| 170 | } | ||
| 171 | Err(e) if e.kind() == io::ErrorKind::WouldBlock => { | ||
| 172 | let ready = if let Some(w) = self.waker.as_ref() { | ||
| 173 | let mut cx = Context::from_waker(w); | ||
| 174 | let ready = self.device.poll_readable(&mut cx).is_ready(); | ||
| 175 | ready | ||
| 176 | } else { | ||
| 177 | false | ||
| 178 | }; | ||
| 179 | if !ready { | ||
| 180 | return None; | ||
| 181 | } | ||
| 182 | } | ||
| 183 | Err(e) => panic!("read error: {:?}", e), | ||
| 184 | } | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | fn register_waker(&mut self, w: &Waker) { | ||
| 189 | match self.waker { | ||
| 190 | // Optimization: If both the old and new Wakers wake the same task, we can simply | ||
| 191 | // keep the old waker, skipping the clone. (In most executor implementations, | ||
| 192 | // cloning a waker is somewhat expensive, comparable to cloning an Arc). | ||
| 193 | Some(ref w2) if (w2.will_wake(w)) => {} | ||
| 194 | _ => { | ||
| 195 | // clone the new waker and store it | ||
| 196 | if let Some(old_waker) = core::mem::replace(&mut self.waker, Some(w.clone())) { | ||
| 197 | // We had a waker registered for another task. Wake it, so the other task can | ||
| 198 | // reregister itself if it's still interested. | ||
| 199 | // | ||
| 200 | // If two tasks are waiting on the same thing concurrently, this will cause them | ||
| 201 | // to wake each other in a loop fighting over this WakerRegistration. This wastes | ||
| 202 | // CPU but things will still work. | ||
| 203 | // | ||
| 204 | // If the user wants to have two tasks waiting on the same thing they should use | ||
| 205 | // a more appropriate primitive that can store multiple wakers. | ||
| 206 | old_waker.wake() | ||
| 207 | } | ||
| 208 | } | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | fn capabilities(&mut self) -> DeviceCapabilities { | ||
| 213 | let mut caps = DeviceCapabilities::default(); | ||
| 214 | caps.max_transmission_unit = self.device.get_ref().mtu; | ||
| 215 | caps | ||
| 216 | } | ||
| 217 | |||
| 218 | fn link_state(&mut self) -> LinkState { | ||
| 219 | LinkState::Up | ||
| 220 | } | ||
| 221 | |||
| 222 | fn ethernet_address(&mut self) -> [u8; 6] { | ||
| 223 | [0x02, 0x03, 0x04, 0x05, 0x06, 0x07] | ||
| 224 | } | ||
| 225 | } | ||
diff --git a/embassy-stm32-examples/.cargo/config.toml b/examples/stm32f4/.cargo/config.toml index 8704a9ba5..8704a9ba5 100644 --- a/embassy-stm32-examples/.cargo/config.toml +++ b/examples/stm32f4/.cargo/config.toml | |||
diff --git a/embassy-stm32-examples/Cargo.toml b/examples/stm32f4/Cargo.toml index 799f0f9b9..c5c8d9ae6 100644 --- a/embassy-stm32-examples/Cargo.toml +++ b/examples/stm32f4/Cargo.toml | |||
| @@ -17,10 +17,10 @@ defmt-warn = [] | |||
| 17 | defmt-error = [] | 17 | defmt-error = [] |
| 18 | 18 | ||
| 19 | [dependencies] | 19 | [dependencies] |
| 20 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] } | 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-traits = { version = "0.1.0", path = "../embassy-traits", features = ["defmt"] } | 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 22 | embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", features = ["defmt", "defmt-trace", "stm32f429zi"] } | 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32f429zi"] } |
| 23 | embassy-extras = {version = "0.1.0", path = "../embassy-extras" } | 23 | embassy-extras = {version = "0.1.0", path = "../../embassy-extras" } |
| 24 | stm32f4 = { version = "0.13", features = ["stm32f429"] } | 24 | stm32f4 = { version = "0.13", features = ["stm32f429"] } |
| 25 | 25 | ||
| 26 | defmt = "0.2.0" | 26 | defmt = "0.2.0" |
diff --git a/embassy-stm32-examples/build.rs b/examples/stm32f4/build.rs index d534cc3df..d534cc3df 100644 --- a/embassy-stm32-examples/build.rs +++ b/examples/stm32f4/build.rs | |||
diff --git a/embassy-stm32-examples/memory.x b/examples/stm32f4/memory.x index f21e32572..f21e32572 100644 --- a/embassy-stm32-examples/memory.x +++ b/examples/stm32f4/memory.x | |||
diff --git a/embassy-stm32-examples/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs index 7590764d8..7590764d8 100644 --- a/embassy-stm32-examples/src/bin/blinky.rs +++ b/examples/stm32f4/src/bin/blinky.rs | |||
diff --git a/embassy-stm32-examples/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs index 1ee99f527..1ee99f527 100644 --- a/embassy-stm32-examples/src/bin/button.rs +++ b/examples/stm32f4/src/bin/button.rs | |||
diff --git a/embassy-stm32-examples/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs index 8fc889dad..8fc889dad 100644 --- a/embassy-stm32-examples/src/bin/button_exti.rs +++ b/examples/stm32f4/src/bin/button_exti.rs | |||
diff --git a/embassy-stm32-examples/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs index af0d57412..af0d57412 100644 --- a/embassy-stm32-examples/src/bin/spi.rs +++ b/examples/stm32f4/src/bin/spi.rs | |||
diff --git a/embassy-stm32-examples/src/bin/usart.rs b/examples/stm32f4/src/bin/usart.rs index f7b66f86b..f7b66f86b 100644 --- a/embassy-stm32-examples/src/bin/usart.rs +++ b/examples/stm32f4/src/bin/usart.rs | |||
diff --git a/embassy-stm32-examples/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs index fae05b607..fae05b607 100644 --- a/embassy-stm32-examples/src/bin/usart_dma.rs +++ b/examples/stm32f4/src/bin/usart_dma.rs | |||
diff --git a/embassy-stm32-examples/src/example_common.rs b/examples/stm32f4/src/example_common.rs index 54d633837..54d633837 100644 --- a/embassy-stm32-examples/src/example_common.rs +++ b/examples/stm32f4/src/example_common.rs | |||
