Skip to content

Commit e0f4768

Browse files
committed
chore: even less expect's
1 parent d5bbdef commit e0f4768

File tree

5 files changed

+41
-30
lines changed

5 files changed

+41
-30
lines changed

src/bluetooth.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,14 @@ async fn load_bonding_info(nvs: &esp_hal_wifimanager::Nvs) -> Option<BondInforma
359359
return None;
360360
}
361361

362-
let bd_addr = BdAddr::new(buf[..6].try_into().expect("Cannot fail"));
362+
let bd_addr = BdAddr::new(buf[..6].try_into().expect(""));
363363
let security_level = match buf[22] {
364364
0 => SecurityLevel::NoEncryption,
365365
1 => SecurityLevel::Encrypted,
366366
2 => SecurityLevel::EncryptedAuthenticated,
367367
_ => return None,
368368
};
369-
let ltk = LongTermKey::from_le_bytes(buf[6..22].try_into().expect("Cannot fail"));
369+
let ltk = LongTermKey::from_le_bytes(buf[6..22].try_into().expect(""));
370370

371371
Some(BondInformation {
372372
identity: Identity { bd_addr, irk: None },
@@ -388,14 +388,15 @@ impl EventHandler for BleDiscovery<'_> {
388388
while let Some(Ok(report)) = it.next() {
389389
if !seen.iter().any(|b| b.raw() == report.addr.raw()) {
390390
if let Some(name) = parse_device_name(report.data)
391-
&& name.starts_with("FKMD-") {
392-
log::info!("Disovered FKM Display! [{:?}] ({name})", report.addr);
391+
&& name.starts_with("FKMD-")
392+
{
393+
log::info!("Disovered FKM Display! [{:?}] ({name})", report.addr);
393394

394-
_ = self.sender.try_send(BleDisplayDevice {
395-
name: name.to_string(),
396-
addr: report.addr.into_inner(),
397-
});
398-
}
395+
_ = self.sender.try_send(BleDisplayDevice {
396+
name: name.to_string(),
397+
addr: report.addr.into_inner(),
398+
});
399+
}
399400

400401
if seen.is_full() {
401402
seen.pop_front();

src/board.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::stackmat::{DEC_DIGITS, DOT_MOD};
22
use adv_shift_registers::wrappers::ShifterValueRange;
3-
use anyhow::Result;
3+
use embedded_hal::digital::OutputPin;
44
use esp_hal::{
55
gpio::{AnyPin, Input, InputConfig, Level, Output, Pin, Pull},
66
peripherals::{
@@ -47,9 +47,7 @@ pub struct Board {
4747
}
4848

4949
impl Board {
50-
pub fn init(peripherals: Peripherals) -> Result<Board> {
51-
use embedded_hal::digital::OutputPin;
52-
50+
pub fn init(peripherals: Peripherals) -> Board {
5351
let timg0 = TimerGroup::new(peripherals.TIMG0);
5452
let timg1 = TimerGroup::new(peripherals.TIMG1);
5553
let rng = Rng::new();
@@ -100,7 +98,7 @@ impl Board {
10098
let mut cs = adv_shift_reg.get_pin_mut(1, 0, true);
10199
_ = cs.set_high();
102100

103-
Ok(Board {
101+
Board {
104102
timg0,
105103
timg1,
106104
rng,
@@ -128,6 +126,6 @@ impl Board {
128126
lcd,
129127
usb_dp,
130128
usb_dm,
131-
})
129+
}
132130
}
133131
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async fn main(spawner: Spawner) {
9999
}
100100

101101
set_brownout_detection(false);
102-
let board = Board::init(peripherals).expect("Board init error");
102+
let board = Board::init(peripherals);
103103
let software_interrupt = SoftwareInterruptControl::new(board.sw_interrupt);
104104
esp_rtos::start(board.timg1.timer0, software_interrupt.software_interrupt0);
105105
FkmLogger::set_logger();

src/rfid.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,39 @@ pub async fn rfid_task(
2626
) {
2727
#[allow(clippy::manual_div_ceil)]
2828
let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(512);
29-
let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).expect("Dma tx buf failed");
30-
let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).expect("Dma rx buf failed");
29+
let Ok(dma_tx_buf) = DmaTxBuf::new(tx_descriptors, tx_buffer) else {
30+
log::error!("Dma tx buf failed");
31+
return;
32+
};
33+
let Ok(dma_rx_buf) = DmaRxBuf::new(rx_descriptors, rx_buffer) else {
34+
log::error!("Dma rx buf failed");
35+
return;
36+
};
3137

32-
let spi = Spi::new(
38+
let Ok(spi) = Spi::new(
3339
spi,
3440
esp_hal::spi::master::Config::default()
3541
.with_frequency(Rate::from_khz(400))
3642
.with_mode(Mode::_0),
3743
)
38-
.expect("Spi init failed")
39-
.with_sck(sck)
40-
.with_miso(miso)
41-
.with_mosi(mosi)
42-
.with_dma(dma_chan)
43-
.with_buffers(dma_rx_buf, dma_tx_buf)
44-
.into_async();
44+
.map(|s| {
45+
s.with_sck(sck)
46+
.with_miso(miso)
47+
.with_mosi(mosi)
48+
.with_dma(dma_chan)
49+
.with_buffers(dma_rx_buf, dma_tx_buf)
50+
.into_async()
51+
}) else {
52+
log::error!("Rfid task error while creating Spi instance!");
53+
return;
54+
};
4555

4656
let mut mfrc522 = {
47-
let spi = embedded_hal_bus::spi::ExclusiveDevice::new(spi, cs_pin, embassy_time::Delay)
48-
.expect("Spi bus init failed (cs set high failed)");
57+
let Ok(spi) = embedded_hal_bus::spi::ExclusiveDevice::new(spi, cs_pin, embassy_time::Delay)
58+
else {
59+
log::error!("Spi bus init failed (cs set high failed)");
60+
return;
61+
};
4962

5063
esp_hal_mfrc522::MFRC522::new(esp_hal_mfrc522::drivers::SpiDriver::new(spi))
5164
};

src/stackmat.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ pub async fn stackmat_task(
2020
global_state: GlobalState,
2121
) {
2222
let serial_config = esp_hal::uart::Config::default().with_baudrate(1200);
23-
let Ok(mut uart) = UartRx::new(uart, serial_config).map(|u| u.with_rx(uart_pin))
24-
else {
23+
let Ok(mut uart) = UartRx::new(uart, serial_config).map(|u| u.with_rx(uart_pin)) else {
2524
log::error!("Stackmat task error while creating UartRx instance!");
2625
return;
2726
};

0 commit comments

Comments
 (0)