Skip to content

Commit

Permalink
Merge pull request #53 from Jim-Hodapp-Coaching/support_tcp_and_restr…
Browse files Browse the repository at this point in the history
…ucture_a

Restructure SPI impl into Wifi module and implement TCP send
  • Loading branch information
calebbourg authored Jan 6, 2023
2 parents f21f7da + 36d9b31 commit 1af839e
Show file tree
Hide file tree
Showing 23 changed files with 1,578 additions and 363 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# will have compiled files and executables
/target/
/cross/target/
/esp32-wroom-rp/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"rust.target": "thumbv6m-none-eabi",
"rust.all_targets": true
"rust.all_targets": true,
"editor.inlayHints.enabled": false
}
3 changes: 2 additions & 1 deletion cross/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[workspace]
members = [
"dns",
"get_fw_version",
"join",
"dns"
"send_data_tcp"
]

[profile.dev]
Expand Down
5 changes: 3 additions & 2 deletions cross/dns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
authors = [
"Jim Hodapp",
"Caleb Bourg",
"Glyn Matthews"
"Glyn Matthews",
"Dilyn Corner"
]
edition = "2021"
name = "dns"
version = "0.1.0"
version = "0.3.0"
description = "Example target application that demonstrates DNS functionality with the Rust-based Espressif ESP32-WROOM WiFi driver crate for RP2040 series microcontroller boards."

