Skip to content

Commit

Permalink
Merge pull request #69 from uorocketry/cleanup
Browse files Browse the repository at this point in the history
Cleanup πŸš€πŸ’₯
  • Loading branch information
NoahSprenger authored Sep 26, 2023
2 parents 1c85708 + 05f20ea commit bbbe96e
Show file tree
Hide file tree
Showing 33 changed files with 129 additions and 345 deletions.
38 changes: 19 additions & 19 deletions boards/camera/src/communication.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
use crate::data_manager::DataManager;
use crate::types::*;

use atsamd_hal::can::Dependencies;
use atsamd_hal::clock::v2::ahb::AhbClk;
use atsamd_hal::clock::v2::gclk::Gclk0Id;
use atsamd_hal::clock::v2::pclk::Pclk;
use atsamd_hal::clock::v2::pclk::PclkToken;

use atsamd_hal::clock::v2::types::Can0;
use atsamd_hal::clock::v2::Source;
use atsamd_hal::dmac;
use atsamd_hal::gpio::{Alternate, AlternateI, Disabled, Floating, Pin, I, PA22, PA23, PB16, PB17};

use atsamd_hal::gpio::{Alternate, AlternateI, Pin, I, PA22, PA23};
use atsamd_hal::pac::CAN0;
use atsamd_hal::pac::MCLK;
use atsamd_hal::pac::SERCOM5;
use atsamd_hal::sercom::Sercom;
use atsamd_hal::sercom::{uart, Sercom5};
use atsamd_hal::sercom;
use atsamd_hal::sercom::uart::{ TxDuplex, RxDuplex};
use atsamd_hal::sercom::uart::{Duplex, Uart};
use atsamd_hal::time::*;








use atsamd_hal::typelevel::Increment;
use common_arm::mcan;
use common_arm::mcan::message::{rx, Raw};
use common_arm::mcan::tx_buffers::DynTx;
use common_arm::HydraError;
use defmt::flush;



use defmt::info;
use common_arm::spawn;
use heapless::Vec;


use mcan::bus::Can;
use mcan::embedded_can as ecan;
use mcan::interrupt::state::EnabledLine0;
Expand All @@ -37,13 +37,13 @@ use mcan::{
config::{BitTiming, Mode},
filter::{Action, Filter},
};
use messages::mavlink;

use messages::Message;
use postcard::from_bytes;
use systick_monotonic::fugit::RateExtU32;
use typenum::{U0, U128, U32, U64};

use atsamd_hal::dmac::Transfer;


pub struct Capacities;

Expand Down
2 changes: 1 addition & 1 deletion boards/camera/src/data_manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use messages::sensor::{Air};
use messages::Message;
use messages::state::{State, StateData};

use defmt::info;
use heapless::HistoryBuffer;

Expand Down
2 changes: 1 addition & 1 deletion boards/camera/src/gpio_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct GPIOManager {
}

