mirror of
https://github.com/hubaldv/bioz-firmware-rs.git
synced 2025-12-06 05:01:18 +00:00
Updated library.
This commit is contained in:
@@ -21,7 +21,7 @@ use postcard_rpc::{
|
||||
|
||||
use bioz_icd_rs::{PingEndpoint, GetUniqueIdEndpoint, SetGreenLedEndpoint, StartImpedanceEndpoint, StopImpedanceEndpoint, StartImpedance, ImpedanceOutputTopic, ENDPOINT_LIST, TOPICS_IN_LIST, TOPICS_OUT_LIST};
|
||||
|
||||
use crate::impedance::{IMPEDANCE_CHANNEL};
|
||||
use crate::impedance::{ImpedanceSetupType, IMPEDANCE_CHANNEL};
|
||||
|
||||
// Postcard RPC types
|
||||
type AppDriver = usb::Driver<'static, peripherals::USB>;
|
||||
@@ -37,15 +37,19 @@ static STORAGE: AppStorage = AppStorage::new();
|
||||
|
||||
pub struct Context {
|
||||
pub unique_id: [u8; 12],
|
||||
pub impedance_setup: &'static ImpedanceSetupType,
|
||||
}
|
||||
|
||||
pub struct SpawnCtx {
|
||||
pub impedance_setup: &'static ImpedanceSetupType,
|
||||
}
|
||||
|
||||
impl SpawnContext for Context {
|
||||
type SpawnCtxt = SpawnCtx;
|
||||
fn spawn_ctxt(&mut self) -> Self::SpawnCtxt {
|
||||
SpawnCtx {}
|
||||
SpawnCtx {
|
||||
impedance_setup: self.impedance_setup,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,13 +63,13 @@ define_dispatch! {
|
||||
endpoints: {
|
||||
list: ENDPOINT_LIST;
|
||||
|
||||
| EndpointTy | kind | handler |
|
||||
| ---------- | ---- | ------- |
|
||||
| PingEndpoint | blocking | ping_handler |
|
||||
| GetUniqueIdEndpoint | blocking | get_unique_id_handler |
|
||||
| SetGreenLedEndpoint | async | set_green_led_handler |
|
||||
| StartImpedanceEndpoint | spawn | start_impedance_handler |
|
||||
| StopImpedanceEndpoint | async | stop_impedance_handler |
|
||||
| EndpointTy | kind | handler |
|
||||
| ---------- | ---- | ------- |
|
||||
| PingEndpoint | blocking | ping_handler |
|
||||
| GetUniqueIdEndpoint | blocking | get_unique_id_handler |
|
||||
| SetGreenLedEndpoint | async | set_green_led_handler |
|
||||
| StartImpedanceEndpoint | spawn | start_single_impedance_handler |
|
||||
| StopImpedanceEndpoint | async | stop_single_impedance_handler |
|
||||
};
|
||||
topics_in: {
|
||||
list: TOPICS_IN_LIST;
|
||||
@@ -111,13 +115,14 @@ async fn server_run(mut server: AppServer) {
|
||||
|
||||
// ---
|
||||
|
||||
pub fn init_communication(usb_driver: Driver<'static, peripherals::USB>, spawner: Spawner) {
|
||||
pub fn init_communication(usb_driver: Driver<'static, peripherals::USB>, impedance_setup: &'static ImpedanceSetupType, spawner: Spawner) {
|
||||
// Initialize communication peripherals
|
||||
let pbufs = PBUFS.take();
|
||||
let config = usb_config();
|
||||
|
||||
let context = Context {
|
||||
unique_id: *uid::uid(),
|
||||
impedance_setup: impedance_setup,
|
||||
};
|
||||
|
||||
let (device, tx_impl, rx_impl) = STORAGE.init(usb_driver, config, pbufs.tx_buf.as_mut_slice());
|
||||
@@ -158,11 +163,16 @@ static RUNNING: Mutex<ThreadModeRawMutex, bool> = Mutex::new(false);
|
||||
static STOP: Mutex<ThreadModeRawMutex, bool> = Mutex::new(false);
|
||||
|
||||
#[embassy_executor::task]
|
||||
pub async fn start_impedance_handler(_context: SpawnCtx, header: VarHeader, rqst: StartImpedance, sender: Sender<AppTx>) {
|
||||
info!("Start impedance measurement with rate {:?} Hz.", rqst.update_frequency);
|
||||
pub async fn start_single_impedance_handler(context: SpawnCtx, header: VarHeader, rqst: StartImpedance, sender: Sender<AppTx>) {
|
||||
info!("Start impedance measurement at {:?} Hz.", rqst.sinus_frequency);
|
||||
|
||||
*RUNNING.lock().await = true;
|
||||
|
||||
// Init the sequencer
|
||||
context.impedance_setup.lock().await.init_single_frequency_measurement(rqst.sinus_frequency).await;
|
||||
// Trigger the sequencer
|
||||
context.impedance_setup.lock().await.start_measurement().await;
|
||||
|
||||
if sender
|
||||
.reply::<StartImpedanceEndpoint>(header.seq_no, &())
|
||||
.await
|
||||
@@ -193,7 +203,7 @@ pub async fn start_impedance_handler(_context: SpawnCtx, header: VarHeader, rqst
|
||||
*STOP.lock().await = false;
|
||||
}
|
||||
|
||||
pub async fn stop_impedance_handler(_context: &mut Context, _header: VarHeader, _rqst: ()) -> bool {
|
||||
pub async fn stop_single_impedance_handler(_context: &mut Context, _header: VarHeader, _rqst: ()) -> bool {
|
||||
info!("Stop impedance measurement");
|
||||
let was_busy = *RUNNING.lock().await;
|
||||
if was_busy {
|
||||
|
||||
Reference in New Issue
Block a user