Skip to content

Commit 3de8b54

Browse files
committed
Addresses all current compile warnings and missing documentation warnings.
1 parent ab6170f commit 3de8b54

File tree

8 files changed

+53
-32
lines changed

8 files changed

+53
-32
lines changed

cross/get_fw_version/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ fn main() -> ! {
8282
defmt::info!("ESP32-WROOM-RP get NINA firmware version example");
8383

8484
// These are implicitly used by the spi driver if they are in the correct mode
85-
let spi_miso = pins.gpio16.into_mode::<hal::gpio::FunctionSpi>();
86-
let spi_sclk = pins.gpio18.into_mode::<hal::gpio::FunctionSpi>();
87-
let spi_mosi = pins.gpio19.into_mode::<hal::gpio::FunctionSpi>();
85+
let _spi_miso = pins.gpio16.into_mode::<hal::gpio::FunctionSpi>();
86+
let _spi_sclk = pins.gpio18.into_mode::<hal::gpio::FunctionSpi>();
87+
let _spi_mosi = pins.gpio19.into_mode::<hal::gpio::FunctionSpi>();
8888

8989
let spi = hal::Spi::<_, _, 8>::new(pac.SPI0);
9090

cross/join/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ use panic_probe as _;
2424
// Alias for our HAL crate
2525
use rp2040_hal as hal;
2626

27+
use embedded_hal::spi::MODE_0;
2728
use embedded_time::fixed_point::FixedPoint;
2829
use embedded_time::rate::Extensions;
2930
use hal::clocks::Clock;
3031
use hal::pac;
3132

32-
use embedded_hal::spi::MODE_0;
33-
use embedded_hal::blocking::delay::DelayMs;
34-
3533
/// The linker will place this boot block at the start of our program image. We
3634
/// need this to help the ROM bootloader get our code up and running.
3735
#[link_section = ".boot2"]
@@ -87,9 +85,9 @@ fn main() -> ! {
8785
defmt::info!("ESP32-WROOM-RP join/leave WiFi network");
8886

8987
// These are implicitly used by the spi driver if they are in the correct mode
90-
let spi_miso = pins.gpio16.into_mode::<hal::gpio::FunctionSpi>();
91-
let spi_sclk = pins.gpio18.into_mode::<hal::gpio::FunctionSpi>();
92-
let spi_mosi = pins.gpio19.into_mode::<hal::gpio::FunctionSpi>();
88+
let _spi_miso = pins.gpio16.into_mode::<hal::gpio::FunctionSpi>();
89+
let _spi_sclk = pins.gpio18.into_mode::<hal::gpio::FunctionSpi>();
90+
let _spi_mosi = pins.gpio19.into_mode::<hal::gpio::FunctionSpi>();
9391

9492
let spi = hal::Spi::<_, _, 8>::new(pac.SPI0);
9593

esp32-wroom-rp/src/gpio.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,59 @@
3333
use embedded_hal::blocking::delay::DelayMs;
3434
use embedded_hal::digital::v2::{InputPin, OutputPin};
3535

36+
#[allow(dead_code)]
3637
#[derive(Clone, Copy, Debug)]
37-
pub enum IOError {
38+
enum IOError {
3839
Pin,
3940
}
4041

42+
/// Provides an internal pin interface that abstracts the extra control lines that
43+
/// are separate from a data bus (e.g. SPI/I2C).
44+
///
45+
/// Not meant to be used outside of the crate.
4146
pub trait EspControlInterface {
47+
/// Initializes all controls pins to set ready communication with the NINA firmware.
4248
fn init(&mut self);
4349

50+
/// Resets communication with the NINA firmware.
4451
fn reset<D: DelayMs<u16>>(&mut self, delay: &mut D);
4552

53+
/// Tells the NINA firmware we're about to send it a protocol command.
4654
fn esp_select(&mut self);
4755

56+
/// Tells the NINA firmware we're done sending it a protocol command.
4857
fn esp_deselect(&mut self);
4958

59+
/// Is the NINA firmware ready to send it a protocol command?
5060
fn get_esp_ready(&self) -> bool;
5161

62+
/// Is the NINA firmware ready to receive more commands? Also referred to as BUSY.
5263
fn get_esp_ack(&self) -> bool;
5364

65+
/// Blocking waits for the NINA firmware to be ready to send it a protocol command.
5466
fn wait_for_esp_ready(&self);
5567

68+
/// Blocking waits for the NINA firmware to acknowledge it's ready to receive more commands.
5669
fn wait_for_esp_ack(&self);
5770

71+
/// Blocking waits for the NINA firmware to be ready to send it a protocol command.
5872
fn wait_for_esp_select(&mut self);
5973
}
6074

6175
/// A structured representation of all GPIO pins that control a ESP32-WROOM NINA firmware-based
6276
/// device outside of commands sent over the SPI/I²C bus. Pass a single instance of this struct
6377
/// into `Wifi::init()`.
6478
pub struct EspControlPins<CS: OutputPin, GPIO0: OutputPin, RESETN: OutputPin, ACK: InputPin> {
79+
/// Chip select pin to let the NINA firmware know we're going to send it a command over
80+
/// the SPI bus.
6581
pub cs: CS,
82+
/// Puts the ESP32 WiFi target into bootloading mode. Or if acting as a server, provides
83+
/// a status line for when data is ready to be read.
6684
pub gpio0: GPIO0,
85+
/// Places the ESP32 WiFi target into reset mode. Useful for when the target gets into
86+
/// a stuck state.
6787
pub resetn: RESETN,
88+
/// Is the ESP32 WiFi target busy?
6889
pub ack: ACK,
6990
}
7091

@@ -134,13 +155,9 @@ mod gpio_tests {
134155
use embedded_hal_mock::pin::{
135156
Mock as PinMock, State as PinState, Transaction as PinTransaction,
136157
};
137-
use embedded_hal_mock::MockError;
138-
use std::io::ErrorKind;
139158

140159
#[test]
141160
fn gpio_init_sets_correct_state() {
142-
let err = MockError::Io(ErrorKind::NotConnected);
143-
144161
let cs_expectations = [PinTransaction::set(PinState::High)];
145162

146163
let gpio0_expectations = [PinTransaction::set(PinState::High)];

esp32-wroom-rp/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ use embedded_hal::blocking::delay::DelayMs;
9898

9999
const ARRAY_LENGTH_PLACEHOLDER: usize = 8;
100100

101+
/// Highest level error types for this crate.
101102
#[derive(Debug)]
102103
pub enum Error {
103-
// Placeholder variants
104+
/// SPI/I2C related communications error with the ESP32 WiFi target
104105
Bus,
106+
/// Timeout in communicating with the ESP32 WiFi target
105107
TimeOut,
106108
}
107109

esp32-wroom-rp/src/protocol.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl NinaParam for NinaByteParam {
9898

9999
fn from_bytes(bytes: &[u8]) -> Self {
100100
let mut data_as_bytes: Vec<u8, 1> = Vec::new();
101-
data_as_bytes.extend_from_slice(bytes);
101+
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
102102
Self {
103103
length: data_as_bytes.len() as u8,
104104
data: data_as_bytes,
@@ -131,7 +131,7 @@ impl NinaParam for NinaWordParam {
131131

132132
fn from_bytes(bytes: &[u8]) -> Self {
133133
let mut data_as_bytes: Vec<u8, 2> = Vec::new();
134-
data_as_bytes.extend_from_slice(bytes);
134+
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
135135
Self {
136136
length: data_as_bytes.len() as u8,
137137
data: data_as_bytes,
@@ -164,7 +164,7 @@ impl NinaParam for NinaSmallArrayParam {
164164

165165
fn from_bytes(bytes: &[u8]) -> Self {
166166
let mut data_as_bytes: Vec<u8, MAX_NINA_PARAM_LENGTH> = Vec::new();
167-
data_as_bytes.extend_from_slice(bytes);
167+
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
168168
Self {
169169
length: data_as_bytes.len() as u8,
170170
data: data_as_bytes,
@@ -197,7 +197,7 @@ impl NinaParam for NinaLargeArrayParam {
197197

198198
fn from_bytes(bytes: &[u8]) -> Self {
199199
let mut data_as_bytes: Vec<u8, MAX_NINA_PARAM_LENGTH> = Vec::new();
200-
data_as_bytes.extend_from_slice(bytes);
200+
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
201201
Self {
202202
length: data_as_bytes.len() as u16,
203203
data: data_as_bytes,

esp32-wroom-rp/src/protocol/operation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ impl<P> Operation<P> {
3030
// builds up an internal byte stream representing one Nina command
3131
// on the data bus.
3232
pub fn param(mut self, param: P) -> Self {
33-
self.params.push(param);
33+
self.params.push(param).ok().unwrap();
3434
self
3535
}
3636

3737
// Used for denoting an Operation where no params are provided.
3838
//
3939
// Sets `has_params` to `false`
4040
pub fn with_no_params(mut self, no_param: P) -> Self {
41-
self.params.push(no_param);
41+
self.params.push(no_param).ok().unwrap();
4242
self.has_params = false;
4343
self
4444
}

esp32-wroom-rp/src/spi.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum ControlByte {
2323
Error = 0xEFu8,
2424
}
2525

26+
/// Fundamental struct for controlling a connected ESP32-WROOM NINA firmware-based Wifi board.
2627
#[derive(Debug, Default)]
2728
pub struct Wifi<B, C> {
2829
common: WifiCommon<NinaProtocolHandler<B, C>>,
@@ -68,6 +69,10 @@ where
6869
self.common.leave()
6970
}
7071

72+
/// Retrieves the current WiFi network connection status.
73+
///
74+
/// NOTE: A future version will provide a enumerated type instead of the raw integer values
75+
/// from the NINA firmware.
7176
pub fn get_connection_status(&mut self) -> Result<u8, Error> {
7277
self.common.get_connection_status()
7378
}
@@ -93,7 +98,7 @@ where
9398
let operation =
9499
Operation::new(NinaCommand::GetFwVersion, 1).with_no_params(NinaNoParams::new(""));
95100

96-
self.execute(&operation);
101+
self.execute(&operation).ok().unwrap();
97102

98103
let result = self.receive(&operation)?;
99104

@@ -105,17 +110,17 @@ where
105110
.param(NinaSmallArrayParam::new(ssid))
106111
.param(NinaSmallArrayParam::new(passphrase));
107112

108-
self.execute(&operation);
113+
self.execute(&operation).ok().unwrap();
109114

110-
self.receive(&operation);
115+
self.receive(&operation).ok().unwrap();
111116
Ok(())
112117
}
113118

114119
fn get_conn_status(&mut self) -> Result<u8, self::Error> {
115120
let operation =
116121
Operation::new(NinaCommand::GetConnStatus, 1).with_no_params(NinaNoParams::new(""));
117122

118-
self.execute(&operation);
123+
self.execute(&operation).ok().unwrap();
119124

120125
let result = self.receive(&operation)?;
121126

@@ -126,9 +131,9 @@ where
126131
let dummy_param = NinaByteParam::from_bytes(&[ControlByte::Dummy as u8]);
127132
let operation = Operation::new(NinaCommand::Disconnect, 1).param(dummy_param);
128133

129-
self.execute(&operation);
134+
self.execute(&operation).ok().unwrap();
130135

131-
self.receive(&operation);
136+
self.receive(&operation).ok().unwrap();
132137

133138
Ok(())
134139
}
@@ -143,16 +148,16 @@ where
143148
let mut param_size: u16 = 0;
144149
self.control_pins.wait_for_esp_select();
145150

146-
self.send_cmd(&operation.command, operation.params.len() as u8);
151+
self.send_cmd(&operation.command, operation.params.len() as u8).ok().unwrap();
147152

148153
// Only send params if they are present
149154
if operation.has_params {
150155
operation.params.iter().for_each(|param| {
151-
self.send_param(param);
156+
self.send_param(param).ok().unwrap();
152157
param_size += param.length();
153158
});
154159

155-
self.send_end_cmd();
160+
self.send_end_cmd().ok().unwrap();
156161

157162
// This is to make sure we align correctly
158163
// 4 (start byte, command byte, reply byte, end byte) + the sum of all param lengths
@@ -320,6 +325,7 @@ where
320325
}
321326
}
322327

328+
#[allow(dead_code)]
323329
/// Error which occurred during a SPI transaction with a target ESP32 device
324330
#[derive(Clone, Copy, Debug)]
325331
pub enum SPIError<SPIE, IOE> {

host-tests/tests/spi.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
use std::{thread, time::Duration};
2-
31
#[test]
42
fn do_something_with_spi_succeeds() {}

0 commit comments

Comments
 (0)