impl GPIOManager {
pub fn new(mut cam1: Pin<PA09, PushPullOutput>, mut cam2: Pin<PA06, PushPullOutput>) -> Self {
pub fn new(cam1: Pin<PA09, PushPullOutput>, cam2: Pin<PA06, PushPullOutput>) -> Self {
Self {
cam1,
cam2
Expand Down
6 changes: 3 additions & 3 deletions boards/camera/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod app {

// SAFETY: Misusing the PAC API can break the system.
// This is safe because we only steal the MCLK.
let (_, _, _, mclk) = unsafe { clocks.pac.steal() };
let (_, _, _, _mclk) = unsafe { clocks.pac.steal() };

/* CAN config */
let (pclk_can, gclk0) = Pclk::enable(tokens.pclks.can0, gclk0);
Expand Down Expand Up @@ -128,9 +128,9 @@ mod app {
});
Ok(())
});
if (*cx.local.num < 3) {
if *cx.local.num < 3 {
*cx.local.num += 1;
spawn_after!(toggle_cams, ExtU64::millis(150));
spawn_after!(toggle_cams, ExtU64::millis(150)).ok();
}
}

Expand Down
28 changes: 11 additions & 17 deletions boards/camera/src/state_machine/states/ascent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,28 @@ use crate::state_machine::states::descent::Descent;
use crate::state_machine::states::wait_for_takeoff::WaitForTakeoff;
use crate::state_machine::{RocketStates, State, StateMachineContext, TransitionInto};
use crate::{no_transition, transition};
use messages::command::{Command, CommandData, PowerDown, RadioRateChange, RadioRate};
use messages::Message;

use defmt::{write, Format, Formatter};
use rtic::mutex::Mutex;
use crate::types::COM_ID;
use crate::app::monotonics;
use systick_monotonic::ExtU64;

use crate::app::toggle_cams;
use common_arm::spawn;

#[derive(Debug, Clone)]
pub struct Ascent {}

impl State for Ascent {
fn enter(&self, context: &mut StateMachineContext) {
spawn!(toggle_cams);
fn enter(&self, _context: &mut StateMachineContext) {
spawn!(toggle_cams).ok();
}
fn step(&mut self, context: &mut StateMachineContext) -> Option<RocketStates> {
context
.shared_resources
.data_manager
.lock(|data| {
if data.is_falling() {
transition!(self, Descent)
} else {
no_transition!()
}
})
context.shared_resources.data_manager.lock(|data| {
if data.is_falling() {
transition!(self, Descent)
} else {
no_transition!()
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion boards/camera/src/state_machine/states/descent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::Ascent;
use crate::state_machine::{TerminalDescent, RocketStates, State, StateMachineContext, TransitionInto};
use crate::{no_transition, transition};
use rtic::mutex::Mutex;
use defmt::{write, Format, Formatter, info};
use defmt::{write, Format, Formatter};

#[derive(Debug, Clone)]
pub struct Descent {}
Expand Down
2 changes: 1 addition & 1 deletion boards/camera/src/state_machine/states/terminal_descent.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use defmt::{write, Format, Formatter, info};
use defmt::{write, Format, Formatter};

use crate::{no_transition, transition};
use crate::state_machine::{WaitForRecovery, RocketStates, State, StateMachineContext, TransitionInto};
Expand Down
14 changes: 4 additions & 10 deletions boards/camera/src/state_machine/states/wait_for_recovery.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use super::TerminalDescent;
use crate::app::monotonics;
use crate::no_transition;
use crate::state_machine::{RocketStates, State, StateMachineContext, TransitionInto};
use crate::types::COM_ID;
use crate::{no_transition, transition};
use rtic::mutex::Mutex;
use defmt::{write, Format, Formatter, info};
use messages::command::{Command, CommandData, PowerDown, RadioRateChange, RadioRate};
use messages::Message;
use messages::sender::Sender::SensorBoard;
use defmt::{write, Format, Formatter};

#[derive(Debug, Clone)]
pub struct WaitForRecovery {}

impl State for WaitForRecovery {
fn step(&mut self, context: &mut StateMachineContext) -> Option<RocketStates> {
no_transition!() // this is our final resting place. We should also powerdown this board.
fn step(&mut self, _context: &mut StateMachineContext) -> Option<RocketStates> {
no_transition!() // this is our final resting place. We should also powerdown this board.
}
}

Expand Down
2 changes: 1 addition & 1 deletion boards/camera/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ use messages::sender::{Sender, Sender::CameraBoard};
// -------
// Sender ID
// -------
pub static COM_ID: Sender = CameraBoard;
pub static _COM_ID: Sender = CameraBoard;
10 changes: 3 additions & 7 deletions boards/communication/src/communication.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::app::send_internal;
use crate::data_manager::DataManager;
use crate::types::*;
use atsamd_hal::can::Dependencies;
Expand All @@ -14,18 +13,15 @@ use atsamd_hal::pac::CAN0;
use atsamd_hal::pac::MCLK;
use atsamd_hal::pac::SERCOM5;
use atsamd_hal::sercom;
use atsamd_hal::sercom::uart::{Duplex, Uart};
use atsamd_hal::sercom::uart::{RxDuplex, TxDuplex};
use atsamd_hal::sercom::uart::{Uart};
use atsamd_hal::sercom::uart::{TxDuplex};
use atsamd_hal::sercom::Sercom;
use atsamd_hal::sercom::{uart, Sercom5};
use atsamd_hal::time::*;
use atsamd_hal::typelevel::Increment;
use common_arm::mcan;
use common_arm::mcan::message::{rx, Raw};
use common_arm::mcan::tx_buffers::DynTx;
use common_arm::spawn;
use common_arm::HydraError;
use defmt::flush;
use defmt::info;
use heapless::Vec;
use mcan::bus::Can;
Expand Down Expand Up @@ -300,7 +296,7 @@ impl RadioManager {
buf_select: false,
}
}
pub fn process_message(&mut self, buf: RadioBuffer) {
pub fn _process_message(&mut self, buf: RadioBuffer) {
match from_bytes::<Message>(buf) {
Ok(msg) => {
info!("Radio: {}", msg);
Expand Down
4 changes: 2 additions & 2 deletions boards/communication/src/data_manager.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use defmt::info;
use messages::command::{Command, CommandData, RadioRate, RadioRateChange};
use messages::command::{RadioRate};
use messages::sensor::{
Air, EkfNav1, EkfNav2, EkfQuat, GpsPos1, GpsPos2, GpsVel, Imu1, Imu2, SensorData, UtcTime,
};
use messages::state::{State, StateData};
use messages::state::{StateData};
use messages::Message;

#[derive(Clone)]
Expand Down
2 changes: 0 additions & 2 deletions boards/communication/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ use communication::{RadioDevice, RadioManager};
use data_manager::DataManager;
// use communication::radio_dma;

use defmt::{flush, info};
use hal::gpio::Pins;
use hal::gpio::{Alternate, Pin, PushPull, PushPullOutput, C, PA05, PB12, PB13, PB14, PB15};
use hal::prelude::*;
use hal::sercom::{spi, spi::Config, spi::Duplex, spi::Pads, spi::Spi, IoSet1, Sercom4};
use heapless::Vec;
use mcan::messageram::SharedMemory;
use messages::command::RadioRate;
use messages::sensor::Sensor;
Expand Down
4 changes: 1 addition & 3 deletions boards/communication/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use atsamd_hal::{gpio::*, dmac};
use atsamd_hal::sercom::uart::EightBit;
use atsamd_hal::sercom::{spi, Sercom4};
use atsamd_hal::sercom::{Sercom5, Sercom1, uart, IoSet1};
use atsamd_hal::sercom::{Sercom5, uart, IoSet1};
use messages::sender::Sender;
use messages::sender::Sender::CommunicationBoard;
use embedded_sdmmc as sd;
use atsamd_hal::dmac::BufferPair;
use atsamd_hal::sercom::uart::Uart;

Expand Down
4 changes: 2 additions & 2 deletions boards/power/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl CanDevice0 {
gclk0,
)
}
pub fn send_message(&mut self, m: Message) -> Result<(), HydraError> {
pub fn _send_message(&mut self, m: Message) -> Result<(), HydraError> {
let payload: Vec<u8, 64> = postcard::to_vec(&m)?;
self.can.tx.transmit_queued(
tx::MessageBuilder {
Expand All @@ -139,7 +139,7 @@ impl CanDevice0 {
)?;
Ok(())
}
pub fn process_data(&mut self, data_manager: &mut DataManager) {
pub fn _process_data(&mut self, data_manager: &mut DataManager) {
let line_interrupts = &self.line_interrupts;
for interrupt in line_interrupts.iter_flagged() {
match interrupt {
Expand Down
12 changes: 6 additions & 6 deletions boards/power/src/data_manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// import messages
use messages::sensor::{Current, Voltage, Regulator, Temperature, SensorData};
use messages::sensor::{Current, Regulator, SensorData, Temperature, Voltage};
use messages::Message;

pub struct DataManager {
Expand All @@ -11,14 +11,14 @@ pub struct DataManager {

impl DataManager {
pub fn new() -> Self {
Self {
Self {
regulator: [None, None, None, None],
voltage: [None, None, None, None],
current: None,
temperature: [None, None, None, None],
}
}
pub fn clone_power(&self) -> [Option<SensorData>; 13] {
pub fn _clone_power(&self) -> [Option<SensorData>; 13] {
[
self.regulator[0].clone().map(|x| x.into()),
self.regulator[1].clone().map(|x| x.into()),
Expand All @@ -35,13 +35,13 @@ impl DataManager {
self.temperature[3].clone().map(|x| x.into()),
]
}
pub fn handle_data(&mut self, data: Message) {
// to do
pub fn handle_data(&mut self, _data: Message) {
// to do
}
}

impl Default for DataManager {
fn default() -> Self {
Self::new()
}
}
}
2 changes: 1 addition & 1 deletion boards/power/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ use messages::sender::{Sender, Sender::PowerBoard};
// -------
// Sender ID
// -------
pub static COM_ID: Sender = PowerBoard;
pub static _COM_ID: Sender = PowerBoard;
8 changes: 4 additions & 4 deletions boards/recovery/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ impl DataManager {
}
},
messages::Data::Command(command) => match command.data {
messages::command::CommandData::DeployDrogue(drogue) => {
spawn!(fire_drogue);
messages::command::CommandData::DeployDrogue(_drogue) => {
spawn!(fire_drogue).ok();
},
messages::command::CommandData::DeployMain(main) => {
spawn!(fire_main);
messages::command::CommandData::DeployMain(_main) => {
spawn!(fire_main).ok();
},
messages::command::CommandData::PowerDown(_) => {
// don't handle for now.
Expand Down
7 changes: 3 additions & 4 deletions boards/recovery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use panic_halt as _;
use state_machine::{StateMachine, StateMachineContext};
use systick_monotonic::*;
use types::COM_ID;
use defmt::info;

#[rtic::app(device = hal::pac, peripherals = true, dispatchers = [EVSYS_0, EVSYS_1, EVSYS_2])]
mod app {
Expand Down Expand Up @@ -132,7 +131,7 @@ mod app {
gpio.fire_drogue();
*cx.local.fired = true;
});
spawn_after!(fire_drogue, ExtU64::secs(5));
spawn_after!(fire_drogue, ExtU64::secs(5)).ok();
} else {
cx.shared.gpio.lock(|gpio| {
gpio.close_drogue();
Expand All @@ -147,7 +146,7 @@ mod app {
gpio.fire_main();
*cx.local.fired = true;
});
spawn_after!(fire_main, ExtU64::secs(5));
spawn_after!(fire_main, ExtU64::secs(5)).ok();
} else {
cx.shared.gpio.lock(|gpio| {
gpio.close_main();
Expand Down Expand Up @@ -208,7 +207,7 @@ mod app {
spawn!(send_internal, message)?;
Ok(())
});
spawn_after!(state_send, ExtU64::secs(2));
spawn_after!(state_send, ExtU64::secs(2)).ok();
}

/// Simple blink task to test the system.
Expand Down
Loading

0 comments on commit bbbe96e

Please sign in to comment.