# makes `cargo check --all-targets` work
Expand Down
10 changes: 6 additions & 4 deletions cross/dns/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ fn main() -> ! {
let spi = hal::Spi::<_, _, 8>::new(pac.SPI0);

// Exchange the uninitialized SPI driver for an initialized one
let mut spi = spi.init(
let spi = spi.init(
&mut pac.RESETS,
clocks.peripheral_clock.freq(),
8.MHz(),
&MODE_0,
);

let mut esp_pins = esp32_wroom_rp::gpio::EspControlPins {
let esp_pins = esp32_wroom_rp::gpio::EspControlPins {
// CS on pin x (GPIO7)
cs: pins.gpio7.into_mode::<hal::gpio::PushPullOutput>(),
// GPIO0 on pin x (GPIO2)
Expand All @@ -108,18 +108,19 @@ fn main() -> ! {
ack: pins.gpio10.into_mode::<hal::gpio::FloatingInput>(),
};

let mut wifi = esp32_wroom_rp::wifi::Wifi::init(&mut spi, &mut esp_pins, &mut delay).unwrap();
let mut wifi = esp32_wroom_rp::wifi::Wifi::init(spi, esp_pins, &mut delay).unwrap();

let result = wifi.join(SSID, PASSPHRASE);
defmt::info!("Join Result: {:?}", result);

defmt::info!("Entering main loop");

let mut sleep: u32 = 1500;
loop {
match wifi.get_connection_status() {
Ok(status) => {
defmt::info!("Get Connection Result: {:?}", status);
let sleep: u32 = 1500;

delay.delay_ms(sleep);

if status == ConnectionStatus::Connected {
Expand Down Expand Up @@ -149,6 +150,7 @@ fn main() -> ! {
wifi.leave().ok().unwrap();
} else if status == ConnectionStatus::Disconnected {
defmt::info!("Disconnected from Network: {:?}", SSID);
sleep = 20000; // No need to loop as often after disconnecting
}
}
Err(e) => {
Expand Down
5 changes: 3 additions & 2 deletions cross/get_fw_version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
authors = [
"Jim Hodapp",
"Caleb Bourg",
"Glyn Matthews"
"Glyn Matthews",
"Dilyn Corner"
]
edition = "2021"
name = "get_fw_version"
version = "0.1.0"
version = "0.3.0"
description = "Example target application that gets the Nina firmware version with the Rust-based Espressif ESP32-WROOM WiFi driver crate for RP2040 series microcontroller boards."

# makes `cargo check --all-targets` work
Expand Down
6 changes: 3 additions & 3 deletions cross/get_fw_version/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ fn main() -> ! {
let spi = hal::Spi::<_, _, 8>::new(pac.SPI0);

// Exchange the uninitialized SPI driver for an initialized one
let mut spi = spi.init(
let spi = spi.init(
&mut pac.RESETS,
clocks.peripheral_clock.freq(),
8.MHz(),
&MODE_0,
);

let mut esp_pins = esp32_wroom_rp::gpio::EspControlPins {
let esp_pins = esp32_wroom_rp::gpio::EspControlPins {
// CS on pin x (GPIO7)
cs: pins.gpio7.into_mode::<hal::gpio::PushPullOutput>(),
// GPIO0 on pin x (GPIO2)
Expand All @@ -102,7 +102,7 @@ fn main() -> ! {
// ACK on pin x (GPIO10)
ack: pins.gpio10.into_mode::<hal::gpio::FloatingInput>(),
};
let mut wifi = esp32_wroom_rp::wifi::Wifi::init(&mut spi, &mut esp_pins, &mut delay).unwrap();
let mut wifi = esp32_wroom_rp::wifi::Wifi::init(spi, esp_pins, &mut delay).unwrap();
let firmware_version = wifi.firmware_version();
defmt::info!("NINA firmware version: {:?}", firmware_version);

Expand Down
5 changes: 3 additions & 2 deletions cross/join/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
authors = [
"Jim Hodapp",
"Caleb Bourg",
"Glyn Matthews"
"Glyn Matthews",
"Dilyn Corner"
]
edition = "2021"
name = "join"
version = "0.1.0"
version = "0.3.0"
description = "Example target application that joins/leaves an SSID with the Rust-based Espressif ESP32-WROOM WiFi driver crate for RP2040 series microcontroller boards."

# makes `cargo check --all-targets` work
Expand Down
12 changes: 6 additions & 6 deletions cross/join/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ fn main() -> ! {
let spi = hal::Spi::<_, _, 8>::new(pac.SPI0);

// Exchange the uninitialized SPI driver for an initialized one
let mut spi = spi.init(
let spi = spi.init(
&mut pac.RESETS,
clocks.peripheral_clock.freq(),
8.MHz(),
&MODE_0,
);

let mut esp_pins = esp32_wroom_rp::gpio::EspControlPins {
let esp_pins = esp32_wroom_rp::gpio::EspControlPins {
// CS on pin x (GPIO7)
cs: pins.gpio7.into_mode::<hal::gpio::PushPullOutput>(),
// GPIO0 on pin x (GPIO2)
Expand All @@ -107,18 +107,19 @@ fn main() -> ! {
ack: pins.gpio10.into_mode::<hal::gpio::FloatingInput>(),
};

let mut wifi = esp32_wroom_rp::wifi::Wifi::init(&mut spi, &mut esp_pins, &mut delay).unwrap();
let mut wifi = esp32_wroom_rp::wifi::Wifi::init(spi, esp_pins, &mut delay).unwrap();

let result = wifi.join(SSID, PASSPHRASE);
defmt::info!("Join Result: {:?}", result);

defmt::info!("Entering main loop");

let mut sleep: u32 = 1500;
loop {
match wifi.get_connection_status() {
Ok(status) => {
defmt::info!("Get Connection Result: {:?}", status);
let sleep: u32 = 1500;

delay.delay_ms(sleep);

if status == ConnectionStatus::Connected {
Expand All @@ -130,8 +131,7 @@ fn main() -> ! {
wifi.leave().ok().unwrap();
} else if status == ConnectionStatus::Disconnected {
defmt::info!("Disconnected from Network: {:?}", SSID);
} else {
defmt::info!("Unhandled WiFi connection status: {:?}", status);
sleep = 20000; // No need to loop as often after disconnecting
}
}
Err(e) => {
Expand Down
4 changes: 2 additions & 2 deletions cross/secrets/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// all example applications
//

const SSID: &str = "ssid";
const PASSPHRASE: &str = "passphrase";
const SSID: &str = "";
const PASSPHRASE: &str = "";
42 changes: 42 additions & 0 deletions cross/send_data_tcp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
authors = [
"Jim Hodapp",
"Caleb Bourg",
"Glyn Matthews",
"Dilyn Corner"
]
edition = "2021"
name = "send_data_tcp"
version = "0.3.0"
description = "Example RP2040 target application that demonstrates how to send data to a remote server over TCP."

# makes `cargo check --all-targets` work
[[bin]]
name = "send_data_tcp"
bench = false
doctest = false
test = false

[dependencies]
defmt = "0.3.0"
defmt-rtt = "0.3.0"
cortex-m = "0.7"
cortex-m-rt = "0.7"
embedded-hal = { version = "0.2", features=["unproven"] }
esp32-wroom-rp = { path = "../../esp32-wroom-rp" }
panic-probe = { version = "0.3.0", features = ["print-rtt"] }
heapless = "0.7.16"

rp2040-hal = { version = "0.6", features=["rt", "eh1_0_alpha"] }
rp2040-boot2 = { version = "0.2" }
fugit = "0.3"

[features]
default = ['defmt-default']
# these features are required by defmt
defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []
Loading

0 comments on commit 1af839e

Please sign in to comment.