A RPi Pico powered Lightning Detector

Reinstate alloc lock, clean read loop

+13 -12
+4 -2
src/allocator.rs
··· 3 3 ptr::NonNull, 4 4 }; 5 5 6 - use embassy_sync::blocking_mutex::{Mutex, raw::CriticalSectionRawMutex}; 6 + use embassy_sync::blocking_mutex::Mutex; 7 7 use rlsf::Tlsf; 8 8 use static_cell::ConstStaticCell; 9 + 10 + use crate::locks::AllocatorLock; 9 11 10 12 type Heap = Tlsf<'static, usize, usize, { usize::BITS as usize }, { usize::BITS as usize }>; 11 13 ··· 14 16 } 15 17 16 18 pub struct PicoHeap<const MEMORY_SIZE: usize> { 17 - inner: Mutex<CriticalSectionRawMutex, HeapInner>, 19 + inner: Mutex<AllocatorLock, HeapInner>, 18 20 block: ConstStaticCell<[u8; MEMORY_SIZE]>, 19 21 } 20 22
+1
src/locks.rs
··· 1 1 use embassy_rp::spinlock_mutex::SpinlockRawMutex; 2 2 3 + pub type AllocatorLock = SpinlockRawMutex<0>; 3 4 pub type RtcLock = SpinlockRawMutex<1>; 4 5 pub type ConnectionStatusLock = SpinlockRawMutex<2>; 5 6 pub type DataTransferLock = SpinlockRawMutex<3>;
+8 -10
src/net/crypto.rs
··· 2 2 use embassy_futures::select::{Either, select}; 3 3 use embassy_net::tcp::{TcpReader, TcpSocket, TcpWriter}; 4 4 use embedded_io_async::{Read, Write}; 5 - use sachy_fmt::{error, unwrap, warn}; 5 + use sachy_fmt::{error, unwrap}; 6 6 use striker_proto::{Server, ServerBuilder, ServerReceiver, ServerSender}; 7 7 8 8 use crate::{ ··· 43 43 .await 44 44 .map_err(|_| PicoError::CryptoProtoError)?; 45 45 46 - if msg_size > 0 47 - && let Ok(req) = recv_state.decode_request(&mut msg_buf) 46 + let req = recv_state.decode_request(&mut msg_buf)?; 47 + 48 + if let Some((resp, resp_tx)) = RpcServer::handle_request(req) 49 + .await 50 + .zip(UpdateConnection::can_update()) 48 51 { 49 - let Some((resp, resp_tx)) = RpcServer::handle_request(req) 50 - .await 51 - .zip(UpdateConnection::can_update()) 52 - else { 53 - warn!("Connection dropped before response"); 54 - break; 55 - }; 56 52 resp_tx.try_send(resp).ok(); 53 + } else { 54 + break; 57 55 } 58 56 59 57 msg_buf.resize_with(4096, Default::default);