Skip to content

Commit 1af839e

Browse files
authored
Merge pull request #53 from Jim-Hodapp-Coaching/support_tcp_and_restructure_a
Restructure SPI impl into Wifi module and implement TCP send
2 parents f21f7da + 36d9b31 commit 1af839e

File tree

23 files changed

+1578
-363
lines changed

23 files changed

+1578
-363
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# will have compiled files and executables
33
/target/
44
/cross/target/
5+
/esp32-wroom-rp/target/
56

67
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
78
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"rust.target": "thumbv6m-none-eabi",
3-
"rust.all_targets": true
3+
"rust.all_targets": true,
4+
"editor.inlayHints.enabled": false
45
}

cross/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[workspace]
22
members = [
3+
"dns",
34
"get_fw_version",
45
"join",
5-
"dns"
6+
"send_data_tcp"
67
]
78

89
[profile.dev]

cross/dns/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
authors = [
33
"Jim Hodapp",
44
"Caleb Bourg",
5-
"Glyn Matthews"
5+
"Glyn Matthews",
6+
"Dilyn Corner"
67
]
78
edition = "2021"
89
name = "dns"
9-
version = "0.1.0"
10+
version = "0.3.0"
1011
description = "Example target application that demonstrates DNS functionality with the Rust-based Espressif ESP32-WROOM WiFi driver crate for RP2040 series microcontroller boards."
1112

1213
# makes `cargo check --all-targets` work

cross/dns/src/main.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ fn main() -> ! {
9090
let spi = hal::Spi::<_, _, 8>::new(pac.SPI0);
9191

9292
// Exchange the uninitialized SPI driver for an initialized one
93-
let mut spi = spi.init(
93+
let spi = spi.init(
9494
&mut pac.RESETS,
9595
clocks.peripheral_clock.freq(),
9696
8.MHz(),
9797
&MODE_0,
9898
);
9999

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

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

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

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

118+
let mut sleep: u32 = 1500;
118119
loop {
119120
match wifi.get_connection_status() {
120121
Ok(status) => {
121122
defmt::info!("Get Connection Result: {:?}", status);
122-
let sleep: u32 = 1500;
123+
123124
delay.delay_ms(sleep);
124125

125126
if status == ConnectionStatus::Connected {
@@ -149,6 +150,7 @@ fn main() -> ! {
149150
wifi.leave().ok().unwrap();
150151
} else if status == ConnectionStatus::Disconnected {
151152
defmt::info!("Disconnected from Network: {:?}", SSID);
153+
sleep = 20000; // No need to loop as often after disconnecting
152154
}
153155
}
154156
Err(e) => {

cross/get_fw_version/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
authors = [
33
"Jim Hodapp",
44
"Caleb Bourg",
5-
"Glyn Matthews"
5+
"Glyn Matthews",
6+
"Dilyn Corner"
67
]
78
edition = "2021"
89
name = "get_fw_version"
9-
version = "0.1.0"
10+
version = "0.3.0"
1011
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."
1112

1213
# makes `cargo check --all-targets` work

cross/get_fw_version/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ fn main() -> ! {
8585
let spi = hal::Spi::<_, _, 8>::new(pac.SPI0);
8686

8787
// Exchange the uninitialized SPI driver for an initialized one
88-
let mut spi = spi.init(
88+
let spi = spi.init(
8989
&mut pac.RESETS,
9090
clocks.peripheral_clock.freq(),
9191
8.MHz(),
9292
&MODE_0,
9393
);
9494

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

cross/join/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
authors = [
33
"Jim Hodapp",
44
"Caleb Bourg",
5-
"Glyn Matthews"
5+
"Glyn Matthews",
6+
"Dilyn Corner"
67
]
78
edition = "2021"
89
name = "join"
9-
version = "0.1.0"
10+
version = "0.3.0"
1011
description = "Example target application that joins/leaves an SSID with the Rust-based Espressif ESP32-WROOM WiFi driver crate for RP2040 series microcontroller boards."
1112

1213
# makes `cargo check --all-targets` work

cross/join/src/main.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ fn main() -> ! {
8989
let spi = hal::Spi::<_, _, 8>::new(pac.SPI0);
9090

9191
// Exchange the uninitialized SPI driver for an initialized one
92-
let mut spi = spi.init(
92+
let spi = spi.init(
9393
&mut pac.RESETS,
9494
clocks.peripheral_clock.freq(),
9595
8.MHz(),
9696
&MODE_0,
9797
);
9898

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

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

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

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

117+
let mut sleep: u32 = 1500;
117118
loop {
118119
match wifi.get_connection_status() {
119120
Ok(status) => {
120121
defmt::info!("Get Connection Result: {:?}", status);
121-
let sleep: u32 = 1500;
122+
122123
delay.delay_ms(sleep);
123124

124125
if status == ConnectionStatus::Connected {
@@ -130,8 +131,7 @@ fn main() -> ! {
130131
wifi.leave().ok().unwrap();
131132
} else if status == ConnectionStatus::Disconnected {
132133
defmt::info!("Disconnected from Network: {:?}", SSID);
133-
} else {
134-
defmt::info!("Unhandled WiFi connection status: {:?}", status);
134+
sleep = 20000; // No need to loop as often after disconnecting
135135
}
136136
}
137137
Err(e) => {

cross/secrets/secrets.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// all example applications
44
//
55

6-
const SSID: &str = "ssid";
7-
const PASSPHRASE: &str = "passphrase";
6+
const SSID: &str = "";
7+
const PASSPHRASE: &str = "";

cross/send_data_tcp/Cargo.toml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[package]
2+
authors = [
3+
"Jim Hodapp",
4+
"Caleb Bourg",
5+
"Glyn Matthews",
6+
"Dilyn Corner"
7+
]
8+
edition = "2021"
9+
name = "send_data_tcp"
10+
version = "0.3.0"
11+
description = "Example RP2040 target application that demonstrates how to send data to a remote server over TCP."
12+
13+
# makes `cargo check --all-targets` work
14+
[[bin]]
15+
name = "send_data_tcp"
16+
bench = false
17+
doctest = false
18+
test = false
19+
20+
[dependencies]
21+
defmt = "0.3.0"
22+
defmt-rtt = "0.3.0"
23+
cortex-m = "0.7"
24+
cortex-m-rt = "0.7"
25+
embedded-hal = { version = "0.2", features=["unproven"] }
26+
esp32-wroom-rp = { path = "../../esp32-wroom-rp" }
27+
panic-probe = { version = "0.3.0", features = ["print-rtt"] }
28+
heapless = "0.7.16"
29+
30+
rp2040-hal = { version = "0.6", features=["rt", "eh1_0_alpha"] }
31+
rp2040-boot2 = { version = "0.2" }
32+
fugit = "0.3"
33+
34+
[features]
35+
default = ['defmt-default']
36+
# these features are required by defmt
37+
defmt-default = []
38+
defmt-trace = []
39+
defmt-debug = []
40+
defmt-info = []
41+
defmt-warn = []
42+
defmt-error = []

0 commit comments

Comments
 (0)