Skip to content

Commit 9534ae0

Browse files
MDr164claude
andcommitted
style(application): apply rustfmt formatting
Run cargo fmt to fix formatting across the application crate. No logic changes. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Marvin Drees <marvin.drees@9elements.com>
1 parent 9d94857 commit 9534ae0

File tree

7 files changed

+64
-44
lines changed

7 files changed

+64
-44
lines changed

application/src/auth.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ impl<'r> FromRequestParts<'r, ()> for AuthUser {
9595
core::str::from_utf8(&decoded[..n]).map_err(|_| AuthError::InvalidEncoding)?;
9696

9797
// 4. Split "username:password"
98-
let colon = decoded_str
99-
.find(':')
100-
.ok_or(AuthError::InvalidEncoding)?;
98+
let colon = decoded_str.find(':').ok_or(AuthError::InvalidEncoding)?;
10199
let username = &decoded_str[..colon];
102100
let password = &decoded_str[colon + 1..];
103101

application/src/main.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mod storage;
1616
mod web;
1717

1818
use defmt::*;
19+
use defmt_rtt as _;
1920
use embassy_executor::Spawner;
2021
use embassy_net::StackResources;
2122
use embassy_net_wiznet::chip::W5500;
@@ -31,13 +32,12 @@ use embassy_rp::spi::{Async, Config as SpiConfig, Spi};
3132
use embassy_rp::watchdog::Watchdog;
3233
use embassy_time::{Duration, Timer};
3334
use embedded_hal_bus::spi::ExclusiveDevice;
34-
use picoserve::AppWithStateBuilder;
35-
use static_cell::StaticCell;
36-
use defmt_rtt as _;
37-
#[cfg(feature = "panic-reset")]
38-
use panic_reset as _;
3935
#[cfg(feature = "panic-probe")]
4036
use panic_probe as _;
37+
#[cfg(feature = "panic-reset")]
38+
use panic_reset as _;
39+
use picoserve::AppWithStateBuilder;
40+
use static_cell::StaticCell;
4141

4242
use config::{FLASH_SIZE, SPI_FREQ_HZ};
4343
use gpio::gpio_task;
@@ -98,8 +98,7 @@ async fn main(spawner: Spawner) {
9898
drop(factory_reset_pin);
9999

100100
// 3. Init flash → ekv database (async flash using DMA_CH2)
101-
let flash: Flash<'static, _, FlashAsync, FLASH_SIZE> =
102-
Flash::new(p.FLASH, p.DMA_CH2, Irqs);
101+
let flash: Flash<'static, _, FlashAsync, FLASH_SIZE> = Flash::new(p.FLASH, p.DMA_CH2, Irqs);
103102
let random_seed_u32 = rng.next_u32();
104103
let db = init_database(flash, random_seed_u32).await;
105104

@@ -129,14 +128,10 @@ async fn main(spawner: Spawner) {
129128
let mut spi_cfg = SpiConfig::default();
130129
spi_cfg.frequency = SPI_FREQ_HZ;
131130
let spi = Spi::new(
132-
p.SPI0,
133-
p.PIN_18, // CLK
131+
p.SPI0, p.PIN_18, // CLK
134132
p.PIN_19, // MOSI
135133
p.PIN_16, // MISO
136-
p.DMA_CH0,
137-
p.DMA_CH1,
138-
Irqs,
139-
spi_cfg,
134+
p.DMA_CH0, p.DMA_CH1, Irqs, spi_cfg,
140135
);
141136
let cs = Output::new(p.PIN_17, Level::High);
142137
let w5500_int = Input::new(p.PIN_21, Pull::Up);

application/src/storage.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//! from the embassy-sync 0.7.x used elsewhere. We alias embassy-sync 0.6.x as
88
//! `embassy_sync_ekv` in Cargo.toml and use its RawMutex for the Database type.
99
10-
use embassy_rp::flash::{Async as FlashAsync, Flash};
11-
use embassy_sync_ekv::blocking_mutex::raw::CriticalSectionRawMutex;
1210
use ekv::flash::PageID;
1311
use ekv::{Config, Database};
12+
use embassy_rp::flash::{Async as FlashAsync, Flash};
13+
use embassy_sync_ekv::blocking_mutex::raw::CriticalSectionRawMutex;
1414
use embedded_storage_async::nor_flash::NorFlash;
1515
use static_cell::StaticCell;
1616

@@ -57,12 +57,8 @@ impl<'d> ekv::flash::Flash for PduFlash<'d> {
5757
data: &mut [u8],
5858
) -> Result<(), Self::Error> {
5959
let flash_offset = Self::page_offset(page_id) + offset as u32;
60-
embedded_storage_async::nor_flash::ReadNorFlash::read(
61-
&mut self.flash,
62-
flash_offset,
63-
data,
64-
)
65-
.await
60+
embedded_storage_async::nor_flash::ReadNorFlash::read(&mut self.flash, flash_offset, data)
61+
.await
6662
}
6763

6864
async fn write(

application/src/web/admin.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ pub async fn handle_set_user_ports(
175175

176176
// ── Delete user ────────────────────────────────────────────────────────────────
177177

178-
pub async fn handle_delete_user(
179-
username: heapless::String<32>,
180-
_admin: AdminUser,
181-
) -> ApiResult {
178+
pub async fn handle_delete_user(username: heapless::String<32>, _admin: AdminUser) -> ApiResult {
182179
let pw_key = user_pw_key(username.as_str());
183180
let ports_key = user_ports_key(username.as_str());
184181
let admin_key = user_admin_key(username.as_str());

application/src/web/gpio.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,29 @@ pub async fn handle_gpio_toggle(pin: u8, user: AuthUser) -> Json<GpioToggleRespo
7575
if pin >= 8 || (user.allowed_ports & (1 << pin) == 0) {
7676
let state_val = {
7777
let states = GPIO_STATES.lock().await;
78-
if (pin as usize) < 8 { states[pin as usize] } else { false }
78+
if (pin as usize) < 8 {
79+
states[pin as usize]
80+
} else {
81+
false
82+
}
7983
};
80-
return Json(GpioToggleResponse { pin, state: state_val });
84+
return Json(GpioToggleResponse {
85+
pin,
86+
state: state_val,
87+
});
8188
}
8289

8390
GPIO_SIGNAL.signal(GpioCommand::Toggle(pin));
8491
embassy_time::Timer::after_millis(1).await;
85-
let state_val = { let states = GPIO_STATES.lock().await; states[pin as usize] };
92+
let state_val = {
93+
let states = GPIO_STATES.lock().await;
94+
states[pin as usize]
95+
};
8696

87-
Json(GpioToggleResponse { pin, state: state_val })
97+
Json(GpioToggleResponse {
98+
pin,
99+
state: state_val,
100+
})
88101
}
89102

90103
// ── POST /api/gpio/:pin/set ────────────────────────────────────────────────────
@@ -97,14 +110,27 @@ pub async fn handle_gpio_set(
97110
if pin >= 8 || (user.allowed_ports & (1 << pin) == 0) {
98111
let state_val = {
99112
let states = GPIO_STATES.lock().await;
100-
if (pin as usize) < 8 { states[pin as usize] } else { false }
113+
if (pin as usize) < 8 {
114+
states[pin as usize]
115+
} else {
116+
false
117+
}
101118
};
102-
return Json(GpioToggleResponse { pin, state: state_val });
119+
return Json(GpioToggleResponse {
120+
pin,
121+
state: state_val,
122+
});
103123
}
104124

105125
GPIO_SIGNAL.signal(GpioCommand::Set(pin, body.state));
106126
embassy_time::Timer::after_millis(1).await;
107-
let state_val = { let states = GPIO_STATES.lock().await; states[pin as usize] };
127+
let state_val = {
128+
let states = GPIO_STATES.lock().await;
129+
states[pin as usize]
130+
};
108131

109-
Json(GpioToggleResponse { pin, state: state_val })
132+
Json(GpioToggleResponse {
133+
pin,
134+
state: state_val,
135+
})
110136
}

application/src/web/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ pub mod status;
77
pub mod update;
88

99
use picoserve::routing::{delete, get, parse_path_segment, post};
10-
use update::FirmwareUpdateService;
1110
use picoserve::{AppWithStateBuilder, Router};
11+
use update::FirmwareUpdateService;
1212

1313
use crate::storage::PduDatabase;
1414

@@ -21,8 +21,7 @@ use crate::storage::PduDatabase;
2121
///
2222
/// Stored as `usize` (pointer-as-integer) in a `portable_atomic::AtomicUsize`
2323
/// so the static is `Sync` without needing unsafe.
24-
static DB_PTR: portable_atomic::AtomicUsize =
25-
portable_atomic::AtomicUsize::new(0);
24+
static DB_PTR: portable_atomic::AtomicUsize = portable_atomic::AtomicUsize::new(0);
2625

2726
/// Initialise the module-level DB handle. Call exactly once before spawning web tasks.
2827
pub fn init_db(db: &'static PduDatabase) {

application/src/web/update.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ impl MethodHandlerService<(), ()> for FirmwareUpdateService {
6262
let conn = body_connection.finalize().await?;
6363

6464
match result {
65-
Ok(()) => (StatusCode::OK, "{\"ok\":true}").write_to(conn, response_writer).await,
66-
Err(msg) => (StatusCode::INTERNAL_SERVER_ERROR, msg)
67-
.write_to(conn, response_writer)
68-
.await,
65+
Ok(()) => {
66+
(StatusCode::OK, "{\"ok\":true}")
67+
.write_to(conn, response_writer)
68+
.await
69+
}
70+
Err(msg) => {
71+
(StatusCode::INTERNAL_SERVER_ERROR, msg)
72+
.write_to(conn, response_writer)
73+
.await
74+
}
6975
}
7076
}
7177
}
@@ -117,7 +123,10 @@ async fn write_firmware_streaming<'r, R: Read>(
117123
remaining -= chunk_size;
118124
}
119125

120-
updater.mark_updated().await.map_err(|_| "Mark update error")?;
126+
updater
127+
.mark_updated()
128+
.await
129+
.map_err(|_| "Mark update error")?;
121130

122131
embassy_time::Timer::after_millis(100).await;
123132
cortex_m::peripheral::SCB::sys_reset();

0 commit comments

Comments
 (0)